New version of alignment framework.
[u/mrichter/AliRoot.git] / STEER / AliTrackResidualsChi2.cxx
CommitLineData
98937d93 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//-----------------------------------------------------------------
17// Implementation of the derived class for track residuals
18// based on Chi2 minimization
19//
20//-----------------------------------------------------------------
21
22#include <TMinuit.h>
23#include <TGeoMatrix.h>
24
25#include "AliAlignObj.h"
26#include "AliTrackPointArray.h"
27#include "AliTrackResidualsChi2.h"
28
46ae650f 29void Fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *x, Int_t iflag);
30
98937d93 31ClassImp(AliTrackResidualsChi2)
32
33//______________________________________________________________________________
34void Fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
35{
36 // This function is called by minuit
37 // The corresponding member method is called
38 // using SetObjectFit/GetObjectFit methods of TMinuit
39 AliTrackResidualsChi2* dummy = (AliTrackResidualsChi2 *)gMinuit->GetObjectFit();
40 dummy->Chi2(npar, gin, f, par, iflag);
41}
42
43//______________________________________________________________________________
44Bool_t AliTrackResidualsChi2::Minimize()
45{
46 // Implementation of Chi2 based minimization
47 // of track residuala sum
46ae650f 48 Double_t arglist[10];
49 Int_t ierflg = 0;
98937d93 50 TMinuit *gMinuit = new TMinuit(6); //initialize TMinuit
46ae650f 51 arglist[0] = -1;
52 gMinuit->mnexcm("SET PRINT", arglist, 1, ierflg);
53
98937d93 54 gMinuit->SetObjectFit(this);
55 gMinuit->SetFCN(Fcn);
56
98937d93 57 arglist[0] = 1;
58 gMinuit->mnexcm("SET ERR", arglist ,1,ierflg);
59
60 // Set starting values and step sizes for parameters
46ae650f 61 Double_t pars[6] = {0,0,0,0,0,0};
62 Double_t step[6] = {0.0001,0.0001,0.0001,0.0001,0.0001,0.0001};
63 gMinuit->mnparm(0, "dx", pars[0], step[0], 0,0,ierflg);
64 gMinuit->mnparm(1, "dy", pars[1], step[1], 0,0,ierflg);
65 gMinuit->mnparm(2, "dz", pars[2], step[2], 0,0,ierflg);
66 gMinuit->mnparm(3, "psi", pars[3], step[3], 0,0,ierflg);
67 gMinuit->mnparm(4, "theta", pars[4], step[4], 0,0,ierflg);
68 gMinuit->mnparm(5, "phi", pars[5], step[5], 0,0,ierflg);
98937d93 69
70 // Now ready for minimization step
71 arglist[0] = 500;
72 arglist[1] = 1.;
73 gMinuit->mnexcm("MIGRAD", arglist ,2,ierflg);
74
75 // Print results
76 Double_t amin,edm,errdef;
77 Int_t nvpar,nparx,icstat;
78 gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat);
46ae650f 79 fChi2 = amin; fNdf -= nvpar;
98937d93 80
81 return kTRUE;
82}
83
84//______________________________________________________________________________
85void AliTrackResidualsChi2::Chi2(Int_t & /* npar */, Double_t * /* gin */, Double_t &f, Double_t *par, Int_t /* iflag */)
86{
87 // Chi2 function to be minimized
88 // Sums all the track residuals
89 Double_t chi2 = 0;
90
91 fAlignObj->SetPars(par[0],par[1],par[2],par[3],par[4],par[5]);
98937d93 92
93 AliTrackPoint p1,p2;
46ae650f 94
95 Bool_t count = kFALSE;
96 if (fNdf == 0) count = kTRUE;
98937d93 97
98 for (Int_t itrack = 0; itrack < fLast; itrack++) {
99 if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
100 for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
101 fVolArray[itrack]->GetPoint(p1,ipoint);
46ae650f 102 fAlignObj->Transform(p1);
98937d93 103 fTrackArray[itrack]->GetPoint(p2,ipoint);
46ae650f 104 Float_t residual = p2.GetResidual(p1,kFALSE);
105 chi2 += residual;
106 if (count) fNdf += 3;
98937d93 107 }
108 }
109 f = chi2;
110}