rivet is hosted by Hepforge, IPPP Durham
ParticleBaseUtils.hh
Go to the documentation of this file.
00001 #ifndef RIVET_PARTICLEBASEUTILS_HH
00002 #define RIVET_PARTICLEBASEUTILS_HH
00003 
00004 #include "Rivet/ParticleBase.hh"
00005 
00006 namespace Rivet {
00007 
00008 
00009   /// @name ParticleBase classifier -> bool functors
00010   /// @todo Move to FourMomentum functions
00011   ///
00012   /// To be passed to any() or all() e.g. any(jets, DeltaRLess(electron, 0.4))
00013   //@{
00014 
00015   /// Base type for Particle -> bool functors
00016   struct BoolParticleBaseFunctor {
00017     virtual bool operator()(const ParticleBase& p) const = 0;
00018   };
00019 
00020   /// Transverse momentum greater-than functor
00021   struct PtGtr : public BoolParticleBaseFunctor {
00022     PtGtr(double pt) : ptcut(pt) { }
00023     bool operator()(const ParticleBase& p) const { return p.pT() > ptcut; }
00024     double ptcut;
00025   };
00026   using pTGtr = PtGtr;
00027   using ptGtr = PtGtr;
00028 
00029   /// Transverse momentum less-than functor
00030   struct PtLess : public BoolParticleBaseFunctor {
00031     PtLess(double pt) : ptcut(pt) { }
00032     bool operator()(const ParticleBase& p) const { return p.pT() < ptcut; }
00033     double ptcut;
00034   };
00035   using pTLess = PtLess;
00036   using ptLess = PtLess;
00037 
00038 
00039   /// Pseudorapidity greater-than functor
00040   struct EtaGtr : public BoolParticleBaseFunctor {
00041     EtaGtr(double eta) : etacut(eta) { }
00042     bool operator()(const ParticleBase& p) const { return p.eta() > etacut; }
00043     double etacut;
00044   };
00045   using etaGtr = EtaGtr;
00046 
00047   /// Pseudorapidity momentum less-than functor
00048   struct EtaLess : public BoolParticleBaseFunctor {
00049     EtaLess(double eta) : etacut(eta) { }
00050     bool operator()(const ParticleBase& p) const { return p.eta() < etacut; }
00051     double etacut;
00052   };
00053   using etaLess = EtaLess;
00054 
00055   /// Abs pseudorapidity greater-than functor
00056   struct AbsEtaGtr : public BoolParticleBaseFunctor {
00057     AbsEtaGtr(double abseta) : absetacut(abseta) { }
00058     bool operator()(const ParticleBase& p) const { return p.abseta() > absetacut; }
00059     double absetacut;
00060   };
00061   using absEtaGtr = AbsEtaGtr;
00062   using absetaGtr = AbsEtaGtr;
00063 
00064   /// Abs pseudorapidity momentum less-than functor
00065   struct AbsEtaLess : public BoolParticleBaseFunctor {
00066     AbsEtaLess(double abseta) : absetacut(abseta) { }
00067     bool operator()(const ParticleBase& p) const { return p.abseta() < absetacut; }
00068     double absetacut;
00069   };
00070   using absEtaLess = AbsEtaLess;
00071   using absetaLess = AbsEtaLess;
00072 
00073 
00074   /// Rapidity greater-than functor
00075   struct RapGtr : public BoolParticleBaseFunctor {
00076     RapGtr(double rap) : rapcut(rap) { }
00077     bool operator()(const ParticleBase& p) const { return p.rap() > rapcut; }
00078     double rapcut;
00079   };
00080   using rapGtr = RapGtr;
00081 
00082   /// Rapidity momentum less-than functor
00083   struct RapLess : public BoolParticleBaseFunctor {
00084     RapLess(double rap) : rapcut(rap) { }
00085     bool operator()(const ParticleBase& p) const { return p.rap() < rapcut; }
00086     double rapcut;
00087   };
00088   using rapLess = RapLess;
00089 
00090   /// Abs rapidity greater-than functor
00091   struct AbsRapGtr : public BoolParticleBaseFunctor {
00092     AbsRapGtr(double absrap) : absrapcut(absrap) { }
00093     bool operator()(const ParticleBase& p) const { return p.absrap() > absrapcut; }
00094     double absrapcut;
00095   };
00096   using absRapGtr = AbsRapGtr;
00097   using absrapGtr = AbsRapGtr;
00098 
00099   /// Abs rapidity momentum less-than functor
00100   struct AbsRapLess : public BoolParticleBaseFunctor {
00101     AbsRapLess(double absrap) : absrapcut(absrap) { }
00102     bool operator()(const ParticleBase& p) const { return p.absrap() < absrapcut; }
00103     double absrapcut;
00104   };
00105   using absRapLess = AbsRapLess;
00106   using absrapLess = AbsRapLess;
00107 
00108 
00109   /// @f$ \Delta R @f$ (with respect to another 4-momentum, @a vec) greater-than functor
00110   struct DeltaRGtr : public BoolParticleBaseFunctor {
00111     DeltaRGtr(const ParticleBase& vec, double dr, RapScheme scheme=PSEUDORAPIDITY)
00112       : refvec(vec.mom()), drcut(dr), rapscheme(scheme) { }
00113     DeltaRGtr(const FourMomentum& vec, double dr, RapScheme scheme=PSEUDORAPIDITY)
00114       : refvec(vec), drcut(dr), rapscheme(scheme) { }
00115     DeltaRGtr(const Vector3& vec, double dr)
00116       : drcut(dr), rapscheme(PSEUDORAPIDITY) { refvec.setPx(vec.x()); refvec.setPy(vec.y()); refvec.setPz(vec.z()); }
00117     bool operator()(const ParticleBase& p) const { return deltaR(p, refvec, rapscheme) > drcut; }
00118     FourMomentum refvec;
00119     double drcut;
00120     RapScheme rapscheme;
00121   };
00122   using deltaRGtr = DeltaRGtr;
00123 
00124   /// @f$ \Delta R @f$ (with respect to another 4-momentum, @a vec) less-than functor
00125   struct DeltaRLess : public BoolParticleBaseFunctor {
00126     DeltaRLess(const ParticleBase& vec, double dr, RapScheme scheme=PSEUDORAPIDITY)
00127       : refvec(vec.mom()), drcut(dr), rapscheme(scheme) { }
00128     DeltaRLess(const FourMomentum& vec, double dr, RapScheme scheme=PSEUDORAPIDITY)
00129       : refvec(vec), drcut(dr), rapscheme(scheme) { }
00130     DeltaRLess(const Vector3& vec, double dr)
00131       : drcut(dr), rapscheme(PSEUDORAPIDITY) { refvec.setPx(vec.x()); refvec.setPy(vec.y()); refvec.setPz(vec.z()); }
00132     bool operator()(const ParticleBase& p) const { return deltaR(p, refvec, rapscheme) < drcut; }
00133     FourMomentum refvec;
00134     double drcut;
00135     RapScheme rapscheme;
00136   };
00137   using deltaRLess = DeltaRLess;
00138 
00139 
00140   /// @f$ |\Delta \phi| @f$ (with respect to another momentum, @a vec) greater-than functor
00141   struct DeltaPhiGtr : public BoolParticleBaseFunctor {
00142     DeltaPhiGtr(const ParticleBase& vec, double dphi)
00143       : refvec(vec.p3()), dphicut(dphi) { }
00144     DeltaPhiGtr(const FourMomentum& vec, double dphi)
00145       : refvec(vec.p3()), dphicut(dphi) { }
00146     DeltaPhiGtr(const Vector3& vec, double dphi)
00147       : refvec(vec), dphicut(dphi) { }
00148     bool operator()(const ParticleBase& p) const { return deltaPhi(p, refvec) > dphicut; }
00149     Vector3 refvec;
00150     double dphicut;
00151   };
00152   using deltaPhiGtr = DeltaPhiGtr;
00153 
00154   /// @f$ |\Delta \phi| @f$ (with respect to another momentum, @a vec) less-than functor
00155   struct DeltaPhiLess : public BoolParticleBaseFunctor {
00156     DeltaPhiLess(const ParticleBase& vec, double dphi)
00157       : refvec(vec.p3()), dphicut(dphi) { }
00158     DeltaPhiLess(const FourMomentum& vec, double dphi)
00159       : refvec(vec.p3()), dphicut(dphi) { }
00160     DeltaPhiLess(const Vector3& vec, double dphi)
00161       : refvec(vec), dphicut(dphi) { }
00162     bool operator()(const ParticleBase& p) const { return deltaPhi(p, refvec) < dphicut; }
00163     Vector3 refvec;
00164     double dphicut;
00165   };
00166   using deltaPhiLess = DeltaPhiLess;
00167 
00168 
00169   /// @f$ |\Delta \eta| @f$ (with respect to another momentum, @a vec) greater-than functor
00170   struct DeltaEtaGtr : public BoolParticleBaseFunctor {
00171     DeltaEtaGtr(const ParticleBase& vec, double deta)
00172       : refvec(vec.p3()), detacut(deta) { }
00173     DeltaEtaGtr(const FourMomentum& vec, double deta)
00174       : refvec(vec.p3()), detacut(deta) { }
00175     DeltaEtaGtr(const Vector3& vec, double deta)
00176       : refvec(vec), detacut(deta) { }
00177     bool operator()(const ParticleBase& p) const { return std::abs(deltaEta(p, refvec)) > detacut; }
00178     Vector3 refvec;
00179     double detacut;
00180   };
00181   using deltaEtaGtr = DeltaEtaGtr;
00182 
00183   /// @f$ |\Delta \eta| @f$ (with respect to another momentum, @a vec) less-than functor
00184   struct DeltaEtaLess : public BoolParticleBaseFunctor {
00185     DeltaEtaLess(const ParticleBase& vec, double deta)
00186       : refvec(vec.p3()), detacut(deta) { }
00187     DeltaEtaLess(const FourMomentum& vec, double deta)
00188       : refvec(vec.p3()), detacut(deta) { }
00189     DeltaEtaLess(const Vector3& vec, double deta)
00190       : refvec(vec), detacut(deta) { }
00191     bool operator()(const ParticleBase& p) const { return std::abs(deltaEta(p, refvec)) < detacut; }
00192     Vector3 refvec;
00193     double detacut;
00194   };
00195   using deltaEtaLess = DeltaEtaLess;
00196 
00197 
00198   /// @f$ |\Delta y| @f$ (with respect to another momentum, @a vec) greater-than functor
00199   struct DeltaRapGtr : public BoolParticleBaseFunctor {
00200     DeltaRapGtr(const ParticleBase& vec, double drap)
00201       : refvec(vec.mom()), drapcut(drap) { }
00202     DeltaRapGtr(const FourMomentum& vec, double drap)
00203       : refvec(vec), drapcut(drap) { }
00204     bool operator()(const ParticleBase& p) const { return std::abs(deltaRap(p, refvec)) > drapcut; }
00205     FourMomentum refvec;
00206     double drapcut;
00207   };
00208   using deltaRapGtr = DeltaRapGtr;
00209 
00210   /// @f$ |\Delta y| @f$ (with respect to another momentum, @a vec) less-than functor
00211   struct DeltaRapLess : public BoolParticleBaseFunctor {
00212     DeltaRapLess(const ParticleBase& vec, double drap)
00213       : refvec(vec.mom()), drapcut(drap) { }
00214     DeltaRapLess(const FourMomentum& vec, double drap)
00215       : refvec(vec), drapcut(drap) { }
00216     bool operator()(const ParticleBase& p) const { return std::abs(deltaRap(p, refvec)) < drapcut; }
00217     FourMomentum refvec;
00218     double drapcut;
00219   };
00220   using deltaRapLess = DeltaRapLess;
00221 
00222   //@}
00223 
00224 
00225   /// @name ParticleBase comparison -> double functors
00226   /// @todo Move to FourMomentum functions
00227   ///
00228   /// To be passed to transform()any(jets, DeltaRLess(electron, 0.4))
00229   //@{
00230 
00231   /// Base type for Particle -> double functors
00232   struct DoubleParticleBaseFunctor {
00233     virtual double operator()(const ParticleBase& p) const = 0;
00234   };
00235 
00236   /// Calculator of @f$ \Delta R @f$ with respect to a given momentum
00237   struct DeltaRWRT : public DoubleParticleBaseFunctor {
00238     DeltaRWRT(const ParticleBase& pb, RapScheme scheme=PSEUDORAPIDITY) : p(pb.mom()) {}
00239     DeltaRWRT(const FourMomentum& p4, RapScheme scheme=PSEUDORAPIDITY) : p(p4) {}
00240     DeltaRWRT(const Vector3& p3) : p(p3.mod(), p3.x(), p3.y(), p3.z()), rapscheme(PSEUDORAPIDITY) {}
00241     double operator()(const ParticleBase& pb) const { return deltaR(p, pb, rapscheme); }
00242     double operator()(const FourMomentum& p4) const { return deltaR(p, p4, rapscheme); }
00243     double operator()(const Vector3& p3) const { return deltaR(p, p3); }
00244     const FourMomentum p;
00245     RapScheme rapscheme;
00246   };
00247   using deltaRWRT = DeltaRWRT;
00248 
00249   /// Calculator of @f$ \Delta \phi @f$ with respect to a given momentum
00250   struct DeltaPhiWRT : public DoubleParticleBaseFunctor {
00251     DeltaPhiWRT(const ParticleBase& pb) : p(pb.mom().vector3()) {}
00252     DeltaPhiWRT(const FourMomentum& p4) : p(p4.vector3()) {}
00253     DeltaPhiWRT(const Vector3& p3) : p(p3) {}
00254     double operator()(const ParticleBase& pb) const { return deltaPhi(p, pb); }
00255     double operator()(const FourMomentum& p4) const { return deltaPhi(p, p4); }
00256     double operator()(const Vector3& p3) const { return deltaPhi(p, p3); }
00257     const Vector3 p;
00258   };
00259   using deltaPhiWRT = DeltaPhiWRT;
00260 
00261   /// Calculator of @f$ \Delta \eta @f$ with respect to a given momentum
00262   struct DeltaEtaWRT : public DoubleParticleBaseFunctor {
00263     DeltaEtaWRT(const ParticleBase& pb) : p(pb.mom().vector3()) {}
00264     DeltaEtaWRT(const FourMomentum& p4) : p(p4.vector3()) {}
00265     DeltaEtaWRT(const Vector3& p3) : p(p3) {}
00266     double operator()(const ParticleBase& pb) const { return deltaEta(p, pb); }
00267     double operator()(const FourMomentum& p4) const { return deltaEta(p, p4); }
00268     double operator()(const Vector3& p3) const { return deltaEta(p, p3); }
00269     const Vector3 p;
00270   };
00271   using deltaEtaWRT = DeltaEtaWRT;
00272 
00273   /// Calculator of @f$ |\Delta \eta| @f$ with respect to a given momentum
00274   struct AbsDeltaEtaWRT : public DoubleParticleBaseFunctor {
00275     AbsDeltaEtaWRT(const ParticleBase& pb) : p(pb.mom().vector3()) {}
00276     AbsDeltaEtaWRT(const FourMomentum& p4) : p(p4.vector3()) {}
00277     AbsDeltaEtaWRT(const Vector3& p3) : p(p3) {}
00278     double operator()(const ParticleBase& pb) const { return fabs(deltaEta(p, pb)); }
00279     double operator()(const FourMomentum& p4) const { return fabs(deltaEta(p, p4)); }
00280     double operator()(const Vector3& p3) const { return fabs(deltaEta(p, p3)); }
00281     const Vector3 p;
00282   };
00283   using absDeltaEtaWRT = AbsDeltaEtaWRT;
00284 
00285   /// Calculator of @f$ \Delta y @f$ with respect to a given momentum
00286   struct DeltaRapWRT : public DoubleParticleBaseFunctor {
00287     DeltaRapWRT(const ParticleBase& pb) : p(pb.mom()) {}
00288     DeltaRapWRT(const FourMomentum& p4) : p(p4) {}
00289     double operator()(const ParticleBase& pb) const { return deltaRap(p, pb); }
00290     double operator()(const FourMomentum& p4) const { return deltaRap(p, p4); }
00291     const FourMomentum p;
00292   };
00293   using deltaRapWRT = DeltaRapWRT;
00294 
00295   /// Calculator of @f$ |\Delta y| @f$ with respect to a given momentum
00296   struct AbsDeltaRapWRT : public DoubleParticleBaseFunctor {
00297     AbsDeltaRapWRT(const ParticleBase& pb) : p(pb.mom()) {}
00298     AbsDeltaRapWRT(const FourMomentum& p4) : p(p4) {}
00299     double operator()(const ParticleBase& pb) const { return fabs(deltaRap(p, pb)); }
00300     double operator()(const FourMomentum& p4) const { return fabs(deltaRap(p, p4)); }
00301     const FourMomentum p;
00302   };
00303   using absDeltaRapWRT = AbsDeltaRapWRT;
00304 
00305   //@}
00306 
00307 
00308   /// @name Non-PID particle properties, via unbound functions
00309   /// @todo Mostly move to functions on FourMomentum
00310   //@{
00311 
00312   /// Unbound function access to momentum
00313   inline FourMomentum mom(const ParticleBase& p) { return p.mom(); }
00314 
00315   /// Unbound function access to p3
00316   inline Vector3 p3(const ParticleBase& p) { return p.p3(); }
00317 
00318   /// Unbound function access to p
00319   inline double p(const ParticleBase& p) { return p.p(); }
00320 
00321   /// Unbound function access to pT
00322   inline double pT(const ParticleBase& p) { return p.pT(); }
00323 
00324   /// Unbound function access to eta
00325   inline double eta(const ParticleBase& p) { return p.eta(); }
00326 
00327   /// Unbound function access to abseta
00328   inline double abseta(const ParticleBase& p) { return p.abseta(); }
00329 
00330   /// Unbound function access to rapidity
00331   inline double rap(const ParticleBase& p) { return p.rap(); }
00332 
00333   /// Unbound function access to abs rapidity
00334   inline double absrap(const ParticleBase& p) { return p.absrap(); }
00335 
00336   //@}
00337 
00338 
00339 }
00340 
00341 #endif