Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:14

0001 #ifndef Surface_GeometricSorting_h
0002 #define Surface_GeometricSorting_h
0003 
0004 #include <functional>
0005 #include <DataFormats/GeometryVector/interface/Phi.h>
0006 
0007 namespace geomsort {
0008 
0009   /** \class ExtractR
0010  *
0011  *  functor to sort in R using precomputed_value_sort.
0012  *  Can be used for any object with a member position(). 
0013  *  
0014  *  Use: 
0015  *
0016  *  precomputed_value_sort(v.begin(), v.end(), ExtractR<Surface>());
0017  *
0018  *  \author N. Amapane - CERN
0019  */
0020 
0021   template <class T, class Scalar = typename T::Scalar>
0022   struct ExtractR {
0023     typedef Scalar result_type;
0024     Scalar operator()(const T* p) const { return p->position().perp(); }
0025     Scalar operator()(const T& p) const { return p.position().perp(); }
0026   };
0027 
0028   /** \class ExtractPhi
0029  *
0030  *  functor to sort in phi (from -pi to pi) using precomputed_value_sort.
0031  *  Can be used for any object with a member position(). 
0032  *
0033  *  Note that sorting in phi is done within the phi range of 
0034  *  (-pi, pi]. It may NOT be what you expect if the elements cluster around
0035  *  the pi discontinuity.
0036  *  
0037  *  Use: 
0038  *
0039  *  precomputed_value_sort(v.begin(), v.end(), ExtractPhi<Surface>());
0040  *
0041  *  \author N. Amapane - CERN
0042  */
0043 
0044   template <class T, class Scalar = typename T::Scalar>
0045   struct ExtractPhi {
0046     typedef Geom::Phi<Scalar> result_type;
0047     Geom::Phi<Scalar> operator()(const T* p) const { return p->position().phi(); }
0048     Geom::Phi<Scalar> operator()(const T& p) const { return p.position().phi(); }
0049   };
0050 
0051   /** \class ExtractZ
0052  *
0053  *  functor to sort in Z using precomputed_value_sort.
0054  *  Can be used for any object with a member position(). 
0055  *  
0056  *  Use: 
0057  *
0058  *  precomputed_value_sort(v.begin(), v.end(), ExtractZ<Surface>());
0059  *
0060  *  \author N. Amapane - CERN
0061  */
0062 
0063   template <class T, class Scalar = typename T::Scalar>
0064   struct ExtractZ {
0065     typedef Scalar result_type;
0066     Scalar operator()(const T* p) const { return p->position().z(); }
0067     Scalar operator()(const T& p) const { return p.position().z(); }
0068   };
0069 
0070   /** \class ExtractAbsZ
0071  *
0072  *  functor to sort in |Z| using precomputed_value_sort.
0073  *  Can be used for any object with a member position(). 
0074  *  
0075  *  Use: 
0076  *
0077  *  precomputed_value_sort(v.begin(), v.end(), ExtractAbsZ<Surface>());
0078  *
0079  *  \author N. Amapane - CERN
0080  */
0081 
0082   template <class T, class Scalar = typename T::Scalar>
0083   struct ExtractAbsZ {
0084     typedef Scalar result_type;
0085     Scalar operator()(const T* p) const { return fabs(p->position().z()); }
0086     Scalar operator()(const T& p) const { return fabs(p.position().z()); }
0087   };
0088 
0089 }  // namespace geomsort
0090 #endif