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/SystemOfUnits.h> 63 #include <CLHEP/Units/PhysicalConstants.h> 76 class HepRandomEngine;
81 public Observer<const BeginOfEvent*>,
120 const std::vector<std::string>
names;
158 hcalOnly(m_Anal.getParameter<
bool>(
"HcalOnly")),
159 mode(m_Anal.getParameter<
int>(
"Mode")),
160 type(m_Anal.getParameter<
int>(
"Type")),
161 ecalNoise(m_Anal.getParameter<double>(
"EcalNoise")),
162 beamOffset(-m_Anal.getParameter<double>(
"BeamPosition") *
CLHEP::cm),
163 scaleHB0(m_Anal.getParameter<double>(
"ScaleHB0")),
164 scaleHB16(m_Anal.getParameter<double>(
"ScaleHB16")),
165 scaleHO(m_Anal.getParameter<double>(
"ScaleHO")),
166 scaleHE0(m_Anal.getParameter<double>(
"ScaleHE0")),
174 double beamEta = (fMaxEta + fMinEta) / 2.;
175 double beamPhi = (fMaxPhi + fMinPhi) / 2.;
176 double beamThet = 2 * atan(
exp(-beamEta));
179 iceta =
static_cast<int>(beamEta / 0.087) + 1;
180 icphi =
static_cast<int>(std::fabs(beamPhi) / 0.087) + 5;
184 produces<PHcalTB04Info>();
191 <<
"HcalTB04:: Initialised as observer of BeginOf Job/BeginOfRun/BeginOfEvent/G4Step/EndOfEvent with Parameter " 192 "values:\n \thcalOnly = " 193 <<
hcalOnly <<
"\tecalNoise = " <<
ecalNoise <<
"\n\tMode = " <<
mode <<
" (0: HB2 Standard; 1:HB2 Segmented)" 194 <<
"\tType = " <<
type <<
" (0: HB; 1 HE; 2 HB+HE)\n\tbeamOffset = " <<
beamOffset <<
"\ticeta = " <<
iceta 205 edm::LogVerbatim(
"HcalTBSim") <<
"\n --------> Total number of selected entries : " <<
count <<
"\nPointers:: QIE " 248 for (
int lay = 1; lay < 8; lay++) {
249 for (
int icr = 1; icr < 8; icr++) {
272 for (
int i = 0;
i < 5;
i++) {
276 for (
int i = 0;
i < 3;
i++) {
280 for (
int i = 0;
i < 20;
i++) {
292 int irun = (*run)()->GetRunID();
295 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
298 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
299 if (aSD ==
nullptr) {
301 <<
" with name " << sdname <<
" in this " 305 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
309 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: set a new numbering scheme";
313 aSD = sd->FindSensitiveDetector(sdname);
314 if (aSD ==
nullptr) {
316 <<
" with name " << sdname <<
" in this " 320 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
324 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::beginOfRun: set a new numbering scheme";
329 <<
"not get SD Manager!";
336 evNum = (*evt)()->GetEventID();
342 if (aStep !=
nullptr) {
344 G4ThreeVector thePreStepPoint = aStep->GetPreStepPoint()->GetPosition();
345 G4ThreeVector thePostStepPoint;
348 G4Track* aTrack = aStep->GetTrack();
349 int trackID = aTrack->GetTrackID();
350 int parentID = aTrack->GetParentID();
351 const G4ThreeVector&
position = aTrack->GetPosition();
352 G4ThreeVector momentum = aTrack->GetMomentum();
353 G4String partType = aTrack->GetDefinition()->GetParticleType();
354 G4String partSubType = aTrack->GetDefinition()->GetParticleSubType();
355 int partPDGEncoding = aTrack->GetDefinition()->GetPDGEncoding();
357 bool isPDGStable = aTrack->GetDefinition()->GetPDGStable();
359 double pDGlifetime = aTrack->GetDefinition()->GetPDGLifeTime();
360 double gammaFactor = aStep->GetPreStepPoint()->GetGamma();
363 double stepDeltaEnergy = aStep->GetDeltaEnergy();
364 double kinEnergy = aTrack->GetKineticEnergy();
367 if (trackID == 1 && parentID == 0 && ((kinEnergy == 0.) || (std::fabs(stepDeltaEnergy / kinEnergy) > 0.1))) {
369 if (kinEnergy == 0.) {
372 if (std::fabs(stepDeltaEnergy / kinEnergy) > 0.1)
382 G4String thePostPVname =
"NoName";
383 G4StepPoint* thePostPoint = aStep->GetPostStepPoint();
385 thePostStepPoint = thePostPoint->GetPosition();
386 G4VPhysicalVolume* thePostPV = thePostPoint->GetPhysicalVolume();
388 thePostPVname = thePostPV->GetName();
391 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: V1 found at: " << thePostStepPoint
392 <<
" G4VPhysicalVolume: " << thePostPVname;
399 if ((trackID != 1 && parentID == 1 && (aTrack->GetCurrentStepNumber() == 1) && (thePreStepPoint ==
pvPosition)) ||
400 (trackID == 1 && thePreStepPoint ==
pvPosition)) {
402 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::A secondary... PDG:" << partPDGEncoding
403 <<
" TrackID:" << trackID <<
" ParentID:" << parentID
404 <<
" stable: " << isPDGStable <<
" Tau: " << pDGlifetime
405 <<
" cTauGamma=" << c_light * pDGlifetime * gammaFactor * 1000.
406 <<
"um GammaFactor: " << gammaFactor;
411 secEkin.push_back(aTrack->GetKineticEnergy());
414 double ctaugamma_um = CLHEP::c_light * pDGlifetime * gammaFactor * 1000.;
415 if ((ctaugamma_um > 0.) && (ctaugamma_um < 100.)) {
423 if (aTrack->GetCurrentStepNumber() == 1) {
428 std::vector<int>::iterator
pos;
434 <<
"HcalTB04Analysis:: A tertiary... PDG:" << partPDGEncoding <<
" TrackID:" << trackID
435 <<
" ParentID:" << parentID <<
" stable: " << isPDGStable <<
" Tau: " << pDGlifetime
436 <<
" cTauGamma=" << c_light * pDGlifetime * gammaFactor * 1000. <<
"um GammaFactor: " << gammaFactor;
451 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::Fill event " << (*evt)()->GetEventID();
459 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
476 int iEvt = (*evt)()->GetEventID();
479 else if ((iEvt < 100) && (iEvt % 10 == 0))
481 else if ((iEvt < 1000) && (iEvt % 100 == 0))
483 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
488 std::vector<CaloHit> hhits, hhitl;
491 std::map<int, float, std::less<int> > primaries;
493 double etot1 = 0, etot2 = 0;
497 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
499 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(
sdName);
503 <<
" is obtained at " << theHC <<
" with " << theHC->entries() <<
" entries";
505 int thehc_entries = theHC->entries();
506 if (idHC >= 0 && theHC !=
nullptr) {
507 hhits.reserve(theHC->entries());
508 hhitl.reserve(theHC->entries());
509 for (
j = 0;
j < thehc_entries;
j++) {
528 hhits.push_back(
hit);
530 hhitl.push_back(hitl);
534 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit i/p " <<
j <<
" ID 0x" << std::hex <<
id <<
" 0x" 535 <<
idx <<
std::dec <<
" time " << std::setw(6) <<
time <<
" " << std::setw(6)
536 << jitter <<
" theta " << std::setw(8) <<
theta <<
" eta " << std::setw(8) <<
eta 537 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) <<
e <<
" " 538 << std::setw(8) << escl;
544 std::vector<CaloHit>::iterator itr;
545 int nHit = hhits.size();
546 std::vector<CaloHit*>
hits(nHit);
547 for (
j = 0, itr = hhits.begin(); itr != hhits.end();
j++, itr++) {
551 std::vector<CaloHit*>::iterator k1,
k2;
555 for (k1 =
hits.begin(); k1 !=
hits.end(); k1++) {
556 int det = (**k1).det();
557 int layer = (**k1).layer();
558 double ehit = (**k1).e();
559 double eta = (**k1).eta();
560 double phi = (**k1).phi();
561 double jitter = (**k1).t();
562 uint32_t
unitID = (**k1).id();
564 for (
k2 = k1 + 1;
k2 !=
hits.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id();
k2++) {
574 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit store " << nhit <<
" ID 0x" << std::hex <<
unitID 575 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 576 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
580 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhit <<
" HCal hits from " << nHit
581 <<
" input hits E(Hcal) " << etot1 <<
" " << etot2;
584 for (
j = 0, itr = hhitl.begin(); itr != hhitl.end();
j++, itr++) {
592 for (k1 =
hits.begin(); k1 !=
hits.end(); k1++) {
593 int det = (**k1).det();
594 int layer = (**k1).layer();
595 double ehit = (**k1).e();
596 double eta = (**k1).eta();
597 double phi = (**k1).phi();
598 double jitter = (**k1).t();
599 uint32_t
unitID = (**k1).id();
601 for (
k2 = k1 + 1;
k2 !=
hits.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id();
k2++) {
611 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Hcal Hit store " << nhitl <<
" ID 0x" << std::hex <<
unitID 612 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 613 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
617 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhitl <<
" HCal hits from " << nHit
618 <<
" input hits E(Hcal) " << etot1 <<
" " << etotl;
621 std::vector<CaloHit> ehits;
623 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(
sdName);
628 <<
" is obtained at " << theHC <<
" with " << theHC->entries() <<
" entries";
630 if (idHC >= 0 && theHC !=
nullptr) {
631 thehc_entries = theHC->entries();
632 ehits.reserve(theHC->entries());
633 for (
j = 0;
j < thehc_entries;
j++) {
637 if (e < 0 || e > 100000.)
648 ehits.push_back(
hit);
652 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Ecal Hit i/p " <<
j <<
" ID 0x" << std::hex <<
id 653 <<
std::dec <<
" time " << std::setw(6) <<
time <<
" theta " << std::setw(8)
654 <<
theta <<
" eta " << std::setw(8) <<
eta <<
" phi " << std::setw(8) <<
phi 655 <<
" e " << std::setw(8) <<
e;
663 std::vector<CaloHit*> hite(nHit);
664 for (
j = 0, itr = ehits.begin(); itr != ehits.end();
j++, itr++) {
671 for (k1 = hite.begin(); k1 != hite.end(); k1++) {
672 int det = (**k1).det();
673 int layer = (**k1).layer();
674 double ehit = (**k1).e();
675 double eta = (**k1).eta();
676 double phi = (**k1).phi();
677 double jitter = (**k1).t();
678 uint32_t
unitID = (**k1).id();
680 for (
k2 = k1 + 1;
k2 != hite.end() && std::fabs(jitter - (**k2).t()) < 1 &&
unitID == (**k2).id();
k2++) {
690 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Ecal Hit store " << nhit <<
" ID 0x" << std::hex <<
unitID 691 <<
std::dec <<
" time " << std::setw(6) << jitter <<
" eta " << std::setw(8) <<
eta 692 <<
" phi " << std::setw(8) <<
phi <<
" e " << std::setw(8) << ehit;
696 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Stores " << nhit <<
" ECal hits from " << nHit
697 <<
" input hits E(Ecal) " << etot1 <<
" " << etot2;
700 nPrimary =
static_cast<int>(primaries.size());
702 G4PrimaryParticle* thePrim =
nullptr;
703 int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
705 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Event has " << nvertex <<
" verteices";
708 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERROR: no vertex found for event " <<
evNum;
709 for (
int i = 0;
i < nvertex;
i++) {
710 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
711 if (avertex ==
nullptr) {
712 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERR: pointer to vertex = 0 for event " <<
evNum;
714 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::Vertex number :" <<
i <<
" " << avertex->GetPosition();
715 int npart = avertex->GetNumberOfParticle();
717 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::End Of Event ERR: no primary!";
718 if (thePrim ==
nullptr)
719 thePrim = avertex->GetPrimary(trackID);
723 if (thePrim !=
nullptr) {
724 double px = thePrim->GetPx();
725 double py = thePrim->GetPy();
726 double pz = thePrim->GetPz();
730 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis:: EndOfEvent ERR: primary has p=0 ";
732 double costheta = pz /
p;
735 if (
px != 0 ||
py != 0)
740 edm::LogWarning(
"HcalTBSim") <<
"HcalTB04Analysis::EndOfEvent ERR: could not find primary";
747 std::vector<CaloHit>
hits(hittot);
755 for (
unsigned int k1 = 0; k1 <
hcalHitCache.size(); k1++) {
757 uint32_t
id =
hit.
id();
759 double esim =
hit.e();
775 <<
" energy from " << nhit <<
" hits starting with hit # " << k1
776 <<
" energy with noise " << eq;
796 <<
" registers " <<
esimh[
k2] <<
" energy from hits and energy after QIE analysis " 804 CLHEP::RandGaussQ randGauss(*engine);
809 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::xtalAnalysis: Size " << iok.size() <<
" " <<
idEcal.size() <<
" " 812 for (
unsigned int k1 = 0; k1 <
ecalHitCache.size(); k1++) {
824 double eq = esim + randGauss.fire(0.,
ecalNoise);
827 <<
" energy from " << nhit <<
" hits starting with hit # " << k1
828 <<
" energy with noise " << eq;
846 <<
" registers " <<
esime[
k2] <<
" energy from hits and energy from noise " 870 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy deposit at Sim Level (Total) " <<
etots <<
" (ECal) " 872 <<
"\nHcalTB04Analysis:: Energy deposit at Qie Level (Total) " <<
etotq <<
" (ECal) " 878 for (
int i = 0;
i < 5;
i++) {
882 for (
int i = 0;
i < 3;
i++) {
886 double e1 = 0, e2 = 0;
901 if (
iphi >= 0 && iphi < 3 && ieta >= 0 &&
ieta < 5) {
910 for (
int i = 0;
i < 3;
i++) {
916 for (
int i = 0;
i < 5;
i++) {
923 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy fraction along Eta and Phi (Sim/Qie)";
924 for (
int i = 0;
i < 5;
i++)
931 for (
int i = 0;
i < 20;
i++) {
943 if (
iphi >= 0 && iphi < 3 && layer >= 0 &&
layer < 20) {
950 for (
int i = 0;
i < 20;
i++) {
957 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Energy fraction along Layer";
958 for (
int i = 0;
i < 20;
i++)
986 std::vector<CaloHit>::iterator itr;
988 uint32_t
id = itr->id();
994 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Save Hit " << std::setw(3) << nhit <<
" ID 0x" << std::hex
995 <<
group <<
std::dec <<
" " << std::setw(2) << det <<
" " << std::setw(2) << lay
996 <<
" " << std::setw(1) <<
z <<
" " << std::setw(3) <<
ieta <<
" " << std::setw(3)
997 <<
iphi <<
" T " << std::setw(6) << itr->t() <<
" E " << std::setw(6) << itr->e();
1000 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Saves " << nhit <<
" hits from Crystals";
1006 uint32_t
id = itr->id();
1012 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Save Hit " << std::setw(3) << nhit + nhit0 <<
" ID 0x" 1013 << std::hex <<
group <<
std::dec <<
" " << std::setw(2) << det <<
" " << std::setw(2)
1014 << lay <<
" " << std::setw(1) <<
z <<
" " << std::setw(3) <<
ieta <<
" " 1015 << std::setw(3) <<
iphi <<
" T " << std::setw(6) << itr->t() <<
" E " << std::setw(6)
1019 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis:: Saves " << nhit <<
" hits from HCal";
1044 pvUVW = G4ThreeVector();
1062 esimh.push_back(0.);
1070 esime.push_back(0.);
1071 enois.push_back(0.);
1078 group = (det & 15) << 20;
1079 group += ((lay - 1) & 31) << 15;
1091 else if (
layer == 17)
1093 else if (
layer > 17)
1106 const double rLay[19] = {1836.0,
1128 const double zLay[19] = {4034.0,
1151 double tmp = dist / c_light / ns;
1153 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB04Analysis::timeOfFlight " <<
tmp <<
" for det/lay " << det <<
" " <<
layer 1154 <<
" eta/theta " <<
eta <<
" " <<
theta / CLHEP::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 *)
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
MPlex< T, D1, D2, N > atan2(const MPlex< T, D1, D2, N > &y, const MPlex< T, D1, D2, N > &x)