CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDigitizer.cc
Go to the documentation of this file.
35 #include <boost/foreach.hpp>
39 
40 //#define DebugLog
41 
42 namespace HcalDigitizerImpl {
43 
44  template<typename SIPMDIGITIZER>
45  void fillSiPMCells(std::vector<int> & siPMCells, SIPMDIGITIZER * siPMDigitizer)
46  {
47  std::vector<DetId> siPMDetIds;
48  siPMDetIds.reserve(siPMCells.size());
49  for(std::vector<int>::const_iterator idItr = siPMCells.begin();
50  idItr != siPMCells.end(); ++idItr)
51  {
52  siPMDetIds.emplace_back(*idItr);
53  }
54  siPMDigitizer->setDetIds(siPMDetIds);
55  }
56 
57  // if both exist, assume the SiPM one has cells filled, and
58  // assign the rest to the HPD
59  template<typename HPDDIGITIZER, typename SIPMDIGITIZER>
60  void fillCells(std::vector<DetId>& allCells,
61  HPDDIGITIZER * hpdDigitizer,
62  SIPMDIGITIZER * siPMDigitizer)
63  {
64  // if both digitizers exist, split up the cells
65  if(siPMDigitizer && hpdDigitizer)
66  {
67  std::vector<DetId> siPMDetIds = siPMDigitizer->detIds();
68  std::sort(siPMDetIds.begin(), siPMDetIds.end());
69  std::vector<DetId> sortedCells = allCells;
70  std::sort(sortedCells.begin(), sortedCells.end());
71  std::vector<DetId> hpdCells;
72  std::set_difference(sortedCells.begin(), sortedCells.end(),
73  siPMDetIds.begin(), siPMDetIds.end(),
74  std::back_inserter(hpdCells) );
75  hpdDigitizer->setDetIds(hpdCells);
76  }
77  else
78  {
79  if(siPMDigitizer) siPMDigitizer->setDetIds(allCells);
80  if(hpdDigitizer) hpdDigitizer->setDetIds(allCells);
81  }
82  }
83 } // namespace HcaiDigitizerImpl
84 
85 
87  theGeometry(0),
88  theRecNumber(0),
89  theParameterMap(new HcalSimParameterMap(ps)),
90  theShapes(new HcalShapes()),
91  theHBHEResponse(0),
92  theHBHESiPMResponse(0),
93  theHOResponse(0),
94  theHOSiPMResponse(0),
95  theHFResponse(new CaloHitResponse(theParameterMap, theShapes)),
96  theZDCResponse(new CaloHitResponse(theParameterMap, theShapes)),
97  theHBHEAmplifier(0),
98  theHFAmplifier(0),
99  theHOAmplifier(0),
100  theZDCAmplifier(0),
101  theIonFeedback(0),
102  theCoderFactory(0),
103  theUpgradeCoderFactory(0),
104  theHBHEElectronicsSim(0),
105  theHFElectronicsSim(0),
106  theHOElectronicsSim(0),
107  theZDCElectronicsSim(0),
108  theUpgradeHBHEElectronicsSim(0),
109  theUpgradeHFElectronicsSim(0),
110  theHBHEHitFilter(),
111  theHFHitFilter(ps.getParameter<bool>("doHFWindow")),
112  theHOHitFilter(),
113  theHOSiPMHitFilter(HcalOuter),
114  theZDCHitFilter(),
115  theHitCorrection(0),
116  theNoiseGenerator(0),
117  theNoiseHitGenerator(0),
118  theHBHEDigitizer(0),
119  theHBHESiPMDigitizer(0),
120  theHODigitizer(0),
121  theHOSiPMDigitizer(0),
122  theHFDigitizer(0),
123  theZDCDigitizer(0),
124  theHBHEUpgradeDigitizer(0),
125  theHFUpgradeDigitizer(0),
126  theRelabeller(0),
127  isZDC(true),
128  isHCAL(true),
129  zdcgeo(true),
130  hbhegeo(true),
131  hogeo(true),
132  hfgeo(true),
133  hitsProducer_(ps.getParameter<std::string>("hitsProducer")),
134  theHOSiPMCode(ps.getParameter<edm::ParameterSet>("ho").getParameter<int>("siPMCode")),
135  deliveredLumi(0.),
136  m_HEDarkening(0),
137  m_HFRecalibration(0)
138 {
139  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "ZDCHITS"));
140  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "HcalHits"));
141 
142  bool doNoise = ps.getParameter<bool>("doNoise");
143  bool PreMix1 = ps.getParameter<bool>("HcalPreMixStage1"); // special threshold/pedestal treatment
144  bool PreMix2 = ps.getParameter<bool>("HcalPreMixStage2"); // special threshold/pedestal treatment
145  bool useOldNoiseHB = ps.getParameter<bool>("useOldHB");
146  bool useOldNoiseHE = ps.getParameter<bool>("useOldHE");
147  bool useOldNoiseHF = ps.getParameter<bool>("useOldHF");
148  bool useOldNoiseHO = ps.getParameter<bool>("useOldHO");
149  bool doEmpty = ps.getParameter<bool>("doEmpty");
150  double HBtp = ps.getParameter<double>("HBTuningParameter");
151  double HEtp = ps.getParameter<double>("HETuningParameter");
152  double HFtp = ps.getParameter<double>("HFTuningParameter");
153  double HOtp = ps.getParameter<double>("HOTuningParameter");
154  bool doHBHEUpgrade = ps.getParameter<bool>("HBHEUpgradeQIE");
155  bool doHFUpgrade = ps.getParameter<bool>("HFUpgradeQIE");
156  deliveredLumi = ps.getParameter<double>("DelivLuminosity");
157  bool agingFlagHE = ps.getParameter<bool>("HEDarkening");
158  bool agingFlagHF = ps.getParameter<bool>("HFDarkening");
159  double minFCToDelay= ps.getParameter<double>("minFCToDelay");
160 
161  if(PreMix1 && PreMix2) {
162  throw cms::Exception("Configuration")
163  << "HcalDigitizer cannot operate in PreMixing digitization and PreMixing\n"
164  "digi combination modes at the same time. Please set one mode to False\n"
165  "in the configuration file.";
166  }
167 
168  // need to make copies, because they might get different noise generators
169  theHBHEAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
170  theHFAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
171  theHOAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
172  theZDCAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
177  theHBHEAmplifier->setUseOldHB(useOldNoiseHB);
178  theHBHEAmplifier->setUseOldHE(useOldNoiseHE);
179  theHFAmplifier->setUseOldHF(useOldNoiseHF);
180  theHOAmplifier->setUseOldHO(useOldNoiseHO);
181 
184 
185 // std::cout << "HcalDigitizer: theUpgradeCoderFactory created" << std::endl;
186 
193 
194 // std::cout << "HcalDigitizer: theUpgradeElectronicsSim created" << std::endl;
195 
196  // a code of 1 means make all cells SiPM
197  std::vector<int> hbSiPMCells(ps.getParameter<edm::ParameterSet>("hb").getParameter<std::vector<int> >("siPMCells"));
198  //std::vector<int> hoSiPMCells(ps.getParameter<edm::ParameterSet>("ho").getParameter<std::vector<int> >("siPMCells"));
199  // 0 means none, 1 means all, and 2 means use hardcoded
200 
201 // std::cout << std::endl << " hbSiPMCells = " << hbSiPMCells.size() << std::endl;
202 
203  bool doHBHEHPD = hbSiPMCells.empty() || (hbSiPMCells[0] != 1);
204  bool doHOHPD = (theHOSiPMCode != 1);
205  bool doHBHESiPM = !hbSiPMCells.empty();
206  bool doHOSiPM = (theHOSiPMCode != 0);
207  if(doHBHEHPD) {
209  edm::LogInfo("HcalDigitizer") <<"Set scale for HB towers";
211 
214  bool changeResponse = ps.getParameter<bool>("ChangeResponse");
215  edm::FileInPath fname = ps.getParameter<edm::FileInPath>("CorrFactorFile");
216  if (changeResponse) {
217  std::string corrFileName = fname.fullPath();
218  edm::LogInfo("HcalDigitizer") << "Set scale for HB towers from " << corrFileName;
219  theHBHEResponse->setHBHEScale(corrFileName); //GMA
220  }
221  }
222  if(doHOHPD) {
226  }
227 
228  if(doHBHESiPM) {
231  if (doHBHEUpgrade) {
233 
234 // std::cout << "HcalDigitizer: theHBHEUpgradeDigitizer created" << std::endl;
235 
236  } else {
238  }
239  }
240  if(doHOSiPM) {
244  }
245 
246  // if both are present, fill the SiPM cells now
247  if(doHBHEHPD && doHBHESiPM) {
248 
249 // std::cout << "HcalDigitizer: fill the SiPM cells now" << std::endl;
250 
252  }
253 
256 
257  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
258  //initialize: they won't be called later if flag is set
259  theTimeSlewSim = 0;
260  if(doTimeSlew) {
261  // no time slewing for HF
262  theTimeSlewSim = new HcalTimeSlewSim(theParameterMap,minFCToDelay);
263  theHBHEAmplifier->setTimeSlewSim(theTimeSlewSim);
264  theHOAmplifier->setTimeSlewSim(theTimeSlewSim);
265  theZDCAmplifier->setTimeSlewSim(theTimeSlewSim);
266  }
267 
268  if (doHFUpgrade) {
270 
271 // std::cout << "HcalDigitizer: theHFUpgradeDigitizer created" << std::endl;
272 
273  } else {
275  }
277 
278  edm::ParameterSet ps0 = ps.getParameter<edm::ParameterSet>("HcalReLabel");
279  relabel_ = ps0.getUntrackedParameter<bool>("RelabelHits");
280 // std::cout << "Flag to see if Hit Relabeller to be initiated " << relabel_ << std::endl;
281  if (relabel_) {
283  }
284 
285  bool doHPDNoise = ps.getParameter<bool>("doHPDNoise");
286  if(doHPDNoise) {
287  //edm::ParameterSet hpdNoisePset = ps.getParameter<edm::ParameterSet>("HPDNoiseLibrary");
291  }
292 
293  if(ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
296  if(ps.getParameter<bool>("doThermalNoise")) {
298  }
299  }
300 
301  if(ps.getParameter<bool>("injectTestHits") ) {
309 
310 // std::cout << "HcalDigitizer: theHBHEUpgradeDigitizer setNoise" << std::endl;
311  }
313  if(theHFUpgradeDigitizer) {
315 
316 // std::cout << "HcalDigitizer: theHFUpgradeDigitizer setNoise" << std::endl;
317  }
319  }
320 
321  if(agingFlagHE) m_HEDarkening = new HEDarkening();
322  if(agingFlagHF) m_HFRecalibration = new HFRecalibration();
323 }
324 
325 
329  if(theHODigitizer) delete theHODigitizer;
331  if(theHFDigitizer) delete theHFDigitizer;
332  delete theZDCDigitizer;
335  delete theParameterMap;
336  delete theHBHEResponse;
337  delete theHBHESiPMResponse;
338  delete theHOResponse;
339  delete theHOSiPMResponse;
340  delete theHFResponse;
341  delete theZDCResponse;
342  delete theHBHEElectronicsSim;
343  delete theHFElectronicsSim;
344  delete theHOElectronicsSim;
345  delete theZDCElectronicsSim;
348  delete theHBHEAmplifier;
349  delete theHFAmplifier;
350  delete theHOAmplifier;
351  delete theZDCAmplifier;
352  delete theCoderFactory;
353  delete theUpgradeCoderFactory;
354  delete theHitCorrection;
355  delete theNoiseGenerator;
356  if (theRelabeller) delete theRelabeller;
357 }
358 
359 
361  noiseGenerator->setParameterMap(theParameterMap);
362  noiseGenerator->setElectronicsSim(theHBHEElectronicsSim);
364  theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
365 }
366 
368  noiseGenerator->setParameterMap(theParameterMap);
369  noiseGenerator->setElectronicsSim(theHFElectronicsSim);
372  theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
373 }
374 
376  noiseGenerator->setParameterMap(theParameterMap);
377  noiseGenerator->setElectronicsSim(theHOElectronicsSim);
380  theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
381 }
382 
384  noiseGenerator->setParameterMap(theParameterMap);
385  noiseGenerator->setElectronicsSim(theZDCElectronicsSim);
386  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
387  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
388 }
389 
391  // get the appropriate gains, noises, & widths for this event
392  edm::ESHandle<HcalDbService> conditions;
393  eventSetup.get<HcalDbRecord>().get(conditions);
394  theHBHEAmplifier->setDbService(conditions.product());
395  theHFAmplifier->setDbService(conditions.product());
396  theHOAmplifier->setDbService(conditions.product());
397  theZDCAmplifier->setDbService(conditions.product());
400 
401  theCoderFactory->setDbService(conditions.product());
403  theParameterMap->setDbService(conditions.product());
404 
406  if (eventSetup.find(edm::eventsetup::EventSetupRecordKey::makeKey<HcalCholeskyMatricesRcd>())) {
407  eventSetup.get<HcalCholeskyMatricesRcd>().get(refCholesky);
408  const HcalCholeskyMatrices * myCholesky = refCholesky.product();
409  theHBHEAmplifier->setCholesky(myCholesky);
410  theHFAmplifier->setCholesky(myCholesky);
411  theHOAmplifier->setCholesky(myCholesky);
412  }
413  edm::ESHandle<HcalPedestals> pedshandle;
414  eventSetup.get<HcalPedestalsRcd>().get(pedshandle);
415  const HcalPedestals * myADCPedestals = pedshandle.product();
416 
417  theHBHEAmplifier->setADCPeds(myADCPedestals);
418  theHFAmplifier->setADCPeds(myADCPedestals);
419  theHOAmplifier->setADCPeds(myADCPedestals);
420 
421  if(theHitCorrection != 0) {
423  }
424 
425  //initialize hits
434 
435 }
436 
437 void HcalDigitizer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit> > const& hcalHandle, edm::Handle<std::vector<PCaloHit> > const& zdcHandle, int bunchCrossing, CLHEP::HepRandomEngine* engine, const HcalTopology *htopoP) {
438 
439  // Step A: pass in inputs, and accumulate digirs
440  if(isHCAL) {
441  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
442  std::vector<PCaloHit> hcalHits;
443  hcalHits.reserve(hcalHitsOrig.size());
444 
445  //evaluate darkening before relabeling
447  darkening(hcalHitsOrig);
448  }
449  // Relabel PCaloHits if necessary
450  if (relabel_) {
451  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
452  theRelabeller->process(hcalHitsOrig);
453  }
454 
455  //eliminate bad hits
456  for (unsigned int i=0; i< hcalHitsOrig.size(); i++) {
457  DetId id(hcalHitsOrig[i].id());
458  HcalDetId hid(id);
459  if (!htopoP->validHcal(hid)) {
460  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << std::endl;
461  } else {
462 #ifdef DebugLog
463  std::cout << "HcalDigitizer format " << hid.oldFormat() << " for " << hid << std::endl;
464 #endif
465  DetId newid = DetId(hid.newForm());
466 #ifdef DebugLog
467  std::cout << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId() << " --> " << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
468 #endif
469  hcalHitsOrig[i].setID(newid.rawId());
470  hcalHits.push_back(hcalHitsOrig[i]);
471  }
472  }
473 
474  if(theHitCorrection != 0) {
475  theHitCorrection->fillChargeSums(hcalHits);
476  }
477  if(hbhegeo) {
478  if(theHBHEDigitizer) theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
479  if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->add(hcalHits, bunchCrossing, engine);
481  theHBHEUpgradeDigitizer->add(hcalHits, bunchCrossing, engine);
482  }
483  }
484 
485  if(hogeo) {
486  if(theHODigitizer) theHODigitizer->add(hcalHits, bunchCrossing, engine);
487  if(theHOSiPMDigitizer) theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
488  }
489 
490  if(hfgeo) {
491  if(theHFDigitizer) theHFDigitizer->add(hcalHits, bunchCrossing, engine);
492  if(theHFUpgradeDigitizer) theHFUpgradeDigitizer->add(hcalHits, bunchCrossing, engine);
493  }
494  } else {
495  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
496  }
497 
498  if(isZDC) {
499  if(zdcgeo) {
500  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
501  }
502  } else {
503  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
504  }
505 }
506 
507 void HcalDigitizer::accumulate(edm::Event const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
508  // Step A: Get Inputs
509  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
511  e.getByLabel(zdcTag, zdcHandle);
512  isZDC = zdcHandle.isValid();
513 
514  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
516  e.getByLabel(hcalTag, hcalHandle);
517  isHCAL = hcalHandle.isValid();
518 
520  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
521  const HcalTopology *htopoP=htopo.product();
522 
523  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
524 }
525 
526 void HcalDigitizer::accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
527  // Step A: Get Inputs
528  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
530  e.getByLabel(zdcTag, zdcHandle);
531  isZDC = zdcHandle.isValid();
532 
533  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
535  e.getByLabel(hcalTag, hcalHandle);
536  isHCAL = hcalHandle.isValid();
537 
539  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
540  const HcalTopology *htopoP=htopo.product();
541 
542  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
543 }
544 
545 void HcalDigitizer::finalizeEvent(edm::Event& e, const edm::EventSetup& eventSetup, CLHEP::HepRandomEngine* engine) {
546 
547  // Step B: Create empty output
548  std::auto_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
549  std::auto_ptr<HODigiCollection> hoResult(new HODigiCollection());
550  std::auto_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
551  std::auto_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
552  std::auto_ptr<HBHEUpgradeDigiCollection> hbheupgradeResult(new HBHEUpgradeDigiCollection());
553  std::auto_ptr<HFUpgradeDigiCollection> hfupgradeResult(new HFUpgradeDigiCollection());
554 
555  // Step C: Invoke the algorithm, getting back outputs.
556  if(isHCAL&&hbhegeo){
557  if(theHBHEDigitizer) theHBHEDigitizer->run(*hbheResult, engine);
558  if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->run(*hbheResult, engine);
560  theHBHEUpgradeDigitizer->run(*hbheupgradeResult, engine);
561 #ifdef DebugLog
562  std::cout << "HcalDigitizer::finalizeEvent theHBHEUpgradeDigitizer->run" << std::endl;
563 #endif
564  }
565  }
566  if(isHCAL&&hogeo) {
567  if(theHODigitizer) theHODigitizer->run(*hoResult, engine);
568  if(theHOSiPMDigitizer) theHOSiPMDigitizer->run(*hoResult, engine);
569  }
570  if(isHCAL&&hfgeo) {
571  if(theHFDigitizer) theHFDigitizer->run(*hfResult, engine);
572  if(theHFUpgradeDigitizer) theHFUpgradeDigitizer->run(*hfupgradeResult, engine);
573  }
574  if(isZDC&&zdcgeo) {
575  theZDCDigitizer->run(*zdcResult, engine);
576  }
577 
578  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
579  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
580  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
581  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
582  edm::LogInfo("HcalDigitizer") << "HCAL HBHE upgrade digis : " << hbheupgradeResult->size();
583  edm::LogInfo("HcalDigitizer") << "HCAL HF upgrade digis : " << hfupgradeResult->size();
584 
585 #ifdef DebugLog
586  std::cout << std::endl;
587  std::cout << "HCAL HBHE digis : " << hbheResult->size() << std::endl;
588  std::cout << "HCAL HO digis : " << hoResult->size() << std::endl;
589  std::cout << "HCAL HF digis : " << hfResult->size() << std::endl;
590 
591  std::cout << "HCAL HBHE upgrade digis : " << hbheupgradeResult->size()
592  << std::endl;
593  std::cout << "HCAL HF upgrade digis : " << hfupgradeResult->size()
594  << std::endl;
595 #endif
596 
597  // Step D: Put outputs into event
598  e.put(hbheResult);
599  e.put(hoResult);
600  e.put(hfResult);
601  e.put(zdcResult);
602  e.put(hbheupgradeResult,"HBHEUpgradeDigiCollection");
603  e.put(hfupgradeResult, "HFUpgradeDigiCollection");
604 #ifdef DebugLog
605  std::cout << std::endl << "========> HcalDigitizer e.put " << std::endl << std::endl;
606 #endif
607  if(theHitCorrection) {
609  }
610 }
611 
612 
614  checkGeometry(es);
615  theShapes->beginRun(es);
616 }
617 
618 
620  theShapes->endRun();
621 }
622 
623 
625  // TODO find a way to avoid doing this every event
627  eventSetup.get<CaloGeometryRecord>().get(geometry);
629  eventSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
630 
631  // See if it's been updated
632  if (&*geometry != theGeometry) {
633  theGeometry = &*geometry;
634  theRecNumber= &*pHRNDC;
635  updateGeometry(eventSetup);
636  }
637 }
638 
639 
648 
649  const std::vector<DetId>& hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
650  const std::vector<DetId>& heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
651  const std::vector<DetId>& hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
652  const std::vector<DetId>& hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
653  const std::vector<DetId>& zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
654  //const std::vector<DetId>& hcalTrigCells = geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower);
655  //const std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
656 // std::cout<<"HcalDigitizer::CheckGeometry number of cells: "<<zdcCells.size()<<std::endl;
657  if(zdcCells.empty()) zdcgeo = false;
658  if(hbCells.empty() && heCells.empty()) hbhegeo = false;
659  if(hoCells.empty()) hogeo = false;
660  if(hfCells.empty()) hfgeo = false;
661  // combine HB & HE
662 
663  theHBHEDetIds = hbCells;
664  theHBHEDetIds.insert(theHBHEDetIds.end(), heCells.begin(), heCells.end());
665 
667  //HcalDigitizerImpl::fillCells(hoCells, theHODigitizer, theHOSiPMDigitizer);
668  buildHOSiPMCells(hoCells, eventSetup);
671  theZDCDigitizer->setDetIds(zdcCells);
674 #ifdef DebugLog
675  std::cout << " HcalDigitizer::updateGeometry theHBHEUpgradeDigitizer->setDetIds(theHBHEDetIds)"<< std::endl;
676 #endif
677  }
678 
679 }
680 
681 
682 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
683  // all HPD
684 
685  if(theHOSiPMCode == 0) {
686  theHODigitizer->setDetIds(allCells);
687  } else if(theHOSiPMCode == 1) {
688  theHOSiPMDigitizer->setDetIds(allCells);
689  // FIXME pick Zecotek or hamamatsu?
690  } else if(theHOSiPMCode == 2) {
691  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
693  eventSetup.get<HcalMCParamsRcd>().get(p);
695  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
696 
697  HcalMCParams mcParams(*p.product());
698  if (mcParams.topo()==0) {
699  mcParams.setTopo(htopo.product());
700  }
701 
702  for(std::vector<DetId>::const_iterator detItr = allCells.begin();
703  detItr != allCells.end(); ++detItr) {
704  int shapeType = mcParams.getValues(*detItr)->signalShape();
705  if(shapeType == HcalShapes::ZECOTEK) {
706  zecotekDetIds.emplace_back(*detItr);
707  theHOSiPMDetIds.push_back(*detItr);
708  } else if(shapeType == HcalShapes::HAMAMATSU) {
709  hamamatsuDetIds.emplace_back(*detItr);
710  theHOSiPMDetIds.push_back(*detItr);
711  } else {
712  theHOHPDDetIds.push_back(*detItr);
713  }
714  }
715 
721  // FIXME not applying a HitFilter to the HPDs, for now
722  theParameterMap->setHOZecotekDetIds(zecotekDetIds);
723  theParameterMap->setHOHamamatsuDetIds(hamamatsuDetIds);
724 
725  // make sure we don't got through this exercise again
726  theHOSiPMCode = -2;
727  }
728 }
729 
730 void HcalDigitizer::darkening(std::vector<PCaloHit>& hcalHits) {
731 
732  for (unsigned int ii=0; ii<hcalHits.size(); ++ii) {
733  uint32_t tmpId = hcalHits[ii].id();
734  int det, z, depth, ieta, phi, lay;
735  HcalTestNumbering::unpackHcalIndex(tmpId,det,z,depth,ieta,phi,lay);
736 
737  bool darkened = false;
738  float dweight = 1.;
739 
740  if(det==int(HcalEndcap) && m_HEDarkening){
741  //HE darkening
742  dweight = m_HEDarkening->degradation(deliveredLumi,ieta,lay-2);//NB:diff. layer count
743  darkened = true;
744  } else if(det==int(HcalForward) && m_HFRecalibration){
745  //HF darkening - approximate: invert recalibration factor
746  dweight = 1.0/m_HFRecalibration->getCorr(ieta,depth,deliveredLumi);
747  darkened = true;
748  }
749 
750  //create new hit with darkened energy
751  //if(darkened) hcalHits[ii] = PCaloHit(hcalHits[ii].energyEM()*dweight,hcalHits[ii].energyHad()*dweight,hcalHits[ii].time(),hcalHits[ii].geantTrackId(),hcalHits[ii].id());
752 
753  //reset hit energy
754  if(darkened) hcalHits[ii].setEnergy(hcalHits[ii].energy()*dweight);
755  }
756 
757 }
758 
759 
void setUseOldHB(bool useOld)
void setNoiseHitGenerator(CaloVNoiseHitGenerator *generator)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setHOtuningParameter(double tp)
T getParameter(std::string const &) const
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
T getUntrackedParameter(std::string const &, T const &) const
HBHEHitFilter theHBHEHitFilter
int i
Definition: DBlmapReader.cc:9
void setGeometry(const CaloGeometry *&, const HcalDDDRecConstants *&)
const HcalDDDRecConstants * theRecNumber
Definition: HcalDigitizer.h:73
void setParameterMap(HcalSimParameterMap *map)
void initializeHits()
void setDetIds(const std::vector< DetId > &detIds)
virtual ~HcalDigitizer()
HcalElectronicsSim * theHFElectronicsSim
HBHEDigitizer * theHBHEDigitizer
HOHitFilter theHOHitFilter
assert(m_qm.get())
CaloTDigitizer< HcalUpgradeDigitizerTraits > UpgradeDigitizer
Definition: HcalDigitizer.h:86
void setUseOldHF(bool useOld)
void darkening(std::vector< PCaloHit > &hcalHits)
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
HFDigitizer * theHFDigitizer
HFHitFilter theHFHitFilter
void checkGeometry(const edm::EventSetup &eventSetup)
HcalSimParameterMap * theParameterMap
Definition: HcalDigitizer.h:88
void setHFtuningParameter(double tp)
bool validHcal(const HcalDetId &id) const
void setPECorrection(const CaloVPECorrection *peCorrection)
if you want to correct the photoelectrons
int ii
Definition: cuy.py:588
HcalTimeSlewSim * theTimeSlewSim
void setADCPeds(const HcalPedestals *ADCPeds)
Definition: HcalAmplifier.h:54
HcalAmplifier * theHFAmplifier
HcalElectronicsSim * theUpgradeHFElectronicsSim
void fillSiPMCells(std::vector< int > &siPMCells, SIPMDIGITIZER *siPMDigitizer)
HcalCoderFactory * theCoderFactory
HcalHitRelabeller * theRelabeller
edm::SortedCollection< ZDCDataFrame > ZDCDigiCollection
HcalCoderFactory * theUpgradeCoderFactory
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:91
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
void setDbService(const HcalDbService *service)
void setIonFeedbackSim(HPDIonFeedbackSim *feedbackSim)
Definition: HcalAmplifier.h:31
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
UpgradeDigitizer * theHFUpgradeDigitizer
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
CaloTDigitizer< HFDigitizerTraits > HFDigitizer
Definition: HcalDigitizer.h:84
void setHOZecotekDetIds(const std::vector< HcalDetId > &ids)
HcalAmplifier * theHBHEAmplifier
void setUseOldHO(bool useOld)
edm::SortedCollection< HODataFrame > HODigiCollection
CaloTDigitizer< ZDCDigitizerTraits > ZDCDigitizer
Definition: HcalDigitizer.h:85
std::string hitsProducer_
HcalElectronicsSim * theHOElectronicsSim
void setHEtuningParameter(double tp)
double deliveredLumi
void setUseOldHE(bool useOld)
void setElectronicsSim(HcalElectronicsSim *electronicsSim)
void setHitFilter(const CaloVHitFilter *filter)
if you want to reject hits, for example, from a certain subdetector, set this
double getCorr(int ieta, int idepth, double lumi)
HcalShapes * theShapes
Definition: HcalDigitizer.h:89
Creates electronics signals from hits.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
void setHFNoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
std::vector< DetId > theHBHEDetIds
void buildHOSiPMCells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
ZDCHitFilter theZDCHitFilter
HPDIonFeedbackSim * theIonFeedback
void fillChargeSums(MixCollection< PCaloHit > &hits)
CaloHitResponse * theHOResponse
Definition: HcalDigitizer.h:93
HcalHitFilter theHOSiPMHitFilter
CaloHitResponse * theHOSiPMResponse
Definition: HcalDigitizer.h:94
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
void setHBHEScale(std::string &)
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
ZDCDigitizer * theZDCDigitizer
edm::SortedCollection< HcalUpgradeDataFrame > HFUpgradeDigiCollection
std::vector< DetId > theHOHPDDetIds
bool isValid() const
Definition: HandleBase.h:75
edm::SortedCollection< HcalUpgradeDataFrame > HBHEUpgradeDigiCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
bool oldFormat() const
Definition: HcalDetId.h:50
HcalHitCorrection * theHitCorrection
CaloHitResponse * theZDCResponse
Definition: HcalDigitizer.h:96
void endRun()
Definition: HcalShapes.cc:118
void setNoiseSignalGenerator(const CaloVNoiseSignalGenerator *noiseSignalGenerator)
Definition: HcalAmplifier.h:35
Definition: DetId.h:18
HcalElectronicsSim * theZDCElectronicsSim
HcalElectronicsSim * theUpgradeHBHEElectronicsSim
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
static const int SubdetectorId
Definition: HcalZDCDetId.h:20
void beginRun(const edm::EventSetup &es)
void process(std::vector< PCaloHit > &hcalHits)
CaloTDigitizer< HODigitizerTraits > HODigitizer
Definition: HcalDigitizer.h:83
void setTimeSlewSim(HcalTimeSlewSim *timeSlewSim)
Definition: HcalAmplifier.h:38
void setHOHamamatsuDetIds(const std::vector< HcalDetId > &ids)
void accumulateCaloHits(edm::Handle< std::vector< PCaloHit > > const &hcalHits, edm::Handle< std::vector< PCaloHit > > const &zdcHits, int bunchCrossing, CLHEP::HepRandomEngine *, const HcalTopology *h)
HcalAmplifier * theHOAmplifier
void setDbService(const HcalDbService *service)
HFRecalibration * m_HFRecalibration
const T & get() const
Definition: EventSetup.h:56
HcalElectronicsSim * theHBHEElectronicsSim
T const * product() const
Definition: ESHandle.h:86
uint32_t newForm() const
Definition: HcalDetId.cc:140
void fillCells(std::vector< DetId > &allCells, HPDDIGITIZER *hpdDigitizer, SIPMDIGITIZER *siPMDigitizer)
CaloHitResponse * theHBHEResponse
Definition: HcalDigitizer.h:91
HODigitizer * theHODigitizer
std::vector< DetId > theHOSiPMDetIds
const CaloGeometry * theGeometry
Definition: HcalDigitizer.h:72
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
void setCholesky(const HcalCholeskyMatrices *Cholesky)
Definition: HcalAmplifier.h:53
string fname
main script
ESHandle< TrackerGeometry > geometry
CaloHitResponse * theHFResponse
Definition: HcalDigitizer.h:95
HODigitizer * theHOSiPMDigitizer
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
void setZDCNoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
HBHEDigitizer * theHBHESiPMDigitizer
HEDarkening * m_HEDarkening
edm::SortedCollection< HFDataFrame > HFDigiCollection
void setDetIds(const std::vector< DetId > &detIds)
void beginRun(edm::EventSetup const &es)
Definition: HcalShapes.cc:103
CaloHitResponse * theHBHESiPMResponse
Definition: HcalDigitizer.h:92
tuple cout
Definition: gather_cfg.py:145
void setHBtuningParameter(double tp)
void updateGeometry(const edm::EventSetup &eventSetup)
float degradation(float intlumi, int ieta, int lay)
Definition: HEDarkening.cc:52
void setHBHENoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
CaloVNoiseHitGenerator * theNoiseHitGenerator
HcalAmplifier * theZDCAmplifier
void setTopo(const HcalTopology *topo)
void setDbService(const HcalDbService *service)
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
UpgradeDigitizer * theHBHEUpgradeDigitizer
void setHONoiseSignalGenerator(HcalBaseSignalGenerator *noiseGenerator)
CaloTDigitizer< HBHEDigitizerTraits > HBHEDigitizer
Definition: HcalDigitizer.h:82
HcalDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
CaloVNoiseSignalGenerator * theNoiseGenerator