Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:21:29

0001 #ifndef SimTracker_SiPhase2Digitizer_Phase2TrackerDigitizerAlgorithm_h
0002 #define SimTracker_SiPhase2Digitizer_Phase2TrackerDigitizerAlgorithm_h
0003 
0004 #include <map>
0005 #include <memory>
0006 #include <vector>
0007 
0008 #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
0009 #include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
0010 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0011 #include "DataFormats/Math/interface/approx_exp.h"
0012 #include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h"
0013 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0014 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h"
0015 
0016 #include "SimTracker/Common/interface/DigitizerUtility.h"
0017 #include "SimTracker/Common/interface/SiPixelChargeReweightingAlgorithm.h"
0018 #include "SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerDigitizerFwd.h"
0019 
0020 // Units and Constants
0021 #include "DataFormats/Math/interface/CMSUnits.h"
0022 #include <CLHEP/Units/PhysicalConstants.h>
0023 #include <CLHEP/Units/SystemOfUnits.h>
0024 
0025 // forward declarations
0026 // For the random numbers
0027 namespace CLHEP {
0028   class HepRandomEngine;
0029   class RandGaussQ;
0030   class RandFlat;
0031 }  // namespace CLHEP
0032 
0033 class DetId;
0034 class GaussianTailNoiseGenerator;
0035 class SiG4UniversalFluctuation;
0036 class SiPixelGainCalibrationOfflineSimService;
0037 class SiPixelLorentzAngle;
0038 class SiPixelQuality;
0039 class SiPhase2OuterTrackerLorentzAngle;
0040 class TrackerGeometry;
0041 class TrackerTopology;
0042 class SiPixelChargeReweightingAlgorithm;
0043 
0044 // REMEMBER CMS conventions:
0045 // -- Energy: GeV
0046 // -- momentum: GeV/c
0047 // -- mass: GeV/c^2
0048 // -- Distance, position: cm
0049 // -- Time: ns
0050 // -- Angles: radian
0051 // Some constants in convenient units
0052 constexpr double c_cm_ns = CLHEP::c_light * CLHEP::ns / CLHEP::cm;
0053 constexpr double c_inv = 1.0 / c_cm_ns;
0054 
0055 class Phase2TrackerDigitizerAlgorithm {
0056 public:
0057   Phase2TrackerDigitizerAlgorithm(const edm::ParameterSet& conf_common,
0058                                   const edm::ParameterSet& conf_specific,
0059                                   edm::ConsumesCollector iC);
0060   virtual ~Phase2TrackerDigitizerAlgorithm();
0061 
0062   // initialization that cannot be done in the constructor
0063   virtual void init(const edm::EventSetup& es) = 0;
0064   virtual void initializeEvent(CLHEP::HepRandomEngine& eng);
0065 
0066   // run the algorithm to digitize a single det
0067   virtual void accumulateSimHits(const std::vector<PSimHit>::const_iterator inputBegin,
0068                                  const std::vector<PSimHit>::const_iterator inputEnd,
0069                                  const size_t inputBeginGlobalIndex,
0070                                  const uint32_t tofBin,
0071                                  const Phase2TrackerGeomDetUnit* pixdet,
0072                                  const GlobalVector& bfield);
0073   virtual void digitize(const Phase2TrackerGeomDetUnit* pixdet,
0074                         std::map<int, digitizerUtility::DigiSimInfo>& digi_map,
0075                         const TrackerTopology* tTopo);
0076   virtual bool select_hit(const PSimHit& hit, double tCorr, double& sigScale) const { return true; }
0077   virtual bool isAboveThreshold(const digitizerUtility::SimHitInfo* hitInfo, float charge, float thr) const {
0078     return true;
0079   }
0080 
0081   // For premixing
0082   void loadAccumulator(uint32_t detId, const std::map<int, float>& accumulator);
0083 
0084 protected:
0085   // Accessing Inner Tracker Lorentz angle from DB:
0086   const SiPixelLorentzAngle* siPixelLorentzAngle_;
0087 
0088   // Accessing Outer Tracker Lorentz angle from DB:
0089   const SiPhase2OuterTrackerLorentzAngle* siPhase2OTLorentzAngle_;
0090 
0091   // Accessing Dead pixel modules from DB:
0092   const SiPixelQuality* siPixelBadModule_;
0093 
0094   // Accessing Map and Geom:
0095   const TrackerGeometry* geom_;
0096   struct SubdetEfficiencies {
0097     SubdetEfficiencies(const edm::ParameterSet& conf);
0098     std::vector<double> barrel_efficiencies;
0099     std::vector<double> endcap_efficiencies;
0100   };
0101 
0102   // Internal type aliases
0103   using signal_map_type = std::map<int, digitizerUtility::Ph2Amplitude, std::less<int> >;
0104   using signalMaps = std::map<uint32_t, signal_map_type>;
0105   using Frame = GloballyPositioned<double>;
0106   using Parameters = std::vector<edm::ParameterSet>;
0107 
0108   // Contains the accumulated hit info.
0109   signalMaps _signal;
0110 
0111   const bool makeDigiSimLinks_;
0112 
0113   const bool use_ineff_from_db_;
0114   const bool use_module_killing_;   // remove or not the dead pixel modules
0115   const bool use_deadmodule_DB_;    // if we want to get dead pixel modules from the DataBase.
0116   const bool use_LorentzAngle_DB_;  // if we want to get Lorentz angle from the DataBase.
0117 
0118   const Parameters deadModules_;
0119 
0120   // Variables
0121   // external parameters
0122   // go from Geant energy GeV to number of electrons
0123   const float GeVperElectron_;  // 3.7E-09
0124 
0125   //-- drift
0126   const bool alpha2Order_;  // Switch on/off of E.B effect
0127   const bool addXtalk_;
0128   const float interstripCoupling_;
0129   const float Sigma0_;      //=0.0007  // Charge diffusion in microns for 300 micron Si
0130   const float SigmaCoeff_;  // delta in the diffusion across the strip pitch
0131 
0132   //-- induce_signal
0133   const float clusterWidth_;  // Gaussian charge cutoff width in sigma units
0134 
0135   //-- make_digis
0136   const int thePhase2ReadoutMode_;   //  Flag to decide readout mode (digital/Analog dual slope etc.)
0137   const float theElectronPerADC_;    // Gain, number of electrons per adc count.
0138   const int theAdcFullScale_;        // Saturation count, 255=8bit.
0139   const float theNoiseInElectrons_;  // Noise (RMS) in units of electrons.
0140   const float theReadoutNoise_;      // Noise of the readount chain in elec,
0141 
0142   // inludes DCOL-Amp,TBM-Amp, Alt, AOH,OptRec.
0143   const float theThresholdInE_Endcap_;  // threshold in electrons Endcap.
0144   const float theThresholdInE_Barrel_;  // threshold in electrons Barrel.
0145 
0146   const double theThresholdSmearing_Endcap_;
0147   const double theThresholdSmearing_Barrel_;
0148 
0149   const double theHIPThresholdInE_Endcap_;
0150   const double theHIPThresholdInE_Barrel_;
0151 
0152   const float theTofLowerCut_;                  // Cut on the particle TOF
0153   const float theTofUpperCut_;                  // Cut on the particle TOF
0154   const float tanLorentzAnglePerTesla_Endcap_;  //FPix Lorentz angle tangent per Tesla
0155   const float tanLorentzAnglePerTesla_Barrel_;  //BPix Lorentz angle tangent per Tesla
0156 
0157   // -- add_noise
0158   const bool addNoise_;
0159   const bool addNoisyPixels_;
0160   const bool fluctuateCharge_;
0161 
0162   //-- pixel efficiency
0163   const bool addPixelInefficiency_;  // bool to read in inefficiencies
0164 
0165   const bool addThresholdSmearing_;
0166 
0167   // pseudoRadDamage
0168   const double pseudoRadDamage_;        // Decrease the amount off freed charge that reaches the collector
0169   const double pseudoRadDamageRadius_;  // Only apply pseudoRadDamage to pixels with radius<=pseudoRadDamageRadius
0170 
0171   // charge reweighting
0172   const bool useChargeReweighting_;
0173   // access 2D templates from DB. Only gets initialized if useChargeReweighting_ is set to true
0174   const std::unique_ptr<SiPixelChargeReweightingAlgorithm> theSiPixelChargeReweightingAlgorithm_;
0175 
0176   // The PDTable
0177   // HepPDTable *particleTable;
0178   // ParticleDataTable *particleTable;
0179 
0180   //-- charge fluctuation
0181   const double tMax_;  // The delta production cut, should be as in OSCAR = 30keV
0182 
0183   // Bad Pixels to be killed
0184   Parameters badPixels_;
0185 
0186   // The eloss fluctuation class from G4. Is the right place?
0187   const std::unique_ptr<SiG4UniversalFluctuation> fluctuate_;  // make a pointer
0188   const std::unique_ptr<GaussianTailNoiseGenerator> theNoiser_;
0189 
0190   //-- additional member functions
0191   // Private methods
0192   virtual std::vector<digitizerUtility::EnergyDepositUnit> primary_ionization(const PSimHit& hit) const;
0193   virtual std::vector<digitizerUtility::SignalPoint> drift(
0194       const PSimHit& hit,
0195       const Phase2TrackerGeomDetUnit* pixdet,
0196       const GlobalVector& bfield,
0197       const std::vector<digitizerUtility::EnergyDepositUnit>& ionization_points) const;
0198   virtual void induce_signal(std::vector<PSimHit>::const_iterator inputBegin,
0199                              const PSimHit& hit,
0200                              const size_t hitIndex,
0201                              const size_t firstHitIndex,
0202                              const uint32_t tofBin,
0203                              const Phase2TrackerGeomDetUnit* pixdet,
0204                              const std::vector<digitizerUtility::SignalPoint>& collection_points);
0205   virtual std::vector<float> fluctuateEloss(
0206       int particleId, float momentum, float eloss, float length, int NumberOfSegments) const;
0207   virtual void add_noise(const Phase2TrackerGeomDetUnit* pixdet);
0208   virtual void add_cross_talk(const Phase2TrackerGeomDetUnit* pixdet);
0209   virtual void add_noisy_cells(const Phase2TrackerGeomDetUnit* pixdet, float thePixelThreshold);
0210   virtual void pixel_inefficiency(const SubdetEfficiencies& eff,
0211                                   const Phase2TrackerGeomDetUnit* pixdet,
0212                                   const TrackerTopology* tTopo);
0213 
0214   virtual void pixel_inefficiency_db(uint32_t detID);
0215 
0216   // access to the gain calibration payloads in the db. Only gets initialized if check_dead_pixels_ is set to true.
0217   const std::unique_ptr<SiPixelGainCalibrationOfflineSimService> theSiPixelGainCalibrationService_;
0218 
0219   LocalVector driftDirection(const Phase2TrackerGeomDetUnit* pixdet,
0220                              const GlobalVector& bfield,
0221                              const DetId& detId) const;
0222 
0223   // remove dead modules using the list in the configuration file PixelDigi_cfi.py
0224   virtual void module_killing_conf(uint32_t detID);
0225   // remove dead modules uisng the list in the DB
0226   virtual void module_killing_DB(const Phase2TrackerGeomDetUnit* pixdet) = 0;
0227 
0228   const SubdetEfficiencies subdetEfficiencies_;
0229   float calcQ(float x);
0230 
0231   // For random numbers
0232   std::unique_ptr<CLHEP::RandGaussQ> gaussDistribution_;
0233 
0234   // Threshold gaussian smearing:
0235   std::unique_ptr<CLHEP::RandGaussQ> smearedThreshold_Endcap_;
0236   std::unique_ptr<CLHEP::RandGaussQ> smearedThreshold_Barrel_;
0237 
0238   //for engine passed into the constructor from Digitizer
0239   CLHEP::HepRandomEngine* rengine_;
0240 
0241   // convert signal in electrons to ADC counts
0242   int convertSignalToAdc(uint32_t detID, float signal_in_elec, float threshold);
0243 
0244   bool pixelFlag_;
0245 };
0246 #endif