69 const std::vector<edm::EDGetTokenT<edm::PCaloHitContainer> >
toks_calo_;
88 : g4Label_(ps.getUntrackedParameter<
std::
string>(
"moduleLabel",
"g4SimHits")),
90 timeSliceUnit_(ps.getParameter<
std::
vector<double> >(
"timeSliceUnit")),
91 maxEnergy_(ps.getUntrackedParameter<double>(
"maxEnergy", 250.0)),
92 maxTime_(ps.getUntrackedParameter<double>(
"maxTime", 1000.0)),
93 tMax_(ps.getUntrackedParameter<double>(
"timeCut", 100.0)),
94 tScale_(ps.getUntrackedParameter<double>(
"timeScale", 1.0)),
95 tCut_(ps.getUntrackedParameter<double>(
"timeThreshold", 15.0)),
96 testNumber_(ps.getUntrackedParameter<
bool>(
"testNumbering",
false)),
97 passive_(ps.getUntrackedParameter<
bool>(
"passiveHits",
false)),
98 allSteps_(ps.getUntrackedParameter<
int>(
"allSteps", 100)),
105 tok_passive_(consumes<edm::PassiveHitContainer>(
edm::InputTag(g4Label_,
"AllPassiveHits"))) {
108 edm::LogVerbatim(
"HitStudy") <<
"Module Label: " << g4Label_ <<
" Hits|timeSliceUnit:";
109 for (
unsigned int i = 0;
i < hitLab_.size();
i++)
110 edm::LogVerbatim(
"HitStudy") <<
"[" <<
i <<
"] " << hitLab_[
i] <<
" " << timeSliceUnit_[
i];
111 edm::LogVerbatim(
"HitStudy") <<
"Passive Hits " << passive_ <<
" from AllPassiveHits";
112 edm::LogVerbatim(
"HitStudy") <<
"maxEnergy: " << maxEnergy_ <<
" maxTime: " << maxTime_ <<
" tMax: " << tMax_;
113 for (
unsigned int k = 0;
k < detNames_.size(); ++
k)
117 if (!
tfile.isAvailable())
119 <<
"please add it to config file";
121 std::string dets[nCalo_] = {
"EB",
"EE",
"HB",
"HE",
"HO",
"HF"};
122 for (
int i = 0;
i < nCalo_;
i++) {
123 sprintf(
name,
"Hit%d",
i);
124 sprintf(
title,
"Number of hits in %s", dets[
i].c_str());
126 h_hit_[
i]->GetXaxis()->SetTitle(
title);
127 h_hit_[
i]->GetYaxis()->SetTitle(
"Events");
128 sprintf(
name,
"Time%d",
i);
129 sprintf(
title,
"Time of the hit (ns) in %s", dets[
i].c_str());
131 h_time_[
i]->GetXaxis()->SetTitle(
title);
132 h_time_[
i]->GetYaxis()->SetTitle(
"Hits");
133 sprintf(
name,
"TimeT%d",
i);
134 sprintf(
title,
"Time of each hit (ns) in %s", dets[
i].c_str());
136 h_timeT_[
i]->GetXaxis()->SetTitle(
title);
137 h_timeT_[
i]->GetYaxis()->SetTitle(
"Hits");
138 double ymax = (
i > 1) ? 0.01 : 0.1;
139 double ymx0 = (
i > 1) ? 0.0025 : 0.025;
140 sprintf(
name,
"Edep%d",
i);
141 sprintf(
title,
"Energy deposit (GeV) in %s", dets[
i].c_str());
143 h_edep_[
i]->GetXaxis()->SetTitle(
title);
144 h_edep_[
i]->GetYaxis()->SetTitle(
"Hits");
145 sprintf(
name,
"EdepT%d",
i);
146 sprintf(
title,
"Energy deposit (GeV) of each hit in %s", dets[
i].c_str());
148 h_edepT_[
i]->GetXaxis()->SetTitle(
title);
149 h_edepT_[
i]->GetYaxis()->SetTitle(
"Hits");
150 sprintf(
name,
"EdepEM%d",
i);
151 sprintf(
title,
"Energy deposit (GeV) by EM particles in %s", dets[
i].c_str());
153 h_edepEM_[
i]->GetXaxis()->SetTitle(
title);
154 h_edepEM_[
i]->GetYaxis()->SetTitle(
"Hits");
155 sprintf(
name,
"EdepHad%d",
i);
156 sprintf(
title,
"Energy deposit (GeV) by hadrons in %s", dets[
i].c_str());
158 h_edepHad_[
i]->GetXaxis()->SetTitle(
title);
159 h_edepHad_[
i]->GetYaxis()->SetTitle(
"Hits");
160 sprintf(
name,
"Edep15%d",
i);
161 sprintf(
title,
"Energy deposit (GeV) for T > %4.0f ns in %s", tCut_, dets[
i].c_str());
163 h_edep1_[
i]->GetXaxis()->SetTitle(
title);
164 h_edep1_[
i]->GetYaxis()->SetTitle(
"Hits");
165 sprintf(
name,
"EdepT15%d",
i);
166 sprintf(
title,
"Energy deposit (GeV) of each hit for T > %4.0f in %s", tCut_, dets[
i].c_str());
168 h_edepT1_[
i]->GetXaxis()->SetTitle(
title);
169 h_edepT1_[
i]->GetYaxis()->SetTitle(
"Hits");
170 ymax = (
i > 1) ? 1.0 : maxEnergy_;
171 sprintf(
name,
"Etot%d",
i);
172 sprintf(
title,
"Total energy deposit (GeV) in %s", dets[
i].c_str());
174 h_etot_[
i]->GetXaxis()->SetTitle(
title);
175 h_etot_[
i]->GetYaxis()->SetTitle(
"Events");
176 sprintf(
name,
"EtotG%d",
i);
177 sprintf(
title,
"Total energy deposit (GeV) in %s (t < 100 ns)", dets[
i].c_str());
179 h_etotg_[
i]->GetXaxis()->SetTitle(
title);
180 h_etotg_[
i]->GetYaxis()->SetTitle(
"Events");
181 sprintf(
name,
"rr%d",
i);
182 sprintf(
title,
"R of hit point (cm) in %s", dets[
i].c_str());
184 h_rr_[
i]->GetXaxis()->SetTitle(
title);
185 h_rr_[
i]->GetYaxis()->SetTitle(
"Hits");
186 sprintf(
name,
"zz%d",
i);
187 sprintf(
title,
"z of hit point (cm) in %s", dets[
i].c_str());
189 h_zz_[
i]->GetXaxis()->SetTitle(
title);
190 h_zz_[
i]->GetYaxis()->SetTitle(
"Hits");
191 sprintf(
name,
"eta%d",
i);
192 sprintf(
title,
"#eta of hit point in %s", dets[
i].c_str());
194 h_eta_[
i]->GetXaxis()->SetTitle(
title);
195 h_eta_[
i]->GetYaxis()->SetTitle(
"Hits");
196 sprintf(
name,
"phi%d",
i);
197 sprintf(
title,
"#phi of hit point in %s", dets[
i].c_str());
199 h_phi_[
i]->GetXaxis()->SetTitle(
title);
200 h_phi_[
i]->GetYaxis()->SetTitle(
"Hits");
202 sprintf(
title,
"R vs Z of hit point");
203 h_rz_ =
tfile->make<TH2F>(
"rz",
title, 120, 0., 600., 100, 0., 250.);
204 h_rz_->GetXaxis()->SetTitle(
"z (cm)");
205 h_rz_->GetYaxis()->SetTitle(
"R (cm)");
206 sprintf(
title,
"R vs Z of hit point for hits with T > %4.0f ns", tCut_);
207 h_rz1_ =
tfile->make<TH2F>(
"rz2",
title, 120, 0., 600., 100, 0., 250.);
208 h_rz1_->GetXaxis()->SetTitle(
"z (cm)");
209 h_rz1_->GetYaxis()->SetTitle(
"R (cm)");
210 sprintf(
title,
"#phi vs #eta of hit point");
211 h_etaphi_ =
tfile->make<TH2F>(
"etaphi",
title, 100, 0., 5., 100, 0.,
M_PI);
212 h_etaphi_->GetXaxis()->SetTitle(
"#eta");
213 h_etaphi_->GetYaxis()->SetTitle(
"#phi");
216 h_hitp_ =
tfile->make<TH1F>(
"hitp",
"All Steps", 100, 0.0, 20000.0);
217 h_hitp_->GetXaxis()->SetTitle(
"Hits");
218 h_hitp_->GetYaxis()->SetTitle(
"Events");
219 h_trackp_ =
tfile->make<TH1F>(
"trackp",
"All Steps", 100, 0.0, 200000.0);
220 h_hitp_->GetXaxis()->SetTitle(
"Tracks");
221 h_hitp_->GetYaxis()->SetTitle(
"Events");
222 h_edepp_ =
tfile->make<TH1F>(
"edepp",
"All Steps", 100, 0.0, 50.0);
223 h_edepp_->GetXaxis()->SetTitle(
"Energy Deposit (MeV)");
224 h_edepp_->GetYaxis()->SetTitle(
"Hits");
225 h_timep_ =
tfile->make<TH1F>(
"timep",
"All Steps", 100, 0.0, 100.0);
226 h_timep_->GetXaxis()->SetTitle(
"Hits");
227 h_timep_->GetYaxis()->SetTitle(
"Hit Time (ns)");
228 h_stepp_ =
tfile->make<TH1F>(
"stepp",
"All Steps", 1000, 0.0, 100.0);
229 h_stepp_->GetXaxis()->SetTitle(
"Hits");
230 h_stepp_->GetYaxis()->SetTitle(
"Step length (cm)");
231 for (
unsigned int k = 0;
k < detNames_.size(); ++
k) {
232 sprintf(
name,
"edept%d",
k);
233 sprintf(
title,
"Energy Deposit (MeV) in %s", detNames_[
k].c_str());
234 h_edepTk_.emplace_back(
tfile->make<TH1F>(
name,
title, 100, 0.0, 1.0));
235 h_edepTk_.back()->GetYaxis()->SetTitle(
"Hits");
236 h_edepTk_.back()->GetXaxis()->SetTitle(
title);
237 sprintf(
name,
"timet%d",
k);
238 sprintf(
title,
"Hit Time (ns) in %s", detNames_[
k].c_str());
239 h_timeTk_.emplace_back(
tfile->make<TH1F>(
name,
title, 100, 0.0, 100.0));
240 h_timeTk_.back()->GetYaxis()->SetTitle(
"Hits");
241 h_timeTk_.back()->GetXaxis()->SetTitle(
title);
243 if ((allSteps_ / 100) % 10 > 0) {
245 int dmax = (
eta < 16) ? 4 : 7;
248 sprintf(
title,
"R vs Z (#eta = %d, depth = %d)",
eta,
depth);
249 etaDepth_[
eta * 100 +
depth] = h_rzH_.size();
250 h_rzH_.emplace_back(
tfile->make<TH2F>(
name,
title, 120, 0., 600., 100, 0., 250.));
251 h_rzH_.back()->GetXaxis()->SetTitle(
"z (cm)");
252 h_rzH_.back()->GetYaxis()->SetTitle(
"R (cm)");
261 std::vector<std::string>
labels = {
"EcalHitsEB1",
"EcalHitsEE1",
"HcalHits1"};
262 std::vector<double> times = {1, 1, 1};
264 desc.add<std::vector<std::string> >(
"hitCollection",
labels);
265 desc.add<std::vector<double> >(
"timeSliceUnit", times);
266 desc.addUntracked<
double>(
"maxEnergy", 250.0);
267 desc.addUntracked<
double>(
"maxTime", 1000.0);
268 desc.addUntracked<
double>(
"timeCut", 100.0);
269 desc.addUntracked<
double>(
"timeScale", 1.0);
270 desc.addUntracked<
double>(
"timeThreshold", 15.0);
271 desc.addUntracked<
bool>(
"testNumbering",
false);
272 desc.addUntracked<
bool>(
"passiveHits",
false);
273 std::vector<std::string>
names = {
"PixelBarrel",
"PixelForward",
"TIB",
"TID",
"TOB",
"TEC"};
274 desc.addUntracked<std::vector<std::string> >(
"detNames",
names);
275 desc.addUntracked<
int>(
"allStep", 100);
276 descriptions.
add(
"caloSimHitAnalysis",
desc);
280 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();
303 bool getHits = (hitsPassive.
isValid());
308 std::vector<PassiveHit> passiveHits;
309 passiveHits.insert(passiveHits.end(), hitsPassive->begin(), hitsPassive->end());
311 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis: Passive Hit buffer " << passiveHits.size();
319 int nHit =
hits.size();
320 int nHB = 0, nHE = 0, nHO = 0, nHF = 0, nEB = 0, nEE = 0, nBad = 0;
325 std::map<CaloHitID, std::pair<double, double> > hitMap;
327 for (
unsigned int k = 0;
k <
nCalo_; ++
k) {
328 etot[
k] = etotG[
k] = 0;
331 double edep =
hit.energy();
333 uint32_t
id =
hit.
id();
334 int itra =
hit.geantTrackId();
335 double edepEM =
hit.energyEM();
336 double edepHad =
hit.energyHad();
356 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
359 }
else if (subdet == static_cast<int>(
HcalOuter)) {
362 }
else if (subdet == static_cast<int>(
HcalForward)) {
368 edm::LogVerbatim(
"HitStudy") <<
"Hit[" << iHit <<
":" << nHit <<
":" <<
idx <<
"] E " << edep <<
":" << edepEM
369 <<
":" << edepHad <<
" T " <<
time <<
" itra " << itra <<
" ID " << std::hex <<
id 375 auto itr = hitMap.find(hid);
376 if (itr == hitMap.end())
377 hitMap[hid] = std::make_pair(
time, edep);
379 ((itr->second).second) += edep;
394 for (
auto itr = hitMap.begin(); itr != hitMap.end(); ++itr) {
397 DetId id((itr->first).unitID());
400 << std::hex <<
id.rawId() <<
std::dec;
406 int subdet =
id.subdetId();
409 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
411 }
else if (subdet == static_cast<int>(
HcalOuter)) {
413 }
else if (subdet == static_cast<int>(
HcalForward)) {
418 double edep = (itr->second).
second;
444 h_etot_[indx]->Fill(etot[indx]);
447 h_hit_[indx]->Fill(
double(nEB));
449 h_hit_[indx]->Fill(
double(nEE));
451 h_hit_[2]->Fill(
double(nHB));
452 h_hit_[3]->Fill(
double(nHE));
453 h_hit_[4]->Fill(
double(nHO));
454 h_hit_[5]->Fill(
double(nHF));
461 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis::analyzeHits: EB " << nEB <<
" EE " << nEE <<
" HB " << nHB
462 <<
" HE " << nHE <<
" HO " << nHO <<
" HF " << nHF <<
" Bad " << nBad <<
" All " << nHit
463 <<
" Reduced " << hitMap.size();
469 std::map<std::pair<std::string, uint32_t>,
int> hitx;
470 std::map<int, int>
tracks;
471 unsigned int passive1(0), passive2(0);
474 std::pair<std::string, uint32_t> volume = std::make_pair(
name, (
hit.
id() % 1000000));
475 auto itr = hitx.find(volume);
476 if (itr == hitx.end())
488 if ((
name.find(active) != std::string::npos) || (
name.find(sensor) != std::string::npos)) {
503 uint32_t
id =
hit.
id();
509 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis::ID: " << hid <<
" Index " << indx <<
" Iterator " 514 uint32_t ipos = itr->second;
516 if (ipos <
h_rzH_.size()) {
526 edm::LogVerbatim(
"HitStudy") <<
"CaloSimHitAnalysis::analyzPassiveHits: Total " <<
hits.size() <<
" Cells " 527 << hitx.size() <<
" Tracks " <<
tracks.size() <<
" Passive " << passive1 <<
":" void analyzeHits(std::vector< PCaloHit > &, int)
static const std::string kSharedResource
Log< level::Info, true > LogVerbatim
std::map< int, unsigned int > etaDepth_
void analyzePassiveHits(std::vector< PassiveHit > &hits)
constexpr int ietaAbs() const
get the absolute value of the cell ieta
const std::vector< std::string > hitLab_
CaloSimHitAnalysis(const edm::ParameterSet &ps)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< TH1F * > h_edepTk_
std::vector< TH1F * > h_timeTk_
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 >
const std::string names[nVars_]
const std::string g4Label_
const std::vector< std::string > detNames_
U second(std::pair< T, U > const &p)
constexpr HcalSubdetector subdet() const
get the subdetector
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tokGeom_
void endRun(edm::Run const &, edm::EventSetup const &) override
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
const edm::EDGetTokenT< edm::PassiveHitContainer > tok_passive_
TH1F * h_edepHad_[nCalo_]
Abs< T >::type abs(const T &t)
static constexpr int nCalo_
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
const HcalGeometry * hcalGeom_
#define DEFINE_FWK_MODULE(type)
const CaloGeometry * caloGeometry_
const std::vector< edm::EDGetTokenT< edm::PCaloHitContainer > > toks_calo_
void beginRun(edm::Run const &, edm::EventSetup const &) override
constexpr uint32_t rawId() const
get the raw id
const std::vector< double > timeSliceUnit_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< TH2F * > h_rzH_
void analyze(edm::Event const &, edm::EventSetup const &) override
GlobalPoint getPosition(const DetId &id) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
*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
~CaloSimHitAnalysis() override
constexpr int depth() const
get the tower depth