00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: TrkOutAvgTimeCalculator.h,v 1.1.1.1 2005/04/21 06:01:42 zhangy Exp $ 00004 // 00005 // Description: 00006 // class TrkOutAvgTimeCalculater. A simple implementation of TrkTimeCalculator 00007 // that takes the weighted average of all selected hot's times assuming a 00008 // Gaussian error, but rejecting outliers based on their pull. 00009 // 00010 // Environment: 00011 // Software developed for the BaBar Detector at the SLAC B-Factory. 00012 // 00013 // Copyright Information: 00014 // Copyright (C) 2001 UC, San Diego 00015 // 00016 // Author List: 00017 // Gerhard Raven 7/19/01 00018 //------------------------------------------------------------------------ 00019 00020 #ifndef TRKOUTAVGTIMECALCULATOR_HH 00021 #define TRKOUTAVGTIMECALCULATOR_HH 00022 00023 #include "TrkBase/TrkTimeCalculator.h" 00024 #include <assert.h> 00025 #include <math.h> 00026 00027 class TrkOutAvgTimeCalculator : public TrkTimeCalculator { 00028 public: 00029 TrkOutAvgTimeCalculator(const TrkHotSelector& selector,double maxpull); 00030 virtual ~TrkOutAvgTimeCalculator(); 00031 // The Function 00032 virtual bool trackTime(const TrkRecoTrk& trk, 00033 double& time, double& timeerr, 00034 int& nHotsUsed) const; 00035 private: 00036 // disallow 00037 TrkOutAvgTimeCalculator(const TrkOutAvgTimeCalculator&); 00038 TrkOutAvgTimeCalculator& operator = (const TrkOutAvgTimeCalculator&); 00039 00040 double _maxpull; 00041 00042 class ws { 00043 public: 00044 ws(double x=0,double w=0):_w(w),_wx(w*x),_n(w>0?1:0) { assert(!(w<0));} 00045 ws& operator+=(const ws& x) { _wx += x._wx; _w+=x._w; _n+=x._n; return *this;} 00046 ws& operator-=(const ws& x) { _wx -= x._wx; _w-=x._w; _n-=x._n; return *this;} 00047 bool operator==(const ws& x) const { return _w==x._w && _wx==x._wx && _n==x._n;} 00048 bool isPhysical() const { return _w>0;} 00049 double mean() const {return _wx/_w;} 00050 double sigma() const { return double(1)/sqrt(_w);} 00051 double pull(const ws& x) const { return (mean()-x.mean())/sqrt(sigma2()+x.sigma2()); } 00052 unsigned n() const { return _n;} 00053 private: 00054 double sigma2() const { return double(1)/_w;} 00055 double _w,_wx; 00056 unsigned _n; 00057 }; 00058 }; 00059 #endif