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