00001
00002
00003 #ifndef XAOD_TRACKPARTICLEXAODHELPERS_H
00004 #define XAOD_TRACKPARTICLEXAODHELPERS_H
00005
00006 #include "xAODTracking/TrackParticle.h"
00007 #include "xAODTracking/Vertex.h"
00008 #include <cmath>
00009
00010
00011 namespace xAOD {
00012
00013 namespace TrackingHelpers {
00015 inline
00016 double sqr(double a) { return a*a; }
00017
00022 double d0significance(const xAOD::TrackParticle *tp);
00023
00029 inline
00030 double d0significanceUnsafe(const xAOD::TrackParticle *tp) {
00031 double d0 = tp->d0();
00032
00033 double sigma_d0 = std::sqrt( tp->definingParametersCovMatrixVec()[0] );
00034 return d0/sigma_d0;
00035 }
00036
00043 inline
00044 double d0UncertaintyBeamSpot2(double track_phi0, double beam_sigma_x,double beam_sigma_y, double beam_sigma_xy) {
00045 double sin_phi = sin(track_phi0);
00046 double cos_phi = cos(track_phi0);
00047 double d0_uncert2= sin_phi * ( sin_phi * sqr(beam_sigma_x)
00048 -cos_phi * beam_sigma_xy)
00049 +cos_phi * ( cos_phi * sqr(beam_sigma_y)
00050 -sin_phi * beam_sigma_xy);
00051 return d0_uncert2;
00052 }
00053
00054
00062 double d0significance(const xAOD::TrackParticle *tp, double beam_sigma_x, double beam_sigma_y, double beam_sigma_xy);
00063
00072
00074 inline
00075 double d0significanceUnsafe(const xAOD::TrackParticle *tp, double beam_sigma_x,double beam_sigma_y, double beam_sigma_xy) {
00076 double d0 = tp->d0();
00077
00078 double sigma_d0 = std::sqrt( tp->definingParametersCovMatrixVec()[0] + d0UncertaintyBeamSpot2(tp->phi(),beam_sigma_x, beam_sigma_y, beam_sigma_xy) );
00079 return d0/sigma_d0;
00080 }
00081
00090 double z0significance(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx=NULL);
00091
00096 inline
00097 double z0significanceUnsafe(const xAOD::TrackParticle *tp) {
00098 double z0 = tp->z0();
00099
00100 double sigma_z0 = std::sqrt( tp->definingParametersCovMatrixVec()[2] );
00101 return z0/sigma_z0;
00102 }
00103
00113 inline
00114 double z0significanceUnsafe(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx) {
00115
00116 double z0 = tp->z0() - vx->z();
00117
00118 if (tp->vertex()) {
00119 z0 += tp->vertex()->z();
00120 }
00121
00122 double sigma_z0 = std::sqrt( tp->definingParametersCovMatrixVec()[2] );
00123 return z0/sigma_z0;
00124 }
00125
00126
00129 bool hasValidCov(const xAOD::TrackParticle *tp);
00130
00133 inline
00134 bool hasValidCovD0(const xAOD::TrackParticle *tp ) {
00135 if (hasValidCov(tp)) {
00136 if ( !tp->definingParametersCovMatrixVec().empty()
00137 && tp->definingParametersCovMatrixVec()[0]>0.) {
00138 return true;
00139 }
00140 }
00141 return false;
00142 }
00143
00146 inline
00147 bool hasValidCovZ0(const xAOD::TrackParticle *tp) {
00148 if (hasValidCov(tp)) {
00149 if ( ! ( tp->definingParametersCovMatrixVec().size() > 2 )
00150 && ( tp->definingParametersCovMatrixVec()[2] > 0. ) ) {
00151 return true;
00152 }
00153 }
00154 return false;
00155 }
00156
00159 inline
00160 bool hasValidCovD0andZ0( const xAOD::TrackParticle *tp) {
00161 if (hasValidCov(tp)) {
00162 if ( ! ( tp->definingParametersCovMatrixVec().size() > 2 )
00163 && ( tp->definingParametersCovMatrixVec()[0] > 0. )
00164 && ( tp->definingParametersCovMatrixVec()[2] > 0. ) ) {
00165 return true;
00166 }
00167 }
00168 return false;
00169 }
00170
00171
00179 inline
00180 bool checkPVReference(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx, const double max_pv_dxy_sqr=0.5*0.5) {
00181 if (hasValidCovD0(tp) && vx) {
00182 return std::abs( sqr(vx->x())+ sqr(vx->y())) < max_pv_dxy_sqr * tp->definingParametersCovMatrixVec()[0];
00183 }
00184 return false;
00185 }
00186
00192 inline
00193 bool checkBeamSpotSigma(double beam_sigma_x,double beam_sigma_y, double beam_sigma_xy) {
00194 return sqr(beam_sigma_x)+sqr(beam_sigma_y)>=2*std::abs(beam_sigma_xy);
00195 }
00196
00200 double pTErr2(const xAOD::TrackParticle *tp);
00201
00205 inline
00206 double pTErr(const xAOD::TrackParticle *tp) {
00207 return sqrt( pTErr2(tp) );
00208 }
00209
00210
00214 inline
00215 double pTErr2Unsafe(const xAOD::TrackParticle *tp) {
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 double pt = tp->pt();
00234 double diff_qp = - pt / std::abs(tp->qOverP());
00235
00236 double diff_theta = pt / tan( tp->theta() );
00237
00238
00239
00240
00241
00242
00243
00244
00245 const std::vector<float>&cov= tp->definingParametersCovMatrixVec();
00246
00247
00248
00249
00250
00251
00252 double pt_err2 = diff_qp * (diff_qp * cov[14] + diff_theta * cov[13] ) + sqr(diff_theta) * cov[9];
00253 return pt_err2;
00254 }
00255
00259 inline
00260 double pTErrUnsafe(const xAOD::TrackParticle *tp) {
00261 return sqrt(pTErr2Unsafe(tp));
00262 }
00263
00266 inline
00267 bool hasValidCovQoverP(const xAOD::TrackParticle *tp ) {
00268 if (hasValidCov(tp)) {
00269 if ( tp->definingParametersCovMatrixVec().size()>=15 && std::abs(tp->qOverP())>0.) {
00270 return true;
00271 }
00272 }
00273 return false;
00274 }
00275
00276 }
00277
00278 }
00279
00280 #endif // XAOD_TRACKPARTICLEXAODHELPERS_H