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

| Rivet 3.1.9

SmearedJets.hh
1// -*- C++ -*-
2#ifndef RIVET_SmearedJets_HH
3#define RIVET_SmearedJets_HH
4
5#include "Rivet/Jet.hh"
6#include "Rivet/Particle.hh"
7#include "Rivet/Projection.hh"
8#include "Rivet/Projections/JetAlg.hh"
9#include "Rivet/Tools/SmearingFunctions.hh"
10#include <functional>
11
12namespace Rivet {
13
14
15 // // Recursive variadic template arg decoding
16 // namespace {
17 // template<typename T>
18 // vector<JetEffSmearFn>& toEffSmearFns(vector<JetEffSmearFn>& v, const T& t) {
19 // v.push_back(JetEffSmearFn(t));
20 // return v;
21 // }
22 // template<typename T, typename... ARGS>
23 // vector<JetEffSmearFn>& toEffSmearFns(vector<JetEffSmearFn>& v, const T& first, ARGS... args) {
24 // v.push_back(JetEffSmearFn(first));
25 // toEffSmearFns(v, args...);
26 // return v;
27 // }
28 // }
29
30
32
33
35 class SmearedJets : public JetFinder {
36 public:
37
39
40
44 SmearedJets(const JetFinder& ja,
45 const JetSmearFn& smearFn,
46 const JetEffFn& bTagEffFn=JET_BTAG_PERFECT,
47 const JetEffFn& cTagEffFn=JET_CTAG_PERFECT)
48 : SmearedJets(ja, vector<JetEffSmearFn>{smearFn}, bTagEffFn, cTagEffFn)
49 { }
50
51
55 SmearedJets(const JetFinder& ja,
56 const JetEffFn& bTagEffFn=JET_BTAG_PERFECT,
57 const JetEffFn& cTagEffFn=JET_CTAG_PERFECT,
58 const initializer_list<JetEffSmearFn>& effSmearFns={})
59 : SmearedJets(ja, vector<JetEffSmearFn>{effSmearFns}, bTagEffFn, cTagEffFn)
60 { }
61
65 SmearedJets(const JetFinder& ja,
66 const JetEffFn& bTagEffFn=JET_BTAG_PERFECT,
67 const JetEffFn& cTagEffFn=JET_CTAG_PERFECT,
68 const vector<JetEffSmearFn>& effSmearFns={})
69 : SmearedJets(ja, effSmearFns, bTagEffFn, cTagEffFn)
70 { }
71
72
76 SmearedJets(const JetFinder& ja,
77 const initializer_list<JetEffSmearFn>& effSmearFns,
78 const JetEffFn& bTagEffFn=JET_BTAG_PERFECT,
79 const JetEffFn& cTagEffFn=JET_CTAG_PERFECT)
80 : SmearedJets(ja, vector<JetEffSmearFn>{effSmearFns}, bTagEffFn, cTagEffFn)
81 { }
82
86 SmearedJets(const JetFinder& ja,
87 const vector<JetEffSmearFn>& effSmearFns,
88 const JetEffFn& bTagEffFn=JET_BTAG_PERFECT,
89 const JetEffFn& cTagEffFn=JET_CTAG_PERFECT)
90 : _detFns(effSmearFns), _bTagEffFn(bTagEffFn), _cTagEffFn(cTagEffFn)
91 {
92 setName("SmearedJets");
93 declare(ja, "TruthJets");
94 }
95
96
101 SmearedJets(const JetFinder& ja,
102 const JetSmearFn& smearFn,
103 const JetEffFn& bTagEffFn,
104 const JetEffFn& cTagEffFn,
105 const JetEffFn& jetEffFn)
106 : SmearedJets(ja, {jetEffFn,smearFn}, bTagEffFn, cTagEffFn)
107 { }
108
109
113
114
116 DEFAULT_RIVET_PROJ_CLONE(SmearedJets);
117
119
121 using Projection::operator =;
122
123
125 CmpState compare(const Projection& p) const {
126 // Compare truth jets definitions
127 const CmpState teq = mkPCmp(p, "TruthJets");
128 if (teq != CmpState::EQ) return teq;
129
130 // Compare lists of detector functions
131 const SmearedJets& other = dynamic_cast<const SmearedJets&>(p);
132 const CmpState nfeq = cmp(_detFns.size(), other._detFns.size());
133 if (nfeq != CmpState::EQ) return nfeq;
134 for (size_t i = 0; i < _detFns.size(); ++i) {
135 const CmpState feq = _detFns[i].cmp(other._detFns[i]);
136 if (feq != CmpState::EQ) return feq;
137 }
138 return Rivet::cmp(get_address(_bTagEffFn), get_address(other._bTagEffFn)) ||
139 Rivet::cmp(get_address(_cTagEffFn), get_address(other._cTagEffFn));
140 }
141
142
144 void project(const Event& e) {
145 // Copying and filtering
146 const Jets& truthjets = apply<JetFinder>(e, "TruthJets").jetsByPt(); //truthJets();
147 _recojets.clear(); _recojets.reserve(truthjets.size());
148 // Apply jet smearing and efficiency transforms
149 for (const Jet& j : truthjets) {
150 Jet jdet = j;
151 bool keep = true;
152 MSG_DEBUG("Truth jet: " << "mom=" << jdet.mom()/GeV << " GeV, pT=" << jdet.pT()/GeV << ", eta=" << jdet.eta());
153 for (const JetEffSmearFn& fn : _detFns) {
154 double jeff = -1;
155 std::tie(jdet, jeff) = fn(jdet); // smear & eff
156 // Re-add constituents & tags if (we assume accidentally) they were lost by the smearing function
157 if (jdet.particles().empty() && !j.particles().empty()) jdet.particles() = j.particles();
158 if (jdet.tags().empty() && !j.tags().empty()) jdet.tags() = j.tags();
159 MSG_DEBUG(" ->" << "mom=" << jdet.mom()/GeV << " GeV, pT=" << jdet.pT()/GeV << ", eta=" << jdet.eta());
160 // MSG_DEBUG("New det jet: "
161 // << "mom=" << jdet.mom()/GeV << " GeV, pT=" << jdet.pT()/GeV << ", eta=" << jdet.eta()
162 // << ", b-tag=" << boolalpha << jdet.bTagged()
163 // << ", c-tag=" << boolalpha << jdet.cTagged()
164 // << " : eff=" << 100*jeff << "%");
165 if (jeff <= 0) { keep = false; break; } //< no need to roll expensive dice (and we deal with -ve probabilities, just in case)
166 if (jeff < 1 && rand01() > jeff) { keep = false; break; } //< roll dice (and deal with >1 probabilities, just in case)
167 }
168 if (keep) _recojets.push_back(jdet);
169 }
170 // Apply tagging efficiencies, using smeared kinematics as input to the tag eff functions
171 for (Jet& j : _recojets) {
172 // Decide whether or not there should be a b-tag on this jet
173 const double beff = _bTagEffFn ? _bTagEffFn(j) : j.bTagged();
174 const bool btag = beff == 1 || (beff != 0 && rand01() < beff);
175 // Remove b-tags if needed, and add a dummy one if needed
176 if (!btag && j.bTagged()) j.tags().erase(std::remove_if(j.tags().begin(), j.tags().end(), hasBottom), j.tags().end());
177 if (btag && !j.bTagged()) j.tags().push_back(Particle(PID::BQUARK, j.mom()));
178 // Decide whether or not there should be a c-tag on this jet
179 const double ceff = _cTagEffFn ? _cTagEffFn(j) : j.cTagged();
180 const bool ctag = ceff == 1 || (ceff != 0 && rand01() < beff);
181 // Remove c-tags if needed, and add a dummy one if needed
182 if (!ctag && j.cTagged()) j.tags().erase(std::remove_if(j.tags().begin(), j.tags().end(), hasCharm), j.tags().end());
183 if (ctag && !j.cTagged()) j.tags().push_back(Particle(PID::CQUARK, j.mom()));
184 }
185 }
186
187
189 Jets _jets() const { return _recojets; }
190
192 const Jets truthJets() const {
193 return getProjection<JetFinder>("TruthJets").jetsByPt();
194 }
195
197 void reset() { _recojets.clear(); }
198
199
200 protected:
201
203 Jets _recojets;
204
206 vector<JetEffSmearFn> _detFns;
207
209 JetEffFn _bTagEffFn, _cTagEffFn;
210
211 };
212
213
214}
215
216#endif
Rivet::Event
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
Rivet::JetFinder
Abstract base class for projections which can return a set of Jets.
Definition JetFinder.hh:15
Rivet::JetFinder::size
size_t size() const
Count the jets.
Definition JetFinder.hh:163
Rivet::Jet
Representation of a clustered jet of particles.
Definition Jet.hh:48
Rivet::Jet::particles
Particles & particles()
Get the particles in this jet.
Definition Jet.hh:77
Rivet::Jet::tags
Particles & tags()
Particles which have been tag-matched to this jet.
Definition Jet.hh:119
Rivet::Jets
Specialised vector of Jet objects.
Definition Jet.hh:23
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::Particle
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition Particle.hh:53
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::SmearedJets
Wrapper projection for smearing Jets with detector resolutions and efficiencies.
Definition SmearedJets.hh:35
Rivet::SmearedJets::DEFAULT_RIVET_PROJ_CLONE
DEFAULT_RIVET_PROJ_CLONE(SmearedJets)
Clone on the heap.
Rivet::SmearedJets::project
void project(const Event &e)
Perform the jet finding & smearing calculation.
Definition SmearedJets.hh:144
Rivet::SmearedJets::SmearedJets
SmearedJets(const JetFinder &ja, const JetEffFn &bTagEffFn=JET_BTAG_PERFECT, const JetEffFn &cTagEffFn=JET_CTAG_PERFECT, const vector< JetEffSmearFn > &effSmearFns={})
Constructor with tagging efficiencies, plus an ordered vector of efficiency and smearing functions.
Definition SmearedJets.hh:65
Rivet::SmearedJets::SmearedJets
SmearedJets(const JetFinder &ja, const JetSmearFn &smearFn, const JetEffFn &bTagEffFn=JET_BTAG_PERFECT, const JetEffFn &cTagEffFn=JET_CTAG_PERFECT)
Constructor with a reco efficiency and optional tagging efficiencies.
Definition SmearedJets.hh:44
Rivet::SmearedJets::SmearedJets
SmearedJets(const JetFinder &ja, const JetSmearFn &smearFn, const JetEffFn &bTagEffFn, const JetEffFn &cTagEffFn, const JetEffFn &jetEffFn)
Constructor with trailing efficiency arg.
Definition SmearedJets.hh:101
Rivet::SmearedJets::SmearedJets
SmearedJets(const JetFinder &ja, const JetEffFn &bTagEffFn=JET_BTAG_PERFECT, const JetEffFn &cTagEffFn=JET_CTAG_PERFECT, const initializer_list< JetEffSmearFn > &effSmearFns={})
Constructor with tagging efficiencies, plus an ordered init-list of efficiency and smearing functions...
Definition SmearedJets.hh:55
Rivet::SmearedJets::compare
CmpState compare(const Projection &p) const
Compare to another SmearedJets.
Definition SmearedJets.hh:125
Rivet::SmearedJets::truthJets
const Jets truthJets() const
Get the truth jets (sorted by pT)
Definition SmearedJets.hh:192
Rivet::SmearedJets::SmearedJets
SmearedJets(const JetFinder &ja, const vector< JetEffSmearFn > &effSmearFns, const JetEffFn &bTagEffFn=JET_BTAG_PERFECT, const JetEffFn &cTagEffFn=JET_CTAG_PERFECT)
Constructor with an ordered vector of efficiency and smearing functions, plus optional tagging effici...
Definition SmearedJets.hh:86
Rivet::SmearedJets::SmearedJets
SmearedJets(const JetFinder &ja, const initializer_list< JetEffSmearFn > &effSmearFns, const JetEffFn &bTagEffFn=JET_BTAG_PERFECT, const JetEffFn &cTagEffFn=JET_CTAG_PERFECT)
Constructor with an ordered init-list of efficiency and smearing functions, plus optional tagging eff...
Definition SmearedJets.hh:76
Rivet::SmearedJets::reset
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition SmearedJets.hh:197
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::JET_CTAG_PERFECT
double JET_CTAG_PERFECT(const Jet &j)
Return 1 if the given Jet contains a c, otherwise 0.
Definition JetSmearingFunctions.hh:57
Rivet::JET_BTAG_PERFECT
double JET_BTAG_PERFECT(const Jet &j)
Return 1 if the given Jet contains a b, otherwise 0.
Definition JetSmearingFunctions.hh:53
Rivet::JetSmearFn
function< Jet(const Jet &)> JetSmearFn
Typedef for Jet smearing functions/functors.
Definition JetSmearingFunctions.hh:20
Rivet::JetEffFn
function< double(const Jet &)> JetEffFn
Typedef for Jet efficiency functions/functors.
Definition JetSmearingFunctions.hh:23
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
std::get_address
uintptr_t get_address(std::function< T(U...)> f)
Get a function pointer / hash integer from an std::function.
Definition RivetSTL.hh:193
Rivet::JetEffSmearFn
Functor for simultaneous efficiency-filtering and smearing of Jets.
Definition JetSmearingFunctions.hh:94