19 #include "G4SDManager.hh" 22 #include "G4VProcess.hh" 23 #include "G4HCofThisEvent.hh" 24 #include "CLHEP/Units/GlobalSystemOfUnits.h" 25 #include "CLHEP/Units/GlobalPhysicalConstants.h" 26 #include "Randomize.hh" 38 int laygroup = m_Anal.
getParameter<
int>(
"LayerGrouping");
44 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of " 45 <<
"begin/end events and of G4step";
50 for (
unsigned int i=0;
i<
group_.size();
i++)
56 <<
" Longitudinal groups and " <<
nTower 64 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of " 65 <<
"selected entries : " <<
count;
67 <<
", HistoClass " <<
tuples <<
", Numbering Scheme " 70 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Delete HcalQie";
73 if (numberingFromDDD) {
74 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Delete HcalNumberingFromDDD";
81 std::vector<int>
temp(19);
83 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
84 for (
int i=0;
i<19;
i++)
86 }
else if (group == 2) {
87 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
88 for (
int i=0;
i<19;
i++)
90 }
else if (group == 3) {
91 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
92 for (
int i=0;
i<19;
i++)
94 }
else if (group == 4) {
95 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
96 for (
int i=0;
i<19;
i++)
99 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
100 for (
int i=0;
i<19;
i++)
104 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Layer Grouping ";
105 for (
int i=0;
i<19;
i++)
106 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Group[" <<
i <<
"] = " 113 int etac = (centre/100)%100;
114 int phic = (centre%100);
132 nbuf = (etamax-etamin+1)*(phimax-phimin+1);
133 std::vector<int>
temp(2*nbuf);
134 for (
int eta=etamin;
eta<=etamax;
eta++) {
136 temp[kount] = (
eta*100 +
phi);
142 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for" 143 <<
" Central " << centre <<
" and " << nadd
144 <<
" on either side";
145 for (
int i=0;
i<nbuf;
i++)
146 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Tower[" << std::setw(3) <<
i 147 <<
"] " << temp[
i] <<
" " << temp[nbuf+
i];
157 (*job)()->get<HcalSimNumberingRecord>().get(hdc);
160 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Initialise " 161 <<
"HcalNumberingFromDDD for " <<
names[0];
175 int irun = (*run)()->GetRunID();
176 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
196 }
else if (idet == static_cast<int>(
HcalBarrel)) {
198 }
else if (idet == static_cast<int>(
HcalEndcap)) {
205 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Central Tower " 207 <<
" phi0 = " <<
phi0;
210 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
212 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
214 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with " 215 <<
"name " << sdname <<
" in this Setup";
218 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with " 219 <<
"name " << theCaloSD->GetName()
223 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new " 224 <<
"numbering scheme";
228 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get" 244 for (i = 0; i < 20; i++)
edepl[i] = 0.;
245 for (i = 0; i < 20; i++)
mudist[i] = -1.;
247 int iev = (*evt)()->GetEventID();
248 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << iev;
254 if (aStep !=
nullptr) {
255 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
256 G4String
name = curPV->GetName();
257 name.assign(name,0,3);
258 double edeposit = aStep->GetTotalEnergyDeposit();
262 }
else if (name ==
"EFR") {
264 }
else if (name ==
"HBS") {
265 layer = (curPV->GetCopyNo()/10)%100;
266 if (layer >= 0 && layer < 17) {
270 << curPV->GetName() << curPV->GetCopyNo();
273 }
else if (name ==
"HES") {
274 layer = (curPV->GetCopyNo()/10)%100;
275 if (layer >= 0 && layer < 19) {
279 << curPV->GetName() << curPV->GetCopyNo();
282 }
else if (name ==
"HTS") {
283 layer = (curPV->GetCopyNo()/10)%100;
284 if (layer >= 17 && layer < 20) {
288 << curPV->GetName() << curPV->GetCopyNo();
292 if (layer >= 0 && layer < 20) {
293 edepl[layer] += edeposit;
296 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
297 if ((part ==
"mu-" || part ==
"mu+") &&
mudist[layer] < 0) {
299 aStep->GetPreStepPoint()->GetPosition().y(),
300 aStep->GetPreStepPoint()->GetPosition().z());
309 if (layer >= 0 && layer < 20) {
310 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: " << name <<
" Layer " 311 << std::setw(3) << layer <<
" Edep " << std::setw(6)
312 << edeposit/
MeV <<
" MeV";
315 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: Null Step";
325 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after Fill";
328 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
330 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after QieAnalysis";
334 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
339 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after fillTree";
346 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Fill event " 347 << (*evt)()->GetEventID();
350 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
352 int nhc = 0, neb = 0, nef = 0, j = 0;
356 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
358 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[0]
359 <<
" of ID " << HCHCid <<
" is obtained at " << theHCHC;
360 if (HCHCid >= 0 && theHCHC !=
nullptr) {
361 for (j = 0; j < theHCHC->entries(); j++) {
369 double theta = pos.theta();
371 double phi = pos.phi();
374 int subdet,
zside, layer, etaIndex, phiIndex, lay;
377 if (jitter<0) jitter = 0;
378 CaloHit hit(subdet,lay,e,eta,phi,jitter,unitID);
385 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
386 if (etaIndex <= 20) {
393 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
394 << layer <<
" time " << std::setw(6) << time
395 <<
" theta " << std::setw(8) << theta <<
" eta " 396 << std::setw(8) << eta <<
" phi " << std::setw(8)
397 << phi <<
" e " << std::setw(8) <<
e;
400 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::HCAL hits : " << nhc <<
"\n";
403 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[1]);
405 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[1]
406 <<
" of ID " << EBHCid <<
" is obtained at " << theEBHC;
407 if (EBHCid >= 0 && theEBHC !=
nullptr) {
408 for (j = 0; j < theEBHC->entries(); j++) {
417 double theta = pos.theta();
419 double phi = pos.phi();
423 int subdet,
zside, layer, ieta, iphi, lay;
428 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
431 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
432 << layer <<
" time " << std::setw(6) << time
433 <<
" theta " << std::setw(8) << theta <<
" eta " 434 << std::setw(8) << eta <<
" phi " << std::setw(8)
435 << phi <<
" e " << std::setw(8) <<
e;
438 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EB hits : " << neb <<
"\n";
441 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[2]);
443 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[2]
444 <<
" of ID " << EEHCid <<
" is obtained at " << theEEHC;
445 if (EEHCid >= 0 && theEEHC !=
nullptr) {
446 for (j = 0; j < theEEHC->entries(); j++) {
455 double theta = pos.theta();
457 double phi = pos.phi();
461 int subdet,
zside, layer, ieta, iphi, lay;
466 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
469 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
470 << layer <<
" time " << std::setw(6) << time
471 <<
" theta " << std::setw(8) << theta <<
" eta " 472 << std::setw(8) << eta <<
" phi " << std::setw(8)
473 << phi <<
" e " << std::setw(8) <<
e;
476 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EE hits : " << nef <<
"\n";
489 int subdet,
zside, layer, ieta, iphi, lay;
494 laymax = 4; det =
"HB";
495 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
496 laymax = 2; det =
"HES";
498 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: " << det <<
" Eta " << ieta
499 <<
" Phi " << iphi <<
" Laymax " << laymax <<
" Hits " 502 if (laymax>0 && hittot>0) {
503 std::vector<CaloHit>
hits(hittot);
504 std::vector<double> eqielay(80,0.0), esimlay(80,0.0), esimtot(4,0.0);
505 std::vector<double> eqietow(200,0.0), esimtow(200,0.0), eqietot(4,0.0);
509 for (
int layr=0; layr<
nGroup; layr++) {
524 for (
int it=0; it<
nTower; it++) {
527 for (
int k1 = 0; k1 < hittot; k1++) {
529 int subdetc = hit.
det();
530 int layer = hit.
layer();
532 if (layer > 0 && layer < 20) group =
group_[layer];
533 if (subdetc == subdet && group == layr+1) {
534 int zsidec, ietac, iphic,
idx;
537 if (etac > 0 && phic > 0) {
538 idx = ietac*100 + iphic;
539 }
else if (etac > 0) {
541 }
else if (phic > 0) {
546 if (zsidec==zside && idx==
tower_[it]) {
548 LogDebug(
"HcalSim") <<
"HcalTest: Hit " << nhit <<
" " << hit;
555 std::vector<int> cd =
myqie->
getCode(nhit, hits, engine);
558 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer " 559 << layr <<
" Sim " << esim <<
" After QIE " <<eqie;
560 for (
int i=0;
i<4;
i++) {
564 esimlay[20*
i+layr] += esim;
565 eqielay[20*
i+layr] += eqie;
566 esimtow[50*
i+it] += esim;
567 eqietow[50*
i+it] += eqie;
572 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3]
573 <<
" (SimHit) " << eqietot[3] <<
" (After QIE)";
575 std::vector<double> latphi(10);
577 for (
int it=0; it<
nt; it++)
579 for (
int i=0;
i<4;
i++) {
580 double scals=1, scalq=1;
581 std::vector<double> latfs(10,0.), latfq(10,0.), longs(20), longq(20);
582 if (esimtot[
i]>0) scals = 1./esimtot[
i];
583 if (eqietot[
i]>0) scalq = 1./eqietot[
i];
584 for (
int it=0; it<
nTower; it++) {
586 latfs[phib] += scals*esimtow[50*
i+it];
587 latfq[phib] += scalq*eqietow[50*
i+it];
589 for (
int layr=0; layr<=
nGroup; layr++) {
590 longs[layr] = scals*esimlay[20*
i+layr];
591 longq[layr] = scalq*eqielay[20*
i+layr];
594 nt,latphi,latfs,latfq);
603 LogDebug(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit in MeV " 604 <<
"\n at EB : " << std::setw(6) <<
edepEB/
MeV 605 <<
"\n at EE : " << std::setw(6) <<
edepEE/
MeV 606 <<
"\n at HB : " << std::setw(6) <<
edepHB/
MeV 607 <<
"\n at HE : " << std::setw(6) <<
edepHE/
MeV 608 <<
"\n at HO : " << std::setw(6) <<
edepHO/
MeV 609 <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
610 for (i = 0; i < 20; i++)
611 LogDebug(
"HcalSim") <<
" Layer " << std::setw(2) << i <<
" E " 612 << std::setw(8) <<
edepl[
i]/
MeV <<
" MeV";
624 const double rLay[19] = {
625 1836.0, 1902.0, 1962.0, 2022.0, 2082.0, 2142.0, 2202.0, 2262.0, 2322.0,
626 2382.0, 2448.0, 2514.0, 2580.0, 2646.0, 2712.0, 2776.0, 2862.5, 3847.0,
628 if (layer>0 && layer<20) dist += rLay[layer-1]*mm/
sin(theta);
630 const double zLay[19] = {
631 4034.0, 4032.0, 4123.0, 4210.0, 4297.0, 4384.0, 4471.0, 4558.0, 4645.0,
632 4732.0, 4819.0, 4906.0, 4993.0, 5080.0, 5167.0, 5254.0, 5341.0, 5428.0,
634 if (layer>0 && layer<20) dist += zLay[layer-1]*mm/
cos(theta);
636 double tmp = dist/c_light/ns;
637 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::timeOfFlight " << tmp
638 <<
" for det/lay " << det <<
" " << layer
639 <<
" eta/theta " << eta <<
" " << theta/deg <<
" dist "
void fillQie(int id, double esimtot, double eqietot, int nGroup, const std::vector< double > &longs, const std::vector< double > &longq, int nTower, const std::vector< double > &latphi, const std::vector< double > &latfs, const std::vector< double > &latfq)
T getParameter(std::string const &) const
math::XYZPoint getPosition() const
HcalNumberingFromDDD * numberingFromDDD
void fillLayers(double el[], double ho, double hbhe, double muxy[])
std::vector< int > layerGrouping(int)
Sin< T >::type sin(const T &t)
Geom::Theta< T > theta() const
void fillHits(std::vector< CaloHit > &)
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
HcalDDDSimConstants * hcons
std::vector< std::string > names
HcalTestNumberingScheme * org
HcalCellType::HcalCell cell(const int &det, const int &zside, const int &depth, const int &etaR, const int &iphi) const
void setNumberingScheme(HcalNumberingScheme *)
std::vector< int > towersToAdd(int centre, int nadd)
double timeOfFlight(int det, int layer, double eta)
void fill(const EndOfEvent *ev)
static uint32_t packHcalIndex(int det, int z, int depth, int eta, int phi, int lay)
std::vector< int > tower_
HcalTestAnalysis(const edm::ParameterSet &p)
double getEnergy(const std::vector< int > &)
Cos< T >::type cos(const T &t)
~HcalTestAnalysis() override
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
HcalTestHistoClass * tuples
std::unique_ptr< HcalTestHistoManager > tuplesManager
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< std::vector< double > > tmp
std::vector< int > getCode(int, const std::vector< CaloHit > &, CLHEP::HepRandomEngine *)
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
std::vector< CaloHit > caloHitCache
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
double getTimeSlice() const
void qieAnalysis(CLHEP::HepRandomEngine *)
uint32_t getUnitID() const
HcalID unitID(int det, const CLHEP::Hep3Vector &pos, int depth, int lay=-1) const
std::vector< int > group_
double getEnergyDeposit() const
uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id) override