Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:53

0001 // -*- C++ -*-
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   /// @ingroup smearing
0013   /// @{
0014 
0015   /// @defgroup smearing_particle Generic particle filtering, efficiency and smearing utils
0016   /// @{
0017 
0018   /// Typedef for Particle smearing functions/functors
0019   typedef function<Particle(const Particle&)> ParticleSmearFn;
0020 
0021   /// Typedef for Particle efficiency functions/functors
0022   typedef function<double(const Particle&)> ParticleEffFn;
0023 
0024 
0025   /// Take a Particle and return 0
0026   inline double PARTICLE_EFF_ZERO(const Particle& ) { return 0; }
0027   /// Alias for PARTICLE_EFF_ZERO
0028   inline double PARTICLE_EFF_0(const Particle& ) { return 0; }
0029   /// Alias for PARTICLE_EFF_ZERO
0030   inline double PARTICLE_FN0(const Particle& ) { return 0; }
0031 
0032   /// Take a Particle and return 1
0033   inline double PARTICLE_EFF_ONE(const Particle& ) { return 1; }
0034   /// Alias for PARTICLE_EFF_ONE
0035   inline double PARTICLE_EFF_1(const Particle& ) { return 1; }
0036   /// Alias for PARTICLE_EFF_ONE
0037   inline double PARTICLE_EFF_PERFECT(const Particle& ) { return 1; }
0038   /// Alias for PARTICLE_EFF_ONE
0039   inline double PARTICLE_FN1(const Particle& ) { return 1; }
0040 
0041   /// Take a Particle and return a constant number
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   /// Take a Particle and return it unmodified
0050   inline Particle PARTICLE_SMEAR_IDENTITY(const Particle& p) { return p; }
0051   /// Alias for PARTICLE_SMEAR_IDENTITY
0052   inline Particle PARTICLE_SMEAR_PERFECT(const Particle& p) { return p; }
0053 
0054 
0055   /// @brief Functor for simultaneous efficiency-filtering and smearing of Particles
0056   ///
0057   /// A central element of the SmearedParticles system
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     /// Smear and calculate an efficiency for the given particle
0075     pair<Particle,double> operator() (const Particle& p) const {
0076       return make_pair(sfn(p), efn(p));
0077     }
0078 
0079     /// Compare to another, for use in the projection system
0080     CmpState cmp(const ParticleEffSmearFn& other) const {
0081       // cout << "Eff hashes = " << get_address(efn) << "," << get_address(other.efn) << "; "
0082       //      << "smear hashes = " << get_address(sfn) << "," << get_address(other.sfn) << '\n';
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     /// Automatic conversion to a smearing function
0089     operator ParticleSmearFn () { return sfn; }
0090     /// Automatic conversion to an efficiency function
0091     operator ParticleEffFn () { return efn; }
0092 
0093     // Stored functions/functors
0094     const ParticleSmearFn sfn;
0095     const ParticleEffFn efn;
0096   };
0097 
0098 
0099   /// Return true if Particle @a p is chosen to survive a random efficiency selection
0100   inline bool efffilt(const Particle& p, const ParticleEffFn& feff) {
0101     return rand01() < feff(p);
0102   }
0103 
0104   /// @brief A functor to return true if Particle @a p survives a random efficiency selection
0105   ///
0106   /// @deprecated Prefer... ?
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