53 #include "G4SDManager.hh" 56 #include "G4ThreeVector.hh" 57 #include "G4VProcess.hh" 58 #include "G4HCofThisEvent.hh" 60 #include <CLHEP/Random/RandGaussQ.h> 61 #include <CLHEP/Random/Randomize.h> 62 #include <CLHEP/Units/GlobalSystemOfUnits.h> 63 #include <CLHEP/Units/GlobalPhysicalConstants.h> 70 class HepRandomEngine;
75 public Observer<const BeginOfEvent*>,
114 const std::vector<std::string>
names;
152 hcalOnly(m_Anal.getParameter<
bool>(
"HcalOnly")),
153 mode(m_Anal.getParameter<
int>(
"Mode")),
154 type(m_Anal.getParameter<
int>(
"Type")),
155 ecalNoise(m_Anal.getParameter<double>(
"EcalNoise")),
156 beamOffset(-m_Anal.getParameter<double>(
"BeamPosition") *
CLHEP::cm),
157 scaleHB0(m_Anal.getParameter<double>(
"ScaleHB0")),
158 scaleHB16(m_Anal.getParameter<double>(
"ScaleHB16")),
159 scaleHO(m_Anal.getParameter<double>(
"ScaleHO")),
160 scaleHE0(m_Anal.getParameter<double>(
"ScaleHE0")),
168 double beamEta = (fMaxEta + fMinEta) / 2.;
169 double beamPhi = (fMaxPhi + fMinPhi) / 2.;
170 double beamThet = 2 * atan(
exp(-beamEta));
173 iceta =
static_cast<int>(beamEta / 0.087) + 1;
174 icphi =
static_cast<int>(std::fabs(beamPhi) / 0.087) + 5;
178 produces<PHcalTB04Info>();
185 <<
"HcalTB04:: Initialised as observer of BeginOf Job/BeginOfRun/BeginOfEvent/G4Step/EndOfEvent with Parameter " 186 "values:\n \thcalOnly = " 187 <<
hcalOnly <<
"\tecalNoise = " <<
ecalNoise <<
"\n\tMode = " <<
mode <<
" (0: HB2 Standard; 1:HB2 Segmented)" 188 <<
"\tType = " <<
type <<
" (0: HB; 1 HE; 2 HB+HE)\n\tbeamOffset = " <<
beamOffset <<
"\ticeta = " <<
iceta 199 edm::LogVerbatim(
"HcalTBSim") <<
"\n --------> Total number of selected entries : " <<
count <<
"\nPointers:: QIE " 242 for (
int lay = 1; lay < 8; lay++) {
243 for (
int icr = 1; icr < 8; icr++) {
266 for (
int i = 0;
i < 5;
i++) {
270 for (
int i = 0;
i < 3;
i++) {
274 for (
int i = 0;
i < 20;
i++) {
286 int irun = (*run)()->GetRunID();
289 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
292 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
293 if (aSD ==
nullptr) {
295 <<
" with name " << sdname <<
" in this " 299 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
303 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: set a new numbering scheme";
307 aSD = sd->FindSensitiveDetector(sdname);
308 if (aSD ==
nullptr) {
310 <<
" with name " << sdname <<
" in this " 314 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
318 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: set a new numbering scheme";
323 <<
"not get SD Manager!";
330 evNum = (*evt)()->GetEventID();
336 if (aStep !=
nullptr) {
338 G4ThreeVector thePreStepPoint = aStep->GetPreStepPoint()->GetPosition();
339 G4ThreeVector thePostStepPoint;
342 G4Track* aTrack = aStep->GetTrack();
343 int trackID = aTrack->GetTrackID();
344 int parentID = aTrack->GetParentID();
345 const G4ThreeVector&
position = aTrack->GetPosition();
346 G4ThreeVector momentum = aTrack->GetMomentum();
347 G4String partType = aTrack->GetDefinition()->GetParticleType();
348 G4String partSubType = aTrack->GetDefinition()->GetParticleSubType();
349 int partPDGEncoding = aTrack->GetDefinition()->GetPDGEncoding();
351 bool isPDGStable = aTrack->GetDefinition()->GetPDGStable();
353 double pDGlifetime = aTrack->GetDefinition()->GetPDGLifeTime();
354 double gammaFactor = aStep->GetPreStepPoint()->GetGamma();
357 double stepDeltaEnergy = aStep->GetDeltaEnergy();
358 double kinEnergy = aTrack->GetKineticEnergy();
361 if (trackID == 1 && parentID == 0 && ((kinEnergy == 0.) || (std::fabs(stepDeltaEnergy / kinEnergy) > 0.1))) {
363 if (kinEnergy == 0.) {
366 if (std::fabs(stepDeltaEnergy / kinEnergy) > 0.1)
376 G4String thePostPVname =
"NoName";
377 G4StepPoint* thePostPoint = aStep->GetPostStepPoint();
379 thePostStepPoint = thePostPoint->GetPosition();
380 G4VPhysicalVolume* thePostPV = thePostPoint->GetPhysicalVolume();
382 thePostPVname = thePostPV->GetName();
385 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: V1 found at: " << thePostStepPoint
386 <<
" G4VPhysicalVolume: " << thePostPVname;
393 if ((trackID != 1 && parentID == 1 && (aTrack->GetCurrentStepNumber() == 1) && (thePreStepPoint ==
pvPosition)) ||
394 (trackID == 1 && thePreStepPoint ==
pvPosition)) {
396 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::A secondary... PDG:" << partPDGEncoding
397 <<
" TrackID:" << trackID <<
" ParentID:" << parentID
398 <<
" stable: " << isPDGStable <<
" Tau: " << pDGlifetime
399 <<
" cTauGamma=" << c_light * pDGlifetime * gammaFactor * 1000.
400 <<
"um GammaFactor: " << gammaFactor;
405 secEkin.push_back(aTrack->GetKineticEnergy());
408 double ctaugamma_um = CLHEP::c_light * pDGlifetime * gammaFactor * 1000.;
409 if ((ctaugamma_um > 0.) && (ctaugamma_um < 100.)) {
417 if (aTrack->GetCurrentStepNumber() == 1) {
422 std::vector<int>::iterator
pos;
428 <<
"HcalTB04Analysis:: A tertiary... PDG:" << partPDGEncoding <<
" TrackID:" << trackID
429 <<
" ParentID:" << parentID <<
" stable: " << isPDGStable <<
" Tau: " << pDGlifetime
430 <<
" cTauGamma=" << c_light * pDGlifetime * gammaFactor * 1000. <<
"um GammaFactor: " << gammaFactor;
445 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::Fill event " << (*evt)()->GetEventID();
453 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
470 int iEvt = (*evt)()->GetEventID();
473 else if ((iEvt < 100) && (iEvt % 10 == 0))
475 else if ((iEvt < 1000) && (iEvt % 100 == 0))
477 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
482 std::vector<CaloHit> hhits, hhitl;
485 std::map<int, float, std::less<int> > primaries;
487 double etot1 = 0, etot2 = 0;
491 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
493 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(
sdName);
497 <<
" is obtained at " << theHC <<
" with " << theHC->entries() <<
" entries";
499 int thehc_entries = theHC->entries();
500 if (idHC >= 0 && theHC !=
nullptr) {
501 hhits.reserve(theHC->entries());
502 hhitl.reserve(theHC->entries());
503 for (
j = 0;
j < thehc_entries;
j++) {
522 hhits.push_back(
hit);
524 hhitl.push_back(hitl);
528 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit i/p " <<
j <<
" ID 0x" << std::hex <<
id <<
" 0x" 529 <<
idx <<
std::dec <<
" time " << std::setw(6) <<
time <<
" " << std::setw(6)
530 << jitter <<
" theta " << std::setw(8) <<
theta <<
" eta " << std::setw(8) <<
eta 531 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) <<
e <<
" " 532 << std::setw(8) << escl;
538 std::vector<CaloHit>::iterator itr;
539 int nHit = hhits.size();
540 std::vector<CaloHit*>
hits(nHit);
541 for (
j = 0, itr = hhits.begin(); itr != hhits.end();
j++, itr++) {
545 std::vector<CaloHit*>::iterator k1, k2;
549 for (k1 =
hits.begin(); k1 !=
hits.end(); k1++) {
550 int det = (**k1).det();
551 int layer = (**k1).layer();
552 double ehit = (**k1).e();
553 double eta = (**k1).eta();
554 double phi = (**k1).phi();
555 double jitter = (**k1).t();
556 uint32_t
unitID = (**k1).id();
558 for (k2 = k1 + 1; k2 !=
hits.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id(); k2++) {
568 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit store " << nhit <<
" ID 0x" << std::hex <<
unitID 569 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 570 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
574 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhit <<
" HCal hits from " << nHit
575 <<
" input hits E(Hcal) " << etot1 <<
" " << etot2;
578 for (
j = 0, itr = hhitl.begin(); itr != hhitl.end();
j++, itr++) {
586 for (k1 =
hits.begin(); k1 !=
hits.end(); k1++) {
587 int det = (**k1).det();
588 int layer = (**k1).layer();
589 double ehit = (**k1).e();
590 double eta = (**k1).eta();
591 double phi = (**k1).phi();
592 double jitter = (**k1).t();
593 uint32_t
unitID = (**k1).id();
595 for (k2 = k1 + 1; k2 !=
hits.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id(); k2++) {
605 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit store " << nhitl <<
" ID 0x" << std::hex <<
unitID 606 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 607 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
611 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhitl <<
" HCal hits from " << nHit
612 <<
" input hits E(Hcal) " << etot1 <<
" " << etotl;
615 std::vector<CaloHit> ehits;
617 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(
sdName);
622 <<
" is obtained at " << theHC <<
" with " << theHC->entries() <<
" entries";
624 if (idHC >= 0 && theHC !=
nullptr) {
625 thehc_entries = theHC->entries();
626 ehits.reserve(theHC->entries());
627 for (
j = 0;
j < thehc_entries;
j++) {
631 if (e < 0 || e > 100000.)
642 ehits.push_back(
hit);
646 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Ecal Hit i/p " <<
j <<
" ID 0x" << std::hex <<
id 647 <<
std::dec <<
" time " << std::setw(6) <<
time <<
" theta " << std::setw(8)
648 <<
theta <<
" eta " << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi 649 <<
" e " << std::setw(8) <<
e;
657 std::vector<CaloHit*> hite(nHit);
658 for (
j = 0, itr = ehits.begin(); itr != ehits.end();
j++, itr++) {
665 for (k1 = hite.begin(); k1 != hite.end(); k1++) {
666 int det = (**k1).det();
667 int layer = (**k1).layer();
668 double ehit = (**k1).e();
669 double eta = (**k1).eta();
670 double phi = (**k1).phi();
671 double jitter = (**k1).t();
672 uint32_t
unitID = (**k1).id();
674 for (k2 = k1 + 1; k2 != hite.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id(); k2++) {
684 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Ecal Hit store " << nhit <<
" ID 0x" << std::hex <<
unitID 685 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 686 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
690 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhit <<
" ECal hits from " << nHit
691 <<
" input hits E(Ecal) " << etot1 <<
" " << etot2;
694 nPrimary =
static_cast<int>(primaries.size());
696 G4PrimaryParticle* thePrim =
nullptr;
697 int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
699 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Event has " << nvertex <<
" verteices";
702 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERROR: no vertex found for event " <<
evNum;
703 for (
int i = 0;
i < nvertex;
i++) {
704 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
705 if (avertex ==
nullptr) {
706 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERR: pointer to vertex = 0 for event " <<
evNum;
708 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::Vertex number :" <<
i <<
" " << avertex->GetPosition();
709 int npart = avertex->GetNumberOfParticle();
711 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::End Of Event ERR: no primary!";
712 if (thePrim ==
nullptr)
713 thePrim = avertex->GetPrimary(trackID);
717 if (thePrim !=
nullptr) {
718 double px = thePrim->GetPx();
719 double py = thePrim->GetPy();
720 double pz = thePrim->GetPz();
724 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis:: EndOfEvent ERR: primary has p=0 ";
726 double costheta = pz /
p;
729 if (
px != 0 ||
py != 0)
734 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERR: could not find primary";
741 std::vector<CaloHit>
hits(hittot);
749 for (
unsigned int k1 = 0; k1 <
hcalHitCache.size(); k1++) {
751 uint32_t
id =
hit.
id();
753 double esim =
hit.e();
755 for (
unsigned int k2 = k1 + 1; k2 <
hcalHitCache.size(); k2++) {
769 <<
" energy from " << nhit <<
" hits starting with hit # " << k1
770 <<
" energy with noise " << eq;
772 for (
int k2 = 0; k2 <
nTower; k2++) {
782 for (
int k2 = 0; k2 <
nTower; k2++) {
790 <<
" registers " <<
esimh[k2] <<
" energy from hits and energy after QIE analysis " 798 CLHEP::RandGaussQ randGauss(*engine);
803 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::xtalAnalysis: Size " << iok.size() <<
" " <<
idEcal.size() <<
" " 806 for (
unsigned int k1 = 0; k1 <
ecalHitCache.size(); k1++) {
810 for (
unsigned int k2 = k1 + 1; k2 <
ecalHitCache.size(); k2++) {
818 double eq = esim + randGauss.fire(0.,
ecalNoise);
821 <<
" energy from " << nhit <<
" hits starting with hit # " << k1
822 <<
" energy with noise " << eq;
824 for (
int k2 = 0; k2 <
nCrystal; k2++) {
834 for (
int k2 = 0; k2 <
nCrystal; k2++) {
840 <<
" registers " <<
esime[k2] <<
" energy from hits and energy from noise " 864 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy deposit at Sim Level (Total) " <<
etots <<
" (ECal) " 866 <<
"\nHcalTB04Analysis:: Energy deposit at Qie Level (Total) " <<
etotq <<
" (ECal) " 872 for (
int i = 0;
i < 5;
i++) {
876 for (
int i = 0;
i < 3;
i++) {
880 double e1 = 0, e2 = 0;
895 if (
iphi >= 0 && iphi < 3 && ieta >= 0 &&
ieta < 5) {
904 for (
int i = 0;
i < 3;
i++) {
910 for (
int i = 0;
i < 5;
i++) {
917 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy fraction along Eta and Phi (Sim/Qie)";
918 for (
int i = 0;
i < 5;
i++)
925 for (
int i = 0;
i < 20;
i++) {
937 if (
iphi >= 0 && iphi < 3 && layer >= 0 &&
layer < 20) {
944 for (
int i = 0;
i < 20;
i++) {
951 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy fraction along Layer";
952 for (
int i = 0;
i < 20;
i++)
980 std::vector<CaloHit>::iterator itr;
982 uint32_t
id = itr->id();
988 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Save Hit " << std::setw(3) << nhit <<
" ID 0x" << std::hex
989 <<
group <<
std::dec <<
" " << std::setw(2) << det <<
" " << std::setw(2) << lay
990 <<
" " << std::setw(1) <<
z <<
" " << std::setw(3) <<
ieta <<
" " << std::setw(3)
991 <<
iphi <<
" T " << std::setw(6) << itr->t() <<
" E " << std::setw(6) << itr->e();
994 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Saves " << nhit <<
" hits from Crystals";
1000 uint32_t
id = itr->id();
1006 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Save Hit " << std::setw(3) << nhit + nhit0 <<
" ID 0x" 1007 << std::hex <<
group <<
std::dec <<
" " << std::setw(2) << det <<
" " << std::setw(2)
1008 << lay <<
" " << std::setw(1) <<
z <<
" " << std::setw(3) <<
ieta <<
" " 1009 << std::setw(3) <<
iphi <<
" T " << std::setw(6) << itr->t() <<
" E " << std::setw(6)
1013 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Saves " << nhit <<
" hits from HCal";
1038 pvUVW = G4ThreeVector();
1056 esimh.push_back(0.);
1064 esime.push_back(0.);
1065 enois.push_back(0.);
1072 group = (det & 15) << 20;
1073 group += ((lay - 1) & 31) << 15;
1085 else if (
layer == 17)
1087 else if (
layer > 17)
1100 const double rLay[19] = {1836.0,
1122 const double zLay[19] = {4034.0,
1145 double tmp = dist / c_light / ns;
1147 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::timeOfFlight " <<
tmp <<
" for det/lay " << det <<
" " <<
layer 1148 <<
" eta/theta " <<
eta <<
" " <<
theta / deg <<
" dist " << dist;
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
std::vector< double > secEkin
void setLongProf(const std::vector< double > &es, const std::vector< double > &eq)
std::vector< int > idHcal
void fillPrimary(double energy, double eta, double phi)
std::vector< CaloHit > hcalHitLayer
std::vector< double > eqeta
std::vector< double > eqie
void fillTrnsProf(const std::vector< double > &es1, const std::vector< double > &eq1, const std::vector< double > &es2, const std::vector< double > &eq2)
Sin< T >::type sin(const T &t)
void fillBuffer(const EndOfEvent *evt)
std::vector< int > shortLivedSecondaries
std::vector< int > secTrackID
std::vector< double > eqphi
void setPrimary(int primary, int id, double energy, double eta, double phi)
const edm::ParameterSet m_Anal
void setNumberingScheme(HcalNumberingScheme *)
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
const std::string names[nVars_]
void setEdep(double simtot, double sime, double simh, double digtot, double dige, double digh)
void setTrnsProf(const std::vector< double > &es1, const std::vector< double > &eq1, const std::vector< double > &es2, const std::vector< double > &eq2)
void saveHit(int det, int lay, int eta, int phi, double e, double t)
std::vector< int > secPartID
static uint32_t packHcalIndex(int det, int z, int depth, int eta, int phi, int lay)
std::vector< uint32_t > idEcal
std::vector< double > eseta
math::XYZPoint getEntry() const
void setIDs(const std::vector< int > &, const std::vector< int > &)
void setVtxSec(int id, int pdg, double px, double py, double pz, double ek)
void setEdepHcal(const std::vector< double > &esim, const std::vector< double > &edig)
double getEnergy(const std::vector< int > &)
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)
G4RotationMatrix * beamline_RM
std::vector< double > esime
static std::vector< uint32_t > getUnitIDs(const int type, const int mode)
double scale(int det, int layer)
std::vector< double > esphi
double timeOfFlight(int det, int layer, double eta)
const std::vector< std::string > names
std::vector< CaloHit > hcalHitCache
void xtalAnalysis(CLHEP::HepRandomEngine *)
static uint32_t getUnitID(const uint32_t id, const int mode)
HcalTB04Analysis(const edm::ParameterSet &p)
~HcalTB04Analysis() override
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< int > idXtal
std::vector< CaloHit > ecalHitCache
double getEnergyDeposit() const
uint32_t getUnitID() const
std::vector< double > enois
void setVtxPrim(int evNum, int type, double x, double y, double z, double u, double v, double w, double px, double py, double pz)
std::vector< G4ThreeVector > secMomentum
std::vector< int > getCode(int, const std::vector< CaloHit > &, CLHEP::HepRandomEngine *)
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
static int position[264][3]
double getTimeSlice() const
std::vector< uint32_t > idTower
void qieAnalysis(CLHEP::HepRandomEngine *)
std::vector< double > eslay
std::vector< double > eqlay
Log< level::Warning, false > LogWarning
void setNumberingScheme(EcalNumberingScheme *)
Geom::Theta< T > theta() const
void fillEdep(double etots, double eecals, double ehcals, double etotq, double eecalq, double ehcalq)
void fillEvent(PHcalTB04Info &)
const HcalTB04Analysis & operator=(const HcalTB04Analysis &)=delete
std::vector< double > esimh
void fillLongProf(const std::vector< double > &es, const std::vector< double > &eq)
void produce(edm::Event &, const edm::EventSetup &) override