running local for SP and LYZEP and new histograms for QC
[u/mrichter/AliRoot.git] / TRD / AliTRDpropagationLayer.cxx
CommitLineData
e4f2f73d 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/* $Id$ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
20// The TRD propagation layer //
21// //
22// Authors: //
23// Marian Ivanov <M.Ivanov@gsi.de> //
24// Alex Bercuci <A.Bercuci@gsi.de> //
25// Markus Fasel <M.Fasel@gsi.de> //
26// //
27////////////////////////////////////////////////////////////////////////////
28
29#include "string.h"
30
31#include "TMath.h"
32
33#include "AliTRDpropagationLayer.h"
34//#include "AliTRDtracker.h"
35#include "AliTRDcluster.h"
36#include "AliTRDgeometry.h"
37
38//_____________________________________________________________________________
39AliTRDpropagationLayer::AliTRDpropagationLayer()
40 :TObject()
41 ,fN(0)
42 ,fSec(0)
43 ,fClusters(NULL)
44 ,fIndex(NULL)
45 ,fX(0.)
46 ,fdX(0.)
47 ,fRho(0.)
48 ,fX0(0.)
49 ,fTimeBinIndex(0)
50 ,fPlane(0)
51 ,fYmax(0)
52 ,fYmaxSensitive(0)
53 ,fHole(kFALSE)
54 ,fHoleZc(0)
55 ,fHoleZmax(0)
56 ,fHoleYc(0)
57 ,fHoleYmax(0)
58 ,fHoleRho(0)
59 ,fHoleX0(0)
60{
61 //
62 // Default constructor
63 //
64
65}
66
67//_____________________________________________________________________________
68AliTRDpropagationLayer::AliTRDpropagationLayer(Double_t x, Double_t dx, Double_t rho
69 , Double_t radLength, Int_t tbIndex, Int_t plane)
70 :TObject()
71 ,fN(0)
72 ,fSec(0)
73 ,fClusters(NULL)
74 ,fIndex(NULL)
75 ,fX(x)
76 ,fdX(dx)
77 ,fRho(rho)
78 ,fX0(radLength)
79 ,fTimeBinIndex(tbIndex)
80 ,fPlane(plane)
81 ,fYmax(0)
82 ,fYmaxSensitive(0)
83 ,fHole(kFALSE)
84 ,fHoleZc(0)
85 ,fHoleZmax(0)
86 ,fHoleYc(0)
87 ,fHoleYmax(0)
88 ,fHoleRho(0)
89 ,fHoleX0(0)
90{
91 //
92 // AliTRDpropagationLayer constructor
93 //
94
95 for (Int_t i = 0; i < (Int_t)kZones; i++) {
96 fZc[i] = 0;
97 fZmax[i] = 0;
98 }
99
100 if (fTimeBinIndex >= 0) {
101 fClusters = new AliTRDcluster*[kMaxClusterPerTimeBin];
102 fIndex = new UInt_t[kMaxClusterPerTimeBin];
103 }
104
105 for (Int_t i = 0; i < 5; i++) {
106 fIsHole[i] = kFALSE;
107 }
108
109}
110
111//_____________________________________________________________________________
112AliTRDpropagationLayer::AliTRDpropagationLayer(const AliTRDpropagationLayer &p)
113 :TObject((TObject&)p)
114 ,fN(p.fN)
115 ,fSec(p.fSec)
116 ,fClusters(0x0)
117 ,fIndex(0x0)
118 ,fX(p.fX)
119 ,fdX(p.fdX)
120 ,fRho(p.fRho)
121 ,fX0(p.fX0)
122 ,fTimeBinIndex(p.fTimeBinIndex)
123 ,fPlane(p.fPlane)
124 ,fYmax(p.fYmax)
125 ,fYmaxSensitive(p.fYmaxSensitive)
126 ,fHole(p.fHole)
127 ,fHoleZc(p.fHoleZc)
128 ,fHoleZmax(p.fHoleZmax)
129 ,fHoleYc(p.fHoleYc)
130 ,fHoleYmax(p.fHoleYmax)
131 ,fHoleRho(p.fHoleRho)
132 ,fHoleX0(p.fHoleX0)
133{
134 //
135 // AliTRDpropagationLayer copy constructor
136 //
137
138 for (Int_t i = 0; i < (Int_t)kZones; i++) {
139 fZc[i] = p.fZc[i];
140 fZmax[i] = p.fZmax[i];
141 fIsHole[i] = p.fIsHole[i];
142 fZmaxSensitive[i] = p.fZmaxSensitive[i];
143 }
144
145 // Make a deep copy of the Clusters array and the Index array unless they are needed in class AliTRDstackLayer
146 Int_t arrsize = (Int_t)kMaxClusterPerTimeBin;
147 if (fTimeBinIndex >= 0) {
148 fClusters = new AliTRDcluster*[arrsize];
149 fIndex = new UInt_t[arrsize];
150 }
151 memset(fIndex, 0, sizeof(UInt_t)*arrsize);
152 memset(fClusters, 0, sizeof(AliTRDcluster *)*arrsize);
153 for(Int_t i = 0; i < arrsize; i++){
154 fClusters[i] = p.fClusters[i];
155 fIndex[i] = p.fIndex[i];
156 }
157}
158
159//_____________________________________________________________________________
160AliTRDpropagationLayer::~AliTRDpropagationLayer()
161{
162 //
163 // Destructor
164 //
165
166 if (fTimeBinIndex >= 0) {
167 delete[] fClusters;
168 delete[] fIndex;
169 }
170
171}
172
173//_____________________________________________________________________________
174void AliTRDpropagationLayer::Copy(TObject &o) const
175{
176 //
177 // Copy function
178 //
179
180 AliTRDpropagationLayer &p = (AliTRDpropagationLayer &)o;
181 p.fN = fN;
182 p.fSec = fSec;
183 p.fX = fX;
184 p.fdX = fdX;
185 p.fRho = fRho;
186 p.fX0 = fX0;
187 p.fTimeBinIndex = fTimeBinIndex;
188 p.fPlane = fPlane;
189 p.fYmax = fYmax;
190 p.fYmaxSensitive = fYmaxSensitive;
191 p.fHole = fHole;
192 p.fHoleZc = fHoleZc;
193 p.fHoleZmax = fHoleZmax;
194 p.fHoleYc = fHoleYc;
195 p.fHoleYmax = fHoleYmax;
196 p.fHoleRho = fHoleRho;
197 p.fHoleX0 = fHoleX0;
198
199 for (Int_t i = 0; i < (Int_t)kZones; i++) {
200 p.fZc[i] = fZc[i];
201 p.fZmax[i] = fZmax[i];
202 p.fIsHole[i] = fIsHole[i];
203 p.fZmaxSensitive[i] = fZmaxSensitive[i];
204 }
205
206 // Make a deep copy of the Clusters array and the Index array
207 // unless they are needed in class AliTRDstackLayer
208 if (fTimeBinIndex >= 0) {
209 if (!p.fClusters)
210 p.fClusters = new AliTRDcluster*[(Int_t)kMaxClusterPerTimeBin];
211 if (!p.fIndex)
212 p.fIndex = new UInt_t[(Int_t)kMaxClusterPerTimeBin];
213 }
214 for (Int_t i = 0; i < (Int_t)kMaxClusterPerTimeBin; i++){
215 //overwrite
216 p.fClusters[i] = fClusters[i];
217 p.fIndex[i] = fIndex[i];
218 }
219
220}
221
222//_____________________________________________________________________________
223void AliTRDpropagationLayer::SetZ(Double_t *center, Double_t *w, Double_t *wsensitive )
224{
225 //
226 // Set centers and the width of sectors
227 //
228
053767a4 229 for (Int_t istack = 0; istack < AliTRDgeometry::kNstack; istack++) {
230 fZc[istack] = center[istack];
231 fZmax[istack] = w[istack];
232 fZmaxSensitive[istack] = wsensitive[istack];
e4f2f73d 233 }
234
235}
236
237//_____________________________________________________________________________
238void AliTRDpropagationLayer::SetHoles(Bool_t *holes)
239{
240 //
241 // Set centers and the width of sectors
242 //
243
244 fHole = kFALSE;
245
053767a4 246 for (Int_t istack = 0; istack < AliTRDgeometry::kNstack; istack++) {
247 fIsHole[istack] = holes[istack];
248 if (holes[istack]) {
e4f2f73d 249 fHole = kTRUE;
250 }
251 }
252
253}
254
255//_____________________________________________________________________________
256void AliTRDpropagationLayer::InsertCluster(AliTRDcluster *c, UInt_t index)
257{
258 //
259 // Insert cluster in cluster array.
260 // Clusters are sorted according to Y coordinate.
261 //
262
263 if (fTimeBinIndex < 0) {
264 //AliWarning("Attempt to insert cluster into non-sensitive time bin!\n");
265 return;
266 }
267
268 if (fN == (Int_t) kMaxClusterPerTimeBin) {
269 //AliWarning("Too many clusters !\n");
270 return;
271 }
272
273 if (fN == 0) {
274 fIndex[0] = index;
275 fClusters[fN++] = c;
276 return;
277 }
278
279 Int_t i = Find(c->GetY());
280 memmove(fClusters+i+1,fClusters+i,(fN-i)*sizeof(AliTRDcluster*));
281 memmove(fIndex +i+1,fIndex +i,(fN-i)*sizeof(UInt_t));
282 fIndex[i] = index;
283 fClusters[i] = c;
284 fN++;
285
286}
287
288//_____________________________________________________________________________
289Int_t AliTRDpropagationLayer::Find(Float_t y) const
290{
291 //
292 // Returns index of the cluster nearest in Y
293 //
294
295 if (fN <= 0) {
296 return 0;
297 }
298 if (y <= fClusters[0]->GetY()) {
299 return 0;
300 }
301 if (y > fClusters[fN-1]->GetY()) {
302 return fN;
303 }
304
305 Int_t b = 0;
306 Int_t e = fN - 1;
307 Int_t m = (b + e) / 2;
308
309 for ( ; b < e; m = (b + e) / 2) {
310 if (y > fClusters[m]->GetY()) {
311 b = m + 1;
312 }
313 else {
314 e = m;
315 }
316 }
317
318 return m;
319
320}
321
322//_____________________________________________________________________________
323Int_t AliTRDpropagationLayer::FindNearestCluster(Float_t y, Float_t z
324 , Float_t maxroad
325 , Float_t maxroadz) const
326{
327 //
328 // Returns index of the cluster nearest to the given y,z
329 //
330
331 Int_t index = -1;
332 Int_t maxn = fN;
333 Float_t mindist = maxroad;
334
335 for (Int_t i = Find(y-maxroad); i < maxn; i++) {
336 AliTRDcluster *c = (AliTRDcluster *) (fClusters[i]);
337 Float_t ycl = c->GetY();
338 if (ycl > (y + maxroad)) {
339 break;
340 }
341 if (TMath::Abs(c->GetZ() - z) > maxroadz) {
342 continue;
343 }
344 if (TMath::Abs(ycl - y) < mindist) {
345 mindist = TMath::Abs(ycl - y);
346 index = fIndex[i];
347 }
348 }
349
350 return index;
351
352}
353