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

CellHelper.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 //           ICellWrapper interface
00012 //
00013 //  I.e. if your object inherits as:
00014 //       class YourObject : virtual public ICellWrapper
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 //      AscendingPT        DescendingPT        simple sort by trans. momentum
00027 //      AscendingMT        DescendingMT        simple sort by trans. mass
00028 //      
00029 //      DeltaPhi    sort by increasing distance in phi from a reference
00030 //      DeltaEta    sort by increasing distance in eta from a reference
00031 //      DeltaR      sort by increasing distance in eta-phi from a reference
00032 //      (note the reference is set in the constructor)
00033 //
00034 
00035 #ifndef ATLFAST_CELLHELPER_H
00036 #define ATLFAST_CELLHELPER_H
00037 
00038 #include "AtlfastCode/IKinematic.h"
00039 //#include <cmath>
00040 //#include <cstdlib>
00041 #include "AtlfastCode/Phi.h"
00042 
00043 
00044 //--------------------------------------------------------
00045 //
00046 // Function objects for sort
00047 //
00048 
00049 namespace CellSortCondition {
00050   
00051   //............ phi ...........
00056   class AscendingPhi {
00057   public:
00058     bool operator() 
00059       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const { 
00060       return( a->phi() < b->phi() ) ; }
00061     
00062     bool operator() 
00063       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00064       { return this->operator() ( &a, &b ) ; }
00065   };
00070   class DescendingPhi {
00071   public:
00072     bool operator() 
00073       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const
00074       { return( a->phi() > b->phi() ) ; }
00075     bool operator() 
00076       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00077       { return( a.phi() > b.phi() ) ; }
00078   };
00079 
00080   
00081   //........... eta ..............
00086   class AscendingEta {
00087   public:
00088     bool operator() 
00089       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const
00090       { return( a->eta() < b->eta() ) ; }
00091     bool operator() 
00092       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00093       { return( a.eta() < b.eta() ) ; }
00094   };
00099   class DescendingEta {
00100   public:
00101     bool operator() 
00102       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const
00103       { return( a->eta() > b->eta() ) ; }
00104     bool operator() 
00105      ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00106       { return( a.eta() > b.eta() ) ; }
00107   };
00108 
00109 
00110 //........... eT ..............
00111   //........... pT ..............
00116   class AscendingPT {
00117   public:
00118     bool operator() 
00119       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const
00120       { return( a->pT() < b->pT() ) ; }
00121     bool operator() 
00122       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00123       { return( a.pT() < b.pT() ) ; }
00124   };
00129   class DescendingPT {
00130   public:
00131     bool operator() 
00132       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const
00133       { return( a->pT() > b->pT() ) ; }
00134     bool operator() 
00135       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00136       { return( a.pT() > b.pT() ) ; }
00137   };
00138   //........... Delta phi ..............
00143   class DeltaPhi {
00144     
00145   private:
00146     Atlfast::ICellWrapper* ref ;
00147 
00148   public:
00149     
00150     // Constructors which accept the reference 
00151     DeltaPhi( Atlfast::ICellWrapper* reference ) : ref(reference) {} 
00152     DeltaPhi( Atlfast::ICellWrapper& reference ) : ref(&reference) {} 
00153     
00154     //function operator
00155     bool operator() 
00156       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const
00157       { 
00158       Phi a_dPhi( a->phi() - ref->phi() ) ;
00159       Phi b_dPhi( b->phi() - ref->phi() ) ;
00160       
00161       return  ( abs(a_dPhi) < abs(b_dPhi) ) ;
00162    }
00163     
00164     //forwarding
00165     bool operator() 
00166       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00167       { return this->operator() ( &a, &b ) ; }
00168 
00169   };
00170 
00171   //........... Delta eta ..............
00176   class DeltaEta {
00177     
00178   private:
00179     Atlfast::ICellWrapper* ref ;
00180     
00181   public:
00182     
00183     // Constructors which accept the reference 
00184     DeltaEta( Atlfast::ICellWrapper* reference ) : ref(reference) {} 
00185     DeltaEta( Atlfast::ICellWrapper& reference ) : ref(&reference) {} 
00186     
00187     //function operator
00188     bool operator() 
00189       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const { 
00190       return( 
00191              abs(a->eta() - ref->eta()) 
00192              < 
00193              abs(b->eta() - ref->eta()) 
00194              );
00195     }
00196     
00197     //forwarding
00198     bool operator() 
00199       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00200       { return this->operator() ( &a, &b ) ; }
00201 
00202   };
00203 
00204   
00205   //........... Delta R  (eta-phi) ..............
00210   class DeltaR {
00211     
00212   private:
00213     Atlfast::ICellWrapper* ref ;
00214     
00215   public:
00216     
00217     // Constructors which accept the reference 
00218     DeltaR( Atlfast::ICellWrapper* reference ) : ref(reference) {} 
00219     DeltaR( Atlfast::ICellWrapper& reference ) : ref(&reference) {} 
00220     
00221     //function operator for comparing two objects
00222     bool operator() 
00223       ( const Atlfast::ICellWrapper* a, const Atlfast::ICellWrapper* b  ) const { 
00224       
00225       Phi a_dPhi( a->phi() - ref->phi() ) ;
00226       Phi b_dPhi( b->phi() - ref->phi() ) ;
00227       
00228       double dista = 
00229         sqrt(
00230              (a_dPhi*a_dPhi) +
00231              (a->eta() - ref->eta())*(a->eta() - ref->eta()) 
00232              );
00233       
00234       double distb = 
00235         sqrt(
00236              (b_dPhi*b_dPhi) +
00237              (b->eta() - ref->eta())*(b->eta() - ref->eta()) 
00238              );
00239       
00240       return ( dista < distb ) ;
00241     }
00242 
00243     
00244     //forwarding
00245     bool operator() 
00246       ( const Atlfast::ICellWrapper& a, const Atlfast::ICellWrapper& b  ) const
00247       { return this->operator() ( &a, &b ) ; }
00248 
00249   };
00250 
00251   
00252   
00253 } // End of SortCondition  namespace
00254 
00255 
00256 //**********************************************
00257 // For use with partition()
00258 //**********************************************
00259 
00260 
00261 namespace CellPartitionCondition {
00262   
00263   
00264   //........... pT ..............
00265   
00270   class AboveThresholdPT {
00271     
00272   public:
00273 
00274     AboveThresholdPT( double boundary ) : m_boundary(boundary) {}
00275     
00276     bool operator() ( const Atlfast::ICellWrapper* a ) const
00277       { return (m_boundary  < a->pT()) ; }
00278     bool operator() ( const Atlfast::ICellWrapper& a ) const
00279       { return (m_boundary  < a.pT()) ; }
00280     
00281   private:
00282     double m_boundary ;
00283     
00284   };
00289   class BelowThresholdpT {
00290     
00291   public:
00292     
00293     BelowThresholdpT( double boundary ) : m_boundary(boundary) {}
00294     
00295     bool operator() ( const Atlfast::ICellWrapper* a ) const
00296       { return (m_boundary  > a->pT()) ; }
00297     bool operator() ( const Atlfast::ICellWrapper& a ) const
00298     { return (m_boundary  > a.pT()) ; }
00299     
00300   private:
00301     double m_boundary ;
00302     
00303   };
00304   
00305 //................. DeltaR .....................
00306   
00311   class BelowThresholdDeltaR {
00312     
00313   public:
00319     BelowThresholdDeltaR( Atlfast::ICellWrapper* ref, double boundary ) 
00320       : m_boundary(boundary), m_ref(ref) {}
00326     BelowThresholdDeltaR( Atlfast::ICellWrapper& ref, double boundary ) 
00327       : m_boundary(boundary), m_ref(&ref) {}
00329     bool operator() ( const Atlfast::ICellWrapper* a ) const
00330       { 
00331         Phi dphi( a->phi() - m_ref->phi() ) ;
00332         
00333         double dist = 
00334           sqrt(
00335                (dphi*dphi) +
00336                (a->eta() - m_ref->eta())*(a->eta() - m_ref->eta()) 
00337                );
00338         
00339         return (dist < m_boundary) ;
00340         
00341       }
00342     
00343     bool operator() 
00344       ( const Atlfast::ICellWrapper& a ) const 
00345       { return this->operator()( &a ) ; }
00346     
00347   private:
00348     double m_boundary ;
00349     Atlfast::ICellWrapper* m_ref ;
00350     
00351   };
00352   
00353 //................. DeltaPT .....................
00354   
00359   class BelowThresholdDeltaPT {
00360     
00361   public:
00367     BelowThresholdDeltaPT( Atlfast::ICellWrapper* ref, double boundary ) 
00368       : m_boundary(boundary), m_ref(ref) {}
00369     
00374     BelowThresholdDeltaPT( Atlfast::ICellWrapper& ref, double boundary ) 
00375       : m_boundary(boundary), m_ref(&ref) {}
00377     bool operator() ( const Atlfast::ICellWrapper* a ) const
00378       { 
00379         return ( abs( a->pT() - m_ref->pT() ) < m_boundary)  ;
00380       }
00382     bool operator() 
00383       ( const Atlfast::ICellWrapper& a ) const 
00384       { return this->operator()( &a ) ; }
00386     bool operator() 
00387       ( const Atlfast::ICellWrapper** a ) const 
00388       { return this->operator()( *a ) ; }
00389     
00390   private:
00392     double m_boundary ;
00394     Atlfast::ICellWrapper* m_ref ;
00395     
00396   };
00397   
00398 //................. DeltaPT .....................
00399   
00405   class CellValidation {
00406     
00407   public:
00412     CellValidation( Atlfast::ICellWrapper* ref, 
00413                     double maxEtaDiff,
00414                     double maxPhiDiff,
00415                     double maxPtDiff ) : 
00416       m_ref(ref), 
00417       m_maxEtaDiff(maxEtaDiff), 
00418       m_maxPhiDiff(maxPhiDiff), 
00419       m_maxPtDiff(maxPtDiff) {}
00420     
00425     CellValidation( Atlfast::ICellWrapper& ref,
00426                     double maxEtaDiff,
00427                     double maxPhiDiff,
00428                     double maxPtDiff ) : 
00429       m_ref(&ref), 
00430       m_maxEtaDiff(maxEtaDiff), 
00431       m_maxPhiDiff(maxPhiDiff), 
00432       m_maxPtDiff(maxPtDiff) {}
00434     bool operator() ( const Atlfast::ICellWrapper* a ) const
00435       { 
00436         double delphi = abs( (Phi(a->phi()) - Phi(m_ref->phi())) );
00437         double deleta = abs( ( a->eta() - m_ref->eta()) );
00438         double delpt  = abs( a->pT() - m_ref->pT() );
00439         
00440         return ( 
00441                 delphi< m_maxPhiDiff &&
00442                 deleta< m_maxEtaDiff &&
00443                 delpt < m_maxPtDiff
00444                 );
00445       }
00447     bool operator() 
00448       ( const Atlfast::ICellWrapper& a ) const 
00449       { return this->operator()( &a ) ; }
00451     bool operator() 
00452       ( const Atlfast::ICellWrapper** a ) const 
00453       { return this->operator()( *a ) ; }
00454     
00455   private:
00457     Atlfast::ICellWrapper* m_ref ;
00459     double m_maxEtaDiff;
00461     double m_maxPhiDiff;
00463     double m_maxPtDiff;    
00464   };
00465   
00471   class MatchParticle {
00472     
00473   public:
00479     MatchParticle( Atlfast::ICellWrapper* ref, 
00480                     double maxEtaDiff,
00481                     double maxPhiDiff,
00482                     double maxPtDiff ) : 
00483       m_ref(ref), 
00484       m_maxEtaDiff(maxEtaDiff), 
00485       m_maxPhiDiff(maxPhiDiff), 
00486       m_maxPtDiff(maxPtDiff) {}
00487 
00493     MatchParticle( Atlfast::ICellWrapper& ref,
00494                     double maxEtaDiff,
00495                     double maxPhiDiff,
00496                     double maxPtDiff ) : 
00497       m_ref(&ref), 
00498       m_maxEtaDiff(maxEtaDiff), 
00499       m_maxPhiDiff(maxPhiDiff), 
00500       m_maxPtDiff(maxPtDiff) {}
00502     bool operator() ( const Atlfast::ICellWrapper* a ) const
00503       { 
00504         std::vector<const HepMC::GenParticle*> p=a->particles();
00505         std::vector<const HepMC::GenParticle*>::const_iterator ip=p.begin();
00506         for(;ip!=p.end();++ip){
00507           
00508           double delphi = abs( Phi((*ip)->momentum().phi()) - Phi( m_ref->phi() ) );
00509           double deleta = abs( (*ip)->momentum().pseudoRapidity() - m_ref->eta() );
00510           double delpt  = abs( (*ip)->momentum().perp() - m_ref->pT() );
00511           if( 
00512              delphi< m_maxPhiDiff &&
00513              deleta< m_maxEtaDiff &&
00514              delpt < m_maxPtDiff
00515              ) return true;
00516         }
00517         return false;
00518       }
00520     bool operator() 
00521       ( const Atlfast::ICellWrapper& a ) const 
00522       { return this->operator()( &a ) ; }
00524     bool operator() 
00525       ( const Atlfast::ICellWrapper** a ) const 
00526       { return this->operator()( *a ) ; }
00527     
00528   private:
00530     Atlfast::ICellWrapper* m_ref ;
00532     double m_maxEtaDiff;
00534     double m_maxPhiDiff;
00536     double m_maxPtDiff;    
00537   };
00538 
00543   class AddModPt{
00544   public:
00545     double operator()( double a, 
00546                        Atlfast::ICellWrapper* b){
00547       double result = (a + abs( b->pT() ) );
00548       return result;
00549     }
00550     
00551   };
00552 }  // End PartitionCondition namespace
00553 
00554 
00555 
00556 
00557 #endif
00558 
00559 
00560 
00561 
00562 

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