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

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