test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelDigitizerAlgorithm.cc
Go to the documentation of this file.
1 //class SiPixelDigitizerAlgorithm SimTracker/SiPixelDigitizer/src/SiPixelDigitizerAlgoithm.cc
2 
3 // Original Author Danek Kotlinski
4 // Ported in CMSSW by Michele Pioppi-INFN perugia
5 // Added DB capabilities by F.Blekman, Cornell University
6 // Created: Mon Sep 26 11:08:32 CEST 2005
7 // Add tof, change AddNoise to tracked. 4/06
8 // Change drift direction. 6/06 d.k.
9 // Add the statuis (non-rate dependent) inefficiency.
10 // -1 - no ineffciency
11 // 0 - static inefficency only
12 // 1,2 - low-lumi rate dependent inefficency added
13 // 10 - high-lumi inefficiency added
14 // Adopt the correct drift sign convetion from Morris Swartz. d.k. 8/06
15 // Add more complex misscalinbration, change kev/e to 3.61, diff=3.7,d.k.9/06
16 // Add the readout channel electronic noise. d.k. 3/07
17 // Lower the pixel noise from 500 to 175elec.
18 // Change the input threshold from noise units to electrons.
19 // Lower the amount of static dead pixels from 0.01 to 0.001.
20 // Modify to the new random number services. d.k. 5/07
21 // Protect against sigma=0 (delta tracks on the surface). d.k.5/07
22 // Change the TOF cut to lower and upper limit. d.k. 7/07
23 //
24 // July 2008: Split Lorentz Angle configuration in BPix/FPix (V. Cuplov)
25 // tanLorentzAngleperTesla_FPix=0.0912 and tanLorentzAngleperTesla_BPix=0.106
26 // Sept. 2008: Disable Pixel modules which are declared dead in the configuration python file. (V. Cuplov)
27 // Oct. 2008: Accessing/Reading the Lorentz angle from the DataBase instead of the cfg file. (V. Cuplov)
28 // Accessing dead modules from the DB. Implementation done and tested on a test.db
29 // Do not use this option for now. The PixelQuality Objects are not in the official DB yet.
30 // Feb. 2009: Split Fpix and Bpix threshold and use official numbers (V. Cuplov)
31 // ThresholdInElectrons_FPix = 2870 and ThresholdInElectrons_BPix = 3700
32 // update the electron to VCAL conversion using: VCAL_electrons = VCAL * 65.5 - 414
33 // Feb. 2009: Threshold gaussian smearing (V. Cuplov)
34 // March, 2009: changed DB access to *SimRcd objects (to de-couple the DB objects from reco chain) (F. Blekman)
35 // May, 2009: Pixel charge VCAL smearing. (V. Cuplov)
36 // November, 2009: new parameterization of the pixel response. (V. Cuplov)
37 // December, 2009: Fix issue with different compilers.
38 // October, 2010: Improvement: Removing single dead ROC (V. Cuplov)
39 // November, 2010: Bug fix in removing TBMB/A half-modules (V. Cuplov)
40 // February, 2011: Time improvement in DriftDirection() (J. Bashir Butt)
41 // June, 2011: Bug Fix for pixels on ROC edges in module_killing_DB() (J. Bashir Butt)
42 #include <iostream>
43 
45 
51 
52 #include <gsl/gsl_sf_erf.h>
54 #include "CLHEP/Random/RandGaussQ.h"
55 #include "CLHEP/Random/RandFlat.h"
56 
57 //#include "PixelIndices.h"
61 
67 
68 // Accessing dead pixel modules from the DB:
70 
72 
87 
93 
94 // Geometry
99 
101 
102 using namespace edm;
103 using namespace sipixelobjects;
104 
105 #define TP_DEBUG // protect all LogDebug with ifdef. Takes too much CPU
106 
107 
109  if(use_ineff_from_db_){// load gain calibration service fromdb...
110  theSiPixelGainCalibrationService_->setESObjects( es );
111  }
112  if(use_deadmodule_DB_) {
113  es.get<SiPixelQualityRcd>().get(SiPixelBadModule_);
114  }
115  if(use_LorentzAngle_DB_) {
116  // Get Lorentz angle from DB record
117  es.get<SiPixelLorentzAngleSimRcd>().get(SiPixelLorentzAngle_);
118  }
119  //gets the map and geometry from the DB (to kill ROCs)
120  es.get<SiPixelFedCablingMapRcd>().get(map_);
121  es.get<TrackerDigiGeometryRecord>().get(geom_);
122 }
123 
124 //=========================================================================
125 
127 
128  _signal(),
129  makeDigiSimLinks_(conf.getUntrackedParameter<bool>("makeDigiSimLinks", true)),
130  use_ineff_from_db_(conf.getParameter<bool>("useDB")),
131  use_module_killing_(conf.getParameter<bool>("killModules")), // boolean to kill or not modules
132  use_deadmodule_DB_(conf.getParameter<bool>("DeadModules_DB")), // boolean to access dead modules from DB
133  use_LorentzAngle_DB_(conf.getParameter<bool>("LorentzAngle_DB")), // boolean to access Lorentz angle from DB
134 
135  DeadModules(use_deadmodule_DB_ ? Parameters() : conf.getParameter<Parameters>("DeadModules")), // get dead module from cfg file
136 
137  // Common pixel parameters
138  // These are parameters which are not likely to be changed
139  GeVperElectron(3.61E-09), // 1 electron(3.61eV, 1keV(277e, mod 9/06 d.k.
140  Sigma0(0.00037), // Charge diffusion constant 7->3.7
141  Dist300(0.0300), // normalized to 300micron Silicon
142  alpha2Order(conf.getParameter<bool>("Alpha2Order")), // switch on/off of E.B effect
143  ClusterWidth(3.), // Charge integration spread on the collection plane
144 
145  // get external parameters:
146  // To account for upgrade geometries do not assume the number
147  // of layers or disks.
148  NumberOfBarrelLayers(conf.exists("NumPixelBarrel")?conf.getParameter<int>("NumPixelBarrel"):3),
149  NumberOfEndcapDisks(conf.exists("NumPixelEndcap")?conf.getParameter<int>("NumPixelEndcap"):2),
150 
151  // ADC calibration 1adc count(135e.
152  // Corresponds to 2adc/kev, 270[e/kev]/135[e/adc](2[adc/kev]
153  // Be carefull, this parameter is also used in SiPixelDet.cc to
154  // calculate the noise in adc counts from noise in electrons.
155  // Both defaults should be the same.
156  theElectronPerADC(conf.getParameter<double>("ElectronPerAdc")),
157 
158  // ADC saturation value, 255(8bit adc.
159  //theAdcFullScale(conf.getUntrackedParameter<int>("AdcFullScale",255)),
160  theAdcFullScale(conf.getParameter<int>("AdcFullScale")),
161  theAdcFullScaleStack(conf.exists("AdcFullScaleStack")?conf.getParameter<int>("AdcFullScaleStack"):255),
162 
163  // Noise in electrons:
164  // Pixel cell noise, relevant for generating noisy pixels
165  theNoiseInElectrons(conf.getParameter<double>("NoiseInElectrons")),
166 
167  // Fill readout noise, including all readout chain, relevant for smearing
168  //theReadoutNoise(conf.getUntrackedParameter<double>("ReadoutNoiseInElec",500.)),
169  theReadoutNoise(conf.getParameter<double>("ReadoutNoiseInElec")),
170 
171  // Pixel threshold in units of noise:
172  // thePixelThreshold(conf.getParameter<double>("ThresholdInNoiseUnits")),
173  // Pixel threshold in electron units.
174  theThresholdInE_FPix(conf.getParameter<double>("ThresholdInElectrons_FPix")),
175  theThresholdInE_BPix(conf.getParameter<double>("ThresholdInElectrons_BPix")),
176  theThresholdInE_BPix_L1(conf.exists("ThresholdInElectrons_BPix_L1")?conf.getParameter<double>("ThresholdInElectrons_BPix_L1"):theThresholdInE_BPix),
177 
178  // Add threshold gaussian smearing:
179  theThresholdSmearing_FPix(conf.getParameter<double>("ThresholdSmearing_FPix")),
180  theThresholdSmearing_BPix(conf.getParameter<double>("ThresholdSmearing_BPix")),
181  theThresholdSmearing_BPix_L1(conf.exists("ThresholdSmearing_BPix_L1")?conf.getParameter<double>("ThresholdSmearing_BPix_L1"):theThresholdSmearing_BPix),
182 
183  // electrons to VCAL conversion needed in misscalibrate()
184  electronsPerVCAL(conf.getParameter<double>("ElectronsPerVcal")),
185  electronsPerVCAL_Offset(conf.getParameter<double>("ElectronsPerVcal_Offset")),
186 
187  //theTofCut 12.5, cut in particle TOD +/- 12.5ns
188  //theTofCut(conf.getUntrackedParameter<double>("TofCut",12.5)),
189  theTofLowerCut(conf.getParameter<double>("TofLowerCut")),
190  theTofUpperCut(conf.getParameter<double>("TofUpperCut")),
191 
192  // Get the Lorentz angle from the cfg file:
193  tanLorentzAnglePerTesla_FPix(use_LorentzAngle_DB_ ? 0.0 : conf.getParameter<double>("TanLorentzAnglePerTesla_FPix")),
194  tanLorentzAnglePerTesla_BPix(use_LorentzAngle_DB_ ? 0.0 : conf.getParameter<double>("TanLorentzAnglePerTesla_BPix")),
195 
196  // signal response new parameterization: split Fpix and BPix
197  FPix_p0(conf.getParameter<double>("FPix_SignalResponse_p0")),
198  FPix_p1(conf.getParameter<double>("FPix_SignalResponse_p1")),
199  FPix_p2(conf.getParameter<double>("FPix_SignalResponse_p2")),
200  FPix_p3(conf.getParameter<double>("FPix_SignalResponse_p3")),
201 
202  BPix_p0(conf.getParameter<double>("BPix_SignalResponse_p0")),
203  BPix_p1(conf.getParameter<double>("BPix_SignalResponse_p1")),
204  BPix_p2(conf.getParameter<double>("BPix_SignalResponse_p2")),
205  BPix_p3(conf.getParameter<double>("BPix_SignalResponse_p3")),
206 
207  // Add noise
208  addNoise(conf.getParameter<bool>("AddNoise")),
209 
210  // Smear the pixel charge with a gaussian which RMS is a function of the
211  // pixel charge (Danek's study)
212  addChargeVCALSmearing(conf.getParameter<bool>("ChargeVCALSmearing")),
213 
214  // Add noisy pixels
215  addNoisyPixels(conf.getParameter<bool>("AddNoisyPixels")),
216 
217  // Fluctuate charge in track subsegments
218  fluctuateCharge(conf.getUntrackedParameter<bool>("FluctuateCharge",true)),
219 
220  // Control the pixel inefficiency
221  AddPixelInefficiency(conf.getParameter<bool>("AddPixelInefficiency")),
222 
223  // Add threshold gaussian smearing:
224  addThresholdSmearing(conf.getParameter<bool>("AddThresholdSmearing")),
225 
226  // Get the constants for the miss-calibration studies
227  doMissCalibrate(conf.getParameter<bool>("MissCalibrate")), // Enable miss-calibration
228  theGainSmearing(conf.getParameter<double>("GainSmearing")), // sigma of the gain smearing
229  theOffsetSmearing(conf.getParameter<double>("OffsetSmearing")), //sigma of the offset smearing
230 
231  // Add pixel radiation damage for upgrade studies
232  AddPixelAging(conf.getParameter<bool>("DoPixelAging")),
233 
234  // delta cutoff in MeV, has to be same as in OSCAR(0.030/cmsim=1.0 MeV
235  //tMax(0.030), // In MeV.
236  //tMax(conf.getUntrackedParameter<double>("deltaProductionCut",0.030)),
237  tMax(conf.getParameter<double>("deltaProductionCut")),
238 
239  fluctuate(fluctuateCharge ? new SiG4UniversalFluctuation() : 0),
240  theNoiser(addNoise ? new GaussianTailNoiseGenerator() : 0),
241  calmap(doMissCalibrate ? initCal() : std::map<int,CalParameters,std::less<int> >()),
242  theSiPixelGainCalibrationService_(use_ineff_from_db_ ? new SiPixelGainCalibrationOfflineSimService(conf) : 0),
243  pixelEfficiencies_(conf, AddPixelInefficiency,NumberOfBarrelLayers,NumberOfEndcapDisks),
244  pixelAging_(conf,AddPixelAging,NumberOfBarrelLayers,NumberOfEndcapDisks)
245 {
246  LogInfo ("PixelDigitizer ") <<"SiPixelDigitizerAlgorithm constructed"
247  <<"Configuration parameters:"
248  << "Threshold/Gain = "
249  << "threshold in electron FPix = "
251  << "threshold in electron BPix = "
253  << "threshold in electron BPix Layer1 = "
255  <<" " << theElectronPerADC << " " << theAdcFullScale
256  << " The delta cut-off is set to " << tMax
257  << " pix-inefficiency "<<AddPixelInefficiency;
258 
259 }
260 
261 std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> >
263 
264  using std::cerr;
265  using std::cout;
266  using std::endl;
267 
268  std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> > calmap;
269  // Prepare for the analog amplitude miss-calibration
270  LogDebug ("PixelDigitizer ")
271  << " miss-calibrate the pixel amplitude ";
272 
273  const bool ReadCalParameters = false;
274  if(ReadCalParameters) { // Read the calibration files from file
275  // read the calibration constants from a file (testing only)
276  std::ifstream in_file; // data file pointer
277  char filename[80] = "phCalibrationFit_C0.dat";
278 
279  in_file.open(filename, std::ios::in ); // in C++
280  if(in_file.bad()) {
281  cout << " File not found " << endl;
282  return calmap; // signal error
283  }
284  cout << " file opened : " << filename << endl;
285 
286  char line[500];
287  for (int i = 0; i < 3; i++) {
288  in_file.getline(line, 500,'\n');
289  cout<<line<<endl;
290  }
291 
292  cout << " test map" << endl;
293 
294  float par0,par1,par2,par3;
295  int colid,rowid;
297  // Read MC tracks
298  for(int i=0;i<(52*80);i++) { // loop over tracks
299  in_file >> par0 >> par1 >> par2 >> par3 >> name >> colid >> rowid;
300  if(in_file.bad()) { // check for errors
301  cerr << "Cannot read data file" << endl;
302  return calmap;
303  }
304  if( in_file.eof() != 0 ) {
305  cerr << in_file.eof() << " " << in_file.gcount() << " "
306  << in_file.fail() << " " << in_file.good() << " end of file "
307  << endl;
308  return calmap;
309  }
310 
311  //cout << " line " << i << " " <<par0<<" "<<par1<<" "<<par2<<" "<<par3<<" "
312  // <<colid<<" "<<rowid<<endl;
313 
314  CalParameters onePix;
315  onePix.p0=par0;
316  onePix.p1=par1;
317  onePix.p2=par2;
318  onePix.p3=par3;
319 
320  // Convert ROC pixel index to channel
321  int chan = PixelIndices::pixelToChannelROC(rowid,colid);
322  calmap.insert(std::pair<int,CalParameters>(chan,onePix));
323 
324  // Testing the index conversion, can be skipped
325  std::pair<int,int> p = PixelIndices::channelToPixelROC(chan);
326  if(rowid!=p.first) cout<<" wrong channel row "<<rowid<<" "<<p.first<<endl;
327  if(colid!=p.second) cout<<" wrong channel col "<<colid<<" "<<p.second<<endl;
328 
329  } // pixel loop in a ROC
330 
331  cout << " map size " << calmap.size() <<" max "<<calmap.max_size() << " "
332  <<calmap.empty()<< endl;
333 
334 // cout << " map size " << calmap.size() << endl;
335 // map<int,CalParameters,std::less<int> >::iterator ix,it;
336 // map<int,CalParameters,std::less<int> >::const_iterator ip;
337 // for (ix = calmap.begin(); ix != calmap.end(); ++ix) {
338 // int i = (*ix).first;
339 // std::pair<int,int> p = channelToPixelROC(i);
340 // it = calmap.find(i);
341 // CalParameters y = (*it).second;
342 // CalParameters z = (*ix).second;
343 // cout << i <<" "<<p.first<<" "<<p.second<<" "<<y.p0<<" "<<z.p0<<" "<<calmap[i].p0<<endl;
344 
345 // //int dummy=0;
346 // //cin>>dummy;
347 // }
348 
349  } // end if readparameters
350  return calmap;
351 } // end initCal()
352 
353 //=========================================================================
355  LogDebug ("PixelDigitizer")<<"SiPixelDigitizerAlgorithm deleted";
356 }
357 
358 // Read DynIneff Scale factors from Configuration
359 SiPixelDigitizerAlgorithm::PixelEfficiencies::PixelEfficiencies(const edm::ParameterSet& conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks) {
360  // pixel inefficiency
361  // Don't use Hard coded values, read inefficiencies in from DB/python config or don't use any
362  int NumberOfTotLayers = NumberOfBarrelLayers + NumberOfEndcapDisks;
364  if (AddPixelInefficiency){
365  FromConfig =
366  conf.exists("thePixelColEfficiency_BPix1") && conf.exists("thePixelColEfficiency_BPix2") && conf.exists("thePixelColEfficiency_BPix3") &&
367  conf.exists("thePixelColEfficiency_FPix1") && conf.exists("thePixelColEfficiency_FPix2") &&
368  conf.exists("thePixelEfficiency_BPix1") && conf.exists("thePixelEfficiency_BPix2") && conf.exists("thePixelEfficiency_BPix3") &&
369  conf.exists("thePixelEfficiency_FPix1") && conf.exists("thePixelEfficiency_FPix2") &&
370  conf.exists("thePixelChipEfficiency_BPix1") && conf.exists("thePixelChipEfficiency_BPix2") && conf.exists("thePixelChipEfficiency_BPix3") &&
371  conf.exists("thePixelChipEfficiency_FPix1") && conf.exists("thePixelChipEfficiency_FPix2");
372  if (NumberOfBarrelLayers==3) FromConfig = FromConfig && conf.exists("theLadderEfficiency_BPix1") && conf.exists("theLadderEfficiency_BPix2") && conf.exists("theLadderEfficiency_BPix3") &&
373  conf.exists("theModuleEfficiency_BPix1") && conf.exists("theModuleEfficiency_BPix2") && conf.exists("theModuleEfficiency_BPix3") &&
374  conf.exists("thePUEfficiency_BPix1") && conf.exists("thePUEfficiency_BPix2") && conf.exists("thePUEfficiency_BPix3") &&
375  conf.exists("theInnerEfficiency_FPix1") && conf.exists("theInnerEfficiency_FPix2") &&
376  conf.exists("theOuterEfficiency_FPix1") && conf.exists("theOuterEfficiency_FPix2") &&
377  conf.exists("thePUEfficiency_FPix_Inner") && conf.exists("thePUEfficiency_FPix_Outer") &&
378  conf.exists("theInstLumiScaleFactor");
379  if (NumberOfBarrelLayers>=4) FromConfig = FromConfig && conf.exists("thePixelColEfficiency_BPix4") &&
380  conf.exists("thePixelEfficiency_BPix4") && conf.exists("thePixelChipEfficiency_BPix4");
381  if (NumberOfEndcapDisks>=3) FromConfig = FromConfig && conf.exists("thePixelColEfficiency_FPix4") &&
382  conf.exists("thePixelEfficiency_FPix3") && conf.exists("thePixelChipEfficiency_FPix3");
383  if (FromConfig) {
384  LogInfo ("PixelDigitizer ") <<"The PixelDigitizer inefficiency configuration is read from the config file.\n";
385  theInstLumiScaleFactor = conf.getParameter<double>("theInstLumiScaleFactor");
386  int i=0;
387  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix1");
388  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix2");
389  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix3");
390  if (NumberOfBarrelLayers>=4){thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix4");}
391  //
392  i=0;
393  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix1");
394  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix2");
395  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix3");
396  if (NumberOfBarrelLayers>=4){thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix4");}
397  //
398  i=0;
399  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix1");
400  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix2");
401  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix3");
402  if (NumberOfBarrelLayers>=4){thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix4");}
403  //
404  if (NumberOfBarrelLayers==3){
405  i=0;
406  theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix1");
407  theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix2");
408  theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix3");
409  if ( ((theLadderEfficiency_BPix[0].size()!=20) || (theLadderEfficiency_BPix[1].size()!=32) ||
410  (theLadderEfficiency_BPix[2].size()!=44)) && (NumberOfBarrelLayers==3) )
411  throw cms::Exception("Configuration") << "Wrong ladder number in efficiency config!";
412  //
413  i=0;
414  theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix1");
415  theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix2");
416  theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix3");
417  if ( ((theModuleEfficiency_BPix[0].size()!=4) || (theModuleEfficiency_BPix[1].size()!=4) ||
418  (theModuleEfficiency_BPix[2].size()!=4)) && (NumberOfBarrelLayers==3) )
419  throw cms::Exception("Configuration") << "Wrong module number in efficiency config!";
420  //
421  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix1"));
422  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix2"));
423  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix3"));
424  if ( ((thePUEfficiency[0].size()==0) || (thePUEfficiency[1].size()==0) ||
425  (thePUEfficiency[2].size()==0)) && (NumberOfBarrelLayers==3) )
426  throw cms::Exception("Configuration") << "At least one PU efficiency (BPix) number is needed in efficiency config!";
427  }
428  // The next is needed for Phase2 Tracker studies
429  if (NumberOfBarrelLayers>=5){
430  if (NumberOfTotLayers>20){throw cms::Exception("Configuration") <<"SiPixelDigitizer was given more layers than it can handle";}
431  // For Phase2 tracker layers just set the outermost BPix inefficiency to 99.9% THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
432  for (int j=5 ; j<=NumberOfBarrelLayers ; j++){
433  thePixelColEfficiency[j-1]=0.999;
434  thePixelEfficiency[j-1]=0.999;
435  thePixelChipEfficiency[j-1]=0.999;
436  }
437  }
438  //
439  i=FPixIndex;
440  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix1");
441  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix2");
442  if (NumberOfEndcapDisks>=3){thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix3");}
443  i=FPixIndex;
444  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix1");
445  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix2");
446  if (NumberOfEndcapDisks>=3){thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix3");}
447  i=FPixIndex;
448  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix1");
449  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix2");
450  if (NumberOfEndcapDisks>=3){thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix3");}
451  // The next is needed for Phase2 Tracker studies
452  if (NumberOfEndcapDisks>=4){
453  if (NumberOfTotLayers>20){throw cms::Exception("Configuration") <<"SiPixelDigitizer was given more layers than it can handle";}
454  // For Phase2 tracker layers just set the extra FPix disk inefficiency to 99.9% THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
455  for (int j=4+FPixIndex ; j<=NumberOfEndcapDisks+NumberOfBarrelLayers ; j++){
456  thePixelColEfficiency[j-1]=0.999;
457  thePixelEfficiency[j-1]=0.999;
458  thePixelChipEfficiency[j-1]=0.999;
459  }
460  }
461  //FPix Dynamic Inefficiency
462  if (NumberOfBarrelLayers==3){
463  i=FPixIndex;
464  theInnerEfficiency_FPix[i++] = conf.getParameter<double>("theInnerEfficiency_FPix1");
465  theInnerEfficiency_FPix[i++] = conf.getParameter<double>("theInnerEfficiency_FPix2");
466  i=FPixIndex;
467  theOuterEfficiency_FPix[i++] = conf.getParameter<double>("theOuterEfficiency_FPix1");
468  theOuterEfficiency_FPix[i++] = conf.getParameter<double>("theOuterEfficiency_FPix2");
469  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_FPix_Inner"));
470  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_FPix_Outer"));
471  if ( ((thePUEfficiency[3].size()==0) || (thePUEfficiency[4].size()==0)) && (NumberOfEndcapDisks==2) )
472  throw cms::Exception("Configuration") << "At least one (FPix) PU efficiency number is needed in efficiency config!";
473  pu_scale.resize(thePUEfficiency.size());
474  }
475  }
476  else LogInfo ("PixelDigitizer ") <<"The PixelDigitizer inefficiency configuration is read from the database.\n";
477  }
478  // the first "NumberOfBarrelLayers" settings [0],[1], ... , [NumberOfBarrelLayers-1] are for the barrel pixels
479  // the next "NumberOfEndcapDisks" settings [NumberOfBarrelLayers],[NumberOfBarrelLayers+1], ... [NumberOfEndcapDisks+NumberOfBarrelLayers-1]
480 }
481 
482 // Read DynIneff Scale factors from DB
483 void SiPixelDigitizerAlgorithm::init_DynIneffDB(const edm::EventSetup& es, const unsigned int& bunchspace){
485  if (bunchspace == 50) es.get<SiPixelDynamicInefficiencyRcd>().get("50ns",SiPixelDynamicInefficiency_);
488  }
489 }
490 
492 
493  theInstLumiScaleFactor = SiPixelDynamicInefficiency->gettheInstLumiScaleFactor();
494  const std::map<uint32_t, double>& PixelGeomFactorsDB = SiPixelDynamicInefficiency->getPixelGeomFactors();
495  const std::map<uint32_t, double>& ColGeomFactorsDB = SiPixelDynamicInefficiency->getColGeomFactors();
496  const std::map<uint32_t, double>& ChipGeomFactorsDB = SiPixelDynamicInefficiency->getChipGeomFactors();
497  const std::map<uint32_t, std::vector<double> >& PUFactors = SiPixelDynamicInefficiency->getPUFactors();
498  std::vector<uint32_t > DetIdmasks = SiPixelDynamicInefficiency->getDetIdmasks();
499 
500  // Loop on all modules, calculate geometrical scale factors and store in map for easy access
501  for(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
502  if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0) continue;
503  const DetId detid = (*it_module)->geographicalId();
504  uint32_t rawid = detid.rawId();
505  PixelGeomFactors[rawid] = 1;
506  ColGeomFactors[rawid] = 1;
507  ChipGeomFactors[rawid] = 1;
508  for (auto db_factor : PixelGeomFactorsDB) if (matches(detid, DetId(db_factor.first), DetIdmasks)) PixelGeomFactors[rawid] *= db_factor.second;
509  for (auto db_factor : ColGeomFactorsDB) if (matches(detid, DetId(db_factor.first), DetIdmasks)) ColGeomFactors[rawid] *= db_factor.second;
510  for (auto db_factor : ChipGeomFactorsDB) if (matches(detid, DetId(db_factor.first), DetIdmasks)) ChipGeomFactors[rawid] *= db_factor.second;
511  }
512 
513  // piluep scale factors are calculated once per event
514  // therefore vector index is stored in a map for each module that matches to a db_id
515  size_t i=0;
516  for (auto factor : PUFactors) {
517  const DetId db_id = DetId(factor.first);
518  for(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
519  if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0) continue;
520  const DetId detid = (*it_module)->geographicalId();
521  if (!matches(detid, db_id, DetIdmasks)) continue;
522  if (iPU.count(detid.rawId())) {
523  throw cms::Exception("Database")<<"Multiple db_ids match to same module in SiPixelDynamicInefficiency DB Object";
524  } else {
525  iPU[detid.rawId()] = i;
526  }
527  }
528  thePUEfficiency.push_back(factor.second);
529  ++i;
530  }
531  pu_scale.resize(thePUEfficiency.size());
532 }
533 
534 bool SiPixelDigitizerAlgorithm::PixelEfficiencies::matches(const DetId& detid, const DetId& db_id, const std::vector<uint32_t >& DetIdmasks) {
535  if (detid.subdetId() != db_id.subdetId()) return false;
536  for (size_t i=0; i<DetIdmasks.size(); ++i) {
537  DetId maskid = DetId(DetIdmasks.at(i));
538  if (maskid.subdetId() != db_id.subdetId()) continue;
539  if ((detid.rawId()&maskid.rawId()) != (db_id.rawId()&maskid.rawId()) &&
540  (db_id.rawId()&maskid.rawId()) != DetId(db_id.det(), db_id.subdetId()).rawId()) return false;
541  }
542  return true;
543 }
544 
546  // pixel aging
547  // Don't use Hard coded values, read aging in from python or don't use any
548  if(AddAging) {
549  int NumberOfTotLayers = NumberOfBarrelLayers + NumberOfEndcapDisks;
550  FPixIndex=NumberOfBarrelLayers;
551 
552  int i=0;
553  thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix1");
554  thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix2");
555  thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix3");
556  thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_BPix4");
557 
558  // to be removed when Gaelle will have the phase2 digitizer
559  if (NumberOfBarrelLayers>=5){
560  if (NumberOfTotLayers>20){throw cms::Exception("Configuration") <<"SiPixelDigitizer was given more layers than it can handle";}
561  // For Phase2 tracker layers just set the outermost BPix aging 0.
562  for (int j=5 ; j<=NumberOfBarrelLayers ; j++){
563  thePixelPseudoRadDamage[j-1]=0.;
564  }
565  }
566  //
567  i=FPixIndex;
568  thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_FPix1");
569  thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_FPix2");
570  thePixelPseudoRadDamage[i++] = conf.getParameter<double>("thePixelPseudoRadDamage_FPix3");
571 
572  //To be removed when Phase2 digitizer will be available
573  if (NumberOfEndcapDisks>=4){
574  if (NumberOfTotLayers>20){throw cms::Exception("Configuration") <<"SiPixelDigitizer was given more layers than it can handle";}
575  // For Phase2 tracker layers just set the extra FPix disk aging to 0. BE CAREFUL THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
576  for (int j=4+FPixIndex ; j<=NumberOfEndcapDisks+NumberOfBarrelLayers ; j++){
577  thePixelPseudoRadDamage[j-1]=0.;
578  }
579  }
580  }
581  // the first "NumberOfBarrelLayers" settings [0],[1], ... , [NumberOfBarrelLayers-1] are for the barrel pixels
582  // the next "NumberOfEndcapDisks" settings [NumberOfBarrelLayers],[NumberOfBarrelLayers+1], ... [NumberOfEndcapDisks+NumberOfBarrelLayers-1]
583 }
584 
585 //=========================================================================
586 void SiPixelDigitizerAlgorithm::accumulateSimHits(std::vector<PSimHit>::const_iterator inputBegin,
587  std::vector<PSimHit>::const_iterator inputEnd,
588  const size_t inputBeginGlobalIndex,
589  const unsigned int tofBin,
590  const PixelGeomDetUnit* pixdet,
591  const GlobalVector& bfield,
592  const TrackerTopology *tTopo,
593  CLHEP::HepRandomEngine* engine) {
594  // produce SignalPoint's for all SimHit's in detector
595  // Loop over hits
596 
597  uint32_t detId = pixdet->geographicalId().rawId();
598  size_t simHitGlobalIndex=inputBeginGlobalIndex; // This needs to stored to create the digi-sim link later
599  for (std::vector<PSimHit>::const_iterator ssbegin = inputBegin; ssbegin != inputEnd; ++ssbegin, ++simHitGlobalIndex) {
600  // skip hits not in this detector.
601  if((*ssbegin).detUnitId() != detId) {
602  continue;
603  }
604 
605 #ifdef TP_DEBUG
606  LogDebug ("Pixel Digitizer")
607  << (*ssbegin).particleType() << " " << (*ssbegin).pabs() << " "
608  << (*ssbegin).energyLoss() << " " << (*ssbegin).tof() << " "
609  << (*ssbegin).trackId() << " " << (*ssbegin).processType() << " "
610  << (*ssbegin).detUnitId()
611  << (*ssbegin).entryPoint() << " " << (*ssbegin).exitPoint() ;
612 #endif
613 
614 
615  std::vector<EnergyDepositUnit> ionization_points;
616  std::vector<SignalPoint> collection_points;
617 
618  // fill collection_points for this SimHit, indpendent of topology
619  // Check the TOF cut
620  if ( ((*ssbegin).tof() - pixdet->surface().toGlobal((*ssbegin).localPosition()).mag()/30.)>= theTofLowerCut &&
621  ((*ssbegin).tof()- pixdet->surface().toGlobal((*ssbegin).localPosition()).mag()/30.) <= theTofUpperCut ) {
622  primary_ionization(*ssbegin, ionization_points, engine); // fills _ionization_points
623  drift(*ssbegin, pixdet, bfield, tTopo, ionization_points, collection_points); // transforms _ionization_points to collection_points
624  // compute induced signal on readout elements and add to _signal
625  induce_signal(*ssbegin, simHitGlobalIndex, tofBin, pixdet, collection_points); // 1st 3 args needed only for SimHit<-->Digi link
626  } // end if
627  } // end for
628 
629 }
630 
631 //============================================================================
633  //Instlumi scalefactor calculating for dynamic inefficiency
634 
635  if (puInfo) {
636  const std::vector<int> bunchCrossing = puInfo->getMix_bunchCrossing();
637  const std::vector<float> TrueInteractionList = puInfo->getMix_TrueInteractions();
638  //const int bunchSpacing = puInfo->getMix_bunchSpacing();
639 
640  int pui = 0, p = 0;
641  std::vector<int>::const_iterator pu;
642  std::vector<int>::const_iterator pu0 = bunchCrossing.end();
643 
644  for (pu=bunchCrossing.begin(); pu!=bunchCrossing.end(); ++pu) {
645  if (*pu==0) {
646  pu0 = pu;
647  p = pui;
648  }
649  pui++;
650  }
651  if (pu0!=bunchCrossing.end()) {
652  for (size_t i=0, n = pixelEfficiencies_.thePUEfficiency.size(); i<n; i++) {
653  double instlumi = TrueInteractionList.at(p)*pixelEfficiencies_.theInstLumiScaleFactor;
654  double instlumi_pow=1.;
656  for (size_t j=0; j<pixelEfficiencies_.thePUEfficiency[i].size(); j++){
658  instlumi_pow*=instlumi;
659  }
660  }
661  }
662  }
663  else {
664  for (int i=0, n = pixelEfficiencies_.thePUEfficiency.size(); i<n; i++) {
666  }
667  }
668 }
669 
670 //============================================================================
672  std::vector<PixelDigi>& digis,
673  std::vector<PixelDigiSimLink>& simlinks,
674  const TrackerTopology *tTopo,
675  CLHEP::HepRandomEngine* engine) {
676 
677  // Pixel Efficiency moved from the constructor to this method because
678  // the information of the det are not available in the constructor
679  // Efficiency parameters. 0 - no inefficiency, 1-low lumi, 10-high lumi
680 
681  uint32_t detID = pixdet->geographicalId().rawId();
682  const signal_map_type& theSignal = _signal[detID];
683 
684  const PixelTopology* topol=&pixdet->specificTopology();
685  int numColumns = topol->ncolumns(); // det module number of cols&rows
686  int numRows = topol->nrows();
687 
688  // Noise already defined in electrons
689  // thePixelThresholdInE = thePixelThreshold * theNoiseInElectrons ;
690  // Find the threshold in noise units, needed for the noiser.
691 
692 
693  float thePixelThresholdInE = 0.;
694 
695  if(theNoiseInElectrons>0.){
696  if(pixdet->type().isTrackerPixel() && pixdet->type().isBarrel()){ // Barrel modules
697  int lay = tTopo->layer(detID);
700  thePixelThresholdInE = CLHEP::RandGaussQ::shoot(engine, theThresholdInE_BPix_L1, theThresholdSmearing_BPix_L1); // gaussian smearing
701  } else {
702  thePixelThresholdInE = CLHEP::RandGaussQ::shoot(engine, theThresholdInE_BPix , theThresholdSmearing_BPix); // gaussian smearing
703  }
704  } else {
706  thePixelThresholdInE = theThresholdInE_BPix_L1;
707  } else {
708  thePixelThresholdInE = theThresholdInE_BPix; // no smearing
709  }
710  }
711  } else if(pixdet->type().isTrackerPixel()) { // Forward disks modules
713  thePixelThresholdInE = CLHEP::RandGaussQ::shoot(engine, theThresholdInE_FPix, theThresholdSmearing_FPix); // gaussian smearing
714  } else {
715  thePixelThresholdInE = theThresholdInE_FPix; // no smearing
716  }
717  }
718  else {throw cms::Exception("NotAPixelGeomDetUnit") << "Not a pixel geomdet unit" << detID;}
719  }
720 
721 
722 #ifdef TP_DEBUG
723  // full detector thickness
724  float moduleThickness = pixdet->specificSurface().bounds().thickness();
725  LogDebug ("PixelDigitizer")
726  << " PixelDigitizer "
727  << numColumns << " " << numRows << " " << moduleThickness;
728 #endif
729 
730  if(addNoise) add_noise(pixdet, thePixelThresholdInE/theNoiseInElectrons, engine); // generate noise
731 
732  // Do only if needed
733 
734  if((AddPixelInefficiency) && (theSignal.size()>0))
735  pixel_inefficiency(pixelEfficiencies_, pixdet, tTopo, engine); // Kill some pixels
736 
737  if(use_ineff_from_db_ && (theSignal.size()>0))
738  pixel_inefficiency_db(detID);
739 
740  if(use_module_killing_) {
741  if (use_deadmodule_DB_) { // remove dead modules using DB
742  module_killing_DB(detID);
743  } else { // remove dead modules using the list in cfg file
744  module_killing_conf(detID);
745  }
746  }
747 
748  make_digis(thePixelThresholdInE, detID, pixdet, digis, simlinks, tTopo);
749 
750 #ifdef TP_DEBUG
751  LogDebug ("PixelDigitizer") << "[SiPixelDigitizerAlgorithm] converted " << digis.size() << " PixelDigis in DetUnit" << detID;
752 #endif
753 }
754 
755 //***********************************************************************/
756 // Generate primary ionization along the track segment.
757 // Divide the track into small sub-segments
758 void SiPixelDigitizerAlgorithm::primary_ionization(const PSimHit& hit, std::vector<EnergyDepositUnit>& ionization_points, CLHEP::HepRandomEngine* engine) const {
759 
760  // Straight line approximation for trajectory inside active media
761 
762  const float SegmentLength = 0.0010; //10microns in cm
763  float energy;
764 
765  // Get the 3D segment direction vector
766  LocalVector direction = hit.exitPoint() - hit.entryPoint();
767 
768  float eLoss = hit.energyLoss(); // Eloss in GeV
769  float length = direction.mag(); // Track length in Silicon
770 
771  int NumberOfSegments = int ( length / SegmentLength); // Number of segments
772  if(NumberOfSegments < 1) NumberOfSegments = 1;
773 
774 #ifdef TP_DEBUG
775  LogDebug ("Pixel Digitizer")
776  << " enter primary_ionzation " << NumberOfSegments
777  << " shift = "
778  << (hit.exitPoint().x()-hit.entryPoint().x()) << " "
779  << (hit.exitPoint().y()-hit.entryPoint().y()) << " "
780  << (hit.exitPoint().z()-hit.entryPoint().z()) << " "
781  << hit.particleType() <<" "<< hit.pabs() ;
782 #endif
783 
784  float* elossVector = new float[NumberOfSegments]; // Eloss vector
785 
786  if( fluctuateCharge ) {
787  //MP DA RIMUOVERE ASSOLUTAMENTE
788  int pid = hit.particleType();
789  //int pid=211; // assume it is a pion
790 
791  float momentum = hit.pabs();
792  // Generate fluctuated charge points
793  fluctuateEloss(pid, momentum, eLoss, length, NumberOfSegments,
794  elossVector, engine);
795  }
796 
797  ionization_points.resize( NumberOfSegments); // set size
798 
799  // loop over segments
800  for ( int i = 0; i != NumberOfSegments; i++) {
801  // Divide the segment into equal length subsegments
802  Local3DPoint point = hit.entryPoint() +
803  float((i+0.5)/NumberOfSegments) * direction;
804 
805  if( fluctuateCharge )
806  energy = elossVector[i]/GeVperElectron; // Convert charge to elec.
807  else
808  energy = hit.energyLoss()/GeVperElectron/float(NumberOfSegments);
809 
810  EnergyDepositUnit edu( energy, point); //define position,energy point
811  ionization_points[i] = edu; // save
812 
813 #ifdef TP_DEBUG
814  LogDebug ("Pixel Digitizer")
815  << i << " " << ionization_points[i].x() << " "
816  << ionization_points[i].y() << " "
817  << ionization_points[i].z() << " "
818  << ionization_points[i].energy();
819 #endif
820 
821  } // end for loop
822 
823  delete[] elossVector;
824 
825 }
826 //******************************************************************************
827 
828 // Fluctuate the charge comming from a small (10um) track segment.
829 // Use the G4 routine. For mip pions for the moment.
830 void SiPixelDigitizerAlgorithm::fluctuateEloss(int pid, float particleMomentum,
831  float eloss, float length,
832  int NumberOfSegs,float elossVector[],
833  CLHEP::HepRandomEngine* engine) const {
834 
835  // Get dedx for this track
836  //float dedx;
837  //if( length > 0.) dedx = eloss/length;
838  //else dedx = eloss;
839 
840  double particleMass = 139.6; // Mass in MeV, Assume pion
841  pid = std::abs(pid);
842  if(pid!=211) { // Mass in MeV
843  if(pid==11) particleMass = 0.511;
844  else if(pid==13) particleMass = 105.7;
845  else if(pid==321) particleMass = 493.7;
846  else if(pid==2212) particleMass = 938.3;
847  }
848  // What is the track segment length.
849  float segmentLength = length/NumberOfSegs;
850 
851  // Generate charge fluctuations.
852  float de=0.;
853  float sum=0.;
854  double segmentEloss = (1000.*eloss)/NumberOfSegs; //eloss in MeV
855  for (int i=0;i<NumberOfSegs;i++) {
856  // material,*, momentum,energy,*, *, mass
857  //myglandz_(14.,segmentLength,2.,2.,dedx,de,0.14);
858  // The G4 routine needs momentum in MeV, mass in Mev, delta-cut in MeV,
859  // track segment length in mm, segment eloss in MeV
860  // Returns fluctuated eloss in MeV
861  double deltaCutoff = tMax; // the cutoff is sometimes redefined inside, so fix it.
862  de = fluctuate->SampleFluctuations(double(particleMomentum*1000.),
863  particleMass, deltaCutoff,
864  double(segmentLength*10.),
865  segmentEloss, engine )/1000.; //convert to GeV
866  elossVector[i]=de;
867  sum +=de;
868  }
869 
870  if(sum>0.) { // If fluctuations give eloss>0.
871  // Rescale to the same total eloss
872  float ratio = eloss/sum;
873 
874  for (int ii=0;ii<NumberOfSegs;ii++) elossVector[ii]= ratio*elossVector[ii];
875  } else { // If fluctuations gives 0 eloss
876  float averageEloss = eloss/NumberOfSegs;
877  for (int ii=0;ii<NumberOfSegs;ii++) elossVector[ii]= averageEloss;
878  }
879  return;
880 }
881 
882 //*******************************************************************************
883 // Drift the charge segments to the sensor surface (collection plane)
884 // Include the effect of E-field and B-field
886  const PixelGeomDetUnit* pixdet,
887  const GlobalVector& bfield,
888  const TrackerTopology *tTopo,
889  const std::vector<EnergyDepositUnit>& ionization_points,
890  std::vector<SignalPoint>& collection_points) const {
891 
892 #ifdef TP_DEBUG
893  LogDebug ("Pixel Digitizer") << " enter drift " ;
894 #endif
895 
896  collection_points.resize(ionization_points.size()); // set size
897 
898  LocalVector driftDir=DriftDirection(pixdet, bfield, hit.detUnitId()); // get the charge drift direction
899  if(driftDir.z() ==0.) {
900  LogWarning("Magnetic field") << " pxlx: drift in z is zero ";
901  return;
902  }
903 
904  // tangent of Lorentz angle
905  //float TanLorenzAngleX = driftDir.x()/driftDir.z();
906  //float TanLorenzAngleY = 0.; // force to 0, driftDir.y()/driftDir.z();
907 
908  float TanLorenzAngleX, TanLorenzAngleY,dir_z, CosLorenzAngleX,
909  CosLorenzAngleY;
910  if( alpha2Order) {
911  TanLorenzAngleX = driftDir.x(); // tangen of Lorentz angle
912  TanLorenzAngleY = driftDir.y();
913  dir_z = driftDir.z(); // The z drift direction
914  CosLorenzAngleX = 1./sqrt(1.+TanLorenzAngleX*TanLorenzAngleX); //cosine
915  CosLorenzAngleY = 1./sqrt(1.+TanLorenzAngleY*TanLorenzAngleY); //cosine;
916 
917  } else{
918  TanLorenzAngleX = driftDir.x();
919  TanLorenzAngleY = 0.; // force to 0, driftDir.y()/driftDir.z();
920  dir_z = driftDir.z(); // The z drift direction
921  CosLorenzAngleX = 1./sqrt(1.+TanLorenzAngleX*TanLorenzAngleX); //cosine to estimate the path length
922  CosLorenzAngleY = 1.;
923  }
924 
925  float moduleThickness = pixdet->specificSurface().bounds().thickness();
926 #ifdef TP_DEBUG
927  LogDebug ("Pixel Digitizer")
928  << " Lorentz Tan " << TanLorenzAngleX << " " << TanLorenzAngleY <<" "
929  << CosLorenzAngleX << " " << CosLorenzAngleY << " "
930  << moduleThickness*TanLorenzAngleX << " " << driftDir;
931 #endif
932 
933  float Sigma_x = 1.; // Charge spread
934  float Sigma_y = 1.;
935  float DriftDistance; // Distance between charge generation and collection
936  float DriftLength; // Actual Drift Lentgh
937  float Sigma;
938 
939  for (unsigned int i = 0; i != ionization_points.size(); i++) {
940 
941  float SegX, SegY, SegZ; // position
942  SegX = ionization_points[i].x();
943  SegY = ionization_points[i].y();
944  SegZ = ionization_points[i].z();
945 
946  // Distance from the collection plane
947  //DriftDistance = (moduleThickness/2. + SegZ); // Drift to -z
948  // Include explixitely the E drift direction (for CMS dir_z=-1)
949  DriftDistance = moduleThickness/2. - (dir_z * SegZ); // Drift to -z
950 
951  //if( DriftDistance <= 0.)
952  //cout<<" <=0 "<<DriftDistance<<" "<<i<<" "<<SegZ<<" "<<dir_z<<" "
953  // <<SegX<<" "<<SegY<<" "<<(moduleThickness/2)<<" "
954  // <<ionization_points[i].energy()<<" "
955  // <<hit.particleType()<<" "<<hit.pabs()<<" "<<hit.energyLoss()<<" "
956  // <<hit.entryPoint()<<" "<<hit.exitPoint()
957  // <<std::endl;
958 
959  if( DriftDistance < 0.) {
960  DriftDistance = 0.;
961  } else if( DriftDistance > moduleThickness )
962  DriftDistance = moduleThickness;
963 
964  // Assume full depletion now, partial depletion will come later.
965  float XDriftDueToMagField = DriftDistance * TanLorenzAngleX;
966  float YDriftDueToMagField = DriftDistance * TanLorenzAngleY;
967 
968  // Shift cloud center
969  float CloudCenterX = SegX + XDriftDueToMagField;
970  float CloudCenterY = SegY + YDriftDueToMagField;
971 
972  // Calculate how long is the charge drift path
973  DriftLength = sqrt( DriftDistance*DriftDistance +
974  XDriftDueToMagField*XDriftDueToMagField +
975  YDriftDueToMagField*YDriftDueToMagField );
976 
977  // What is the charge diffusion after this path
978  Sigma = sqrt(DriftLength/Dist300) * Sigma0;
979 
980  // Project the diffusion sigma on the collection plane
981  Sigma_x = Sigma / CosLorenzAngleX ;
982  Sigma_y = Sigma / CosLorenzAngleY ;
983 
984  // Insert a charge loss due to Rad Damage here
985  float energyOnCollector = ionization_points[i].energy(); // The energy that reaches the collector
986 
987  // add pixel aging
988  if (AddPixelAging) {
989  float kValue = pixel_aging(pixelAging_,pixdet,tTopo);
990  energyOnCollector *= exp( -1*kValue*DriftDistance/moduleThickness );
991  }
992 
993 #ifdef TP_DEBUG
994  LogDebug ("Pixel Digitizer")
995  <<" Dift DistanceZ= "<<DriftDistance<<" module thickness= "<<moduleThickness
996  <<" Start Energy= "<<ionization_points[i].energy()<<" Energy after loss= "<<energyOnCollector;
997 #endif
998  SignalPoint sp( CloudCenterX, CloudCenterY,
999  Sigma_x, Sigma_y, hit.tof(), energyOnCollector );
1000 
1001  // Load the Charge distribution parameters
1002  collection_points[i] = (sp);
1003 
1004  } // loop over ionization points, i.
1005 
1006 } // end drift
1007 
1008 //*************************************************************************
1009 // Induce the signal on the collection plane of the active sensor area.
1011  const size_t hitIndex,
1012  const unsigned int tofBin,
1013  const PixelGeomDetUnit* pixdet,
1014  const std::vector<SignalPoint>& collection_points) {
1015 
1016  // X - Rows, Left-Right, 160, (1.6cm) for barrel
1017  // Y - Columns, Down-Up, 416, (6.4cm)
1018 
1019  const PixelTopology* topol=&pixdet->specificTopology();
1020  uint32_t detID= pixdet->geographicalId().rawId();
1021  signal_map_type& theSignal = _signal[detID];
1022 
1023 #ifdef TP_DEBUG
1024  LogDebug ("Pixel Digitizer")
1025  << " enter induce_signal, "
1026  << topol->pitch().first << " " << topol->pitch().second; //OK
1027 #endif
1028 
1029  // local map to store pixels hit by 1 Hit.
1030  typedef std::map< int, float, std::less<int> > hit_map_type;
1031  hit_map_type hit_signal;
1032 
1033  // map to store pixel integrals in the x and in the y directions
1034  std::map<int, float, std::less<int> > x,y;
1035 
1036  // Assign signals to readout channels and store sorted by channel number
1037 
1038  // Iterate over collection points on the collection plane
1039  for ( std::vector<SignalPoint>::const_iterator i=collection_points.begin();
1040  i != collection_points.end(); ++i) {
1041 
1042  float CloudCenterX = i->position().x(); // Charge position in x
1043  float CloudCenterY = i->position().y(); // in y
1044  float SigmaX = i->sigma_x(); // Charge spread in x
1045  float SigmaY = i->sigma_y(); // in y
1046  float Charge = i->amplitude(); // Charge amplitude
1047 
1048 
1049  //if(SigmaX==0 || SigmaY==0) {
1050  //cout<<SigmaX<<" "<<SigmaY
1051  // << " cloud " << i->position().x() << " " << i->position().y() << " "
1052  // << i->sigma_x() << " " << i->sigma_y() << " " << i->amplitude()<<std::endl;
1053  //}
1054 
1055 #ifdef TP_DEBUG
1056  LogDebug ("Pixel Digitizer")
1057  << " cloud " << i->position().x() << " " << i->position().y() << " "
1058  << i->sigma_x() << " " << i->sigma_y() << " " << i->amplitude();
1059 #endif
1060 
1061  // Find the maximum cloud spread in 2D plane , assume 3*sigma
1062  float CloudRight = CloudCenterX + ClusterWidth*SigmaX;
1063  float CloudLeft = CloudCenterX - ClusterWidth*SigmaX;
1064  float CloudUp = CloudCenterY + ClusterWidth*SigmaY;
1065  float CloudDown = CloudCenterY - ClusterWidth*SigmaY;
1066 
1067  // Define 2D cloud limit points
1068  LocalPoint PointRightUp = LocalPoint(CloudRight,CloudUp);
1069  LocalPoint PointLeftDown = LocalPoint(CloudLeft,CloudDown);
1070 
1071  // This points can be located outside the sensor area.
1072  // The conversion to measurement point does not check for that
1073  // so the returned pixel index might be wrong (outside range).
1074  // We rely on the limits check below to fix this.
1075  // But remember whatever we do here THE CHARGE OUTSIDE THE ACTIVE
1076  // PIXEL AREA IS LOST, it should not be collected.
1077 
1078  // Convert the 2D points to pixel indices
1079  MeasurementPoint mp = topol->measurementPosition(PointRightUp ); //OK
1080 
1081  int IPixRightUpX = int( floor( mp.x()));
1082  int IPixRightUpY = int( floor( mp.y()));
1083 
1084 #ifdef TP_DEBUG
1085  LogDebug ("Pixel Digitizer") << " right-up " << PointRightUp << " "
1086  << mp.x() << " " << mp.y() << " "
1087  << IPixRightUpX << " " << IPixRightUpY ;
1088 #endif
1089 
1090  mp = topol->measurementPosition(PointLeftDown ); //OK
1091 
1092  int IPixLeftDownX = int( floor( mp.x()));
1093  int IPixLeftDownY = int( floor( mp.y()));
1094 
1095 #ifdef TP_DEBUG
1096  LogDebug ("Pixel Digitizer") << " left-down " << PointLeftDown << " "
1097  << mp.x() << " " << mp.y() << " "
1098  << IPixLeftDownX << " " << IPixLeftDownY ;
1099 #endif
1100 
1101  // Check detector limits to correct for pixels outside range.
1102  int numColumns = topol->ncolumns(); // det module number of cols&rows
1103  int numRows = topol->nrows();
1104 
1105  IPixRightUpX = numRows>IPixRightUpX ? IPixRightUpX : numRows-1 ;
1106  IPixRightUpY = numColumns>IPixRightUpY ? IPixRightUpY : numColumns-1 ;
1107  IPixLeftDownX = 0<IPixLeftDownX ? IPixLeftDownX : 0 ;
1108  IPixLeftDownY = 0<IPixLeftDownY ? IPixLeftDownY : 0 ;
1109 
1110  x.clear(); // clear temporary integration array
1111  y.clear();
1112 
1113  // First integrate charge strips in x
1114  int ix; // TT for compatibility
1115  for (ix=IPixLeftDownX; ix<=IPixRightUpX; ix++) { // loop over x index
1116  float xUB, xLB, UpperBound, LowerBound;
1117 
1118  // Why is set to 0 if ix=0, does it meen that we accept charge
1119  // outside the sensor? CHeck How it was done in ORCA?
1120  //if(ix == 0) LowerBound = 0.;
1121  if(ix == 0 || SigmaX==0. ) // skip for surface segemnts
1122  LowerBound = 0.;
1123  else {
1124  mp = MeasurementPoint( float(ix), 0.0);
1125  xLB = topol->localPosition(mp).x();
1126  LowerBound = 1-calcQ((xLB-CloudCenterX)/SigmaX);
1127  }
1128 
1129  if(ix == numRows-1 || SigmaX==0. )
1130  UpperBound = 1.;
1131  else {
1132  mp = MeasurementPoint( float(ix+1), 0.0);
1133  xUB = topol->localPosition(mp).x();
1134  UpperBound = 1. - calcQ((xUB-CloudCenterX)/SigmaX);
1135  }
1136 
1137  float TotalIntegrationRange = UpperBound - LowerBound; // get strip
1138  x[ix] = TotalIntegrationRange; // save strip integral
1139  //if(SigmaX==0 || SigmaY==0)
1140  //cout<<TotalIntegrationRange<<" "<<ix<<std::endl;
1141 
1142  }
1143 
1144  // Now integrate strips in y
1145  int iy; // TT for compatibility
1146  for (iy=IPixLeftDownY; iy<=IPixRightUpY; iy++) { //loope over y ind
1147  float yUB, yLB, UpperBound, LowerBound;
1148 
1149  if(iy == 0 || SigmaY==0.)
1150  LowerBound = 0.;
1151  else {
1152  mp = MeasurementPoint( 0.0, float(iy) );
1153  yLB = topol->localPosition(mp).y();
1154  LowerBound = 1. - calcQ((yLB-CloudCenterY)/SigmaY);
1155  }
1156 
1157  if(iy == numColumns-1 || SigmaY==0. )
1158  UpperBound = 1.;
1159  else {
1160  mp = MeasurementPoint( 0.0, float(iy+1) );
1161  yUB = topol->localPosition(mp).y();
1162  UpperBound = 1. - calcQ((yUB-CloudCenterY)/SigmaY);
1163  }
1164 
1165  float TotalIntegrationRange = UpperBound - LowerBound;
1166  y[iy] = TotalIntegrationRange; // save strip integral
1167  //if(SigmaX==0 || SigmaY==0)
1168  //cout<<TotalIntegrationRange<<" "<<iy<<std::endl;
1169  }
1170 
1171  // Get the 2D charge integrals by folding x and y strips
1172  int chan;
1173  for (ix=IPixLeftDownX; ix<=IPixRightUpX; ix++) { // loop over x index
1174  for (iy=IPixLeftDownY; iy<=IPixRightUpY; iy++) { //loope over y ind
1175 
1176  float ChargeFraction = Charge*x[ix]*y[iy];
1177 
1178  if( ChargeFraction > 0. ) {
1179  chan = PixelDigi::pixelToChannel( ix, iy); // Get index
1180  // Load the amplitude
1181  hit_signal[chan] += ChargeFraction;
1182  } // endif
1183 
1184 
1185  mp = MeasurementPoint( float(ix), float(iy) );
1186  LocalPoint lp = topol->localPosition(mp);
1187  chan = topol->channel(lp);
1188 
1189 #ifdef TP_DEBUG
1190  LogDebug ("Pixel Digitizer")
1191  << " pixel " << ix << " " << iy << " - "<<" "
1192  << chan << " " << ChargeFraction<<" "
1193  << mp.x() << " " << mp.y() <<" "
1194  << lp.x() << " " << lp.y() << " " // givex edge position
1195  << chan; // edge belongs to previous ?
1196 #endif
1197 
1198  } // endfor iy
1199  } //endfor ix
1200 
1201 
1202  // Test conversions (THIS IS FOR TESTING ONLY) comment-out.
1203  // mp = topol->measurementPosition( i->position() ); //OK
1204  // LocalPoint lp = topol->localPosition(mp); //OK
1205  // std::pair<float,float> p = topol->pixel( i->position() ); //OK
1206  // chan = PixelDigi::pixelToChannel( int(p.first), int(p.second));
1207  // std::pair<int,int> ip = PixelDigi::channelToPixel(chan);
1208  // MeasurementPoint mp1 = MeasurementPoint( float(ip.first),
1209  // float(ip.second) );
1210  // LogDebug ("Pixel Digitizer") << " Test "<< mp.x() << " " << mp.y()
1211  // << " "<< lp.x() << " " << lp.y() << " "<<" "
1212  // <<p.first <<" "<<p.second<<" "<<chan<< " "
1213  // <<" " << ip.first << " " << ip.second << " "
1214  // << mp1.x() << " " << mp1.y() << " " //OK
1215  // << topol->localPosition(mp1).x() << " " //OK
1216  // << topol->localPosition(mp1).y() << " "
1217  // << topol->channel( i->position() ); //OK
1218 
1219 
1220  } // loop over charge distributions
1221 
1222  // Fill the global map with all hit pixels from this event
1223 
1224  for ( hit_map_type::const_iterator im = hit_signal.begin();
1225  im != hit_signal.end(); ++im) {
1226  int chan = (*im).first;
1227  theSignal[chan] += (makeDigiSimLinks_ ? Amplitude( (*im).second, &hit, hitIndex, tofBin, (*im).second) : Amplitude( (*im).second, (*im).second) ) ;
1228 
1229 #ifdef TP_DEBUG
1230  std::pair<int,int> ip = PixelDigi::channelToPixel(chan);
1231  LogDebug ("Pixel Digitizer")
1232  << " pixel " << ip.first << " " << ip.second << " "
1233  << theSignal[chan];
1234 #endif
1235  }
1236 
1237 } // end induce_signal
1238 
1239 /***********************************************************************/
1240 
1241 // Build pixels, check threshold, add misscalibration, ...
1242 void SiPixelDigitizerAlgorithm::make_digis(float thePixelThresholdInE,
1243  uint32_t detID,
1244  const PixelGeomDetUnit* pixdet,
1245  std::vector<PixelDigi>& digis,
1246  std::vector<PixelDigiSimLink>& simlinks,
1247  const TrackerTopology *tTopo) const {
1248 
1249 #ifdef TP_DEBUG
1250  LogDebug ("Pixel Digitizer") << " make digis "<<" "
1251  << " pixel threshold FPix" << theThresholdInE_FPix << " "
1252  << " pixel threshold BPix" << theThresholdInE_BPix << " "
1253  << " pixel threshold BPix Layer1" << theThresholdInE_BPix_L1 << " "
1254  << " List pixels passing threshold ";
1255 #endif
1256 
1257  // Loop over hit pixels
1258 
1259  signalMaps::const_iterator it = _signal.find(detID);
1260  if (it == _signal.end()) {
1261  return;
1262  }
1263 
1264  const signal_map_type& theSignal = (*it).second;
1265 
1266  for (signal_map_const_iterator i = theSignal.begin(); i != theSignal.end(); ++i) {
1267 
1268  float signalInElectrons = (*i).second ; // signal in electrons
1269 
1270  // Do the miss calibration for calibration studies only.
1271  //if(doMissCalibrate) signalInElectrons = missCalibrate(signalInElectrons)
1272 
1273  // Do only for pixels above threshold
1274 
1275  if( signalInElectrons >= thePixelThresholdInE) { // check threshold
1276 
1277  int chan = (*i).first; // channel number
1278  std::pair<int,int> ip = PixelDigi::channelToPixel(chan);
1279  int adc=0; // ADC count as integer
1280 
1281  // Do the miss calibration for calibration studies only.
1282  if(doMissCalibrate) {
1283  int row = ip.first; // X in row
1284  int col = ip.second; // Y is in col
1285  adc = int(missCalibrate(detID, pixdet, col, row, signalInElectrons)); //full misscalib.
1286  } else { // Just do a simple electron->adc conversion
1287  adc = int( signalInElectrons / theElectronPerADC ); // calibrate gain
1288  }
1289  adc = std::min(adc, theAdcFullScale); // Check maximum value
1290 // Calculate layerIndex
1292  if(pixdet->subDetector() == GeomDetEnumerators::SubDetector::P2OTB) { // Phase 2 OT Barrel only
1293  // Set to 1 if over the threshold
1294  if (theAdcFullScaleStack==1) {adc=1;}
1295  // Make it a linear fit to the full scale of the normal adc count. Start new adc from 1 not zero.
1297  }
1298  } // Only enter this if the Adc changes for the outer layers
1299 #ifdef TP_DEBUG
1300  LogDebug ("Pixel Digitizer")
1301  << (*i).first << " " << (*i).second << " " << signalInElectrons
1302  << " " << adc << ip.first << " " << ip.second ;
1303 #endif
1304 
1305  // Load digis
1306  digis.emplace_back(ip.first, ip.second, adc);
1307 
1308  if (makeDigiSimLinks_ && (*i).second.hitInfo()!=0) {
1309  //digilink
1310  if((*i).second.trackIds().size()>0){
1311  simlink_map simi;
1312  unsigned int il=0;
1313  for( std::vector<unsigned int>::const_iterator itid = (*i).second.trackIds().begin();
1314  itid != (*i).second.trackIds().end(); ++itid) {
1315  simi[*itid].push_back((*i).second.individualampl()[il]);
1316  il++;
1317  }
1318 
1319  //sum the contribution of the same trackid
1320  for( simlink_map::iterator simiiter=simi.begin();
1321  simiiter!=simi.end();
1322  simiiter++){
1323 
1324  float sum_samechannel=0;
1325  for (unsigned int iii=0;iii<(*simiiter).second.size();iii++){
1326  sum_samechannel+=(*simiiter).second[iii];
1327  }
1328  float fraction=sum_samechannel/(*i).second;
1329  if(fraction>1.) fraction=1.;
1330  simlinks.emplace_back((*i).first, (*simiiter).first, (*i).second.hitIndex(), (*i).second.tofBin(), (*i).second.eventId(), fraction);
1331  }
1332  }
1333  }
1334  }
1335  }
1336 }
1337 
1338 /***********************************************************************/
1339 
1340 // Add electronic noise to pixel charge
1342  float thePixelThreshold,
1343  CLHEP::HepRandomEngine* engine) {
1344 
1345 #ifdef TP_DEBUG
1346  LogDebug ("Pixel Digitizer") << " enter add_noise " << theNoiseInElectrons;
1347 #endif
1348 
1349  uint32_t detID= pixdet->geographicalId().rawId();
1350  signal_map_type& theSignal = _signal[detID];
1351 
1352 
1353  // First add noise to hit pixels
1354  float theSmearedChargeRMS = 0.0;
1355 
1356  for ( signal_map_iterator i = theSignal.begin(); i != theSignal.end(); i++) {
1357 
1359  {
1360  if((*i).second < 3000)
1361  {
1362  theSmearedChargeRMS = 543.6 - (*i).second * 0.093;
1363  } else if((*i).second < 6000){
1364  theSmearedChargeRMS = 307.6 - (*i).second * 0.01;
1365  } else{
1366  theSmearedChargeRMS = -432.4 +(*i).second * 0.123;
1367  }
1368 
1369  // Noise from Vcal smearing:
1370  float noise_ChargeVCALSmearing = theSmearedChargeRMS * CLHEP::RandGaussQ::shoot(engine, 0., 1.);
1371  // Noise from full readout:
1372  float noise = CLHEP::RandGaussQ::shoot(engine, 0., theReadoutNoise);
1373 
1374  if(((*i).second + Amplitude(noise+noise_ChargeVCALSmearing, -1.)) < 0. ) {
1375  (*i).second.set(0);}
1376  else{
1377  (*i).second +=Amplitude(noise+noise_ChargeVCALSmearing, -1.);
1378  }
1379 
1380  } // End if addChargeVCalSmearing
1381  else
1382  {
1383  // Noise: ONLY full READOUT Noise.
1384  // Use here the FULL readout noise, including TBM,ALT,AOH,OPT-REC.
1385  float noise = CLHEP::RandGaussQ::shoot(engine, 0., theReadoutNoise);
1386 
1387  if(((*i).second + Amplitude(noise, -1.)) < 0. ) {
1388  (*i).second.set(0);}
1389  else{
1390  (*i).second +=Amplitude(noise, -1.);
1391  }
1392  } // end if only Noise from full readout
1393 
1394  }
1395 
1396  if(!addNoisyPixels) // Option to skip noise in non-hit pixels
1397  return;
1398 
1399  const PixelTopology* topol=&pixdet->specificTopology();
1400  int numColumns = topol->ncolumns(); // det module number of cols&rows
1401  int numRows = topol->nrows();
1402 
1403  // Add noise on non-hit pixels
1404  // Use here the pixel noise
1405  int numberOfPixels = (numRows * numColumns);
1406  std::map<int,float, std::less<int> > otherPixels;
1407  std::map<int,float, std::less<int> >::iterator mapI;
1408 
1409  theNoiser->generate(numberOfPixels,
1410  thePixelThreshold, //thr. in un. of nois
1411  theNoiseInElectrons, // noise in elec.
1412  otherPixels,
1413  engine );
1414 
1415 #ifdef TP_DEBUG
1416  LogDebug ("Pixel Digitizer")
1417  << " Add noisy pixels " << numRows << " "
1418  << numColumns << " " << theNoiseInElectrons << " "
1419  << theThresholdInE_FPix << theThresholdInE_BPix <<" "<< numberOfPixels<<" "
1420  << otherPixels.size() ;
1421 #endif
1422 
1423  // Add noisy pixels
1424  for (mapI = otherPixels.begin(); mapI!= otherPixels.end(); mapI++) {
1425  int iy = ((*mapI).first) / numRows;
1426  int ix = ((*mapI).first) - (iy*numRows);
1427 
1428  // Keep for a while for testing.
1429  if( iy < 0 || iy > (numColumns-1) )
1430  LogWarning ("Pixel Geometry") << " error in iy " << iy ;
1431  if( ix < 0 || ix > (numRows-1) )
1432  LogWarning ("Pixel Geometry") << " error in ix " << ix ;
1433 
1434  int chan = PixelDigi::pixelToChannel(ix, iy);
1435 
1436 #ifdef TP_DEBUG
1437  LogDebug ("Pixel Digitizer")
1438  <<" Storing noise = " << (*mapI).first << " " << (*mapI).second
1439  << " " << ix << " " << iy << " " << chan ;
1440 #endif
1441 
1442  if(theSignal[chan] == 0){
1443  // float noise = float( (*mapI).second );
1444  int noise=int( (*mapI).second );
1445  theSignal[chan] = Amplitude (noise, -1.);
1446  }
1447  }
1448 }
1449 
1450 /***********************************************************************/
1451 
1452 // Simulate the readout inefficiencies.
1453 // Delete a selected number of single pixels, dcols and rocs.
1455  const PixelGeomDetUnit* pixdet,
1456  const TrackerTopology *tTopo,
1457  CLHEP::HepRandomEngine* engine) {
1458 
1459  uint32_t detID= pixdet->geographicalId().rawId();
1460  signal_map_type& theSignal = _signal[detID];
1461  const PixelTopology* topol=&pixdet->specificTopology();
1462  int numColumns = topol->ncolumns(); // det module number of cols&rows
1463  int numRows = topol->nrows();
1464 
1465  // Predefined efficiencies
1466  double pixelEfficiency = 1.0;
1467  double columnEfficiency = 1.0;
1468  double chipEfficiency = 1.0;
1469 
1470  if (eff.FromConfig) {
1471  // setup the chip indices conversion
1473  pixdet->subDetector()==GeomDetEnumerators::SubDetector::P1PXB){// barrel layers
1474  int layerIndex=tTopo->layer(detID);
1475  pixelEfficiency = eff.thePixelEfficiency[layerIndex-1];
1476  columnEfficiency = eff.thePixelColEfficiency[layerIndex-1];
1477  chipEfficiency = eff.thePixelChipEfficiency[layerIndex-1];
1478  //std::cout <<"Using BPix columnEfficiency = "<<columnEfficiency<< " for layer = "<<layerIndex <<"\n";
1479  // This should never happen, but only check if it is not an upgrade geometry
1480  if (NumberOfBarrelLayers==3){
1481  if(numColumns>416) LogWarning ("Pixel Geometry") <<" wrong columns in barrel "<<numColumns;
1482  if(numRows>160) LogWarning ("Pixel Geometry") <<" wrong rows in barrel "<<numRows;
1483 
1484  int ladder=tTopo->pxbLadder(detID);
1485  int module=tTopo->pxbModule(detID);
1486  if (module<=4) module=5-module;
1487  else module-=4;
1488 
1489  columnEfficiency *= eff.theLadderEfficiency_BPix[layerIndex-1][ladder-1]*eff.theModuleEfficiency_BPix[layerIndex-1][module-1]*eff.pu_scale[layerIndex-1];
1490  }
1493  pixdet->subDetector()==GeomDetEnumerators::SubDetector::P2PXEC){ // forward disks
1494 
1495  unsigned int diskIndex=tTopo->layer(detID)+eff.FPixIndex; // Use diskIndex-1 later to stay consistent with BPix
1496  unsigned int panelIndex=tTopo->pxfPanel(detID);
1497  unsigned int moduleIndex=tTopo->pxfModule(detID);
1498  //if (eff.FPixIndex>diskIndex-1){throw cms::Exception("Configuration") <<"SiPixelDigitizer is using the wrong efficiency value. index = "
1499  // <<diskIndex-1<<" , MinIndex = "<<eff.FPixIndex<<" ... "<<tTopo->pxfDisk(detID);}
1500  pixelEfficiency = eff.thePixelEfficiency[diskIndex-1];
1501  columnEfficiency = eff.thePixelColEfficiency[diskIndex-1];
1502  chipEfficiency = eff.thePixelChipEfficiency[diskIndex-1];
1503  //std::cout <<"Using FPix columnEfficiency = "<<columnEfficiency<<" for Disk = "<< tTopo->pxfDisk(detID)<<"\n";
1504  // Sometimes the forward pixels have wrong size,
1505  // this crashes the index conversion, so exit, but only check if it is not an upgrade geometry
1506  if (NumberOfBarrelLayers==3){ // whether it is the present or the phase 1 detector can be checked using GeomDetEnumerators::SubDetector
1507  if(numColumns>260 || numRows>160) {
1508  if(numColumns>260) LogWarning ("Pixel Geometry") <<" wrong columns in endcaps "<<numColumns;
1509  if(numRows>160) LogWarning ("Pixel Geometry") <<" wrong rows in endcaps "<<numRows;
1510  return;
1511  }
1512  if ((panelIndex==1 && (moduleIndex==1 || moduleIndex==2)) || (panelIndex==2 && moduleIndex==1)) { //inner modules
1513  columnEfficiency*=eff.theInnerEfficiency_FPix[diskIndex-1]*eff.pu_scale[3];
1514  } else { //outer modules
1515  columnEfficiency*=eff.theOuterEfficiency_FPix[diskIndex-1]*eff.pu_scale[4];
1516  }
1517  } // current detector, forward
1519  // If phase 2 outer tracker, hardcoded values as they have been so far
1520  pixelEfficiency = 0.999;
1521  columnEfficiency = 0.999;
1522  chipEfficiency = 0.999;
1523  } // if barrel/forward
1524  } else { // Load precomputed factors from Database
1525  pixelEfficiency = eff.PixelGeomFactors.at(detID);
1526  columnEfficiency = eff.ColGeomFactors.at(detID)*eff.pu_scale[eff.iPU.at(detID)];
1527  chipEfficiency = eff.ChipGeomFactors.at(detID);
1528  }
1529 
1530 #ifdef TP_DEBUG
1531  LogDebug ("Pixel Digitizer") << " enter pixel_inefficiency " << pixelEfficiency << " "
1532  << columnEfficiency << " " << chipEfficiency;
1533 #endif
1534 
1535  // Initilize the index converter
1536  //PixelIndices indexConverter(numColumns,numRows);
1537  std::auto_ptr<PixelIndices> pIndexConverter(new PixelIndices(numColumns,numRows));
1538 
1539  int chipIndex = 0;
1540  int rowROC = 0;
1541  int colROC = 0;
1542  std::map<int, int, std::less<int> >chips, columns;
1543  std::map<int, int, std::less<int> >::iterator iter;
1544 
1545  // Find out the number of columns and rocs hits
1546  // Loop over hit pixels, amplitude in electrons, channel = coded row,col
1547  for (signal_map_const_iterator i = theSignal.begin(); i != theSignal.end(); ++i) {
1548 
1549  int chan = i->first;
1550  std::pair<int,int> ip = PixelDigi::channelToPixel(chan);
1551  int row = ip.first; // X in row
1552  int col = ip.second; // Y is in col
1553  //transform to ROC index coordinates
1554  pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
1555  int dColInChip = pIndexConverter->DColumn(colROC); // get ROC dcol from ROC col
1556  //dcol in mod
1557  int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
1558 
1559  chips[chipIndex]++;
1560  columns[dColInDet]++;
1561  }
1562 
1563  // Delete some ROC hits.
1564  for ( iter = chips.begin(); iter != chips.end() ; iter++ ) {
1565  //float rand = RandFlat::shoot();
1566  float rand = CLHEP::RandFlat::shoot(engine);
1567  if( rand > chipEfficiency ) chips[iter->first]=0;
1568  }
1569 
1570  // Delete some Dcol hits.
1571  for ( iter = columns.begin(); iter != columns.end() ; iter++ ) {
1572  //float rand = RandFlat::shoot();
1573  float rand = CLHEP::RandFlat::shoot(engine);
1574  if( rand > columnEfficiency ) columns[iter->first]=0;
1575  }
1576 
1577  // Now loop again over pixels to kill some of them.
1578  // Loop over hit pixels, amplitude in electrons, channel = coded row,col
1579  for(signal_map_iterator i = theSignal.begin();i != theSignal.end(); ++i) {
1580 
1581  // int chan = i->first;
1582  std::pair<int,int> ip = PixelDigi::channelToPixel(i->first);//get pixel pos
1583  int row = ip.first; // X in row
1584  int col = ip.second; // Y is in col
1585  //transform to ROC index coordinates
1586  pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
1587  int dColInChip = pIndexConverter->DColumn(colROC); //get ROC dcol from ROC col
1588  //dcol in mod
1589  int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
1590 
1591  //float rand = RandFlat::shoot();
1592  float rand = CLHEP::RandFlat::shoot(engine);
1593  if( chips[chipIndex]==0 || columns[dColInDet]==0
1594  || rand>pixelEfficiency ) {
1595  // make pixel amplitude =0, pixel will be lost at clusterization
1596  i->second.set(0.); // reset amplitude,
1597  } // end if
1598 
1599  } // end pixel loop
1600 } // end pixel_indefficiency
1601 
1602 //***************************************************************************************
1603 // Simulate pixel aging with an exponential function
1604 //**************************************************************************************
1605 
1607  const PixelGeomDetUnit *pixdet,
1608  const TrackerTopology *tTopo) const {
1609 
1610  uint32_t detID= pixdet->geographicalId().rawId();
1611 
1612 
1613  // Predefined damage parameter (no aging)
1614  float pseudoRadDamage = 0.0;
1615 
1616  // setup the chip indices conversion
1618  pixdet->subDetector() == GeomDetEnumerators::SubDetector::P1PXB){// barrel layers
1619  int layerIndex=tTopo->layer(detID);
1620 
1621  pseudoRadDamage = aging.thePixelPseudoRadDamage[layerIndex-1];
1622 
1623  // std::cout << "pixel_aging: " << std::endl;
1624  // std::cout << "Subid " << Subid << " layerIndex " << layerIndex << " ladder " << tTopo->pxbLadder(detID) << " module " << tTopo->pxbModule(detID) << std::endl;
1625 
1628  pixdet->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC) { // forward disks
1629  unsigned int diskIndex=tTopo->layer(detID)+aging.FPixIndex; // Use diskIndex-1 later to stay consistent with BPix
1630 
1631  pseudoRadDamage = aging.thePixelPseudoRadDamage[diskIndex-1];
1632 
1633  // std::cout << "pixel_aging: " << std::endl;
1634  // std::cout << "Subid " << Subid << " diskIndex " << diskIndex << std::endl;
1636  // if phase 2 OT hardcoded value as it has always been
1637  pseudoRadDamage = 0.;
1638  } // if barrel/forward
1639 
1640  // std::cout << " pseudoRadDamage " << pseudoRadDamage << std::endl;
1641  // std::cout << " end pixel_aging " << std::endl;
1642 
1643  return pseudoRadDamage;
1644 #ifdef TP_DEBUG
1645  LogDebug ("Pixel Digitizer") << " enter pixel_aging " << pseudoRadDamage;
1646 #endif
1647 
1648 }
1649 
1650 //***********************************************************************
1651 
1652 // Fluctuate the gain and offset for the amplitude calibration
1653 // Use gaussian smearing.
1654 //float SiPixelDigitizerAlgorithm::missCalibrate(const float amp) const {
1655  //float gain = RandGaussQ::shoot(1.,theGainSmearing);
1656  //float offset = RandGaussQ::shoot(0.,theOffsetSmearing);
1657  //float newAmp = amp * gain + offset;
1658  // More complex misscalibration
1659 float SiPixelDigitizerAlgorithm::missCalibrate(uint32_t detID, const PixelGeomDetUnit* pixdet, int col,int row,
1660  const float signalInElectrons) const {
1661  // Central values
1662  //const float p0=0.00352, p1=0.868, p2=112., p3=113.; // pix(0,0,0)
1663  // const float p0=0.00382, p1=0.886, p2=112.7, p3=113.0; // average roc=0
1664  //const float p0=0.00492, p1=1.998, p2=90.6, p3=134.1; // average roc=6
1665  // Smeared (rms)
1666  //const float s0=0.00020, s1=0.051, s2=5.4, s3=4.4; // average roc=0
1667  //const float s0=0.00015, s1=0.043, s2=3.2, s3=3.1; // col average roc=0
1668 
1669  // Make 2 sets of parameters for Fpix and BPIx:
1670 
1671  float p0=0.0;
1672  float p1=0.0;
1673  float p2=0.0;
1674  float p3=0.0;
1675 
1676  if(pixdet->type().isTrackerPixel() && pixdet->type().isBarrel()){// barrel layers
1677  p0 = BPix_p0;
1678  p1 = BPix_p1;
1679  p2 = BPix_p2;
1680  p3 = BPix_p3;
1681  } else if(pixdet->type().isTrackerPixel()) {// forward disks
1682  p0 = FPix_p0;
1683  p1 = FPix_p1;
1684  p2 = FPix_p2;
1685  p3 = FPix_p3;
1686  } else {
1687  throw cms::Exception("NotAPixelGeomDetUnit") << "Not a pixel geomdet unit" << detID;
1688  }
1689 
1690  // const float electronsPerVCAL = 65.5; // our present VCAL calibration (feb 2009)
1691  // const float electronsPerVCAL_Offset = -414.0; // our present VCAL calibration (feb 2009)
1692  float newAmp = 0.; //Modified signal
1693 
1694  // Convert electrons to VCAL units
1695  float signal = (signalInElectrons-electronsPerVCAL_Offset)/electronsPerVCAL;
1696 
1697  // Simulate the analog response with fixed parametrization
1698  newAmp = p3 + p2 * tanh(p0*signal - p1);
1699 
1700 
1701  // Use the pixel-by-pixel calibrations
1702  //transform to ROC index coordinates
1703  //int chipIndex=0, colROC=0, rowROC=0;
1704  //std::auto_ptr<PixelIndices> pIndexConverter(new PixelIndices(numColumns,numRows));
1705  //pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
1706 
1707  // Use calibration from a file
1708  //int chanROC = PixelIndices::pixelToChannelROC(rowROC,colROC); // use ROC coordinates
1709  //float pp0=0, pp1=0,pp2=0,pp3=0;
1710  //map<int,CalParameters,std::less<int> >::const_iterator it=calmap.find(chanROC);
1711  //CalParameters y = (*it).second;
1712  //pp0 = y.p0;
1713  //pp1 = y.p1;
1714  //pp2 = y.p2;
1715  //pp3 = y.p3;
1716 
1717  //
1718  // Use random smearing
1719  // Randomize the pixel response
1720  //float pp0 = RandGaussQ::shoot(p0,s0);
1721  //float pp1 = RandGaussQ::shoot(p1,s1);
1722  //float pp2 = RandGaussQ::shoot(p2,s2);
1723  //float pp3 = RandGaussQ::shoot(p3,s3);
1724 
1725  //newAmp = pp3 + pp2 * tanh(pp0*signal - pp1); // Final signal
1726 
1727  //cout<<" misscalibrate "<<col<<" "<<row<<" "<<chipIndex<<" "<<colROC<<" "
1728  // <<rowROC<<" "<<signalInElectrons<<" "<<signal<<" "<<newAmp<<" "
1729  // <<(signalInElectrons/theElectronPerADC)<<std::endl;
1730 
1731  return newAmp;
1732 }
1733 //******************************************************************************
1734 
1735 // Set the drift direction accoring to the Bfield in local det-unit frame
1736 // Works for both barrel and forward pixels.
1737 // Replace the sign convention to fit M.Swartz's formulaes.
1738 // Configurations for barrel and foward pixels possess different tanLorentzAngleperTesla
1739 // parameter value
1740 
1742  const GlobalVector& bfield,
1743  const DetId& detId) const {
1744  Frame detFrame(pixdet->surface().position(),pixdet->surface().rotation());
1745  LocalVector Bfield=detFrame.toLocal(bfield);
1746 
1747  float alpha2_FPix;
1748  float alpha2_BPix;
1749  float alpha2;
1750 
1751  //float dir_x = -tanLorentzAnglePerTesla * Bfield.y();
1752  //float dir_y = +tanLorentzAnglePerTesla * Bfield.x();
1753  //float dir_z = -1.; // E field always in z direction, so electrons go to -z
1754  // The dir_z has to be +/- 1. !
1755  // LocalVector theDriftDirection = LocalVector(dir_x,dir_y,dir_z);
1756 
1757  float dir_x = 0.0;
1758  float dir_y = 0.0;
1759  float dir_z = 0.0;
1760  float scale = 0.0;
1761 
1762  uint32_t detID= pixdet->geographicalId().rawId();
1763 
1764 
1765  // Read Lorentz angle from cfg file:**************************************************************
1766 
1767  if(!use_LorentzAngle_DB_){
1768 
1769  if( alpha2Order) {
1772  }else {
1773  alpha2_FPix = 0.0;
1774  alpha2_BPix = 0.0;
1775  }
1776 
1777  if(pixdet->type().isTrackerPixel() && pixdet->type().isBarrel()){// barrel layers
1778  dir_x = -( tanLorentzAnglePerTesla_BPix * Bfield.y() + alpha2_BPix* Bfield.z()* Bfield.x() );
1779  dir_y = +( tanLorentzAnglePerTesla_BPix * Bfield.x() - alpha2_BPix* Bfield.z()* Bfield.y() );
1780  dir_z = -(1 + alpha2_BPix* Bfield.z()*Bfield.z() );
1781  scale = -dir_z;
1782  } else if (pixdet->type().isTrackerPixel()) {// forward disks
1783  dir_x = -( tanLorentzAnglePerTesla_FPix * Bfield.y() + alpha2_FPix* Bfield.z()* Bfield.x() );
1784  dir_y = +( tanLorentzAnglePerTesla_FPix * Bfield.x() - alpha2_FPix* Bfield.z()* Bfield.y() );
1785  dir_z = -(1 + alpha2_FPix* Bfield.z()*Bfield.z() );
1786  scale = -dir_z;
1787  } else {
1788  throw cms::Exception("NotAPixelGeomDetUnit") << "Not a pixel geomdet unit" << detID;
1789  }
1790  } // end: Read LA from cfg file.
1791 
1792  //Read Lorentz angle from DB:********************************************************************
1794  float lorentzAngle = SiPixelLorentzAngle_->getLorentzAngle(detId);
1795  alpha2 = lorentzAngle * lorentzAngle;
1796  //std::cout << "detID is: "<< it->first <<"The LA per tesla is: "<< it->second << std::std::endl;
1797  dir_x = -( lorentzAngle * Bfield.y() + alpha2 * Bfield.z()* Bfield.x() );
1798  dir_y = +( lorentzAngle * Bfield.x() - alpha2 * Bfield.z()* Bfield.y() );
1799  dir_z = -(1 + alpha2 * Bfield.z()*Bfield.z() );
1800  scale = -dir_z;
1801  }// end: Read LA from DataBase.
1802 
1803  LocalVector theDriftDirection = LocalVector(dir_x/scale, dir_y/scale, dir_z/scale );
1804 
1805 #ifdef TP_DEBUG
1806  LogDebug ("Pixel Digitizer") << " The drift direction in local coordinate is "
1807  << theDriftDirection ;
1808 #endif
1809 
1810  return theDriftDirection;
1811 }
1812 
1813 //****************************************************************************************************
1814 
1816 
1817  signal_map_type& theSignal = _signal[detID];
1818 
1819  // Loop over hit pixels, amplitude in electrons, channel = coded row,col
1820  for(signal_map_iterator i = theSignal.begin();i != theSignal.end(); ++i) {
1821 
1822  // int chan = i->first;
1823  std::pair<int,int> ip = PixelDigi::channelToPixel(i->first);//get pixel pos
1824  int row = ip.first; // X in row
1825  int col = ip.second; // Y is in col
1826  //transform to ROC index coordinates
1827  if(theSiPixelGainCalibrationService_->isDead(detID, col, row)){
1828  // std::cout << "now in isdead check, row " << detID << " " << col << "," << row << std::std::endl;
1829  // make pixel amplitude =0, pixel will be lost at clusterization
1830  i->second.set(0.); // reset amplitude,
1831  } // end if
1832  } // end pixel loop
1833 } // end pixel_indefficiency
1834 
1835 
1836 //****************************************************************************************************
1837 
1839 
1840  bool isbad=false;
1841 
1842  Parameters::const_iterator itDeadModules=DeadModules.begin();
1843 
1844  int detid = detID;
1845  for(; itDeadModules != DeadModules.end(); ++itDeadModules){
1846  int Dead_detID = itDeadModules->getParameter<int>("Dead_detID");
1847  if(detid == Dead_detID){
1848  isbad=true;
1849  break;
1850  }
1851  }
1852 
1853  if(!isbad)
1854  return;
1855 
1856  signal_map_type& theSignal = _signal[detID];
1857 
1858  std::string Module = itDeadModules->getParameter<std::string>("Module");
1859 
1860  if(Module=="whole"){
1861  for(signal_map_iterator i = theSignal.begin();i != theSignal.end(); ++i) {
1862  i->second.set(0.); // reset amplitude
1863  }
1864  }
1865 
1866  for(signal_map_iterator i = theSignal.begin();i != theSignal.end(); ++i) {
1867  std::pair<int,int> ip = PixelDigi::channelToPixel(i->first);//get pixel pos
1868 
1869  if(Module=="tbmA" && ip.first>=80 && ip.first<=159){
1870  i->second.set(0.);
1871  }
1872 
1873  if( Module=="tbmB" && ip.first<=79){
1874  i->second.set(0.);
1875  }
1876  }
1877 }
1878 //****************************************************************************************************
1880 // Not SLHC safe for now
1881 
1882  bool isbad=false;
1883 
1884  std::vector<SiPixelQuality::disabledModuleType>disabledModules = SiPixelBadModule_->getBadComponentList();
1885 
1887 
1888  for (size_t id=0;id<disabledModules.size();id++)
1889  {
1890  if(detID==disabledModules[id].DetID){
1891  isbad=true;
1892  badmodule = disabledModules[id];
1893  break;
1894  }
1895  }
1896 
1897  if(!isbad)
1898  return;
1899 
1900  signal_map_type& theSignal = _signal[detID];
1901 
1902  //std::cout<<"Hit in: "<< detID <<" errorType "<< badmodule.errorType<<" BadRocs="<<std::hex<<SiPixelBadModule_->getBadRocs(detID)<<dec<<" "<<std::endl;
1903  if(badmodule.errorType == 0){ // this is a whole dead module.
1904 
1905  for(signal_map_iterator i = theSignal.begin();i != theSignal.end(); ++i) {
1906  i->second.set(0.); // reset amplitude
1907  }
1908  }
1909  else { // all other module types: half-modules and single ROCs.
1910  // Get Bad ROC position:
1911  //follow the example of getBadRocPositions in CondFormats/SiPixelObjects/src/SiPixelQuality.cc
1912  std::vector<GlobalPixel> badrocpositions (0);
1913  for(unsigned int j = 0; j < 16; j++){
1914  if(SiPixelBadModule_->IsRocBad(detID, j) == true){
1915 
1916  std::vector<CablingPathToDetUnit> path = map_.product()->pathToDetUnit(detID);
1917  typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
1918  for (IT it = path.begin(); it != path.end(); ++it) {
1919  const PixelROC* myroc = map_.product()->findItem(*it);
1920  if( myroc->idInDetUnit() == j) {
1921  LocalPixel::RocRowCol local = { 39, 25}; //corresponding to center of ROC row, col
1922  GlobalPixel global = myroc->toGlobal( LocalPixel(local) );
1923  badrocpositions.push_back(global);
1924  break;
1925  }
1926  }
1927  }
1928  }// end of getBadRocPositions
1929 
1930 
1931  for(signal_map_iterator i = theSignal.begin();i != theSignal.end(); ++i) {
1932  std::pair<int,int> ip = PixelDigi::channelToPixel(i->first);//get pixel pos
1933 
1934  for(std::vector<GlobalPixel>::const_iterator it = badrocpositions.begin(); it != badrocpositions.end(); ++it){
1935  if(it->row >= 80 && ip.first >= 80 ){
1936  if((fabs(ip.second - it->col) < 26) ) {i->second.set(0.);}
1937  else if(it->row==120 && ip.second-it->col==26){i->second.set(0.);}
1938  else if(it->row==119 && it->col-ip.second==26){i->second.set(0.);}
1939  }
1940  else if(it->row < 80 && ip.first < 80 ){
1941  if((fabs(ip.second - it->col) < 26) ){i->second.set(0.);}
1942  else if(it->row==40 && ip.second-it->col==26){i->second.set(0.);}
1943  else if(it->row==39 && it->col-ip.second==26){i->second.set(0.);}
1944  }
1945  }
1946  }
1947  }
1948 }
1949 
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogDebug(id)
void init(const edm::EventSetup &es)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
T getParameter(std::string const &) const
Map map_
int i
Definition: DBlmapReader.cc:9
void pixel_inefficiency_db(uint32_t detID)
signal_map_type::const_iterator signal_map_const_iterator
Local3DVector LocalVector
Definition: LocalVector.h:12
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:72
edm::ESHandle< SiPixelFedCablingMap > map_
void init_DynIneffDB(const edm::EventSetup &, const unsigned int &)
bool isBarrel() const
Definition: GeomDetType.cc:13
T y() const
Definition: PV2DBase.h:46
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_
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
LocalVector DriftDirection(const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const DetId &detId) const
SiPixelDigitizerAlgorithm(const edm::ParameterSet &conf)
virtual int ncolumns() const =0
const std::vector< float > & getMix_TrueInteractions() const
const std::unique_ptr< SiG4UniversalFluctuation > fluctuate
PixelEfficiencies(const edm::ParameterSet &conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const std::vector< int > & getMix_bunchCrossing() const
virtual const GeomDetType & type() const override
unsigned int pxbLadder(const DetId &id) const
T y() const
Definition: PV3DBase.h:63
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual int nrows() const =0
const Bounds & bounds() const
Definition: Surface.h:120
std::vector< std::vector< double > > thePUEfficiency
unsigned int pxbModule(const DetId &id) const
#define Module(md)
Definition: vmac.h:201
int ii
Definition: cuy.py:588
edm::ESHandle< TrackerGeometry > geom_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
identify pixel inside single ROC
Definition: LocalPixel.h:7
void make_digis(float thePixelThresholdInE, uint32_t detID, const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo) const
static int pixelToChannel(int row, int col)
Definition: PixelDigi.h:68
global coordinates (row and column in DetUnit, as in PixelDigi)
Definition: GlobalPixel.h:6
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual float thickness() const =0
void induce_signal(const PSimHit &hit, const size_t hitIndex, const unsigned int tofBin, const PixelGeomDetUnit *pixdet, const std::vector< SignalPoint > &collection_points)
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
Local3DPoint exitPoint() const
Exit point in the local Det frame.
Definition: PSimHit.h:38
T mag() const
Definition: PV3DBase.h:67
float missCalibrate(uint32_t detID, const PixelGeomDetUnit *pixdet, int col, int row, float amp) const
const std::map< int, CalParameters, std::less< int > > calmap
float pixel_aging(const PixelAging &aging, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo) const
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
static int pixelToChannelROC(const int rowROC, const int colROC)
Definition: PixelIndices.h:250
static std::pair< int, int > channelToPixelROC(const int chan)
Definition: PixelIndices.h:253
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:39
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
virtual int channel(const LocalPoint &p) const =0
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< LinkConnSpec >::const_iterator IT
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:63
bool isTrackerPixel() const
Definition: GeomDetType.cc:29
signal_map_type::iterator signal_map_iterator
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
double p2[4]
Definition: TauolaWrapper.h:90
edm::ESHandle< SiPixelLorentzAngle > SiPixelLorentzAngle_
unsigned int pxfModule(const DetId &id) const
tuple par0
Definition: fitWZ.py:51
virtual std::pair< float, float > pitch() const =0
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:18
std::map< int, Amplitude, std::less< int > > signal_map_type
edm::ESHandle< SiPixelQuality > SiPixelBadModule_
void primary_ionization(const PSimHit &hit, std::vector< EnergyDepositUnit > &ionization_points, CLHEP::HepRandomEngine *) const
void init_from_db(const edm::ESHandle< TrackerGeometry > &, const edm::ESHandle< SiPixelDynamicInefficiency > &)
void calculateInstlumiFactor(PileupMixingContent *puInfo)
const T & get() const
Definition: EventSetup.h:56
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:62
tuple pid
Definition: sysUtil.py:22
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T const * product() const
Definition: ESHandle.h:86
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 *)
row and collumn in ROC representation
Definition: LocalPixel.h:15
edm::ESHandle< SiPixelDynamicInefficiency > SiPixelDynamicInefficiency_
unsigned int layer(const DetId &id) const
bool matches(const DetId &, const DetId &, const std::vector< uint32_t > &)
std::vector< edm::ParameterSet > Parameters
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:75
int particleType() const
Definition: PSimHit.h:85
double p1[4]
Definition: TauolaWrapper.h:89
tuple columns
Definition: mps_check.py:210
tuple filename
Definition: lut2db_cfg.py:20
Signal rand(Signal arg)
Definition: vlib.cc:442
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
const RotationType & rotation() const
tuple cout
Definition: gather_cfg.py:145
Definition: sp.h:21
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:1008
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:44
T x() const
Definition: PV2DBase.h:45
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
Definition: vlib.h:208
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:35
tuple size
Write out results.
unsigned int pxfPanel(const DetId &id) const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
unsigned int detUnitId() const
Definition: PSimHit.h:93
const Plane & specificSurface() const
Same as surface(), kept for backward compatibility.
Definition: GeomDet.h:45
GlobalPixel toGlobal(const LocalPixel &loc) const
Definition: PixelROC.h:58
void add_noise(const PixelGeomDetUnit *pixdet, float thePixelThreshold, CLHEP::HepRandomEngine *)
double p3[4]
Definition: TauolaWrapper.h:91
void pixel_inefficiency(const PixelEfficiencies &eff, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)