Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:02:56

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Chao Peng, Wouter Deconinck, Sylvester Joosten, Barak Schmookler, David Lawrence
0003 
0004 // A general digitization for CalorimeterHit from simulation
0005 // 1. Smear energy deposit with a/sqrt(E/GeV) + b + c/E or a/sqrt(E/GeV) (relative value)
0006 // 2. Digitize the energy with dynamic ADC range and add pedestal (mean +- sigma)
0007 // 3. Time conversion with smearing resolution (absolute value)
0008 // 4. Signal is summed if the SumFields are provided
0009 //
0010 // Author: Chao Peng
0011 // Date: 06/02/2021
0012 
0013 
0014 #pragma once
0015 
0016 #include <algorithms/algorithm.h>
0017 #include <algorithms/geo.h>
0018 #include <DD4hep/IDDescriptor.h>
0019 #include <edm4eic/EDM4eicVersion.h>
0020 #if EDM4EIC_VERSION_MAJOR >= 7
0021 #include <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
0022 #endif
0023 #include <edm4hep/RawCalorimeterHitCollection.h>
0024 #include <edm4hep/SimCalorimeterHitCollection.h>
0025 #include <random>
0026 #include <stdint.h>
0027 #include <string>
0028 #include <string_view>
0029 #include <functional>
0030 
0031 #include "CalorimeterHitDigiConfig.h"
0032 #include "algorithms/interfaces/WithPodConfig.h"
0033 
0034 namespace eicrecon {
0035 
0036   using CalorimeterHitDigiAlgorithm = algorithms::Algorithm<
0037     algorithms::Input<
0038       edm4hep::SimCalorimeterHitCollection
0039     >,
0040     algorithms::Output<
0041 #if EDM4EIC_VERSION_MAJOR >= 7
0042       edm4hep::RawCalorimeterHitCollection,
0043       edm4eic::MCRecoCalorimeterHitAssociationCollection
0044 #else
0045       edm4hep::RawCalorimeterHitCollection
0046 #endif
0047     >
0048   >;
0049 
0050   class CalorimeterHitDigi
0051   : public CalorimeterHitDigiAlgorithm,
0052     public WithPodConfig<CalorimeterHitDigiConfig> {
0053 
0054   public:
0055     CalorimeterHitDigi(std::string_view name)
0056       : CalorimeterHitDigiAlgorithm{name,
0057                             {"inputHitCollection"},
0058 #if EDM4EIC_VERSION_MAJOR >= 7
0059                             {"outputRawHitCollection", "outputRawHitAssociationCollection"},
0060 #else
0061                             {"outputRawHitCollection"},
0062 #endif
0063                             "Smear energy deposit, digitize within ADC range, add pedestal, "
0064                             "convert time with smearing resolution, and sum signals."} {}
0065 
0066     void init() final;
0067     void process(const Input&, const Output&) const final;
0068 
0069   private:
0070 
0071     // unitless counterparts of inputs
0072     double           dyRangeADC{0}, stepTDC{0}, tRes{0};
0073 
0074     uint64_t         id_mask{0};
0075 
0076     std::function<double(const edm4hep::SimCalorimeterHit &h)> corrMeanScale;
0077 
0078     dd4hep::IDDescriptor id_spec;
0079 
0080   private:
0081     const algorithms::GeoSvc& m_geo = algorithms::GeoSvc::instance();
0082 
0083     mutable std::default_random_engine m_generator;
0084     mutable std::normal_distribution<double> m_gaussian;
0085 
0086   };
0087 
0088 } // namespace eicrecon