00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: TrkOutAvgTimeCalculator.cxx,v 1.2 2005/12/01 06:18:42 zhangy Exp $ 00004 // 00005 // Description: 00006 // See header file 00007 // 00008 // Environment: 00009 // Software developed for the BaBar Detector at the SLAC B-Factory. 00010 // 00011 // Copyright Information: 00012 // Copyright (C) 2001 UC, San Diego 00013 // 00014 // Author List: 00015 // Gerhard Raven 7/19/01 00016 //------------------------------------------------------------------------ 00017 #include "TrkBase/TrkOutAvgTimeCalculator.h" 00018 #include "TrkBase/TrkHotSelector.h" 00019 #include "TrkBase/TrkRecoTrk.h" 00020 #include "TrkBase/TrkHitOnTrk.h" 00021 #include "TrkBase/TrkHitList.h" 00022 #include <vector> 00023 00024 00025 TrkOutAvgTimeCalculator::TrkOutAvgTimeCalculator(const TrkHotSelector& selector, double maxpull) : 00026 TrkTimeCalculator(selector),_maxpull(maxpull) 00027 {} 00028 00029 TrkOutAvgTimeCalculator::~TrkOutAvgTimeCalculator() 00030 {} 00031 00032 bool 00033 TrkOutAvgTimeCalculator::trackTime(const TrkRecoTrk& trk, 00034 double& time, double& timeerr, 00035 int& nHotsUsed) const 00036 { 00037 const TrkHitList *hotlist = trk.hits(); 00038 std::vector<ws> l; 00039 ws sum; 00040 for(TrkHitList::hot_iterator i(hotlist->begin());i!=hotlist->end();++i){ 00041 double hottime,hottimeerr; 00042 if(!useHot(*i) || !i->timeResid(hottime,hottimeerr)) continue; 00043 hottime*=1e9; hottimeerr*=1e9; 00044 ws x(hottime,double(1)/(hottimeerr*hottimeerr)); 00045 l.push_back(x); 00046 sum +=x; 00047 } 00048 if (_maxpull>0 && sum.n()>2 && sum.isPhysical()) { // do pull based pruning 00049 std::vector<ws>::iterator worst=l.end(); 00050 do { 00051 worst=l.end(); double worstPull = _maxpull; 00052 for(std::vector<ws>::iterator i=l.begin();i!=l.end();++i) { 00053 ws u(sum); u-=*i; 00054 if (!u.isPhysical()) { 00055 #ifdef MDCPATREC_WARNING 00056 std::cout<<"ErrMsg(warning) rounding problem?" << std::endl; 00057 #endif 00058 continue; 00059 } 00060 double p = fabs(u.pull( *i )); 00061 if (p>worstPull) { worstPull = p; worst = i; } 00062 } 00063 if (worst!=l.end()) { 00064 sum-=*worst; l.erase(worst); 00065 } 00066 } while (sum.isPhysical() && sum.n()>2 && worst!=l.end()); 00067 } 00068 if (sum.isPhysical()) { 00069 time = sum.mean()*1e-9 + trk.trackT0();; 00070 timeerr = sum.sigma()*1e-9; 00071 nHotsUsed = sum.n(); 00072 return true; 00073 } 00074 return false; 00075 }