115 {
116
117 const EventContext& ctx = Gaudi::Hive::currentContext();
118 auto hitCollections = std::make_shared<HitCollectionMap>();
119
121 if ( curSimTool ) {
122 if (auto* g4sim =
123 dynamic_cast<ISF::BaseSimulatorG4Tool*>(curSimTool.get())) {
124 ATH_CHECK(g4sim->setupEvent(ctx, *hitCollections));
125 } else {
127 }
128 ATH_MSG_DEBUG(
"Event setup done for " << curSimTool->name() );
129 }
130 }
131
133 if (!inputEvgen.isValid()) {
134 ATH_MSG_FATAL(
"Unable to read input GenEvent collection '" << inputEvgen.key() <<
"'");
135 return StatusCode::FAILURE;
136 }
137
138
140 std::unique_ptr<McEventCollection> shadowTruth{};
142 outputTruth = std::make_unique<McEventCollection>();
143
144 shadowTruth = std::make_unique<McEventCollection>(*inputEvgen);
145 for (HepMC::GenEvent* currentGenEvent : *shadowTruth ) {
146
149 }
150
152 outputTruth->push_back(outputEvent.release());
153 }
154 }
155 else {
156
157 outputTruth = std::make_unique<McEventCollection>(*inputEvgen);
158
160 for (HepMC::GenEvent* currentGenEvent : *outputTruth ) {
162 }
163 }
164 }
165
170
172
173
175 caloEntryLayer = std::make_unique<TrackRecordCollection>(caloEntryLayer.name());
178 muonEntryLayer = std::make_unique<TrackRecordCollection>(muonEntryLayer.name());
181 muonExitLayer = std::make_unique<TrackRecordCollection>(muonExitLayer.name());
183
184
187
188
190 for ( auto& particle : simParticles ) {
191
193
194 particle->setOrder( -particleQueue.size() );
195 } else {
197 }
198
199 particleQueue.push( particle );
200 }
201
202 unsigned int loopCounter{0};
203
205 ISimulatorTool* lastSimulator{};
207 while ( particleQueue.size() ) {
208 ++loopCounter;
210 ATH_MSG_VERBOSE(
"Queue starts with " << particleQueue.size() <<
" particles.");
211
213 while ( particleQueue.size() ) {
214 auto particlePtr = particleQueue.top();
215 ISFParticle& curParticle( *particlePtr );
216 particleQueue.pop();
217
218
220 m_geoIDSvc->identifyAndRegNextGeoID( curParticle );
221 }
222
223
225
226
228
230 lastSimulator=&simTool;
231 }
233
234 tempQueue.push(particlePtr);
235 }
236 else {
238 }
239 }
240 particleQueue = std::move(tempQueue);
241 #ifdef ISFDEBUG
242 if (loopCounter>100 &&
particles.size()<3) {
244 ATH_MSG_INFO(
"Selected " <<
particles.size() <<
" particles to be processed by " << lastSimulator->name());
245 for ( const ISFParticle *particle : particles ) {
247 }
248 }
249 #endif
250
252
253 if (auto* g4sim = dynamic_cast<ISF::BaseSimulatorG4Tool*>(lastSimulator)) {
254 ATH_CHECK(g4sim->simulateVector(ctx, particles, newSecondaries,
255 outputTruth.ptr(), hitCollections,
256 shadowTruth.get()));
257 } else {
258 ATH_CHECK(lastSimulator->simulateVector(ctx, particles, newSecondaries,
259 outputTruth.ptr(),
260 shadowTruth.get()));
261 }
262
263 ATH_MSG_VERBOSE(lastSimulator->name() <<
" returned " << newSecondaries.size() <<
" new particles to be added to the queue." );
264
265 for ( auto* secondary : newSecondaries ) {
266
267
270 m_geoIDSvc->identifyAndRegNextGeoID( *secondary );
271 }
272
274
275 secondary->setOrder( -particleQueue.size() );
276 } else {
278 }
279
280 particleQueue.push( secondary );
281 }
282 newSecondaries.clear();
283
284
285 for ( auto usedParticle : particles ) {
286 delete usedParticle;
287 }
289 }
290 ATH_MSG_VERBOSE(
"Final status: queue contains " << particleQueue.size() <<
" particles.");
291
292
294 if ( curSimTool ) {
295 if (auto* g4sim =
296 dynamic_cast<ISF::BaseSimulatorG4Tool*>(curSimTool.get())) {
297 ATH_CHECK(g4sim->releaseEvent(ctx, *hitCollections));
298 } else {
299 ATH_CHECK(curSimTool->releaseEvent(ctx));
300 }
301 ATH_MSG_DEBUG(
"releaseEvent() completed for " << curSimTool->name() );
302 }
303 }
304
305
307 for (HepMC::GenEvent* currentGenEvent : *outputTruth ) {
309 }
310 }
311
312 return StatusCode::SUCCESS;
313}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
bool validAtlasRegion(AtlasDetDescr::AtlasRegion region)
Check a given AtlasRegion for its validity.
SG::WriteHandleKey< McEventCollection > m_outputTruthKey
Output Simulation Truth collection.
ToolHandleArray< ISimulatorTool > m_simulationTools
Simulation Tools.
SG::ReadHandleKey< McEventCollection > m_inputEvgenKey
Input Generator Truth collection.
BooleanProperty m_useShadowEvent
SG::WriteHandleKey< TrackRecordCollection > m_muonEntryLayerKey
ToolHandle< IGenEventFilter > m_truthPreselectionTool
ToolHandle< IParticleOrderingTool > m_orderingTool
Tool to set particle ordering.
Gaudi::Property< size_t > m_maxParticleVectorSize
Number of particles simultaneously sent to simulator.
ISimulatorTool & identifySimulator(const ISF::ISFParticle &particle)
Returns the simulator to use for the given particle.
ServiceHandle< IGeoIDSvc > m_geoIDSvc
Service to set particle GeoIDs.
SG::WriteHandleKey< TrackRecordCollection > m_caloEntryLayerKey
Output TrackRecordCollections.
ServiceHandle< Simulation::IZeroLifetimePatcher > m_qspatcher
Quasi-Stable Particle Simulation Patcher.
ServiceHandle< IInputConverter > m_inputConverter
Input converter service (from Generator->ISF particle types)
SG::WriteHandleKey< TrackRecordCollection > m_muonExitLayerKey
Gaudi::Property< bool > m_forceGeoIDSvc
Force geoID recalculation for each particle.
PublicToolHandle< IEntryLayerTool > m_entryLayerTool
AthenaTool responsible for writing Calo/Muon Entry/Exit Layer collection.
ServiceHandle< ITruthSvc > m_truthRecordSvc
Central truth service.
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.
std::priority_queue< ISF::ISFParticle *, ISF::ISFParticleVector, ISF::ISFParticleOrdering > ISFParticleOrderedQueue
the actual particle priority_queue
std::list< ISF::ISFParticle * > ISFParticleContainer
generic ISFParticle container (not necessarily a std::list!)
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses