gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
Utils.cpp
Go to the documentation of this file.
3 #include <iostream>
4 using namespace std;
5 
6 namespace Gambit {
7  namespace ColliderBit {
8 
9 
10  bool random_bool(double eff) {
12  return Random::draw() < eff;
13  }
14 
15 
16  void filtereff(std::vector<HEPUtils::Particle*>& particles, double eff, bool do_delete) {
17  if (particles.empty()) return;
18  auto keptParticlesEnd = std::remove_if(particles.begin(), particles.end(),
19  [&](HEPUtils::Particle* p) {
20  const bool rm = !random_bool(eff);
21  if (do_delete && rm) delete p;
22  return rm;
23  } );
24  particles.erase(keptParticlesEnd, particles.end());
25  }
26 
27 
29  void filtereff(std::vector<HEPUtils::Particle*>& particles, std::function<double(HEPUtils::Particle*)> eff_fn, bool do_delete) {
30  if (particles.empty()) return;
31  auto keptParticlesEnd = std::remove_if(particles.begin(), particles.end(),
32  [&](HEPUtils::Particle* p) {
33  const double eff = eff_fn(p);
34  const bool rm = !random_bool(eff);
35  if (do_delete && rm) delete p;
36  return rm;
37  } );
38  particles.erase(keptParticlesEnd, particles.end());
39  }
40 
41 
42  // Utility function for filtering a supplied particle vector by sampling wrt a binned 1D efficiency map in pT
43  void filtereff_pt(std::vector<HEPUtils::Particle*>& particles, const HEPUtils::BinnedFn1D<double>& eff_pt, bool do_delete) {
44  if (particles.empty()) return;
45  auto keptParticlesEnd = std::remove_if(particles.begin(), particles.end(),
46  [&](const HEPUtils::Particle* p) {
47  const bool rm = !random_bool(eff_pt, p->pT());
48  if (do_delete && rm) delete p;
49  return rm;
50  } );
51  particles.erase(keptParticlesEnd, particles.end());
52  }
53 
54 
55  // Utility function for filtering a supplied particle vector by sampling wrt a binned 2D efficiency map in |eta| and pT
56  void filtereff_etapt(std::vector<HEPUtils::Particle*>& particles, const HEPUtils::BinnedFn2D<double>& eff_etapt, bool do_delete) {
57  if (particles.empty()) return;
58  auto keptParticlesEnd = std::remove_if(particles.begin(), particles.end(),
59  [&](const HEPUtils::Particle* p) {
60  const bool rm = !random_bool(eff_etapt, p->abseta(), p->pT());
61  if (do_delete && rm) delete p;
62  return rm;
63  } );
64  particles.erase(keptParticlesEnd, particles.end());
65  }
66 
67 
68  // Utility function for returning a collection of same-flavour, oppsosite-sign particle pairs
69  std::vector<std::vector<HEPUtils::Particle*>> getSFOSpairs(std::vector<HEPUtils::Particle*> particles) {
70  std::vector<std::vector<HEPUtils::Particle*>> SFOSpair_container;
71  for (size_t ip1=0; ip1<particles.size(); ip1++) {
72  for (size_t ip2=ip1+1; ip2<particles.size(); ip2++) {
73  if (particles[ip1]->abspid()==particles[ip2]->abspid() && particles[ip1]->pid()!=particles[ip2]->pid()) {
74  std::vector<HEPUtils::Particle*> SFOSpair;
75  SFOSpair.push_back(particles[ip1]);
76  SFOSpair.push_back(particles[ip2]);
77  SFOSpair_container.push_back(SFOSpair);
78  }
79  }
80  }
81  return SFOSpair_container;
82  }
83 
84 
85  // Utility function for returning a collection of oppsosite-sign particle pairs
86  std::vector<std::vector<HEPUtils::Particle*>> getOSpairs(std::vector<HEPUtils::Particle*> particles) {
87  std::vector<std::vector<HEPUtils::Particle*>> OSpair_container;
88  for (size_t ip1=0;ip1<particles.size();ip1++) {
89  for (size_t ip2=ip1+1; ip2<particles.size(); ip2++) {
90  if (particles[ip1]->pid()*particles[ip2]->pid()<0.) {
91  std::vector<HEPUtils::Particle*> OSpair;
92  OSpair.push_back(particles[ip1]);
93  OSpair.push_back(particles[ip2]);
94  OSpair_container.push_back(OSpair);
95  }
96  }
97  }
98  return OSpair_container;
99  }
100 
101 
102  // Utility function for returning a collection of same-sign particle pairs
103  std::vector<std::vector<HEPUtils::Particle*>> getSSpairs(std::vector<HEPUtils::Particle*> particles) {
104  std::vector<std::vector<HEPUtils::Particle*>> SSpair_container;
105  for (size_t ip1=0;ip1<particles.size();ip1++) {
106  for (size_t ip2=ip1+1; ip2<particles.size(); ip2++) {
107  if (particles[ip1]->pid()*particles[ip2]->pid()>0.) {
108  std::vector<HEPUtils::Particle*> SSpair;
109  SSpair.push_back(particles[ip1]);
110  SSpair.push_back(particles[ip2]);
111  SSpair_container.push_back(SSpair);
112  }
113  }
114  }
115  return SSpair_container;
116  }
117 
118  }
119 }
void filtereff(std::vector< HEPUtils::Particle *> &particles, double eff, bool do_delete=false)
Utility function for filtering a supplied particle vector by sampling wrt an efficiency scalar...
Definition: Utils.cpp:16
STL namespace.
std::vector< std::vector< HEPUtils::Particle * > > getSSpairs(std::vector< HEPUtils::Particle *> particles)
Utility function for returning a collection of same-sign particle pairs.
Definition: Utils.cpp:103
void filtereff_pt(std::vector< HEPUtils::Particle *> &particles, const HEPUtils::BinnedFn1D< double > &eff_pt, bool do_delete=false)
Utility function for filtering a supplied particle vector by sampling wrt a binned 1D efficiency map ...
Definition: Utils.cpp:43
std::vector< std::vector< HEPUtils::Particle * > > getOSpairs(std::vector< HEPUtils::Particle *> particles)
Utility function for returning a collection of oppsosite-sign particle pairs.
Definition: Utils.cpp:86
A threadsafe interface to the STL random number generators.
void filtereff_etapt(std::vector< HEPUtils::Particle *> &particles, const HEPUtils::BinnedFn2D< double > &eff_etapt, bool do_delete=false)
Utility function for filtering a supplied particle vector by sampling wrt a binned 2D efficiency map ...
Definition: Utils.cpp:56
std::vector< std::vector< HEPUtils::Particle * > > getSFOSpairs(std::vector< HEPUtils::Particle *> particles)
Utility function for returning a collection of same-flavour, oppsosite-sign particle pairs...
Definition: Utils.cpp:69
TODO: see if we can use this one:
Definition: Analysis.hpp:33
bool random_bool(double eff)
Return a random true/false at a success rate given by a number.
Definition: Utils.cpp:10