]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTrackResidualsChi2.cxx
Correct bug in MakeSlidingCell and define 3 new data members related to the number...
[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
29ClassImp(AliTrackResidualsChi2)
30
31//______________________________________________________________________________
32void Fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
33{
34 // This function is called by minuit
35 // The corresponding member method is called
36 // using SetObjectFit/GetObjectFit methods of TMinuit
37 AliTrackResidualsChi2* dummy = (AliTrackResidualsChi2 *)gMinuit->GetObjectFit();
38 dummy->Chi2(npar, gin, f, par, iflag);
39}
40
41//______________________________________________________________________________
42Bool_t AliTrackResidualsChi2::Minimize()
43{
44 // Implementation of Chi2 based minimization
45 // of track residuala sum
46 TMinuit *gMinuit = new TMinuit(6); //initialize TMinuit
47 gMinuit->SetObjectFit(this);
48 gMinuit->SetFCN(Fcn);
49
50 Double_t arglist[10];
51 Int_t ierflg = 0;
52
53 arglist[0] = 1;
54 gMinuit->mnexcm("SET ERR", arglist ,1,ierflg);
55
56 // Set starting values and step sizes for parameters
57 Double_t tr[3],rot[3];
58 fAlignObj->GetPars(tr,rot);
59 static Double_t step[6] = {0,0,0,0,0,0};
60 gMinuit->mnparm(0, "x", tr[0], step[0], 0,0,ierflg);
61 gMinuit->mnparm(1, "y", tr[1], step[1], 0,0,ierflg);
62 gMinuit->mnparm(2, "z", tr[2], step[2], 0,0,ierflg);
63 gMinuit->mnparm(3, "psi", rot[0], step[3], 0,0,ierflg);
64 gMinuit->mnparm(4, "theta", rot[1], step[4], 0,0,ierflg);
65 gMinuit->mnparm(5, "phi", rot[2], step[5], 0,0,ierflg);
66
67 // Now ready for minimization step
68 arglist[0] = 500;
69 arglist[1] = 1.;
70 gMinuit->mnexcm("MIGRAD", arglist ,2,ierflg);
71
72 // Print results
73 Double_t amin,edm,errdef;
74 Int_t nvpar,nparx,icstat;
75 gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat);
76 gMinuit->mnprin(3,amin);
77
78 return kTRUE;
79}
80
81//______________________________________________________________________________
82void AliTrackResidualsChi2::Chi2(Int_t & /* npar */, Double_t * /* gin */, Double_t &f, Double_t *par, Int_t /* iflag */)
83{
84 // Chi2 function to be minimized
85 // Sums all the track residuals
86 Double_t chi2 = 0;
87
88 fAlignObj->SetPars(par[0],par[1],par[2],par[3],par[4],par[5]);
89 TGeoHMatrix m;
90 fAlignObj->GetMatrix(m);
91 Double_t *rot = m.GetRotationMatrix();
92 Double_t *tr = m.GetTranslation();
93
94 AliTrackPoint p1,p2;
95 Double_t dR[3];
96 Float_t xyzvol[3],xyztr[3];
97 Float_t covvol[6],covtr[6];
98
99 for (Int_t itrack = 0; itrack < fLast; itrack++) {
100 if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
101 for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
102 fVolArray[itrack]->GetPoint(p1,ipoint);
103 fTrackArray[itrack]->GetPoint(p2,ipoint);
104 p1.GetXYZ(xyzvol,covvol);
105 p2.GetXYZ(xyztr,covtr);
106
107 for (Int_t i = 0; i < 3; i++)
108 dR[i] = tr[i]
109 + xyzvol[0]*rot[3*i]
110 + xyzvol[1]*rot[3*i+1]
111 + xyzvol[2]*rot[3*i+2]
112 - xyztr[i];
113 chi2 += dR[0]*dR[0]+dR[1]*dR[1]+dR[2]*dR[2];
114 }
115 }
116 f = chi2;
117}