CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
28 #include "boost/multi_array.hpp"
29 
30 typedef boost::multi_array<float, 2> array_2d;
31 
32 // forward declarations
33 
34 // For the random numbers
35 namespace CLHEP {
36  class HepRandomEngine;
37 }
38 
39 class DetId;
41 class PixelDigi;
42 class PixelDigiSimLink;
43 class PixelGeomDetUnit;
48 class SiPixelQuality;
50 class TrackerGeometry;
51 class TrackerTopology;
55 
57 public:
60 
61  // initialization that cannot be done in the constructor
62  void init(const edm::EventSetup& es);
63 
64  void initializeEvent() { _signal.clear(); }
65 
66  //run the algorithm to digitize a single det
67  void accumulateSimHits(const std::vector<PSimHit>::const_iterator inputBegin,
68  const std::vector<PSimHit>::const_iterator inputEnd,
69  const size_t inputBeginGlobalIndex,
70  const unsigned int tofBin,
71  const PixelGeomDetUnit* pixdet,
72  const GlobalVector& bfield,
73  const TrackerTopology* tTopo,
74  CLHEP::HepRandomEngine*);
75  void digitize(const PixelGeomDetUnit* pixdet,
76  std::vector<PixelDigi>& digis,
77  std::vector<PixelDigiSimLink>& simlinks,
78  const TrackerTopology* tTopo,
79  CLHEP::HepRandomEngine*);
81  void init_DynIneffDB(const edm::EventSetup&);
82  std::unique_ptr<PixelFEDChannelCollection> chooseScenario(PileupMixingContent* puInfo, CLHEP::HepRandomEngine*);
83 
84  // for premixing
85  void calculateInstlumiFactor(const std::vector<PileupSummaryInfo>& ps,
86  int bunchSpacing); // TODO: try to remove the duplication of logic...
87  void setSimAccumulator(const std::map<uint32_t, std::map<int, int> >& signalMap);
88  std::unique_ptr<PixelFEDChannelCollection> chooseScenario(const std::vector<PileupSummaryInfo>& ps,
89  CLHEP::HepRandomEngine* engine);
90 
91  bool killBadFEDChannels() const;
92  typedef std::unordered_map<std::string, PixelFEDChannelCollection> PixelFEDChannelCollectionMap;
94 
95  class Amplitude {
96  public:
97  Amplitude() : _amp(0.0) {}
98  Amplitude(float amp, float frac) : _amp(amp), _frac(1, frac) {
99  //in case of digi from noisypixels
100  //the MC information are removed
101  if (_frac[0] < -0.5) {
102  _frac.pop_back();
103  }
104  }
105 
106  Amplitude(float amp, const PSimHit* hitp, size_t hitIndex, unsigned int tofBin, float frac)
107  : _amp(amp), _frac(1, frac) {
108  //in case of digi from noisypixels
109  //the MC information are removed
110  if (_frac[0] < -0.5) {
111  _frac.pop_back();
112  } else {
113  _hitInfos.emplace_back(hitp, hitIndex, tofBin);
114  }
115  }
116 
117  // can be used as a float by convers.
118  operator float() const { return _amp; }
119  float ampl() const { return _amp; }
120  const std::vector<float>& individualampl() const { return _frac; }
121  const std::vector<SimHitInfoForLinks>& hitInfos() const { return _hitInfos; }
122 
123  void operator+=(const Amplitude& other) {
124  _amp += other._amp;
125  //in case of contribution of noise to the digi
126  //the MC information are removed
127  if (other._frac[0] > -0.5) {
128  if (!other._hitInfos.empty()) {
129  _hitInfos.insert(_hitInfos.end(), other._hitInfos.begin(), other._hitInfos.end());
130  }
131  _frac.insert(_frac.end(), other._frac.begin(), other._frac.end());
132  }
133  }
134  void operator+=(const float& amp) { _amp += amp; }
135 
136  void set(const float amplitude) { // Used to reset the amplitude
137  _amp = amplitude;
138  }
139  /* void setind (const float indamplitude) { // Used to reset the amplitude */
140  /* _frac = idamplitude; */
141  /* } */
142  private:
143  float _amp;
144  std::vector<float> _frac;
145  std::vector<SimHitInfoForLinks> _hitInfos;
146  }; // end class Amplitude
147 
148 private:
149  //Accessing Lorentz angle from DB:
152 
153  //Accessing Dead pixel modules from DB:
156 
157  //Accessing Map and Geom:
160  const SiPixelFedCablingMap* map_ = nullptr;
161  const TrackerGeometry* geom_ = nullptr;
162 
163  // Get Dynamic Inefficiency scale factors from DB
166 
167  // For BadFEDChannel simulation
172  // Define internal classes
173 
174  // definition class
175  //
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) : _energy(energy), _position(x, y, z) {}
197  float x() const { return _position.x(); }
198  float y() const { return _position.y(); }
199  float z() const { return _position.z(); }
200  float energy() const { return _energy; }
201 
202  private:
203  float _energy;
205  };
206 
207  //
208  // define class to store signals on the collection surface
209  //
214  class SignalPoint {
215  public:
216  SignalPoint() : _pos(0, 0), _time(0), _amplitude(0), _sigma_x(1.), _sigma_y(1.), _hitp(nullptr) {}
217 
218  SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, float a = 1.0)
219  : _pos(x, y), _time(t), _amplitude(a), _sigma_x(sigma_x), _sigma_y(sigma_y), _hitp(nullptr) {}
220 
221  SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, const PSimHit& hit, float a = 1.0)
222  : _pos(x, y), _time(t), _amplitude(a), _sigma_x(sigma_x), _sigma_y(sigma_y), _hitp(&hit) {}
223 
224  const LocalPoint& position() const { return _pos; }
225  float x() const { return _pos.x(); }
226  float y() const { return _pos.y(); }
227  float sigma_x() const { return _sigma_x; }
228  float sigma_y() const { return _sigma_y; }
229  float time() const { return _time; }
230  float amplitude() const { return _amplitude; }
231  const PSimHit& hit() { return *_hitp; }
233  _amplitude = amp;
234  return *this;
235  }
236 
237  private:
239  float _time;
240  float _amplitude;
241  float _sigma_x; // gaussian sigma in the x direction (cm)
242  float _sigma_y; // " " y direction (cm) */
243  const PSimHit* _hitp;
244  };
245 
246  //
247  // PixelEfficiencies struct
248  //
256  int NumberOfEndcapDisks);
257  bool FromConfig; // If true read from Config, otherwise use Database
258 
260  std::vector<double> pu_scale; // in config: 0-3 BPix, 4-5 FPix (inner, outer)
261  std::vector<std::vector<double> > thePUEfficiency; // Instlumi dependent efficiency
262 
263  // Read factors from Configuration
264  double thePixelEfficiency[20]; // Single pixel effciency
265  double thePixelColEfficiency[20]; // Column effciency
266  double thePixelChipEfficiency[20]; // ROC efficiency
267  std::vector<double> theLadderEfficiency_BPix[20]; // Ladder efficiency
268  std::vector<double> theModuleEfficiency_BPix[20]; // Module efficiency
269  double theInnerEfficiency_FPix[20]; // Fpix inner module efficiency
270  double theOuterEfficiency_FPix[20]; // Fpix outer module efficiency
271  unsigned int FPixIndex; // The Efficiency index for FPix Disks
272 
273  // Read factors from DB and fill containers
274  std::map<uint32_t, double> PixelGeomFactors;
275  std::map<uint32_t, std::vector<double> > PixelGeomFactorsROCStdPixels;
276  std::map<uint32_t, std::vector<double> > PixelGeomFactorsROCBigPixels;
277  std::map<uint32_t, double> ColGeomFactors;
278  std::map<uint32_t, double> ChipGeomFactors;
279  std::map<uint32_t, size_t> iPU;
280 
281  // constants for ROC level simulation for Phase1
283  static const int rocIdMaskBits = 0x1F;
285  bool matches(const DetId&, const DetId&, const std::vector<uint32_t>&);
286  std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_;
287  };
288 
289  //
290  // PixelAging struct
291  //
295  struct PixelAging {
297  float thePixelPseudoRadDamage[20]; // PseudoRadiation Damage Values for aging studies
298  unsigned int FPixIndex; // The Efficiency index for FPix Disks
299  };
300 
301 private:
302  // Internal typedefs
303  typedef std::map<int, Amplitude, std::less<int> > signal_map_type; // from Digi.Skel.
304  typedef signal_map_type::iterator signal_map_iterator; // from Digi.Skel.
305  typedef signal_map_type::const_iterator signal_map_const_iterator; // from Digi.Skel.
306  typedef std::map<uint32_t, signal_map_type> signalMaps;
308  typedef std::vector<edm::ParameterSet> Parameters;
309  typedef boost::multi_array<float, 2> array_2d;
310 
311  // Contains the accumulated hit info.
313 
314  const bool makeDigiSimLinks_;
315 
316  const bool use_ineff_from_db_;
317  const bool use_module_killing_; // remove or not the dead pixel modules
318  const bool use_deadmodule_DB_; // if we want to get dead pixel modules from the DataBase.
319  const bool use_LorentzAngle_DB_; // if we want to get Lorentz angle from the DataBase.
320 
322 
323  std::unique_ptr<SiPixelChargeReweightingAlgorithm> TheNewSiPixelChargeReweightingAlgorithmClass;
324 
325 private:
326  // Variables
327  //external parameters
328  // go from Geant energy GeV to number of electrons
329  const float GeVperElectron; // 3.7E-09
330 
331  //-- drift
332  const float Sigma0; //=0.0007 // Charge diffusion in microns for 300 micron Si
333  const float Dist300; //=0.0300 // Define 300microns for normalization
334  const bool alpha2Order; // Switch on/off of E.B effect
335 
336  //-- induce_signal
337  const float ClusterWidth; // Gaussian charge cutoff width in sigma units
338  //-- Allow for upgrades
339  const int NumberOfBarrelLayers; // Default = 3
340  const int NumberOfEndcapDisks; // Default = 2
341 
342  //-- make_digis
343  const float theElectronPerADC; // Gain, number of electrons per adc count.
344  const int theAdcFullScale; // Saturation count, 255=8bit.
345  const float theNoiseInElectrons; // Noise (RMS) in units of electrons.
346  const float theReadoutNoise; // Noise of the readount chain in elec,
347  //inludes DCOL-Amp,TBM-Amp, Alt, AOH,OptRec.
348 
349  const float theThresholdInE_FPix; // Pixel threshold in electrons FPix.
350  const float theThresholdInE_BPix; // Pixel threshold in electrons BPix.
351  const float theThresholdInE_BPix_L1; // In case the BPix layer1 gets a different threshold
352  const float theThresholdInE_BPix_L2; // In case the BPix layer2 gets a different threshold
353 
358 
359  const float electronsPerVCAL; // for electrons - VCAL conversion
360  const float electronsPerVCAL_Offset; // in misscalibrate()
361  const float electronsPerVCAL_L1; // same for Layer 1
362  const float electronsPerVCAL_L1_Offset; // same for Layer 1
363 
364  const float theTofLowerCut; // Cut on the particle TOF
365  const float theTofUpperCut; // Cut on the particle TOF
366  const float tanLorentzAnglePerTesla_FPix; //FPix Lorentz angle tangent per Tesla
367  const float tanLorentzAnglePerTesla_BPix; //BPix Lorentz angle tangent per Tesla
368 
369  const float FPix_p0;
370  const float FPix_p1;
371  const float FPix_p2;
372  const float FPix_p3;
373  const float BPix_p0;
374  const float BPix_p1;
375  const float BPix_p2;
376  const float BPix_p3;
377 
378  //-- add_noise
379  const bool addNoise;
381  const bool addNoisyPixels;
382  const bool fluctuateCharge;
383 
384  //-- pixel efficiency
385  const bool AddPixelInefficiency; // bool to read in inefficiencies
386  const bool KillBadFEDChannels;
388 
389  //-- calibration smearing
390  const bool doMissCalibrate; // Switch on the calibration smearing
391  const float theGainSmearing; // The sigma of the gain fluctuation (around 1)
392  const float theOffsetSmearing; // The sigma of the offset fluct. (around 0)
393 
394  // pixel aging
395  const bool AddPixelAging;
396  const bool UseReweighting;
397 
398  // The PDTable
399  //HepPDTable *particleTable;
400  //ParticleDataTable *particleTable;
401 
402  //-- charge fluctuation
403  const double tMax; // The delta production cut, should be as in OSCAR = 30keV
404  // cmsim = 100keV
405 
406  // The eloss fluctuation class from G4. Is the right place?
407  const std::unique_ptr<SiG4UniversalFluctuation> fluctuate; // make a pointer
408  const std::unique_ptr<GaussianTailNoiseGenerator> theNoiser;
409 
410  // To store calibration constants
411  const std::map<int, CalParameters, std::less<int> > calmap;
412 
413  //-- additional member functions
414  // Private methods
415  std::map<int, CalParameters, std::less<int> > initCal() const;
416  void primary_ionization(const PSimHit& hit,
417  std::vector<EnergyDepositUnit>& ionization_points,
418  CLHEP::HepRandomEngine*) const;
419  void drift(const PSimHit& hit,
420  const PixelGeomDetUnit* pixdet,
421  const GlobalVector& bfield,
422  const TrackerTopology* tTopo,
423  const std::vector<EnergyDepositUnit>& ionization_points,
424  std::vector<SignalPoint>& collection_points) const;
425  void induce_signal(std::vector<PSimHit>::const_iterator inputBegin,
426  std::vector<PSimHit>::const_iterator inputEnd,
427  const PSimHit& hit,
428  const size_t hitIndex,
429  const size_t FirstHitIndex,
430  const unsigned int tofBin,
431  const PixelGeomDetUnit* pixdet,
432  const std::vector<SignalPoint>& collection_points);
433  void fluctuateEloss(int particleId,
434  float momentum,
435  float eloss,
436  float length,
437  int NumberOfSegments,
438  float elossVector[],
439  CLHEP::HepRandomEngine*) const;
440  void add_noise(const PixelGeomDetUnit* pixdet, float thePixelThreshold, CLHEP::HepRandomEngine*);
441  void make_digis(float thePixelThresholdInE,
442  uint32_t detID,
443  const PixelGeomDetUnit* pixdet,
444  std::vector<PixelDigi>& digis,
445  std::vector<PixelDigiSimLink>& simlinks,
446  const TrackerTopology* tTopo) const;
447  void pixel_inefficiency(const PixelEfficiencies& eff,
448  const PixelGeomDetUnit* pixdet,
449  const TrackerTopology* tTopo,
450  CLHEP::HepRandomEngine*);
451 
452  void pixel_inefficiency_db(uint32_t detID);
453 
454  float pixel_aging(const PixelAging& aging, const PixelGeomDetUnit* pixdet, const TrackerTopology* tTopo) const;
455 
456  // access to the gain calibration payloads in the db. Only gets initialized if check_dead_pixels_ is set to true.
457  const std::unique_ptr<SiPixelGainCalibrationOfflineSimService> theSiPixelGainCalibrationService_;
458  float missCalibrate(
459  uint32_t detID, const TrackerTopology* tTopo, const PixelGeomDetUnit* pixdet, int col, int row, float amp) const;
460  LocalVector DriftDirection(const PixelGeomDetUnit* pixdet, const GlobalVector& bfield, const DetId& detId) const;
461 
462  void module_killing_conf(
463  uint32_t detID); // remove dead modules using the list in the configuration file PixelDigi_cfi.py
464  void module_killing_DB(uint32_t detID); // remove dead modules uisng the list in the DB
465 
468 
469  double calcQ(float x) const {
470  // need erf(x/sqrt2)
471  //float x2=0.5*x*x;
472  //float a=0.147;
473  //double erf=sqrt(1.0f-exp( -1.0f*x2*( (4/M_PI)+a*x2)/(1.0+a*x2)));
474  //if (x<0.) erf*=-1.0;
475  //return 0.5*(1.0-erf);
476 
477  auto xx = std::min(0.5f * x * x, 12.5f);
478  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));
479  }
480 };
481 
482 #endif
void init(const edm::EventSetup &es)
Amplitude(float amp, const PSimHit *hitp, size_t hitIndex, unsigned int tofBin, float frac)
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)
std::map< int, CalParameters, std::less< int > > initCal() const
const std::unique_ptr< SiPixelGainCalibrationOfflineSimService > theSiPixelGainCalibrationService_
LocalVector DriftDirection(const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const DetId &detId) const
const std::vector< float > & individualampl() const
EnergyDepositUnit(float energy, Local3DPoint position)
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)
T y() const
Definition: PV3DBase.h:60
edm::ESGetToken< SiPixelQualityProbabilities, SiPixelStatusScenarioProbabilityRcd > scenarioProbabilityToken_
std::unique_ptr< PixelFEDChannelCollection > PixelFEDChannelCollection_
std::vector< std::vector< double > > thePUEfficiency
const SiPixelDynamicInefficiency * SiPixelDynamicInefficiency_
std::unique_ptr< SiPixelChargeReweightingAlgorithm > TheNewSiPixelChargeReweightingAlgorithmClass
void make_digis(float thePixelThresholdInE, uint32_t detID, const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo) const
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)
edm::ESGetToken< SiPixelQuality, SiPixelQualityRcd > SiPixelBadModuleToken_
SiPixelDigitizerAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
const PixelFEDChannelCollectionMap * quality_map
boost::multi_array< float, 2 > array_2d
float pixel_aging(const PixelAging &aging, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo) const
std::map< uint32_t, std::vector< double > > PixelGeomFactorsROCBigPixels
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
const SiPixelLorentzAngle * SiPixelLorentzAngle_
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
void fluctuateEloss(int particleId, float momentum, float eloss, float length, int NumberOfSegments, float elossVector[], CLHEP::HepRandomEngine *) const
const std::unique_ptr< GaussianTailNoiseGenerator > theNoiser
Definition: DetId.h:17
std::map< int, Amplitude, std::less< int > > signal_map_type
const SiPixelQuality * SiPixelBadModule_
const SiPixelFedCablingMap * map_
std::map< uint32_t, std::vector< double > > PixelGeomFactorsROCStdPixels
void primary_ionization(const PSimHit &hit, std::vector< EnergyDepositUnit > &ionization_points, CLHEP::HepRandomEngine *) const
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_
float missCalibrate(uint32_t detID, const TrackerTopology *tTopo, const PixelGeomDetUnit *pixdet, int col, int row, float amp) const
bool matches(const DetId &, const DetId &, const std::vector< uint32_t > &)
std::vector< edm::ParameterSet > Parameters
const std::vector< SimHitInfoForLinks > & hitInfos() const
std::vector< SimHitInfoForLinks > _hitInfos
double a
Definition: hdecay.h:119
static int position[264][3]
Definition: ReadPGInfo.cc:289
edm::ESGetToken< SiPixelDynamicInefficiency, SiPixelDynamicInefficiencyRcd > SiPixelDynamicInefficiencyToken_
PixelAging(const edm::ParameterSet &conf, bool AddPixelAging, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
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
int col
Definition: cuy.py:1009
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > mapToken_
T x() const
Definition: PV3DBase.h:59
std::map< uint32_t, signal_map_type > signalMaps
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
void add_noise(const PixelGeomDetUnit *pixdet, float thePixelThreshold, CLHEP::HepRandomEngine *)
void pixel_inefficiency(const PixelEfficiencies &eff, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)