27 #include "G4SDManager.hh" 30 #include "G4VProcess.hh" 31 #include "G4HCofThisEvent.hh" 32 #include "CLHEP/Units/GlobalSystemOfUnits.h" 33 #include "CLHEP/Units/GlobalPhysicalConstants.h" 39 jetf(0), numberingFromDDD(0), org(0) {
59 if (infolevel > 0) produces<PHcalValidInfoNxN>(
labelNxN);
60 if (infolevel > 1) produces<PHcalValidInfoJets>(
labelJets);
62 edm::LogInfo(
"ValidHcal") <<
"HcalTestAnalysis:: Initialised as observer of " 63 <<
"begin/end events and of G4step with Parameter " 64 <<
"values: \n\tInfoLevel = " << infolevel
65 <<
"\n\thcalOnly = " << hcalOnly
66 <<
"\n\tapplySampling = " << applySampling
67 <<
"\n\tconeSize = " << coneSize
68 <<
"\n\tehitThreshold = " << ehitThreshold
69 <<
"\n\thhitThreshold = " << hhitThreshold
70 <<
"\n\tttimeLowlim = " << timeLowlim
71 <<
"\n\tttimeUplim = " << timeUplim
72 <<
"\n\teta0 = " << eta0
73 <<
"\n\tphi0 = " << phi0
74 <<
"\nLabels (Layer): " << labelLayer
75 <<
" (NxN): " << labelNxN <<
" (Jets): " 83 edm::LogInfo(
"ValidHcal") <<
"\n --------> Total number of selected entries" 84 <<
" : " <<
count <<
"\nPointers:: JettFinder " 85 <<
jetf <<
", Numbering Scheme " <<
org 92 if (numberingFromDDD) {
93 edm::LogInfo(
"ValidHcal") <<
"Delete HcalNumberingFromDDD";
121 float sHB[4] = { 117., 117., 178., 217.};
122 float sHE[3] = { 178., 178., 178.};
123 float sHF[3] = { 2.84, 2.09, 0.};
125 float deta[4] = { 0.0435, 0.1305, 0.2175, 0.3045 };
126 float dphi[4] = { 0.0436, 0.1309, 0.2182, 0.3054 };
129 for (i = 0; i < 4; i++) {
132 for (i = 0; i < 3; i++) {
135 for (i = 0; i < 3; i++) {
140 for(i = 0; i < 4; i++) {
141 dEta.push_back(deta[i]);
142 dPhi.push_back(dphi[i]);
157 (*job)()->get<HcalSimNumberingRecord>().get(hdc);
159 edm::LogInfo(
"ValidHcal") <<
"HcalTestAnalysis:: Initialise " 160 <<
"HcalNumberingFromDDD";
170 int irun = (*run)()->GetRunID();
172 edm::LogInfo(
"ValidHcal") <<
" =====> Begin of Run = " << irun;
175 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
177 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
179 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: No SD" 180 <<
" with name " << sdname <<
" in this " 184 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Finds SD" 185 <<
"with name " << theCaloSD->GetName()
189 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: set a " 190 <<
"new numbering scheme";
194 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Could " 195 <<
"not get SD Manager!";
205 for (i = 0; i < 5; i++)
edepd[i] = 0.;
206 for (i = 0; i < 20; i++)
edepl[i] = 0.;
211 int iev = (*evt)()->GetEventID();
212 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation: =====> Begin of event = " 220 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
221 G4String
name = curPV->GetName();
222 name.assign(name,0,3);
223 double edeposit = aStep->GetTotalEnergyDeposit();
224 int layer=-1,
depth=-1;
228 }
else if (name ==
"EFR") {
231 }
else if (name ==
"HBS") {
232 layer = (curPV->GetCopyNo()/10)%100;
233 depth = (curPV->GetCopyNo())%10 + 1;
234 if (
depth > 0 && depth < 4 && layer >= 0 && layer < 17) {
238 << curPV->GetName() << curPV->GetCopyNo();
239 depth = -1; layer = -1;
241 }
else if (name ==
"HES") {
242 layer = (curPV->GetCopyNo()/10)%100;
243 depth = (curPV->GetCopyNo())%10 + 1;
244 if (
depth > 0 && depth < 3 && layer >= 0 && layer < 19) {
248 << curPV->GetName() << curPV->GetCopyNo();
249 depth = -1; layer = -1;
251 }
else if (name ==
"HTS") {
252 layer = (curPV->GetCopyNo()/10)%100;
253 depth = (curPV->GetCopyNo())%10 + 1;
254 if (
depth > 3 && depth < 5 && layer >= 17 && layer < 20) {
258 << curPV->GetName() <<curPV->GetCopyNo();
259 depth = -1; layer = -1;
263 if (layer >= 0 && layer < 20)
edepl[layer] += edeposit;
265 if (layer >= 0 && layer < 20) {
266 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: G4Step: " << name
267 <<
" Layer " << std::setw(3) << layer <<
" Depth " 268 << std::setw(2) <<
depth <<
" Edep " <<std::setw(6)
269 << edeposit/
MeV <<
" MeV";
281 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: --- after Fill ";
287 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:Fill event " 288 << (*evt)()->GetEventID();
291 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
296 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
298 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation :: Hit Collection for " 299 <<
names[0] <<
" of ID " << HCHCid <<
" is obtained at " 301 if (HCHCid >= 0 && theHCHC !=
nullptr) {
302 for (j = 0; j < theHCHC->entries(); j++) {
310 double theta = pos.theta();
312 double phi = pos.phi();
315 int subdet,
zside, layer, etaIndex, phiIndex, lay;
324 if (depth != 0) { layer += 2; lay += 2; }
326 else if (layer == 0)
vhitec +=
e;
328 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::HitPMT " 329 << subdet <<
" " << (2*zside-1)*etaIndex
330 <<
" " << phiIndex <<
" " << layer+1
331 <<
" R " << pos.rho() <<
" Phi " << phi/deg
332 <<
" Edep " << e <<
" Time " <<
time;
333 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
334 if (etaIndex <= 20) {
340 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Hcal " 341 << det <<
" layer " << std::setw(2) << layer
342 <<
" lay " << std::setw(2) << lay <<
" time " 343 << std::setw(6) << time <<
" theta " 344 << std::setw(8) << theta <<
" eta " << std::setw(8)
345 << eta <<
" phi " << std::setw(8) << phi <<
" e " 346 << std::setw(8) << e <<
" ID 0x" << std::hex
347 << unitID <<
" ID dec " <<
std::dec << (
int)unitID;
355 CaloHit ahit(subdet,lay,e,eta,phi,time,unitID);
361 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: HCAL hits : " << nhc;
364 int ndets =
names.size();
365 if (ndets > 3) ndets = 3;
366 for (
int idty = 1; idty < ndets; idty++) {
368 if (idty == 2) det =
"EE";
369 else if (idty > 2) det =
"ES";
372 int ECHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[idty]);
374 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: Hit Collection for " 375 <<
names[idty] <<
" of ID " << ECHCid
376 <<
" is obtained at " << theECHC;
377 if (ECHCid >= 0 && theECHC !=
nullptr) {
378 for (j = 0; j < theECHC->entries(); j++) {
386 double theta = pos.theta();
388 double phi = pos.phi();
391 int subdet,
zside, layer, ieta, iphi, lay;
400 CaloHit ahit(subdet,lay,e,eta,phi,time,unitID);
405 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Ecal " 406 << det <<
" layer " << std::setw(2) << layer
407 <<
" lay " << std::setw(2) << lay <<
" time " 408 << std::setw(6) << time <<
" theta " 409 << std::setw(8) << theta <<
" eta " 410 << std::setw(8) << eta <<
" phi " 411 << std::setw(8) << phi <<
" e " << std::setw(8)
412 << e <<
" ID 0x" << std::hex << unitID
418 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: " << det <<
" hits : " 428 LogDebug(
"ValidHcal") <<
"\n ===>>> SimG4HcalValidation: Energy deposit " 429 <<
"in MeV\n at EB : " << std::setw(6) <<
edepEB/
MeV 430 <<
"\n at EE : " << std::setw(6) <<
edepEE/
MeV 431 <<
"\n at HB : " << std::setw(6) <<
edepHB/
MeV 432 <<
"\n at HE : " << std::setw(6) <<
edepHE/
MeV 433 <<
"\n at HO : " << std::setw(6) <<
edepHO/
MeV 434 <<
"\n ---- SimG4HcalValidation: Energy deposit in";
435 for (i = 0; i < 5; i++)
436 LogDebug(
"ValidHcal") <<
" Depth " << std::setw(2) << i <<
" E " 437 << std::setw(8) <<
edepd[
i]/
MeV <<
" MeV";
438 LogDebug(
"ValidHcal") <<
" ---- SimG4HcalValidation: Energy deposit in" 440 for (i = 0; i < 20; i++)
441 LogDebug(
"ValidHcal") <<
" Layer " << std::setw(2) << i <<
" E " 442 << std::setw(8) <<
edepl[
i]/
MeV <<
" MeV";
448 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::HF hits " <<
vhitec 449 <<
" in EC and " <<
vhithc <<
" in HC\n" 451 <<
" in EC and " <<
enHcal <<
" in HC";
456 LogDebug(
"ValidHcal") <<
" layerAnalysis ===> after fetchHits";
464 std::vector<CaloHit>::iterator hit_itr;
466 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::NxNAnalysis : entrance ";
471 LogDebug(
"ValidHcal") <<
" NxNAnalysis : coolectEnergyRdir - Ecal " <<
een 481 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
483 double e = hit_itr->e();
484 double t = hit_itr->t();
485 double eta = hit_itr->eta();
486 double phi = hit_itr->phi();
487 int type = hit_itr->det();
488 int layer = hit_itr->layer();
494 if (type == 10 || type == 11 || type == 12) ee +=
e;
499 if (type == static_cast<int>(
HcalBarrel) && layer > 17) hoe +=
e;
502 for (
int i = 0;
i <
max;
i++ ) {
506 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: nxNAnalysis eta0," 507 <<
" phi0 = " <<
eta0 <<
" " <<
phi0 508 <<
" type, layer = " << type <<
"," 509 << layer <<
" eta, phi = " << eta <<
" " 524 LogDebug(
"ValidHcal") <<
" nxNAnalysis ===> after fillHvsE";
533 std::vector<CaloHit> * hhit = &
hitcache;
540 std::vector<SimG4HcalHitCluster>::iterator clus_itr;
542 LogDebug(
"ValidHcal") <<
"\n ---------- Final list of " << (*result).size()
543 <<
" clusters ---------------";
544 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++)
545 LogDebug(
"ValidHcal") << (*clus_itr);
547 std::vector<double> enevec, etavec, phivec;
549 if ((*result).size() > 0) {
551 sort((*result).begin(),(*result).end());
553 clus_itr = result->begin();
554 double etac = clus_itr->eta();
555 double phic = clus_itr->phi();
557 double ecal_collect = 0.;
559 ecal_collect = clus_itr->collectEcalEnergyR();}
564 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> ecal_collect = " 569 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> eta phi deviation = " << dist;
572 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEtaPhiProfileJet";
574 std::vector<CaloHit> *
hits = clus_itr->getHits() ;
575 std::vector<CaloHit>::iterator hit_itr;
577 double ee = 0.,
he = 0., hoe = 0., etot = 0.;
580 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
581 double e = hit_itr->e();
582 double t = hit_itr->t();
583 double r =
jetf->
rDist(&(*clus_itr), &(*hit_itr));
587 if (hit_itr->det() == 10 || hit_itr->det() == 11 ||
588 hit_itr->det() == 12) ee += e;
589 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) ||
590 hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
593 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) &&
594 hit_itr->layer() > 17)
598 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) ||
599 hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
607 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEcollectJet: " 608 <<
"ee/he/hoe/etot " << ee <<
"/" <<
he <<
"/" 609 << hoe <<
"/" << etot;
612 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++) {
614 enevec.push_back(clus_itr->e());
615 etavec.push_back(clus_itr->eta());
616 phivec.push_back(clus_itr->phi());
619 product.
fillJets(enevec, etavec, phivec);
621 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillJets\n" 622 <<
" JetAnalysis ===> (*result).size() " 626 if (etavec.size() > 1) {
627 if (etavec[0] > -2.5 && etavec[0] < 2.5 &&
628 etavec[1] > -2.5 && etavec[1] < 2.5) {
630 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet mass enter\n" 631 <<
" JetAnalysis ===> Di-jet vectors ";
632 for (
unsigned int i = 0;
i < enevec.size();
i++)
633 LogDebug(
"ValidHcal") <<
" e, eta, phi = " << enevec[
i] <<
" " 634 << etavec[
i] <<
" " << phivec[
i];
636 double et0 = enevec[0] / cosh(etavec[0]);
637 double px0 = et0 *
cos(phivec[0]);
638 double py0 = et0 *
sin(phivec[0]);
639 double pz0 = et0 * sinh(etavec[0]);
640 double et1 = enevec[1] / cosh(etavec[1]);
641 double px1 = et1 *
cos(phivec[1]);
642 double py1 = et1 *
sin(phivec[1]);
643 double pz1 = et1 * sinh(etavec[1]);
645 double dijetmass2 = (enevec[0]+enevec[1])*(enevec[0]+enevec[1])
646 - (px1+px0)*(px1+px0) - (py1+py0)*(py1+py0) - (pz1+pz0)*(pz1+pz0);
648 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet massSQ " 652 if(dijetmass2 >= 0.) dijetmass =
sqrt(dijetmass2);
653 else dijetmass = -
sqrt(-1. * dijetmass2);
657 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillDiJets";
666 LogDebug(
"ValidHcal") <<
"Enter SimG4HcalValidation::fetchHits with " 671 std::vector<CaloHit>::iterator itr;
672 std::vector<CaloHit*> lhits(nHit);
674 uint32_t unitID=itr->id();
680 group = (subdet&15)<<20;
681 group += ((lay-1)&31)<<15;
682 group += (zside&1)<<14;
683 group += (ieta&127)<<7;
687 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Original " << i
689 <<
"SimG4HcalValidation::fetchHits:Copied " << i
693 std::vector<CaloHit*>::iterator k1, k2;
694 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
695 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Sorted " << i
698 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
699 double ehit = (**k1).e();
700 double t = (**k1).t();
701 uint32_t unitID= (**k1).id();
703 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Start " << i
704 <<
" U/T/E" <<
" 0x" << std::hex << unitID
705 <<
std::dec <<
" " << t <<
" " << ehit;
706 for (k2 = k1+1; k2 != lhits.end() && (t-(**k2).t()) < 1 &&
707 (t-(**k2).t()) > -1 && unitID == (**k2).id(); k2++) {
709 LogDebug(
"ValidHcal") <<
"\t + " << (**k2).e();
712 LogDebug(
"ValidHcal") <<
"\t = " << ehit <<
" in " << jump;
714 double eta = (*k1)->eta();
715 double phi = (*k1)->phi();
716 int lay = ((unitID>>15)&31) + 1;
717 int subdet = (unitID>>20)&15;
718 int zside = (unitID>>14)&1;
719 int ieta = (unitID>>7)&127;
720 int iphi = (unitID)&127;
723 product.
fillHits(nHits, lay, subdet, eta, phi, ehit, t);
726 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Hit " << nHits
727 <<
" " << i <<
" ID 0x" << std::hex << unitID
728 <<
" det " <<
std::dec << subdet <<
" " << lay
729 <<
" " << zside <<
" " << ieta <<
" " << iphi
730 <<
" Time " << t <<
" E " << ehit;
736 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits called with " 737 << nHit <<
" hits" <<
" and writes out " << nHits
738 <<
'(' << hit <<
") hits";
751 std::vector<CaloHit>::iterator hit_itr;
753 double sume = 0., sumh = 0., sumho = 0.;
755 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
757 double e = hit_itr->e();
758 double eta = hit_itr->eta();
759 double phi = hit_itr->phi();
761 int type = hit_itr->det();
765 if (type == 10 || type == 11 || type == 12) {
770 hit_itr->layer() > 17) sumho += e;
787 }
else if (det ==
"HES" || det ==
"HED") {
789 }
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 update(const BeginOfJob *job)
This routine will be called when the appropriate signal arrives.
void fillLayers(double el[], double ed[], double ho, double hbhe, double ebee)
std::vector< float > scaleHF
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id)
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 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)
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 fillEcollectNxN(double een, double hen, double hoen, double etotn)
std::vector< SimG4HcalHitCluster > * getClusters(bool)
virtual ~SimG4HcalValidation()
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
HcalID unitID(int det, const CLHEP::Hep3Vector &pos, int depth, int lay=-1) const
HcalTestNumberingScheme * org
void layerAnalysis(PHcalValidInfoLayer &)
void fillHF(double fibl, double fibs, double enec, double enhc)
void produce(edm::Event &, const edm::EventSetup &)
double getEnergyDeposit() const