ATLAS Offline Software
Loading...
Searching...
No Matches
iGeant4::G4TransportTool Class Reference

Geant4 AlgTool to create a ISFParticle at a volume entry/exit. More...

#include <TransportTool.h>

Inheritance diagram for iGeant4::G4TransportTool:
Collaboration diagram for iGeant4::G4TransportTool:

Public Member Functions

 G4TransportTool (const std::string &, const std::string &, const IInterface *)
 Constructor.
virtual ~G4TransportTool ()=default
 Destructor.
virtual StatusCode initialize () override final
 AlgTool initialize method.
void initializeOnce ATLAS_NOT_THREAD_SAFE ()
 G4 initialization called only by the first tool instance.
virtual StatusCode finalize () override final
 AlgTool finalize method.
void finalizeOnce ()
 G4 finalization called only by the first tool instance.
virtual StatusCode simulate (const EventContext &ctx, ISF::ISFParticle &isp, ISF::ISFParticleContainer &secondaries, McEventCollection *mcEventCollection, std::shared_ptr< HitCollectionMap > hitCollections) override
 Simulation call for individual particles.
virtual StatusCode simulateVector (const EventContext &ctx, const ISF::ISFParticleVector &particles, ISF::ISFParticleContainer &secondaries, McEventCollection *mcEventCollection, std::shared_ptr< HitCollectionMap > hitCollections, McEventCollection *shadowTruth=nullptr) override
 Simulation call for vectors of particles.
virtual StatusCode setupEvent (const EventContext &, HitCollectionMap &) override
 Create data containers for an event.
virtual StatusCode releaseEvent (const EventContext &, HitCollectionMap &) override
 Finalise data containers for an event.
virtual ISF::SimulationFlavor simFlavor () const override
virtual StatusCode releaseEvent (const EventContext &)
 Finalise data containers for an event.
virtual StatusCode setupEvent (const EventContext &)
 Create data containers for an event.
virtual StatusCode simulate (const EventContext &, ISFParticle &, ISFParticleContainer &, McEventCollection *)
 Simulation call for individual particles.
virtual StatusCode simulateVector (const EventContext &, const ISFParticleVector &, ISFParticleContainer &, McEventCollection *, McEventCollection *)
 Simulation call for vectors of particles.
virtual StatusCode simulate (const EventContext &, ISFParticle &, ISFParticleContainer &, McEventCollection *)
 Simulation call for individual particles.
virtual StatusCode simulateVector (const EventContext &, const ISFParticleVector &, ISFParticleContainer &, McEventCollection *, McEventCollection *)
 Simulation call for vectors of particles.
virtual StatusCode setupEventST (HitCollectionMap &hitCollections)
 Create data containers for an event (called by ISimulationSvc)
virtual StatusCode setupEventST ()
 Create data containers for an event (called by ISimulationSvc)
virtual StatusCode releaseEventST (HitCollectionMap &hitCollections)
 Finalise data containers for an event (called by ISimulationSvc)
virtual StatusCode releaseEventST ()
 Finalise data containers for an event (called by ISimulationSvc)
 BaseSimulatorTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard BaseSimulatorTool constructor.
virtual StatusCode sysInitialize () override
 Gaudi sysInitialize() methods.
const ChronoEntity * chronoStart (const IChronoSvc::ChronoTag &tag)
 wrapper call to start chrono with given tag
const ChronoEntity * chronoStop (const IChronoSvc::ChronoTag &tag)
 wrapper call to stop chrono with given tag

Protected Attributes

ServiceHandle< IChronoStatSvc > m_chrono {this, "ChronoStatService", "ChronoStatSvc"}
 The timing service for general usage.

Private Member Functions

void commandLog (int returnCode, const std::string &commandString) const
 This command prints a message about a G4Command depending on its returnCode.
HepMC::GenEvent * genEvent (McEventCollection *mcEventCollection) const

Configurable Properties

using passbackAction_t = G4UA::iGeant4::TrackProcessorUserActionBase
using passbackActionMap_t
Gaudi::Property< bool > m_doTiming {this, "PrintTimingInfo", true, ""}
float m_accumulatedEventTime {0.}
float m_accumulatedEventTimeSq {0.}
unsigned int m_nrOfEntries {0}
G4Timer * m_runTimer {nullptr}
G4Timer * m_eventTimer {nullptr}
passbackActionMap_t m_secondaryActions ATLAS_THREAD_SAFE
Gaudi::Property< std::string > m_mcEventCollectionName
Gaudi::Property< std::string > m_libList {this, "Dll", "", ""}
Gaudi::Property< std::string > m_physList {this, "Physics", "", ""}
Gaudi::Property< std::string > m_fieldMap {this, "FieldMap", "", ""}
Gaudi::Property< bool > m_releaseGeoModel {this, "ReleaseGeoModel", true, ""}
Gaudi::Property< bool > m_recordFlux {this, "RecordFlux", false, ""}
Gaudi::Property< bool > m_quietMode {this, "QuietMode", false, ""}
Gaudi::Property< std::vector< std::string > > m_g4commands
 Commands to send to the G4 UI.
