ATLAS Offline Software
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
iGeant4::G4TransportTool Class Reference

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

Protected Attributes

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

Private Member Functions

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

Configurable Properties

using passbackAction_t = G4UA::iGeant4::TrackProcessorUserActionBase
 
using passbackActionMap_t = tbb::concurrent_unordered_map< std::thread::id, std::vector< passbackAction_t * >, std::hash< std::thread::id > >
 
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. More...
 
Gaudi::Property< bool > m_useMT
 Activate multi-threading configuration. More...
 
Gaudi::Property< bool > m_activateParallelGeometries
 
ServiceHandle< IAthRNGSvcm_rndmGenSvc
 
Gaudi::Property< std::string > m_randomStreamName
 Random Stream Name. More...
 
ServiceHandle< IUserLimitsSvcm_userLimitsSvc
 
ServiceHandle< G4UA::IUserActionSvcm_userActionSvc
 user action service More...
 
PublicToolHandle< IDetectorConstructionToolm_detConstruction {this, "DetectorConstruction", "", "Tool handle of the DetectorConstruction"}
 
ServiceHandle< ISF::IInputConverterm_inputConverter
 Service to convert ISF_Particles into a G4Event. More...
 
ServiceHandle< IPhysicsListSvcm_physListSvc
 Physics List Service. More...
 
PublicToolHandle< ISensitiveDetectorMasterToolm_senDetTool
 Sensitive Detector Master Tool. More...
 
PublicToolHandle< IFastSimulationMasterToolm_fastSimTool
 Fast Simulation Master Tool. More...
 
PublicToolHandleArray< IPhysicsInitializationToolm_physicsInitializationTools {this, "PhysicsInitializationTools", {}, "Physics initialization happening after Geant4 initialization"}
 

Detailed Description

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

Author
Robert Harrington

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

Member Typedef Documentation

◆ passbackAction_t

◆ passbackActionMap_t

using iGeant4::G4TransportTool::passbackActionMap_t = tbb::concurrent_unordered_map<std::thread::id, std::vector<passbackAction_t*>, std::hash<std::thread::id> >
private

Constructor & Destructor Documentation

◆ G4TransportTool()

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

Constructor.

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

64 {
65  //declareProperty("KillAllNeutrinos", m_KillAllNeutrinos=true);
66  //declareProperty("KillLowEPhotons", m_KillLowEPhotons=-1.);
67 }

◆ ~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
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  }

◆ 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 478 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

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

◆ finalize()

StatusCode iGeant4::G4TransportTool::finalize ( )
finaloverridevirtual

AlgTool finalize method.

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

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

◆ 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 259 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

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

◆ genEvent()

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

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

457 {
458 
459  if(!mcEventCollection) {
460  // retrieve McEventCollection from storegate
461  if (evtStore()->contains<McEventCollection>(m_mcEventCollectionName)) {
462  if (evtStore()->retrieve( mcEventCollection, m_mcEventCollectionName).isFailure()) {
463  ATH_MSG_ERROR( "Unable to retrieve McEventCollection with name=" << m_mcEventCollectionName
464  << ".");
465  return nullptr;
466  }
467  else {
468  ATH_MSG_WARNING( "Fallback. Sucessfully retrieved McEventCollection with name=" << m_mcEventCollectionName);
469  }
470  }
471  else { return nullptr; }
472  }
473  // collect last GenEvent from McEventCollection
474  return mcEventCollection->back();
475 }

◆ initialize()

StatusCode iGeant4::G4TransportTool::initialize ( )
finaloverridevirtual

AlgTool initialize method.

Reimplemented from ISF::BaseSimulatorTool.

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

71 {
72  ATH_MSG_VERBOSE("initialize");
73 
75 
76  // create G4Timers if enabled
77  if (m_doTiming) {
78  m_runTimer = new G4Timer();
79  m_eventTimer = new G4Timer();
80  m_runTimer->Start();
81  }
82 
83  // Create the scoring manager if requested
84  if (m_recordFlux) G4ScoringManager::GetScoringManager();
85 
86  // One-time initialization
87  try {
88  std::call_once(initializeOnceFlag, &iGeant4::G4TransportTool::initializeOnce, this);
89  }
90  catch(const std::exception& e) {
91  ATH_MSG_ERROR("Failure in iGeant4::G4TransportTool::initializeOnce: " << e.what());
92  return StatusCode::FAILURE;
93  }
94 
95  ATH_CHECK( m_rndmGenSvc.retrieve() );
96  ATH_CHECK( m_userActionSvc.retrieve() );
97 
98  ATH_CHECK(m_senDetTool.retrieve());
99  ATH_CHECK(m_fastSimTool.retrieve());
100 
101  ATH_CHECK(m_inputConverter.retrieve());
102 
103  return StatusCode::SUCCESS;
104 }

◆ releaseEvent() [1/2]

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

Finalise data containers for an event.

Reimplemented from ISF::BaseSimulatorTool.

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 410 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

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

◆ 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  }

◆ setupEvent() [1/2]

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

Create data containers for an event.

Reimplemented from ISF::BaseSimulatorTool.

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 388 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

389  {
390  ATH_MSG_DEBUG ( "setup Event" );
391 
392  // Set the RNG to use for this event. We need to reset it for MT jobs
393  // because of the mismatch between Gaudi slot-local and G4 thread-local RNG.
394  ATHRNG::RNGWrapper* rngWrapper = m_rndmGenSvc->getEngine(this, m_randomStreamName);
395  rngWrapper->setSeed( m_randomStreamName, ctx );
396  G4Random::setTheEngine(rngWrapper->getEngine(ctx));
397 
398  ATH_CHECK(m_senDetTool->BeginOfAthenaEvent(hitCollections));
399 
400  m_nrOfEntries++;
401  if (m_doTiming) m_eventTimer->Start();
402 
403  // make sure SD collections are properly initialized in every Athena event
404  G4SDManager::GetSDMpointer()->PrepareNewEvent();
405 
406  return StatusCode::SUCCESS;
407 }

