11 #include "G4EventManager.hh" 12 #include "G4SDManager.hh" 15 #include "G4VProcess.hh" 16 #include "G4GFlashSpot.hh" 17 #include "G4ParticleTable.hh" 19 #include "G4SystemOfUnits.hh" 20 #include "G4PhysicalConstants.hh" 27 float timeSliceUnit,
bool ignoreTkID) :
29 G4VGFlashSensitiveDetector(), theTrack(
nullptr), preStepPoint(
nullptr), eminHit(0),
30 eminHitD(0), m_trackManager(manager), currentHit(
nullptr), runInit(
false),
31 timeSlice(timeSliceUnit), ignoreTrackID(ignoreTkID), hcID(-1), theHC(
nullptr),
38 std::vector<double> eminHits = m_CaloSD.
getParameter<std::vector<double> >(
"EminHits");
39 std::vector<double> tmaxHits = m_CaloSD.
getParameter<std::vector<double> >(
"TmaxHits");
40 std::vector<std::string> hcn = m_CaloSD.
getParameter<std::vector<std::string> >(
"HCNames");
41 std::vector<int> useResMap = m_CaloSD.
getParameter<std::vector<int> >(
"UseResponseTables");
42 std::vector<double> eminHitX = m_CaloSD.
getParameter<std::vector<double> >(
"EminHitsDepth");
51 double beamZ = m_CaloSD.
getParameter<
double>(
"BeamPosition")*cm;
54 SetVerboseLevel(verbn);
55 for (
unsigned int k=0;
k<hcn.size(); ++
k) {
56 if (name == (G4String)(hcn[
k])) {
59 if (
k < tmaxHits.size()) tmaxHit = tmaxHits[
k]*ns;
73 edm::LogInfo(
"CaloSim") <<
"CaloSD: Minimum energy of track for saving it " 74 << energyCut/
GeV <<
" GeV" <<
"\n" 75 <<
" Use of HitID Map " << useMap <<
"\n" 76 <<
" Check last " << checkHits
77 <<
" before saving the hit\n" 78 <<
" Correct TOF globally by " << correctT
79 <<
" ns (Flag =" << corrTOFBeam <<
")\n" 80 <<
" Save hits recorded before " << tmaxHit
81 <<
" ns and if energy is above " <<
eminHit/
MeV 83 <<
" MeV (for nonzero depths); Time Slice Unit " 97 if (aStep ==
nullptr) {
110 if (aSpot !=
nullptr) {
111 theTrack =
const_cast<G4Track *
>(aSpot->GetOriginatorTrack()->GetPrimaryTrack());
112 G4int particleCode =
theTrack->GetDefinition()->GetPDGEncoding();
114 if (particleCode ==
emPDG ||
115 particleCode ==
epPDG ||
117 edepositEM = aSpot->GetEnergySpot()->GetEnergy();
125 G4Step * fFakeStep =
new G4Step();
127 G4StepPoint * fFakePostStepPoint = fFakeStep->GetPostStepPoint();
129 fFakePostStepPoint->SetPosition(aSpot->GetPosition());
131 G4TouchableHandle fTouchableHandle = aSpot->GetTouchableHandle();
133 fFakeStep->SetTotalEnergyDeposit(aSpot->GetEnergySpot()->GetEnergy());
143 LogDebug(
"CaloSim") <<
"CaloSD:: GetSpotInfo for" 152 posGlobal = aSpot->GetEnergySpot()->GetPosition();
160 LogDebug(
"CaloSim") <<
"CaloSD: Incident energy " 178 return aStep->GetTotalEnergyDeposit();
185 edm::LogInfo(
"CaloSim") <<
"CaloSD : Initialize called for " << GetName();
202 edm::LogInfo(
"CaloSim") <<
"CaloSD: EndofEvent entered with " <<
theHC->entries()
216 theHC->PrintAllHits();
229 double time = (aStep->GetPostStepPoint()->GetGlobalTime())/nanosecond;
234 bool flag = (unitID > 0);
238 G4TouchableHistory* touch =(G4TouchableHistory*)(
theTrack->GetTouchable());
240 <<
" PV " << touch->GetVolume(0)->GetName()
241 <<
" PVid = " << touch->GetReplicaNumber(0)
242 <<
" MVid = " << touch->GetReplicaNumber(1)
246 G4TouchableHistory* touch =(G4TouchableHistory*)(
theTrack->GetTouchable());
248 <<
" PV " << touch->GetVolume(0)->GetName()
249 <<
" PVid = " << touch->GetReplicaNumber(0)
250 <<
" MVid = " << touch->GetReplicaNumber(1)
251 <<
" Unit " << std::hex << unitID <<
std::dec 256 G4int particleCode =
theTrack->GetDefinition()->GetPDGEncoding();
257 if (particleCode ==
emPDG ||
258 particleCode ==
epPDG ||
272 G4ThreeVector localPoint = touch->GetHistory()->GetTopTransform().TransformPoint(global);
279 G4ThreeVector globalPoint = touch->GetHistory()->GetTopTransform().Inverse().TransformPoint(local);
289 <<
" maybe detector name changed";
309 std::map<CaloHitID,CaloG4Hit*>::const_iterator it =
hitMap.find(
currentID);
317 int maxhit=
theHC->entries()-1;
319 for (
int j=maxhit; j>minhit&&!
found; --j) {
345 <<
" For Track " <<
theTrack->GetTrackID()
346 <<
" which is a " <<
theTrack->GetDefinition()->GetParticleName()
347 <<
" of energy " <<
theTrack->GetKineticEnergy()/
GeV 349 <<
" daughter of part. " <<
theTrack->GetParentID()
350 <<
" and created by " ;
379 etrack=
theTrack->GetKineticEnergy();
388 edm::LogInfo(
"CaloSim") <<
"CaloSD: set save the track " 395 edm::LogInfo(
"CaloSim") <<
"CaloSD : TrackwithHistory pointer for " 398 if (trkh !=
nullptr) {
403 edm::LogInfo(
"CaloSim") <<
"CaloSD: set save the track " 433 edm::LogInfo(
"CaloSim") <<
"CaloSD: Incident energy " << incidentEnergy/
GeV 441 double charge = aStep->GetPreStepPoint()->GetCharge();
443 if (charge != 0. && aStep->GetStepLength() > 0) {
444 G4Material* mat = aStep->GetPreStepPoint()->GetMaterial();
445 double density = mat->GetDensity();
446 double dedx = aStep->GetTotalEnergyDeposit()/aStep->GetStepLength();
447 double rkb = birk1/density;
448 double c = birk2*rkb*rkb;
449 if (
std::abs(charge) >= 2.) rkb /= birk3;
450 weight = 1./(1.+rkb*dedx+c*dedx*dedx);
452 edm::LogInfo(
"CaloSim") <<
"CaloSD::getAttenuation in " << mat->GetName()
453 <<
" Charge " << charge <<
" dE/dx " << dedx
454 <<
" Birk Const " << rkb <<
", " << c <<
" Weight = " 455 << weight <<
" dE " << aStep->GetTotalEnergyDeposit();
462 G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
464 emPDG = theParticleTable->FindParticle(particleName=
"e-")->GetPDGEncoding();
465 epPDG = theParticleTable->FindParticle(particleName=
"e+")->GetPDGEncoding();
466 gammaPDG = theParticleTable->FindParticle(particleName=
"gamma")->GetPDGEncoding();
477 edm::LogInfo(
"CaloSim") <<
"CaloSD: Dispatched BeginOfEvent for " 478 << GetName() <<
" !" ;
484 int id = (*trk)()->GetTrackID();
486 int lastTrackID = -1;
488 if (
id == lastTrackID) {
490 if (trksForThisEvent !=
nullptr) {
491 int it = (
int)(trksForThisEvent->size()) - 1;
496 edm::LogInfo(
"CaloSim") <<
"CaloSD: get track " << it <<
" from " 497 <<
"Container of size " << trksForThisEvent->size()
498 <<
" with ID " << trkH->
trackID();
500 edm::LogInfo(
"CaloSim") <<
"CaloSD: get track " << it <<
" from " 501 <<
"Container of size " << trksForThisEvent->size()
510 int count = 0, wrong = 0;
515 for (
int i=0;
i<
theHC->entries(); ++
i) {
521 edm::LogInfo(
"CaloSim") <<
"CaloSD: " << GetName() <<
" store " << count
522 <<
" hits recorded with " << wrong
523 <<
" track IDs not given properly and " 524 <<
totalHits-count <<
" hits not passing cuts";
538 edm::LogInfo(
"CaloSim") <<
"CaloSD: Clears hit vector for " << GetName() <<
" " <<
slave;
542 edm::LogInfo(
"CaloSim") <<
"CaloSD: Initialises slave SD for " << GetName();
555 edm::LogInfo(
"CaloSim") <<
"CaloSD: hit update from track Id on Calo Surface " 559 primaryID = aTrack->GetTrackID();
561 edm::LogWarning(
"CaloSim") <<
"CaloSD: Problem with primaryID **** set by " 562 <<
"force to TkID **** " << primaryID <<
" in " 563 <<
preStepPoint->GetTouchable()->GetVolume(0)->GetName();
592 if (hit ==
nullptr) {
619 <<
" changed to " << tkID <<
" by SimTrackManager" 627 edm::LogInfo(
"CaloSim") <<
"CaloSD: Store Hit at " << std::hex
629 << aHit->
getDepth() <<
" due to " << tkID
630 <<
" in time " << time <<
" of energy " 631 << aHit->
getEM()/
GeV <<
" GeV (EM) and " 642 if ( trkInfo->
isPrimary() ) primary = (*trk)()->GetTrackID();
646 <<
" primary ID = " << primary
652 if (primary > 0 && primary != primAncestor) {
653 primAncestor = primary;
663 std::vector<CaloG4Hit*>* theCollection =
theHC->GetVector();
666 edm::LogInfo(
"CaloSim") <<
"CaloSD: collection before merging, size = " <<
theHC->entries();
674 hitvec.swap(*theCollection);
677 edm::LogInfo(
"CaloSim") <<
"CaloSD::cleanHitCollection: sort hits in buffer " 679 for (
unsigned int i = 0;
i<
hitvec.size(); ++
i)
684 for (i=cleanIndex; i<hitvec.size(); ++
i) {
687 for (j = i+1; j <hitvec.size() &&
equal(hitvec[i], hitvec[j]); ++j) {
690 (*hitvec[
i]).addEnergyDeposit(*hitvec[j]);
691 (*hitvec[j]).setEM(0.);
692 (*hitvec[j]).setHadr(0.);
698 edm::LogInfo(
"CaloSim") <<
"CaloSD: cleanHitCollection merge the hits in buffer ";
699 for (
unsigned int i = 0; i<hitvec.size(); ++
i)
702 for (
unsigned int i = cleanIndex; i < cleanIndex+
selIndex.size(); ++
i ) {
705 hitvec.resize(cleanIndex+
selIndex.size());
707 edm::LogInfo(
"CaloSim") <<
"CaloSD::cleanHitCollection: remove the merged hits in buffer," 708 <<
" new size = " << hitvec.size();
709 for (
unsigned int i = 0; i<hitvec.size(); ++
i)
712 hitvec.swap(*theCollection);
713 std::vector<CaloG4Hit*>().
swap(hitvec);
719 edm::LogInfo(
"CaloSim") <<
"CaloSD: collection after merging, size = " <<
theHC->entries();
730 for (
unsigned int i =
cleanIndex;
i<theCollection->size(); ++
i) {
739 edm::LogInfo(
"CaloSim") <<
"CaloSD: dropped CaloG4Hit " <<
" " << *aHit;
744 reusehit.push_back((*theCollection)[i]);
752 edm::LogInfo(
"CaloSim") <<
"CaloSD: Size of reusehit after selection = " 753 <<
reusehit.size() <<
" Number of added hit = " 759 for (
int ii = addhit-1;
ii>=0; --
ii) {
765 for (
unsigned int j = 0; j<
selIndex.size(); ++j) {
773 edm::LogInfo(
"CaloSim") <<
"CaloSD: hit collection after selection, size = " 775 theHC->PrintAllHits();
virtual bool processHits(uint32_t, double, double, double, int, uint16_t depth=0)
T getParameter(std::string const &) const
virtual void Initialize()
T getUntrackedParameter(std::string const &, T const &) const
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3)
std::vector< PCaloHit > PCaloHitContainer
void updateHit(CaloG4Hit *)
virtual uint16_t getDepth(const G4Step *)
void setIncidentEnergy(double e)
void setEntryLocal(double x, double y, double z)
uint32_t setDetUnitId(const G4Step *step) override=0
uint16_t getDepth() const
virtual int getTrackID(const G4Track *)
void Initialize(G4HCofThisEvent *HCE) override
type of data representation of DDCompactView
void fillHits(edm::PCaloHitContainer &, const std::string &) override
void swap(Association< C > &lhs, Association< C > &rhs)
std::vector< CaloG4Hit * > reusehit
bool equal(const T &first, const T &second)
void cleanHitCollection()
double getWeight(int genPID, double genP)
void addEnergyDeposit(double em, double hd)
const TrackContainer * trackContainer() const
void resetForNewPrimary(const G4ThreeVector &, double)
std::string const collectionName[nCollections]
std::vector< TrackWithHistory * > TrackContainer
unsigned int trackID() const
bool trackExists(unsigned int i) const
virtual void ReserveMemory(unsigned int size)
void setID(uint32_t i, double d, int j, uint16_t k=0)
Abs< T >::type abs(const T &t)
std::vector< CaloG4Hit * > hitvec
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *)
CaloSD(const std::string &aSDname, const DDCompactView &cpv, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false)
int giveMotherNeeded(int i) const
std::vector< unsigned int > selIndex
CaloMeanResponse * meanResponse
void storeHit(CaloG4Hit *)
virtual bool filterHit(CaloG4Hit *, double)
virtual G4bool getStepInfo(G4Step *aStep)
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
G4StepPoint * preStepPoint
const math::XYZVectorD & momentum() const
void EndOfEvent(G4HCofThisEvent *eventHC) override
CSCCFEBTimeSlice const *const timeSlice(T const &data, int nCFEB, int nSample)
std::map< CaloHitID, CaloG4Hit * > hitMap
CaloG4HitCollection * theHC
void setPosition(double x, double y, double z)
void setEntry(double x, double y, double z)
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
double getTimeSlice() const
bool ProcessHits(G4Step *step, G4TouchableHistory *tHistory) override
std::map< int, TrackWithHistory * > tkMap
const SimTrackManager * m_trackManager
uint32_t getUnitID() const
void clearHits() override
double getResponseWt(const G4Track *)
bool saveHit(CaloG4Hit *)
CaloG4Hit * createNewHit()
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
G4ThreeVector entrancePoint
G4ThreeVector entranceLocal
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
double getEnergyDeposit() const
virtual double getEnergyDeposit(G4Step *step)
void NaNTrap(const G4Step *step) const
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *)