Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KalFit.h

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/reconstruction/reconstruction/KalFit.h,v 1.5 2001/01/22 15:53:55 burnett Exp $
00002 //----------------------------------------
00003 //
00004 //      Kalman Filter Objects Declarations
00005 //
00006 //               J.A. Hernando, B. Atwood.  Santa Cruz,  7/20/98
00007 //-----------------------------------------------------------------------
00008 
00009 #ifndef _KALFIT_H
00010 #define _KALFIT_H 1
00011 
00012 
00013 #include <vector>
00014 
00015 
00016 #include "data/SiData.h"
00017 namespace gui { class DisplayRep; }
00018 
00019 //  Specific header-files for Little Kalman
00020 //#include "geometry.h"
00021 //#include "SiTracker.h"
00022 //
00023 
00024 class KalMatrix;
00025 class KalTrack;
00026 
00027 //double CONTROL_minKalEne = 0.03;
00028 
00029 //##############
00030 class KalPar
00031 //##############
00032 {
00033     // Kalman Parameters
00034 public:
00035     
00036     // constructors
00037     KalPar ()
00038         : position(0), slope(0) 
00039     {}
00040     KalPar (double a, double b)
00041         : position(a), slope(b) 
00042     {}
00043 
00044     friend KalPar operator* (const KalMatrix&, const KalPar&);
00045     
00046     friend double operator*(const KalPar&, const KalPar&);
00047     friend KalPar operator+(const KalPar&, const KalPar&);
00048     friend KalPar operator-(const KalPar&, const KalPar&);
00049     
00050     inline double getPosition() const {return position;}
00051     inline double getSlope() const {return slope;}
00052     
00053 private:
00054     
00055     double position;
00056     double slope;
00057     
00058 };
00059 
00060 double operator*(const KalPar&, const KalPar&);
00061 KalPar operator+(const KalPar&, const KalPar&); 
00062 KalPar operator-(const KalPar&, const KalPar&);
00063 
00064 KalPar operator*(const KalMatrix&, const KalPar&);
00065 
00066 //##############
00067 class KalMatrix
00068 //###############
00069 {
00070     // kalman matrices (in fact, normal matrices)
00071     friend class KalFit;
00072     
00073 public:
00074     // constructors
00075     KalMatrix(){
00076         a[0][0]=a[0][1]=a[1][0]=a[1][1]=0.;
00077     }
00078     // 07/29/99 hsg - added copy constructor
00079     KalMatrix (const KalMatrix& right) {
00080         for (int i = 0; i < 2; i++) {
00081             for (int j = 0; j < 2; j++) {
00082                 a[i][j] = right.a[i][j];
00083             }
00084         }
00085     }
00086     KalMatrix(double sig2a, double sig2b, double covab){
00087         a[0][0]=sig2a;
00088         a[0][1]=a[1][0]=covab;
00089         a[1][1]=sig2b;
00090     }
00091     KalMatrix(double a00,double a01,double a10, double a11){
00092         a[0][0]=a00;
00093         a[0][1]=a01;
00094         a[1][0]=a10;
00095         a[1][1]=a11;
00096     }
00097     
00098     inline double getsiga() const {return a[0][0];}
00099     inline double getsigb() const {return a[1][1];}
00100     
00101     // Manipulators
00102     static int kfdim;
00103     
00104     KalMatrix invert();
00105     KalMatrix transpose();
00106     
00107     friend KalPar operator*(const KalMatrix&, const KalPar&);
00108     friend KalMatrix operator*(const KalMatrix&, const KalMatrix&);
00109     friend KalMatrix operator+(const KalMatrix&, const KalMatrix&);
00110     friend KalMatrix operator-(const KalMatrix&, const KalMatrix&);
00111     
00112 private:
00113     
00114     double a[2][2]; 
00115     
00116 };
00117 
00118 KalMatrix operator*(const KalMatrix&, const KalMatrix&);
00119 KalMatrix operator+(const KalMatrix&, const KalMatrix&);
00120 KalMatrix operator-(const KalMatrix&, const KalMatrix&);
00121 
00122 //##############
00123 class KalHit
00124 //##############
00125 {
00126     
00127 public:
00128     
00129     enum TYPE {MEAS, FIT, PRED, SMOOTH, UNKNOWN};
00130     
00131     KalHit() 
00132         : type(UNKNOWN) 
00133     {}
00134     KalHit(TYPE t) 
00135         : type(t)  
00136     {}
00137     KalHit(TYPE t, const KalPar& p, const KalMatrix& m)
00138         :type(t),par(p),cov(m) 
00139     {}
00140     KalHit (const KalHit& right)
00141         : type(right.type), par(right.par), cov(right.cov)
00142     {}
00143     
00144     KalHit changeType(TYPE type);
00145     
00146     inline const TYPE& getType() const{return type;}
00147     inline const KalPar& getPar() const{return par;}
00148     inline const KalMatrix& getCov() const{return cov;}
00149     
00150 private:
00151     
00152     TYPE type;
00153     KalPar par;
00154     KalMatrix cov;
00155 };
00156 
00157 //##############
00158 class KalPlane
00159 //##############
00160 {
00161     
00162 public:
00163     
00164     KalPlane() 
00165         : m_IDHit (0), m_IDTower(0), m_IDPlane(0), m_zplane(0), m_eneplane(0)
00166     {}
00167     KalPlane(unsigned id, int kplane, double ene, double z, const KalPar& OrthPar, const KalHit& hit)
00168         : m_IDPlane(kplane), m_zplane(z), m_eneplane(ene), m_OrthPar(OrthPar) 
00169     { 
00170         setIDHit(id);
00171         setHit(hit); 
00172     }
00173     KalPlane(unsigned id, int kplane, double ene, double z, const KalPar& OrthPar)
00174         : m_IDPlane(kplane), m_zplane(z), m_eneplane(ene), m_OrthPar(OrthPar) 
00175     {
00176         setIDHit(id);
00177     }
00178     
00179     // Adding Hits, energy and other variables
00180     void setHit(const KalHit& hit);
00181     inline void setEnergy(double const e) {
00182         m_eneplane = (e < 0.03? 0.03:e);}
00183     inline void setOrthPar(const KalPar& OrthPar) { m_OrthPar = OrthPar; }
00184     inline void setIDHit(unsigned id) {
00185         m_IDHit = id;
00186         m_IDTower = (int) id/1000000;
00187     }
00188     inline void setZPlane(double z) {m_zplane = z;}
00189 
00190     // Get Information
00191     inline unsigned getIDHit()  const{return m_IDHit;}
00192     inline int getIDTower() const{return m_IDTower;}
00193     inline int getIDPlane()  const{return m_IDPlane;}
00194     inline double getZPlane()  const{return m_zplane;}
00195     inline double getEnergy()  const{return m_eneplane;}
00196     inline KalPar getOrthPar() const{return m_OrthPar;}
00197     //  inline KalPlane* getOrthPlane() const{return _mOrthKalPlane;}
00198     
00199     // Get Information (compatible with LSQFit)
00200     KalHit   getHit(KalHit::TYPE type) const;
00201     Point    getPoint(KalHit::TYPE type) const;
00202     double   getDeltaChiSq(KalHit::TYPE type) const;
00203     double   getDeltaChiEne(KalHit::TYPE type) const; 
00204     double   getSigma(KalHit::TYPE type) const;
00205     KalMatrix getQmaterial() const {return m_Qmaterial;} 
00206 
00207     void writeOut(int level) const;
00208 
00209 public:
00210 
00211     // Utility functions for Kalman Filter
00212     KalHit predicted(KalPlane& kpnext);
00213     KalHit predicted(KalHit::TYPE typ, double zEnd, int klayerEnd);
00214     KalHit predicted(KalHit::TYPE typ, int nsteps);
00215     void setDeltaEne(double ene);
00216     KalHit filter();
00217     KalHit smoother(const KalPlane& kplast);
00218     void clean();   // clean the PRED - FIT - SMOOTH values but not the MEAS
00219     void clear();   // clean everything
00220     void removeHit();
00221 
00222     // Static Member functions - Related with the MS introduced by one plane
00223     //           radlen0=radLen() is the radiation thickness for one plane (theta=0)
00224     static double theta0ms(double ene, double cosZ, double radlen0);
00225     static double radLen(int kplane);
00226     static KalMatrix Q(double ene, double slope, double orth_slope, double radlen0);
00227  
00228     
00229 private:
00230     
00231     unsigned m_IDHit; // SiCluster Index - code = tower+layer+hit
00232     int m_IDTower;
00233     int m_IDPlane;
00234     //  unsigned m_IDTower;
00235     
00236     double m_zplane;
00237     double m_eneplane;
00238     
00239     KalPar m_OrthPar;
00240     //  KalPlane* _mOrthKalPlane;
00241     
00242     //  KalTrack* _mMotherTrack;
00243     
00244     KalHit m_hitmeas;
00245     KalHit m_hitpred;
00246     KalHit m_hitfit;
00247     KalHit m_hitsmooth;
00248     KalMatrix m_Qmaterial;  // covarianve matrix of the material effects 
00249 };
00250 bool operator<(const KalPlane&, const KalPlane&); 
00251 bool operator==(const KalPlane&, const KalPlane&); 
00252 
00253 
00254 //##############
00255 class KalTrack
00256 //##############
00257 {
00258     
00259 public:
00260     
00261         friend class GlastFit;
00262 
00263     // Constructors
00264     KalTrack();
00265     void setIniEnergy(double ene);
00266     virtual ~KalTrack() {}
00267     
00268     // access to the Data - Compatible with LSQFit 
00269     KalTrack getKalTrack() const {return *this;}
00270     inline double iniEnergy()              const{return m_energy0;} 
00271 
00272     double positionAtZ(double const z) const;
00273 
00274     inline double position(double deltaZ)  const{return m_x0+deltaZ*m_slopeX;} 
00275     inline double slope()                  const{return m_slopeX;}
00276     double errorPosition() const;
00277     double errorSlope() const;
00278     double errorSlopeAtVertex() const;
00279     inline double chiSquare()              const{return m_chisq;}
00280     inline double chiSquareSmooth()        const{return m_chisqSmooth;}
00281     inline double KalThetaMS()             const{return m_KalThetaMS;}
00282     inline double KalEnergy()              const{return m_KalEnergy;}
00283     inline double scatter()                const{return m_rmsResid;}
00284     inline int numDataPoints()             const{return(int) kplanelist.size();}
00285     int numGaps() const;
00286     inline int numSegmentPoints()          const{return m_numSegmentPoints;}
00287     inline double chiSquareSegment(double penaltyGap = 0.)  const {return m_chisqSegment + penaltyGap*numGaps();}
00288     
00289     double kink(int iplane) const;
00290     double kinkNorma(int iplane) const;
00291 
00292         // operations
00293     void clear();
00294     void writeOut(int level) const;
00295 
00296     // LSQ Fit compatible
00297     double maxResidual(int* index)const;
00298     Point getHit(unsigned)const;
00299     unsigned getHitIndex(unsigned)const;
00300     int compareFits(KalTrack& ktrack); // gives error with const ?!
00301     
00302     // Drawing and Printting
00303     virtual void printOn(std::ostream &os = std::cout) const;
00304     void drawTrack(gui::DisplayRep& v, SiData::Axis, KalHit::TYPE);
00305     void drawChiSq(gui::DisplayRep& v, SiData::Axis, KalHit::TYPE);
00306 
00307     double doFit();
00308     void filterStep(int iplane);
00309 
00310     double computeChiSqSegment(int nhits, KalHit::TYPE typ = KalHit::SMOOTH);
00311 
00312 protected:
00313     // Do Fit
00314     void ini();
00315     KalHit generateFirstFitHit();
00316     void finish();
00317     
00318 private:
00319 
00320     // Energy Part
00321     void eneDetermination();
00322     
00323     // segment Part
00324     int computeNumSegmentPoints(KalHit::TYPE typ = KalHit::SMOOTH);
00325 
00326 public:
00327     
00328     std::vector<KalPlane> kplanelist;
00329     
00330 private:
00331     
00332     double m_energy0;
00333     double m_x0;
00334     double m_slopeX;
00335     double m_chisq;
00336     double m_chisqSmooth;
00337     double m_KalEnergy;
00338     double m_KalThetaMS;
00339     double m_rmsResid;
00340  
00341     int m_numSegmentPoints;
00342     double m_chisqSegment;
00343 };
00344 
00345 #endif _KALFIT_H
00346 

Generated at Wed Nov 21 12:20:44 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000