rivet is hosted by Hepforge, IPPP Durham
IsolationEstimators.hh
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_IsolationEstimators_HH
00003 #define RIVET_IsolationEstimators_HH
00004 
00005 #include "Rivet/Math/MathUtils.hh"
00006 #include "Rivet/Particle.hh"
00007 #include "Rivet/Jet.hh"
00008 
00009 #include <vector>
00010 #include <typeinfo>
00011 
00012 namespace Rivet {
00013 
00014   /// @cond ISOLATION_DETAILS
00015 
00016   template < typename T, typename C >
00017   class IsolationEstimator {
00018 
00019     public:
00020 
00021     virtual ~IsolationEstimator(){};
00022 
00023       virtual double estimate(const T & t, const C & c) const = 0;
00024 
00025       virtual int compare(const IsolationEstimator < T, C > *other) const = 0;
00026 
00027       virtual bool before(const IsolationEstimator * other) const {
00028         const std::type_info & thisid = typeid(*this);
00029         const std::type_info & otherid = typeid(*other);
00030         if (thisid == otherid) {
00031           return compare(other) < 0;
00032         } else {
00033           return thisid.before(otherid);
00034         }
00035       }
00036 
00037       bool operator < (const IsolationEstimator& other) const{
00038         return this->before(&other);
00039       }
00040   };
00041 
00042 
00043   // An estimator for the sum of the pt of the particles in collection C
00044   // being within radius from t
00045   template < class T, class C >
00046   class PtInConeEstimator : public IsolationEstimator < T, C > {
00047   public:
00048     PtInConeEstimator(double radius, double ptmin = 0.0)
00049       : _radius(radius), _ptmin(ptmin) { }
00050 
00051     virtual double estimate(const T & t, const C & c) const {
00052       double ptsum = 0;
00053       for (typename C::const_iterator ic = c.begin(); ic != c.end(); ++ic) {
00054         if (ic->momentum().pT() < _ptmin)
00055           continue;
00056         if (deltaR(t.momentum(), ic->momentum()) < _radius) {
00057           ptsum += ic->momentum().pT();
00058         }
00059       }
00060       return ptsum / t.momentum().pT();
00061     }
00062 
00063     virtual int compare(const IsolationEstimator < T, C > *other) const {
00064       const PtInConeEstimator *concreteother = dynamic_cast<const PtInConeEstimator*>(other);
00065       int ptmincmp = cmp(_ptmin, concreteother->getPtMin());
00066       if (ptmincmp != 0)
00067          return ptmincmp;
00068       int radcmp = cmp(_radius, concreteother->getRadius());
00069       if (radcmp != 0)
00070          return radcmp;
00071        return 0;
00072     }
00073 
00074     double radius() const {
00075       return _radius;
00076     }
00077 
00078     double ptMin() const {
00079       return _ptmin;
00080     }
00081   private:
00082     double _radius;
00083     double _ptmin;
00084   };
00085 
00086 
00087   // An estimator for the number of particles in collection C
00088   // being within radius from t
00089   template < class T, class C >
00090   class MultiplicityInConeEstimator : public IsolationEstimator < T, C > {
00091   public:
00092     MultiplicityInConeEstimator(double radius, double ptmin = 0.0)
00093       : _radius(radius), _ptmin(ptmin) {  }
00094 
00095     virtual double estimate(const T & t, const C & c) const {
00096       double npart = 0;
00097       for (typename C::const_iterator ic = c.begin(); ic != c.end(); ++ic) {
00098         if (ic->momentum().pT() < _ptmin)
00099           continue;
00100         if (deltaR(t.momentum(), ic->momentum()) < _radius) {
00101           npart++;
00102         }
00103       }
00104       return npart;
00105     }
00106 
00107     virtual int compare(const IsolationEstimator < T, C > *other) const {
00108       const MultiplicityInConeEstimator *concreteother = dynamic_cast < const MultiplicityInConeEstimator * >(other);
00109       int ptmincmp = cmp(_ptmin, concreteother->getPtMin());
00110       if (ptmincmp != 0)
00111          return ptmincmp;
00112       int radcmp = cmp(_radius, concreteother->getRadius());
00113       if (radcmp != 0)
00114          return radcmp;
00115        return 0;
00116     }
00117 
00118     double radius() const {
00119       return _radius;
00120     }
00121 
00122     double ptMin() const {
00123       return _ptmin;
00124     }
00125 
00126   private:
00127     double _radius;
00128     double _ptmin;
00129   };
00130 
00131 
00132   /// Typedefs
00133   typedef MultiplicityInConeEstimator < Jet, std::vector < Jet > >JetIsoEstimatorByMultiplicity;
00134   typedef MultiplicityInConeEstimator < Particle, std::vector < Jet > >ParticleFromJetIsoEstimatorByMultiplicity;
00135   typedef MultiplicityInConeEstimator < Particle, std::vector < Particle > >ParticleIsoEstimatorByMultiplicity;
00136 
00137   typedef PtInConeEstimator < Jet, std::vector < Jet > >JetIsoEstimatorByPt;
00138   typedef PtInConeEstimator < Particle, std::vector < Jet > >ParticleFromJetIsoEstimatorByPt;
00139   typedef PtInConeEstimator < Particle, std::vector < Particle > >ParticleIsoEstimatorByPt;
00140   template <typename TYPE1, typename TYPE2> struct isohelper {
00141             typedef IsolationEstimator<TYPE1, TYPE2> estimatorhelper;
00142   };
00143 
00144 
00145   /// @endcond
00146 
00147 }
00148 
00149 #endif