CMS 3D CMS Logo

SiPixelDigitizerAlgorithm.h
Go to the documentation of this file.
1 #ifndef SimTracker_SiPixelDigitizer_SiPixelDigitizerAlgorithm_h
2 #define SimTracker_SiPixelDigitizer_SiPixelDigitizerAlgorithm_h
3 
4 #include <map>
5 #include <memory>
6 #include <vector>
7 #include <iostream>
30 #include "boost/multi_array.hpp"
31 
32 typedef boost::multi_array<float, 2> array_2d;
33 
34 // forward declarations
35 
36 // For the random numbers
37 namespace CLHEP {
38  class HepRandomEngine;
39 }
40 
41 class DetId;
43 class PixelDigi;
44 class PixelDigiSimLink;
45 class PixelGeomDetUnit;
50 class SiPixelQuality;
52 class TrackerGeometry;
53 class TrackerTopology;
57 
59 public:
62 
63  // initialization that cannot be done in the constructor
64  void init(const edm::EventSetup& es);
65 
66  void initializeEvent() { _signal.clear(); }
67 
68  //run the algorithm to digitize a single det
69  void accumulateSimHits(const std::vector<PSimHit>::const_iterator inputBegin,
70  const std::vector<PSimHit>::const_iterator inputEnd,
71  const size_t inputBeginGlobalIndex,
72  const unsigned int tofBin,
73  const PixelGeomDetUnit* pixdet,
74  const GlobalVector& bfield,
75  const TrackerTopology* tTopo,
76  CLHEP::HepRandomEngine*);
77  void digitize(const PixelGeomDetUnit* pixdet,
78  std::vector<PixelDigi>& digis,
79  std::vector<PixelDigiSimLink>& simlinks,
80  std::vector<PixelDigiAddTempInfo>& newClass_Digi_extra,
81  const TrackerTopology* tTopo,
82  CLHEP::HepRandomEngine*);
84  void fillSimHitMaps(std::vector<PSimHit> simHits, const unsigned int tofBin);
85  void resetSimHitMaps();
86  void init_DynIneffDB(const edm::EventSetup&);
87  std::unique_ptr<PixelFEDChannelCollection> chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine*);
88 
89  void lateSignalReweight(const PixelGeomDetUnit* pixdet,
90  std::vector<PixelDigi>& digis,
91  std::vector<PixelSimHitExtraInfo>& newClass_Sim_extra,
92  const TrackerTopology* tTopo,
93  CLHEP::HepRandomEngine* engine);
94 
95  // for premixing
96  void calculateInstlumiFactor(const std::vector<PileupSummaryInfo>& ps,
97  int bunchSpacing); // TODO: try to remove the duplication of logic...
98  void setSimAccumulator(const std::map<uint32_t, std::map<int, int> >& signalMap);
99  std::unique_ptr<PixelFEDChannelCollection> chooseScenario(const std::vector<PileupSummaryInfo>& ps,
100  CLHEP::HepRandomEngine* engine);
101 
102  bool killBadFEDChannels() const;
103  typedef std::unordered_map<std::string, PixelFEDChannelCollection> PixelFEDChannelCollectionMap;
105 
106 private:
107  //Accessing Lorentz angle from DB:
110 
111  //Accessing Dead pixel modules from DB:
114 
115  //Accessing Map and Geom:
118  const SiPixelFedCablingMap* map_ = nullptr;
119  const TrackerGeometry* geom_ = nullptr;
120 
121  // Get Dynamic Inefficiency scale factors from DB
124 
125  // For BadFEDChannel simulation
130  // Define internal classes
131 
132  // definition class
133  //
134 
135  // Define a class to hold the calibration parameters per pixel
136  // Internal
138  public:
139  float p0;
140  float p1;
141  float p2;
142  float p3;
143  };
144  //
145  // Define a class for 3D ionization points and energy
146  //
151  public:
152  EnergyDepositUnit() : _energy(0), _position(0, 0, 0) {}
153  EnergyDepositUnit(float energy, float x, float y, float z) : _energy(energy), _position(x, y, z) {}
155  float x() const { return _position.x(); }
156  float y() const { return _position.y(); }
157  float z() const { return _position.z(); }
158  float energy() const { return _energy; }
159 
160  private:
161  float _energy;
163  };
164 
165  //
166  // define class to store signals on the collection surface
167  //
172  class SignalPoint {
173  public:
174  SignalPoint() : _pos(0, 0), _time(0), _amplitude(0), _sigma_x(1.), _sigma_y(1.), _hitp(nullptr) {}
175 
176  SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, float a = 1.0)
177  : _pos(x, y), _time(t), _amplitude(a), _sigma_x(sigma_x), _sigma_y(sigma_y), _hitp(nullptr) {}
178 
179  SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, const PSimHit& hit, float a = 1.0)
181 
182  const LocalPoint& position() const { return _pos; }
183  float x() const { return _pos.x(); }
184  float y() const { return _pos.y(); }
185  float sigma_x() const { return _sigma_x; }
186  float sigma_y() const { return _sigma_y; }
187  float time() const { return _time; }
188  float amplitude() const { return _amplitude; }
189  const PSimHit& hit() { return *_hitp; }
191  _amplitude = amp;
192  return *this;
193  }
194 
195  private:
197  float _time;
198  float _amplitude;
199  float _sigma_x; // gaussian sigma in the x direction (cm)
200  float _sigma_y; // " " y direction (cm) */
201  const PSimHit* _hitp;
202  };
203 
204  //
205  // PixelEfficiencies struct
206  //
214  int NumberOfEndcapDisks);
215  bool FromConfig; // If true read from Config, otherwise use Database
216 
218  std::vector<double> pu_scale; // in config: 0-3 BPix, 4-5 FPix (inner, outer)
219  std::vector<std::vector<double> > thePUEfficiency; // Instlumi dependent efficiency
220 
221  // Read factors from Configuration
222  double thePixelEfficiency[20]; // Single pixel effciency
223  double thePixelColEfficiency[20]; // Column effciency
224  double thePixelChipEfficiency[20]; // ROC efficiency
225  std::vector<double> theLadderEfficiency_BPix[20]; // Ladder efficiency
226  std::vector<double> theModuleEfficiency_BPix[20]; // Module efficiency
227  double theInnerEfficiency_FPix[20]; // Fpix inner module efficiency
228  double theOuterEfficiency_FPix[20]; // Fpix outer module efficiency
229  unsigned int FPixIndex; // The Efficiency index for FPix Disks
230 
231  // Read factors from DB and fill containers
232  std::map<uint32_t, double> PixelGeomFactors;
233  std::map<uint32_t, std::vector<double> > PixelGeomFactorsROCStdPixels;
234  std::map<uint32_t, std::vector<double> > PixelGeomFactorsROCBigPixels;
235  std::map<uint32_t, double> ColGeomFactors;
236  std::map<uint32_t, double> ChipGeomFactors;
237  std::map<uint32_t, size_t> iPU;
238 
239  // constants for ROC level simulation for Phase1
241  static const int rocIdMaskBits = 0x1F;
243  bool matches(const DetId&, const DetId&, const std::vector<uint32_t>&);
244  std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_;
245  };
246 
247  //
248  // PixelAging struct
249  //
253  struct PixelAging {
255  float thePixelPseudoRadDamage[20]; // PseudoRadiation Damage Values for aging studies
256  unsigned int FPixIndex; // The Efficiency index for FPix Disks
257  };
258 
259 private:
260  // Internal typedefs
261  typedef std::map<int, digitizerUtility::Amplitude, std::less<int> > signal_map_type; // from Digi.Skel.
262  typedef signal_map_type::iterator signal_map_iterator; // from Digi.Skel.
263  typedef signal_map_type::const_iterator signal_map_const_iterator; // from Digi.Skel.
264  typedef std::map<uint32_t, signal_map_type> signalMaps;
266  typedef std::vector<edm::ParameterSet> Parameters;
267  typedef boost::multi_array<float, 2> array_2d;
268 
269  typedef std::pair<unsigned int, unsigned int> subDetTofBin;
270  typedef std::map<unsigned int, std::vector<PSimHit> > simhit_map;
272  typedef std::map<subDetTofBin, unsigned int> simhit_collectionMap;
274 
275  // Contains the accumulated hit info.
277 
278  const bool makeDigiSimLinks_;
280 
281  const bool use_ineff_from_db_;
282  const bool use_module_killing_; // remove or not the dead pixel modules
283  const bool use_deadmodule_DB_; // if we want to get dead pixel modules from the DataBase.
284  const bool use_LorentzAngle_DB_; // if we want to get Lorentz angle from the DataBase.
285 
287 
288  std::unique_ptr<SiPixelChargeReweightingAlgorithm> TheNewSiPixelChargeReweightingAlgorithmClass;
289 
290 private:
291  // Variables
292  //external parameters
293  // go from Geant energy GeV to number of electrons
294  const float GeVperElectron; // 3.7E-09
295 
296  //-- drift
297  const float Sigma0; //=0.0007 // Charge diffusion in microns for 300 micron Si
298  const float Dist300; //=0.0300 // Define 300microns for normalization
299  const bool alpha2Order; // Switch on/off of E.B effect
300 
301  //-- induce_signal
302  const float ClusterWidth; // Gaussian charge cutoff width in sigma units
303  //-- Allow for upgrades
304  const int NumberOfBarrelLayers; // Default = 3
305  const int NumberOfEndcapDisks; // Default = 2
306 
307  //-- make_digis
308  const float theElectronPerADC; // Gain, number of electrons per adc count.
309  const int theAdcFullScale; // Saturation count, 255=8bit.
310  const int theAdcFullScLateCR; // Saturation count, 255=8bit.
311  const float theNoiseInElectrons; // Noise (RMS) in units of electrons.
312  const float theReadoutNoise; // Noise of the readount chain in elec,
313  //inludes DCOL-Amp,TBM-Amp, Alt, AOH,OptRec.
314 
315  const float theThresholdInE_FPix; // Pixel threshold in electrons FPix.
316  const float theThresholdInE_BPix; // Pixel threshold in electrons BPix.
317  const float theThresholdInE_BPix_L1; // In case the BPix layer1 gets a different threshold
318  const float theThresholdInE_BPix_L2; // In case the BPix layer2 gets a different threshold
319 
324 
325  const float electronsPerVCAL; // for electrons - VCAL conversion
326  const float electronsPerVCAL_Offset; // in misscalibrate()
327  const float electronsPerVCAL_L1; // same for Layer 1
328  const float electronsPerVCAL_L1_Offset; // same for Layer 1
329 
330  const float theTofLowerCut; // Cut on the particle TOF
331  const float theTofUpperCut; // Cut on the particle TOF
332  const float tanLorentzAnglePerTesla_FPix; //FPix Lorentz angle tangent per Tesla
333  const float tanLorentzAnglePerTesla_BPix; //BPix Lorentz angle tangent per Tesla
334 
335  const float FPix_p0;
336  const float FPix_p1;
337  const float FPix_p2;
338  const float FPix_p3;
339  const float BPix_p0;
340  const float BPix_p1;
341  const float BPix_p2;
342  const float BPix_p3;
343 
344  //-- add_noise
345  const bool addNoise;
347  const bool addNoisyPixels;
348  const bool fluctuateCharge;
349 
350  //-- pixel efficiency
351  const bool AddPixelInefficiency; // bool to read in inefficiencies
352  const bool KillBadFEDChannels;
354 
355  //-- calibration smearing
356  const bool doMissCalibrate; // Switch on the calibration smearing
357  const bool doMissCalInLateCR; // Switch on the calibration smearing
358  const float theGainSmearing; // The sigma of the gain fluctuation (around 1)
359  const float theOffsetSmearing; // The sigma of the offset fluct. (around 0)
360 
361  // pixel aging
362  const bool AddPixelAging;
363  const bool UseReweighting;
364 
365  // The PDTable
366  //HepPDTable *particleTable;
367  //ParticleDataTable *particleTable;
368 
369  //-- charge fluctuation
370  const double tMax; // The delta production cut, should be as in OSCAR = 30keV
371  // cmsim = 100keV
372 
373  // The eloss fluctuation class from G4. Is the right place?
374  const std::unique_ptr<SiG4UniversalFluctuation> fluctuate; // make a pointer
375  const std::unique_ptr<GaussianTailNoiseGenerator> theNoiser;
376 
377  // To store calibration constants
378  const std::map<int, CalParameters, std::less<int> > calmap;
379 
380  //-- additional member functions
381  // Private methods
382  std::map<int, CalParameters, std::less<int> > initCal() const;
383  void primary_ionization(const PSimHit& hit,
384  std::vector<EnergyDepositUnit>& ionization_points,
385  CLHEP::HepRandomEngine*) const;
386  void drift(const PSimHit& hit,
387  const PixelGeomDetUnit* pixdet,
388  const GlobalVector& bfield,
389  const TrackerTopology* tTopo,
390  const std::vector<EnergyDepositUnit>& ionization_points,
391  std::vector<SignalPoint>& collection_points) const;
392  void induce_signal(std::vector<PSimHit>::const_iterator inputBegin,
393  std::vector<PSimHit>::const_iterator inputEnd,
394  const PSimHit& hit,
395  const size_t hitIndex,
396  const size_t FirstHitIndex,
397  const unsigned int tofBin,
398  const PixelGeomDetUnit* pixdet,
399  const std::vector<SignalPoint>& collection_points);
400  void fluctuateEloss(int particleId,
401  float momentum,
402  float eloss,
403  float length,
404  int NumberOfSegments,
405  float elossVector[],
406  CLHEP::HepRandomEngine*) const;
407  void add_noise(const PixelGeomDetUnit* pixdet, float thePixelThreshold, CLHEP::HepRandomEngine*);
408  void make_digis(float thePixelThresholdInE,
409  uint32_t detID,
410  const PixelGeomDetUnit* pixdet,
411  std::vector<PixelDigi>& digis,
412  std::vector<PixelDigiSimLink>& simlinks,
413  std::vector<PixelDigiAddTempInfo>& newClass_Digi_extra,
414  const TrackerTopology* tTopo) const;
415  void pixel_inefficiency(const PixelEfficiencies& eff,
416  const PixelGeomDetUnit* pixdet,
417  const TrackerTopology* tTopo,
418  CLHEP::HepRandomEngine*);
419 
420  void pixel_inefficiency_db(uint32_t detID);
421 
422  float pixel_aging(const PixelAging& aging, const PixelGeomDetUnit* pixdet, const TrackerTopology* tTopo) const;
423 
424  // access to the gain calibration payloads in the db. Only gets initialized if check_dead_pixels_ is set to true.
425  const std::unique_ptr<SiPixelGainCalibrationOfflineSimService> theSiPixelGainCalibrationService_;
426  float missCalibrate(
427  uint32_t detID, const TrackerTopology* tTopo, const PixelGeomDetUnit* pixdet, int col, int row, float amp) const;
428  LocalVector DriftDirection(const PixelGeomDetUnit* pixdet, const GlobalVector& bfield, const DetId& detId) const;
429 
430  void module_killing_conf(
431  uint32_t detID); // remove dead modules using the list in the configuration file PixelDigi_cfi.py
432  void module_killing_DB(uint32_t detID); // remove dead modules uisng the list in the DB
433 
436 
437  double calcQ(float x) const {
438  // need erf(x/sqrt2)
439  //float x2=0.5*x*x;
440  //float a=0.147;
441  //double erf=sqrt(1.0f-exp( -1.0f*x2*( (4/M_PI)+a*x2)/(1.0+a*x2)));
442  //if (x<0.) erf*=-1.0;
443  //return 0.5*(1.0-erf);
444 
445  auto xx = std::min(0.5f * x * x, 12.5f);
446  return 0.5 * (1.0 - std::copysign(std::sqrt(1.f - unsafe_expf<4>(-xx * (1.f + 0.2733f / (1.f + 0.147f * xx)))), x));
447  }
448 };
449 
450 #endif
void init(const edm::EventSetup &es)
void fillSimHitMaps(std::vector< PSimHit > simHits, const unsigned int tofBin)
std::map< int, digitizerUtility::Amplitude, std::less< int > > signal_map_type
void pixel_inefficiency_db(uint32_t detID)
signal_map_type::const_iterator signal_map_const_iterator
SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, const PSimHit &hit, float a=1.0)
const std::unique_ptr< SiPixelGainCalibrationOfflineSimService > theSiPixelGainCalibrationService_
EnergyDepositUnit(float energy, Local3DPoint position)
T z() const
Definition: PV3DBase.h:61
const std::unique_ptr< SiG4UniversalFluctuation > fluctuate
PixelEfficiencies(const edm::ParameterSet &conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, float a=1.0)
edm::ESGetToken< SiPixelQualityProbabilities, SiPixelStatusScenarioProbabilityRcd > scenarioProbabilityToken_
std::unique_ptr< PixelFEDChannelCollection > PixelFEDChannelCollection_
std::vector< std::vector< double > > thePUEfficiency
void make_digis(float thePixelThresholdInE, uint32_t detID, const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, std::vector< PixelDigiAddTempInfo > &newClass_Digi_extra, const TrackerTopology *tTopo) const
float pixel_aging(const PixelAging &aging, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo) const
void drift(const PSimHit &hit, const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const TrackerTopology *tTopo, const std::vector< EnergyDepositUnit > &ionization_points, std::vector< SignalPoint > &collection_points) const
std::map< unsigned int, std::vector< PSimHit > > simhit_map
const SiPixelDynamicInefficiency * SiPixelDynamicInefficiency_
std::unique_ptr< SiPixelChargeReweightingAlgorithm > TheNewSiPixelChargeReweightingAlgorithmClass
std::map< subDetTofBin, unsigned int > simhit_collectionMap
void induce_signal(std::vector< PSimHit >::const_iterator inputBegin, std::vector< PSimHit >::const_iterator inputEnd, const PSimHit &hit, const size_t hitIndex, const size_t FirstHitIndex, const unsigned int tofBin, const PixelGeomDetUnit *pixdet, const std::vector< SignalPoint > &collection_points)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
LocalVector DriftDirection(const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const DetId &detId) const
edm::ESGetToken< SiPixelQuality, SiPixelQualityRcd > SiPixelBadModuleToken_
SiPixelDigitizerAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
const PixelFEDChannelCollectionMap * quality_map
std::pair< unsigned int, unsigned int > subDetTofBin
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, std::vector< PixelDigiAddTempInfo > &newClass_Digi_extra, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
boost::multi_array< float, 2 > array_2d
std::map< uint32_t, std::vector< double > > PixelGeomFactorsROCBigPixels
void primary_ionization(const PSimHit &hit, std::vector< EnergyDepositUnit > &ionization_points, CLHEP::HepRandomEngine *) const
T sqrt(T t)
Definition: SSEVec.h:19
const SiPixelLorentzAngle * SiPixelLorentzAngle_
double f[11][100]
float missCalibrate(uint32_t detID, const TrackerTopology *tTopo, const PixelGeomDetUnit *pixdet, int col, int row, float amp) const
void init_from_db(const TrackerGeometry *, const SiPixelDynamicInefficiency *)
edm::ESGetToken< SiPixelLorentzAngle, SiPixelLorentzAngleSimRcd > SiPixelLorentzAngleToken_
signal_map_type::iterator signal_map_iterator
void init_DynIneffDB(const edm::EventSetup &)
std::unique_ptr< PixelFEDChannelCollection > chooseScenario(PileupMixingContent *puInfo, CLHEP::HepRandomEngine *)
EnergyDepositUnit(float energy, float x, float y, float z)
boost::multi_array< float, 2 > array_2d
void setSimAccumulator(const std::map< uint32_t, std::map< int, int > > &signalMap)
edm::ESGetToken< PixelFEDChannelCollectionMap, SiPixelFEDChannelContainerESProducerRcd > PixelFEDChannelCollectionMapToken_
const std::map< int, CalParameters, std::less< int > > calmap
const std::unique_ptr< GaussianTailNoiseGenerator > theNoiser
Definition: DetId.h:17
const SiPixelQuality * SiPixelBadModule_
const SiPixelFedCablingMap * map_
std::map< uint32_t, std::vector< double > > PixelGeomFactorsROCStdPixels
void calculateInstlumiFactor(PileupMixingContent *puInfo)
std::unordered_map< std::string, PixelFEDChannelCollection > PixelFEDChannelCollectionMap
void accumulateSimHits(const std::vector< PSimHit >::const_iterator inputBegin, const std::vector< PSimHit >::const_iterator inputEnd, const size_t inputBeginGlobalIndex, const unsigned int tofBin, const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
GloballyPositioned< double > Frame
const SiPixelQualityProbabilities * scenarioProbability_
void fluctuateEloss(int particleId, float momentum, float eloss, float length, int NumberOfSegments, float elossVector[], CLHEP::HepRandomEngine *) const
bool matches(const DetId &, const DetId &, const std::vector< uint32_t > &)
void lateSignalReweight(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelSimHitExtraInfo > &newClass_Sim_extra, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *engine)
std::vector< edm::ParameterSet > Parameters
double a
Definition: hdecay.h:121
static int position[264][3]
Definition: ReadPGInfo.cc:289
col
Definition: cuy.py:1009
edm::ESGetToken< SiPixelDynamicInefficiency, SiPixelDynamicInefficiencyRcd > SiPixelDynamicInefficiencyToken_
std::map< int, CalParameters, std::less< int > > initCal() const
PixelAging(const edm::ParameterSet &conf, bool AddPixelAging, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > mapToken_
std::map< uint32_t, signal_map_type > signalMaps
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Definition: aging.py:1
void add_noise(const PixelGeomDetUnit *pixdet, float thePixelThreshold, CLHEP::HepRandomEngine *)
void pixel_inefficiency(const PixelEfficiencies &eff, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)