]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTrackResiduals.cxx
New version of alignment framework.
[u/mrichter/AliRoot.git] / 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 "AliTrackPointArray.h"
26
27 ClassImp(AliTrackResiduals)
28
29 //_____________________________________________________________________________
30 AliTrackResiduals::AliTrackResiduals():
31   fN(0),
32   fLast(0),
33   fAlignObj(0),
34   fVolArray(0),
35   fTrackArray(0),
36   fChi2(0),
37   fNdf(0),
38   fIsOwner(kTRUE)
39 {
40   // Default constructor
41 }
42
43 //_____________________________________________________________________________
44 AliTrackResiduals::AliTrackResiduals(Int_t ntracks):
45   fN(ntracks),
46   fLast(0),
47   fAlignObj(0),
48   fChi2(0),
49   fNdf(0),
50   fIsOwner(kTRUE)
51 {
52   // Constructor
53   if (ntracks > 0) {
54     fVolArray = new AliTrackPointArray*[ntracks];
55     fTrackArray = new AliTrackPointArray*[ntracks];
56     for (Int_t itrack = 0; itrack < ntracks; itrack++)
57       fVolArray[itrack] = fTrackArray[itrack] = 0x0;
58   }
59 }
60
61 //_____________________________________________________________________________
62 AliTrackResiduals::AliTrackResiduals(const AliTrackResiduals &res):
63   TObject(res),
64   fN(res.fN),
65   fLast(res.fLast),
66   fChi2(res.fChi2),
67   fNdf(res.fNdf),
68   fIsOwner(kTRUE)
69 {
70   // Copy constructor
71   // By default the created copy owns the track point arrays
72   if (res.fAlignObj)
73     fAlignObj = (AliAlignObj *)res.fAlignObj->Clone();
74
75   if (fN > 0) {
76     fVolArray = new AliTrackPointArray*[fN];
77     fTrackArray = new AliTrackPointArray*[fN];
78     for (Int_t itrack = 0; itrack < fN; itrack++)
79       {
80         if (res.fVolArray[itrack])
81           fVolArray[itrack] = new AliTrackPointArray(*res.fVolArray[itrack]);
82         else
83           fVolArray = 0x0;
84         if (res.fTrackArray[itrack])
85           fTrackArray[itrack] = new AliTrackPointArray(*res.fTrackArray[itrack]);
86         else
87           fTrackArray = 0x0;
88       }
89   }
90 }
91
92 //_____________________________________________________________________________
93 AliTrackResiduals &AliTrackResiduals::operator =(const AliTrackResiduals& res)
94 {
95   // assignment operator
96   // Does not copy the track point arrays
97   if(this==&res) return *this;
98   ((TObject *)this)->operator=(res);
99
100   fN = res.fN;
101   fLast = res.fLast;
102   fChi2 = res.fChi2;
103   fNdf  = res.fNdf;
104   fIsOwner = kFALSE;
105   fAlignObj = res.fAlignObj;
106
107   fVolArray = res.fVolArray;
108   fTrackArray = res.fTrackArray;
109
110   return *this;
111 }
112
113 //_____________________________________________________________________________
114 AliTrackResiduals::~AliTrackResiduals()
115 {
116   // Destructor
117   if (fAlignObj) delete fAlignObj;
118   DeleteTrackPointArrays();
119 }
120
121 //_____________________________________________________________________________
122 void AliTrackResiduals::SetNTracks(Int_t ntracks)
123 {
124   // Set new size for the track point arrays.
125   // Delete the old arrays and allocate the
126   // new ones.
127   DeleteTrackPointArrays();
128
129   fN = ntracks;
130   fLast = 0;
131   fChi2 = 0;
132   fNdf  = 0;
133   fIsOwner = kTRUE;
134
135   if (ntracks > 0) {
136     fVolArray = new AliTrackPointArray*[ntracks];
137     fTrackArray = new AliTrackPointArray*[ntracks];
138     for (Int_t itrack = 0; itrack < ntracks; itrack++)
139       fVolArray[itrack] = fTrackArray[itrack] = 0x0;
140   }
141 }
142
143 //_____________________________________________________________________________
144 Bool_t AliTrackResiduals::AddTrackPointArrays(AliTrackPointArray *volarray, AliTrackPointArray *trackarray)
145 {
146   // Adds pair of track space point and
147   // track extrapolation point arrays
148   if (!fVolArray || !fTrackArray) return kFALSE;
149
150   if (fLast >= fN) return kFALSE;
151
152   fVolArray[fLast] = volarray;
153   fTrackArray[fLast] = trackarray;
154   fLast++;
155
156   return kTRUE;
157 }
158
159 //_____________________________________________________________________________
160 void AliTrackResiduals::SetAlignObj(AliAlignObj *alignobj)
161 {
162   // Copy the alignment object to be updated in fAlignObj
163   // and flush its parameters
164   if (fAlignObj) delete fAlignObj;
165   fAlignObj = (AliAlignObj *)alignobj->Clone();
166   fAlignObj->SetPars(0,0,0,0,0,0);
167 }
168
169
170 //_____________________________________________________________________________
171 Bool_t AliTrackResiduals::GetTrackPointArrays(Int_t i, AliTrackPointArray* &volarray, AliTrackPointArray* &trackarray) const
172 {
173   // Provide an access to a pair of track point arrays
174   // with given index
175   if (i >= fLast) {
176     volarray = trackarray = 0x0;
177     return kFALSE;
178   }
179   else {
180     volarray = fVolArray[i];
181     trackarray = fTrackArray[i];
182     return kTRUE;
183   }
184 }
185
186 //_____________________________________________________________________________
187 void AliTrackResiduals::DeleteTrackPointArrays()
188 {
189   // Deletes the track point arrays only in case
190   // the object is their owner.
191   // Called by the destructor and SetNTracks methods.
192   if (fIsOwner) {
193     for (Int_t itrack = 0; itrack < fLast; itrack++)
194       {
195         delete fVolArray[itrack];
196         delete fTrackArray[itrack];
197       }
198     delete [] fVolArray;
199     delete [] fTrackArray;
200   }
201 }