Gaudi::Property< bool > m_useMT
 Activate multi-threading configuration.
Gaudi::Property< bool > m_activateParallelGeometries
ServiceHandle< IAthRNGSvcm_rndmGenSvc
Gaudi::Property< std::string > m_randomStreamName
 Random Stream Name.
ServiceHandle< IUserLimitsSvcm_userLimitsSvc
ServiceHandle< G4UA::IUserActionSvcm_userActionSvc
 user action service
PublicToolHandle< IDetectorConstructionToolm_detConstruction {this, "DetectorConstruction", "", "Tool handle of the DetectorConstruction"}
ServiceHandle< ISF::IInputConverterm_inputConverter
 Service to convert ISF_Particles into a G4Event.
ServiceHandle< IPhysicsListSvcm_physListSvc
 Physics List Service.
PublicToolHandle< ISensitiveDetectorMasterToolm_senDetTool
 Sensitive Detector Master Tool.
PublicToolHandle< IFastSimulationMasterToolm_fastSimTool
 Fast Simulation Master Tool.
PublicToolHandleArray< IPhysicsInitializationToolm_physicsInitializationTools {this, "PhysicsInitializationTools", {}, "Physics initialization happening after Geant4 initialization"}

Detailed Description

Geant4 AlgTool to create a ISFParticle at a volume entry/exit.

  • universal transport tool
Author
Robert Harrington

Definition at line 67 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

Member Typedef Documentation

◆ passbackAction_t

◆ passbackActionMap_t

Initial value:
tbb::concurrent_unordered_map<std::thread::id,
std::vector<passbackAction_t*>,
std::hash<std::thread::id> >

Definition at line 139 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

Constructor & Destructor Documentation

◆ G4TransportTool()

iGeant4::G4TransportTool::G4TransportTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor.

Definition at line 59 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

62 : ISF::BaseSimulatorG4Tool(type, name, parent)
63{
64 //declareProperty("KillAllNeutrinos", m_KillAllNeutrinos=true);
65 //declareProperty("KillLowEPhotons", m_KillLowEPhotons=-1.);
66}

◆ ~G4TransportTool()

virtual iGeant4::G4TransportTool::~G4TransportTool ( )
virtualdefault

Destructor.

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

void initializeOnce iGeant4::G4TransportTool::ATLAS_NOT_THREAD_SAFE ( )

G4 initialization called only by the first tool instance.

This is done (for now) because we get multiple tool instances in hive.

◆ BaseSimulatorTool()

ISF::BaseSimulatorTool::BaseSimulatorTool ( const std::string & type,
const std::string & name,
const IInterface * parent )
inlineinherited

Standard BaseSimulatorTool constructor.

Definition at line 40 of file BaseSimulatorTool.h.

41 : base_class(type, name, parent)
42 {
43 }

◆ chronoStart()

const ChronoEntity * ISF::BaseSimulatorTool::chronoStart ( const IChronoSvc::ChronoTag & tag)
inlineinherited

wrapper call to start chrono with given tag

Definition at line 98 of file BaseSimulatorTool.h.

98 {
99 if (m_chrono) return m_chrono->chronoStart( tag);
100 return nullptr;
101 }
ServiceHandle< IChronoStatSvc > m_chrono
The timing service for general usage.

◆ chronoStop()

const ChronoEntity * ISF::BaseSimulatorTool::chronoStop ( const IChronoSvc::ChronoTag & tag)
inlineinherited

wrapper call to stop chrono with given tag

Definition at line 104 of file BaseSimulatorTool.h.

104 {
105 if (m_chrono) return m_chrono->chronoStop( tag);
106 return nullptr;
107 }

◆ commandLog()

void iGeant4::G4TransportTool::commandLog ( int returnCode,
const std::string & commandString ) const
private

This command prints a message about a G4Command depending on its returnCode.

Definition at line 477 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

478{
479 switch(returnCode) {
480 case 0: { ATH_MSG_DEBUG("G4 Command: " << commandString << " - Command Succeeded"); } break;
481 case 100: { ATH_MSG_ERROR("G4 Command: " << commandString << " - Command Not Found!"); } break;
482 case 200: {
483 auto* stateManager = G4StateManager::GetStateManager();
484 ATH_MSG_DEBUG("G4 Command: " << commandString << " - Illegal Application State (" <<
485 stateManager->GetStateString(stateManager->GetCurrentState()) << ")!");
486 } break;
487 case 300: { ATH_MSG_ERROR("G4 Command: " << commandString << " - Parameter Out of Range!"); } break;
488 case 400: { ATH_MSG_ERROR("G4 Command: " << commandString << " - Parameter Unreadable!"); } break;
489 case 500: { ATH_MSG_ERROR("G4 Command: " << commandString << " - Parameter Out of Candidates!"); } break;
490 case 600: { ATH_MSG_ERROR("G4 Command: " << commandString << " - Alias Not Found!"); } break;
491 default: { ATH_MSG_ERROR("G4 Command: " << commandString << " - Unknown Status!"); } break;
492 }
493
494}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)

