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;
486 double etot1 = 0, etot2 = 0;
489 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
491 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(
sdName);
495 <<
" is obtained at " << theHC <<
" with " << theHC->entries() <<
" entries";
497 int thehc_entries = theHC->entries();
498 if (idHC >= 0 && theHC !=
nullptr) {
499 hhits.reserve(theHC->entries());
500 hhitl.reserve(theHC->entries());
501 for (
j = 0;
j < thehc_entries;
j++) {
520 hhits.push_back(
hit);
522 hhitl.push_back(hitl);
526 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit i/p " <<
j <<
" ID 0x" << std::hex <<
id <<
" 0x" 527 <<
idx <<
std::dec <<
" time " << std::setw(6) <<
time <<
" " << std::setw(6)
528 << jitter <<
" theta " << std::setw(8) <<
theta <<
" eta " << std::setw(8) <<
eta 529 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) <<
e <<
" " 530 << std::setw(8) << escl;
536 std::vector<CaloHit>::iterator itr;
537 int nHit = hhits.size();
538 std::vector<CaloHit*>
hits(nHit);
539 for (
j = 0, itr = hhits.begin(); itr != hhits.end();
j++, itr++) {
543 std::vector<CaloHit*>::iterator k1, k2;
545 for (k1 =
hits.begin(); k1 !=
hits.end(); k1++) {
546 int det = (**k1).det();
547 int layer = (**k1).layer();
548 double ehit = (**k1).e();
549 double eta = (**k1).eta();
550 double phi = (**k1).phi();
551 double jitter = (**k1).t();
552 uint32_t
unitID = (**k1).id();
554 for (k2 = k1 + 1; k2 !=
hits.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id(); k2++) {
564 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit store " << nhit <<
" ID 0x" << std::hex <<
unitID 565 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 566 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
570 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhit <<
" HCal hits from " << nHit
571 <<
" input hits E(Hcal) " << etot1 <<
" " << etot2;
574 for (
j = 0, itr = hhitl.begin(); itr != hhitl.end();
j++, itr++) {
580 for (k1 =
hits.begin(); k1 !=
hits.end(); k1++) {
581 int det = (**k1).det();
582 int layer = (**k1).layer();
583 double ehit = (**k1).e();
584 double eta = (**k1).eta();
585 double phi = (**k1).phi();
586 double jitter = (**k1).t();
587 uint32_t
unitID = (**k1).id();
589 for (k2 = k1 + 1; k2 !=
hits.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id(); k2++) {
599 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit store " << nhitl <<
" ID 0x" << std::hex <<
unitID 600 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 601 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
605 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhitl <<
" HCal hits from " << nHit
606 <<
" input hits E(Hcal) " << etot1 <<
" " << etotl;
609 std::vector<CaloHit> ehits;
611 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(
sdName);
616 <<
" is obtained at " << theHC <<
" with " << theHC->entries() <<
" entries";
618 if (idHC >= 0 && theHC !=
nullptr) {
619 thehc_entries = theHC->entries();
620 ehits.reserve(theHC->entries());
621 for (
j = 0;
j < thehc_entries;
j++) {
625 if (e < 0 || e > 100000.)
636 ehits.push_back(
hit);
640 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Ecal Hit i/p " <<
j <<
" ID 0x" << std::hex <<
id 641 <<
std::dec <<
" time " << std::setw(6) <<
time <<
" theta " << std::setw(8)
642 <<
theta <<
" eta " << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi 643 <<
" e " << std::setw(8) <<
e;
651 std::vector<CaloHit*> hite(nHit);
652 for (
j = 0, itr = ehits.begin(); itr != ehits.end();
j++, itr++) {
657 for (k1 = hite.begin(); k1 != hite.end(); k1++) {
658 int det = (**k1).det();
659 int layer = (**k1).layer();
660 double ehit = (**k1).e();
661 double eta = (**k1).eta();
662 double phi = (**k1).phi();
663 double jitter = (**k1).t();
664 uint32_t
unitID = (**k1).id();
666 for (k2 = k1 + 1; k2 != hite.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id(); k2++) {
676 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Ecal Hit store " << nhit <<
" ID 0x" << std::hex <<
unitID 677 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 678 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
682 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhit <<
" ECal hits from " << nHit
683 <<
" input hits E(Ecal) " << etot1 <<
" " << etot2;
686 nPrimary =
static_cast<int>(primaries.size());
688 G4PrimaryParticle* thePrim =
nullptr;
689 int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
691 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Event has " << nvertex <<
" verteices";
694 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERROR: no vertex found for event " <<
evNum;
695 for (
int i = 0;
i < nvertex;
i++) {
696 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
697 if (avertex ==
nullptr) {
698 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERR: pointer to vertex = 0 for event " <<
evNum;
700 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::Vertex number :" <<
i <<
" " << avertex->GetPosition();
701 int npart = avertex->GetNumberOfParticle();
703 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::End Of Event ERR: no primary!";
704 if (thePrim ==
nullptr)
705 thePrim = avertex->GetPrimary(trackID);
709 if (thePrim !=
nullptr) {
710 double px = thePrim->GetPx();
711 double py = thePrim->GetPy();
712 double pz = thePrim->GetPz();
716 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis:: EndOfEvent ERR: primary has p=0 ";
718 double costheta = pz /
p;
721 if (
px != 0 ||
py != 0)
726 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERR: could not find primary";
733 std::vector<CaloHit>
hits(hittot);
741 for (
unsigned int k1 = 0; k1 <
hcalHitCache.size(); k1++) {
743 uint32_t
id =
hit.
id();
745 double esim =
hit.e();
747 for (
unsigned int k2 = k1 + 1; k2 <
hcalHitCache.size(); k2++) {
761 <<
" energy from " << nhit <<
" hits starting with hit # " << k1
762 <<
" energy with noise " << eq;
764 for (
int k2 = 0; k2 <
nTower; k2++) {
774 for (
int k2 = 0; k2 <
nTower; k2++) {
782 <<
" registers " <<
esimh[k2] <<
" energy from hits and energy after QIE analysis " 790 CLHEP::RandGaussQ randGauss(*engine);
795 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::xtalAnalysis: Size " << iok.size() <<
" " <<
idEcal.size() <<
" " 798 for (
unsigned int k1 = 0; k1 <
ecalHitCache.size(); k1++) {
802 for (
unsigned int k2 = k1 + 1; k2 <
ecalHitCache.size(); k2++) {
810 double eq = esim + randGauss.fire(0.,
ecalNoise);
813 <<
" energy from " << nhit <<
" hits starting with hit # " << k1
814 <<
" energy with noise " << eq;
816 for (
int k2 = 0; k2 <
nCrystal; k2++) {
826 for (
int k2 = 0; k2 <
nCrystal; k2++) {
832 <<
" registers " <<
esime[k2] <<
" energy from hits and energy from noise " 856 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy deposit at Sim Level (Total) " <<
etots <<
" (ECal) " 858 <<
"\nHcalTB04Analysis:: Energy deposit at Qie Level (Total) " <<
etotq <<
" (ECal) " 864 for (
int i = 0;
i < 5;
i++) {
868 for (
int i = 0;
i < 3;
i++) {
872 double e1 = 0, e2 = 0;
887 if (
iphi >= 0 && iphi < 3 && ieta >= 0 &&
ieta < 5) {
896 for (
int i = 0;
i < 3;
i++) {
902 for (
int i = 0;
i < 5;
i++) {
909 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy fraction along Eta and Phi (Sim/Qie)";
910 for (
int i = 0;
i < 5;
i++)
917 for (
int i = 0;
i < 20;
i++) {
929 if (
iphi >= 0 && iphi < 3 && layer >= 0 &&
layer < 20) {
936 for (
int i = 0;
i < 20;
i++) {
943 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy fraction along Layer";
944 for (
int i = 0;
i < 20;
i++)
972 std::vector<CaloHit>::iterator itr;
974 uint32_t
id = itr->id();
980 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Save Hit " << std::setw(3) <<
i + 1 <<
" ID 0x" << std::hex
981 <<
group <<
std::dec <<
" " << std::setw(2) << det <<
" " << std::setw(2) << lay
982 <<
" " << std::setw(1) <<
z <<
" " << std::setw(3) <<
ieta <<
" " << std::setw(3)
983 <<
iphi <<
" T " << std::setw(6) << itr->t() <<
" E " << std::setw(6) << itr->e();
986 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Saves " << nhit <<
" hits from Crystals";
991 uint32_t
id = itr->
id();
997 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Save Hit " << std::setw(3) <<
i + 1 <<
" ID 0x" << std::hex
998 <<
group <<
std::dec <<
" " << std::setw(2) << det <<
" " << std::setw(2) << lay
999 <<
" " << std::setw(1) <<
z <<
" " << std::setw(3) <<
ieta <<
" " << std::setw(3)
1000 <<
iphi <<
" T " << std::setw(6) << itr->t() <<
" E " << std::setw(6) << itr->e();
1003 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Saves " << nhit <<
" hits from HCal";
1028 pvUVW = G4ThreeVector();
1046 esimh.push_back(0.);
1054 esime.push_back(0.);
1055 enois.push_back(0.);
1062 group = (det & 15) << 20;
1063 group += ((lay - 1) & 31) << 15;
1075 else if (
layer == 17)
1077 else if (
layer > 17)
1090 const double rLay[19] = {1836.0,
1112 const double zLay[19] = {4034.0,
1135 double tmp = dist / c_light / ns;
1137 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::timeOfFlight " <<
tmp <<
" for det/lay " << det <<
" " <<
layer 1138 <<
" 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)
constexpr std::array< uint8_t, layerIndexSize > layer
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
Power< A, B >::type pow(const A &a, const B &b)
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