00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef ROOT_TCFit
00011 #define ROOT_TCFit
00012 #include "Rtypes.h"
00013 #include "TNamed.h"
00014 #include "TString.h"
00015 #include "TMatrixD.h"
00016 class TCFitData;
00017
00018
00019 class TCFit : public TNamed {
00020 public:
00021 enum FitResult {
00022 kFitOK = 0,
00023 kBadAprx = 0x001,
00024 kBadFcn = 0x002,
00025 kBadCon = 0x004,
00026 kTooItr = 0x008,
00027 kFatal = 0xfff
00028 };
00029 enum FitAction {
00030 kEndFit = 0,
00031 kNextStep = 1,
00032 kNextCut = 2,
00033 kBadFit = 3,
00034 kTooIter = 4
00035 };
00036
00037 public:
00038 TCFit(const char *name,TCFitData *dat=0);
00039 virtual ~TCFit();
00040 void Reset();
00041 Int_t SetData(TCFitData *dat);
00042 void SetMaxIter(int maxiter) { fMaxIter=maxiter;}
00043 void SetMaxCuts(int maxcuts) { fMaxCuts=maxcuts;}
00044 void SetDebug(int deb=1) { fDebug=deb;}
00045 int Fit();
00046 double ErMx(int jcol,int jrow) const;
00047 static void Test0();
00048 private:
00049 int PriStep(const char *tit="");
00050
00051 private:
00052
00053 int CheckIn();
00054 int CheckOut();
00055 int FitStep();
00056 int CheckStep();
00057 int CutStep();
00058 int EndStep();
00059
00060
00061 TCFitData *fDat;
00062 TMatrixD *fBigM;
00063 TMatrixD *fBigI;
00064 TMatrixD *fBigB;
00065 TMatrixD *fOldP;
00066 TMatrixD *fAddP;
00067 int fDebug;
00068 int fUPars;
00069 int fUMeas;
00070 int fUCons;
00071 int fIter;
00072 int fMaxIter;
00073 int fCuts;
00074 int fMaxCuts;
00075 int fAkt;
00076 int fFitRes;
00077 double fFcnQA[2];
00078 double fConQA[2];
00079 double fAddQA[2];
00080 ClassDef(TCFit,0)
00081
00082 };
00083
00084
00085 class Deriv1st;
00086 class Deriv2nd;
00087 class TCFit;
00088
00089 class TCFitData : public TNamed {
00090 friend class Deriv1st;
00091 friend class Deriv2nd;
00092 public:
00093 enum {kMEAS=0,kSLAC=1,kCNSR=2};
00094 enum {kMaxId=100};
00095 public:
00096 TCFitData(const char *name, const char *title="");
00097 virtual ~TCFitData();
00098 void Reset();
00099
00103 int AddPar(int tyPar,int idPar,double *par,int nPars=1,const char *name="",double tiny=0.);
00104
00105 int GetId(const char *name) const;
00106
00108
00109 int GetId(int jd) const;
00110 int GetJd(int id) const;
00111 const char *GetNam(int idx) const;
00112 int GetType(int id) const;
00113
00114 void FixPar (int id,int yes=1);
00115 int IsFixed(int id) const ;
00116
00117
00118 virtual int Ready();
00119 virtual int Approx()=0;
00120 virtual double Fcn()=0;
00121 virtual double DFcn(int ipar);
00122 virtual double DDFcn(int ipar,int jpar);
00123
00124 virtual double Con(int icon);
00125 virtual double DCon(int icon,int ipar);
00126
00127 virtual void Update()=0;
00128
00129
00130
00131 virtual void Print(const char *name) const;
00132
00133
00134
00135 void SetFitter(const TCFit *fitter) {fFitter = fitter;}
00136 void SetFail(int ifail) {fFail = ifail ;}
00137 int GetFail() const {return fFail;}
00138 int Modified() const {return fModi;}
00139 void Modify(int m=1) {fModi = m;}
00140 void Evaluate();
00141 double &GetPar (int ipar);
00142 double GetPar (int ipar) const ;
00143 double GetTiny(int ipar) const {return fTiny[ipar];}
00144 double GetFcn () const {return fFcn[0];}
00145 void SetFcn (double fcn) {fFcn[0] = fcn ;}
00146 void SetFcn (double tiny,double big) {fFcn[1] = tiny; fFcn[2]=big;}
00147 double GetBigFcn() const {return fFcn[2];}
00148 double GetTinyFcn() const {return fFcn[1];}
00149
00150 int GetNPars() const {return fNPars[0]+fNPars[1];}
00151 int GetNMeas() const {return fNPars[0];}
00152 int GetNSlac() const {return fNPars[1];}
00153 int GetNCons() const {return fNPars[2];}
00154 int GetUPars() const {return fNPars[0]-fNFixs[0]+fNPars[1]-fNFixs[1];}
00155 int GetUMeas() const {return fNPars[0]-fNFixs[0];}
00156 int GetUSlac() const {return fNPars[1]-fNFixs[1];}
00157 int GetUCons() const {return fNPars[2]-fNFixs[2];}
00158 int GetNDF() const {return GetUCons()-GetUSlac();}
00159 double ErMx(int icol,int irow) const;
00160
00161
00162 private:
00163
00164 protected:
00165 const TCFit *fFitter;
00166
00167 char fBeg[1];
00168 int fFail;
00169 int fModi;
00170 int fFlag;
00171 int fNPars[3];
00172 int fNFixs[3];
00173
00174 double *fPars[kMaxId+1];
00175 double fTiny[kMaxId+1];
00176 short fTyps[kMaxId+1];
00177 short fFixs[kMaxId+1];
00178 char fIndx[kMaxId+1];
00179 char fJndx[kMaxId+1];
00180 double fFcn[3];
00181 char fEnd[1];
00182 TString fNams[kMaxId];
00183 private:
00184 Deriv1st *fD1st;
00185 Deriv2nd *fD2nd;
00186 ClassDef(TCFitData,0)
00187 };
00188
00189
00190
00191 class TLorentzVector;
00192 class THelixTrack;
00193 class TVector3;
00194 class TkErrs;
00195
00196 class TkPars {
00197
00198 public:
00199 TkPars() { Reset(); SetHz();}
00200 void Reset();
00201 void Update(){curv = hz*ptin;}
00202 void Print(const char *tit) const;
00203 double *Arr() { return &dca;}
00204 const double *Arr() const { return &dca;}
00205 double P() const { return sqrt(1.+tanl*tanl)/fabs(ptin);}
00206 double E() const { return sqrt((1.+tanl*tanl)/(ptin*ptin)+mass*mass);}
00207 TLorentzVector P4() const;
00208 void P4D(double D[4][5]) const;
00209 TVector3 V3() const;
00210 void Fill(THelixTrack &hlx);
00211 void Set(const TVector3 &v3,const TVector3 &d3 ,double pts );
00212 void Get( TVector3 *v3, TVector3 *d3=0,double *pts=0) const;
00213 void Rand(const TkErrs &errs);
00214 void SetHz(double factor=1.);
00215
00216 static const char* Name(int mem);
00217 static double Tiny(int mem);
00218
00219
00220 TkPars &operator+=(const TkPars &a);
00222 double dca,z;
00224 double phi;
00226 double ptin;
00228 double tanl;
00230 double curv;
00232 double hz;
00234 double mass;
00235 };
00236
00237 class TkErrs {
00238 public:
00239
00240 TkErrs() {Reset();}
00241 void Reset();
00242 void Set(int i,int j,double err);
00243 double Get(int i,int j) const;
00244 void Invert();
00245 double Xi2(const TkPars &pars) const;
00246 void Mpy(const TkPars &pars,double der[5]) const;
00247 public:
00248 double emx[15];
00249
00250 };
00251
00252 class VxPars {
00253 public:
00254 VxPars() {memset(x,0,sizeof(x));}
00255
00256 TVector3 V3() const;
00257
00258 double x[3];
00259 public:
00260 };
00261
00262 class VxErrs {
00263 public:
00264 double emx[6];
00265 };
00266
00267 class TCFitV0 : public TCFitData {
00268 public:
00269 enum eTCFitV0 { kDCA_0= 0,kZ_0 = 1,kPHI_0= 2,kPTIN_0= 3,kTANL_0= 4
00270 , kDCA_1=10,kZ_1 =11,kPHI_1=12,kPTIN_1=13,kTANL_1=14
00271 , kLEN_0=20,kLEN_1=21,kLEN_2=22
00272 , kCX_0 =30,kCY_0 =31,kCZ_0 =32
00273 , kCX_1 =33,kCY_1 =34,kCZ_1 =35
00274 , kCNRJ =36 };
00275 public:
00276 TCFitV0();
00277 ~TCFitV0(){;}
00278 virtual double Fcn();
00279 virtual double DFcn(int ipar);
00280 virtual double DDFcn(int ipar,int jpar);
00281
00282 virtual double Con(int icon);
00283 virtual double DCon(int icon,int ipar);
00284 int Ready();
00285 int Approx();
00286 virtual void Update();
00287 virtual void Print(const char *name) const;
00288 public:
00289 void Reset();
00290 static void Test(int mode=0);
00291
00292 private:
00293 public:
00294 TkPars mTkBas[2];
00295 TkErrs mTEBas[2];
00296 TkPars mTkFit[2];
00297 TkPars mTkDif[2];
00298
00299 char mBeg[1];
00300 char mReady;
00301
00302 VxPars mVx;
00303 VxErrs mVE;
00304 double mLen[3];
00305
00306 double mConr[7];
00307 double mDFcn[2][5];
00308 double mDConDL[3][3];
00309 double mP4d[2][4][5];
00310 double mMas;
00311 char mEnd[1];
00312
00313 ClassDef(TCFitV0,0)
00314 };
00315
00316 #endif //ROOT_TCFit
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329