Fixes for bug #52499: Field polarities inconsistiency
[u/mrichter/AliRoot.git] / STEER / AliTrackResiduals.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 base class for track residuals
18//
19//
20//-----------------------------------------------------------------
21
22#include "AliTrackResiduals.h"
23
24#include "AliAlignObj.h"
90dbf5fb 25#include "AliAlignObjParams.h"
98937d93 26#include "AliTrackPointArray.h"
27
28ClassImp(AliTrackResiduals)
29
30//_____________________________________________________________________________
31AliTrackResiduals::AliTrackResiduals():
32 fN(0),
33 fLast(0),
46ae650f 34 fAlignObj(0),
35 fVolArray(0),
36 fTrackArray(0),
37 fChi2(0),
38 fNdf(0),
cc345ce3 39 fMinNPoints(0),
98937d93 40 fIsOwner(kTRUE)
41{
42 // Default constructor
29317b68 43 for (Int_t ipar=0; ipar<6; ipar++){
44 fBFixed[ipar] = kFALSE;
45 fFixed[ipar] = 0.;
46 }
98937d93 47}
48
49//_____________________________________________________________________________
46ae650f 50AliTrackResiduals::AliTrackResiduals(Int_t ntracks):
98937d93 51 fN(ntracks),
52 fLast(0),
46ae650f 53 fAlignObj(0),
75e3794b 54 fVolArray(0),
55 fTrackArray(0),
46ae650f 56 fChi2(0),
57 fNdf(0),
cc345ce3 58 fMinNPoints(0),
98937d93 59 fIsOwner(kTRUE)
60{
61 // Constructor
62 if (ntracks > 0) {
63 fVolArray = new AliTrackPointArray*[ntracks];
64 fTrackArray = new AliTrackPointArray*[ntracks];
65 for (Int_t itrack = 0; itrack < ntracks; itrack++)
66 fVolArray[itrack] = fTrackArray[itrack] = 0x0;
67 }
faf254af 68
29317b68 69 for (Int_t ipar=0; ipar<6; ipar++){
70 fBFixed[ipar] = kFALSE;
71 fFixed[ipar] = 0.;
72 }
98937d93 73}
74
75//_____________________________________________________________________________
76AliTrackResiduals::AliTrackResiduals(const AliTrackResiduals &res):
77 TObject(res),
78 fN(res.fN),
79 fLast(res.fLast),
75e3794b 80 fAlignObj(0),
81 fVolArray(0),
82 fTrackArray(0),
46ae650f 83 fChi2(res.fChi2),
84 fNdf(res.fNdf),
cc345ce3 85 fMinNPoints(res.fMinNPoints),
98937d93 86 fIsOwner(kTRUE)
87{
88 // Copy constructor
89 // By default the created copy owns the track point arrays
46ae650f 90 if (res.fAlignObj)
91 fAlignObj = (AliAlignObj *)res.fAlignObj->Clone();
92
98937d93 93 if (fN > 0) {
94 fVolArray = new AliTrackPointArray*[fN];
95 fTrackArray = new AliTrackPointArray*[fN];
96 for (Int_t itrack = 0; itrack < fN; itrack++)
97 {
98 if (res.fVolArray[itrack])
99 fVolArray[itrack] = new AliTrackPointArray(*res.fVolArray[itrack]);
100 else
101 fVolArray = 0x0;
102 if (res.fTrackArray[itrack])
103 fTrackArray[itrack] = new AliTrackPointArray(*res.fTrackArray[itrack]);
104 else
105 fTrackArray = 0x0;
106 }
107 }
29317b68 108 for(Int_t i=0;i<6;i++) {
109 fBFixed[i]=res.fBFixed[i];
110 fFixed[i]=res.fFixed[i];
111 }
98937d93 112}
113
114//_____________________________________________________________________________
115AliTrackResiduals &AliTrackResiduals::operator =(const AliTrackResiduals& res)
116{
117 // assignment operator
118 // Does not copy the track point arrays
119 if(this==&res) return *this;
120 ((TObject *)this)->operator=(res);
121
122 fN = res.fN;
123 fLast = res.fLast;
46ae650f 124 fChi2 = res.fChi2;
125 fNdf = res.fNdf;
cc345ce3 126 fMinNPoints = res.fMinNPoints;
98937d93 127 fIsOwner = kFALSE;
128 fAlignObj = res.fAlignObj;
129
130 fVolArray = res.fVolArray;
131 fTrackArray = res.fTrackArray;
132
29317b68 133 for(Int_t i=0;i<6;i++) {
134 fBFixed[i]=res.fBFixed[i];
135 fFixed[i]=res.fFixed[i];
136 }
137
98937d93 138 return *this;
139}
140
141//_____________________________________________________________________________
142AliTrackResiduals::~AliTrackResiduals()
143{
144 // Destructor
46ae650f 145 if (fAlignObj) delete fAlignObj;
98937d93 146 DeleteTrackPointArrays();
147}
148
149//_____________________________________________________________________________
150void AliTrackResiduals::SetNTracks(Int_t ntracks)
151{
152 // Set new size for the track point arrays.
153 // Delete the old arrays and allocate the
154 // new ones.
155 DeleteTrackPointArrays();
156
157 fN = ntracks;
158 fLast = 0;
46ae650f 159 fChi2 = 0;
160 fNdf = 0;
98937d93 161 fIsOwner = kTRUE;
162
163 if (ntracks > 0) {
164 fVolArray = new AliTrackPointArray*[ntracks];
165 fTrackArray = new AliTrackPointArray*[ntracks];
166 for (Int_t itrack = 0; itrack < ntracks; itrack++)
167 fVolArray[itrack] = fTrackArray[itrack] = 0x0;
168 }
faf254af 169 else {
170 fVolArray = fTrackArray = 0x0;
171 }
98937d93 172}
173
174//_____________________________________________________________________________
175Bool_t AliTrackResiduals::AddTrackPointArrays(AliTrackPointArray *volarray, AliTrackPointArray *trackarray)
176{
177 // Adds pair of track space point and
178 // track extrapolation point arrays
179 if (!fVolArray || !fTrackArray) return kFALSE;
180
cc345ce3 181 if (!volarray || !trackarray) return kFALSE;
182
183 if (volarray->GetNPoints() < fMinNPoints) return kFALSE;
184
98937d93 185 if (fLast >= fN) return kFALSE;
186
187 fVolArray[fLast] = volarray;
188 fTrackArray[fLast] = trackarray;
189 fLast++;
190
191 return kTRUE;
192}
193
194//_____________________________________________________________________________
cc345ce3 195void AliTrackResiduals::InitAlignObj()
46ae650f 196{
cc345ce3 197 // Create the alignment object
198 // to be updated
46ae650f 199 if (fAlignObj) delete fAlignObj;
90dbf5fb 200 fAlignObj = new AliAlignObjParams;
46ae650f 201}
202
203
204//_____________________________________________________________________________
98937d93 205Bool_t AliTrackResiduals::GetTrackPointArrays(Int_t i, AliTrackPointArray* &volarray, AliTrackPointArray* &trackarray) const
206{
207 // Provide an access to a pair of track point arrays
208 // with given index
209 if (i >= fLast) {
210 volarray = trackarray = 0x0;
211 return kFALSE;
212 }
213 else {
214 volarray = fVolArray[i];
215 trackarray = fTrackArray[i];
216 return kTRUE;
217 }
218}
219
220//_____________________________________________________________________________
221void AliTrackResiduals::DeleteTrackPointArrays()
222{
223 // Deletes the track point arrays only in case
224 // the object is their owner.
225 // Called by the destructor and SetNTracks methods.
226 if (fIsOwner) {
faf254af 227 if (fVolArray) {
228 for (Int_t itrack = 0; itrack < fN; itrack++) {
229 if (fVolArray[itrack]) delete fVolArray[itrack];
230 }
231 delete [] fVolArray;
232 }
233 if (fTrackArray) {
234 for (Int_t itrack = 0; itrack < fN; itrack++) {
235 if (fTrackArray[itrack]) delete fTrackArray[itrack];
98937d93 236 }
faf254af 237 delete [] fTrackArray;
238 }
98937d93 239 }
240}
cc101660 241
242//_____________________________________________________
f12d42ce 243Int_t AliTrackResiduals::GetNFreeParam(){
cc101660 244 Int_t unfixedparam=6;
245 for(Int_t j=0;j<6;j++){
246 if(fBFixed[j]==kTRUE)unfixedparam--;
247 }
248 return unfixedparam;
249}