Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

FunctionObjects.h

Go to the documentation of this file.
00001 //================================================
00002 //
00003 // A set of "function objects"  for use with some 
00004 // STL generic algorithms.
00005 //
00006 // ===============================================
00007 //
00008 //  The function objects implemented here allow STL generic algortihms
00009 //  to be used on iterable collections containing any objects which
00010 //  honour the 
00011 //           IKinematic interface
00012 //
00013 //  I.e. if your object inherits as:
00014 //       class YourObject : virtual public IKinematic
00015 //  then these will work for you.
00016 //
00017 //  The collections may contain the objects themselves, or pointers to
00018 //  the objects
00019 // 
00020 //  Currently included:
00021 //  
00022 //  Function objects for sort  (in namespace SortAttribute )
00023 //
00024 //      AscendingPhi       DescendingPhi       simple sort by phi
00025 //      AscendingEta       DescendingEta       simple sort by eta
00026 //      AscendingET        DescendingET        simple sort by trans. energy
00027 //      AscendingPT        DescendingPT        simple sort by trans. momentum
00028 //      AscendingMT        DescendingMT        simple sort by trans. mass
00029 //      
00030 //      DeltaPhi    sort by increasing distance in phi from a reference
00031 //      DeltaEta    sort by increasing distance in eta from a reference
00032 //      DeltaR      sort by increasing distance in eta-phi from a reference
00033 //      (note the reference is set in the constructor)
00034 //
00035 
00036 #ifndef ATLFAST_FUNCTIONOBJECTS_H
00037 #define ATLFAST_FUNCTIONOBJECTS_H
00038 
00039 #include "AtlfastEvent/IKinematic.h"
00040 #include "AtlfastEvent/Phi.h"
00041 
00042 #include <cmath>
00043 
00044 
00045 //--------------------------------------------------------
00046 //
00047 // Function objects for sort
00048 //
00049 
00050 namespace SortAttribute {
00051   using std::abs;
00052   
00053   //............ phi ...........
00054 
00055 
00062   class AscendingPhi {
00063   public:
00064     bool operator() 
00065       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const { 
00066       return( a->phi() < b->phi() ) ; }
00067     
00068      bool operator() 
00069       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00070        { return this->operator() ( &a, &b ) ; }
00071   };
00078   class DescendingPhi {
00079   public:
00080     bool operator() 
00081       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00082       { return( a->phi() > b->phi() ) ; }
00083     bool operator() 
00084       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00085       { return( a.phi() > b.phi() ) ; }
00086   };
00087 
00088   
00089   //........... eta ..............
00096   class AscendingEta {
00097   public:
00098     bool operator() 
00099       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00100       { return( a->eta() < b->eta() ) ; }
00101     bool operator() 
00102       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00103       { return( a.eta() < b.eta() ) ; }
00104   };
00111   class DescendingEta {
00112   public:
00113     bool operator() 
00114       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00115       { return( a->eta() > b->eta() ) ; }
00116     bool operator() 
00117      ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00118       { return( a.eta() > b.eta() ) ; }
00119   };
00120 
00121 
00122 //........... eT ..............
00123 
00130   class AscendingET {
00131   public:
00132     
00133     // For sorting
00134     bool operator() 
00135       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00136       { return( a->eT() < b->eT() ) ; }
00137     bool operator() 
00138       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00139       { return( a.eT() < b.eT() ) ; }
00140 
00141    // For applying cuts - not documented yet
00142     bool operator() 
00143       ( const double boundary , const Atlfast::IKinematic* a ) const
00144       { return (boundary  < a->eT()) ; }
00145     bool operator() 
00146       ( const double boundary , const Atlfast::IKinematic& a ) const
00147       { return (boundary  < a.eT()) ; }
00148 
00149   };
00156   class DescendingET {
00157   public:
00158     bool operator() 
00159       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00160       { return( a->eT() > b->eT() ) ; }
00161     bool operator() 
00162       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00163       { return( a.eT() > b.eT() ) ; }
00164   };
00165 
00166 
00167   //........... pT ..............
00174   class AscendingPT {
00175   public:
00176     bool operator() 
00177       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00178       { return( a->pT() < b->pT() ) ; }
00179     bool operator() 
00180       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00181       { return( a.pT() < b.pT() ) ; }
00182   };
00189   class DescendingPT {
00190   public:
00191     bool operator() 
00192       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00193       { return( a->pT() > b->pT() ) ; }
00194     bool operator() 
00195       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00196       { return( a.pT() > b.pT() ) ; }
00197   };
00198 
00199 
00200   //........... mT ..............
00207   class AscendingMT {
00208   public:
00209     bool operator() 
00210       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00211       { return( a->mT() < b->mT() ) ; }
00212     bool operator() 
00213       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00214       { return( a.mT() < b.mT() ) ; }
00215   };
00222   class DescendingMT {
00223   public:
00224     bool operator() 
00225       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00226       { return( a->mT() > b->mT() ) ; }
00227     bool operator() 
00228       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00229       { return( a.mT() > b.mT() ) ; }
00230   };
00231   
00232   //........... Delta phi ..............
00239   class DeltaPhi {
00240     
00241   private:
00242     Atlfast::IKinematic* ref ;
00243 
00244   public:
00245     
00246     // Constructors which accept the reference 
00247     DeltaPhi( Atlfast::IKinematic* reference ) : ref(reference) {} 
00248     DeltaPhi( Atlfast::IKinematic& reference ) : ref(&reference) {} 
00249     
00250     //function operator
00251     bool operator() 
00252       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00253       { 
00254       Phi a_dPhi( a->phi() - ref->phi() ) ;
00255       Phi b_dPhi( b->phi() - ref->phi() ) ;
00256       
00257       return  ( abs(a_dPhi) < abs(b_dPhi) ) ;
00258    }
00259     
00260     //forwarding
00261     bool operator() 
00262       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00263       { return this->operator() ( &a, &b ) ; }
00264 
00265   };
00266 
00267   //........... Delta eta ..............
00274   class DeltaEta {
00275     
00276   private:
00277     Atlfast::IKinematic* ref ;
00278     
00279   public:
00280     
00282     DeltaEta( Atlfast::IKinematic* reference ) : ref(reference) {} 
00284     DeltaEta( Atlfast::IKinematic& reference ) : ref(&reference) {} 
00285     
00287     bool operator() 
00288       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const { 
00289       return( 
00290              abs(a->eta() - ref->eta()) 
00291              < 
00292              abs(b->eta() - ref->eta()) 
00293              );
00294     }
00295     
00297     bool operator() 
00298       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00299       { return this->operator() ( &a, &b ) ; }
00300 
00301   };
00302 
00303   
00304   //........... Delta R  (eta-phi) ..............
00311   class DeltaR {
00312     
00313   private:
00314     Atlfast::IKinematic* ref ;
00315     
00316   public:
00317     
00319     DeltaR( Atlfast::IKinematic* reference ) : ref(reference) {}
00321     DeltaR( Atlfast::IKinematic& reference ) : ref(&reference) {} 
00322     
00324     bool operator() 
00325       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const { 
00326       
00327       Phi a_dPhi( a->phi() - ref->phi() ) ;
00328       Phi b_dPhi( b->phi() - ref->phi() ) ;
00329       
00330       double dista = 
00331         sqrt(
00332              (a_dPhi*a_dPhi) +
00333              (a->eta() - ref->eta())*(a->eta() - ref->eta()) 
00334              );
00335       
00336       double distb = 
00337         sqrt(
00338              (b_dPhi*b_dPhi) +
00339              (b->eta() - ref->eta())*(b->eta() - ref->eta()) 
00340              );
00341       
00342       return ( dista < distb ) ;
00343     }
00344 
00345     
00347     bool operator() 
00348       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00349       { return this->operator() ( &a, &b ) ; }
00350 
00351   };
00352 
00353   
00354   
00355 } // End of SortCondition  namespace
00356 
00357 
00358 //**********************************************
00359 // For use with partition()
00360 //**********************************************
00361 
00362 
00363 namespace PartitionCondition {
00364   
00365   
00366   //........... eT ..............
00372   class AboveThresholdET {
00373     
00374   public:
00375 
00376     AboveThresholdET( double boundary ) : m_boundary(boundary) {}
00378     bool operator() ( const Atlfast::IKinematic* a ) const
00379       { return (m_boundary  < a->eT()) ; }
00381     bool operator() ( const Atlfast::IKinematic& a ) const
00382       { return (m_boundary  < a.eT()) ; }
00383     
00384   private:
00386     double m_boundary ;
00387     
00388   };
00394   class BelowThresholdET {
00395     
00396   public:
00397     
00398     BelowThresholdET( double boundary ) : m_boundary(boundary) {}
00400     bool operator() ( const Atlfast::IKinematic* a ) const
00401       { return (m_boundary  > a->eT()) ; }
00403     bool operator() ( const Atlfast::IKinematic& a ) const
00404     { return (m_boundary  > a.eT()) ; }
00405     
00406   private:
00408     double m_boundary ;
00409     
00410   };
00411   
00412 //................. DeltaR .....................
00413   
00419   class BelowThresholdDeltaR {
00420     
00421   public:
00423     BelowThresholdDeltaR( Atlfast::IKinematic* ref, double boundary ) 
00424       : m_boundary(boundary), m_ref(ref) {}
00425     
00426     BelowThresholdDeltaR( Atlfast::IKinematic& ref, double boundary ) 
00427       : m_boundary(boundary), m_ref(&ref) {}
00428     
00429     bool operator() ( const Atlfast::IKinematic* a ) const
00430       { 
00431         Phi dphi( a->phi() - m_ref->phi() ) ;
00432         
00433         double dist = 
00434           sqrt(
00435                (dphi*dphi) +
00436                (a->eta() - m_ref->eta())*(a->eta() - m_ref->eta()) 
00437                );
00438         
00439         return (dist < m_boundary) ;
00440         
00441       }
00442     
00443     bool operator() 
00444       ( const Atlfast::IKinematic& a ) const 
00445       { return this->operator()( &a ) ; }
00446     
00447   private:
00448     double m_boundary ;
00449     Atlfast::IKinematic* m_ref ;
00450     
00451   };
00452   
00453   
00454   
00455 
00456 }  // End PartitionCondition namespace
00457 
00458 
00459 
00460 
00461 #endif
00462 
00463 
00464 
00465 
00466 

Generated on Wed Jan 15 11:00:29 2003 for AtlfastUtils by doxygen1.3-rc1