Adaption to new fluka common blocks (E. Futo)
[u/mrichter/AliRoot.git] / CONTAINERS / AliH2F.cxx
CommitLineData
cc80f89e 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
5270561d 16/* $Id$ */
cc80f89e 17
18//----------------------------------------------------------------------------
19// Author: Marian Ivanov
20//
21// Implementation of class AliH2F
22//
23//-----------------------------------------------------------------------------
24
25#include "AliH2F.h"
26#include "TClonesArray.h"
27#include "AliTPC.h"
28#include "TRandom.h"
cc80f89e 29
30
31ClassImp(AliH2F)
32//***********************************************************************
33//***********************************************************************
34//***********************************************************************
35//***********************************************************************
36AliH2F::AliH2F():TH2F()
37{
73042f01 38 //
39
cc80f89e 40}
41AliH2F::AliH2F(const Text_t *name,const Text_t *title,
42 Int_t nbinsx,Axis_t xlow,Axis_t xup
43 ,Int_t nbinsy,Axis_t ylow,Axis_t yup):
44 TH2F(name,title,nbinsx,xlow,xup
45 ,nbinsy,ylow,yup)
46{
73042f01 47 //
48
cc80f89e 49}
50
51AliH2F::~AliH2F()
52{
73042f01 53 //
cc80f89e 54}
55
73042f01 56AliH2F::AliH2F(const AliH2F &his)
cc80f89e 57{
73042f01 58 //
59
cc80f89e 60}
61
73042f01 62AliH2F & AliH2F::operator = (const AliH2F & his)
cc80f89e 63{
73042f01 64 //
65 return *this;
cc80f89e 66}
67
68TClonesArray * AliH2F::FindPeaks(Float_t threshold, Float_t noise)
69{
1c53abe2 70
71 //
72 // not implemented
73 //
74 return 0;
cc80f89e 75}
76
77void AliH2F::ClearSpectrum()
78{
73042f01 79 //clera histogram
cc80f89e 80 Int_t dimx = fXaxis.GetNbins();
81 Int_t dimy = fYaxis.GetNbins();
82 for (Int_t i = 0 ;i<dimx;i++)
83 for (Int_t j = 0 ;j<dimy;j++)
84 {
85 SetCellContent(i,j,0);
86 SetCellError(i,j,0);
87 }
88}
89
90
91void AliH2F::AddNoise(Float_t sn)
92{
73042f01 93 // add gauss noise with sigma sn
cc80f89e 94 Int_t dimx = fXaxis.GetNbins();
95 Int_t dimy = fYaxis.GetNbins();
96 for (Int_t i = 0 ;i<dimx;i++)
97 for (Int_t j = 0 ;j<dimy;j++)
98 {
99 Float_t noise = gRandom->Gaus(0,sn);
100 Float_t oldv =GetCellContent(i,j);
101 Float_t olds =GetCellError(i,j);
102 if (noise >0)
103 {
104 SetCellContent(i,j,noise+oldv);
105 SetCellError(i,j,TMath::Sqrt((noise*noise+olds*olds)));
106 }
107 }
108}
109void AliH2F::AddGauss(Float_t x, Float_t y,
110 Float_t sx, Float_t sy, Float_t max)
73042f01 111{
cc80f89e 112 //transform to histogram coordinata
113 Int_t dimx = fXaxis.GetNbins();
114 Int_t dimy = fYaxis.GetNbins();
115 Float_t dx =(GetXaxis()->GetXmax()-GetXaxis()->GetXmin())/Float_t(dimx);
116 Float_t dy =(GetYaxis()->GetXmax()-GetYaxis()->GetXmin())/Float_t(dimy);
117 // x=(x-GetXaxis()->GetXmin())/dx;
118 //y=(y-GetYaxis()->GetXmin())/dy;
119 sx/=dx;
120 sy/=dy;
121
122
123 for (Int_t i = 0 ;i<dimx;i++)
124 for (Int_t j = 0 ;j<dimy;j++)
125 {
126 Float_t x2 =GetXaxis()->GetBinCenter(i+1);
127 Float_t y2 =GetYaxis()->GetBinCenter(j+1);
128 Float_t dx2 = (x2-x)*(x2-x);
129 Float_t dy2 = (y2-y)*(y2-y);
130 Float_t amp =max*exp(-(dx2/(2*sx*sx)+dy2/(2*sy*sy)));
131 //Float_t oldv =GetCellContent(i+1,j+1);
132 // SetCellContent(i+1,j+1,amp+oldv);
133 Fill(x2,y2,amp);
134 }
135}
136
137void AliH2F::ClearUnderTh(Int_t threshold)
138{
73042f01 139 //clear histogram for bin under threshold
cc80f89e 140 Int_t dimx = fXaxis.GetNbins();
141 Int_t dimy = fYaxis.GetNbins();
142 for (Int_t i = 0 ;i<=dimx;i++)
143 for (Int_t j = 0 ;j<=dimy;j++)
144 {
145 Float_t oldv =GetCellContent(i,j);
146 if (oldv <threshold)
147 SetCellContent(i,j,0);
148 }
149}
150
151void AliH2F::Round()
152{
73042f01 153 //round float to integer
cc80f89e 154 Int_t dimx = fXaxis.GetNbins();
155 Int_t dimy = fYaxis.GetNbins();
156 for (Int_t i = 0 ;i<=dimx;i++)
157 for (Int_t j = 0 ;j<=dimy;j++)
158 {
159 Float_t oldv =GetCellContent(i,j);
160 oldv=(Int_t)oldv;
161 SetCellContent(i,j,oldv);
162 }
163}
164
165
166
167AliH2F *AliH2F::GetSubrange2d(Float_t xmin, Float_t xmax,
168 Float_t ymin, Float_t ymax)
169{
170 //this function return pointer to the new created
171 //histogram which is subhistogram of the
172 //calculate number
173 //subhistogram range must be inside histogram
174
175 if (xmax<=xmin) {
176 xmin=fXaxis.GetXmin();
177 xmax=fXaxis.GetXmax();
178 }
179 if (ymax<=ymin) {
180 ymin=fYaxis.GetXmin();
181 ymax=fYaxis.GetXmax();
182 }
183
184 Int_t nx = Int_t((xmax-xmin)/(fXaxis.GetXmax()-fXaxis.GetXmin()) *
185 Float_t(fXaxis.GetNbins()));
186 Int_t ny = Int_t((ymax-ymin)/(fYaxis.GetXmax()-fYaxis.GetXmin()) *
187 Float_t(fYaxis.GetNbins()));
188 TString t1 = fName ;
189 TString t2 = fTitle ;
190 t1+="_subrange";
191 t2+="_subrange";
73042f01 192 const Text_t *ktt1 = t1;
193 const Text_t *ktt2 = t2;
cc80f89e 194
73042f01 195 AliH2F * sub = new AliH2F(ktt1,ktt2,nx,xmin,xmax,ny,ymin,ymax);
cc80f89e 196
197 Int_t i1 = Int_t( Float_t(fXaxis.GetNbins())*(xmin-fXaxis.GetXmin())/
198 (fXaxis.GetXmax()-fXaxis.GetXmin()) ) ;
199 Int_t i2 = Int_t( Float_t(fYaxis.GetNbins())*(ymin-fYaxis.GetXmin())/
200 (fYaxis.GetXmax()-fYaxis.GetXmin()) ) ;
201 for (Int_t i=0;i<nx;i++)
202 for (Int_t j=0;j<ny;j++)
203 {
204 Int_t index1 = GetBin(i1+i,i2+j);
205 // Int_t index2 = sub->GetBin(i,j);
206 Float_t val = GetBinContent(index1);
207 // sub->SetBinContent(index2,val);
208 // Float_t err = GetBinError(index1);
209 //sub->SetBinError(index2,GetBinError(index1));
210 sub->SetCellContent(i,j,val);
211 }
212 return sub;
213}
214
215TH1F *AliH2F::GetAmplitudes(Float_t zmin, Float_t zmax, Float_t th, Float_t xmin, Float_t xmax,
216 Float_t ymin, Float_t ymax)
217{
218 //this function return pointer to the new created
219 //histogram which is subhistogram of the
220 //calculate number
221 //subhistogram range must be inside histogram
222
223 if (xmax<=xmin) {
224 xmin=fXaxis.GetXmin();
225 xmax=fXaxis.GetXmax();
226 }
227 if (ymax<=ymin) {
228 ymin=fYaxis.GetXmin();
229 ymax=fYaxis.GetXmax();
230 }
231 Int_t nx = Int_t((xmax-xmin)/(fXaxis.GetXmax()-fXaxis.GetXmin()) *
232 Float_t(fXaxis.GetNbins()));
233 Int_t ny = Int_t((ymax-ymin)/(fYaxis.GetXmax()-fYaxis.GetXmin()) *
234 Float_t(fYaxis.GetNbins()));
235 TString t1 = fName ;
236 TString t2 = fTitle ;
237 t1+="_amplitudes";
238 t2+="_amplitudes";
73042f01 239 const Text_t *ktt1 = t1;
240 const Text_t *ktt2 = t2;
cc80f89e 241
73042f01 242 TH1F * h = new TH1F(ktt1,ktt2,100,zmin,zmax);
cc80f89e 243
244 Int_t i1 = Int_t( Float_t(fXaxis.GetNbins())*(xmin-fXaxis.GetXmin())/
245 (fXaxis.GetXmax()-fXaxis.GetXmin()) ) ;
246 Int_t i2 = Int_t( Float_t(fYaxis.GetNbins())*(ymin-fYaxis.GetXmin())/
247 (fYaxis.GetXmax()-fYaxis.GetXmin()) ) ;
248 for (Int_t i=0;i<nx;i++)
249 for (Int_t j=0;j<ny;j++)
250 {
251 Int_t index1 = GetBin(i1+i,i2+j);
252 Float_t val = GetBinContent(index1);
253 if (val>th) h->Fill(val);
254 }
255 return h;
256}
257
258Float_t AliH2F::GetOccupancy(Float_t th , Float_t xmin, Float_t xmax,
259 Float_t ymin, Float_t ymax)
260{
261 //this function return pointer to the new created
262 //histogram which is subhistogram of the
263 //calculate number
264 //subhistogram range must be inside histogram
265
266 if (xmax<=xmin) {
267 xmin=fXaxis.GetXmin();
268 xmax=fXaxis.GetXmax();
269 }
270 if (ymax<=ymin) {
271 ymin=fYaxis.GetXmin();
272 ymax=fYaxis.GetXmax();
273 }
274 Int_t nx = Int_t((xmax-xmin)/(fXaxis.GetXmax()-fXaxis.GetXmin()) *
275 Float_t(fXaxis.GetNbins()));
276 Int_t ny = Int_t((ymax-ymin)/(fYaxis.GetXmax()-fYaxis.GetXmin()) *
277 Float_t(fYaxis.GetNbins()));
278
279 Int_t over =0;
280 Int_t i1 = Int_t( Float_t(fXaxis.GetNbins())*(xmin-fXaxis.GetXmin())/
281 (fXaxis.GetXmax()-fXaxis.GetXmin()) ) ;
282 Int_t i2 = Int_t( Float_t(fYaxis.GetNbins())*(ymin-fYaxis.GetXmin())/
283 (fYaxis.GetXmax()-fYaxis.GetXmin()) ) ;
284 for (Int_t i=0;i<nx;i++)
285 for (Int_t j=0;j<ny;j++)
286 {
287 Int_t index1 = GetBin(i1+i,i2+j);
288 Float_t val = GetBinContent(index1);
289 if (val>th) over++;
290 }
291 Int_t all = nx*ny;
292 if (all>0) return Float_t(over)/Float_t(all);
293 else
294 return 0;
295}