◆ finalize()

StatusCode iGeant4::G4TransportTool::finalize ( )
finaloverridevirtual

AlgTool finalize method.

Definition at line 222 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

223{
224 ATH_MSG_VERBOSE("++++++++++++ ISF G4 G4TransportTool finalized ++++++++++++");
225
226 // One time finalization
227 try {
229 }
230 catch(const std::exception& e) {
231 ATH_MSG_ERROR("Failure in iGeant4::G4TransportTool::finalizeOnce: " << e.what());
232 return StatusCode::FAILURE;
233 }
234
235 if (m_doTiming) {
236 m_runTimer->Stop();
237 const float numEntriesFloat(m_nrOfEntries);
238 const float runTime=m_runTimer->GetUserElapsed()+m_runTimer->GetSystemElapsed();
239 const float avgTimePerEvent=(m_nrOfEntries>1) ? m_accumulatedEventTime/(numEntriesFloat-1.f) : runTime;
240 const float avgTimeSqPerEvent=(m_nrOfEntries>1) ? m_accumulatedEventTimeSq/(numEntriesFloat-1.f) : runTime*runTime;
241 const float sigma=(m_nrOfEntries>2) ? std::sqrt(std::abs(avgTimeSqPerEvent - avgTimePerEvent*avgTimePerEvent)/(numEntriesFloat-2.f)) : 0;
242 ATH_MSG_INFO("*****************************************"<<endmsg<<
243 "** **"<<endmsg<<
244 " End of run - time spent is "<<std::setprecision(4) <<
245 runTime<<endmsg<<
246 " Average time per event was "<<std::setprecision(4) <<
247 avgTimePerEvent <<" +- "<< std::setprecision(4) << sigma<<endmsg<<
248 "** **"<<endmsg<<
249 "*****************************************");
250 }
251
252 return StatusCode::SUCCESS;
253}
#define endmsg
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
static std::once_flag finalizeOnceFlag
void finalizeOnce()
G4 finalization called only by the first tool instance.

◆ finalizeOnce()

void iGeant4::G4TransportTool::finalizeOnce ( )

G4 finalization called only by the first tool instance.

This is done (for now) because we get multiple tool instances in hive.

Definition at line 256 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

257{
258 ATH_MSG_DEBUG("\t terminating the current G4 run");
259 auto runMgr = G4RunManager::GetRunManager();
260 runMgr->RunTermination();
261 return;
262}

◆ genEvent()

HepMC::GenEvent * iGeant4::G4TransportTool::genEvent ( McEventCollection * mcEventCollection) const
private

Definition at line 455 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

456{
457
458 if(!mcEventCollection) {
459 // retrieve McEventCollection from storegate
461 if (evtStore()->retrieve( mcEventCollection, m_mcEventCollectionName).isFailure()) {
462 ATH_MSG_ERROR( "Unable to retrieve McEventCollection with name=" << m_mcEventCollectionName
463 << ".");
464 return nullptr;
465 }
466 else {
467 ATH_MSG_WARNING( "Fallback. Sucessfully retrieved McEventCollection with name=" << m_mcEventCollectionName);
468 }
469 }
470 else { return nullptr; }
471 }
472 // collect last GenEvent from McEventCollection
473 return mcEventCollection->back();
474}
#define ATH_MSG_WARNING(x)
const T * back() const
Access the last element in the collection as an rvalue.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ initialize()

StatusCode iGeant4::G4TransportTool::initialize ( )
finaloverridevirtual

AlgTool initialize method.

Reimplemented from ISF::BaseSimulatorTool.

Definition at line 69 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

70{
71 ATH_MSG_VERBOSE("initialize");
72
74
75 // create G4Timers if enabled
76 if (m_doTiming) {
77 m_runTimer = new G4Timer();
78 m_eventTimer = new G4Timer();
79 m_runTimer->Start();
80 }
81
82 // Create the scoring manager if requested
83 if (m_recordFlux) G4ScoringManager::GetScoringManager();
84
85 // One-time initialization
86 try {
87 std::call_once(initializeOnceFlag, &iGeant4::G4TransportTool::initializeOnce, this);
88 }
89 catch(const std::exception& e) {
90 ATH_MSG_ERROR("Failure in iGeant4::G4TransportTool::initializeOnce: " << e.what());
91 return StatusCode::FAILURE;
92 }
93
94 ATH_CHECK( m_rndmGenSvc.retrieve() );
95 ATH_CHECK( m_userActionSvc.retrieve() );
96
97 ATH_CHECK(m_senDetTool.retrieve());
98 ATH_CHECK(m_fastSimTool.retrieve());
99
100 ATH_CHECK(m_inputConverter.retrieve());
101
102 return StatusCode::SUCCESS;
103}
#define ATH_CHECK
Evaluate an expression and check for errors.
static std::once_flag initializeOnceFlag
virtual StatusCode initialize() override
PublicToolHandle< ISensitiveDetectorMasterTool > m_senDetTool
Sensitive Detector Master Tool.
PublicToolHandle< IFastSimulationMasterTool > m_fastSimTool
Fast Simulation Master Tool.
ServiceHandle< ISF::IInputConverter > m_inputConverter
Service to convert ISF_Particles into a G4Event.
ServiceHandle< G4UA::IUserActionSvc > m_userActionSvc
user action service

