18#include "BDSAuxiliaryNavigator.hh"
20#include "BDSGlobalConstants.hh"
21#include "BDSHitSamplerLink.hh"
22#include "BDSLinkEventAction.hh"
23#include "BDSLinkEventInfo.hh"
24#include "BDSLinkRunAction.hh"
25#include "BDSOutput.hh"
26#include "BDSSDSampler.hh"
27#include "BDSSDSamplerLink.hh"
28#include "BDSSDManager.hh"
29#include "BDSUtilities.hh"
33#include "G4EventManager.hh"
34#include "G4HCofThisEvent.hh"
35#include "G4PropagatorInField.hh"
37#include "G4SDManager.hh"
38#include "G4THitsMap.hh"
39#include "G4TransportationManager.hh"
40#include "G4VUserEventInformation.hh"
45BDSLinkEventAction::BDSLinkEventAction(
BDSOutput* outputIn,
49 runAction(runActionIn),
51 collIDSamplerLink(-1),
54 primaryAbsorbedInCollimator(false)
57 verboseEventBDSIM = globals->VerboseEventBDSIM();
58 verboseEventStart = globals->VerboseEventStart();
60 printModulo = globals->PrintModuloEvents();
63BDSLinkEventAction::~BDSLinkEventAction()
66void BDSLinkEventAction::BeginOfEventAction(
const G4Event* evt)
68 currentEventIndex = evt->GetEventID();
69 primaryAbsorbedInCollimator =
false;
72 BDSAuxiliaryNavigator::ResetNavigatorStates();
75 G4Navigator* trackingNavigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
76 trackingNavigator->ResetStackAndState();
77 G4TransportationManager* tm = G4TransportationManager::GetTransportationManager();
79 for (
auto it = tm->GetActiveNavigatorsIterator(); i < (int)tm->GetNoActiveNavigators(); it++)
80 {(*it)->ResetStackAndState(); i++;}
81 tm->GetPropagatorInField()->ClearPropagatorState();
86 if (currentEventIndex % printModulo == 0)
87 {G4cout <<
"---> Begin of event: " << currentEventIndex << G4endl;}
89 if (verboseEventBDSIM)
90 {G4cout << __METHOD_NAME__ <<
"event #" << currentEventIndex << G4endl;}
93 if (collIDSamplerLink < 0)
95 G4SDManager* g4SDMan = G4SDManager::GetSDMpointer();
97 collIDSamplerLink = g4SDMan->GetCollectionID(bdsSDMan->
SamplerLink()->GetName());
98 collIDSampler = g4SDMan->GetCollectionID(bdsSDMan->
SamplerPlane()->GetName());
102void BDSLinkEventAction::EndOfEventAction(
const G4Event* evt)
105 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
107 slhc* samplerLink = HCE ?
dynamic_cast<slhc*
>(HCE->GetHC(collIDSamplerLink)) : nullptr;
109 shc* sampHC = HCE ?
dynamic_cast<shc*
>(HCE->GetHC(collIDSampler)) : nullptr;
110 std::vector<shc*> allSamplerHits = {sampHC};
112 G4VUserEventInformation* evtInfoG4 = evt->GetUserInformation();
114 G4int primaryExternalParticleID = 0;
115 G4int primaryExternalParentID = 0;
118 primaryExternalParticleID = evtInfo->externalParticleIDofPrimary;
119 primaryExternalParentID = evtInfo->externalParentIDofPrimary;
124 if (samplerLink->entries() <= 0)
127 {runAction->AppendHits(currentEventIndex, primaryExternalParticleID, primaryExternalParentID, samplerLink);}
130 evt->GetPrimaryVertex(),
132 std::vector<BDSHitsCollectionSamplerCylinder*>(),
133 std::vector<BDSHitsCollectionSamplerSphere*>(),
142 std::vector<const BDSTrajectoryPointHit*>(),
143 std::vector<const BDSTrajectoryPointHit*>(),
147 std::map<G4String, G4THitsMap<G4double>*>(),
A class that holds global options and constants.
static BDSGlobalConstants * Instance()
Access method.
BDSOutput * output
Cache of output instance. Not owned by this class.
Simple extension to cache extra variables through an event.
Simplified run action to hold link hits.
Output base class that defines interface for all output types.
void FillEvent(const BDSEventInfo *info, const G4PrimaryVertex *vertex, const std::vector< BDSHitsCollectionSampler * > &samplerHitsPlane, const std::vector< BDSHitsCollectionSamplerCylinder * > &samplerHitsCylinder, const std::vector< BDSHitsCollectionSamplerSphere * > &samplerHitsSphere, const BDSHitsCollectionSamplerLink *samplerHitsLink, const BDSHitsCollectionEnergyDeposition *energyLoss, const BDSHitsCollectionEnergyDeposition *energyLossFull, const BDSHitsCollectionEnergyDeposition *energyLossVacuum, const BDSHitsCollectionEnergyDeposition *energyLossTunnel, const BDSHitsCollectionEnergyDepositionGlobal *energyLossWorld, const BDSHitsCollectionEnergyDepositionGlobal *energyLossWorldContents, const BDSHitsCollectionEnergyDepositionGlobal *worldExitHits, const std::vector< const BDSTrajectoryPointHit * > &primaryHits, const std::vector< const BDSTrajectoryPointHit * > &primaryLosses, const BDSTrajectoriesToStore *trajectories, const BDSHitsCollectionCollimator *collimatorHits, const BDSHitsCollectionApertureImpacts *apertureImpactHits, const std::map< G4String, G4THitsMap< G4double > * > &scorerHitsMap, const G4int turnsTaken)
Copy event information from Geant4 simulation structures to output structures.
A singleton class that holds all required sensitive detector class instances.
BDSSDSamplerLink * SamplerLink() const
SD for link samplers.
BDSSDSampler * SamplerPlane() const
SD for samplers (plane type). See also SamplerPlaneWithFilter below.
G4int VerboseEventStop(G4int verboseEventStart, G4int verboseEventContinueFor)