CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoEgamma/EgammaElectronAlgos/interface/ElectronUtilities.h

Go to the documentation of this file.
00001 #ifndef RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
00002 #define RecoEgamma_EgammaElectronAlgos_ElectronUtilities_H
00003 
00004 #include <DataFormats/GeometryVector/interface/GlobalPoint.h>
00005 #include <DataFormats/GeometryVector/interface/GlobalVector.h>
00006 #include <DataFormats/Math/interface/Point3D.h>
00007 #include <DataFormats/Math/interface/Vector3D.h>
00008 #include <CLHEP/Units/GlobalPhysicalConstants.h>
00009 
00010 
00011 //===============================================================
00012 // For an stl collection of pointers, enforce the deletion
00013 // of pointed objects in case of exception.
00014 //===============================================================
00015 
00016 template <typename StlColType>
00017 class ExceptionSafeStlPtrCol : public StlColType
00018  {
00019   public :
00020     ExceptionSafeStlPtrCol() : StlColType() {}
00021     ~ExceptionSafeStlPtrCol()
00022      {
00023       typename StlColType::const_iterator it ;
00024       for ( it = StlColType::begin() ; it != StlColType::end() ; it++ )
00025        { delete (*it) ; }
00026      }
00027  } ;
00028 
00029 
00030 //===============================================================
00031 // Normalization of angles
00032 //===============================================================
00033 
00034 template <typename RealType>
00035 RealType normalized_phi( RealType phi )
00036  {
00037   if (phi>CLHEP::pi)
00038    { phi -= (2*CLHEP::pi) ; }
00039   if (phi<-CLHEP::pi)
00040    { phi += (2*CLHEP::pi) ; }
00041   return phi ;
00042  }
00043 
00044 
00045 //===============================================================
00046 // Convert between flavors of points and vectors,
00047 // assuming existence of x(), y() and z().
00048 //===============================================================
00049 
00050 template <typename Type1, typename Type2>
00051 void ele_convert( const Type1 & obj1, Type2 & obj2 )
00052  { obj2 = Type2(obj1.x(),obj1.y(),obj1.z()) ; }
00053 
00054 
00055 //===============================================================
00056 // When wanting to compute and compare several characteristics of
00057 // one or two points, relatively to a given origin
00058 //===============================================================
00059 
00060 class EleRelPoint
00061  {
00062   public :
00063     EleRelPoint( const math::XYZPoint & p, const math::XYZPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
00064     EleRelPoint( const GlobalPoint & p, const math::XYZPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
00065     EleRelPoint( const math::XYZPoint & p, const GlobalPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
00066     EleRelPoint( const GlobalPoint & p, const GlobalPoint & origin ) : relP_(p.x()-origin.x(),p.y()-origin.y(),p.z()-origin.z()) {}
00067     double eta() { return relP_.eta() ; }
00068     double phi() { return normalized_phi(relP_.phi()) ; }
00069     double perp() { return sqrt(relP_.x()*relP_.x()+relP_.y()*relP_.y()) ; }
00070   private :
00071     math::XYZVector relP_ ;
00072  } ;
00073 
00074 class EleRelPointPair
00075  {
00076   public :
00077     EleRelPointPair( const math::XYZPoint & p1, const math::XYZPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00078     EleRelPointPair( const GlobalPoint & p1, const math::XYZPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00079     EleRelPointPair( const math::XYZPoint & p1, const GlobalPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00080     EleRelPointPair( const math::XYZPoint & p1, const math::XYZPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00081     EleRelPointPair( const GlobalPoint & p1, const GlobalPoint & p2, const math::XYZPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00082     EleRelPointPair( const math::XYZPoint & p1, const GlobalPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00083     EleRelPointPair( const GlobalPoint & p1, const math::XYZPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00084     EleRelPointPair( const GlobalPoint & p1, const GlobalPoint & p2, const GlobalPoint & origin ) : relP1_(p1.x()-origin.x(),p1.y()-origin.y(),p1.z()-origin.z()), relP2_(p2.x()-origin.x(),p2.y()-origin.y(),p2.z()-origin.z()) {}
00085     double dEta() { return (relP1_.eta()-relP2_.eta()) ; }
00086     double dPhi() { return normalized_phi(relP1_.phi()-relP2_.phi()) ; }
00087     double dZ() { return (relP1_.z()-relP2_.z()) ; }
00088     double dPerp() { return normalized_phi(relP1_.perp()-relP2_.perp()) ; }
00089   private :
00090     GlobalVector relP1_ ;
00091     GlobalVector relP2_ ;
00092  } ;
00093 
00094 
00095 //===============================================================
00096 // Low level functions for the computing of characteristics
00097 // relatively to a given origin. Not meant to improve
00098 // performance, but rather for the easy later localization
00099 // of all such transformations.
00100 //===============================================================
00101 
00102 template <typename PointType>
00103 double relative_eta( const PointType & p, const PointType & origin )
00104  { return (p-origin).eta() ; }
00105 
00106 template <typename PointType>
00107 double relative_phi( const PointType & p, const PointType & origin )
00108  { return normalized_phi((p-origin).phi()) ; }
00109 
00110 
00111 #endif
00112