ATLAS Offline Software
G4LegacyTransportTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ISF_GEANT4TOOLS_G4LEGACYTRANSPORTTOOL_H
6 #define ISF_GEANT4TOOLS_G4LEGACYTRANSPORTTOOL_H
7 
8 
9 
10 // Gaudi headers
11 #include "GaudiKernel/ToolHandle.h"
12 #include "GaudiKernel/ServiceHandle.h"
13 
14 // DetectorDescription
16 
17 // Athena headers
28 
29 // ISF includes
34 // STL headers
35 #include <memory>
36 #include <string>
37 #include <unordered_map>
38 
39 class G4Event;
40 class G4Timer;
41 class G4AtlasRunManager;
42 
43 namespace ISF {
44  class ISFParticle;
45 }
46 
48 
49 namespace iGeant4
50 {
51 
61  : public ISF::BaseSimulatorG4Tool {
62 
63  public:
65  G4LegacyTransportTool(const std::string&, const std::string&,
66  const IInterface*);
67 
69  virtual ~G4LegacyTransportTool() = default;
70 
72  virtual StatusCode initialize() override final;
73 
76  void initializeOnce ATLAS_NOT_THREAD_SAFE();
77 
79  virtual StatusCode finalize() override final;
80 
83  void finalizeOnce();
84 
85  using ISF::BaseSimulatorG4Tool::releaseEvent;
86  using ISF::BaseSimulatorG4Tool::setupEvent;
87  using ISF::BaseSimulatorG4Tool::simulate;
88  using ISF::BaseSimulatorG4Tool::simulateVector;
89 
90  virtual StatusCode simulate(const EventContext& ctx, ISF::ISFParticle& isp,
91  ISF::ISFParticleContainer& secondaries,
92  McEventCollection* mcEventCollection,
93  std::shared_ptr<HitCollectionMap>) override;
94 
95  virtual StatusCode simulateVector(
96  const EventContext& ctx, const ISF::ISFParticleVector& particles,
97  ISF::ISFParticleContainer& secondaries,
98  McEventCollection* mcEventCollection, std::shared_ptr<HitCollectionMap> hitCollections,
99  McEventCollection* shadowTruth = nullptr) override;
100 
101  virtual StatusCode setupEvent(const EventContext&,
102  HitCollectionMap&) override;
103 
104  virtual StatusCode releaseEvent(const EventContext&,
105  HitCollectionMap&) override;
106 
107  virtual ISF::SimulationFlavor simFlavor() const override {
108  return ISF::Geant4;
109  };
110 
111  private:
114  void commandLog(int returnCode, const std::string& commandString) const;
115 
116  HepMC::GenEvent* genEvent(McEventCollection* mcEventCollection) const;
117 
120 
121  // timing checks
122  Gaudi::Property<bool> m_doTiming{this, "PrintTimingInfo", true, ""};
123  // float m_runTime;
124  float m_accumulatedEventTime{0.};
125  float m_accumulatedEventTimeSq{0.};
126  unsigned int m_nrOfEntries{0};
127 
128  G4Timer* m_runTimer{nullptr};
129  G4Timer* m_eventTimer{nullptr};
130 
131  // store secondary particles that have been pushed back
132  struct Slot {
133  std::unordered_map<ISF::ISFParticle const*, ISF::ISFParticleContainer>
136  typedef std::lock_guard<mutex_t> lock_t;
138  };
140  Gaudi::Property<std::string> m_mcEventCollectionName{
141  this, "McEventCollection", "TruthEvent", ""};
143  PublicToolHandle<ISF::IG4RunManagerHelper> m_g4RunManagerHelper{
144  this, "G4RunManagerHelper",
145  "iGeant4::G4RunManagerHelper/G4RunManagerHelper", ""};
146  G4AtlasRunManager* m_pRunMgr{};
147 
148  Gaudi::Property<std::string> m_libList{this, "Dll", "", ""};
149  Gaudi::Property<std::string> m_physList{this, "Physics", "", ""};
150  Gaudi::Property<std::string> m_fieldMap{this, "FieldMap", "", ""};
151  Gaudi::Property<bool> m_releaseGeoModel{this, "ReleaseGeoModel", true, ""};
152  Gaudi::Property<bool> m_recordFlux{this, "RecordFlux", false, ""};
153  Gaudi::Property<bool> m_quietMode{this, "QuietMode", false, ""};
155  Gaudi::Property<std::vector<std::string> > m_g4commands{
156  this, "G4Commands", {}, "Commands to send to the G4UI"};
158  Gaudi::Property<bool> m_useMT{this, "MultiThreading", false,
159  "Multi-threading specific settings"};
160  Gaudi::Property<bool> m_activateParallelGeometries{
161  this, "ActivateParallelWorlds", false,
162  "Toggle on/off the G4 parallel geometry system"};
163  // Random number service
164  ServiceHandle<IAthRNGSvc> m_rndmGenSvc{this, "RandomNumberService",
165  "AthRNGSvc", ""};
167  Gaudi::Property<std::string> m_randomStreamName{this, "RandomStreamName",
168  "Geant4", ""};
170  ServiceHandle<IUserLimitsSvc> m_userLimitsSvc{this, "UserLimitsSvc",
171  "UserLimitsSvc", ""};
173  ServiceHandle<G4UA::IUserActionSvc> m_userActionSvc{this, "UserActionSvc", "",
174  ""};
175  PublicToolHandle<IDetectorConstructionTool> m_detConstruction{this, "DetectorConstruction", "", "Tool handle of the DetectorConstruction"};
178  this, "InputConverter", "ISF_InputConverter", ""};
180  ServiceHandle<IPhysicsListSvc> m_physListSvc{this, "PhysicsListSvc",
181  "PhysicsListSvc", ""};
183  PublicToolHandle<ISensitiveDetectorMasterTool> m_senDetTool{
184  this, "SenDetMasterTool", "SensitiveDetectorMasterTool", ""};
186  PublicToolHandle<IFastSimulationMasterTool> m_fastSimTool{
187  this, "FastSimMasterTool", "FastSimulationMasterTool", ""};
188  PublicToolHandleArray<IPhysicsInitializationTool> m_physicsInitializationTools{this, "PhysicsInitializationTools", {}, "Physics initialization happening after Geant4 initialization"};
190 };
191 }
192 
193 
194 #endif // ISF_GEANT4TOOLS_G4LEGACYTRANSPORTTOOL_H
ISF::ISFParticleContainer
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)
Definition: ISFParticleContainer.h:23
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
HitCollectionMap
Small wrapper around hit collection map to facilitate accessing the hit collection.
Definition: HitCollectionMap.h:21
iGeant4::G4LegacyTransportTool
Definition: G4LegacyTransportTool.h:61
IUserActionSvc.h
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition: checker_macros.h:212
AtlasRegion.h
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
initialize
void initialize()
Definition: run_EoverP.cxx:894
ISensitiveDetectorMasterTool.h
IInputConverter.h
iGeant4::G4LegacyTransportTool::~G4LegacyTransportTool
virtual ~G4LegacyTransportTool()=default
Destructor.
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
G4AtlasRunManager
ATLAS custom singleton run manager.
Definition: G4AtlasRunManager.h:28
iGeant4::G4LegacyTransportTool::Slot
Definition: G4LegacyTransportTool.h:132
IFastSimulationMasterTool.h
IUserLimitsSvc.h
SG::SlotSpecificObj
Maintain a set of objects, one per slot.
Definition: AthenaKernel/AthenaKernel/SlotSpecificObj.h:70
IG4RunManagerHelper.h
ISF::Geant4
@ Geant4
Definition: SimulationFlavor.h:23
ISimulationSelector.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ISF::ISFParticleVector
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
Definition: ISFParticleContainer.h:26
GenEvent_fwd.h
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:32
iGeant4::G4LegacyTransportTool::Slot::mutex_t
std::mutex mutex_t
Definition: G4LegacyTransportTool.h:135
iGeant4::G4LegacyTransportTool::ATLAS_THREAD_SAFE
SG::SlotSpecificObj< Slot > m_slots ATLAS_THREAD_SAFE
Definition: G4LegacyTransportTool.h:139
IPhysicsInitialization.h
iGeant4::G4LegacyTransportTool::Slot::m_mutex
mutex_t m_mutex
Definition: G4LegacyTransportTool.h:137
BaseSimulatorG4Tool.h
SimulationFlavor
Definition: SimulationFlavor.py:1
IDetectorConstructionTool.h
ISF
ISFParticleOrderedQueue.
Definition: PrimaryParticleInformation.h:13
iGeant4::G4LegacyTransportTool::Slot::lock_t
std::lock_guard< mutex_t > lock_t
Definition: G4LegacyTransportTool.h:136
iGeant4::G4LegacyTransportTool::Slot::m_secondariesMap
std::unordered_map< ISF::ISFParticle const *, ISF::ISFParticleContainer > m_secondariesMap
Definition: G4LegacyTransportTool.h:134
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
ISF::BaseSimulatorG4Tool
Definition: BaseSimulatorG4Tool.h:28
IPhysicsListSvc.h
SlotSpecificObj.h
Maintain a set of objects, one per slot.
checker_macros.h
Define macros for attributes used to control the static checker.
IAthRNGSvc.h
ServiceHandle< IAthRNGSvc >
iGeant4
Definition: Geant4TruthIncident.h:35