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 "CLHEP/Random/Random.h"
33 myqie(0), addTower(3), tuplesManager(0), tuples(0), numberingFromDDD(0), org(0) {
38 int laygroup = m_Anal.
getParameter<
int>(
"LayerGrouping");
43 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of "
44 <<
"begin/end events and of G4step";
49 for (
unsigned int i=0;
i<
group_.size();
i++)
55 <<
" Longitudinal groups and " <<
nTower
63 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of "
64 <<
"selected entries : " <<
count;
66 <<
", HistoClass " <<
tuples <<
", Numbering Scheme "
69 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Delete HcalQie";
72 if (numberingFromDDD) {
73 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Delete HcalNumberingFromDDD";
80 std::vector<int>
temp(19);
82 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
83 for (
int i=0;
i<19;
i++)
85 }
else if (group == 2) {
86 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
87 for (
int i=0;
i<19;
i++)
89 }
else if (group == 3) {
90 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
91 for (
int i=0;
i<19;
i++)
93 }
else if (group == 4) {
94 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
95 for (
int i=0;
i<19;
i++)
98 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
99 for (
int i=0;
i<19;
i++)
103 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Layer Grouping ";
104 for (
int i=0;
i<19;
i++)
105 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Group[" <<
i <<
"] = "
112 int etac = (centre/100)%100;
113 int phic = (centre%100);
131 nbuf = (etamax-etamin+1)*(phimax-phimin+1);
132 std::vector<int>
temp(2*nbuf);
133 for (
int eta=etamin;
eta<=etamax;
eta++) {
135 temp[kount] = (
eta*100 +
phi);
141 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for"
142 <<
" Central " << centre <<
" and " << nadd
143 <<
" on either side";
144 for (
int i=0;
i<nbuf;
i++)
145 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis: Tower[" << std::setw(3) <<
i
146 <<
"] " << temp[
i] <<
" " << temp[nbuf+
i];
155 (*job)()->get<IdealGeometryRecord>().get(pDD);
156 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Initialise "
157 <<
"HcalNumberingFromDDD for " <<
names[0];
171 int irun = (*run)()->GetRunID();
172 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
192 }
else if (idet == static_cast<int>(
HcalBarrel)) {
194 }
else if (idet == static_cast<int>(
HcalEndcap)) {
201 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Central Tower "
203 <<
" phi0 = " <<
phi0;
206 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
208 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
210 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with "
211 <<
"name " << sdname <<
" in this Setup";
214 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with "
215 <<
"name " << theCaloSD->GetName()
219 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new "
220 <<
"numbering scheme";
224 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get"
240 for (i = 0; i < 20; i++)
edepl[i] = 0.;
241 for (i = 0; i < 20; i++)
mudist[i] = -1.;
243 int iev = (*evt)()->GetEventID();
244 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << iev;
251 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
252 G4String
name = curPV->GetName();
253 name.assign(name,0,3);
254 double edeposit = aStep->GetTotalEnergyDeposit();
258 }
else if (name ==
"EFR") {
260 }
else if (name ==
"HBS") {
261 layer = (curPV->GetCopyNo()/10)%100;
262 if (layer >= 0 && layer < 17) {
266 << curPV->GetName() << curPV->GetCopyNo();
269 }
else if (name ==
"HES") {
270 layer = (curPV->GetCopyNo()/10)%100;
271 if (layer >= 0 && layer < 19) {
275 << curPV->GetName() << curPV->GetCopyNo();
278 }
else if (name ==
"HTS") {
279 layer = (curPV->GetCopyNo()/10)%100;
280 if (layer >= 17 && layer < 20) {
284 << curPV->GetName() << curPV->GetCopyNo();
288 if (layer >= 0 && layer < 20) {
289 edepl[layer] += edeposit;
292 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
293 if ((part ==
"mu-" || part ==
"mu+") &&
mudist[layer] < 0) {
295 aStep->GetPreStepPoint()->GetPosition().y(),
296 aStep->GetPreStepPoint()->GetPosition().z());
297 double theta = pos.theta();
299 double phi = pos.phi();
305 if (layer >= 0 && layer < 20) {
306 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: " << name <<
" Layer "
307 << std::setw(3) << layer <<
" Edep " << std::setw(6)
308 << edeposit/
MeV <<
" MeV";
311 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: Null Step";
321 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after Fill";
324 CLHEP::HepRandomEngine* engine = CLHEP::HepRandom::getTheEngine();
326 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after QieAnalysis";
330 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
335 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after fillTree";
342 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Fill event "
343 << (*evt)()->GetEventID();
346 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
348 int nhc = 0, neb = 0, nef = 0,
j = 0;
352 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
354 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[0]
355 <<
" of ID " << HCHCid <<
" is obtained at " << theHCHC;
356 if (HCHCid >= 0 && theHCHC > 0) {
357 for (
j = 0;
j < theHCHC->entries();
j++) {
365 double theta = pos.theta();
367 double phi = pos.phi();
370 int subdet,
zside, layer, etaIndex, phiIndex, lay;
373 if (jitter<0) jitter = 0;
374 CaloHit hit(subdet,lay,e,eta,phi,jitter,unitID);
381 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
382 if (etaIndex <= 20) {
389 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
390 << layer <<
" time " << std::setw(6) << time
391 <<
" theta " << std::setw(8) << theta <<
" eta "
392 << std::setw(8) << eta <<
" phi " << std::setw(8)
393 << phi <<
" e " << std::setw(8) <<
e;
396 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::HCAL hits : " << nhc <<
"\n";
399 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[1]);
401 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[1]
402 <<
" of ID " << EBHCid <<
" is obtained at " << theEBHC;
403 if (EBHCid >= 0 && theEBHC > 0) {
404 for (
j = 0;
j < theEBHC->entries();
j++) {
413 double theta = pos.theta();
415 double phi = pos.phi();
419 int subdet,
zside, layer, ieta, iphi, lay;
424 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
427 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
428 << layer <<
" time " << std::setw(6) << time
429 <<
" theta " << std::setw(8) << theta <<
" eta "
430 << std::setw(8) << eta <<
" phi " << std::setw(8)
431 << phi <<
" e " << std::setw(8) <<
e;
434 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EB hits : " << neb <<
"\n";
437 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[2]);
439 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[2]
440 <<
" of ID " << EEHCid <<
" is obtained at " << theEEHC;
441 if (EEHCid >= 0 && theEEHC > 0) {
442 for (
j = 0;
j < theEEHC->entries();
j++) {
451 double theta = pos.theta();
453 double phi = pos.phi();
457 int subdet,
zside, layer, ieta, iphi, lay;
462 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
465 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
466 << layer <<
" time " << std::setw(6) << time
467 <<
" theta " << std::setw(8) << theta <<
" eta "
468 << std::setw(8) << eta <<
" phi " << std::setw(8)
469 << phi <<
" e " << std::setw(8) <<
e;
472 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EE hits : " << nef <<
"\n";
485 int subdet,
zside, layer, ieta, iphi, lay;
490 laymax = 4; det =
"HB";
491 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
492 laymax = 2; det =
"HES";
494 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: " << det <<
" Eta " << ieta
495 <<
" Phi " << iphi <<
" Laymax " << laymax <<
" Hits "
498 if (laymax>0 && hittot>0) {
499 std::vector<CaloHit> hits(hittot);
500 std::vector<double> eqielay(80,0.0), esimlay(80,0.0), esimtot(4,0.0);
501 std::vector<double> eqietow(200,0.0), esimtow(200,0.0), eqietot(4,0.0);
505 for (
int layr=0; layr<
nGroup; layr++) {
520 for (
int it=0; it<
nTower; it++) {
523 for (
int k1 = 0; k1 < hittot; k1++) {
525 int subdetc = hit.
det();
526 int layer = hit.
layer();
528 if (layer > 0 && layer < 20) group =
group_[layer];
529 if (subdetc == subdet && group == layr+1) {
530 int zsidec, ietac, iphic,
idx;
533 if (etac > 0 && phic > 0) {
534 idx = ietac*100 + iphic;
535 }
else if (etac > 0) {
537 }
else if (phic > 0) {
542 if (zsidec==zside && idx==
tower_[it]) {
544 LogDebug(
"HcalSim") <<
"HcalTest: Hit " << nhit <<
" " << hit;
551 std::vector<int> cd =
myqie->
getCode(nhit, hits, engine);
554 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer "
555 << layr <<
" Sim " << esim <<
" After QIE " <<eqie;
556 for (
int i=0;
i<4;
i++) {
560 esimlay[20*
i+layr] += esim;
561 eqielay[20*
i+layr] += eqie;
562 esimtow[50*
i+it] += esim;
563 eqietow[50*
i+it] += eqie;
568 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3]
569 <<
" (SimHit) " << eqietot[3] <<
" (After QIE)";
571 std::vector<double> latphi(10);
573 for (
int it=0; it<
nt; it++)
575 for (
int i=0;
i<4;
i++) {
576 double scals=1, scalq=1;
577 std::vector<double> latfs(10,0.), latfq(10,0.), longs(20), longq(20);
578 if (esimtot[
i]>0) scals = 1./esimtot[
i];
579 if (eqietot[
i]>0) scalq = 1./eqietot[
i];
580 for (
int it=0; it<
nTower; it++) {
582 latfs[phib] += scals*esimtow[50*
i+it];
583 latfq[phib] += scalq*eqietow[50*
i+it];
585 for (
int layr=0; layr<=
nGroup; layr++) {
586 longs[layr] = scals*esimlay[20*
i+layr];
587 longq[layr] = scalq*eqielay[20*
i+layr];
590 nt,latphi,latfs,latfq);
599 LogDebug(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit in MeV "
600 <<
"\n at EB : " << std::setw(6) <<
edepEB/
MeV
601 <<
"\n at EE : " << std::setw(6) <<
edepEE/
MeV
602 <<
"\n at HB : " << std::setw(6) <<
edepHB/
MeV
603 <<
"\n at HE : " << std::setw(6) <<
edepHE/
MeV
604 <<
"\n at HO : " << std::setw(6) <<
edepHO/
MeV
605 <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
606 for (i = 0; i < 20; i++)
607 LogDebug(
"HcalSim") <<
" Layer " << std::setw(2) << i <<
" E "
608 << std::setw(8) <<
edepl[
i]/
MeV <<
" MeV";
620 const double rLay[19] = {
621 1836.0, 1902.0, 1962.0, 2022.0, 2082.0, 2142.0, 2202.0, 2262.0, 2322.0,
622 2382.0, 2448.0, 2514.0, 2580.0, 2646.0, 2712.0, 2776.0, 2862.5, 3847.0,
624 if (layer>0 && layer<20) dist += rLay[layer-1]*mm/
sin(theta);
626 const double zLay[19] = {
627 4034.0, 4032.0, 4123.0, 4210.0, 4297.0, 4384.0, 4471.0, 4558.0, 4645.0,
628 4732.0, 4819.0, 4906.0, 4993.0, 5080.0, 5167.0, 5254.0, 5341.0, 5428.0,
630 if (layer>0 && layer<20) dist += zLay[layer-1]*mm/
cos(theta);
632 double tmp = dist/c_light/ns;
633 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::timeOfFlight " << tmp
634 <<
" for det/lay " << det <<
" " << layer
635 <<
" 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[])
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id)
virtual ~HcalTestAnalysis()
std::vector< int > layerGrouping(int)
Sin< T >::type sin(const T &t)
Geom::Theta< T > theta() const
std::auto_ptr< HcalTestHistoManager > tuplesManager
void fillHits(std::vector< CaloHit > &)
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)
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)
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
HcalTestHistoClass * tuples
XYZPointD XYZPoint
point in space with cartesian internal representation
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
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
HcalCellType::HcalCell cell(int det, int zside, int depth, int etaR, int iphi, bool corr=true) 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