]>
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 | // AliCFContainer Class // | |
19 | // Class to accumulate data on an N-dimensional grids, at different // | |
20 | // selection stages. To be used as an input to get corrections for // | |
21 | // Reconstruction & Trigger efficiency // | |
22 | // // | |
23 | // -- Author : S.Arcelli // | |
24 | //--------------------------------------------------------------------// | |
25 | // | |
26 | // | |
27 | #include <AliLog.h> | |
28 | #include "AliCFGridSparse.h" | |
29 | #include "AliCFContainer.h" | |
30 | #include "TAxis.h" | |
31 | //____________________________________________________________________ | |
32 | ClassImp(AliCFContainer) | |
33 | ||
34 | //____________________________________________________________________ | |
35 | AliCFContainer::AliCFContainer() : | |
36 | AliCFFrame(), | |
37 | fNStep(0), | |
38 | fGrid(0x0) | |
39 | { | |
40 | // | |
41 | // default constructor | |
42 | // | |
43 | } | |
44 | ||
45 | //____________________________________________________________________ | |
46 | AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title, const Int_t nSelSteps, const Int_t nVarIn, const Int_t* nBinIn) : | |
47 | AliCFFrame(name,title), | |
48 | fNStep(nSelSteps), | |
49 | fGrid(0x0) | |
50 | { | |
51 | // | |
52 | // main constructor | |
53 | // | |
54 | ||
55 | // The grids | |
56 | fGrid = new AliCFGridSparse*[fNStep]; //the grids at the various selection steps | |
57 | for (Int_t istep=0; istep<fNStep; istep++) { | |
58 | fGrid[istep] = new AliCFGridSparse(Form("%s_SelStep%d",name,istep),Form("step%d",istep),nVarIn,nBinIn); | |
59 | fGrid[istep]->SumW2(); | |
60 | } | |
61 | for (Int_t iVar=0; iVar<nVarIn; iVar++) SetVarTitle(iVar,Form("var%d",iVar)); | |
62 | AliInfo(Form("Grids created for %d steps required \n => Don't forget to set the bin limits !!",fNStep)); | |
63 | } | |
64 | //____________________________________________________________________ | |
65 | AliCFContainer::AliCFContainer(const AliCFContainer& c) : | |
66 | AliCFFrame(c.fName,c.fTitle), | |
67 | fNStep(0), | |
68 | fGrid(0x0) | |
69 | { | |
70 | // | |
71 | // copy constructor | |
72 | // | |
73 | c.Copy(*this); | |
74 | } | |
75 | //____________________________________________________________________ | |
76 | AliCFContainer::~AliCFContainer() | |
77 | { | |
78 | // | |
79 | // destructor | |
80 | // | |
81 | if (fGrid) { | |
82 | for ( Int_t istep=0; istep<fNStep; istep++ ) | |
83 | delete fGrid[istep]; | |
84 | } | |
85 | delete [] fGrid; | |
86 | } | |
87 | //____________________________________________________________________ | |
88 | AliCFContainer &AliCFContainer::operator=(const AliCFContainer &c) | |
89 | { | |
90 | // | |
91 | // assigment operator | |
92 | // | |
93 | if (this != &c) c.Copy(*this); | |
94 | return *this; | |
95 | } | |
96 | ||
97 | //____________________________________________________________________ | |
98 | void AliCFContainer::Copy(TObject& c) const | |
99 | { | |
100 | // | |
101 | // copy function | |
102 | // | |
103 | AliCFFrame::Copy(c); | |
104 | AliCFContainer& target = (AliCFContainer &) c; | |
105 | target.fNStep = fNStep; | |
106 | target.fGrid = new AliCFGridSparse*[fNStep]; | |
107 | for (Int_t iStep=0; iStep<fNStep; iStep++) { | |
108 | if (fGrid[iStep]) target.fGrid[iStep] = new AliCFGridSparse(*(fGrid[iStep])); | |
109 | } | |
110 | } | |
111 | ||
112 | //____________________________________________________________________ | |
113 | void AliCFContainer::Fill(const Double_t *var, Int_t istep, Double_t weight) | |
114 | { | |
115 | // | |
116 | // Fills the grid at selection step istep for a set of values of the | |
117 | // input variables, with a given weight (by default w=1) | |
118 | // | |
119 | if(istep >= fNStep || istep < 0){ | |
120 | AliError("Non-existent selection step, grid was not filled"); | |
121 | return; | |
122 | } | |
123 | fGrid[istep]->Fill(var,weight); | |
124 | } | |
125 | ||
126 | //____________________________________________________________________ | |
127 | TH1* AliCFContainer::Project(Int_t istep, Int_t ivar1, Int_t ivar2, Int_t ivar3) const | |
128 | { | |
129 | // | |
130 | // returns a projection along variables ivar1 (and ivar2 (and ivar3)) | |
131 | // at selection step istep | |
132 | // | |
133 | if (istep >= fNStep || istep < 0){ | |
134 | AliError("Non-existent selection step, return NULL"); | |
135 | return 0x0; | |
136 | } | |
137 | return fGrid[istep]->Project(ivar1,ivar2,ivar3); | |
138 | } | |
139 | ||
140 | //____________________________________________________________________ | |
141 | AliCFContainer* AliCFContainer::MakeSlice(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const | |
142 | { | |
143 | // | |
144 | // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for all the container steps. | |
145 | // The ranges of ALL the container variables must be defined in the array varMin[GetNVar()] and varMax[GetNVar()] | |
146 | // The function returns a new container of nVars variables. | |
147 | // If useBins=true, varMin and varMax are taken as bin numbers | |
148 | // | |
149 | Int_t* steps = new Int_t[fNStep]; | |
150 | for (Int_t iStep=0;iStep<fNStep;iStep++) steps[iStep]=iStep; | |
151 | AliCFContainer* out = MakeSlice(fNStep,steps,nVars,vars,varMin,varMax,useBins); | |
152 | delete [] steps ; | |
153 | return out; | |
154 | } | |
155 | ||
156 | //____________________________________________________________________ | |
157 | AliCFContainer* AliCFContainer::MakeSlice(Int_t nSteps, const Int_t* steps, | |
158 | Int_t nVars, const Int_t* vars, | |
159 | const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const | |
160 | { | |
161 | // | |
162 | // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for the given "nSteps" defined in "steps[nSteps]". | |
163 | // The ranges of ALL the container variables must be defined in the array varMin[GetNVar()] and varMax[GetNVar()] | |
164 | // The function returns a new container of nVars variables. | |
165 | // If useBins=true, varMin and varMax are taken as bin numbers | |
166 | // | |
167 | ||
168 | if (nVars < 1 || nVars > GetNVar()) AliError("Bad number of dimensions required for the slice"); | |
169 | if (nSteps< 1 || nSteps> fNStep) AliError("Bad number of steps required for the slice"); | |
170 | ||
171 | AliInfo(Form("Making a slice in %d dimension(s)",nVars)); | |
172 | ||
173 | // create the output grids | |
174 | AliCFGridSparse** grids = new AliCFGridSparse*[nSteps] ; | |
175 | for (Int_t iStep=0; iStep<nSteps; iStep++) grids[iStep] = fGrid[steps[iStep]]->MakeSlice(nVars,vars,varMin,varMax,useBins); | |
176 | ||
177 | TAxis ** axis = new TAxis*[nVars]; | |
178 | for (Int_t iVar=0; iVar<nVars; iVar++) axis[iVar] = ((AliCFGridSparse*)grids[0])->GetGrid()->GetAxis(iVar); //same axis for every grid | |
179 | ||
180 | //define new binning for new container | |
181 | Int_t* bins=new Int_t[nVars]; | |
182 | for (Int_t iVar=0; iVar<nVars; iVar++) bins[iVar] = axis[iVar]->GetNbins(); | |
183 | ||
184 | AliCFContainer* out = new AliCFContainer(fName,fTitle,nSteps,nVars,bins); | |
185 | ||
186 | //set the bin limits | |
187 | for (Int_t iVar=0; iVar<nVars; iVar++) { | |
188 | Int_t nBins = bins[iVar]; | |
189 | Double_t *array = new Double_t[nBins+1]; | |
190 | for (Int_t iBin=1; iBin<=nBins+1; iBin++) { | |
191 | array[iBin-1] = axis[iVar]->GetBinLowEdge(iBin); | |
192 | } | |
193 | out->SetBinLimits(iVar,array); | |
194 | delete [] array; | |
195 | } | |
196 | ||
197 | //set grid for the given steps | |
198 | for (Int_t iStep=0; iStep<nSteps; iStep++) out->SetGrid(iStep,grids[iStep]); | |
199 | ||
200 | delete [] bins; | |
201 | delete [] axis ; | |
202 | delete [] grids; | |
203 | return out; | |
204 | } | |
205 | ||
206 | //____________________________________________________________________ | |
207 | Long64_t AliCFContainer::Merge(TCollection* list) | |
208 | { | |
209 | // Merge a list of AliCorrection objects with this (needed for | |
210 | // PROOF). | |
211 | // Returns the number of merged objects (including this). | |
212 | ||
213 | if (!list) | |
214 | return 0; | |
215 | ||
216 | if (list->IsEmpty()) | |
217 | return 1; | |
218 | ||
219 | TIter iter(list); | |
220 | TObject* obj; | |
221 | ||
222 | Int_t count = 0; | |
223 | while ((obj = iter())) { | |
224 | AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj); | |
225 | if (entry == 0) | |
226 | continue; | |
227 | this->Add(entry); | |
228 | count++; | |
229 | } | |
230 | ||
231 | return count+1; | |
232 | } | |
233 | ||
234 | //____________________________________________________________________ | |
235 | void AliCFContainer::Add(const AliCFContainer* aContainerToAdd, Double_t c) | |
236 | { | |
237 | // | |
238 | //add the content of container aContainerToAdd to the current one | |
239 | // | |
240 | if ((aContainerToAdd->GetNStep() != fNStep) || | |
241 | (aContainerToAdd->GetNVar() != GetNVar()) || | |
242 | (aContainerToAdd->GetNBinsTotal() != GetNBinsTotal())) | |
243 | { | |
244 | AliError("Different number of steps/sensitive variables/grid elements: cannot add the containers"); | |
245 | return; | |
246 | } | |
247 | for (Int_t istep=0; istep<fNStep; istep++) { | |
248 | fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c); | |
249 | } | |
250 | } | |
251 | //____________________________________________________________________ | |
252 | Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep, Bool_t exclusive) const { | |
253 | // | |
254 | // Get overflows in variable var at selection level istep | |
255 | // Set 'exclusive' to true for an exclusive check on variable ivar | |
256 | // | |
257 | if(istep >= fNStep || istep < 0){ | |
258 | AliError("Non-existent selection step, return -1"); | |
259 | return -1.; | |
260 | } | |
261 | return fGrid[istep]->GetOverFlows(ivar,exclusive); | |
262 | } | |
263 | //____________________________________________________________________ | |
264 | Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep, Bool_t exclusive) const { | |
265 | // | |
266 | // Get underflows in variable var at selection level istep | |
267 | // Set 'exclusive' to true for an exclusive check on variable ivar | |
268 | // | |
269 | if(istep >= fNStep || istep < 0){ | |
270 | AliError("Non-existent selection step, return -1"); | |
271 | return -1.; | |
272 | } | |
273 | return fGrid[istep]->GetUnderFlows(ivar,exclusive); | |
274 | } | |
275 | //____________________________________________________________________ | |
276 | Float_t AliCFContainer::GetEntries(Int_t istep) const { | |
277 | // | |
278 | // Get total entries in variable var at selection level istep | |
279 | // | |
280 | if(istep >= fNStep || istep < 0){ | |
281 | AliError("Non-existent selection step, return -1"); | |
282 | return -1.; | |
283 | } | |
284 | return fGrid[istep]->GetEntries(); | |
285 | } | |
286 | //_____________________________________________________________________ | |
287 | Double_t AliCFContainer::GetIntegral( Int_t istep) const | |
288 | { | |
289 | // | |
290 | // Get Integral over the grid at selection level istep | |
291 | // | |
292 | if(istep >= fNStep || istep < 0){ | |
293 | AliError("Non-existent selection step, return -1"); | |
294 | return -1.; | |
295 | } | |
296 | return fGrid[istep]->GetIntegral(); | |
297 | } | |
298 | ||
299 | //_____________________________________________________________________ | |
300 | void AliCFContainer::SetRangeUser(Int_t ivar, Double_t varMin, Double_t varMax, Bool_t useBins) const | |
301 | { | |
302 | // | |
303 | // set axis range for variable ivar | |
304 | // put useBins=kTRUE if you want to pass bin numbers instead of values | |
305 | // | |
306 | if (ivar >= GetNVar() || ivar < 0){ | |
307 | AliError("Non-existent selection var"); | |
308 | return ; | |
309 | } | |
310 | for (Int_t iStep=0; iStep<GetNStep(); iStep++) fGrid[iStep]->SetRangeUser(ivar,varMin,varMax,useBins); | |
311 | } | |
312 | ||
313 | //_____________________________________________________________________ | |
314 | void AliCFContainer::SetRangeUser(const Double_t* varMin, const Double_t* varMax, Bool_t useBins) const | |
315 | { | |
316 | // | |
317 | // set all axis ranges according to arrays varMin and varMax | |
318 | // put useBins=kTRUE if you want to pass bin numbers instead of values | |
319 | // | |
320 | for (Int_t iStep=0; iStep<GetNStep(); iStep++) fGrid[iStep]->SetRangeUser(varMin,varMax,useBins); | |
321 | } | |
322 | ||
323 | //_____________________________________________________________________ | |
324 | void AliCFContainer::Print(const Option_t*) const { | |
325 | AliInfo("===================================================================================="); | |
326 | AliInfo(Form("AliCFContainer : name = %s title = %s",GetName(),GetTitle())); | |
327 | AliInfo(Form("number of steps \t %d",GetNStep())); | |
328 | for (Int_t iStep=0;iStep<GetNStep();iStep++) AliInfo(Form("step %d \t -> %s",iStep,GetStepTitle(iStep))); | |
329 | AliInfo(Form("number of variables \t %d",GetNVar())); | |
330 | for (Int_t iVar=0;iVar<GetNVar();iVar++) { | |
331 | Double_t *binLimits = new Double_t[GetNBins(iVar)+1]; | |
332 | GetBinLimits(iVar,binLimits); | |
333 | AliInfo(Form("variable %d \t -> %s : %d bins in [%f,%f]",iVar,GetVarTitle(iVar),GetNBins(iVar),binLimits[0],binLimits[GetNBins(iVar)])); | |
334 | delete[] binLimits; | |
335 | } | |
336 | AliInfo("===================================================================================="); | |
337 | } |