47 : fApplication(nullptr), fCurrentEngine(nullptr), fTotalNPrimaries(0), fTotalNTracks(0), fUserStack(nullptr),
48 fBranchArrayContainer(), fIsInitialized(
kFALSE), fIsInitializedUser(
kFALSE)
51 ::Fatal(
"TMCManager::TMCManager",
"Attempt to create two instances of singleton.");
91 ::Fatal(
"TMCManager::RegisterMC",
"This engine is already registered.");
114 ::Fatal(
"TMCManager::Register",
"The application is already registered.");
116 ::Info(
"TMCManager::Register",
"Register user application and construct geometry");
126 ::Fatal(
"TMCManager::Register",
"The TGeo geometry is not closed. Please check whether you just have to close "
127 "it or whether something was forgotten.");
149 engines.resize(
fEngines.size(),
nullptr);
163 ::Fatal(
"TMCManager::GetEngine",
"Unknown engine ID.");
180 ::Warning(
"TMCManager::GetEngineId",
"Unknown engine %s.", engineName);
236 if (engineId < 0 || engineId >=
static_cast<Int_t>(
fEngines.size())) {
237 ::Fatal(
"TMCManager::ForwardTrack",
"Engine ID %i out of bounds. Have %zu engines.", engineId,
fEngines.size());
255 fStacks[engineId]->PushPrimaryTrackId(trackId);
257 fStacks[engineId]->PushSecondaryTrackId(trackId);
282 if (engineTargetId < 0 || engineTargetId >=
static_cast<Int_t>(
fEngines.size())) {
283 ::Fatal(
"TMCManager::TransferTrack",
284 "Target engine ID out of bounds. Have %zu engines. Requested target ID was %i",
fEngines.size(),
338 if(geoStateId == 0) {
371 ::Fatal(
"TMCManager::Run",
"Missing user stack pointer.");
374 ::Fatal(
"TMCManager::Run",
"No engines registered");
379 if (!mc->IsRootGeometrySupported()) {
380 ::Fatal(
"TMCManager::Run",
"Engine %s does not support geometry built via ROOT's TGeoManager", mc->GetName());
382 Int_t currentEngineId = mc->GetId();
397 ::Warning(
"TMCManager::Run",
"Only one engine registered. That will lead to overhead in "
398 "the simulation run due to additional hooks and dispatches "
399 "to the TMCManager.");
411 ::Fatal(
"TMCManager::Run",
"Engines have not yet been initialized.");
418 ::Fatal(
"TMCManager::Run",
"Need at least one event to process but %i events specified.", nEvents);
422 for (
Int_t i = 0; i < nEvents; i++) {
423 ::Info(
"TMCManager::Run",
"Start event %i", i + 1);
445 stack->ResetInternals();
466 if (
fStacks[i]->GetStackedNtrack() > 0) {
void Info(const char *location, const char *msgfmt,...)
void Warning(const char *location, const char *msgfmt,...)
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TGeoManager * gGeoManager
An array of daughter indices making a geometry path.
void UpdateNavigator(TGeoNavigator *nav) const
Update the navigator to reflect the branch.
void InitFromNavigator(TGeoNavigator *nav)
Init the branch array from current navigator state.
TGeoBranchArray * GetNewGeoState(UInt_t &userIndex)
Get a TGeoBranchArray to set to current geo state.
const TGeoBranchArray * GetGeoState(UInt_t userIndex)
Get a TGeoBranchArray to read the current state from.
void InitializeFromGeoManager(TGeoManager *man, UInt_t size=8)
Initialize from TGeoManager to extract maxlevels.
void FreeGeoStates()
Free all geo states at once but keep the container size.
void FreeGeoState(UInt_t userIndex)
Free the index of this geo state such that it can be re-used.
TGeoNavigator * GetCurrentNavigator() const
Returns current navigator for the calling thread.
void SetOutside(Bool_t flag=kTRUE)
Concrete implementation of particles stack used by the TMCManager.
Singleton manager class for handling and steering a run with multiple TVirtualMC engines sharing even...
Int_t GetEngineId(const char *name) const
Get engine ID by its name.
Bool_t RestoreGeometryState()
Try to restore geometry for the track currently set.
TVirtualMC * GetCurrentEngine() const
Get the current engine pointer.
void TerminateRun()
Terminate a run in all engines.
virtual ~TMCManager()
Destructor.
void ForwardTrack(Int_t toBeDone, Int_t trackId, Int_t parentId, TParticle *particle, Int_t engineId)
User interface to forward particle to specifiic engine.
std::vector< TParticle * > fParticles
All tracks (persistent)
std::vector< TVirtualMC ** > fConnectedEnginePointers
Connected engine pointers which will be updated everytime the current engine changes.
Int_t fTotalNPrimaries
Total number of primaries ever pushed.
void ConnectEnginePointer(TVirtualMC **mc)
Connect a pointer which is updated whenever the engine is changed.
void TransferTrack(Int_t engineTargetId)
Transfer track from current engine to engine with engineTargetId.
Bool_t GetNextEngine()
Find the next engine.
TVirtualMC * fCurrentEngine
Pointer to current engine.
TVirtualMC * GetEngine(Int_t id) const
Get an engine pointer by ID.
void UpdateEnginePointers(TVirtualMC *mc)
Update all engine pointers connected to the TMCManager.
void Init()
Initialize engines.
Bool_t fIsInitializedUser
Flag if specific initialization for engines was done.
TVirtualMCApplication * fApplication
Pointer to user application.
void PrepareNewEvent()
Do necessary steps before an event is triggered.
std::vector< std::unique_ptr< TMCManagerStack > > fStacks
Stacks connected to engines.
TVirtualMCStack * fUserStack
Pointer to user stack.
static TMCThreadLocal TMCManager * fgInstance
Singleton instance.
static TMCManager * Instance()
Static access method.
Int_t fTotalNTracks
Total number of tracks ever pushed.
TMCManager()
Default constructor.
std::vector< std::unique_ptr< TMCParticleStatus > > fParticlesStatus
All particles' status (persistent)
void Run(Int_t nEvents)
Run the event loop.
std::vector< TVirtualMC * > fEngines
Collecting pointers to all instanciated TVirtualMCs.
Bool_t fIsInitialized
Flag if engines are initilaized.
void SetUserStack(TVirtualMCStack *stack)
Set user stack.
Int_t NEngines() const
Return the number of registered engines.
TGeoMCBranchArrayContainer fBranchArrayContainer
Pointer to cache with geometry states.
void Register(TVirtualMC *engine)
A TVirtualMC will register itself via this method during construction if a TMCManager was instanciate...
void GetEngines(std::vector< TVirtualMC * > &engines) const
Get registered engine pointers.
Description of the dynamic properties of a particle.
Interface to a user Monte Carlo application.
virtual void GeneratePrimaries()=0
Generate primary particles.
virtual void ConstructGeometry()=0
Construct user geometry.
virtual Bool_t MisalignGeometry()
Misalign user geometry (optional)
virtual void ConstructOpGeometry()
Define parameters for optical processes (optional)
virtual void BeginEvent()=0
Define actions at the beginning of the event.
virtual void FinishEvent()=0
Define actions at the end of the event.
Interface to a user defined particles stack.
Abstract Monte Carlo interface.
virtual Double_t TrackLength() const =0
Return the length of the current track from its origin (in cm)
virtual void TrackPolarization(Double_t &polX, Double_t &polY, Double_t &polZ) const
Get the current polarization.
virtual Int_t StepNumber() const
Return the current step number.
virtual void InterruptTrack()
That triggers stopping the transport of the current track without dispatching to common routines like...
void SetId(UInt_t id)
Set the VMC id.
virtual void ProcessEvent(Int_t eventId)
Process one event.
virtual void TrackPosition(TLorentzVector &position) const =0
Return the current position in the master reference frame of the track being transported.
virtual void SetStack(TVirtualMCStack *stack)
Set the particle stack.
void SetManagerStack(TMCManagerStack *stack)
Set container holding additional information for transported TParticles.
virtual Double_t TrackWeight() const
Get the current weight.
static TMCThreadLocal TVirtualMC * fgMC
Static TVirtualMC pointer.
virtual void TrackMomentum(TLorentzVector &momentum) const =0
Return the direction and the momentum (GeV/c) of the track currently being transported.
Int_t GetId() const
Return the VMC's ID.
std::string GetName(const std::string &scope_name)