CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingSiPixelMCDigiWorker.cc
Go to the documentation of this file.
1 // File: DataMixingSiPixelWorker.cc
2 // Description: see DataMixingSiPixelMCDigiWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
8 #include <memory>
16 //
17 //
18 
26 
27 #include "CLHEP/Random/RandFlat.h"
28 
30 
31 
32 using namespace std;
33 
34 namespace edm
35 {
36 
37  // Virtual constructor
38 
39  // DataMixingSiPixelMCDigiWorker::DataMixingSiPixelMCDigiWorker() { }
40 
41  // Constructor
42  DataMixingSiPixelMCDigiWorker::DataMixingSiPixelMCDigiWorker(const edm::ParameterSet& ps, edm::ConsumesCollector && iC) :
43  label_(ps.getParameter<std::string>("Label")),
44  geometryType_(ps.getParameter<std::string>("GeometryType")),
45  // get external parameters:
46  // To account for upgrade geometries do not assume the number
47  // of layers or disks.
48  NumberOfBarrelLayers(ps.exists("NumPixelBarrel")?ps.getParameter<int>("NumPixelBarrel"):3),
49  NumberOfEndcapDisks(ps.exists("NumPixelEndcap")?ps.getParameter<int>("NumPixelEndcap"):2),
50  //theInstLumiScaleFactor(ps.getParameter<double>("theInstLumiScaleFactor")), //For dynamic inefficiency PU scaling
51  //bunchScaleAt25(ps.getParameter<double>("bunchScaleAt25")), //For dynamic inefficiency bunchspace scaling
52  // Control the pixel inefficiency
53  AddPixelInefficiency(ps.getParameter<bool>("AddPixelInefficiency")),
54  pixelEff_(ps, AddPixelInefficiency,NumberOfBarrelLayers,NumberOfEndcapDisks)
55  {
56 
57  // get the subdetector names
58  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
59 
60  // declare the products to produce
61 
62  pixeldigi_collectionSig_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionSig");
63  pixeldigi_collectionPile_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionPile");
64  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
65 
68 
69  // clear local storage for this event
70  SiHitStorage_.clear();
71 
72  FirstCall_ = true;
73 
74  }
75 
76 
77  // Virtual destructor needed.
79  }
80 
81  // Need an event initialization
82 
84 
86  //edm::ESHandle<TrackerTopology> tTopoHand;
87  //iSetup.get<IdealGeometryRecord>().get(tTopoHand);
88  //const TrackerTopology *tTopo=tTopoHand.product();
89  }
90 
91 
92  DataMixingSiPixelMCDigiWorker::PixelEfficiencies::PixelEfficiencies(const edm::ParameterSet& conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks) {
93  // pixel inefficiency
94  // Don't use Hard coded values, read inefficiencies in from DB/python config or don't use any
95  int NumberOfTotLayers = NumberOfBarrelLayers + NumberOfEndcapDisks;
97  if (AddPixelInefficiency){
98  FromConfig =
99  conf.exists("thePixelColEfficiency_BPix1") && conf.exists("thePixelColEfficiency_BPix2") && conf.exists("thePixelColEfficiency_BPix3") &&
100  conf.exists("thePixelColEfficiency_FPix1") && conf.exists("thePixelColEfficiency_FPix2") &&
101  conf.exists("thePixelEfficiency_BPix1") && conf.exists("thePixelEfficiency_BPix2") && conf.exists("thePixelEfficiency_BPix3") &&
102  conf.exists("thePixelEfficiency_FPix1") && conf.exists("thePixelEfficiency_FPix2") &&
103  conf.exists("thePixelChipEfficiency_BPix1") && conf.exists("thePixelChipEfficiency_BPix2") && conf.exists("thePixelChipEfficiency_BPix3") &&
104  conf.exists("thePixelChipEfficiency_FPix1") && conf.exists("thePixelChipEfficiency_FPix2");
105  if (NumberOfBarrelLayers==3) FromConfig = FromConfig && conf.exists("theLadderEfficiency_BPix1") && conf.exists("theLadderEfficiency_BPix2") && conf.exists("theLadderEfficiency_BPix3") &&
106  conf.exists("theModuleEfficiency_BPix1") && conf.exists("theModuleEfficiency_BPix2") && conf.exists("theModuleEfficiency_BPix3") &&
107  conf.exists("thePUEfficiency_BPix1") && conf.exists("thePUEfficiency_BPix2") && conf.exists("thePUEfficiency_BPix3") &&
108  conf.exists("theInnerEfficiency_FPix1") && conf.exists("theInnerEfficiency_FPix2") &&
109  conf.exists("theOuterEfficiency_FPix1") && conf.exists("theOuterEfficiency_FPix2") &&
110  conf.exists("thePUEfficiency_FPix_Inner") && conf.exists("thePUEfficiency_FPix_Outer") &&
111  conf.exists("theInstLumiScaleFactor");
112  if (NumberOfBarrelLayers>=4) FromConfig = FromConfig && conf.exists("thePixelColEfficiency_BPix4") &&
113  conf.exists("thePixelEfficiency_BPix4") && conf.exists("thePixelChipEfficiency_BPix4");
114  if (NumberOfEndcapDisks>=3) FromConfig = FromConfig && conf.exists("thePixelColEfficiency_FPix4") &&
115  conf.exists("thePixelEfficiency_FPix3") && conf.exists("thePixelChipEfficiency_FPix3");
116  if (FromConfig) {
117  LogInfo ("PixelDigitizer ") <<"The PixelDigitizer inefficiency configuration is read from the config file.\n";
118  theInstLumiScaleFactor = conf.getParameter<double>("theInstLumiScaleFactor");
119  int i=0;
120  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix1");
121  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix2");
122  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix3");
123  if (NumberOfBarrelLayers>=4){thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_BPix4");}
124  //
125  i=0;
126  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix1");
127  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix2");
128  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix3");
129  if (NumberOfBarrelLayers>=4){thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_BPix4");}
130  //
131  i=0;
132  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix1");
133  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix2");
134  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix3");
135  if (NumberOfBarrelLayers>=4){thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_BPix4");}
136  //
137  if (NumberOfBarrelLayers==3){
138  i=0;
139  theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix1");
140  theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix2");
141  theLadderEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theLadderEfficiency_BPix3");
142  if ( ((theLadderEfficiency_BPix[0].size()!=20) || (theLadderEfficiency_BPix[1].size()!=32) ||
143  (theLadderEfficiency_BPix[2].size()!=44)) && (NumberOfBarrelLayers==3) )
144  throw cms::Exception("Configuration") << "Wrong ladder number in efficiency config!";
145  //
146  i=0;
147  theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix1");
148  theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix2");
149  theModuleEfficiency_BPix[i++] = conf.getParameter<std::vector<double> >("theModuleEfficiency_BPix3");
150  if ( ((theModuleEfficiency_BPix[0].size()!=4) || (theModuleEfficiency_BPix[1].size()!=4) ||
151  (theModuleEfficiency_BPix[2].size()!=4)) && (NumberOfBarrelLayers==3) )
152  throw cms::Exception("Configuration") << "Wrong module number in efficiency config!";
153  //
154  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix1"));
155  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix2"));
156  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_BPix3"));
157  if ( ((thePUEfficiency[0].size()==0) || (thePUEfficiency[1].size()==0) ||
158  (thePUEfficiency[2].size()==0)) && (NumberOfBarrelLayers==3) )
159  throw cms::Exception("Configuration") << "At least one PU efficiency (BPix) number is needed in efficiency config!";
160  }
161  // The next is needed for Phase2 Tracker studies
162  if (NumberOfBarrelLayers>=5){
163  if (NumberOfTotLayers>20){throw cms::Exception("Configuration") <<"SiPixelDigitizer was given more layers than it can handle";}
164  // For Phase2 tracker layers just set the outermost BPix inefficiency to 99.9% THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
165  for (int j=5 ; j<=NumberOfBarrelLayers ; j++){
166  thePixelColEfficiency[j-1]=0.999;
167  thePixelEfficiency[j-1]=0.999;
168  thePixelChipEfficiency[j-1]=0.999;
169  }
170  }
171  //
172  i=FPixIndex;
173  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix1");
174  thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix2");
175  if (NumberOfEndcapDisks>=3){thePixelColEfficiency[i++] = conf.getParameter<double>("thePixelColEfficiency_FPix3");}
176  i=FPixIndex;
177  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix1");
178  thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix2");
179  if (NumberOfEndcapDisks>=3){thePixelEfficiency[i++] = conf.getParameter<double>("thePixelEfficiency_FPix3");}
180  i=FPixIndex;
181  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix1");
182  thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix2");
183  if (NumberOfEndcapDisks>=3){thePixelChipEfficiency[i++] = conf.getParameter<double>("thePixelChipEfficiency_FPix3");}
184  // The next is needed for Phase2 Tracker studies
185  if (NumberOfEndcapDisks>=4){
186  if (NumberOfTotLayers>20){throw cms::Exception("Configuration") <<"SiPixelDigitizer was given more layers than it can handle";}
187  // For Phase2 tracker layers just set the extra FPix disk inefficiency to 99.9% THESE VALUES ARE HARDCODED ALSO ELSEWHERE IN THIS FILE
188  for (int j=4+FPixIndex ; j<=NumberOfEndcapDisks+NumberOfBarrelLayers ; j++){
189  thePixelColEfficiency[j-1]=0.999;
190  thePixelEfficiency[j-1]=0.999;
191  thePixelChipEfficiency[j-1]=0.999;
192  }
193  }
194  //FPix Dynamic Inefficiency
195  if (NumberOfBarrelLayers==3){
196  i=FPixIndex;
197  theInnerEfficiency_FPix[i++] = conf.getParameter<double>("theInnerEfficiency_FPix1");
198  theInnerEfficiency_FPix[i++] = conf.getParameter<double>("theInnerEfficiency_FPix2");
199  i=FPixIndex;
200  theOuterEfficiency_FPix[i++] = conf.getParameter<double>("theOuterEfficiency_FPix1");
201  theOuterEfficiency_FPix[i++] = conf.getParameter<double>("theOuterEfficiency_FPix2");
202  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_FPix_Inner"));
203  thePUEfficiency.push_back(conf.getParameter<std::vector<double> >("thePUEfficiency_FPix_Outer"));
204  if ( ((thePUEfficiency[3].size()==0) || (thePUEfficiency[4].size()==0)) && (NumberOfEndcapDisks==2) )
205  throw cms::Exception("Configuration") << "At least one (FPix) PU efficiency number is needed in efficiency config!";
206  pu_scale.resize(thePUEfficiency.size());
207  }
208  }
209  else LogInfo ("PixelDigitizer ") <<"The PixelDigitizer inefficiency configuration is read from the database.\n";
210 
211  }
212  // the first "NumberOfBarrelLayers" settings [0],[1], ... , [NumberOfBarrelLayers-1] are for the barrel pixels
213  // the next "NumberOfEndcapDisks" settings [NumberOfBarrelLayers],[NumberOfBarrelLayers+1], ... [NumberOfEndcapDisks+NumberOfBarrelLayers-1]
214 }
215 
216 // Read DynIneff Scale factors from DB
217 void DataMixingSiPixelMCDigiWorker::init_DynIneffDB(const edm::EventSetup& es, const unsigned int& bunchspace){
219  if (bunchspace == 50) es.get<SiPixelDynamicInefficiencyRcd>().get("50ns",SiPixelDynamicInefficiency_);
222  }
223 }
224 
226 
227  theInstLumiScaleFactor = SiPixelDynamicInefficiency->gettheInstLumiScaleFactor();
228  std::map<uint32_t, double> PixelGeomFactorsDB = SiPixelDynamicInefficiency->getPixelGeomFactors();
229  std::map<uint32_t, double> ColGeomFactorsDB = SiPixelDynamicInefficiency->getColGeomFactors();
230  std::map<uint32_t, double> ChipGeomFactorsDB = SiPixelDynamicInefficiency->getChipGeomFactors();
231  std::map<uint32_t, std::vector<double> > PUFactors = SiPixelDynamicInefficiency->getPUFactors();
232  std::vector<uint32_t > DetIdmasks = SiPixelDynamicInefficiency->getDetIdmasks();
233 
234  // Loop on all modules, calculate geometrical scale factors and store in map for easy access
235  for(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
236  if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0) continue;
237  const DetId detid = (*it_module)->geographicalId();
238  uint32_t rawid = detid.rawId();
239  PixelGeomFactors[rawid] = 1;
240  ColGeomFactors[rawid] = 1;
241  ChipGeomFactors[rawid] = 1;
242  for (auto db_factor : PixelGeomFactorsDB) if (matches(detid, DetId(db_factor.first), DetIdmasks)) PixelGeomFactors[rawid] *= db_factor.second;
243  for (auto db_factor : ColGeomFactorsDB) if (matches(detid, DetId(db_factor.first), DetIdmasks)) ColGeomFactors[rawid] *= db_factor.second;
244  for (auto db_factor : ChipGeomFactorsDB) if (matches(detid, DetId(db_factor.first), DetIdmasks)) ChipGeomFactors[rawid] *= db_factor.second;
245  }
246 
247  // piluep scale factors are calculated once per event
248  // therefore vector index is stored in a map for each module that matches to a db_id
249  size_t i=0;
250  for (auto factor : PUFactors) {
251  const DetId db_id = DetId(factor.first);
252  for(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
253  if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0) continue;
254  const DetId detid = (*it_module)->geographicalId();
255  if (!matches(detid, db_id, DetIdmasks)) continue;
256  if (iPU.count(detid.rawId())) {
257  throw cms::Exception("Database")<<"Multiple db_ids match to same module in SiPixelDynamicInefficiency DB Object";
258  } else {
259  iPU[detid.rawId()] = i;
260  }
261  }
262  thePUEfficiency.push_back(factor.second);
263  ++i;
264  }
265  pu_scale.resize(thePUEfficiency.size());
266 }
267 
268 bool DataMixingSiPixelMCDigiWorker::PixelEfficiencies::matches(const DetId& detid, const DetId& db_id, const std::vector<uint32_t >& DetIdmasks) {
269  if (detid.subdetId() != db_id.subdetId()) return false;
270  for (size_t i=0; i<DetIdmasks.size(); ++i) {
271  DetId maskid = DetId(DetIdmasks.at(i));
272  if (maskid.subdetId() != db_id.subdetId()) continue;
273  if ((detid.rawId()&maskid.rawId()) != (db_id.rawId()&maskid.rawId()) &&
274  (db_id.rawId()&maskid.rawId()) != DetId(db_id.det(), db_id.subdetId()).rawId()) return false;
275  }
276  return true;
277 }
278 
279 
280 
281 
283  // fill in maps of hits
284 
285  LogDebug("DataMixingSiPixelMCDigiWorker")<<"===============> adding MC signals for "<<e.id();
286 
288 
289  if( e.getByToken(PixelDigiToken_,input) ) {
290 
291  //loop on all detsets (detectorIDs) inside the input collection
292  edm::DetSetVector<PixelDigi>::const_iterator DSViter=input->begin();
293  for (; DSViter!=input->end();DSViter++){
294 
295 #ifdef DEBUG
296  LogDebug("DataMixingSiPixelMCDigiWorker") << "Processing DetID " << DSViter->id;
297 #endif
298 
299  uint32_t detID = DSViter->id;
303 
304  OneDetectorMap LocalMap;
305 
306  for (icopy=begin; icopy!=end; icopy++) {
307  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
308  }
309 
310  SiHitStorage_.insert( SiGlobalIndex::value_type( detID, LocalMap ) );
311  }
312 
313  }
314  } // end of addSiPixelSignals
315 
316 
317 
318  void DataMixingSiPixelMCDigiWorker::addSiPixelPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,
319  ModuleCallingContext const* mcc) {
320 
321  LogDebug("DataMixingSiPixelMCDigiWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
322 
323  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
324 
325  std::shared_ptr<Wrapper<edm::DetSetVector<PixelDigi> > const> inputPTR =
326  getProductByTag<edm::DetSetVector<PixelDigi> >(*ep, pixeldigi_collectionPile_, mcc);
327 
328  if(inputPTR ) {
329 
330  const edm::DetSetVector<PixelDigi> *input = const_cast< edm::DetSetVector<PixelDigi> * >(inputPTR->product());
331 
332 
333 
334  // Handle< edm::DetSetVector<PixelDigi> > input;
335 
336  // if( e->getByLabel(pixeldigi_collectionPile_,input) ) {
337 
338  //loop on all detsets (detectorIDs) inside the input collection
340  for (; DSViter!=input->end();DSViter++){
341 
342 #ifdef DEBUG
343  LogDebug("DataMixingSiPixelMCDigiWorker") << "Pileups: Processing DetID " << DSViter->id;
344 #endif
345 
346  uint32_t detID = DSViter->id;
350 
351  // find correct local map (or new one) for this detector ID
352 
353  SiGlobalIndex::const_iterator itest;
354 
355  itest = SiHitStorage_.find(detID);
356 
357  if(itest!=SiHitStorage_.end()) { // this detID already has hits, add to existing map
358 
359  OneDetectorMap LocalMap = itest->second;
360 
361  // fill in local map with extra channels
362  for (icopy=begin; icopy!=end; icopy++) {
363  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
364  }
365 
366  SiHitStorage_[detID]=LocalMap;
367 
368  }
369  else{ // fill local storage with this information, put in global collection
370 
371  OneDetectorMap LocalMap;
372 
373  for (icopy=begin; icopy!=end; icopy++) {
374  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
375  }
376 
377  SiHitStorage_.insert( SiGlobalIndex::value_type( detID, LocalMap ) );
378  }
379 
380  }
381  }
382  }
383 
384 
385 
386  void DataMixingSiPixelMCDigiWorker::putSiPixel(edm::Event &e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> &ps, int &bs) {
387 
388  // collection of Digis to put in the event
389 
390  std::vector< edm::DetSet<PixelDigi> > vPixelDigi;
391 
392  // loop through our collection of detectors, merging hits and putting new ones in the output
393 
394  _signal.clear();
395 
396  // big loop over Detector IDs:
397 
398  for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
399  IDet != SiHitStorage_.end(); IDet++) {
400 
401  uint32_t detID = IDet->first;
402 
403  OneDetectorMap LocalMap = IDet->second;
404 
405  signal_map_type Signals;
406  Signals.clear();
407 
408  //counter variables
409  int formerPixel = -1;
410  int currentPixel;
411  int ADCSum = 0;
412 
413 
414  OneDetectorMap::const_iterator iLocalchk;
415 
416  for(OneDetectorMap::const_iterator iLocal = LocalMap.begin();
417  iLocal != LocalMap.end(); ++iLocal) {
418 
419  currentPixel = iLocal->first;
420 
421  if (currentPixel == formerPixel) { // we have to add these digis together
422  ADCSum+=(iLocal->second).adc();
423  }
424  else{
425  if(formerPixel!=-1){ // ADC info stolen from SiStrips...
426  if (ADCSum > 511) ADCSum = 255;
427  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
428 
429  Signals.insert( std::make_pair(formerPixel, ADCSum));
430  //PixelDigi aHit(formerPixel, ADCSum);
431  //SPD.push_back( aHit );
432  }
433  // save pointers for next iteration
434  formerPixel = currentPixel;
435  ADCSum = (iLocal->second).adc();
436  }
437 
438  iLocalchk = iLocal;
439  if((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
440  if (ADCSum > 511) ADCSum = 255;
441  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
442  Signals.insert( std::make_pair(formerPixel, ADCSum));
443  //SPD.push_back( PixelDigi(formerPixel, ADCSum) );
444  }
445 
446  }// end of loop over one detector
447 
448  // stick this into the global vector of detector info
449  _signal.insert( std::make_pair( detID, Signals));
450 
451  } // end of big loop over all detector IDs
452 
453  // put the collection of digis in the event
454  LogInfo("DataMixingSiPixelMCDigiWorker") << "total # Merged Pixels: " << _signal.size() ;
455 
456  // Now, we have to run Lumi-Dependent efficiency calculation on the merged pixels.
457  // This is the only place where we have the PreMixed pileup information so that we can calculate
458  // the instantaneous luminosity and do the dynamic inefficiency.
459 
461  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
462 
464  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
465  const TrackerTopology *tTopo=tTopoHand.product();
466 
467  // Load inefficiency constants (1st pass), set pileup information.
468 
469  if(FirstCall_) {
470  init_DynIneffDB(iSetup, bs);
471  FirstCall_ = false;
472  }
473 
474  setPileupInfo(ps, bs);
475 
476  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
477 
478  if((*iu)->type().isTrackerPixel()) {
479 
480  //
481  const PixelGeomDetUnit* pixdet = dynamic_cast<const PixelGeomDetUnit*>((*iu));
482  uint32_t detID = pixdet->geographicalId().rawId();
483 
484  // fetch merged hits for this detID
485 
486  signal_map_type& theSignal = _signal[detID];
487 
488  // if we have some hits...
489  if(theSignal.size()>0) {
490 
491  edm::DetSet<PixelDigi> SPD(detID); // make empty vector with this detID so we can push back digis at the end
492 
493  const PixelTopology* topol=&pixdet->specificTopology();
494  int numColumns = topol->ncolumns(); // det module number of cols&rows
495  int numRows = topol->nrows();
496 
497  // do inefficiency calculation, drop some pixel hits
498 
499  // Predefined efficiencies
500  double pixelEfficiency = 1.0;
501  double columnEfficiency = 1.0;
502  double chipEfficiency = 1.0;
503 
504  if (pixelEff_.FromConfig) {
505  // setup the chip indices conversion
507  pixdet->subDetector()==GeomDetEnumerators::SubDetector::P1PXB){// barrel layers
508  int layerIndex=tTopo->layer(detID);
509  pixelEfficiency = pixelEff_.thePixelEfficiency[layerIndex-1];
510  columnEfficiency = pixelEff_.thePixelColEfficiency[layerIndex-1];
511  chipEfficiency = pixelEff_.thePixelChipEfficiency[layerIndex-1];
512  //std::cout <<"Using BPix columnEfficiency = "<<columnEfficiency<< " for layer = "<<layerIndex <<"\n";
513  // This should never happen, but only check if it is not an upgrade geometry
514  if (NumberOfBarrelLayers==3){
515  if(numColumns>416) LogWarning ("Pixel Geometry") <<" wrong columns in barrel "<<numColumns;
516  if(numRows>160) LogWarning ("Pixel Geometry") <<" wrong rows in barrel "<<numRows;
517 
518  int ladder=tTopo->pxbLadder(detID);
519  int module=tTopo->pxbModule(detID);
520  if (module<=4) module=5-module;
521  else module-=4;
522 
523  columnEfficiency *= pixelEff_.theLadderEfficiency_BPix[layerIndex-1][ladder-1]*pixelEff_.theModuleEfficiency_BPix[layerIndex-1][module-1]*pixelEff_.pu_scale[layerIndex-1];
524  }
527  pixdet->subDetector()==GeomDetEnumerators::SubDetector::P2PXEC){ // forward disks
528 
529  unsigned int diskIndex=tTopo->layer(detID)+pixelEff_.FPixIndex; // Use diskIndex-1 later to stay consistent with BPix
530  unsigned int panelIndex=tTopo->pxfPanel(detID);
531  unsigned int moduleIndex=tTopo->pxfModule(detID);
532  //if (pixelEff_.FPixIndex>diskIndex-1){throw cms::Exception("Configuration") <<"SiPixelDigitizer is using the wrong efficiency value. index = "
533  // <<diskIndex-1<<" , MinIndex = "<<pixelEff_.FPixIndex<<" ... "<<tTopo->pxfDisk(detID);}
534  pixelEfficiency = pixelEff_.thePixelEfficiency[diskIndex-1];
535  columnEfficiency = pixelEff_.thePixelColEfficiency[diskIndex-1];
536  chipEfficiency = pixelEff_.thePixelChipEfficiency[diskIndex-1];
537  //std::cout <<"Using FPix columnEfficiency = "<<columnEfficiency<<" for Disk = "<< tTopo->pxfDisk(detID)<<"\n";
538  // Sometimes the forward pixels have wrong size,
539  // this crashes the index conversion, so exit, but only check if it is not an upgrade geometry
540  if (NumberOfBarrelLayers==3){ // whether it is the present or the phase 1 detector can be checked using GeomDetEnumerators::SubDetector
541  if(numColumns>260 || numRows>160) {
542  if(numColumns>260) LogWarning ("Pixel Geometry") <<" wrong columns in endcaps "<<numColumns;
543  if(numRows>160) LogWarning ("Pixel Geometry") <<" wrong rows in endcaps "<<numRows;
544  return;
545  }
546  if ((panelIndex==1 && (moduleIndex==1 || moduleIndex==2)) || (panelIndex==2 && moduleIndex==1)) { //inner modules
547  columnEfficiency*=pixelEff_.theInnerEfficiency_FPix[diskIndex-1]*pixelEff_.pu_scale[3];
548  } else { //outer modules
549  columnEfficiency*=pixelEff_.theOuterEfficiency_FPix[diskIndex-1]*pixelEff_.pu_scale[4];
550  }
551  } // current detector, forward
553  // If phase 2 outer tracker, hardcoded values as they have been so far
554  pixelEfficiency = 0.999;
555  columnEfficiency = 0.999;
556  chipEfficiency = 0.999;
557  } // if barrel/forward
558  } else { // Load precomputed factors from Database
559  pixelEfficiency = pixelEff_.PixelGeomFactors.at(detID);
560  columnEfficiency = pixelEff_.ColGeomFactors.at(detID)*pixelEff_.pu_scale[pixelEff_.iPU.at(detID)];
561  chipEfficiency = pixelEff_.ChipGeomFactors.at(detID);
562  }
563 
564 #ifdef TP_DEBUG
565  LogDebug ("Pixel Digitizer") << " enter pixel_inefficiency " << pixelEfficiency << " "
566  << columnEfficiency << " " << chipEfficiency;
567 #endif
568 
569  // Initilize the index converter
570  //PixelIndices indexConverter(numColumns,numRows);
571  std::auto_ptr<PixelIndices> pIndexConverter(new PixelIndices(numColumns,numRows));
572 
573 
574  int chipIndex = 0;
575  int rowROC = 0;
576  int colROC = 0;
577  std::map<int, int, std::less<int> >chips, columns;
578  std::map<int, int, std::less<int> >::iterator iter;
579 
580  // Find out the number of columns and rocs hits
581  // Loop over hit pixels, amplitude in electrons, channel = coded row,col
582  for (signal_map_const_iterator i = theSignal.begin(); i != theSignal.end(); ++i) {
583 
584  int chan = i->first;
585  std::pair<int,int> ip = PixelDigi::channelToPixel(chan);
586  int row = ip.first; // X in row
587  int col = ip.second; // Y is in col
588  //transform to ROC index coordinates
589  pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
590  int dColInChip = pIndexConverter->DColumn(colROC); // get ROC dcol from ROC col
591  //dcol in mod
592  int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
593 
594  chips[chipIndex]++;
595  columns[dColInDet]++;
596  }
597 
598  // Delete some ROC hits.
599  for ( iter = chips.begin(); iter != chips.end() ; iter++ ) {
600  //float rand = RandFlat::shoot();
601  float rand = CLHEP::RandFlat::shoot(engine);
602  if( rand > chipEfficiency ) chips[iter->first]=0;
603  }
604 
605  // Delete some Dcol hits.
606  for ( iter = columns.begin(); iter != columns.end() ; iter++ ) {
607  //float rand = RandFlat::shoot();
608  float rand = CLHEP::RandFlat::shoot(engine);
609  if( rand > columnEfficiency ) columns[iter->first]=0;
610  }
611 
612  // Now loop again over pixels to kill some of them.
613  // Loop over hit pixels, amplitude in electrons, channel = coded row,col
614  for(signal_map_iterator i = theSignal.begin();i != theSignal.end(); ++i) {
615 
616  // int chan = i->first;
617  std::pair<int,int> ip = PixelDigi::channelToPixel(i->first);//get pixel pos
618  int row = ip.first; // X in row
619  int col = ip.second; // Y is in col
620  //transform to ROC index coordinates
621  pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
622  int dColInChip = pIndexConverter->DColumn(colROC); //get ROC dcol from ROC col
623  //dcol in mod
624  int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
625 
626  //float rand = RandFlat::shoot();
627  float rand = CLHEP::RandFlat::shoot(engine);
628  if( chips[chipIndex]==0 || columns[dColInDet]==0
629  || rand>pixelEfficiency ) {
630  // make pixel amplitude =0, pixel will be lost at clusterization
631  i->second=(0.); // reset amplitude
632  } // end if
633  //Make a new Digi:
634 
635  SPD.push_back( PixelDigi(i->first, i->second) );
636 
637  } // end pixel loop
638  // push back vector here of one detID
639 
640  vPixelDigi.push_back(SPD);
641  }
642  }
643  }// end of loop over detectors
644 
645  // make new digi collection
646 
647  std::auto_ptr< edm::DetSetVector<PixelDigi> > MyPixelDigis(new edm::DetSetVector<PixelDigi>(vPixelDigi) );
648 
649  // put collection
650 
651  e.put( MyPixelDigis, PixelDigiCollectionDM_ );
652 
653  // clear local storage for this event
654  SiHitStorage_.clear();
655  }
656 
657 void DataMixingSiPixelMCDigiWorker::setPileupInfo(const std::vector<PileupSummaryInfo> &ps, const int &bunchSpacing) {
658 
659  //double bunchScale=1.0;
660  //if (bunchSpacing==25) bunchScale=bunchScaleAt25;
661 
662  int p = -1;
663  for ( unsigned int i=0; i<ps.size(); i++)
664  if ( ps[i].getBunchCrossing() == 0 )
665  p=i;
666 
667  if ( p>=0 ) {
668  for (size_t i=0, n = pixelEff_.thePUEfficiency.size(); i<n; i++) {
669  double instlumi = ps[p].getTrueNumInteractions()*pixelEff_.theInstLumiScaleFactor;
670  double instlumi_pow=1.;
671  pixelEff_.pu_scale[i] = 0;
672  for (size_t j=0; j<pixelEff_.thePUEfficiency[i].size(); j++){
673  pixelEff_.pu_scale[i]+=instlumi_pow*pixelEff_.thePUEfficiency[i][j];
674  instlumi_pow*=instlumi;
675  }
676  }
677  }
678 
679 } //this sets pu_scale
680 
681 } //edm
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void init_DynIneffDB(const edm::EventSetup &, const unsigned int &)
std::multimap< int, PixelDigi > OneDetectorMap
void push_back(const T &t)
Definition: DetSet.h:68
virtual int ncolumns() const =0
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiToken_
EventID const & id() const
unsigned int pxbLadder(const DetId &id) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual int nrows() const =0
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
unsigned int pxbModule(const DetId &id) const
static std::string const input
Definition: EdmProvDump.cc:43
signal_map_type::const_iterator signal_map_const_iterator
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
bool matches(const DetId &, const DetId &, const std::vector< uint32_t > &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
edm::ESHandle< SiPixelDynamicInefficiency > SiPixelDynamicInefficiency_
int j
Definition: DBlmapReader.cc:9
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
#define end
Definition: vmac.h:37
std::map< int, Amplitude, std::less< int > > signal_map_type
Container::value_type value_type
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:365
tuple conf
Definition: dbtoconf.py:185
unsigned int pxfModule(const DetId &id) const
void init_from_db(const edm::ESHandle< TrackerGeometry > &, const edm::ESHandle< SiPixelDynamicInefficiency > &)
Definition: DetId.h:18
void setPileupInfo(const std::vector< PileupSummaryInfo > &ps, const int &bs)
const T & get() const
Definition: EventSetup.h:56
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:62
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T const * product() const
Definition: ESHandle.h:86
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
unsigned int layer(const DetId &id) const
edm::EventID id() const
Definition: EventBase.h:60
#define begin
Definition: vmac.h:30
void addSiPixelPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
StreamID streamID() const
Definition: Event.h:79
Signal rand(Signal arg)
Definition: vlib.cc:442
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiPToken_
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:350
PixelEfficiencies(const edm::ParameterSet &conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
int col
Definition: cuy.py:1008
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:108
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:49
void putSiPixel(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > &ps, int &bs)
Definition: vlib.h:208
tuple size
Write out results.
unsigned int pxfPanel(const DetId &id) const