61 void analyzeHits(std::vector<PCaloHit>&, std::vector<PCaloHit>&, std::vector<PCaloHit>&);
70 const std::vector<edm::EDGetTokenT<edm::PCaloHitContainer>>
toks_calo_;
71 std::vector<edm::EDGetTokenT<edm::PSimHitContainer>>
toks_track_;
73 std::vector<edm::EDGetTokenT<edm::PSimHitContainer>>
toks_tkLow_;
78 const std::vector<std::string>
muonLab_ = {
"MuonRPCHits",
"MuonCSCHits",
"MuonDTHits",
"MuonGEMHits"};
79 const std::vector<std::string>
tkHighLab_ = {
"TrackerHitsPixelBarrelHighTof",
80 "TrackerHitsPixelEndcapHighTof",
81 "TrackerHitsTECHighTof",
82 "TrackerHitsTIBHighTof",
83 "TrackerHitsTIDHighTof",
84 "TrackerHitsTOBHighTof"};
85 const std::vector<std::string>
tkLowLab_ = {
"TrackerHitsPixelBarrelLowTof",
86 "TrackerHitsPixelEndcapLowTof",
87 "TrackerHitsTECLowTof",
88 "TrackerHitsTIBLowTof",
89 "TrackerHitsTIDLowTof",
90 "TrackerHitsTOBLowTof"};
102 : g4Label_(ps.getUntrackedParameter<
std::
string>(
"ModuleLabel")),
104 maxEnergy_(ps.getUntrackedParameter<double>(
"MaxEnergy", 200.0)),
105 tmax_(ps.getUntrackedParameter<double>(
"TimeCut", 100.0)),
106 eMIP_(ps.getUntrackedParameter<double>(
"MIPCut", 0.70)),
107 storeRL_(ps.getUntrackedParameter<
bool>(
"StoreRL",
false)),
108 testNumber_(ps.getUntrackedParameter<
bool>(
"TestNumbering",
true)),
117 for (
unsigned i = 0;
i != muonLab_.size();
i++)
118 toks_track_.emplace_back(consumes<edm::PSimHitContainer>(
edm::InputTag(g4Label_, muonLab_[
i])));
119 for (
unsigned i = 0;
i != tkHighLab_.size();
i++)
120 toks_tkHigh_.emplace_back(consumes<edm::PSimHitContainer>(
edm::InputTag(g4Label_, tkHighLab_[
i])));
121 for (
unsigned i = 0;
i != tkLowLab_.size();
i++)
122 toks_tkLow_.emplace_back(consumes<edm::PSimHitContainer>(
edm::InputTag(g4Label_, tkLowLab_[
i])));
124 edm::LogVerbatim(
"HitStudy") <<
"Module Label: " << g4Label_ <<
" Hits: " << hitLab_[0] <<
", " << hitLab_[1]
125 <<
", " << hitLab_[2] <<
", " << hitLab_[3] <<
" MaxEnergy: " << maxEnergy_
126 <<
" Tmax: " << tmax_ <<
" MIP Cut: " << eMIP_;
130 if (!
tfile.isAvailable())
132 <<
"please add it to config file";
134 sprintf(
title,
"Incident PT (GeV)");
135 ptInc_ =
tfile->make<TH1F>(
"PtInc",
title, 1000, 0., maxEnergy_);
136 ptInc_->GetXaxis()->SetTitle(
title);
137 ptInc_->GetYaxis()->SetTitle(
"Events");
138 sprintf(
title,
"Incident Energy (GeV)");
139 eneInc_ =
tfile->make<TH1F>(
"EneInc",
title, 1000, 0., maxEnergy_);
140 eneInc_->GetXaxis()->SetTitle(
title);
141 eneInc_->GetYaxis()->SetTitle(
"Events");
142 sprintf(
title,
"Incident #eta");
143 etaInc_ =
tfile->make<TH1F>(
"EtaInc",
title, 200, -5., 5.);
144 etaInc_->GetXaxis()->SetTitle(
title);
145 etaInc_->GetYaxis()->SetTitle(
"Events");
146 sprintf(
title,
"Incident #phi");
147 phiInc_ =
tfile->make<TH1F>(
"PhiInc",
title, 200, -3.1415926, 3.1415926);
148 phiInc_->GetXaxis()->SetTitle(
title);
149 phiInc_->GetYaxis()->SetTitle(
"Events");
151 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for incident particle";
153 std::string dets[nCalo_] = {
"EB",
"EB(APD)",
"EB(ATJ)",
"EE",
"ES",
"HB",
"HE",
"HO",
"HF"};
154 double nhcMax[nCalo_] = {40000., 2000., 2000., 40000., 10000., 10000., 10000., 2000., 10000.};
155 for (
int i = 0;
i < nCalo_;
i++) {
156 sprintf(
name,
"Hit%d",
i);
157 sprintf(
title,
"Number of hits in %s", dets[
i].c_str());
159 hit_[
i]->GetXaxis()->SetTitle(
title);
160 hit_[
i]->GetYaxis()->SetTitle(
"Events");
161 sprintf(
name,
"Time%d",
i);
162 sprintf(
title,
"Time of the hit (ns) in %s", dets[
i].c_str());
164 time_[
i]->GetXaxis()->SetTitle(
title);
165 time_[
i]->GetYaxis()->SetTitle(
"Hits");
166 sprintf(
name,
"TimeAll%d",
i);
167 sprintf(
title,
"Hit time (ns) in %s with no check on Track ID", dets[
i].c_str());
169 timeAll_[
i]->GetXaxis()->SetTitle(
title);
170 timeAll_[
i]->GetYaxis()->SetTitle(
"Hits");
171 double ymax = maxEnergy_;
172 if (
i == 1 ||
i == 2 ||
i == 4)
174 else if (
i > 4 &&
i < 8)
176 sprintf(
name,
"Edep%d",
i);
177 sprintf(
title,
"Energy deposit (GeV) in %s", dets[
i].c_str());
179 edep_[
i]->GetXaxis()->SetTitle(
title);
180 edep_[
i]->GetYaxis()->SetTitle(
"Hits");
181 sprintf(
name,
"EdepEM%d",
i);
182 sprintf(
title,
"Energy deposit (GeV) by EM particles in %s", dets[
i].c_str());
184 edepEM_[
i]->GetXaxis()->SetTitle(
title);
185 edepEM_[
i]->GetYaxis()->SetTitle(
"Hits");
186 sprintf(
name,
"EdepHad%d",
i);
187 sprintf(
title,
"Energy deposit (GeV) by hadrons in %s", dets[
i].c_str());
189 edepHad_[
i]->GetXaxis()->SetTitle(
title);
190 edepHad_[
i]->GetYaxis()->SetTitle(
"Hits");
191 sprintf(
name,
"Etot%d",
i);
192 sprintf(
title,
"Total energy deposit (GeV) in %s", dets[
i].c_str());
194 etot_[
i]->GetXaxis()->SetTitle(
title);
195 etot_[
i]->GetYaxis()->SetTitle(
"Events");
196 sprintf(
name,
"EtotG%d",
i);
197 sprintf(
title,
"Total energy deposit (GeV) in %s (t < 100 ns)", dets[
i].c_str());
199 etotg_[
i]->GetXaxis()->SetTitle(
title);
200 etotg_[
i]->GetYaxis()->SetTitle(
"Events");
201 sprintf(
name,
"eta%d",
i);
202 sprintf(
title,
"#eta of hit point in %s", dets[
i].c_str());
204 eta_[
i]->GetXaxis()->SetTitle(
title);
205 eta_[
i]->GetYaxis()->SetTitle(
"Hits");
206 sprintf(
name,
"phi%d",
i);
207 sprintf(
title,
"#phi of hit point in %s", dets[
i].c_str());
209 phi_[
i]->GetXaxis()->SetTitle(
title);
210 phi_[
i]->GetYaxis()->SetTitle(
"Hits");
213 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for first level of Calorimeter";
224 for (
int i = 0;
i < 9;
i++) {
226 if (
i == 0 ||
i == 3 ||
i == 6)
228 sprintf(
name,
"EdepCal%d",
i);
229 sprintf(
title,
"Energy deposit in %s", detx[
i].c_str());
231 edepC_[
i]->GetXaxis()->SetTitle(
title);
232 edepC_[
i]->GetYaxis()->SetTitle(
"Events");
233 sprintf(
name,
"EdepCalT%d",
i);
234 sprintf(
title,
"Energy deposit (t < %f ns) in %s", tmax_, detx[
i].c_str());
236 edepT_[
i]->GetXaxis()->SetTitle(
title);
237 edepT_[
i]->GetYaxis()->SetTitle(
"Events");
240 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for second level of Calorimeter";
242 hitLow =
tfile->make<TH1F>(
"HitLow",
"Number of hits in Track (Low)", 1000, 0, 20000.);
243 hitLow->GetXaxis()->SetTitle(
"Number of hits in Track (Low)");
244 hitLow->GetYaxis()->SetTitle(
"Events");
245 hitHigh =
tfile->make<TH1F>(
"HitHigh",
"Number of hits in Track (High)", 1000, 0, 5000.);
246 hitHigh->GetXaxis()->SetTitle(
"Number of hits in Track (High)");
247 hitHigh->GetYaxis()->SetTitle(
"Events");
248 hitMu =
tfile->make<TH1F>(
"HitMu",
"Number of hits in Track (Muon)", 1000, 0, 2000.);
249 hitMu->GetXaxis()->SetTitle(
"Number of hits in Muon");
250 hitMu->GetYaxis()->SetTitle(
"Events");
252 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for general tracking hits";
254 std::string dett[nTrack_] = {
"Pixel Barrel (High)",
255 "Pixel Endcap (High)",
260 "Pixel Barrel (Low)",
261 "Pixel Endcap (Low)",
270 double nhtMax[nTrack_] = {
271 500., 500., 1000., 1000., 500., 1000., 5000., 2000., 10000., 5000., 2000., 5000., 500., 1000., 1000., 500.};
272 for (
int i = 0;
i < nTrack_;
i++) {
273 sprintf(
name,
"HitTk%d",
i);
274 sprintf(
title,
"Number of hits in %s", dett[
i].c_str());
276 hitTk_[
i]->GetXaxis()->SetTitle(
title);
277 hitTk_[
i]->GetYaxis()->SetTitle(
"Events");
278 sprintf(
name,
"TimeTk%d",
i);
279 sprintf(
title,
"Time of the hit (ns) in %s", dett[
i].c_str());
281 tofTk_[
i]->GetXaxis()->SetTitle(
title);
282 tofTk_[
i]->GetYaxis()->SetTitle(
"Hits");
283 sprintf(
name,
"EdepTk%d",
i);
284 sprintf(
title,
"Energy deposit (GeV) in %s", dett[
i].c_str());
285 double ymax = (
i < 12) ? 0.25 : 0.005;
287 edepTk_[
i]->GetXaxis()->SetTitle(
title);
288 edepTk_[
i]->GetYaxis()->SetTitle(
"Hits");
291 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Completed defining histos for SimHit objects";
297 std::vector<std::string> calonames = {
"EcalHitsEB",
"EcalHitsEE",
"EcalHitsES",
"HcalHits"};
300 desc.addUntracked<std::vector<std::string>>(
"CaloCollection", calonames);
301 desc.addUntracked<
double>(
"MaxEnergy", 200.0);
302 desc.addUntracked<
double>(
"TimeCut", 100.0);
303 desc.addUntracked<
double>(
"MIPCut", 0.70);
304 desc.addUntracked<
bool>(
"StoreRL",
false);
305 desc.addUntracked<
bool>(
"TestNumbering",
true);
306 descriptions.
add(
"CaloSimHitStudy",
desc);
310 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy:Run = " <<
e.id().run() <<
" Event = " <<
e.id().event();
318 double eInc = 0, etaInc = 0, phiInc = 0;
319 HepMC::GenEvent::particle_const_iterator
p = myGenEvent->particles_begin();
320 if (
p != myGenEvent->particles_end()) {
321 eInc = (*p)->momentum().e();
322 etaInc = (*p)->momentum().eta();
323 phiInc = (*p)->momentum().phi();
325 double ptInc = eInc / std::cosh(etaInc);
331 std::vector<PCaloHit> ebHits, eeHits, hcHits;
333 bool getHits =
false;
338 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Input flags Hits " << getHits;
341 std::vector<PCaloHit> caloHits;
342 caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
344 ebHits.insert(ebHits.end(), hitsCalo->begin(), hitsCalo->end());
346 eeHits.insert(eeHits.end(), hitsCalo->begin(), hitsCalo->end());
348 hcHits.insert(hcHits.end(), hitsCalo->begin(), hitsCalo->end());
350 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy: Hit buffer " << caloHits.size();
357 std::vector<PSimHit> muonHits;
361 muonHits.insert(muonHits.end(), hitsTrack->begin(), hitsTrack->end());
365 unsigned int nhmu = muonHits.size();
366 hitMu->Fill(
double(nhmu));
367 std::vector<PSimHit> tkHighHits;
371 tkHighHits.insert(tkHighHits.end(), hitsTrack->begin(), hitsTrack->end());
375 unsigned int nhtkh = tkHighHits.size();
377 std::vector<PSimHit> tkLowHits;
381 tkLowHits.insert(tkLowHits.end(), hitsTrack->begin(), hitsTrack->end());
385 unsigned int nhtkl = tkLowHits.size();
386 hitLow->Fill(
double(nhtkl));
390 int nHit =
hits.size();
391 int nHB(0), nHE(0), nHO(0), nHF(0), nEB(0), nEBAPD(0), nEBATJ(0), nEE(0), nES(0);
395 std::map<unsigned int, double> hitMap;
397 for (
int i = 0;
i < nHit;
i++) {
398 double edep =
hits[
i].energy();
400 unsigned int id =
hits[
i].id();
401 double edepEM =
hits[
i].energyEM();
402 double edepHad =
hits[
i].energyHad();
410 std::map<unsigned int, double>::const_iterator it = hitMap.find(
id);
411 if (it == hitMap.end()) {
412 hitMap.insert(std::pair<unsigned int, double>(
id,
time));
441 if (indx >= 0 && indx < 3) {
457 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
460 }
else if (subdet == static_cast<int>(
HcalOuter)) {
463 }
else if (subdet == static_cast<int>(
HcalForward)) {
483 etot_[indx + 2]->Fill(etot[indx + 2]);
484 etotg_[indx + 2]->Fill(etotG[indx + 2]);
486 etot_[indx]->Fill(etot[indx]);
487 etotg_[indx]->Fill(etotG[indx]);
488 etot_[indx + 1]->Fill(etot[indx + 1]);
489 etotg_[indx + 1]->Fill(etotG[indx + 1]);
490 hit_[indx]->Fill(
double(nEB));
491 hit_[indx + 1]->Fill(
double(nEBAPD));
492 hit_[indx + 2]->Fill(
double(nEBATJ));
494 hit_[indx + 2]->Fill(
double(nHit));
496 }
else if (indx == 3) {
497 hit_[5]->Fill(
double(nHB));
498 hit_[6]->Fill(
double(nHE));
499 hit_[7]->Fill(
double(nHO));
500 hit_[8]->Fill(
double(nHF));
508 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy::analyzeHits: EB " << nEB <<
", " << nEBAPD <<
", " << nEBATJ
509 <<
" EE " << nEE <<
" ES " << nES <<
" HB " << nHB <<
" HE " << nHE <<
" HO " << nHO
510 <<
" HF " << nHF <<
" Bad " << nBad <<
" All " << nHit <<
" Reduced " << hitMap.size();
512 std::map<unsigned int, double>::const_iterator it = hitMap.begin();
513 for (; it != hitMap.end(); it++) {
514 double time = it->second;
522 if ((
id & 0x20000) != 0)
524 else if ((
id & 0x40000) != 0)
533 }
else if (indx == 3) {
534 int idx(-1), subdet(0);
543 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
545 }
else if (subdet == static_cast<int>(
HcalOuter)) {
547 }
else if (subdet == static_cast<int>(
HcalForward)) {
561 edm::PSimHitContainer::const_iterator ihit;
563 if (indx >= 0 && indx < 6)
565 else if (indx >= 6 && indx < 12)
567 else if (indx >= 12 && indx <
nTrack_)
569 for (ihit =
hits->begin(); ihit !=
hits->end(); ihit++) {
570 edepTk_[indx]->Fill(ihit->energyLoss());
571 tofTk_[indx]->Fill(ihit->timeOfFlight());
574 hitTk_[indx]->Fill(
float(nHit));
576 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy::analyzeHits: for " <<
label <<
" Index " << indx <<
" # of Hits " 582 std::vector<PCaloHit>& eeHits,
583 std::vector<PCaloHit>& hcHits) {
584 double edepEB = 0, edepEBT = 0;
585 for (
unsigned int i = 0;
i < ebHits.size();
i++) {
586 double edep = ebHits[
i].energy();
587 double time = ebHits[
i].time();
594 double edepEE = 0, edepEET = 0;
595 for (
unsigned int i = 0;
i < eeHits.size();
i++) {
596 double edep = eeHits[
i].energy();
597 double time = eeHits[
i].time();
602 double edepH = 0, edepHT = 0, edepHO = 0, edepHOT = 0;
603 for (
unsigned int i = 0;
i < hcHits.size();
i++) {
604 double edep = hcHits[
i].energy();
605 double time = hcHits[
i].time();
612 subdet =
id.subdet();
618 }
else if (subdet == static_cast<int>(
HcalOuter)) {
624 double edepE = edepEB + edepEE;
625 double edepET = edepEBT + edepEET;
626 double edepHC = edepH + edepHO;
627 double edepHCT = edepHT + edepHOT;
629 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitStudy::energy in EB " << edepEB <<
" (" << edepEBT <<
") from " 630 << ebHits.size() <<
" hits; " 631 <<
" energy in EE " << edepEE <<
" (" << edepEET <<
") from " << eeHits.size()
632 <<
" hits; energy in HC " << edepH <<
", " << edepHO <<
" (" << edepHT <<
", " << edepHOT
633 <<
") from " << hcHits.size() <<
" hits";
650 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)
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
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_
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
static const int kEcalDepthIdMask