CMS 3D CMS Logo

SiPixelDigitizerAlgorithm.h
Go to the documentation of this file.
1 #ifndef SiPixelDigitizerAlgorithm_h
2 #define SiPixelDigitizerAlgorithm_h
3 
4 #include <map>
5 #include <memory>
6 #include <vector>
7 #include <iostream>
22 #include "boost/multi_array.hpp"
23 
24 typedef boost::multi_array<float, 2> array_2d;
25 
26 // forward declarations
27 
28 
29 // For the random numbers
30 namespace CLHEP {
31  class HepRandomEngine;
32 }
33 
34 namespace edm {
35  class EventSetup;
36  class ParameterSet;
37 }
38 
39 class DetId;
41 class PixelDigi;
42 class PixelDigiSimLink;
43 class PixelGeomDetUnit;
48 class SiPixelQuality;
50 class TrackerGeometry;
51 class TrackerTopology;
54 
56  public:
59 
60  // initialization that cannot be done in the constructor
61  void init(const edm::EventSetup& es);
62 
63  void initializeEvent() {
64  _signal.clear();
65  }
66 
67  //run the algorithm to digitize a single det
68  void accumulateSimHits(const std::vector<PSimHit>::const_iterator inputBegin,
69  const std::vector<PSimHit>::const_iterator inputEnd,
70  const size_t inputBeginGlobalIndex,
71  const unsigned int tofBin,
72  const PixelGeomDetUnit *pixdet,
73  const GlobalVector& bfield,
74  const TrackerTopology *tTopo,
75  CLHEP::HepRandomEngine*);
76  void digitize(const PixelGeomDetUnit *pixdet,
77  std::vector<PixelDigi>& digis,
78  std::vector<PixelDigiSimLink>& simlinks,
79  const TrackerTopology *tTopo,
80  CLHEP::HepRandomEngine*);
81  void calculateInstlumiFactor(PileupMixingContent* puInfo);
82  void init_DynIneffDB(const edm::EventSetup&, const unsigned int&);
83  std::unique_ptr<PixelFEDChannelCollection> chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine*);
84 
85  // for premixing
86  void calculateInstlumiFactor(const std::vector<PileupSummaryInfo> &ps, int bunchSpacing); // TODO: try to remove the duplication of logic...
87  void setSimAccumulator(const std::map<uint32_t, std::map<int, int> >& signalMap);
88 
89  std::unique_ptr<PixelFEDChannelCollection> chooseScenario(const std::vector<PileupSummaryInfo>& ps,
90  CLHEP::HepRandomEngine* engine);
91 
92  bool killBadFEDChannels() const;
93  typedef std::unordered_map<std::string,PixelFEDChannelCollection> PixelFEDChannelCollectionMap;
94  const PixelFEDChannelCollectionMap* quality_map;
95 
96  private:
97 
98  //Accessing Lorentz angle from DB:
100 
101  //Accessing Dead pixel modules from DB:
104 
105  //Accessing Map and Geom:
108 
109  // Get Dynamic Inefficiency scale factors from DB
111 
112  // For BadFEDChannel simulation
115  // Define internal classes
116 
117  // definition class
118  //
119  class Amplitude {
120  public:
121  Amplitude() : _amp(0.0) {}
122  Amplitude( float amp, float frac) :
123  _amp(amp), _frac(1, frac) {
124  //in case of digi from noisypixels
125  //the MC information are removed
126  if (_frac[0]<-0.5) {
127  _frac.pop_back();
128  }
129  }
130 
131  Amplitude( float amp, const PSimHit* hitp, size_t hitIndex, unsigned int tofBin, float frac) :
132  _amp(amp), _frac(1, frac) {
133 
134  //in case of digi from noisypixels
135  //the MC information are removed
136  if (_frac[0]<-0.5) {
137  _frac.pop_back();
138  }
139  else {
140  _hitInfos.emplace_back(hitp, hitIndex, tofBin);
141  }
142  }
143 
144  // can be used as a float by convers.
145  operator float() const { return _amp;}
146  float ampl() const {return _amp;}
147  const std::vector<float>& individualampl() const {return _frac;}
148  const std::vector<SimHitInfoForLinks>& hitInfos() const { return _hitInfos; }
149 
150  void operator+=( const Amplitude& other) {
151  _amp += other._amp;
152  //in case of contribution of noise to the digi
153  //the MC information are removed
154  if (other._frac[0]>-0.5){
155  if(!other._hitInfos.empty()) {
156  _hitInfos.insert(_hitInfos.end(), other._hitInfos.begin(), other._hitInfos.end());
157  }
158  _frac.insert(_frac.end(), other._frac.begin(), other._frac.end());
159  }
160  }
161  void operator+=( const float& amp) {
162  _amp += amp;
163  }
164 
165  void set (const float amplitude) { // Used to reset the amplitude
166  _amp = amplitude;
167  }
168 /* void setind (const float indamplitude) { // Used to reset the amplitude */
169 /* _frac = idamplitude; */
170 /* } */
171  private:
172  float _amp;
173  std::vector<float> _frac;
174  std::vector<SimHitInfoForLinks> _hitInfos;
175  }; // end class Amplitude
176 
177  // Define a class to hold the calibration parameters per pixel
178  // Internal
180  public:
181  float p0;
182  float p1;
183  float p2;
184  float p3;
185  };
186  //
187  // Define a class for 3D ionization points and energy
188  //
193  public:
194  EnergyDepositUnit(): _energy(0),_position(0,0,0){}
195  EnergyDepositUnit(float energy,float x, float y, float z):
196  _energy(energy),_position(x,y,z){}
198  _energy(energy),_position(position){}
199  float x() const{return _position.x();}
200  float y() const{return _position.y();}
201  float z() const{return _position.z();}
202  float energy() const { return _energy;}
203  private:
204  float _energy;
206  };
207 
208  //
209  // define class to store signals on the collection surface
210  //
215  class SignalPoint {
216  public:
217  SignalPoint() : _pos(0,0), _time(0), _amplitude(0),
218  _sigma_x(1.), _sigma_y(1.), _hitp(nullptr) {}
219 
220  SignalPoint( float x, float y, float sigma_x, float sigma_y,
221  float t, float a=1.0) :
222  _pos(x,y), _time(t), _amplitude(a), _sigma_x(sigma_x),
223  _sigma_y(sigma_y), _hitp(nullptr) {}
224 
225  SignalPoint( float x, float y, float sigma_x, float sigma_y,
226  float t, const PSimHit& hit, float a=1.0) :
227  _pos(x,y), _time(t), _amplitude(a), _sigma_x(sigma_x),
228  _sigma_y(sigma_y),_hitp(&hit) {}
229 
230  const LocalPoint& position() const { return _pos;}
231  float x() const { return _pos.x();}
232  float y() const { return _pos.y();}
233  float sigma_x() const { return _sigma_x;}
234  float sigma_y() const { return _sigma_y;}
235  float time() const { return _time;}
236  float amplitude() const { return _amplitude;}
237  const PSimHit& hit() { return *_hitp;}
238  SignalPoint& set_amplitude( float amp) { _amplitude = amp; return *this;}
239 
240 
241 
242  private:
244  float _time;
245  float _amplitude;
246  float _sigma_x; // gaussian sigma in the x direction (cm)
247  float _sigma_y; // " " y direction (cm) */
248  const PSimHit* _hitp;
249  };
250 
251  //
252  // PixelEfficiencies struct
253  //
258  PixelEfficiencies(const edm::ParameterSet& conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks);
259  bool FromConfig; // If true read from Config, otherwise use Database
260 
262  std::vector<double> pu_scale; // in config: 0-3 BPix, 4-5 FPix (inner, outer)
263  std::vector<std::vector<double> > thePUEfficiency; // Instlumi dependent efficiency
264 
265  // Read factors from Configuration
266  double thePixelEfficiency[20]; // Single pixel effciency
267  double thePixelColEfficiency[20]; // Column effciency
268  double thePixelChipEfficiency[20]; // ROC efficiency
269  std::vector<double> theLadderEfficiency_BPix[20]; // Ladder efficiency
270  std::vector<double> theModuleEfficiency_BPix[20]; // Module efficiency
271  double theInnerEfficiency_FPix[20]; // Fpix inner module efficiency
272  double theOuterEfficiency_FPix[20]; // Fpix outer module efficiency
273  unsigned int FPixIndex; // The Efficiency index for FPix Disks
274 
275  // Read factors from DB and fill containers
276  std::map<uint32_t, double> PixelGeomFactors;
277  std::map<uint32_t, std::vector<double> > PixelGeomFactorsROCStdPixels;
278  std::map<uint32_t, std::vector<double> > PixelGeomFactorsROCBigPixels;
279  std::map<uint32_t, double> ColGeomFactors;
280  std::map<uint32_t, double> ChipGeomFactors;
281  std::map<uint32_t, size_t > iPU;
282 
283  // constants for ROC level simulation for Phase1
284  enum shiftEnumerator {FPixRocIdShift = 3, BPixRocIdShift = 6};
285  static const int rocIdMaskBits = 0x1F;
287  bool matches(const DetId&, const DetId&, const std::vector<uint32_t >&);
288  std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_;
289  };
290 
291  //
292  // PixelAging struct
293  //
297  struct PixelAging {
298  PixelAging(const edm::ParameterSet& conf, bool AddPixelAging, int NumberOfBarrelLayers, int NumberOfEndcapDisks);
299  float thePixelPseudoRadDamage[20]; // PseudoRadiation Damage Values for aging studies
300  unsigned int FPixIndex; // The Efficiency index for FPix Disks
301  };
302 
303  private:
304  // Internal typedefs
305  typedef std::map<int, Amplitude, std::less<int> > signal_map_type; // from Digi.Skel.
306  typedef signal_map_type::iterator signal_map_iterator; // from Digi.Skel.
307  typedef signal_map_type::const_iterator signal_map_const_iterator; // from Digi.Skel.
308  typedef std::map<uint32_t, signal_map_type> signalMaps;
310  typedef std::vector<edm::ParameterSet> Parameters;
311  typedef boost::multi_array<float, 2> array_2d;
312 
313  // Contains the accumulated hit info.
314  signalMaps _signal;
315 
316  const bool makeDigiSimLinks_;
317 
318  const bool use_ineff_from_db_;
319  const bool use_module_killing_; // remove or not the dead pixel modules
320  const bool use_deadmodule_DB_; // if we want to get dead pixel modules from the DataBase.
321  const bool use_LorentzAngle_DB_; // if we want to get Lorentz angle from the DataBase.
322 
323  const Parameters DeadModules;
324 
325  // Variables and objects for the charge reweighting using 2D templates
327  std::vector<bool> xdouble;
328  std::vector<bool> ydouble;
329  std::vector<float> track;
330  int IDnum, IDden;
331 
332  std::vector<SiPixelTemplateStore2D> templateStores_;
333 
336 
337  private:
338 
339 
340  // Variables
341  //external parameters
342  // go from Geant energy GeV to number of electrons
343  const float GeVperElectron; // 3.7E-09
344 
345  //-- drift
346  const float Sigma0; //=0.0007 // Charge diffusion in microns for 300 micron Si
347  const float Dist300; //=0.0300 // Define 300microns for normalization
348  const bool alpha2Order; // Switch on/off of E.B effect
349 
350 
351 
352  //-- induce_signal
353  const float ClusterWidth; // Gaussian charge cutoff width in sigma units
354  //-- Allow for upgrades
355  const int NumberOfBarrelLayers; // Default = 3
356  const int NumberOfEndcapDisks; // Default = 2
357 
358  //-- make_digis
359  const float theElectronPerADC; // Gain, number of electrons per adc count.
360  const int theAdcFullScale; // Saturation count, 255=8bit.
361  const float theNoiseInElectrons; // Noise (RMS) in units of electrons.
362  const float theReadoutNoise; // Noise of the readount chain in elec,
363  //inludes DCOL-Amp,TBM-Amp, Alt, AOH,OptRec.
364 
365  const float theThresholdInE_FPix; // Pixel threshold in electrons FPix.
366  const float theThresholdInE_BPix; // Pixel threshold in electrons BPix.
367  const float theThresholdInE_BPix_L1; // In case the BPix layer1 gets a different threshold
368  const float theThresholdInE_BPix_L2; // In case the BPix layer2 gets a different threshold
369 
374 
375  const float electronsPerVCAL; // for electrons - VCAL conversion
376  const float electronsPerVCAL_Offset; // in misscalibrate()
377  const float electronsPerVCAL_L1; // same for Layer 1
378  const float electronsPerVCAL_L1_Offset;// same for Layer 1
379 
380  const float theTofLowerCut; // Cut on the particle TOF
381  const float theTofUpperCut; // Cut on the particle TOF
382  const float tanLorentzAnglePerTesla_FPix; //FPix Lorentz angle tangent per Tesla
383  const float tanLorentzAnglePerTesla_BPix; //BPix Lorentz angle tangent per Tesla
384 
385  const float FPix_p0;
386  const float FPix_p1;
387  const float FPix_p2;
388  const float FPix_p3;
389  const float BPix_p0;
390  const float BPix_p1;
391  const float BPix_p2;
392  const float BPix_p3;
393 
394 
395  //-- add_noise
396  const bool addNoise;
398  const bool addNoisyPixels;
399  const bool fluctuateCharge;
400 
401  //-- pixel efficiency
402  const bool AddPixelInefficiency; // bool to read in inefficiencies
403  const bool KillBadFEDChannels;
405 
406  //-- calibration smearing
407  const bool doMissCalibrate; // Switch on the calibration smearing
408  const float theGainSmearing; // The sigma of the gain fluctuation (around 1)
409  const float theOffsetSmearing; // The sigma of the offset fluct. (around 0)
410 
411  // pixel aging
412  const bool AddPixelAging;
413  const bool UseReweighting;
414  const bool PrintClusters;
415  const bool PrintTemplates;
416 
417  // The PDTable
418  //HepPDTable *particleTable;
419  //ParticleDataTable *particleTable;
420 
421  //-- charge fluctuation
422  const double tMax; // The delta production cut, should be as in OSCAR = 30keV
423  // cmsim = 100keV
424 
425  // The eloss fluctuation class from G4. Is the right place?
426  const std::unique_ptr<SiG4UniversalFluctuation> fluctuate; // make a pointer
427  const std::unique_ptr<GaussianTailNoiseGenerator> theNoiser;
428 
429  // To store calibration constants
430  const std::map<int,CalParameters,std::less<int> > calmap;
431 
432 
433  //-- additional member functions
434  // Private methods
435  std::map<int,CalParameters,std::less<int> > initCal() const;
436  void primary_ionization( const PSimHit& hit, std::vector<EnergyDepositUnit>& ionization_points, CLHEP::HepRandomEngine*) const;
437  void drift(const PSimHit& hit,
438  const PixelGeomDetUnit *pixdet,
439  const GlobalVector& bfield,
440  const TrackerTopology *tTopo,
441  const std::vector<EnergyDepositUnit>& ionization_points,
442  std::vector<SignalPoint>& collection_points) const;
443  void induce_signal(std::vector<PSimHit>::const_iterator inputBegin,
444  std::vector<PSimHit>::const_iterator inputEnd,
445  const PSimHit& hit,
446  const size_t hitIndex,
447  const unsigned int tofBin,
448  const PixelGeomDetUnit *pixdet,
449  const std::vector<SignalPoint>& collection_points);
450  void fluctuateEloss(int particleId, float momentum, float eloss,
451  float length, int NumberOfSegments,
452  float elossVector[],
453  CLHEP::HepRandomEngine*) const;
454  void add_noise(const PixelGeomDetUnit *pixdet,
455  float thePixelThreshold,
456  CLHEP::HepRandomEngine*);
457  void make_digis(float thePixelThresholdInE,
458  uint32_t detID,
459  const PixelGeomDetUnit* pixdet,
460  std::vector<PixelDigi>& digis,
461  std::vector<PixelDigiSimLink>& simlinks,
462  const TrackerTopology *tTopo) const;
463  void pixel_inefficiency(const PixelEfficiencies& eff,
464  const PixelGeomDetUnit* pixdet,
465  const TrackerTopology *tTopo,
466  CLHEP::HepRandomEngine*);
467 
468  void pixel_inefficiency_db(uint32_t detID);
469 
470  float pixel_aging(const PixelAging& aging,
471  const PixelGeomDetUnit* pixdet,
472  const TrackerTopology *tTopo) const;
473 
474  // access to the gain calibration payloads in the db. Only gets initialized if check_dead_pixels_ is set to true.
475  const std::unique_ptr<SiPixelGainCalibrationOfflineSimService> theSiPixelGainCalibrationService_;
476  float missCalibrate(uint32_t detID, const TrackerTopology *tTopo, const PixelGeomDetUnit* pixdet, int col, int row, float amp) const;
477  LocalVector DriftDirection(const PixelGeomDetUnit* pixdet,
478  const GlobalVector& bfield,
479  const DetId& detId) const;
480 
481  void module_killing_conf(uint32_t detID); // remove dead modules using the list in the configuration file PixelDigi_cfi.py
482  void module_killing_DB(uint32_t detID); // remove dead modules uisng the list in the DB
483 
484  // methods for charge reweighting in irradiated sensors
485  int PixelTempRewgt2D( int id_gen, int id_rewgt,
486  array_2d& cluster);
487  bool hitSignalReweight(const PSimHit& hit,
488  std::map< int, float, std::less<int> >& hit_signal,
489  const size_t hitIndex,
490  const unsigned int tofBin,
491  const PixelTopology* topol,
492  uint32_t detID,
493  signal_map_type& theSignal,
494  unsigned short int processType);
495  void printCluster(array_2d& cluster);
496  void printCluster(float arr[BXM2][BYM2]);
497  void printCluster(float arr[TXSIZE][TYSIZE]);
498 
499 
502 
503  double calcQ(float x) const {
504  // need erf(x/sqrt2)
505  //float x2=0.5*x*x;
506  //float a=0.147;
507  //double erf=sqrt(1.0f-exp( -1.0f*x2*( (4/M_PI)+a*x2)/(1.0+a*x2)));
508  //if (x<0.) erf*=-1.0;
509  //return 0.5*(1.0-erf);
510 
511  auto xx=std::min(0.5f*x*x,12.5f);
512  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));
513  }
514 
515 
516 };
517 
518 #endif
const SiPixel2DTemplateDBObject * dbobject_den
Amplitude(float amp, const PSimHit *hitp, size_t hitIndex, unsigned int tofBin, float frac)
signal_map_type::const_iterator signal_map_const_iterator
edm::ESHandle< SiPixelFedCablingMap > map_
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_
const std::vector< float > & individualampl() const
EnergyDepositUnit(float energy, Local3DPoint position)
#define TXSIZE
const std::unique_ptr< SiG4UniversalFluctuation > fluctuate
edm::ESHandle< SiPixelQualityProbabilities > scenarioProbabilityHandle
SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, float a=1.0)
#define nullptr
int init
Definition: HydjetWrapper.h:67
LocalVector drift(const StripGeomDetUnit *, const MagneticField &, const SiStripLorentzAngle &)
Definition: ShallowTools.cc:37
std::unique_ptr< PixelFEDChannelCollection > PixelFEDChannelCollection_
std::vector< std::vector< double > > thePUEfficiency
edm::ESHandle< TrackerGeometry > geom_
edm::ESHandle< PixelFEDChannelCollectionMap > PixelFEDChannelCollectionMapHandle
const SiPixel2DTemplateDBObject * dbobject_num
#define BXM2
const PixelFEDChannelCollectionMap * quality_map
const std::map< int, CalParameters, std::less< int > > calmap
boost::multi_array< float, 2 > array_2d
std::map< uint32_t, std::vector< double > > PixelGeomFactorsROCBigPixels
T sqrt(T t)
Definition: SSEVec.h:18
std::unordered_map< std::string, PixelFEDChannelCollection > PixelFEDChannelCollectionMap
#define BYM2
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
signal_map_type::iterator signal_map_iterator
EnergyDepositUnit(float energy, float x, float y, float z)
edm::ESHandle< SiPixelLorentzAngle > SiPixelLorentzAngle_
boost::multi_array< float, 2 > array_2d
const std::unique_ptr< GaussianTailNoiseGenerator > theNoiser
Definition: DetId.h:18
std::map< int, Amplitude, std::less< int > > signal_map_type
#define TYSIZE
edm::ESHandle< SiPixelQuality > SiPixelBadModule_
std::map< uint32_t, std::vector< double > > PixelGeomFactorsROCStdPixels
GloballyPositioned< double > Frame
std::vector< SiPixelTemplateStore2D > templateStores_
edm::ESHandle< SiPixelDynamicInefficiency > SiPixelDynamicInefficiency_
std::vector< edm::ParameterSet > Parameters
const std::vector< SimHitInfoForLinks > & hitInfos() const
HLT enums.
std::vector< SimHitInfoForLinks > _hitInfos
double a
Definition: hdecay.h:121
static int position[264][3]
Definition: ReadPGInfo.cc:509
col
Definition: cuy.py:1010
std::map< uint32_t, signal_map_type > signalMaps
Definition: aging.py:1