19#include "BDSAuxiliaryNavigator.hh"
21#include "BDSGlobalConstants.hh"
22#include "BDSHitSamplerLink.hh"
23#include "BDSLinkEventAction.hh"
24#include "BDSLinkEventInfo.hh"
25#include "BDSLinkRunAction.hh"
26#include "BDSOutput.hh"
27#include "BDSSDSampler.hh"
28#include "BDSSDSamplerLink.hh"
29#include "BDSSDManager.hh"
30#include "BDSUtilities.hh"
34#include "G4EventManager.hh"
35#include "G4HCofThisEvent.hh"
36#include "G4PropagatorInField.hh"
38#include "G4SDManager.hh"
39#include "G4THitsMap.hh"
40#include "G4TransportationManager.hh"
41#include "G4VUserEventInformation.hh"
46BDSLinkEventAction::BDSLinkEventAction(
BDSOutput* outputIn,
50 runAction(runActionIn),
52 collIDSamplerLink(-1),
55 primaryAbsorbedInCollimator(false)
58 verboseEventBDSIM = globals->VerboseEventBDSIM();
59 verboseEventStart = globals->VerboseEventStart();
61 printModulo = globals->PrintModuloEvents();
64BDSLinkEventAction::~BDSLinkEventAction()
67void BDSLinkEventAction::BeginOfEventAction(
const G4Event* evt)
69 currentEventIndex = evt->GetEventID();
70 primaryAbsorbedInCollimator =
false;
73 BDSAuxiliaryNavigator::ResetNavigatorStates();
76 G4Navigator* trackingNavigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
77 trackingNavigator->ResetStackAndState();
78 G4TransportationManager* tm = G4TransportationManager::GetTransportationManager();
80 for (
auto it = tm->GetActiveNavigatorsIterator(); i < (
int)tm->GetNoActiveNavigators(); it++)
81 {(*it)->ResetStackAndState(); i++;}
82 tm->GetPropagatorInField()->ClearPropagatorState();
87 if (currentEventIndex % printModulo == 0)
88 {G4cout <<
"---> Begin of event: " << currentEventIndex << G4endl;}
90 if (verboseEventBDSIM)
91 {G4cout << __METHOD_NAME__ <<
"event #" << currentEventIndex << G4endl;}
94 if (collIDSamplerLink < 0)
96 G4SDManager* g4SDMan = G4SDManager::GetSDMpointer();
98 collIDSamplerLink = g4SDMan->GetCollectionID(bdsSDMan->
SamplerLink()->GetName());
99 collIDSampler = g4SDMan->GetCollectionID(bdsSDMan->
SamplerPlane()->GetName());
103void BDSLinkEventAction::EndOfEventAction(
const G4Event* evt)
106 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
108 slhc* samplerLink = HCE ?
dynamic_cast<slhc*
>(HCE->GetHC(collIDSamplerLink)) :
nullptr;
110 shc* sampHC = HCE ?
dynamic_cast<shc*
>(HCE->GetHC(collIDSampler)) :
nullptr;
111 std::vector<shc*> allSamplerHits = {sampHC};
113 G4VUserEventInformation* evtInfoG4 = evt->GetUserInformation();
115 G4int primaryExternalParticleID = 0;
116 G4int primaryExternalParentID = 0;
119 primaryExternalParticleID = evtInfo->externalParticleIDofPrimary;
120 primaryExternalParentID = evtInfo->externalParentIDofPrimary;
125 if (samplerLink->entries() <= 0)
128 {runAction->AppendHits(currentEventIndex, primaryExternalParticleID, primaryExternalParentID, samplerLink);}
131 evt->GetPrimaryVertex(),
133 std::vector<BDSHitsCollectionSamplerCylinder*>(),
134 std::vector<BDSHitsCollectionSamplerSphere*>(),
143 std::vector<const BDSTrajectoryPointHit*>(),
144 std::vector<const BDSTrajectoryPointHit*>(),
148 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)