Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TrackFunctor.h

Go to the documentation of this file.
00001 #ifndef TrackEvent_TrackFunctor_H
00002 #define TrackEvent_TrackFunctor_H 1
00003 
00004 // Include files
00005 // -------------
00006 #include <functional>
00007 #include "Event/Track.h"
00008 
00024 namespace TrackFunctor
00025 {
00026 
00027 //=============================================================================
00028 // Class to test if the z of a class T is < than a certain value
00029 //=============================================================================
00030   template <class T>
00031   class less_z: public std::unary_function<T*, bool> {
00032   private:
00033     double m_z;
00034   public:
00035     explicit less_z( double z ):m_z(z) {}
00036     bool operator()( const T* t ) const 
00037     {
00038       return t -> z() < m_z;
00039     }
00040   };
00041   
00042 //=============================================================================
00043 // Class to test if the z of a class T is > than a certain value
00044 //=============================================================================
00045   template <class T>
00046   class greater_z: public std::unary_function<T*, bool> {
00047   private:
00048     double m_z;
00049   public:
00050     explicit greater_z( double z ):m_z(z) {}
00051     bool operator()( const T* t ) const 
00052     {
00053       return t -> z() > m_z;
00054     }
00055   };
00056   
00057 //=============================================================================
00058 // select T object close to z position
00059 //=============================================================================
00060   template <class T>
00061   class closestToZ {
00062   private:
00063     double m_z0;
00064   public:
00065     explicit closestToZ( double z0 = 0.):m_z0(z0) {}
00066     const T* operator()( const T* t1,
00067                          const T* t2 ) const
00068     {
00069       return (fabs(t1->z()-m_z0) < fabs(t2->z()-m_z0))? t1:t2;
00070     }
00071   };
00072 
00073 //=============================================================================
00074 // select T object close to plane position
00075 //=============================================================================
00076   template <class T>
00077   class closestToPlane {
00078   private:
00079     HepPlane3D m_plane;
00080   public:
00081     explicit closestToPlane(const HepPlane3D& plane):m_plane(plane) {}
00082     const T* operator()( const T* t1,
00083                          const T* t2 ) const
00084     {
00085       double d1 = fabs(m_plane.distance(t1->position()));
00086       double d2 = fabs(m_plane.distance(t2->position()));
00087       return (d1 < d2)? t1:t2;
00088     }
00089   };
00090 
00091 //=============================================================================
00092 // Class for sorting class T by z in order (+1/-1)
00093 //=============================================================================
00094   template <class T>
00095   class orderByZ {
00096   private:
00097     int m_order;
00098   public:
00099     explicit orderByZ( int order = +1):m_order(order) {}
00100     bool operator()( const T* t1,
00101                      const T* t2 ) const
00102     {
00103       return (m_order)*t1->z() > (m_order)*t2->z();
00104     }
00105   };
00106 
00107 
00108 //=============================================================================
00109 // Class for sorting class T by increasing z
00110 //=============================================================================
00111   template <class T>
00112   class increasingByZ {
00113   public:
00114     bool operator()( const T* t1,
00115                      const T* t2 ) const
00116     {
00117       return t1->z() < t2->z();
00118     }
00119   };
00120 
00121 //=============================================================================
00122 // Class for sorting class T by decreasing z
00123 //=============================================================================
00124   template <class T>
00125   class decreasingByZ {
00126   public:
00127     bool operator()( const T* t1,
00128                      const T* t2 ) const
00129     {
00130       return t1->z() > t2->z();
00131     }
00132   };
00133 
00134   template <class T>
00135   class HasKey: public std::unary_function<T*, bool> {
00136   public:
00137     // A predicate (unary bool function):
00138     // example:
00139     // HasKey<Track> isBackward = 
00140     // HasKey<Track>(&Track::checkFlag,TrackKeys::Backwards)
00141     // if (isBackward(track)) ...
00142     typedef bool (T::* ptr_memfun) (unsigned int) const;
00143   private:
00144     ptr_memfun m_pmf;
00145     unsigned int m_key;
00146   public:
00147     explicit HasKey(ptr_memfun check, unsigned int key ):
00148       m_pmf(check),m_key(key) {}
00149     bool operator()( const T* t ) const 
00150     {
00151       return (t ->* m_pmf) (m_key);
00152     }
00153   };  
00154 
00155   template <class T>
00156   void deleteFromList(std::vector<T*>& List, T* value) 
00157   {
00158     typename std::vector<T*>::iterator it;
00159     it = std::remove(List.begin(), List.end(), value );
00160     delete *it;
00161     List.erase( it, List.end() );
00162   }
00163 
00164   template <class T>
00165   unsigned int nMeasurements(const Track& track, T& pred) 
00166   {
00167     const std::vector<LHCbID>& ids = track.lhcbIDs();
00168     return std::count_if(ids.begin(),ids.end(),pred);
00169   }
00170   
00171 }
00172 
00173 #endif   

Generated on Fri May 27 13:59:37 2005 for New Track Event Model by doxygen 1.4.1