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