]>
Commit | Line | Data |
---|---|---|
1 | /* $Id$ */ | |
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 | **************************************************************************/ | |
16 | //--------------------------------------------------------------------// | |
17 | // // | |
18 | // AliCFEffGrid Class // | |
19 | // Class to handle efficiency grids // | |
20 | // // | |
21 | // -- Author : S.Arcelli // | |
22 | // // | |
23 | // // | |
24 | // // | |
25 | //--------------------------------------------------------------------// | |
26 | // | |
27 | // | |
28 | #include "TMath.h" | |
29 | #include "AliLog.h" | |
30 | #include "AliCFEffGrid.h" | |
31 | #include "TH1D.h" | |
32 | #include "TH2D.h" | |
33 | #include "TH3D.h" | |
34 | ||
35 | //____________________________________________________________________ | |
36 | ClassImp(AliCFEffGrid) | |
37 | ||
38 | //____________________________________________________________________ | |
39 | AliCFEffGrid::AliCFEffGrid() : | |
40 | AliCFGridSparse(), | |
41 | fContainer(0x0), | |
42 | fSelNum(-1), | |
43 | fSelDen(-1) | |
44 | { | |
45 | // | |
46 | // default constructor | |
47 | // | |
48 | } | |
49 | ||
50 | //____________________________________________________________________ | |
51 | AliCFEffGrid::AliCFEffGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn) : | |
52 | AliCFGridSparse(name,title,nVarIn,nBinIn,binLimitsIn), | |
53 | fContainer(0x0), | |
54 | fSelNum(-1), | |
55 | fSelDen(-1) | |
56 | { | |
57 | // | |
58 | // ctor | |
59 | // | |
60 | SumW2(); | |
61 | } | |
62 | //____________________________________________________________________ | |
63 | AliCFEffGrid::AliCFEffGrid(const Char_t* name, const Char_t* title, const AliCFContainer &c) : | |
64 | AliCFGridSparse(name,title,c.GetNVar(),c.GetNBins(),c.GetBinLimits()), | |
65 | fContainer(NULL), | |
66 | fSelNum(-1), | |
67 | fSelDen(-1) | |
68 | { | |
69 | // | |
70 | // main constructor | |
71 | // | |
72 | SumW2(); | |
73 | //assign the container; | |
74 | fContainer=&c; | |
75 | } | |
76 | //____________________________________________________________________ | |
77 | AliCFEffGrid::AliCFEffGrid(const AliCFEffGrid& eff) : AliCFGridSparse(), | |
78 | fContainer(0x0), | |
79 | fSelNum(-1), | |
80 | fSelDen(-1) | |
81 | { | |
82 | // | |
83 | // copy constructor | |
84 | // | |
85 | ((AliCFEffGrid &)eff).Copy(*this); | |
86 | } | |
87 | ||
88 | //____________________________________________________________________ | |
89 | AliCFEffGrid::~AliCFEffGrid() | |
90 | { | |
91 | // | |
92 | // destructor | |
93 | // | |
94 | } | |
95 | ||
96 | //____________________________________________________________________ | |
97 | AliCFEffGrid &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 | ||
108 | void AliCFEffGrid::CalculateEfficiency(Int_t istep1,Int_t istep2, Option_t *option) | |
109 | { | |
110 | // | |
111 | // Calculate the efficiency matrix and its error between selection | |
112 | // Steps istep1 and istep2 | |
113 | // | |
114 | // 'option' is used as an argument for THnSparse::Divide | |
115 | // default is "B" : binomial error calculation | |
116 | // | |
117 | ||
118 | fSelNum=istep1; | |
119 | fSelDen=istep2; | |
120 | AliCFVGrid *num=GetNum(); | |
121 | AliCFVGrid *den=GetDen(); | |
122 | num->SumW2(); | |
123 | den->SumW2(); | |
124 | this->SumW2(); | |
125 | this->Divide(num,den,1.,1.,option); | |
126 | ||
127 | AliInfo(Form("Efficiency calculated for steps %i and %i.",fSelNum,fSelDen)); | |
128 | } | |
129 | //_____________________________________________________________________ | |
130 | Double_t AliCFEffGrid::GetAverage() const | |
131 | { | |
132 | // | |
133 | // Get the average efficiency | |
134 | // | |
135 | ||
136 | Double_t val=0; | |
137 | Double_t valnum=0; | |
138 | Double_t valden=0; | |
139 | ||
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)); | |
147 | return val; | |
148 | } | |
149 | //_____________________________________________________________________ | |
150 | Double_t AliCFEffGrid::GetAverage(Double_t *varMin, Double_t* varMax ) const | |
151 | { | |
152 | // | |
153 | // Get ave efficiency in a range | |
154 | // (may not work properly, should be modified) | |
155 | ||
156 | Double_t val=0; | |
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++){ | |
164 | Double_t xmin=varMin[i]; // the min values | |
165 | Double_t xmax=varMax[i]; // the max values | |
166 | Int_t nbins=fNVarBins[i]+1; | |
167 | Double_t *bins=new Double_t[nbins]; | |
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 | ||
179 | Double_t valnum=0; | |
180 | Double_t valden=0; | |
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){ | |
188 | valnum+=GetNum()->GetElement(i); | |
189 | valden+=GetDen()->GetElement(i); | |
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 | //____________________________________________________________________ | |
200 | void 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 | //___________________________________________________________________ | |
214 | TH1D *AliCFEffGrid::Project(Int_t ivar) const | |
215 | { | |
216 | // | |
217 | // Make a 1D projection along variable ivar | |
218 | // | |
219 | ||
220 | THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid(); | |
221 | THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid(); | |
222 | THnSparse* ratio = (THnSparse*)hNum->Clone(); | |
223 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
224 | return ratio->Projection(ivar); | |
225 | } | |
226 | //___________________________________________________________________ | |
227 | TH2D *AliCFEffGrid::Project(Int_t ivar1,Int_t ivar2) const | |
228 | { | |
229 | // | |
230 | // Make a 2D projection along variable ivar1,ivar2 | |
231 | // | |
232 | THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid(); | |
233 | THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid(); | |
234 | THnSparse* ratio = (THnSparse*)hNum->Clone(); | |
235 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
236 | return ratio->Projection(ivar1,ivar2); | |
237 | } | |
238 | //___________________________________________________________________ | |
239 | TH3D *AliCFEffGrid::Project(Int_t ivar1, Int_t ivar2, Int_t ivar3) const | |
240 | { | |
241 | // | |
242 | // Make a 3D projection along variable ivar1,ivar2,ivar3 | |
243 | // | |
244 | ||
245 | THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid(); | |
246 | THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid(); | |
247 | THnSparse* ratio = (THnSparse*)hNum->Clone(); | |
248 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
249 | return ratio->Projection(ivar1,ivar2,ivar3); | |
250 | } | |
251 |