ATLAS Offline Software
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>
13 template <class T> class DecayBase {
14 public:
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
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
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
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  }
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
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
DecayBase::apply
int apply(bool(*func)(const int &)) const
Definition: DecayProducts.h:23
DecayBase::apd
int apd(int i1, int i2) const
Definition: DecayProducts.h:18
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
DecayBase
A class that allows for a fast calculation of the flavours of the descendants of a vertex,...
Definition: DecayProducts.h:13
athena.value
value
Definition: athena.py:122
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DecayBase::size
size_t size() const
Definition: DecayProducts.h:22
DecayBase::m_size
size_t m_size
Definition: DecayProducts.h:26
DecayBase::apd
int apd(int i) const
Definition: DecayProducts.h:19
DecayBase::m_pids
std::map< int, int > m_pids
Definition: DecayProducts.h:24
lumiFormat.i
int i
Definition: lumiFormat.py:92
ret
T ret(T t)
Definition: rootspy.cxx:260
Monitored::Y
@ Y
Definition: HistogramFillerUtils.h:24
DecayBase::pd
int pd(int i1, int i2) const
Definition: DecayProducts.h:17
python.PyAthena.v
v
Definition: PyAthena.py:157
a
TList * a
Definition: liststreamerinfos.cxx:10
DecayBase::pd
int pd(const std::vector< int > &i) const
Definition: DecayProducts.h:20
DecayBase::m_apids
std::map< int, int > m_apids
Definition: DecayProducts.h:25
python.compressB64.c
def c
Definition: compressB64.py:93
DecayBase::count
void count(const int c)
Definition: DecayProducts.h:15
DecayBase::pd
int pd(int i) const
Definition: DecayProducts.h:16
DecayBase::apd
int apd(const std::vector< int > &i) const
Definition: DecayProducts.h:21