68 std::vector<edm::EDGetTokenT<edm::PCaloHitContainer> >
toks_calo_;
87 : g4Label_(ps.getUntrackedParameter<
std::
string>(
"moduleLabel",
"g4SimHits")),
89 timeSliceUnit_(ps.getParameter<
std::
vector<double> >(
"timeSliceUnit")),
90 maxEnergy_(ps.getUntrackedParameter<double>(
"maxEnergy", 250.0)),
91 maxTime_(ps.getUntrackedParameter<double>(
"maxTime", 1000.0)),
92 tMax_(ps.getUntrackedParameter<double>(
"timeCut", 100.0)),
93 tScale_(ps.getUntrackedParameter<double>(
"timeScale", 1.0)),
94 tCut_(ps.getUntrackedParameter<double>(
"timeThreshold", 15.0)),
95 testNumber_(ps.getUntrackedParameter<
bool>(
"testNumbering",
false)),
96 passive_(ps.getUntrackedParameter<
bool>(
"passiveHits",
false)),
97 allSteps_(ps.getUntrackedParameter<
int>(
"allSteps", 100)),
103 for (
unsigned int i = 0;
i <
hitLab_.size();
i++)
108 for (
unsigned int i = 0;
i <
hitLab_.size();
i++)
116 if (!
tfile.isAvailable())
118 <<
"please add it to config file";
122 sprintf(
name,
"Hit%d",
i);
123 sprintf(
title,
"Number of hits in %s", dets[
i].c_str());
126 h_hit_[
i]->GetYaxis()->SetTitle(
"Events");
127 sprintf(
name,
"Time%d",
i);
128 sprintf(
title,
"Time of the hit (ns) in %s", dets[
i].c_str());
131 h_time_[
i]->GetYaxis()->SetTitle(
"Hits");
132 sprintf(
name,
"TimeT%d",
i);
133 sprintf(
title,
"Time of each hit (ns) in %s", dets[
i].c_str());
136 h_timeT_[
i]->GetYaxis()->SetTitle(
"Hits");
137 double ymax = (
i > 1) ? 0.01 : 0.1;
138 double ymx0 = (
i > 1) ? 0.0025 : 0.025;
139 sprintf(
name,
"Edep%d",
i);
140 sprintf(
title,
"Energy deposit (GeV) in %s", dets[
i].c_str());
143 h_edep_[
i]->GetYaxis()->SetTitle(
"Hits");
144 sprintf(
name,
"EdepT%d",
i);
145 sprintf(
title,
"Energy deposit (GeV) of each hit in %s", dets[
i].c_str());
148 h_edepT_[
i]->GetYaxis()->SetTitle(
"Hits");
149 sprintf(
name,
"EdepEM%d",
i);
150 sprintf(
title,
"Energy deposit (GeV) by EM particles in %s", dets[
i].c_str());
154 sprintf(
name,
"EdepHad%d",
i);
155 sprintf(
title,
"Energy deposit (GeV) by hadrons in %s", dets[
i].c_str());
159 sprintf(
name,
"Edep15%d",
i);
160 sprintf(
title,
"Energy deposit (GeV) for T > %4.0f ns in %s",
tCut_, dets[
i].c_str());
163 h_edep1_[
i]->GetYaxis()->SetTitle(
"Hits");
164 sprintf(
name,
"EdepT15%d",
i);
165 sprintf(
title,
"Energy deposit (GeV) of each hit for T > %4.0f in %s",
tCut_, dets[
i].c_str());
170 sprintf(
name,
"Etot%d",
i);
171 sprintf(
title,
"Total energy deposit (GeV) in %s", dets[
i].c_str());
174 h_etot_[
i]->GetYaxis()->SetTitle(
"Events");
175 sprintf(
name,
"EtotG%d",
i);
176 sprintf(
title,
"Total energy deposit (GeV) in %s (t < 100 ns)", dets[
i].c_str());
179 h_etotg_[
i]->GetYaxis()->SetTitle(
"Events");
180 sprintf(
name,
"rr%d",
i);
181 sprintf(
title,
"R of hit point (cm) in %s", dets[
i].c_str());
184 h_rr_[
i]->GetYaxis()->SetTitle(
"Hits");
185 sprintf(
name,
"zz%d",
i);
186 sprintf(
title,
"z of hit point (cm) in %s", dets[
i].c_str());
189 h_zz_[
i]->GetYaxis()->SetTitle(
"Hits");
190 sprintf(
name,
"eta%d",
i);
191 sprintf(
title,
"#eta of hit point in %s", dets[
i].c_str());
194 h_eta_[
i]->GetYaxis()->SetTitle(
"Hits");
195 sprintf(
name,
"phi%d",
i);
196 sprintf(
title,
"#phi of hit point in %s", dets[
i].c_str());
199 h_phi_[
i]->GetYaxis()->SetTitle(
"Hits");
201 sprintf(
title,
"R vs Z of hit point");
203 h_rz_->GetXaxis()->SetTitle(
"z (cm)");
204 h_rz_->GetYaxis()->SetTitle(
"R (cm)");
205 sprintf(
title,
"R vs Z of hit point for hits with T > %4.0f ns",
tCut_);
207 h_rz1_->GetXaxis()->SetTitle(
"z (cm)");
208 h_rz1_->GetYaxis()->SetTitle(
"R (cm)");
209 sprintf(
title,
"#phi vs #eta of hit point");
215 h_hitp_ =
tfile->make<TH1F>(
"hitp",
"All Steps", 100, 0.0, 20000.0);
216 h_hitp_->GetXaxis()->SetTitle(
"Hits");
217 h_hitp_->GetYaxis()->SetTitle(
"Events");
218 h_trackp_ =
tfile->make<TH1F>(
"trackp",
"All Steps", 100, 0.0, 200000.0);
219 h_hitp_->GetXaxis()->SetTitle(
"Tracks");
220 h_hitp_->GetYaxis()->SetTitle(
"Events");
221 h_edepp_ =
tfile->make<TH1F>(
"edepp",
"All Steps", 100, 0.0, 50.0);
222 h_edepp_->GetXaxis()->SetTitle(
"Energy Deposit (MeV)");
223 h_edepp_->GetYaxis()->SetTitle(
"Hits");
224 h_timep_ =
tfile->make<TH1F>(
"timep",
"All Steps", 100, 0.0, 100.0);
225 h_timep_->GetXaxis()->SetTitle(
"Hits");
226 h_timep_->GetYaxis()->SetTitle(
"Hit Time (ns)");
227 h_stepp_ =
tfile->make<TH1F>(
"stepp",
"All Steps", 1000, 0.0, 100.0);
228 h_stepp_->GetXaxis()->SetTitle(
"Hits");
229 h_stepp_->GetYaxis()->SetTitle(
"Step length (cm)");
231 sprintf(
name,
"edept%d",
k);
234 h_edepTk_.back()->GetYaxis()->SetTitle(
"Hits");
236 sprintf(
name,
"timet%d",
k);
239 h_timeTk_.back()->GetYaxis()->SetTitle(
"Hits");
244 int dmax = (
eta < 16) ? 4 : 7;
247 sprintf(
title,
"R vs Z (#eta = %d, depth = %d)",
eta,
depth);
250 h_rzH_.back()->GetXaxis()->SetTitle(
"z (cm)");
251 h_rzH_.back()->GetYaxis()->SetTitle(
"R (cm)");
260 std::vector<std::string>
labels = {
"EcalHitsEB1",
"EcalHitsEE1",
"HcalHits1"};
261 std::vector<double> times = {1, 1, 1};
263 desc.add<std::vector<std::string> >(
"hitCollection",
labels);
264 desc.add<std::vector<double> >(
"timeSliceUnit", times);
265 desc.addUntracked<
double>(
"maxEnergy", 250.0);
266 desc.addUntracked<
double>(
"maxTime", 1000.0);
267 desc.addUntracked<
double>(
"timeCut", 100.0);
268 desc.addUntracked<
double>(
"timeScale", 1.0);
269 desc.addUntracked<
double>(
"timeThreshold", 15.0);
270 desc.addUntracked<
bool>(
"testNumbering",
false);
271 desc.addUntracked<
bool>(
"passiveHits",
false);
272 std::vector<std::string>
names = {
"PixelBarrel",
"PixelForward",
"TIB",
"TID",
"TOB",
"TEC"};
273 desc.addUntracked<std::vector<std::string> >(
"detNames",
names);
274 desc.addUntracked<
int>(
"allStep", 100);
275 descriptions.
add(
"caloSimHitAnalysis",
desc);
279 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis:Run = " <<
e.id().run() <<
" Event = " <<
e.id().event();
287 bool getHits = (hitsCalo.
isValid());
289 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis: Input flags Hits[" <<
i <<
"]: " << getHits;
292 std::vector<PCaloHit> caloHits;
293 caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
295 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis: Hit buffer [" <<
i <<
"] " << caloHits.size();
304 bool getHits = (hitsPassive.
isValid());
309 std::vector<PassiveHit> passiveHits;
310 passiveHits.insert(passiveHits.end(), hitsPassive->begin(), hitsPassive->end());
312 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis: Passive Hit buffer " << passiveHits.size();
320 int nHit =
hits.size();
321 int nHB = 0, nHE = 0, nHO = 0, nHF = 0, nEB = 0, nEE = 0, nBad = 0, iHit = 0;
322 std::map<CaloHitID, std::pair<double, double> > hitMap;
324 for (
unsigned int k = 0;
k <
nCalo_; ++
k) {
325 etot[
k] = etotG[
k] = 0;
328 double edep =
hit.energy();
330 uint32_t
id =
hit.
id();
331 int itra =
hit.geantTrackId();
332 double edepEM =
hit.energyEM();
333 double edepHad =
hit.energyHad();
353 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
356 }
else if (subdet == static_cast<int>(
HcalOuter)) {
359 }
else if (subdet == static_cast<int>(
HcalForward)) {
365 edm::LogVerbatim(
"HitStudy") <<
"Hit[" << iHit <<
":" << nHit <<
":" <<
idx <<
"] E " << edep <<
":" << edepEM
366 <<
":" << edepHad <<
" T " <<
time <<
" itra " << itra <<
" ID " << std::hex <<
id
372 auto itr = hitMap.find(hid);
373 if (itr == hitMap.end())
374 hitMap[hid] = std::make_pair(
time, edep);
376 ((itr->second).second) += edep;
391 for (
auto itr = hitMap.begin(); itr != hitMap.end(); ++itr) {
394 DetId id((itr->first).unitID());
397 << std::hex <<
id.rawId() <<
std::dec;
403 int subdet =
id.subdetId();
406 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
408 }
else if (subdet == static_cast<int>(
HcalOuter)) {
410 }
else if (subdet == static_cast<int>(
HcalForward)) {
415 double edep = (itr->second).
second;
441 h_etot_[indx]->Fill(etot[indx]);
444 h_hit_[indx]->Fill(
double(nEB));
446 h_hit_[indx]->Fill(
double(nEE));
448 h_hit_[2]->Fill(
double(nHB));
449 h_hit_[3]->Fill(
double(nHE));
450 h_hit_[4]->Fill(
double(nHO));
451 h_hit_[5]->Fill(
double(nHF));
458 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis::analyzeHits: EB " << nEB <<
" EE " << nEE <<
" HB " << nHB
459 <<
" HE " << nHE <<
" HO " << nHO <<
" HF " << nHF <<
" Bad " << nBad <<
" All " << nHit
460 <<
" Reduced " << hitMap.size();
466 std::map<std::pair<std::string, uint32_t>,
int> hitx;
467 std::map<int, int>
tracks;
468 unsigned int passive1(0), passive2(0);
471 std::pair<std::string, uint32_t> volume = std::make_pair(
name, (
hit.
id() % 1000000));
472 auto itr = hitx.find(volume);
473 if (itr == hitx.end())
485 if ((
name.find(active) != std::string::npos) || (
name.find(sensor) != std::string::npos)) {
500 uint32_t
id =
hit.
id();
506 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis::ID: " << hid <<
" Index " << indx <<
" Iterator "
511 uint32_t ipos = itr->second;
513 if (ipos <
h_rzH_.size()) {
523 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis::analyzPassiveHits: Total " <<
hits.size() <<
" Cells "
524 << hitx.size() <<
" Tracks " <<
tracks.size() <<
" Passive " << passive1 <<
":"