◆ releaseEvent() [1/2]

virtual StatusCode ISF::BaseSimulatorG4Tool::releaseEvent ( const EventContext & )
inlinevirtual

Finalise data containers for an event.

Reimplemented from ISF::BaseSimulatorG4Tool.

Definition at line 87 of file BaseSimulatorG4Tool.h.

87 {
88 return StatusCode::FAILURE;
89 };

◆ releaseEvent() [2/2]

StatusCode iGeant4::G4TransportTool::releaseEvent ( const EventContext & ,
HitCollectionMap &  )
overridevirtual

Finalise data containers for an event.

Todo
: strip hits of the tracks ...

Implements ISF::BaseSimulatorG4Tool.

Definition at line 408 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

409 {
410 ATH_MSG_DEBUG ( "release Event" );
412
413 /* todo: ELLI: the following is copied in from the PyG4AtlasAlg:
414 -> this somehow needs to be moved into C++
415 and put into releaseEvent() ( or setupEvent() ?)
416
417 from ISF_Geant4Example import AtlasG4Eng
418 from ISF_Geant4Example.ISF_SimFlags import simFlags
419 if self.doFirstEventG4SeedsCheck :
420 if simFlags.SeedsG4.statusOn:
421 rnd = AtlasG4Eng.G4Eng.menu_G4RandomNrMenu()
422 rnd.set_Seed(simFlags.SeedsG4.get_Value())
423 self.doFirstEventG4SeedsCheck = False
424 if self.RndG4Menu.SaveStatus:
425 self.RndG4Menu.Menu.saveStatus('G4Seeds.txt')
426 */
427
428 // print per-event timing info if enabled
429 if (m_doTiming) {
430 m_eventTimer->Stop();
431
432 const double eventTime=m_eventTimer->GetUserElapsed()+m_eventTimer->GetSystemElapsed();
433 if (m_nrOfEntries>1) {
434 m_accumulatedEventTime +=eventTime;
435 m_accumulatedEventTimeSq+=eventTime*eventTime;
436 }
437
438 const float numEntriesFloat(m_nrOfEntries);
439 const float avgTimePerEvent=(m_nrOfEntries>1) ? m_accumulatedEventTime/(numEntriesFloat-1.f) : eventTime;
440 const float avgTimeSqPerEvent=(m_nrOfEntries>1) ? m_accumulatedEventTimeSq/(numEntriesFloat-1.f) : eventTime*eventTime;
441 const float sigma=(m_nrOfEntries>2) ? std::sqrt(std::abs(avgTimeSqPerEvent - avgTimePerEvent*avgTimePerEvent)/(numEntriesFloat-2.f)) : 0;
442 ATH_MSG_INFO("\t Run:Event "<<ctx.eventID().run_number()<<":"<<ctx.eventID().event_number() << "\t ("<<m_nrOfEntries<<"th event for this worker) took " << std::setprecision(4) <<
443 eventTime << " s. New average " << std::setprecision(4) <<
444 avgTimePerEvent<<" +- "<<std::setprecision(4) << sigma);
445 }
446
447 ATH_CHECK(m_senDetTool->EndOfAthenaEvent(hitCollections));
448 ATH_CHECK(m_userActionSvc->EndOfAthenaEvent(hitCollections));
449 ATH_CHECK(m_fastSimTool->EndOfAthenaEvent());
450
451 return StatusCode::SUCCESS;
452}

◆ releaseEventST() [1/2]

virtual StatusCode ISF::BaseSimulatorG4Tool::releaseEventST ( )
inlinevirtualinherited

Finalise data containers for an event (called by ISimulationSvc)

Reimplemented from ISF::BaseSimulatorTool.

Definition at line 92 of file BaseSimulatorG4Tool.h.

92{ return StatusCode::FAILURE; };

◆ releaseEventST() [2/2]

virtual StatusCode ISF::BaseSimulatorG4Tool::releaseEventST ( HitCollectionMap & hitCollections)
inlinevirtualinherited

Finalise data containers for an event (called by ISimulationSvc)

Definition at line 58 of file BaseSimulatorG4Tool.h.

58 {
59 return releaseEvent(Gaudi::Hive::currentContext(), hitCollections);
60 }
virtual StatusCode releaseEvent(const EventContext &, HitCollectionMap &)=0
Finalise data containers for an event.

