19 #include "G4SDManager.hh"
22 #include "G4VProcess.hh"
23 #include "G4HCofThisEvent.hh"
24 #include "CLHEP/Units/GlobalSystemOfUnits.h"
25 #include "CLHEP/Units/GlobalPhysicalConstants.h"
32 myqie(0), addTower(3), tuplesManager(0), tuples(0), numberingFromDDD(0), org(0) {
37 int laygroup = m_Anal.
getParameter<
int>(
"LayerGrouping");
42 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of "
43 <<
"begin/end events and of G4step";
48 for (
unsigned int i=0;
i<
group_.size();
i++)
54 <<
" Longitudinal groups and " <<
nTower
62 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of "
63 <<
"selected entries : " <<
count;
65 <<
", HistoClass " <<
tuples <<
", Numbering Scheme "
68 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Delete HcalQie";
71 if (numberingFromDDD) {
72 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Delete HcalNumberingFromDDD";
79 std::vector<int>
temp(19);
81 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
82 for (
int i=0;
i<19;
i++)
84 }
else if (group == 2) {
85 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
86 for (
int i=0;
i<19;
i++)
88 }
else if (group == 3) {
89 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
90 for (
int i=0;
i<19;
i++)
92 }
else if (group == 4) {
93 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
94 for (
int i=0;
i<19;
i++)
97 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
98 for (
int i=0;
i<19;
i++)
102 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Layer Grouping ";
103 for (
int i=0;
i<19;
i++)
104 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Group[" <<
i <<
"] = "
111 int etac = (centre/100)%100;
112 int phic = (centre%100);
130 nbuf = (etamax-etamin+1)*(phimax-phimin+1);
131 std::vector<int>
temp(2*nbuf);
132 for (
int eta=etamin;
eta<=etamax;
eta++) {
134 temp[kount] = (
eta*100 +
phi);
140 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for"
141 <<
" Central " << centre <<
" and " << nadd
142 <<
" on either side";
143 for (
int i=0;
i<nbuf;
i++)
144 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Tower[" << std::setw(3) <<
i
145 <<
"] " << temp[
i] <<
" " << temp[nbuf+
i];
154 (*job)()->get<IdealGeometryRecord>().get(pDD);
155 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Initialise "
156 <<
"HcalNumberingFromDDD for " <<
names[0];
170 int irun = (*run)()->GetRunID();
171 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
191 }
else if (idet == static_cast<int>(
HcalBarrel)) {
193 }
else if (idet == static_cast<int>(
HcalEndcap)) {
200 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Central Tower "
202 <<
" phi0 = " <<
phi0;
204 std::string sdname =
names[0];
205 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
207 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
209 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with "
210 <<
"name " << sdname <<
" in this Setup";
213 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with "
214 <<
"name " << theCaloSD->GetName()
218 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new "
219 <<
"numbering scheme";
223 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get"
239 for (i = 0; i < 20; i++)
edepl[i] = 0.;
240 for (i = 0; i < 20; i++)
mudist[i] = -1.;
242 int iev = (*evt)()->GetEventID();
243 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << iev;
250 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
251 G4String
name = curPV->GetName();
252 name.assign(name,0,3);
253 double edeposit = aStep->GetTotalEnergyDeposit();
257 }
else if (name ==
"EFR") {
259 }
else if (name ==
"HBS") {
260 layer = (curPV->GetCopyNo()/10)%100;
261 if (layer >= 0 && layer < 17) {
265 << curPV->GetName() << curPV->GetCopyNo();
268 }
else if (name ==
"HES") {
269 layer = (curPV->GetCopyNo()/10)%100;
270 if (layer >= 0 && layer < 19) {
274 << curPV->GetName() << curPV->GetCopyNo();
277 }
else if (name ==
"HTS") {
278 layer = (curPV->GetCopyNo()/10)%100;
279 if (layer >= 17 && layer < 20) {
283 << curPV->GetName() << curPV->GetCopyNo();
287 if (layer >= 0 && layer < 20) {
288 edepl[layer] += edeposit;
291 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
292 if ((part ==
"mu-" || part ==
"mu+") &&
mudist[layer] < 0) {
294 aStep->GetPreStepPoint()->GetPosition().y(),
295 aStep->GetPreStepPoint()->GetPosition().z());
304 if (layer >= 0 && layer < 20) {
305 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: " << name <<
" Layer "
306 << std::setw(3) << layer <<
" Edep " << std::setw(6)
307 << edeposit/MeV <<
" MeV";
310 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: Null Step";
320 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after Fill";
324 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after QieAnalysis";
328 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
333 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after fillTree";
340 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Fill event "
341 << (*evt)()->GetEventID();
344 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
346 int nhc = 0, neb = 0, nef = 0,
j = 0;
350 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
352 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[0]
353 <<
" of ID " << HCHCid <<
" is obtained at " << theHCHC;
354 if (HCHCid >= 0 && theHCHC > 0) {
355 for (
j = 0;
j < theHCHC->entries();
j++) {
363 double theta = pos.theta();
365 double phi = pos.phi();
368 int subdet, zside, layer, etaIndex, phiIndex, lay;
371 if (jitter<0) jitter = 0;
372 CaloHit hit(subdet,lay,e,eta,phi,jitter,unitID);
376 std::string det =
"HB";
379 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
380 if (etaIndex <= 20) {
387 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
388 << layer <<
" time " << std::setw(6) << time
389 <<
" theta " << std::setw(8) << theta <<
" eta "
390 << std::setw(8) << eta <<
" phi " << std::setw(8)
391 << phi <<
" e " << std::setw(8) <<
e;
394 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::HCAL hits : " << nhc <<
"\n";
397 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[1]);
399 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[1]
400 <<
" of ID " << EBHCid <<
" is obtained at " << theEBHC;
401 if (EBHCid >= 0 && theEBHC > 0) {
402 for (
j = 0;
j < theEBHC->entries();
j++) {
408 std::string det =
"EB";
411 double theta = pos.theta();
413 double phi = pos.phi();
417 int subdet, zside, layer, ieta, iphi, lay;
422 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
425 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
426 << layer <<
" time " << std::setw(6) << time
427 <<
" theta " << std::setw(8) << theta <<
" eta "
428 << std::setw(8) << eta <<
" phi " << std::setw(8)
429 << phi <<
" e " << std::setw(8) <<
e;
432 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EB hits : " << neb <<
"\n";
435 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[2]);
437 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[2]
438 <<
" of ID " << EEHCid <<
" is obtained at " << theEEHC;
439 if (EEHCid >= 0 && theEEHC > 0) {
440 for (
j = 0;
j < theEEHC->entries();
j++) {
446 std::string det =
"EE";
449 double theta = pos.theta();
451 double phi = pos.phi();
455 int subdet, zside, layer, ieta, iphi, lay;
460 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
463 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
464 << layer <<
" time " << std::setw(6) << time
465 <<
" theta " << std::setw(8) << theta <<
" eta "
466 << std::setw(8) << eta <<
" phi " << std::setw(8)
467 << phi <<
" e " << std::setw(8) <<
e;
470 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EE hits : " << nef <<
"\n";
483 int subdet, zside, layer, ieta, iphi, lay;
486 std::string det =
"Unknown";
488 laymax = 4; det =
"HB";
489 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
490 laymax = 2; det =
"HES";
492 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: " << det <<
" Eta " << ieta
493 <<
" Phi " << iphi <<
" Laymax " << laymax <<
" Hits "
496 if (laymax>0 && hittot>0) {
497 std::vector<CaloHit> hits(hittot);
498 std::vector<double> eqielay(80,0.0), esimlay(80,0.0), esimtot(4,0.0);
499 std::vector<double> eqietow(200,0.0), esimtow(200,0.0), eqietot(4,0.0);
503 for (
int layr=0; layr<
nGroup; layr++) {
518 for (
int it=0; it<
nTower; it++) {
521 for (
int k1 = 0; k1 < hittot; k1++) {
523 int subdetc = hit.
det();
524 int layer = hit.
layer();
526 if (layer > 0 && layer < 20) group =
group_[layer];
527 if (subdetc == subdet && group == layr+1) {
528 int zsidec, ietac, iphic, idx;
531 if (etac > 0 && phic > 0) {
532 idx = ietac*100 + iphic;
533 }
else if (etac > 0) {
535 }
else if (phic > 0) {
540 if (zsidec==zside && idx==
tower_[it]) {
542 LogDebug(
"HcalSim") <<
"HcalTest: Hit " << nhit <<
" " << hit;
552 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer "
553 << layr <<
" Sim " << esim <<
" After QIE " <<eqie;
554 for (
int i=0;
i<4;
i++) {
558 esimlay[20*
i+layr] += esim;
559 eqielay[20*
i+layr] += eqie;
560 esimtow[50*
i+it] += esim;
561 eqietow[50*
i+it] += eqie;
566 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3]
567 <<
" (SimHit) " << eqietot[3] <<
" (After QIE)";
569 std::vector<double> latphi(10);
571 for (
int it=0; it<
nt; it++)
573 for (
int i=0;
i<4;
i++) {
574 double scals=1, scalq=1;
575 std::vector<double> latfs(10,0.), latfq(10,0.), longs(20), longq(20);
576 if (esimtot[
i]>0) scals = 1./esimtot[
i];
577 if (eqietot[
i]>0) scalq = 1./eqietot[
i];
578 for (
int it=0; it<
nTower; it++) {
580 latfs[phib] += scals*esimtow[50*
i+it];
581 latfq[phib] += scalq*eqietow[50*
i+it];
583 for (
int layr=0; layr<=
nGroup; layr++) {
584 longs[layr] = scals*esimlay[20*
i+layr];
585 longq[layr] = scalq*eqielay[20*
i+layr];
588 nt,latphi,latfs,latfq);
597 LogDebug(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit in MeV "
598 <<
"\n at EB : " << std::setw(6) <<
edepEB/MeV
599 <<
"\n at EE : " << std::setw(6) <<
edepEE/MeV
600 <<
"\n at HB : " << std::setw(6) <<
edepHB/MeV
601 <<
"\n at HE : " << std::setw(6) <<
edepHE/MeV
602 <<
"\n at HO : " << std::setw(6) <<
edepHO/MeV
603 <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
604 for (i = 0; i < 20; i++)
605 LogDebug(
"HcalSim") <<
" Layer " << std::setw(2) << i <<
" E "
606 << std::setw(8) <<
edepl[
i]/MeV <<
" MeV";
618 const double rLay[19] = {
619 1836.0, 1902.0, 1962.0, 2022.0, 2082.0, 2142.0, 2202.0, 2262.0, 2322.0,
620 2382.0, 2448.0, 2514.0, 2580.0, 2646.0, 2712.0, 2776.0, 2862.5, 3847.0,
622 if (layer>0 && layer<20) dist += rLay[layer-1]*mm/
sin(theta);
624 const double zLay[19] = {
625 4034.0, 4032.0, 4123.0, 4210.0, 4297.0, 4384.0, 4471.0, 4558.0, 4645.0,
626 4732.0, 4819.0, 4906.0, 4993.0, 5080.0, 5167.0, 5254.0, 5341.0, 5428.0,
628 if (layer>0 && layer<20) dist += zLay[layer-1]*mm/
cos(theta);
630 double tmp = dist/c_light/ns;
631 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::timeOfFlight " << tmp
632 <<
" for det/lay " << det <<
" " << layer
633 <<
" eta/theta " << eta <<
" " << theta/deg <<
" dist "
T getParameter(std::string const &) const
double getEnergy(std::vector< int >)
math::XYZPoint getPosition() const
HcalNumberingFromDDD * numberingFromDDD
void fillLayers(double el[], double ho, double hbhe, double muxy[])
virtual ~HcalTestAnalysis()
std::vector< int > layerGrouping(int)
Sin< T >::type sin(const T &t)
Geom::Theta< T > theta() const
std::auto_ptr< HcalTestHistoManager > tuplesManager
std::vector< std::string > names
HcalTestNumberingScheme * org
void setNumberingScheme(HcalNumberingScheme *)
std::vector< int > towersToAdd(int centre, int nadd)
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
double timeOfFlight(int det, int layer, double eta)
const T & max(const T &a, const T &b)
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)
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
HcalTestHistoClass * tuples
std::vector< int > getCode(int, std::vector< CaloHit >)
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< std::vector< double > > tmp
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
HcalCellType::HcalCell cell(int det, int zside, int depth, int etaR, int iphi, bool corr=true) const
HcalID unitID(int det, CLHEP::Hep3Vector pos, int depth, int lay=-1) const
void fillQie(int id, double esimtot, double eqietot, int nGroup, std::vector< double > longs, std::vector< double > longq, int nTower, std::vector< double > latphi, std::vector< double > latfs, std::vector< double > latfq)
uint32_t getUnitID() const
void fillHits(std::vector< CaloHit >)
std::vector< int > group_
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID id)
double getEnergyDeposit() const