Rivet: /Users/chrisg/software/rivet/include/Rivet/Projections/SmearedParticles.hh Source File

| Rivet 3.1.9

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
10namespace 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
31 class SmearedParticles : public ParticleFinder {
32 public:
33
35
36
38 SmearedParticles(const ParticleFinder& pf,
39 double eff,
40 const Cut& c=Cuts::open())
41 : SmearedParticles(pf, {{eff}}, c)
42 { }
43
45 SmearedParticles(const ParticleFinder& pf,
46 const ParticleEffFn& effFn,
47 const Cut& c=Cuts::open())
48 : SmearedParticles(pf, {{effFn}}, c)
49 { }
50
52 SmearedParticles(const ParticleFinder& pf,
53 double eff, const ParticleSmearFn& smearFn,
54 const Cut& c=Cuts::open())
55 : SmearedParticles(pf, {eff, smearFn}, c)
56 { }
57
59 SmearedParticles(const ParticleFinder& pf,
60 const ParticleSmearFn& smearFn, double eff,
61 const Cut& c=Cuts::open())
62 : SmearedParticles(pf, {smearFn, eff}, c)
63 { }
64
66 SmearedParticles(const ParticleFinder& pf,
67 const ParticleEffFn& effFn, const ParticleSmearFn& smearFn,
68 const Cut& c=Cuts::open())
69 : SmearedParticles(pf, {effFn, smearFn}, c)
70 { }
71
73 SmearedParticles(const ParticleFinder& pf,
74 const ParticleSmearFn& smearFn, const ParticleEffFn& effFn,
75 const Cut& c=Cuts::open())
76 : SmearedParticles(pf, {smearFn, effFn}, c)
77 { }
78
80 SmearedParticles(const ParticleFinder& pf,
81 const vector<ParticleEffSmearFn>& effSmearFns,
82 const Cut& c=Cuts::open())
83 : ParticleFinder(c),
84 _detFns(effSmearFns)
85 {
86 setName("SmearedParticles");
87 declare(pf, "TruthParticles");
88 }
89
91 SmearedParticles(const ParticleFinder& pf,
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
107 DEFAULT_RIVET_PROJ_CLONE(SmearedParticles);
108
110
112 using Projection::operator =;
113
114
119 CmpState compare(const Projection& p) const {
120 const SmearedParticles& other = dynamic_cast<const SmearedParticles&>(p);
121
122 // Compare truth particles definitions
123 const CmpState teq = mkPCmp(other, "TruthParticles");
124 if (teq != CmpState::EQ) return teq;
125
126 // Compare cuts
127 if (_cuts != other._cuts) return CmpState::NEQ;
128
129 // Compare lists of detector functions
130 const CmpState nfeq = cmp(_detFns.size(), other._detFns.size());
131 MSG_TRACE("Numbers of detector functions = " << _detFns.size() << " VS " << other._detFns.size());
132 if (nfeq != CmpState::EQ) return nfeq;
133 for (size_t i = 0; i < _detFns.size(); ++i) {
134 const CmpState feq = _detFns[i].cmp(other._detFns[i]);
135 if (feq != CmpState::EQ) return feq;
136 }
137
138 // If we got this far, we're equal
139 MSG_DEBUG("Equivalent detected! " << p.name() << ", " << this->name());
140 return CmpState::EQ;
141 }
142
143
145 void project(const Event& e) {
146 // Copying and filtering
147 const Particles& truthparticles = apply<ParticleFinder>(e, "TruthParticles").particlesByPt(); //truthParticles();
148 _theParticles.clear(); _theParticles.reserve(truthparticles.size());
149 for (const Particle& p : truthparticles) {
150 Particle pdet = p;
151 double peff = -1;
152 bool keep = true;
153 MSG_TRACE("Number of detector functions = " << _detFns.size());
154 for (const ParticleEffSmearFn& fn : _detFns) {
155 std::tie(pdet, peff) = fn(pdet); // smear & eff
156 // Test the short-circuit random numbers if possible; note handling of < 0 and > 1 probabilities
157 if (peff <= 0 || rand01() > peff) keep = false;
158 MSG_DEBUG("New det particle: pid=" << pdet.pid()
159 << ", mom=" << pdet.mom()/GeV << " GeV, "
160 << "pT=" << pdet.pT()/GeV << ", eta=" << pdet.eta()
161 << " : eff=" << 100*peff << "%, discarded=" << std::boolalpha << !keep);
162 if (!keep) break; // discarded; no need to try more smear-eff functions
163 }
164 // If discarding, go straight to the next particle
165 if (!keep) continue;
166 //Ensure the smeared particle satisfies the cuts associated with this projection
167 if (!_cuts->accept(pdet)) continue;
168
169 // Store, recording where the smearing was built from
170 pdet.addConstituent(p);
171 _theParticles.push_back(pdet);
172 }
173 }
174
176 const Particles truthParticles() const {
177 return getProjection<ParticleFinder>("TruthParticles").particlesByPt();
178 }
179
181 void reset() { _theParticles.clear(); }
182
183
184 protected:
185
187 vector<ParticleEffSmearFn> _detFns;
188
189 };
190
191
192}
193
194#endif
Rivet::Event
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
Rivet::ParticleBase::mom
const FourMomentum & mom() const
Get equivalent single momentum four-vector (const) (alias).
Definition ParticleBase.hh:39
Rivet::ParticleBase::pT
double pT() const
Get the directly (alias).
Definition ParticleBase.hh:63
Rivet::ParticleBase::eta
double eta() const
Get the directly (alias).
Definition ParticleBase.hh:87
Rivet::ParticleFinder
Base class for projections which return subsets of an event's particles.
Definition ParticleFinder.hh:11
Rivet::ParticleFinder::size
size_t size() const
Count the final-state particles.
Definition ParticleFinder.hh:38
Rivet::Particle
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition Particle.hh:53
Rivet::Particle::addConstituent
virtual void addConstituent(const Particle &c, bool addmom=false)
Add a single direct constituent to this particle.
Rivet::Particle::pid
PdgId pid() const
This Particle's PDG ID code.
Definition Particle.hh:197
Rivet::Particles
Specialised vector of Particle objects.
Definition Particle.hh:25
Rivet::ProjectionApplier::declare
const PROJ & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition ProjectionApplier.hh:170
Rivet::Projection
Base class for all Rivet projections.
Definition Projection.hh:29
Rivet::Projection::mkPCmp
Cmp< Projection > mkPCmp(const Projection &otherparent, const std::string &pname) const
Rivet::Projection::setName
void setName(const std::string &name)
Used by derived classes to set their name.
Definition Projection.hh:142
Rivet::SmearedParticles
Wrapper projection for smearing Jets with detector resolutions and efficiencies.
Definition SmearedParticles.hh:31
Rivet::SmearedParticles::SmearedParticles
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
Rivet::SmearedParticles::SmearedParticles
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
Rivet::SmearedParticles::SmearedParticles
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
Rivet::SmearedParticles::SmearedParticles
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
Rivet::SmearedParticles::truthParticles
const Particles truthParticles() const
Get the truth particles (sorted by pT)
Definition SmearedParticles.hh:176
Rivet::SmearedParticles::SmearedParticles
SmearedParticles(const ParticleFinder &pf, double eff, const Cut &c=Cuts::open())
Constructor with const efficiency.
Definition SmearedParticles.hh:38
Rivet::SmearedParticles::project
void project(const Event &e)
Perform the particle finding & smearing calculation.
Definition SmearedParticles.hh:145
Rivet::SmearedParticles::SmearedParticles
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
Rivet::SmearedParticles::reset
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition SmearedParticles.hh:181
Rivet::SmearedParticles::SmearedParticles
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
Rivet::SmearedParticles::compare
CmpState compare(const Projection &p) const
Definition SmearedParticles.hh:119
Rivet::SmearedParticles::SmearedParticles
SmearedParticles(const ParticleFinder &pf, const ParticleEffFn &effFn, const Cut &c=Cuts::open())
Constructor with an efficiency function.
Definition SmearedParticles.hh:45
Rivet::SmearedParticles::SmearedParticles
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
Rivet::SmearedParticles::DEFAULT_RIVET_PROJ_CLONE
DEFAULT_RIVET_PROJ_CLONE(SmearedParticles)
Clone on the heap.
MSG_TRACE
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:193
MSG_DEBUG
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
Rivet::Kin::p
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:684
Rivet::ParticleSmearFn
function< Particle(const Particle &)> ParticleSmearFn
Typedef for Particle smearing functions/functors.
Definition ParticleSmearingFunctions.hh:19
Rivet::ParticleEffFn
function< double(const Particle &)> ParticleEffFn
Typedef for Particle efficiency functions/functors.
Definition ParticleSmearingFunctions.hh:22
Rivet::Cuts::open
const Cut & open()
Fully open cut singleton, accepts everything.
Rivet
Definition MC_Cent_pPb.hh:10
Rivet::rand01
double rand01()
Return a uniformly sampled random number between 0 and 1.
Rivet::cmp
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition Cmp.hh:255
Rivet::ParticleEffSmearFn
Functor for simultaneous efficiency-filtering and smearing of Particles.
Definition ParticleSmearingFunctions.hh:58