]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSMapA2.cxx
New&delete used for array with variable size
[u/mrichter/AliRoot.git] / ITS / AliITSMapA2.cxx
CommitLineData
e8189707 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 <TObjArray.h>
18#include <TMath.h>
19
20#include "AliITSMapA2.h"
21#include "AliITSsegmentation.h"
22#include "AliITSresponse.h"
23#include "AliITSdigit.h"
24
25
26ClassImp(AliITSMapA2)
27
94d90134 28AliITSMapA2::AliITSMapA2()
29{
30 // default constructor
31 fSegmentation = 0;
32 fNpz=0;
33 fNpx=0;
34 fMaxIndex=0;
35
f50d33af 36 fHitMapD = 0;
94d90134 37 fObjects = 0;
38 fNobjects = 0;
f50d33af 39 fMapThresholdD=0.;
94d90134 40}
41
e8189707 42 AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg)
43{
44 //constructor
45 fScaleSizeZ=1;
46 fScaleSizeX=1;
47 fSegmentation = seg;
48 fNpz=fSegmentation->Npz();
49 fNpx=fSegmentation->Npx();
50 fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector
51
f50d33af 52 fHitMapD = new Double_t[fMaxIndex];
53 fMapThresholdD=0.;
94d90134 54 fObjects = 0;
55 fNobjects = 0;
e8189707 56 ClearMap();
57}
58//--------------------------------------
59 AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg, Int_t scalesizeX, Int_t scalesizeZ)
60{
61 //constructor
62 fSegmentation = seg;
63 fScaleSizeX=scalesizeX;
64 fScaleSizeZ=scalesizeZ;
65 fNpz=fScaleSizeZ*fSegmentation->Npz();
66 fNpx=fScaleSizeX*fSegmentation->Npx();
67 fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector
68
f50d33af 69 fHitMapD = new Double_t[fMaxIndex];
70 fMapThresholdD=0.;
94d90134 71 fObjects = 0;
72 fNobjects = 0;
e8189707 73 ClearMap();
74}
75
76//--------------------------------------
77AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg, TObjArray *obj, Double_t thresh)
78{
79 //constructor
94d90134 80 fNobjects = 0;
e8189707 81 fScaleSizeZ=1;
82 fScaleSizeX=1;
83 fSegmentation = seg;
84 fNpz=fSegmentation->Npz();
85 fNpx=fSegmentation->Npx();
86 fMaxIndex=fNpz*fNpx+fNpx; // 2 halves of detector
87
f50d33af 88 fHitMapD = new Double_t[fMaxIndex];
e8189707 89 fObjects = obj;
90 if (fObjects) fNobjects = fObjects->GetEntriesFast();
f50d33af 91 fMapThresholdD = thresh;
e8189707 92 ClearMap();
93}
94//--------------------------------------
95
96
97AliITSMapA2::~AliITSMapA2()
98{
99 //destructor
f50d33af 100 if (fHitMapD) delete[] fHitMapD;
e8189707 101}
102//--------------------------------------
103
104//__________________________________________________________________________
105AliITSMapA2::AliITSMapA2(const AliITSMapA2 &source){
106 // Copy Constructor
107 if(&source == this) return;
f50d33af 108 this->fMapThresholdD = source.fMapThresholdD;
e8189707 109 this->fScaleSizeX = source.fScaleSizeX;
110 this->fScaleSizeZ = source.fScaleSizeZ;
f50d33af 111 this->fHitMapD = source.fHitMapD;
e8189707 112 return;
113}
114
115//_________________________________________________________________________
116AliITSMapA2&
117 AliITSMapA2::operator=(const AliITSMapA2 &source) {
118 // Assignment operator
119 if(&source == this) return *this;
f50d33af 120 this->fMapThresholdD = source.fMapThresholdD;
e8189707 121 this->fScaleSizeX = source.fScaleSizeX;
122 this->fScaleSizeZ = source.fScaleSizeZ;
f50d33af 123 this->fHitMapD = source.fHitMapD;
e8189707 124 return *this;
125}
126
127//_________________________________________________________________________
128void AliITSMapA2::ClearMap()
129{
130 //clear array
f50d33af 131 memset(fHitMapD,0,sizeof(Double_t)*fMaxIndex);
e8189707 132}
133
134//--------------------------------------
135void AliITSMapA2::FillMap()
136{
137
138 // fills signal map from digits - apply a threshold for signal
94d90134 139
e8189707 140 if (!fObjects) return;
141
142 Int_t ndigits = fObjects->GetEntriesFast();
143 if (!ndigits) return;
144
145 AliITSdigit *dig;
146 for (Int_t ndig=0; ndig<ndigits; ndig++) {
147 dig = (AliITSdigit*)fObjects->UncheckedAt(ndig);
148 Double_t signal = (Double_t)(dig->fSignal);
f50d33af 149 if (signal > fMapThresholdD) SetHit(dig->fCoord1,dig->fCoord2,signal);
e8189707 150 }
151}
152
153//--------------------------------------
154void AliITSMapA2::SetHit(Int_t iz, Int_t ix, Double_t signal)
155{
156 // set signal at a certain position in array
f50d33af 157 fHitMapD[CheckedIndex(iz, ix)]=signal;
e8189707 158
159}
160
161//--------------------------------------
162void AliITSMapA2::DeleteHit(Int_t iz, Int_t ix)
163{
164 //set the entry value to zero
f50d33af 165 fHitMapD[CheckedIndex(iz, ix)]=0;
e8189707 166}
167
168//--------------------------------------
169void AliITSMapA2::FlagHit(Int_t iz, Int_t ix)
170{
171 //flag an entry
f50d33af 172 fHitMapD[CheckedIndex(iz, ix)]=
173 -1000.*TMath::Abs((Int_t)(fHitMapD[CheckedIndex(iz, ix)])+1.);
e8189707 174
175}
176
177//--------------------------------------
178Int_t AliITSMapA2::GetHitIndex(Int_t iz, Int_t ix)
179{
180 //return the index of an entry in array
181 return CheckedIndex(iz, ix);
182}
183
184//--------------------------------------
185TObject* AliITSMapA2::GetHit(Int_t i, Int_t dummy)
186{
187
188 //return a pointer to the 1D histogram
189 if (fObjects) {
190
191 return fObjects->UncheckedAt(i);
192
193 } else return NULL;
194
195}
196
197//--------------------------------------
198Double_t AliITSMapA2::GetSignal(Int_t iz, Int_t ix)
199{
200 //get signal in a cell
201 Int_t index=GetHitIndex(iz,ix);
f50d33af 202 return (index <0) ? 0. : fHitMapD[CheckedIndex(iz, ix)];
e8189707 203}
204
205//--------------------------------------
206Double_t AliITSMapA2::GetSignal(Int_t index)
207{
208 //get signal in a cell
f50d33af 209 if (index<fMaxIndex) return (index <0) ? 0. : fHitMapD[index];
e8189707 210 else return 0.;
211}
212//--------------------------------------
213FlagType AliITSMapA2::TestHit(Int_t iz, Int_t ix)
214{
215 // check if the entry has already been flagged
94d90134 216
217 if (CheckedIndex(iz, ix) < 0) return kEmpty;
f50d33af 218 Int_t inf=(Int_t)fHitMapD[CheckedIndex(iz, ix)];
e8189707 219
220 if (inf <= -1000) {
221 return kUsed;
222 } else if (inf == 0) {
223 return kEmpty;
224 } else {
225 return kUnused;
226 }
227}
228
229//--------------------------------------
230void AliITSMapA2::FillMapFromHist()
231{
232
233 // fills map from 1D histograms
234
235 if (!fObjects) return;
236
237 // an example
238 for( Int_t i=0; i<fNobjects; i++) {
239 TH1F *hist =(TH1F *)fObjects->UncheckedAt(i);
240 Int_t nsamples = hist->GetNbinsX();
241 for( Int_t j=0; j<nsamples; j++) {
242 Double_t signal = (Double_t)(hist->GetBinContent(j+1));
f50d33af 243 if (signal > fMapThresholdD) SetHit(i,j,signal);
e8189707 244 }
245 }
246
247}
248//--------------------------------------
249void AliITSMapA2::FillHist()
250{
251
252 // fill 1D histograms from map
253 if (!fObjects || fScaleSizeX != 1) return;
254
255 // an example
256 for( Int_t i=0; i<fNobjects; i++) {
257 TH1F *hist =(TH1F *)fObjects->UncheckedAt(i);
258 for( Int_t j=0; j<fNpx; j++) {
259 Double_t signal=GetSignal(i,j);
f50d33af 260 if (signal > fMapThresholdD) hist->Fill((Float_t)j,signal);
e8189707 261 }
262 }
263
264}
265//--------------------------------------
266void AliITSMapA2::ResetHist()
267{
268 //
269 // Reset histograms
270 //
271
272 if (!fObjects) return;
273
274 for( Int_t i=0; i<fNobjects; i++) {
275 if ((*fObjects)[i]) ((TH1F*)(*fObjects)[i])->Reset();
276 }
277
278}
279