rivet is hosted by Hepforge, IPPP Durham
Rivet  2.7.0
SmearedParticles.hh
1 // -*- C++ -*-
2 #ifndef RIVET_SmearedParticles_HH
3 #define RIVET_SmearedParticles_HH
4 
5 #include "Rivet/Particle.hh"
6 #include "Rivet/Projection.hh"
7 #include "Rivet/Projections/ParticleFinder.hh"
8 #include "Rivet/Tools/SmearingFunctions.hh"
9 
10 namespace Rivet {
11 
12 
13  // Recursive variadic template arg decoding
14  namespace {
15  template<typename T>
16  vector<ParticleEffSmearFn>& toEffSmearFns(vector<ParticleEffSmearFn>& v, const T& t) {
17  v.push_back(ParticleEffSmearFn(t));
18  return v;
19  }
20  template<typename T, typename... ARGS>
21  vector<ParticleEffSmearFn>& toEffSmearFns(vector<ParticleEffSmearFn>& v, const T& first, ARGS... args) {
22  v.push_back(ParticleEffSmearFn(first));
23  toEffSmearFns(v, args...);
24  return v;
25  }
26  }
27 
28 
29 
32  public:
33 
35 
36 
39  double eff,
40  const Cut& c=Cuts::open())
41  : SmearedParticles(pf, {{eff}}, c)
42  { }
43 
46  const ParticleEffFn& effFn,
47  const Cut& c=Cuts::open())
48  : SmearedParticles(pf, {{effFn}}, c)
49  { }
50 
53  double eff, const ParticleSmearFn& smearFn,
54  const Cut& c=Cuts::open())
55  : SmearedParticles(pf, {eff, smearFn}, c)
56  { }
57 
60  const ParticleSmearFn& smearFn, double eff,
61  const Cut& c=Cuts::open())
62  : SmearedParticles(pf, {smearFn, eff}, c)
63  { }
64 
67  const ParticleEffFn& effFn, const ParticleSmearFn& smearFn,
68  const Cut& c=Cuts::open())
69  : SmearedParticles(pf, {effFn, smearFn}, c)
70  { }
71 
74  const ParticleSmearFn& smearFn, const ParticleEffFn& effFn,
75  const Cut& c=Cuts::open())
76  : SmearedParticles(pf, {smearFn, effFn}, c)
77  { }
78 
81  const vector<ParticleEffSmearFn>& effSmearFns,
82  const Cut& c=Cuts::open())
83  : ParticleFinder(c),
84  _detFns(effSmearFns)
85  {
86  setName("SmearedParticles");
87  addProjection(pf, "TruthParticles");
88  }
89 
92  const initializer_list<ParticleEffSmearFn>& effSmearFns,
93  const Cut& c=Cuts::open())
94  : SmearedParticles(pf, vector<ParticleEffSmearFn>{effSmearFns}, c)
95  { }
96 
100  template<typename... ARGS>
101  SmearedParticles(const ParticleFinder& pf, const Cut& c, ARGS... effSmearFns)
102  : SmearedParticles(pf, toEffSmearFns(_detFns, effSmearFns...), c)
103  { }
104 
105 
108 
110 
111 
113  int compare(const Projection& p) const {
114  const SmearedParticles& other = dynamic_cast<const SmearedParticles&>(p);
115 
116  // Compare truth particles definitions
117  const int teq = mkPCmp(other, "TruthParticles");
118  if (teq != EQUIVALENT) return teq;
119 
120  // Compare lists of detector functions
121  const int nfeq = cmp(_detFns.size(), other._detFns.size());
122  if (nfeq != EQUIVALENT) return nfeq;
123  for (size_t i = 0; i < _detFns.size(); ++i) {
124  const int feq = _detFns[i].cmp(other._detFns[i]);
125  if (feq != EQUIVALENT) return feq;
126  }
127 
128  // If we got this far, we're equal
129  return EQUIVALENT;
130  }
131 
132 
134  void project(const Event& e) {
135  // Copying and filtering
136  const Particles& truthparticles = apply<ParticleFinder>(e, "TruthParticles").particlesByPt();
137  _theParticles.clear(); _theParticles.reserve(truthparticles.size());
138  for (const Particle& p : truthparticles) {
139  Particle pdet = p;
140  double peff = -1;
141  bool keep = true;
142  for (const ParticleEffSmearFn& fn : _detFns) {
143  tie(pdet, peff) = fn(pdet); // smear & eff
144  MSG_DEBUG("New det particle: pid=" << pdet.pid()
145  << ", mom=" << pdet.mom()/GeV << " GeV, "
146  << "pT=" << pdet.pT()/GeV << ", eta=" << pdet.eta()
147  << " : eff=" << 100*peff << "%");
148  if (peff <= 0) { keep = false; break; } //< no need to roll expensive dice (and we deal with -ve probabilities, just in case)
149  if (peff < 1 && rand01() > peff) { keep = false; break; } //< roll dice (and deal with >1 probabilities, just in case)
150  }
151  if (keep) {
152  pdet.addConstituent(p); //< record where the smearing was built from
153  _theParticles.push_back(pdet);
154  }
155  }
156  }
157 
158 
160  void reset() { _theParticles.clear(); }
161 
162 
163  private:
164 
166  vector<ParticleEffSmearFn> _detFns;
167 
168  };
169 
170 
171 }
172 
173 #endif
void setName(const std::string &name)
Used by derived classes to set their name.
Definition: Projection.hh:133
Definition: ALICE_2010_I880049.cc:13
DEFAULT_RIVET_PROJ_CLONE(SmearedParticles)
Clone on the heap.
SmearedParticles(const ParticleFinder &pf, const ParticleSmearFn &smearFn, const ParticleEffFn &effFn, const Cut &c=Cuts::open())
Constructor with a smearing function followed by an efficiency function.
Definition: SmearedParticles.hh:73
SmearedParticles(const ParticleFinder &pf, double eff, const Cut &c=Cuts::open())
Constructor with const efficiency.
Definition: SmearedParticles.hh:38
SmearedParticles(const ParticleFinder &pf, const ParticleEffFn &effFn, const Cut &c=Cuts::open())
Constructor with an efficiency function.
Definition: SmearedParticles.hh:45
const FourMomentum & mom() const
Get equivalent single momentum four-vector (const) (alias).
Definition: ParticleBase.hh:39
virtual void addConstituent(const Particle &c, bool addmom=false)
Add a single direct constituent to this particle.
Definition: Particle.cc:15
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition: SmearedParticles.hh:160
SmearedParticles(const ParticleFinder &pf, const vector< ParticleEffSmearFn > &effSmearFns, const Cut &c=Cuts::open())
Constructor with an ordered list of efficiency and/or smearing functions.
Definition: SmearedParticles.hh:80
SmearedParticles(const ParticleFinder &pf, const ParticleSmearFn &smearFn, double eff, const Cut &c=Cuts::open())
Constructor with a smearing function followed by const efficiency.
Definition: SmearedParticles.hh:59
Particles particlesByPt(const Cut &c=Cuts::open()) const
Definition: ParticleFinder.hh:100
PdgId pid() const
This Particle&#39;s PDG ID code.
Definition: Particle.hh:135
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition: Particle.hh:18
Base class for projections which return subsets of an event&#39;s particles.
Definition: ParticleFinder.hh:11
Functor for simultaneous efficiency-filtering and smearing of Particles.
Definition: ParticleSmearingFunctions.hh:55
Definition: Event.hh:22
Cmp< Projection > mkPCmp(const Projection &otherparent, const std::string &pname) const
Definition: Projection.cc:55
Wrapper projection for smearing Jets with detector resolutions and efficiencies.
Definition: SmearedParticles.hh:31
const Cut & open()
Fully open cut singleton, accepts everything.
Definition: Cuts.cc:81
SmearedParticles(const ParticleFinder &pf, double eff, const ParticleSmearFn &smearFn, const Cut &c=Cuts::open())
Constructor with const efficiency followed by a smearing function.
Definition: SmearedParticles.hh:52
SmearedParticles(const ParticleFinder &pf, const ParticleEffFn &effFn, const ParticleSmearFn &smearFn, const Cut &c=Cuts::open())
Constructor with an efficiency function followed by a smearing function.
Definition: SmearedParticles.hh:66
double pT() const
Get the directly (alias).
Definition: ParticleBase.hh:63
const PROJ & addProjection(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition: ProjectionApplier.hh:170
size_t size() const
Count the final-state particles.
Definition: ParticleFinder.hh:35
double eta() const
Get the directly (alias).
Definition: ParticleBase.hh:87
void project(const Event &e)
Perform the particle finding & smearing calculation.
Definition: SmearedParticles.hh:134
int compare(const Projection &p) const
Compare to another SmearedParticles.
Definition: SmearedParticles.hh:113
Base class for all Rivet projections.
Definition: Projection.hh:29
SmearedParticles(const ParticleFinder &pf, const Cut &c, ARGS... effSmearFns)
Constructor with a variadic ordered list of efficiency and smearing function args.
Definition: SmearedParticles.hh:101
SmearedParticles(const ParticleFinder &pf, const initializer_list< ParticleEffSmearFn > &effSmearFns, const Cut &c=Cuts::open())
Constructor with an ordered list of efficiency and/or smearing functions.
Definition: SmearedParticles.hh:91
double rand01()
Return a uniformly sampled random number between 0 and 1.
Definition: Random.cc:39
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition: Cmp.hh:285