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