00001
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
00015 template < typename T, typename C >
00016 class IsolationEstimator {
00017
00018 public:
00019
00020 virtual ~IsolationEstimator(){};
00021
00022 virtual double estimate(const T & t, const C & c) const = 0;
00023
00024 virtual int compare(const IsolationEstimator < T, C > *other) const = 0;
00025
00026 virtual bool before(const IsolationEstimator * other) const {
00027 const std::type_info & thisid = typeid(*this);
00028 const std::type_info & otherid = typeid(*other);
00029 if (thisid == otherid) {
00030 return compare(other) < 0;
00031 } else {
00032 return thisid.before(otherid);
00033 }
00034 }
00035
00036 bool operator < (const IsolationEstimator& other) const{
00037 return this->before(&other);
00038 }
00039 };
00040
00041
00042
00043
00044 template < class T, class C >
00045 class PtInConeEstimator : public IsolationEstimator < T, C > {
00046 public:
00047 PtInConeEstimator(double radius, double ptmin = 0.0)
00048 : _radius(radius), _ptmin(ptmin) { }
00049
00050 virtual double estimate(const T & t, const C & c) const {
00051 double ptsum = 0;
00052 for (typename C::const_iterator ic = c.begin(); ic != c.end(); ++ic) {
00053 if (ic->momentum().pT() < _ptmin)
00054 continue;
00055 if (deltaR(t.momentum(), ic->momentum()) < _radius) {
00056 ptsum += ic->momentum().pT();
00057 }
00058 }
00059 return ptsum / t.momentum().pT();
00060 }
00061
00062 virtual int compare(const IsolationEstimator < T, C > *other) const {
00063 const PtInConeEstimator *concreteother = dynamic_cast<const PtInConeEstimator*>(other);
00064 int ptmincmp = cmp(_ptmin, concreteother->getPtMin());
00065 if (ptmincmp != 0)
00066 return ptmincmp;
00067 int radcmp = cmp(_radius, concreteother->getRadius());
00068 if (radcmp != 0)
00069 return radcmp;
00070 return 0;
00071 }
00072
00073 double radius() const {
00074 return _radius;
00075 }
00076
00077 double ptMin() const {
00078 return _ptmin;
00079 }
00080 private:
00081 double _radius;
00082 double _ptmin;
00083 };
00084
00085
00086
00087
00088 template < class T, class C >
00089 class MultiplicityInConeEstimator : public IsolationEstimator < T, C > {
00090 public:
00091 MultiplicityInConeEstimator(double radius, double ptmin = 0.0)
00092 : _radius(radius), _ptmin(ptmin) { }
00093
00094 virtual double estimate(const T & t, const C & c) const {
00095 double npart = 0;
00096 for (typename C::const_iterator ic = c.begin(); ic != c.end(); ++ic) {
00097 if (ic->momentum().pT() < _ptmin)
00098 continue;
00099 if (deltaR(t.momentum(), ic->momentum()) < _radius) {
00100 npart++;
00101 }
00102 }
00103 return npart;
00104 }
00105
00106 virtual int compare(const IsolationEstimator < T, C > *other) const {
00107 const MultiplicityInConeEstimator *concreteother = dynamic_cast < const MultiplicityInConeEstimator * >(other);
00108 int ptmincmp = cmp(_ptmin, concreteother->getPtMin());
00109 if (ptmincmp != 0)
00110 return ptmincmp;
00111 int radcmp = cmp(_radius, concreteother->getRadius());
00112 if (radcmp != 0)
00113 return radcmp;
00114 return 0;
00115 }
00116
00117 double radius() const {
00118 return _radius;
00119 }
00120
00121 double ptMin() const {
00122 return _ptmin;
00123 }
00124
00125 private:
00126 double _radius;
00127 double _ptmin;
00128 };
00129
00130
00131
00132 typedef MultiplicityInConeEstimator < Jet, std::vector < Jet > >JetIsoEstimatorByMultiplicity;
00133 typedef MultiplicityInConeEstimator < Particle, std::vector < Jet > >ParticleFromJetIsoEstimatorByMultiplicity;
00134 typedef MultiplicityInConeEstimator < Particle, std::vector < Particle > >ParticleIsoEstimatorByMultiplicity;
00135
00136 typedef PtInConeEstimator < Jet, std::vector < Jet > >JetIsoEstimatorByPt;
00137 typedef PtInConeEstimator < Particle, std::vector < Jet > >ParticleFromJetIsoEstimatorByPt;
00138 typedef PtInConeEstimator < Particle, std::vector < Particle > >ParticleIsoEstimatorByPt;
00139 template <typename TYPE1, typename TYPE2> struct isohelper {
00140 typedef IsolationEstimator<TYPE1, TYPE2> estimatorhelper;
00141 };
00142
00143
00144 }
00145
00146 #endif