17#include "Gaudi/Property.h"
65 "Input Hard Scatter EVGEN collection.");
68 "Input Pileup EVGEN collection.");
71 "Output Hard Scatter Truth collection.");
74 "Output Pileup Truth collection.");
77 "Input McEventCollection->ISFParticleContainer conversion service.");
104 ATH_MSG_VERBOSE (
"--------------------------------------------------------" );
113 m_memMon->recordCurrent(
"at beginning of SimKernel initialize()");
152 ATH_MSG_INFO(
"The following Event Filters are defined:");
159 ATH_MSG_INFO (
"The following SimulationSvc are registered to ISF:");
170 ATH_MSG_INFO(
"The following routing chains are defined:");
185 return StatusCode::SUCCESS;
199 ATH_MSG_INFO(
" ========================= ISF Timing Stats =========================");
202 ATH_MSG_INFO(
"Breakdown of simulation loop by SimulatorID:");
211 <<
"\t\tn="<<
count<<
"\t\tt=" <<time_ms<<
" ms\t\tt/n="<<time_ms/
count<<
" ms"
212 <<std::setprecision(-1) );
261 ATH_MSG_INFO(
" ====================== ISF Memory Usage Stats =======================");
262 m_memMon->dumpSummary(
"end of ISF event");
265 ATH_MSG_INFO(
" =====================================================================");
267 return StatusCode::SUCCESS;
274 if ( simSelectorTools.retrieve().isFailure() ) {
275 ATH_MSG_FATAL(
"Could not retrieve SimulatorSelector Tool Array. Abort." );
276 return StatusCode::FAILURE;
280 SimSelectorToolArray::iterator fSimSelectorIter = simSelectorTools.begin();
281 SimSelectorToolArray::iterator fSimSelectorIterEnd = simSelectorTools.end();
282 for ( ; fSimSelectorIter != fSimSelectorIterEnd; ++fSimSelectorIter ) {
287 if ( (*curSimulator).retrieve().isFailure() ){
288 ATH_MSG_FATAL(
"Could not retrieve SimulatorSelector Tool. Abort." );
289 return StatusCode::FAILURE;
291 ATH_MSG_INFO(
"- SimulationSelector : " << fSimSelectorIter->typeAndName() );
295 ATH_MSG_FATAL(
"Unable to register ParticleService to SimulationService "
297 return StatusCode::FAILURE;
301 SimSvcID curID = (*curSimulator)->simSvcID();
319 return StatusCode::SUCCESS;
330 m_memMon->dumpCurrent(
"before 1st event",
false );
331 m_memMon->recordCurrent(
"before 1st event");
334 auto hitCollections = std::make_shared<HitCollectionMap>();
339 std::unique_ptr<McEventCollection> shadowTruth{};
340 std::unique_ptr<McEventCollection> shadowPileUpTruth{};
363 std::vector<ISimulationSvc*>::iterator fSimSvcIter =
m_simSvcs.begin();
364 std::vector<ISimulationSvc*>::iterator fSimSvcIterEnd =
m_simSvcs.end();
365 for ( ; fSimSvcIter != fSimSvcIterEnd; ++fSimSvcIter ){
371 if (
auto* curSimSvcG4 =
374 return curSimSvcG4->setupEvent(*hitCollections);
380 if (status.isFailure()) {
396 unsigned int loopCounter{0};
404 const unsigned int numParticlesLeftInBroker =
m_particleBroker->numParticles();
405 int numParticles = particles.size();
408 if (numParticles==0)
break;
422 if (loopCounter>100 && numParticles<3) {
433 if ( particle->nextSimID() != simID ) {
434 ATH_MSG_WARNING(
"Particle with SimID " << particle->nextSimID() <<
" found in vector with expected ID " << simID );
450 if (
auto* curSimSvcG4 =
455 hitCollections, shadowTruth.get())
478 ATH_MSG_WARNING(
"ParticleBroker returned with an error in event finalization." );
482 std::vector<ISimulationSvc*>::iterator fSimSvcIter =
m_simSvcs.begin();
483 std::vector<ISimulationSvc*>::iterator fSimSvcIterEnd =
m_simSvcs.end();
484 for ( ; fSimSvcIter != fSimSvcIterEnd; ++fSimSvcIter ){
490 if (
auto* curSimSvcG4 =
493 return curSimSvcG4->releaseEvent(*hitCollections);
499 if (status.isFailure()) {
511 ATH_MSG_FATAL(
"Event finalize failed for TruthService. Abort." );
512 return StatusCode::FAILURE;
523 ToolHandleArray<IEventFilterTool>::iterator eventFilter(
m_eventFilters.begin());
524 const ToolHandleArray<IEventFilterTool>::iterator endOfEventFilters(
m_eventFilters.end());
525 while (eventFilter != endOfEventFilters) {
526 if (!((**eventFilter).eventPassesFilter())) {
527 setFilterPassed(
false);
528 ATH_MSG_INFO(
"This event failed the " << (**eventFilter).name() <<
" Filter. Therefore it will not be recorded.");
540 std::string descr(
"after event " + evtStr);
541 m_memMon->dumpCurrent( descr.c_str(),
true);
554 return StatusCode::SUCCESS;
562 std::unique_ptr<McEventCollection>& shadowTruth,
566 ATH_MSG_FATAL(
"Unable to read input GenEvent collection '" << inputTruth.
key() <<
"'");
567 return StatusCode::FAILURE;
571 outputTruth = std::make_unique<McEventCollection>();
573 shadowTruth = std::make_unique<McEventCollection>(*inputTruth);
574 for (HepMC::GenEvent* currentGenEvent : *shadowTruth ) {
581 outputTruth->push_back(outputEvent.release());
586 outputTruth = std::make_unique<McEventCollection>(*inputTruth);
590 for (HepMC::GenEvent* currentGenEvent : *outputTruth ) {
597 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
bool prepareInput(const std::string &name, const std::vector< int64_t > &shape, const std::vector< T > &data, std::vector< std::shared_ptr< tc::InferInput > > &inputs)
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
static const char * getName(int region)
Base class for an ISimulatorSvc which requires a Geant4 UserInfo object.
The generic ISF particle definition,.
SimSvcID nextSimID() const
the next simulation service the particle will be sent to
virtual const std::string & simSvcDescriptor()=0
Return the simulation service descriptor.
virtual StatusCode setupEvent()=0
Setup Event chain - in case of a begin-of event action is needed, to be called by simulation kernel.
virtual StatusCode releaseEvent()=0
Release Event chain - in case of an end-of event action is needed, to be called by simulation kernel.
bool m_doMemMon
The Memory Info Tool.
StatusCode prepareInput(SG::ReadHandle< McEventCollection > &inputTruth, SG::WriteHandle< McEventCollection > &outputTruth, std::unique_ptr< McEventCollection > &shadowTruth, ISFParticleContainer &simParticles) const
Convert input generator particles to ISFParticles and copy input generator truth collection into outp...
virtual ~SimKernel()
Destructor.
ServiceHandle< Simulation::IZeroLifetimePatcher > m_qspatcher
Quasi-Stable Particle Simulation Patcher.
SG::WriteHandle< McEventCollection > m_outputPileupTruth
output pileup truth collection
std::vector< ISimulationSvc * > m_simSvcs
Simulators to be used.
bool m_doCPUMon
CPU Benchmarking.
std::array< PublicToolHandleArray< ISimulationSelector >, AtlasDetDescr::fNumAtlasRegions > m_simSelectors
The Simulation Selector Chains.
PMonUtils::CustomBenchmark * m_benchSimID
StatusCode initialize()
Athena algorithm's interface method initialize()
long int m_numParticles
Statistics.
BooleanProperty m_useShadowEvent
ToolHandleArray< IEventFilterTool > m_eventFilters
The Event Filters.
StatusCode finalize()
Athena algorithm's interface method finalize()
ServiceHandle< ITruthSvc > m_truthRecordSvc
Central truth service.
std::vector< std::string > m_simSvcNames
SimSvc names.
StatusCode execute()
Athena algorithm's interface method execute()
ToolHandle< IGenEventFilter > m_truthPreselectionTool
SG::WriteHandle< McEventCollection > m_outputHardScatterTruth
output hard scatter truth collection
SimKernel(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
ISF::SimSvcID m_numSimSvcs
total number of SimSvcs used
ServiceHandle< IInputConverter > m_inputConverter
input->ISFParticle converter
SG::ReadHandle< McEventCollection > m_inputPileupEvgen
input pileup collection
SG::ReadHandle< McEventCollection > m_inputHardScatterEvgen
Input/output truth collections and input conversion.
unsigned int m_memUsageEvts
unsigned int m_numISFEvents
keep track of the number of events processed
StatusCode initSimSvcs(SimSelectorToolArray &simSelectorTools)
ToolHandle< IMonitoringTool > m_memMon
size_t m_maxParticleVectorSize
tuning
ServiceHandle< IParticleBroker > m_particleBroker
Central particle broker service.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
AtlasRegion
A simple enum of ATLAS regions and sub-detectors.
int maxGeneratedVertexBarcode(const HepMC::GenEvent *genEvent)
Get the maximal absolute value of barcode of vertex present in the event. Returns a negative number.
constexpr int UNDEFINED_ID
int maxGeneratedParticleBarcode(const HepMC::GenEvent *genEvent)
Get the maximal value of barcode of particle present in the event.
ToolHandleArray< ISimulationSelector > SimSelectorToolArray
typedef for better readable code
uint8_t SimSvcID
Simulation service ID datatype.
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.