27 #include "CLHEP/Units/GlobalPhysicalConstants.h" 28 #include "CLHEP/Units/GlobalSystemOfUnits.h" 29 #include "G4HCofThisEvent.hh" 30 #include "G4SDManager.hh" 33 #include "G4VProcess.hh" 59 produces<PHcalValidInfoNxN>(
labelNxN);
63 edm::LogInfo(
"ValidHcal") <<
"HcalTestAnalysis:: Initialised as observer of " 64 <<
"begin/end events and of G4step with Parameter " 65 <<
"values: \n\tInfoLevel = " << infolevel <<
"\n\thcalOnly = " << hcalOnly
66 <<
"\n\tapplySampling = " << applySampling <<
"\n\tconeSize = " << coneSize
67 <<
"\n\tehitThreshold = " << ehitThreshold <<
"\n\thhitThreshold = " << hhitThreshold
68 <<
"\n\tttimeLowlim = " << timeLowlim <<
"\n\tttimeUplim = " << timeUplim
69 <<
"\n\teta0 = " << eta0 <<
"\n\tphi0 = " << phi0
70 <<
"\nLabels (Layer): " << labelLayer <<
" (NxN): " << labelNxN <<
" (Jets): " <<
labelJets;
76 edm::LogInfo(
"ValidHcal") <<
"\n --------> Total number of selected entries" 77 <<
" : " <<
count <<
"\nPointers:: JettFinder " <<
jetf <<
", Numbering Scheme " <<
org 84 if (numberingFromDDD) {
85 edm::LogInfo(
"ValidHcal") <<
"Delete HcalNumberingFromDDD";
87 numberingFromDDD =
nullptr;
111 float sHB[4] = {117., 117., 178., 217.};
112 float sHE[3] = {178., 178., 178.};
113 float sHF[3] = {2.84, 2.09, 0.};
115 float deta[4] = {0.0435, 0.1305, 0.2175, 0.3045};
116 float dphi[4] = {0.0436, 0.1309, 0.2182, 0.3054};
119 for (i = 0; i < 4; i++) {
122 for (i = 0; i < 3; i++) {
125 for (i = 0; i < 3; i++) {
130 for (i = 0; i < 4; i++) {
131 dEta.push_back(deta[i]);
132 dPhi.push_back(dphi[i]);
145 (*job)()->get<HcalSimNumberingRecord>().get(hdc);
147 edm::LogInfo(
"ValidHcal") <<
"HcalTestAnalysis:: Initialise " 148 <<
"HcalNumberingFromDDD";
156 int irun = (*run)()->GetRunID();
158 edm::LogInfo(
"ValidHcal") <<
" =====> Begin of Run = " << irun;
161 G4SDManager *
sd = G4SDManager::GetSDMpointerIfExist();
163 G4VSensitiveDetector *aSD = sd->FindSensitiveDetector(sdname);
164 if (aSD ==
nullptr) {
165 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: No SD" 166 <<
" with name " << sdname <<
" in this " 170 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Finds SD" 171 <<
"with name " << theCaloSD->GetName() <<
" in this Setup";
174 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: set a " 175 <<
"new numbering scheme";
179 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Could " 180 <<
"not get SD Manager!";
188 for (i = 0; i < 5; i++)
190 for (i = 0; i < 20; i++)
196 int iev = (*evt)()->GetEventID();
197 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation: =====> Begin of event = " << iev;
202 if (aStep !=
nullptr) {
203 G4VPhysicalVolume *curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
204 G4String
name = curPV->GetName();
205 name.assign(name, 0, 3);
206 double edeposit = aStep->GetTotalEnergyDeposit();
207 int layer = -1,
depth = -1;
211 }
else if (name ==
"EFR") {
214 }
else if (name ==
"HBS") {
215 layer = (curPV->GetCopyNo() / 10) % 100;
216 depth = (curPV->GetCopyNo()) % 10 + 1;
217 if (
depth > 0 && depth < 4 && layer >= 0 && layer < 17) {
220 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
224 }
else if (name ==
"HES") {
225 layer = (curPV->GetCopyNo() / 10) % 100;
226 depth = (curPV->GetCopyNo()) % 10 + 1;
227 if (
depth > 0 && depth < 3 && layer >= 0 && layer < 19) {
230 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
234 }
else if (name ==
"HTS") {
235 layer = (curPV->GetCopyNo() / 10) % 100;
236 depth = (curPV->GetCopyNo()) % 10 + 1;
237 if (
depth > 3 && depth < 5 && layer >= 17 && layer < 20) {
240 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation:Error " << curPV->GetName() << curPV->GetCopyNo();
247 if (layer >= 0 && layer < 20)
248 edepl[layer] += edeposit;
250 if (layer >= 0 && layer < 20) {
251 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: G4Step: " << name <<
" Layer " << std::setw(3) << layer
252 <<
" Depth " << std::setw(2) <<
depth <<
" Edep " << std::setw(6) << edeposit /
MeV 264 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: --- after Fill ";
269 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:Fill event " << (*evt)()->GetEventID();
272 G4HCofThisEvent *allHC = (*evt)()->GetHCofThisEvent();
277 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
279 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation :: Hit Collection for " <<
names[0] <<
" of ID " << HCHCid
280 <<
" is obtained at " << theHCHC;
281 if (HCHCid >= 0 && theHCHC !=
nullptr) {
282 for (j = 0; j < theHCHC->entries(); j++) {
289 double theta = pos.theta();
291 double phi = pos.phi();
294 int subdet,
zside, layer, etaIndex, phiIndex, lay;
312 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::HitPMT " << subdet <<
" " << (2 * zside - 1) * etaIndex
313 <<
" " << phiIndex <<
" " << layer + 1 <<
" R " << pos.rho() <<
" Phi " << phi / deg
314 <<
" Edep " << e <<
" Time " <<
time;
315 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
316 if (etaIndex <= 20) {
322 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Hcal " << det <<
" layer " << std::setw(2) << layer
323 <<
" lay " << std::setw(2) << lay <<
" time " << std::setw(6) << time <<
" theta " 324 << std::setw(8) << theta <<
" eta " << std::setw(8) << eta <<
" phi " << std::setw(8) << phi
325 <<
" e " << std::setw(8) << e <<
" ID 0x" << std::hex << unitID <<
" ID dec " <<
std::dec 335 CaloHit ahit(subdet, lay, e, eta, phi, time, unitID);
341 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: HCAL hits : " << nhc;
344 int ndets =
names.size();
347 for (
int idty = 1; idty < ndets; idty++) {
355 int ECHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[idty]);
357 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: Hit Collection for " <<
names[idty] <<
" of ID " << ECHCid
358 <<
" is obtained at " << theECHC;
359 if (ECHCid >= 0 && theECHC !=
nullptr) {
360 for (j = 0; j < theECHC->entries(); j++) {
367 double theta = pos.theta();
369 double phi = pos.phi();
372 int subdet,
zside, layer, ieta, iphi, lay;
381 CaloHit ahit(subdet, lay, e, eta, phi, time, unitID);
386 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Ecal " << det <<
" layer " << std::setw(2) << layer
387 <<
" lay " << std::setw(2) << lay <<
" time " << std::setw(6) << time <<
" theta " 388 << std::setw(8) << theta <<
" eta " << std::setw(8) << eta <<
" phi " << std::setw(8)
389 << phi <<
" e " << std::setw(8) << e <<
" ID 0x" << std::hex << unitID <<
" ID dec " 394 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: " << det <<
" hits : " << nec;
401 LogDebug(
"ValidHcal") <<
"\n ===>>> SimG4HcalValidation: Energy deposit " 402 <<
"in MeV\n at EB : " << std::setw(6) <<
edepEB /
MeV <<
"\n at EE : " << std::setw(6)
404 <<
"\n at HE : " << std::setw(6) <<
edepHE /
MeV <<
"\n at HO : " << std::setw(6)
405 <<
edepHO /
MeV <<
"\n ---- SimG4HcalValidation: Energy deposit in";
406 for (i = 0; i < 5; i++)
407 LogDebug(
"ValidHcal") <<
" Depth " << std::setw(2) << i <<
" E " << std::setw(8) <<
edepd[
i] /
MeV <<
" MeV";
408 LogDebug(
"ValidHcal") <<
" ---- SimG4HcalValidation: Energy deposit in" 410 for (i = 0; i < 20; i++)
411 LogDebug(
"ValidHcal") <<
" Layer " << std::setw(2) << i <<
" E " << std::setw(8) <<
edepl[
i] /
MeV <<
" MeV";
417 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::HF hits " <<
vhitec <<
" in EC and " <<
vhithc <<
" in HC\n" 418 <<
" HB/HE " <<
enEcal <<
" in EC and " <<
enHcal <<
" in HC";
423 LogDebug(
"ValidHcal") <<
" layerAnalysis ===> after fetchHits";
429 std::vector<CaloHit>::iterator hit_itr;
431 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::NxNAnalysis : entrance ";
436 LogDebug(
"ValidHcal") <<
" NxNAnalysis : coolectEnergyRdir - Ecal " <<
een <<
" Hcal " <<
hen;
445 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
446 double e = hit_itr->e();
447 double t = hit_itr->t();
448 double eta = hit_itr->eta();
449 double phi = hit_itr->phi();
450 int type = hit_itr->det();
451 int layer = hit_itr->layer();
455 if (fabs(
eta0 - eta) <=
dEta[max - 1] && fabs(
phi0 - phi) <=
dPhi[max - 1]) {
457 if (type == 10 || type == 11 || type == 12)
462 if (type == static_cast<int>(
HcalBarrel) && layer > 17)
466 for (
int i = 0;
i <
max;
i++) {
469 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: nxNAnalysis eta0," 470 <<
" phi0 = " <<
eta0 <<
" " <<
phi0 <<
" type, layer = " << type <<
"," << layer
471 <<
" eta, phi = " << eta <<
" " <<
phi;
485 LogDebug(
"ValidHcal") <<
" nxNAnalysis ===> after fillHvsE";
490 std::vector<CaloHit> *hhit = &
hitcache;
497 std::vector<SimG4HcalHitCluster>::iterator clus_itr;
499 LogDebug(
"ValidHcal") <<
"\n ---------- Final list of " << (*result).size() <<
" clusters ---------------";
500 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++)
501 LogDebug(
"ValidHcal") << (*clus_itr);
503 std::vector<double> enevec, etavec, phivec;
505 if (!(*result).empty()) {
506 sort((*result).begin(), (*result).end());
508 clus_itr = result->begin();
509 double etac = clus_itr->eta();
510 double phic = clus_itr->phi();
512 double ecal_collect = 0.;
514 ecal_collect = clus_itr->collectEcalEnergyR();
519 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> ecal_collect = " << ecal_collect;
523 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> eta phi deviation = " << dist;
526 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEtaPhiProfileJet";
528 std::vector<CaloHit> *
hits = clus_itr->getHits();
529 std::vector<CaloHit>::iterator hit_itr;
531 double ee = 0.,
he = 0.,
hoe = 0., etot = 0.;
534 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
535 double e = hit_itr->e();
536 double t = hit_itr->t();
537 double r =
jetf->
rDist(&(*clus_itr), &(*hit_itr));
541 if (hit_itr->det() == 10 || hit_itr->det() == 11 || hit_itr->det() == 12)
543 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) || hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
546 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) && hit_itr->layer() > 17)
550 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) || hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
558 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEcollectJet: " 559 <<
"ee/he/hoe/etot " << ee <<
"/" <<
he <<
"/" <<
hoe <<
"/" << etot;
562 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++) {
564 enevec.push_back(clus_itr->e());
565 etavec.push_back(clus_itr->eta());
566 phivec.push_back(clus_itr->phi());
569 product.
fillJets(enevec, etavec, phivec);
571 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillJets\n" 572 <<
" JetAnalysis ===> (*result).size() " << (*result).size();
575 if (etavec.size() > 1) {
576 if (etavec[0] > -2.5 && etavec[0] < 2.5 && etavec[1] > -2.5 && etavec[1] < 2.5) {
577 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet mass enter\n" 578 <<
" JetAnalysis ===> Di-jet vectors ";
579 for (
unsigned int i = 0;
i < enevec.size();
i++)
580 LogDebug(
"ValidHcal") <<
" e, eta, phi = " << enevec[
i] <<
" " << etavec[
i] <<
" " << phivec[
i];
582 double et0 = enevec[0] / cosh(etavec[0]);
583 double px0 = et0 *
cos(phivec[0]);
584 double py0 = et0 *
sin(phivec[0]);
585 double pz0 = et0 * sinh(etavec[0]);
586 double et1 = enevec[1] / cosh(etavec[1]);
587 double px1 = et1 *
cos(phivec[1]);
588 double py1 = et1 *
sin(phivec[1]);
589 double pz1 = et1 * sinh(etavec[1]);
591 double dijetmass2 = (enevec[0] + enevec[1]) * (enevec[0] + enevec[1]) - (px1 + px0) * (px1 + px0) -
592 (py1 + py0) * (py1 + py0) - (pz1 + pz0) * (pz1 + pz0);
594 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet massSQ " << dijetmass2;
597 if (dijetmass2 >= 0.)
598 dijetmass =
sqrt(dijetmass2);
600 dijetmass = -
sqrt(-1. * dijetmass2);
604 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillDiJets";
612 LogDebug(
"ValidHcal") <<
"Enter SimG4HcalValidation::fetchHits with " <<
hitcache.size() <<
" hits";
616 std::vector<CaloHit>::iterator itr;
617 std::vector<CaloHit *> lhits(nHit);
619 uint32_t unitID = itr->id();
624 group = (subdet & 15) << 20;
625 group += ((lay - 1) & 31) << 15;
626 group += (zside & 1) << 14;
627 group += (ieta & 127) << 7;
628 group += (iphi & 127);
631 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Original " << i <<
" " <<
hitcache[
i] <<
"\n" 632 <<
"SimG4HcalValidation::fetchHits:Copied " << i <<
" " << *lhits[
i];
635 std::vector<CaloHit *>::iterator k1, k2;
636 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
637 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Sorted " << i <<
" " << **k1;
639 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
640 double ehit = (**k1).e();
641 double t = (**k1).t();
642 uint32_t unitID = (**k1).id();
644 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Start " << i <<
" U/T/E" 645 <<
" 0x" << std::hex << unitID <<
std::dec <<
" " << t <<
" " << ehit;
646 for (k2 = k1 + 1; k2 != lhits.end() && (t - (**k2).t()) < 1 && (t - (**k2).t()) > -1 && unitID == (**k2).id();
649 LogDebug(
"ValidHcal") <<
"\t + " << (**k2).e();
652 LogDebug(
"ValidHcal") <<
"\t = " << ehit <<
" in " << jump;
654 double eta = (*k1)->eta();
655 double phi = (*k1)->phi();
656 int lay = ((unitID >> 15) & 31) + 1;
657 int subdet = (unitID >> 20) & 15;
658 int zside = (unitID >> 14) & 1;
659 int ieta = (unitID >> 7) & 127;
660 int iphi = (unitID)&127;
663 product.
fillHits(nHits, lay, subdet, eta, phi, ehit, t);
666 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Hit " << nHits <<
" " << i <<
" ID 0x" << std::hex
667 << unitID <<
" det " <<
std::dec << subdet <<
" " << lay <<
" " << zside <<
" " << ieta
668 <<
" " << iphi <<
" Time " << t <<
" E " << ehit;
674 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits called with " << nHit <<
" hits" 675 <<
" and writes out " << nHits <<
'(' << hit <<
") hits";
683 std::vector<CaloHit>::iterator hit_itr;
685 double sume = 0., sumh = 0., sumho = 0.;
687 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
688 double e = hit_itr->e();
689 double eta = hit_itr->eta();
690 double phi = hit_itr->phi();
692 int type = hit_itr->det();
696 if (type == 10 || type == 11 || type == 12) {
700 if (type == static_cast<int>(
HcalBarrel) && hit_itr->layer() > 17)
717 }
else if (det ==
"HES" || det ==
"HED") {
719 }
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)
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
std::vector< std::vector< double > > tmp
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