62 void analyzeHits(std::vector<PCaloHit>&, std::vector<PCaloHit>&, std::vector<PCaloHit>&);
71 const std::vector<edm::EDGetTokenT<edm::PCaloHitContainer>>
toks_calo_;
72 std::vector<edm::EDGetTokenT<edm::PSimHitContainer>>
toks_track_;
74 std::vector<edm::EDGetTokenT<edm::PSimHitContainer>>
toks_tkLow_;
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"};
103 : g4Label_(ps.getUntrackedParameter<
std::
string>(
"ModuleLabel")),
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)),
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])));
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_;
131 if (!
tfile.isAvailable())
133 <<
"please add it to config file";
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");
152 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for incident particle";
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());
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());
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());
170 timeAll_[
i]->GetXaxis()->SetTitle(
title);
171 timeAll_[
i]->GetYaxis()->SetTitle(
"Hits");
172 double ymax = maxEnergy_;
173 if (
i == 1 ||
i == 2 ||
i == 4)
175 else if (
i > 4 &&
i < 8)
177 sprintf(
name,
"Edep%d",
i);
178 sprintf(
title,
"Energy deposit (GeV) in %s", dets[
i].c_str());
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());
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());
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());
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());
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());
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());
210 phi_[
i]->GetXaxis()->SetTitle(
title);
211 phi_[
i]->GetYaxis()->SetTitle(
"Hits");
214 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for first level of Calorimeter";
225 for (
int i = 0;
i < 9;
i++) {
227 if (
i == 0 ||
i == 3 ||
i == 6)
229 sprintf(
name,
"EdepCal%d",
i);
230 sprintf(
title,
"Energy deposit in %s", detx[
i].c_str());
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());
237 edepT_[
i]->GetXaxis()->SetTitle(
title);
238 edepT_[
i]->GetYaxis()->SetTitle(
"Events");
241 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for second level of Calorimeter";
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");
253 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for general tracking hits";
255 std::string dett[nTrack_] = {
"Pixel Barrel (High)",
256 "Pixel Endcap (High)",
261 "Pixel Barrel (Low)",
262 "Pixel Endcap (Low)",
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());
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());
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;
288 edepTk_[
i]->GetXaxis()->SetTitle(
title);
289 edepTk_[
i]->GetYaxis()->SetTitle(
"Hits");
292 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for SimHit objects";
298 std::vector<std::string> calonames = {
"EcalHitsEB",
"EcalHitsEE",
"EcalHitsES",
"HcalHits"};
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);
311 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy:Run = " <<
e.id().run() <<
" Event = " <<
e.id().event();
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();
326 double ptInc = eInc / std::cosh(etaInc);
332 std::vector<PCaloHit> ebHits, eeHits, hcHits;
334 bool getHits =
false;
339 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Input flags Hits " << getHits;
342 std::vector<PCaloHit> caloHits;
343 caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
345 ebHits.insert(ebHits.end(), hitsCalo->begin(), hitsCalo->end());
347 eeHits.insert(eeHits.end(), hitsCalo->begin(), hitsCalo->end());
349 hcHits.insert(hcHits.end(), hitsCalo->begin(), hitsCalo->end());
351 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Hit buffer " << caloHits.size();
358 std::vector<PSimHit> muonHits;
362 muonHits.insert(muonHits.end(), hitsTrack->begin(), hitsTrack->end());
366 unsigned int nhmu = muonHits.size();
367 hitMu->Fill(
double(nhmu));
368 std::vector<PSimHit> tkHighHits;
372 tkHighHits.insert(tkHighHits.end(), hitsTrack->begin(), hitsTrack->end());
376 unsigned int nhtkh = tkHighHits.size();
378 std::vector<PSimHit> tkLowHits;
382 tkLowHits.insert(tkLowHits.end(), hitsTrack->begin(), hitsTrack->end());
386 unsigned int nhtkl = tkLowHits.size();
387 hitLow->Fill(
double(nhtkl));
391 int nHit =
hits.size();
392 int nHB(0), nHE(0), nHO(0), nHF(0), nEB(0), nEBAPD(0), nEBATJ(0);
394 int nBad(0), nEE(0), nES(0);
396 std::map<unsigned int, double> hitMap;
398 for (
int i = 0;
i < nHit;
i++) {
399 double edep =
hits[
i].energy();
401 unsigned int id =
hits[
i].id();
402 double edepEM =
hits[
i].energyEM();
403 double edepHad =
hits[
i].energyHad();
410 }
else if (indx == 3) {
419 edm::LogVerbatim(
"HitStudy") <<
"From SIM step subdet:z:depth:eta:phi:lay " << subdet <<
":" <<
z <<
":" 421 <<
" After getHCID subdet:zside:eta:phi:depth " << hid1.
subdet <<
":" <<
zside 422 <<
":" << hid1.
eta <<
":" << hid1.
phi <<
":" << hid1.
depth <<
" ID " << hid2;
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));
458 if (indx >= 0 && indx < 3) {
494 etot_[indx + 2]->Fill(etot[indx + 2]);
495 etotg_[indx + 2]->Fill(etotG[indx + 2]);
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));
505 hit_[indx + 2]->Fill(
double(nHit));
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));
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();
523 std::map<unsigned int, double>::const_iterator it = hitMap.begin();
524 for (; it != hitMap.end(); it++) {
525 double time = it->second;
533 if ((
id & 0x20000) != 0)
535 else if ((
id & 0x40000) != 0)
544 }
else if (indx == 3) {
545 int idx(-1), subdet(0);
554 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
556 }
else if (subdet == static_cast<int>(
HcalOuter)) {
558 }
else if (subdet == static_cast<int>(
HcalForward)) {
572 edm::PSimHitContainer::const_iterator ihit;
574 if (indx >= 0 && indx < 6)
576 else if (indx >= 6 && indx < 12)
578 else if (indx >= 12 && indx <
nTrack_)
580 for (ihit =
hits->begin(); ihit !=
hits->end(); ihit++) {
581 edepTk_[indx]->Fill(ihit->energyLoss());
582 tofTk_[indx]->Fill(ihit->timeOfFlight());
585 hitTk_[indx]->Fill(
float(nHit));
587 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy::analyzeHits: for " <<
label <<
" Index " << indx <<
" # of Hits " 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();
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();
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();
623 subdet =
id.subdet();
629 }
else if (subdet == static_cast<int>(
HcalOuter)) {
635 double edepE = edepEB + edepEE;
636 double edepET = edepEBT + edepEET;
637 double edepHC = edepH + edepHO;
638 double edepHCT = edepHT + edepHOT;
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";
661 if (edepET <
eMIP_) {
static const std::string kSharedResource
Log< level::Info, true > LogVerbatim
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_
void analyzeHits(std::vector< PCaloHit > &, int)
HcalID getHCID(int subdet, int ieta, int iphi, int lay, int idepth) 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 >
void beginRun(edm::Run const &, edm::EventSetup const &) override
constexpr HcalSubdetector subdet() const
get the subdetector
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
const std::vector< std::string > muonLab_
const std::string g4Label_
const std::vector< edm::EDGetTokenT< edm::PCaloHitContainer > > toks_calo_
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)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
CaloSimHitStudy(const edm::ParameterSet &ps)
const HepMC::GenEvent * GetEvent() const
constexpr uint32_t rawId() const
get the raw id
const std::vector< std::string > tkHighLab_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~CaloSimHitStudy() override
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_tkHigh_
const HcalGeometry * hcalGeom_
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > toks_track_
const HcalDDDRecConstants * dddConstants() const
void analyze(edm::Event const &, edm::EventSetup const &) override
const std::vector< std::string > hitLab_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
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
const HcalTopology & topology() const
static const int kEcalDepthIdMask