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