Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-18 22:24:06

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/SiPhase2Digitizer/plugins/DigitizerUtility.h"
0017 #include "SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerDigitizerFwd.h"
0018 
0019 // Units and Constants
0020 #include "DataFormats/Math/interface/CMSUnits.h"
0021 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0022 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0023 
0024 // forward declarations
0025 // For the random numbers
0026 namespace CLHEP {
0027   class HepRandomEngine;
0028   class RandGaussQ;
0029   class RandFlat;
0030 }  // namespace CLHEP
0031 
0032 class DetId;
0033 class GaussianTailNoiseGenerator;
0034 class SiG4UniversalFluctuation;
0035 class SiPixelFedCablingMap;
0036 class SiPixelGainCalibrationOfflineSimService;
0037 class SiPixelLorentzAngle;
0038 class SiPixelQuality;
0039 class SiPhase2OuterTrackerLorentzAngle;
0040 class TrackerGeometry;
0041 class TrackerTopology;
0042 
0043 // REMEMBER CMS conventions:
0044 // -- Energy: GeV
0045 // -- momentum: GeV/c
0046 // -- mass: GeV/c^2
0047 // -- Distance, position: cm
0048 // -- Time: ns
0049 // -- Angles: radian
0050 // Some constants in convenient units
0051 constexpr double c_cm_ns = CLHEP::c_light * CLHEP::ns / CLHEP::cm;
0052 constexpr double c_inv = 1.0 / c_cm_ns;
0053 
0054 class Phase2TrackerDigitizerAlgorithm {
0055 public:
0056   Phase2TrackerDigitizerAlgorithm(const edm::ParameterSet& conf_common,
0057                                   const edm::ParameterSet& conf_specific,
0058                                   edm::ConsumesCollector iC);
0059   virtual ~Phase2TrackerDigitizerAlgorithm();
0060 
0061   // initialization that cannot be done in the constructor
0062   virtual void init(const edm::EventSetup& es) = 0;
0063   virtual void initializeEvent(CLHEP::HepRandomEngine& eng);
0064 
0065   // run the algorithm to digitize a single det
0066   virtual void accumulateSimHits(const std::vector<PSimHit>::const_iterator inputBegin,
0067                                  const std::vector<PSimHit>::const_iterator inputEnd,
0068                                  const size_t inputBeginGlobalIndex,
0069                                  const uint32_t tofBin,
0070                                  const Phase2TrackerGeomDetUnit* pixdet,
0071                                  const GlobalVector& bfield);
0072   virtual void digitize(const Phase2TrackerGeomDetUnit* pixdet,
0073                         std::map<int, DigitizerUtility::DigiSimInfo>& digi_map,
0074                         const TrackerTopology* tTopo);
0075   virtual bool select_hit(const PSimHit& hit, double tCorr, double& sigScale) const { return true; }
0076   virtual bool isAboveThreshold(const DigitizerUtility::SimHitInfo* hitInfo, float charge, float thr) const {
0077     return true;
0078   }
0079 
0080   // For premixing
0081   void loadAccumulator(uint32_t detId, const std::map<int, float>& accumulator);
0082 
0083 protected:
0084   // Accessing Inner Tracker Lorentz angle from DB:
0085   const SiPixelLorentzAngle* siPixelLorentzAngle_;
0086 
0087   // Accessing Outer Tracker Lorentz angle from DB:
0088   const SiPhase2OuterTrackerLorentzAngle* siPhase2OTLorentzAngle_;
0089 
0090   // Accessing Dead pixel modules from DB:
0091   const SiPixelQuality* siPixelBadModule_;
0092 
0093   // Accessing Map and Geom:
0094   const SiPixelFedCablingMap* fedCablingMap_;
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::Amplitude, 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   // The PDTable
0172   // HepPDTable *particleTable;
0173   // ParticleDataTable *particleTable;
0174 
0175   //-- charge fluctuation
0176   const double tMax_;  // The delta production cut, should be as in OSCAR = 30keV
0177 
0178   // Bad Pixels to be killed
0179   Parameters badPixels_;
0180 
0181   // The eloss fluctuation class from G4. Is the right place?
0182   const std::unique_ptr<SiG4UniversalFluctuation> fluctuate_;  // make a pointer
0183   const std::unique_ptr<GaussianTailNoiseGenerator> theNoiser_;
0184 
0185   //-- additional member functions
0186   // Private methods
0187   virtual std::vector<DigitizerUtility::EnergyDepositUnit> primary_ionization(const PSimHit& hit) const;
0188   virtual std::vector<DigitizerUtility::SignalPoint> drift(
0189       const PSimHit& hit,
0190       const Phase2TrackerGeomDetUnit* pixdet,
0191       const GlobalVector& bfield,
0192       const std::vector<DigitizerUtility::EnergyDepositUnit>& ionization_points) const;
0193   virtual void induce_signal(const PSimHit& hit,
0194                              const size_t hitIndex,
0195                              const uint32_t tofBin,
0196                              const Phase2TrackerGeomDetUnit* pixdet,
0197                              const std::vector<DigitizerUtility::SignalPoint>& collection_points);
0198   virtual std::vector<float> fluctuateEloss(
0199       int particleId, float momentum, float eloss, float length, int NumberOfSegments) const;
0200   virtual void add_noise(const Phase2TrackerGeomDetUnit* pixdet);
0201   virtual void add_cross_talk(const Phase2TrackerGeomDetUnit* pixdet);
0202   virtual void add_noisy_cells(const Phase2TrackerGeomDetUnit* pixdet, float thePixelThreshold);
0203   virtual void pixel_inefficiency(const SubdetEfficiencies& eff,
0204                                   const Phase2TrackerGeomDetUnit* pixdet,
0205                                   const TrackerTopology* tTopo);
0206 
0207   virtual void pixel_inefficiency_db(uint32_t detID);
0208 
0209   // access to the gain calibration payloads in the db. Only gets initialized if check_dead_pixels_ is set to true.
0210   const std::unique_ptr<SiPixelGainCalibrationOfflineSimService> theSiPixelGainCalibrationService_;
0211   LocalVector DriftDirection(const Phase2TrackerGeomDetUnit* pixdet,
0212                              const GlobalVector& bfield,
0213                              const DetId& detId) const;
0214 
0215   // remove dead modules using the list in the configuration file PixelDigi_cfi.py
0216   virtual void module_killing_conf(uint32_t detID);
0217   // remove dead modules uisng the list in the DB
0218   virtual void module_killing_DB(const Phase2TrackerGeomDetUnit* pixdet) = 0;
0219 
0220   const SubdetEfficiencies subdetEfficiencies_;
0221   float calcQ(float x);
0222 
0223   // For random numbers
0224   std::unique_ptr<CLHEP::RandGaussQ> gaussDistribution_;
0225 
0226   // Threshold gaussian smearing:
0227   std::unique_ptr<CLHEP::RandGaussQ> smearedThreshold_Endcap_;
0228   std::unique_ptr<CLHEP::RandGaussQ> smearedThreshold_Barrel_;
0229 
0230   //for engine passed into the constructor from Digitizer
0231   CLHEP::HepRandomEngine* rengine_;
0232 
0233   // convert signal in electrons to ADC counts
0234   int convertSignalToAdc(uint32_t detID, float signal_in_elec, float threshold);
0235 
0236   bool pixelFlag_;
0237 };
0238 #endif