CMS 3D CMS Logo

HGCDigitizer.cc
Go to the documentation of this file.
19 
20 #include <algorithm>
21 #include <boost/foreach.hpp>
23 
24 //#define EDM_ML_DEBUG
25 
26 using namespace hgc_digi;
27 
28 namespace {
29 
30  constexpr std::array<double,4> occupancyGuesses = { { 0.5,0.2,0.2,0.8 } };
31 
32 
33  float getPositionDistance(const HGCalGeometry* geom, const DetId& id) {
34  return geom->getPosition(id).mag();
35  }
36 
37  float getPositionDistance(const HcalGeometry* geom, const DetId& id) {
38  return geom->getGeometry(id)->getPosition().mag();
39  }
40 
41  int getCellThickness(const HGCalGeometry* geom, const DetId& detid ) {
42  const auto& dddConst = geom->topology().dddConstants();
43  return dddConst.waferType(detid);
44  }
45 
46  int getCellThickness(const HcalGeometry* geom, const DetId& detid ) {
47  return 1;
48  }
49 
50  void getValidDetIds(const HGCalGeometry* geom, std::unordered_set<DetId>& valid) {
51  const std::vector<DetId>& ids = geom->getValidDetIds();
52  valid.reserve(ids.size());
53  valid.insert(ids.begin(),ids.end());
54  }
55 
56  void getValidDetIds(const HcalGeometry* geom, std::unordered_set<DetId>& valid) {
57  const std::vector<DetId>& ids = geom->getValidDetIds();
58  for( const auto& id : ids ) {
59  if( HcalEndcap == id.subdetId() &&
60  DetId::Hcal == id.det() )
61  valid.emplace(id);
62  }
63  valid.reserve(valid.size());
64  }
65 
66  DetId simToReco(const HcalGeometry* geom, unsigned simid) {
67  DetId result(0);
68  const auto& topo = geom->topology();
69  const auto* dddConst = topo.dddConstants();
70  HcalDetId id = HcalHitRelabeller::relabel(simid,dddConst);
71 
72  if (id.subdet()==int(HcalEndcap)) {
73  result = id;
74  }
75 
76  return result;
77  }
78 
79  DetId simToReco(const HGCalGeometry* geom, unsigned simId) {
80  DetId result(0);
81  const auto& topo = geom->topology();
82  const auto& dddConst = topo.dddConstants();
83 
84  if ((dddConst.geomMode() == HGCalGeometryMode::Hexagon8) ||
85  (dddConst.geomMode() == HGCalGeometryMode::Hexagon8Full) ||
86  (dddConst.geomMode() == HGCalGeometryMode::Trapezoid)) {
87  result = DetId(simId);
88  } else {
89  int subdet(DetId(simId).subdetId()), layer, cell, sec, subsec, zp;
90  HGCalTestNumbering::unpackHexagonIndex(simId, subdet, zp, layer, sec, subsec, cell);
91  //sec is wafer and subsec is celltyp
92  //skip this hit if after ganging it is not valid
93  auto recoLayerCell = dddConst.simToReco(cell,layer,sec,topo.detectorType());
94  cell = recoLayerCell.first;
95  layer = recoLayerCell.second;
96  if (layer<0 || cell<0) {
97  return result;
98  } else {
99  //assign the RECO DetId
100  result = HGCalDetId((ForwardSubdetector)subdet,zp,layer,subsec,sec,cell);
101  }
102  }
103  return result;
104  }
105 
106  float getCCE(const HGCalGeometry* geom,
107  const DetId& detid,
108  const std::vector<float>&cces) {
109  if ( cces.empty() ) return 1.f;
110  if ((detid.det() == DetId::Hcal) || (detid.det() == DetId::HGCalHSc)) {
111  return 1.f;
112  } else {
113  const auto& topo = geom->topology();
114  const auto& dddConst = topo.dddConstants();
115  int waferTypeL = dddConst.waferType(detid);
116  return cces[waferTypeL-1];
117  }
118  }
119 
120  float getCCE(const HcalGeometry* geom,
121  const DetId& id,
122  const std::vector<float>&cces) {
123  return 1.f;
124  }
125 
126  // Dumps the internals of the SimHit accumulator to the digis for premixing
127  void saveSimHitAccumulator(PHGCSimAccumulator& simResult, const hgc::HGCSimHitDataAccumulator& simData, const std::unordered_set<DetId>& validIds, const float minCharge, const float maxCharge) {
128  constexpr auto nEnergies = std::tuple_size<decltype(hgc_digi::HGCCellInfo().hit_info)>::value;
129  static_assert(nEnergies <= PHGCSimAccumulator::Data::energyMask+1, "PHGCSimAccumulator bit pattern needs to updated");
130  static_assert(hgc_digi::nSamples <= PHGCSimAccumulator::Data::sampleMask+1, "PHGCSimAccumulator bit pattern needs to updated");
131 
132  const float minPackChargeLog = minCharge > 0.f ? std::log(minCharge) : -2;
133  const float maxPackChargeLog = std::log(maxCharge);
135 
136  simResult.reserve(simData.size());
137  // mimicing the digitization
138  for(const auto& id: validIds) {
139  auto found = simData.find(id);
140  if(found == simData.end())
141  continue;
142  // store only non-zero
143  for(size_t iEn = 0; iEn < nEnergies; ++iEn) {
144  const auto& samples = found->second.hit_info[iEn];
145  for(size_t iSample = 0; iSample < hgc_digi::nSamples; ++iSample) {
146  if(samples[iSample] > minCharge) {
147  const auto packed = logintpack::pack16log(samples[iSample], minPackChargeLog, maxPackChargeLog, base);
148  simResult.emplace_back(id.rawId(), iEn, iSample, packed);
149  }
150  }
151  }
152  }
153  simResult.shrink_to_fit();
154  }
155 
156  // Loads the internals of the SimHit accumulator from the digis for premixing
157  void loadSimHitAccumulator(hgc::HGCSimHitDataAccumulator& simData, const PHGCSimAccumulator& simAccumulator, const float minCharge, const float maxCharge, bool setIfZero) {
158  const float minPackChargeLog = minCharge > 0.f ? std::log(minCharge) : -2;
159  const float maxPackChargeLog = std::log(maxCharge);
161 
162  for(const auto& detIdIndexHitInfo: simAccumulator) {
163  auto simIt = simData.emplace(detIdIndexHitInfo.detId(), HGCCellInfo()).first;
164  auto& hit_info = simIt->second.hit_info;
165 
166  size_t iEn = detIdIndexHitInfo.energyIndex();
167  size_t iSample = detIdIndexHitInfo.sampleIndex();
168 
169  float value = logintpack::unpack16log(detIdIndexHitInfo.data(), minPackChargeLog, maxPackChargeLog, base);
170 
171  if(iEn == 0 || !setIfZero) {
172  hit_info[iEn][iSample] += value;
173  }
174  else if(hit_info[iEn][iSample] == 0) {
175  hit_info[iEn][iSample] = value;
176  }
177  }
178  }
179 }
180 
181 //
184  simHitAccumulator_( new HGCSimHitDataAccumulator() ),
185  myDet_(DetId::Forward),
186  mySubDet_(ForwardSubdetector::ForwardEmpty),
187  refSpeed_(0.1*CLHEP::c_light), //[CLHEP::c_light]=mm/ns convert to cm/ns
188  averageOccupancies_(occupancyGuesses),
189  nEvents_(1)
190 {
191  //configure from cfg
192  hitCollection_ = ps.getParameter< std::string >("hitCollection");
193  digiCollection_ = ps.getParameter< std::string >("digiCollection");
194  maxSimHitsAccTime_ = ps.getParameter< uint32_t >("maxSimHitsAccTime");
195  bxTime_ = ps.getParameter< double >("bxTime");
196  geometryType_ = ps.getParameter< uint32_t >("geometryType");
197  digitizationType_ = ps.getParameter< uint32_t >("digitizationType");
198  verbosity_ = ps.getUntrackedParameter< uint32_t >("verbosity",0);
199  tofDelay_ = ps.getParameter< double >("tofDelay");
200  premixStage1_ = ps.getParameter<bool>("premixStage1");
201  premixStage1MinCharge_ = ps.getParameter<double>("premixStage1MinCharge");
202  premixStage1MaxCharge_ = ps.getParameter<double>("premixStage1MaxCharge");
203 
204  std::unordered_set<DetId>().swap(validIds_);
205 
206  iC.consumes<std::vector<PCaloHit> >(edm::InputTag("g4SimHits",hitCollection_));
207  const auto& myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg");
208 
209  if( myCfg_.existsAs<edm::ParameterSet>("chargeCollectionEfficiencies")) {
210  cce_.clear();
211  const auto& temp = myCfg_.getParameter<edm::ParameterSet>("chargeCollectionEfficiencies").getParameter<std::vector<double>>("values");
212  for( double cce : temp ) {
213  cce_.emplace_back(cce);
214  }
215  } else {
216  std::vector<float>().swap(cce_);
217  }
218 
219  if(hitCollection_.find("HitsEE")!=std::string::npos) {
220  if (geometryType_ == 0) {
222  } else {
224  }
225  theHGCEEDigitizer_=std::make_unique<HGCEEDigitizer>(ps);
226  }
227  if(hitCollection_.find("HitsHEfront")!=std::string::npos) {
228  if (geometryType_ == 0) {
230  } else {
232  }
233  theHGCHEfrontDigitizer_=std::make_unique<HGCHEfrontDigitizer>(ps);
234  }
235  if(hitCollection_.find("HcalHits")!=std::string::npos and geometryType_ == 0) {
237  theHGCHEbackDigitizer_=std::make_unique<HGCHEbackDigitizer>(ps);
238  }
239  if(hitCollection_.find("HitsHEback")!=std::string::npos and geometryType_ == 1) {
241  theHGCHEbackDigitizer_=std::make_unique<HGCHEbackDigitizer>(ps);
242  }
243  if(hitCollection_.find("HFNoseHits")!=std::string::npos) {
246  theHFNoseDigitizer_=std::make_unique<HFNoseDigitizer>(ps);
247  }
248 }
249 
250 //
252 {
253  // reserve memory for a full detector
254  unsigned idx = getType();
255  simHitAccumulator_->reserve( averageOccupancies_[idx]*validIds_.size() );
256 }
257 
258 //
259 void HGCDigitizer::finalizeEvent(edm::Event& e, edm::EventSetup const& es, CLHEP::HepRandomEngine* hre)
260 {
261  hitRefs_bx0.clear();
262 
263  const CaloSubdetectorGeometry* theGeom = ( nullptr == gHGCal_ ?
264  static_cast<const CaloSubdetectorGeometry*>(gHcal_) :
265  static_cast<const CaloSubdetectorGeometry*>(gHGCal_) );
266 
267  ++nEvents_;
268  unsigned idx = getType();
269  // release memory for unfilled parts of hash table
270  if( validIds_.size()*averageOccupancies_[idx] > simHitAccumulator_->size() ) {
271  simHitAccumulator_->reserve(simHitAccumulator_->size());
272  }
273  //update occupancy guess
274  const double thisOcc = simHitAccumulator_->size()/((double)validIds_.size());
276 
277  if(premixStage1_) {
278  std::unique_ptr<PHGCSimAccumulator> simResult;
279  if(!simHitAccumulator_->empty()) {
280  simResult = std::make_unique<PHGCSimAccumulator>();
281  saveSimHitAccumulator(*simResult, *simHitAccumulator_, validIds_, premixStage1MinCharge_, premixStage1MaxCharge_);
282  }
283  e.put(std::move(simResult), digiCollection());
284  } else {
285  if( producesEEDigis() ) {
286  auto digiResult = std::make_unique<HGCalDigiCollection>();
287  theHGCEEDigitizer_->run(digiResult,*simHitAccumulator_,theGeom,validIds_,digitizationType_, hre);
288  edm::LogInfo("HGCDigitizer") << " @ finalize event - produced "
289  << digiResult->size() << " EE hits";
290 #ifdef EDM_ML_DEBUG
291  checkPosition(&(*digiResult));
292 #endif
293  e.put(std::move(digiResult),digiCollection());
294  }
295  if( producesHEfrontDigis()) {
296  auto digiResult = std::make_unique<HGCalDigiCollection>();
298  edm::LogInfo("HGCDigitizer") << " @ finalize event - produced "
299  << digiResult->size() << " HE front hits";
300 #ifdef EDM_ML_DEBUG
301  checkPosition(&(*digiResult));
302 #endif
303  e.put(std::move(digiResult),digiCollection());
304  }
305  if( producesHEbackDigis() ) {
306  auto digiResult = std::make_unique<HGCalDigiCollection>();
308  edm::LogInfo("HGCDigitizer") << " @ finalize event - produced "
309  << digiResult->size() << " HE back hits";
310 #ifdef EDM_ML_DEBUG
311  checkPosition(&(*digiResult));
312 #endif
313  e.put(std::move(digiResult),digiCollection());
314  }
315  if( producesHFNoseDigis() ) {
316  auto digiResult = std::make_unique<HGCalDigiCollection>();
317  theHFNoseDigitizer_->run(digiResult,*simHitAccumulator_,theGeom,
319  edm::LogInfo("HGCDigitizer") << " @ finalize event - produced "
320  << digiResult->size() << " HFNose hits";
321 #ifdef EDM_ML_DEBUG
322  checkPosition(&(*digiResult));
323 #endif
324  e.put(std::move(digiResult),digiCollection());
325  }
326  }
327 
329 }
330 
331 //
332 void HGCDigitizer::accumulate(edm::Event const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* hre) {
333 
334  //get inputs
336  e.getByLabel(edm::InputTag("g4SimHits",hitCollection_),hits);
337  if( !hits.isValid() ){
338  edm::LogError("HGCDigitizer") << " @ accumulate : can't find " << hitCollection_ << " collection of g4SimHits";
339  return;
340  }
341 
342  //accumulate in-time the main event
343  if( nullptr != gHGCal_ ) {
344  accumulate(hits, 0, gHGCal_, hre);
345  } else if( nullptr != gHcal_ ) {
346  accumulate(hits, 0, gHcal_, hre);
347  } else {
348  throw cms::Exception("BadConfiguration")
349  << "HGCDigitizer is not producing EE, FH, or BH digis!";
350  }
351 }
352 
353 //
354 void HGCDigitizer::accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* hre) {
355 
356  //get inputs
358  e.getByLabel(edm::InputTag("g4SimHits",hitCollection_),hits);
359  if( !hits.isValid() ){
360  edm::LogError("HGCDigitizer") << " @ accumulate : can't find " << hitCollection_ << " collection of g4SimHits";
361  return;
362  }
363 
364  //accumulate for the simulated bunch crossing
365  if( nullptr != gHGCal_ ) {
366  accumulate(hits, e.bunchCrossing(), gHGCal_, hre);
367  } else if ( nullptr != gHcal_ ) {
368  accumulate(hits, e.bunchCrossing(), gHcal_, hre);
369  } else {
370  throw cms::Exception("BadConfiguration")
371  << "HGCDigitizer is not producing EE, FH, or BH digis!";
372  }
373 }
374 
375 //
376 template<typename GEOM>
378  int bxCrossing,
379  const GEOM* geom,
380  CLHEP::HepRandomEngine* hre) {
381  if( nullptr == geom ) return;
382 
383 
384 
385  //configuration to apply for the computation of time-of-flight
386  std::array<float, 3> tdcForToAOnset{ {0.f, 0.f, 0.f} };
387  float keV2fC(0.f);
388  bool weightToAbyEnergy= getWeight(tdcForToAOnset, keV2fC);
389 
390  //create list of tuples (pos in container, RECO DetId, time) to be sorted first
391  int nchits=(int)hits->size();
392  std::vector< HGCCaloHitTuple_t > hitRefs;
393  hitRefs.reserve(nchits);
394  for(int i=0; i<nchits; ++i) {
395  const auto& the_hit = hits->at(i);
396 
397  DetId id = simToReco(geom,the_hit.id());
398 
399  if (verbosity_>0) {
400  if (producesEEDigis())
401  edm::LogInfo("HGCDigitizer") << " i/p " << std::hex << the_hit.id() << " o/p " << id.rawId() << std::dec << std::endl;
402  else
403  edm::LogInfo("HGCDigitizer") << " i/p " << std::hex << the_hit.id() << " o/p " << id.rawId() << std::dec << std::endl;
404  }
405 
406  if( 0 != id.rawId() ) {
407  hitRefs.emplace_back( i, id.rawId(), (float)the_hit.time() );
408  }
409  }
410  std::sort(hitRefs.begin(),hitRefs.end(),this->orderByDetIdThenTime);
411 
412  //loop over sorted hits
413  nchits = hitRefs.size();
414  for(int i=0; i<nchits; ++i) {
415  const int hitidx = std::get<0>(hitRefs[i]);
416  const uint32_t id = std::get<1>(hitRefs[i]);
417 
418  //get the data for this cell, if not available then we skip it
419 
420  if( !validIds_.count(id) ) continue;
421  HGCSimHitDataAccumulator::iterator simHitIt = simHitAccumulator_->emplace(id,HGCCellInfo()).first;
422 
423  if(id==0) continue; // to be ignored at RECO level
424 
425  const float toa = std::get<2>(hitRefs[i]);
426  const PCaloHit &hit=hits->at( hitidx );
427  const float charge = hit.energy()*1e6*keV2fC*getCCE(geom,id,cce_);
428 
429  //distance to the center of the detector
430  const float dist2center( getPositionDistance(geom,id) );
431 
432  //hit time: [time()]=ns [centerDist]=cm [refSpeed_]=cm/ns + delay by 1ns
433  //accumulate in 15 buckets of 25ns (9 pre-samples, 1 in-time, 5 post-samples)
434  const float tof = toa-dist2center/refSpeed_+tofDelay_ ;
435  const int itime= std::floor( tof/bxTime_ ) + 9;
436 
437  //no need to add bx crossing - tof comes already corrected from the mixing module
438  //itime += bxCrossing;
439  //itime += 9;
440 
441  if(itime<0 || itime>14) continue;
442 
443  //check if time index is ok and store energy
444  if(itime >= (int)simHitIt->second.hit_info[0].size() ) continue;
445 
446  (simHitIt->second).hit_info[0][itime] += charge;
447 
448 
449  //working version with pileup only for in-time hits
450  int waferThickness = getCellThickness(geom,id);
451  bool orderChanged = false;
452  if(itime == 9){
453  if(hitRefs_bx0[id].empty()){
454  hitRefs_bx0[id].emplace_back(charge, tof);
455  }
456  else if(tof <= hitRefs_bx0[id].back().second){
457  std::vector<std::pair<float, float> >::iterator findPos =
458  std::upper_bound(hitRefs_bx0[id].begin(), hitRefs_bx0[id].end(), std::pair<float, float>(0.f,tof),
459  [](const auto& i, const auto& j){return i.second < j.second;});
460 
461  std::vector<std::pair<float, float> >::iterator insertedPos =
462  hitRefs_bx0[id].insert(findPos, (findPos == hitRefs_bx0[id].begin()) ?
463  std::pair<float, float>(charge,tof) : std::pair<float, float>((findPos-1)->first+charge,tof));
464 
465  for(std::vector<std::pair<float, float> >::iterator step = insertedPos+1; step != hitRefs_bx0[id].end(); ++step){
466  step->first += charge;
467  if(step->first > tdcForToAOnset[waferThickness-1] && step->second != hitRefs_bx0[id].back().second){
468  hitRefs_bx0[id].resize(std::upper_bound(hitRefs_bx0[id].begin(), hitRefs_bx0[id].end(), std::pair<float, float>(0.f,step->second),
469  [](const auto& i, const auto& j){return i.second < j.second;}) - hitRefs_bx0[id].begin());
470  for(auto stepEnd = step+1; stepEnd != hitRefs_bx0[id].end(); ++stepEnd) stepEnd->first += charge;
471  break;
472  }
473  }
474  orderChanged = true;
475  }
476  else{
477  if(hitRefs_bx0[id].back().first <= tdcForToAOnset[waferThickness-1]){
478  hitRefs_bx0[id].emplace_back(hitRefs_bx0[id].back().first+charge, tof);
479  }
480  }
481  }
482 
483  float accChargeForToA = hitRefs_bx0[id].empty() ? 0.f : hitRefs_bx0[id].back().first;
484 
485  //time-of-arrival (check how to be used)
486  if(weightToAbyEnergy) (simHitIt->second).hit_info[1][itime] += charge*tof;
487  else if(accChargeForToA > tdcForToAOnset[waferThickness-1] &&
488  ((simHitIt->second).hit_info[1][itime] == 0 || orderChanged == true) ){
489  float fireTDC = hitRefs_bx0[id].back().second;
490  if (hitRefs_bx0[id].size() > 1){
491  float chargeBeforeThr = 0.f;
492  float tofchargeBeforeThr = 0.f;
493  for(const auto& step : hitRefs_bx0[id]){
494  if(step.first + chargeBeforeThr <= tdcForToAOnset[waferThickness-1]){
495  chargeBeforeThr += step.first;
496  tofchargeBeforeThr = step.second;
497  }
498  else break;
499  }
500  float deltaQ = accChargeForToA - chargeBeforeThr;
501  float deltaTOF = fireTDC - tofchargeBeforeThr;
502  fireTDC = (tdcForToAOnset[waferThickness-1] - chargeBeforeThr) * deltaTOF / deltaQ + tofchargeBeforeThr;
503  }
504  (simHitIt->second).hit_info[1][itime] = fireTDC;
505  }
506 
507  }
508  hitRefs.clear();
509 }
510 
511 void HGCDigitizer::accumulate(const PHGCSimAccumulator& simAccumulator) {
512  //configuration to apply for the computation of time-of-flight
513  std::array<float, 3> tdcForToAOnset{ {0.f, 0.f, 0.f} };
514  float keV2fC(0.f);
515  bool weightToAbyEnergy= getWeight(tdcForToAOnset, keV2fC);
516  loadSimHitAccumulator(*simHitAccumulator_, simAccumulator, premixStage1MinCharge_, premixStage1MaxCharge_, !weightToAbyEnergy);
517 }
518 
519 //
521  //get geometry
523  es.get<CaloGeometryRecord>().get(geom);
524 
525  gHGCal_ = nullptr;
526  gHcal_ = nullptr;
527 
528  if( producesEEDigis() ) gHGCal_ = dynamic_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(myDet_,mySubDet_));
529  if( producesHEfrontDigis() ) gHGCal_ = dynamic_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(myDet_,mySubDet_));
530  if( producesHFNoseDigis() ) gHGCal_ = dynamic_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(myDet_,mySubDet_));
531 
532  if( producesHEbackDigis() ) {
533  if (geometryType_ == 0) {
534  gHcal_ = dynamic_cast<const HcalGeometry*>(geom->getSubdetectorGeometry(DetId::Hcal, HcalEndcap));
535  } else {
536  gHGCal_ = dynamic_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(myDet_,mySubDet_));
537  }
538  }
539 
540  int nadded(0);
541  //valid ID lists
542  if( nullptr != gHGCal_ ) {
543  getValidDetIds( gHGCal_, validIds_ );
544  } else if( nullptr != gHcal_ ) {
545  getValidDetIds( gHcal_, validIds_ );
546  } else {
547  throw cms::Exception("BadConfiguration")
548  << "HGCDigitizer is not producing EE, FH, or BH digis!";
549  }
550 
551  if (verbosity_ > 0)
552  edm::LogInfo("HGCDigitizer")
553  << "Added " << nadded << ":" << validIds_.size()
554  << " detIds without " << hitCollection_
555  << " in first event processed" << std::endl;
556 }
557 
558 //
560 {
561  std::unordered_set<DetId>().swap(validIds_);
562 }
563 
564 //
566 {
567  for( HGCSimHitDataAccumulator::iterator it = simHitAccumulator_->begin(); it!=simHitAccumulator_->end(); it++)
568  {
569  it->second.hit_info[0].fill(0.);
570  it->second.hit_info[1].fill(0.);
571  }
572 }
573 
574 uint32_t HGCDigitizer::getType() const {
575 
577  if (geometryType_ == 0) {
578  switch(mySubDet_) {
580  idx = 0;
581  break;
583  idx = 1;
584  break;
586  idx = 2;
587  break;
589  idx = 3;
590  break;
591  default:
592  break;
593  }
594  } else {
595  switch(myDet_) {
596  case DetId::HGCalEE:
597  idx = 0;
598  break;
599  case DetId::HGCalHSi:
600  idx = 1;
601  break;
602  case DetId::HGCalHSc:
603  idx = 2;
604  break;
605  case DetId::Forward:
606  idx = 3;
607  break;
608  default:
609  break;
610  }
611  }
612  return idx;
613 }
614 
615 bool HGCDigitizer::getWeight(std::array<float,3>& tdcForToAOnset,
616  float& keV2fC) const {
617 
618  bool weightToAbyEnergy(false);
619  if (geometryType_ == 0) {
620  switch( mySubDet_ ) {
622  weightToAbyEnergy = theHGCEEDigitizer_->toaModeByEnergy();
623  tdcForToAOnset = theHGCEEDigitizer_->tdcForToAOnset();
624  keV2fC = theHGCEEDigitizer_->keV2fC();
625  break;
627  weightToAbyEnergy = theHGCHEfrontDigitizer_->toaModeByEnergy();
628  tdcForToAOnset = theHGCHEfrontDigitizer_->tdcForToAOnset();
629  keV2fC = theHGCHEfrontDigitizer_->keV2fC();
630  break;
632  weightToAbyEnergy = theHGCHEbackDigitizer_->toaModeByEnergy();
633  tdcForToAOnset = theHGCHEbackDigitizer_->tdcForToAOnset();
634  keV2fC = theHGCHEbackDigitizer_->keV2fC();
635  break;
637  weightToAbyEnergy = theHFNoseDigitizer_->toaModeByEnergy();
638  tdcForToAOnset = theHFNoseDigitizer_->tdcForToAOnset();
639  keV2fC = theHFNoseDigitizer_->keV2fC();
640  break;
641  default:
642  break;
643  }
644  } else {
645  switch(myDet_) {
646  case DetId::HGCalEE:
647  weightToAbyEnergy = theHGCEEDigitizer_->toaModeByEnergy();
648  tdcForToAOnset = theHGCEEDigitizer_->tdcForToAOnset();
649  keV2fC = theHGCEEDigitizer_->keV2fC();
650  break;
651  case DetId::HGCalHSi:
652  weightToAbyEnergy = theHGCHEfrontDigitizer_->toaModeByEnergy();
653  tdcForToAOnset = theHGCHEfrontDigitizer_->tdcForToAOnset();
654  keV2fC = theHGCHEfrontDigitizer_->keV2fC();
655  break;
656  case DetId::HGCalHSc:
657  weightToAbyEnergy = theHGCHEbackDigitizer_->toaModeByEnergy();
658  tdcForToAOnset = theHGCHEbackDigitizer_->tdcForToAOnset();
659  keV2fC = theHGCHEbackDigitizer_->keV2fC();
660  break;
661  case DetId::Forward:
662  weightToAbyEnergy = theHFNoseDigitizer_->toaModeByEnergy();
663  tdcForToAOnset = theHFNoseDigitizer_->tdcForToAOnset();
664  keV2fC = theHFNoseDigitizer_->keV2fC();
665  break;
666  default:
667  break;
668  }
669  }
670 return weightToAbyEnergy;
671 }
672 
674 
675  const double tol(0.5);
676  if (geometryType_ != 0 && nullptr != gHGCal_) {
677  for (const auto & digi : *(digis)) {
678  const DetId& id = digi.id();
679  const GlobalPoint& global = gHGCal_->getPosition(id);
680  double r = global.perp();
681  double z = std::abs(global.z());
682  std::pair<double,double> zrange = gHGCal_->topology().dddConstants().rangeZ(true);
683  std::pair<double,double> rrange = gHGCal_->topology().dddConstants().rangeR(z,true);
684  bool ok = ((r >= rrange.first) && (r <= rrange.second) &&
685  (z >= zrange.first) && (z <= zrange.second));
686  std::string ck = (((r < rrange.first-tol) || (r > rrange.second+tol) ||
687  (z < zrange.first-tol) || (z > zrange.second+tol)) ?
688  "***** ERROR *****" : "");
689  if (!ok) {
690  if (id.det() == DetId::HGCalHSi) {
691  edm::LogVerbatim("HGCDigitizer") << "Check " << HGCSiliconDetId(id)
692  << " " << global << " R " << r
693  << ":" << rrange.first << ":"
694  << rrange.second << " Z " << z
695  << ":" << zrange.first << ":"
696  << zrange.second << " Flag "
697  << ok << " " << ck;
698  } else if (id.det() == DetId::HGCalHSc) {
699  edm::LogVerbatim("HGCDigitizer") << "Check " << HGCScintillatorDetId(id)
700  << " " << global << " R " << r
701  << ":" << rrange.first << ":"
702  << rrange.second << " Z " << z
703  << ":" << zrange.first << ":"
704  << zrange.second << " Flag "
705  << ok << " " << ck;
706  } else {
707  edm::LogVerbatim("HGCDigitizer") << "Check " << HFNoseDetId(id)
708  << " " << global << " R " << r
709  << ":" << rrange.first << ":"
710  << rrange.second << " Z " << z
711  << ":" << zrange.first << ":"
712  << zrange.second << " Flag "
713  << ok << " " << ck;
714  }
715  }
716  }
717  }
718 }
719 
720 template void HGCDigitizer::accumulate<HcalGeometry>(edm::Handle<edm::PCaloHitContainer> const &hits, int bxCrossing,const HcalGeometry *geom, CLHEP::HepRandomEngine* hre);
721 template void HGCDigitizer::accumulate<HGCalGeometry>(edm::Handle<edm::PCaloHitContainer> const &hits, int bxCrossing,const HGCalGeometry *geom, CLHEP::HepRandomEngine* hre);
size
Write out results.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
uint32_t nEvents_
Definition: HGCDigitizer.h:145
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
T getUntrackedParameter(std::string const &, T const &) const
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:167
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const override
Get the cell geometry of a given detector id. Should return false if not found.
Definition: HcalGeometry.cc:86
bool premixStage1_
Definition: HGCDigitizer.h:103
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
std::vector< float > cce_
Definition: HGCDigitizer.h:147
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre)
ForwardSubdetector mySubDet_
Definition: HGCDigitizer.h:132
T perp() const
Definition: PV3DBase.h:72
int digitizationType_
Definition: HGCDigitizer.h:100
std::string hitCollection_
Definition: HGCDigitizer.h:94
void resetSimHitDataAccumulator()
static constexpr unsigned sampleMask
const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const override
Get a list of valid detector ids (for the given subdetector)
Definition: HcalGeometry.cc:76
void emplace_back(unsigned int detId, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data)
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
actions at the start/end of event
double unpack16log(int16_t i, double lmin, double lmax, uint16_t base=32768)
Definition: liblogintpack.h:55
GlobalPoint getPosition(const DetId &id) const
DetId::Detector myDet_
Definition: HGCDigitizer.h:131
ForwardSubdetector
std::unique_ptr< HFNoseDigitizer > theHFNoseDigitizer_
Definition: HGCDigitizer.h:123
const HGCalGeometry * gHGCal_
Definition: HGCDigitizer.h:127
bool producesEEDigis()
Definition: HGCDigitizer.h:71
#define constexpr
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
bool getWeight(std::array< float, 3 > &tdcForToAOnset, float &keV2fC) const
std::string digiCollection_
Definition: HGCDigitizer.h:94
const HcalTopology & topology() const
Definition: HcalGeometry.h:117
static constexpr unsigned sampleOffset
static constexpr unsigned energyMask
U second(std::pair< T, U > const &p)
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
std::pair< double, double > rangeR(double z, bool reco) const
std::pair< double, double > rangeZ(bool reco) const
T mag() const
Definition: PV3DBase.h:67
void beginRun(const edm::EventSetup &es)
actions at the start/end of run
T z() const
Definition: PV3DBase.h:64
const HGCalTopology & topology() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
std::unordered_set< DetId > validIds_
Definition: HGCDigitizer.h:126
#define end
Definition: vmac.h:39
Definition: value.py:1
base
Make Sure CMSSW is Setup ##.
bool isValid() const
Definition: HandleBase.h:74
constexpr size_t nSamples
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
std::array< double, 4 > averageOccupancies_
Definition: HGCDigitizer.h:144
bool producesHFNoseDigis()
Definition: HGCDigitizer.h:77
bool producesHEfrontDigis()
Definition: HGCDigitizer.h:73
int waferType(DetId const &id) const
uint32_t getType() const
std::unique_ptr< HGCHEbackDigitizer > theHGCHEbackDigitizer_
Definition: HGCDigitizer.h:121
Definition: DetId.h:18
const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const override
Get a list of valid detector ids (for the given subdetector)
Definition: HGCalGeometry.h:84
void reserve(size_t size)
double premixStage1MinCharge_
Definition: HGCDigitizer.h:106
void checkPosition(const HGCalDigiCollection *digis) const
bool producesHEbackDigis()
Definition: HGCDigitizer.h:75
const HGCalDDDConstants & dddConstants() const
int maxSimHitsAccTime_
Definition: HGCDigitizer.h:111
std::unique_ptr< HGCHEfrontDigitizer > theHGCHEfrontDigitizer_
Definition: HGCDigitizer.h:122
std::unique_ptr< HGCEEDigitizer > theHGCEEDigitizer_
Definition: HGCDigitizer.h:120
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *hre)
handle SimHit accumulation
#define begin
Definition: vmac.h:32
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
T get() const
Definition: EventSetup.h:62
std::map< uint32_t, std::vector< std::pair< float, float > > > hitRefs_bx0
Definition: HGCDigitizer.h:149
HGCDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
step
DetId relabel(const uint32_t testId) const
std::unique_ptr< hgc::HGCSimHitDataAccumulator > simHitAccumulator_
Definition: HGCDigitizer.h:113
static bool orderByDetIdThenTime(const HGCCaloHitTuple_t &a, const HGCCaloHitTuple_t &b)
Definition: HGCDigitizer.h:39
double bxTime_
Definition: HGCDigitizer.h:112
int16_t pack16log(double x, double lmin, double lmax, uint16_t base=32768)
Definition: liblogintpack.h:26
double premixStage1MaxCharge_
Definition: HGCDigitizer.h:108
std::string digiCollection()
Definition: HGCDigitizer.h:79
const HcalGeometry * gHcal_
Definition: HGCDigitizer.h:128
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
def move(src, dest)
Definition: eostools.py:511
uint32_t verbosity_
Definition: HGCDigitizer.h:135
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39