19 #include <G4RunManager.hh> 22 #include <G4PrimaryVertex.hh> 23 #include <G4PrimaryParticle.hh> 24 #include <G4StepStatus.hh> 25 #include <G4ProcessType.hh> 26 #include <G4EmProcessSubType.hh> 27 #include <G4UnitsTable.hh> 28 #include <G4ParticleTable.hh> 29 #include <G4SDManager.hh> 30 #include <G4HCtable.hh> 32 #include <G4SystemOfUnits.hh> 33 #include <G4PhysicalConstants.hh> 46 : G4VPersistencyManager(), fFilename(
"/dev/null"),
47 fLengthThreshold(10*
mm),
48 fGammaThreshold(5*
MeV), fNeutronThreshold(50*
MeV),
49 fTrajectoryPointAccuracy(1.*
mm), fTrajectoryPointDeposit(0*
MeV),
50 fSaveAllPrimaryTrajectories(true) {
61 EDepSimSevere(
" -- Open is not implimented for " << filename);
80 if (!aRun)
return false;
81 EDepSimSevere(
" -- Run store called without a save method for " 82 <<
"GEANT4 run " << aRun->GetRunID());
88 if (!aWorld)
return false;
89 EDepSimSevere(
" -- Geometry store called without a save method for " 90 << aWorld->GetName());
95 TPRegexp* bound =
new TPRegexp(b.c_str());
110 G4String currentVolume,
111 G4String prevVolume) {
112 if (status != fGeomBoundary)
return false;
113 std::string particleInfo =
":" + g4Traj->GetParticleName();
114 if (
std::abs(g4Traj->GetCharge())<0.1) particleInfo +=
":neutral";
115 else particleInfo +=
":charged";
122 if ((*r)->Match(current)>0 && (*r)->Match(previous)<1) {
127 if ((*r)->Match(current)<1 && (*r)->Match(previous)>0) {
137 const G4Run* runInfo = G4RunManager::GetRunManager()->GetCurrentRun();
159 std::vector<TG4PrimaryVertex>&
dest,
160 const G4PrimaryVertex* src) {
174 for (
int i=0; i< src->GetNumberOfParticle(); ++i) {
176 G4PrimaryParticle *g4Prim = src->GetPrimary(i);
178 if (g4Prim->GetG4code()) {
179 prim.
Name = g4Prim->GetG4code()->GetParticleName();
180 E =
pow(g4Prim->GetG4code()->GetPDGMass(),2);
183 prim.
Name =
"unknown";
185 prim.
PDGCode = g4Prim->GetPDGcode();
186 prim.
TrackId = g4Prim->GetTrackID() - 1;
187 prim.
Momentum.SetX(g4Prim->GetPx());
188 prim.
Momentum.SetY(g4Prim->GetPy());
189 prim.
Momentum.SetZ(g4Prim->GetPz());
191 if (E>0) E = std::sqrt(E);
211 const G4PrimaryVertex* infoVertex
220 src = src->GetNext();
226 const G4Event*
event) {
236 const G4TrajectoryContainer* trajectories =
event->GetTrajectoryContainer();
241 if (!trajectories->GetVector()) {
242 EDepSimError(
"No trajectory vector in trajectory container");
249 t != trajectories->GetVector()->end();
257 G4ParticleDefinition* part
258 = G4ParticleTable::GetParticleTable()->FindParticle(
262 +
"No particle information for " 278 int throttle = 999999;
291 }
while (--throttle > 0);
292 tempContainer.push_back(traj);
299 dest.push_back(tempContainer[i->second]);
317 t != dest.end(); ++
t) {
325 const G4TrajectoryContainer* trajectories =
event->GetTrajectoryContainer();
348 t != trajectories->GetVector()->end();
369 if (particleName ==
"anti_nu_e")
continue;
370 if (particleName ==
"anti_nu_mu")
continue;
371 if (particleName ==
"anti_nu_tau")
continue;
372 if (particleName ==
"nu_e")
continue;
373 if (particleName ==
"nu_mu")
continue;
374 if (particleName ==
"nu_tau")
continue;
377 if (processName ==
"Decay") {
410 if (particleName ==
"neutron" 422 G4HCofThisEvent* hitCollections =
event->GetHCofThisEvent();
423 if (!hitCollections)
return;
424 for (
int i=0; i < hitCollections->GetNumberOfCollections(); ++i) {
425 G4VHitsCollection* g4Hits = hitCollections->GetHC(i);
426 if (g4Hits->GetSize()<1)
continue;
427 for (
unsigned int h=0;
h<g4Hits->GetSize(); ++
h) {
453 G4VTrajectory* g4Traj) {
454 std::vector<int> selected;
460 std::sort(selected.begin(),selected.end());
461 selected.erase(std::unique(selected.begin(), selected.end()),
468 tp != selected.end(); ++tp) {
472 point.
Position.SetXYZT(edepPoint->GetPosition().x(),
473 edepPoint->GetPosition().y(),
474 edepPoint->GetPosition().z(),
481 traj.
Points.push_back(point);
488 const G4Event*
event) {
491 G4HCofThisEvent* HCofEvent =
event->GetHCofThisEvent();
492 if (!HCofEvent)
return;
493 G4SDManager *sdM = G4SDManager::GetSDMpointer();
494 G4HCtable *hcT = sdM->GetHCtable();
496 for (
int i=0; i<hcT->entries(); ++i) {
497 G4String SDname = hcT->GetSDname(i);
498 G4String HCname = hcT->GetHCname(i);
499 int HCId = sdM->GetCollectionID(SDname+
"/"+HCname);
500 G4VHitsCollection* g4Hits = HCofEvent->GetHC(HCId);
501 if (g4Hits->GetSize()<1)
continue;
504 if (!hitSeg)
continue;
511 G4VHitsCollection* g4Hits) {
517 for (std::size_t
h=0;
h<g4Hits->GetSize(); ++
h) {
538 const std::vector<int>& src) {
543 c != src.end(); ++
c) {
569 std::sort(dest.begin(),dest.end());
570 dest.erase(std::unique(dest.begin(),dest.end()),dest.end());
574 G4VTrajectory* g4Traj,
int point1,
int point2) {
575 if ((point2-point1) < 2)
return 0;
577 G4ThreeVector p1 = g4Traj->GetPoint(point1)->GetPosition();
578 G4ThreeVector p2 = g4Traj->GetPoint(point2)->GetPosition();
582 G4ThreeVector
dir = (p2-p1).unit();
584 int step = (point2-point1)/10 + 1;
586 double approach = 0.0;
587 for (
int p = point1+1;
p<point2;
p =
p +
step) {
588 p2 = g4Traj->GetPoint(
p)->GetPosition() - p1;
589 approach =
std::max((p2 - (dir*p2)*dir).
mag(), approach);
596 int point1,
int point2) {
598 int point3 = 0.5*(point1 + point2);
599 if (point3 <= point1)
EDepSimThrow(
"Points too close to split");
600 if (point2 <= point3)
EDepSimThrow(
"Points too close to split");
605 for (
int p = point1+1;
p<point2-1; ++
p) {
609 if (accuracy < bestAccuracy) {
611 bestAccuracy = accuracy;
620 G4VTrajectory* g4Traj) {
623 if (g4Traj->GetPointEntries() < 1) {
625 <<
" " << g4Traj->GetTrackID()
626 <<
" " << g4Traj->GetParentID()
627 <<
" " << g4Traj->GetParticleName());
634 selected.push_back(0);
639 int lastIndex = g4Traj->GetPointEntries()-1;
642 <<
" " << g4Traj->GetTrackID()
643 <<
" " << g4Traj->GetParentID()
644 <<
" " << g4Traj->GetParticleName());
647 selected.push_back(lastIndex);
664 for (
int tp = 1; tp < lastIndex; ++tp) {
671 volumeName,prevVolumeName)) {
672 selected.push_back(tp);
674 prevVolumeName = volumeName;
678 for (
int tp = 1; tp < lastIndex; ++tp) {
697 selected.push_back(tp);
701 std::sort(selected.begin(), selected.end());
702 selected.erase(std::unique(selected.begin(), selected.end()),
709 for (
int throttle = 0; throttle < 1000; ++throttle) {
710 bool addPoint =
false;
712 p1 != selected.end();
715 if (p2==selected.end())
break;
717 if (trajectoryAccuracy <= desiredAccuracy)
continue;
719 if (split < 0)
continue;
720 selected.push_back(split);
724 std::sort(selected.begin(), selected.end());
725 selected.erase(std::unique(selected.begin(), selected.end()),
727 if (!addPoint)
break;
#define EDepSimLog(outStream)
TG4PrimaryVertexContainer Primaries
void SummarizeTrajectories(std::vector< TG4Trajectory > &trajectories, const G4Event *event)
Fill the trajectory container.
double GetProbability() const
Get the probability of the interaction.
virtual ~PersistencyManager()
std::string Filename
The name of the input file.
double GetTrackLength(void) const
#define EDepSimNamedDebug(trace, outStream)
Float_t CrossSection
The cross section for the reaction that created this vertex.
TLorentzVector InitialMomentum
The initial momentum of the particle.
void CopyTrajectoryPoints(TG4Trajectory &traj, G4VTrajectory *g4Traj)
int SplitTrajectory(G4VTrajectory *traj, int point1, int point2)
PrimaryParticles Particles
The PrimaryVertex points for this PrimaryVertex.
G4int GetTrackID() const
Get the track id described by this trajectory.
double GetWeight() const
Get the weight of the vertex. This will be one if it's not filled.
TG4TrajectoryContainer Trajectories
G4double GetSDEnergyDeposit() const
Get the amount of energy deposited into a sensitive detector.
bool SaveTrajectoryBoundary(G4VTrajectory *g4Traj, G4StepStatus status, G4String currentVolume, G4String prevVolume)
G4int GetProcessSubType() const
G4double GetTime() const
Get the time that the particle passed this trajectory point.
const G4String & GetReaction() const
Get the reaction code that created this vertex.
const G4ThreeVector GetMomentum() const
Get the 3-momentum of the particle at this trajectory point.
virtual void AddTrajectoryBoundary(const G4String &boundary)
std::vector< TG4Trajectory > TG4TrajectoryContainer
std::map< std::string, TG4HitSegmentContainer > TG4HitSegmentDetectors
#define EDepSimThrow(message)
Print an error message, and then throw an exception.
virtual bool GetSaveAllPrimaryTrajectories(void) const
static constexpr double MeV
#define EDepSimSevere(outStream)
G4ThreeVector GetInitialMomentum() const
Get the initial momentum of the particle that created this trajectory.
TLorentzVector Stop
The stopping position of the segment.
TrajectoryPoints Points
The trajectory points for this trajectory.
double fTrajectoryPointAccuracy
void CopyHitContributors(std::vector< int > &dest, const std::vector< int > &src)
virtual G4double GetNeutronThreshold() const
Float_t EnergyDeposit
The total energy deposit in this hit.
G4double GetSDLength() const
Get the total length of this trajectory that is in a sensitive detector.
std::string Name
The name of the particle.
TLorentzVector Momentum
The initial momentum of the particle.
std::vector< TG4HitSegment > TG4HitSegmentContainer
A container for the hit segment information.
Int_t PDGCode
The PDG encoding of the particle.
void SummarizeHitSegments(std::vector< TG4HitSegment > &segments, G4VHitsCollection *hits)
Fill a container of hit segments.
virtual double GetTrajectoryPointAccuracy(void) const
const G4LorentzVector & GetStart() const
The position of the starting point.
Int_t ParentId
The unique Id of the parent trajectory (The TrackId of the parent).
void MarkTrajectory(bool save=true)
Mark this trajectory as one that should be saved in the output.
G4String GetParticleName() const
Get the particle name.
G4String GetProcessName() const
Get the interaction process that created the trajectory.
TG4HitSegmentDetectors SegmentDetectors
std::string Reaction
The reaction that created this vertex.
virtual double GetTrajectoryPointDeposit(void) const
double FindTrajectoryAccuracy(G4VTrajectory *traj, int point1, int point2)
static constexpr double eV
TVector3 Momentum
The momentum of the particle at this trajectory point.
void SummarizeSegmentDetectors(TG4HitSegmentDetectors &segmentDetectors, const G4Event *event)
sensitive detector.
bool SaveTrajectory() const
Check if this trajectory should be saved.
void SelectTrajectoryPoints(std::vector< int > &selected, G4VTrajectory *g4Traj)
TG4Event fEventSummary
A summary of the primary vertices in the event.
G4int GetPDGEncoding() const
Get the PDG MC particle number for this particle.
int EventId
The event number.
G4ProcessType GetProcessType() const
int GetInteractionNumber() const
Get the index of the interaction within the input interaction file.
G4double GetSDTotalEnergyDeposit() const
static int max(int a, int b)
#define EDepSimVerbose(outStream)
const G4String & GetFilename()
Get the file that this vertex came from.
virtual G4double GetGammaThreshold() const
void SetFilename(G4String file)
std::string Name
The name of the particle.
double GetSecondaryDeposit(void) const
G4StepStatus GetStepStatus() const
int GetPrimaryTrajectoryId(void) const
G4double GetProcessDeposit() const
virtual G4bool Open(G4String filename)
virtual void ClearTrajectoryBoundaries()
void SummarizePrimaries(std::vector< TG4PrimaryVertex > &primaries, const G4PrimaryVertex *event)
const G4LorentzVector & GetStop() const
The position of the stopping point.
G4String GetPhysVolName() const
#define EDepSimError(outStream)
TG4PrimaryVertexContainer Informational
The informational vertices associated with this vertex.
double GetDiffCrossSection() const
virtual const G4PrimaryVertex * GetInformationalVertex(int i=0) const
std::string GeneratorName
The name of the generator that created this vertex.
Int_t PDGCode
The PDG code of the particle.
TLorentzVector Position
The initial position of the particle.
static constexpr double mm
Int_t TrackId
The TrackId of this trajectory.
void split(std::string const &s, char c, OutIter dest)
std::vector< int > & GetContributors()
Provide public access to the contributors for internal G4 classes.
double GetCrossSection() const
Get the cross section for the reaction that created this vertex.
void MarkTrajectories(const G4Event *event)
Mark the G4 Trajectories that should be saved.
Int_t InteractionNumber
The index (or identifier) of the interaction in the kinematics file.
virtual G4bool Close(void)
Make sure the output file is closed.
TLorentzVector Start
The starting position of the segment.
virtual G4bool Store(const G4Event *anEvent)
stores anEvent and the associated objects into database.
static G4VTrajectory * Get(int trackId)
Provide a map between the track id and the trajectory object.
EDepSim::PersistencyMessenger * fPersistencyMessenger
TLorentzVector Position
The position of this trajectory point.
double GetEnergyDeposit(void) const
Get the total energy deposited in this hit.
G4int GetParentID() const
std::vector< TPRegexp * > fTrajectoryBoundaries
Event finding and building.
virtual G4double GetLengthThreshold() const
Get the threshold for length in a sensitive detector.
void UpdateSummaries(const G4Event *event)
Update the event summary fields.