ATLAS Offline Software
Filters.h
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
12 #ifndef TIDA_FILTERS_H
13 #define TIDA_FILTERS_H
14 
18 
20 
21 
22 #include <cmath>
23 
25 
26 class Filter_True : public TrackFilter {
27 public:
28  bool select( const TIDA::Track* , const TIDARoiDescriptor* =0 ) { return true; }
29 };
30 
31 
32 class Filter_Author : public TrackFilter {
33 public:
34 
35  Filter_Author(const int& author) : m_author(author) { }
36  void setAuthor(unsigned int author) { m_author = author; }
37 
38  bool select( const TIDA::Track* t, const TIDARoiDescriptor* =0 ) {
39  if ( t->author()>m_author ) return false;
40  // if ( std::fabs(t->author())!=m_author ) return false;
41  return true;
42  }
43 
44 private:
45 
46  int m_author;
47 
48 };
49 
50 
51 
52 //Filter truth particles based on their Id
53 class Filter_pdgId : public TrackFilter {
54 public:
55 
56  Filter_pdgId(const unsigned int& pdgId) : m_pdgId(pdgId) { }
57 
58  bool select( const TIDA::Track* t, const TIDARoiDescriptor* =0 ) {
59  //Author stores pdgId
60  if (std::fabs(t->author())!=m_pdgId) return false;
61  return true;
62  }
63 
64 private:
65 
66  int m_pdgId;
67 
68 };
69 
70 
71 
72 //Filter truth particles based on Id and pt and eta
74 
75 public:
76 
77  Filter_pdgIdpTeta(const unsigned int& pdgId, double etaMax, double pTMin) : m_pdgId(pdgId), m_etaMax(etaMax), m_pTMin(pTMin) { }
78 
79  bool select( const TIDA::Track* t, const TIDARoiDescriptor* /*r=0*/ ) {
80  //Author stores pdgId
81  if ( std::abs(t->author())!=m_pdgId ||
82  std::fabs(t->eta())>m_etaMax ||
83  std::fabs(t->pT())<m_pTMin) return false;
84 
85  return true;
86  }
87 
88 private:
89 
90  int m_pdgId;
91  double m_etaMax;
92  double m_pTMin;
93 };
94 
95 
96 
97 
98 //Set upper and lower pT and upper eta bound
99 class Filter_Bound : public TrackFilter {
100 public:
101  Filter_Bound(const double &eta_max, const double &pT_min, const double &pT_max) :
102  m_pT_max(pT_max),
103  m_pT_min(pT_min),
104  m_eta_max(eta_max) {}
105 
106  bool select ( const TIDA::Track* t, const TIDARoiDescriptor* =0) {
107  if (std::fabs(t->eta()) > m_eta_max) return false;
108  if (std::fabs(t->pT()) > m_pT_max) return false;
109  if (std::fabs(t->pT()) < m_pT_min) return false;
110  return true;
111  }
112 private:
113  double m_pT_max;
114  double m_pT_min;
115  double m_eta_max;
116 };
117 
118 
119 //class Filter_Roi : public TrackFilter {
120 // public:
121 //
122 // Filter_Roi() : m_set(false), m_roi(0) {
123 // std::cout << "Filter_Roi::Filter_Roi" << std::endl;
124 // }
125 //
126 // void setRoi( TIDARoiDescriptor* roi ) { m_roi = roi; m_set = true; }
127 //
128 // bool select( const Track* t, const TIDARoiDescriptor* r=0 ) {
129 //
130 // // std::cout << "select()" << std::endl;
131 //
132 // if ( r==0 ) r = m_roi;
133 // if ( r==0 ) { std::cerr << "roi not set" << std::endl; return false; }
134 // double deta = t->eta() - r->eta();
135 // double dphi = t->phi() - r->phi();
136 //
137 // if ( dphi<-M_PI ) dphi += M_PI;
138 // if ( dphi>M_PI ) dphi -= M_PI;
139 //
140 // if ( std::fabs(deta)<r->etaHalfWidth() &&
141 // std::fabs(dphi)<r->phiHalfWidth() ) return true;
142 // else return false;
143 //
144 // }
145 //
146 // private:
147 //
148 // bool m_set;
149 // TIDARoiDescriptor* m_roi;
150 //
151 //};
152 
153 
154 
155 class Filter_Vertex : public TrackFilter {
156 public:
157 
158  Filter_Vertex(double d0Cut, double z0Cut) : m_d0Cut(d0Cut), m_z0Cut(z0Cut) {
159  std::cout << "Filter_Vertex::Filter_Vertex() with d0 cut " << m_d0Cut << "\tz0 cut " << m_z0Cut << std::endl;
162  }
163 
164  virtual ~Filter_Vertex() { }
165 
166  void setVertex(const TIDA::Vertex& v) {
167  m_v.clear();
168  m_v.push_back(v);
169  }
170 
171  void setVertex(const std::vector<TIDA::Vertex>& vv) {
172  m_v.clear();
173  m_v = vv;
174  }
175 
176  bool select( const TIDA::Track* t, const TIDARoiDescriptor* =0 ) {
179 
180  // std::cout << "Filter_Vertex::select() " << *t << "\t" << m_v.size() << std::endl;
181 
182  if ( m_v.size()==0 ) return true;
183 
184  for (unsigned int i=0 ; i<m_v.size() ; i++ ) {
185 
186  double* v = m_v[i].position();
188  // double a0 = t->a0() + v[0]*std::sin( t->phi() ) - v[1]*std::cos( t->phi() );
189  double a0 = t->a0();
190 
192 
193  double theta = 2*std::atan(std::exp( -t->eta() ));
194  // double z = t->z0() + ( v[0]*std::cos( t->phi() ) + v[1]*std::sin( t->phi() ) )/std::atan(theta);
195  double z = t->z0();
196  double z0sin = (z-v[2])*std::sin(theta);
197 
198 
199  // std::cout << "Filter_Vertex::select()"
200  // << "\ta0 " << std::fabs(a0) << "(" << m_d0Cut << ")"
201  // << "\tz0sin " << std::fabs(z0sin) << "(" << m_z0Cut << ")"
202  // << std::endl;
203 
205  if ( std::fabs(a0)<m_d0Cut && std::fabs(z0sin)<m_z0Cut ) return true;
206  }
207 
208  return false;
209  }
210 
211 private:
212 
213  double m_d0Cut;
214  double m_z0Cut;
215 
216  std::vector<TIDA::Vertex> m_v;
217 
218 };
219 
220 
221 
222 
223 
224 
225 class Filter_Combined : public TrackFilter {
226 
227 public:
228 
230  m_f1(f1), m_f2(f2), m_roi(0),
231  m_debugPrintout(false),
232  m_containPhi(true),
233  m_contain(false)
234  { }
235 
236  void setRoi( TIDARoiDescriptor* r ) { m_roi = r; }
237 
238 
241 
242  void containtracks( bool b=true ) { m_contain=b; }
243 
246 
247  void containtracksPhi( bool b=true ) { m_containPhi=b; }
248 
249 
250  bool contains( const TIDA::Track* t, const TIDARoiDescriptor* r ) const {
251 
252  if ( r==0 ) {
253  std::cerr << "Filter_Combined::contains() called with null roidescriptor" << std::endl;
254  return true;
255  }
256 
257  if ( r->composite() ) {
258  for ( unsigned i=r->size() ; i-- ; ) if ( contains( t, r->at(i) ) ) return true;
259  }
260  else {
261 
262  if ( r->isFullscan() ) return true;
263 
264  bool contained_phi = false;
265 
268  if ( r->phiMinus()<r->phiPlus() ) contained_phi = ( t->phi()>r->phiMinus() && t->phi()<r->phiPlus() );
269  else contained_phi = ( t->phi()>r->phiMinus() || t->phi()<r->phiPlus() );
270 
271  bool contained_zed = ( t->z0()>r->zedMinus() && t->z0()<r->zedPlus() );
272 
275  bool contained_eta = ( t->eta()<r->etaPlus() && t->eta()>r->etaMinus() );
276 
277  if ( m_contain || m_containPhi ) {
278 
281 
282  double rexit = 0;
283  double zexit = 0;
284 
285  // double tantheta = TIDARoiDescriptor::exitpoint( t->z0(), t->eta(), zexit, rexit );
286 
287  TIDARoiDescriptor::exitpoint( t->z0(), t->eta(), zexit, rexit );
288 
292 
293  double cross0 = zexit*r->rMinusZed() - rexit*r->zedMinusR();
294  double cross1 = zexit*r->rPlusZed() - rexit*r->zedPlusR();
295 
296  if ( m_contain ) {
297  if ( cross0>0 && cross1<0 ) contained_eta=true;
298  else contained_eta=false;
299  }
300 
302 
303  double newphi = outerphi( t->pT(), t->phi(), rexit );
304 
305  if ( newphi==0 ) return false;
306 
307  if ( r->phiMinus()<r->phiPlus() ) contained_phi &= ( newphi>r->phiMinus() && newphi<r->phiPlus() );
308  else contained_phi &= ( newphi>r->phiMinus() || newphi<r->phiPlus() );
309 
310  }
311 
312  if ( contained_eta &&
313  contained_phi &&
314  contained_zed ) {
315  if ( m_debugPrintout ) std::cout << "\tFilter::inside roi" << std::endl;
316  return true;
317  }
318 
319  }
320 
321  return false;
322 
323  }
324 
325 
326  bool select( const TIDA::Track* t, const TIDARoiDescriptor* r=0 ) {
327 
328  if ( r!=0 ) m_roi = r;
329 
330  if ( m_debugPrintout ) {
331  std::cout << "\tFilter: " << this << "\tfilter1 " << m_f1->select(t,m_roi) << "\tfilter2 " << m_f2->select(t,m_roi) << "\troi " << m_roi << std::endl;
332  }
333 
335  if ( m_roi==0 ) return ( m_f1->select(t,r) && m_f2->select(t,r) );
336  else {
337 
338  if ( m_debugPrintout ) {
339  std::cout << "\tFilter::filter1 " << m_f1->select(t,m_roi) << "\tfilter2 " << m_f2->select(t,m_roi) << "\troi " << *m_roi << std::endl;
340  }
341 
342  if ( contains( t, m_roi ) ) return ( m_f1->select(t,m_roi) && m_f2->select(t,m_roi) );
343  else return false;
344 
345  }
346  }
347 
348  void setDebug(bool b) { m_debugPrintout=b; }
349 
350 public:
351 
352 
355 
356  static double outerphi( double pt, double phi, double r=1000 ) {
357 
359 
360  double mqR = 10*pt/(2.99792458*2); // 2.998=speed of light, 2=Atlas B field
361 
362  double ratio = 0.5*r/mqR;
363 
364  double newphi = phi;
365 
368  if ( std::fabs(ratio)>1 ) return 0;
369 
371  newphi -= std::asin( ratio );
372 
374  while ( newphi<-M_PI ) newphi += 2*M_PI;
375  while ( newphi> M_PI ) newphi -= 2*M_PI;
376 
377  return newphi;
378 
379  }
380 
381 private:
382 
385 
387 
389 
391  bool m_contain;
392 
393 };
394 
395 
396 #endif // TIDA_FILTERS_H
397 
Filter_Author::select
bool select(const TIDA::Track *t, const TIDARoiDescriptor *=0)
Definition: Filters.h:38
Filter_pdgId::select
bool select(const TIDA::Track *t, const TIDARoiDescriptor *=0)
Definition: Filters.h:58
beamspotman.r
def r
Definition: beamspotman.py:676
Filter_Bound::select
bool select(const TIDA::Track *t, const TIDARoiDescriptor *=0)
Definition: Filters.h:106
Filter_Vertex::m_v
std::vector< TIDA::Vertex > m_v
Definition: Filters.h:216
Filter_Combined::m_f2
TrackFilter * m_f2
Definition: Filters.h:384
Filter_Vertex
Definition: Filters.h:155
Filter_pdgIdpTeta::Filter_pdgIdpTeta
Filter_pdgIdpTeta(const unsigned int &pdgId, double etaMax, double pTMin)
Definition: Filters.h:77
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
Filter_Vertex::m_z0Cut
double m_z0Cut
Definition: Filters.h:214
TrackFilter
Definition: TrackFilter.h:26
Filter_pdgIdpTeta::m_etaMax
double m_etaMax
Definition: Filters.h:91
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
TIDAVertex.h
Filter_Vertex::m_d0Cut
double m_d0Cut
Definition: Filters.h:213
TIDARoiDescriptor::exitpoint
static double exitpoint(double tz0, double teta, double &zexit, double &rexit)
Definition: TIDARoiDescriptor.cxx:32
test_pyathena.pt
pt
Definition: test_pyathena.py:11
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Filter_Author::setAuthor
void setAuthor(unsigned int author)
Definition: Filters.h:36
xAOD::etaMax
etaMax
Definition: HIEventShape_v2.cxx:46
Filter_Combined::select
bool select(const TIDA::Track *t, const TIDARoiDescriptor *r=0)
Definition: Filters.h:326
TIDARoiDescriptor
Describes the Region of Ineterest geometry It has basically 8 parameters.
Definition: TIDARoiDescriptor.h:42
Filter_Combined::outerphi
static double outerphi(double pt, double phi, double r=1000)
calculate the (very approximate) phi position for a track at a rafius r
Definition: Filters.h:356
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Filter_Combined::contains
bool contains(const TIDA::Track *t, const TIDARoiDescriptor *r) const
Definition: Filters.h:250
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
Filter_Vertex::setVertex
void setVertex(const std::vector< TIDA::Vertex > &vv)
Definition: Filters.h:171
TrackFilter::select
virtual bool select(const TIDA::Track *t, const TIDARoiDescriptor *r=0)=0
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
Filter_Author::m_author
int m_author
Definition: Filters.h:46
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
Filter_Author::Filter_Author
Filter_Author(const int &author)
Definition: Filters.h:35
read_hist_ntuple.f2
f2
Definition: read_hist_ntuple.py:20
Filter_pdgIdpTeta::select
bool select(const TIDA::Track *t, const TIDARoiDescriptor *)
Definition: Filters.h:79
Filter_pdgIdpTeta
Definition: Filters.h:73
Filter_Combined::m_debugPrintout
bool m_debugPrintout
Definition: Filters.h:388
Filter_Bound::m_eta_max
double m_eta_max
Definition: Filters.h:115
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
Filter_Bound::m_pT_min
double m_pT_min
Definition: Filters.h:114
Filter_Combined::m_containPhi
bool m_containPhi
Definition: Filters.h:390
Filter_Bound::m_pT_max
double m_pT_max
Definition: Filters.h:113
Filter_Combined::m_contain
bool m_contain
Definition: Filters.h:391
Filter_Vertex::Filter_Vertex
Filter_Vertex(double d0Cut, double z0Cut)
Definition: Filters.h:158
Filter_Vertex::~Filter_Vertex
virtual ~Filter_Vertex()
Definition: Filters.h:164
Filter_etaPT.h
Filter_Bound::Filter_Bound
Filter_Bound(const double &eta_max, const double &pT_min, const double &pT_max)
Definition: Filters.h:101
a0
double a0
Definition: globals.cxx:27
Filter_True
default simple filter which accepts all tracks
Definition: Filters.h:26
Filter_pdgId::Filter_pdgId
Filter_pdgId(const unsigned int &pdgId)
Definition: Filters.h:56
Filter_TrackQuality.h
TIDA::Vertex
Definition: TIDAVertex.h:23
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Filter_Combined
Definition: Filters.h:225
Filter_Vertex::select
bool select(const TIDA::Track *t, const TIDARoiDescriptor *=0)
Definition: Filters.h:176
Filter_Combined::Filter_Combined
Filter_Combined(TrackFilter *f1, TrackFilter *f2)
Definition: Filters.h:229
Filter_Combined::containtracks
void containtracks(bool b=true)
set / unset the flag to determine whether tracks should be fully contained in the RoI or not
Definition: Filters.h:242
python.PyAthena.v
v
Definition: PyAthena.py:157
Filter_Combined::setRoi
void setRoi(TIDARoiDescriptor *r)
Definition: Filters.h:236
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
Filter_pdgId
Definition: Filters.h:53
Filter_pdgIdpTeta::m_pdgId
int m_pdgId
Definition: Filters.h:90
Filter_Combined::setDebug
void setDebug(bool b)
Definition: Filters.h:348
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:26
Filter_Author
Definition: Filters.h:32
TIDA::Track
Definition: Trigger/TrigAnalysis/TrigInDetAnalysis/TrigInDetAnalysis/Track.h:26
Filter_Combined::m_f1
TrackFilter * m_f1
Definition: Filters.h:383
Filter_Combined::containtracksPhi
void containtracksPhi(bool b=true)
set / unset to allow the strict phi containment to be used even if the full rigorous containement is ...
Definition: Filters.h:247
Filter_Bound
Definition: Filters.h:99
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Filter_Vertex::setVertex
void setVertex(const TIDA::Vertex &v)
Definition: Filters.h:166
PlotCalibFromCool.vv
vv
Definition: PlotCalibFromCool.py:716
Filter_Track.h
Filter_pdgId::m_pdgId
int m_pdgId
Definition: Filters.h:66
Filter_pdgIdpTeta::m_pTMin
double m_pTMin
Definition: Filters.h:92
Filter_Combined::m_roi
const TIDARoiDescriptor * m_roi
Definition: Filters.h:386
read_hist_ntuple.f1
f1
Definition: read_hist_ntuple.py:4
Filter_True::select
bool select(const TIDA::Track *, const TIDARoiDescriptor *=0)
Definition: Filters.h:28