CMS 3D CMS Logo

HcalDigitizer.cc
Go to the documentation of this file.
29 #include <boost/foreach.hpp>
36 
37 //#define DebugLog
38 
40  theGeometry(nullptr),
41  theRecNumber(nullptr),
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(nullptr),
52  theHFAmplifier(nullptr),
53  theHOAmplifier(nullptr),
54  theZDCAmplifier(nullptr),
55  theHFQIE10Amplifier(nullptr),
56  theHBHEQIE11Amplifier(nullptr),
57  theIonFeedback(nullptr),
58  theCoderFactory(nullptr),
59  theHBHEElectronicsSim(nullptr),
60  theHFElectronicsSim(nullptr),
61  theHOElectronicsSim(nullptr),
62  theZDCElectronicsSim(nullptr),
63  theHFQIE10ElectronicsSim(nullptr),
64  theHBHEQIE11ElectronicsSim(nullptr),
65  theHBHEHitFilter(),
66  theHBHEQIE11HitFilter(),
67  theHFHitFilter(),
68  theHFQIE10HitFilter(),
69  theHOHitFilter(),
70  theHOSiPMHitFilter(),
71  theZDCHitFilter(),
72  theHBHEDigitizer(nullptr),
73  theHODigitizer(nullptr),
74  theHOSiPMDigitizer(nullptr),
75  theHFDigitizer(nullptr),
76  theZDCDigitizer(nullptr),
77  theHFQIE10Digitizer(nullptr),
78  theHBHEQIE11Digitizer(nullptr),
79  theRelabeller(nullptr),
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  hcalTimeSlew_delay_ = nullptr;
161  theTimeSlewSim = nullptr;
162  if(doTimeSlew) {
163  // no time slewing for HF
164  theTimeSlewSim = new HcalTimeSlewSim(theParameterMap,minFCToDelay);
169  }
170 
174 
175  //QIE8 and QIE10 can coexist in HF
178 
180 
181  testNumbering_ = ps.getParameter<bool>("TestNumbering");
182 // std::cout << "Flag to see if Hit Relabeller to be initiated " << testNumbering_ << std::endl;
183  if (testNumbering_) theRelabeller=new HcalHitRelabeller(ps.getParameter<bool>("doNeutralDensityFilter"));
184 
185  if(ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
188  if(ps.getParameter<bool>("doThermalNoise")) {
190  }
191  }
192 
193  //option to save CaloSamples as event product for debugging
194  if(debugCS_){
202  }
203 
204  //option to ignore Geant time distribution in SimHits, for debugging
205  if(ignoreTime_){
213  }
214 
215  if(agingFlagHF) m_HFRecalibration.reset(new HFRecalibration(ps.getParameter<edm::ParameterSet>("HFRecalParameterBlock")));
216 }
217 
218 
222  if(theHODigitizer) delete theHODigitizer;
224  if(theHFDigitizer) delete theHFDigitizer;
226  delete theZDCDigitizer;
227  delete theParameterMap;
228  delete theHBHEResponse;
229  delete theHBHESiPMResponse;
230  delete theHOResponse;
231  delete theHOSiPMResponse;
232  delete theHFResponse;
233  delete theHFQIE10Response;
234  delete theZDCResponse;
235  delete theHBHEElectronicsSim;
236  delete theHFElectronicsSim;
237  delete theHOElectronicsSim;
238  delete theZDCElectronicsSim;
241  delete theHBHEAmplifier;
242  delete theHFAmplifier;
243  delete theHOAmplifier;
244  delete theZDCAmplifier;
245  delete theHFQIE10Amplifier;
246  delete theHBHEQIE11Amplifier;
247  delete theCoderFactory;
248  if (theRelabeller) delete theRelabeller;
249  if(theTimeSlewSim) delete theTimeSlewSim;
250  if(theIonFeedback) delete theIonFeedback;
251 }
252 
253 
255  noiseGenerator->setParameterMap(theParameterMap);
256  noiseGenerator->setElectronicsSim(theHBHEElectronicsSim);
258  theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
259 }
260 
262  noiseGenerator->setParameterMap(theParameterMap);
266 }
267 
269  noiseGenerator->setParameterMap(theParameterMap);
270  noiseGenerator->setElectronicsSim(theHFElectronicsSim);
272  theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
273 }
274 
276  noiseGenerator->setParameterMap(theParameterMap);
280 }
281 
283  noiseGenerator->setParameterMap(theParameterMap);
284  noiseGenerator->setElectronicsSim(theHOElectronicsSim);
287  theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
288 }
289 
291  noiseGenerator->setParameterMap(theParameterMap);
292  noiseGenerator->setElectronicsSim(theZDCElectronicsSim);
293  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
294  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
295 }
296 
298  setup(eventSetup);
299 
300  // get the appropriate gains, noises, & widths for this event
301  edm::ESHandle<HcalDbService> conditions;
302  eventSetup.get<HcalDbRecord>().get(conditions);
303 
304  theShapes->setDbService(conditions.product());
305 
306  theHBHEAmplifier->setDbService(conditions.product());
307  theHFAmplifier->setDbService(conditions.product());
308  theHOAmplifier->setDbService(conditions.product());
309  theZDCAmplifier->setDbService(conditions.product());
312 
315 
316  theCoderFactory->setDbService(conditions.product());
317  theParameterMap->setDbService(conditions.product());
318 
319  //initialize hits
327 
328 }
329 
330 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) {
331 
332  // Step A: pass in inputs, and accumulate digis
333  if(isHCAL) {
334  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
335  if(injectTestHits_) hcalHitsOrig = injectedHits_;
336  std::vector<PCaloHit> hcalHits;
337  hcalHits.reserve(hcalHitsOrig.size());
338 
339  //evaluate darkening before relabeling
340  if (testNumbering_) {
342  darkening(hcalHitsOrig);
343  }
344  // Relabel PCaloHits if necessary
345  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
346  theRelabeller->process(hcalHitsOrig);
347  }
348 
349  //eliminate bad hits
350  for (unsigned int i=0; i< hcalHitsOrig.size(); i++) {
351  DetId id(hcalHitsOrig[i].id());
352  HcalDetId hid(id);
353  if (!htopoP->validHcal(hid)) {
354  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << " " << hid << std::endl;
355  continue;
356  }
357  else if(hid.subdet()==HcalForward && !doHFWindow_ && hcalHitsOrig[i].depth()!=0){
358  //skip HF window hits unless desired
359  continue;
360  }
361  else if( killHE_ && hid.subdet()==HcalEndcap ) {
362  // remove HE hits if asked for (phase 2)
363  continue;
364  }
365  else {
366 #ifdef DebugLog
367  std::cout << "HcalDigitizer format " << hid.oldFormat() << " for " << hid << std::endl;
368 #endif
369  DetId newid = DetId(hid.newForm());
370 #ifdef DebugLog
371  std::cout << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId() << " --> " << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
372 #endif
373  hcalHitsOrig[i].setID(newid.rawId());
374  hcalHits.push_back(hcalHitsOrig[i]);
375  }
376  }
377 
378  if(hbhegeo) {
379  if(theHBHEDigitizer) theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
380  if(theHBHEQIE11Digitizer) theHBHEQIE11Digitizer->add(hcalHits, bunchCrossing, engine);
381  }
382 
383  if(hogeo) {
384  if(theHODigitizer) theHODigitizer->add(hcalHits, bunchCrossing, engine);
385  if(theHOSiPMDigitizer) theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
386  }
387 
388  if(hfgeo) {
389  if(theHFDigitizer) theHFDigitizer->add(hcalHits, bunchCrossing, engine);
390  if(theHFQIE10Digitizer) theHFQIE10Digitizer->add(hcalHits, bunchCrossing, engine);
391  }
392  } else {
393  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
394  }
395 
396  if(isZDC) {
397  if(zdcgeo) {
398  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
399  }
400  } else {
401  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
402  }
403 }
404 
405 void HcalDigitizer::accumulate(edm::Event const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
406  // Step A: Get Inputs
407  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
409  e.getByLabel(zdcTag, zdcHandle);
410  isZDC = zdcHandle.isValid();
411 
412  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
414  e.getByLabel(hcalTag, hcalHandle);
415  isHCAL = hcalHandle.isValid() or injectTestHits_;
416 
418  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
419  const HcalTopology *htopoP=htopo.product();
420 
421  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
422 }
423 
424 void HcalDigitizer::accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
425  // Step A: Get Inputs
426  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
428  e.getByLabel(zdcTag, zdcHandle);
429  isZDC = zdcHandle.isValid();
430 
431  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
433  e.getByLabel(hcalTag, hcalHandle);
434  isHCAL = hcalHandle.isValid();
435 
437  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
438  const HcalTopology *htopoP=htopo.product();
439 
440  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
441 }
442 
443 void HcalDigitizer::finalizeEvent(edm::Event& e, const edm::EventSetup& eventSetup, CLHEP::HepRandomEngine* engine) {
444 
445  // Step B: Create empty output
446  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
447  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
448  std::unique_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
449  std::unique_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
450  std::unique_ptr<QIE10DigiCollection> hfQIE10Result(
452  !theHFQIE10DetIds.empty() ?
455  )
456  );
457  std::unique_ptr<QIE11DigiCollection> hbheQIE11Result(
459  !theHBHEQIE11DetIds.empty() ?
460  ((HcalSiPMHitResponse *)theHBHESiPMResponse)->getReadoutFrameSize(theHBHEQIE11DetIds[0]) :
461 // theParameterMap->simParameters(theHBHEQIE11DetIds[0]).readoutFrameSize() :
463  )
464  );
465 
466  // Step C: Invoke the algorithm, getting back outputs.
467  if(isHCAL&&hbhegeo){
468  if(theHBHEDigitizer) theHBHEDigitizer->run(*hbheResult, engine);
469  if(theHBHEQIE11Digitizer) theHBHEQIE11Digitizer->run(*hbheQIE11Result, engine);
470  }
471  if(isHCAL&&hogeo) {
472  if(theHODigitizer) theHODigitizer->run(*hoResult, engine);
473  if(theHOSiPMDigitizer) theHOSiPMDigitizer->run(*hoResult, engine);
474  }
475  if(isHCAL&&hfgeo) {
476  if(theHFDigitizer) theHFDigitizer->run(*hfResult, engine);
477  if(theHFQIE10Digitizer) theHFQIE10Digitizer->run(*hfQIE10Result, engine);
478  }
479  if(isZDC&&zdcgeo) {
480  theZDCDigitizer->run(*zdcResult, engine);
481  }
482 
483  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
484  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
485  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
486  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
487  edm::LogInfo("HcalDigitizer") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
488  edm::LogInfo("HcalDigitizer") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
489 
490 #ifdef DebugLog
491  std::cout << std::endl;
492  std::cout << "HCAL HBHE digis : " << hbheResult->size() << std::endl;
493  std::cout << "HCAL HO digis : " << hoResult->size() << std::endl;
494  std::cout << "HCAL HF digis : " << hfResult->size() << std::endl;
495  std::cout << "HCAL ZDC digis : " << zdcResult->size() << std::endl;
496  std::cout << "HCAL HF QIE10 digis : " << hfQIE10Result->size() << std::endl;
497  std::cout << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size() << std::endl;
498 #endif
499 
500  // Step D: Put outputs into event
501  e.put(std::move(hbheResult));
502  e.put(std::move(hoResult));
503  e.put(std::move(hfResult));
504  e.put(std::move(zdcResult));
505  e.put(std::move(hfQIE10Result), "HFQIE10DigiCollection");
506  e.put(std::move(hbheQIE11Result), "HBHEQIE11DigiCollection");
507 
508  if(debugCS_){
509  std::unique_ptr<CaloSamplesCollection> csResult(new CaloSamplesCollection());
510  //smush together all the results
511  if(theHBHEDigitizer) csResult->insert(csResult->end(),theHBHEDigitizer->getCaloSamples().begin(),theHBHEDigitizer->getCaloSamples().end());
512  if(theHBHEQIE11Digitizer) csResult->insert(csResult->end(),theHBHEQIE11Digitizer->getCaloSamples().begin(),theHBHEQIE11Digitizer->getCaloSamples().end());
513  if(theHODigitizer) csResult->insert(csResult->end(),theHODigitizer->getCaloSamples().begin(),theHODigitizer->getCaloSamples().end());
514  if(theHOSiPMDigitizer) csResult->insert(csResult->end(),theHOSiPMDigitizer->getCaloSamples().begin(),theHOSiPMDigitizer->getCaloSamples().end());
515  if(theHFDigitizer) csResult->insert(csResult->end(),theHFDigitizer->getCaloSamples().begin(),theHFDigitizer->getCaloSamples().end());
516  if(theHFQIE10Digitizer) csResult->insert(csResult->end(),theHFQIE10Digitizer->getCaloSamples().begin(),theHFQIE10Digitizer->getCaloSamples().end());
517  csResult->insert(csResult->end(),theZDCDigitizer->getCaloSamples().begin(),theZDCDigitizer->getCaloSamples().end());
518  e.put(std::move(csResult),"HcalSamples");
519  }
520 
521  if(injectTestHits_){
522  std::unique_ptr<edm::PCaloHitContainer> pcResult(new edm::PCaloHitContainer());
523  pcResult->insert(pcResult->end(),injectedHits_.begin(),injectedHits_.end());
524  e.put(std::move(pcResult),"HcalHits");
525  }
526 
527 #ifdef DebugLog
528  std::cout << std::endl << "========> HcalDigitizer e.put " << std::endl << std::endl;
529 #endif
530 
531 }
532 
533 
535  checkGeometry(es);
536 
537  if (agingFlagHB) {
539  es.get<HBHEDarkeningRecord>().get("HB",hdark);
540  m_HBDarkening = &*hdark;
541  }
542  if (agingFlagHE) {
544  es.get<HBHEDarkeningRecord>().get("HE",hdark);
545  m_HEDarkening = &*hdark;
546  }
547 
549  es.get<HcalTimeSlewRecord>().get("HBHE", delay);
550  hcalTimeSlew_delay_ = &*delay;
551 
556 }
557 
558 
561  eventSetup.get<CaloGeometryRecord>().get(geometry);
562  theGeometry = &*geometry;
564  eventSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
565  theRecNumber= &*pHRNDC;
566 
575 
576  // See if it's been updated
577  bool check1 = theGeometryWatcher_.check(eventSetup);
578  bool check2 = theRecNumberWatcher_.check(eventSetup);
579  if (check1 or check2) {
580  updateGeometry(eventSetup);
581  }
582 }
583 
584 
586  const std::vector<DetId>& hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
587  const std::vector<DetId>& heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
588  const std::vector<DetId>& hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
589  const std::vector<DetId>& hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
590  const std::vector<DetId>& zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
591  //const std::vector<DetId>& hcalTrigCells = geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower);
592  //const std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
593 // std::cout<<"HcalDigitizer::CheckGeometry number of cells: "<<zdcCells.size()<<std::endl;
594  if(zdcCells.empty()) zdcgeo = false;
595  if(hbCells.empty() && heCells.empty()) hbhegeo = false;
596  if(hoCells.empty()) hogeo = false;
597  if(hfCells.empty()) hfgeo = false;
598  // combine HB & HE
599 
600  hbheCells = hbCells;
601  if( !killHE_) {
602  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
603  }
604  //handle mixed QIE8/11 scenario in HBHE
605  buildHBHEQIECells(hbheCells,eventSetup);
608 
609  if(theHOSiPMDigitizer) {
610  buildHOSiPMCells(hoCells, eventSetup);
612  ((HcalSiPMHitResponse *)theHOSiPMResponse)->setDetIds(hoCells);
613  }
614 
615  //handle mixed QIE8/10 scenario in HF
616  buildHFQIECells(hfCells,eventSetup);
617 
618  theZDCDigitizer->setDetIds(zdcCells);
619 
620  //fill test hits collection if desired and empty
621  if(injectTestHits_ && injectedHits_.empty() && !injectedHitsCells_.empty() && !injectedHitsEnergy_.empty()){
622  //make list of specified cells if desired
623  std::vector<DetId> testCells;
624  if(injectedHitsCells_.size()>=4){
625  testCells.reserve(injectedHitsCells_.size()/4);
626  for(unsigned ic = 0; ic < injectedHitsCells_.size(); ic += 4){
627  if(ic+4 > injectedHitsCells_.size()) break;
628  testCells.push_back(HcalDetId((HcalSubdetector)injectedHitsCells_[ic],injectedHitsCells_[ic+1],
630  }
631  }
632  else{
633  int testSubdet = injectedHitsCells_[0];
634  if(testSubdet==HcalBarrel) testCells = hbCells;
635  else if(testSubdet==HcalEndcap) testCells = heCells;
636  else if(testSubdet==HcalForward) testCells = hfCells;
637  else if(testSubdet==HcalOuter) testCells = hoCells;
638  else throw cms::Exception("Configuration") << "Unknown subdet " << testSubdet << " for HCAL test hit injection";
639  }
640  bool useHitTimes = (injectedHitsTime_.size()==injectedHitsEnergy_.size());
641  injectedHits_.reserve(testCells.size()*injectedHitsEnergy_.size());
642  for(unsigned ih = 0; ih < injectedHitsEnergy_.size(); ++ih){
643  double tmp = useHitTimes ? injectedHitsTime_[ih] : 0.;
644  for(auto& aCell: testCells){
645  injectedHits_.emplace_back(aCell,injectedHitsEnergy_[ih],tmp);
646  }
647  }
648  }
649 }
650 
651 void HcalDigitizer::buildHFQIECells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
652  //if results are already cached, no need to look again
653  if(!theHFQIE8DetIds.empty() || !theHFQIE10DetIds.empty()) return;
654 
655  //get the QIETypes
657  eventSetup.get<HcalQIETypesRcd>().get(q);
659  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
660 
661  HcalQIETypes qieTypes(*q.product());
662  if (qieTypes.topo()==nullptr) {
663  qieTypes.setTopo(htopo.product());
664  }
665 
666  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
667  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
668  if(qieType == QIE8) {
669  theHFQIE8DetIds.push_back(*detItr);
670  } else if(qieType == QIE10) {
671  theHFQIE10DetIds.push_back(*detItr);
672  } else { //default is QIE8
673  theHFQIE8DetIds.push_back(*detItr);
674  }
675  }
676 
678  else {
679  delete theHFDigitizer;
680  theHFDigitizer = nullptr;
681  }
682 
684  else {
685  delete theHFQIE10Digitizer;
686  theHFQIE10Digitizer = nullptr;
687  }
688 }
689 
690 void HcalDigitizer::buildHBHEQIECells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
691  //if results are already cached, no need to look again
692  if(!theHBHEQIE8DetIds.empty() || !theHBHEQIE11DetIds.empty()) return;
693 
694  //get the QIETypes
696  eventSetup.get<HcalQIETypesRcd>().get(q);
698  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
699 
700  HcalQIETypes qieTypes(*q.product());
701  if (qieTypes.topo()==nullptr) {
702  qieTypes.setTopo(htopo.product());
703  }
704 
705  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
706  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
707  if(qieType == QIE8) {
708  theHBHEQIE8DetIds.push_back(*detItr);
709  }
710  else if(qieType == QIE11) {
711  theHBHEQIE11DetIds.push_back(*detItr);
712  }
713  else { //default is QIE8
714  theHBHEQIE8DetIds.push_back(*detItr);
715  }
716  }
717 
719  else {
720  delete theHBHEDigitizer;
721  theHBHEDigitizer = nullptr;
722  }
723 
725  else {
726  delete theHBHEQIE11Digitizer;
727  theHBHEQIE11Digitizer = nullptr;
728  }
729 
730  if(!theHBHEQIE8DetIds.empty() && !theHBHEQIE11DetIds.empty()){
733  }
734 }
735 
736 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
737  // all HPD
738 
739  if(theHOSiPMCode == 0) {
740  theHODigitizer->setDetIds(allCells);
741  } else if(theHOSiPMCode == 1) {
742  theHOSiPMDigitizer->setDetIds(allCells);
743  // FIXME pick Zecotek or hamamatsu?
744  } else if(theHOSiPMCode == 2) {
745  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
747  eventSetup.get<HcalMCParamsRcd>().get(p);
749  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
750 
751  HcalMCParams mcParams(*p.product());
752  if (mcParams.topo()==nullptr) {
753  mcParams.setTopo(htopo.product());
754  }
755 
756  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
757  int shapeType = mcParams.getValues(*detItr)->signalShape();
758  if(shapeType == HcalShapes::ZECOTEK) {
759  zecotekDetIds.emplace_back(*detItr);
760  theHOSiPMDetIds.push_back(*detItr);
761  } else if(shapeType == HcalShapes::HAMAMATSU) {
762  hamamatsuDetIds.emplace_back(*detItr);
763  theHOSiPMDetIds.push_back(*detItr);
764  } else {
765  theHOHPDDetIds.push_back(*detItr);
766  }
767  }
768 
770  else {
771  delete theHODigitizer;
772  theHODigitizer = nullptr;
773  }
774 
776  else {
777  delete theHOSiPMDigitizer;
778  theHOSiPMDigitizer = nullptr;
779  }
780 
781  if(!theHOHPDDetIds.empty() && !theHOSiPMDetIds.empty()){
784  }
785 
786  theParameterMap->setHOZecotekDetIds(zecotekDetIds);
787  theParameterMap->setHOHamamatsuDetIds(hamamatsuDetIds);
788 
789  // make sure we don't got through this exercise again
790  theHOSiPMCode = -2;
791  }
792 }
793 
794 void HcalDigitizer::darkening(std::vector<PCaloHit>& hcalHits) {
795 
796  for (unsigned int ii=0; ii<hcalHits.size(); ++ii) {
797  uint32_t tmpId = hcalHits[ii].id();
798  int det, z, depth, ieta, phi, lay;
799  HcalTestNumbering::unpackHcalIndex(tmpId,det,z,depth,ieta,phi,lay);
800 
801  bool darkened = false;
802  float dweight = 1.;
803 
804  if(det==int(HcalBarrel) && m_HBDarkening){
805  //HB darkening
806  dweight = m_HBDarkening->degradation(deliveredLumi,ieta,lay);
807  darkened = true;
808  }
809  else if(det==int(HcalEndcap) && m_HEDarkening){
810  //HE darkening
811  dweight = m_HEDarkening->degradation(deliveredLumi,ieta,lay);
812  darkened = true;
813  }
814  else if(det==int(HcalForward) && m_HFRecalibration){
815  //HF darkening - approximate: invert recalibration factor
816  dweight = 1.0/m_HFRecalibration->getCorr(ieta,depth,deliveredLumi);
817  darkened = true;
818  }
819 
820  //reset hit energy
821  if(darkened) hcalHits[ii].setEnergy(hcalHits[ii].energy()*dweight);
822  }
823 
824 }
825 
826 
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
std::vector< PCaloHit > PCaloHitContainer
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
void setQIE10NoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::vector< CaloSamples > CaloSamplesCollection
Definition: CaloSamples.h:88
const HcalDDDRecConstants * theRecNumber
Definition: HcalDigitizer.h:76
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 ~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)
HFDigitizer * theHFDigitizer
HFHitFilter theHFHitFilter
CaloTDigitizer< HODigitizerTraits, CaloTDigitizerQIE8Run > HODigitizer
Definition: HcalDigitizer.h:88
void checkGeometry(const edm::EventSetup &eventSetup)
HcalSimParameterMap * theParameterMap
Definition: HcalDigitizer.h:94
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:87
#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:28
HcalAmplifier * theHBHEQIE11Amplifier
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
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::ESWatcher< HcalRecNumberingRecord > theRecNumberWatcher_
Definition: HcalDigitizer.h:74
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:95
Creates electronics signals from hits.
const HcalTimeSlew * hcalTimeSlew_delay_
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
void setTimeSlew(const HcalTimeSlew *timeSlew)
Definition: HcalAmplifier.h:40
HPDIonFeedbackSim * theIonFeedback
CaloTDigitizer< ZDCDigitizerTraits, CaloTDigitizerQIE8Run > ZDCDigitizer
Definition: HcalDigitizer.h:90
CaloHitResponse * theHOResponse
Definition: HcalDigitizer.h:99
CaloHitResponse * theHOSiPMResponse
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:475
bool oldFormat() const
Definition: HcalDetId.h:50
CaloHitResponse * theZDCResponse
ii
Definition: cuy.py:588
CaloTDigitizer< HFDigitizerTraits, CaloTDigitizerQIE8Run > HFDigitizer
Definition: HcalDigitizer.h:89
void setNoiseSignalGenerator(const CaloVNoiseSignalGenerator *noiseSignalGenerator)
Definition: HcalAmplifier.h:32
HcalDataFrameContainer< QIE11DataFrame > QIE11DigiCollection
Definition: DetId.h:18
HcalElectronicsSim * theZDCElectronicsSim
edm::ESWatcher< CaloGeometryRecord > theGeometryWatcher_
Definition: HcalDigitizer.h:73
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
void process(std::vector< PCaloHit > &hcalHits)
void setTimeSlewSim(HcalTimeSlewSim *timeSlewSim)
Definition: HcalAmplifier.h:35
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)
void setDbService(const HcalDbService *service)
Definition: HcalShapes.h:25
HcalAmplifier * theHOAmplifier
std::vector< DetId > theHFQIE8DetIds
void setDbService(const HcalDbService *service)
const T & get() const
Definition: EventSetup.h:59
HcalElectronicsSim * theHBHEElectronicsSim
uint32_t newForm() const
Definition: HcalDetId.cc:142
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
CaloHitResponse * theHBHEResponse
Definition: HcalDigitizer.h:97
HODigitizer * theHODigitizer
void setDetIds(const std::vector< DetId > &detIds)
Definition: HcalHitFilter.h:17
std::vector< DetId > theHOSiPMDetIds
HOHitFilter theHOSiPMHitFilter
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const CaloGeometry * theGeometry
Definition: HcalDigitizer.h:75
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:97
std::vector< DetId > hbheCells
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
ESHandle< TrackerGeometry > geometry
const HBHEDarkening * m_HBDarkening
CaloHitResponse * theHFResponse
CaloTDigitizer< HcalQIE11DigitizerTraits, CaloTDigitizerQIE1011Run > QIE11Digitizer
Definition: HcalDigitizer.h:92
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 setDebugCaloSamples(bool debug)
CaloHitResponse * theHBHESiPMResponse
Definition: HcalDigitizer.h:98
const CaloSimParameters & simParameters(const DetId &id) const override
CaloTDigitizer< HcalQIE10DigitizerTraits, CaloTDigitizerQIE1011Run > QIE10Digitizer
Definition: HcalDigitizer.h:91
void updateGeometry(const edm::EventSetup &eventSetup)
void setHBHENoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
void setup(const edm::EventSetup &es)
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)