]> git.uio.no Git - u/mrichter/AliRoot.git/blame - CORRFW/AliCFEffGrid.cxx
Updated list of files
[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()),
5188c2a7 65 fContainer(NULL),
563113d0 66 fSelNum(-1),
67 fSelDen(-1)
68{
69 //
70 // main constructor
71 //
72 SumW2();
73 //assign the container;
74 fContainer=&c;
75}
76//____________________________________________________________________
25488e18 77AliCFEffGrid::AliCFEffGrid(const AliCFEffGrid& eff) : AliCFGridSparse(),
563113d0 78 fContainer(0x0),
79 fSelNum(-1),
80 fSelDen(-1)
81{
82 //
83 // copy constructor
84 //
85 ((AliCFEffGrid &)eff).Copy(*this);
86}
87
88//____________________________________________________________________
89AliCFEffGrid::~AliCFEffGrid()
90{
91 //
92 // destructor
93 //
94}
95
96//____________________________________________________________________
97AliCFEffGrid &AliCFEffGrid::operator=(const AliCFEffGrid &eff)
98{
99 //
100 // assigment operator
101 //
102 if (this != &eff)
103 ((AliCFEffGrid &) eff).Copy(*this);
104 return *this;
105}
106//____________________________________________________________________
107
5d14ed73 108void AliCFEffGrid::CalculateEfficiency(Int_t istep1,Int_t istep2, Option_t *option)
563113d0 109{
110 //
111 // Calculate the efficiency matrix and its error between selection
112 // Steps istep1 and istep2
113 //
9be0fa4e 114 // 'option' is used as an argument for THnSparse::Divide
115 // default is "B" : binomial error calculation
116 //
563113d0 117
118 fSelNum=istep1;
119 fSelDen=istep2;
ac6b9aed 120 AliCFVGrid *num=GetNum();
121 AliCFVGrid *den=GetDen();
563113d0 122 num->SumW2();
123 den->SumW2();
1e9dad92 124 this->SumW2();
5d14ed73 125 this->Divide(num,den,1.,1.,option);
563113d0 126
9be0fa4e 127 AliInfo(Form("Efficiency calculated for steps %i and %i.",fSelNum,fSelDen));
563113d0 128}
129//_____________________________________________________________________
1e9dad92 130Double_t AliCFEffGrid::GetAverage() const
563113d0 131{
132 //
133 // Get the average efficiency
134 //
135
1e9dad92 136 Double_t val=0;
137 Double_t valnum=0;
138 Double_t valden=0;
563113d0 139
9be0fa4e 140 THnSparse* num = ((AliCFGridSparse*)GetNum())->GetGrid() ;
141 THnSparse* den = ((AliCFGridSparse*)GetDen())->GetGrid() ;
142
143 for (Long_t iBin=0; iBin<num->GetNbins(); iBin++) valnum+=num->GetBinContent(iBin);
144 for (Long_t iBin=0; iBin<den->GetNbins(); iBin++) valden+=den->GetBinContent(iBin);
145 if (valden>0) val=valnum/valden;
146 AliInfo(Form(" The Average Efficiency = %f ",val));
563113d0 147 return val;
148}
149//_____________________________________________________________________
1e9dad92 150Double_t AliCFEffGrid::GetAverage(Double_t *varMin, Double_t* varMax ) const
563113d0 151{
152 //
153 // Get ave efficiency in a range
9be0fa4e 154 // (may not work properly, should be modified)
563113d0 155
1e9dad92 156 Double_t val=0;
563113d0 157 Int_t *indexMin = new Int_t[fNVar];
158 Int_t *indexMax = new Int_t[fNVar];
159 Int_t *index = new Int_t[fNVar];
160
161 //Find out the min and max bins
162
163 for(Int_t i=0;i<fNVar;i++){
1e9dad92 164 Double_t xmin=varMin[i]; // the min values
165 Double_t xmax=varMax[i]; // the max values
563113d0 166 Int_t nbins=fNVarBins[i]+1;
365c0ea4 167 Double_t *bins=new Double_t[nbins];
563113d0 168 for(Int_t ibin =0;ibin<nbins;ibin++){
169 bins[ibin] = fVarBinLimits[ibin+fOffset[i]];
170 }
171 indexMin[i] = TMath::BinarySearch(nbins,bins,xmin);
172 indexMax[i] = TMath::BinarySearch(nbins,bins,xmax);
173 if(xmax>=bins[nbins-1]){
174 indexMax[i]=indexMax[i]-1;
175 }
176 delete [] bins;
177 }
178
1e9dad92 179 Double_t valnum=0;
180 Double_t valden=0;
563113d0 181 for(Int_t i=0;i<fNDim;i++){
182 for (Int_t j=0;j<fNVar;j++)index[j]=GetBinIndex(j,i);
183 Bool_t isIn=kTRUE;
184 for (Int_t j=0;j<fNVar;j++){
185 if(!(index[j]>=indexMin[j] && index[j]<=indexMax[j]))isIn=kFALSE;
186 }
187 if(isIn){
ac6b9aed 188 valnum+=GetNum()->GetElement(i);
189 valden+=GetDen()->GetElement(i);
563113d0 190 }
191 }
192 delete [] index;
193 delete [] indexMin;
194 delete [] indexMax;
195 if(valden>0)val=valnum/valden;
196 AliInfo(Form(" the Average Efficiency = %f ",val));
197 return val;
198}
199//____________________________________________________________________
200void AliCFEffGrid::Copy(TObject& eff) const
201{
202 //
203 // copy function
204 //
205 Copy(eff);
206 AliCFEffGrid& target = (AliCFEffGrid &) eff;
207
208 target.fSelNum=fSelNum;
209 target.fSelDen=fSelDen;
210 if(fContainer)
211 target.fContainer=fContainer;
212}
213//___________________________________________________________________
1e9dad92 214TH1D *AliCFEffGrid::Project(Int_t ivar) const
563113d0 215{
216 //
217 // Make a 1D projection along variable ivar
218 //
219
a757643f 220 const Int_t nDim = 1 ;
221 Int_t dim[nDim] = {ivar} ;
222 THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid()->Projection(nDim,dim);
223 THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid()->Projection(nDim,dim);
ac6b9aed 224 THnSparse* ratio = (THnSparse*)hNum->Clone();
225 ratio->Divide(hNum,hDen,1.,1.,"B");
a757643f 226 delete hNum; delete hDen;
227 return ratio->Projection(0);
563113d0 228}
229//___________________________________________________________________
1e9dad92 230TH2D *AliCFEffGrid::Project(Int_t ivar1,Int_t ivar2) const
563113d0 231{
232 //
233 // Make a 2D projection along variable ivar1,ivar2
234 //
a757643f 235
236 const Int_t nDim = 2 ;
237 Int_t dim[nDim] = {ivar1,ivar2} ;
238 THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid()->Projection(nDim,dim);
239 THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid()->Projection(nDim,dim);
ac6b9aed 240 THnSparse* ratio = (THnSparse*)hNum->Clone();
241 ratio->Divide(hNum,hDen,1.,1.,"B");
a757643f 242 delete hNum; delete hDen;
243 return ratio->Projection(0,1);
563113d0 244}
245//___________________________________________________________________
1e9dad92 246TH3D *AliCFEffGrid::Project(Int_t ivar1, Int_t ivar2, Int_t ivar3) const
563113d0 247{
248 //
249 // Make a 3D projection along variable ivar1,ivar2,ivar3
250 //
251
a757643f 252 const Int_t nDim = 3 ;
253 Int_t dim[nDim] = {ivar1,ivar2,ivar3} ;
254 THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid()->Projection(nDim,dim);
255 THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid()->Projection(nDim,dim);
ac6b9aed 256 THnSparse* ratio = (THnSparse*)hNum->Clone();
257 ratio->Divide(hNum,hDen,1.,1.,"B");
a757643f 258 delete hNum; delete hDen;
259 return ratio->Projection(0,1,2);
563113d0 260}
a757643f 261//___________________________________________________________________
262AliCFEffGrid* AliCFEffGrid::MakeSlice(Int_t nVars, Int_t* vars, Double_t* varMin, Double_t* varMax, Int_t numStep, Int_t denStep) const {
263 //
264 // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for all the container steps.
265 // The ranges of ALL the container variables must be defined in the array varMin[fNVar] and varMax[fNVar].
266 // This function returns the effiency relative to this new 'sliced' container, between steps defined in numStep and denStep
267 //
268 AliCFContainer* cont = fContainer->MakeSlice(nVars,vars,varMin,varMax);
269 AliCFEffGrid * eff = new AliCFEffGrid(Form("%s_sliced",GetName()), Form("%s_sliced",GetTitle()), *cont);
270 eff->CalculateEfficiency(numStep,denStep);
271 return eff;
272}