2#ifndef RIVET_SmearedParticles_HH
3#define RIVET_SmearedParticles_HH
5#include "Rivet/Particle.hh"
6#include "Rivet/Projection.hh"
7#include "Rivet/Projections/ParticleFinder.hh"
8#include "Rivet/Tools/SmearingFunctions.hh"
16 vector<ParticleEffSmearFn>& toEffSmearFns(vector<ParticleEffSmearFn>& v,
const T& t) {
17 v.push_back(ParticleEffSmearFn(t));
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...);
81 const vector<ParticleEffSmearFn>& effSmearFns,
92 const initializer_list<ParticleEffSmearFn>& effSmearFns,
100 template<
typename... ARGS>
112 using Projection::operator =;
123 const CmpState teq =
mkPCmp(other,
"TruthParticles");
124 if (teq != CmpState::EQ)
return teq;
127 if (_cuts != other._cuts)
return CmpState::NEQ;
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;
139 MSG_DEBUG(
"Equivalent detected! " <<
p.name() <<
", " << this->name());
147 const Particles& truthparticles = apply<ParticleFinder>(e,
"TruthParticles").particlesByPt();
148 _theParticles.clear(); _theParticles.reserve(truthparticles.size());
149 for (
const Particle&
p : truthparticles) {
153 MSG_TRACE(
"Number of detector functions = " << _detFns.size());
155 std::tie(pdet, peff) = fn(pdet);
157 if (peff <= 0 ||
rand01() > peff) keep =
false;
159 <<
", mom=" << pdet.
mom()/GeV <<
" GeV, "
160 <<
"pT=" << pdet.
pT()/GeV <<
", eta=" << pdet.
eta()
161 <<
" : eff=" << 100*peff <<
"%, discarded=" << std::boolalpha << !keep);
167 if (!_cuts->accept(pdet))
continue;
171 _theParticles.push_back(pdet);
177 return getProjection<ParticleFinder>(
"TruthParticles").particlesByPt();
181 void reset() { _theParticles.clear(); }
187 vector<ParticleEffSmearFn> _detFns;
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
const FourMomentum & mom() const
Get equivalent single momentum four-vector (const) (alias).
Definition ParticleBase.hh:39
double pT() const
Get the directly (alias).
Definition ParticleBase.hh:63
double eta() const
Get the directly (alias).
Definition ParticleBase.hh:87
Base class for projections which return subsets of an event's particles.
Definition ParticleFinder.hh:11
size_t size() const
Count the final-state particles.
Definition ParticleFinder.hh:38
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition Particle.hh:53
virtual void addConstituent(const Particle &c, bool addmom=false)
Add a single direct constituent to this particle.
PdgId pid() const
This Particle's PDG ID code.
Definition Particle.hh:197
Specialised vector of Particle objects.
Definition Particle.hh:25
const PROJ & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition ProjectionApplier.hh:170
Base class for all Rivet projections.
Definition Projection.hh:29
Cmp< Projection > mkPCmp(const Projection &otherparent, const std::string &pname) const
void setName(const std::string &name)
Used by derived classes to set their name.
Definition Projection.hh:142
Wrapper projection for smearing Jets with detector resolutions and efficiencies.
Definition SmearedParticles.hh:31
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 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 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 ParticleEffFn &effFn, const ParticleSmearFn &smearFn, const Cut &c=Cuts::open())
Constructor with an efficiency function followed by a smearing function.
Definition SmearedParticles.hh:66
const Particles truthParticles() const
Get the truth particles (sorted by pT)
Definition SmearedParticles.hh:176
SmearedParticles(const ParticleFinder &pf, double eff, const Cut &c=Cuts::open())
Constructor with const efficiency.
Definition SmearedParticles.hh:38
void project(const Event &e)
Perform the particle finding & smearing calculation.
Definition SmearedParticles.hh:145
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
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition SmearedParticles.hh:181
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
CmpState compare(const Projection &p) const
Definition SmearedParticles.hh:119
SmearedParticles(const ParticleFinder &pf, const ParticleEffFn &effFn, const Cut &c=Cuts::open())
Constructor with an efficiency function.
Definition SmearedParticles.hh:45
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
DEFAULT_RIVET_PROJ_CLONE(SmearedParticles)
Clone on the heap.
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:193
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:684
function< Particle(const Particle &)> ParticleSmearFn
Typedef for Particle smearing functions/functors.
Definition ParticleSmearingFunctions.hh:19
function< double(const Particle &)> ParticleEffFn
Typedef for Particle efficiency functions/functors.
Definition ParticleSmearingFunctions.hh:22
const Cut & open()
Fully open cut singleton, accepts everything.
Definition MC_Cent_pPb.hh:10
double rand01()
Return a uniformly sampled random number between 0 and 1.
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition Cmp.hh:255
Functor for simultaneous efficiency-filtering and smearing of Particles.
Definition ParticleSmearingFunctions.hh:58