ATLAS Offline Software
Loading...
Searching...
No Matches
AncestorFinder.h
Go to the documentation of this file.
1
11
12
13#ifndef IDTPM2_ANCESTORFINDER_H
14#define IDTPM2_ANCESTORFINDER_H
15
16#include "ConfiguredValue.h"
17
18#include <cmath>
19
20
23
24namespace IDTPM2 {
25
26template<typename T>
27class IFinder {
28
29public:
30
31 virtual ~IFinder() = default;
32
33 const T* findAncestor(const T* t) const {
34
35 // reached the end ...
36 if (!t) return 0;
37
39 if ( predicate(t) ) return t;
40
41 for ( size_t p=0 ; p<t->nParents() ; p++ ) {
42 const T* parent = t->parent(p);
43
44 if ( parent==t ) continue;
45
47 if ( const T* found = findAncestor(parent) ) return found;
48 }
49
50 return 0;
51 }
52
53 virtual bool predicate( const T* t ) const = 0;
54
55};
56
57
58
60
61template<typename T, typename Predicate>
62class GenericAncestorFinder : public IFinder<T> {
63
64public:
65
66 GenericAncestorFinder( Predicate p ) : m_predicate(p) { }
67
68 bool predicate( const T* t ) const override { return m_predicate(t); }
69
70private:
71
72 Predicate m_predicate;
73
74};
75
76
77
80
81template<typename T>
83public:
84 virtual ~IPredicate() {}
85 virtual bool operator()(const T* t) const = 0;
86};
87
88
89
95
96template<typename T>
97class PdgIdHelper : public IPredicate<T> {
98
99public:
100
101 PdgIdHelper(int pdgid) : m_pdgid(std::abs(pdgid)) {}
102
107 bool operator()(const T* t) const { return std::abs(t->pdgId()) == m_pdgid; }
108
109private:
110
112
113};
114
115
116
117template<typename T>
118class PtHelper : public IPredicate<T> {
119
120public:
121
123
125 bool operator()(const T* t) const {
126 if ( std::abs(t->pt()) < m_pt ) return false;
127 return true;
128 }
129
130private:
131
133
134};
135
136
137template<typename T, typename U=T>
138class PtPdgIdHelper : public IPredicate<T> {
139
140public:
141
143 m_pt(pt), m_pdgid(pdgid) {}
144
146 bool operator()(const T* t) const {
147 if ( std::abs(t->pt()) < m_pt ) return false;
148 if ( std::abs(t->template as<U>()->pdgId()) != m_pdgid ) return false;
149 return true;
150 }
151
152private:
153
156
157};
158
159
160
161
165
166template<typename T>
167class PdgAncestorFinder : public GenericAncestorFinder<T, PdgIdHelper<T>> {
168public:
170};
171
172
173
174
180
181template<typename T, typename P=bool (*)(const T*)>
186
187
188
189
194
195template<typename T>
196class HadronAncestorFinder : public IFinder<T> {
197
198public:
199
200 using Predicate = bool (T::*)() const;
201
203
204 bool predicate( const T* t ) const override { return (t->*m_predicate)(); }
205
206private:
207
209
210};
211
212
213} // namespace IDTPM2
214
215
216#endif // IDTPM2_ANCESTORFINDER_H
217
218
219
220
221
222
223
224
225
226
static Double_t P(Double_t *tt, Double_t *par)
bool predicate(const T *t) const override
bool predicate(const T *t) const override
virtual ~IFinder()=default
const T * findAncestor(const T *t) const
virtual bool predicate(const T *t) const =0
predicate base class, so we can take any predicates and store them on a vector or in a unique_ptr<IPr...
virtual bool operator()(const T *t) const =0
and a specific PDG ID helper, so we can select particles of a particular type NB: this is a class,...
bool operator()(const T *t) const
this is quite clever - if we want to pass in an actual class the if we defined operator() then for an...
bool operator()(const T *t) const
this is quite clever - can pass the class instance and use it like a function
PtHelper(ConfiguredValue< float > pt={})
ConfiguredValue< float > m_pt
bool operator()(const T *t) const
this is quite clever - can pass the class instance and use it like a function
PtPdgIdHelper(ConfiguredValue< float > pt={}, const ConfiguredValue< int > pdgid={})
ConfiguredValue< float > m_pt
ConfiguredValue< int > m_pdgid
Search the ancestor history, looking for an ancestor that satifies the predicate ....
Definition AnalysisR4.h:31
STL namespace.