Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File 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 "AtlfastCode/IKinematic.h"
00040 #include <cmath>
00041 //#include <cstdlib>
00042 #include "AtlfastCode/Phi.h"
00043 
00044 
00045 //--------------------------------------------------------
00046 //
00047 // Function objects for sort
00048 //
00049 
00050 namespace SortAttribute {
00051   
00052   //............ phi ...........
00053 
00054 
00061   class AscendingPhi {
00062   public:
00063     bool operator() 
00064       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const { 
00065       return( a->phi() < b->phi() ) ; }
00066     
00067      bool operator() 
00068       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00069        { return this->operator() ( &a, &b ) ; }
00070   };
00077   class DescendingPhi {
00078   public:
00079     bool operator() 
00080       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00081       { return( a->phi() > b->phi() ) ; }
00082     bool operator() 
00083       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00084       { return( a.phi() > b.phi() ) ; }
00085   };
00086 
00087   
00088   //........... eta ..............
00095   class AscendingEta {
00096   public:
00097     bool operator() 
00098       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00099       { return( a->eta() < b->eta() ) ; }
00100     bool operator() 
00101       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00102       { return( a.eta() < b.eta() ) ; }
00103   };
00110   class DescendingEta {
00111   public:
00112     bool operator() 
00113       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00114       { return( a->eta() > b->eta() ) ; }
00115     bool operator() 
00116      ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00117       { return( a.eta() > b.eta() ) ; }
00118   };
00119 
00120 
00121 //........... eT ..............
00122 
00129   class AscendingET {
00130   public:
00131     
00132     // For sorting
00133     bool operator() 
00134       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00135       { return( a->eT() < b->eT() ) ; }
00136     bool operator() 
00137       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00138       { return( a.eT() < b.eT() ) ; }
00139 
00140    // For applying cuts - not documented yet
00141     bool operator() 
00142       ( const double boundary , const Atlfast::IKinematic* a ) const
00143       { return (boundary  < a->eT()) ; }
00144     bool operator() 
00145       ( const double boundary , const Atlfast::IKinematic& a ) const
00146       { return (boundary  < a.eT()) ; }
00147 
00148   };
00155   class DescendingET {
00156   public:
00157     bool operator() 
00158       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00159       { return( a->eT() > b->eT() ) ; }
00160     bool operator() 
00161       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00162       { return( a.eT() > b.eT() ) ; }
00163   };
00164 
00165 
00166   //........... pT ..............
00173   class AscendingPT {
00174   public:
00175     bool operator() 
00176       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00177       { return( a->pT() < b->pT() ) ; }
00178     bool operator() 
00179       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00180       { return( a.pT() < b.pT() ) ; }
00181   };
00188   class DescendingPT {
00189   public:
00190     bool operator() 
00191       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00192       { return( a->pT() > b->pT() ) ; }
00193     bool operator() 
00194       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00195       { return( a.pT() > b.pT() ) ; }
00196   };
00197 
00198 
00199   //........... mT ..............
00206   class AscendingMT {
00207   public:
00208     bool operator() 
00209       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00210       { return( a->mT() < b->mT() ) ; }
00211     bool operator() 
00212       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00213       { return( a.mT() < b.mT() ) ; }
00214   };
00221   class DescendingMT {
00222   public:
00223     bool operator() 
00224       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00225       { return( a->mT() > b->mT() ) ; }
00226     bool operator() 
00227       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00228       { return( a.mT() > b.mT() ) ; }
00229   };
00230   
00231   //........... Delta phi ..............
00238   class DeltaPhi {
00239     
00240   private:
00241     Atlfast::IKinematic* ref ;
00242 
00243   public:
00244     
00245     // Constructors which accept the reference 
00246     DeltaPhi( Atlfast::IKinematic* reference ) : ref(reference) {} 
00247     DeltaPhi( Atlfast::IKinematic& reference ) : ref(&reference) {} 
00248     
00249     //function operator
00250     bool operator() 
00251       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const
00252       { 
00253       Phi a_dPhi( a->phi() - ref->phi() ) ;
00254       Phi b_dPhi( b->phi() - ref->phi() ) ;
00255       
00256       return  ( abs(a_dPhi) < abs(b_dPhi) ) ;
00257    }
00258     
00259     //forwarding
00260     bool operator() 
00261       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00262       { return this->operator() ( &a, &b ) ; }
00263 
00264   };
00265 
00266   //........... Delta eta ..............
00273   class DeltaEta {
00274     
00275   private:
00276     Atlfast::IKinematic* ref ;
00277     
00278   public:
00279     
00281     DeltaEta( Atlfast::IKinematic* reference ) : ref(reference) {} 
00283     DeltaEta( Atlfast::IKinematic& reference ) : ref(&reference) {} 
00284     
00286     bool operator() 
00287       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const { 
00288       return( 
00289              abs(a->eta() - ref->eta()) 
00290              < 
00291              abs(b->eta() - ref->eta()) 
00292              );
00293     }
00294     
00296     bool operator() 
00297       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00298       { return this->operator() ( &a, &b ) ; }
00299 
00300   };
00301 
00302   
00303   //........... Delta R  (eta-phi) ..............
00310   class DeltaR {
00311     
00312   private:
00313     Atlfast::IKinematic* ref ;
00314     
00315   public:
00316     
00318     DeltaR( Atlfast::IKinematic* reference ) : ref(reference) {}
00320     DeltaR( Atlfast::IKinematic& reference ) : ref(&reference) {} 
00321     
00323     bool operator() 
00324       ( const Atlfast::IKinematic* a, const Atlfast::IKinematic* b  ) const { 
00325       
00326       Phi a_dPhi( a->phi() - ref->phi() ) ;
00327       Phi b_dPhi( b->phi() - ref->phi() ) ;
00328       
00329       double dista = 
00330         sqrt(
00331              (a_dPhi*a_dPhi) +
00332              (a->eta() - ref->eta())*(a->eta() - ref->eta()) 
00333              );
00334       
00335       double distb = 
00336         sqrt(
00337              (b_dPhi*b_dPhi) +
00338              (b->eta() - ref->eta())*(b->eta() - ref->eta()) 
00339              );
00340       
00341       return ( dista < distb ) ;
00342     }
00343 
00344     
00346     bool operator() 
00347       ( const Atlfast::IKinematic& a, const Atlfast::IKinematic& b  ) const
00348       { return this->operator() ( &a, &b ) ; }
00349 
00350   };
00351 
00352   
00353   
00354 } // End of SortCondition  namespace
00355 
00356 
00357 //**********************************************
00358 // For use with partition()
00359 //**********************************************
00360 
00361 
00362 namespace PartitionCondition {
00363   
00364   
00365   //........... eT ..............
00371   class AboveThresholdET {
00372     
00373   public:
00374 
00375     AboveThresholdET( double boundary ) : m_boundary(boundary) {}
00377     bool operator() ( const Atlfast::IKinematic* a ) const
00378       { return (m_boundary  < a->eT()) ; }
00380     bool operator() ( const Atlfast::IKinematic& a ) const
00381       { return (m_boundary  < a.eT()) ; }
00382     
00383   private:
00385     double m_boundary ;
00386     
00387   };
00393   class BelowThresholdET {
00394     
00395   public:
00396     
00397     BelowThresholdET( double boundary ) : m_boundary(boundary) {}
00399     bool operator() ( const Atlfast::IKinematic* a ) const
00400       { return (m_boundary  > a->eT()) ; }
00402     bool operator() ( const Atlfast::IKinematic& a ) const
00403     { return (m_boundary  > a.eT()) ; }
00404     
00405   private:
00407     double m_boundary ;
00408     
00409   };
00410   
00411 //................. DeltaR .....................
00412   
00418   class BelowThresholdDeltaR {
00419     
00420   public:
00422     BelowThresholdDeltaR( Atlfast::IKinematic* ref, double boundary ) 
00423       : m_boundary(boundary), m_ref(ref) {}
00424     
00425     BelowThresholdDeltaR( Atlfast::IKinematic& ref, double boundary ) 
00426       : m_boundary(boundary), m_ref(&ref) {}
00427     
00428     bool operator() ( const Atlfast::IKinematic* a ) const
00429       { 
00430         Phi dphi( a->phi() - m_ref->phi() ) ;
00431         
00432         double dist = 
00433           sqrt(
00434                (dphi*dphi) +
00435                (a->eta() - m_ref->eta())*(a->eta() - m_ref->eta()) 
00436                );
00437         
00438         return (dist < m_boundary) ;
00439         
00440       }
00441     
00442     bool operator() 
00443       ( const Atlfast::IKinematic& a ) const 
00444       { return this->operator()( &a ) ; }
00445     
00446   private:
00447     double m_boundary ;
00448     Atlfast::IKinematic* m_ref ;
00449     
00450   };
00451   
00452   
00453   
00454 
00455 }  // End PartitionCondition namespace
00456 
00457 
00458 
00459 
00460 #endif
00461 
00462 
00463 
00464 
00465 

Generated on Mon Feb 4 15:54:23 2002 for Atlfast by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001