CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DataFormats/RecoCandidate/interface/IsoDepositDirection.h

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