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