New ITS code for new structure and simulations.
[u/mrichter/AliRoot.git] / ITS / AliITSMap.cxx
CommitLineData
b0f5e3fc 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#include <TH1.h>
17#include "AliITSMap.h"
18
19ClassImp(AliITSMap)
20
21ClassImp(AliITSMapA1)
22
23AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg)
24{
25 //constructor
26 fSegmentation = seg;
27 fNpz=fSegmentation->Npz();
28 fNpx=fSegmentation->Npx();
29 fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector
30
31 fHitMap = new Int_t[fMaxIndex];
32 fObjects = 0;
33 ClearMap();
34}
35
36AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg, TObjArray *obj)
37{
38 //constructor
39 fSegmentation = seg;
40 fNpz=fSegmentation->Npz();
41 fNpx=fSegmentation->Npx();
42 fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector
43
44 fHitMap = new Int_t[fMaxIndex];
45 fObjects = obj;
46 if (fObjects) fNobjects = fObjects->GetEntriesFast();
47 ClearMap();
48}
49
50
51AliITSMapA1::~AliITSMapA1()
52{
53 //destructor
54 if (fHitMap) delete[] fHitMap;
55}
56
57//__________________________________________________________________________
58AliITSMapA1::AliITSMapA1(const AliITSMapA1 &source){
59 // Copy Constructor
60 if(&source == this) return;
61 this->fNpx = source.fNpx;
62 this->fNpz = source.fNpz;
63 this->fObjects = source.fObjects;
64 this->fNobjects = source.fNobjects;
65 this->fMaxIndex = source.fMaxIndex;
66 this->fHitMap = source.fHitMap;
67 return;
68}
69
70//_________________________________________________________________________
71AliITSMapA1&
72 AliITSMapA1::operator=(const AliITSMapA1 &source) {
73 // Assignment operator
74 if(&source == this) return *this;
75 this->fNpx = source.fNpx;
76 this->fNpz = source.fNpz;
77 this->fObjects = source.fObjects;
78 this->fNobjects = source.fNobjects;
79 this->fMaxIndex = source.fMaxIndex;
80 this->fHitMap = source.fHitMap;
81 return *this;
82}
83
84void AliITSMapA1::ClearMap()
85{
86 //clear array
87 memset(fHitMap,0,sizeof(int)*fMaxIndex);
88}
89
90void AliITSMapA1::SetArray(TObjArray *obj)
91{
92 // set array of objects
93 fObjects = obj;
94 if (fObjects) fNobjects = fObjects->GetEntriesFast();
95}
96
97
98Int_t AliITSMapA1::CheckedIndex(Int_t iz, Int_t ix)
99{
100 //check boundaries and return an index in array
101 Int_t index=fNpx*iz+ix;
102 if (index > fMaxIndex) {
103 printf("\n \n \n Try to read/write outside array !!!! \n \n %d %d %d %d %d %d",iz,ix, fMaxIndex, index, fNpz, fNpx);
104 // force crash
105 return -1;
106 } else {
107 return index;
108 }
109}
110
111
112void AliITSMapA1::FillMap()
113{
114 // fill array with digits indices
115 Int_t ndigits = fObjects->GetEntriesFast();
116 //printf("MapA1: ndigits fNobjects %d %d \n",ndigits,fNobjects);
117 if (!ndigits) return;
118
119 AliITSdigit *dig;
120 Int_t ndig;
121 for(ndig=0; ndig<ndigits; ndig++) {
122 dig = (AliITSdigit*)fObjects->UncheckedAt(ndig);
123 //printf("MapA1: ndig fCoord1 fCoord2 %d %d %d \n",dig->fCoord1,dig->fCoord2,ndig);
124 SetHit(dig->fCoord1,dig->fCoord2,ndig);
125 }
126
127}
128
129void AliITSMapA1::SetHit(Int_t iz, Int_t ix, Int_t idigit)
130{
131 // set the digit index at a certain position in array
132 fHitMap[CheckedIndex(iz, ix)]=idigit+1;
133}
134
135void AliITSMapA1::DeleteHit(Int_t iz, Int_t ix)
136{
137 // delete an entry in array
138 fHitMap[CheckedIndex(iz, ix)]=0;
139}
140
141void AliITSMapA1::FlagHit(Int_t iz, Int_t ix)
142{
143 // flag an entry in array
144 fHitMap[CheckedIndex(iz, ix)]=
145 -TMath::Abs(fHitMap[CheckedIndex(iz, ix)]);
146}
147
148Int_t AliITSMapA1::GetHitIndex(Int_t iz, Int_t ix)
149{
150 // return the digit index from a specific entry in array
151 return TMath::Abs(fHitMap[CheckedIndex(iz, ix)])-1;
152}
153
154TObject* AliITSMapA1::GetHit(Int_t iz, Int_t ix)
155{
156 // return the pointer to the digit
157 Int_t index=GetHitIndex(iz,ix);
158 // Force crash if index does not exist !
159 return (index <0) ? 0 : fObjects->UncheckedAt(GetHitIndex(iz,ix));
160}
161
162
163Flag_t AliITSMapA1::TestHit(Int_t iz, Int_t ix)
164{
165 // check whether the digit has already been flagged
166 Int_t inf=fHitMap[CheckedIndex(iz, ix)];
167 if (inf < 0) {
168 return kUsed;
169 } else if (inf == 0) {
170 return kEmpty;
171 } else {
172 return kUnused;
173 }
174}
175//_______________________________________________________________________
176void AliITSMapA1::Streamer(TBuffer &R__b)
177{
178 // Stream an object of class AliITSMapA1.
179
180 if (R__b.IsReading()) {
181 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
182 AliITSMap::Streamer(R__b);
183 R__b >> fSegmentation;
184 R__b >> fNpx;
185 R__b >> fNpz;
186 R__b >> fObjects;
187 R__b >> fNobjects;
188 R__b >> fMaxIndex;
189 R__b.ReadArray(fHitMap);
190 } else {
191 R__b.WriteVersion(AliITSMapA1::IsA());
192 AliITSMap::Streamer(R__b);
193 R__b << fSegmentation;
194 R__b << fNpx;
195 R__b << fNpz;
196 R__b << fObjects;
197 R__b << fNobjects;
198 R__b << fMaxIndex;
199 R__b.WriteArray(fHitMap,fMaxIndex);
200 }
201}
202
203//========================================================================
204ClassImp(AliITSMapA2)
205
206 AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg)
207{
208 //constructor
209 fSegmentation = seg;
210 fNpz=fSegmentation->Npz();
211 fNpx=fSegmentation->Npx();
212 fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector
213
214 fHitMap = new Double_t[fMaxIndex];
215 fMapThreshold=0.;
216 ClearMap();
217}
218
219//--------------------------------------
220AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg, TObjArray *hist, Double_t thresh)
221{
222 //constructor
223 fSegmentation = seg;
224 fNpz=fSegmentation->Npz();
225 fNpx=fSegmentation->Npx();
226 fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector
227
228 fHitMap = new Double_t[fMaxIndex];
229 fObjects = hist;
230 if (fObjects) fNobjects = fObjects->GetEntriesFast();
231 fMapThreshold = thresh;
232 ClearMap();
233}
234//--------------------------------------
235
236
237AliITSMapA2::~AliITSMapA2()
238{
239 //destructor
240 if (fHitMap) delete[] fHitMap;
241}
242//--------------------------------------
243
244//__________________________________________________________________________
245AliITSMapA2::AliITSMapA2(const AliITSMapA2 &source){
246 // Copy Constructor
247 if(&source == this) return;
248 this->fMapThreshold = source.fMapThreshold;
249 this->fHitMap = source.fHitMap;
250 return;
251}
252
253//_________________________________________________________________________
254AliITSMapA2&
255 AliITSMapA2::operator=(const AliITSMapA2 &source) {
256 // Assignment operator
257 if(&source == this) return *this;
258 this->fMapThreshold = source.fMapThreshold;
259 this->fHitMap = source.fHitMap;
260 return *this;
261}
262
263void AliITSMapA2::ClearMap()
264{
265 //clear array
266 memset(fHitMap,0,sizeof(Double_t)*fMaxIndex);
267}
268
269//--------------------------------------
270void AliITSMapA2::FillMap()
271{
272
273 // fills signal map from digits - apply a threshold for signal
274
275 if (!fObjects) return;
276
277 Int_t ndigits = fObjects->GetEntriesFast();
278 printf("MapA2: ndigits fNobjects %d %d \n",ndigits,fNobjects);
279 if (!ndigits) return;
280
281 AliITSdigit *dig;
282 Int_t ndig;
283 for(ndig=0; ndig<ndigits; ndig++) {
284 dig = (AliITSdigit*)fObjects->UncheckedAt(ndig);
285 Double_t signal = (Double_t)(dig->fSignal);
286 if (signal >= fMapThreshold) SetHit(dig->fCoord1,dig->fCoord2,signal);
287 }
288}
289
290//--------------------------------------
291void AliITSMapA2::SetHit(Int_t iz, Int_t ix, Double_t signal)
292{
293 // set signal at a certain position in array
294 fHitMap[CheckedIndex(iz, ix)]=signal;
295
296}
297
298//--------------------------------------
299void AliITSMapA2::DeleteHit(Int_t iz, Int_t ix)
300{
301 //set the entry value to zero
302 fHitMap[CheckedIndex(iz, ix)]=0;
303}
304
305//--------------------------------------
306void AliITSMapA2::FlagHit(Int_t iz, Int_t ix)
307{
308 //flag an entry
309 fHitMap[CheckedIndex(iz, ix)]=
310 -1000.*TMath::Abs((Int_t)(fHitMap[CheckedIndex(iz, ix)])+1.);
311
312}
313
314//--------------------------------------
315Int_t AliITSMapA2::GetHitIndex(Int_t iz, Int_t ix)
316{
317 //return the index of an entry in array
318 return CheckedIndex(iz, ix);
319}
320
321//--------------------------------------
322TObject* AliITSMapA2::GetHit(Int_t i, Int_t dummy)
323{
324
325 //return a pointer to the 1D histogram
326 if (fObjects) {
327
328 return fObjects->UncheckedAt(i);
329
330 } else return NULL;
331
332}
333
334//--------------------------------------
335Double_t AliITSMapA2::GetSignal(Int_t iz, Int_t ix)
336{
337 //get signal in a cell
338 Int_t index=GetHitIndex(iz,ix);
339 return (index <0) ? 0. : fHitMap[CheckedIndex(iz, ix)];
340}
341
342//--------------------------------------
343Double_t AliITSMapA2::GetSignal(Int_t index)
344{
345 //get signal in a cell
346 if (index<fMaxIndex) return (index <0) ? 0. : fHitMap[index];
347 else return 0.;
348}
349//--------------------------------------
350Flag_t AliITSMapA2::TestHit(Int_t iz, Int_t ix)
351{
352 // check if the entry has already been flagged
353 Int_t inf=(Int_t)fHitMap[CheckedIndex(iz, ix)];
354
355 if (inf <= -1000) {
356 return kUsed;
357 } else if (inf == 0) {
358 return kEmpty;
359 } else {
360 return kUnused;
361 }
362}
363
364//--------------------------------------
365void AliITSMapA2::FillMapFromHist()
366{
367
368 // fills map from 1D histograms
369
370 if (!fObjects) return;
371
372 // an example
373 Int_t i,j;
374 for(i=0; i<fNobjects; i++) {
375 TH1F *hist =(TH1F *)fObjects->UncheckedAt(i);
376 Int_t nsamples = hist->GetNbinsX();
377 for(j=0; j<nsamples; j++) {
378 Double_t signal = (Double_t)(hist->GetBinContent(j+1));
379 if (signal >= fMapThreshold) SetHit(i,j,signal);
380 }
381 }
382
383}
384//--------------------------------------
385void AliITSMapA2::FillHist()
386{
387
388 // fill 1D histograms from map
389 if (!fObjects) return;
390
391 // an example
392 Int_t i,j;
393 for(i=0; i<fNobjects; i++) {
394 TH1F *hist =(TH1F *)fObjects->UncheckedAt(i);
395 for(j=0; j<fNpx; j++) {
396 Double_t signal=GetSignal(i,j);
397 if (signal >= fMapThreshold) hist->Fill((Float_t)j,signal);
398 }
399 }
400
401}
402//--------------------------------------
403void AliITSMapA2::ResetHist()
404{
405 //
406 // Reset histograms
407 //
408
409 if (!fObjects) return;
410
411 Int_t i;
412 for(i=0; i<fNobjects; i++) {
413 if ((*fObjects)[i]) ((TH1F*)(*fObjects)[i])->Reset();
414 }
415
416}
417//______________________________________________________________________________
418void AliITSMapA2::Streamer(TBuffer &R__b)
419{
420 // Stream an object of class AliITSMapA2.
421
422 if (R__b.IsReading()) {
423 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
424 AliITSMapA1::Streamer(R__b);
425 R__b.ReadArray(fHitMap);
426 R__b >> fMapThreshold;
427 } else {
428 R__b.WriteVersion(AliITSMapA2::IsA());
429 AliITSMapA1::Streamer(R__b);
430 R__b.WriteArray(fHitMap, fMaxIndex); // fMaxIndex is from AliITSMapA1.
431 R__b << fMapThreshold;
432 }
433}