CMS 3D CMS Logo

HcalDigitizer.cc
Go to the documentation of this file.
29 #include <boost/foreach.hpp>
30 #include <memory>
31 
32 //#define EDM_ML_DEBUG
33 
35  : conditionsToken_(iC.esConsumes()),
36  topoToken_(iC.esConsumes()),
37  hcalTimeSlew_delay_token_(iC.esConsumes(edm::ESInputTag("", "HBHE"))),
38  theGeometryToken(iC.esConsumes()),
39  theRecNumberToken(iC.esConsumes()),
40  qieTypesToken_(iC.esConsumes()),
41  theGeometry(nullptr),
42  theRecNumber(nullptr),
43  theParameterMap(ps),
44  theShapes(),
45  theHBHEResponse(std::make_unique<CaloHitResponse>(&theParameterMap, &theShapes)),
46  theHBHESiPMResponse(std::make_unique<HcalSiPMHitResponse>(
47  &theParameterMap, &theShapes, ps.getParameter<bool>("HcalPreMixStage1"), true)),
48  theHOResponse(std::make_unique<CaloHitResponse>(&theParameterMap, &theShapes)),
49  theHOSiPMResponse(std::make_unique<HcalSiPMHitResponse>(
50  &theParameterMap, &theShapes, ps.getParameter<bool>("HcalPreMixStage1"), false)),
51  theHFResponse(std::make_unique<CaloHitResponse>(&theParameterMap, &theShapes)),
52  theHFQIE10Response(std::make_unique<CaloHitResponse>(
53  &theParameterMap, &theShapes, ps.getParameter<bool>("HcalPreMixStage1"), true)),
54  theZDCResponse(std::make_unique<CaloHitResponse>(
55  &theParameterMap, &theShapes, ps.getParameter<bool>("HcalPreMixStage1"), false)),
56  theHBHEAmplifier(nullptr),
57  theHFAmplifier(nullptr),
58  theHOAmplifier(nullptr),
59  theZDCAmplifier(nullptr),
60  theHFQIE10Amplifier(nullptr),
61  theHBHEQIE11Amplifier(nullptr),
62  theIonFeedback(nullptr),
63  theCoderFactory(nullptr),
64  theHBHEElectronicsSim(nullptr),
65  theHFElectronicsSim(nullptr),
66  theHOElectronicsSim(nullptr),
67  theZDCElectronicsSim(nullptr),
68  theHFQIE10ElectronicsSim(nullptr),
69  theHBHEQIE11ElectronicsSim(nullptr),
70  theHBHEHitFilter(),
71  theHBHEQIE11HitFilter(),
72  theHFHitFilter(),
73  theHFQIE10HitFilter(),
74  theHOHitFilter(),
75  theHOSiPMHitFilter(),
76  theZDCHitFilter(),
77  theHBHEDigitizer(nullptr),
78  theHODigitizer(nullptr),
79  theHOSiPMDigitizer(nullptr),
80  theHFDigitizer(nullptr),
81  theZDCDigitizer(nullptr),
82  theHFQIE10Digitizer(nullptr),
83  theHBHEQIE11Digitizer(nullptr),
84  theRelabeller(nullptr),
85  isZDC(true),
86  isHCAL(true),
87  zdcgeo(true),
88  hbhegeo(true),
89  hogeo(true),
90  hfgeo(true),
91  doHFWindow_(ps.getParameter<bool>("doHFWindow")),
92  killHE_(ps.getParameter<bool>("killHE")),
93  debugCS_(ps.getParameter<bool>("debugCaloSamples")),
94  ignoreTime_(ps.getParameter<bool>("ignoreGeantTime")),
95  injectTestHits_(ps.getParameter<bool>("injectTestHits")),
96  hitsProducer_(ps.getParameter<std::string>("hitsProducer")),
97  theHOSiPMCode(ps.getParameter<edm::ParameterSet>("ho").getParameter<int>("siPMCode")),
98  deliveredLumi(0.),
99  agingFlagHB(ps.getParameter<bool>("HBDarkening")),
100  agingFlagHE(ps.getParameter<bool>("HEDarkening")),
101  zdcToken_(iC.consumes(edm::InputTag(hitsProducer_, "ZDCHITS"))),
102  hcalToken_(iC.consumes(edm::InputTag(hitsProducer_, "HcalHits"))),
103  m_HBDarkening(nullptr),
104  m_HEDarkening(nullptr),
105  m_HFRecalibration(nullptr),
106  injectedHitsEnergy_(ps.getParameter<std::vector<double>>("injectTestHitsEnergy")),
107  injectedHitsTime_(ps.getParameter<std::vector<double>>("injectTestHitsTime")),
108  injectedHitsCells_(ps.getParameter<std::vector<int>>("injectTestHitsCells")) {
109  if (agingFlagHB) {
111  }
112  if (agingFlagHE) {
114  }
115  if (theHOSiPMCode == 2) {
116  mcParamsToken_ = iC.esConsumes();
117  }
118 
119  bool doNoise = ps.getParameter<bool>("doNoise");
120 
121  bool PreMix1 = ps.getParameter<bool>("HcalPreMixStage1"); // special threshold/pedestal treatment
122  bool PreMix2 = ps.getParameter<bool>("HcalPreMixStage2"); // special threshold/pedestal treatment
123  bool doEmpty = ps.getParameter<bool>("doEmpty");
124  deliveredLumi = ps.getParameter<double>("DelivLuminosity");
125  bool agingFlagHF = ps.getParameter<bool>("HFDarkening");
126  double minFCToDelay = ps.getParameter<double>("minFCToDelay");
127 
128  if (PreMix1 && PreMix2) {
129  throw cms::Exception("Configuration") << "HcalDigitizer cannot operate in PreMixing digitization and "
130  "PreMixing\n"
131  "digi combination modes at the same time. Please set one mode to "
132  "False\n"
133  "in the configuration file.";
134  }
135 
136  // need to make copies, because they might get different noise generators
137  theHBHEAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
138  theHFAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
139  theHOAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
140  theZDCAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
141  theHFQIE10Amplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
142  theHBHEQIE11Amplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
143 
144  theCoderFactory = std::make_unique<HcalCoderFactory>(HcalCoderFactory::DB);
145 
147  std::make_unique<HcalElectronicsSim>(&theParameterMap, theHBHEAmplifier.get(), theCoderFactory.get(), PreMix1);
149  std::make_unique<HcalElectronicsSim>(&theParameterMap, theHFAmplifier.get(), theCoderFactory.get(), PreMix1);
151  std::make_unique<HcalElectronicsSim>(&theParameterMap, theHOAmplifier.get(), theCoderFactory.get(), PreMix1);
153  std::make_unique<HcalElectronicsSim>(&theParameterMap, theZDCAmplifier.get(), theCoderFactory.get(), PreMix1);
155  std::make_unique<HcalElectronicsSim>(&theParameterMap,
156  theHFQIE10Amplifier.get(),
157  theCoderFactory.get(),
158  PreMix1); // should this use a different coder factory?
160  std::make_unique<HcalElectronicsSim>(&theParameterMap,
161  theHBHEQIE11Amplifier.get(),
162  theCoderFactory.get(),
163  PreMix1); // should this use a different coder factory?
164 
165  bool doHOHPD = (theHOSiPMCode != 1);
166  bool doHOSiPM = (theHOSiPMCode != 0);
167  if (doHOHPD) {
168  theHOResponse = std::make_unique<CaloHitResponse>(&theParameterMap, &theShapes);
169  theHOResponse->setHitFilter(&theHOHitFilter);
170  theHODigitizer = std::make_unique<HODigitizer>(theHOResponse.get(), theHOElectronicsSim.get(), doEmpty);
171  }
172  if (doHOSiPM) {
173  theHOSiPMResponse->setHitFilter(&theHOSiPMHitFilter);
174  theHOSiPMDigitizer = std::make_unique<HODigitizer>(theHOSiPMResponse.get(), theHOElectronicsSim.get(), doEmpty);
175  }
176 
177  theHBHEResponse->setHitFilter(&theHBHEHitFilter);
179 
180  // QIE8 and QIE11 can coexist in HBHE
182  std::make_unique<QIE11Digitizer>(theHBHESiPMResponse.get(), theHBHEQIE11ElectronicsSim.get(), doEmpty);
183  theHBHEDigitizer = std::make_unique<HBHEDigitizer>(theHBHEResponse.get(), theHBHEElectronicsSim.get(), doEmpty);
184 
185  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
186  // initialize: they won't be called later if flag is set
187  hcalTimeSlew_delay_ = nullptr;
188  theTimeSlewSim.reset(nullptr);
189  if (doTimeSlew) {
190  // no time slewing for HF
191  theTimeSlewSim = std::make_unique<HcalTimeSlewSim>(&theParameterMap, minFCToDelay);
192  theHBHEAmplifier->setTimeSlewSim(theTimeSlewSim.get());
193  theHBHEQIE11Amplifier->setTimeSlewSim(theTimeSlewSim.get());
194  theHOAmplifier->setTimeSlewSim(theTimeSlewSim.get());
195  theZDCAmplifier->setTimeSlewSim(theTimeSlewSim.get());
196  }
197 
198  theHFResponse->setHitFilter(&theHFHitFilter);
199  theHFQIE10Response->setHitFilter(&theHFQIE10HitFilter);
200  theZDCResponse->setHitFilter(&theZDCHitFilter);
201 
202  // QIE8 and QIE10 can coexist in HF
204  std::make_unique<QIE10Digitizer>(theHFQIE10Response.get(), theHFQIE10ElectronicsSim.get(), doEmpty);
205  theHFDigitizer = std::make_unique<HFDigitizer>(theHFResponse.get(), theHFElectronicsSim.get(), doEmpty);
206 
207  theZDCDigitizer = std::make_unique<ZDCDigitizer>(theZDCResponse.get(), theZDCElectronicsSim.get(), doEmpty);
208 
209  testNumbering_ = ps.getParameter<bool>("TestNumbering");
210  // edm::LogVerbatim("HcalSim") << "Flag to see if Hit Relabeller to be initiated " << testNumbering_;
211  if (testNumbering_)
212  theRelabeller = std::make_unique<HcalHitRelabeller>(ps.getParameter<bool>("doNeutralDensityFilter"));
213 
214  if (ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
215  theIonFeedback = std::make_unique<HPDIonFeedbackSim>(ps, &theShapes);
216  theHBHEResponse->setPECorrection(theIonFeedback.get());
217  if (ps.getParameter<bool>("doThermalNoise")) {
218  theHBHEAmplifier->setIonFeedbackSim(theIonFeedback.get());
219  }
220  }
221 
222  // option to save CaloSamples as event product for debugging
223  if (debugCS_) {
224  if (theHBHEDigitizer)
225  theHBHEDigitizer->setDebugCaloSamples(true);
227  theHBHEQIE11Digitizer->setDebugCaloSamples(true);
228  if (theHODigitizer)
229  theHODigitizer->setDebugCaloSamples(true);
230  if (theHOSiPMDigitizer)
231  theHOSiPMDigitizer->setDebugCaloSamples(true);
232  if (theHFDigitizer)
233  theHFDigitizer->setDebugCaloSamples(true);
235  theHFQIE10Digitizer->setDebugCaloSamples(true);
236  theZDCDigitizer->setDebugCaloSamples(true);
237  }
238 
239  // option to ignore Geant time distribution in SimHits, for debugging
240  if (ignoreTime_) {
241  theHBHEResponse->setIgnoreGeantTime(ignoreTime_);
242  theHBHESiPMResponse->setIgnoreGeantTime(ignoreTime_);
243  theHOResponse->setIgnoreGeantTime(ignoreTime_);
244  theHOSiPMResponse->setIgnoreGeantTime(ignoreTime_);
245  theHFResponse->setIgnoreGeantTime(ignoreTime_);
246  theHFQIE10Response->setIgnoreGeantTime(ignoreTime_);
247  theZDCResponse->setIgnoreGeantTime(ignoreTime_);
248  }
249 
250  if (agingFlagHF)
251  m_HFRecalibration = std::make_unique<HFRecalibration>(ps.getParameter<edm::ParameterSet>("HFRecalParameterBlock"));
252 }
253 
255 
257  noiseGenerator->setParameterMap(&theParameterMap);
258  noiseGenerator->setElectronicsSim(theHBHEElectronicsSim.get());
259  if (theHBHEDigitizer)
260  theHBHEDigitizer->setNoiseSignalGenerator(noiseGenerator);
261  theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
262 }
263 
265  noiseGenerator->setParameterMap(&theParameterMap);
266  noiseGenerator->setElectronicsSim(theHBHEQIE11ElectronicsSim.get());
268  theHBHEQIE11Digitizer->setNoiseSignalGenerator(noiseGenerator);
269  theHBHEQIE11Amplifier->setNoiseSignalGenerator(noiseGenerator);
270 }
271 
273  noiseGenerator->setParameterMap(&theParameterMap);
274  noiseGenerator->setElectronicsSim(theHFElectronicsSim.get());
275  if (theHFDigitizer)
276  theHFDigitizer->setNoiseSignalGenerator(noiseGenerator);
277  theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
278 }
279 
281  noiseGenerator->setParameterMap(&theParameterMap);
282  noiseGenerator->setElectronicsSim(theHFQIE10ElectronicsSim.get());
284  theHFQIE10Digitizer->setNoiseSignalGenerator(noiseGenerator);
285  theHFQIE10Amplifier->setNoiseSignalGenerator(noiseGenerator);
286 }
287 
289  noiseGenerator->setParameterMap(&theParameterMap);
290  noiseGenerator->setElectronicsSim(theHOElectronicsSim.get());
291  if (theHODigitizer)
292  theHODigitizer->setNoiseSignalGenerator(noiseGenerator);
293  if (theHOSiPMDigitizer)
294  theHOSiPMDigitizer->setNoiseSignalGenerator(noiseGenerator);
295  theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
296 }
297 
299  noiseGenerator->setParameterMap(&theParameterMap);
300  noiseGenerator->setElectronicsSim(theZDCElectronicsSim.get());
301  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
302  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
303 }
304 
306  setup(eventSetup);
307 
308  // get the appropriate gains, noises, & widths for this event
310 
312 
313  theHBHEAmplifier->setDbService(conditions);
314  theHFAmplifier->setDbService(conditions);
315  theHOAmplifier->setDbService(conditions);
316  theZDCAmplifier->setDbService(conditions);
317  theHFQIE10Amplifier->setDbService(conditions);
318  theHBHEQIE11Amplifier->setDbService(conditions);
319 
320  theHFQIE10ElectronicsSim->setDbService(conditions);
321  theHBHEQIE11ElectronicsSim->setDbService(conditions);
322 
323  theCoderFactory->setDbService(conditions);
325 
326  // initialize hits
327  if (theHBHEDigitizer)
328  theHBHEDigitizer->initializeHits();
330  theHBHEQIE11Digitizer->initializeHits();
331  if (theHODigitizer)
332  theHODigitizer->initializeHits();
333  if (theHOSiPMDigitizer)
334  theHOSiPMDigitizer->initializeHits();
336  theHFQIE10Digitizer->initializeHits();
337  if (theHFDigitizer)
338  theHFDigitizer->initializeHits();
339  theZDCDigitizer->initializeHits();
340 }
341 
342 void HcalDigitizer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit>> const &hcalHandle,
343  edm::Handle<std::vector<PCaloHit>> const &zdcHandle,
344  int bunchCrossing,
345  CLHEP::HepRandomEngine *engine,
346  const HcalTopology *htopoP) {
347  // Step A: pass in inputs, and accumulate digis
348  if (isHCAL) {
349  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
350  if (injectTestHits_)
351  hcalHitsOrig = injectedHits_;
352  std::vector<PCaloHit> hcalHits;
353  hcalHits.reserve(hcalHitsOrig.size());
354 
355  // evaluate darkening before relabeling
356  if (testNumbering_) {
358  darkening(hcalHitsOrig);
359  }
360  // Relabel PCaloHits if necessary
361  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
362  theRelabeller->process(hcalHitsOrig);
363  }
364 
365  // eliminate bad hits
366  for (unsigned int i = 0; i < hcalHitsOrig.size(); i++) {
367  DetId id(hcalHitsOrig[i].id());
368  HcalDetId hid(id);
369  if (!htopoP->validHcal(hid)) {
370  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << " " << hid;
371  continue;
372  } else if (hid.subdet() == HcalForward && !doHFWindow_ && hcalHitsOrig[i].depth() != 0) {
373  // skip HF window hits unless desired
374  continue;
375  } else if (killHE_ && hid.subdet() == HcalEndcap) {
376  // remove HE hits if asked for (phase 2)
377  continue;
378  } else {
379 #ifdef EDM_ML_DEBUG
380  edm::LogVerbatim("HcalSim") << "HcalDigitizer format " << hid.oldFormat() << " for " << hid;
381 #endif
382  DetId newid = DetId(hid.newForm());
383 #ifdef EDM_ML_DEBUG
384  edm::LogVerbatim("HcalSim") << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId()
385  << " --> " << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
386 #endif
387  hcalHitsOrig[i].setID(newid.rawId());
388  hcalHits.push_back(hcalHitsOrig[i]);
389  }
390  }
391 
392  if (hbhegeo) {
393  if (theHBHEDigitizer)
394  theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
396  theHBHEQIE11Digitizer->add(hcalHits, bunchCrossing, engine);
397  }
398 
399  if (hogeo) {
400  if (theHODigitizer)
401  theHODigitizer->add(hcalHits, bunchCrossing, engine);
402  if (theHOSiPMDigitizer)
403  theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
404  }
405 
406  if (hfgeo) {
407  if (theHFDigitizer)
408  theHFDigitizer->add(hcalHits, bunchCrossing, engine);
410  theHFQIE10Digitizer->add(hcalHits, bunchCrossing, engine);
411  }
412  } else {
413  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
414  }
415 
416  if (isZDC) {
417  if (zdcgeo) {
418  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
419  }
420  } else {
421  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
422  }
423 }
424 
425 void HcalDigitizer::accumulate(edm::Event const &e, edm::EventSetup const &eventSetup, CLHEP::HepRandomEngine *engine) {
426  // Step A: Get Inputs
427  const edm::Handle<std::vector<PCaloHit>> &zdcHandle = e.getHandle(zdcToken_);
428  isZDC = zdcHandle.isValid();
429 
430  const edm::Handle<std::vector<PCaloHit>> &hcalHandle = e.getHandle(hcalToken_);
431  isHCAL = hcalHandle.isValid() or injectTestHits_;
432 
433  const HcalTopology *htopoP = &eventSetup.getData(topoToken_);
434 
435  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
436 }
437 
440  CLHEP::HepRandomEngine *engine) {
441  // Step A: Get Inputs
442  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
444  e.getByLabel(zdcTag, zdcHandle);
445  isZDC = zdcHandle.isValid();
446 
447  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
449  e.getByLabel(hcalTag, hcalHandle);
450  isHCAL = hcalHandle.isValid();
451 
452  const HcalTopology *htopoP = &eventSetup.getData(topoToken_);
453 
454  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
455 }
456 
457 void HcalDigitizer::finalizeEvent(edm::Event &e, const edm::EventSetup &eventSetup, CLHEP::HepRandomEngine *engine) {
458  // Step B: Create empty output
459  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
460  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
461  std::unique_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
462  std::unique_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
463  std::unique_ptr<QIE10DigiCollection> hfQIE10Result(new QIE10DigiCollection(
464  !theHFQIE10DetIds.empty() ? theHFQIE10Response.get()->getReadoutFrameSize(theHFQIE10DetIds[0])
466  std::unique_ptr<QIE11DigiCollection> hbheQIE11Result(new QIE11DigiCollection(
467  !theHBHEQIE11DetIds.empty() ? theHBHESiPMResponse.get()->getReadoutFrameSize(theHBHEQIE11DetIds[0]) :
468  // theParameterMap->simParameters(theHBHEQIE11DetIds[0]).readoutFrameSize()
469  // :
471 
472  // Step C: Invoke the algorithm, getting back outputs.
473  if (isHCAL && hbhegeo) {
474  if (theHBHEDigitizer)
475  theHBHEDigitizer->run(*hbheResult, engine);
477  theHBHEQIE11Digitizer->run(*hbheQIE11Result, engine);
478  }
479  if (isHCAL && hogeo) {
480  if (theHODigitizer)
481  theHODigitizer->run(*hoResult, engine);
482  if (theHOSiPMDigitizer)
483  theHOSiPMDigitizer->run(*hoResult, engine);
484  }
485  if (isHCAL && hfgeo) {
486  if (theHFDigitizer)
487  theHFDigitizer->run(*hfResult, engine);
489  theHFQIE10Digitizer->run(*hfQIE10Result, engine);
490  }
491  if (isZDC && zdcgeo) {
492  theZDCDigitizer->run(*zdcResult, engine);
493  }
494 
495  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
496  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
497  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
498  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
499  edm::LogInfo("HcalDigitizer") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
500  edm::LogInfo("HcalDigitizer") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
501 
502 #ifdef EDM_ML_DEBUG
503  edm::LogVerbatim("HcalSim") << "\nHCAL HBHE digis : " << hbheResult->size();
504  edm::LogVerbatim("HcalSim") << "HCAL HO digis : " << hoResult->size();
505  edm::LogVerbatim("HcalSim") << "HCAL HF digis : " << hfResult->size();
506  edm::LogVerbatim("HcalSim") << "HCAL ZDC digis : " << zdcResult->size();
507  edm::LogVerbatim("HcalSim") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
508  edm::LogVerbatim("HcalSim") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
509 #endif
510 
511  // Step D: Put outputs into event
512  e.put(std::move(hbheResult));
513  e.put(std::move(hoResult));
514  e.put(std::move(hfResult));
515  e.put(std::move(zdcResult));
516  e.put(std::move(hfQIE10Result), "HFQIE10DigiCollection");
517  e.put(std::move(hbheQIE11Result), "HBHEQIE11DigiCollection");
518 
519  if (debugCS_) {
520  std::unique_ptr<CaloSamplesCollection> csResult(new CaloSamplesCollection());
521  // smush together all the results
522  if (theHBHEDigitizer)
523  csResult->insert(
524  csResult->end(), theHBHEDigitizer->getCaloSamples().begin(), theHBHEDigitizer->getCaloSamples().end());
526  csResult->insert(csResult->end(),
527  theHBHEQIE11Digitizer->getCaloSamples().begin(),
528  theHBHEQIE11Digitizer->getCaloSamples().end());
529  if (theHODigitizer)
530  csResult->insert(
531  csResult->end(), theHODigitizer->getCaloSamples().begin(), theHODigitizer->getCaloSamples().end());
532  if (theHOSiPMDigitizer)
533  csResult->insert(
534  csResult->end(), theHOSiPMDigitizer->getCaloSamples().begin(), theHOSiPMDigitizer->getCaloSamples().end());
535  if (theHFDigitizer)
536  csResult->insert(
537  csResult->end(), theHFDigitizer->getCaloSamples().begin(), theHFDigitizer->getCaloSamples().end());
539  csResult->insert(
540  csResult->end(), theHFQIE10Digitizer->getCaloSamples().begin(), theHFQIE10Digitizer->getCaloSamples().end());
541  csResult->insert(
542  csResult->end(), theZDCDigitizer->getCaloSamples().begin(), theZDCDigitizer->getCaloSamples().end());
543  e.put(std::move(csResult), "HcalSamples");
544  }
545 
546  if (injectTestHits_) {
547  std::unique_ptr<edm::PCaloHitContainer> pcResult(new edm::PCaloHitContainer());
548  pcResult->insert(pcResult->end(), injectedHits_.begin(), injectedHits_.end());
549  e.put(std::move(pcResult), "HcalHits");
550  }
551 
552 #ifdef EDM_ML_DEBUG
553  edm::LogVerbatim("HcalSim") << "\n========> HcalDigitizer e.put\n";
554 #endif
555 }
556 
558  checkGeometry(es);
559 
560  if (agingFlagHB) {
562  }
563  if (agingFlagHE) {
565  }
566 
568 
571  theHOAmplifier->setTimeSlew(hcalTimeSlew_delay_);
572  theZDCAmplifier->setTimeSlew(hcalTimeSlew_delay_);
573 }
574 
578 
579  if (theHBHEResponse)
580  theHBHEResponse->setGeometry(theGeometry);
582  theHBHESiPMResponse->setGeometry(theGeometry);
583  if (theHOResponse)
584  theHOResponse->setGeometry(theGeometry);
585  if (theHOSiPMResponse)
586  theHOSiPMResponse->setGeometry(theGeometry);
587  theHFResponse->setGeometry(theGeometry);
588  theHFQIE10Response->setGeometry(theGeometry);
589  theZDCResponse->setGeometry(theGeometry);
590  if (theRelabeller)
591  theRelabeller->setGeometry(theRecNumber);
592 
593  // See if it's been updated
594  bool check1 = theGeometryWatcher_.check(eventSetup);
595  bool check2 = theRecNumberWatcher_.check(eventSetup);
596  if (check1 or check2) {
598  }
599 }
600 
602  const std::vector<DetId> &hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
603  const std::vector<DetId> &heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
604  const std::vector<DetId> &hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
605  const std::vector<DetId> &hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
606  const std::vector<DetId> &zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
607  // const std::vector<DetId>& hcalTrigCells =
608  // geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower); const
609  // std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo,
610  // HcalCastorDetId::SubdetectorId);
611  // edm::LogVerbatim("HcalSim") <<"HcalDigitizer::CheckGeometry number of cells: << zdcCells.size();
612  if (zdcCells.empty())
613  zdcgeo = false;
614  if (hbCells.empty() && heCells.empty())
615  hbhegeo = false;
616  if (hoCells.empty())
617  hogeo = false;
618  if (hfCells.empty())
619  hfgeo = false;
620  // combine HB & HE
621 
622  hbheCells = hbCells;
623  if (!killHE_) {
624  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
625  }
626  // handle mixed QIE8/11 scenario in HBHE
630 
631  if (theHOSiPMDigitizer) {
632  buildHOSiPMCells(hoCells, eventSetup);
633  if (theHOSiPMResponse)
634  theHOSiPMResponse->setDetIds(hoCells);
635  }
636 
637  // handle mixed QIE8/10 scenario in HF
638  buildHFQIECells(hfCells, eventSetup);
639 
640  theZDCDigitizer->setDetIds(zdcCells);
641 
642  // fill test hits collection if desired and empty
643  if (injectTestHits_ && injectedHits_.empty() && !injectedHitsCells_.empty() && !injectedHitsEnergy_.empty()) {
644  // make list of specified cells if desired
645  std::vector<DetId> testCells;
646  if (injectedHitsCells_.size() >= 4) {
647  testCells.reserve(injectedHitsCells_.size() / 4);
648  for (unsigned ic = 0; ic < injectedHitsCells_.size(); ic += 4) {
649  if (ic + 4 > injectedHitsCells_.size())
650  break;
651  testCells.push_back(HcalDetId((HcalSubdetector)injectedHitsCells_[ic],
652  injectedHitsCells_[ic + 1],
653  injectedHitsCells_[ic + 2],
654  injectedHitsCells_[ic + 3]));
655  }
656  } else {
657  int testSubdet = injectedHitsCells_[0];
658  if (testSubdet == HcalBarrel)
659  testCells = hbCells;
660  else if (testSubdet == HcalEndcap)
661  testCells = heCells;
662  else if (testSubdet == HcalForward)
663  testCells = hfCells;
664  else if (testSubdet == HcalOuter)
665  testCells = hoCells;
666  else
667  throw cms::Exception("Configuration") << "Unknown subdet " << testSubdet << " for HCAL test hit injection";
668  }
669  bool useHitTimes = (injectedHitsTime_.size() == injectedHitsEnergy_.size());
670  injectedHits_.reserve(testCells.size() * injectedHitsEnergy_.size());
671  for (unsigned ih = 0; ih < injectedHitsEnergy_.size(); ++ih) {
672  double tmp = useHitTimes ? injectedHitsTime_[ih] : 0.;
673  for (auto &aCell : testCells) {
674  injectedHits_.emplace_back(aCell, injectedHitsEnergy_[ih], tmp);
675  }
676  }
677  }
678 }
679 
680 void HcalDigitizer::buildHFQIECells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
681  // if results are already cached, no need to look again
682  if (!theHFQIE8DetIds.empty() || !theHFQIE10DetIds.empty())
683  return;
684 
685  // get the QIETypes
686  // intentional copy
687  HcalQIETypes qieTypes = eventSetup.getData(qieTypesToken_);
688  if (qieTypes.topo() == nullptr) {
689  qieTypes.setTopo(&eventSetup.getData(topoToken_));
690  }
691 
692  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
693  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
694  if (qieType == QIE8) {
695  theHFQIE8DetIds.push_back(*detItr);
696  } else if (qieType == QIE10) {
697  theHFQIE10DetIds.push_back(*detItr);
698  } else { // default is QIE8
699  theHFQIE8DetIds.push_back(*detItr);
700  }
701  }
702 
703  if (!theHFQIE8DetIds.empty())
704  theHFDigitizer->setDetIds(theHFQIE8DetIds);
705  else {
706  theHFDigitizer.reset();
707  }
708 
709  if (!theHFQIE10DetIds.empty())
711  else {
712  theHFQIE10Digitizer.reset();
713  }
714 }
715 
716 void HcalDigitizer::buildHBHEQIECells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
717  // if results are already cached, no need to look again
718  if (!theHBHEQIE8DetIds.empty() || !theHBHEQIE11DetIds.empty())
719  return;
720 
721  // get the QIETypes
722  // intentional copy
723  HcalQIETypes qieTypes = eventSetup.getData(qieTypesToken_);
724  if (qieTypes.topo() == nullptr) {
725  qieTypes.setTopo(&eventSetup.getData(topoToken_));
726  }
727 
728  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
729  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
730  if (qieType == QIE8) {
731  theHBHEQIE8DetIds.push_back(*detItr);
732  } else if (qieType == QIE11) {
733  theHBHEQIE11DetIds.push_back(*detItr);
734  } else { // default is QIE8
735  theHBHEQIE8DetIds.push_back(*detItr);
736  }
737  }
738 
739  if (!theHBHEQIE8DetIds.empty())
741  else {
742  theHBHEDigitizer.reset();
743  }
744 
745  if (!theHBHEQIE11DetIds.empty())
747  else {
748  theHBHEQIE11Digitizer.reset();
749  }
750 
751  if (!theHBHEQIE8DetIds.empty() && !theHBHEQIE11DetIds.empty()) {
754  }
755 }
756 
757 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
758  // all HPD
759 
760  if (theHOSiPMCode == 0) {
761  theHODigitizer->setDetIds(allCells);
762  } else if (theHOSiPMCode == 1) {
763  theHOSiPMDigitizer->setDetIds(allCells);
764  // FIXME pick Zecotek or hamamatsu?
765  } else if (theHOSiPMCode == 2) {
766  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
767 
768  // intentional copy
769  HcalMCParams mcParams = eventSetup.getData(mcParamsToken_);
770  if (mcParams.topo() == nullptr) {
771  mcParams.setTopo(&eventSetup.getData(topoToken_));
772  }
773 
774  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
775  int shapeType = mcParams.getValues(*detItr)->signalShape();
776  if (shapeType == HcalShapes::ZECOTEK) {
777  zecotekDetIds.emplace_back(*detItr);
778  theHOSiPMDetIds.push_back(*detItr);
779  } else if (shapeType == HcalShapes::HAMAMATSU) {
780  hamamatsuDetIds.emplace_back(*detItr);
781  theHOSiPMDetIds.push_back(*detItr);
782  } else {
783  theHOHPDDetIds.push_back(*detItr);
784  }
785  }
786 
787  if (!theHOHPDDetIds.empty())
788  theHODigitizer->setDetIds(theHOHPDDetIds);
789  else {
790  theHODigitizer.reset();
791  }
792 
793  if (!theHOSiPMDetIds.empty())
795  else {
796  theHOSiPMDigitizer.reset();
797  }
798 
799  if (!theHOHPDDetIds.empty() && !theHOSiPMDetIds.empty()) {
802  }
803 
804  theParameterMap.setHOZecotekDetIds(zecotekDetIds);
805  theParameterMap.setHOHamamatsuDetIds(hamamatsuDetIds);
806 
807  // make sure we don't got through this exercise again
808  theHOSiPMCode = -2;
809  }
810 }
811 
812 void HcalDigitizer::darkening(std::vector<PCaloHit> &hcalHits) {
813  for (unsigned int ii = 0; ii < hcalHits.size(); ++ii) {
814  uint32_t tmpId = hcalHits[ii].id();
815  int det, z, depth, ieta, phi, lay;
816  HcalTestNumbering::unpackHcalIndex(tmpId, det, z, depth, ieta, phi, lay);
817 
818  bool darkened = false;
819  float dweight = 1.;
820 
821  if (det == int(HcalBarrel) && m_HBDarkening) {
822  // HB darkening
823  dweight = m_HBDarkening->degradation(deliveredLumi, ieta, lay);
824  darkened = true;
825  } else if (det == int(HcalEndcap) && m_HEDarkening) {
826  // HE darkening
827  dweight = m_HEDarkening->degradation(deliveredLumi, ieta, lay);
828  darkened = true;
829  } else if (det == int(HcalForward) && m_HFRecalibration) {
830  // HF darkening - approximate: invert recalibration factor
831  dweight = 1.0 / m_HFRecalibration->getCorr(ieta, depth, deliveredLumi);
832  darkened = true;
833  }
834 
835  // reset hit energy
836  if (darkened)
837  hcalHits[ii].setEnergy(hcalHits[ii].energy() * dweight);
838  }
839 }
HFHitFilter theHFQIE10HitFilter
std::vector< DetId > theHFQIE10DetIds
Log< level::Info, true > LogVerbatim
std::vector< int > injectedHitsCells_
HBHEHitFilter theHBHEHitFilter
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
constexpr bool oldFormat() const
Definition: HcalDetId.h:139
std::vector< PCaloHit > PCaloHitContainer
void setQIE10NoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::vector< CaloSamples > CaloSamplesCollection
Definition: CaloSamples.h:99
const HcalDDDRecConstants * theRecNumber
void setParameterMap(HcalSimParameterMap *map)
std::unique_ptr< CaloHitResponse > theHFResponse
const edm::ESGetToken< HcalDDDRecConstants, HcalRecNumberingRecord > theRecNumberToken
Definition: HcalDigitizer.h:93
std::unique_ptr< HcalTimeSlewSim > theTimeSlewSim
std::unique_ptr< HcalAmplifier > theHBHEAmplifier
int getValue() const
Definition: HcalQIEType.h:19
virtual ~HcalDigitizer()
std::unique_ptr< HBHEDigitizer > theHBHEDigitizer
void buildHFQIECells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
Definition: HcalQIENum.h:4
float degradation(float intlumi, int ieta, int lay) const
HOHitFilter theHOHitFilter
std::unique_ptr< ZDCDigitizer > theZDCDigitizer
void darkening(std::vector< PCaloHit > &hcalHits)
std::unique_ptr< HcalHitRelabeller > theRelabeller
HFHitFilter theHFHitFilter
void checkGeometry(const edm::EventSetup &eventSetup)
Log< level::Error, false > LogError
void buildHBHEQIECells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
std::unique_ptr< HFDigitizer > theHFDigitizer
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > theGeometryToken
Definition: HcalDigitizer.h:92
std::unique_ptr< HODigitizer > theHODigitizer
std::unique_ptr< HcalAmplifier > theHFAmplifier
edm::SortedCollection< ZDCDataFrame > ZDCDigiCollection
edm::ESGetToken< HBHEDarkening, HBHEDarkeningRecord > m_HBDarkeningToken
Definition: HcalDigitizer.h:89
const Item * getValues(DetId fId, bool throwOnFail=true) const
std::unique_ptr< HcalCoderFactory > theCoderFactory
HcalDataFrameContainer< QIE10DataFrame > QIE10DigiCollection
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
std::unique_ptr< HcalElectronicsSim > theZDCElectronicsSim
std::unique_ptr< HFRecalibration > m_HFRecalibration
edm::EDGetTokenT< std::vector< PCaloHit > > zdcToken_
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
constexpr uint32_t newForm() const
Definition: HcalDetId.h:199
std::vector< double > injectedHitsEnergy_
void setQIE11NoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
void setHOZecotekDetIds(const std::vector< HcalDetId > &ids)
std::unique_ptr< HcalElectronicsSim > theHFQIE10ElectronicsSim
const HBHEDarkening * m_HEDarkening
std::unique_ptr< HcalElectronicsSim > theHFElectronicsSim
const HcalTopology * topo() const
edm::ESWatcher< HcalRecNumberingRecord > theRecNumberWatcher_
Definition: HcalDigitizer.h:97
edm::SortedCollection< HODataFrame > HODigiCollection
std::string hitsProducer_
double deliveredLumi
void setElectronicsSim(HcalElectronicsSim *electronicsSim)
std::unique_ptr< HODigitizer > theHOSiPMDigitizer
Creates electronics signals from hits.
const HcalTimeSlew * hcalTimeSlew_delay_
void setHFNoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::unique_ptr< HcalAmplifier > theHBHEQIE11Amplifier
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
std::unique_ptr< HcalSiPMHitResponse > theHBHESiPMResponse
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
bool getData(T &iHolder) const
Definition: EventSetup.h:122
static const size_type MAXSAMPLES
HcalShapes theShapes
std::unique_ptr< CaloHitResponse > theHBHEResponse
std::vector< DetId > theHOHPDDetIds
edm::EDGetTokenT< std::vector< PCaloHit > > hcalToken_
unsigned int signalShape() const
Definition: HcalMCParam.h:38
edm::ESGetToken< HBHEDarkening, HBHEDarkeningRecord > m_HEDarkeningToken
Definition: HcalDigitizer.h:90
HcalSimParameterMap theParameterMap
std::unique_ptr< HcalElectronicsSim > theHBHEElectronicsSim
ii
Definition: cuy.py:589
const edm::ESGetToken< HcalQIETypes, HcalQIETypesRcd > qieTypesToken_
Definition: HcalDigitizer.h:94
HcalDataFrameContainer< QIE11DataFrame > QIE11DigiCollection
Log< level::Info, false > LogInfo
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > topoToken_
Definition: HcalDigitizer.h:88
std::unique_ptr< CaloHitResponse > theHOResponse
std::unique_ptr< HPDIonFeedbackSim > theIonFeedback
Definition: DetId.h:17
std::unique_ptr< HcalAmplifier > theZDCAmplifier
edm::ESWatcher< CaloGeometryRecord > theGeometryWatcher_
Definition: HcalDigitizer.h:96
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
void setHOHamamatsuDetIds(const std::vector< HcalDetId > &ids)
void setDbService(const HcalDbService *service)
Definition: HcalShapes.h:24
std::vector< DetId > theHFQIE8DetIds
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
std::unique_ptr< QIE11Digitizer > theHBHEQIE11Digitizer
std::unique_ptr< QIE10Digitizer > theHFQIE10Digitizer
void setDetIds(const std::vector< DetId > &detIds)
Definition: HcalHitFilter.h:17
std::vector< DetId > theHOSiPMDetIds
HOHitFilter theHOSiPMHitFilter
std::unique_ptr< CaloHitResponse > theZDCResponse
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const CaloGeometry * theGeometry
Definition: HcalDigitizer.h:99
bool isValid() const
Definition: HandleBase.h:70
std::unique_ptr< HcalAmplifier > theHOAmplifier
std::unique_ptr< HcalSiPMHitResponse > theHOSiPMResponse
bool validHcal(const HcalDetId &id) const
std::vector< DetId > hbheCells
const HBHEDarkening * m_HBDarkening
HLT enums.
std::unique_ptr< HcalElectronicsSim > theHOElectronicsSim
HBHEHitFilter theHBHEQIE11HitFilter
void setZDCNoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::vector< DetId > theHBHEQIE8DetIds
std::unique_ptr< CaloHitResponse > theHFQIE10Response
edm::SortedCollection< HFDataFrame > HFDigiCollection
void accumulateCaloHits(edm::Handle< std::vector< PCaloHit >> const &hcalHits, edm::Handle< std::vector< PCaloHit >> const &zdcHits, int bunchCrossing, CLHEP::HepRandomEngine *, const HcalTopology *h)
edm::ESGetToken< HcalMCParams, HcalMCParamsRcd > mcParamsToken_
Definition: HcalDigitizer.h:95
const edm::ESGetToken< HcalDbService, HcalDbRecord > conditionsToken_
Definition: HcalDigitizer.h:87
std::unique_ptr< HcalAmplifier > theHFQIE10Amplifier
std::unique_ptr< HcalElectronicsSim > theHBHEQIE11ElectronicsSim
void updateGeometry(const edm::EventSetup &eventSetup)
tmp
align.sh
Definition: createJobs.py:716
void setHBHENoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
void setup(const edm::EventSetup &es)
std::vector< DetId > theHBHEQIE11DetIds
def move(src, dest)
Definition: eostools.py:511
void setTopo(const HcalTopology *topo)
void setDbService(const HcalDbService *service)
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection
std::vector< PCaloHit > injectedHits_
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
void setHONoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
HcalDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
const edm::ESGetToken< HcalTimeSlew, HcalTimeSlewRecord > hcalTimeSlew_delay_token_
Definition: HcalDigitizer.h:91