CMS 3D CMS Logo

CaloSimHitStudy.cc
Go to the documentation of this file.
3 
7 
14 
17 
23 
30 
36 
37 #include <TH1F.h>
38 
39 #include <memory>
40 #include <iostream>
41 #include <fstream>
42 #include <vector>
43 #include <map>
44 #include <string>
45 
46 //#define EDM_ML_DEBUG
47 
48 class CaloSimHitStudy : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
49 public:
51  ~CaloSimHitStudy() override {}
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 protected:
55  void beginJob() override {}
56  void analyze(edm::Event const&, edm::EventSetup const&) override;
57  void beginRun(edm::Run const&, edm::EventSetup const&) override {}
58  void endRun(edm::Run const&, edm::EventSetup const&) override {}
59 
60  void analyzeHits(std::vector<PCaloHit>&, int);
62  void analyzeHits(std::vector<PCaloHit>&, std::vector<PCaloHit>&, std::vector<PCaloHit>&);
63 
64 private:
66  const std::vector<std::string> hitLab_;
67  const double maxEnergy_, tmax_, eMIP_;
68  const bool storeRL_, testNumber_;
71  const std::vector<edm::EDGetTokenT<edm::PCaloHitContainer>> toks_calo_;
72  std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> toks_track_;
73  std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> toks_tkHigh_;
74  std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> toks_tkLow_;
75 
78 
79  const std::vector<std::string> muonLab_ = {"MuonRPCHits", "MuonCSCHits", "MuonDTHits", "MuonGEMHits"};
80  const std::vector<std::string> tkHighLab_ = {"TrackerHitsPixelBarrelHighTof",
81  "TrackerHitsPixelEndcapHighTof",
82  "TrackerHitsTECHighTof",
83  "TrackerHitsTIBHighTof",
84  "TrackerHitsTIDHighTof",
85  "TrackerHitsTOBHighTof"};
86  const std::vector<std::string> tkLowLab_ = {"TrackerHitsPixelBarrelLowTof",
87  "TrackerHitsPixelEndcapLowTof",
88  "TrackerHitsTECLowTof",
89  "TrackerHitsTIBLowTof",
90  "TrackerHitsTIDLowTof",
91  "TrackerHitsTOBLowTof"};
92 
93  static constexpr int nCalo_ = 9;
94  static constexpr int nTrack_ = 16;
100 };
101 
103  : g4Label_(ps.getUntrackedParameter<std::string>("ModuleLabel")),
104  hitLab_(ps.getUntrackedParameter<std::vector<std::string>>("CaloCollection")),
105  maxEnergy_(ps.getUntrackedParameter<double>("MaxEnergy", 200.0)),
106  tmax_(ps.getUntrackedParameter<double>("TimeCut", 100.0)),
107  eMIP_(ps.getUntrackedParameter<double>("MIPCut", 0.70)),
108  storeRL_(ps.getUntrackedParameter<bool>("StoreRL", false)),
109  testNumber_(ps.getUntrackedParameter<bool>("TestNumbering", true)),
111  tok_evt_(consumes<edm::HepMCProduct>(
112  edm::InputTag(ps.getUntrackedParameter<std::string>("SourceLabel", "VtxSmeared")))),
113  toks_calo_{edm::vector_transform(hitLab_, [this](const std::string& name) {
114  return consumes<edm::PCaloHitContainer>(edm::InputTag{g4Label_, name});
115  })} {
116  usesResource(TFileService::kSharedResource);
117 
118  for (unsigned i = 0; i != muonLab_.size(); i++)
119  toks_track_.emplace_back(consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, muonLab_[i])));
120  for (unsigned i = 0; i != tkHighLab_.size(); i++)
121  toks_tkHigh_.emplace_back(consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, tkHighLab_[i])));
122  for (unsigned i = 0; i != tkLowLab_.size(); i++)
123  toks_tkLow_.emplace_back(consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, tkLowLab_[i])));
124 
125  edm::LogVerbatim("HitStudy") << "Module Label: " << g4Label_ << " Hits: " << hitLab_[0] << ", " << hitLab_[1]
126  << ", " << hitLab_[2] << ", " << hitLab_[3] << " MaxEnergy: " << maxEnergy_
127  << " Tmax: " << tmax_ << " MIP Cut: " << eMIP_;
128 
130 
131  if (!tfile.isAvailable())
132  throw cms::Exception("BadConfig") << "TFileService unavailable: "
133  << "please add it to config file";
134  char name[20], title[120];
135  sprintf(title, "Incident PT (GeV)");
136  ptInc_ = tfile->make<TH1F>("PtInc", title, 1000, 0., maxEnergy_);
137  ptInc_->GetXaxis()->SetTitle(title);
138  ptInc_->GetYaxis()->SetTitle("Events");
139  sprintf(title, "Incident Energy (GeV)");
140  eneInc_ = tfile->make<TH1F>("EneInc", title, 1000, 0., maxEnergy_);
141  eneInc_->GetXaxis()->SetTitle(title);
142  eneInc_->GetYaxis()->SetTitle("Events");
143  sprintf(title, "Incident #eta");
144  etaInc_ = tfile->make<TH1F>("EtaInc", title, 200, -5., 5.);
145  etaInc_->GetXaxis()->SetTitle(title);
146  etaInc_->GetYaxis()->SetTitle("Events");
147  sprintf(title, "Incident #phi");
148  phiInc_ = tfile->make<TH1F>("PhiInc", title, 200, -3.1415926, 3.1415926);
149  phiInc_->GetXaxis()->SetTitle(title);
150  phiInc_->GetYaxis()->SetTitle("Events");
151 #ifdef EDM_ML_DEBUG
152  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for incident particle";
153 #endif
154  std::string dets[nCalo_] = {"EB", "EB(APD)", "EB(ATJ)", "EE", "ES", "HB", "HE", "HO", "HF"};
155  double nhcMax[nCalo_] = {40000., 2000., 2000., 40000., 10000., 10000., 10000., 2000., 10000.};
156  for (int i = 0; i < nCalo_; i++) {
157  sprintf(name, "Hit%d", i);
158  sprintf(title, "Number of hits in %s", dets[i].c_str());
159  hit_[i] = tfile->make<TH1F>(name, title, 1000, 0., nhcMax[i]);
160  hit_[i]->GetXaxis()->SetTitle(title);
161  hit_[i]->GetYaxis()->SetTitle("Events");
162  sprintf(name, "Time%d", i);
163  sprintf(title, "Time of the hit (ns) in %s", dets[i].c_str());
164  time_[i] = tfile->make<TH1F>(name, title, 1000, 0., 1000.);
165  time_[i]->GetXaxis()->SetTitle(title);
166  time_[i]->GetYaxis()->SetTitle("Hits");
167  sprintf(name, "TimeAll%d", i);
168  sprintf(title, "Hit time (ns) in %s with no check on Track ID", dets[i].c_str());
169  timeAll_[i] = tfile->make<TH1F>(name, title, 1000, 0., 1000.);
170  timeAll_[i]->GetXaxis()->SetTitle(title);
171  timeAll_[i]->GetYaxis()->SetTitle("Hits");
172  double ymax = maxEnergy_;
173  if (i == 1 || i == 2 || i == 4)
174  ymax = 1.0;
175  else if (i > 4 && i < 8)
176  ymax = 10.0;
177  sprintf(name, "Edep%d", i);
178  sprintf(title, "Energy deposit (GeV) in %s", dets[i].c_str());
179  edep_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
180  edep_[i]->GetXaxis()->SetTitle(title);
181  edep_[i]->GetYaxis()->SetTitle("Hits");
182  sprintf(name, "EdepEM%d", i);
183  sprintf(title, "Energy deposit (GeV) by EM particles in %s", dets[i].c_str());
184  edepEM_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
185  edepEM_[i]->GetXaxis()->SetTitle(title);
186  edepEM_[i]->GetYaxis()->SetTitle("Hits");
187  sprintf(name, "EdepHad%d", i);
188  sprintf(title, "Energy deposit (GeV) by hadrons in %s", dets[i].c_str());
189  edepHad_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
190  edepHad_[i]->GetXaxis()->SetTitle(title);
191  edepHad_[i]->GetYaxis()->SetTitle("Hits");
192  sprintf(name, "Etot%d", i);
193  sprintf(title, "Total energy deposit (GeV) in %s", dets[i].c_str());
194  etot_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
195  etot_[i]->GetXaxis()->SetTitle(title);
196  etot_[i]->GetYaxis()->SetTitle("Events");
197  sprintf(name, "EtotG%d", i);
198  sprintf(title, "Total energy deposit (GeV) in %s (t < 100 ns)", dets[i].c_str());
199  etotg_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
200  etotg_[i]->GetXaxis()->SetTitle(title);
201  etotg_[i]->GetYaxis()->SetTitle("Events");
202  sprintf(name, "eta%d", i);
203  sprintf(title, "#eta of hit point in %s", dets[i].c_str());
204  eta_[i] = tfile->make<TH1F>(name, title, 100, -5.0, 5.0);
205  eta_[i]->GetXaxis()->SetTitle(title);
206  eta_[i]->GetYaxis()->SetTitle("Hits");
207  sprintf(name, "phi%d", i);
208  sprintf(title, "#phi of hit point in %s", dets[i].c_str());
209  phi_[i] = tfile->make<TH1F>(name, title, 100, -M_PI, M_PI);
210  phi_[i]->GetXaxis()->SetTitle(title);
211  phi_[i]->GetYaxis()->SetTitle("Hits");
212  }
213 #ifdef EDM_ML_DEBUG
214  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for first level of Calorimeter";
215 #endif
216  std::string detx[9] = {"EB/EE (MIP)",
217  "HB/HE (MIP)",
218  "HB/HE/HO (MIP)",
219  "EB/EE (no MIP)",
220  "HB/HE (no MIP)",
221  "HB/HE/HO (no MIP)",
222  "EB/EE (All)",
223  "HB/HE (All)",
224  "HB/HE/HO (All)"};
225  for (int i = 0; i < 9; i++) {
226  double ymax = 1.0;
227  if (i == 0 || i == 3 || i == 6)
228  ymax = maxEnergy_;
229  sprintf(name, "EdepCal%d", i);
230  sprintf(title, "Energy deposit in %s", detx[i].c_str());
231  edepC_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
232  edepC_[i]->GetXaxis()->SetTitle(title);
233  edepC_[i]->GetYaxis()->SetTitle("Events");
234  sprintf(name, "EdepCalT%d", i);
235  sprintf(title, "Energy deposit (t < %f ns) in %s", tmax_, detx[i].c_str());
236  edepT_[i] = tfile->make<TH1F>(name, title, 5000, 0., ymax);
237  edepT_[i]->GetXaxis()->SetTitle(title);
238  edepT_[i]->GetYaxis()->SetTitle("Events");
239  }
240 #ifdef EDM_ML_DEBUG
241  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for second level of Calorimeter";
242 #endif
243  hitLow = tfile->make<TH1F>("HitLow", "Number of hits in Track (Low)", 1000, 0, 20000.);
244  hitLow->GetXaxis()->SetTitle("Number of hits in Track (Low)");
245  hitLow->GetYaxis()->SetTitle("Events");
246  hitHigh = tfile->make<TH1F>("HitHigh", "Number of hits in Track (High)", 1000, 0, 5000.);
247  hitHigh->GetXaxis()->SetTitle("Number of hits in Track (High)");
248  hitHigh->GetYaxis()->SetTitle("Events");
249  hitMu = tfile->make<TH1F>("HitMu", "Number of hits in Track (Muon)", 1000, 0, 2000.);
250  hitMu->GetXaxis()->SetTitle("Number of hits in Muon");
251  hitMu->GetYaxis()->SetTitle("Events");
252 #ifdef EDM_ML_DEBUG
253  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for general tracking hits";
254 #endif
255  std::string dett[nTrack_] = {"Pixel Barrel (High)",
256  "Pixel Endcap (High)",
257  "TEC (High)",
258  "TIB (High)",
259  "TID (High)",
260  "TOB (High)",
261  "Pixel Barrel (Low)",
262  "Pixel Endcap (Low)",
263  "TEC (Low)",
264  "TIB (Low)",
265  "TID (Low)",
266  "TOB (Low)",
267  "RPC",
268  "CSC",
269  "DT",
270  "GEM"};
271  double nhtMax[nTrack_] = {
272  500., 500., 1000., 1000., 500., 1000., 5000., 2000., 10000., 5000., 2000., 5000., 500., 1000., 1000., 500.};
273  for (int i = 0; i < nTrack_; i++) {
274  sprintf(name, "HitTk%d", i);
275  sprintf(title, "Number of hits in %s", dett[i].c_str());
276  hitTk_[i] = tfile->make<TH1F>(name, title, 1000, 0., nhtMax[i]);
277  hitTk_[i]->GetXaxis()->SetTitle(title);
278  hitTk_[i]->GetYaxis()->SetTitle("Events");
279  sprintf(name, "TimeTk%d", i);
280  sprintf(title, "Time of the hit (ns) in %s", dett[i].c_str());
281  tofTk_[i] = tfile->make<TH1F>(name, title, 1000, 0., 200.);
282  tofTk_[i]->GetXaxis()->SetTitle(title);
283  tofTk_[i]->GetYaxis()->SetTitle("Hits");
284  sprintf(name, "EdepTk%d", i);
285  sprintf(title, "Energy deposit (GeV) in %s", dett[i].c_str());
286  double ymax = (i < 12) ? 0.25 : 0.005;
287  edepTk_[i] = tfile->make<TH1F>(name, title, 250, 0., ymax);
288  edepTk_[i]->GetXaxis()->SetTitle(title);
289  edepTk_[i]->GetYaxis()->SetTitle("Hits");
290  }
291 #ifdef EDM_ML_DEBUG
292  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Completed defining histos for SimHit objects";
293 #endif
294 }
295 
298  std::vector<std::string> calonames = {"EcalHitsEB", "EcalHitsEE", "EcalHitsES", "HcalHits"};
299  desc.addUntracked<std::string>("SourceLabel", "generatorSmeared");
300  desc.addUntracked<std::string>("ModuleLabel", "g4SimHits");
301  desc.addUntracked<std::vector<std::string>>("CaloCollection", calonames);
302  desc.addUntracked<double>("MaxEnergy", 200.0);
303  desc.addUntracked<double>("TimeCut", 100.0);
304  desc.addUntracked<double>("MIPCut", 0.70);
305  desc.addUntracked<bool>("StoreRL", false);
306  desc.addUntracked<bool>("TestNumbering", true);
307  descriptions.add("CaloSimHitStudy", desc);
308 }
309 
311  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy:Run = " << e.id().run() << " Event = " << e.id().event();
312 
313  caloGeometry_ = &set.getData(tokGeom_);
315 
316  const edm::Handle<edm::HepMCProduct> EvtHandle = e.getHandle(tok_evt_);
317  const HepMC::GenEvent* myGenEvent = EvtHandle->GetEvent();
318 
319  double eInc = 0, etaInc = 0, phiInc = 0;
320  HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
321  if (p != myGenEvent->particles_end()) {
322  eInc = (*p)->momentum().e();
323  etaInc = (*p)->momentum().eta();
324  phiInc = (*p)->momentum().phi();
325  }
326  double ptInc = eInc / std::cosh(etaInc);
327  ptInc_->Fill(ptInc);
328  eneInc_->Fill(eInc);
329  etaInc_->Fill(etaInc);
330  phiInc_->Fill(phiInc);
331 
332  std::vector<PCaloHit> ebHits, eeHits, hcHits;
333  for (unsigned int i = 0; i < toks_calo_.size(); i++) {
334  bool getHits = false;
335  const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(toks_calo_[i]);
336  if (hitsCalo.isValid())
337  getHits = true;
338 #ifdef EDM_ML_DEBUG
339  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Input flags Hits " << getHits;
340 #endif
341  if (getHits) {
342  std::vector<PCaloHit> caloHits;
343  caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
344  if (i == 0)
345  ebHits.insert(ebHits.end(), hitsCalo->begin(), hitsCalo->end());
346  else if (i == 1)
347  eeHits.insert(eeHits.end(), hitsCalo->begin(), hitsCalo->end());
348  else if (i == 3)
349  hcHits.insert(hcHits.end(), hitsCalo->begin(), hitsCalo->end());
350 #ifdef EDM_ML_DEBUG
351  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy: Hit buffer " << caloHits.size();
352 #endif
353  analyzeHits(caloHits, i);
354  }
355  }
356  analyzeHits(ebHits, eeHits, hcHits);
357 
358  std::vector<PSimHit> muonHits;
359  for (unsigned int i = 0; i < toks_track_.size(); i++) {
360  const edm::Handle<edm::PSimHitContainer>& hitsTrack = e.getHandle(toks_track_[i]);
361  if (hitsTrack.isValid()) {
362  muonHits.insert(muonHits.end(), hitsTrack->begin(), hitsTrack->end());
363  analyzeHits(hitsTrack, i + 12);
364  }
365  }
366  unsigned int nhmu = muonHits.size();
367  hitMu->Fill(double(nhmu));
368  std::vector<PSimHit> tkHighHits;
369  for (unsigned int i = 0; i < toks_tkHigh_.size(); i++) {
370  const edm::Handle<edm::PSimHitContainer>& hitsTrack = e.getHandle(toks_tkHigh_[i]);
371  if (hitsTrack.isValid()) {
372  tkHighHits.insert(tkHighHits.end(), hitsTrack->begin(), hitsTrack->end());
373  analyzeHits(hitsTrack, i);
374  }
375  }
376  unsigned int nhtkh = tkHighHits.size();
377  hitHigh->Fill(double(nhtkh));
378  std::vector<PSimHit> tkLowHits;
379  for (unsigned int i = 0; i < toks_tkLow_.size(); i++) {
380  const edm::Handle<edm::PSimHitContainer>& hitsTrack = e.getHandle(toks_tkLow_[i]);
381  if (hitsTrack.isValid()) {
382  tkLowHits.insert(tkLowHits.end(), hitsTrack->begin(), hitsTrack->end());
383  analyzeHits(hitsTrack, i + 6);
384  }
385  }
386  unsigned int nhtkl = tkLowHits.size();
387  hitLow->Fill(double(nhtkl));
388 }
389 
390 void CaloSimHitStudy::analyzeHits(std::vector<PCaloHit>& hits, int indx) {
391  int nHit = hits.size();
392  int nHB(0), nHE(0), nHO(0), nHF(0), nEB(0), nEBAPD(0), nEBATJ(0);
393 #ifdef EDM_ML_DEBUG
394  int nBad(0), nEE(0), nES(0);
395 #endif
396  std::map<unsigned int, double> hitMap;
397  std::vector<double> etot(nCalo_, 0), etotG(nCalo_, 0);
398  for (int i = 0; i < nHit; i++) {
399  double edep = hits[i].energy();
400  double time = hits[i].time();
401  unsigned int id = hits[i].id();
402  double edepEM = hits[i].energyEM();
403  double edepHad = hits[i].energyHad();
404  if (indx == 0) {
405  int dep = (hits[i].depth()) & PCaloHit::kEcalDepthIdMask;
406  if (dep == 1)
407  id |= 0x20000;
408  else if (dep == 2)
409  id |= 0x40000;
410  } else if (indx == 3) {
411  if (testNumber_) {
412  int subdet(0), ieta(0), iphi(0), z(0), lay(0), depth(0);
413  HcalTestNumbering::unpackHcalIndex(id, subdet, z, depth, ieta, iphi, lay);
415  hcalGeom_->topology().dddConstants()->getHCID(subdet, ieta, iphi, lay, depth);
416  int zside = 2 * z - 1;
417  HcalDetId hid2(static_cast<HcalSubdetector>(hid1.subdet), (zside * hid1.eta), hid1.phi, hid1.depth);
418 #ifdef EDM_ML_DEBUG
419  edm::LogVerbatim("HitStudy") << "From SIM step subdet:z:depth:eta:phi:lay " << subdet << ":" << z << ":"
420  << depth << ":" << ieta << ":" << iphi << ":" << lay
421  << " After getHCID subdet:zside:eta:phi:depth " << hid1.subdet << ":" << zside
422  << ":" << hid1.eta << ":" << hid1.phi << ":" << hid1.depth << " ID " << hid2;
423 #endif
424  id = hid2.rawId();
425  }
426  }
427  std::map<unsigned int, double>::const_iterator it = hitMap.find(id);
428  if (it == hitMap.end()) {
429  hitMap.insert(std::pair<unsigned int, double>(id, time));
430  }
431  int idx = -1;
432  if (indx != 3) {
433  if (indx == 0) {
434  if (storeRL_)
435  idx = 0;
436  else
437  idx = ((hits[i].depth()) & PCaloHit::kEcalDepthIdMask);
438  } else
439  idx = indx + 2;
440  time_[idx]->Fill(time);
441  edep_[idx]->Fill(edep);
442  edepEM_[idx]->Fill(edepEM);
443  edepHad_[idx]->Fill(edepHad);
444  if (idx == 0)
445  nEB++;
446  else if (idx == 1)
447  nEBAPD++;
448  else if (idx == 2)
449  nEBATJ++;
450 #ifdef EDM_ML_DEBUG
451  else if (idx == 3)
452  nEE++;
453  else if (idx == 4)
454  nES++;
455  else
456  nBad++;
457 #endif
458  if (indx >= 0 && indx < 3) {
459  etot[idx] += edep;
460  if (time < 100)
461  etotG[idx] += edep;
462  }
463  } else {
464  HcalSubdetector subdet = HcalDetId(id).subdet();
465  if (subdet == HcalSubdetector::HcalBarrel) {
466  idx = indx + 2;
467  nHB++;
468  } else if (subdet == HcalSubdetector::HcalEndcap) {
469  idx = indx + 3;
470  nHE++;
471  } else if (subdet == HcalSubdetector::HcalOuter) {
472  idx = indx + 4;
473  nHO++;
474  } else if (subdet == HcalSubdetector::HcalForward) {
475  idx = indx + 5;
476  nHF++;
477  }
478  if (idx > 0) {
479  time_[idx]->Fill(time);
480  edep_[idx]->Fill(edep);
481  edepEM_[idx]->Fill(edepEM);
482  edepHad_[idx]->Fill(edepHad);
483  etot[idx] += edep;
484  if (time < 100)
485  etotG[idx] += edep;
486  } else {
487 #ifdef EDM_ML_DEBUG
488  nBad++;
489 #endif
490  }
491  }
492  }
493  if (indx < 3) {
494  etot_[indx + 2]->Fill(etot[indx + 2]);
495  etotg_[indx + 2]->Fill(etotG[indx + 2]);
496  if (indx == 0) {
497  etot_[indx]->Fill(etot[indx]);
498  etotg_[indx]->Fill(etotG[indx]);
499  etot_[indx + 1]->Fill(etot[indx + 1]);
500  etotg_[indx + 1]->Fill(etotG[indx + 1]);
501  hit_[indx]->Fill(double(nEB));
502  hit_[indx + 1]->Fill(double(nEBAPD));
503  hit_[indx + 2]->Fill(double(nEBATJ));
504  } else {
505  hit_[indx + 2]->Fill(double(nHit));
506  }
507  } else if (indx == 3) {
508  hit_[5]->Fill(double(nHB));
509  hit_[6]->Fill(double(nHE));
510  hit_[7]->Fill(double(nHO));
511  hit_[8]->Fill(double(nHF));
512  for (int idx = 5; idx < 9; idx++) {
513  etot_[idx]->Fill(etot[idx]);
514  etotg_[idx]->Fill(etotG[idx]);
515  }
516  }
517 
518 #ifdef EDM_ML_DEBUG
519  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy::analyzeHits: EB " << nEB << ", " << nEBAPD << ", " << nEBATJ
520  << " EE " << nEE << " ES " << nES << " HB " << nHB << " HE " << nHE << " HO " << nHO
521  << " HF " << nHF << " Bad " << nBad << " All " << nHit << " Reduced " << hitMap.size();
522 #endif
523  std::map<unsigned int, double>::const_iterator it = hitMap.begin();
524  for (; it != hitMap.end(); it++) {
525  double time = it->second;
527  DetId id(it->first);
528  if (indx != 2)
530  int idx = -1;
531  if (indx < 3) {
532  if (indx == 0) {
533  if ((id & 0x20000) != 0)
534  idx = indx + 1;
535  else if ((id & 0x40000) != 0)
536  idx = indx + 1;
537  else
538  idx = indx;
539  } else {
540  idx = indx + 2;
541  }
542  if (idx >= 0 && idx < 5)
543  timeAll_[idx]->Fill(time);
544  } else if (indx == 3) {
545  int idx(-1), subdet(0);
546  if (testNumber_) {
547  int ieta(0), phi(0), z(0), lay(0), depth(0);
548  HcalTestNumbering::unpackHcalIndex(id.rawId(), subdet, z, depth, ieta, phi, lay);
549  } else {
550  subdet = HcalDetId(id).subdet();
551  }
552  if (subdet == static_cast<int>(HcalBarrel)) {
553  idx = indx + 2;
554  } else if (subdet == static_cast<int>(HcalEndcap)) {
555  idx = indx + 3;
556  } else if (subdet == static_cast<int>(HcalOuter)) {
557  idx = indx + 4;
558  } else if (subdet == static_cast<int>(HcalForward)) {
559  idx = indx + 5;
560  }
561  if (idx > 0) {
562  timeAll_[idx]->Fill(time);
563  eta_[idx]->Fill(point.eta());
564  phi_[idx]->Fill(point.phi());
565  }
566  }
567  }
568 }
569 
571  int nHit = 0;
572  edm::PSimHitContainer::const_iterator ihit;
573  std::string label(" ");
574  if (indx >= 0 && indx < 6)
575  label = tkHighLab_[indx];
576  else if (indx >= 6 && indx < 12)
577  label = tkLowLab_[indx - 6];
578  else if (indx >= 12 && indx < nTrack_)
579  label = muonLab_[indx - 12];
580  for (ihit = hits->begin(); ihit != hits->end(); ihit++) {
581  edepTk_[indx]->Fill(ihit->energyLoss());
582  tofTk_[indx]->Fill(ihit->timeOfFlight());
583  nHit++;
584  }
585  hitTk_[indx]->Fill(float(nHit));
586 #ifdef EDM_ML_DEBUG
587  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy::analyzeHits: for " << label << " Index " << indx << " # of Hits "
588  << nHit;
589 #endif
590 }
591 
592 void CaloSimHitStudy::analyzeHits(std::vector<PCaloHit>& ebHits,
593  std::vector<PCaloHit>& eeHits,
594  std::vector<PCaloHit>& hcHits) {
595  double edepEB = 0, edepEBT = 0;
596  for (unsigned int i = 0; i < ebHits.size(); i++) {
597  double edep = ebHits[i].energy();
598  double time = ebHits[i].time();
599  if (((ebHits[i].depth()) & PCaloHit::kEcalDepthIdMask) == 0) {
600  edepEB += edep;
601  if (time < tmax_)
602  edepEBT += edep;
603  }
604  }
605  double edepEE = 0, edepEET = 0;
606  for (unsigned int i = 0; i < eeHits.size(); i++) {
607  double edep = eeHits[i].energy();
608  double time = eeHits[i].time();
609  edepEE += edep;
610  if (time < tmax_)
611  edepEET += edep;
612  }
613  double edepH = 0, edepHT = 0, edepHO = 0, edepHOT = 0;
614  for (unsigned int i = 0; i < hcHits.size(); i++) {
615  double edep = hcHits[i].energy();
616  double time = hcHits[i].time();
617  int subdet(0);
618  if (testNumber_) {
619  int ieta(0), phi(0), z(0), lay(0), depth(0);
620  HcalTestNumbering::unpackHcalIndex(hcHits[i].id(), subdet, z, depth, ieta, phi, lay);
621  } else {
622  HcalDetId id = HcalDetId(hcHits[i].id());
623  subdet = id.subdet();
624  }
625  if (subdet == static_cast<int>(HcalBarrel) || subdet == static_cast<int>(HcalEndcap)) {
626  edepH += edep;
627  if (time < tmax_)
628  edepHT += edep;
629  } else if (subdet == static_cast<int>(HcalOuter)) {
630  edepHO += edep;
631  if (time < tmax_)
632  edepHOT += edep;
633  }
634  }
635  double edepE = edepEB + edepEE;
636  double edepET = edepEBT + edepEET;
637  double edepHC = edepH + edepHO;
638  double edepHCT = edepHT + edepHOT;
639 #ifdef EDM_ML_DEBUG
640  edm::LogVerbatim("HitStudy") << "CaloSimHitStudy::energy in EB " << edepEB << " (" << edepEBT << ") from "
641  << ebHits.size() << " hits; "
642  << " energy in EE " << edepEE << " (" << edepEET << ") from " << eeHits.size()
643  << " hits; energy in HC " << edepH << ", " << edepHO << " (" << edepHT << ", " << edepHOT
644  << ") from " << hcHits.size() << " hits";
645 #endif
646  edepC_[6]->Fill(edepE);
647  edepT_[6]->Fill(edepET);
648  edepC_[7]->Fill(edepH);
649  edepT_[7]->Fill(edepHT);
650  edepC_[8]->Fill(edepHC);
651  edepT_[8]->Fill(edepHCT);
652  if (edepE < eMIP_) {
653  edepC_[0]->Fill(edepE);
654  edepC_[1]->Fill(edepH);
655  edepC_[2]->Fill(edepHC);
656  } else {
657  edepC_[3]->Fill(edepE);
658  edepC_[4]->Fill(edepH);
659  edepC_[5]->Fill(edepHC);
660  }
661  if (edepET < eMIP_) {
662  edepT_[0]->Fill(edepET);
663  edepT_[1]->Fill(edepHT);
664  edepT_[2]->Fill(edepHCT);
665  } else {
666  edepT_[3]->Fill(edepET);
667  edepT_[4]->Fill(edepHT);
668  edepT_[5]->Fill(edepHCT);
669  }
670 }
671 
672 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< edm::HepMCProduct > tok_evt_
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_tkLow_
const std::vector< std::string > tkLowLab_
static constexpr int nCalo_
TH1F * edepT_[nCalo_]
void analyzeHits(std::vector< PCaloHit > &, int)
HcalID getHCID(int subdet, int ieta, int iphi, int lay, int idepth) const
TH1F * timeAll_[nCalo_]
int zside(DetId const &)
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
TH1F * hitTk_[nTrack_]
void beginRun(edm::Run const &, edm::EventSetup const &) override
TH1F * edep_[nCalo_]
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
char const * label
const double eMIP_
TH1F * etot_[nCalo_]
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
const std::vector< std::string > muonLab_
const std::string g4Label_
Definition: tfile.py:1
const std::vector< edm::EDGetTokenT< edm::PCaloHitContainer > > toks_calo_
TH1F * tofTk_[nTrack_]
HcalSubdetector
Definition: HcalAssistant.h:31
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tokGeom_
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TH1F * edepHad_[nCalo_]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
CaloSimHitStudy(const edm::ParameterSet &ps)
const double maxEnergy_
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
#define M_PI
Definition: DetId.h:17
TH1F * etotg_[nCalo_]
void beginJob() override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
TH1F * phi_[nCalo_]
TH1F * time_[nCalo_]
const std::vector< std::string > tkHighLab_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const bool testNumber_
TH1F * edepTk_[nTrack_]
bool isValid() const
Definition: HandleBase.h:70
~CaloSimHitStudy() override
TH1F * hit_[nCalo_]
void endRun(edm::Run const &, edm::EventSetup const &) override
HLT enums.
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_tkHigh_
const HcalGeometry * hcalGeom_
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_track_
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:161
TH1F * edepC_[nCalo_]
const bool storeRL_
const double tmax_
void analyze(edm::Event const &, edm::EventSetup const &) override
const std::vector< std::string > hitLab_
TH1F * edepEM_[nCalo_]
TH1F * eta_[nCalo_]
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
const CaloGeometry * caloGeometry_
static constexpr int nTrack_
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
Definition: Run.h:45
const HcalTopology & topology() const
Definition: HcalGeometry.h:111
static const int kEcalDepthIdMask
Definition: PCaloHit.h:60