00001
00002
00003
00004
00006 #ifndef FOURMOMUTILS_XAODP4HELPERS_H
00007 #define FOURMOMUTILS_XAODP4HELPERS_H
00008
00017
00018 #include <cmath>
00019
00020
00021 #include "CxxUtils/fpcompare.h"
00022
00023
00024 #include "xAODBase/IParticle.h"
00025 #include "xAODMissingET/MissingET.h"
00026
00027
00028 namespace xAOD
00029 {
00030 namespace P4Helpers
00031 {
00033 inline
00034 double deltaRapidity( const xAOD::IParticle& p1, const xAOD::IParticle& p2 )
00035 {
00036 return p1.rapidity() - p2.rapidity();
00037 }
00038
00040 inline
00041 double deltaRapidity( const xAOD::IParticle * const p1, const xAOD::IParticle * const p2 )
00042 {
00043 return xAOD::P4Helpers::deltaRapidity(*p1, *p2);
00044 }
00045
00046
00048 inline
00049 double deltaEta( const xAOD::IParticle& p1, const xAOD::IParticle& p2 )
00050 {
00051 return p1.eta() - p2.eta();
00052 }
00053
00055 inline
00056 double deltaEta( const xAOD::IParticle * const p1, const xAOD::IParticle * const p2 )
00057 {
00058 return xAOD::P4Helpers::deltaEta(*p1, *p2);
00059 }
00060
00061
00063 inline
00064 double deltaPhi( double phiA, double phiB )
00065 {
00066 return -remainder( -phiA + phiB, 2*M_PI );
00067 }
00068
00070 inline
00071 double deltaPhi( const xAOD::IParticle& p4, const double phi )
00072 {
00073 return xAOD::P4Helpers::deltaPhi( p4.phi(), phi );
00074 }
00075
00077 inline
00078 double deltaPhi( const xAOD::IParticle & pA, const xAOD::IParticle & pB )
00079 {
00080 return xAOD::P4Helpers::deltaPhi( pA.phi(), pB.phi() );
00081 }
00082
00084 inline
00085 double deltaPhi( const xAOD::IParticle * const pA, const xAOD::IParticle * const pB )
00086 { return xAOD::P4Helpers::deltaPhi( pA->phi(), pB->phi() ); }
00087
00088
00089
00091 inline
00092 double deltaPhi( const xAOD::IParticle & pA, const xAOD::MissingET & met )
00093 {
00094 return xAOD::P4Helpers::deltaPhi( pA.phi(), met.phi() );
00095 }
00096
00098 inline
00099 double deltaPhi( const xAOD::IParticle * const pA, const xAOD::MissingET * const met )
00100 { return xAOD::P4Helpers::deltaPhi( pA->phi(), met->phi() ); }
00101
00102
00103
00105 inline
00106 double deltaR2( const xAOD::IParticle& p4, double rapidity, double phi, bool useRapidity=true )
00107 {
00108 const double dPhi = xAOD::P4Helpers::deltaPhi( p4, phi );
00109 if (useRapidity) {
00110 const double dRapidity = p4.rapidity() - rapidity;
00111 return dRapidity*dRapidity + dPhi*dPhi;
00112 }
00113 else {
00114 const double dEta = p4.eta() - rapidity;
00115 return dEta*dEta + dPhi*dPhi;
00116 }
00117 }
00118
00120 inline
00121 double deltaR2( const xAOD::IParticle& pA, const xAOD::IParticle& pB, bool useRapidity=true )
00122 {
00123 const double dPhi = xAOD::P4Helpers::deltaPhi( pA, pB );
00124 const double dPhiSq = dPhi*dPhi;
00125 if (useRapidity) {
00126 const double dRapidity = xAOD::P4Helpers::deltaRapidity( pA, pB );
00127 return dRapidity*dRapidity + dPhiSq;
00128 }
00129 else {
00130 const double dEta = xAOD::P4Helpers::deltaEta( pA, pB );
00131 return dEta*dEta + dPhiSq;
00132 }
00133 }
00134
00136 inline
00137 double deltaR2( const xAOD::IParticle * const pA, const xAOD::IParticle * const pB, bool useRapidity=true )
00138 { return xAOD::P4Helpers::deltaR2( *pA, *pB, useRapidity ); }
00139
00140
00141
00143 inline
00144 double deltaR( const xAOD::IParticle& p4, double rapidity, double phi, bool useRapidity=true )
00145 { return std::sqrt( xAOD::P4Helpers::deltaR2( p4, rapidity, phi, useRapidity ) ); }
00146
00148 inline
00149 double deltaR( const xAOD::IParticle& pA, const xAOD::IParticle& pB, bool useRapidity=true )
00150 { return std::sqrt( xAOD::P4Helpers::deltaR2( pA, pB, useRapidity ) ); }
00151
00153 inline
00154 double deltaR( const xAOD::IParticle * const pA, const xAOD::IParticle * const pB, bool useRapidity=true )
00155 { return std::sqrt( xAOD::P4Helpers::deltaR2( *pA, *pB, useRapidity ) ); }
00156
00157
00158
00162 inline
00163 bool isInDeltaR( const xAOD::IParticle& p1, const xAOD::IParticle& p2,
00164 double dR, bool useRapidity=true )
00165 {
00166 const double dPhi = std::abs( xAOD::P4Helpers::deltaPhi(p1,p2) );
00167 if ( CxxUtils::fpcompare::greater(dPhi,dR) ) return false;
00168 if (useRapidity) {
00169 const double dRapidity = std::abs( xAOD::P4Helpers::deltaRapidity(p1,p2) );
00170 if ( CxxUtils::fpcompare::greater(dRapidity,dR) ) return false;
00171 const double deltaR2 = dRapidity*dRapidity + dPhi*dPhi;
00172 if ( CxxUtils::fpcompare::greater(deltaR2,dR*dR) ) return false;
00173 return true;
00174 }
00175 else {
00176 const double dEta = std::abs( xAOD::P4Helpers::deltaEta(p1,p2) );
00177 if ( CxxUtils::fpcompare::greater(dEta,dR) ) return false;
00178 const double deltaR2 = dEta*dEta + dPhi*dPhi;
00179 if ( CxxUtils::fpcompare::greater(deltaR2,dR*dR) ) return false;
00180 return true;
00181 }
00182 }
00183
00184
00185
00187 inline
00188 double deltaAbsP( const xAOD::IParticle& pA, const xAOD::IParticle& pB )
00189 {
00190 const double absPA = std::abs( pA.p4().P() );
00191 const double absPB = std::abs( pB.p4().P() );
00192 return absPA - absPB;
00193 }
00194
00196 inline
00197 double deltaAbsP( const xAOD::IParticle * const pA, const xAOD::IParticle * const pB )
00198 { return xAOD::P4Helpers::deltaAbsP( *pA, *pB ); }
00199
00200
00201 }
00202
00203 }
00204
00205
00206 #endif // FOURMOMUTILS_XAODP4HELPERS_H