ATLAS Offline Software
Loading...
Searching...
No Matches
ISFTruthIncident.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// class header
7
8// ISF includes
10
11// HepMC includes
14#include "AtlasHepMC/GenEvent.h"
16
17#include <cmath>
18
20
21 const Amg::Vector3D &mom = particle.momentum();
22 double mass = particle.mass();
23 double energy = std::sqrt( mom.mag2() + mass*mass);
24 HepMC::FourVector fourMomentum( mom.x(), mom.y(), mom.z(), energy);
25
26 auto hepParticle = HepMC::newGenParticlePtr( fourMomentum, particle.pdgCode(), particle.status() );
27 // return a newly created GenParticle
28 return hepParticle;
29}
30
31
32
34 const ISFParticleVector& children,
35 int process,
37 ISF::KillPrimary killsPrimary,
39 ITruthIncident(geoID, children.size()),
40 m_parent(parent),
41 m_children(children),
43 m_killsPrimary(killsPrimary),
45{
46 if ( !m_position) {
47 // No position was given, so compute it.
48 // Default to the parent particle position in the case that there are no child particles.
49 const ISF::ISFParticle *particle = (m_children.empty()) ? &m_parent : m_children.front();
50 if ( !particle) particle = &m_parent; // protection against nullptrs in m_children ISFParticleVector - this would indicate a bug upstream, better to throw an exception here?
51 const Amg::Vector3D &pos = particle->position();
52
53 double time = 0.; //<! TODO: FIXME
54 m_position = new HepMC::FourVector( pos.x(), pos.y(), pos.z(), time );
55 }
56}
57
61
65
67 return -1;
68}
69
73
75 return m_parent.momentum().mag2();
76}
77
79 return m_parent.momentum().perp2();
80}
81
83 return m_parent.ekin();
84}
85
87 return m_parent.pdgCode();
88}
89
91 return m_parent.status();
92}
93
97
98int ISF::ISFTruthIncident::parentBarcode() { // TODO Remove this method
99 return HepMC::barcode(m_parent); // FIXME barcode-based
100}
101
105
109
111 // if parent is killed in the interaction -> return nullptr
112 if (m_killsPrimary==ISF::fKillsPrimary) return nullptr;
113
114 // only update the parent particle, if it survived the interaction
115
116 // set a new barcode
117 m_parent.setBarcode( newBC );
118
119 // set a new status
121
122 // FIXME At this point the m_parent ISFParticle's id, truthBinding
123 // and particleLink all still need to be updated
124
125 // and update truth info (including the ISFParticle's HMPL)
127}
128
129double ISF::ISFTruthIncident::childP2(unsigned short index) const {
130 return m_children[index]->momentum().mag2();
131}
132
133double ISF::ISFTruthIncident::childPt2(unsigned short index) const {
134 return m_children[index]->momentum().perp2();
135}
136
137double ISF::ISFTruthIncident::childEkin(unsigned short index) const {
138 return m_children[index]->ekin();
139}
140
141
143 return m_children[index]->pdgCode();
144}
145
149
151 int bc) {
152 // the child particle
154
155 // set particle barcode of the child particle
156 if (bc) {
157 sec->setBarcode( bc);
158 }
159
160 // Enforce that the status is set correctly
162
163 // FIXME At this point the sec ISFParticle's id, truthBinding
164 // and particleLink all still need to be updated
165
166 // and update truth info (including the ISFParticle's HMPL)
167 return updateHepMCTruthParticle( *sec, &m_parent );
168}
169
170
173 auto* truthBinding = particle.getTruthBinding();
174 HepMC::GenParticlePtr currentGenParticle = truthBinding ? truthBinding->getCurrentGenParticle() : nullptr;
175
176 // We have what we want
177 if (currentGenParticle) {
178 return currentGenParticle;
179 }
180 //Otherwise we need to create it
181 return updateHepMCTruthParticle(particle,&particle);
182}
183
186 ISF::ISFParticle* parent ) const {
187 auto* truthBinding = particle.getTruthBinding();
188 HepMC::GenParticlePtr newGenParticle = ParticleHelper_convert( particle );
189
190 if (truthBinding) {
191 truthBinding->setCurrentGenParticle(newGenParticle);
192 } else {
193 auto parentTruthBinding = parent ? parent->getTruthBinding() : nullptr;
194 auto primaryGenParticle = parentTruthBinding ? parentTruthBinding->getPrimaryGenParticle() : nullptr;
195 auto generationZeroGenParticle = newGenParticle; // New physical particle so this is also the generation zero particle
196 truthBinding = new TruthBinding( newGenParticle, primaryGenParticle, generationZeroGenParticle );
197 particle.setTruthBinding(truthBinding);
198 }
199 // At this point the values returned by particle.getParticleLink()
200 // and particle.id() are not consistent with what is stored in the
201 // TruthBinding.
202
203 // FIXME Consider deleting the HepMcParticleLink and setting the id to HepMC::UNDEFINED_ID at this point?
204 return newGenParticle;
205}
206
209 // FIXME Check that we correctly deal with the case that the parent
210 // particle survives the interaction, but is rejected by
211 // registerTruthIncident
212 const ISF::TruthBinding *parentAfterIncidentTruthBinding = m_parent.getTruthBinding();
213 auto parentAfterIncidentGenParticle = (parentAfterIncidentTruthBinding) ? parentAfterIncidentTruthBinding->getCurrentGenParticle() : nullptr;
214 const int parentAfterIncidentID = (parentAfterIncidentGenParticle) ? HepMC::uniqueID(parentAfterIncidentGenParticle) : HepMC::UNDEFINED_ID;
215 HepMcParticleLink* parentAfterIncidentHMPL{};
216 const HepMcParticleLink* parentBeforeIncidentHMPL = m_parent.getParticleLink();
217 int eventIndex{0};
218 if (parentAfterIncidentGenParticle) { eventIndex = parentAfterIncidentGenParticle->parent_event()->event_number(); }
219 else if (parentBeforeIncidentHMPL) { eventIndex = parentBeforeIncidentHMPL->eventIndex(); }
220 const HepMcParticleLink::PositionFlag idxFlag =
222 if (parentBeforeIncidentHMPL) {
223 delete parentBeforeIncidentHMPL;
224 }
225 if (!parentAfterIncidentGenParticle) {
226 parentAfterIncidentHMPL = new HepMcParticleLink(parentAfterIncidentID, eventIndex, idxFlag, HepMcParticleLink::IS_ID);
227 }
228 else {
229 parentAfterIncidentHMPL = new HepMcParticleLink(parentAfterIncidentGenParticle, eventIndex, idxFlag);
230 }
231 m_parent.setId(parentAfterIncidentID);
232 m_parent.setParticleLink(parentAfterIncidentHMPL);
233}
234
237 unsigned short numSec = numberOfChildren();
238 for (unsigned short i=0; i<numSec; i++) {
239 // the current particle
240 ISF::ISFParticle *child = m_children[i];
241 ISF::TruthBinding *childTruthBinding = child->getTruthBinding();
242 if (!childTruthBinding) {
243 // Child particles which were rejected during
244 // registerTruthIncident need a TruthBinding
245 auto parentTruthBinding = m_parent.getTruthBinding();
246 if (parentTruthBinding) {
247 childTruthBinding = parentTruthBinding->childTruthBinding(nullptr);
248 }
249 else {
250 // FIXME We really shouldn't end up here, possibly abort if we hit this?
251 childTruthBinding = new TruthBinding( nullptr, nullptr, nullptr );
252 }
253 child->setTruthBinding(childTruthBinding);
254 }
255 auto childGenParticle = childTruthBinding->getCurrentGenParticle();
256 const int childID = (childGenParticle) ? HepMC::uniqueID(childGenParticle) : HepMC::UNDEFINED_ID;
257 HepMcParticleLink* childHMPL{};
258 const HepMcParticleLink* oldChildHMPL = child->getParticleLink();
259 int eventIndex{0};
260 if (childGenParticle) { eventIndex = childGenParticle->parent_event()->event_number(); }
261 else if (oldChildHMPL) { eventIndex = oldChildHMPL->eventIndex(); }
262 const HepMcParticleLink::PositionFlag idxFlag =
264 if (oldChildHMPL) {
265 delete oldChildHMPL;
266 }
267 if (!childGenParticle) {
268 childHMPL = new HepMcParticleLink(childID, eventIndex, idxFlag, HepMcParticleLink::IS_ID);
269 }
270 else {
271 childHMPL = new HepMcParticleLink(childGenParticle, eventIndex, idxFlag);
272 }
273 child->setId(childID);
274 child->setParticleLink(childHMPL);
275 }
276}
static HepMC::GenParticlePtr ParticleHelper_convert(const ISF::ISFParticle &particle)
size_t size() const
Number of registered mappings.
The generic ISF particle definition,.
Definition ISFParticle.h:42
const TruthBinding * getTruthBinding() const
pointer to the simulation truth - optional, can be 0
const HepMcParticleLink * getParticleLink() const
HepMcParticleLink accessors.
void setBarcode(int bc)
set a new barcode
void setId(int id)
set a new unique ID
void setStatus(int a)
void setParticleLink(const HepMcParticleLink *partLink)
void setTruthBinding(TruthBinding *truth)
void updateChildParticleProperties()
Update the id and particleLink properties of the child particles (to be called after registerTruthInc...
double parentP2() const override final
Return p^2 of the parent particle.
int physicsProcessCategory() const override final
Return category of the physics process represented by the truth incident (eg hadronic,...
const HepMC::FourVector * m_position
HepMC::GenParticlePtr parentParticleAfterIncident(int newBC) override final
Return the parent particle after the TruthIncident vertex (and give it a new barcode).
double childPt2(unsigned short index) const override final
Return pT^2 of the i-th child particle.
HepMC::GenParticlePtr childParticle(unsigned short index, int bc) override final
Return the i-th child as a HepMC particle type and assign the given Barcode to the simulator particle...
int parentStatus() override final
ISF::ISFParticle & m_parent
const ISFParticleVector & m_children
int physicsProcessCode() const override final
Return specific physics process code of the truth incident (eg ionisation, bremsstrahlung,...
bool parentSurvivesIncident() const override final
Return a boolean whether or not the parent particle survives the incident.
double childP2(unsigned short index) const override final
Return p^2 of the i-th child particle.
double parentEkin() const override final
Return Ekin of the parent particle.
HepMC::GenParticlePtr parentParticle() override final
Return the parent particle as a HepMC particle type (usually only called for particles that will ente...
const ISF::KillPrimary m_killsPrimary
double parentPt2() const override final
Return pT^2 of the parent particle.
void updateParentAfterIncidentProperties()
Update the id and particleLink properties of the parentAfterIncident (to be called after registerTrut...
int childPdgCode(unsigned short index) const override final
Return the PDG Code of the i-th child particle.
int parentPdgCode() const override final
Return the PDG Code of the parent particle.
int parentBarcode() override final
Return the barcode of the parent particle.
HepMC::GenParticlePtr updateHepMCTruthParticle(ISF::ISFParticle &particle, ISF::ISFParticle *parent=nullptr) const
convert ISFParticle to GenParticle and attach to ISFParticle's TruthBinding
int childBarcode(unsigned short) const override final
Return the barcode of the i-th child particle (if defined as part of the TruthIncident) otherwise ret...
HepMC::GenParticlePtr getHepMCTruthParticle(ISF::ISFParticle &particle) const
return attached truth particle
const HepMC::FourVector & position() const override final
Return HepMC position of the truth vertex.
int parentUniqueID() override final
Return the unique ID of the parent particle.
double childEkin(unsigned short index) const override final
Return Ekin of the i-th child particle.
unsigned short numberOfChildren() const
Return total number of child particles.
AtlasDetDescr::AtlasRegion geoID()
Return the SimGeoID corresponding to the vertex of the truth incident.
ITruthIncident(AtlasDetDescr::AtlasRegion geoID, unsigned short numChildren)
HepMC::GenParticlePtr getCurrentGenParticle()
pointer to the particle in the simulation truth
TruthBinding * childTruthBinding(HepMC::GenParticlePtr childP)
Create a TruthBinding for a child particle.
const std::string process
Eigen::Matrix< double, 3, 1 > Vector3D
AtlasRegion
A simple enum of ATLAS regions and sub-detectors.
Definition AtlasRegion.h:21
int barcode(const T *p)
Definition Barcode.h:15
HepMC3::FourVector FourVector
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition GenParticle.h:21
constexpr int SIM_STATUS_INCREMENT
Constant defining the barcode threshold for regenerated particles, i.e. particles surviving an intera...
constexpr int SIM_STATUS_THRESHOLD
Constant definiting the status threshold for simulated particles, eg. can be used to separate generat...
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
KillPrimary
Basically only a boolean, which helps making the code more readable.
@ fKillsPrimary
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
Definition index.py:1