CMS 3D CMS Logo

HcalDigitizer.cc
Go to the documentation of this file.
30 #include <boost/foreach.hpp>
37 
38 //#define DebugLog
39 
41  theGeometry(nullptr),
42  theRecNumber(nullptr),
43  theParameterMap(new HcalSimParameterMap(ps)),
44  theShapes(new HcalShapes()),
45  theHBHEResponse(new CaloHitResponse(theParameterMap, theShapes)),
46  theHBHESiPMResponse(new HcalSiPMHitResponse(theParameterMap, theShapes, ps.getParameter<bool>("HcalPreMixStage1"), true)),
47  theHOResponse(new CaloHitResponse(theParameterMap, theShapes)),
48  theHOSiPMResponse(new HcalSiPMHitResponse(theParameterMap, theShapes, ps.getParameter<bool>("HcalPreMixStage1"), false)),
49  theHFResponse(new CaloHitResponse(theParameterMap, theShapes)),
50  theHFQIE10Response(new CaloHitResponse(theParameterMap, theShapes)),
51  theZDCResponse(new CaloHitResponse(theParameterMap, theShapes)),
52  theHBHEAmplifier(nullptr),
53  theHFAmplifier(nullptr),
54  theHOAmplifier(nullptr),
55  theZDCAmplifier(nullptr),
56  theHFQIE10Amplifier(nullptr),
57  theHBHEQIE11Amplifier(nullptr),
58  theIonFeedback(nullptr),
59  theCoderFactory(nullptr),
60  theHBHEElectronicsSim(nullptr),
61  theHFElectronicsSim(nullptr),
62  theHOElectronicsSim(nullptr),
63  theZDCElectronicsSim(nullptr),
64  theHFQIE10ElectronicsSim(nullptr),
65  theHBHEQIE11ElectronicsSim(nullptr),
66  theHBHEHitFilter(),
67  theHBHEQIE11HitFilter(),
68  theHFHitFilter(),
69  theHFQIE10HitFilter(),
70  theHOHitFilter(),
71  theHOSiPMHitFilter(),
72  theZDCHitFilter(),
73  theHBHEDigitizer(nullptr),
74  theHODigitizer(nullptr),
75  theHOSiPMDigitizer(nullptr),
76  theHFDigitizer(nullptr),
77  theZDCDigitizer(nullptr),
78  theHFQIE10Digitizer(nullptr),
79  theHBHEQIE11Digitizer(nullptr),
80  theRelabeller(nullptr),
81  isZDC(true),
82  isHCAL(true),
83  zdcgeo(true),
84  hbhegeo(true),
85  hogeo(true),
86  hfgeo(true),
87  doHFWindow_(ps.getParameter<bool>("doHFWindow")),
88  killHE_(ps.getParameter<bool>("killHE")),
89  debugCS_(ps.getParameter<bool>("debugCaloSamples")),
90  ignoreTime_(ps.getParameter<bool>("ignoreGeantTime")),
91  injectTestHits_(ps.getParameter<bool>("injectTestHits")),
92  hitsProducer_(ps.getParameter<std::string>("hitsProducer")),
93  theHOSiPMCode(ps.getParameter<edm::ParameterSet>("ho").getParameter<int>("siPMCode")),
94  deliveredLumi(0.),
95  agingFlagHB(ps.getParameter<bool>("HBDarkening")),
96  agingFlagHE(ps.getParameter<bool>("HEDarkening")),
97  m_HBDarkening(nullptr),
98  m_HEDarkening(nullptr),
99  m_HFRecalibration(nullptr),
100  injectedHitsEnergy_(ps.getParameter<std::vector<double>>("injectTestHitsEnergy")),
101  injectedHitsTime_(ps.getParameter<std::vector<double>>("injectTestHitsTime")),
102  injectedHitsCells_(ps.getParameter<std::vector<int>>("injectTestHitsCells"))
103 {
104  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "ZDCHITS"));
105  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "HcalHits"));
106 
107  bool doNoise = ps.getParameter<bool>("doNoise");
108 
109  bool PreMix1 = ps.getParameter<bool>("HcalPreMixStage1"); // special threshold/pedestal treatment
110  bool PreMix2 = ps.getParameter<bool>("HcalPreMixStage2"); // special threshold/pedestal treatment
111  bool doEmpty = ps.getParameter<bool>("doEmpty");
112  deliveredLumi = ps.getParameter<double>("DelivLuminosity");
113  bool agingFlagHF = ps.getParameter<bool>("HFDarkening");
114  double minFCToDelay= ps.getParameter<double>("minFCToDelay");
115 
116  if(PreMix1 && PreMix2) {
117  throw cms::Exception("Configuration")
118  << "HcalDigitizer cannot operate in PreMixing digitization and PreMixing\n"
119  "digi combination modes at the same time. Please set one mode to False\n"
120  "in the configuration file.";
121  }
122 
123  // need to make copies, because they might get different noise generators
124  theHBHEAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
125  theHFAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
126  theHOAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
127  theZDCAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
128  theHFQIE10Amplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
129  theHBHEQIE11Amplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
130 
132 
137  theHFQIE10ElectronicsSim = new HcalElectronicsSim(theHFQIE10Amplifier, theCoderFactory, PreMix1); //should this use a different coder factory?
138  theHBHEQIE11ElectronicsSim = new HcalElectronicsSim(theHBHEQIE11Amplifier, theCoderFactory, PreMix1); //should this use a different coder factory?
139 
140  bool doHOHPD = (theHOSiPMCode != 1);
141  bool doHOSiPM = (theHOSiPMCode != 0);
142  if(doHOHPD) {
146  }
147  if(doHOSiPM) {
150  }
151 
154 
155  //QIE8 and QIE11 can coexist in HBHE
158 
159  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
160  //initialize: they won't be called later if flag is set
161  hcalTimeSlew_delay_ = nullptr;
162  theTimeSlewSim = nullptr;
163  if(doTimeSlew) {
164  // no time slewing for HF
165  theTimeSlewSim = new HcalTimeSlewSim(theParameterMap,minFCToDelay);
170  }
171 
175 
176  //QIE8 and QIE10 can coexist in HF
179 
181 
182  testNumbering_ = ps.getParameter<bool>("TestNumbering");
183 // std::cout << "Flag to see if Hit Relabeller to be initiated " << testNumbering_ << std::endl;
184  if (testNumbering_) theRelabeller=new HcalHitRelabeller(ps.getParameter<bool>("doNeutralDensityFilter"));
185 
186  if(ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
189  if(ps.getParameter<bool>("doThermalNoise")) {
191  }
192  }
193 
194  //option to save CaloSamples as event product for debugging
195  if(debugCS_){
203  }
204 
205  //option to ignore Geant time distribution in SimHits, for debugging
206  if(ignoreTime_){
214  }
215 
216  if(agingFlagHF) m_HFRecalibration.reset(new HFRecalibration(ps.getParameter<edm::ParameterSet>("HFRecalParameterBlock")));
217 }
218 
219 
223  if(theHODigitizer) delete theHODigitizer;
225  if(theHFDigitizer) delete theHFDigitizer;
227  delete theZDCDigitizer;
228  delete theParameterMap;
229  delete theHBHEResponse;
230  delete theHBHESiPMResponse;
231  delete theHOResponse;
232  delete theHOSiPMResponse;
233  delete theHFResponse;
234  delete theHFQIE10Response;
235  delete theZDCResponse;
236  delete theHBHEElectronicsSim;
237  delete theHFElectronicsSim;
238  delete theHOElectronicsSim;
239  delete theZDCElectronicsSim;
242  delete theHBHEAmplifier;
243  delete theHFAmplifier;
244  delete theHOAmplifier;
245  delete theZDCAmplifier;
246  delete theHFQIE10Amplifier;
247  delete theHBHEQIE11Amplifier;
248  delete theCoderFactory;
249  if (theRelabeller) delete theRelabeller;
250  if(theTimeSlewSim) delete theTimeSlewSim;
251  if(theIonFeedback) delete theIonFeedback;
252 }
253 
254 
256  noiseGenerator->setParameterMap(theParameterMap);
257  noiseGenerator->setElectronicsSim(theHBHEElectronicsSim);
259  theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
260 }
261 
263  noiseGenerator->setParameterMap(theParameterMap);
267 }
268 
270  noiseGenerator->setParameterMap(theParameterMap);
271  noiseGenerator->setElectronicsSim(theHFElectronicsSim);
273  theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
274 }
275 
277  noiseGenerator->setParameterMap(theParameterMap);
281 }
282 
284  noiseGenerator->setParameterMap(theParameterMap);
285  noiseGenerator->setElectronicsSim(theHOElectronicsSim);
288  theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
289 }
290 
292  noiseGenerator->setParameterMap(theParameterMap);
293  noiseGenerator->setElectronicsSim(theZDCElectronicsSim);
294  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
295  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
296 }
297 
299  // get the appropriate gains, noises, & widths for this event
300  edm::ESHandle<HcalDbService> conditions;
301  eventSetup.get<HcalDbRecord>().get(conditions);
302 
303  theHBHEAmplifier->setDbService(conditions.product());
304  theHFAmplifier->setDbService(conditions.product());
305  theHOAmplifier->setDbService(conditions.product());
306  theZDCAmplifier->setDbService(conditions.product());
309 
312 
313  theCoderFactory->setDbService(conditions.product());
314  theParameterMap->setDbService(conditions.product());
315 
316  //initialize hits
324 
325 }
326 
327 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) {
328 
329  // Step A: pass in inputs, and accumulate digis
330  if(isHCAL) {
331  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
332  if(injectTestHits_) hcalHitsOrig = injectedHits_;
333  std::vector<PCaloHit> hcalHits;
334  hcalHits.reserve(hcalHitsOrig.size());
335 
336  //evaluate darkening before relabeling
337  if (testNumbering_) {
339  darkening(hcalHitsOrig);
340  }
341  // Relabel PCaloHits if necessary
342  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
343  theRelabeller->process(hcalHitsOrig);
344  }
345 
346  //eliminate bad hits
347  for (unsigned int i=0; i< hcalHitsOrig.size(); i++) {
348  DetId id(hcalHitsOrig[i].id());
349  HcalDetId hid(id);
350  if (!htopoP->validHcal(hid)) {
351  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << " " << hid << std::endl;
352  continue;
353  }
354  else if(hid.subdet()==HcalForward && !doHFWindow_ && hcalHitsOrig[i].depth()!=0){
355  //skip HF window hits unless desired
356  continue;
357  }
358  else if( killHE_ && hid.subdet()==HcalEndcap ) {
359  // remove HE hits if asked for (phase 2)
360  continue;
361  }
362  else {
363 #ifdef DebugLog
364  std::cout << "HcalDigitizer format " << hid.oldFormat() << " for " << hid << std::endl;
365 #endif
366  DetId newid = DetId(hid.newForm());
367 #ifdef DebugLog
368  std::cout << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId() << " --> " << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
369 #endif
370  hcalHitsOrig[i].setID(newid.rawId());
371  hcalHits.push_back(hcalHitsOrig[i]);
372  }
373  }
374 
375  if(hbhegeo) {
376  if(theHBHEDigitizer) theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
377  if(theHBHEQIE11Digitizer) theHBHEQIE11Digitizer->add(hcalHits, bunchCrossing, engine);
378  }
379 
380  if(hogeo) {
381  if(theHODigitizer) theHODigitizer->add(hcalHits, bunchCrossing, engine);
382  if(theHOSiPMDigitizer) theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
383  }
384 
385  if(hfgeo) {
386  if(theHFDigitizer) theHFDigitizer->add(hcalHits, bunchCrossing, engine);
387  if(theHFQIE10Digitizer) theHFQIE10Digitizer->add(hcalHits, bunchCrossing, engine);
388  }
389  } else {
390  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
391  }
392 
393  if(isZDC) {
394  if(zdcgeo) {
395  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
396  }
397  } else {
398  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
399  }
400 }
401 
402 void HcalDigitizer::accumulate(edm::Event const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
403  // Step A: Get Inputs
404  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
406  e.getByLabel(zdcTag, zdcHandle);
407  isZDC = zdcHandle.isValid();
408 
409  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
411  e.getByLabel(hcalTag, hcalHandle);
412  isHCAL = hcalHandle.isValid() or injectTestHits_;
413 
415  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
416  const HcalTopology *htopoP=htopo.product();
417 
418  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
419 }
420 
421 void HcalDigitizer::accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
422  // Step A: Get Inputs
423  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
425  e.getByLabel(zdcTag, zdcHandle);
426  isZDC = zdcHandle.isValid();
427 
428  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
430  e.getByLabel(hcalTag, hcalHandle);
431  isHCAL = hcalHandle.isValid();
432 
434  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
435  const HcalTopology *htopoP=htopo.product();
436 
437  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
438 }
439 
440 void HcalDigitizer::finalizeEvent(edm::Event& e, const edm::EventSetup& eventSetup, CLHEP::HepRandomEngine* engine) {
441 
442  // Step B: Create empty output
443  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
444  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
445  std::unique_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
446  std::unique_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
447  std::unique_ptr<QIE10DigiCollection> hfQIE10Result(
449  !theHFQIE10DetIds.empty() ?
452  )
453  );
454  std::unique_ptr<QIE11DigiCollection> hbheQIE11Result(
456  !theHBHEQIE11DetIds.empty() ?
457  ((HcalSiPMHitResponse *)theHBHESiPMResponse)->getReadoutFrameSize(theHBHEQIE11DetIds[0]) :
458 // theParameterMap->simParameters(theHBHEQIE11DetIds[0]).readoutFrameSize() :
460  )
461  );
462 
463  // Step C: Invoke the algorithm, getting back outputs.
464  if(isHCAL&&hbhegeo){
465  if(theHBHEDigitizer) theHBHEDigitizer->run(*hbheResult, engine);
466  if(theHBHEQIE11Digitizer) theHBHEQIE11Digitizer->run(*hbheQIE11Result, engine);
467  }
468  if(isHCAL&&hogeo) {
469  if(theHODigitizer) theHODigitizer->run(*hoResult, engine);
470  if(theHOSiPMDigitizer) theHOSiPMDigitizer->run(*hoResult, engine);
471  }
472  if(isHCAL&&hfgeo) {
473  if(theHFDigitizer) theHFDigitizer->run(*hfResult, engine);
474  if(theHFQIE10Digitizer) theHFQIE10Digitizer->run(*hfQIE10Result, engine);
475  }
476  if(isZDC&&zdcgeo) {
477  theZDCDigitizer->run(*zdcResult, engine);
478  }
479 
480  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
481  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
482  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
483  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
484  edm::LogInfo("HcalDigitizer") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
485  edm::LogInfo("HcalDigitizer") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
486 
487 #ifdef DebugLog
488  std::cout << std::endl;
489  std::cout << "HCAL HBHE digis : " << hbheResult->size() << std::endl;
490  std::cout << "HCAL HO digis : " << hoResult->size() << std::endl;
491  std::cout << "HCAL HF digis : " << hfResult->size() << std::endl;
492  std::cout << "HCAL ZDC digis : " << zdcResult->size() << std::endl;
493  std::cout << "HCAL HF QIE10 digis : " << hfQIE10Result->size() << std::endl;
494  std::cout << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size() << std::endl;
495 #endif
496 
497  // Step D: Put outputs into event
498  e.put(std::move(hbheResult));
499  e.put(std::move(hoResult));
500  e.put(std::move(hfResult));
501  e.put(std::move(zdcResult));
502  e.put(std::move(hfQIE10Result), "HFQIE10DigiCollection");
503  e.put(std::move(hbheQIE11Result), "HBHEQIE11DigiCollection");
504 
505  if(debugCS_){
506  std::unique_ptr<CaloSamplesCollection> csResult(new CaloSamplesCollection());
507  //smush together all the results
508  if(theHBHEDigitizer) csResult->insert(csResult->end(),theHBHEDigitizer->getCaloSamples().begin(),theHBHEDigitizer->getCaloSamples().end());
509  if(theHBHEQIE11Digitizer) csResult->insert(csResult->end(),theHBHEQIE11Digitizer->getCaloSamples().begin(),theHBHEQIE11Digitizer->getCaloSamples().end());
510  if(theHODigitizer) csResult->insert(csResult->end(),theHODigitizer->getCaloSamples().begin(),theHODigitizer->getCaloSamples().end());
511  if(theHOSiPMDigitizer) csResult->insert(csResult->end(),theHOSiPMDigitizer->getCaloSamples().begin(),theHOSiPMDigitizer->getCaloSamples().end());
512  if(theHFDigitizer) csResult->insert(csResult->end(),theHFDigitizer->getCaloSamples().begin(),theHFDigitizer->getCaloSamples().end());
513  if(theHFQIE10Digitizer) csResult->insert(csResult->end(),theHFQIE10Digitizer->getCaloSamples().begin(),theHFQIE10Digitizer->getCaloSamples().end());
514  csResult->insert(csResult->end(),theZDCDigitizer->getCaloSamples().begin(),theZDCDigitizer->getCaloSamples().end());
515  e.put(std::move(csResult),"HcalSamples");
516  }
517 
518  if(injectTestHits_){
519  std::unique_ptr<edm::PCaloHitContainer> pcResult(new edm::PCaloHitContainer());
520  pcResult->insert(pcResult->end(),injectedHits_.begin(),injectedHits_.end());
521  e.put(std::move(pcResult),"HcalHits");
522  }
523 
524 #ifdef DebugLog
525  std::cout << std::endl << "========> HcalDigitizer e.put " << std::endl << std::endl;
526 #endif
527 
528 }
529 
530 
532  checkGeometry(es);
533  theShapes->beginRun(es);
534 
535  if (agingFlagHB) {
537  es.get<HBHEDarkeningRecord>().get("HB",hdark);
538  m_HBDarkening = &*hdark;
539  }
540  if (agingFlagHE) {
542  es.get<HBHEDarkeningRecord>().get("HE",hdark);
543  m_HEDarkening = &*hdark;
544  }
545 
547  es.get<HcalTimeSlewRecord>().get("HBHE", delay);
548  hcalTimeSlew_delay_ = &*delay;
549 
554 }
555 
556 
558  theShapes->endRun();
559 }
560 
561 
563  // TODO find a way to avoid doing this every event
565  eventSetup.get<CaloGeometryRecord>().get(geometry);
567  eventSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
568 
569  // See if it's been updated
570  if (&*geometry != theGeometry) {
571  theGeometry = &*geometry;
572  theRecNumber= &*pHRNDC;
573  updateGeometry(eventSetup);
574  }
575 }
576 
577 
587 
588  const std::vector<DetId>& hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
589  const std::vector<DetId>& heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
590  const std::vector<DetId>& hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
591  const std::vector<DetId>& hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
592  const std::vector<DetId>& zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
593  //const std::vector<DetId>& hcalTrigCells = geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower);
594  //const std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
595 // std::cout<<"HcalDigitizer::CheckGeometry number of cells: "<<zdcCells.size()<<std::endl;
596  if(zdcCells.empty()) zdcgeo = false;
597  if(hbCells.empty() && heCells.empty()) hbhegeo = false;
598  if(hoCells.empty()) hogeo = false;
599  if(hfCells.empty()) hfgeo = false;
600  // combine HB & HE
601 
602  hbheCells = hbCells;
603  if( !killHE_) {
604  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
605  }
606  //handle mixed QIE8/11 scenario in HBHE
607  buildHBHEQIECells(hbheCells,eventSetup);
610 
611  if(theHOSiPMDigitizer) {
612  buildHOSiPMCells(hoCells, eventSetup);
614  ((HcalSiPMHitResponse *)theHOSiPMResponse)->setDetIds(hoCells);
615  }
616 
617  //handle mixed QIE8/10 scenario in HF
618  buildHFQIECells(hfCells,eventSetup);
619 
620  theZDCDigitizer->setDetIds(zdcCells);
621 
622  //fill test hits collection if desired and empty
623  if(injectTestHits_ && injectedHits_.empty() && !injectedHitsCells_.empty() && !injectedHitsEnergy_.empty()){
624  //make list of specified cells if desired
625  std::vector<DetId> testCells;
626  if(injectedHitsCells_.size()>=4){
627  testCells.reserve(injectedHitsCells_.size()/4);
628  for(unsigned ic = 0; ic < injectedHitsCells_.size(); ic += 4){
629  if(ic+4 > injectedHitsCells_.size()) break;
630  testCells.push_back(HcalDetId((HcalSubdetector)injectedHitsCells_[ic],injectedHitsCells_[ic+1],
632  }
633  }
634  else{
635  int testSubdet = injectedHitsCells_[0];
636  if(testSubdet==HcalBarrel) testCells = hbCells;
637  else if(testSubdet==HcalEndcap) testCells = heCells;
638  else if(testSubdet==HcalForward) testCells = hfCells;
639  else if(testSubdet==HcalOuter) testCells = hoCells;
640  else throw cms::Exception("Configuration") << "Unknown subdet " << testSubdet << " for HCAL test hit injection";
641  }
642  bool useHitTimes = (injectedHitsTime_.size()==injectedHitsEnergy_.size());
643  injectedHits_.reserve(testCells.size()*injectedHitsEnergy_.size());
644  for(unsigned ih = 0; ih < injectedHitsEnergy_.size(); ++ih){
645  double tmp = useHitTimes ? injectedHitsTime_[ih] : 0.;
646  for(auto& aCell: testCells){
647  injectedHits_.emplace_back(aCell,injectedHitsEnergy_[ih],tmp);
648  }
649  }
650  }
651 }
652 
653 void HcalDigitizer::buildHFQIECells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
654  //if results are already cached, no need to look again
655  if(!theHFQIE8DetIds.empty() || !theHFQIE10DetIds.empty()) return;
656 
657  //get the QIETypes
659  eventSetup.get<HcalQIETypesRcd>().get(q);
661  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
662 
663  HcalQIETypes qieTypes(*q.product());
664  if (qieTypes.topo()==nullptr) {
665  qieTypes.setTopo(htopo.product());
666  }
667 
668  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
669  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
670  if(qieType == QIE8) {
671  theHFQIE8DetIds.push_back(*detItr);
672  } else if(qieType == QIE10) {
673  theHFQIE10DetIds.push_back(*detItr);
674  } else { //default is QIE8
675  theHFQIE8DetIds.push_back(*detItr);
676  }
677  }
678 
680  else {
681  delete theHFDigitizer;
682  theHFDigitizer = nullptr;
683  }
684 
686  else {
687  delete theHFQIE10Digitizer;
688  theHFQIE10Digitizer = nullptr;
689  }
690 }
691 
692 void HcalDigitizer::buildHBHEQIECells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
693  //if results are already cached, no need to look again
694  if(!theHBHEQIE8DetIds.empty() || !theHBHEQIE11DetIds.empty()) return;
695 
696  //get the QIETypes
698  eventSetup.get<HcalQIETypesRcd>().get(q);
700  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
701 
702  HcalQIETypes qieTypes(*q.product());
703  if (qieTypes.topo()==nullptr) {
704  qieTypes.setTopo(htopo.product());
705  }
706 
707  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
708  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
709  if(qieType == QIE8) {
710  theHBHEQIE8DetIds.push_back(*detItr);
711  }
712  else if(qieType == QIE11) {
713  theHBHEQIE11DetIds.push_back(*detItr);
714  }
715  else { //default is QIE8
716  theHBHEQIE8DetIds.push_back(*detItr);
717  }
718  }
719 
721  else {
722  delete theHBHEDigitizer;
723  theHBHEDigitizer = nullptr;
724  }
725 
727  else {
728  delete theHBHEQIE11Digitizer;
729  theHBHEQIE11Digitizer = nullptr;
730  }
731 
732  if(!theHBHEQIE8DetIds.empty() && !theHBHEQIE11DetIds.empty()){
735  }
736 }
737 
738 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
739  // all HPD
740 
741  if(theHOSiPMCode == 0) {
742  theHODigitizer->setDetIds(allCells);
743  } else if(theHOSiPMCode == 1) {
744  theHOSiPMDigitizer->setDetIds(allCells);
745  // FIXME pick Zecotek or hamamatsu?
746  } else if(theHOSiPMCode == 2) {
747  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
749  eventSetup.get<HcalMCParamsRcd>().get(p);
751  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
752 
753  HcalMCParams mcParams(*p.product());
754  if (mcParams.topo()==nullptr) {
755  mcParams.setTopo(htopo.product());
756  }
757 
758  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
759  int shapeType = mcParams.getValues(*detItr)->signalShape();
760  if(shapeType == HcalShapes::ZECOTEK) {
761  zecotekDetIds.emplace_back(*detItr);
762  theHOSiPMDetIds.push_back(*detItr);
763  } else if(shapeType == HcalShapes::HAMAMATSU) {
764  hamamatsuDetIds.emplace_back(*detItr);
765  theHOSiPMDetIds.push_back(*detItr);
766  } else {
767  theHOHPDDetIds.push_back(*detItr);
768  }
769  }
770 
772  else {
773  delete theHODigitizer;
774  theHODigitizer = nullptr;
775  }
776 
778  else {
779  delete theHOSiPMDigitizer;
780  theHOSiPMDigitizer = nullptr;
781  }
782 
783  if(!theHOHPDDetIds.empty() && !theHOSiPMDetIds.empty()){
786  }
787 
788  theParameterMap->setHOZecotekDetIds(zecotekDetIds);
789  theParameterMap->setHOHamamatsuDetIds(hamamatsuDetIds);
790 
791  // make sure we don't got through this exercise again
792  theHOSiPMCode = -2;
793  }
794 }
795 
796 void HcalDigitizer::darkening(std::vector<PCaloHit>& hcalHits) {
797 
798  for (unsigned int ii=0; ii<hcalHits.size(); ++ii) {
799  uint32_t tmpId = hcalHits[ii].id();
800  int det, z, depth, ieta, phi, lay;
801  HcalTestNumbering::unpackHcalIndex(tmpId,det,z,depth,ieta,phi,lay);
802 
803  bool darkened = false;
804  float dweight = 1.;
805 
806  if(det==int(HcalBarrel) && m_HBDarkening){
807  //HB darkening
808  dweight = m_HBDarkening->degradation(deliveredLumi,ieta,lay);
809  darkened = true;
810  }
811  else if(det==int(HcalEndcap) && m_HEDarkening){
812  //HE darkening
813  dweight = m_HEDarkening->degradation(deliveredLumi,ieta,lay);
814  darkened = true;
815  }
816  else if(det==int(HcalForward) && m_HFRecalibration){
817  //HF darkening - approximate: invert recalibration factor
818  dweight = 1.0/m_HFRecalibration->getCorr(ieta,depth,deliveredLumi);
819  darkened = true;
820  }
821 
822  //reset hit energy
823  if(darkened) hcalHits[ii].setEnergy(hcalHits[ii].energy()*dweight);
824  }
825 
826 }
827 
828 
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:98
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:72
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:84
void checkGeometry(const edm::EventSetup &eventSetup)
HcalSimParameterMap * theParameterMap
Definition: HcalDigitizer.h:90
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:83
#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: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:91
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:86
CaloHitResponse * theHOResponse
Definition: HcalDigitizer.h:95
CaloHitResponse * theHOSiPMResponse
Definition: HcalDigitizer.h:96
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
Definition: HcalDigitizer.h:99
void endRun()
Definition: HcalShapes.cc:73
ii
Definition: cuy.py:588
CaloTDigitizer< HFDigitizerTraits, CaloTDigitizerQIE8Run > HFDigitizer
Definition: HcalDigitizer.h:85
void setNoiseSignalGenerator(const CaloVNoiseSignalGenerator *noiseSignalGenerator)
Definition: HcalAmplifier.h:32
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: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)
HcalAmplifier * theHOAmplifier
std::vector< DetId > theHFQIE8DetIds
void setDbService(const HcalDbService *service)
const T & get() const
Definition: EventSetup.h:58
HcalElectronicsSim * theHBHEElectronicsSim
uint32_t newForm() const
Definition: HcalDetId.cc:142
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
CaloHitResponse * theHBHEResponse
Definition: HcalDigitizer.h:93
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:71
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
Definition: HcalDigitizer.h:97
CaloTDigitizer< HcalQIE11DigitizerTraits, CaloTDigitizerQIE1011Run > QIE11Digitizer
Definition: HcalDigitizer.h:88
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:58
void setDebugCaloSamples(bool debug)
CaloHitResponse * theHBHESiPMResponse
Definition: HcalDigitizer.h:94
const CaloSimParameters & simParameters(const DetId &id) const override
CaloTDigitizer< HcalQIE10DigitizerTraits, CaloTDigitizerQIE1011Run > QIE10Digitizer
Definition: HcalDigitizer.h:87
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)