53 void analyzeHits(std::vector<PCaloHit>&, std::vector<PCaloHit>&, std::vector<PCaloHit>&);
61 std::vector<edm::EDGetTokenT<edm::PCaloHitContainer>>
toks_calo_;
62 std::vector<edm::EDGetTokenT<edm::PSimHitContainer>>
toks_track_;
64 std::vector<edm::EDGetTokenT<edm::PSimHitContainer>>
toks_tkLow_;
66 const std::vector<std::string>
muonLab_ = {
"MuonRPCHits",
"MuonCSCHits",
"MuonDTHits",
"MuonGEMHits"};
67 const std::vector<std::string>
tkHighLab_ = {
"TrackerHitsPixelBarrelHighTof",
68 "TrackerHitsPixelEndcapHighTof",
69 "TrackerHitsTECHighTof",
70 "TrackerHitsTIBHighTof",
71 "TrackerHitsTIDHighTof",
72 "TrackerHitsTOBHighTof"};
73 const std::vector<std::string>
tkLowLab_ = {
"TrackerHitsPixelBarrelLowTof",
74 "TrackerHitsPixelEndcapLowTof",
75 "TrackerHitsTECLowTof",
76 "TrackerHitsTIBLowTof",
77 "TrackerHitsTIDLowTof",
78 "TrackerHitsTOBLowTof"};
87 : g4Label_(ps.getUntrackedParameter<
std::
string>(
"ModuleLabel")),
89 maxEnergy_(ps.getUntrackedParameter<double>(
"MaxEnergy", 200.0)),
90 tmax_(ps.getUntrackedParameter<double>(
"TimeCut", 100.0)),
91 eMIP_(ps.getUntrackedParameter<double>(
"MIPCut", 0.70)),
92 storeRL_(ps.getUntrackedParameter<
bool>(
"StoreRL",
false)),
93 testNumber_(ps.getUntrackedParameter<
bool>(
"TestNumbering",
true)) {
109 <<
" Tmax: " <<
tmax_ <<
" MIP Cut: " <<
eMIP_;
113 if (!
tfile.isAvailable())
115 <<
"please add it to config file";
117 sprintf(
title,
"Incident PT (GeV)");
120 ptInc_->GetYaxis()->SetTitle(
"Events");
121 sprintf(
title,
"Incident Energy (GeV)");
124 eneInc_->GetYaxis()->SetTitle(
"Events");
125 sprintf(
title,
"Incident #eta");
128 etaInc_->GetYaxis()->SetTitle(
"Events");
129 sprintf(
title,
"Incident #phi");
132 phiInc_->GetYaxis()->SetTitle(
"Events");
134 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for incident particle";
136 std::string dets[9] = {
"EB",
"EB(APD)",
"EB(ATJ)",
"EE",
"ES",
"HB",
"HE",
"HO",
"HF"};
137 double nhcMax[9] = {40000., 2000., 2000., 40000., 10000., 10000., 10000., 2000., 10000.};
138 for (
int i = 0;
i < 9;
i++) {
139 sprintf(
name,
"Hit%d",
i);
140 sprintf(
title,
"Number of hits in %s", dets[
i].c_str());
143 hit_[
i]->GetYaxis()->SetTitle(
"Events");
144 sprintf(
name,
"Time%d",
i);
145 sprintf(
title,
"Time of the hit (ns) in %s", dets[
i].c_str());
148 time_[
i]->GetYaxis()->SetTitle(
"Hits");
149 sprintf(
name,
"TimeAll%d",
i);
150 sprintf(
title,
"Hit time (ns) in %s with no check on Track ID", dets[
i].c_str());
153 timeAll_[
i]->GetYaxis()->SetTitle(
"Hits");
155 if (
i == 1 ||
i == 2 ||
i == 4)
157 else if (
i > 4 &&
i < 8)
159 sprintf(
name,
"Edep%d",
i);
160 sprintf(
title,
"Energy deposit (GeV) in %s", dets[
i].c_str());
163 edep_[
i]->GetYaxis()->SetTitle(
"Hits");
164 sprintf(
name,
"EdepEM%d",
i);
165 sprintf(
title,
"Energy deposit (GeV) by EM particles in %s", dets[
i].c_str());
168 edepEM_[
i]->GetYaxis()->SetTitle(
"Hits");
169 sprintf(
name,
"EdepHad%d",
i);
170 sprintf(
title,
"Energy deposit (GeV) by hadrons in %s", dets[
i].c_str());
173 edepHad_[
i]->GetYaxis()->SetTitle(
"Hits");
174 sprintf(
name,
"Etot%d",
i);
175 sprintf(
title,
"Total energy deposit (GeV) in %s", dets[
i].c_str());
178 etot_[
i]->GetYaxis()->SetTitle(
"Events");
179 sprintf(
name,
"EtotG%d",
i);
180 sprintf(
title,
"Total energy deposit (GeV) in %s (t < 100 ns)", dets[
i].c_str());
183 etotg_[
i]->GetYaxis()->SetTitle(
"Events");
186 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for first level of Calorimeter";
197 for (
int i = 0;
i < 9;
i++) {
199 if (
i == 0 ||
i == 3 ||
i == 6)
201 sprintf(
name,
"EdepCal%d",
i);
202 sprintf(
title,
"Energy deposit in %s", detx[
i].c_str());
205 edepC_[
i]->GetYaxis()->SetTitle(
"Events");
206 sprintf(
name,
"EdepCalT%d",
i);
207 sprintf(
title,
"Energy deposit (t < %f ns) in %s",
tmax_, detx[
i].c_str());
210 edepT_[
i]->GetYaxis()->SetTitle(
"Events");
213 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for second level of Calorimeter";
215 hitLow =
tfile->make<TH1F>(
"HitLow",
"Number of hits in Track (Low)", 1000, 0, 20000.);
216 hitLow->GetXaxis()->SetTitle(
"Number of hits in Track (Low)");
217 hitLow->GetYaxis()->SetTitle(
"Events");
218 hitHigh =
tfile->make<TH1F>(
"HitHigh",
"Number of hits in Track (High)", 1000, 0, 5000.);
219 hitHigh->GetXaxis()->SetTitle(
"Number of hits in Track (High)");
220 hitHigh->GetYaxis()->SetTitle(
"Events");
221 hitMu =
tfile->make<TH1F>(
"HitMu",
"Number of hits in Track (Muon)", 1000, 0, 2000.);
222 hitMu->GetXaxis()->SetTitle(
"Number of hits in Muon");
223 hitMu->GetYaxis()->SetTitle(
"Events");
225 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for general tracking hits";
228 "Pixel Endcap (High)",
233 "Pixel Barrel (Low)",
234 "Pixel Endcap (Low)",
243 double nhtMax[16] = {
244 500., 500., 1000., 1000., 500., 1000., 5000., 2000., 10000., 5000., 2000., 5000., 500., 1000., 1000., 500.};
245 for (
int i = 0;
i < 16;
i++) {
246 sprintf(
name,
"HitTk%d",
i);
247 sprintf(
title,
"Number of hits in %s", dett[
i].c_str());
250 hitTk_[
i]->GetYaxis()->SetTitle(
"Events");
251 sprintf(
name,
"TimeTk%d",
i);
252 sprintf(
title,
"Time of the hit (ns) in %s", dett[
i].c_str());
255 tofTk_[
i]->GetYaxis()->SetTitle(
"Hits");
256 sprintf(
name,
"EdepTk%d",
i);
257 sprintf(
title,
"Energy deposit (GeV) in %s", dett[
i].c_str());
258 double ymax = (
i < 12) ? 0.25 : 0.005;
261 edepTk_[
i]->GetYaxis()->SetTitle(
"Hits");
264 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for SimHit objects";
270 std::vector<std::string> calonames = {
"EcalHitsEB",
"EcalHitsEE",
"EcalHitsES",
"HcalHits"};
273 desc.addUntracked<std::vector<std::string>>(
"CaloCollection", calonames);
274 desc.addUntracked<
double>(
"MaxEnergy", 200.0);
275 desc.addUntracked<
double>(
"TimeCut", 100.0);
276 desc.addUntracked<
double>(
"MIPCut", 0.70);
277 desc.addUntracked<
bool>(
"StoreRL",
false);
278 desc.addUntracked<
bool>(
"TestNumbering",
true);
279 descriptions.
add(
"CaloSimHitStudy",
desc);
283 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy:Run = " <<
e.id().run() <<
" Event = " <<
e.id().event();
288 double eInc = 0, etaInc = 0, phiInc = 0;
289 HepMC::GenEvent::particle_const_iterator
p = myGenEvent->particles_begin();
290 if (
p != myGenEvent->particles_end()) {
291 eInc = (*p)->momentum().e();
292 etaInc = (*p)->momentum().eta();
293 phiInc = (*p)->momentum().phi();
295 double ptInc = eInc / std::cosh(etaInc);
301 std::vector<PCaloHit> ebHits, eeHits, hcHits;
303 bool getHits =
false;
308 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Input flags Hits " << getHits;
311 std::vector<PCaloHit> caloHits;
312 caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
314 ebHits.insert(ebHits.end(), hitsCalo->begin(), hitsCalo->end());
316 eeHits.insert(eeHits.end(), hitsCalo->begin(), hitsCalo->end());
318 hcHits.insert(hcHits.end(), hitsCalo->begin(), hitsCalo->end());
320 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Hit buffer " << caloHits.size();
327 std::vector<PSimHit> muonHits;
331 muonHits.insert(muonHits.end(), hitsTrack->begin(), hitsTrack->end());
335 unsigned int nhmu = muonHits.size();
336 hitMu->Fill(
double(nhmu));
337 std::vector<PSimHit> tkHighHits;
341 tkHighHits.insert(tkHighHits.end(), hitsTrack->begin(), hitsTrack->end());
345 unsigned int nhtkh = tkHighHits.size();
347 std::vector<PSimHit> tkLowHits;
351 tkLowHits.insert(tkLowHits.end(), hitsTrack->begin(), hitsTrack->end());
355 unsigned int nhtkl = tkLowHits.size();
356 hitLow->Fill(
double(nhtkl));
360 int nHit =
hits.size();
361 int nHB(0), nHE(0), nHO(0), nHF(0), nEB(0), nEBAPD(0), nEBATJ(0), nEE(0), nES(0);
365 std::map<unsigned int, double> hitMap;
366 std::vector<double> etot(9, 0), etotG(9, 0);
367 for (
int i = 0;
i < nHit;
i++) {
368 double edep =
hits[
i].energy();
370 unsigned int id_ =
hits[
i].id();
371 double edepEM =
hits[
i].energyEM();
372 double edepHad =
hits[
i].energyHad();
380 std::map<unsigned int, double>::const_iterator it = hitMap.find(id_);
381 if (it == hitMap.end()) {
382 hitMap.insert(std::pair<unsigned int, double>(id_,
time));
411 if (indx >= 0 && indx < 3) {
423 subdet =
id.subdet();
428 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
431 }
else if (subdet == static_cast<int>(
HcalOuter)) {
434 }
else if (subdet == static_cast<int>(
HcalForward)) {
454 etot_[indx + 2]->Fill(etot[indx + 2]);
455 etotg_[indx + 2]->Fill(etotG[indx + 2]);
457 etot_[indx]->Fill(etot[indx]);
458 etotg_[indx]->Fill(etotG[indx]);
459 etot_[indx + 1]->Fill(etot[indx + 1]);
460 etotg_[indx + 1]->Fill(etotG[indx + 1]);
461 hit_[indx]->Fill(
double(nEB));
462 hit_[indx + 1]->Fill(
double(nEBAPD));
463 hit_[indx + 2]->Fill(
double(nEBATJ));
465 hit_[indx + 2]->Fill(
double(nHit));
467 }
else if (indx == 3) {
468 hit_[5]->Fill(
double(nHB));
469 hit_[6]->Fill(
double(nHE));
470 hit_[7]->Fill(
double(nHO));
471 hit_[8]->Fill(
double(nHF));
479 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy::analyzeHits: EB " << nEB <<
", " << nEBAPD <<
", " << nEBATJ
480 <<
" EE " << nEE <<
" ES " << nES <<
" HB " << nHB <<
" HE " << nHE <<
" HO " << nHO
481 <<
" HF " << nHF <<
" Bad " << nBad <<
" All " << nHit <<
" Reduced " << hitMap.size();
483 std::map<unsigned int, double>::const_iterator it = hitMap.begin();
484 for (; it != hitMap.end(); it++) {
485 double time = it->second;
486 unsigned int id_ = (it->first);
490 if ((id_ & 0x20000) != 0)
492 else if ((id_ & 0x40000) != 0)
501 }
else if (indx == 3) {
502 int idx(-1), subdet(0);
508 subdet =
id.subdet();
512 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
514 }
else if (subdet == static_cast<int>(
HcalOuter)) {
516 }
else if (subdet == static_cast<int>(
HcalForward)) {
528 edm::PSimHitContainer::const_iterator ihit;
530 if (indx >= 0 && indx < 6)
532 else if (indx >= 6 && indx < 12)
534 else if (indx >= 12 && indx < 16)
536 for (ihit =
hits->begin(); ihit !=
hits->end(); ihit++) {
537 edepTk_[indx]->Fill(ihit->energyLoss());
538 tofTk_[indx]->Fill(ihit->timeOfFlight());
541 hitTk_[indx]->Fill(
float(nHit));
543 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy::analyzeHits: for " <<
label <<
" Index " << indx <<
" # of Hits " 549 std::vector<PCaloHit>& eeHits,
550 std::vector<PCaloHit>& hcHits) {
551 double edepEB = 0, edepEBT = 0;
552 for (
unsigned int i = 0;
i < ebHits.size();
i++) {
553 double edep = ebHits[
i].energy();
554 double time = ebHits[
i].time();
561 double edepEE = 0, edepEET = 0;
562 for (
unsigned int i = 0;
i < eeHits.size();
i++) {
563 double edep = eeHits[
i].energy();
564 double time = eeHits[
i].time();
569 double edepH = 0, edepHT = 0, edepHO = 0, edepHOT = 0;
570 for (
unsigned int i = 0;
i < hcHits.size();
i++) {
571 double edep = hcHits[
i].energy();
572 double time = hcHits[
i].time();
579 subdet =
id.subdet();
585 }
else if (subdet == static_cast<int>(
HcalOuter)) {
591 double edepE = edepEB + edepEE;
592 double edepET = edepEBT + edepEET;
593 double edepHC = edepH + edepHO;
594 double edepHCT = edepHT + edepHOT;
596 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy::energy in EB " << edepEB <<
" (" << edepEBT <<
") from " 597 << ebHits.size() <<
" hits; " 598 <<
" energy in EE " << edepEE <<
" (" << edepEET <<
") from " << eeHits.size()
599 <<
" hits; energy in HC " << edepH <<
", " << edepHO <<
" (" << edepHT <<
", " << edepHOT
600 <<
") from " << hcHits.size() <<
" hits";
617 if (edepET <
eMIP_) {
static const std::string kSharedResource
Log< level::Info, true > LogVerbatim
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_tkLow_
const std::vector< std::string > tkLowLab_
#define DEFINE_FWK_MODULE(type)
void analyzeHits(std::vector< PCaloHit > &, int)
edm::EDGetTokenT< edm::HepMCProduct > tok_evt_
T getUntrackedParameter(std::string const &, T const &) const
void beginRun(edm::Run const &, edm::EventSetup const &) override
const std::vector< std::string > muonLab_
const std::string g4Label_
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
CaloSimHitStudy(const edm::ParameterSet &ps)
const HepMC::GenEvent * GetEvent() const
const std::vector< std::string > tkHighLab_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< edm::EDGetTokenT< edm::PCaloHitContainer > > toks_calo_
~CaloSimHitStudy() override
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_tkHigh_
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_track_
void analyze(edm::Event const &, edm::EventSetup const &) override
const std::vector< std::string > hitLab_
static const int kEcalDepthIdMask