Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 #ifndef RIVET_JetSmearingFunctions_HH
0003 #define RIVET_JetSmearingFunctions_HH
0004 
0005 #include "Rivet/Jet.hh"
0006 #include "Rivet/Tools/MomentumSmearingFunctions.hh"
0007 #include "Rivet/Tools/ParticleSmearingFunctions.hh"
0008 #include "Rivet/Tools/Random.hh"
0009 
0010 namespace Rivet {
0011 
0012 
0013   /// @ingroup smearing
0014   /// @{
0015 
0016   /// @defgroup smearing_particle Generic jet filtering, efficiency and smearing utils
0017   /// @{
0018 
0019   /// Typedef for Jet smearing functions/functors
0020   typedef function<Jet(const Jet&)> JetSmearFn;
0021 
0022   /// Typedef for Jet efficiency functions/functors
0023   typedef function<double(const Jet&)> JetEffFn;
0024 
0025 
0026 
0027   /// Take a jet and return a constant 0
0028   inline double JET_EFF_ZERO(const Jet&) { return 0; }
0029   /// Alias for JET_EFF_ZERO
0030   inline double JET_EFF_0(const Jet&) { return 0; }
0031   /// Alias for JET_EFF_ZERO
0032   inline double JET_FN0(const Jet&) { return 0; }
0033 
0034   /// Take a jet and return a constant 1
0035   inline double JET_EFF_ONE(const Jet&) { return 1; }
0036   /// Alias for JET_EFF_ONE
0037   inline double JET_EFF_1(const Jet&) { return 1; }
0038   /// Alias for JET_EFF_ONE
0039   inline double JET_EFF_PERFECT(const Jet&) { return 1; }
0040   /// Alias for JET_EFF_ONE
0041   inline double JET_FN1(const Jet&) { return 1; }
0042 
0043   /// Take a Jet and return a constant efficiency
0044   struct JET_EFF_CONST {
0045     JET_EFF_CONST(double eff) : _eff(eff) {}
0046     double operator () (const Jet& )  const { return _eff; }
0047     double _eff;
0048   };
0049 
0050 
0051   /// @brief Return 1 if the given Jet contains a b, otherwise 0
0052   /// @todo Need to be able to pass a tag pT threshold? -> functor struct
0053   inline double JET_BTAG_PERFECT(const Jet& j) { return j.bTagged() ? 1 : 0; }
0054 
0055   /// @brief Return 1 if the given Jet contains a c, otherwise 0
0056   /// @todo Need to be able to pass a tag pT threshold? -> functor struct
0057   inline double JET_CTAG_PERFECT(const Jet& j) { return j.cTagged() ? 1 : 0; }
0058 
0059   /// @brief Return 1 if the given Jet contains a c, otherwise 0
0060   /// @todo Need to be able to pass a tag pT threshold? -> functor struct
0061   inline double JET_TAUTAG_PERFECT(const Jet& j) { return j.tauTagged() ? 1 : 0; }
0062 
0063 
0064   /// @brief b-tagging efficiency functor, for more readable b-tag effs and mistag rates
0065   ///
0066   /// @note Note the several constructors, allowing for optional specification of charm, tau, and light jet mistag rates.
0067   struct JET_BTAG_EFFS {
0068     JET_BTAG_EFFS(double eff_b, double eff_light=0) : _eff_b(eff_b), _eff_c(-1), _eff_t(-1), _eff_l(eff_light) { }
0069     JET_BTAG_EFFS(double eff_b, double eff_c, double eff_light) : _eff_b(eff_b), _eff_c(eff_c), _eff_t(-1), _eff_l(eff_light) { }
0070     JET_BTAG_EFFS(double eff_b, double eff_c, double eff_tau, double eff_light) : _eff_b(eff_b), _eff_c(eff_c), _eff_t(eff_tau), _eff_l(eff_light) { }
0071     inline double operator () (const Jet& j) {
0072       if (j.bTagged()) return _eff_b;
0073       if (_eff_c >= 0 && j.cTagged()) return _eff_c;
0074       if (_eff_t >= 0 && j.tauTagged()) return _eff_t;
0075       return _eff_l;
0076     }
0077     double _eff_b, _eff_c, _eff_t, _eff_l;
0078   };
0079 
0080 
0081   /// Take a jet and return an unmodified copy
0082   /// @todo Modify constituent particle vectors for consistency
0083   /// @todo Set a null PseudoJet if the Jet is smeared?
0084   inline Jet JET_SMEAR_IDENTITY(const Jet& j) { return j; }
0085   /// Alias for JET_SMEAR_IDENTITY
0086   inline Jet JET_SMEAR_PERFECT(const Jet& j) { return j; }
0087 
0088 
0089   /// @brief Functor for simultaneous efficiency-filtering and smearing of Jets
0090   ///
0091   /// A central element of the SmearedJets system
0092   ///
0093   /// @todo Include tagging efficiency functions?
0094   struct JetEffSmearFn {
0095     JetEffSmearFn(const JetSmearFn& s, const JetEffFn& e)
0096       : sfn(s), efn(e) {    }
0097 
0098     JetEffSmearFn(const JetEffFn& e, const JetSmearFn& s)
0099       : sfn(s), efn(e) {    }
0100 
0101     JetEffSmearFn(const JetSmearFn& s)
0102       : sfn(s), efn(JET_EFF_ONE) {    }
0103 
0104     JetEffSmearFn(const JetEffFn& e)
0105       : sfn(JET_SMEAR_IDENTITY), efn(e) {    }
0106 
0107     JetEffSmearFn(double eff)
0108       : JetEffSmearFn(JET_EFF_CONST(eff)) {    }
0109 
0110     /// Smear and calculate an efficiency for the given jet
0111     pair<Jet,double> operator() (const Jet& j) const {
0112       return make_pair(sfn(j), efn(j));
0113     }
0114 
0115     /// Compare to another, for use in the projection system
0116     CmpState cmp(const JetEffSmearFn& other) const {
0117       // cout << "Eff hashes = " << get_address(efn) << "," << get_address(other.efn) << "; "
0118       //      << "smear hashes = " << get_address(sfn) << "," << get_address(other.sfn) << '\n';
0119       if (get_address(sfn) == 0 || get_address(other.sfn) == 0) return CmpState::NEQ;
0120       if (get_address(efn) == 0 || get_address(other.efn) == 0) return CmpState::NEQ;
0121       return Rivet::cmp(get_address(sfn), get_address(other.sfn)) || Rivet::cmp(get_address(efn), get_address(other.efn));
0122     }
0123 
0124     /// Automatic conversion to a smearing function
0125     operator JetSmearFn () { return sfn; }
0126     /// Automatic conversion to an efficiency function
0127     /// @todo Ambiguity re. whether reco eff or a tagging efficiency...
0128     // operator JetEffFn () { return efn; }
0129 
0130     // Stored functions/functors
0131     JetSmearFn sfn;
0132     JetEffFn efn;
0133   };
0134 
0135 
0136   /// Return true if Jet @a j is chosen to survive a random efficiency selection
0137   template <typename FN>
0138   inline bool efffilt(const Jet& j, FN& feff) {
0139     return rand01() < feff(j);
0140   }
0141 
0142   /// A functor to return true if Jet @a j survives a random efficiency selection
0143   struct JetEffFilter {
0144     template <typename FN>
0145     JetEffFilter(const FN& feff) : _feff(feff) {}
0146     JetEffFilter(double eff) : JetEffFilter( [&](const Jet&){return eff;} ) {}
0147     bool operator () (const Jet& j) const { return efffilt(j, _feff); }
0148   private:
0149     const JetEffFn _feff;
0150   };
0151   using jetEffFilter = JetEffFilter;
0152 
0153   /// @}
0154 
0155   /// @}
0156 
0157 }
0158 
0159 #endif