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#ifndef HEPMC3
28 HepMC::suggest_barcode(hepParticle, particle.barcode() );
29#endif
30 // return a newly created GenParticle
31 return hepParticle;
32}
33
34
35
37 const ISFParticleVector& children,
38 int process,
40 ISF::KillPrimary killsPrimary,
41 const HepMC::FourVector *position) :
42 ITruthIncident(geoID, children.size()),
43 m_parent(parent),
44 m_children(children),
46 m_killsPrimary(killsPrimary),
48{
49 if ( !m_position) {
50 // No position was given, so compute it.
51 // Default to the parent particle position in the case that there are no child particles.
52 const ISF::ISFParticle *particle = (m_children.empty()) ? &m_parent : m_children.front();
53 if ( !particle) particle = &m_parent; // protection against nullptrs in m_children ISFParticleVector - this would indicate a bug upstream, better to throw an exception here?
54 const Amg::Vector3D &pos = particle->position();
55
56 double time = 0.; //<! TODO: FIXME
57 m_position = new HepMC::FourVector( pos.x(), pos.y(), pos.z(), time );
58 }
59}
60
64
65const HepMC::FourVector& ISF::ISFTruthIncident::position() const {
66 return *m_position;
67}
68
70 return -1;
71}
72
76
78 return m_parent.momentum().mag2();
79}
80
82 return m_parent.momentum().perp2();
83}
84
86 return m_parent.ekin();
87}
88
90 return m_parent.pdgCode();
91}
92
94 return m_parent.status();
95}
96
100
101int ISF::ISFTruthIncident::parentBarcode() { // TODO Remove this method
102 return HepMC::barcode(m_parent); // FIXME barcode-based
103}
104
108
112
114 // if parent is killed in the interaction -> return nullptr
115 if (m_killsPrimary==ISF::fKillsPrimary) return nullptr;
116
117 // only update the parent particle, if it survived the interaction
118
119 // set a new barcode
120 m_parent.setBarcode( newBC );
121
122 // set a new status
124
125 // FIXME At this point the m_parent ISFParticle's id, truthBinding
126 // and particleLink all still need to be updated
127
128 // and update truth info (including the ISFParticle's HMPL)
130}
131
132double ISF::ISFTruthIncident::childP2(unsigned short index) const {
133 return m_children[index]->momentum().mag2();
134}
135
136double ISF::ISFTruthIncident::childPt2(unsigned short index) const {
137 return m_children[index]->momentum().perp2();
138}
139
140double ISF::ISFTruthIncident::childEkin(unsigned short index) const {
141 return m_children[index]->ekin();
142}
143
144
146 return m_children[index]->pdgCode();
147}
148
152
154 int bc) {
155 // the child particle
157
158 // set particle barcode of the child particle
159 if (bc) {
160 sec->setBarcode( bc);
161 }
162
163 // Enforce that the status is set correctly
165
166 // FIXME At this point the sec ISFParticle's id, truthBinding
167 // and particleLink all still need to be updated
168
169 // and update truth info (including the ISFParticle's HMPL)
170 return updateHepMCTruthParticle( *sec, &m_parent );
171}
172
173
176 auto* truthBinding = particle.getTruthBinding();
177 HepMC::GenParticlePtr currentGenParticle = truthBinding ? truthBinding->getCurrentGenParticle() : nullptr;
178
179 // We have what we want
180 if (currentGenParticle) {
181 return currentGenParticle;
182 }
183 //Otherwise we need to create it
184 return updateHepMCTruthParticle(particle,&particle);
185}
186
189 ISF::ISFParticle* parent ) const {
190 auto* truthBinding = particle.getTruthBinding();
191 HepMC::GenParticlePtr newGenParticle = ParticleHelper_convert( particle );
192
193 if (truthBinding) {
194 truthBinding->setCurrentGenParticle(newGenParticle);
195 } else {
196 auto parentTruthBinding = parent ? parent->getTruthBinding() : nullptr;
197 auto primaryGenParticle = parentTruthBinding ? parentTruthBinding->getPrimaryGenParticle() : nullptr;
198 auto generationZeroGenParticle = newGenParticle; // New physical particle so this is also the generation zero particle
199 truthBinding = new TruthBinding( newGenParticle, primaryGenParticle, generationZeroGenParticle );
200 particle.setTruthBinding(truthBinding);
201 }
202 // At this point the values returned by particle.getParticleLink()
203 // and particle.id() are not consistent with what is stored in the
204 // TruthBinding.
205
206 // FIXME Consider deleting the HepMcParticleLink and setting the id to HepMC::UNDEFINED_ID at this point?
207 return newGenParticle;
208}
209
212 // FIXME Check that we correctly deal with the case that the parent
213 // particle survives the interaction, but is rejected by
214 // registerTruthIncident
215 const ISF::TruthBinding *parentAfterIncidentTruthBinding = m_parent.getTruthBinding();
216 auto parentAfterIncidentGenParticle = (parentAfterIncidentTruthBinding) ? parentAfterIncidentTruthBinding->getCurrentGenParticle() : nullptr;
217 const int parentAfterIncidentID = (parentAfterIncidentGenParticle) ? HepMC::uniqueID(parentAfterIncidentGenParticle) : HepMC::UNDEFINED_ID;
218 HepMcParticleLink* parentAfterIncidentHMPL{};
219 const HepMcParticleLink* parentBeforeIncidentHMPL = m_parent.getParticleLink();
220 int eventIndex{0};
221 if (parentAfterIncidentGenParticle) { eventIndex = parentAfterIncidentGenParticle->parent_event()->event_number(); }
222 else if (parentBeforeIncidentHMPL) { eventIndex = parentBeforeIncidentHMPL->eventIndex(); }
223 const HepMcParticleLink::PositionFlag idxFlag =
225 if (parentBeforeIncidentHMPL) {
226 delete parentBeforeIncidentHMPL;
227 }
228 if (!parentAfterIncidentGenParticle) {
229 parentAfterIncidentHMPL = new HepMcParticleLink(parentAfterIncidentID, eventIndex, idxFlag, HepMcParticleLink::IS_ID);
230 }
231 else {
232 parentAfterIncidentHMPL = new HepMcParticleLink(parentAfterIncidentGenParticle, eventIndex, idxFlag);
233 }
234 m_parent.setId(parentAfterIncidentID);
235 m_parent.setParticleLink(parentAfterIncidentHMPL);
236}
237
240 unsigned short numSec = numberOfChildren();
241 for (unsigned short i=0; i<numSec; i++) {
242 // the current particle
243 ISF::ISFParticle *child = m_children[i];
244 ISF::TruthBinding *childTruthBinding = child->getTruthBinding();
245 if (!childTruthBinding) {
246 // Child particles which were rejected during
247 // registerTruthIncident need a TruthBinding
248 auto parentTruthBinding = m_parent.getTruthBinding();
249 if (parentTruthBinding) {
250 childTruthBinding = parentTruthBinding->childTruthBinding(nullptr);
251 }
252 else {
253 // FIXME We really shouldn't end up here, possibly abort if we hit this?
254 childTruthBinding = new TruthBinding( nullptr, nullptr, nullptr );
255 }
256 child->setTruthBinding(childTruthBinding);
257 }
258 auto childGenParticle = childTruthBinding->getCurrentGenParticle();
259 const int childID = (childGenParticle) ? HepMC::uniqueID(childGenParticle) : HepMC::UNDEFINED_ID;
260 HepMcParticleLink* childHMPL{};
261 const HepMcParticleLink* oldChildHMPL = child->getParticleLink();
262 int eventIndex{0};
263 if (childGenParticle) { eventIndex = childGenParticle->parent_event()->event_number(); }
264 else if (oldChildHMPL) { eventIndex = oldChildHMPL->eventIndex(); }
265 const HepMcParticleLink::PositionFlag idxFlag =
267 if (oldChildHMPL) {
268 delete oldChildHMPL;
269 }
270 if (!childGenParticle) {
271 childHMPL = new HepMcParticleLink(childID, eventIndex, idxFlag, HepMcParticleLink::IS_ID);
272 }
273 else {
274 childHMPL = new HepMcParticleLink(childGenParticle, eventIndex, idxFlag);
275 }
276 child->setId(childID);
277 child->setParticleLink(childHMPL);
278 }
279}
static HepMC::GenParticlePtr ParticleHelper_convert(const ISF::ISFParticle &particle)
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:16
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
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...
bool suggest_barcode(T &p, int i)
Definition GenEvent.h:672
GenParticlePtr newGenParticlePtr(const HepMC::FourVector &mom=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), int pid=0, int status=0)
Definition GenParticle.h:39
GenParticle * GenParticlePtr
Definition GenParticle.h:37
KillPrimary
Basically only a boolean, which helps making the code more readable.
@ fKillsPrimary
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.
Definition index.py:1