6#ifndef TRUTHUTILS_MAGICNUMBERS_H
7#define TRUTHUTILS_MAGICNUMBERS_H
15#if !defined(XAOD_STANDALONE)
65 template <
typename T>
struct is_smart_ptr<
std::shared_ptr<T>> : std::true_type {};
76#if defined(XAOD_STANDALONE)
78 template <
class T>
inline int barcode(
const T& p){
86 template <>
inline int barcode(
const int& p){
return p;}
90 template <
typename T>
inline int uniqueID(
const T& p) {
91 if constexpr (std::is_integral_v<T>) {
94 else if constexpr (std::is_integral_v<std::remove_pointer_t<T>>) {
97 else if constexpr (std::is_same_v<T, xAOD::TruthParticle_v1> || std::is_same_v<T, xAOD::TruthVertex_v1>) {
100 else if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>, xAOD::TruthParticle_v1> || std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>, xAOD::TruthVertex_v1>) {
103 else if constexpr (std::is_same_v<T, CaloCalibrationHit>) {
104 return p.particleUID();
106 else if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>, CaloCalibrationHit>) {
107 return p->particleUID();
117 template <
typename T>
inline int uniqueID(
const T& p) {
118 if constexpr (std::is_integral_v<T>) {
121 else if constexpr (std::is_integral_v<std::remove_pointer_t<T>>) {
124 else if constexpr (std::is_same_v<T, xAOD::TruthParticle_v1> || std::is_same_v<T, xAOD::TruthVertex_v1>) {
127 else if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
xAOD::TruthParticle_v1> || std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
xAOD::TruthVertex_v1>) {
130 else if constexpr (std::is_same_v<T, CaloCalibrationHit>) {
131 return p.particleUID();
133 else if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
CaloCalibrationHit>) {
134 return p->particleUID();
144 template <
typename T>
inline int status(
const T& p) {
145 if constexpr (std::is_integral_v<T>) {
148 else if constexpr (std::is_integral_v<std::remove_pointer_t<T>>) {
158#if !defined(HEPMC3) && !defined(XAOD_STANDALONE)
164 template <
class T>
inline void get_particle_history(
const T& p, std::deque<int>& out,
const int direction = 0) {
167 auto pv = p->production_vertex();
169 for (
auto pa: pv->particles_in()) {
170 if (!pa || pa->pdg_id() != p->pdg_id())
continue;
180 auto pv = p->end_vertex();
182 for (
auto pa: pv->particles_out()) {
183 if (!pa || pa->pdg_id() != p->pdg_id())
continue;
233 else if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
HepMcParticleLink>) {
244 return p.linkIsNull();
246 else if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
HepMcParticleLink>) {
247 return p->linkIsNull();
256 if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
HepMcParticleLink>) {
280 if (id1 ==
id2) {
return true;}
283 if (generations1 == generations2) {
return false; }
284 if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T1>>>,
TrackRecord>) {
286 const int direction = (generations2 > generations1) ? -1 : 1;
288 if (std::find(history2.begin(),history2.end(), id1) == history2.end()) {
return false; }
292 const int direction = (generations1 > generations2) ? -1 : 1;
294 if (std::find(history1.begin(),history1.end(),
id2) == history1.end()) {
return false; }
300 template <
class T1,
class T2>
inline bool is_same_object(
const T1& p1,
const T2& p2) {
311 if (id1 ==
id2) {
return true;}
314 if (generations1 == generations2) {
return false; }
315 if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T1>>>,
TrackRecord>) {
317 constexpr int descendents = 1;
319 if (std::find(history2.begin(),history2.end(), id1) == history2.end()) {
return false; }
323 constexpr int ancestors = -1;
325 if (std::find(history1.begin(),history1.end(),
id2) == history1.end()) {
return false; }
333 if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
HepMcParticleLink>) {
346 if constexpr (std::is_same_v<std::remove_const_t<remove_smart_pointer_t<std::remove_pointer_t<T>>>,
HepMcParticleLink>) {
388 for (
auto p: evt->particles()) {
391 for (
auto v: evt->vertices()) {
395 for (
auto p = evt->particles_begin(); p != evt->particles_end(); ++p) {
396 (*p)->set_status (particle_status ((*p)->barcode(), (*p)->status()));
398 for (
auto v = evt->vertices_begin(); v != evt->vertices_end(); ++v) {
399 (*v)->set_id (vertex_status ((*v)->barcode(), (*v)->id()));
425#if !defined(XAOD_STANDALONE)
431 auto allbarcodes = genEvent->attribute<HepMC::GenEventBarcodes>(
"barcodes");
432 for (
const auto& bp: allbarcodes->barcode_to_particle_map()) {
436 for (
auto currentGenParticle: *genEvent) {
448 auto allbarcodes = genEvent->attribute<HepMC::GenEventBarcodes>(
"barcodes");
449 for (
const auto& bp: allbarcodes->barcode_to_vertex_map()) {
453 HepMC::GenEvent::vertex_const_iterator currentGenVertexIter;
454 for (currentGenVertexIter= genEvent->vertices_begin();
455 currentGenVertexIter!= genEvent->vertices_end();
456 ++currentGenVertexIter) {
457 const int barcode((*currentGenVertexIter)->barcode());
std::pair< std::vector< unsigned int >, bool > res
Class to store calorimeter calibration hit.
a link optimized in size for a GenParticle in a McEventCollection
Class describing a truth particle in the MC record.
Class describing a truth vertex in the MC record.
bool is_same_object(const T1 &p1, const T2 &p2)
Method to establish if two particles/vertices in the GenEvent actually represent the same generated p...
bool is_sim_secondary(const T &p)
Method to establish if a particle (or barcode) is a new seondary created during the simulation (only ...
bool is_truth_suppressed_pileup(const T &p)
Method to establish if a particle (or barcode) corresponds to truth-suppressed pile-up.
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (only to be used in legacy TP convert...
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (only to be used in...
bool is_same_generator_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same generated particle.
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
bool no_truth_link(const T &p)
Method to establish if a if the object is linked to something which was never saved to the HepMC Trut...
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (only to be used in ...
bool is_sim_descendant(const T1 &p1, const T2 &p2)
Method to check if the first particle is a descendant of the second in the simulation,...
bool is_sim_secondary(const T &p)
Method to establish if a particle is a new seondary created during the simulation based on the status...
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation based on the status...
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation from the status.
bool is_same_object(const T1 &p1, const T2 &p2)
Method to establish if two particles/vertices in the GenEvent actually represent the same particle.
bool is_truth_suppressed_pileup(const T &p)
Method to establish if a particle corresponds to truth-suppressed pile-up.
bool is_simulation_particle(const T &p)
Method to establish if a particle was created during the simulation based on the status value.
bool is_same_generator_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same generated particle.
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
bool is_sim_descendant(const T1 &p1, const T2 &p2)
Method to check if the first particle is a descendant of the second in the simulation,...
bool no_truth_link(const T &p)
Method to establish if a if the object is linked to something which was never saved to the HepMC Trut...
int maxGeneratedVertexBarcode(const HepMC::GenEvent *genEvent)
Get the maximal absolute value of barcode of vertex present in the event. Returns a negative number.
bool is_same_generator_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same generated particle.
constexpr int INVALID_PARTICLE_ID
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (TODO migrate to be based on status).
void old_to_new_simulation_scheme(T &evt)
Function that converts the old scheme of labeling the simulation particles (barcodes) into the new sc...
constexpr int UNDEFINED_ID
void get_particle_history(const T &p, std::deque< int > &out, const int direction=0)
Function to calculate all the descendants(direction=1)/ancestors(direction=-1) of the particle.
typename remove_smart_pointer< T >::type remove_smart_pointer_t
constexpr int SUPPRESSED_PILEUP_BARCODE(std::numeric_limits< int32_t >::max())
This barcode is used by objects matched to particles from pile-up interactions in standard MC Product...
constexpr int INVALID_PARTICLE_BARCODE
constexpr int SIM_STATUS_INCREMENT
Constant defining the barcode threshold for regenerated particles, i.e. particles surviving an intera...
HepMC::GenVertex * GenVertexPtr
constexpr int SIM_STATUS_THRESHOLD
Constant definiting the status threshold for simulated particles, eg. can be used to separate generat...
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
int new_vertex_status_from_old(const int oldStatus, const int barcode)
Get vertex status in the new scheme from the barcode and status in the old scheme.
int old_vertex_status_from_new(const int newStatus)
Get vertex status in the old scheme from the status in the new scheme.
bool is_truth_suppressed_pileup(const T &p)
Method to establish if a particle (or barcode) corresponds to truth-suppressed pile-up (TODO update t...
int maxGeneratedParticleBarcode(const HepMC::GenEvent *genEvent)
Get the maximal value of barcode of particle present in the event.
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
constexpr int INVALID_VERTEX_ID
constexpr int FORWARD_TRANSPORT_MODEL_PROCESS
Special Forward transport Geant process for vertices.
int new_particle_status_from_old(const int oldStatus, const int barcode)
Get particle status in the new scheme from the barcode and status in the old scheme.
constexpr bool is_smart_ptr_v
bool no_truth_link(const T &p)
Method to establish if a if the object is linked to something which was never saved to the HepMC Trut...
int old_particle_status_from_new(const int newStatus)
Get particle status in the old scheme from the status in the new scheme.
std::deque< int > simulation_history(const T &p, const int direction)
Function to calculate all the descendants(direction=1)/ancestors(direction=-1) of the particle.
bool is_same_vertex(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same vertex.
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
constexpr int SIM_BARCODE_THRESHOLD
Constant defining the barcode threshold for simulated particles, eg. can be used to separate generato...
bool is_sim_descendant(const T1 &p1, const T2 &p2)
Method to check if the first particle is a descendant of the second in the simulation,...
const HepMC::GenVertex * ConstGenVertexPtr
bool ignoreTruthLink(const T &p, bool vetoPileUp)
Helper function for SDO creation in PileUpTools.
constexpr int SIM_REGENERATION_INCREMENT
Constant defining the barcode threshold for regenerated particles, i.e. particles surviving an intera...
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.