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