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>
120 const CmpState teq =
mkPCmp(other,
"TruthParticles");
121 if (teq != CmpState::EQ)
return teq;
124 const CmpState nfeq =
cmp(_detFns.size(), other._detFns.
size());
125 MSG_TRACE(
"Numbers of detector functions = " << _detFns.size() <<
" VS " << other._detFns.
size());
126 if (nfeq != CmpState::EQ)
return nfeq;
127 for (
size_t i = 0; i < _detFns.size(); ++i) {
128 const CmpState feq = _detFns[i].cmp(other._detFns[i]);
129 if (feq != CmpState::EQ)
return feq;
133 MSG_DEBUG(
"Equivalent detected! " << p.
name() <<
", " << this->
name());
141 const Particles& truthparticles = apply<ParticleFinder>(e,
"TruthParticles").
particlesByPt();
142 _theParticles.clear(); _theParticles.reserve(truthparticles.size());
143 for (
const Particle& p : truthparticles) {
147 MSG_TRACE(
"Number of detector functions = " << _detFns.size());
149 std::tie(pdet, peff) = fn(pdet);
151 if (peff <= 0 ||
rand01() > peff) keep =
false;
152 MSG_DEBUG(
"New det particle: pid=" << pdet.
pid()
153 <<
", mom=" << pdet.
mom()/GeV <<
" GeV, " 154 <<
"pT=" << pdet.
pT()/GeV <<
", eta=" << pdet.
eta()
155 <<
" : eff=" << 100*peff <<
"%, discarded=" << std::boolalpha << !keep);
162 _theParticles.push_back(pdet);
168 return getProjection<ParticleFinder>(
"TruthParticles").
particlesByPt();
172 void reset() { _theParticles.clear(); }
178 vector<ParticleEffSmearFn> _detFns;
void setName(const std::string &name)
Used by derived classes to set their name.
Definition: Projection.hh:142
Definition: MC_Cent_pPb.hh:10
DEFAULT_RIVET_PROJ_CLONE(SmearedParticles)
Clone on the heap.
const Particles truthParticles() const
Get the truth particles (sorted by pT)
Definition: SmearedParticles.hh:167
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
CmpState compare(const Projection &p) const
Definition: SmearedParticles.hh:116
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
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition: SmearedParticles.hh:172
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's PDG ID code.
Definition: Particle.hh:162
const Cut & open()
Fully open cut singleton, accepts everything.
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition: Particle.hh:18
virtual void addConstituent(const Particle &c, bool addmom=false)
Add a single direct constituent to this particle.
Base class for projections which return subsets of an event's particles.
Definition: ParticleFinder.hh:11
Functor for simultaneous efficiency-filtering and smearing of Particles.
Definition: ParticleSmearingFunctions.hh:58
Representation of a HepMC event, and enabler of Projection caching.
Definition: Event.hh:22
Cmp< Projection > mkPCmp(const Projection &otherparent, const std::string &pname) const
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
virtual std::string name() const
Get the name of the projection.
Definition: Projection.hh:56
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 & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition: ProjectionApplier.hh:160
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:139
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
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.
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition: Cmp.hh:255