CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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>
16 
17 // forward declarations
18 
19 
20 // For the random numbers
21 namespace CLHEP {
22  class HepRandomEngine;
23 }
24 
25 namespace edm {
26  class EventSetup;
27  class ParameterSet;
28 }
29 
30 class DetId;
32 class PixelDigi;
33 class PixelDigiSimLink;
34 class PixelGeomDetUnit;
39 class SiPixelQuality;
40 class TrackerGeometry;
41 class TrackerTopology;
42 
44  public:
47 
48  // initialization that cannot be done in the constructor
49  void init(const edm::EventSetup& es);
50 
51  void initializeEvent() {
52  _signal.clear();
53  }
54 
55  //run the algorithm to digitize a single det
56  void accumulateSimHits(const std::vector<PSimHit>::const_iterator inputBegin,
57  const std::vector<PSimHit>::const_iterator inputEnd,
58  const size_t inputBeginGlobalIndex,
59  const unsigned int tofBin,
60  const PixelGeomDetUnit *pixdet,
61  const GlobalVector& bfield,
62  CLHEP::HepRandomEngine*);
63  void digitize(const PixelGeomDetUnit *pixdet,
64  std::vector<PixelDigi>& digis,
65  std::vector<PixelDigiSimLink>& simlinks,
66  const TrackerTopology *tTopo,
67  CLHEP::HepRandomEngine*);
69 
70  private:
71 
72  //Accessing Lorentz angle from DB:
74 
75  //Accessing Dead pixel modules from DB:
77 
78  //Accessing Map and Geom:
81 
82  // Define internal classes
83 
84  // definition class
85  //
86  class Amplitude {
87  public:
88  Amplitude() : _amp(0.0) {}
89  Amplitude( float amp, float frac) :
90  _amp(amp), _frac(1, frac), _hitInfo() {
91  //in case of digi from noisypixels
92  //the MC information are removed
93  if (_frac[0]<-0.5) {
94  _frac.pop_back();
95  }
96  }
97 
98  Amplitude( float amp, const PSimHit* hitp, size_t hitIndex, unsigned int tofBin, float frac) :
99  _amp(amp), _frac(1, frac), _hitInfo(new SimHitInfoForLinks(hitp, hitIndex, tofBin) ) {
100 
101  //in case of digi from noisypixels
102  //the MC information are removed
103  if (_frac[0]<-0.5) {
104  _frac.pop_back();
105  _hitInfo->trackIds_.pop_back();
106  }
107  }
108 
109  // can be used as a float by convers.
110  operator float() const { return _amp;}
111  float ampl() const {return _amp;}
112  std::vector<float> individualampl() const {return _frac;}
113  const std::vector<unsigned int>& trackIds() const {
114  return _hitInfo->trackIds_;
115  }
116  const std::shared_ptr<SimHitInfoForLinks>& hitInfo() const {return _hitInfo;}
117 
118  void operator+=( const Amplitude& other) {
119  _amp += other._amp;
120  //in case of contribution of noise to the digi
121  //the MC information are removed
122  if (other._frac[0]>-0.5){
123  if(other._hitInfo) {
124  std::vector<unsigned int>& otherTrackIds = other._hitInfo->trackIds_;
125  if(_hitInfo) {
126  std::vector<unsigned int>& trackIds = _hitInfo->trackIds_;
127  trackIds.insert(trackIds.end(), otherTrackIds.begin(), otherTrackIds.end());
128  } else {
129  _hitInfo.reset(new SimHitInfoForLinks(*other._hitInfo));
130  }
131  }
132  _frac.insert(_frac.end(), other._frac.begin(), other._frac.end());
133  }
134  }
135  const EncodedEventId& eventId() const {
136  return _hitInfo->eventId_;
137  }
138  const unsigned int hitIndex() const {
139  return _hitInfo->hitIndex_;
140  }
141  const unsigned int tofBin() const {
142  return _hitInfo->tofBin_;
143  }
144  void operator+=( const float& amp) {
145  _amp += amp;
146  }
147 
148  void set (const float amplitude) { // Used to reset the amplitude
149  _amp = amplitude;
150  }
151 /* void setind (const float indamplitude) { // Used to reset the amplitude */
152 /* _frac = idamplitude; */
153 /* } */
154  private:
155  float _amp;
156  std::vector<float> _frac;
157  std::shared_ptr<SimHitInfoForLinks> _hitInfo;
158  }; // end class Amplitude
159 
160  // Define a class to hold the calibration parameters per pixel
161  // Internal
163  public:
164  float p0;
165  float p1;
166  float p2;
167  float p3;
168  };
169  //
170  // Define a class for 3D ionization points and energy
171  //
176  public:
178  EnergyDepositUnit(float energy,float x, float y, float z):
179  _energy(energy),_position(x,y,z){}
181  _energy(energy),_position(position){}
182  float x() const{return _position.x();}
183  float y() const{return _position.y();}
184  float z() const{return _position.z();}
185  float energy() const { return _energy;}
186  private:
187  float _energy;
189  };
190 
191  //
192  // define class to store signals on the collection surface
193  //
198  class SignalPoint {
199  public:
200  SignalPoint() : _pos(0,0), _time(0), _amplitude(0),
201  _sigma_x(1.), _sigma_y(1.), _hitp(0) {}
202 
203  SignalPoint( float x, float y, float sigma_x, float sigma_y,
204  float t, float a=1.0) :
205  _pos(x,y), _time(t), _amplitude(a), _sigma_x(sigma_x),
206  _sigma_y(sigma_y), _hitp(0) {}
207 
208  SignalPoint( float x, float y, float sigma_x, float sigma_y,
209  float t, const PSimHit& hit, float a=1.0) :
210  _pos(x,y), _time(t), _amplitude(a), _sigma_x(sigma_x),
211  _sigma_y(sigma_y),_hitp(&hit) {}
212 
213  const LocalPoint& position() const { return _pos;}
214  float x() const { return _pos.x();}
215  float y() const { return _pos.y();}
216  float sigma_x() const { return _sigma_x;}
217  float sigma_y() const { return _sigma_y;}
218  float time() const { return _time;}
219  float amplitude() const { return _amplitude;}
220  const PSimHit& hit() { return *_hitp;}
221  SignalPoint& set_amplitude( float amp) { _amplitude = amp; return *this;}
222 
223 
224 
225  private:
227  float _time;
228  float _amplitude;
229  float _sigma_x; // gaussian sigma in the x direction (cm)
230  float _sigma_y; // " " y direction (cm) */
231  const PSimHit* _hitp;
232  };
233 
234  //
235  // PixelEfficiencies struct
236  //
242  float thePixelEfficiency[20]; // Single pixel effciency
243  float thePixelColEfficiency[20]; // Column effciency
244  float thePixelChipEfficiency[20]; // ROC efficiency
245  std::vector<double> theLadderEfficiency_BPix[20]; // Ladder efficiency
246  std::vector<double> theModuleEfficiency_BPix[20]; // Module efficiency
247  std::vector<double> thePUEfficiency_BPix[20]; // Instlumi dependent efficiency
248  unsigned int FPixIndex; // The Efficiency index for FPix Disks
249  };
250 
251  private:
252  // Needed by dynamic inefficiency
253  // 0-3 BPix, 4-5 FPix
254  double _pu_scale[20];
255 
256  // Internal typedefs
257  typedef std::map<int, Amplitude, std::less<int> > signal_map_type; // from Digi.Skel.
258  typedef signal_map_type::iterator signal_map_iterator; // from Digi.Skel.
259  typedef signal_map_type::const_iterator signal_map_const_iterator; // from Digi.Skel.
260  typedef std::map<unsigned int, std::vector<float>,std::less<unsigned int> > simlink_map;
261  typedef std::map<uint32_t, signal_map_type> signalMaps;
263  typedef std::vector<edm::ParameterSet> Parameters;
264 
265  // Contains the accumulated hit info.
267 
268  const bool makeDigiSimLinks_;
269 
270  const bool use_ineff_from_db_;
271  const bool use_module_killing_; // remove or not the dead pixel modules
272  const bool use_deadmodule_DB_; // if we want to get dead pixel modules from the DataBase.
273  const bool use_LorentzAngle_DB_; // if we want to get Lorentz angle from the DataBase.
274 
276 
277  // Variables
278  //external parameters
279  // go from Geant energy GeV to number of electrons
280  const float GeVperElectron; // 3.7E-09
281 
282  //-- drift
283  const float Sigma0; //=0.0007 // Charge diffusion in microns for 300 micron Si
284  const float Dist300; //=0.0300 // Define 300microns for normalization
285  const bool alpha2Order; // Switch on/off of E.B effect
286 
287 
288 
289  //-- induce_signal
290  const float ClusterWidth; // Gaussian charge cutoff width in sigma units
291  //-- Allow for upgrades
292  const int NumberOfBarrelLayers; // Default = 3
293  const int NumberOfEndcapDisks; // Default = 2
294 
295  //-- make_digis
296  const float theElectronPerADC; // Gain, number of electrons per adc count.
297  const int theAdcFullScale; // Saturation count, 255=8bit.
298  const int theAdcFullScaleStack; // Saturation count for stack layers, 1=1bit.
299  const int theFirstStackLayer; // The first BPix layer to use theAdcFullScaleStack.
300  const float theNoiseInElectrons; // Noise (RMS) in units of electrons.
301  const float theReadoutNoise; // Noise of the readount chain in elec,
302  //inludes DCOL-Amp,TBM-Amp, Alt, AOH,OptRec.
303 
304  const float theThresholdInE_FPix; // Pixel threshold in electrons FPix.
305  const float theThresholdInE_BPix; // Pixel threshold in electrons BPix.
306  const float theThresholdInE_BPix_L1; // In case the BPix layer1 gets a different threshold
307 
311 
312  const double electronsPerVCAL; // for electrons - VCAL conversion
313  const double electronsPerVCAL_Offset; // in misscalibrate()
314 
315  const float theTofLowerCut; // Cut on the particle TOF
316  const float theTofUpperCut; // Cut on the particle TOF
317  const float tanLorentzAnglePerTesla_FPix; //FPix Lorentz angle tangent per Tesla
318  const float tanLorentzAnglePerTesla_BPix; //BPix Lorentz angle tangent per Tesla
319 
320  const float FPix_p0;
321  const float FPix_p1;
322  const float FPix_p2;
323  const float FPix_p3;
324  const float BPix_p0;
325  const float BPix_p1;
326  const float BPix_p2;
327  const float BPix_p3;
328 
329 
330  //-- add_noise
331  const bool addNoise;
333  const bool addNoisyPixels;
334  const bool fluctuateCharge;
335  //-- pixel efficiency
336  const bool AddPixelInefficiency; // bool to read in inefficiencies
337 
339 
340  //-- calibration smearing
341  const bool doMissCalibrate; // Switch on the calibration smearing
342  const float theGainSmearing; // The sigma of the gain fluctuation (around 1)
343  const float theOffsetSmearing; // The sigma of the offset fluct. (around 0)
344 
345  // pseudoRadDamage
346  const double pseudoRadDamage; // Decrease the amount off freed charge that reaches the collector
347  const double pseudoRadDamageRadius; // Only apply pseudoRadDamage to pixels with radius<=pseudoRadDamageRadius
348  // The PDTable
349  //HepPDTable *particleTable;
350  //ParticleDataTable *particleTable;
351 
352  //-- charge fluctuation
353  const double tMax; // The delta production cut, should be as in OSCAR = 30keV
354  // cmsim = 100keV
355 
356  // The eloss fluctuation class from G4. Is the right place?
357  const std::unique_ptr<SiG4UniversalFluctuation> fluctuate; // make a pointer
358  const std::unique_ptr<GaussianTailNoiseGenerator> theNoiser;
359 
360  // To store calibration constants
361  const std::map<int,CalParameters,std::less<int> > calmap;
362 
363 
364  //-- additional member functions
365  // Private methods
366  std::map<int,CalParameters,std::less<int> > initCal() const;
367  void primary_ionization( const PSimHit& hit, std::vector<EnergyDepositUnit>& ionization_points, CLHEP::HepRandomEngine*) const;
368  void drift(const PSimHit& hit,
369  const PixelGeomDetUnit *pixdet,
370  const GlobalVector& bfield,
371  const std::vector<EnergyDepositUnit>& ionization_points,
372  std::vector<SignalPoint>& collection_points) const;
373  void induce_signal(const PSimHit& hit,
374  const size_t hitIndex,
375  const unsigned int tofBin,
376  const PixelGeomDetUnit *pixdet,
377  const std::vector<SignalPoint>& collection_points);
378  void fluctuateEloss(int particleId, float momentum, float eloss,
379  float length, int NumberOfSegments,
380  float elossVector[],
381  CLHEP::HepRandomEngine*) const;
382  void add_noise(const PixelGeomDetUnit *pixdet,
383  float thePixelThreshold,
384  CLHEP::HepRandomEngine*);
385  void make_digis(float thePixelThresholdInE,
386  uint32_t detID,
387  std::vector<PixelDigi>& digis,
388  std::vector<PixelDigiSimLink>& simlinks,
389  const TrackerTopology *tTopo) const;
390  void pixel_inefficiency(const PixelEfficiencies& eff,
391  const PixelGeomDetUnit* pixdet,
392  const TrackerTopology *tTopo,
393  CLHEP::HepRandomEngine*);
394 
395  void pixel_inefficiency_db(uint32_t detID);
396 
397  // access to the gain calibration payloads in the db. Only gets initialized if check_dead_pixels_ is set to true.
398  const std::unique_ptr<SiPixelGainCalibrationOfflineSimService> theSiPixelGainCalibrationService_;
399  float missCalibrate(uint32_t detID, int col, int row, float amp) const;
401  const GlobalVector& bfield,
402  const DetId& detId) const;
403 
404  void module_killing_conf(uint32_t detID); // remove dead modules using the list in the configuration file PixelDigi_cfi.py
405  void module_killing_DB(uint32_t detID); // remove dead modules uisng the list in the DB
406 
408 
409  double calcQ(float x) const {
410  // need erf(x/sqrt2)
411  //float x2=0.5*x*x;
412  //float a=0.147;
413  //double erf=sqrt(1.0f-exp( -1.0f*x2*( (4/M_PI)+a*x2)/(1.0+a*x2)));
414  //if (x<0.) erf*=-1.0;
415  //return 0.5*(1.0-erf);
416 
417  auto xx=std::min(0.5f*x*x,12.5f);
418  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));
419  }
420 
421 
422 };
423 
424 #endif
void init(const edm::EventSetup &es)
Amplitude(float amp, const PSimHit *hitp, size_t hitIndex, unsigned int tofBin, float frac)
std::vector< float > individualampl() const
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, CLHEP::HepRandomEngine *)
void pixel_inefficiency_db(uint32_t detID)
const EncodedEventId & eventId() const
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)
std::map< int, CalParameters, std::less< int > > initCal() const
std::map< unsigned int, std::vector< float >, std::less< unsigned int > > simlink_map
const std::unique_ptr< SiPixelGainCalibrationOfflineSimService > theSiPixelGainCalibrationService_
LocalVector DriftDirection(const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const DetId &detId) const
SiPixelDigitizerAlgorithm(const edm::ParameterSet &conf)
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)
float missCalibrate(uint32_t detID, int col, int row, float amp) const
T y() const
Definition: PV3DBase.h:63
edm::ESHandle< TrackerGeometry > geom_
const std::shared_ptr< SimHitInfoForLinks > & hitInfo() const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
void induce_signal(const PSimHit &hit, const size_t hitIndex, const unsigned int tofBin, const PixelGeomDetUnit *pixdet, const std::vector< SignalPoint > &collection_points)
const std::map< int, CalParameters, std::less< int > > calmap
void drift(const PSimHit &hit, const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const std::vector< EnergyDepositUnit > &ionization_points, std::vector< SignalPoint > &collection_points) const
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
double f[11][100]
std::shared_ptr< SimHitInfoForLinks > _hitInfo
signal_map_type::iterator signal_map_iterator
EnergyDepositUnit(float energy, float x, float y, float z)
edm::ESHandle< SiPixelLorentzAngle > SiPixelLorentzAngle_
tuple conf
Definition: dbtoconf.py:185
void fluctuateEloss(int particleId, float momentum, float eloss, float length, int NumberOfSegments, float elossVector[], CLHEP::HepRandomEngine *) const
const std::unique_ptr< GaussianTailNoiseGenerator > theNoiser
const std::vector< unsigned int > & trackIds() const
Definition: DetId.h:18
std::map< int, Amplitude, std::less< int > > signal_map_type
void make_digis(float thePixelThresholdInE, uint32_t detID, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo) const
const PixelEfficiencies pixelEfficiencies_
edm::ESHandle< SiPixelQuality > SiPixelBadModule_
void primary_ionization(const PSimHit &hit, std::vector< EnergyDepositUnit > &ionization_points, CLHEP::HepRandomEngine *) const
void calculateInstlumiFactor(PileupMixingContent *puInfo)
GloballyPositioned< double > Frame
std::vector< edm::ParameterSet > Parameters
double a
Definition: hdecay.h:121
Definition: DDAxes.h:10
int col
Definition: cuy.py:1008
T x() const
Definition: PV3DBase.h:62
std::map< uint32_t, signal_map_type > signalMaps
void add_noise(const PixelGeomDetUnit *pixdet, float thePixelThreshold, CLHEP::HepRandomEngine *)
void pixel_inefficiency(const PixelEfficiencies &eff, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)