2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 //--------------------------------------------------------------------//
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 //
23 // -- Author : S.Arcelli //
24 //--------------------------------------------------------------------//
28 #include "AliCFGrid.h"
29 #include "AliCFGridSparse.h"
30 #include "AliCFContainer.h"
32 //____________________________________________________________________
33 ClassImp(AliCFContainer)
35 //____________________________________________________________________
36 AliCFContainer::AliCFContainer() :
42 // default constructor
45 //____________________________________________________________________
46 AliCFContainer::AliCFContainer(const Char_t* name, const Char_t* title) :
47 AliCFFrame(name,title),
51 // default constructor
54 //____________________________________________________________________
55 AliCFContainer::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) :
56 AliCFFrame(name,title,nVarIn,nBinIn,binLimitsIn),
64 // The selection steps
68 fGrid = new AliCFVGrid*[fNStep]; //the grids at the various selection steps
70 for(Int_t istep=0;istep<fNStep;istep++){
71 sprintf(gname,"%s%s%i",GetName(),"_SelStep", istep);
73 fGrid[istep] = new AliCFGrid(gname,title,nVarIn,nBinIn,binLimitsIn);
76 fGrid[istep] = new AliCFGridSparse(gname,title,nVarIn,nBinIn,binLimitsIn);
78 fGrid[istep]->SumW2();
81 //____________________________________________________________________
82 AliCFContainer::AliCFContainer(const AliCFContainer& c) :
90 ((AliCFContainer &)c).Copy(*this);
92 //____________________________________________________________________
93 AliCFContainer::~AliCFContainer()
98 if(fGrid)delete [] fGrid;
101 //____________________________________________________________________
102 AliCFContainer &AliCFContainer::operator=(const AliCFContainer &c)
105 // assigment operator
108 ((AliCFContainer &) c).Copy(*this);
111 //____________________________________________________________________
112 void AliCFContainer::SetBinLimits(Int_t varindex, Double_t *array)
115 // setting the arrays containing the bin limits
117 Int_t nbins=fNVarBins[varindex]+1;
118 for(Int_t i=0;i<nbins;i++){
119 fVarBinLimits[fOffset[varindex]+i] =array[i];
121 for(Int_t istep=0;istep<fNStep;istep++){
122 fGrid[istep]->SetBinLimits(varindex,array);
125 //____________________________________________________________________
126 void AliCFContainer::Copy(TObject& c) const
131 AliCFContainer& target = (AliCFContainer &) c;
132 target.fNStep=fNStep;
135 target.fNVarBinLimits=fNVarBinLimits;
137 target.fNVarBins = fNVarBins;
139 target.fVarBinLimits = fVarBinLimits;
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));
148 //____________________________________________________________________
149 void AliCFContainer::Fill(Double_t *var, Int_t istep, Double_t weight)
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)
155 if(istep >= fNStep || istep < 0){
156 AliError("Non-existent selection step, grid was not filled");
159 fGrid[istep]->Fill(var,weight);
161 //___________________________________________________________________
162 TH1D *AliCFContainer::ShowProjection(Int_t ivar, Int_t istep) const
165 // returns 1-D projection along variable ivar at selection step istep
167 if(istep >= fNStep || istep < 0){
168 AliError("Non-existent selection step, return NULL");
171 if(ivar >= fNVar || ivar < 0){
172 AliError("Non-existent selection step, return NULL");
176 return fGrid[istep]->Project(ivar);
178 //___________________________________________________________________
179 TH2D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t istep) const
182 // returns 2-D projection along variables ivar1,ivar2 at selection step istep
184 if(istep >= fNStep || istep < 0){
185 AliError("Non-existent selection step, return NULL");
188 if(ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0){
189 AliError("Non-existent selection step, return NULL");
193 return fGrid[istep]->Project(ivar1,ivar2);
195 //___________________________________________________________________
196 TH3D *AliCFContainer::ShowProjection(Int_t ivar1, Int_t ivar2, Int_t ivar3, Int_t istep) const
199 // returns 3-D projection along variables ivar1,ivar2,ivar3
200 // at selection step istep
202 if(istep >= fNStep || istep < 0){
203 AliError("Non-existent selection step, return NULL");
206 if(ivar1 >= fNVar || ivar1 < 0 ||
207 ivar2 >= fNVar || ivar2 < 0 ||
208 ivar3 >= fNVar || ivar3 < 0 ) {
209 AliError("Non-existent selection step, return NULL");
213 return fGrid[istep]->Project(ivar1,ivar2,ivar3);
215 //___________________________________________________________________
216 TH1D *AliCFContainer::ShowSlice(Int_t ivar, Double_t *varMin, Double_t* varMax, Int_t istep) const
219 // Make a slice along variable ivar at selection level istep in range [varMin,varMax]
221 if(istep >= fNStep || istep < 0){
222 AliError("Non-existent selection step, return NULL");
225 if (ivar >= fNVar || ivar < 0) {
226 AliError("Non-existent variable, return NULL");
229 return (TH1D*)fGrid[istep]->Slice(ivar,varMin,varMax);
231 //___________________________________________________________________
232 TH2D *AliCFContainer::ShowSlice(Int_t ivar1, Int_t ivar2, Double_t *varMin, Double_t* varMax, Int_t istep) const
235 // Make a slice along variables ivar1 and ivar2 at selection level istep in range [varMin,varMax]
237 if(istep >= fNStep || istep < 0){
238 AliError("Non-existent selection step, return NULL");
241 if (ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0) {
242 AliError("Non-existent variable, return NULL");
245 return (TH2D*)fGrid[istep]->Slice(ivar1,ivar2,varMin,varMax);
247 //___________________________________________________________________
248 TH3D *AliCFContainer::ShowSlice(Int_t ivar1, Int_t ivar2, Int_t ivar3, Double_t *varMin, Double_t* varMax, Int_t istep) const
251 // Make a slice along variables ivar1, ivar2and ivar3 at selection level istep in range [varMin,varMax]
253 if(istep >= fNStep || istep < 0){
254 AliError("Non-existent selection step, return NULL");
257 if (ivar1 >= fNVar || ivar1 < 0 || ivar2 >= fNVar || ivar2 < 0 || ivar3 >= fNVar || ivar3 < 0) {
258 AliError("Non-existent variable, return NULL");
261 return (TH3D*)fGrid[istep]->Slice(ivar1,ivar2,ivar3,varMin,varMax);
263 //____________________________________________________________________
264 AliCFContainer* AliCFContainer::MakeSlice(Int_t nVars, Int_t* vars, Double_t* varMin, Double_t* varMax) const
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.
271 Int_t* steps = new Int_t[fNStep];
272 for (Int_t iStep=0;iStep<fNStep;iStep++) steps[iStep]=iStep;
273 return MakeSlice(nVars,vars,varMin,varMax,fNStep,steps);
276 //____________________________________________________________________
277 AliCFContainer* AliCFContainer::MakeSlice(Int_t nVars, Int_t* vars, Double_t* varMin, Double_t* varMax, Int_t nSteps, Int_t* steps) const
280 // Makes a slice along the "nVars" variables defined in the array "vars[nVars]" for the given "nSteps" defined in "steps[nSteps]".
281 // The ranges of ALL the container variables must be defined in the array varMin[fNVar] and varMax[fNVar]
282 // The function returns a new container of nVars variables.
285 if (nVars < 1 || nVars > fNVar) AliError("Bad number of dimensions required for the slice");
286 if (nSteps< 1 || nSteps> fNStep) AliError("Bad number of steps required for the slice");
288 //define new binning for new container
289 Int_t* bins=new Int_t[nVars];
290 for (Int_t iVar=0; iVar<nVars; iVar++) bins[iVar] = fNVarBins[vars[iVar]];
291 AliCFContainer* out = new AliCFContainer(fName,fTitle,nSteps,nVars,bins);
294 for (Int_t iVar=0; iVar<nVars; iVar++) {
295 Double_t *array = new Double_t[fNVarBins[vars[iVar]]+1];
296 GetBinLimits(vars[iVar],array);
297 out->SetBinLimits(iVar,array);
301 //set grid for the given steps
302 AliInfo(Form("Making a slice in %d dimension(s)",nVars));
303 for (Int_t iStep=0; iStep<nSteps; iStep++) out->SetGrid(iStep,fGrid[steps[iStep]]->Project(nVars,vars,varMin,varMax));
309 //____________________________________________________________________
310 Long64_t AliCFContainer::Merge(TCollection* list)
312 // Merge a list of AliCorrection objects with this (needed for
314 // Returns the number of merged objects (including this).
322 TIterator* iter = list->MakeIterator();
326 while ((obj = iter->Next())) {
327 AliCFContainer* entry = dynamic_cast<AliCFContainer*> (obj);
337 //____________________________________________________________________
338 void AliCFContainer::Add(AliCFContainer* aContainerToAdd, Double_t c)
341 //add the content of container aContainerToAdd to the current one
343 if( (aContainerToAdd->GetNStep()!=fNStep)
345 (aContainerToAdd->GetNVar()!=fNVar)
347 (aContainerToAdd->GetNDim()!=fNDim)){
348 AliError("Different number of steps/sensitive variables/grid elements: cannot add the containers");
351 for(Int_t istep=0;istep<fNStep;istep++){
352 fGrid[istep]->Add(aContainerToAdd->GetGrid(istep),c);
355 //____________________________________________________________________
356 Float_t AliCFContainer::GetOverFlows( Int_t ivar, Int_t istep) const {
358 // Get overflows in variable var at selection level istep
360 if(istep >= fNStep || istep < 0){
361 AliError("Non-existent selection step, return -1");
364 return fGrid[istep]->GetOverFlows(ivar);
366 //____________________________________________________________________
367 Float_t AliCFContainer::GetUnderFlows( Int_t ivar, Int_t istep) const {
369 // Get underflows in variable var at selection level istep
371 if(istep >= fNStep || istep < 0){
372 AliError("Non-existent selection step, return -1");
375 return fGrid[istep]->GetUnderFlows(ivar);
377 //____________________________________________________________________
378 Float_t AliCFContainer::GetEntries( Int_t istep) const {
380 // Get total entries in variable var at selection level istep
382 if(istep >= fNStep || istep < 0){
383 AliError("Non-existent selection step, return -1");
386 return fGrid[istep]->GetEntries();
388 //____________________________________________________________________
389 Int_t AliCFContainer::GetEmptyBins( Int_t istep) const {
391 // Get empty bins in variable var at selection level istep
393 if(istep >= fNStep || istep < 0){
394 AliError("Non-existent selection step, return -1");
397 return fGrid[istep]->GetEmptyBins();
399 //____________________________________________________________________
400 Int_t AliCFContainer::GetEmptyBins( Int_t istep, Double_t *varMin, Double_t* varMax) const {
402 // Get empty bins in a range in variable var at selection level istep
404 if(istep >= fNStep || istep < 0){
405 AliError("Non-existent selection step, return -1");
408 return fGrid[istep]->GetEmptyBins(varMin,varMax);
410 //_____________________________________________________________________
411 Double_t AliCFContainer::GetIntegral( Int_t istep) const
414 // Get Integral over the grid at selection level istep
416 if(istep >= fNStep || istep < 0){
417 AliError("Non-existent selection step, return -1");
420 return fGrid[istep]->GetIntegral();
422 //_____________________________________________________________________
423 Double_t AliCFContainer::GetIntegral( Int_t istep, Double_t *varMin, Double_t* varMax ) const
426 // Get Integral over the grid in a range at selection level istep
428 if(istep >= fNStep || istep < 0){
429 AliError("Non-existent selection step, return -1");
432 return fGrid[istep]->GetIntegral(varMin,varMax);
434 //_____________________________________________________________________
435 void AliCFContainer::SetRangeUser(Int_t ivar, Double_t varMin, Double_t varMax, Int_t istep)
438 // set axis range at step istep
440 if ( strcmp(fGrid[istep]->ClassName(),"AliCFGrid") ==0 ) {
441 AliWarning("Could not AliCFGrid::SetRangeUser(), function not implemented");
444 if (istep >= fNStep || istep < 0){
445 AliError("Non-existent selection step");
448 if (ivar >= fNVar || ivar < 0){
449 AliError("Non-existent selection var");
452 ((AliCFGridSparse*)fGrid[istep])->SetRangeUser(ivar,varMin,varMax);
455 //_____________________________________________________________________
456 void AliCFContainer::SetRangeUser(Double_t* varMin, Double_t* varMax, Int_t istep)
459 // set all axis ranges at step istep according to varMin and varMax values
461 if ( strcmp(fGrid[istep]->ClassName(),"AliCFGrid") ==0 ) {
462 AliWarning("Could not AliCFGrid::SetRangeUser(), function not implemented");
465 if (istep >= fNStep || istep < 0){
466 AliError("Non-existent selection step");
469 ((AliCFGridSparse*)fGrid[istep])->SetRangeUser(varMin,varMax);