ATLAS Offline Software
ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ISF_GEANT4TOOLS_TRANSPORTTOOL_H
6 #define ISF_GEANT4TOOLS_TRANSPORTTOOL_H
7 
8 
9 
10 // Gaudi headers
11 #include "GaudiKernel/ToolHandle.h"
12 #include "GaudiKernel/ServiceHandle.h"
13 
14 // DetectorDescription
16 
17 // Athena headers
19 //#include "AthenaKernel/SlotSpecificObj.h"
27 
28 // ISF includes
30 //#include "ISF_Interfaces/ISimulationSelector.h"
32 //#include "ISF_Geant4Tools/IG4RunManagerHelper.h"
33 
36 // TBB
37 #include "tbb/concurrent_unordered_map.h"
38 
39 // STL headers
40 #include <string>
41 #include <thread>
42 
43 
44 
45 class G4Event;
46 class G4Timer;
47 class G4AtlasRunManager;
48 
49 namespace ISF {
50  class ISFParticle;
51 }
52 
53 
54 
55 namespace iGeant4
56 {
57 
67 
68  public:
70  G4TransportTool(const std::string&,const std::string&,const IInterface*);
71 
73  virtual ~G4TransportTool () = default;
74 
76  virtual StatusCode initialize() override final;
77 
80  void initializeOnce ATLAS_NOT_THREAD_SAFE ();
81 
83  virtual StatusCode finalize() override final;
84 
87  void finalizeOnce();
88 
89  virtual StatusCode simulate( ISF::ISFParticle& isp, ISF::ISFParticleContainer& secondaries, McEventCollection* mcEventCollection ) override;
90 
91  virtual StatusCode simulateVector( const ISF::ISFParticleVector& particles, ISF::ISFParticleContainer& secondaries, McEventCollection* mcEventCollection, McEventCollection *shadowTruth=nullptr ) override;
92 
93  virtual StatusCode setupEvent(const EventContext&) override;
94 
95  virtual StatusCode releaseEvent(const EventContext&) override;
96 
97  virtual ISF::SimulationFlavor simFlavor() const override { return ISF::Geant4; };
98 
99  private:
100 
102  void commandLog(int returnCode, const std::string& commandString) const;
103 
104  HepMC::GenEvent* genEvent(McEventCollection* mcEventCollection) const;
105 
108 
109  // timing checks
110  Gaudi::Property<bool> m_doTiming{this, "PrintTimingInfo", true, ""};
111  //float m_runTime;
114  unsigned int m_nrOfEntries{0};
115 
116  G4Timer* m_runTimer{nullptr};
117  G4Timer* m_eventTimer{nullptr};
118 
119  // user actions that can return secondaries
120  // Must be indexed by thread ID, and accessible from multiple threads
122  using passbackActionMap_t = tbb::concurrent_unordered_map< std::thread::id, std::vector< passbackAction_t* >, std::hash<std::thread::id> >;
123  mutable passbackActionMap_t m_secondaryActions ATLAS_THREAD_SAFE;
124 
125  Gaudi::Property<std::string> m_mcEventCollectionName{this, "McEventCollection", "TruthEvent", ""};
127  // PublicToolHandle<ISF::IG4RunManagerHelper> m_g4RunManagerHelper{this, "G4RunManagerHelper", "iGeant4::G4RunManagerHelper/G4RunManagerHelper", ""};
128  // G4AtlasRunManager *m_pRunMgr{};
129 
130  Gaudi::Property<std::string> m_libList{this, "Dll", "", ""};
131  Gaudi::Property<std::string> m_physList{this, "Physics", "", ""};
132  Gaudi::Property<std::string> m_fieldMap{this, "FieldMap", "", ""};
133  Gaudi::Property<bool> m_releaseGeoModel{this, "ReleaseGeoModel", true, ""};
134  Gaudi::Property<bool> m_recordFlux{this, "RecordFlux", false, ""};
136  Gaudi::Property<std::vector<std::string> > m_g4commands{this, "G4Commands", {}, "Commands to send to the G4UI"};
138  Gaudi::Property<bool> m_useMT{this,"MultiThreading", false, "Multi-threading specific settings"};
139  Gaudi::Property<bool> m_activateParallelGeometries{this, "ActivateParallelWorlds", false, "Toggle on/off the G4 parallel geometry system"};
140  // Random number service
141  ServiceHandle<IAthRNGSvc> m_rndmGenSvc{this, "RandomNumberService", "AthRNGSvc", ""};
143  Gaudi::Property<std::string> m_randomStreamName{this, "RandomStreamName", "Geant4", ""};
145  ServiceHandle<IUserLimitsSvc> m_userLimitsSvc{this, "UserLimitsSvc", "UserLimitsSvc", ""};
147  ServiceHandle<G4UA::IUserActionSvc> m_userActionSvc{this, "UserActionSvc", "", ""};
149  ServiceHandle<IDetectorGeometrySvc> m_detGeoSvc{this, "DetGeoSvc", "DetectorGeometrySvc", ""};
151  ServiceHandle<ISF::IInputConverter> m_inputConverter{this, "InputConverter", "ISF_InputConverter", ""};
153  ServiceHandle<IPhysicsListSvc> m_physListSvc{this, "PhysicsListSvc", "PhysicsListSvc", ""};
155  PublicToolHandle<ISensitiveDetectorMasterTool> m_senDetTool{this, "SenDetMasterTool", "SensitiveDetectorMasterTool", ""};
157  PublicToolHandle<IFastSimulationMasterTool> m_fastSimTool{this, "FastSimMasterTool", "FastSimulationMasterTool", ""};
159 
160  };
161 
162 
163 }
164 
165 
166 #endif // ISF_GEANT4TOOLS_TRANSPORTTOOL_H
ISF::ISFParticleContainer
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)
Definition: ISFParticleContainer.h:23
iGeant4::G4TransportTool::m_activateParallelGeometries
Gaudi::Property< bool > m_activateParallelGeometries
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:139
iGeant4::G4TransportTool::m_libList
Gaudi::Property< std::string > m_libList
Helper Tool to provide G4RunManager.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:130
iGeant4::G4TransportTool::G4TransportTool
G4TransportTool(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:58
G4UA::iGeant4::TrackProcessorUserActionBase
Definition: TrackProcessorUserActionBase.h:33
iGeant4::G4TransportTool::simFlavor
virtual ISF::SimulationFlavor simFlavor() const override
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:97
iGeant4::G4TransportTool::m_nrOfEntries
unsigned int m_nrOfEntries
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:114
IUserActionSvc.h
iGeant4::G4TransportTool::~G4TransportTool
virtual ~G4TransportTool()=default
Destructor.
AtlasRegion.h
iGeant4::G4TransportTool::m_accumulatedEventTimeSq
float m_accumulatedEventTimeSq
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:113
ISensitiveDetectorMasterTool.h
iGeant4::G4TransportTool::m_fieldMap
Gaudi::Property< std::string > m_fieldMap
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:132
iGeant4::G4TransportTool::setupEvent
virtual StatusCode setupEvent(const EventContext &) override
Setup Event chain - in case of a begin-of event action is needed.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:366
IInputConverter.h
iGeant4::G4TransportTool::m_physListSvc
ServiceHandle< IPhysicsListSvc > m_physListSvc
Physics List Service.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:153
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
iGeant4::G4TransportTool::m_physList
Gaudi::Property< std::string > m_physList
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:131
G4AtlasRunManager
ATLAS custom singleton run manager.
Definition: G4AtlasRunManager.h:30
iGeant4::G4TransportTool::m_senDetTool
PublicToolHandle< ISensitiveDetectorMasterTool > m_senDetTool
Sensitive Detector Master Tool.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:155
iGeant4::G4TransportTool::simulate
virtual StatusCode simulate(ISF::ISFParticle &isp, ISF::ISFParticleContainer &secondaries, McEventCollection *mcEventCollection) override
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:258
IFastSimulationMasterTool.h
iGeant4::G4TransportTool::m_mcEventCollectionName
Gaudi::Property< std::string > m_mcEventCollectionName
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:125
IUserLimitsSvc.h
iGeant4::G4TransportTool::m_runTimer
G4Timer * m_runTimer
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:116
iGeant4::G4TransportTool::genEvent
HepMC::GenEvent * genEvent(McEventCollection *mcEventCollection) const
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:448
iGeant4::G4TransportTool::m_doTiming
Gaudi::Property< bool > m_doTiming
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:110
iGeant4::G4TransportTool::simulateVector
virtual StatusCode simulateVector(const ISF::ISFParticleVector &particles, ISF::ISFParticleContainer &secondaries, McEventCollection *mcEventCollection, McEventCollection *shadowTruth=nullptr) override
Simulation call for vectors of particles.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:275
iGeant4::G4TransportTool::finalize
virtual StatusCode finalize() override final
AlgTool finalize method.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:215
ISF::Geant4
@ Geant4
Definition: SimulationFlavor.h:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TrackProcessorUserActionBase.h
iGeant4::G4TransportTool::m_inputConverter
ServiceHandle< ISF::IInputConverter > m_inputConverter
Service to convert ISF_Particles into a G4Event.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:151
IDetectorGeometrySvc.h
iGeant4::G4TransportTool::m_accumulatedEventTime
float m_accumulatedEventTime
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:112
ISF::ISFParticleVector
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
Definition: ISFParticleContainer.h:26
GenEvent_fwd.h
BaseSimulatorTool.h
iGeant4::G4TransportTool::ATLAS_NOT_THREAD_SAFE
void initializeOnce ATLAS_NOT_THREAD_SAFE()
G4 initialization called only by the first tool instance.
iGeant4::G4TransportTool::m_rndmGenSvc
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:141
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
iGeant4::G4TransportTool::m_fastSimTool
PublicToolHandle< IFastSimulationMasterTool > m_fastSimTool
Fast Simulation Master Tool.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:157
iGeant4::G4TransportTool::passbackActionMap_t
tbb::concurrent_unordered_map< std::thread::id, std::vector< passbackAction_t * >, std::hash< std::thread::id > > passbackActionMap_t
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:122
iGeant4::G4TransportTool::releaseEvent
virtual StatusCode releaseEvent(const EventContext &) override
Release Event chain - in case of an end-of event action is needed.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:402
iGeant4::G4TransportTool
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:66
ISF::BaseSimulatorTool
Definition: BaseSimulatorTool.h:36
iGeant4::G4TransportTool::m_g4commands
Gaudi::Property< std::vector< std::string > > m_g4commands
Commands to send to the G4 UI.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:136
SimulationFlavor
Definition: SimulationFlavor.py:1
iGeant4::G4TransportTool::m_eventTimer
G4Timer * m_eventTimer
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:117
iGeant4::G4TransportTool::commandLog
void commandLog(int returnCode, const std::string &commandString) const
This command prints a message about a G4Command depending on its returnCode.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:470
iGeant4::G4TransportTool::finalizeOnce
void finalizeOnce()
G4 finalization called only by the first tool instance.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:249
iGeant4::G4TransportTool::m_useMT
Gaudi::Property< bool > m_useMT
Activate multi-threading configuration.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:138
iGeant4::G4TransportTool::m_userLimitsSvc
ServiceHandle< IUserLimitsSvc > m_userLimitsSvc
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:145
ISF
ISFParticleOrderedQueue.
Definition: PrimaryParticleInformation.h:13
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
IPhysicsListSvc.h
iGeant4::G4TransportTool::m_detGeoSvc
ServiceHandle< IDetectorGeometrySvc > m_detGeoSvc
Detector Geometry Service (builds G4 Geometry)
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:149
iGeant4::G4TransportTool::initialize
virtual StatusCode initialize() override final
AlgTool initialize method.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:68
CI_EMPFlowData22test.returnCode
returnCode
Definition: CI_EMPFlowData22test.py:16
checker_macros.h
Define macros for attributes used to control the static checker.
iGeant4::G4TransportTool::m_releaseGeoModel
Gaudi::Property< bool > m_releaseGeoModel
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:133
iGeant4::G4TransportTool::m_recordFlux
Gaudi::Property< bool > m_recordFlux
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:134
iGeant4::G4TransportTool::m_userActionSvc
ServiceHandle< G4UA::IUserActionSvc > m_userActionSvc
user action service
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:147
iGeant4::G4TransportTool::m_randomStreamName
Gaudi::Property< std::string > m_randomStreamName
Random Stream Name.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:143
iGeant4::G4TransportTool::ATLAS_THREAD_SAFE
passbackActionMap_t m_secondaryActions ATLAS_THREAD_SAFE
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:123
IAthRNGSvc.h
ServiceHandle< IAthRNGSvc >
iGeant4
Definition: Geant4TruthIncident.h:35