CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoPixelVertexing/PixelVertexFinding/src/PVPositionBuilder.cc

Go to the documentation of this file.
00001 #include "RecoPixelVertexing/PixelVertexFinding/interface/PVPositionBuilder.h"
00002 #include <cmath>
00003 
00005 PVPositionBuilder::PVPositionBuilder() {}
00006 
00007 Measurement1D PVPositionBuilder::average(const reco::TrackRefVector &trks) const {
00008   // Cut and paste (more or less) from same class in ORCA framework
00009   double ntracks = double(trks.size());
00010   if (ntracks==0) return Measurement1D ( 0. , 0. );
00011   double sumZIP = 0;
00012   double err = 0;
00013   for (unsigned int i=0; i<trks.size(); i++) {
00014     sumZIP += trks[i]->dz(); // Z at IP
00015     err += trks[i]->dzError(); // error on Z at IP (I hope). Fix d.k.
00016   }  
00017   return Measurement1D ( sumZIP/ntracks, err/ntracks/std::sqrt(ntracks) );
00018 
00019 }
00020 
00021 Measurement1D PVPositionBuilder::wtAverage(const reco::TrackRefVector &trks) const {
00022   double ntracks = double(trks.size());
00023   if (ntracks==0) return Measurement1D ( 0.0 , 0.0 );
00024   double sumUp = 0;
00025   double sumDown = 0;
00026   double err = 0;
00027   for (unsigned int i=0; i<trks.size(); i++) {
00028     //    double err2 = trks[i]->covariance(3,3); // error on Z at IP (I hope)
00029     double err2 = trks[i]->dzError(); // Fix d.k.
00030     err2 *= err2;
00031     if (err2 != 0){
00032       sumUp += trks[i]->dz() * 1/err2; // error-weighted average of Z at IP
00033       sumDown += 1/err2;
00034     }
00035     err += std::sqrt( err2 );
00036   }  
00037   if (sumDown > 0) return Measurement1D ( sumUp/sumDown , err/ntracks/sqrt(ntracks) );
00038   else return Measurement1D ( 0.0 , 0.0 );
00039 }