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>
40 
41 //#define DebugLog
42 
43 namespace HcalDigitizerImpl {
44 
45  template<typename SIPMDIGITIZER>
46  void fillSiPMCells(std::vector<int> & siPMCells, SIPMDIGITIZER * siPMDigitizer)
47  {
48  std::vector<DetId> siPMDetIds;
49  siPMDetIds.reserve(siPMCells.size());
50  for(std::vector<int>::const_iterator idItr = siPMCells.begin();
51  idItr != siPMCells.end(); ++idItr)
52  {
53  siPMDetIds.emplace_back(*idItr);
54  }
55  siPMDigitizer->setDetIds(siPMDetIds);
56  }
57 
58  // if both exist, assume the SiPM one has cells filled, and
59  // assign the rest to the HPD
60  template<typename HPDDIGITIZER, typename SIPMDIGITIZER>
61  void fillCells(std::vector<DetId>& allCells,
62  HPDDIGITIZER * hpdDigitizer,
63  SIPMDIGITIZER * siPMDigitizer)
64  {
65  // if both digitizers exist, split up the cells
66  if(siPMDigitizer && hpdDigitizer)
67  {
68  std::vector<DetId> siPMDetIds = siPMDigitizer->detIds();
69  std::sort(siPMDetIds.begin(), siPMDetIds.end());
70  std::vector<DetId> sortedCells = allCells;
71  std::sort(sortedCells.begin(), sortedCells.end());
72  std::vector<DetId> hpdCells;
73  std::set_difference(sortedCells.begin(), sortedCells.end(),
74  siPMDetIds.begin(), siPMDetIds.end(),
75  std::back_inserter(hpdCells) );
76  hpdDigitizer->setDetIds(hpdCells);
77  }
78  else
79  {
80  if(siPMDigitizer) siPMDigitizer->setDetIds(allCells);
81  if(hpdDigitizer) hpdDigitizer->setDetIds(allCells);
82  }
83  }
84 } // namespace HcaiDigitizerImpl
85 
86 
88  theGeometry(0),
89  theRecNumber(0),
90  theParameterMap(new HcalSimParameterMap(ps)),
91  theShapes(new HcalShapes()),
92  theHBHEResponse(0),
93  theHBHESiPMResponse(0),
94  theHOResponse(0),
95  theHOSiPMResponse(0),
96  theHFResponse(new CaloHitResponse(theParameterMap, theShapes)),
97  theHFQIE10Response(new CaloHitResponse(theParameterMap, theShapes)),
98  theZDCResponse(new CaloHitResponse(theParameterMap, theShapes)),
99  theHBHEAmplifier(0),
100  theHFAmplifier(0),
101  theHOAmplifier(0),
102  theZDCAmplifier(0),
103  theIonFeedback(0),
104  theCoderFactory(0),
105  theUpgradeCoderFactory(0),
106  theHBHEElectronicsSim(0),
107  theHFElectronicsSim(0),
108  theHOElectronicsSim(0),
109  theZDCElectronicsSim(0),
110  theUpgradeHBHEElectronicsSim(0),
111  theUpgradeHFElectronicsSim(0),
112  theHFQIE10ElectronicsSim(0),
113  theHBHEHitFilter(),
114  theHFHitFilter(ps.getParameter<bool>("doHFWindow")),
115  theHOHitFilter(),
116  theHOSiPMHitFilter(HcalOuter),
117  theZDCHitFilter(),
118  theHitCorrection(0),
119  theNoiseGenerator(0),
120  theNoiseHitGenerator(0),
121  theHBHEDigitizer(0),
122  theHBHESiPMDigitizer(0),
123  theHODigitizer(0),
124  theHOSiPMDigitizer(0),
125  theHFDigitizer(0),
126  theZDCDigitizer(0),
127  theHBHEUpgradeDigitizer(0),
128  theHFUpgradeDigitizer(0),
129  theHFQIE10Digitizer(0),
130  theRelabeller(0),
131  isZDC(true),
132  isHCAL(true),
133  zdcgeo(true),
134  hbhegeo(true),
135  hogeo(true),
136  hfgeo(true),
137  hitsProducer_(ps.getParameter<std::string>("hitsProducer")),
138  theHOSiPMCode(ps.getParameter<edm::ParameterSet>("ho").getParameter<int>("siPMCode")),
139  deliveredLumi(0.),
140  m_HEDarkening(0),
141  m_HFRecalibration(0)
142 {
143  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "ZDCHITS"));
144  iC.consumes<std::vector<PCaloHit> >(edm::InputTag(hitsProducer_, "HcalHits"));
145 
146  bool doNoise = ps.getParameter<bool>("doNoise");
147  bool PreMix1 = ps.getParameter<bool>("HcalPreMixStage1"); // special threshold/pedestal treatment
148  bool PreMix2 = ps.getParameter<bool>("HcalPreMixStage2"); // special threshold/pedestal treatment
149  bool useOldNoiseHB = ps.getParameter<bool>("useOldHB");
150  bool useOldNoiseHE = ps.getParameter<bool>("useOldHE");
151  bool useOldNoiseHF = ps.getParameter<bool>("useOldHF");
152  bool useOldNoiseHO = ps.getParameter<bool>("useOldHO");
153  bool doEmpty = ps.getParameter<bool>("doEmpty");
154  double HBtp = ps.getParameter<double>("HBTuningParameter");
155  double HEtp = ps.getParameter<double>("HETuningParameter");
156  double HFtp = ps.getParameter<double>("HFTuningParameter");
157  double HOtp = ps.getParameter<double>("HOTuningParameter");
158  bool doHBHEUpgrade = ps.getParameter<bool>("HBHEUpgradeQIE");
159  bool doHFUpgrade = ps.getParameter<bool>("HFUpgradeQIE");
160  deliveredLumi = ps.getParameter<double>("DelivLuminosity");
161  bool agingFlagHE = ps.getParameter<bool>("HEDarkening");
162  bool agingFlagHF = ps.getParameter<bool>("HFDarkening");
163  double minFCToDelay= ps.getParameter<double>("minFCToDelay");
164  bool doHFQIE10 = ps.getParameter<bool>("HFQIE10");
165  bool doHFQIE8 = ps.getParameter<bool>("HFQIE8");
166 
167  if(PreMix1 && PreMix2) {
168  throw cms::Exception("Configuration")
169  << "HcalDigitizer cannot operate in PreMixing digitization and PreMixing\n"
170  "digi combination modes at the same time. Please set one mode to False\n"
171  "in the configuration file.";
172  }
173 
174  // need to make copies, because they might get different noise generators
175  theHBHEAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
176  theHFAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
177  theHOAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
178  theZDCAmplifier = new HcalAmplifier(theParameterMap, doNoise, PreMix1, PreMix2);
183  theHBHEAmplifier->setUseOldHB(useOldNoiseHB);
184  theHBHEAmplifier->setUseOldHE(useOldNoiseHE);
185  theHFAmplifier->setUseOldHF(useOldNoiseHF);
186  theHOAmplifier->setUseOldHO(useOldNoiseHO);
187 
190 
191 // std::cout << "HcalDigitizer: theUpgradeCoderFactory created" << std::endl;
192 
199  theHFQIE10ElectronicsSim = new HcalElectronicsSim(theHFAmplifier, theUpgradeCoderFactory, PreMix1); //should this use a different coder factory?
200 
201 // std::cout << "HcalDigitizer: theUpgradeElectronicsSim created" << std::endl;
202 
203  // a code of 1 means make all cells SiPM
204  std::vector<int> hbSiPMCells(ps.getParameter<edm::ParameterSet>("hb").getParameter<std::vector<int> >("siPMCells"));
205  //std::vector<int> hoSiPMCells(ps.getParameter<edm::ParameterSet>("ho").getParameter<std::vector<int> >("siPMCells"));
206  // 0 means none, 1 means all, and 2 means use hardcoded
207 
208 // std::cout << std::endl << " hbSiPMCells = " << hbSiPMCells.size() << std::endl;
209 
210  bool doHBHEHPD = hbSiPMCells.empty() || (hbSiPMCells[0] != 1);
211  bool doHOHPD = (theHOSiPMCode != 1);
212  bool doHBHESiPM = !hbSiPMCells.empty();
213  bool doHOSiPM = (theHOSiPMCode != 0);
214  if(doHBHEHPD) {
216  edm::LogInfo("HcalDigitizer") <<"Set scale for HB towers";
218 
221  bool changeResponse = ps.getParameter<bool>("ChangeResponse");
222  edm::FileInPath fname = ps.getParameter<edm::FileInPath>("CorrFactorFile");
223  if (changeResponse) {
224  std::string corrFileName = fname.fullPath();
225  edm::LogInfo("HcalDigitizer") << "Set scale for HB towers from " << corrFileName;
226  theHBHEResponse->setHBHEScale(corrFileName); //GMA
227  }
228  }
229  if(doHOHPD) {
233  }
234 
235  if(doHBHESiPM) {
238  if (doHBHEUpgrade) {
240 
241 // std::cout << "HcalDigitizer: theHBHEUpgradeDigitizer created" << std::endl;
242 
243  } else {
245  }
246  }
247  if(doHOSiPM) {
251  }
252 
253  // if both are present, fill the SiPM cells now
254  if(doHBHEHPD && doHBHESiPM) {
255 
256 // std::cout << "HcalDigitizer: fill the SiPM cells now" << std::endl;
257 
259  }
260 
264 
265  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
266  //initialize: they won't be called later if flag is set
267  theTimeSlewSim = 0;
268  if(doTimeSlew) {
269  // no time slewing for HF
270  theTimeSlewSim = new HcalTimeSlewSim(theParameterMap,minFCToDelay);
271  theHBHEAmplifier->setTimeSlewSim(theTimeSlewSim);
272  theHOAmplifier->setTimeSlewSim(theTimeSlewSim);
273  theZDCAmplifier->setTimeSlewSim(theTimeSlewSim);
274  }
275 
276  if (doHFQIE10 || doHFQIE8) { //QIE8 and QIE10 can coexist in HF
278  if(doHFQIE8) theHFDigitizer = new HFDigitizer(theHFResponse, theHFElectronicsSim, doEmpty);
279  }
280  else if (doHFUpgrade) {
282 
283 // std::cout << "HcalDigitizer: theHFUpgradeDigitizer created" << std::endl;
284 
285  } else {
287  }
289 
290  edm::ParameterSet ps0 = ps.getParameter<edm::ParameterSet>("HcalReLabel");
291  relabel_ = ps0.getUntrackedParameter<bool>("RelabelHits");
292 // std::cout << "Flag to see if Hit Relabeller to be initiated " << relabel_ << std::endl;
293  if (relabel_) {
295  }
296 
297  bool doHPDNoise = ps.getParameter<bool>("doHPDNoise");
298  if(doHPDNoise) {
299  //edm::ParameterSet hpdNoisePset = ps.getParameter<edm::ParameterSet>("HPDNoiseLibrary");
303  }
304 
305  if(ps.getParameter<bool>("doIonFeedback") && theHBHEResponse) {
308  if(ps.getParameter<bool>("doThermalNoise")) {
310  }
311  }
312 
313  if(ps.getParameter<bool>("injectTestHits") ) {
321 
322 // std::cout << "HcalDigitizer: theHBHEUpgradeDigitizer setNoise" << std::endl;
323  }
325  if(theHFUpgradeDigitizer) {
327 
328 // std::cout << "HcalDigitizer: theHFUpgradeDigitizer setNoise" << std::endl;
329  }
332  }
333 
334  if(agingFlagHE) m_HEDarkening = new HEDarkening();
335  if(agingFlagHF) m_HFRecalibration = new HFRecalibration();
336 }
337 
338 
342  if(theHODigitizer) delete theHODigitizer;
344  if(theHFDigitizer) delete theHFDigitizer;
345  delete theZDCDigitizer;
348  delete theParameterMap;
349  delete theHBHEResponse;
350  delete theHBHESiPMResponse;
351  delete theHOResponse;
352  delete theHOSiPMResponse;
353  delete theHFResponse;
354  delete theHFQIE10Response;
355  delete theZDCResponse;
356  delete theHBHEElectronicsSim;
357  delete theHFElectronicsSim;
358  delete theHOElectronicsSim;
359  delete theZDCElectronicsSim;
362  delete theHBHEAmplifier;
363  delete theHFAmplifier;
364  delete theHOAmplifier;
365  delete theZDCAmplifier;
366  delete theCoderFactory;
367  delete theUpgradeCoderFactory;
368  delete theHitCorrection;
369  delete theNoiseGenerator;
370  if (theRelabeller) delete theRelabeller;
371 }
372 
373 
375  noiseGenerator->setParameterMap(theParameterMap);
376  noiseGenerator->setElectronicsSim(theHBHEElectronicsSim);
378  theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
379 }
380 
382  noiseGenerator->setParameterMap(theParameterMap);
383  noiseGenerator->setElectronicsSim(theHFElectronicsSim);
387  theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
388 }
389 
391  noiseGenerator->setParameterMap(theParameterMap);
392  noiseGenerator->setElectronicsSim(theHOElectronicsSim);
395  theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
396 }
397 
399  noiseGenerator->setParameterMap(theParameterMap);
400  noiseGenerator->setElectronicsSim(theZDCElectronicsSim);
401  theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
402  theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
403 }
404 
406  // get the appropriate gains, noises, & widths for this event
407  edm::ESHandle<HcalDbService> conditions;
408  eventSetup.get<HcalDbRecord>().get(conditions);
409  theHBHEAmplifier->setDbService(conditions.product());
410  theHFAmplifier->setDbService(conditions.product());
411  theHOAmplifier->setDbService(conditions.product());
412  theZDCAmplifier->setDbService(conditions.product());
416 
417  theCoderFactory->setDbService(conditions.product());
419  theParameterMap->setDbService(conditions.product());
420 
422  if (eventSetup.find(edm::eventsetup::EventSetupRecordKey::makeKey<HcalCholeskyMatricesRcd>())) {
423  eventSetup.get<HcalCholeskyMatricesRcd>().get(refCholesky);
424  const HcalCholeskyMatrices * myCholesky = refCholesky.product();
425  theHBHEAmplifier->setCholesky(myCholesky);
426  theHFAmplifier->setCholesky(myCholesky);
427  theHOAmplifier->setCholesky(myCholesky);
428  }
429  edm::ESHandle<HcalPedestals> pedshandle;
430  eventSetup.get<HcalPedestalsRcd>().get(pedshandle);
431  const HcalPedestals * myADCPedestals = pedshandle.product();
432 
433  theHBHEAmplifier->setADCPeds(myADCPedestals);
434  theHFAmplifier->setADCPeds(myADCPedestals);
435  theHOAmplifier->setADCPeds(myADCPedestals);
436 
437  if(theHitCorrection != 0) {
439  }
440 
441  //initialize hits
451 
452 }
453 
454 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) {
455 
456  // Step A: pass in inputs, and accumulate digirs
457  if(isHCAL) {
458  std::vector<PCaloHit> hcalHitsOrig = *hcalHandle.product();
459  std::vector<PCaloHit> hcalHits;
460  hcalHits.reserve(hcalHitsOrig.size());
461 
462  //evaluate darkening before relabeling
464  darkening(hcalHitsOrig);
465  }
466  // Relabel PCaloHits if necessary
467  if (relabel_) {
468  edm::LogInfo("HcalDigitizer") << "Calling Relabeller";
469  theRelabeller->process(hcalHitsOrig);
470  }
471 
472  //eliminate bad hits
473  for (unsigned int i=0; i< hcalHitsOrig.size(); i++) {
474  DetId id(hcalHitsOrig[i].id());
475  HcalDetId hid(id);
476  if (!htopoP->validHcal(hid)) {
477  edm::LogError("HcalDigitizer") << "bad hcal id found in digitizer. Skipping " << id.rawId() << " " << hid << std::endl;
478  } else {
479 #ifdef DebugLog
480  std::cout << "HcalDigitizer format " << hid.oldFormat() << " for " << hid << std::endl;
481 #endif
482  DetId newid = DetId(hid.newForm());
483 #ifdef DebugLog
484  std::cout << "Hit " << i << " out of " << hcalHits.size() << " " << std::hex << id.rawId() << " --> " << newid.rawId() << std::dec << " " << HcalDetId(newid.rawId()) << '\n';
485 #endif
486  hcalHitsOrig[i].setID(newid.rawId());
487  hcalHits.push_back(hcalHitsOrig[i]);
488  }
489  }
490 
491  if(theHitCorrection != 0) {
492  theHitCorrection->fillChargeSums(hcalHits);
493  }
494  if(hbhegeo) {
495  if(theHBHEDigitizer) theHBHEDigitizer->add(hcalHits, bunchCrossing, engine);
496  if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->add(hcalHits, bunchCrossing, engine);
498  theHBHEUpgradeDigitizer->add(hcalHits, bunchCrossing, engine);
499  }
500  }
501 
502  if(hogeo) {
503  if(theHODigitizer) theHODigitizer->add(hcalHits, bunchCrossing, engine);
504  if(theHOSiPMDigitizer) theHOSiPMDigitizer->add(hcalHits, bunchCrossing, engine);
505  }
506 
507  if(hfgeo) {
508  if(theHFDigitizer) theHFDigitizer->add(hcalHits, bunchCrossing, engine);
509  if(theHFUpgradeDigitizer) theHFUpgradeDigitizer->add(hcalHits, bunchCrossing, engine);
510  if(theHFQIE10Digitizer) theHFQIE10Digitizer->add(hcalHits, bunchCrossing, engine);
511  }
512  } else {
513  edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
514  }
515 
516  if(isZDC) {
517  if(zdcgeo) {
518  theZDCDigitizer->add(*zdcHandle.product(), bunchCrossing, engine);
519  }
520  } else {
521  edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
522  }
523 }
524 
525 void HcalDigitizer::accumulate(edm::Event const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
526  // Step A: Get Inputs
527  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
529  e.getByLabel(zdcTag, zdcHandle);
530  isZDC = zdcHandle.isValid();
531 
532  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
534  e.getByLabel(hcalTag, hcalHandle);
535  isHCAL = hcalHandle.isValid();
536 
538  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
539  const HcalTopology *htopoP=htopo.product();
540 
541  accumulateCaloHits(hcalHandle, zdcHandle, 0, engine, htopoP);
542 }
543 
544 void HcalDigitizer::accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
545  // Step A: Get Inputs
546  edm::InputTag zdcTag(hitsProducer_, "ZDCHITS");
548  e.getByLabel(zdcTag, zdcHandle);
549  isZDC = zdcHandle.isValid();
550 
551  edm::InputTag hcalTag(hitsProducer_, "HcalHits");
553  e.getByLabel(hcalTag, hcalHandle);
554  isHCAL = hcalHandle.isValid();
555 
557  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
558  const HcalTopology *htopoP=htopo.product();
559 
560  accumulateCaloHits(hcalHandle, zdcHandle, e.bunchCrossing(), engine, htopoP);
561 }
562 
563 void HcalDigitizer::finalizeEvent(edm::Event& e, const edm::EventSetup& eventSetup, CLHEP::HepRandomEngine* engine) {
564 
565  // Step B: Create empty output
566  std::auto_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
567  std::auto_ptr<HODigiCollection> hoResult(new HODigiCollection());
568  std::auto_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
569  std::auto_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
570  std::auto_ptr<HBHEUpgradeDigiCollection> hbheupgradeResult(new HBHEUpgradeDigiCollection());
571  std::auto_ptr<HFUpgradeDigiCollection> hfupgradeResult(new HFUpgradeDigiCollection());
572  std::auto_ptr<QIE10DigiCollection> hfQIE10Result(new QIE10DigiCollection());
573 
574  // Step C: Invoke the algorithm, getting back outputs.
575  if(isHCAL&&hbhegeo){
576  if(theHBHEDigitizer) theHBHEDigitizer->run(*hbheResult, engine);
577  if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->run(*hbheResult, engine);
579  theHBHEUpgradeDigitizer->run(*hbheupgradeResult, engine);
580 #ifdef DebugLog
581  std::cout << "HcalDigitizer::finalizeEvent theHBHEUpgradeDigitizer->run" << std::endl;
582 #endif
583  }
584  }
585  if(isHCAL&&hogeo) {
586  if(theHODigitizer) theHODigitizer->run(*hoResult, engine);
587  if(theHOSiPMDigitizer) theHOSiPMDigitizer->run(*hoResult, engine);
588  }
589  if(isHCAL&&hfgeo) {
590  if(theHFDigitizer) theHFDigitizer->run(*hfResult, engine);
591  if(theHFUpgradeDigitizer) theHFUpgradeDigitizer->run(*hfupgradeResult, engine);
592  if(theHFQIE10Digitizer) theHFQIE10Digitizer->run(*hfQIE10Result, engine);
593  }
594  if(isZDC&&zdcgeo) {
595  theZDCDigitizer->run(*zdcResult, engine);
596  }
597 
598  edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
599  edm::LogInfo("HcalDigitizer") << "HCAL HO digis : " << hoResult->size();
600  edm::LogInfo("HcalDigitizer") << "HCAL HF digis : " << hfResult->size();
601  edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis : " << zdcResult->size();
602  edm::LogInfo("HcalDigitizer") << "HCAL HBHE upgrade digis : " << hbheupgradeResult->size();
603  edm::LogInfo("HcalDigitizer") << "HCAL HF upgrade digis : " << hfupgradeResult->size();
604  edm::LogInfo("HcalDigitizer") << "HCAL HF QIE10 digis : " << hfQIE10Result->size();
605 
606 #ifdef DebugLog
607  std::cout << std::endl;
608  std::cout << "HCAL HBHE digis : " << hbheResult->size() << std::endl;
609  std::cout << "HCAL HO digis : " << hoResult->size() << std::endl;
610  std::cout << "HCAL HF digis : " << hfResult->size() << std::endl;
611 
612  std::cout << "HCAL HBHE upgrade digis : " << hbheupgradeResult->size()
613  << std::endl;
614  std::cout << "HCAL HF upgrade digis : " << hfupgradeResult->size()
615  << std::endl;
616 #endif
617 
618  // Step D: Put outputs into event
619  e.put(hbheResult);
620  e.put(hoResult);
621  e.put(hfResult);
622  e.put(zdcResult);
623  e.put(hbheupgradeResult,"HBHEUpgradeDigiCollection");
624  e.put(hfupgradeResult, "HFUpgradeDigiCollection");
625  e.put(hfQIE10Result, "HFQIE10DigiCollection");
626 
627 #ifdef DebugLog
628  std::cout << std::endl << "========> HcalDigitizer e.put " << std::endl << std::endl;
629 #endif
630 
631  if(theHitCorrection) {
633  }
634 }
635 
636 
638  checkGeometry(es);
639  theShapes->beginRun(es);
640 }
641 
642 
644  theShapes->endRun();
645 }
646 
647 
649  // TODO find a way to avoid doing this every event
651  eventSetup.get<CaloGeometryRecord>().get(geometry);
653  eventSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
654 
655  // See if it's been updated
656  if (&*geometry != theGeometry) {
657  theGeometry = &*geometry;
658  theRecNumber= &*pHRNDC;
659  updateGeometry(eventSetup);
660  }
661 }
662 
663 
673 
674  const std::vector<DetId>& hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
675  const std::vector<DetId>& heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
676  const std::vector<DetId>& hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
677  const std::vector<DetId>& hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
678  const std::vector<DetId>& zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
679  //const std::vector<DetId>& hcalTrigCells = geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower);
680  //const std::vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
681 // std::cout<<"HcalDigitizer::CheckGeometry number of cells: "<<zdcCells.size()<<std::endl;
682  if(zdcCells.empty()) zdcgeo = false;
683  if(hbCells.empty() && heCells.empty()) hbhegeo = false;
684  if(hoCells.empty()) hogeo = false;
685  if(hfCells.empty()) hfgeo = false;
686  // combine HB & HE
687 
688  theHBHEDetIds = hbCells;
689  theHBHEDetIds.insert(theHBHEDetIds.end(), heCells.begin(), heCells.end());
690 
692  //HcalDigitizerImpl::fillCells(hoCells, theHODigitizer, theHOSiPMDigitizer);
693  buildHOSiPMCells(hoCells, eventSetup);
694  //handle mixed QIE8/10 scenario in HF
695  if(theHFDigitizer && theHFQIE10Digitizer) buildHFQIECells(hfCells,eventSetup);
696  else if(theHFDigitizer) theHFDigitizer->setDetIds(hfCells);
699  theZDCDigitizer->setDetIds(zdcCells);
702 #ifdef DebugLog
703  std::cout << " HcalDigitizer::updateGeometry theHBHEUpgradeDigitizer->setDetIds(theHBHEDetIds)"<< std::endl;
704 #endif
705  }
706 
707 }
708 
709 void HcalDigitizer::buildHFQIECells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
710  //if results are already cached, no need to look again
711  if(theHFQIE8DetIds.size()>0 || theHFQIE10DetIds.size()>0) return;
712 
713  //get the QIETypes
715  eventSetup.get<HcalQIETypesRcd>().get(q);
717  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
718 
719  HcalQIETypes qieTypes(*q.product());
720  if (qieTypes.topo()==0) {
721  qieTypes.setTopo(htopo.product());
722  }
723 
724  for(std::vector<DetId>::const_iterator detItr = allCells.begin(); detItr != allCells.end(); ++detItr) {
725  HcalQIENum qieType = HcalQIENum(qieTypes.getValues(*detItr)->getValue());
726  if(qieType == QIE8) {
727  theHFQIE8DetIds.push_back(*detItr);
728  } else if(qieType == QIE10) {
729  theHFQIE10DetIds.push_back(*detItr);
730  } else { //default is QIE8
731  theHFQIE8DetIds.push_back(*detItr);
732  }
733  }
734 
736  else {
737  delete theHFDigitizer;
739  }
740 
742  else {
743  delete theHFQIE10Digitizer;
745  }
746 }
747 
748 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup) {
749  // all HPD
750 
751  if(theHOSiPMCode == 0) {
752  theHODigitizer->setDetIds(allCells);
753  } else if(theHOSiPMCode == 1) {
754  theHOSiPMDigitizer->setDetIds(allCells);
755  // FIXME pick Zecotek or hamamatsu?
756  } else if(theHOSiPMCode == 2) {
757  std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
759  eventSetup.get<HcalMCParamsRcd>().get(p);
761  eventSetup.get<HcalRecNumberingRecord>().get(htopo);
762 
763  HcalMCParams mcParams(*p.product());
764  if (mcParams.topo()==0) {
765  mcParams.setTopo(htopo.product());
766  }
767 
768  for(std::vector<DetId>::const_iterator detItr = allCells.begin();
769  detItr != allCells.end(); ++detItr) {
770  int shapeType = mcParams.getValues(*detItr)->signalShape();
771  if(shapeType == HcalShapes::ZECOTEK) {
772  zecotekDetIds.emplace_back(*detItr);
773  theHOSiPMDetIds.push_back(*detItr);
774  } else if(shapeType == HcalShapes::HAMAMATSU) {
775  hamamatsuDetIds.emplace_back(*detItr);
776  theHOSiPMDetIds.push_back(*detItr);
777  } else {
778  theHOHPDDetIds.push_back(*detItr);
779  }
780  }
781 
787  // FIXME not applying a HitFilter to the HPDs, for now
788  theParameterMap->setHOZecotekDetIds(zecotekDetIds);
789  theParameterMap->setHOHamamatsuDetIds(hamamatsuDetIds);
790 
791  // make sure we don't got through this exercise again
792  theHOSiPMCode = -2;
793  }
794 }
795 
796 void HcalDigitizer::darkening(std::vector<PCaloHit>& hcalHits) {
797 
798  for (unsigned int ii=0; ii<hcalHits.size(); ++ii) {
799  uint32_t tmpId = hcalHits[ii].id();
800  int det, z, depth, ieta, phi, lay;
801  HcalTestNumbering::unpackHcalIndex(tmpId,det,z,depth,ieta,phi,lay);
802 
803  bool darkened = false;
804  float dweight = 1.;
805 
806  if(det==int(HcalEndcap) && m_HEDarkening){
807  //HE darkening
808  dweight = m_HEDarkening->degradation(deliveredLumi,ieta,lay-2);//NB:diff. layer count
809  darkened = true;
810  } else if(det==int(HcalForward) && m_HFRecalibration){
811  //HF darkening - approximate: invert recalibration factor
812  dweight = 1.0/m_HFRecalibration->getCorr(ieta,depth,deliveredLumi);
813  darkened = true;
814  }
815 
816  //create new hit with darkened energy
817  //if(darkened) hcalHits[ii] = PCaloHit(hcalHits[ii].energyEM()*dweight,hcalHits[ii].energyHad()*dweight,hcalHits[ii].time(),hcalHits[ii].geantTrackId(),hcalHits[ii].id());
818 
819  //reset hit energy
820  if(darkened) hcalHits[ii].setEnergy(hcalHits[ii].energy()*dweight);
821  }
822 
823 }
824 
825 
std::vector< DetId > theHFQIE10DetIds
void setUseOldHB(bool useOld)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setHOtuningParameter(double tp)
QIE10Digitizer * theHFQIE10Digitizer
T getParameter(std::string const &) const
void setNoiseHitGenerator(CaloVNoiseHitGenerator *generator)
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
CaloHitResponse * theHFQIE10Response
Definition: HcalDigitizer.h:99
void setGeometry(const CaloGeometry *&, const HcalDDDRecConstants *&)
const HcalDDDRecConstants * theRecNumber
Definition: HcalDigitizer.h:74
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
void setParameterMap(HcalSimParameterMap *map)
void setDetIds(const std::vector< DetId > &detIds)
virtual ~HcalDigitizer()
HcalElectronicsSim * theHFElectronicsSim
void buildHFQIECells(const std::vector< DetId > &allCells, const edm::EventSetup &eventSetup)
Definition: HcalQIENum.h:4
HBHEDigitizer * theHBHEDigitizer
HOHitFilter theHOHitFilter
assert(m_qm.get())
CaloTDigitizer< HcalUpgradeDigitizerTraits > UpgradeDigitizer
Definition: HcalDigitizer.h:88
void setUseOldHF(bool useOld)
void darkening(std::vector< PCaloHit > &hcalHits)
#define NULL
Definition: scimark2.h:8
HFDigitizer * theHFDigitizer
HFHitFilter theHFHitFilter
void checkGeometry(const edm::EventSetup &eventSetup)
HcalSimParameterMap * theParameterMap
Definition: HcalDigitizer.h:91
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
HcalDataFrameContainer< QIE10DataFrame > QIE10DigiCollection
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:86
void setHOZecotekDetIds(const std::vector< HcalDetId > &ids)
HcalAmplifier * theHBHEAmplifier
void setUseOldHO(bool useOld)
edm::SortedCollection< HODataFrame > HODigiCollection
CaloTDigitizer< ZDCDigitizerTraits > ZDCDigitizer
Definition: HcalDigitizer.h:87
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:92
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)
void initializeHits()
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:96
HcalHitFilter theHOSiPMHitFilter
CaloHitResponse * theHOSiPMResponse
Definition: HcalDigitizer.h:97
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
void setHBHEScale(std::string &)
HcalQIENum
Definition: HcalQIENum.h:4
ZDCDigitizer * theZDCDigitizer
edm::SortedCollection< HcalUpgradeDataFrame > HFUpgradeDigiCollection
void setNoiseSignalGenerator(CaloVNoiseSignalGenerator *generator)
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
void endRun()
Definition: HcalShapes.cc:118
void setNoiseSignalGenerator(const CaloVNoiseSignalGenerator *noiseSignalGenerator)
Definition: HcalAmplifier.h:35
Definition: DetId.h:18
HcalElectronicsSim * theZDCElectronicsSim
HcalElectronicsSim * theUpgradeHBHEElectronicsSim
static const int SubdetectorId
Definition: HcalZDCDetId.h:20
void beginRun(const edm::EventSetup &es)
CaloTDigitizer< HcalQIE10DigitizerTraits, CaloTDigitizerQIE10Run > QIE10Digitizer
Definition: HcalDigitizer.h:89
void process(std::vector< PCaloHit > &hcalHits)
CaloTDigitizer< HODigitizerTraits > HODigitizer
Definition: HcalDigitizer.h:85
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
std::vector< DetId > theHFQIE8DetIds
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 run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
void fillCells(std::vector< DetId > &allCells, HPDDIGITIZER *hpdDigitizer, SIPMDIGITIZER *siPMDigitizer)
CaloHitResponse * theHBHEResponse
Definition: HcalDigitizer.h:94
HODigitizer * theHODigitizer
std::vector< DetId > theHOSiPMDetIds
const CaloGeometry * theGeometry
Definition: HcalDigitizer.h:73
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:98
HcalElectronicsSim * theHFQIE10ElectronicsSim
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 beginRun(edm::EventSetup const &es)
Definition: HcalShapes.cc:103
CaloHitResponse * theHBHESiPMResponse
Definition: HcalDigitizer.h:95
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)
void setDetIds(const std::vector< DetId > &detIds)
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:84
HcalDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
CaloVNoiseSignalGenerator * theNoiseGenerator