◆ setupEvent() [1/2]

virtual StatusCode ISF::BaseSimulatorG4Tool::setupEvent ( const EventContext & )
inlinevirtual

Create data containers for an event.

Reimplemented from ISF::BaseSimulatorG4Tool.

Definition at line 79 of file BaseSimulatorG4Tool.h.

79 {
80 return StatusCode::FAILURE;
81 };

◆ setupEvent() [2/2]

StatusCode iGeant4::G4TransportTool::setupEvent ( const EventContext & ,
HitCollectionMap &  )
overridevirtual

Create data containers for an event.

Implements ISF::BaseSimulatorG4Tool.

Definition at line 385 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

386 {
387 ATH_MSG_DEBUG ( "setup Event" );
388
389 // Set the RNG to use for this event. We need to reset it for MT jobs
390 // because of the mismatch between Gaudi slot-local and G4 thread-local RNG.
391 ATHRNG::RNGWrapper* rngWrapper = m_rndmGenSvc->getEngine(this, m_randomStreamName);
392 rngWrapper->setSeed( m_randomStreamName, ctx );
393 G4Random::setTheEngine(rngWrapper->getEngine(ctx));
394
395 ATH_CHECK(m_senDetTool->BeginOfAthenaEvent(hitCollections));
396 ATH_CHECK(m_userActionSvc->BeginOfAthenaEvent(hitCollections));
397
399 if (m_doTiming) m_eventTimer->Start();
400
401 // make sure SD collections are properly initialized in every Athena event
402 G4SDManager::GetSDMpointer()->PrepareNewEvent();
403
404 return StatusCode::SUCCESS;
405}
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
Gaudi::Property< std::string > m_randomStreamName
Random Stream Name.

◆ setupEventST() [1/2]

virtual StatusCode ISF::BaseSimulatorG4Tool::setupEventST ( )
inlinevirtualinherited

Create data containers for an event (called by ISimulationSvc)

Reimplemented from ISF::BaseSimulatorTool.

Definition at line 84 of file BaseSimulatorG4Tool.h.

84{ return StatusCode::FAILURE; };

◆ setupEventST() [2/2]

virtual StatusCode ISF::BaseSimulatorG4Tool::setupEventST ( HitCollectionMap & hitCollections)
inlinevirtualinherited

Create data containers for an event (called by ISimulationSvc)

Definition at line 49 of file BaseSimulatorG4Tool.h.

49 {
50 return setupEvent(Gaudi::Hive::currentContext(), hitCollections);
51 }
virtual StatusCode setupEvent(const EventContext &, HitCollectionMap &)=0
Create data containers for an event.

◆ simFlavor()

virtual ISF::SimulationFlavor iGeant4::G4TransportTool::simFlavor ( ) const
inlineoverridevirtual

Definition at line 112 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

112 {
113 return ISF::Geant4;
114 };

◆ simulate() [1/3]

virtual StatusCode ISF::BaseSimulatorG4Tool::simulate ( const EventContext & ,
ISFParticle & ,
ISFParticleContainer & ,
McEventCollection *  )
inline

Simulation call for individual particles.

Definition at line 65 of file BaseSimulatorG4Tool.h.

66 {
67 return StatusCode::FAILURE;
68 };

◆ simulate() [2/3]

StatusCode iGeant4::G4TransportTool::simulate ( const EventContext & ctx,
ISF::ISFParticle & isp,
ISF::ISFParticleContainer & secondaries,
McEventCollection * mcEventCollection,
std::shared_ptr< HitCollectionMap >  )
overridevirtual

Simulation call for individual particles.

Process ParticleState from particle stack

Implements ISF::BaseSimulatorG4Tool.

Definition at line 265 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

268 {
269
270 // give a screen output that you entered Geant4SimSvc
271 ATH_MSG_VERBOSE( "Particle " << isp << " received for simulation." );
272
274 // wrap the given ISFParticle into a STL vector of ISFParticles with length 1
275 // (minimizing code duplication)
276 const ISF::ISFParticleVector ispVector(1, &isp);
277 StatusCode success = this->simulateVector(ctx, ispVector, secondaries,
278 mcEventCollection, hitCollections);
279 ATH_MSG_VERBOSE( "Simulation done" );
280
281 // Geant4 call done
282 return success;
283}
virtual StatusCode simulateVector(const EventContext &ctx, const ISF::ISFParticleVector &particles, ISF::ISFParticleContainer &secondaries, McEventCollection *mcEventCollection, std::shared_ptr< HitCollectionMap > hitCollections, McEventCollection *shadowTruth=nullptr) override
Simulation call for vectors of particles.
::StatusCode StatusCode
StatusCode definition for legacy code.
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.

◆ simulate() [3/3]

