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"
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<HcalSimNumberingRecord>().get(hdc);
157 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Initialise "
158 <<
"HcalNumberingFromDDD for " <<
names[0];
172 int irun = (*run)()->GetRunID();
173 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
193 }
else if (idet == static_cast<int>(
HcalBarrel)) {
195 }
else if (idet == static_cast<int>(
HcalEndcap)) {
202 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: Central Tower "
204 <<
" phi0 = " <<
phi0;
207 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
209 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
211 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with "
212 <<
"name " << sdname <<
" in this Setup";
215 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with "
216 <<
"name " << theCaloSD->GetName()
220 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new "
221 <<
"numbering scheme";
225 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get"
241 for (i = 0; i < 20; i++)
edepl[i] = 0.;
242 for (i = 0; i < 20; i++)
mudist[i] = -1.;
244 int iev = (*evt)()->GetEventID();
245 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << iev;
252 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
253 G4String
name = curPV->GetName();
254 name.assign(name,0,3);
255 double edeposit = aStep->GetTotalEnergyDeposit();
259 }
else if (name ==
"EFR") {
261 }
else if (name ==
"HBS") {
262 layer = (curPV->GetCopyNo()/10)%100;
263 if (layer >= 0 && layer < 17) {
267 << curPV->GetName() << curPV->GetCopyNo();
270 }
else if (name ==
"HES") {
271 layer = (curPV->GetCopyNo()/10)%100;
272 if (layer >= 0 && layer < 19) {
276 << curPV->GetName() << curPV->GetCopyNo();
279 }
else if (name ==
"HTS") {
280 layer = (curPV->GetCopyNo()/10)%100;
281 if (layer >= 17 && layer < 20) {
285 << curPV->GetName() << curPV->GetCopyNo();
289 if (layer >= 0 && layer < 20) {
290 edepl[layer] += edeposit;
293 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
294 if ((part ==
"mu-" || part ==
"mu+") &&
mudist[layer] < 0) {
296 aStep->GetPreStepPoint()->GetPosition().y(),
297 aStep->GetPreStepPoint()->GetPosition().z());
298 double theta = pos.theta();
300 double phi = pos.phi();
306 if (layer >= 0 && layer < 20) {
307 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: " << name <<
" Layer "
308 << std::setw(3) << layer <<
" Edep " << std::setw(6)
309 << edeposit/
MeV <<
" MeV";
312 edm::LogInfo(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: Null Step";
322 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after Fill";
325 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
327 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after QieAnalysis";
331 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
336 LogDebug(
"HcalSim") <<
"HcalTestAnalysis:: --- after fillTree";
343 LogDebug(
"HcalSim") <<
"HcalTestAnalysis: Fill event "
344 << (*evt)()->GetEventID();
347 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
349 int nhc = 0, neb = 0, nef = 0,
j = 0;
353 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[0]);
355 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[0]
356 <<
" of ID " << HCHCid <<
" is obtained at " << theHCHC;
357 if (HCHCid >= 0 && theHCHC > 0) {
358 for (
j = 0;
j < theHCHC->entries();
j++) {
366 double theta = pos.theta();
368 double phi = pos.phi();
371 int subdet,
zside, layer, etaIndex, phiIndex, lay;
374 if (jitter<0) jitter = 0;
375 CaloHit hit(subdet,lay,e,eta,phi,jitter,unitID);
382 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
383 if (etaIndex <= 20) {
390 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
391 << layer <<
" time " << std::setw(6) << time
392 <<
" theta " << std::setw(8) << theta <<
" eta "
393 << std::setw(8) << eta <<
" phi " << std::setw(8)
394 << phi <<
" e " << std::setw(8) <<
e;
397 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::HCAL hits : " << nhc <<
"\n";
400 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[1]);
402 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[1]
403 <<
" of ID " << EBHCid <<
" is obtained at " << theEBHC;
404 if (EBHCid >= 0 && theEBHC > 0) {
405 for (
j = 0;
j < theEBHC->entries();
j++) {
414 double theta = pos.theta();
416 double phi = pos.phi();
420 int subdet,
zside, layer, ieta, iphi, lay;
425 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
428 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
429 << layer <<
" time " << std::setw(6) << time
430 <<
" theta " << std::setw(8) << theta <<
" eta "
431 << std::setw(8) << eta <<
" phi " << std::setw(8)
432 << phi <<
" e " << std::setw(8) <<
e;
435 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EB hits : " << neb <<
"\n";
438 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names[2]);
440 LogDebug(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names[2]
441 <<
" of ID " << EEHCid <<
" is obtained at " << theEEHC;
442 if (EEHCid >= 0 && theEEHC > 0) {
443 for (
j = 0;
j < theEEHC->entries();
j++) {
452 double theta = pos.theta();
454 double phi = pos.phi();
458 int subdet,
zside, layer, ieta, iphi, lay;
463 CaloHit hit(subdet,lay,e,eta,phi,time,unitID);
466 LogDebug(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2)
467 << layer <<
" time " << std::setw(6) << time
468 <<
" theta " << std::setw(8) << theta <<
" eta "
469 << std::setw(8) << eta <<
" phi " << std::setw(8)
470 << phi <<
" e " << std::setw(8) <<
e;
473 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::EE hits : " << nef <<
"\n";
486 int subdet,
zside, layer, ieta, iphi, lay;
491 laymax = 4; det =
"HB";
492 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
493 laymax = 2; det =
"HES";
495 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: " << det <<
" Eta " << ieta
496 <<
" Phi " << iphi <<
" Laymax " << laymax <<
" Hits "
499 if (laymax>0 && hittot>0) {
500 std::vector<CaloHit> hits(hittot);
501 std::vector<double> eqielay(80,0.0), esimlay(80,0.0), esimtot(4,0.0);
502 std::vector<double> eqietow(200,0.0), esimtow(200,0.0), eqietot(4,0.0);
506 for (
int layr=0; layr<
nGroup; layr++) {
521 for (
int it=0; it<
nTower; it++) {
524 for (
int k1 = 0; k1 < hittot; k1++) {
526 int subdetc = hit.
det();
527 int layer = hit.
layer();
529 if (layer > 0 && layer < 20) group =
group_[layer];
530 if (subdetc == subdet && group == layr+1) {
531 int zsidec, ietac, iphic,
idx;
534 if (etac > 0 && phic > 0) {
535 idx = ietac*100 + iphic;
536 }
else if (etac > 0) {
538 }
else if (phic > 0) {
543 if (zsidec==zside && idx==
tower_[it]) {
545 LogDebug(
"HcalSim") <<
"HcalTest: Hit " << nhit <<
" " << hit;
552 std::vector<int> cd =
myqie->
getCode(nhit, hits, engine);
555 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer "
556 << layr <<
" Sim " << esim <<
" After QIE " <<eqie;
557 for (
int i=0;
i<4;
i++) {
561 esimlay[20*
i+layr] += esim;
562 eqielay[20*
i+layr] += eqie;
563 esimtow[50*
i+it] += esim;
564 eqietow[50*
i+it] += eqie;
569 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3]
570 <<
" (SimHit) " << eqietot[3] <<
" (After QIE)";
572 std::vector<double> latphi(10);
574 for (
int it=0; it<
nt; it++)
576 for (
int i=0;
i<4;
i++) {
577 double scals=1, scalq=1;
578 std::vector<double> latfs(10,0.), latfq(10,0.), longs(20), longq(20);
579 if (esimtot[
i]>0) scals = 1./esimtot[
i];
580 if (eqietot[
i]>0) scalq = 1./eqietot[
i];
581 for (
int it=0; it<
nTower; it++) {
583 latfs[phib] += scals*esimtow[50*
i+it];
584 latfq[phib] += scalq*eqietow[50*
i+it];
586 for (
int layr=0; layr<=
nGroup; layr++) {
587 longs[layr] = scals*esimlay[20*
i+layr];
588 longq[layr] = scalq*eqielay[20*
i+layr];
591 nt,latphi,latfs,latfq);
600 LogDebug(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit in MeV "
601 <<
"\n at EB : " << std::setw(6) <<
edepEB/
MeV
602 <<
"\n at EE : " << std::setw(6) <<
edepEE/
MeV
603 <<
"\n at HB : " << std::setw(6) <<
edepHB/
MeV
604 <<
"\n at HE : " << std::setw(6) <<
edepHE/
MeV
605 <<
"\n at HO : " << std::setw(6) <<
edepHO/
MeV
606 <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
607 for (i = 0; i < 20; i++)
608 LogDebug(
"HcalSim") <<
" Layer " << std::setw(2) << i <<
" E "
609 << std::setw(8) <<
edepl[
i]/
MeV <<
" MeV";
621 const double rLay[19] = {
622 1836.0, 1902.0, 1962.0, 2022.0, 2082.0, 2142.0, 2202.0, 2262.0, 2322.0,
623 2382.0, 2448.0, 2514.0, 2580.0, 2646.0, 2712.0, 2776.0, 2862.5, 3847.0,
625 if (layer>0 && layer<20) dist += rLay[layer-1]*mm/
sin(theta);
627 const double zLay[19] = {
628 4034.0, 4032.0, 4123.0, 4210.0, 4297.0, 4384.0, 4471.0, 4558.0, 4645.0,
629 4732.0, 4819.0, 4906.0, 4993.0, 5080.0, 5167.0, 5254.0, 5341.0, 5428.0,
631 if (layer>0 && layer<20) dist += zLay[layer-1]*mm/
cos(theta);
633 double tmp = dist/c_light/ns;
634 LogDebug(
"HcalSim") <<
"HcalTestAnalysis::timeOfFlight " << tmp
635 <<
" for det/lay " << det <<
" " << layer
636 <<
" 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 > &)
HcalDDDSimConstants * hcons
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
HcalCellType::HcalCell cell(int det, int zside, int depth, int etaR, int iphi) const
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