]>
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 | // // | |
fb494025 | 18 | // AliCFEffGrid Class // |
563113d0 | 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 | //____________________________________________________________________ | |
fb494025 | 51 | AliCFEffGrid::AliCFEffGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn) : |
52 | AliCFGridSparse(name,title,nVarIn,nBinIn), | |
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) : | |
fb494025 | 64 | AliCFGridSparse(name,title,c.GetNVar(),c.GetNBins()), |
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; | |
fb494025 | 75 | for (Int_t iVar=0; iVar<GetNVar(); iVar++) { |
91e32eeb | 76 | Int_t nbins = c.GetNBins(iVar); |
77 | Double_t* array=new Double_t[nbins+1] ; | |
78 | c.GetBinLimits(iVar,array); | |
79 | SetBinLimits(iVar,array); | |
53ab59fe | 80 | delete [] array ; |
fb494025 | 81 | } |
82 | for (Int_t iVar=0; iVar<GetNVar(); iVar++) SetVarTitle(iVar,c.GetVarTitle(iVar)); | |
563113d0 | 83 | } |
84 | //____________________________________________________________________ | |
fb494025 | 85 | AliCFEffGrid::AliCFEffGrid(const AliCFEffGrid& eff) : |
86 | AliCFGridSparse(eff), | |
563113d0 | 87 | fContainer(0x0), |
88 | fSelNum(-1), | |
89 | fSelDen(-1) | |
90 | { | |
91 | // | |
92 | // copy constructor | |
93 | // | |
94 | ((AliCFEffGrid &)eff).Copy(*this); | |
95 | } | |
96 | ||
97 | //____________________________________________________________________ | |
98 | AliCFEffGrid::~AliCFEffGrid() | |
99 | { | |
100 | // | |
101 | // destructor | |
102 | // | |
103 | } | |
104 | ||
105 | //____________________________________________________________________ | |
106 | AliCFEffGrid &AliCFEffGrid::operator=(const AliCFEffGrid &eff) | |
107 | { | |
108 | // | |
109 | // assigment operator | |
110 | // | |
fb494025 | 111 | if (this != &eff) eff.Copy(*this); |
563113d0 | 112 | return *this; |
113 | } | |
563113d0 | 114 | |
fb494025 | 115 | //____________________________________________________________________ |
5d14ed73 | 116 | void AliCFEffGrid::CalculateEfficiency(Int_t istep1,Int_t istep2, Option_t *option) |
563113d0 | 117 | { |
118 | // | |
119 | // Calculate the efficiency matrix and its error between selection | |
120 | // Steps istep1 and istep2 | |
121 | // | |
9be0fa4e | 122 | // 'option' is used as an argument for THnSparse::Divide |
123 | // default is "B" : binomial error calculation | |
124 | // | |
563113d0 | 125 | |
126 | fSelNum=istep1; | |
127 | fSelDen=istep2; | |
fb494025 | 128 | AliCFGridSparse *num=GetNum(); |
129 | AliCFGridSparse *den=GetDen(); | |
563113d0 | 130 | num->SumW2(); |
131 | den->SumW2(); | |
1e9dad92 | 132 | this->SumW2(); |
5d14ed73 | 133 | this->Divide(num,den,1.,1.,option); |
fb494025 | 134 | SetTitle(Form("Efficiency: %s / %s",fContainer->GetStepTitle(istep1),fContainer->GetStepTitle(istep2))); |
563113d0 | 135 | |
9be0fa4e | 136 | AliInfo(Form("Efficiency calculated for steps %i and %i.",fSelNum,fSelDen)); |
563113d0 | 137 | } |
138 | //_____________________________________________________________________ | |
1e9dad92 | 139 | Double_t AliCFEffGrid::GetAverage() const |
563113d0 | 140 | { |
141 | // | |
142 | // Get the average efficiency | |
143 | // | |
144 | ||
1e9dad92 | 145 | Double_t val=0; |
146 | Double_t valnum=0; | |
147 | Double_t valden=0; | |
563113d0 | 148 | |
9be0fa4e | 149 | THnSparse* num = ((AliCFGridSparse*)GetNum())->GetGrid() ; |
150 | THnSparse* den = ((AliCFGridSparse*)GetDen())->GetGrid() ; | |
151 | ||
152 | for (Long_t iBin=0; iBin<num->GetNbins(); iBin++) valnum+=num->GetBinContent(iBin); | |
153 | for (Long_t iBin=0; iBin<den->GetNbins(); iBin++) valden+=den->GetBinContent(iBin); | |
154 | if (valden>0) val=valnum/valden; | |
155 | AliInfo(Form(" The Average Efficiency = %f ",val)); | |
563113d0 | 156 | return val; |
157 | } | |
563113d0 | 158 | //___________________________________________________________________ |
d91baff0 | 159 | TH1* AliCFEffGrid::Project(Int_t ivar1, Int_t ivar2, Int_t ivar3) const |
563113d0 | 160 | { |
161 | // | |
d91baff0 | 162 | // Make a projection along variable ivar1 (and ivar2 (and ivar3)) |
563113d0 | 163 | // |
164 | ||
fb494025 | 165 | if (fSelNum<0 || fSelDen<0) { |
166 | AliError("You must call CalculateEfficiency() first !"); | |
167 | return 0x0; | |
168 | } | |
a757643f | 169 | const Int_t nDim = 3 ; |
170 | Int_t dim[nDim] = {ivar1,ivar2,ivar3} ; | |
d91baff0 | 171 | |
172 | THnSparse *hNum, *hDen, *ratio; | |
173 | TH1* h ; | |
174 | ||
175 | if (ivar3<0) { | |
176 | if (ivar2<0) { | |
177 | hNum = ((AliCFGridSparse*)GetNum())->GetGrid()->Projection(nDim-2,dim); | |
178 | hDen = ((AliCFGridSparse*)GetDen())->GetGrid()->Projection(nDim-2,dim); | |
179 | ratio = (THnSparse*)hNum->Clone(); | |
180 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
181 | h = ratio->Projection(0); | |
182 | } | |
183 | else{ | |
184 | hNum = ((AliCFGridSparse*)GetNum())->GetGrid()->Projection(nDim-1,dim); | |
185 | hDen = ((AliCFGridSparse*)GetDen())->GetGrid()->Projection(nDim-1,dim); | |
186 | ratio = (THnSparse*)hNum->Clone(); | |
187 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
188 | h = ratio->Projection(1,0); | |
189 | } | |
190 | } | |
191 | else { | |
192 | hNum = ((AliCFGridSparse*)GetNum())->GetGrid()->Projection(nDim,dim); | |
193 | hDen = ((AliCFGridSparse*)GetDen())->GetGrid()->Projection(nDim,dim); | |
194 | ratio = (THnSparse*)hNum->Clone(); | |
195 | ratio->Divide(hNum,hDen,1.,1.,"B"); | |
196 | h = ratio->Projection(0,1,2); | |
197 | } | |
198 | ||
199 | delete hNum; delete hDen; delete ratio; | |
200 | return h ; | |
563113d0 | 201 | } |
a757643f | 202 | //___________________________________________________________________ |
d91baff0 | 203 | AliCFEffGrid* AliCFEffGrid::MakeSlice(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const { |
a757643f | 204 | // |
d91baff0 | 205 | // returns a slice of the efficiency grid (slice is actually done on the container, and efficiency recomputed) |
a757643f | 206 | // |
fb494025 | 207 | |
98a5f772 | 208 | AliCFContainer* cont = fContainer->MakeSlice(nVars,vars,varMin,varMax,useBins); |
a757643f | 209 | AliCFEffGrid * eff = new AliCFEffGrid(Form("%s_sliced",GetName()), Form("%s_sliced",GetTitle()), *cont); |
d91baff0 | 210 | eff->CalculateEfficiency(fSelNum,fSelDen); |
a757643f | 211 | return eff; |
212 | } |