◆ 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  }

◆ 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/2]

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  };

◆ simulate() [2/2]

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 268 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

271  {
272 
273  // give a screen output that you entered Geant4SimSvc
274  ATH_MSG_VERBOSE( "Particle " << isp << " received for simulation." );
275 
277  // wrap the given ISFParticle into a STL vector of ISFParticles with length 1
278  // (minimizing code duplication)
279  const ISF::ISFParticleVector ispVector(1, &isp);
280  StatusCode success = this->simulateVector(ctx, ispVector, secondaries,
281  mcEventCollection, hitCollections);
282  ATH_MSG_VERBOSE( "Simulation done" );
283 
284  // Geant4 call done
285  return success;
286 }

◆ simulateVector() [1/2]

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  };

◆ simulateVector() [2/2]

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 289 of file ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx.

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

◆ 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  }

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

◆ m_accumulatedEventTimeSq

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

◆ 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.

◆ 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.

◆ m_detConstruction

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

◆ m_doTiming

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

◆ m_eventTimer

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

◆ 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.

◆ m_fieldMap

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

◆ 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.

◆ 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.

◆ m_libList

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

◆ 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.

◆ m_nrOfEntries

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

◆ m_physicsInitializationTools

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

◆ m_physList

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

◆ 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.

◆ m_quietMode

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

◆ 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.

◆ m_recordFlux

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

◆ m_releaseGeoModel

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

◆ 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.

◆ m_runTimer

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

◆ 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.

◆ 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.

◆ 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.

◆ 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.


The documentation for this class was generated from the following files:
ISF::ISFParticleContainer
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)
Definition: ISFParticleContainer.h:23
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
iGeant4::G4TransportTool::m_nrOfEntries
unsigned int m_nrOfEntries
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:131
iGeant4::G4TransportTool::m_accumulatedEventTimeSq
float m_accumulatedEventTimeSq
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:130
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
ISF::BaseSimulatorG4Tool::releaseEvent
virtual StatusCode releaseEvent(const EventContext &, HitCollectionMap &)=0
Finalise data containers for an event.
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
iGeant4::G4TransportTool::m_senDetTool
PublicToolHandle< ISensitiveDetectorMasterTool > m_senDetTool
Sensitive Detector Master Tool.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:183
iGeant4::G4TransportTool::m_mcEventCollectionName
Gaudi::Property< std::string > m_mcEventCollectionName
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:145
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ISF::BaseSimulatorG4Tool::setupEvent
virtual StatusCode setupEvent(const EventContext &, HitCollectionMap &)=0
Create data containers for an event.
iGeant4::G4TransportTool::m_runTimer
G4Timer * m_runTimer
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:133
iGeant4::G4TransportTool::genEvent
HepMC::GenEvent * genEvent(McEventCollection *mcEventCollection) const
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:456
iGeant4::G4TransportTool::m_doTiming
Gaudi::Property< bool > m_doTiming
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:127
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ISF::Geant4
@ Geant4
Definition: SimulationFlavor.h:23
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ISF::BaseSimulatorTool::m_chrono
ServiceHandle< IChronoStatSvc > m_chrono
The timing service for general usage.
Definition: BaseSimulatorTool.h:115
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:177
iGeant4::G4TransportTool::m_accumulatedEventTime
float m_accumulatedEventTime
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:129
ISF::ISFParticleVector
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
Definition: ISFParticleContainer.h:26
calibdata.exception
exception
Definition: calibdata.py:495
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:140
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:164
iGeant4::G4TransportTool::m_fastSimTool
PublicToolHandle< IFastSimulationMasterTool > m_fastSimTool
Fast Simulation Master Tool.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:186
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize
virtual StatusCode sysInitialize() override
Perform system initialization for an algorithm.
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
iGeant4::G4TransportTool::m_eventTimer
G4Timer * m_eventTimer
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:134
ISF::BaseSimulatorTool::initialize
virtual StatusCode initialize() override
Definition: BaseSimulatorTool.h:57
iGeant4::G4TransportTool::finalizeOnce
void finalizeOnce()
G4 finalization called only by the first tool instance.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:259
iGeant4::G4TransportTool::m_useMT
Gaudi::Property< bool > m_useMT
Activate multi-threading configuration.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:158
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
iGeant4::G4TransportTool::simulateVector
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.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.cxx:289
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
iGeant4::G4TransportTool::passbackAction_t
G4UA::iGeant4::TrackProcessorUserActionBase passbackAction_t
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:138
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
ISF::BaseSimulatorG4Tool
Definition: BaseSimulatorG4Tool.h:28
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
iGeant4::G4TransportTool::m_recordFlux
Gaudi::Property< bool > m_recordFlux
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:152
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
iGeant4::G4TransportTool::m_userActionSvc
ServiceHandle< G4UA::IUserActionSvc > m_userActionSvc
user action service
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:173
iGeant4::G4TransportTool::m_randomStreamName
Gaudi::Property< std::string > m_randomStreamName
Random Stream Name.
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:167
iGeant4::G4TransportTool::ATLAS_THREAD_SAFE
passbackActionMap_t m_secondaryActions ATLAS_THREAD_SAFE
Definition: ISF_Geant4/ISF_Geant4Tools/src/TransportTool.h:143