HackAnalysis  2
isolation.h
1 #pragma once
2 
3 #include "heputil.h"
4 #include "math.h"
5 #include <random>
6 #include <functional>
7 #include <cfloat> // for DBL_MAX
8 
17 double d0Calc(const HEP::P4 &xv, const HEP::P4 &p);
18 
20 double dzCalc(const HEP::P4 &xv, const HEP::P4 &p);
21 
22 
24 double dz_sintheta(const HEP::P4 &xv, const HEP::P4 &p);
25 
26 
28 double sumpTisolation(const HEP::P4 &p4, const HEP::Event* evt, const double &DR);
29 
31 double sumETIsolation(const HEP::P4 &p4, const HEP::Event* evt, const double &DR);
32 
33 double totalEventE(const HEP::Event* evt);
34 double medianEventE(const HEP::Event* evt);
35 
36 double sumCaloE(const HEP::P4 &p4, const HEP::Event* evt, const double &DR);
37 double coneAreaApprox(const HEP::P4 &p4, const double &DR);
38 
39 
41 bool IsGradientElectron_ATLAS_Run2(const HEP::Particle* Lep, const HEP::Event* event, std::mt19937& engine);
42 
47 bool IsLooseTightLepton(const HEP::Particle* Lep, const HEP::Event* event,
48  const double DeltaRp, const double DeltaRE, const double pratio, const double Eratio);
49 
55 bool IsHighPTCaloOnly(const HEP::Particle* Lep, const HEP::Event* event, const double DeltaRE);
56 
57 
59 double mTcalc_simple( const HEP::P4 &v1, const HEP::P4 &v2);
60 
61 
62 bool ATLASradiusCalcLepton(const HEP::Particle* lepton,const HEP::Jet* jet);
63 
64 
71 template<typename T1> std::vector<T1*> filterObjects(std::vector<T1*> &vec_t1,const double &pTmin, const double &absEtaMax)
72 {
73  // filters the particles/jets in a vector by pT and eta.
74  std::vector<T1*> result;
75 
76  for(auto t1 : vec_t1)
77  {
78  if( (t1->pT() > pTmin) && (t1->abseta() < absEtaMax))
79  {
80  result.push_back(t1);
81  }
82 
83  }
84 
85  return result;
86 
87 }
88 
98 template<typename T1> std::vector<T1*> filterObjects(std::vector<T1*> &vec_t1,const double &pTmin, const double &absEtaMax, const HEP::Event* evt,std::mt19937 &engine, bool (*select_condition)(T1*,const HEP::Event*, std::mt19937&))
99 {
100  // filters the particles/jets in a vector by pT and eta.
101  std::vector<T1*> result;
102 
103  for(auto t1 : vec_t1)
104  {
105  if( (t1->pT() > pTmin) && (t1->abseta() < absEtaMax))
106  {
107  //double efficiency=eff(t1,evt);
108  //static std::uniform_real_distribution<double> rd(0.0,1.0);
109  //if (rd(engine) < efficiency)
110  if(select_condition(t1,evt,engine))
111  {
112  result.push_back(t1);
113  }
114  }
115 
116  }
117 
118  return result;
119 
120 }
121 
129 template<typename T1> std::vector<T1*> filterObjects(std::vector<T1*> &vec_t1,const HEP::Event* evt,std::mt19937 &engine, bool (*select_condition)(T1*,const HEP::Event*, std::mt19937&) )
130 {
131  // filters the particles/jets in a vector by pT and eta.
132  std::vector<T1*> result;
133 
134  for(auto t1 : vec_t1)
135  {
136 
137  if(select_condition(t1,evt,engine))
138  {
139  result.push_back(t1);
140  }
141 
142  }
143 
144  return result;
145 
146 }
147 
153 template<typename T1> void filterPhaseSpace(std::vector<T1*> &vec_t1, const double &pTmin, const double &absEtaMax)
154 {
155  // filters the particles/jets in a vector by pT and eta.
156 
157 
158  auto it = vec_t1.begin();
159  while(it != vec_t1.end())
160  {
161  //T1* t1 = vec_t1[it];
162  //if( (t1->pT() > pTmin) || (t1->abseta() > absEtaMax))
163  if( ((*it)->pT() < pTmin ) || ((*it)->abseta() > absEtaMax))
164  {
165  it = vec_t1.erase(it);
166  }
167  else
168  {
169  it++;
170  }
171 
172  }
173 
174 }
175 
177 template<typename T1> void delete_and_filterPhaseSpace(std::vector<T1*> &vec_t1, const double &pTmin, const double &absEtaMax)
178 {
179  // filters the particles/jets in a vector by pT and eta.
180 
181  std::vector<T1*> out_vector;
182  for(auto t1 : vec_t1)
183  {
184  if( (t1->pT() < pTmin ) || (t1->abseta() > absEtaMax))
185  {
186  delete t1;
187  }
188  else
189  {
190  out_vector.push_back(t1);
191  }
192 
193  }
194  vec_t1=out_vector;
195 
196 }
197 
198 
199 
200 
201 
202 // Overlap Removal
203 //template<typename T1, typename T2> std::vector<T1*> Removal(std::vector<T1*> &v1, std::vector<T2*> &v2,const double &drmin);
204 
205 // Overlap Removal for electrons with Delta R < min(0.4, 0.04 + 10 GeV/pT) around Jet
206 //template<typename T1, typename T2> std::vector<T1*> RemovalJE(std::vector<T1*> &v1, std::vector<T2*> &v2);
207 
208 
209 // Overlap Removal
210 
211 
213 template<typename T1, typename T2> std::vector<T1*> FullRemoval(std::vector<T1*> &v1, std::vector<T2*> &v2, const double &drmin)
214 {
215  // Determining with objects should be removed, and free memory
216 
217  std::vector<bool> mask(v1.size(),false);
218 
219  for (unsigned int j=0;j<v1.size();j++)
220  {
221  for (unsigned int i=0; !mask[j] && i<v2.size();i++)
222  {
223  if (v2[i]->mom().deltaR_eta(v1[j]->mom()) < drmin)
224  {
225  mask[j]=true;
226  //break;
227  }
228  }
229  };
230  // Building the cleaned container
231  std::vector<T1*> cleaned_v1;
232  for (unsigned int i=0;i<v1.size();i++)
233  {
234  if (!mask[i]) {
235  cleaned_v1.push_back(v1[i]);
236  }
237  else
238  {
239  delete v1[i];
240  }
241 
242  }
243 
244  return cleaned_v1;
245 };
246 
247 
248 
250 template<typename T1, typename T2> std::vector<T1*>
251  Removal(std::vector<T1*> &v1, std::vector<T2*> &v2,
252  const double &drmin)
253 {
254  // Determining with objects should be removed
255 
256  std::vector<bool> mask(v1.size(),false);
257 
258  for (unsigned int j=0;j<v1.size();j++)
259  {
260  for (unsigned int i=0; !mask[j] && i<v2.size();i++)
261  {
262  if (v2[i]->mom().deltaR_eta(v1[j]->mom()) < drmin)
263  {
264  mask[j]=true;
265  //break;
266  }
267  }
268  };
269  // Building the cleaned container
270  std::vector<T1*> cleaned_v1;
271  for (unsigned int i=0;i<v1.size();i++)
272  if (!mask[i]) cleaned_v1.push_back(v1[i]);
273 
274  return cleaned_v1;
275 };
276 
277 
280 template<typename T1, typename T2> std::vector<T1*>
281  Removal(std::vector<T1*> &v1, std::vector<T2*> &v2,
282  const double &drmin,bool (*special_condition)(T1*,T2*))
283 {
284  // Determining with objects should be removed
285 
286  std::vector<bool> mask(v1.size(),false);
287 
288  for (unsigned int j=0;j<v1.size();j++)
289  {
290  for (unsigned int i=0; !mask[j] && i<v2.size();i++)
291  {
292  if (special_condition(v1[j],v2[i]) && (v2[i]->mom().deltaR_eta(v1[j]->mom()) < drmin))
293  {
294  mask[j]=true;
295  //break;
296  }
297  }
298  };
299  // Building the cleaned container
300  std::vector<T1*> cleaned_v1;
301  for (unsigned int i=0;i<v1.size();i++)
302  if (!mask[i]) cleaned_v1.push_back(v1[i]);
303 
304  return cleaned_v1;
305 };
306 
307 
308 
309 
312 template<typename T1> std::vector<T1*> SelfRemoval(std::vector<T1*> &v1, const double &drmin)
313 {
314  // Determining with objects should be removed -- keep the higher pT version. This only applies for electrons anyway
315 
316  std::vector<bool> mask(v1.size(),false);
317 
318  double tdr;
319  for (unsigned int j=0;j<v1.size();j++){
320  for (unsigned int i=j+1;i<v1.size();i++) {
321 
322  tdr=v1[i]->mom().deltaR_eta(v1[j]->mom());
323  if ((tdr < drmin))
324  {
325  if(v1[i]->mom().pT() < v1[j]->mom().pT())
326  {
327  mask[i]=true;
328  }
329  else
330  {
331  mask[j]=true;
332  }
333  }
334 
335  }
336  };
337 
338 
339  // Building the cleaned container
340  std::vector<T1*> cleaned_v1;
341  for (unsigned int i=0;i<v1.size();i++)
342  if (!mask[i]) cleaned_v1.push_back(v1[i]);
343 
344  return cleaned_v1;
345 };
346 
347 
348 
350 template<typename T1, typename T2> std::vector<T1*>
351  RemovalJE(std::vector<T1*> &v1, std::vector<T2*> &v2)
352 {
353  // Determining with objects should be removed
354  double EPT,drmin;
355  std::vector<bool> mask(v1.size(),false);
356  for (unsigned int j=0;j<v1.size();j++)
357  {
358  EPT=v1[j]->pT();
359  drmin=0.04+10.0/EPT;
360  if(drmin > 0.4) drmin=0.4;
361 
362  for (unsigned int i=0;!mask[j] && i<v2.size();i++)
363  if (v2[i]->mom().deltaR_eta(v1[j]->mom()) < drmin)
364  {
365 
366  mask[j]=true;
367  //break;
368  }
369  }
370  // Building the cleaned container
371  std::vector<T1*> cleaned_v1;
372  for (unsigned int i=0;i<v1.size();i++)
373  if (!mask[i]) cleaned_v1.push_back(v1[i]);
374 
375  return cleaned_v1;
376 }
377 
378 
379 
380 /*
381 Selection functions for ATLAS
382 */
383 
389 bool IsLooseElectron_ATLAS_Run2(const HEP::Particle* Lep, const HEP::Event* event, std::mt19937& engine);
390 bool IsTightElectron_ATLAS_Run2(const HEP::Particle* Lep, const HEP::Event* event, std::mt19937& engine);
391 
392 bool IsLooseTightMuon_ATLAS_Run2(const HEP::Particle* Lep, const HEP::Event* event, std::mt19937& engine);
393 
394 bool ED0Sigma5_ATLAS_Run2(const HEP::Particle* Lep, const HEP::Event* event, std::mt19937& engine);
395 bool MuD0Sigma3_ATLAS_Run2(const HEP::Particle* Lep, const HEP::Event* event, std::mt19937& engine);
396 
397 bool BTag70DL1r_ATLAS_Run2(const HEP::Jet* jet, const HEP::Event* event, std::mt19937& engine);
398 
399 
Simple event class, separating particles into classes.
Definition: heputil.h:227
Definition: Jet.h:21
A 4-momentum class for vectors.
Definition: Vectors.h:45
Definition: Particle.h:24
double deltaR_eta(const P4 &a, const P4 &b)
Difference in pseudorapidity-based R between two vectors.
Definition: Vectors.h:618