72 const std::vector<edm::EDGetTokenT<edm::PCaloHitContainer>>
toks_calo_;
85 g4Label_(ps.getUntrackedParameter<
std::
string>(
"ModuleLabel",
"g4SimHits")),
87 maxEnergy_(ps.getUntrackedParameter<double>(
"MaxEnergy", 200.0)),
88 tmax_(ps.getUntrackedParameter<double>(
"TimeCut", 100.0)),
89 w0_(ps.getUntrackedParameter<double>(
"W0", 4.7)),
90 selX_(ps.getUntrackedParameter<
int>(
"SelectX", -1)),
98 edm::LogVerbatim(
"HitStudy") <<
"Module Label: " << g4Label_ <<
" Hits: " << hitLab_[0] <<
", " << hitLab_[1]
99 <<
" MaxEnergy: " << maxEnergy_ <<
" Tmax: " << tmax_ <<
" Select " << selX_;
104 std::vector<std::string> calonames;
106 desc.addUntracked<std::vector<std::string>>(
"CaloCollection", calonames);
108 desc.addUntracked<
double>(
"MaxEnergy", 200.0);
109 desc.addUntracked<
double>(
"TimeCut", 100.0);
110 desc.addUntracked<
int>(
"SelectX", -1);
111 descriptions.
add(
"EcalSimHitStudy",
desc);
116 if (!
tfile.isAvailable())
118 <<
"please add it to config file";
120 sprintf(
title,
"Incident PT (GeV)");
123 ptInc_->GetYaxis()->SetTitle(
"Events");
124 sprintf(
title,
"Incident Energy (GeV)");
127 eneInc_->GetYaxis()->SetTitle(
"Events");
128 sprintf(
title,
"Incident #eta");
131 etaInc_->GetYaxis()->SetTitle(
"Events");
132 sprintf(
title,
"Incident #phi");
135 phiInc_->GetYaxis()->SetTitle(
"Events");
138 sprintf(
name,
"Hit%d",
i);
139 sprintf(
title,
"Number of hits in %s", dets[
i].c_str());
142 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");
150 sprintf(
name,
"TimeAll%d",
i);
151 sprintf(
title,
"Hit time (ns) in %s (for first hit in the cell)", dets[
i].c_str());
154 timeAll_[
i]->GetYaxis()->SetTitle(
"Hits");
156 sprintf(
name,
"Edep%d",
i);
157 sprintf(
title,
"Energy deposit (GeV) in %s", dets[
i].c_str());
160 edep_[
i]->GetYaxis()->SetTitle(
"Hits");
162 sprintf(
name,
"EdepAll%d",
i);
163 sprintf(
title,
"Total Energy deposit in the cell (GeV) in %s", dets[
i].c_str());
166 edepAll_[
i]->GetYaxis()->SetTitle(
"Hits");
168 sprintf(
name,
"EdepEM%d",
i);
169 sprintf(
title,
"Energy deposit (GeV) by EM particles in %s", dets[
i].c_str());
172 edepEM_[
i]->GetYaxis()->SetTitle(
"Hits");
174 sprintf(
name,
"EdepHad%d",
i);
175 sprintf(
title,
"Energy deposit (GeV) by hadrons in %s", dets[
i].c_str());
178 edepHad_[
i]->GetYaxis()->SetTitle(
"Hits");
180 sprintf(
name,
"Etot%d",
i);
181 sprintf(
title,
"Total energy deposit (GeV) in %s", dets[
i].c_str());
184 etot_[
i]->GetYaxis()->SetTitle(
"Events");
186 sprintf(
name,
"EtotG%d",
i);
187 sprintf(
title,
"Total energy deposit (GeV) in %s (t < 100 ns)", dets[
i].c_str());
190 etotg_[
i]->GetYaxis()->SetTitle(
"Events");
192 sprintf(
name,
"r1by9%d",
i);
193 sprintf(
title,
"E1/E9 in %s", dets[
i].c_str());
196 r1by9_[
i]->GetYaxis()->SetTitle(
"Events");
198 sprintf(
name,
"r1by25%d",
i);
199 sprintf(
title,
"E1/E25 in %s", dets[
i].c_str());
202 r1by25_[
i]->GetYaxis()->SetTitle(
"Events");
204 sprintf(
name,
"r9by25%d",
i);
205 sprintf(
title,
"E9/E25 in %s", dets[
i].c_str());
208 r9by25_[
i]->GetYaxis()->SetTitle(
"Events");
210 double ymax = (
i == 0) ? 0.0005 : 0.005;
211 sprintf(
name,
"sEtaEta%d",
i);
212 sprintf(
title,
"Cov(#eta,#eta) in %s", dets[
i].c_str());
215 sEtaEta_[
i]->GetYaxis()->SetTitle(
"Events");
217 sprintf(
name,
"sEtaPhi%d",
i);
218 sprintf(
title,
"Cov(#eta,#phi) in %s", dets[
i].c_str());
221 sEtaPhi_[
i]->GetYaxis()->SetTitle(
"Events");
223 ymax = (
i == 0) ? 0.001 : 0.01;
224 sprintf(
name,
"sPhiPhi%d",
i);
225 sprintf(
title,
"Cov(#phi,#phi) in %s", dets[
i].c_str());
228 sPhiPhi_[
i]->GetYaxis()->SetTitle(
"Events");
231 sprintf(
title,
"%s+", dets[
i].c_str());
233 poszp_[
i]->GetXaxis()->SetTitle(
"i#eta");
234 poszp_[
i]->GetYaxis()->SetTitle(
"i#phi");
235 sprintf(
title,
"%s-", dets[
i].c_str());
237 poszn_[
i]->GetXaxis()->SetTitle(
"i#eta");
238 poszn_[
i]->GetYaxis()->SetTitle(
"i#phi");
240 sprintf(
title,
"%s+", dets[
i].c_str());
242 poszp_[
i]->GetXaxis()->SetTitle(
"x (cm)");
243 poszp_[
i]->GetYaxis()->SetTitle(
"y (cm)");
244 sprintf(
title,
"%s-", dets[
i].c_str());
246 poszn_[
i]->GetXaxis()->SetTitle(
"x (cm)");
247 poszn_[
i]->GetYaxis()->SetTitle(
"y (cm)");
249 poszp_[
i]->GetYaxis()->SetTitleOffset(1.2);
251 poszn_[
i]->GetYaxis()->SetTitleOffset(1.2);
258 edm::LogVerbatim(
"HitStudy") <<
"Run = " <<
e.id().run() <<
" Event = " <<
e.id().event();
263 double eInc = 0, etaInc = 0, phiInc = 0;
270 HepMC::GenEvent::particle_const_iterator
p = myGenEvent->particles_begin();
271 if (
p != myGenEvent->particles_end()) {
272 eInc = (*p)->momentum().e();
273 etaInc = (*p)->momentum().eta();
274 phiInc = (*p)->momentum().phi();
276 double ptInc = eInc / std::cosh(etaInc);
288 int typeMin = (
type < 0) ? 0 :
type;
289 int typeMax = (
type < 0) ? 1 :
type;
293 bool getHits = (hitsCalo.
isValid());
295 edm::LogVerbatim(
"HitStudy") <<
"EcalSimHitStudy: Input flags Hits " << getHits <<
" with " << hitsCalo->size()
299 std::vector<PCaloHit> caloHits;
300 caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
301 if (!caloHits.empty())
309 std::map<unsigned int, EcalHit> hitMap;
310 double etot(0), etotG(0);
312 double edep =
hit.energy();
314 unsigned int id_ =
hit.
id();
315 double edepEM =
hit.energyEM();
316 double edepHad =
hit.energyHad();
318 if ((
hit.depth() == 1) || (
hit.depth() == 2))
322 auto it = hitMap.find(id_);
323 if (it == hitMap.end()) {
324 uint16_t dep =
hit.depth();
327 (it->second).
energy += edep;
333 edep_[indx]->Fill(edep);
342 for (
auto it : hitMap) {
343 if (it.second.energy > edepM) {
345 edepM = it.second.energy;
352 if ((depM & 0X4) != 0)
358 edm::LogVerbatim(
"HitStudy") <<
"EcalSimHitStudy::analyzeHits: Index " << indx <<
" Emax " << edepM <<
" IDMax " 360 <<
" Hits " <<
hits.size() <<
":" << nEC <<
":" << hitMap.size() <<
" ETotal " << etot
364 etot_[indx]->Fill(etot);
365 etotg_[indx]->Fill(etotG);
366 hit_[indx]->Fill(
double(nEC));
367 for (
auto it : hitMap) {
368 timeAll_[indx]->Fill((it.second).time);
369 edepAll_[indx]->Fill((it.second).energy);
379 poszp_[indx]->Fill(gpos.
x(), gpos.
y());
381 poszn_[indx]->Fill(gpos.
x(), gpos.
y());
386 std::vector<math::XYZVector>
position;
387 std::vector<double>
energy;
388 double e9(0), e25(0);
389 for (
auto it : hitMap) {
391 int deta(99), dphi(99),
dz(0);
403 if (deta <= 1 && dphi <= 1 &&
dz < 1)
405 if (deta <= 2 && dphi <= 2 &&
dz < 1) {
406 e25 += (it.second).
energy;
409 meanPosition += (it.second).
energy *
pos;
411 energy.push_back((it.second).energy);
414 double r1by9 = (e9 > 0) ? (edepM / e9) : -1;
415 double r1by25 = (e25 > 0) ? (edepM / e25) : -1;
416 double r9by25 = (e25 > 0) ? (e9 / e25) : -1;
419 double denom(0), numEtaEta(0), numEtaPhi(0), numPhiPhi(0);
420 for (
unsigned int k = 0;
k <
position.size(); ++
k) {
440 double sEtaEta = (
denom > 0) ? (numEtaEta /
denom) : -1.0;
441 double sEtaPhi = (
denom > 0) ? (numEtaPhi /
denom) : -1.0;
442 double sPhiPhi = (
denom > 0) ? (numPhiPhi /
denom) : -1.0;
445 edm::LogVerbatim(
"HitStudy") <<
"EcalSimHitStudy::Ratios " << r1by9 <<
" : " << r1by25 <<
" : " << r9by25
446 <<
" Covariances " << sEtaEta <<
" : " << sEtaPhi <<
" : " << sPhiPhi;
448 r1by9_[indx]->Fill(r1by9);
static const std::string kSharedResource
Log< level::Info, true > LogVerbatim
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const CaloGeometry * geometry_
const std::string g4Label_
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 edm::EDGetTokenT< edm::HepMCProduct > tok_evt_
EcalSimHitStudy(const edm::ParameterSet &ps)
void beginRun(edm::Run const &, edm::EventSetup const &) override
void analyze(edm::Event const &, edm::EventSetup const &) override
Abs< T >::type abs(const T &t)
std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id.
const std::vector< edm::EDGetTokenT< edm::PCaloHitContainer > > toks_calo_
void endRun(edm::Run const &, edm::EventSetup const &) override
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tokGeom_
#define DEFINE_FWK_MODULE(type)
void analyzeHits(std::vector< PCaloHit > &, int)
const HepMC::GenEvent * GetEvent() const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::vector< std::string > hitLab_
static int position[264][3]
EcalHit(uint16_t i=0, double t=0, double e=0)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~EcalSimHitStudy() override