CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalDigitizer.cc
Go to the documentation of this file.
29 #include <boost/foreach.hpp>
30 #include <memory>
31 
32 //#define DebugLog
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  m_HBDarkening(nullptr),
102  m_HEDarkening(nullptr),
103  m_HFRecalibration(nullptr),
104  injectedHitsEnergy_(ps.getParameter<std::vector<double>>("injectTestHitsEnergy")),
105  injectedHitsTime_(ps.getParameter<std::vector<double>>("injectTestHitsTime")),
106  injectedHitsCells_(ps.getParameter<std::vector<int>>("injectTestHitsCells")) {
107  iC.consumes<std::vector<PCaloHit>>(edm::InputTag(hitsProducer_, "ZDCHITS"));
108  iC.consumes<std::vector<PCaloHit>>(edm::InputTag(hitsProducer_, "HcalHits"));
109 
110  if (agingFlagHB) {
112  }
113  if (agingFlagHE) {
115  }
116  if (theHOSiPMCode == 2) {
117  mcParamsToken_ = iC.esConsumes();
118  }
119 
120  bool doNoise = ps.getParameter<bool>("doNoise");
121 
122  bool PreMix1 = ps.getParameter<bool>("HcalPreMixStage1"); // special threshold/pedestal treatment
123  bool PreMix2 = ps.getParameter<bool>("HcalPreMixStage2"); // special threshold/pedestal treatment
124  bool doEmpty = ps.getParameter<bool>("doEmpty");
125  deliveredLumi = ps.getParameter<double>("DelivLuminosity");
126  bool agingFlagHF = ps.getParameter<bool>("HFDarkening");
127  double minFCToDelay = ps.getParameter<double>("minFCToDelay");
128 
129  if (PreMix1 && PreMix2) {
130  throw cms::Exception("Configuration") << "HcalDigitizer cannot operate in PreMixing digitization and "
131  "PreMixing\n"
132  "digi combination modes at the same time. Please set one mode to "
133  "False\n"
134  "in the configuration file.";
135  }
136 
137  // need to make copies, because they might get different noise generators
138  theHBHEAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
139  theHFAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
140  theHOAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
141  theZDCAmplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
142  theHFQIE10Amplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
143  theHBHEQIE11Amplifier = std::make_unique<HcalAmplifier>(&theParameterMap, doNoise, PreMix1, PreMix2);
144 
145  theCoderFactory = std::make_unique<HcalCoderFactory>(HcalCoderFactory::DB);
146 
148  std::make_unique<HcalElectronicsSim>(&theParameterMap, theHBHEAmplifier.get(), theCoderFactory.get(), PreMix1);
150  std::make_unique<HcalElectronicsSim>(&theParameterMap, theHFAmplifier.get(), theCoderFactory.get(), PreMix1);
152  std::make_unique<HcalElectronicsSim>(&theParameterMap, theHOAmplifier.get(), theCoderFactory.get(), PreMix1);
154  std::make_unique<HcalElectronicsSim>(&theParameterMap, theZDCAmplifier.get(), theCoderFactory.get(), PreMix1);
156  std::make_unique<HcalElectronicsSim>(&theParameterMap,
157  theHFQIE10Amplifier.get(),
158  theCoderFactory.get(),
159  PreMix1); // should this use a different coder factory?
161  std::make_unique<HcalElectronicsSim>(&theParameterMap,
162  theHBHEQIE11Amplifier.get(),
163  theCoderFactory.get(),
164  PreMix1); // should this use a different coder factory?
165 
166  bool doHOHPD = (theHOSiPMCode != 1);
167  bool doHOSiPM = (theHOSiPMCode != 0);
168  if (doHOHPD) {
169  theHOResponse = std::make_unique<CaloHitResponse>(&theParameterMap, &theShapes);
170  theHOResponse->setHitFilter(&theHOHitFilter);
171  theHODigitizer = std::make_unique<HODigitizer>(theHOResponse.get(), theHOElectronicsSim.get(), doEmpty);
172  }
173  if (doHOSiPM) {
174  theHOSiPMResponse->setHitFilter(&theHOSiPMHitFilter);
175  theHOSiPMDigitizer = std::make_unique<HODigitizer>(theHOSiPMResponse.get(), theHOElectronicsSim.get(), doEmpty);
176  }
177 
178  theHBHEResponse->setHitFilter(&theHBHEHitFilter);
180 
181  // QIE8 and QIE11 can coexist in HBHE
183  std::make_unique<QIE11Digitizer>(theHBHESiPMResponse.get(), theHBHEQIE11ElectronicsSim.get(), doEmpty);
184  theHBHEDigitizer = std::make_unique<HBHEDigitizer>(theHBHEResponse.get(), theHBHEElectronicsSim.get(), doEmpty);
185 
186  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
187  // initialize: they won't be called later if flag is set
188  hcalTimeSlew_delay_ = nullptr;
189  theTimeSlewSim.reset(nullptr);
190  if (doTimeSlew) {
191  // no time slewing for HF
192  theTimeSlewSim = std::make_unique<HcalTimeSlewSim>(&theParameterMap, minFCToDelay);
193  theHBHEAmplifier->setTimeSlewSim(theTimeSlewSim.get());
194  theHBHEQIE11Amplifier->setTimeSlewSim(theTimeSlewSim.get());
195  theHOAmplifier->setTimeSlewSim(theTimeSlewSim.get());
196  theZDCAmplifier->setTimeSlewSim(theTimeSlewSim.get());
197  }
198 
199  theHFResponse->setHitFilter(&theHFHitFilter);
200  theHFQIE10Response->setHitFilter(&theHFQIE10HitFilter);
201  theZDCResponse->setHitFilter(&theZDCHitFilter);
202 
203  // QIE8 and QIE10 can coexist in HF
205  std::make_unique<QIE10Digitizer>(theHFQIE10Response.get(), theHFQIE10ElectronicsSim.get(), doEmpty);
206  theHFDigitizer = std::make_unique<HFDigitizer>(theHFResponse.get(), theHFElectronicsSim.get(), doEmpty);
207 
208  theZDCDigitizer = std::make_unique<ZDCDigitizer>(theZDCResponse.get(), theZDCElectronicsSim.get(), doEmpty);
209 
210  testNumbering_ = ps.getParameter<bool>("TestNumbering");
211  // std::cout << "Flag to see if Hit Relabeller to be initiated " <<
212  // testNumbering_ << std::endl;
213  if (testNumbering_)
214  theRelabeller = std::make_unique<HcalHitRelabeller>(ps.getParameter<bool>("doNeutralDensityFilter"));
215 
216  if (ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
217  theIonFeedback = std::make_unique<HPDIonFeedbackSim>(ps, &theShapes);
218  theHBHEResponse->setPECorrection(theIonFeedback.get());
219  if (ps.getParameter<bool>("doThermalNoise")) {
220  theHBHEAmplifier->setIonFeedbackSim(theIonFeedback.get());
221  }
222  }
223 
224  // option to save CaloSamples as event product for debugging
225  if (debugCS_) {
226  if (theHBHEDigitizer)
227  theHBHEDigitizer->setDebugCaloSamples(true);
229  theHBHEQIE11Digitizer->setDebugCaloSamples(true);
230  if (theHODigitizer)
231  theHODigitizer->setDebugCaloSamples(true);
232  if (theHOSiPMDigitizer)
233  theHOSiPMDigitizer->setDebugCaloSamples(true);
234  if (theHFDigitizer)
235  theHFDigitizer->setDebugCaloSamples(true);
237  theHFQIE10Digitizer->setDebugCaloSamples(true);
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  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
304  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
305 }
306 
308  setup(eventSetup);
309 
310  // get the appropriate gains, noises, & widths for this event
311  const HcalDbService *conditions = &eventSetup.getData(conditionsToken_);
312 
313  theShapes.setDbService(conditions);
314 
315  theHBHEAmplifier->setDbService(conditions);
316  theHFAmplifier->setDbService(conditions);
317  theHOAmplifier->setDbService(conditions);
318  theZDCAmplifier->setDbService(conditions);
319  theHFQIE10Amplifier->setDbService(conditions);
320  theHBHEQIE11Amplifier->setDbService(conditions);
321 
322  theHFQIE10ElectronicsSim->setDbService(conditions);
323  theHBHEQIE11ElectronicsSim->setDbService(conditions);
324 
325  theCoderFactory->setDbService(conditions);
326  theParameterMap.setDbService(conditions);
327 
328  // initialize hits
329  if (theHBHEDigitizer)
330  theHBHEDigitizer->initializeHits();
332  theHBHEQIE11Digitizer->initializeHits();
333  if (theHODigitizer)
334  theHODigitizer->initializeHits();
335  if (theHOSiPMDigitizer)
336  theHOSiPMDigitizer->initializeHits();
338  theHFQIE10Digitizer->initializeHits();
339  if (theHFDigitizer)
340  theHFDigitizer->initializeHits();
341  theZDCDigitizer->initializeHits();
342 }
343 
344 void HcalDigitizer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit>> const &hcalHandle,
345  edm::Handle<std::vector<PCaloHit>> const &zdcHandle,
346  int bunchCrossing,
347  CLHEP::HepRandomEngine *engine,
348  const HcalTopology *htopoP) {
349  // Step A: pass in inputs, and accumulate digis
350  if (isHCAL) {
351  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
352  if (injectTestHits_)
353  hcalHitsOrig = injectedHits_;
354  std::vector<PCaloHit> hcalHits;
355  hcalHits.reserve(hcalHitsOrig.size());
356 
357  // evaluate darkening before relabeling
358  if (testNumbering_) {
360  darkening(hcalHitsOrig);
361  }
362  // Relabel PCaloHits if necessary
363  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
364  theRelabeller->process(hcalHitsOrig);
365  }
366 
367  // eliminate bad hits
368  for (unsigned int i = 0; i < hcalHitsOrig.size(); i++) {
369  DetId id(hcalHitsOrig[i].id());
370  HcalDetId hid(id);
371  if (!htopoP->validHcal(hid)) {
372  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << " " << hid
373  << std::endl;
374  continue;
375  } else if (hid.subdet() == HcalForward && !doHFWindow_ && hcalHitsOrig[i].depth() != 0) {
376  // skip HF window hits unless desired
377  continue;
378  } else if (killHE_ && hid.subdet() == HcalEndcap) {
379  // remove HE hits if asked for (phase 2)
380  continue;
381  } else {
382 #ifdef DebugLog
383  std::cout << "HcalDigitizer format " << hid.oldFormat() << " for " << hid << std::endl;
384 #endif
385  DetId newid = DetId(hid.newForm());
386 #ifdef DebugLog
387  std::cout << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId() << " --> "
388  << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
389 #endif
390  hcalHitsOrig[i].setID(newid.rawId());
391  hcalHits.push_back(hcalHitsOrig[i]);
392  }
393  }
394 
395  if (hbhegeo) {
396  if (theHBHEDigitizer)
397  theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
399  theHBHEQIE11Digitizer->add(hcalHits, bunchCrossing, engine);
400  }
401 
402  if (hogeo) {
403  if (theHODigitizer)
404  theHODigitizer->add(hcalHits, bunchCrossing, engine);
405  if (theHOSiPMDigitizer)
406  theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
407  }
408 
409  if (hfgeo) {
410  if (theHFDigitizer)
411  theHFDigitizer->add(hcalHits, bunchCrossing, engine);
413  theHFQIE10Digitizer->add(hcalHits, bunchCrossing, engine);
414  }
415  } else {
416  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
417  }
418 
419  if (isZDC) {
420  if (zdcgeo) {
421  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
422  }
423  } else {
424  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
425  }
426 }
427 
428 void HcalDigitizer::accumulate(edm::Event const &e, edm::EventSetup const &eventSetup, CLHEP::HepRandomEngine *engine) {
429  // Step A: Get Inputs
430  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
432  e.getByLabel(zdcTag, zdcHandle);
433  isZDC = zdcHandle.isValid();
434 
435  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
437  e.getByLabel(hcalTag, hcalHandle);
438  isHCAL = hcalHandle.isValid() or injectTestHits_;
439 
440  const HcalTopology *htopoP = &eventSetup.getData(topoToken_);
441 
442  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
443 }
444 
446  edm::EventSetup const &eventSetup,
447  CLHEP::HepRandomEngine *engine) {
448  // Step A: Get Inputs
449  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
451  e.getByLabel(zdcTag, zdcHandle);
452  isZDC = zdcHandle.isValid();
453 
454  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
456  e.getByLabel(hcalTag, hcalHandle);
457  isHCAL = hcalHandle.isValid();
458 
459  const HcalTopology *htopoP = &eventSetup.getData(topoToken_);
460 
461  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
462 }
463 
464 void HcalDigitizer::finalizeEvent(edm::Event &e, const edm::EventSetup &eventSetup, CLHEP::HepRandomEngine *engine) {
465  // Step B: Create empty output
466  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
467  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
468  std::unique_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
469  std::unique_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
470  std::unique_ptr<QIE10DigiCollection> hfQIE10Result(new QIE10DigiCollection(
471  !theHFQIE10DetIds.empty() ? theHFQIE10Response.get()->getReadoutFrameSize(theHFQIE10DetIds[0])
473  std::unique_ptr<QIE11DigiCollection> hbheQIE11Result(new QIE11DigiCollection(
474  !theHBHEQIE11DetIds.empty() ? theHBHESiPMResponse.get()->getReadoutFrameSize(theHBHEQIE11DetIds[0]) :
475  // theParameterMap->simParameters(theHBHEQIE11DetIds[0]).readoutFrameSize()
476  // :
478 
479  // Step C: Invoke the algorithm, getting back outputs.
480  if (isHCAL && hbhegeo) {
481  if (theHBHEDigitizer)
482  theHBHEDigitizer->run(*hbheResult, engine);
484  theHBHEQIE11Digitizer->run(*hbheQIE11Result, engine);
485  }
486  if (isHCAL && hogeo) {
487  if (theHODigitizer)
488  theHODigitizer->run(*hoResult, engine);
489  if (theHOSiPMDigitizer)
490  theHOSiPMDigitizer->run(*hoResult, engine);
491  }
492  if (isHCAL && hfgeo) {
493  if (theHFDigitizer)
494  theHFDigitizer->run(*hfResult, engine);
496  theHFQIE10Digitizer->run(*hfQIE10Result, engine);
497  }
498  if (isZDC && zdcgeo) {
499  theZDCDigitizer->run(*zdcResult, engine);
500  }
501 
502  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
503  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
504  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
505  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
506  edm::LogInfo("HcalDigitizer") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
507  edm::LogInfo("HcalDigitizer") << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size();
508 
509 #ifdef DebugLog
510  std::cout << std::endl;
511  std::cout << "HCAL HBHE digis : " << hbheResult->size() << std::endl;
512  std::cout << "HCAL HO digis : " << hoResult->size() << std::endl;
513  std::cout << "HCAL HF digis : " << hfResult->size() << std::endl;
514  std::cout << "HCAL ZDC digis : " << zdcResult->size() << std::endl;
515  std::cout << "HCAL HF QIE10 digis : " << hfQIE10Result->size() << std::endl;
516  std::cout << "HCAL HBHE QIE11 digis : " << hbheQIE11Result->size() << std::endl;
517 #endif
518 
519  // Step D: Put outputs into event
520  e.put(std::move(hbheResult));
521  e.put(std::move(hoResult));
522  e.put(std::move(hfResult));
523  e.put(std::move(zdcResult));
524  e.put(std::move(hfQIE10Result), "HFQIE10DigiCollection");
525  e.put(std::move(hbheQIE11Result), "HBHEQIE11DigiCollection");
526 
527  if (debugCS_) {
528  std::unique_ptr<CaloSamplesCollection> csResult(new CaloSamplesCollection());
529  // smush together all the results
530  if (theHBHEDigitizer)
531  csResult->insert(
532  csResult->end(), theHBHEDigitizer->getCaloSamples().begin(), theHBHEDigitizer->getCaloSamples().end());
534  csResult->insert(csResult->end(),
535  theHBHEQIE11Digitizer->getCaloSamples().begin(),
536  theHBHEQIE11Digitizer->getCaloSamples().end());
537  if (theHODigitizer)
538  csResult->insert(
539  csResult->end(), theHODigitizer->getCaloSamples().begin(), theHODigitizer->getCaloSamples().end());
540  if (theHOSiPMDigitizer)
541  csResult->insert(
542  csResult->end(), theHOSiPMDigitizer->getCaloSamples().begin(), theHOSiPMDigitizer->getCaloSamples().end());
543  if (theHFDigitizer)
544  csResult->insert(
545  csResult->end(), theHFDigitizer->getCaloSamples().begin(), theHFDigitizer->getCaloSamples().end());
547  csResult->insert(
548  csResult->end(), theHFQIE10Digitizer->getCaloSamples().begin(), theHFQIE10Digitizer->getCaloSamples().end());
549  csResult->insert(
550  csResult->end(), theZDCDigitizer->getCaloSamples().begin(), theZDCDigitizer->getCaloSamples().end());
551  e.put(std::move(csResult), "HcalSamples");
552  }
553 
554  if (injectTestHits_) {
555  std::unique_ptr<edm::PCaloHitContainer> pcResult(new edm::PCaloHitContainer());
556  pcResult->insert(pcResult->end(), injectedHits_.begin(), injectedHits_.end());
557  e.put(std::move(pcResult), "HcalHits");
558  }
559 
560 #ifdef DebugLog
561  std::cout << std::endl << "========> HcalDigitizer e.put " << std::endl << std::endl;
562 #endif
563 }
564 
566  checkGeometry(es);
567 
568  if (agingFlagHB) {
570  }
571  if (agingFlagHE) {
573  }
574 
576 
579  theHOAmplifier->setTimeSlew(hcalTimeSlew_delay_);
580  theZDCAmplifier->setTimeSlew(hcalTimeSlew_delay_);
581 }
582 
584  theGeometry = &eventSetup.getData(theGeometryToken);
585  theRecNumber = &eventSetup.getData(theRecNumberToken);
586 
587  if (theHBHEResponse)
588  theHBHEResponse->setGeometry(theGeometry);
590  theHBHESiPMResponse->setGeometry(theGeometry);
591  if (theHOResponse)
592  theHOResponse->setGeometry(theGeometry);
593  if (theHOSiPMResponse)
594  theHOSiPMResponse->setGeometry(theGeometry);
595  theHFResponse->setGeometry(theGeometry);
596  theHFQIE10Response->setGeometry(theGeometry);
597  theZDCResponse->setGeometry(theGeometry);
598  if (theRelabeller)
599  theRelabeller->setGeometry(theRecNumber);
600 
601  // See if it's been updated
602  bool check1 = theGeometryWatcher_.check(eventSetup);
603  bool check2 = theRecNumberWatcher_.check(eventSetup);
604  if (check1 or check2) {
605  updateGeometry(eventSetup);
606  }
607 }
608 
610  const std::vector<DetId> &hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
611  const std::vector<DetId> &heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
612  const std::vector<DetId> &hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
613  const std::vector<DetId> &hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
614  const std::vector<DetId> &zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
615  // const std::vector<DetId>& hcalTrigCells =
616  // geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower); const
617  // std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo,
618  // HcalCastorDetId::SubdetectorId);
619  // std::cout<<"HcalDigitizer::CheckGeometry number of cells:
620  // "<<zdcCells.size()<<std::endl;
621  if (zdcCells.empty())
622  zdcgeo = false;
623  if (hbCells.empty() && heCells.empty())
624  hbhegeo = false;
625  if (hoCells.empty())
626  hogeo = false;
627  if (hfCells.empty())
628  hfgeo = false;
629  // combine HB & HE
630 
631  hbheCells = hbCells;
632  if (!killHE_) {
633  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
634  }
635  // handle mixed QIE8/11 scenario in HBHE
636  buildHBHEQIECells(hbheCells, eventSetup);
639 
640  if (theHOSiPMDigitizer) {
641  buildHOSiPMCells(hoCells, eventSetup);
642  if (theHOSiPMResponse)
643  theHOSiPMResponse->setDetIds(hoCells);
644  }
645 
646  // handle mixed QIE8/10 scenario in HF
647  buildHFQIECells(hfCells, eventSetup);
648 
649  theZDCDigitizer->setDetIds(zdcCells);
650 
651  // fill test hits collection if desired and empty
652  if (injectTestHits_ && injectedHits_.empty() && !injectedHitsCells_.empty() && !injectedHitsEnergy_.empty()) {
653  // make list of specified cells if desired
654  std::vector<DetId> testCells;
655  if (injectedHitsCells_.size() >= 4) {
656  testCells.reserve(injectedHitsCells_.size() / 4);
657  for (unsigned ic = 0; ic < injectedHitsCells_.size(); ic += 4) {
658  if (ic + 4 > injectedHitsCells_.size())
659  break;
660  testCells.push_back(HcalDetId((HcalSubdetector)injectedHitsCells_[ic],
661  injectedHitsCells_[ic + 1],
662  injectedHitsCells_[ic + 2],
663  injectedHitsCells_[ic + 3]));
664  }
665  } else {
666  int testSubdet = injectedHitsCells_[0];
667  if (testSubdet == HcalBarrel)
668  testCells = hbCells;
669  else if (testSubdet == HcalEndcap)
670  testCells = heCells;
671  else if (testSubdet == HcalForward)
672  testCells = hfCells;
673  else if (testSubdet == HcalOuter)
674  testCells = hoCells;
675  else
676  throw cms::Exception("Configuration") << "Unknown subdet " << testSubdet << " for HCAL test hit injection";
677  }
678  bool useHitTimes = (injectedHitsTime_.size() == injectedHitsEnergy_.size());
679  injectedHits_.reserve(testCells.size() * injectedHitsEnergy_.size());
680  for (unsigned ih = 0; ih < injectedHitsEnergy_.size(); ++ih) {
681  double tmp = useHitTimes ? injectedHitsTime_[ih] : 0.;
682  for (auto &aCell : testCells) {
683  injectedHits_.emplace_back(aCell, injectedHitsEnergy_[ih], tmp);
684  }
685  }
686  }
687 }
688 
689 void HcalDigitizer::buildHFQIECells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
690  // if results are already cached, no need to look again
691  if (!theHFQIE8DetIds.empty() || !theHFQIE10DetIds.empty())
692  return;
693 
694  // get the QIETypes
695  // intentional copy
696  HcalQIETypes qieTypes = eventSetup.getData(qieTypesToken_);
697  if (qieTypes.topo() == nullptr) {
698  qieTypes.setTopo(&eventSetup.getData(topoToken_));
699  }
700 
701  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
702  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
703  if (qieType == QIE8) {
704  theHFQIE8DetIds.push_back(*detItr);
705  } else if (qieType == QIE10) {
706  theHFQIE10DetIds.push_back(*detItr);
707  } else { // default is QIE8
708  theHFQIE8DetIds.push_back(*detItr);
709  }
710  }
711 
712  if (!theHFQIE8DetIds.empty())
713  theHFDigitizer->setDetIds(theHFQIE8DetIds);
714  else {
715  theHFDigitizer.reset();
716  }
717 
718  if (!theHFQIE10DetIds.empty())
720  else {
721  theHFQIE10Digitizer.reset();
722  }
723 }
724 
725 void HcalDigitizer::buildHBHEQIECells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
726  // if results are already cached, no need to look again
727  if (!theHBHEQIE8DetIds.empty() || !theHBHEQIE11DetIds.empty())
728  return;
729 
730  // get the QIETypes
731  // intentional copy
732  HcalQIETypes qieTypes = eventSetup.getData(qieTypesToken_);
733  if (qieTypes.topo() == nullptr) {
734  qieTypes.setTopo(&eventSetup.getData(topoToken_));
735  }
736 
737  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
738  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
739  if (qieType == QIE8) {
740  theHBHEQIE8DetIds.push_back(*detItr);
741  } else if (qieType == QIE11) {
742  theHBHEQIE11DetIds.push_back(*detItr);
743  } else { // default is QIE8
744  theHBHEQIE8DetIds.push_back(*detItr);
745  }
746  }
747 
748  if (!theHBHEQIE8DetIds.empty())
750  else {
751  theHBHEDigitizer.reset();
752  }
753 
754  if (!theHBHEQIE11DetIds.empty())
756  else {
757  theHBHEQIE11Digitizer.reset();
758  }
759 
760  if (!theHBHEQIE8DetIds.empty() && !theHBHEQIE11DetIds.empty()) {
763  }
764 }
765 
766 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId> &allCells, const edm::EventSetup &eventSetup) {
767  // all HPD
768 
769  if (theHOSiPMCode == 0) {
770  theHODigitizer->setDetIds(allCells);
771  } else if (theHOSiPMCode == 1) {
772  theHOSiPMDigitizer->setDetIds(allCells);
773  // FIXME pick Zecotek or hamamatsu?
774  } else if (theHOSiPMCode == 2) {
775  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
776 
777  // intentional copy
778  HcalMCParams mcParams = eventSetup.getData(mcParamsToken_);
779  if (mcParams.topo() == nullptr) {
780  mcParams.setTopo(&eventSetup.getData(topoToken_));
781  }
782 
783  for (std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
784  int shapeType = mcParams.getValues(*detItr)->signalShape();
785  if (shapeType == HcalShapes::ZECOTEK) {
786  zecotekDetIds.emplace_back(*detItr);
787  theHOSiPMDetIds.push_back(*detItr);
788  } else if (shapeType == HcalShapes::HAMAMATSU) {
789  hamamatsuDetIds.emplace_back(*detItr);
790  theHOSiPMDetIds.push_back(*detItr);
791  } else {
792  theHOHPDDetIds.push_back(*detItr);
793  }
794  }
795 
796  if (!theHOHPDDetIds.empty())
797  theHODigitizer->setDetIds(theHOHPDDetIds);
798  else {
799  theHODigitizer.reset();
800  }
801 
802  if (!theHOSiPMDetIds.empty())
804  else {
805  theHOSiPMDigitizer.reset();
806  }
807 
808  if (!theHOHPDDetIds.empty() && !theHOSiPMDetIds.empty()) {
811  }
812 
813  theParameterMap.setHOZecotekDetIds(zecotekDetIds);
814  theParameterMap.setHOHamamatsuDetIds(hamamatsuDetIds);
815 
816  // make sure we don't got through this exercise again
817  theHOSiPMCode = -2;
818  }
819 }
820 
821 void HcalDigitizer::darkening(std::vector<PCaloHit> &hcalHits) {
822  for (unsigned int ii = 0; ii < hcalHits.size(); ++ii) {
823  uint32_t tmpId = hcalHits[ii].id();
824  int det, z, depth, ieta, phi, lay;
825  HcalTestNumbering::unpackHcalIndex(tmpId, det, z, depth, ieta, phi, lay);
826 
827  bool darkened = false;
828  float dweight = 1.;
829 
830  if (det == int(HcalBarrel) && m_HBDarkening) {
831  // HB darkening
832  dweight = m_HBDarkening->degradation(deliveredLumi, ieta, lay);
833  darkened = true;
834  } else if (det == int(HcalEndcap) && m_HEDarkening) {
835  // HE darkening
836  dweight = m_HEDarkening->degradation(deliveredLumi, ieta, lay);
837  darkened = true;
838  } else if (det == int(HcalForward) && m_HFRecalibration) {
839  // HF darkening - approximate: invert recalibration factor
840  dweight = 1.0 / m_HFRecalibration->getCorr(ieta, depth, deliveredLumi);
841  darkened = true;
842  }
843 
844  // reset hit energy
845  if (darkened)
846  hcalHits[ii].setEnergy(hcalHits[ii].energy() * dweight);
847  }
848 }
HFHitFilter theHFQIE10HitFilter
std::vector< DetId > theHFQIE10DetIds
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< int > injectedHitsCells_
HBHEHitFilter theHBHEHitFilter
std::vector< PCaloHit > PCaloHitContainer
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
int getValue() const
Definition: HcalQIEType.h:19
void setQIE10NoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::vector< CaloSamples > CaloSamplesCollection
Definition: CaloSamples.h:99
const HcalDDDRecConstants * theRecNumber
Definition: HcalDigitizer.h:88
void setParameterMap(HcalSimParameterMap *map)
std::unique_ptr< CaloHitResponse > theHFResponse
uint16_t *__restrict__ id
const edm::ESGetToken< HcalDDDRecConstants, HcalRecNumberingRecord > theRecNumberToken
Definition: HcalDigitizer.h:82
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::unique_ptr< HcalTimeSlewSim > theTimeSlewSim
std::unique_ptr< HcalAmplifier > theHBHEAmplifier
virtual ~HcalDigitizer()
std::unique_ptr< HBHEDigitizer > theHBHEDigitizer
void buildHFQIECells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
Definition: HcalQIENum.h:4
constexpr bool oldFormat() const
Definition: HcalDetId.h:139
HOHitFilter theHOHitFilter
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::unique_ptr< ZDCDigitizer > theZDCDigitizer
void darkening(std::vector< PCaloHit > &hcalHits)
std::unique_ptr< HcalHitRelabeller > theRelabeller
HFHitFilter theHFHitFilter
void checkGeometry(const edm::EventSetup &eventSetup)
const Item * getValues(DetId fId, bool throwOnFail=true) const
bool validHcal(const HcalDetId &id) const
Log< level::Error, false > LogError
int ii
Definition: cuy.py:589
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:81
std::unique_ptr< HODigitizer > theHODigitizer
std::unique_ptr< HcalAmplifier > theHFAmplifier
edm::SortedCollection< ZDCDataFrame > ZDCDigiCollection
edm::ESGetToken< HBHEDarkening, HBHEDarkeningRecord > m_HBDarkeningToken
Definition: HcalDigitizer.h:78
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
bool getData(T &iHolder) const
Definition: EventSetup.h:128
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
std::vector< double > injectedHitsEnergy_
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
void setQIE11NoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
void setHOZecotekDetIds(const std::vector< HcalDetId > &ids)
std::unique_ptr< HcalElectronicsSim > theHFQIE10ElectronicsSim
const HBHEDarkening * m_HEDarkening
std::unique_ptr< HcalElectronicsSim > theHFElectronicsSim
edm::ESWatcher< HcalRecNumberingRecord > theRecNumberWatcher_
Definition: HcalDigitizer.h:86
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)
ZDCHitFilter theZDCHitFilter
std::unique_ptr< HcalSiPMHitResponse > theHBHESiPMResponse
def move
Definition: eostools.py:511
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
bool isValid() const
Definition: HandleBase.h:70
edm::ESGetToken< HBHEDarkening, HBHEDarkeningRecord > m_HEDarkeningToken
Definition: HcalDigitizer.h:79
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
HcalSimParameterMap theParameterMap
std::unique_ptr< HcalElectronicsSim > theHBHEElectronicsSim
const edm::ESGetToken< HcalQIETypes, HcalQIETypesRcd > qieTypesToken_
Definition: HcalDigitizer.h:83
HcalDataFrameContainer< QIE11DataFrame > QIE11DigiCollection
Log< level::Info, false > LogInfo
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > topoToken_
Definition: HcalDigitizer.h:77
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:85
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
std::unique_ptr< QIE11Digitizer > theHBHEQIE11Digitizer
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::unique_ptr< QIE10Digitizer > theHFQIE10Digitizer
void setDetIds(const std::vector< DetId > &detIds)
Definition: HcalHitFilter.h:17
unsigned int signalShape() const
Definition: HcalMCParam.h:38
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:87
std::unique_ptr< HcalAmplifier > theHOAmplifier
std::unique_ptr< HcalSiPMHitResponse > theHOSiPMResponse
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
std::vector< DetId > hbheCells
const HBHEDarkening * m_HBDarkening
std::unique_ptr< HcalElectronicsSim > theHOElectronicsSim
HBHEHitFilter theHBHEQIE11HitFilter
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
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:84
const edm::ESGetToken< HcalDbService, HcalDbRecord > conditionsToken_
Definition: HcalDigitizer.h:76
tuple cout
Definition: gather_cfg.py:144
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)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< DetId > theHBHEQIE11DetIds
void setTopo(const HcalTopology *topo)
void setDbService(const HcalDbService *service)
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection
float degradation(float intlumi, int ieta, int lay) const
std::vector< PCaloHit > injectedHits_
const HcalTopology * topo() const
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
constexpr uint32_t newForm() const
Definition: HcalDetId.h:199
void setHONoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
HcalDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
const edm::ESGetToken< HcalTimeSlew, HcalTimeSlewRecord > hcalTimeSlew_delay_token_
Definition: HcalDigitizer.h:80