TH2 histograms (Energy vs Time): Number of energy bins reduced.
[u/mrichter/AliRoot.git] / CORRFW / AliCFContainer.cxx
CommitLineData
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// //
9105291d 18// AliCFContainer Class //
19// Class to accumulate data on an N-dimensional grids, at different //
563113d0 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 "AliCFGrid.h"
db6722a5 29#include "AliCFGridSparse.h"
563113d0 30#include "AliCFContainer.h"
c8df672e 31#include "TAxis.h"
563113d0 32//____________________________________________________________________
33ClassImp(AliCFContainer)
34
35//____________________________________________________________________
36AliCFContainer::AliCFContainer() :
37 AliCFFrame(),
38 fNStep(0),
39 fGrid(0x0)
40{
41 //
42 // default constructor
43 //
44}
45//____________________________________________________________________
46AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title) :
47 AliCFFrame(name,title),
48 fNStep(0),
49 fGrid(0x0)
50{
51 // default constructor
52}
53
54//____________________________________________________________________
db6722a5 55AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title,const Int_t nSelSteps, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn, const Bool_t useSparse) :
563113d0 56 AliCFFrame(name,title,nVarIn,nBinIn,binLimitsIn),
57 fNStep(0),
58 fGrid(0x0)
59{
60 //
61 // main constructor
62 //
63
64 // The selection steps
65 fNStep=nSelSteps;
66
67 // The grids
1e9dad92 68 fGrid = new AliCFVGrid*[fNStep]; //the grids at the various selection steps
563113d0 69 char gname[30];
70 for(Int_t istep=0;istep<fNStep;istep++){
71 sprintf(gname,"%s%s%i",GetName(),"_SelStep", istep);
db6722a5 72 if(!useSparse){
73 fGrid[istep] = new AliCFGrid(gname,title,nVarIn,nBinIn,binLimitsIn);
74 }
75 else{
76 fGrid[istep] = new AliCFGridSparse(gname,title,nVarIn,nBinIn,binLimitsIn);
77 }
1e9dad92 78 fGrid[istep]->SumW2();
563113d0 79 }
80}
81//____________________________________________________________________
82AliCFContainer::AliCFContainer(const AliCFContainer& c) :
83 AliCFFrame(),
318f64b1 84 fNStep(c.fNStep),
318f64b1 85 fGrid(c.fGrid)
563113d0 86{
87 //
88 // copy constructor
89 //
90 ((AliCFContainer &)c).Copy(*this);
91}
92//____________________________________________________________________
93AliCFContainer::~AliCFContainer()
94{
95 //
96 // destructor
97 //
98 if(fGrid)delete [] fGrid;
99
100}
101//____________________________________________________________________
102AliCFContainer &AliCFContainer::operator=(const AliCFContainer &c)
103{
104 //
105 // assigment operator
106 //
107 if (this != &c)
108 ((AliCFContainer &) c).Copy(*this);
109 return *this;
110}
111//____________________________________________________________________
1e9dad92 112void AliCFContainer::SetBinLimits(Int_t varindex, Double_t *array)
563113d0 113{
114 //
115 // setting the arrays containing the bin limits
116 //
117 Int_t nbins=fNVarBins[varindex]+1;
118 for(Int_t i=0;i<nbins;i++){
119 fVarBinLimits[fOffset[varindex]+i] =array[i];
120 }
121 for(Int_t istep=0;istep<fNStep;istep++){
122 fGrid[istep]->SetBinLimits(varindex,array);
123 }
124}
125//____________________________________________________________________
126void AliCFContainer::Copy(TObject& c) const
127{
128 //
129 // copy function
130 //
131 AliCFContainer& target = (AliCFContainer &) c;
132 target.fNStep=fNStep;
133 target.fNVar=fNVar;
134 target.fNDim=fNDim;
135 target.fNVarBinLimits=fNVarBinLimits;
136 if (fNVarBins)
137 target.fNVarBins = fNVarBins;
138 if (fVarBinLimits)
139 target.fVarBinLimits = fVarBinLimits;
140 if (fGrid)
141 target.fGrid = fGrid;
142 for(Int_t istep=0;istep<fNStep;istep++){
143 for(Int_t iel=0;iel<fNDim;iel++){
144 target.fGrid[istep]->SetElement(iel,fGrid[istep]->GetElement(iel));
145 }
146 }
147}
148//____________________________________________________________________
1e9dad92 149void AliCFContainer::Fill(Double_t *var, Int_t istep, Double_t weight)
563113d0 150{
151 //
152 // Fills the grid at selection step istep for a set of values of the
153 // input variables, with a given weight (by default w=1)
154 //
a2255142 155 if(istep >= fNStep || istep < 0){
156 AliError("Non-existent selection step, grid was not filled");
157 return;
158 }
563113d0 159 fGrid[istep]->Fill(var,weight);
160}
161//___________________________________________________________________
1e9dad92 162TH1D *AliCFContainer::ShowProjection(Int_t ivar, Int_t istep) const
563113d0 163{
164 //
165 // returns 1-D projection along variable ivar at selection step istep
166 //
a2255142 167 if(istep >= fNStep || istep < 0){
168 AliError("Non-existent selection step, return NULL");
169 return 0x0;
170 }
9105291d 171 if(ivar >= fNVar || ivar < 0){
172 AliError("Non-existent selection step, return NULL");
173 return 0x0;
174 }
175
563113d0 176 return fGrid[istep]->Project(ivar);
177}
178//___________________________________________________________________
1e9dad92 179TH2D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t istep) const
563113d0 180{
181 //
182 // returns 2-D projection along variables ivar1,ivar2 at selection step istep
183 //
a2255142 184 if(istep >= fNStep || istep < 0){
185 AliError("Non-existent selection step, return NULL");
186 return 0x0;
187 }
9105291d 188 if(ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0){
189 AliError("Non-existent selection step, return NULL");
190 return 0x0;
191 }
192
563113d0 193 return fGrid[istep]->Project(ivar1,ivar2);
194}
195//___________________________________________________________________
1e9dad92 196TH3D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t ivar3, Int_t istep) const
563113d0 197{
198 //
199 // returns 3-D projection along variables ivar1,ivar2,ivar3
200 // at selection step istep
201 //
a2255142 202 if(istep >= fNStep || istep < 0){
203 AliError("Non-existent selection step, return NULL");
204 return 0x0;
205 }
9105291d 206 if(ivar1 >= fNVar || ivar1 < 0 ||
207 ivar2 >= fNVar || ivar2 < 0 ||
208 ivar3 >= fNVar || ivar3 < 0 ) {
209 AliError("Non-existent selection step, return NULL");
210 return 0x0;
211 }
212
563113d0 213 return fGrid[istep]->Project(ivar1,ivar2,ivar3);
214}
215//___________________________________________________________________
1e9dad92 216TH1D *AliCFContainer::ShowSlice(Int_t ivar, Double_t *varMin, Double_t* varMax, Int_t istep) const
563113d0 217{
218 //
219 // Make a slice along variable ivar at selection level istep in range [varMin,varMax]
220 //
a2255142 221 if(istep >= fNStep || istep < 0){
222 AliError("Non-existent selection step, return NULL");
223 return 0x0;
224 }
c8df672e 225 if (ivar >= fNVar || ivar < 0) {
226 AliError("Non-existent variable, return NULL");
227 return 0x0;
228 }
1e9dad92 229 return (TH1D*)fGrid[istep]->Slice(ivar,varMin,varMax);
563113d0 230}
c8df672e 231//___________________________________________________________________
232TH2D *AliCFContainer::ShowSlice(Int_t ivar1, Int_t ivar2, Double_t *varMin, Double_t* varMax, Int_t istep) const
233{
234 //
235 // Make a slice along variables ivar1 and ivar2 at selection level istep in range [varMin,varMax]
236 //
237 if(istep >= fNStep || istep < 0){
238 AliError("Non-existent selection step, return NULL");
239 return 0x0;
240 }
241 if (ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0) {
242 AliError("Non-existent variable, return NULL");
243 return 0x0;
244 }
245 return (TH2D*)fGrid[istep]->Slice(ivar1,ivar2,varMin,varMax);
246}
247//___________________________________________________________________
248TH3D *AliCFContainer::ShowSlice(Int_t ivar1, Int_t ivar2, Int_t ivar3, Double_t *varMin, Double_t* varMax, Int_t istep) const
249{
250 //
251 // Make a slice along variables ivar1, ivar2and ivar3 at selection level istep in range [varMin,varMax]
252 //
253 if(istep >= fNStep || istep < 0){
254 AliError("Non-existent selection step, return NULL");
255 return 0x0;
256 }
257 if (ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0 || ivar3 >= fNVar || ivar3 < 0) {
258 AliError("Non-existent variable, return NULL");
259 return 0x0;
260 }
261 return (TH3D*)fGrid[istep]->Slice(ivar1,ivar2,ivar3,varMin,varMax);
262}
563113d0 263//____________________________________________________________________
9105291d 264AliCFContainer* AliCFContainer::MakeSlice(Int_t nVars, Int_t* vars, Double_t* varMin, Double_t* varMax) const
265{
266 //
38b1447f 267 // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for all the container steps.
268 // The ranges of ALL the container variables must be defined in the array varMin[fNVar] and varMax[fNVar]
269 // The function returns a new container of nVars variables.
270 //
271 Int_t* steps = new Int_t[fNStep];
272 for (Int_t iStep=0;iStep<fNStep;iStep++) steps[iStep]=iStep;
9be0fa4e 273 AliCFContainer* out = MakeSlice(nVars,vars,varMin,varMax,fNStep,steps);
274 delete [] steps ;
275 return out;
38b1447f 276}
277
278//____________________________________________________________________
279AliCFContainer* AliCFContainer::MakeSlice(Int_t nVars, Int_t* vars, Double_t* varMin, Double_t* varMax, Int_t nSteps, Int_t* steps) const
280{
281 //
282 // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for the given "nSteps" defined in "steps[nSteps]".
a8b83c87 283 // The ranges of ALL the container variables must be defined in the array varMin[fNVar] and varMax[fNVar]
284 // The function returns a new container of nVars variables.
9105291d 285 //
286
287 if (nVars < 1 || nVars > fNVar) AliError("Bad number of dimensions required for the slice");
38b1447f 288 if (nSteps< 1 || nSteps> fNStep) AliError("Bad number of steps required for the slice");
9105291d 289
9be0fa4e 290 AliInfo(Form("Making a slice in %d dimension(s)",nVars));
291
292 // create the output grids
293 AliCFVGrid** grids = new AliCFVGrid*[nSteps] ;
294 for (Int_t iStep=0; iStep<nSteps; iStep++) grids[iStep] = fGrid[steps[iStep]]->Project(nVars,vars,varMin,varMax);
295
296 TAxis ** axis = new TAxis*[nVars];
297 for (Int_t iVar=0; iVar<nVars; iVar++) axis[iVar] = ((AliCFGridSparse*)grids[0])->GetGrid()->GetAxis(iVar); //same axis for every grid
298
9105291d 299 //define new binning for new container
300 Int_t* bins=new Int_t[nVars];
9be0fa4e 301 for (Int_t iVar=0; iVar<nVars; iVar++) bins[iVar] = axis[iVar]->GetNbins();
302
38b1447f 303 AliCFContainer* out = new AliCFContainer(fName,fTitle,nSteps,nVars,bins);
9105291d 304
305 //set the bin limits
306 for (Int_t iVar=0; iVar<nVars; iVar++) {
9be0fa4e 307 Int_t nBins = bins[iVar];
308 Double_t *array = new Double_t[nBins+1];
309 for (Int_t iBin=1; iBin<=nBins; iBin++) {
310 array[iBin-1] = axis[iVar]->GetBinLowEdge(iBin);
311 }
312 array[nBins] = axis[iVar]->GetBinUpEdge(nBins);
9105291d 313 out->SetBinLimits(iVar,array);
9be0fa4e 314 delete [] array;
9105291d 315 }
316
38b1447f 317 //set grid for the given steps
9be0fa4e 318 for (Int_t iStep=0; iStep<nSteps; iStep++) out->SetGrid(iStep,grids[iStep]);
9105291d 319
320 delete bins;
9be0fa4e 321 delete [] axis ;
9105291d 322 return out;
323}
324
325//____________________________________________________________________
563113d0 326Long64_t AliCFContainer::Merge(TCollection* list)
327{
328 // Merge a list of AliCorrection objects with this (needed for
329 // PROOF).
330 // Returns the number of merged objects (including this).
331
332 if (!list)
333 return 0;
334
335 if (list->IsEmpty())
336 return 1;
337
338 TIterator* iter = list->MakeIterator();
339 TObject* obj;
340
341 Int_t count = 0;
342 while ((obj = iter->Next())) {
343 AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj);
344 if (entry == 0)
345 continue;
346 this->Add(entry);
347 count++;
348 }
349
350 return count+1;
351}
352
353//____________________________________________________________________
1e9dad92 354void AliCFContainer::Add(AliCFContainer* aContainerToAdd, Double_t c)
563113d0 355{
356 //
357 //add the content of container aContainerToAdd to the current one
358 //
a2255142 359 if( (aContainerToAdd->GetNStep()!=fNStep)
360 ||
361 (aContainerToAdd->GetNVar()!=fNVar)
362 ||
363 (aContainerToAdd->GetNDim()!=fNDim)){
364 AliError("Different number of steps/sensitive variables/grid elements: cannot add the containers");
365 return;
366 }
563113d0 367 for(Int_t istep=0;istep<fNStep;istep++){
368 fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c);
369 }
370}
371//____________________________________________________________________
372Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep) const {
373 //
374 // Get overflows in variable var at selection level istep
375 //
a2255142 376 if(istep >= fNStep || istep < 0){
377 AliError("Non-existent selection step, return -1");
378 return -1.;
379 }
563113d0 380 return fGrid[istep]->GetOverFlows(ivar);
381}
382//____________________________________________________________________
563113d0 383Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep) const {
384 //
a2255142 385 // Get underflows in variable var at selection level istep
563113d0 386 //
a2255142 387 if(istep >= fNStep || istep < 0){
388 AliError("Non-existent selection step, return -1");
389 return -1.;
390 }
563113d0 391 return fGrid[istep]->GetUnderFlows(ivar);
392}
393//____________________________________________________________________
563113d0 394Float_t AliCFContainer::GetEntries( Int_t istep) const {
395 //
a2255142 396 // Get total entries in variable var at selection level istep
563113d0 397 //
a2255142 398 if(istep >= fNStep || istep < 0){
399 AliError("Non-existent selection step, return -1");
400 return -1.;
401 }
563113d0 402 return fGrid[istep]->GetEntries();
403}
404//____________________________________________________________________
405Int_t AliCFContainer::GetEmptyBins( Int_t istep) const {
406 //
a2255142 407 // Get empty bins in variable var at selection level istep
563113d0 408 //
a2255142 409 if(istep >= fNStep || istep < 0){
410 AliError("Non-existent selection step, return -1");
411 return -1;
412 }
563113d0 413 return fGrid[istep]->GetEmptyBins();
414}
415//____________________________________________________________________
1e9dad92 416Int_t AliCFContainer::GetEmptyBins( Int_t istep, Double_t *varMin, Double_t* varMax) const {
563113d0 417 //
a2255142 418 // Get empty bins in a range in variable var at selection level istep
563113d0 419 //
a2255142 420 if(istep >= fNStep || istep < 0){
421 AliError("Non-existent selection step, return -1");
422 return -1;
423 }
563113d0 424 return fGrid[istep]->GetEmptyBins(varMin,varMax);
425}
426//_____________________________________________________________________
1e9dad92 427Double_t AliCFContainer::GetIntegral( Int_t istep) const
563113d0 428{
429 //
a2255142 430 // Get Integral over the grid at selection level istep
563113d0 431 //
a2255142 432 if(istep >= fNStep || istep < 0){
433 AliError("Non-existent selection step, return -1");
434 return -1.;
435 }
563113d0 436 return fGrid[istep]->GetIntegral();
437}
438//_____________________________________________________________________
1e9dad92 439Double_t AliCFContainer::GetIntegral( Int_t istep, Double_t *varMin, Double_t* varMax ) const
563113d0 440{
441 //
a2255142 442 // Get Integral over the grid in a range at selection level istep
563113d0 443 //
a2255142 444 if(istep >= fNStep || istep < 0){
445 AliError("Non-existent selection step, return -1");
446 return -1.;
447 }
563113d0 448 return fGrid[istep]->GetIntegral(varMin,varMax);
449}
c8df672e 450//_____________________________________________________________________
451void AliCFContainer::SetRangeUser(Int_t ivar, Double_t varMin, Double_t varMax, Int_t istep)
452{
453 //
454 // set axis range at step istep
455 //
456 if ( strcmp(fGrid[istep]->ClassName(),"AliCFGrid") ==0 ) {
457 AliWarning("Could not AliCFGrid::SetRangeUser(), function not implemented");
458 return;
459 }
460 if (istep >= fNStep || istep < 0){
461 AliError("Non-existent selection step");
462 return ;
463 }
464 if (ivar >= fNVar || ivar < 0){
465 AliError("Non-existent selection var");
466 return ;
467 }
9105291d 468 ((AliCFGridSparse*)fGrid[istep])->SetRangeUser(ivar,varMin,varMax);
469}
470
471//_____________________________________________________________________
472void AliCFContainer::SetRangeUser(Double_t* varMin, Double_t* varMax, Int_t istep)
473{
474 //
475 // set all axis ranges at step istep according to varMin and varMax values
476 //
477 if ( strcmp(fGrid[istep]->ClassName(),"AliCFGrid") ==0 ) {
478 AliWarning("Could not AliCFGrid::SetRangeUser(), function not implemented");
479 return;
480 }
481 if (istep >= fNStep || istep < 0){
482 AliError("Non-existent selection step");
483 return ;
484 }
485 ((AliCFGridSparse*)fGrid[istep])->SetRangeUser(varMin,varMax);
c8df672e 486}