]>
Commit | Line | Data |
---|---|---|
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 | //____________________________________________________________________ | |
36 | ClassImp(AliCFEffGrid) | |
37 | ||
38 | //____________________________________________________________________ | |
39 | AliCFEffGrid::AliCFEffGrid() : | |
25488e18 | 40 | AliCFGridSparse(), |
563113d0 | 41 | fContainer(0x0), |
42 | fSelNum(-1), | |
43 | fSelDen(-1) | |
44 | { | |
45 | // | |
46 | // default constructor | |
47 | // | |
48 | } | |
49 | ||
50 | //____________________________________________________________________ | |
1e9dad92 | 51 | AliCFEffGrid::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 | //____________________________________________________________________ | |
63 | AliCFEffGrid::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 | 77 | AliCFEffGrid::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 | //____________________________________________________________________ | |
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 | ||
5d14ed73 | 108 | void 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 | 130 | Double_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 | 150 | Double_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 | //____________________________________________________________________ | |
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 | //___________________________________________________________________ | |
1e9dad92 | 214 | TH1D *AliCFEffGrid::Project(Int_t ivar) const |
563113d0 | 215 | { |
216 | // | |
217 | // Make a 1D projection along variable ivar | |
218 | // | |
219 | ||
52a155da | 220 | THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid(); |
221 | THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid(); | |
ac6b9aed | 222 | THnSparse* ratio = (THnSparse*)hNum->Clone(); |
223 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
ac6b9aed | 224 | return ratio->Projection(ivar); |
563113d0 | 225 | } |
226 | //___________________________________________________________________ | |
1e9dad92 | 227 | TH2D *AliCFEffGrid::Project(Int_t ivar1,Int_t ivar2) const |
563113d0 | 228 | { |
229 | // | |
230 | // Make a 2D projection along variable ivar1,ivar2 | |
231 | // | |
52a155da | 232 | THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid(); |
233 | THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid(); | |
ac6b9aed | 234 | THnSparse* ratio = (THnSparse*)hNum->Clone(); |
235 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
ac6b9aed | 236 | return ratio->Projection(ivar1,ivar2); |
563113d0 | 237 | } |
238 | //___________________________________________________________________ | |
1e9dad92 | 239 | TH3D *AliCFEffGrid::Project(Int_t ivar1, Int_t ivar2, Int_t ivar3) const |
563113d0 | 240 | { |
241 | // | |
242 | // Make a 3D projection along variable ivar1,ivar2,ivar3 | |
243 | // | |
244 | ||
52a155da | 245 | THnSparse* hNum = ((AliCFGridSparse*)GetNum())->GetGrid(); |
246 | THnSparse* hDen = ((AliCFGridSparse*)GetDen())->GetGrid(); | |
ac6b9aed | 247 | THnSparse* ratio = (THnSparse*)hNum->Clone(); |
248 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
ac6b9aed | 249 | return ratio->Projection(ivar1,ivar2,ivar3); |
563113d0 | 250 | } |
9105291d | 251 |