]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSMapA2.cxx
added tcsh UI
[u/mrichter/AliRoot.git] / ITS / AliITSMapA2.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 #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
26 ClassImp(AliITSMapA2)
27
28 AliITSMapA2::AliITSMapA2()
29 {
30   // default constructor
31   fSegmentation = 0;
32   fNpz=0;
33   fNpx=0;
34   fMaxIndex=0;         
35   
36   fHitMapD = 0;
37   fObjects = 0;
38   fNobjects = 0;
39   fMapThresholdD=0.;
40 }
41
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   
52   fHitMapD = new Double_t[fMaxIndex];
53   fMapThresholdD=0.;
54   fObjects = 0;
55   fNobjects = 0;
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   
69   fHitMapD = new Double_t[fMaxIndex];
70   fMapThresholdD=0.;
71   fObjects = 0;
72   fNobjects = 0;
73   ClearMap();
74 }
75
76 //--------------------------------------
77 AliITSMapA2::AliITSMapA2(AliITSsegmentation *seg, TObjArray *obj, Double_t thresh)
78 {
79   //constructor
80   fNobjects = 0;
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   
88   fHitMapD = new Double_t[fMaxIndex];
89   fObjects =  obj;
90   if (fObjects) fNobjects = fObjects->GetEntriesFast();
91   fMapThresholdD = thresh;
92   ClearMap();
93 }
94 //--------------------------------------
95
96
97 AliITSMapA2::~AliITSMapA2()
98 {
99   //destructor
100   if (fHitMapD) delete[] fHitMapD;
101 }
102 //--------------------------------------
103
104 //__________________________________________________________________________
105 AliITSMapA2::AliITSMapA2(const AliITSMapA2 &source){
106   //     Copy Constructor 
107   if(&source == this) return;
108   this->fMapThresholdD = source.fMapThresholdD;
109   this->fScaleSizeX = source.fScaleSizeX;
110   this->fScaleSizeZ = source.fScaleSizeZ;
111   this->fHitMapD = source.fHitMapD;
112   return;
113 }
114
115 //_________________________________________________________________________
116 AliITSMapA2& 
117   AliITSMapA2::operator=(const AliITSMapA2 &source) {
118   //    Assignment operator
119   if(&source == this) return *this;
120   this->fMapThresholdD = source.fMapThresholdD;
121   this->fScaleSizeX = source.fScaleSizeX;
122   this->fScaleSizeZ = source.fScaleSizeZ;
123   this->fHitMapD = source.fHitMapD;
124   return *this;
125 }
126
127 //_________________________________________________________________________
128 void AliITSMapA2::ClearMap()
129 {
130   //clear array
131   memset(fHitMapD,0,sizeof(Double_t)*fMaxIndex);
132 }
133
134 //--------------------------------------
135 void  AliITSMapA2::FillMap()
136 {
137   
138   // fills signal map from digits - apply a threshold for signal
139   
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);
149     if (signal > fMapThresholdD) SetHit(dig->fCoord1,dig->fCoord2,signal);
150   }
151 }
152
153 //--------------------------------------
154 void  AliITSMapA2::SetHit(Int_t iz, Int_t ix, Double_t signal)
155 {
156   // set signal at a certain position in array
157   fHitMapD[CheckedIndex(iz, ix)]=signal;
158   
159 }
160
161 //--------------------------------------
162 void AliITSMapA2::DeleteHit(Int_t iz, Int_t ix)
163 {
164   //set the entry value to zero
165   fHitMapD[CheckedIndex(iz, ix)]=0;
166 }
167
168 //--------------------------------------
169 void AliITSMapA2::FlagHit(Int_t iz, Int_t ix)
170 {
171   //flag an entry
172   fHitMapD[CheckedIndex(iz, ix)]=
173     -1000.*TMath::Abs((Int_t)(fHitMapD[CheckedIndex(iz, ix)])+1.);
174   
175 }
176
177 //--------------------------------------
178 Int_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 //--------------------------------------
185 TObject* 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 //--------------------------------------
198 Double_t AliITSMapA2::GetSignal(Int_t iz, Int_t ix)
199 {
200   //get signal in a cell 
201   Int_t index=GetHitIndex(iz,ix);
202   return (index <0) ? 0. : fHitMapD[CheckedIndex(iz, ix)];
203 }
204
205 //--------------------------------------
206 Double_t AliITSMapA2::GetSignal(Int_t index)
207 {
208   //get signal in a cell 
209   if (index<fMaxIndex) return (index <0) ? 0. : fHitMapD[index];
210   else return 0.;
211 }
212 //--------------------------------------
213 FlagType AliITSMapA2::TestHit(Int_t iz, Int_t ix)
214 {
215   // check if the entry has already been flagged
216
217     if (CheckedIndex(iz, ix) < 0) return kEmpty;
218     Int_t inf=(Int_t)fHitMapD[CheckedIndex(iz, ix)];
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 //--------------------------------------
230 void  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));
243       if (signal > fMapThresholdD) SetHit(i,j,signal);
244     }
245   }
246   
247 }
248 //--------------------------------------
249 void  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);
260       if (signal > fMapThresholdD) hist->Fill((Float_t)j,signal);
261     }
262   }
263   
264 }
265 //--------------------------------------
266 void  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