virtual StatusCode ISF::BaseSimulatorG4Tool::simulate ( const EventContext & ,
ISFParticle & ,
ISFParticleContainer & ,
McEventCollection *  )
inlinevirtualinherited

Simulation call for individual particles.

Reimplemented from ISF::BaseSimulatorTool.

Definition at line 65 of file BaseSimulatorG4Tool.h.

66 {
67 return StatusCode::FAILURE;
68 };

◆ simulateVector() [1/3]

virtual StatusCode ISF::BaseSimulatorG4Tool::simulateVector ( const EventContext & ,
const ISFParticleVector & ,
ISFParticleContainer & ,
McEventCollection * ,
McEventCollection *  )
inline

Simulation call for vectors of particles.

Definition at line 71 of file BaseSimulatorG4Tool.h.

74 {
75 return StatusCode::FAILURE;
76 };

◆ simulateVector() [2/3]

StatusCode iGeant4::G4TransportTool::simulateVector ( const EventContext & ctx,
const ISF::ISFParticleVector & particles,
ISF::ISFParticleContainer & secondaries,
McEventCollection * mcEventCollection,
std::shared_ptr< HitCollectionMap > HitCollectionMap,
McEventCollection * shadowTruth = nullptr )
overridevirtual

Simulation call for vectors of particles.

Process ParticleState from particle stack

Implements ISF::BaseSimulatorG4Tool.

Definition at line 286 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

290 {
291
292 ATH_MSG_DEBUG (name() << ".simulateVector(...) : Received a vector of " << particles.size() << " particles for simulation.");
294
295 bool abort = [&] ATLAS_NOT_THREAD_SAFE {
296 auto eventInfo = std::make_unique<AtlasG4EventUserInfo>(ctx);
297 eventInfo->SetHitCollectionMap(hitCollections);
298
299 auto inputEvent = std::make_unique<G4Event>(ctx.eventID().event_number());
300 inputEvent->SetUserInformation(eventInfo.release());
301
302 HepMC::GenEvent* shadowGenEvent =
303 (shadowTruth && !shadowTruth->empty())
304 ? static_cast<HepMC::GenEvent*>(shadowTruth->back())
305 : nullptr;
306 m_inputConverter->ISF_to_G4Event(
307 *inputEvent, particles, genEvent(mcEventCollection), shadowGenEvent);
308
309 ATH_MSG_DEBUG("Calling ISF_Geant4 ProcessEvent");
310 // Worker run manager
311 // Custom class has custom method call: ProcessEvent.
312 // So, grab custom singleton class directly, rather than base.
313 // Maybe that should be changed! Then we can use a base pointer.
314 if (m_useMT) {
315# ifdef G4MULTITHREADED
316 auto* workerRM = G4AtlasWorkerRunManager::GetG4AtlasWorkerRunManager();
317 return workerRM->ProcessEvent(inputEvent.release());
318# else
319 ATH_MSG_ERROR("Trying to use multi-threading in non-MT build!");
320 return true;
321# endif
322 } else {
323 auto* workerRM ATLAS_THREAD_SAFE =
324 G4AtlasRunManager::GetG4AtlasRunManager(); // non-MT case
325 return workerRM->ProcessEvent(inputEvent.release());
326 }
327 }();
328
329 if (abort) {
330 ATH_MSG_WARNING("Event was aborted !! ");
331 // ATH_MSG_WARNING("Simulation will now go on to the next event ");
332 // ATH_MSG_WARNING("setFilterPassed is now False");
333 // setFilterPassed(false);
334 return StatusCode::FAILURE;
335 }
336
337 // Get user actions that return secondaries
338 auto actionsFound = m_secondaryActions.find( std::this_thread::get_id() );
339 if ( actionsFound == m_secondaryActions.end() ) {
340 // Get all UAs
341 std::vector< G4UserSteppingAction* > allActions;
342 StatusCode sc = m_userActionSvc->getSecondaryActions( allActions );
343 if ( !sc.isSuccess() ) {
344 ATH_MSG_ERROR( "Failed to retrieve secondaries from UASvc" );
345 return sc;
346 }
347
348 // Find the UAs that can return secondaries
349 for ( G4UserSteppingAction* action : allActions ) {
350 passbackAction_t* castAction = dynamic_cast< passbackAction_t* >( action );
351 if ( castAction ) {
352 m_secondaryActions[ std::this_thread::get_id() ].push_back( castAction );
353 }
354 }
355
356 actionsFound = m_secondaryActions.find( std::this_thread::get_id() );
357 }
358
359 // Retrieve secondaries from user actions
360 for ( auto* action : actionsFound->second ) {
361 for ( auto& parent : particles ) {
362
363 ISF::ISFParticleContainer someSecondaries = action->ReturnSecondaries( parent );
364
365 secondaries.splice( begin(secondaries), std::move(someSecondaries) );
366 }
367 }
368
369 // const DataHandle <TrackRecordCollection> tracks;
370
371 // StatusCode sc = evtStore()->retrieve(tracks,m_trackCollName);
372
373 // if (sc.isFailure()) {
374 // ATH_MSG_WARNING(" Cannot retrieve TrackRecordCollection " << m_trackCollName);
375 // }
376
377 // not implemented yet... need to get particle stack from Geant4 and convert to ISFParticle
378 ATH_MSG_VERBOSE( "Simulation done" );
379
380 // Geant4 call done
381 return StatusCode::SUCCESS;
382}
static Double_t sc
bool empty() const noexcept
Returns true if the collection is empty.
void initializeOnce ATLAS_NOT_THREAD_SAFE()
G4 initialization called only by the first tool instance.
G4UA::iGeant4::TrackProcessorUserActionBase passbackAction_t
Gaudi::Property< bool > m_useMT
Activate multi-threading configuration.
HepMC::GenEvent * genEvent(McEventCollection *mcEventCollection) const
passbackActionMap_t m_secondaryActions ATLAS_THREAD_SAFE
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)

