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<IdealGeometryRecord>().get(pDD);
158 edm::LogInfo(
"ValidHcal") <<
"HcalTestAnalysis:: Initialise "
159 <<
"HcalNumberingFromDDD for " <<
names[0];
169 int irun = (*run)()->GetRunID();
171 edm::LogInfo(
"ValidHcal") <<
" =====> Begin of Run = " << irun;
173 std::string sdname =
names[0];
174 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
176 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
178 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: No SD"
179 <<
" with name " << sdname <<
" in this "
183 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Finds SD"
184 <<
"with name " << theCaloSD->GetName()
188 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: set a "
189 <<
"new numbering scheme";
193 edm::LogWarning(
"ValidHcal") <<
"SimG4HcalValidation::beginOfRun: Could "
194 <<
"not get SD Manager!";
204 for (i = 0; i < 5; i++)
edepd[i] = 0.;
205 for (i = 0; i < 20; i++)
edepl[i] = 0.;
210 int iev = (*evt)()->GetEventID();
211 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation: =====> Begin of event = "
219 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
220 G4String
name = curPV->GetName();
221 name.assign(name,0,3);
222 double edeposit = aStep->GetTotalEnergyDeposit();
223 int layer=-1, depth=-1;
227 }
else if (name ==
"EFR") {
230 }
else if (name ==
"HBS") {
231 layer = (curPV->GetCopyNo()/10)%100;
232 depth = (curPV->GetCopyNo())%10 + 1;
233 if (depth > 0 && depth < 4 && layer >= 0 && layer < 17) {
237 << curPV->GetName() << curPV->GetCopyNo();
238 depth = -1; layer = -1;
240 }
else if (name ==
"HES") {
241 layer = (curPV->GetCopyNo()/10)%100;
242 depth = (curPV->GetCopyNo())%10 + 1;
243 if (depth > 0 && depth < 3 && layer >= 0 && layer < 19) {
247 << curPV->GetName() << curPV->GetCopyNo();
248 depth = -1; layer = -1;
250 }
else if (name ==
"HTS") {
251 layer = (curPV->GetCopyNo()/10)%100;
252 depth = (curPV->GetCopyNo())%10 + 1;
253 if (depth > 3 && depth < 5 && layer >= 17 && layer < 20) {
257 << curPV->GetName() <<curPV->GetCopyNo();
258 depth = -1; layer = -1;
261 if (depth >= 0 && depth < 5)
edepd[depth] += edeposit;
262 if (layer >= 0 && layer < 20)
edepl[layer] += edeposit;
264 if (layer >= 0 && layer < 20) {
265 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: G4Step: " << name
266 <<
" Layer " << std::setw(3) << layer <<
" Depth "
267 << std::setw(2) << depth <<
" Edep " <<std::setw(6)
268 << edeposit/MeV <<
" MeV";
280 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: --- after Fill ";
286 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:Fill event "
287 << (*evt)()->GetEventID();
290 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
295 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
297 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation :: Hit Collection for "
298 <<
names[0] <<
" of ID " << HCHCid <<
" is obtained at "
300 if (HCHCid >= 0 && theHCHC > 0) {
301 for (
j = 0;
j < theHCHC->entries();
j++) {
309 double theta = pos.theta();
311 double phi = pos.phi();
314 int subdet, zside, layer, etaIndex, phiIndex, lay;
319 std::string det =
"HB";
323 if (depth != 0) { layer += 2; lay += 2; }
324 if (layer == 1)
vhithc += e;
325 else if (layer == 0)
vhitec += e;
327 edm::LogInfo(
"ValidHcal") <<
"SimG4HcalValidation::HitPMT "
328 << subdet <<
" " << (2*zside-1)*etaIndex
329 <<
" " << phiIndex <<
" " << layer+1
330 <<
" R " << pos.rho() <<
" Phi " << phi/deg
331 <<
" Edep " << e <<
" Time " <<
time;
332 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
333 if (etaIndex <= 20) {
339 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Hcal "
340 << det <<
" layer " << std::setw(2) << layer
341 <<
" lay " << std::setw(2) << lay <<
" time "
342 << std::setw(6) << time <<
" theta "
343 << std::setw(8) << theta <<
" eta " << std::setw(8)
344 << eta <<
" phi " << std::setw(8) << phi <<
" e "
345 << std::setw(8) << e <<
" ID 0x" << std::hex
346 << unitID <<
" ID dec " << std::dec << (int)unitID;
354 CaloHit ahit(subdet,lay,e,eta,phi,time,unitID);
360 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: HCAL hits : " << nhc;
363 int ndets =
names.size();
364 if (ndets > 3) ndets = 3;
365 for (
int idty = 1; idty < ndets; idty++) {
366 std::string det =
"EB";
367 if (idty == 2) det =
"EE";
368 else if (idty > 2) det =
"ES";
371 int ECHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[idty]);
373 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: Hit Collection for "
374 <<
names[idty] <<
" of ID " << ECHCid
375 <<
" is obtained at " << theECHC;
376 if (ECHCid >= 0 && theECHC > 0) {
377 for (
j = 0;
j < theECHC->entries();
j++) {
385 double theta = pos.theta();
387 double phi = pos.phi();
390 int subdet, zside, layer, ieta, iphi, lay;
399 CaloHit ahit(subdet,lay,e,eta,phi,time,unitID);
404 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::debugFill Ecal "
405 << det <<
" layer " << std::setw(2) << layer
406 <<
" lay " << std::setw(2) << lay <<
" time "
407 << std::setw(6) << time <<
" theta "
408 << std::setw(8) << theta <<
" eta "
409 << std::setw(8) << eta <<
" phi "
410 << std::setw(8) << phi <<
" e " << std::setw(8)
411 << e <<
" ID 0x" << std::hex << unitID
412 <<
" ID dec " << std::dec << (int)unitID;
417 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation:: " << det <<
" hits : "
427 LogDebug(
"ValidHcal") <<
"\n ===>>> SimG4HcalValidation: Energy deposit "
428 <<
"in MeV\n at EB : " << std::setw(6) <<
edepEB/MeV
429 <<
"\n at EE : " << std::setw(6) <<
edepEE/MeV
430 <<
"\n at HB : " << std::setw(6) <<
edepHB/MeV
431 <<
"\n at HE : " << std::setw(6) <<
edepHE/MeV
432 <<
"\n at HO : " << std::setw(6) <<
edepHO/MeV
433 <<
"\n ---- SimG4HcalValidation: Energy deposit in";
434 for (i = 0; i < 5; i++)
435 LogDebug(
"ValidHcal") <<
" Depth " << std::setw(2) << i <<
" E "
436 << std::setw(8) <<
edepd[
i]/MeV <<
" MeV";
437 LogDebug(
"ValidHcal") <<
" ---- SimG4HcalValidation: Energy deposit in"
439 for (i = 0; i < 20; i++)
440 LogDebug(
"ValidHcal") <<
" Layer " << std::setw(2) << i <<
" E "
441 << std::setw(8) <<
edepl[
i]/MeV <<
" MeV";
447 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::HF hits " <<
vhitec
448 <<
" in EC and " <<
vhithc <<
" in HC\n"
450 <<
" in EC and " <<
enHcal <<
" in HC";
455 LogDebug(
"ValidHcal") <<
" layerAnalysis ===> after fetchHits";
462 std::vector<CaloHit> * hits = &
hitcache;
463 std::vector<CaloHit>::iterator hit_itr;
465 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::NxNAnalysis : entrance ";
470 LogDebug(
"ValidHcal") <<
" NxNAnalysis : coolectEnergyRdir - Ecal " <<
een
480 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
482 double e = hit_itr->e();
483 double t = hit_itr->t();
484 double eta = hit_itr->eta();
485 double phi = hit_itr->phi();
486 int type = hit_itr->det();
487 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 <<
" "
525 LogDebug(
"ValidHcal") <<
" nxNAnalysis ===> after fillHvsE";
534 std::vector<CaloHit> * hhit = &
hitcache;
541 std::vector<SimG4HcalHitCluster>::iterator clus_itr;
543 LogDebug(
"ValidHcal") <<
"\n ---------- Final list of " << (*result).size()
544 <<
" clusters ---------------";
545 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++)
546 LogDebug(
"ValidHcal") << (*clus_itr);
548 std::vector<double> enevec, etavec, phivec;
550 if ((*result).size() > 0) {
552 sort((*result).begin(),(*result).end());
554 clus_itr = result->begin();
555 double etac = clus_itr->eta();
556 double phic = clus_itr->phi();
558 double ecal_collect = 0.;
560 ecal_collect = clus_itr->collectEcalEnergyR();}
565 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> ecal_collect = "
570 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> eta phi deviation = " << dist;
573 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEtaPhiProfileJet";
575 std::vector<CaloHit> * hits = clus_itr->getHits() ;
576 std::vector<CaloHit>::iterator hit_itr;
578 double ee = 0., he = 0., hoe = 0., etot = 0.;
581 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
582 double e = hit_itr->e();
583 double t = hit_itr->t();
584 double r =
jetf->
rDist(&(*clus_itr), &(*hit_itr));
588 if (hit_itr->det() == 10 || hit_itr->det() == 11 ||
589 hit_itr->det() == 12) ee += e;
590 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) ||
591 hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
594 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) &&
595 hit_itr->layer() > 17)
599 if (hit_itr->det() ==
static_cast<int>(
HcalBarrel) ||
600 hit_itr->det() ==
static_cast<int>(
HcalEndcap) ||
608 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillEcollectJet: "
609 <<
"ee/he/hoe/etot " << ee <<
"/" << he <<
"/"
610 << hoe <<
"/" << etot;
613 for (clus_itr = result->begin(); clus_itr < result->end(); clus_itr++) {
615 enevec.push_back(clus_itr->e());
616 etavec.push_back(clus_itr->eta());
617 phivec.push_back(clus_itr->phi());
620 product.
fillJets(enevec, etavec, phivec);
622 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillJets\n"
623 <<
" JetAnalysis ===> (*result).size() "
627 if (etavec.size() > 1) {
628 if (etavec[0] > -2.5 && etavec[0] < 2.5 &&
629 etavec[1] > -2.5 && etavec[1] < 2.5) {
631 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet mass enter\n"
632 <<
" JetAnalysis ===> Di-jet vectors ";
633 for (
unsigned int i = 0;
i < enevec.size();
i++)
634 LogDebug(
"ValidHcal") <<
" e, eta, phi = " << enevec[
i] <<
" "
635 << etavec[
i] <<
" " << phivec[
i];
637 double et0 = enevec[0] / cosh(etavec[0]);
638 double px0 = et0 *
cos(phivec[0]);
639 double py0 = et0 *
sin(phivec[0]);
640 double pz0 = et0 * sinh(etavec[0]);
641 double et1 = enevec[1] / cosh(etavec[1]);
642 double px1 = et1 *
cos(phivec[1]);
643 double py1 = et1 *
sin(phivec[1]);
644 double pz1 = et1 * sinh(etavec[1]);
646 double dijetmass2 = (enevec[0]+enevec[1])*(enevec[0]+enevec[1])
647 - (px1+px0)*(px1+px0) - (py1+py0)*(py1+py0) - (pz1+pz0)*(pz1+pz0);
649 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> Di-jet massSQ "
653 if(dijetmass2 >= 0.) dijetmass =
sqrt(dijetmass2);
654 else dijetmass = -
sqrt(-1. * dijetmass2);
658 LogDebug(
"ValidHcal") <<
" JetAnalysis ===> after fillDiJets";
667 LogDebug(
"ValidHcal") <<
"Enter SimG4HcalValidation::fetchHits with "
672 std::vector<CaloHit>::iterator itr;
673 std::vector<CaloHit*> lhits(nHit);
675 uint32_t unitID=itr->id();
676 int subdet, zside, group, ieta, iphi, lay;
681 group = (subdet&15)<<20;
682 group += ((lay-1)&31)<<15;
683 group += (zside&1)<<14;
684 group += (ieta&127)<<7;
688 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Original " << i
690 <<
"SimG4HcalValidation::fetchHits:Copied " << i
694 std::vector<CaloHit*>::iterator k1, k2;
695 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
696 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Sorted " << i
699 for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
700 double ehit = (**k1).e();
701 double t = (**k1).t();
702 uint32_t unitID= (**k1).id();
704 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Start " << i
705 <<
" U/T/E" <<
" 0x" << std::hex << unitID
706 << std::dec <<
" " << t <<
" " << ehit;
707 for (k2 = k1+1; k2 != lhits.end() && (t-(**k2).t()) < 1 &&
708 (t-(**k2).t()) > -1 && unitID == (**k2).id(); k2++) {
710 LogDebug(
"ValidHcal") <<
"\t + " << (**k2).e();
713 LogDebug(
"ValidHcal") <<
"\t = " << ehit <<
" in " << jump;
715 double eta = (*k1)->eta();
716 double phi = (*k1)->phi();
717 int lay = ((unitID>>15)&31) + 1;
718 int subdet = (unitID>>20)&15;
719 int zside = (unitID>>14)&1;
720 int ieta = (unitID>>7)&127;
721 int iphi = (unitID)&127;
724 product.
fillHits(nHits, lay, subdet, eta, phi, ehit, t);
727 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits:Hit " << nHits
728 <<
" " << i <<
" ID 0x" << std::hex << unitID
729 <<
" det " << std::dec << subdet <<
" " << lay
730 <<
" " << zside <<
" " << ieta <<
" " << iphi
731 <<
" Time " << t <<
" E " << ehit;
737 LogDebug(
"ValidHcal") <<
"SimG4HcalValidation::fetchHits called with "
738 << nHit <<
" hits" <<
" and writes out " << nHits
739 <<
'(' << hit <<
") hits";
751 std::vector<CaloHit> * hits = &
hitcache;
752 std::vector<CaloHit>::iterator hit_itr;
754 double sume = 0., sumh = 0., sumho = 0.;
756 for (hit_itr = hits->begin(); hit_itr < hits->end(); hit_itr++) {
758 double e = hit_itr->e();
759 double eta = hit_itr->eta();
760 double phi = hit_itr->phi();
762 int type = hit_itr->det();
766 if (type == 10 || type == 11 || type == 12) {
771 hit_itr->layer() > 17) sumho += e;
788 }
else if (det ==
"HES" || det ==
"HED") {
790 }
else if (det ==
"HF") {
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
HcalNumberingFromDDD * numberingFromDDD
math::XYZPoint getPosition() const
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
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
const T & max(const T &a, const T &b)
static uint32_t packHcalIndex(int det, int z, int depth, int eta, int phi, int lay)
void fetchHits(PHcalValidInfoLayer &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
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)
Log< T >::type log(const T &t)
virtual ~SimG4HcalValidation()
void fillTProfileNxN(double e, int i, double t)
XYZPointD XYZPoint
point in space with cartesian internal representation
void fillJets(std::vector< double > enj, std::vector< double > etaj, std::vector< double > phij)
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)
HcalID unitID(int det, CLHEP::Hep3Vector pos, int depth, int lay=-1) const
uint32_t getUnitID() const
HcalTestNumberingScheme * org
void layerAnalysis(PHcalValidInfoLayer &)
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID id)
void fillHF(double fibl, double fibs, double enec, double enhc)
void produce(edm::Event &, const edm::EventSetup &)
double getEnergyDeposit() const