File indexing completed on 2025-04-19 09:06:53
0001
0002 #ifndef RIVET_ParticleSmearingFunctions_HH
0003 #define RIVET_ParticleSmearingFunctions_HH
0004
0005 #include "Rivet/Particle.hh"
0006 #include "Rivet/Tools/MomentumSmearingFunctions.hh"
0007 #include "Rivet/Tools/Random.hh"
0008
0009 namespace Rivet {
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 typedef function<Particle(const Particle&)> ParticleSmearFn;
0020
0021
0022 typedef function<double(const Particle&)> ParticleEffFn;
0023
0024
0025
0026 inline double PARTICLE_EFF_ZERO(const Particle& ) { return 0; }
0027
0028 inline double PARTICLE_EFF_0(const Particle& ) { return 0; }
0029
0030 inline double PARTICLE_FN0(const Particle& ) { return 0; }
0031
0032
0033 inline double PARTICLE_EFF_ONE(const Particle& ) { return 1; }
0034
0035 inline double PARTICLE_EFF_1(const Particle& ) { return 1; }
0036
0037 inline double PARTICLE_EFF_PERFECT(const Particle& ) { return 1; }
0038
0039 inline double PARTICLE_FN1(const Particle& ) { return 1; }
0040
0041
0042 struct PARTICLE_EFF_CONST {
0043 PARTICLE_EFF_CONST(double x) : _x(x) {}
0044 double operator () (const Particle& ) const { return _x; }
0045 double _x;
0046 };
0047
0048
0049
0050 inline Particle PARTICLE_SMEAR_IDENTITY(const Particle& p) { return p; }
0051
0052 inline Particle PARTICLE_SMEAR_PERFECT(const Particle& p) { return p; }
0053
0054
0055
0056
0057
0058 struct ParticleEffSmearFn {
0059 ParticleEffSmearFn(const ParticleSmearFn& s, const ParticleEffFn& e)
0060 : sfn(s), efn(e) { }
0061
0062 ParticleEffSmearFn(const ParticleEffFn& e, const ParticleSmearFn& s)
0063 : sfn(s), efn(e) { }
0064
0065 ParticleEffSmearFn(const ParticleSmearFn& s)
0066 : sfn(s), efn(PARTICLE_EFF_ONE) { }
0067
0068 ParticleEffSmearFn(const ParticleEffFn& e)
0069 : sfn(PARTICLE_SMEAR_IDENTITY), efn(e) { }
0070
0071 ParticleEffSmearFn(double eff)
0072 : ParticleEffSmearFn(PARTICLE_EFF_CONST(eff)) { }
0073
0074
0075 pair<Particle,double> operator() (const Particle& p) const {
0076 return make_pair(sfn(p), efn(p));
0077 }
0078
0079
0080 CmpState cmp(const ParticleEffSmearFn& other) const {
0081
0082
0083 if (get_address(sfn) == 0 || get_address(other.sfn) == 0) return CmpState::NEQ;
0084 if (get_address(efn) == 0 || get_address(other.efn) == 0) return CmpState::NEQ;
0085 return Rivet::cmp(get_address(sfn), get_address(other.sfn)) || Rivet::cmp(get_address(efn), get_address(other.efn));
0086 }
0087
0088
0089 operator ParticleSmearFn () { return sfn; }
0090
0091 operator ParticleEffFn () { return efn; }
0092
0093
0094 const ParticleSmearFn sfn;
0095 const ParticleEffFn efn;
0096 };
0097
0098
0099
0100 inline bool efffilt(const Particle& p, const ParticleEffFn& feff) {
0101 return rand01() < feff(p);
0102 }
0103
0104
0105
0106
0107 struct ParticleEffFilter {
0108 template <typename FN>
0109 ParticleEffFilter(const FN& feff) : _feff(feff) {}
0110 ParticleEffFilter(double eff) : ParticleEffFilter( [&](const Particle& ){ return eff; } ) {}
0111 bool operator () (const Particle& p) const { return efffilt(p, _feff); }
0112 private:
0113 const ParticleEffFn _feff;
0114 };
0115 using particleEffFilter = ParticleEffFilter;
0116
0117
0118
0119
0120
0121 }
0122
0123 #endif