◆ simulateVector() [3/3]

virtual StatusCode ISF::BaseSimulatorG4Tool::simulateVector ( const EventContext & ,
const ISFParticleVector & ,
ISFParticleContainer & ,
McEventCollection * ,
McEventCollection *  )
inlinevirtualinherited

Simulation call for vectors of particles.

Reimplemented from ISF::BaseSimulatorTool.

Definition at line 71 of file BaseSimulatorG4Tool.h.

74 {
75 return StatusCode::FAILURE;
76 };

◆ sysInitialize()

virtual StatusCode ISF::BaseSimulatorTool::sysInitialize ( )
inlineoverridevirtualinherited

Gaudi sysInitialize() methods.

Definition at line 49 of file BaseSimulatorTool.h.

50 {
52 ATH_CHECK( m_chrono.retrieve() );
53 return StatusCode::SUCCESS;
54 }
virtual StatusCode sysInitialize() override

Member Data Documentation

◆ ATLAS_THREAD_SAFE

passbackActionMap_t m_secondaryActions iGeant4::G4TransportTool::ATLAS_THREAD_SAFE
mutableprivate

◆ m_accumulatedEventTime

float iGeant4::G4TransportTool::m_accumulatedEventTime {0.}
private

Definition at line 129 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

129{0.};

◆ m_accumulatedEventTimeSq

float iGeant4::G4TransportTool::m_accumulatedEventTimeSq {0.}
private

Definition at line 130 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

130{0.};

◆ m_activateParallelGeometries

Gaudi::Property<bool> iGeant4::G4TransportTool::m_activateParallelGeometries
private
Initial value:
{
this, "ActivateParallelWorlds", false,
"Toggle on/off the G4 parallel geometry system"}

Definition at line 160 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

160 {
161 this, "ActivateParallelWorlds", false,
162 "Toggle on/off the G4 parallel geometry system"};

◆ m_chrono

ServiceHandle<IChronoStatSvc> ISF::BaseSimulatorTool::m_chrono {this, "ChronoStatService", "ChronoStatSvc"}
protectedinherited

The timing service for general usage.

Definition at line 115 of file BaseSimulatorTool.h.

115{this, "ChronoStatService", "ChronoStatSvc"};

◆ m_detConstruction

PublicToolHandle<IDetectorConstructionTool> iGeant4::G4TransportTool::m_detConstruction {this, "DetectorConstruction", "", "Tool handle of the DetectorConstruction"}
private

Definition at line 175 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

175{this, "DetectorConstruction", "", "Tool handle of the DetectorConstruction"};

◆ m_doTiming

Gaudi::Property<bool> iGeant4::G4TransportTool::m_doTiming {this, "PrintTimingInfo", true, ""}
private

Definition at line 127 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

127{this, "PrintTimingInfo", true, ""};

◆ m_eventTimer

G4Timer* iGeant4::G4TransportTool::m_eventTimer {nullptr}
private

Definition at line 134 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

134{nullptr};

◆ m_fastSimTool

PublicToolHandle<IFastSimulationMasterTool> iGeant4::G4TransportTool::m_fastSimTool
private
Initial value:
{
this, "FastSimMasterTool", "FastSimulationMasterTool", ""}

Fast Simulation Master Tool.

Definition at line 186 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

186 {
187 this, "FastSimMasterTool", "FastSimulationMasterTool", ""};

◆ m_fieldMap

Gaudi::Property<std::string> iGeant4::G4TransportTool::m_fieldMap {this, "FieldMap", "", ""}
private

Definition at line 150 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

150{this, "FieldMap", "", ""};

◆ m_g4commands

Gaudi::Property<std::vector<std::string> > iGeant4::G4TransportTool::m_g4commands
private
Initial value:
{
this, "G4Commands", {}, "Commands to send to the G4UI"}

Commands to send to the G4 UI.

Definition at line 155 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

155 {
156 this, "G4Commands", {}, "Commands to send to the G4UI"};

◆ m_inputConverter

