CMS 3D CMS Logo

HcalDigitizer.cc
Go to the documentation of this file.
30 #include <boost/foreach.hpp>
36 
37 //#define DebugLog
38 
40  theGeometry(0),
41  theRecNumber(0),
42  theParameterMap(new HcalSimParameterMap(ps)),
43  theShapes(new HcalShapes()),
44  theHBHEResponse(new CaloHitResponse(theParameterMap, theShapes)),
45  theHBHESiPMResponse(new HcalSiPMHitResponse(theParameterMap, theShapes, ps.getParameter<bool>("HcalPreMixStage1"), true)),
46  theHOResponse(new CaloHitResponse(theParameterMap, theShapes)),
47  theHOSiPMResponse(new HcalSiPMHitResponse(theParameterMap, theShapes, ps.getParameter<bool>("HcalPreMixStage1"), false)),
48  theHFResponse(new CaloHitResponse(theParameterMap, theShapes)),
49  theHFQIE10Response(new CaloHitResponse(theParameterMap, theShapes)),
50  theZDCResponse(new CaloHitResponse(theParameterMap, theShapes)),
51  theHBHEAmplifier(0),
52  theHFAmplifier(0),
53  theHOAmplifier(0),
54  theZDCAmplifier(0),
55  theHFQIE10Amplifier(0),
56  theHBHEQIE11Amplifier(0),
57  theIonFeedback(0),
58  theCoderFactory(0),
59  theHBHEElectronicsSim(0),
60  theHFElectronicsSim(0),
61  theHOElectronicsSim(0),
62  theZDCElectronicsSim(0),
63  theHFQIE10ElectronicsSim(0),
64  theHBHEQIE11ElectronicsSim(0),
65  theHBHEHitFilter(),
66  theHBHEQIE11HitFilter(),
67  theHFHitFilter(),
68  theHFQIE10HitFilter(),
69  theHOHitFilter(),
70  theHOSiPMHitFilter(),
71  theZDCHitFilter(),
72  theHBHEDigitizer(0),
73  theHODigitizer(0),
74  theHOSiPMDigitizer(0),
75  theHFDigitizer(0),
76  theZDCDigitizer(0),
77  theHFQIE10Digitizer(0),
78  theHBHEQIE11Digitizer(0),
79  theRelabeller(0),
80  isZDC(true),
81  isHCAL(true),
82  zdcgeo(true),
83  hbhegeo(true),
84  hogeo(true),
85  hfgeo(true),
86  doHFWindow_(ps.getParameter<bool>("doHFWindow")),
87  killHE_(ps.getParameter<bool>("killHE")),
88  debugCS_(ps.getParameter<bool>("debugCaloSamples")),
89  ignoreTime_(ps.getParameter<bool>("ignoreGeantTime")),
90  injectTestHits_(ps.getParameter<bool>("injectTestHits")),
91  hitsProducer_(ps.getParameter<std::string>("hitsProducer")),
92  theHOSiPMCode(ps.getParameter<edm::ParameterSet>("ho").getParameter<int>("siPMCode")),
93  deliveredLumi(0.),
94  agingFlagHB(ps.getParameter<bool>("HBDarkening")),
95  agingFlagHE(ps.getParameter<bool>("HEDarkening")),
96  m_HBDarkening(nullptr),
97  m_HEDarkening(nullptr),
98  m_HFRecalibration(nullptr),
99  injectedHitsEnergy_(ps.getParameter<std::vector<double>>("injectTestHitsEnergy")),
100  injectedHitsTime_(ps.getParameter<std::vector<double>>("injectTestHitsTime")),
101  injectedHitsCells_(ps.getParameter<std::vector<int>>("injectTestHitsCells"))
102 {
103  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "ZDCHITS"));
104  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "HcalHits"));
105 
106  bool doNoise = ps.getParameter<bool>("doNoise");
107 
108  bool PreMix1 = ps.getParameter<bool>("HcalPreMixStage1"); // special threshold/pedestal treatment
109  bool PreMix2 = ps.getParameter<bool>("HcalPreMixStage2"); // special threshold/pedestal treatment
110  bool doEmpty = ps.getParameter<bool>("doEmpty");
111  deliveredLumi = ps.getParameter<double>("DelivLuminosity");
112  bool agingFlagHF = ps.getParameter<bool>("HFDarkening");
113  double minFCToDelay= ps.getParameter<double>("minFCToDelay");
114 
115  if(PreMix1 && PreMix2) {
116  throw cms::Exception("Configuration")
117  << "HcalDigitizer cannot operate in PreMixing digitization and PreMixing\n"
118  "digi combination modes at the same time. Please set one mode to False\n"
119  "in the configuration file.";
120  }
121 
122  // need to make copies, because they might get different noise generators
123  theHBHEAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
124  theHFAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
125  theHOAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
126  theZDCAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
127  theHFQIE10Amplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
128  theHBHEQIE11Amplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
129 
131 
136  theHFQIE10ElectronicsSim = new HcalElectronicsSim(theHFQIE10Amplifier, theCoderFactory, PreMix1); //should this use a different coder factory?
137  theHBHEQIE11ElectronicsSim = new HcalElectronicsSim(theHBHEQIE11Amplifier, theCoderFactory, PreMix1); //should this use a different coder factory?
138 
139  bool doHOHPD = (theHOSiPMCode != 1);
140  bool doHOSiPM = (theHOSiPMCode != 0);
141  if(doHOHPD) {
145  }
146  if(doHOSiPM) {
149  }
150 
153 
154  //QIE8 and QIE11 can coexist in HBHE
157 
158  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
159  //initialize: they won't be called later if flag is set
160  theTimeSlewSim = 0;
161  if(doTimeSlew) {
162  // no time slewing for HF
163  theTimeSlewSim = new HcalTimeSlewSim(theParameterMap,minFCToDelay);
164  theHBHEAmplifier->setTimeSlewSim(theTimeSlewSim);
165  theHBHEQIE11Amplifier->setTimeSlewSim(theTimeSlewSim);
166  theHOAmplifier->setTimeSlewSim(theTimeSlewSim);
167  theZDCAmplifier->setTimeSlewSim(theTimeSlewSim);
168  }
169 
173 
174  //QIE8 and QIE10 can coexist in HF
177 
179 
180  testNumbering_ = ps.getParameter<bool>("TestNumbering");
181 // std::cout << "Flag to see if Hit Relabeller to be initiated " << testNumbering_ << std::endl;
182  if (testNumbering_) theRelabeller=new HcalHitRelabeller(ps.getParameter<bool>("doNeutralDensityFilter"));
183 
184  if(ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
187  if(ps.getParameter<bool>("doThermalNoise")) {
189  }
190  }
191 
192  //option to save CaloSamples as event product for debugging
193  if(debugCS_){
201  }
202 
203  //option to ignore Geant time distribution in SimHits, for debugging
204  if(ignoreTime_){
212  }
213 
214  if(agingFlagHF) m_HFRecalibration.reset(new HFRecalibration(ps.getParameter<edm::ParameterSet>("HFRecalParameterBlock")));
215 }
216 
217 
221  if(theHODigitizer) delete theHODigitizer;
223  if(theHFDigitizer) delete theHFDigitizer;
225  delete theZDCDigitizer;
226  delete theParameterMap;
227  delete theHBHEResponse;
228  delete theHBHESiPMResponse;
229  delete theHOResponse;
230  delete theHOSiPMResponse;
231  delete theHFResponse;
232  delete theHFQIE10Response;
233  delete theZDCResponse;
234  delete theHBHEElectronicsSim;
235  delete theHFElectronicsSim;
236  delete theHOElectronicsSim;
237  delete theZDCElectronicsSim;
240  delete theHBHEAmplifier;
241  delete theHFAmplifier;
242  delete theHOAmplifier;
243  delete theZDCAmplifier;
244  delete theHFQIE10Amplifier;
245  delete theHBHEQIE11Amplifier;
246  delete theCoderFactory;
247  if (theRelabeller) delete theRelabeller;
248  if(theTimeSlewSim) delete theTimeSlewSim;
249  if(theIonFeedback) delete theIonFeedback;
250 }
251 
252 
254  noiseGenerator->setParameterMap(theParameterMap);
255  noiseGenerator->setElectronicsSim(theHBHEElectronicsSim);
257  theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
258 }
259 
261  noiseGenerator->setParameterMap(theParameterMap);
265 }
266 
268  noiseGenerator->setParameterMap(theParameterMap);
269  noiseGenerator->setElectronicsSim(theHFElectronicsSim);
271  theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
272 }
273 
275  noiseGenerator->setParameterMap(theParameterMap);
279 }
280 
282  noiseGenerator->setParameterMap(theParameterMap);
283  noiseGenerator->setElectronicsSim(theHOElectronicsSim);
286  theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
287 }
288 
290  noiseGenerator->setParameterMap(theParameterMap);
291  noiseGenerator->setElectronicsSim(theZDCElectronicsSim);
292  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
293  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
294 }
295 
297  // get the appropriate gains, noises, & widths for this event
298  edm::ESHandle<HcalDbService> conditions;
299  eventSetup.get<HcalDbRecord>().get(conditions);
300 
301  theHBHEAmplifier->setDbService(conditions.product());
302  theHFAmplifier->setDbService(conditions.product());
303  theHOAmplifier->setDbService(conditions.product());
304  theZDCAmplifier->setDbService(conditions.product());
307 
310 
311  theCoderFactory->setDbService(conditions.product());
312  theParameterMap->setDbService(conditions.product());
313 
314  //initialize hits
322 
323 }
324 
325 void HcalDigitizer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit> > const& hcalHandle, edm::Handle<std::vector<PCaloHit> > const& zdcHandle, int bunchCrossing, CLHEP::HepRandomEngine* engine, const HcalTopology *htopoP) {
326 
327  // Step A: pass in inputs, and accumulate digis
328  if(isHCAL) {
329  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
330  if(injectTestHits_) hcalHitsOrig = injectedHits_;
331  std::vector<PCaloHit> hcalHits;
332  hcalHits.reserve(hcalHitsOrig.size());
333 
334  //evaluate darkening before relabeling
335  if (testNumbering_) {
337  darkening(hcalHitsOrig);
338  }
339  // Relabel PCaloHits if necessary
340  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
341  theRelabeller->process(hcalHitsOrig);
342  }
343 
344  //eliminate bad hits
345  for (unsigned int i=0; i< hcalHitsOrig.size(); i++) {
346  DetId id(hcalHitsOrig[i].id());
347  HcalDetId hid(id);
348  if (!htopoP->validHcal(hid)) {
349  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << " " << hid << std::endl;
350  continue;
351  }
352  else if(hid.subdet()==HcalForward && !doHFWindow_ && hcalHitsOrig[i].depth()!=0){
353  //skip HF window hits unless desired
354  continue;
355  }
356  else if( killHE_ && hid.subdet()==HcalEndcap ) {
357  // remove HE hits if asked for (phase 2)
358  continue;
359  }
360  else {
361 #ifdef DebugLog
362  std::cout << "HcalDigitizer format " << hid.oldFormat() << " for " << hid << std::endl;
363 #endif
364  DetId newid = DetId(hid.newForm());
365 #ifdef DebugLog
366  std::cout << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId() << " --> " << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
367 #endif
368  hcalHitsOrig[i].setID(newid.rawId());
369  hcalHits.push_back(hcalHitsOrig[i]);
370  }
371  }
372 
373  if(hbhegeo) {
374  if(theHBHEDigitizer) theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
375  if(theHBHEQIE11Digitizer) theHBHEQIE11Digitizer->add(hcalHits, bunchCrossing, engine);
376  }
377 
378  if(hogeo) {
379  if(theHODigitizer) theHODigitizer->add(hcalHits, bunchCrossing, engine);
380  if(theHOSiPMDigitizer) theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
381  }
382 
383  if(hfgeo) {
384  if(theHFDigitizer) theHFDigitizer->add(hcalHits, bunchCrossing, engine);
385  if(theHFQIE10Digitizer) theHFQIE10Digitizer->add(hcalHits, bunchCrossing, engine);
386  }
387  } else {
388  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
389  }
390 
391  if(isZDC) {
392  if(zdcgeo) {
393  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
394  }
395  } else {
396  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
397  }
398 }
399 
400 void HcalDigitizer::accumulate(edm::Event const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
401  // Step A: Get Inputs
402  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
404  e.getByLabel(zdcTag, zdcHandle);
405  isZDC = zdcHandle.isValid();
406 
407  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
409  e.getByLabel(hcalTag, hcalHandle);
410  isHCAL = hcalHandle.isValid() or injectTestHits_;
411 
413  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
414  const HcalTopology *htopoP=htopo.product();
415 
416  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
417 }
418 
419 void HcalDigitizer::accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
420  // Step A: Get Inputs
421  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
423  e.getByLabel(zdcTag, zdcHandle);
424  isZDC = zdcHandle.isValid();
425 
426  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
428  e.getByLabel(hcalTag, hcalHandle);
429  isHCAL = hcalHandle.isValid();
430 
432  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
433  const HcalTopology *htopoP=htopo.product();
434 
435  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
436 }
437 
438 void HcalDigitizer::finalizeEvent(edm::Event& e, const edm::EventSetup& eventSetup, CLHEP::HepRandomEngine* engine) {
439 
440  // Step B: Create empty output
441  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
442  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
443  std::unique_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
444  std::unique_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
445  std::unique_ptr<QIE10DigiCollection> hfQIE10Result(
447  theHFQIE10DetIds.size()>0 ?
450  )
451  );
452  std::unique_ptr<QIE11DigiCollection> hbheQIE11Result(
454  theHBHEQIE11DetIds.size()>0 ?
455  ((HcalSiPMHitResponse *)theHBHESiPMResponse)->getReadoutFrameSize(theHBHEQIE11DetIds[0]) :
456 // theParameterMap->simParameters(theHBHEQIE11DetIds[0]).readoutFrameSize() :
458  )
459  );
460 
461  // Step C: Invoke the algorithm, getting back outputs.
462  if(isHCAL&&hbhegeo){
463  if(theHBHEDigitizer) theHBHEDigitizer->run(*hbheResult, engine);
464  if(theHBHEQIE11Digitizer) theHBHEQIE11Digitizer->run(*hbheQIE11Result, engine);
465  }
466  if(isHCAL&&hogeo) {
467  if(theHODigitizer) theHODigitizer->run(*hoResult, engine);
468  if(theHOSiPMDigitizer) theHOSiPMDigitizer->run(*hoResult, engine);
469  }
470  if(isHCAL&&hfgeo) {
471  if(theHFDigitizer) theHFDigitizer->run(*hfResult, engine);
472  if(theHFQIE10Digitizer) theHFQIE10Digitizer->run(*hfQIE10Result, engine);
473  }
474  if(isZDC&&zdcgeo) {
475  theZDCDigitizer->run(*zdcResult, engine);
476  }
477 
478  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
479  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
480  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
481  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
482  edm::LogInfo("HcalDigitizer") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
483  edm::LogInfo("HcalDigitizer") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
484 
485 #ifdef DebugLog
486  std::cout << std::endl;
487  std::cout << "HCAL HBHE digis : " << hbheResult->size() << std::endl;
488  std::cout << "HCAL HO digis : " << hoResult->size() << std::endl;
489  std::cout << "HCAL HF digis : " << hfResult->size() << std::endl;
490  std::cout << "HCAL ZDC digis : " << zdcResult->size() << std::endl;
491  std::cout << "HCAL HF QIE10 digis : " << hfQIE10Result->size() << std::endl;
492  std::cout << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size() << std::endl;
493 #endif
494 
495  // Step D: Put outputs into event
496  e.put(std::move(hbheResult));
497  e.put(std::move(hoResult));
498  e.put(std::move(hfResult));
499  e.put(std::move(zdcResult));
500  e.put(std::move(hfQIE10Result), "HFQIE10DigiCollection");
501  e.put(std::move(hbheQIE11Result), "HBHEQIE11DigiCollection");
502 
503  if(debugCS_){
504  std::unique_ptr<CaloSamplesCollection> csResult(new CaloSamplesCollection());
505  //smush together all the results
506  if(theHBHEDigitizer) csResult->insert(csResult->end(),theHBHEDigitizer->getCaloSamples().begin(),theHBHEDigitizer->getCaloSamples().end());
507  if(theHBHEQIE11Digitizer) csResult->insert(csResult->end(),theHBHEQIE11Digitizer->getCaloSamples().begin(),theHBHEQIE11Digitizer->getCaloSamples().end());
508  if(theHODigitizer) csResult->insert(csResult->end(),theHODigitizer->getCaloSamples().begin(),theHODigitizer->getCaloSamples().end());
509  if(theHOSiPMDigitizer) csResult->insert(csResult->end(),theHOSiPMDigitizer->getCaloSamples().begin(),theHOSiPMDigitizer->getCaloSamples().end());
510  if(theHFDigitizer) csResult->insert(csResult->end(),theHFDigitizer->getCaloSamples().begin(),theHFDigitizer->getCaloSamples().end());
511  if(theHFQIE10Digitizer) csResult->insert(csResult->end(),theHFQIE10Digitizer->getCaloSamples().begin(),theHFQIE10Digitizer->getCaloSamples().end());
512  csResult->insert(csResult->end(),theZDCDigitizer->getCaloSamples().begin(),theZDCDigitizer->getCaloSamples().end());
513  e.put(std::move(csResult),"HcalSamples");
514  }
515 
516  if(injectTestHits_){
517  std::unique_ptr<edm::PCaloHitContainer> pcResult(new edm::PCaloHitContainer());
518  pcResult->insert(pcResult->end(),injectedHits_.begin(),injectedHits_.end());
519  e.put(std::move(pcResult),"HcalHits");
520  }
521 
522 #ifdef DebugLog
523  std::cout << std::endl << "========> HcalDigitizer e.put " << std::endl << std::endl;
524 #endif
525 
526 }
527 
528 
530  checkGeometry(es);
531  theShapes->beginRun(es);
532 
533  if (agingFlagHB) {
535  es.get<HBHEDarkeningRecord>().get("HB",hdark);
536  m_HBDarkening = &*hdark;
537  }
538  if (agingFlagHE) {
540  es.get<HBHEDarkeningRecord>().get("HE",hdark);
541  m_HEDarkening = &*hdark;
542  }
543 }
544 
545 
547  theShapes->endRun();
548 }
549 
550 
552  // TODO find a way to avoid doing this every event
554  eventSetup.get<CaloGeometryRecord>().get(geometry);
556  eventSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
557 
558  // See if it's been updated
559  if (&*geometry != theGeometry) {
560  theGeometry = &*geometry;
561  theRecNumber= &*pHRNDC;
562  updateGeometry(eventSetup);
563  }
564 }
565 
566 
576 
577  const std::vector<DetId>& hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
578  const std::vector<DetId>& heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
579  const std::vector<DetId>& hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
580  const std::vector<DetId>& hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
581  const std::vector<DetId>& zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
582  //const std::vector<DetId>& hcalTrigCells = geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower);
583  //const std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
584 // std::cout<<"HcalDigitizer::CheckGeometry number of cells: "<<zdcCells.size()<<std::endl;
585  if(zdcCells.empty()) zdcgeo = false;
586  if(hbCells.empty() && heCells.empty()) hbhegeo = false;
587  if(hoCells.empty()) hogeo = false;
588  if(hfCells.empty()) hfgeo = false;
589  // combine HB & HE
590 
591  hbheCells = hbCells;
592  if( !killHE_) {
593  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
594  }
595  //handle mixed QIE8/11 scenario in HBHE
596  buildHBHEQIECells(hbheCells,eventSetup);
599 
600  if(theHOSiPMDigitizer) {
601  buildHOSiPMCells(hoCells, eventSetup);
603  ((HcalSiPMHitResponse *)theHOSiPMResponse)->setDetIds(hoCells);
604  }
605 
606  //handle mixed QIE8/10 scenario in HF
607  buildHFQIECells(hfCells,eventSetup);
608 
609  theZDCDigitizer->setDetIds(zdcCells);
610 
611  //fill test hits collection if desired and empty
612  if(injectTestHits_ && injectedHits_.size()==0 && injectedHitsCells_.size()>0 && injectedHitsEnergy_.size()>0){
613  //make list of specified cells if desired
614  std::vector<DetId> testCells;
615  if(injectedHitsCells_.size()>=4){
616  testCells.reserve(injectedHitsCells_.size()/4);
617  for(unsigned ic = 0; ic < injectedHitsCells_.size(); ic += 4){
618  if(ic+4 > injectedHitsCells_.size()) break;
619  testCells.push_back(HcalDetId((HcalSubdetector)injectedHitsCells_[ic],injectedHitsCells_[ic+1],
621  }
622  }
623  else{
624  int testSubdet = injectedHitsCells_[0];
625  if(testSubdet==HcalBarrel) testCells = hbCells;
626  else if(testSubdet==HcalEndcap) testCells = heCells;
627  else if(testSubdet==HcalForward) testCells = hfCells;
628  else if(testSubdet==HcalOuter) testCells = hoCells;
629  else throw cms::Exception("Configuration") << "Unknown subdet " << testSubdet << " for HCAL test hit injection";
630  }
631  bool useHitTimes = (injectedHitsTime_.size()==injectedHitsEnergy_.size());
632  injectedHits_.reserve(testCells.size()*injectedHitsEnergy_.size());
633  for(unsigned ih = 0; ih < injectedHitsEnergy_.size(); ++ih){
634  double tmp = useHitTimes ? injectedHitsTime_[ih] : 0.;
635  for(auto& aCell: testCells){
636  injectedHits_.emplace_back(aCell,injectedHitsEnergy_[ih],tmp);
637  }
638  }
639  }
640 }
641 
642 void HcalDigitizer::buildHFQIECells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
643  //if results are already cached, no need to look again
644  if(theHFQIE8DetIds.size()>0 || theHFQIE10DetIds.size()>0) return;
645 
646  //get the QIETypes
648  eventSetup.get<HcalQIETypesRcd>().get(q);
650  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
651 
652  HcalQIETypes qieTypes(*q.product());
653  if (qieTypes.topo()==0) {
654  qieTypes.setTopo(htopo.product());
655  }
656 
657  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
658  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
659  if(qieType == QIE8) {
660  theHFQIE8DetIds.push_back(*detItr);
661  } else if(qieType == QIE10) {
662  theHFQIE10DetIds.push_back(*detItr);
663  } else { //default is QIE8
664  theHFQIE8DetIds.push_back(*detItr);
665  }
666  }
667 
669  else {
670  delete theHFDigitizer;
672  }
673 
675  else {
676  delete theHFQIE10Digitizer;
678  }
679 }
680 
681 void HcalDigitizer::buildHBHEQIECells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
682  //if results are already cached, no need to look again
683  if(theHBHEQIE8DetIds.size()>0 || theHBHEQIE11DetIds.size()>0) return;
684 
685  //get the QIETypes
687  eventSetup.get<HcalQIETypesRcd>().get(q);
689  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
690 
691  HcalQIETypes qieTypes(*q.product());
692  if (qieTypes.topo()==0) {
693  qieTypes.setTopo(htopo.product());
694  }
695 
696  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
697  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
698  if(qieType == QIE8) {
699  theHBHEQIE8DetIds.push_back(*detItr);
700  }
701  else if(qieType == QIE11) {
702  theHBHEQIE11DetIds.push_back(*detItr);
703  }
704  else { //default is QIE8
705  theHBHEQIE8DetIds.push_back(*detItr);
706  }
707  }
708 
710  else {
711  delete theHBHEDigitizer;
713  }
714 
716  else {
717  delete theHBHEQIE11Digitizer;
719  }
720 
721  if(theHBHEQIE8DetIds.size()>0 && theHBHEQIE11DetIds.size()>0){
724  }
725 }
726 
727 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
728  // all HPD
729 
730  if(theHOSiPMCode == 0) {
731  theHODigitizer->setDetIds(allCells);
732  } else if(theHOSiPMCode == 1) {
733  theHOSiPMDigitizer->setDetIds(allCells);
734  // FIXME pick Zecotek or hamamatsu?
735  } else if(theHOSiPMCode == 2) {
736  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
738  eventSetup.get<HcalMCParamsRcd>().get(p);
740  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
741 
742  HcalMCParams mcParams(*p.product());
743  if (mcParams.topo()==0) {
744  mcParams.setTopo(htopo.product());
745  }
746 
747  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
748  int shapeType = mcParams.getValues(*detItr)->signalShape();
749  if(shapeType == HcalShapes::ZECOTEK) {
750  zecotekDetIds.emplace_back(*detItr);
751  theHOSiPMDetIds.push_back(*detItr);
752  } else if(shapeType == HcalShapes::HAMAMATSU) {
753  hamamatsuDetIds.emplace_back(*detItr);
754  theHOSiPMDetIds.push_back(*detItr);
755  } else {
756  theHOHPDDetIds.push_back(*detItr);
757  }
758  }
759 
761  else {
762  delete theHODigitizer;
764  }
765 
767  else {
768  delete theHOSiPMDigitizer;
770  }
771 
772  if(theHOHPDDetIds.size()>0 && theHOSiPMDetIds.size()>0){
775  }
776 
777  theParameterMap->setHOZecotekDetIds(zecotekDetIds);
778  theParameterMap->setHOHamamatsuDetIds(hamamatsuDetIds);
779 
780  // make sure we don't got through this exercise again
781  theHOSiPMCode = -2;
782  }
783 }
784 
785 void HcalDigitizer::darkening(std::vector<PCaloHit>& hcalHits) {
786 
787  for (unsigned int ii=0; ii<hcalHits.size(); ++ii) {
788  uint32_t tmpId = hcalHits[ii].id();
789  int det, z, depth, ieta, phi, lay;
790  HcalTestNumbering::unpackHcalIndex(tmpId,det,z,depth,ieta,phi,lay);
791 
792  bool darkened = false;
793  float dweight = 1.;
794 
795  if(det==int(HcalBarrel) && m_HBDarkening){
796  //HB darkening
797  dweight = m_HBDarkening->degradation(deliveredLumi,ieta,lay);
798  darkened = true;
799  }
800  else if(det==int(HcalEndcap) && m_HEDarkening){
801  //HE darkening
802  dweight = m_HEDarkening->degradation(deliveredLumi,ieta,lay);
803  darkened = true;
804  }
805  else if(det==int(HcalForward) && m_HFRecalibration){
806  //HF darkening - approximate: invert recalibration factor
807  dweight = 1.0/m_HFRecalibration->getCorr(ieta,depth,deliveredLumi);
808  darkened = true;
809  }
810 
811  //reset hit energy
812  if(darkened) hcalHits[ii].setEnergy(hcalHits[ii].energy()*dweight);
813  }
814 
815 }
816 
817 
HFHitFilter theHFQIE10HitFilter
std::vector< DetId > theHFQIE10DetIds
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
QIE10Digitizer * theHFQIE10Digitizer
T getParameter(std::string const &) const
std::vector< int > injectedHitsCells_
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
HBHEHitFilter theHBHEHitFilter
CaloHitResponse * theHFQIE10Response
Definition: HcalDigitizer.h:97
std::vector< PCaloHit > PCaloHitContainer
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
void setQIE10NoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::vector< CaloSamples > CaloSamplesCollection
Definition: CaloSamples.h:86
const HcalDDDRecConstants * theRecNumber
Definition: HcalDigitizer.h:71
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
void setParameterMap(HcalSimParameterMap *map)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
virtual const CaloSimParameters & simParameters(const DetId &id) const
virtual ~HcalDigitizer()
HcalElectronicsSim * theHFElectronicsSim
void buildHFQIECells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
Definition: HcalQIENum.h:4
HBHEDigitizer * theHBHEDigitizer
HcalElectronicsSim * theHBHEQIE11ElectronicsSim
HOHitFilter theHOHitFilter
void darkening(std::vector< PCaloHit > &hcalHits)
#define NULL
Definition: scimark2.h:8
HFDigitizer * theHFDigitizer
HFHitFilter theHFHitFilter
CaloTDigitizer< HODigitizerTraits, CaloTDigitizerQIE8Run > HODigitizer
Definition: HcalDigitizer.h:83
void checkGeometry(const edm::EventSetup &eventSetup)
HcalSimParameterMap * theParameterMap
Definition: HcalDigitizer.h:89
bool validHcal(const HcalDetId &id) const
void setPECorrection(const CaloVPECorrection *peCorrection)
if you want to correct the photoelectrons
CaloTDigitizer< HBHEDigitizerTraits, CaloTDigitizerQIE8Run > HBHEDigitizer
Definition: HcalDigitizer.h:82
#define nullptr
HcalTimeSlewSim * theTimeSlewSim
void buildHBHEQIECells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
void setGeometry(const HcalDDDRecConstants *&)
HcalAmplifier * theHFAmplifier
HcalCoderFactory * theCoderFactory
HcalHitRelabeller * theRelabeller
edm::SortedCollection< ZDCDataFrame > ZDCDigiCollection
HcalDataFrameContainer< QIE10DataFrame > QIE10DigiCollection
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
std::unique_ptr< HFRecalibration > m_HFRecalibration
void setDbService(const HcalDbService *service)
void setIonFeedbackSim(HPDIonFeedbackSim *feedbackSim)
Definition: HcalAmplifier.h:27
HcalAmplifier * theHBHEQIE11Amplifier
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
std::vector< double > injectedHitsEnergy_
void setQIE11NoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
void setHOZecotekDetIds(const std::vector< HcalDetId > &ids)
const HBHEDarkening * m_HEDarkening
HcalAmplifier * theHBHEAmplifier
edm::SortedCollection< HODataFrame > HODigiCollection
std::string hitsProducer_
HcalElectronicsSim * theHOElectronicsSim
double deliveredLumi
void setElectronicsSim(HcalElectronicsSim *electronicsSim)
void setHitFilter(const CaloVHitFilter *filter)
if you want to reject hits, for example, from a certain subdetector, set this
HcalShapes * theShapes
Definition: HcalDigitizer.h:90
Creates electronics signals from hits.
void setHFNoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
void initializeHits()
void buildHOSiPMCells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
ZDCHitFilter theZDCHitFilter
HPDIonFeedbackSim * theIonFeedback
CaloTDigitizer< ZDCDigitizerTraits, CaloTDigitizerQIE8Run > ZDCDigitizer
Definition: HcalDigitizer.h:85
CaloHitResponse * theHOResponse
Definition: HcalDigitizer.h:94
CaloHitResponse * theHOSiPMResponse
Definition: HcalDigitizer.h:95
HcalSubdetector
Definition: HcalAssistant.h:31
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
std::vector< double > injectedHitsTime_
HcalQIENum
Definition: HcalQIENum.h:4
ZDCDigitizer * theZDCDigitizer
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
std::vector< DetId > theHOHPDDetIds
int readoutFrameSize() const
for now, the LinearFrames and trhe digis will be one-to-one.
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
bool oldFormat() const
Definition: HcalDetId.h:50
CaloHitResponse * theZDCResponse
Definition: HcalDigitizer.h:98
void endRun()
Definition: HcalShapes.cc:70
ii
Definition: cuy.py:588
CaloTDigitizer< HFDigitizerTraits, CaloTDigitizerQIE8Run > HFDigitizer
Definition: HcalDigitizer.h:84
void setNoiseSignalGenerator(const CaloVNoiseSignalGenerator *noiseSignalGenerator)
Definition: HcalAmplifier.h:31
HcalDataFrameContainer< QIE11DataFrame > QIE11DigiCollection
Definition: DetId.h:18
HcalElectronicsSim * theZDCElectronicsSim
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
void beginRun(const edm::EventSetup &es)
void process(std::vector< PCaloHit > &hcalHits)
void setTimeSlewSim(HcalTimeSlewSim *timeSlewSim)
Definition: HcalAmplifier.h:34
void setHOHamamatsuDetIds(const std::vector< HcalDetId > &ids)
void accumulateCaloHits(edm::Handle< std::vector< PCaloHit > > const &hcalHits, edm::Handle< std::vector< PCaloHit > > const &zdcHits, int bunchCrossing, CLHEP::HepRandomEngine *, const HcalTopology *h)
HcalAmplifier * theHOAmplifier
std::vector< DetId > theHFQIE8DetIds
void setDbService(const HcalDbService *service)
const T & get() const
Definition: EventSetup.h:56
HcalElectronicsSim * theHBHEElectronicsSim
uint32_t newForm() const
Definition: HcalDetId.cc:142
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
CaloHitResponse * theHBHEResponse
Definition: HcalDigitizer.h:92
HODigitizer * theHODigitizer
void setDetIds(const std::vector< DetId > &detIds)
Definition: HcalHitFilter.h:17
std::vector< DetId > theHOSiPMDetIds
HOHitFilter theHOSiPMHitFilter
const CaloGeometry * theGeometry
Definition: HcalDigitizer.h:70
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:92
std::vector< DetId > hbheCells
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
ESHandle< TrackerGeometry > geometry
const HBHEDarkening * m_HBDarkening
CaloHitResponse * theHFResponse
Definition: HcalDigitizer.h:96
CaloTDigitizer< HcalQIE11DigitizerTraits, CaloTDigitizerQIE1011Run > QIE11Digitizer
Definition: HcalDigitizer.h:87
HLT enums.
HcalElectronicsSim * theHFQIE10ElectronicsSim
HODigitizer * theHOSiPMDigitizer
QIE11Digitizer * theHBHEQIE11Digitizer
HBHEHitFilter theHBHEQIE11HitFilter
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
void setZDCNoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::vector< DetId > theHBHEQIE8DetIds
edm::SortedCollection< HFDataFrame > HFDigiCollection
void beginRun(edm::EventSetup const &es)
Definition: HcalShapes.cc:55
void setDebugCaloSamples(bool debug)
CaloHitResponse * theHBHESiPMResponse
Definition: HcalDigitizer.h:93
CaloTDigitizer< HcalQIE10DigitizerTraits, CaloTDigitizerQIE1011Run > QIE10Digitizer
Definition: HcalDigitizer.h:86
void updateGeometry(const edm::EventSetup &eventSetup)
void setHBHENoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
T const * product() const
Definition: ESHandle.h:86
HcalAmplifier * theZDCAmplifier
std::vector< DetId > theHBHEQIE11DetIds
const CaloSamplesCollection & getCaloSamples() const
def move(src, dest)
Definition: eostools.py:510
void setTopo(const HcalTopology *topo)
void setDbService(const HcalDbService *service)
void setDetIds(const std::vector< DetId > &detIds)
void setIgnoreGeantTime(bool gt)
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection
float degradation(float intlumi, int ieta, int lay) const
std::vector< PCaloHit > injectedHits_
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
HcalAmplifier * theHFQIE10Amplifier
void setHONoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
HcalDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)