28 #include "G4HCofThisEvent.hh" 29 #include "G4SDManager.hh" 32 #include "G4VProcess.hh" 57 produces<PHcalValidInfoNxN>(
labelNxN);
61 edm::LogVerbatim(
"ValidHcal") <<
"HcalTestAnalysis:: Initialised as observer of begin/end events and " 62 <<
"of G4step with Parameter values: \n\tInfoLevel = " << infolevel
63 <<
"\n\thcalOnly = " << hcalOnly <<
"\n\tapplySampling = " << applySampling
64 <<
"\n\tconeSize = " << coneSize <<
"\n\tehitThreshold = " << ehitThreshold
65 <<
"\n\thhitThreshold = " << hhitThreshold <<
"\n\tttimeLowlim = " << timeLowlim
66 <<
"\n\tttimeUplim = " << timeUplim <<
"\n\teta0 = " << eta0
67 <<
"\n\tphi0 = " << phi0 <<
"\nLabels (Layer): " << labelLayer
68 <<
" (NxN): " << labelNxN <<
" (Jets): " <<
labelJets;
74 edm::LogVerbatim(
"ValidHcal") <<
"\n --------> Total number of selected entries" 75 <<
" : " <<
count <<
"\nPointers:: JettFinder " <<
jetf <<
", Numbering Scheme " <<
org 82 if (numberingFromDDD) {
85 numberingFromDDD =
nullptr;
109 float sHB[4] = {117., 117., 178., 217.};
110 float sHE[3] = {178., 178., 178.};
111 float sHF[3] = {2.84, 2.09, 0.};
113 float deta[4] = {0.0435, 0.1305, 0.2175, 0.3045};
114 float dphi[4] = {0.0436, 0.1309, 0.2182, 0.3054};
117 for (i = 0; i < 4; i++) {
120 for (i = 0; i < 3; i++) {
123 for (i = 0; i < 3; i++) {
128 for (i = 0; i < 4; i++) {
129 dEta.push_back(deta[i]);
130 dPhi.push_back(dphi[i]);
143 (*job)()->get<HcalSimNumberingRecord>().get(hdc);
146 <<
"HcalNumberingFromDDD";
154 int irun = (*run)()->GetRunID();
159 G4SDManager *
sd = G4SDManager::GetSDMpointerIfExist();
161 G4VSensitiveDetector *aSD = sd->FindSensitiveDetector(sdname);
162 if (aSD ==
nullptr) {
163 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: No SD" 164 <<
" with name " << sdname <<
" in this " 168 edm::LogVerbatim(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Finds SD with name " << theCaloSD->GetName()
172 edm::LogVerbatim(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: set a new numbering scheme";
176 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Could " 177 <<
"not get SD Manager!";
185 for (i = 0; i < 5; i++)
187 for (i = 0; i < 20; i++)
193 int iev = (*evt)()->GetEventID();
194 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation: =====> Begin of event = " << iev;
199 if (aStep !=
nullptr) {
200 G4VPhysicalVolume *curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
201 G4String
name = curPV->GetName();
202 name.assign(name, 0, 3);
203 double edeposit = aStep->GetTotalEnergyDeposit();
204 int layer = -1,
depth = -1;
208 }
else if (name ==
"EFR") {
211 }
else if (name ==
"HBS") {
212 layer = (curPV->GetCopyNo() / 10) % 100;
213 depth = (curPV->GetCopyNo()) % 10 + 1;
214 if (
depth > 0 && depth < 4 && layer >= 0 && layer < 17) {
217 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
221 }
else if (name ==
"HES") {
222 layer = (curPV->GetCopyNo() / 10) % 100;
223 depth = (curPV->GetCopyNo()) % 10 + 1;
224 if (
depth > 0 && depth < 3 && layer >= 0 && layer < 19) {
227 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
231 }
else if (name ==
"HTS") {
232 layer = (curPV->GetCopyNo() / 10) % 100;
233 depth = (curPV->GetCopyNo()) % 10 + 1;
234 if (
depth > 3 && depth < 5 && layer >= 17 && layer < 20) {
237 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
244 if (layer >= 0 && layer < 20)
245 edepl[layer] += edeposit;
247 if (layer >= 0 && layer < 20) {
248 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: G4Step: " << name <<
" Layer " << std::setw(3) << layer
249 <<
" Depth " << std::setw(2) <<
depth <<
" Edep " << std::setw(6) << edeposit /
MeV 261 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: --- after Fill ";
266 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:Fill event " << (*evt)()->GetEventID();
269 G4HCofThisEvent *allHC = (*evt)()->GetHCofThisEvent();
274 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
276 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation :: Hit Collection for " <<
names[0] <<
" of ID " << HCHCid
277 <<
" is obtained at " << theHCHC;
278 if (HCHCid >= 0 && theHCHC !=
nullptr) {
279 for (
j = 0;
j < theHCHC->entries();
j++) {
286 double theta = pos.theta();
288 double phi = pos.phi();
291 int subdet,
zside, layer, etaIndex, phiIndex, lay;
309 edm::LogVerbatim(
"ValidHcal") <<
"SimG4HcalValidation::HitPMT " << subdet <<
" " << (2 * zside - 1) * etaIndex
310 <<
" " << phiIndex <<
" " << layer + 1 <<
" R " << pos.rho() <<
" Phi " 312 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
313 if (etaIndex <= 20) {
319 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Hcal " << det <<
" layer " << std::setw(2) << layer
320 <<
" lay " << std::setw(2) << lay <<
" time " << std::setw(6) << time <<
" theta " 321 << std::setw(8) << theta <<
" eta " << std::setw(8) << eta <<
" phi " << std::setw(8) << phi
322 <<
" e " << std::setw(8) << e <<
" ID 0x" << std::hex << unitID <<
" ID dec " <<
std::dec 332 CaloHit ahit(subdet, lay, e, eta, phi, time, unitID);
338 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: HCAL hits : " << nhc;
341 int ndets =
names.size();
344 for (
int idty = 1; idty < ndets; idty++) {
352 int ECHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[idty]);
354 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: Hit Collection for " <<
names[idty] <<
" of ID " << ECHCid
355 <<
" is obtained at " << theECHC;
356 if (ECHCid >= 0 && theECHC !=
nullptr) {
357 for (
j = 0;
j < theECHC->entries();
j++) {
364 double theta = pos.theta();
366 double phi = pos.phi();
378 CaloHit ahit(subdet, lay, e, eta, phi, time, unitID);
383 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Ecal " << det <<
" layer " << std::setw(2) << layer
384 <<
" lay " << std::setw(2) << lay <<
" time " << std::setw(6) << time <<
" theta " 385 << std::setw(8) << theta <<
" eta " << std::setw(8) << eta <<
" phi " << std::setw(8)
386 << phi <<
" e " << std::setw(8) << e <<
" ID 0x" << std::hex << unitID <<
" ID dec " 391 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: " << det <<
" hits : " << nec;
398 LogDebug(
"ValidHcal") <<
"\n ===>>> SimG4HcalValidation: Energy deposit " 399 <<
"in MeV\n at EB : " << std::setw(6) <<
edepEB /
MeV <<
"\n at EE : " << std::setw(6)
401 <<
"\n at HE : " << std::setw(6) <<
edepHE /
MeV <<
"\n at HO : " << std::setw(6)
402 <<
edepHO /
MeV <<
"\n ---- SimG4HcalValidation: Energy deposit in";
403 for (i = 0; i < 5; i++)
404 LogDebug(
"ValidHcal") <<
" Depth " << std::setw(2) << i <<
" E " << std::setw(8) <<
edepd[
i] /
MeV <<
" MeV";
405 LogDebug(
"ValidHcal") <<
" ---- SimG4HcalValidation: Energy deposit in" 407 for (i = 0; i < 20; i++)
408 LogDebug(
"ValidHcal") <<
" Layer " << std::setw(2) << i <<
" E " << std::setw(8) <<
edepl[
i] /
MeV <<
" MeV";
414 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::HF hits " <<
vhitec <<
" in EC and " <<
vhithc <<
" in HC\n" 415 <<
" HB/HE " <<
enEcal <<
" in EC and " <<
enHcal <<
" in HC";
420 LogDebug(
"ValidHcal") <<
" layerAnalysis ===> after fetchHits";
426 std::vector<CaloHit>::iterator hit_itr;
428 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::NxNAnalysis : entrance ";
433 LogDebug(
"ValidHcal") <<
" NxNAnalysis : coolectEnergyRdir - Ecal " <<
een <<
" Hcal " <<
hen;
442 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
443 double e = hit_itr->e();
444 double t = hit_itr->t();
445 double eta = hit_itr->eta();
446 double phi = hit_itr->phi();
447 int type = hit_itr->det();
448 int layer = hit_itr->layer();
452 if (fabs(
eta0 - eta) <=
dEta[max - 1] && fabs(
phi0 - phi) <=
dPhi[max - 1]) {
454 if (type == 10 || type == 11 || type == 12)
459 if (type == static_cast<int>(
HcalBarrel) && layer > 17)
463 for (
int i = 0;
i <
max;
i++) {
466 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: nxNAnalysis eta0," 467 <<
" phi0 = " <<
eta0 <<
" " <<
phi0 <<
" type, layer = " << type <<
"," << layer
468 <<
" eta, phi = " << eta <<
" " <<
phi;
482 LogDebug(
"ValidHcal") <<
" nxNAnalysis ===> after fillHvsE";
487 std::vector<CaloHit> *hhit = &
hitcache;
494 std::vector<SimG4HcalHitCluster>::iterator clus_itr;
496 LogDebug(
"ValidHcal") <<
"\n ---------- Final list of " << (*result).size() <<
" clusters ---------------";
497 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++)
498 LogDebug(
"ValidHcal") << (*clus_itr);
500 std::vector<double> enevec, etavec, phivec;
502 if (!(*result).empty()) {
503 sort((*result).begin(), (*result).end());
505 clus_itr = result->begin();
506 double etac = clus_itr->eta();
507 double phic = clus_itr->phi();
509 double ecal_collect = 0.;
511 ecal_collect = clus_itr->collectEcalEnergyR();
516 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> ecal_collect = " << ecal_collect;
520 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> eta phi deviation = " << dist;
523 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEtaPhiProfileJet";
525 std::vector<CaloHit> *
hits = clus_itr->getHits();
526 std::vector<CaloHit>::iterator hit_itr;
528 double ee = 0.,
he = 0.,
hoe = 0., etot = 0.;
531 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
532 double e = hit_itr->e();
533 double t = hit_itr->t();
534 double r =
jetf->
rDist(&(*clus_itr), &(*hit_itr));
538 if (hit_itr->det() == 10 || hit_itr->det() == 11 || hit_itr->det() == 12)
540 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) || hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
543 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) && hit_itr->layer() > 17)
547 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) || hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
555 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEcollectJet: " 556 <<
"ee/he/hoe/etot " << ee <<
"/" <<
he <<
"/" <<
hoe <<
"/" << etot;
559 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++) {
561 enevec.push_back(clus_itr->e());
562 etavec.push_back(clus_itr->eta());
563 phivec.push_back(clus_itr->phi());
566 product.
fillJets(enevec, etavec, phivec);
568 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillJets\n" 569 <<
" JetAnalysis ===> (*result).size() " << (*result).size();
572 if (etavec.size() > 1) {
573 if (etavec[0] > -2.5 && etavec[0] < 2.5 && etavec[1] > -2.5 && etavec[1] < 2.5) {
574 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet mass enter\n" 575 <<
" JetAnalysis ===> Di-jet vectors ";
576 for (
unsigned int i = 0;
i < enevec.size();
i++)
577 LogDebug(
"ValidHcal") <<
" e, eta, phi = " << enevec[
i] <<
" " << etavec[
i] <<
" " << phivec[
i];
579 double et0 = enevec[0] / cosh(etavec[0]);
580 double px0 = et0 *
cos(phivec[0]);
581 double py0 = et0 *
sin(phivec[0]);
582 double pz0 = et0 * sinh(etavec[0]);
583 double et1 = enevec[1] / cosh(etavec[1]);
584 double px1 = et1 *
cos(phivec[1]);
585 double py1 = et1 *
sin(phivec[1]);
586 double pz1 = et1 * sinh(etavec[1]);
588 double dijetmass2 = (enevec[0] + enevec[1]) * (enevec[0] + enevec[1]) - (px1 + px0) * (px1 + px0) -
589 (py1 + py0) * (py1 + py0) - (pz1 + pz0) * (pz1 + pz0);
591 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet massSQ " << dijetmass2;
594 if (dijetmass2 >= 0.)
595 dijetmass =
sqrt(dijetmass2);
597 dijetmass = -
sqrt(-1. * dijetmass2);
601 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillDiJets";
609 LogDebug(
"ValidHcal") <<
"Enter SimG4HcalValidation::fetchHits with " <<
hitcache.size() <<
" hits";
613 std::vector<CaloHit>::iterator itr;
614 std::vector<CaloHit *> lhits(nHit);
616 uint32_t unitID = itr->id();
621 group = (subdet & 15) << 20;
622 group += ((lay - 1) & 31) << 15;
623 group += (zside & 1) << 14;
624 group += (ieta & 127) << 7;
625 group += (iphi & 127);
628 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Original " << i <<
" " <<
hitcache[
i] <<
"\n" 629 <<
"SimG4HcalValidation::fetchHits:Copied " << i <<
" " << *lhits[
i];
632 std::vector<CaloHit *>::iterator k1, k2;
633 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
634 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Sorted " << i <<
" " << **k1;
636 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
637 double ehit = (**k1).e();
638 double t = (**k1).t();
639 uint32_t unitID = (**k1).id();
641 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Start " << i <<
" U/T/E" 642 <<
" 0x" << std::hex << unitID <<
std::dec <<
" " << t <<
" " << ehit;
643 for (k2 = k1 + 1; k2 != lhits.end() && (t - (**k2).t()) < 1 && (t - (**k2).t()) > -1 && unitID == (**k2).id();
646 LogDebug(
"ValidHcal") <<
"\t + " << (**k2).e();
649 LogDebug(
"ValidHcal") <<
"\t = " << ehit <<
" in " << jump;
651 double eta = (*k1)->eta();
652 double phi = (*k1)->phi();
653 int lay = ((unitID >> 15) & 31) + 1;
654 int subdet = (unitID >> 20) & 15;
655 int zside = (unitID >> 14) & 1;
656 int ieta = (unitID >> 7) & 127;
657 int iphi = (unitID)&127;
660 product.
fillHits(nHits, lay, subdet, eta, phi, ehit, t);
663 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Hit " << nHits <<
" " << i <<
" ID 0x" << std::hex
664 << unitID <<
" det " <<
std::dec << subdet <<
" " << lay <<
" " << zside <<
" " << ieta
665 <<
" " << iphi <<
" Time " << t <<
" E " << ehit;
671 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits called with " << nHit <<
" hits" 672 <<
" and writes out " << nHits <<
'(' << hit <<
") hits";
680 std::vector<CaloHit>::iterator hit_itr;
682 double sume = 0., sumh = 0., sumho = 0.;
684 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
685 double e = hit_itr->e();
686 double eta = hit_itr->eta();
687 double phi = hit_itr->phi();
689 int type = hit_itr->det();
693 if (type == 10 || type == 11 || type == 12) {
697 if (type == static_cast<int>(
HcalBarrel) && hit_itr->layer() > 17)
714 }
else if (det ==
"HES" || det ==
"HED") {
716 }
else if (det ==
"HF") {
void fillJets(const std::vector< double > &enj, const std::vector< double > &etaj, const std::vector< double > &phij)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
HcalNumberingFromDDD * numberingFromDDD
math::XYZPoint getPosition() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void fillHvsE(double ee, double he, double hoe, double etot)
void fillTProfileJet(double e, double r, double t)
double getHcalScale(std::string, int) const
void fill(const EndOfEvent *ev)
void fillLayers(double el[], double ed[], double ho, double hbhe, double ebee)
std::vector< float > scaleHF
void fillEcollectJet(double ee, double he, double hoe, double etot)
void collectEnergyRdir(const double, const double)
std::vector< std::string > names
void fillEtaPhiProfileJet(double eta0, double phi0, double eta, double phi, double dist)
constexpr NumType convertRadToDeg(NumType radians)
std::vector< CaloHit > hitcache
Sin< T >::type sin(const T &t)
void produce(edm::Event &, const edm::EventSetup &) override
void fillDiJets(double mass)
Geom::Theta< T > theta() const
uint16_t getDepth() const
std::vector< double > dEta
void setInput(std::vector< CaloHit > *)
void setNumberingScheme(HcalNumberingScheme *)
void fillHits(int Nhits, int lay, int unitID, double eta, double phi, double ehit, double t)
~SimG4HcalValidation() override
void jetAnalysis(PHcalValidInfoJets &)
void nxNAnalysis(PHcalValidInfoNxN &)
SimG4HcalHitJetFinder * jetf
std::vector< double > dPhi
static uint32_t packHcalIndex(int det, int z, int depth, int eta, int phi, int lay)
void fetchHits(PHcalValidInfoLayer &)
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
std::vector< float > scaleHB
void update(const BeginOfJob *job) override
This routine will be called when the appropriate signal arrives.
void fillEcollectNxN(double een, double hen, double hoen, double etotn)
HcalID unitID(int det, const math::XYZVectorD &pos, int depth, int lay=-1) const
std::vector< SimG4HcalHitCluster > * getClusters(bool)
void fillTProfileNxN(double e, int i, double t)
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< float > scaleHE
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
double getTimeSlice() const
double rDist(const SimG4HcalHitCluster *, const CaloHit *) const
SimG4HcalValidation(const edm::ParameterSet &p)
uint32_t getUnitID() const
T const * product() const
HcalTestNumberingScheme * org
void layerAnalysis(PHcalValidInfoLayer &)
void fillHF(double fibl, double fibs, double enec, double enhc)
double getEnergyDeposit() const
uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id) override