ServiceHandle<ISF::IInputConverter> iGeant4::G4TransportTool::m_inputConverter
private
Initial value:
{
this, "InputConverter", "ISF_InputConverter", ""}

Service to convert ISF_Particles into a G4Event.

Definition at line 177 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

177 {
178 this, "InputConverter", "ISF_InputConverter", ""};

◆ m_libList

Gaudi::Property<std::string> iGeant4::G4TransportTool::m_libList {this, "Dll", "", ""}
private

Definition at line 148 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

148{this, "Dll", "", ""};

◆ m_mcEventCollectionName

Gaudi::Property<std::string> iGeant4::G4TransportTool::m_mcEventCollectionName
private
Initial value:
{
this, "McEventCollection", "TruthEvent", ""}

Definition at line 145 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

145 {
146 this, "McEventCollection", "TruthEvent", ""};

◆ m_nrOfEntries

unsigned int iGeant4::G4TransportTool::m_nrOfEntries {0}
private

Definition at line 131 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

131{0};

◆ m_physicsInitializationTools

PublicToolHandleArray<IPhysicsInitializationTool> iGeant4::G4TransportTool::m_physicsInitializationTools {this, "PhysicsInitializationTools", {}, "Physics initialization happening after Geant4 initialization"}
private

Definition at line 188 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

188{this, "PhysicsInitializationTools", {}, "Physics initialization happening after Geant4 initialization"};

◆ m_physList

Gaudi::Property<std::string> iGeant4::G4TransportTool::m_physList {this, "Physics", "", ""}
private

Definition at line 149 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

149{this, "Physics", "", ""};

◆ m_physListSvc

ServiceHandle<IPhysicsListSvc> iGeant4::G4TransportTool::m_physListSvc
private
Initial value:
{this, "PhysicsListSvc",
"PhysicsListSvc", ""}

Physics List Service.

Definition at line 180 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

180 {this, "PhysicsListSvc",
181 "PhysicsListSvc", ""};

◆ m_quietMode

Gaudi::Property<bool> iGeant4::G4TransportTool::m_quietMode {this, "QuietMode", false, ""}
private

Definition at line 153 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

153{this, "QuietMode", false, ""};

◆ m_randomStreamName

Gaudi::Property<std::string> iGeant4::G4TransportTool::m_randomStreamName
private
Initial value:
{this, "RandomStreamName",
"Geant4", ""}

Random Stream Name.

Definition at line 167 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

167 {this, "RandomStreamName",
168 "Geant4", ""};

◆ m_recordFlux

Gaudi::Property<bool> iGeant4::G4TransportTool::m_recordFlux {this, "RecordFlux", false, ""}
private

Definition at line 152 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

152{this, "RecordFlux", false, ""};

◆ m_releaseGeoModel

Gaudi::Property<bool> iGeant4::G4TransportTool::m_releaseGeoModel {this, "ReleaseGeoModel", true, ""}
private

Definition at line 151 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

151{this, "ReleaseGeoModel", true, ""};

◆ m_rndmGenSvc

ServiceHandle<IAthRNGSvc> iGeant4::G4TransportTool::m_rndmGenSvc
private
Initial value:
{this, "RandomNumberService",
"AthRNGSvc", ""}

Definition at line 164 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

164 {this, "RandomNumberService",
165 "AthRNGSvc", ""};

◆ m_runTimer

G4Timer* iGeant4::G4TransportTool::m_runTimer {nullptr}
private

Definition at line 133 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

133{nullptr};

◆ m_senDetTool

PublicToolHandle<ISensitiveDetectorMasterTool> iGeant4::G4TransportTool::m_senDetTool
private
Initial value:
{
this, "SenDetMasterTool", "SensitiveDetectorMasterTool", ""}

Sensitive Detector Master Tool.

Definition at line 183 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

183 {
184 this, "SenDetMasterTool", "SensitiveDetectorMasterTool", ""};

◆ m_useMT

Gaudi::Property<bool> iGeant4::G4TransportTool::m_useMT
private
Initial value:
{this, "MultiThreading", false,
"Multi-threading specific settings"}

Activate multi-threading configuration.

Definition at line 158 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

158 {this, "MultiThreading", false,
159 "Multi-threading specific settings"};

◆ m_userActionSvc

ServiceHandle<G4UA::IUserActionSvc> iGeant4::G4TransportTool::m_userActionSvc
private
Initial value:
{this, "UserActionSvc", "",
""}

user action service

Definition at line 173 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

173 {this, "UserActionSvc", "",
174 ""};

◆ m_userLimitsSvc

ServiceHandle<IUserLimitsSvc> iGeant4::G4TransportTool::m_userLimitsSvc
private
Initial value:
{this, "UserLimitsSvc",
"UserLimitsSvc", ""}

Definition at line 170 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h.

170 {this, "UserLimitsSvc",
171 "UserLimitsSvc", ""};

The documentation for this class was generated from the following files: