11 #include "GaudiKernel/ISvcLocator.h"
13 #include "GaudiKernel/SystemOfUnits.h"
24 #include "CLHEP/Geometry/Point3D.h"
33 if (!
p)
return std::vector<HepMC::GenParticlePtr>();
34 const auto&
v =
p->end_vertex();
35 if (!
v)
return std::vector<HepMC::GenParticlePtr>();
37 std::vector<HepMC::GenParticlePtr>
ret =
v->particles_out();
39 std::vector<HepMC::GenParticlePtr>
ret;
40 for (
auto pp=
v->particles_out_const_begin();pp!=
v->particles_out_const_end();++pp)
ret.push_back(*pp);
62 ATH_MSG_DEBUG(
"--------------------------------------------------------");
65 if ( m_barcodeSvc.retrieve().isFailure() ) {
67 return StatusCode::FAILURE;
75 m_numStrategies[geoID] = 0;
76 for (
const auto &truthStrategy : m_truthStrategies) {
77 if(truthStrategy->appliesToRegion(geoID)) {
78 ++m_numStrategies[geoID];
84 unsigned short curNumStrategies = m_truthStrategies.size();
85 unsigned short nStrat(0);
86 for (
unsigned short i = 0;
i < curNumStrategies; ++
i) {
87 if(m_truthStrategies[
i]->appliesToRegion(geoID)) {
88 m_geoStrategies[geoID][nStrat++] = &(*m_truthStrategies[
i]);
94 bool forceEndVtx =
std::find( m_forceEndVtxRegionsVec.begin(),
95 m_forceEndVtxRegionsVec.end(),
96 geoID ) != m_forceEndVtxRegionsVec.end();
97 m_forceEndVtx[geoID] = forceEndVtx;
100 return StatusCode::SUCCESS;
108 return StatusCode::SUCCESS;
115 ATH_CHECK( m_barcodeSvc->initializeBarcodes(largestGeneratedParticleBC, largestGeneratedVertexBC) );
116 return StatusCode::SUCCESS;
120 return StatusCode::SUCCESS;
127 const bool passWholeVertex = m_passWholeVertex || saveAllChildren;
136 const auto& position = ti.
position();
137 ATH_MSG_ERROR(
"Unable to register truth incident with unknown SimGeoID="<< geoID
138 <<
" at position z=" << position.z() <<
" r=" << position.perp());
147 if ( m_skipIfNoChildren && (numSec==0) ) {
149 <<
" will not record this TruthIncident.");
156 ATH_MSG_VERBOSE(
"Parent particle in TruthIncident does not have an id,"
157 <<
" will not record this TruthIncident.");
163 for (
unsigned short stratID=0; (!pass) && (stratID<m_numStrategies[geoID]); stratID++) {
165 pass = m_geoStrategies[geoID][stratID]->pass(ti);
172 recordIncidentToMCTruth(ti, passWholeVertex);
179 ATH_MSG_VERBOSE(
"No TruthStrategies passed and parent destroyed - create end vertex.");
180 this->createGenVertexFromTruthIncident( ti );
182 #ifdef DEBUG_TRUTHSVC
185 ATH_MSG_INFO(
"TruthSvc: " << vtxType <<
" vertex + " << survival
200 #ifdef DEBUG_TRUTHSVC
206 ATH_MSG_WARNING (
"Attempting to record a TruthIncident for a particle which has already decayed!");
214 #ifdef DEBUG_TRUTHSVC
217 ATH_MSG_INFO(
"TruthSvc: " << vtxType <<
" vertex + " << survival
231 newPrimaryBC = m_barcodeSvc->newGeneratedParticle(parentBC);
238 if(parentAfterIncident) {
246 ATH_MSG_WARNING (
"recordIncidentToMCTruth - check parentAfterIncident: " << parentAfterIncident );
249 vtxFromTI->add_particle_out( parentAfterIncident );
262 for (
unsigned short i=0;
i<numSec; ++
i) {
267 int secondaryParticleBC = (isQuasiStableVertex) ?
268 m_barcodeSvc->newGeneratedParticle(parentBC) : m_barcodeSvc->newSecondaryParticle(parentBC);
270 if (m_ignoreUndefinedBarcodes)
271 ATH_MSG_WARNING(
"Unable to generate new Secondary Particle Barcode. Continuing due to 'IgnoreUndefinedBarcodes'==True");
273 ATH_MSG_ERROR(
"Unable to generate new Secondary Particle Barcode. Aborting");
280 vtxFromTI->add_particle_out(
p);
296 ATH_MSG_VERBOSE(
"--------------------------------------------------------");
305 std::vector<double> weights(1);
307 weights[0] =
static_cast<double>( primaryBC );
315 ATH_MSG_ERROR(
"Unable to write particle interaction to MC truth due to missing parent HepMC::GenParticle instance");
318 HepMC::GenEvent *mcEvent =
parent->parent_event();
320 ATH_MSG_ERROR(
"Unable to write particle interaction to MC truth due to missing parent HepMC::GenEvent instance");
325 int vtxbcode = m_barcodeSvc->newSimulationVertex();
327 if (m_ignoreUndefinedBarcodes) {
328 ATH_MSG_WARNING(
"Unable to generate new Truth Vertex Barcode. Continuing due to 'IgnoreUndefinedBarcodes'==True");
330 ATH_MSG_ERROR(
"Unable to generate new Truth Vertex Barcode. Aborting");
339 std::unique_ptr<HepMC::GenVertex> newVtx = std::make_unique<HepMC::GenVertex>( ti.
position(), vtxStatus, weights );
343 if (
parent->end_vertex()){
344 ATH_MSG_ERROR (
"createGVfromTI: Parent particle found with an end vertex attached. This should not happen!");
349 #ifdef DEBUG_TRUTHSVC
353 newVtx->add_particle_in(
parent );
354 #ifdef DEBUG_TRUTHSVC
355 ATH_MSG_VERBOSE (
"createGVfromTI End Vertex representing process: " << processCode <<
", for parent with barcode "<<parentBC<<
". Creating." );
359 mcEvent->add_vertex(newVtx);
361 newVtx->add_attribute(
"weights",std::make_shared<HepMC3::VectorDoubleAttribute>(weights));
363 mcEvent->add_vertex( newVtx.release() );
367 return parent->end_vertex();