ATLAS Offline Software
Loading...
Searching...
No Matches
DecayProducts.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef TRUTHUTILS_DECAYPRODUCTS_H
5#define TRUTHUTILS_DECAYPRODUCTS_H
6#include <vector>
7#include <type_traits>
8#include <algorithm>
9#include <map>
10#include <vector>
13template <class T> class DecayBase {
14public:
15 void count(const int c) { m_pids[c]++; m_apids[std::abs(c)]++; m_size++;}
16 int pd(int i) const { return m_pids.count(i)?m_pids.at(i):0; }
17 int pd(int i1, int i2) const { int ret = 0; for ( auto & a: m_pids) if (i1 <= a.first && a.first <= i2) ret += a.second; return ret; }
18 int apd(int i1, int i2) const { int ret = 0; for ( auto & a: m_apids) if (i1 <= a.first && a.first <= i2) ret += a.second; return ret; }
19 int apd(int i) const { return m_apids.count(i)?m_apids.at(i):0; }
20 int pd(const std::vector<int>& i) const { int ret = 0; for ( auto ii: i) ret += pd(ii); return ret;}
21 int apd(const std::vector<int>& i) const { int ret = 0; for ( auto ii: i) ret += apd(ii); return ret; }
22 size_t size() const { return m_size; }
23 int apply(bool (*func)(const int&)) const { int ret = 0; for ( auto & a: m_pids) if (func(a.first)) ret+=a.second; return ret; }
24 std::map<int,int> m_pids;
25 std::map<int,int> m_apids;
26 size_t m_size;
27};
28#ifdef ATLASHEPMC_GENEVENT_H
29#ifdef ATLASHEPMC_GENPARTICLE_H
30 template <class Y,std::enable_if_t<std::is_same<Y, HepMC::GenParticlePtr>::value ||std::is_same<Y, HepMC::ConstGenParticlePtr>::value, bool > = true >
31 DecayBase<Y> DecayProducts(const Y& p) {
33 auto v = p->end_vertex();
34 if (v) for (auto prod: *v) if (prod) t.count(prod->pdg_id());
35 return t;
36 }
37#endif
38#ifdef ATLASHEPMC_GENVERTEX_H
39 template <class Y,std::enable_if_t<std::is_same<Y, HepMC::GenVertexPtr>::value ||std::is_same<Y, HepMC::ConstGenVertexPtr>::value, bool > = true>
40 DecayBase<Y> DecayProducts(const Y& p) {
42 if (p) for (auto prod: *p) if (prod) t.count(prod->pdg_id());
43 return t;
44 }
45#endif
46#endif
47#ifdef XAODTRUTH_TRUTHPARTICLE_H
48 template <class Y,std::enable_if_t<std::is_same<Y, xAOD::TruthParticle>::value, bool > = true>
49 DecayBase<Y> DecayProducts(const Y& p) {
51 auto v = p.end_vertex();
52 if (v) for (auto prod: v->particles_out()) if (prod) t.count(prod->pdg_id());
53 return t;
54 }
55 template <class Y,std::enable_if_t<std::is_same<Y, xAOD::TruthParticle*>::value || std::is_same<Y, xAOD::TruthParticle const*>::value , bool > = true>
56 DecayBase<Y> DecayProducts(const Y& p) {
58 auto v = p->end_vertex();
59 if (v) for (auto prod: v->particles_out()) if (prod) t.count(prod->pdg_id());
60 return t;
61 }
62 template <class Y,std::enable_if_t<std::is_same<Y, std::vector<const xAOD::TruthParticle*> >::value, bool > = true>
63 DecayBase<Y> DecayProducts(const Y& p) {
65 for (auto prod: p) if (prod) t.count(prod->pdg_id());
66 return t;
67 }
68#endif
69#ifdef XAODTRUTH_TRUTHVERTEX_H
70 template <class Y,std::enable_if_t<std::is_same<Y, xAOD::TruthVertex*>::value || std::is_same<Y, xAOD::TruthVertex const*>::value , bool > = true>
71 DecayBase<Y> DecayProducts(const Y& p) {
73 if (p) for (auto prod: p->particles_out()) if (prod) t.count(prod->pdg_id());
74 return t;
75 }
76#endif
77#endif
static Double_t a
A class that allows for a fast calculation of the flavours of the descendants of a vertex,...
int apply(bool(*func)(const int &)) const
int pd(int i1, int i2) const
int apd(int i) const
int apd(const std::vector< int > &i) const
void count(const int c)
int pd(int i) const
size_t m_size
std::map< int, int > m_apids
int apd(int i1, int i2) const
int pd(const std::vector< int > &i) const
std::map< int, int > m_pids
size_t size() const