rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.2
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
15 public:
16
19
21 template<typename... Args,
22 typename = std::enable_if_t< allArgumentsOf<ParticleEffSmearFn, Args...>::value >>
23 SmearedParticles(const ParticleFinder& pf, Args&& ... effSmearFns)
24 : SmearedParticles(pf, Cuts::open(), std::forward<Args>(effSmearFns) ...)
25 { }
26
30 template<typename... Args,
31 typename = std::enable_if_t< allArgumentsOf<ParticleEffSmearFn, Args...>::value >>
32 SmearedParticles(const ParticleFinder& pf, const Cut& c, Args&& ... effSmearFns)
33 : ParticleFinder(c), _detFns({ParticleEffSmearFn(std::forward<Args>(effSmearFns))...})
34 {
35 setName("SmearedParticles");
36 declare(pf, "TruthParticles");
37 }
38
39
42
44
46 using Projection::operator =;
47
48
53 CmpState compare(const Projection& p) const {
54 const SmearedParticles& other = dynamic_cast<const SmearedParticles&>(p);
55
56 // Compare truth particles definitions
57 const CmpState teq = mkPCmp(other, "TruthParticles");
58 if (teq != CmpState::EQ) return teq;
59
60 // Compare cuts
61 if (_cuts != other._cuts) return CmpState::NEQ;
62
63 // Compare lists of detector functions
64 const CmpState nfeq = cmp(_detFns.size(), other._detFns.size());
65 MSG_TRACE("Numbers of detector functions = " << _detFns.size() << " VS " << other._detFns.size());
66 if (nfeq != CmpState::EQ) return nfeq;
67 for (size_t i = 0; i < _detFns.size(); ++i) {
68 const CmpState feq = _detFns[i].cmp(other._detFns[i]);
69 if (feq != CmpState::EQ) return feq;
70 }
71
72 // If we got this far, we're equal
73 MSG_DEBUG("Equivalent detected! " << p.name() << ", " << this->name());
74 return CmpState::EQ;
75 }
76
77
79 void project(const Event& e) {
80 // Copying and filtering
81 const Particles& truthparticles = apply<ParticleFinder>(e, "TruthParticles").particlesByPt(); //truthParticles();
82 _theParticles.clear(); _theParticles.reserve(truthparticles.size());
83 for (const Particle& p : truthparticles) {
84 Particle pdet = p;
85 double peff = -1;
86 bool keep = true;
87 MSG_TRACE("Number of detector functions = " << _detFns.size());
88 for (const ParticleEffSmearFn& fn : _detFns) {
89 std::tie(pdet, peff) = fn(pdet); // smear & eff
90 // Test the short-circuit random numbers if possible; note handling of < 0 and > 1 probabilities
91 if (peff <= 0 || rand01() > peff) keep = false;
92 MSG_DEBUG("New det particle: pid=" << pdet.pid()
93 << ", mom=" << pdet.mom()/GeV << " GeV, "
94 << "pT=" << pdet.pT()/GeV << ", eta=" << pdet.eta()
95 << " : eff=" << 100*peff << "%, discarded=" << std::boolalpha << !keep);
96 if (!keep) break; // discarded; no need to try more smear-eff functions
97 }
98 // If discarding, go straight to the next particle
99 if (!keep) continue;
100 //Ensure the smeared particle satisfies the cuts associated with this projection
101 if (!_cuts->accept(pdet)) continue;
102
103 // Store, recording where the smearing was built from
104 pdet.addConstituent(p);
105 _theParticles.push_back(pdet);
106 }
107 }
108
110 const Particles truthParticles() const {
111 return getProjection<ParticleFinder>("TruthParticles").particlesByPt();
112 }
113
115 void reset() { _theParticles.clear(); }
116
117
118 protected:
119
121 vector<ParticleEffSmearFn> _detFns;
122
123 };
124
125
126}
127
128#endif
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:51
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition Particle.hh:45
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:191
Specialised vector of Particle objects.
Definition Particle.hh:21
const PROJ & declare(const PROJ &proj, const std::string &name) const
Register a contained projection (user-facing version)
Definition ProjectionApplier.hh:175
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:148
Wrapper projection for smearing Jets with detector resolutions and efficiencies.
Definition SmearedParticles.hh:14
SmearedParticles(const ParticleFinder &pf, Args &&... effSmearFns)
Constructor with a variadic ordered list of efficiency and smearing function args.
Definition SmearedParticles.hh:23
const Particles truthParticles() const
Get the truth particles (sorted by pT)
Definition SmearedParticles.hh:110
void project(const Event &e)
Perform the particle finding & smearing calculation.
Definition SmearedParticles.hh:79
RIVET_DEFAULT_PROJ_CLONE(SmearedParticles)
Clone on the heap.
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition SmearedParticles.hh:115
CmpState compare(const Projection &p) const
Definition SmearedParticles.hh:53
SmearedParticles(const ParticleFinder &pf, const Cut &c, Args &&... effSmearFns)
Constructor with a variadic ordered list of efficiency and smearing function args.
Definition SmearedParticles.hh:32
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:180
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:182
Definition MC_CENT_PPB_Projections.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
STL namespace.
Functor for simultaneous efficiency-filtering and smearing of Particles.
Definition ParticleSmearingFunctions.hh:58