]>
Commit | Line | Data |
---|---|---|
db6722a5 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | //--------------------------------------------------------------------// | |
16 | // // | |
17 | // AliCFGridSparse Class // | |
18 | // Class to accumulate data on an N-dimensional grid, to be used // | |
19 | // as input to get corrections for Reconstruction & Trigger efficiency// | |
20 | // Based on root THnSparse // | |
21 | // -- Author : S.Arcelli // | |
22 | // Still to be done: // | |
23 | // --Interpolate among bins in a range // | |
24 | //--------------------------------------------------------------------// | |
25 | // | |
26 | // | |
27 | #include "AliCFGridSparse.h" | |
28 | #include "THnSparse.h" | |
29 | #include "AliLog.h" | |
30 | #include "TMath.h" | |
31 | #include "TROOT.h" | |
32 | #include "TH1D.h" | |
33 | #include "TH2D.h" | |
34 | #include "TH3D.h" | |
35 | #include "TAxis.h" | |
36 | ||
37 | //____________________________________________________________________ | |
38 | ClassImp(AliCFGridSparse) | |
39 | ||
40 | //____________________________________________________________________ | |
41 | AliCFGridSparse::AliCFGridSparse() : | |
42 | AliCFVGrid(), | |
db6722a5 | 43 | fData(0x0) |
44 | { | |
45 | // default constructor | |
46 | } | |
47 | //____________________________________________________________________ | |
48 | AliCFGridSparse::AliCFGridSparse(const Char_t* name, const Char_t* title) : | |
49 | AliCFVGrid(name,title), | |
db6722a5 | 50 | fData(0x0) |
51 | { | |
52 | // default constructor | |
53 | } | |
54 | //____________________________________________________________________ | |
55 | AliCFGridSparse::AliCFGridSparse(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn) : | |
56 | AliCFVGrid(name,title,nVarIn,nBinIn,binLimitsIn), | |
db6722a5 | 57 | fData(0x0) |
58 | { | |
59 | // | |
60 | // main constructor | |
61 | // | |
62 | ||
63 | fData=new THnSparseF(name,title,fNVar,fNVarBins); | |
64 | ||
65 | if(binLimitsIn){ | |
66 | for(Int_t ivar=0;ivar<fNVar;ivar++){ | |
67 | Int_t nbins=fNVarBins[ivar]+1; | |
68 | Double_t *array= new Double_t[nbins]; | |
69 | for(Int_t i=0;i<nbins;i++){ | |
70 | array[i]=fVarBinLimits[fOffset[ivar]+i]; | |
71 | } | |
72 | fData->SetBinEdges(ivar, array); | |
73 | delete array; | |
74 | } | |
75 | } | |
76 | } | |
77 | //____________________________________________________________________ | |
78 | AliCFGridSparse::AliCFGridSparse(const AliCFGridSparse& c) : | |
79 | AliCFVGrid(c), | |
db6722a5 | 80 | fData(c.fData) |
81 | { | |
82 | // | |
83 | // copy constructor | |
84 | // | |
85 | ((AliCFGridSparse &)c).Copy(*this); | |
86 | } | |
87 | ||
88 | //____________________________________________________________________ | |
89 | AliCFGridSparse::~AliCFGridSparse() | |
90 | { | |
91 | // | |
92 | // destructor | |
93 | // | |
94 | if(fData) delete fData; | |
95 | } | |
96 | ||
97 | //____________________________________________________________________ | |
98 | AliCFGridSparse &AliCFGridSparse::operator=(const AliCFGridSparse &c) | |
99 | { | |
100 | // | |
101 | // assigment operator | |
102 | // | |
103 | if (this != &c) | |
104 | ((AliCFGridSparse &) c).Copy(*this); | |
105 | return *this; | |
106 | } | |
107 | ||
108 | //____________________________________________________________________ | |
109 | void AliCFGridSparse::SetBinLimits(Int_t ivar, Double_t *array) | |
110 | { | |
111 | // | |
112 | // setting the arrays containing the bin limits | |
113 | // | |
114 | fData->SetBinEdges(ivar, array); | |
115 | //then fill the appropriate array in ALICFFrame, to be able to use | |
116 | //the getter, in case.... | |
117 | Int_t nbins=fNVarBins[ivar]+1; | |
118 | for(Int_t i=0;i<nbins;i++){ | |
119 | fVarBinLimits[fOffset[ivar]+i] =array[i]; | |
120 | } | |
121 | } | |
122 | ||
123 | //____________________________________________________________________ | |
124 | void AliCFGridSparse::Fill(Double_t *var, Double_t weight) | |
125 | { | |
126 | // | |
127 | // Fill the grid, | |
128 | // given a set of values of the input variable, | |
129 | // with weight (by default w=1) | |
130 | // | |
131 | fData->Fill(var,weight); | |
132 | } | |
133 | ||
134 | //___________________________________________________________________ | |
135 | TH1D *AliCFGridSparse::Project(Int_t ivar) const | |
136 | { | |
137 | // | |
138 | // Make a 1D projection along variable ivar | |
139 | // | |
140 | ||
db6722a5 | 141 | TH1D *hist=fData->Projection(ivar); |
db6722a5 | 142 | return hist; |
db6722a5 | 143 | } |
144 | //___________________________________________________________________ | |
145 | TH2D *AliCFGridSparse::Project(Int_t ivar1, Int_t ivar2) const | |
146 | { | |
147 | // | |
148 | // Make a 2D projection along variables ivar1 & ivar2 | |
149 | // | |
150 | ||
318f64b1 | 151 | TH2D *hist=fData->Projection(ivar2,ivar1); //notice inverted axis (THnSparse uses TH3 2d-projection convention...) |
db6722a5 | 152 | return hist; |
153 | ||
154 | } | |
155 | //___________________________________________________________________ | |
156 | TH3D *AliCFGridSparse::Project(Int_t ivar1, Int_t ivar2, Int_t ivar3) const | |
157 | { | |
158 | // | |
159 | // Make a 3D projection along variables ivar1 & ivar2 & ivar3 | |
160 | // | |
db6722a5 | 161 | |
162 | TH3D *hist=fData->Projection(ivar1,ivar2,ivar3); | |
db6722a5 | 163 | return hist; |
164 | ||
165 | } | |
166 | ||
9105291d | 167 | //___________________________________________________________________ |
168 | AliCFGridSparse* AliCFGridSparse::Project(Int_t nVars, Int_t* vars, Double_t* varMin, Double_t* varMax) const | |
169 | { | |
38b1447f | 170 | // |
171 | // projects the grid on the nVars dimensions defined in vars. | |
172 | // axis ranges can be defined in arrays varMin, varMax | |
173 | // | |
9105291d | 174 | |
175 | // binning for new grid | |
176 | Int_t* bins = new Int_t[nVars]; | |
177 | for (Int_t iVar=0; iVar<nVars; iVar++) { | |
178 | bins[iVar] = fNVarBins[vars[iVar]]; | |
179 | } | |
180 | ||
181 | // create new grid sparse | |
182 | AliCFGridSparse* out = new AliCFGridSparse(fName,fTitle,nVars,bins); | |
183 | ||
184 | //set the range in the THnSparse to project | |
185 | THnSparse* clone = ((THnSparse*)fData->Clone()); | |
38b1447f | 186 | if (varMin && varMax) { |
187 | for (Int_t iAxis=0; iAxis<fNVar; iAxis++) { | |
188 | clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); | |
189 | } | |
9105291d | 190 | } |
38b1447f | 191 | else AliInfo("Keeping same axis ranges"); |
192 | ||
9105291d | 193 | out->SetGrid(clone->Projection(nVars,vars)); |
194 | return out; | |
195 | } | |
196 | ||
db6722a5 | 197 | //____________________________________________________________________ |
198 | Float_t AliCFGridSparse::GetOverFlows(Int_t ivar) const | |
199 | { | |
200 | // | |
318f64b1 | 201 | // Returns exclusive overflows in variable ivar |
db6722a5 | 202 | // |
7411edfd | 203 | Int_t* bin = new Int_t[fNVar]; |
204 | memset(bin, 0, sizeof(Int_t) * fNVar); | |
db6722a5 | 205 | Float_t ovfl=0.; |
206 | for (Long64_t i = 0; i < fData->GetNbins(); ++i) { | |
207 | Double_t v = fData->GetBinContent(i, bin); | |
208 | Bool_t add=kTRUE; | |
209 | for(Int_t j=0;j<fNVar;j++){ | |
210 | if(ivar==j)continue; | |
211 | if((bin[j]==0) || (bin[j]==fNVarBins[j]+1))add=kFALSE; | |
212 | } | |
213 | if(bin[ivar]==fNVarBins[ivar]+1 && add) ovfl+=v; | |
214 | } | |
215 | ||
216 | delete[] bin; | |
217 | return ovfl; | |
218 | } | |
219 | ||
220 | //____________________________________________________________________ | |
221 | Float_t AliCFGridSparse::GetUnderFlows(Int_t ivar) const | |
222 | { | |
223 | // | |
318f64b1 | 224 | // Returns exclusive overflows in variable ivar |
db6722a5 | 225 | // |
7411edfd | 226 | Int_t* bin = new Int_t[fNVar]; |
227 | memset(bin, 0, sizeof(Int_t) * fNVar); | |
db6722a5 | 228 | Float_t unfl=0.; |
229 | for (Long64_t i = 0; i < fData->GetNbins(); ++i) { | |
230 | Double_t v = fData->GetBinContent(i, bin); | |
231 | Bool_t add=kTRUE; | |
232 | for(Int_t j=0;j<fNVar;j++){ | |
233 | if(ivar==j)continue; | |
234 | if((bin[j]==0) || (bin[j]==fNVarBins[j]+1))add=kFALSE; | |
235 | } | |
236 | if(bin[ivar]==0 && add) unfl+=v; | |
237 | } | |
238 | ||
239 | delete[] bin; | |
240 | return unfl; | |
241 | } | |
242 | ||
243 | ||
244 | //____________________________________________________________________ | |
245 | Float_t AliCFGridSparse::GetEntries() const | |
246 | { | |
247 | // | |
248 | // total entries (including overflows and underflows) | |
249 | // | |
250 | ||
251 | return fData->GetEntries(); | |
252 | } | |
253 | ||
254 | //____________________________________________________________________ | |
255 | Float_t AliCFGridSparse::GetElement(Int_t index) const | |
256 | { | |
257 | // | |
258 | // Returns content of grid element index according to the | |
259 | // linear indexing in AliCFFrame | |
260 | // | |
261 | Int_t *bin = new Int_t[fNVar]; | |
262 | GetBinIndex(index, bin); | |
263 | for(Int_t i=0;i<fNVar;i++)fIndex[i]=bin[i]+1; //consistency with AliCFGrid | |
264 | Float_t val=GetElement(fIndex); | |
265 | delete [] bin; | |
266 | return val; | |
267 | ||
268 | } | |
269 | //____________________________________________________________________ | |
270 | Float_t AliCFGridSparse::GetElement(Int_t *bin) const | |
271 | { | |
272 | // | |
273 | // Get the content in a bin corresponding to a set of bin indexes | |
274 | // | |
275 | return fData->GetBinContent(bin); | |
276 | ||
277 | } | |
278 | //____________________________________________________________________ | |
279 | Float_t AliCFGridSparse::GetElement(Double_t *var) const | |
280 | { | |
281 | // | |
282 | // Get the content in a bin corresponding to a set of input variables | |
283 | // | |
284 | ||
285 | Long_t index=fData->GetBin(var,kFALSE); //this is the THnSparse index (do not allocate new cells if content is empty) | |
286 | if(index<0){ | |
287 | return 0.; | |
288 | }else{ | |
289 | return fData->GetBinContent(index); | |
290 | } | |
291 | } | |
292 | ||
293 | //____________________________________________________________________ | |
294 | Float_t AliCFGridSparse::GetElementError(Int_t index) const | |
295 | { | |
296 | // | |
297 | // Returns the error on the content of a bin according to a linear | |
298 | // indexing in AliCFFrame | |
299 | // | |
300 | ||
301 | Int_t *bin = new Int_t[fNVar]; | |
302 | GetBinIndex(index, bin); | |
303 | for(Int_t i=0;i<fNVar;i++)fIndex[i]=bin[i]+1; //consistency with AliCFGrid | |
304 | Float_t val=GetElementError(fIndex); | |
305 | delete [] bin; | |
306 | return val; | |
307 | ||
308 | } | |
309 | //____________________________________________________________________ | |
310 | Float_t AliCFGridSparse::GetElementError(Int_t *bin) const | |
311 | { | |
312 | // | |
313 | // Get the error in a bin corresponding to a set of bin indexes | |
314 | // | |
315 | return fData->GetBinError(bin); | |
316 | ||
317 | } | |
318 | //____________________________________________________________________ | |
319 | Float_t AliCFGridSparse::GetElementError(Double_t *var) const | |
320 | { | |
321 | // | |
322 | // Get the error in a bin corresponding to a set of input variables | |
323 | // | |
324 | ||
325 | Long_t index=fData->GetBin(var,kFALSE); //this is the THnSparse index (do not allocate new cells if content is empy) | |
326 | if(index<0){ | |
327 | return 0.; | |
328 | }else{ | |
329 | return fData->GetBinError(index); | |
330 | } | |
331 | } | |
332 | ||
333 | ||
334 | //____________________________________________________________________ | |
335 | void AliCFGridSparse::SetElement(Int_t index, Float_t val) | |
336 | { | |
337 | // | |
338 | // Sets grid element iel to val (linear indexing) in AliCFFrame | |
339 | // | |
340 | Int_t *bin = new Int_t[fNVar]; | |
341 | GetBinIndex(index, bin); | |
342 | for(Int_t i=0;i<fNVar;i++)fIndex[i]=bin[i]+1; | |
343 | SetElement(fIndex,val); | |
344 | delete [] bin; | |
345 | } | |
346 | //____________________________________________________________________ | |
347 | void AliCFGridSparse::SetElement(Int_t *bin, Float_t val) | |
348 | { | |
349 | // | |
350 | // Sets grid element of bin indeces bin to val | |
351 | // | |
da2a218a | 352 | |
353 | AliWarning("Important: bins should be numbered from 1 to NBins"); | |
db6722a5 | 354 | fData->SetBinContent(bin,val); |
355 | } | |
356 | //____________________________________________________________________ | |
357 | void AliCFGridSparse::SetElement(Double_t *var, Float_t val) | |
358 | { | |
359 | // | |
360 | // Set the content in a bin to value val corresponding to a set of input variables | |
361 | // | |
362 | Long_t index=fData->GetBin(var); //THnSparse index: allocate the cell | |
363 | Int_t *bin = new Int_t[fNVar]; | |
364 | fData->GetBinContent(index,bin); //trick to access the array of bins | |
365 | fData->SetBinContent(bin,val); | |
366 | delete [] bin; | |
367 | ||
368 | } | |
369 | ||
370 | //____________________________________________________________________ | |
371 | void AliCFGridSparse::SetElementError(Int_t index, Float_t val) | |
372 | { | |
373 | // | |
374 | // Sets grid element iel error to val (linear indexing) in AliCFFrame | |
375 | // | |
376 | Int_t *bin = new Int_t[fNVar]; | |
377 | GetBinIndex(index, bin); | |
378 | for(Int_t i=0;i<fNVar;i++)fIndex[i]=bin[i]+1; | |
379 | SetElementError(fIndex,val); | |
380 | delete [] bin; | |
381 | } | |
382 | //____________________________________________________________________ | |
383 | void AliCFGridSparse::SetElementError(Int_t *bin, Float_t val) | |
384 | { | |
385 | // | |
386 | // Sets grid element error of bin indeces bin to val | |
387 | // | |
388 | fData->SetBinError(bin,val); | |
389 | } | |
390 | //____________________________________________________________________ | |
391 | void AliCFGridSparse::SetElementError(Double_t *var, Float_t val) | |
392 | { | |
393 | // | |
394 | // Set the error in a bin to value val corresponding to a set of input variables | |
395 | // | |
396 | Long_t index=fData->GetBin(var); //THnSparse index | |
397 | Int_t *bin = new Int_t[fNVar]; | |
398 | fData->GetBinContent(index,bin); //trick to access the array of bins | |
399 | fData->SetBinError(bin,val); | |
400 | delete [] bin; | |
401 | } | |
402 | ||
403 | //____________________________________________________________________ | |
404 | void AliCFGridSparse::SumW2() | |
405 | { | |
406 | // | |
407 | //set calculation of the squared sum of the weighted entries | |
408 | // | |
409 | if(!fSumW2){ | |
410 | fData->CalculateErrors(kTRUE); | |
411 | } | |
412 | ||
413 | fSumW2=kTRUE; | |
414 | } | |
415 | ||
416 | //____________________________________________________________________ | |
9be0fa4e | 417 | void AliCFGridSparse::Add(const AliCFVGrid* aGrid, Double_t c) |
db6722a5 | 418 | { |
419 | // | |
420 | //add aGrid to the current one | |
421 | // | |
422 | ||
423 | ||
424 | if(aGrid->GetNVar()!=fNVar){ | |
425 | AliInfo("Different number of variables, cannot add the grids"); | |
426 | return; | |
427 | } | |
db6722a5 | 428 | |
429 | if(!fSumW2 && aGrid->GetSumW2())SumW2(); | |
430 | ||
db6722a5 | 431 | fData->Add(((AliCFGridSparse*)aGrid)->GetGrid(),c); |
db6722a5 | 432 | } |
433 | ||
434 | //____________________________________________________________________ | |
9be0fa4e | 435 | void AliCFGridSparse::Add(const AliCFVGrid* aGrid1, const AliCFVGrid* aGrid2, Double_t c1,Double_t c2) |
db6722a5 | 436 | { |
437 | // | |
438 | //Add aGrid1 and aGrid2 and deposit the result into the current one | |
439 | // | |
440 | ||
441 | if(fNVar!=aGrid1->GetNVar()|| fNVar!=aGrid2->GetNVar()){ | |
442 | AliInfo("Different number of variables, cannot add the grids"); | |
443 | return; | |
444 | } | |
db6722a5 | 445 | |
446 | if(!fSumW2 && (aGrid1->GetSumW2() || aGrid2->GetSumW2()))SumW2(); | |
447 | ||
448 | ||
449 | fData->Reset(); | |
450 | fData->Add(((AliCFGridSparse*)aGrid1)->GetGrid(),c1); | |
451 | fData->Add(((AliCFGridSparse*)aGrid2)->GetGrid(),c2); | |
452 | ||
453 | } | |
454 | ||
455 | //____________________________________________________________________ | |
9be0fa4e | 456 | void AliCFGridSparse::Multiply(const AliCFVGrid* aGrid, Double_t c) |
db6722a5 | 457 | { |
458 | // | |
459 | // Multiply aGrid to the current one | |
460 | // | |
461 | ||
462 | ||
463 | if(aGrid->GetNVar()!=fNVar){ | |
464 | AliInfo("Different number of variables, cannot multiply the grids"); | |
465 | return; | |
466 | } | |
db6722a5 | 467 | |
468 | if(!fSumW2 && aGrid->GetSumW2())SumW2(); | |
469 | ||
470 | THnSparse *h= ((AliCFGridSparse*)aGrid)->GetGrid(); | |
471 | ||
472 | fData->Multiply(h); | |
473 | fData->Scale(c); | |
474 | ||
475 | } | |
476 | ||
477 | //____________________________________________________________________ | |
9be0fa4e | 478 | void AliCFGridSparse::Multiply(const AliCFVGrid* aGrid1, const AliCFVGrid* aGrid2, Double_t c1,Double_t c2) |
db6722a5 | 479 | { |
480 | // | |
481 | //Multiply aGrid1 and aGrid2 and deposit the result into the current one | |
482 | // | |
483 | ||
484 | if(fNVar!=aGrid1->GetNVar()|| fNVar!=aGrid2->GetNVar()){ | |
485 | AliInfo("Different number of variables, cannot multiply the grids"); | |
486 | return; | |
487 | } | |
db6722a5 | 488 | |
489 | if(!fSumW2 && (aGrid1->GetSumW2() || aGrid2->GetSumW2()))SumW2(); | |
490 | ||
491 | ||
492 | fData->Reset(); | |
493 | THnSparse *h1= ((AliCFGridSparse*)aGrid1)->GetGrid(); | |
494 | THnSparse *h2= ((AliCFGridSparse*)aGrid2)->GetGrid(); | |
495 | h2->Multiply(h1); | |
496 | h2->Scale(c1*c2); | |
497 | fData->Add(h2); | |
498 | } | |
499 | ||
500 | ||
501 | ||
502 | //____________________________________________________________________ | |
9be0fa4e | 503 | void AliCFGridSparse::Divide(const AliCFVGrid* aGrid, Double_t c) |
db6722a5 | 504 | { |
505 | // | |
506 | // Divide aGrid to the current one | |
507 | // | |
508 | ||
509 | ||
510 | if(aGrid->GetNVar()!=fNVar){ | |
511 | AliInfo("Different number of variables, cannot divide the grids"); | |
512 | return; | |
513 | } | |
db6722a5 | 514 | |
515 | if(!fSumW2 && aGrid->GetSumW2())SumW2(); | |
516 | ||
517 | THnSparse *h= ((AliCFGridSparse*)aGrid)->GetGrid(); | |
518 | ||
519 | fData->Divide(h); | |
520 | fData->Scale(c); | |
521 | ||
522 | } | |
523 | ||
524 | //____________________________________________________________________ | |
9be0fa4e | 525 | void AliCFGridSparse::Divide(const AliCFVGrid* aGrid1, const AliCFVGrid* aGrid2, Double_t c1,Double_t c2, Option_t *option) |
db6722a5 | 526 | { |
527 | // | |
528 | //Divide aGrid1 and aGrid2 and deposit the result into the current one | |
529 | //bynomial errors are supported | |
530 | // | |
531 | ||
532 | if(fNVar!=aGrid1->GetNVar()|| fNVar!=aGrid2->GetNVar()){ | |
533 | AliInfo("Different number of variables, cannot divide the grids"); | |
534 | return; | |
535 | } | |
9be0fa4e | 536 | // if(fNDim!=aGrid1->GetNDim()|| fNDim!=aGrid2->GetNDim()){ |
537 | // AliInfo("Different number of dimensions, cannot divide the grids!"); | |
538 | // return; | |
539 | // } | |
db6722a5 | 540 | |
541 | if(!fSumW2 && (aGrid1->GetSumW2() || aGrid2->GetSumW2()))SumW2(); | |
542 | ||
543 | ||
544 | THnSparse *h1= ((AliCFGridSparse*)aGrid1)->GetGrid(); | |
545 | THnSparse *h2= ((AliCFGridSparse*)aGrid2)->GetGrid(); | |
546 | fData->Divide(h1,h2,c1,c2,option); | |
547 | } | |
548 | ||
549 | ||
7411edfd | 550 | //____________________________________________________________________ |
551 | void AliCFGridSparse::Rebin(const Int_t* group) | |
552 | { | |
553 | // | |
554 | // rebin the grid according to Rebin() as in THnSparse | |
555 | // Please notice that the original number of bins on | |
556 | // a given axis has to be divisible by the rebin group. | |
557 | // | |
558 | ||
559 | for(Int_t i=0;i<fNVar;i++){ | |
560 | if(group[i]!=1)AliInfo(Form(" merging bins along dimension %i in groups of %i bins", i,group[i])); | |
561 | } | |
562 | ||
563 | THnSparse *rebinned =fData->Rebin(group); | |
564 | fData->Reset(); | |
565 | fData = rebinned; | |
566 | ||
567 | //redefine the needed stuff | |
568 | ||
569 | Int_t ndimTot=1; | |
570 | Int_t nbinTot=0; | |
571 | ||
572 | //number of bins in each dimension, auxiliary variables | |
573 | ||
574 | for(Int_t ivar=0;ivar<fNVar;ivar++){ | |
575 | Int_t nbins = fData->GetAxis(ivar)->GetNbins(); | |
576 | fNVarBins[ivar]=nbins; | |
577 | ndimTot*=fNVarBins[ivar]; | |
578 | nbinTot+=(fNVarBins[ivar]+1); | |
579 | Int_t offset=0; | |
580 | for(Int_t i =0;i<ivar;i++)offset+=(fNVarBins[i]+1); | |
581 | fOffset[ivar]=offset; | |
582 | Int_t prod=1; | |
583 | for(Int_t i=0;i<ivar;i++)prod*=fNVarBins[i]; | |
584 | fProduct[ivar]=prod; | |
585 | } | |
586 | ||
587 | fNDim=ndimTot; | |
588 | ||
589 | //now the array of bin limits | |
590 | ||
591 | delete fVarBinLimits; | |
592 | fNVarBinLimits=nbinTot; | |
593 | fVarBinLimits=new Double_t[fNVarBinLimits]; | |
594 | ||
595 | for(Int_t ivar=0;ivar<fNVar;ivar++){ | |
596 | Double_t low = fData->GetAxis(ivar)->GetXmin(); | |
597 | Double_t high = fData->GetAxis(ivar)->GetXmax(); | |
598 | const TArrayD *xbins = fData->GetAxis(ivar)->GetXbins(); | |
599 | if (xbins->fN == 0){ | |
600 | for(Int_t ibin=0;ibin<=fNVarBins[ivar];ibin++){ | |
601 | fVarBinLimits[ibin+fOffset[ivar]] = low + ibin*(high-low)/((Double_t) fNVarBins[ivar]); | |
602 | } | |
603 | } | |
604 | else{ | |
605 | ||
606 | for(Int_t ibin=0;ibin<=fNVarBins[ivar];ibin++) { | |
607 | fVarBinLimits[ibin+fOffset[ivar]] = xbins->At(ibin); | |
608 | } | |
609 | } | |
610 | } | |
611 | ||
612 | } | |
db6722a5 | 613 | //____________________________________________________________________ |
614 | void AliCFGridSparse::Copy(TObject& c) const | |
615 | { | |
616 | // | |
617 | // copy function | |
618 | // | |
619 | AliCFGridSparse& target = (AliCFGridSparse &) c; | |
620 | ||
621 | if(fData)target.fData = fData; | |
622 | } | |
623 | ||
c8df672e | 624 | //____________________________________________________________________ |
625 | TH1D* AliCFGridSparse::Slice(Int_t iVar, Double_t *varMin, Double_t *varMax) const | |
626 | { | |
627 | // | |
628 | // return a slice (1D-projection) on variable iVar while axis ranges are defined with varMin,varMax | |
629 | // arrays varMin and varMax contain the min and max values of each variable. | |
630 | // therefore varMin and varMax must have their dimensions equal to fNVar | |
631 | // | |
632 | ||
633 | THnSparse* clone = (THnSparse*)fData->Clone(); | |
634 | for (Int_t iAxis=0; iAxis<fNVar; iAxis++) { | |
635 | clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); | |
636 | } | |
637 | return clone->Projection(iVar); | |
638 | } | |
639 | ||
640 | //____________________________________________________________________ | |
641 | TH2D* AliCFGridSparse::Slice(Int_t iVar1, Int_t iVar2, Double_t *varMin, Double_t *varMax) const | |
642 | { | |
643 | // | |
644 | // return a slice (2D-projection) on variables iVar1 and iVar2 while axis ranges are defined with varMin,varMax | |
645 | // arrays varMin and varMax contain the min and max values of each variable. | |
646 | // therefore varMin and varMax must have their dimensions equal to fNVar | |
647 | // | |
648 | ||
649 | THnSparse* clone = (THnSparse*)fData->Clone(); | |
650 | for (Int_t iAxis=0; iAxis<fNVar; iAxis++) { | |
651 | clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); | |
652 | } | |
653 | return clone->Projection(iVar1,iVar2); | |
654 | } | |
655 | ||
656 | //____________________________________________________________________ | |
657 | TH3D* AliCFGridSparse::Slice(Int_t iVar1, Int_t iVar2, Int_t iVar3, Double_t *varMin, Double_t *varMax) const | |
658 | { | |
659 | // | |
660 | // return a slice (3D-projection) on variables iVar1, iVar2 and iVar3 while axis ranges are defined with varMin,varMax | |
661 | // arrays varMin and varMax contain the min and max values of each variable. | |
662 | // therefore varMin and varMax must have their dimensions equal to fNVar | |
663 | // | |
664 | ||
665 | THnSparse* clone = (THnSparse*)fData->Clone(); | |
666 | for (Int_t iAxis=0; iAxis<fNVar; iAxis++) { | |
667 | clone->GetAxis(iAxis)->SetRangeUser(varMin[iAxis],varMax[iAxis]); | |
668 | } | |
669 | return clone->Projection(iVar1,iVar2,iVar3); | |
670 | } | |
671 | ||
9105291d | 672 | //____________________________________________________________________ |
673 | void AliCFGridSparse::SetRangeUser(Int_t iVar, Double_t varMin, Double_t varMax) { | |
674 | // | |
675 | // set range of axis iVar. | |
676 | // | |
677 | fData->GetAxis(iVar)->SetRangeUser(varMin,varMax); | |
678 | AliWarning(Form("THnSparse axis %d range has been modified",iVar)); | |
679 | } | |
680 | ||
c8df672e | 681 | //____________________________________________________________________ |
682 | void AliCFGridSparse::SetRangeUser(Double_t *varMin, Double_t *varMax) { | |
683 | // | |
684 | // set range of every axis. varMin and varMax must be of dimension fNVar | |
685 | // | |
686 | for (Int_t iAxis=0; iAxis<fNVar ; iAxis++) { // set new range for every axis | |
9105291d | 687 | SetRangeUser(iAxis,varMin[iAxis],varMax[iAxis]); |
c8df672e | 688 | } |
9105291d | 689 | AliWarning("THnSparse axes ranges have been modified"); |
690 | } | |
691 | ||
692 | //____________________________________________________________________ | |
693 | void AliCFGridSparse::UseAxisRange(Bool_t b) const { | |
694 | for (Int_t iAxis=0; iAxis<fNVar; iAxis++) fData->GetAxis(iAxis)->SetBit(TAxis::kAxisRange,b); | |
c8df672e | 695 | } |