00001
00002
00003
00004
00005
00006
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
00023 public:
00024
00025
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
00060 friend class KalFit;
00061
00062 public:
00063
00064 KalMatrix(){
00065 a[0][0]=a[0][1]=a[1][0]=a[1][1]=0.;
00066 }
00067
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
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
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
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
00193
00194
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
00203
00204 public:
00205
00206
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();
00214 void clear();
00215 void removeHit();
00216
00217
00218
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;
00227 int m_IDTower;
00228 int m_IDPlane;
00229
00230
00231 double m_zplane;
00232 double m_eneplane;
00233
00234 KalPar m_OrthPar;
00235
00236
00237
00238
00239 KalHit m_hitmeas;
00240 KalHit m_hitpred;
00241 KalHit m_hitfit;
00242 KalHit m_hitsmooth;
00243 KalMatrix m_Qmaterial;
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
00259 KalTrack();
00260 void setIniEnergy(double ene);
00261 virtual ~KalTrack() {}
00262
00263
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
00288 void clear();
00289
00290
00291 void draw(gui::DisplayRep& v);
00292
00293
00294 double maxResidual(int* index)const;
00295 Point getHit(unsigned)const;
00296 unsigned getHitIndex(unsigned)const;
00297 int compareFits(KalTrack& ktrack);
00298
00299
00300
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
00312 void ini();
00313 KalHit generateFirstFitHit();
00314 void finish();
00315
00316 private:
00317
00318
00319 void eneDetermination();
00320
00321
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