00001 #ifndef MuonIsolation_Direction_H
00002 #define MuonIsolation_Direction_H
00003
00009 #ifndef USE_MUISODEPOSIT_REQUIRED
00010 #error THIS FILE IS NOT SUPPOSED TO BE INCLUDED: USE "DataFormats/RecoCandidate/interface/IsoDepositDirection.h" instead
00011 #error THIS FILE IS HERE FOR BKW COMPATIBILITY ONLY
00012
00013
00014 #else
00015
00016 #include <cmath>
00017 #include <sstream>
00018 #include <iostream>
00019
00020 #include "PhysicsTools/Utilities/interface/deltaR.h"
00021 #include "PhysicsTools/Utilities/interface/deltaPhi.h"
00022
00023
00024 namespace muonisolation {
00025
00026 class Direction {
00027 public:
00028
00029 struct Distance {
00030 float deltaR;
00031 float relativeAngle;
00032 bool operator < (const Distance & rd2) const { return deltaR < rd2.deltaR; };
00033 };
00034
00035 Direction(double eta = 0., double phi = 0.) : theEta(eta), thePhi(phi) {
00036 while( thePhi < 0.0 ) thePhi += 2*M_PI;
00037 while( thePhi >= 2*M_PI ) thePhi -= 2*M_PI;
00038 };
00039
00040 double eta() const { return theEta; }
00041 double phi() const { return thePhi; }
00042 double theta() const { return acos(tanh(theEta)); }
00043
00044 inline bool operator==(const Direction & d2) {
00045 if ( this == &d2 ) return true;
00046 if ( deltaR(d2) < 1.e-4) return true;
00047 return false;
00048 }
00049
00050 inline double deltaR2(const Direction & dir2) const {
00051 return reco::deltaR2(*this, dir2);
00052 }
00053 inline double deltaR(const Direction & dir2) const {
00054 return reco::deltaR(*this, dir2);
00055 }
00056
00057 Distance operator- (const Direction & dir2) const {
00058 Distance result;
00059 double dR = deltaR(dir2);
00060 double dEta = theEta-dir2.eta();
00061 double dPhi = reco::deltaPhi(thePhi,dir2.phi());
00062
00063 result.relativeAngle = (dR > 1.e-4) ? atan2(dPhi,dEta) : 0.;
00064 result.deltaR = dR;
00065 return result;
00066 }
00067
00068 Direction operator+ (const Distance & relDir) const {
00069 double eta = theEta + relDir.deltaR*cos(relDir.relativeAngle);
00070 double phi = thePhi + relDir.deltaR*sin(relDir.relativeAngle);
00071 return Direction(eta,phi);
00072 }
00073
00074 std::string print() const {
00075 std::ostringstream str;
00076 str<<" (Eta="<<theEta<< "," << "Phi=" <<thePhi<<")";
00077 return str.str();
00078 }
00079
00080 private:
00081 float theEta;
00082 float thePhi;
00083 };
00084
00085 }
00086
00087 #endif //USE_MUISODEPOSIT_REQUIRED
00088 #endif