#ifndef BLOCKCOMPARE_H #define BLOCKCOMPARE_H /** \class BlockCompare * * Definition of comparison object functions for block classes * * $Date: 2008-11-04 10:32:25 $ * $Revision: 1.1 $ * * * \author S. Ovyn - UCL, Louvain-la-Neuve * */ // Dependencies (#includes) #include "Rtypes.h" #include "TMath.h" //------------------------------------------------------------------------------ class TObject; class TCompare { public: virtual Bool_t IsSortable(const TObject *obj) const { return kTRUE; } virtual Int_t Compare(const TObject *obj1, const TObject *obj2) const = 0; virtual ~TCompare() {}; }; //--------------------------------------------------------------------------- template class TCompareE: public TCompare { TCompareE() {} public: static TCompareE *Instance() { static TCompareE single; return &single; } Int_t Compare(const TObject *obj1, const TObject *obj2) const { const T *t1 = static_cast(obj1); const T *t2 = static_cast(obj2); if(t1->E > t2->E) return -1; else if(t1->E < t2->E) return 1; else return 0; } }; //--------------------------------------------------------------------------- template class TComparePT: public TCompare { TComparePT() {} public: static TComparePT *Instance() { static TComparePT single; return &single; } Int_t Compare(const TObject *obj1, const TObject *obj2) const { const T *t1 = static_cast(obj1); const T *t2 = static_cast(obj2); if(t1->PT > t2->PT) return -1; else if(t1->PT < t2->PT) return 1; else return 0; } }; //--------------------------------------------------------------------------- template class TCompareET: public TCompare { TCompareET() {} public: static TCompareET *Instance() { static TCompareET single; return &single; } Int_t Compare(const TObject *obj1, const TObject *obj2) const { const T *t1 = static_cast(obj1); const T *t2 = static_cast(obj2); if(t1->ET > t2->ET) return -1; else if(t1->ET < t2->ET) return 1; else return 0; } }; //--------------------------------------------------------------------------- template class TCompareCalPT: public TCompare { TCompareCalPT() {} public: static TCompareCalPT *Instance() { static TCompareCalPT single; return &single; } Int_t Compare(const TObject *obj1, const TObject *obj2) const { const T *t1 = static_cast(obj1); const T *t2 = static_cast(obj2); if(t1->CalPT > t2->CalPT) return -1; else if(t1->CalPT < t2->CalPT) return 1; else return 0; } }; //--------------------------------------------------------------------------- template class TCompareCalET: public TCompare { TCompareCalET() {} public: static TCompareCalET *Instance() { static TCompareCalET single; return &single; } Int_t Compare(const TObject *obj1, const TObject *obj2) const { const T *t1 = static_cast(obj1); const T *t2 = static_cast(obj2); if(t1->CalET > t2->CalET) return -1; else if(t1->CalET < t2->CalET) return 1; else return 0; } }; //--------------------------------------------------------------------------- template class TCompareDeltaR: public TCompare { TCompareDeltaR(const T2 *obj = 0) : fObj(obj) {} Float_t DeltaPhi(Float_t phi1, Float_t phi2) { Float_t phi = TMath::Abs(phi1 - phi2); return (phi <= TMath::Pi()) ? phi : (2.0*TMath::Pi()) - phi; } Float_t Sqr(Float_t x) { return x*x; } Float_t SumSqr(Float_t a, Float_t b) { Float_t aAbs = TMath::Abs(a); Float_t bAbs = TMath::Abs(b); if(aAbs > bAbs) return aAbs * TMath::Sqrt(1.0 + Sqr(bAbs / aAbs)); else return (bAbs == 0) ? 0.0 : bAbs * TMath::Sqrt(1.0 + Sqr(aAbs / bAbs)); }; const T2 *fObj; public: static TCompareDeltaR *Instance(const T2 *obj = 0) { static TCompareDeltaR single(obj); return &single; } void SetObject(const T2 *obj) { fObj = obj; } Int_t Compare(const TObject *obj1, const TObject *obj2) const { Float_t eta[3], phi[3], deltaR[2]; const T1 *t1 = static_cast(obj1); const T1 *t2 = static_cast(obj2); eta[0] = fObj->Eta; phi[0] = fObj->Phi; eta[1] = t1->Eta; phi[1] = t1->Phi; eta[2] = t2->Eta; phi[2] = t2->Phi; deltaR[0] = SumSqr(TMath::Abs(eta[0] - eta[1]), DeltaPhi(phi[0], phi[1])); deltaR[1] = SumSqr(TMath::Abs(eta[0] - eta[2]), DeltaPhi(phi[0], phi[2])); if(deltaR[0] < deltaR[1]) return -1; else if(deltaR[0] > deltaR[1]) return 1; else return 0; } }; #endif // BLOCKCOMPARE_H