]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSMapA1.cxx
stdlib.h included (HP,Sun)
[u/mrichter/AliRoot.git] / ITS / AliITSMapA1.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 #include "AliITSMapA1.h"
18 #include "AliITSsegmentation.h"
19 #include "AliITSresponse.h"
20 #include "AliITSdigit.h"
21
22 #include <TObjArray.h>
23 #include <TMath.h>
24
25
26 ClassImp(AliITSMapA1)
27
28 AliITSMapA1::AliITSMapA1()
29 {
30   // default constructor
31   fSegmentation = 0;
32   fNpz=0;
33   fNpx=0;
34   fMaxIndex=0;         
35   
36   fHitMap = 0;
37   fObjects = 0;
38   fNobjects = 0;
39   fMapThreshold=0;
40 }
41
42 AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg)
43 {
44   //constructor
45   fSegmentation = seg;
46   fNpz=fSegmentation->Npz();
47   fNpx=fSegmentation->Npx();
48   fMaxIndex=fNpz*fNpx+fNpx;             // 2 halves of detector
49   
50   fHitMap = new Int_t[fMaxIndex];
51   fObjects = 0;
52   fNobjects = 0;
53   fMapThreshold=0;
54   ClearMap();
55 }
56
57 AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg, TObjArray *obj)
58 {
59   //constructor
60   fNobjects = 0;
61   fSegmentation = seg;
62   fNpz=fSegmentation->Npz();
63   fNpx=fSegmentation->Npx();
64   fMaxIndex=fNpz*fNpx+fNpx;             // 2 halves of detector
65   
66   fHitMap = new Int_t[fMaxIndex];
67   fObjects =  obj;
68   if (fObjects) fNobjects = fObjects->GetEntriesFast();
69   fMapThreshold=0;
70   ClearMap();
71 }
72
73 AliITSMapA1::AliITSMapA1(AliITSsegmentation *seg, TObjArray *obj, Int_t thr)
74 {
75   //constructor
76   fNobjects = 0;
77   fSegmentation = seg;
78   fNpz=fSegmentation->Npz();
79   fNpx=fSegmentation->Npx();
80   fMaxIndex=fNpz*fNpx+fNpx;             // 2 halves of detector
81   
82   fHitMap = new Int_t[fMaxIndex];
83   fObjects =  obj;
84   if (fObjects) fNobjects = fObjects->GetEntriesFast();
85   fMapThreshold=thr;
86   ClearMap();
87 }
88
89
90 AliITSMapA1::~AliITSMapA1()
91 {
92   //destructor
93   if (fHitMap) delete[] fHitMap;
94 }
95
96 //__________________________________________________________________________
97 AliITSMapA1::AliITSMapA1(const AliITSMapA1 &source){
98   //     Copy Constructor 
99   if(&source == this) return;
100   this->fNpx = source.fNpx;
101   this->fNpz = source.fNpz;
102   this->fObjects = source.fObjects;
103   this->fNobjects = source.fNobjects;
104   this->fMaxIndex = source.fMaxIndex;
105   this->fHitMap = source.fHitMap;
106   this->fMapThreshold = source.fMapThreshold;
107   return;
108 }
109
110 //_________________________________________________________________________
111 AliITSMapA1& 
112   AliITSMapA1::operator=(const AliITSMapA1 &source) {
113   //    Assignment operator
114   if(&source == this) return *this;
115   this->fNpx = source.fNpx;
116   this->fNpz = source.fNpz;
117   this->fObjects = source.fObjects;
118   this->fNobjects = source.fNobjects;
119   this->fMaxIndex = source.fMaxIndex;
120   this->fHitMap = source.fHitMap;
121   this->fMapThreshold = source.fMapThreshold;
122   return *this;
123 }
124
125 void AliITSMapA1::ClearMap()
126 {
127   //clear array
128   memset(fHitMap,0,sizeof(int)*fMaxIndex);
129 }
130
131 void AliITSMapA1::SetArray(TObjArray *obj)
132 {
133   // set array of objects
134   fObjects =  obj;
135   if (fObjects) fNobjects = fObjects->GetEntriesFast();
136 }
137
138
139 Int_t AliITSMapA1::CheckedIndex(Int_t iz, Int_t ix)
140 {
141   //check boundaries and return an index in array
142   Int_t index=fNpx*iz+ix;
143
144   //if (index > fMaxIndex) {
145   if (index > fMaxIndex || index < 0) {
146     printf("\n \n \n Try to read/write outside array !!!! \n \n %d %d %d %d %d %d \n",iz,ix, fMaxIndex, index, fNpz, fNpx);
147     // force crash
148     return  -1;
149   } else {
150     return index;
151   }
152 }
153
154
155 void  AliITSMapA1::FillMap()
156 {
157   // fill array with digits indices
158
159   //printf("fMapThreshold %d\n",fMapThreshold);
160   Int_t ndigits = fObjects->GetEntriesFast();
161   if (!ndigits) return;
162   
163   AliITSdigit *dig;
164   for (Int_t ndig=0; ndig<ndigits; ndig++) {
165     dig = (AliITSdigit*)fObjects->UncheckedAt(ndig);
166     if(dig->fSignal > fMapThreshold) {
167       SetHit(dig->fCoord1,dig->fCoord2,ndig);
168     }
169   }
170   
171 }
172
173 void  AliITSMapA1::SetHit(Int_t iz, Int_t ix, Int_t idigit)
174 {
175   // set the digit index at a certain position in array
176   fHitMap[CheckedIndex(iz, ix)]=idigit+1;
177 }
178
179 void AliITSMapA1::DeleteHit(Int_t iz, Int_t ix)
180 {
181   // delete an entry in array
182   fHitMap[CheckedIndex(iz, ix)]=0;
183 }
184
185 void AliITSMapA1::FlagHit(Int_t iz, Int_t ix)
186 {
187   // flag an entry in array
188   fHitMap[CheckedIndex(iz, ix)]=
189       -TMath::Abs(fHitMap[CheckedIndex(iz, ix)]);
190
191 }
192
193 Int_t AliITSMapA1::GetHitIndex(Int_t iz, Int_t ix)
194 {
195   // return the digit index from a specific entry in array
196   return TMath::Abs(fHitMap[CheckedIndex(iz, ix)])-1;
197 }
198
199 TObject* AliITSMapA1::GetHit(Int_t iz, Int_t ix)
200 {
201   // return the pointer to the digit 
202   Int_t index=GetHitIndex(iz,ix);
203   // Force crash if index does not exist ! 
204   return (index <0) ? 0 : fObjects->UncheckedAt(GetHitIndex(iz,ix));
205 }
206
207 Double_t AliITSMapA1::GetSignal(Int_t iz, Int_t ix)
208 {
209   // get a pad signal 
210   Double_t signal;
211   AliITSdigit *dig = (AliITSdigit*)GetHit(iz,ix);
212   if(dig) signal=(Double_t)dig->fSignal;
213   else signal=0.;
214   return signal;
215
216 }
217
218 FlagType AliITSMapA1::TestHit(Int_t iz, Int_t ix)
219 {
220   // check whether the digit has already been flagged
221
222   if (CheckedIndex(iz, ix) < 0) return kEmpty;
223   Int_t inf=fHitMap[CheckedIndex(iz, ix)]; 
224   if (inf < 0) {
225       return kUsed;
226   } else if (inf == 0) {
227       return kEmpty;
228   } else {
229       return kUnused;
230   }
231 }