Rivet API documentation

Rivet 4.1.3
ParticleSmearingFunctions.hh
1// -*- C++ -*-
2#ifndef RIVET_ParticleSmearingFunctions_HH
3#define RIVET_ParticleSmearingFunctions_HH
4
5#include "Rivet/Particle.hh"
6#include "Rivet/Tools/MomentumSmearingFunctions.hh"
7#include "Rivet/Tools/Random.hh"
8
9namespace Rivet {
10
11
14
17
19 typedef function<Particle(const Particle&)> ParticleSmearFn;
20
22 typedef function<double(const Particle&)> ParticleEffFn;
23
24
26 inline double PARTICLE_EFF_ZERO(const Particle&) {
27 return 0;
28 }
29
30 inline double PARTICLE_EFF_0(const Particle&) {
31 return 0;
32 }
33
34 inline double PARTICLE_FN0(const Particle&) {
35 return 0;
36 }
37
39 inline double PARTICLE_EFF_ONE(const Particle&) {
40 return 1;
41 }
42
43 inline double PARTICLE_EFF_1(const Particle&) {
44 return 1;
45 }
46
47 inline double PARTICLE_EFF_PERFECT(const Particle&) {
48 return 1;
49 }
50
51 inline double PARTICLE_FN1(const Particle&) {
52 return 1;
53 }
54
56 struct PARTICLE_EFF_CONST {
57 PARTICLE_EFF_CONST(double x)
58 : _x(x) { }
59 double operator()(const Particle&) const {
60 return _x;
61 }
62 double _x;
63 };
64
65
68 return p;
69 }
70
72 return p;
73 }
74
75
79 struct ParticleEffSmearFn {
80 ParticleEffSmearFn(const ParticleSmearFn& s, const ParticleEffFn& e)
81 : sfn(s), efn(e) { }
82
83 ParticleEffSmearFn(const ParticleEffFn& e, const ParticleSmearFn& s)
84 : sfn(s), efn(e) { }
85
86 ParticleEffSmearFn(const ParticleSmearFn& s)
87 : sfn(s), efn(PARTICLE_EFF_ONE) { }
88
89 ParticleEffSmearFn(const ParticleEffFn& e)
90 : sfn(PARTICLE_SMEAR_IDENTITY), efn(e) { }
91
92 ParticleEffSmearFn(double eff)
93 : ParticleEffSmearFn(PARTICLE_EFF_CONST(eff)) { }
94
96 pair<Particle, double> operator()(const Particle& p) const {
97 return make_pair(sfn(p), efn(p));
98 }
99
101 CmpState cmp(const ParticleEffSmearFn& other) const {
102 // cout << "Eff hashes = " << get_address(efn) << "," << get_address(other.efn) << "; "
103 // << "smear hashes = " << get_address(sfn) << "," << get_address(other.sfn) << '\n';
104 if (get_address(sfn) == 0 || get_address(other.sfn) == 0) return CmpState::NEQ;
105 if (get_address(efn) == 0 || get_address(other.efn) == 0) return CmpState::NEQ;
106 return Rivet::cmp(get_address(sfn), get_address(other.sfn))
107 || Rivet::cmp(get_address(efn), get_address(other.efn));
108 }
109
111 operator ParticleSmearFn() {
112 return sfn;
113 }
114
115 operator ParticleEffFn() {
116 return efn;
117 }
118
119 // Stored functions/functors
120 const ParticleSmearFn sfn;
121 const ParticleEffFn efn;
122 };
123
124
126 inline bool efffilt(const Particle& p, const ParticleEffFn& feff) {
127 return rand01() < feff(p);
128 }
129
133 struct ParticleEffFilter {
134 template <typename FN>
135 ParticleEffFilter(const FN& feff)
136 : _feff(feff) { }
137 ParticleEffFilter(double eff)
138 : ParticleEffFilter([&](const Particle&) { return eff; }) { }
139 bool operator()(const Particle& p) const {
140 return efffilt(p, _feff);
141 }
142
143 private:
144
145 const ParticleEffFn _feff;
146 };
147 using particleEffFilter = ParticleEffFilter;
148
150
152
153}
154
155#endif
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition Particle.hh:50
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
double PARTICLE_EFF_ONE(const Particle &)
Take a Particle and return 1.
Definition ParticleSmearingFunctions.hh:39
Particle PARTICLE_SMEAR_PERFECT(const Particle &p)
Alias for PARTICLE_SMEAR_IDENTITY.
Definition ParticleSmearingFunctions.hh:71
double PARTICLE_EFF_PERFECT(const Particle &)
Alias for PARTICLE_EFF_ONE.
Definition ParticleSmearingFunctions.hh:47
function< Particle(const Particle &)> ParticleSmearFn
Typedef for Particle smearing functions/functors.
Definition ParticleSmearingFunctions.hh:19
double PARTICLE_FN1(const Particle &)
Alias for PARTICLE_EFF_ONE.
Definition ParticleSmearingFunctions.hh:51
Particle PARTICLE_SMEAR_IDENTITY(const Particle &p)
Take a Particle and return it unmodified.
Definition ParticleSmearingFunctions.hh:67
double PARTICLE_EFF_0(const Particle &)
Alias for PARTICLE_EFF_ZERO.
Definition ParticleSmearingFunctions.hh:30
double PARTICLE_FN0(const Particle &)
Alias for PARTICLE_EFF_ZERO.
Definition ParticleSmearingFunctions.hh:34
double PARTICLE_EFF_ZERO(const Particle &)
Take a Particle and return 0.
Definition ParticleSmearingFunctions.hh:26
function< double(const Particle &)> ParticleEffFn
Typedef for Particle efficiency functions/functors.
Definition ParticleSmearingFunctions.hh:22
double PARTICLE_EFF_1(const Particle &)
Alias for PARTICLE_EFF_ONE.
Definition ParticleSmearingFunctions.hh:43
bool efffilt(const Jet &j, FN &feff)
Return true if Jet j is chosen to survive a random efficiency selection.
Definition JetSmearingFunctions.hh:189
Definition LHCbCommon.hh:9
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:253
uintptr_t get_address(std::function< T(U...)> f)
Get a function pointer / hash integer from an std::function.
Definition RivetSTL.hh:338
Take a Particle and return a constant number.
Definition ParticleSmearingFunctions.hh:56
A functor to return true if Particle p survives a random efficiency selection.
Definition ParticleSmearingFunctions.hh:133
CmpState cmp(const ParticleEffSmearFn &other) const
Compare to another, for use in the projection system.
Definition ParticleSmearingFunctions.hh:101
pair< Particle, double > operator()(const Particle &p) const
Smear and calculate an efficiency for the given particle.
Definition ParticleSmearingFunctions.hh:96