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  // temporary move until Run3 ZDC will be added
208  theZDCDigitizer = std::make_unique<ZDCDigitizer>(theZDCResponse.get(), theZDCElectronicsSim.get(), doEmpty);
209 
210  testNumbering_ = ps.getParameter<bool>("TestNumbering");
211  // edm::LogVerbatim("HcalSim") << "Flag to see if Hit Relabeller to be initiated " << testNumbering_;
212  if (testNumbering_)
213  theRelabeller = std::make_unique<HcalHitRelabeller>(ps.getParameter<bool>("doNeutralDensityFilter"));
214 
215  if (ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
216  theIonFeedback = std::make_unique<HPDIonFeedbackSim>(ps, &theShapes);
217  theHBHEResponse->setPECorrection(theIonFeedback.get());
218  if (ps.getParameter<bool>("doThermalNoise")) {
219  theHBHEAmplifier->setIonFeedbackSim(theIonFeedback.get());
220  }
221  }
222 
223  // option to save CaloSamples as event product for debugging
224  if (debugCS_) {
225  if (theHBHEDigitizer)
226  theHBHEDigitizer->setDebugCaloSamples(true);
228  theHBHEQIE11Digitizer->setDebugCaloSamples(true);
229  if (theHODigitizer)
230  theHODigitizer->setDebugCaloSamples(true);
231  if (theHOSiPMDigitizer)
232  theHOSiPMDigitizer->setDebugCaloSamples(true);
233  if (theHFDigitizer)
234  theHFDigitizer->setDebugCaloSamples(true);
236  theHFQIE10Digitizer->setDebugCaloSamples(true);
237  if (theZDCDigitizer)
238  theZDCDigitizer->setDebugCaloSamples(true);
239  }
240 
241  // option to ignore Geant time distribution in SimHits, for debugging
242  if (ignoreTime_) {
243  theHBHEResponse->setIgnoreGeantTime(ignoreTime_);
244  theHBHESiPMResponse->setIgnoreGeantTime(ignoreTime_);
245  theHOResponse->setIgnoreGeantTime(ignoreTime_);
246  theHOSiPMResponse->setIgnoreGeantTime(ignoreTime_);
247  theHFResponse->setIgnoreGeantTime(ignoreTime_);
248  theHFQIE10Response->setIgnoreGeantTime(ignoreTime_);
249  theZDCResponse->setIgnoreGeantTime(ignoreTime_);
250  }
251 
252  if (agingFlagHF)
253  m_HFRecalibration = std::make_unique<HFRecalibration>(ps.getParameter<edm::ParameterSet>("HFRecalParameterBlock"));
254 }
255 
257 
259  noiseGenerator->setParameterMap(&theParameterMap);
260  noiseGenerator->setElectronicsSim(theHBHEElectronicsSim.get());
261  if (theHBHEDigitizer)
262  theHBHEDigitizer->setNoiseSignalGenerator(noiseGenerator);
263  theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
264 }
265 
267  noiseGenerator->setParameterMap(&theParameterMap);
268  noiseGenerator->setElectronicsSim(theHBHEQIE11ElectronicsSim.get());
270  theHBHEQIE11Digitizer->setNoiseSignalGenerator(noiseGenerator);
271  theHBHEQIE11Amplifier->setNoiseSignalGenerator(noiseGenerator);
272 }
273 
275  noiseGenerator->setParameterMap(&theParameterMap);
276  noiseGenerator->setElectronicsSim(theHFElectronicsSim.get());
277  if (theHFDigitizer)
278  theHFDigitizer->setNoiseSignalGenerator(noiseGenerator);
279  theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
280 }
281 
283  noiseGenerator->setParameterMap(&theParameterMap);
284  noiseGenerator->setElectronicsSim(theHFQIE10ElectronicsSim.get());
286  theHFQIE10Digitizer->setNoiseSignalGenerator(noiseGenerator);
287  theHFQIE10Amplifier->setNoiseSignalGenerator(noiseGenerator);
288 }
289 
291  noiseGenerator->setParameterMap(&theParameterMap);
292  noiseGenerator->setElectronicsSim(theHOElectronicsSim.get());
293  if (theHODigitizer)
294  theHODigitizer->setNoiseSignalGenerator(noiseGenerator);
295  if (theHOSiPMDigitizer)
296  theHOSiPMDigitizer->setNoiseSignalGenerator(noiseGenerator);
297  theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
298 }
299 
301  noiseGenerator->setParameterMap(&theParameterMap);
302  noiseGenerator->setElectronicsSim(theZDCElectronicsSim.get());
303  if (theZDCDigitizer) {
304  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
305  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
306  }
307 }
308 
310  setup(eventSetup);
311 
312  // get the appropriate gains, noises, & widths for this event
314 
316 
317  theHBHEAmplifier->setDbService(conditions);
318  theHFAmplifier->setDbService(conditions);
319  theHOAmplifier->setDbService(conditions);
320  theZDCAmplifier->setDbService(conditions);
321  theHFQIE10Amplifier->setDbService(conditions);
322  theHBHEQIE11Amplifier->setDbService(conditions);
323 
324  theHFQIE10ElectronicsSim->setDbService(conditions);
325  theHBHEQIE11ElectronicsSim->setDbService(conditions);
326 
327  theCoderFactory->setDbService(conditions);
329 
330  // initialize hits
331  if (theHBHEDigitizer)
332  theHBHEDigitizer->initializeHits();
334  theHBHEQIE11Digitizer->initializeHits();
335  if (theHODigitizer)
336  theHODigitizer->initializeHits();
337  if (theHOSiPMDigitizer)
338  theHOSiPMDigitizer->initializeHits();
340  theHFQIE10Digitizer->initializeHits();
341  if (theHFDigitizer)
342  theHFDigitizer->initializeHits();
343  if (theZDCDigitizer)
344  theZDCDigitizer->initializeHits();
345 }
346 
347 void HcalDigitizer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit>> const &hcalHandle,
348  edm::Handle<std::vector<PCaloHit>> const &zdcHandle,
349  int bunchCrossing,
350  CLHEP::HepRandomEngine *engine,
351  const HcalTopology *htopoP) {
352  // Step A: pass in inputs, and accumulate digis
353  if (isHCAL) {
354  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
355  if (injectTestHits_)
356  hcalHitsOrig = injectedHits_;
357  std::vector<PCaloHit> hcalHits;
358  hcalHits.reserve(hcalHitsOrig.size());
359 
360  // evaluate darkening before relabeling
361  if (testNumbering_) {
363  darkening(hcalHitsOrig);
364  }
365  // Relabel PCaloHits if necessary
366  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
367  theRelabeller->process(hcalHitsOrig);
368  }
369 
370  // eliminate bad hits
371  for (unsigned int i = 0; i < hcalHitsOrig.size(); i++) {
372  DetId id(hcalHitsOrig[i].id());
373  HcalDetId hid(id);
374  if (!htopoP->validHcal(hid)) {
375  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << " " << hid;
376  continue;
377  } else if (hid.subdet() == HcalForward && !doHFWindow_ && hcalHitsOrig[i].depth() != 0) {
378  // skip HF window hits unless desired
379  continue;
380  } else if (killHE_ && hid.subdet() == HcalEndcap) {
381  // remove HE hits if asked for (phase 2)
382  continue;
383  } else {
384 #ifdef EDM_ML_DEBUG
385  edm::LogVerbatim("HcalSim") << "HcalDigitizer format " << hid.oldFormat() << " for " << hid;
386 #endif
387  DetId newid = DetId(hid.newForm());
388 #ifdef EDM_ML_DEBUG
389  edm::LogVerbatim("HcalSim") << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId()
390  << " --> " << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
391 #endif
392  hcalHitsOrig[i].setID(newid.rawId());
393  hcalHits.push_back(hcalHitsOrig[i]);
394  }
395  }
396 
397  if (hbhegeo) {
398  if (theHBHEDigitizer)
399  theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
401  theHBHEQIE11Digitizer->add(hcalHits, bunchCrossing, engine);
402  }
403 
404  if (hogeo) {
405  if (theHODigitizer)
406  theHODigitizer->add(hcalHits, bunchCrossing, engine);
407  if (theHOSiPMDigitizer)
408  theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
409  }
410 
411  if (hfgeo) {
412  if (theHFDigitizer)
413  theHFDigitizer->add(hcalHits, bunchCrossing, engine);
415  theHFQIE10Digitizer->add(hcalHits, bunchCrossing, engine);
416  }
417  } else {
418  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
419  }
420 
421  if (isZDC) {
422  if (zdcgeo && theZDCDigitizer) {
423  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
424  }
425  } else {
426  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
427  }
428 }
429 
430 void HcalDigitizer::accumulate(edm::Event const &e, edm::EventSetup const &eventSetup, CLHEP::HepRandomEngine *engine) {
431  // Step A: Get Inputs
432  const edm::Handle<std::vector<PCaloHit>> &zdcHandle = e.getHandle(zdcToken_);
433  isZDC = zdcHandle.isValid();
434 
435  const edm::Handle<std::vector<PCaloHit>> &hcalHandle = e.getHandle(hcalToken_);
436  isHCAL = hcalHandle.isValid() or injectTestHits_;
437 
438  const HcalTopology *htopoP = &eventSetup.getData(topoToken_);
439 
440  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
441 }
442 
445  CLHEP::HepRandomEngine *engine) {
446  // Step A: Get Inputs
447  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
449  e.getByLabel(zdcTag, zdcHandle);
450  isZDC = zdcHandle.isValid();
451 
452  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
454  e.getByLabel(hcalTag, hcalHandle);
455  isHCAL = hcalHandle.isValid();
456 
457  const HcalTopology *htopoP = &eventSetup.getData(topoToken_);
458 
459  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
460 }
461 
462 void HcalDigitizer::finalizeEvent(edm::Event &e, const edm::EventSetup &eventSetup, CLHEP::HepRandomEngine *engine) {
463  // Step B: Create empty output
464  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
465  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
466  std::unique_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
467  std::unique_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
468  std::unique_ptr<QIE10DigiCollection> hfQIE10Result(new QIE10DigiCollection(
469  !theHFQIE10DetIds.empty() ? theHFQIE10Response.get()->getReadoutFrameSize(theHFQIE10DetIds[0])
471  std::unique_ptr<QIE11DigiCollection> hbheQIE11Result(new QIE11DigiCollection(
472  !theHBHEQIE11DetIds.empty() ? theHBHESiPMResponse.get()->getReadoutFrameSize(theHBHEQIE11DetIds[0]) :
473  // theParameterMap->simParameters(theHBHEQIE11DetIds[0]).readoutFrameSize()
474  // :
476 
477  // Step C: Invoke the algorithm, getting back outputs.
478  if (isHCAL && hbhegeo) {
479  if (theHBHEDigitizer)
480  theHBHEDigitizer->run(*hbheResult, engine);
482  theHBHEQIE11Digitizer->run(*hbheQIE11Result, engine);
483  }
484  if (isHCAL && hogeo) {
485  if (theHODigitizer)
486  theHODigitizer->run(*hoResult, engine);
487  if (theHOSiPMDigitizer)
488  theHOSiPMDigitizer->run(*hoResult, engine);
489  }
490  if (isHCAL && hfgeo) {
491  if (theHFDigitizer)
492  theHFDigitizer->run(*hfResult, engine);
494  theHFQIE10Digitizer->run(*hfQIE10Result, engine);
495  }
496  if (isZDC && zdcgeo && theZDCDigitizer) {
497  theZDCDigitizer->run(*zdcResult, engine);
498  }
499 
500  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
501  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
502  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
503  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
504  edm::LogInfo("HcalDigitizer") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
505  edm::LogInfo("HcalDigitizer") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
506 
507 #ifdef EDM_ML_DEBUG
508  edm::LogVerbatim("HcalSim") << "\nHCAL HBHE digis : " << hbheResult->size();
509  edm::LogVerbatim("HcalSim") << "HCAL HO digis : " << hoResult->size();
510  edm::LogVerbatim("HcalSim") << "HCAL HF digis : " << hfResult->size();
511  edm::LogVerbatim("HcalSim") << "HCAL ZDC digis : " << zdcResult->size();
512  edm::LogVerbatim("HcalSim") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
513  edm::LogVerbatim("HcalSim") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
514 #endif
515 
516  // Step D: Put outputs into event
517  e.put(std::move(hbheResult));
518  e.put(std::move(hoResult));
519  e.put(std::move(hfResult));
520  e.put(std::move(zdcResult));
521  e.put(std::move(hfQIE10Result), "HFQIE10DigiCollection");
522  e.put(std::move(hbheQIE11Result), "HBHEQIE11DigiCollection");
523 
524  if (debugCS_) {
525  std::unique_ptr<CaloSamplesCollection> csResult(new CaloSamplesCollection());
526  // smush together all the results
527  if (theHBHEDigitizer)
528  csResult->insert(
529  csResult->end(), theHBHEDigitizer->getCaloSamples().begin(), theHBHEDigitizer->getCaloSamples().end());
531  csResult->insert(csResult->end(),
532  theHBHEQIE11Digitizer->getCaloSamples().begin(),
533  theHBHEQIE11Digitizer->getCaloSamples().end());
534  if (theHODigitizer)
535  csResult->insert(
536  csResult->end(), theHODigitizer->getCaloSamples().begin(), theHODigitizer->getCaloSamples().end());
537  if (theHOSiPMDigitizer)
538  csResult->insert(
539  csResult->end(), theHOSiPMDigitizer->getCaloSamples().begin(), theHOSiPMDigitizer->getCaloSamples().end());
540  if (theHFDigitizer)
541  csResult->insert(
542  csResult->end(), theHFDigitizer->getCaloSamples().begin(), theHFDigitizer->getCaloSamples().end());
544  csResult->insert(
545  csResult->end(), theHFQIE10Digitizer->getCaloSamples().begin(), theHFQIE10Digitizer->getCaloSamples().end());
546  if (theZDCDigitizer)
547  csResult->insert(
548  csResult->end(), theZDCDigitizer->getCaloSamples().begin(), theZDCDigitizer->getCaloSamples().end());
549  e.put(std::move(csResult), "HcalSamples");
550  }
551 
552  if (injectTestHits_) {
553  std::unique_ptr<edm::PCaloHitContainer> pcResult(new edm::PCaloHitContainer());
554  pcResult->insert(pcResult->end(), injectedHits_.begin(), injectedHits_.end());
555  e.put(std::move(pcResult), "HcalHits");
556  }
557 
558 #ifdef EDM_ML_DEBUG
559  edm::LogVerbatim("HcalSim") << "\n========> HcalDigitizer e.put\n";
560 #endif
561 }
562 
564  checkGeometry(es);
565 
566  if (agingFlagHB) {
568  }
569  if (agingFlagHE) {
571  }
572 
574 
577  theHOAmplifier->setTimeSlew(hcalTimeSlew_delay_);
578  theZDCAmplifier->setTimeSlew(hcalTimeSlew_delay_);
579 }
580 
584 
585  if (theHBHEResponse)
586  theHBHEResponse->setGeometry(theGeometry);
588  theHBHESiPMResponse->setGeometry(theGeometry);
589  if (theHOResponse)
590  theHOResponse->setGeometry(theGeometry);
591  if (theHOSiPMResponse)
592  theHOSiPMResponse->setGeometry(theGeometry);
593  theHFResponse->setGeometry(theGeometry);
594  theHFQIE10Response->setGeometry(theGeometry);
595  theZDCResponse->setGeometry(theGeometry);
596  if (theRelabeller)
597  theRelabeller->setGeometry(theRecNumber);
598 
599  // See if it's been updated
600  bool check1 = theGeometryWatcher_.check(eventSetup);
601  bool check2 = theRecNumberWatcher_.check(eventSetup);
602  if (check1 or check2) {
604  }
605 }
606 
608  const std::vector<DetId> &hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
609  const std::vector<DetId> &heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
610  const std::vector<DetId> &hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
611  const std::vector<DetId> &hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
612  const std::vector<DetId> &zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
613  // const std::vector<DetId>& hcalTrigCells =
614  // geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower); const
615  // std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo,
616  // HcalCastorDetId::SubdetectorId);
617  // edm::LogVerbatim("HcalSim") <<"HcalDigitizer::CheckGeometry number of cells: << zdcCells.size();
618  if (zdcCells.empty())
619  zdcgeo = false;
620  if (hbCells.empty() && heCells.empty())
621  hbhegeo = false;
622  if (hoCells.empty())
623  hogeo = false;
624  if (hfCells.empty())
625  hfgeo = false;
626  // combine HB & HE
627 
628  hbheCells = hbCells;
629  if (!killHE_) {
630  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
631  }
632  // handle mixed QIE8/11 scenario in HBHE
636 
637  if (theHOSiPMDigitizer) {
638  buildHOSiPMCells(hoCells, eventSetup);
639  if (theHOSiPMResponse)
640  theHOSiPMResponse->setDetIds(hoCells);
641  }
642 
643  // handle mixed QIE8/10 scenario in HF
644  buildHFQIECells(hfCells, eventSetup);
645 
646  if (theZDCDigitizer)
647  theZDCDigitizer->setDetIds(zdcCells);
648 
649  // fill test hits collection if desired and empty
650  if (injectTestHits_ && injectedHits_.empty() && !injectedHitsCells_.empty() && !injectedHitsEnergy_.empty()) {
651  // make list of specified cells if desired
652  std::vector<DetId> testCells;
653  if (injectedHitsCells_.size() >= 4) {
654  testCells.reserve(injectedHitsCells_.size() / 4);
655  for (unsigned ic = 0; ic < injectedHitsCells_.size(); ic += 4) {
656  if (ic + 4 > injectedHitsCells_.size())
657  break;
658  testCells.push_back(HcalDetId((HcalSubdetector)injectedHitsCells_[ic],
659  injectedHitsCells_[ic + 1],
660  injectedHitsCells_[ic + 2],
661  injectedHitsCells_[ic + 3]));
662  }
663  } else {
664  int testSubdet = injectedHitsCells_[0];
665  if (testSubdet == HcalBarrel)
666  testCells = hbCells;
667  else if (testSubdet == HcalEndcap)
668  testCells = heCells;
669  else if (testSubdet == HcalForward)
670  testCells = hfCells;
671  else if (testSubdet == HcalOuter)
672  testCells = hoCells;
673  else
674  throw cms::Exception("Configuration") << "Unknown subdet " << testSubdet << " for HCAL test hit injection";
675  }
676  bool useHitTimes = (injectedHitsTime_.size() == injectedHitsEnergy_.size());
677  injectedHits_.reserve(testCells.size() * injectedHitsEnergy_.size());
678  for (unsigned ih = 0; ih < injectedHitsEnergy_.size(); ++ih) {
679  double tmp = useHitTimes ? injectedHitsTime_[ih] : 0.;
680  for (auto &aCell : testCells) {
681  injectedHits_.emplace_back(aCell, injectedHitsEnergy_[ih], tmp);
682  }
683  }
684  }
685 }
686 
687 void HcalDigitizer::buildHFQIECells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
688  // if results are already cached, no need to look again
689  if (!theHFQIE8DetIds.empty() || !theHFQIE10DetIds.empty())
690  return;
691 
692  // get the QIETypes
693  // intentional copy
694  HcalQIETypes qieTypes = eventSetup.getData(qieTypesToken_);
695  if (qieTypes.topo() == nullptr) {
696  qieTypes.setTopo(&eventSetup.getData(topoToken_));
697  }
698 
699  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
700  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
701  if (qieType == QIE8) {
702  theHFQIE8DetIds.push_back(*detItr);
703  } else if (qieType == QIE10) {
704  theHFQIE10DetIds.push_back(*detItr);
705  } else { // default is QIE8
706  theHFQIE8DetIds.push_back(*detItr);
707  }
708  }
709 
710  if (!theHFQIE8DetIds.empty())
711  theHFDigitizer->setDetIds(theHFQIE8DetIds);
712  else {
713  theHFDigitizer.reset();
714  }
715 
716  if (!theHFQIE10DetIds.empty())
718  else {
719  theHFQIE10Digitizer.reset();
720  }
721 }
722 
723 void HcalDigitizer::buildHBHEQIECells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
724  // if results are already cached, no need to look again
725  if (!theHBHEQIE8DetIds.empty() || !theHBHEQIE11DetIds.empty())
726  return;
727 
728  // get the QIETypes
729  // intentional copy
730  HcalQIETypes qieTypes = eventSetup.getData(qieTypesToken_);
731  if (qieTypes.topo() == nullptr) {
732  qieTypes.setTopo(&eventSetup.getData(topoToken_));
733  }
734 
735  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
736  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
737  if (qieType == QIE8) {
738  theHBHEQIE8DetIds.push_back(*detItr);
739  } else if (qieType == QIE11) {
740  theHBHEQIE11DetIds.push_back(*detItr);
741  } else { // default is QIE8
742  theHBHEQIE8DetIds.push_back(*detItr);
743  }
744  }
745 
746  if (!theHBHEQIE8DetIds.empty())
748  else {
749  theHBHEDigitizer.reset();
750  }
751 
752  if (!theHBHEQIE11DetIds.empty())
754  else {
755  theHBHEQIE11Digitizer.reset();
756  }
757 
758  if (!theHBHEQIE8DetIds.empty() && !theHBHEQIE11DetIds.empty()) {
761  }
762 }
763 
764 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
765  // all HPD
766 
767  if (theHOSiPMCode == 0) {
768  theHODigitizer->setDetIds(allCells);
769  } else if (theHOSiPMCode == 1) {
770  theHOSiPMDigitizer->setDetIds(allCells);
771  // FIXME pick Zecotek or hamamatsu?
772  } else if (theHOSiPMCode == 2) {
773  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
774 
775  // intentional copy
776  HcalMCParams mcParams = eventSetup.getData(mcParamsToken_);
777  if (mcParams.topo() == nullptr) {
778  mcParams.setTopo(&eventSetup.getData(topoToken_));
779  }
780 
781  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
782  int shapeType = mcParams.getValues(*detItr)->signalShape();
783  if (shapeType == HcalShapes::ZECOTEK) {
784  zecotekDetIds.emplace_back(*detItr);
785  theHOSiPMDetIds.push_back(*detItr);
786  } else if (shapeType == HcalShapes::HAMAMATSU) {
787  hamamatsuDetIds.emplace_back(*detItr);
788  theHOSiPMDetIds.push_back(*detItr);
789  } else {
790  theHOHPDDetIds.push_back(*detItr);
791  }
792  }
793 
794  if (!theHOHPDDetIds.empty())
795  theHODigitizer->setDetIds(theHOHPDDetIds);
796  else {
797  theHODigitizer.reset();
798  }
799 
800  if (!theHOSiPMDetIds.empty())
802  else {
803  theHOSiPMDigitizer.reset();
804  }
805 
806  if (!theHOHPDDetIds.empty() && !theHOSiPMDetIds.empty()) {
809  }
810 
811  theParameterMap.setHOZecotekDetIds(zecotekDetIds);
812  theParameterMap.setHOHamamatsuDetIds(hamamatsuDetIds);
813 
814  // make sure we don't got through this exercise again
815  theHOSiPMCode = -2;
816  }
817 }
818 
819 void HcalDigitizer::darkening(std::vector<PCaloHit> &hcalHits) {
820  for (unsigned int ii = 0; ii < hcalHits.size(); ++ii) {
821  uint32_t tmpId = hcalHits[ii].id();
822  int det, z, depth, ieta, phi, lay;
823  HcalTestNumbering::unpackHcalIndex(tmpId, det, z, depth, ieta, phi, lay);
824 
825  bool darkened = false;
826  float dweight = 1.;
827 
828  if (det == int(HcalBarrel) && m_HBDarkening) {
829  // HB darkening
830  dweight = m_HBDarkening->degradation(deliveredLumi, ieta, lay);
831  darkened = true;
832  } else if (det == int(HcalEndcap) && m_HEDarkening) {
833  // HE darkening
834  dweight = m_HEDarkening->degradation(deliveredLumi, ieta, lay);
835  darkened = true;
836  } else if (det == int(HcalForward) && m_HFRecalibration) {
837  // HF darkening - approximate: invert recalibration factor
838  dweight = 1.0 / m_HFRecalibration->getCorr(ieta, depth, deliveredLumi);
839  darkened = true;
840  }
841 
842  // reset hit energy
843  if (darkened)
844  hcalHits[ii].setEnergy(hcalHits[ii].energy() * dweight);
845  }
846 }
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)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
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
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
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
static constexpr int32_t SubdetectorId
Definition: HcalZDCDetId.h:35
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