extended by cuts on min / max absolute and relative impact parameter
[u/mrichter/AliRoot.git] / CORRFW / AliCFEffGrid.cxx
CommitLineData
563113d0 1/* $Id$ */
1e9dad92 2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
563113d0 16//--------------------------------------------------------------------//
17// //
18// AliCFEffGrid Class //
19// Class to handle efficiency grids //
20// //
21// -- Author : S.Arcelli //
22// //
23// //
24// //
25//--------------------------------------------------------------------//
26//
27//
9f6be3a2 28#include "TMath.h"
29#include "AliLog.h"
563113d0 30#include "AliCFEffGrid.h"
9f6be3a2 31#include "TH1D.h"
32#include "TH2D.h"
33#include "TH3D.h"
563113d0 34
35//____________________________________________________________________
36ClassImp(AliCFEffGrid)
37
38//____________________________________________________________________
39AliCFEffGrid::AliCFEffGrid() :
25488e18 40 AliCFGridSparse(),
563113d0 41 fContainer(0x0),
42 fSelNum(-1),
43 fSelDen(-1)
44{
45 //
46 // default constructor
47 //
48}
49
50//____________________________________________________________________
1e9dad92 51AliCFEffGrid::AliCFEffGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn) :
25488e18 52 AliCFGridSparse(name,title,nVarIn,nBinIn,binLimitsIn),
563113d0 53 fContainer(0x0),
54 fSelNum(-1),
55 fSelDen(-1)
56{
57 //
58 // ctor
59 //
60 SumW2();
61}
62//____________________________________________________________________
63AliCFEffGrid::AliCFEffGrid(const Char_t* name, const Char_t* title, const AliCFContainer &c) :
25488e18 64 AliCFGridSparse(name,title,c.GetNVar(),c.GetNBins(),c.GetBinLimits()),
563113d0 65 fSelNum(-1),
66 fSelDen(-1)
67{
68 //
69 // main constructor
70 //
71 SumW2();
72 //assign the container;
73 fContainer=&c;
74}
75//____________________________________________________________________
25488e18 76AliCFEffGrid::AliCFEffGrid(const AliCFEffGrid& eff) : AliCFGridSparse(),
563113d0 77 fContainer(0x0),
78 fSelNum(-1),
79 fSelDen(-1)
80{
81 //
82 // copy constructor
83 //
84 ((AliCFEffGrid &)eff).Copy(*this);
85}
86
87//____________________________________________________________________
88AliCFEffGrid::~AliCFEffGrid()
89{
90 //
91 // destructor
92 //
93}
94
95//____________________________________________________________________
96AliCFEffGrid &AliCFEffGrid::operator=(const AliCFEffGrid &eff)
97{
98 //
99 // assigment operator
100 //
101 if (this != &eff)
102 ((AliCFEffGrid &) eff).Copy(*this);
103 return *this;
104}
105//____________________________________________________________________
106
107void AliCFEffGrid::CalculateEfficiency(Int_t istep1,Int_t istep2)
108{
109 //
110 // Calculate the efficiency matrix and its error between selection
111 // Steps istep1 and istep2
112 //
113
114 fSelNum=istep1;
115 fSelDen=istep2;
1e9dad92 116 AliCFVGrid *num=fContainer->GetGrid(fSelNum);
117 AliCFVGrid *den=fContainer->GetGrid(fSelDen);
563113d0 118 num->SumW2();
119 den->SumW2();
1e9dad92 120 this->SumW2();
563113d0 121 this->Divide(num,den,1.,1.,"B");
122
123 Int_t nEmptyBinsNum=0;
124 Int_t nEmptyBinsNumAndDen=0;
125 for(Int_t iel=0;iel<fNDim;iel++){
126 if(den->GetElement(iel)>0){
127 if(num->GetElement(iel)==0)nEmptyBinsNum++; //num==0,den!=0
1e9dad92 128 }
563113d0 129 else{
130 nEmptyBinsNumAndDen++;
131 }
132 }
133 // Some monitoring printout:
134 AliInfo(Form("Efficiency calculated for steps %i and %i: %i empty bins in the numerator && !denominator and %i empty bins in numerator && denominator were found.",fSelNum,fSelDen,nEmptyBinsNumAndDen,nEmptyBinsNum));
135 AliInfo(Form("The correction map contains %i empty bins ",nEmptyBinsNum+nEmptyBinsNumAndDen));
136}
137//_____________________________________________________________________
1e9dad92 138Double_t AliCFEffGrid::GetAverage() const
563113d0 139{
140 //
141 // Get the average efficiency
142 //
143
1e9dad92 144 Double_t val=0;
145 Double_t valnum=0;
146 Double_t valden=0;
563113d0 147 for(Int_t i=0;i<fNDim;i++){
148 valnum+=fContainer->GetGrid(fSelNum)->GetElement(i);
149 valden+=fContainer->GetGrid(fSelDen)->GetElement(i);
150 }
151 if(valden>0)val=valnum/valden;
152 AliInfo(Form(" The Average Efficiency = %f ",val));
153
154 return val;
155}
156//_____________________________________________________________________
1e9dad92 157Double_t AliCFEffGrid::GetAverage(Double_t *varMin, Double_t* varMax ) const
563113d0 158{
159 //
160 // Get ave efficiency in a range
161 //
162
163
1e9dad92 164 Double_t val=0;
563113d0 165 Int_t *indexMin = new Int_t[fNVar];
166 Int_t *indexMax = new Int_t[fNVar];
167 Int_t *index = new Int_t[fNVar];
168
169 //Find out the min and max bins
170
171 for(Int_t i=0;i<fNVar;i++){
1e9dad92 172 Double_t xmin=varMin[i]; // the min values
173 Double_t xmax=varMax[i]; // the max values
563113d0 174 Int_t nbins=fNVarBins[i]+1;
365c0ea4 175 Double_t *bins=new Double_t[nbins];
563113d0 176 for(Int_t ibin =0;ibin<nbins;ibin++){
177 bins[ibin] = fVarBinLimits[ibin+fOffset[i]];
178 }
179 indexMin[i] = TMath::BinarySearch(nbins,bins,xmin);
180 indexMax[i] = TMath::BinarySearch(nbins,bins,xmax);
181 if(xmax>=bins[nbins-1]){
182 indexMax[i]=indexMax[i]-1;
183 }
184 delete [] bins;
185 }
186
1e9dad92 187 Double_t valnum=0;
188 Double_t valden=0;
563113d0 189 for(Int_t i=0;i<fNDim;i++){
190 for (Int_t j=0;j<fNVar;j++)index[j]=GetBinIndex(j,i);
191 Bool_t isIn=kTRUE;
192 for (Int_t j=0;j<fNVar;j++){
193 if(!(index[j]>=indexMin[j] && index[j]<=indexMax[j]))isIn=kFALSE;
194 }
195 if(isIn){
196 valnum+=fContainer->GetGrid(fSelNum)->GetElement(i);
197 valden+=fContainer->GetGrid(fSelDen)->GetElement(i);
198 }
199 }
200 delete [] index;
201 delete [] indexMin;
202 delete [] indexMax;
203 if(valden>0)val=valnum/valden;
204 AliInfo(Form(" the Average Efficiency = %f ",val));
205 return val;
206}
207//____________________________________________________________________
208void AliCFEffGrid::Copy(TObject& eff) const
209{
210 //
211 // copy function
212 //
213 Copy(eff);
214 AliCFEffGrid& target = (AliCFEffGrid &) eff;
215
216 target.fSelNum=fSelNum;
217 target.fSelDen=fSelDen;
218 if(fContainer)
219 target.fContainer=fContainer;
220}
221//___________________________________________________________________
1e9dad92 222TH1D *AliCFEffGrid::Project(Int_t ivar) const
563113d0 223{
224 //
225 // Make a 1D projection along variable ivar
226 //
227
1e9dad92 228 TH1D *proj1D=0;
563113d0 229 Int_t nbins =fNVarBins[ivar];
230 Float_t *bins = new Float_t[nbins+1];
231 for(Int_t ibin =0;ibin<nbins+1;ibin++){
232 bins[ibin] = fVarBinLimits[ibin+fOffset[ivar]];
233 }
234
235 char pname[30];
236 sprintf(pname,"%s%s%i%i%s%i",GetName(),"_SelStep",fSelNum,fSelDen,"_proj1D_var", ivar);
237 char htitle[30];
238 sprintf(htitle,"%s%s%i%i%s%i",GetName(),"_SelStep",fSelNum,fSelDen,"_proj1D_var", ivar);
239
240 if(!proj1D){
1e9dad92 241 proj1D =new TH1D(pname,htitle, nbins, bins);
563113d0 242 }
243
9105291d 244 //unset the use of axis range to be able to divide the histos
245 fContainer->GetGrid(fSelNum)->UseAxisRange(kFALSE);
246 fContainer->GetGrid(fSelDen)->UseAxisRange(kFALSE);
247
1e9dad92 248 proj1D->Sumw2();
563113d0 249 proj1D->Divide(fContainer->GetGrid(fSelNum)->Project(ivar),fContainer->GetGrid(fSelDen)->Project(ivar),1.,1.,"B");
398ea452 250
251 fContainer->GetGrid(fSelNum)->UseAxisRange(kTRUE);
252 fContainer->GetGrid(fSelDen)->UseAxisRange(kTRUE);
253 proj1D->GetXaxis()->SetRange(
254 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar)->GetFirst(),
255 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar)->GetLast()
256 );
257
563113d0 258 delete [] bins;
259 return proj1D;
260}
261//___________________________________________________________________
1e9dad92 262TH2D *AliCFEffGrid::Project(Int_t ivar1,Int_t ivar2) const
563113d0 263{
264 //
265 // Make a 2D projection along variable ivar1,ivar2
266 //
267
1e9dad92 268 TH2D *proj2D=0;
563113d0 269
270 Int_t nbins1 =fNVarBins[ivar1];
271 Float_t *bins1 = new Float_t[nbins1+1];
272 Int_t nbins2 =fNVarBins[ivar2];
273 Float_t *bins2 = new Float_t[nbins2+1];
274 for(Int_t ibin1 =0;ibin1<nbins1+1;ibin1++){
275 bins1[ibin1] = fVarBinLimits[ibin1+fOffset[ivar1]];
276 }
277 for(Int_t ibin2 =0;ibin2<nbins2+1;ibin2++){
278 bins2[ibin2] = fVarBinLimits[ibin2+fOffset[ivar2]];
279 }
280
281 char pname[30];
282 sprintf(pname,"%s%s%i%i%s%i%i",GetName(),"_SelStep",fSelNum,fSelDen,"_proj2D_var", ivar1,ivar2);
283 char htitle[30];
284 sprintf(htitle,"%s%s%i%i%s%i%i",GetName(),"_SelStep",fSelNum,fSelDen,"_proj2D_var",ivar1,ivar2);
285
286 if(!proj2D){
1e9dad92 287 proj2D =new TH2D(pname,htitle, nbins1,bins1,nbins2,bins2);
563113d0 288 }
289
9105291d 290 //unset the use of axis range to be able to divide the histos
291 fContainer->GetGrid(fSelNum)->UseAxisRange(kFALSE);
292 fContainer->GetGrid(fSelDen)->UseAxisRange(kFALSE);
293
1e9dad92 294 proj2D->Sumw2();
563113d0 295 proj2D->Divide(fContainer->GetGrid(fSelNum)->Project(ivar1,ivar2),fContainer->GetGrid(fSelDen)->Project(ivar1,ivar2),1.,1.,"B");
296
398ea452 297 fContainer->GetGrid(fSelNum)->UseAxisRange(kTRUE);
298 fContainer->GetGrid(fSelDen)->UseAxisRange(kTRUE);
299 proj2D->GetXaxis()->SetRange(
300 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar1)->GetFirst(),
301 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar1)->GetLast()
302 );
303 proj2D->GetYaxis()->SetRange(
304 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar2)->GetFirst(),
305 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar2)->GetLast()
306 );
307
563113d0 308 delete [] bins1;
309 delete [] bins2;
310 return proj2D;
311}
312//___________________________________________________________________
1e9dad92 313TH3D *AliCFEffGrid::Project(Int_t ivar1, Int_t ivar2, Int_t ivar3) const
563113d0 314{
315 //
316 // Make a 3D projection along variable ivar1,ivar2,ivar3
317 //
318
1e9dad92 319 TH3D *proj3D=0;
563113d0 320
321 Int_t nbins1 =fNVarBins[ivar1];
322 Int_t nbins2 =fNVarBins[ivar2];
323 Int_t nbins3 =fNVarBins[ivar3];
324
325 Float_t *bins1 = new Float_t[nbins1+1];
326 Float_t *bins2 = new Float_t[nbins2+1];
327 Float_t *bins3 = new Float_t[nbins3+1];
328
329 for(Int_t ibin =0;ibin<nbins1+1;ibin++){
330 bins1[ibin] = fVarBinLimits[ibin+fOffset[ivar1]];
331 }
332 for(Int_t ibin =0;ibin<nbins2+1;ibin++){
333 bins2[ibin] = fVarBinLimits[ibin+fOffset[ivar2]];
334 }
335 for(Int_t ibin =0;ibin<nbins3+1;ibin++){
336 bins3[ibin] = fVarBinLimits[ibin+fOffset[ivar3]];
337 }
338
339 char pname[30];
340 sprintf(pname,"%s%s%i%i%s%i%i%i",GetName(),"_SelStep",fSelNum,fSelDen,"_proj3D_var",ivar1,ivar2,ivar3);
341 char htitle[30];
342 sprintf(htitle,"%s%s%i%i%s%i%i%i",GetName(),"_SelStep",fSelNum,fSelDen,"_proj3D_var",ivar1,ivar2,ivar3);
343
344
345 if(!proj3D){
1e9dad92 346 proj3D =new TH3D(pname,htitle, nbins1, bins1,nbins2,bins2,nbins3,bins3);
563113d0 347 }
348
9105291d 349 //unset the use of axis range to be able to divide the histos
350 fContainer->GetGrid(fSelNum)->UseAxisRange(kFALSE);
351 fContainer->GetGrid(fSelDen)->UseAxisRange(kFALSE);
352
1e9dad92 353 proj3D->Sumw2();
563113d0 354 proj3D->Divide(fContainer->GetGrid(fSelNum)->Project(ivar1,ivar2,ivar3),fContainer->GetGrid(fSelDen)->Project(ivar1,ivar2,ivar3),1.,1.,"B");
355
398ea452 356 fContainer->GetGrid(fSelNum)->UseAxisRange(kTRUE);
357 fContainer->GetGrid(fSelDen)->UseAxisRange(kTRUE);
358
359 proj3D->GetXaxis()->SetRange(
360 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar1)->GetFirst(),
361 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar1)->GetLast()
362 );
363 proj3D->GetYaxis()->SetRange(
364 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar2)->GetFirst(),
365 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar2)->GetLast()
366 );
367 proj3D->GetZaxis()->SetRange(
368 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar3)->GetFirst(),
369 ((AliCFGridSparse*)GetNum())->GetGrid()->GetAxis(ivar3)->GetLast()
370 );
371
563113d0 372 delete [] bins1;
373 delete [] bins2;
374 delete [] bins3;
375
376 return proj3D;
377}
9105291d 378