|
ATLAS Offline Software
|
Go to the documentation of this file.
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);
42 if (ret.size()==1)
if (ret.at(0)->pdg_id()==
p->pdg_id()) ret =
findChildren(ret.at(0));
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();
HepMC::GenVertex * GenVertexPtr
TruthSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
virtual const HepMC::FourVector & position() const =0
Return HepMC position of the truth vertex.
bool suggest_barcode(T &p, int i)
virtual HepMC::GenParticlePtr childParticle(unsigned short index, int bc=HepMC::UNDEFINED_ID)=0
Return the i-th child as a HepMC particle type and assign the given Barcode to the simulator particle...
void registerTruthIncident(ITruthIncident &truthincident, bool saveAllChildren=false) const override
Register a truth incident.
StatusCode releaseEvent() override
Finalize the Truth Svc at the end of each event.
std::string find(const std::string &s)
return a remapped string
virtual int physicsProcessCode() const =0
Return specific physics process code of the truth incident (eg ionisation, bremsstrahlung,...
GenParticle * GenParticlePtr
virtual int childBarcode(unsigned short index) const =0
Return the barcode of the i-th child particle (if defined as part of the TruthIncident) otherwise ret...
virtual ISF::InteractionClass_t interactionClassification() const
The interaction classifications are described as follows: STD_VTX: interaction of a particle without ...
#define ATH_MSG_VERBOSE(x)
StatusCode finalize() override
Athena algorithm's interface method finalize()
static const char * getName(int region)
virtual HepMC::GenParticlePtr parentParticleAfterIncident(int newBC)=0
Return the parent particle after the TruthIncident vertex (and assign a new barcode to it)
virtual HepMC::GenParticlePtr parentParticle()=0
Return the parent particle as a HepMC particle type (only called for particles that will enter the He...
unsigned short numberOfChildren() const
Return total number of child particles.
GenVertexPtr newGenVertexPtr(const HepMC::FourVector &pos=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), const int i=0)
::StatusCode StatusCode
StatusCode definition for legacy code.
HepMC::GenVertexPtr createGenVertexFromTruthIncident(ITruthIncident &truthincident) const
Record and end vertex to the MC Truth for the parent particle.
AthROOTErrorHandlerSvc * svc
StatusCode initializeTruthCollection(int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
Initialize the Truth Svc at the beginning of each event.
virtual bool parentSurvivesIncident() const =0
Return a boolean whether or not the parent particle survives the incident.
constexpr int UNDEFINED_ID
constexpr int SIM_REGENERATION_INCREMENT
Constant defining the barcode threshold for regenerated particles, i.e. particles surviving an intera...
void recordIncidentToMCTruth(ITruthIncident &truthincident, bool passWholeVertex) const
Record the given truth incident to the MC Truth.
constexpr int SIM_STATUS_THRESHOLD
Constant definiting the status threshold for simulated particles, eg. can be used to separate generat...
InteractionClass_t
The interaction classifications are described as follows: STD_VTX: interaction of a particle without ...
bool childPassedFilters(unsigned short index) const
Should a particular child be written out to the GenEvent.
virtual int parentBarcode()=0
Return the barcode of the parent particle.
#define ATH_MSG_WARNING(x)
bool isDecayed(const T &p)
Identify if the particle decayed.
void setPassWholeVertices(bool passWholeVertex)
Set whether this TruthIncident should pass the vertex as a whole or individual children.
virtual int physicsProcessCategory() const =0
Return category of the physics process represented by the truth incident (eg hadronic,...
#define validAtlasRegion(region)
StatusCode initialize() override
Athena algorithm's interface method initialize()
virtual int parentUniqueID()=0
Return the unique ID of the parent particle.
AtlasDetDescr::AtlasRegion geoID()
Return the SimGeoID corresponding to the vertex of the truth incident.
std::vector< HepMC::GenParticlePtr > findChildren(const HepMC::GenParticlePtr &p)