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 // AliCFFrame Class //
19 // Class to accumulate data on an N-dimensional grid, to be used //
20 // as input to get corrections for Reconstruction & Trigger efficiency//
22 // -- Author : S.Arcelli //
23 // Still to be done: //
24 // --Implement methods to merge cells //
25 // --Interpolate among bins in a range //
26 //--------------------------------------------------------------------//
33 #include "AliCFFrame.h"
35 //____________________________________________________________________
38 //____________________________________________________________________
39 AliCFFrame::AliCFFrame() :
50 // default constructor
52 //____________________________________________________________________
53 AliCFFrame::AliCFFrame(const Char_t* name, const Char_t* title) :
66 //____________________________________________________________________
67 AliCFFrame::AliCFFrame(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn) :
82 //the number of variables on the grid
85 // the binning in each variable
86 fNVarBins= new Int_t[fNVar];
88 fIndex= new Int_t[fNVar];
94 //Calculate total number of elements and bins...
96 for(Int_t i=0;i<fNVar;i++){
97 fNVarBins[i]=nBinIn[i];
99 nbinTot+=(nBinIn[i]+1);
103 //total number of elements
107 fOffset= new Int_t[fNVar];
108 fProduct= new Int_t[fNVar];
110 for(Int_t ivar=0;ivar<fNVar;ivar++){
112 for(Int_t i =0;i<ivar;i++)offset+=(fNVarBins[i]+1);
113 fOffset[ivar]=offset;
115 for(Int_t i=0;i<ivar;i++)prod*=fNVarBins[i];
121 fNVarBinLimits=nbinTot;
122 fVarBinLimits=new Double_t[fNVarBinLimits];
124 for(Int_t i=0;i<fNVarBinLimits;i++){
125 fVarBinLimits[i] =binLimitsIn[i];
129 //____________________________________________________________________
130 AliCFFrame::AliCFFrame(const AliCFFrame& c) :
144 ((AliCFFrame &)c).Copy(*this);
146 //____________________________________________________________________
147 AliCFFrame::~AliCFFrame()
152 if(fNVarBins)delete [] fNVarBins;
153 if(fVarBinLimits)delete [] fVarBinLimits;
154 if(fIndex)delete [] fIndex;
155 if(fProduct)delete [] fProduct;
156 if(fOffset)delete [] fOffset;
159 //____________________________________________________________________
160 AliCFFrame &AliCFFrame::operator=(const AliCFFrame &c)
163 // assigment operator
166 ((AliCFFrame &) c).Copy(*this);
169 //____________________________________________________________________
170 void AliCFFrame::SetBinLimits(Int_t ivar, Double_t *array)
173 // setting the arrays containing the bin limits
175 Int_t nbins=fNVarBins[ivar]+1;
176 for(Int_t i=0;i<nbins;i++){
177 fVarBinLimits[fOffset[ivar]+i] =array[i];
180 //____________________________________________________________________
181 void AliCFFrame::GetBinLimits(Int_t ivar, Double_t *array) const
184 // getting the arrays containing the bin limits
186 Int_t nbins=fNVarBins[ivar]+1;
187 for(Int_t i=0;i<nbins;i++){
188 array[i]=fVarBinLimits[fOffset[ivar]+i];
191 //____________________________________________________________________
192 Int_t AliCFFrame::GetBinIndex(Int_t *ibin) const
195 // getting the element number on the grid for a given set of bin indeces
196 //(here the numbering of bin indeces ranges from 0 to N-1)
198 Int_t ind=ibin[fNVar-1];
199 for(Int_t i=fNVar-1;i>0;i--){
200 ind=ibin[i-1]+ind*fNVarBins[i-1];
204 //____________________________________________________________________
205 Int_t AliCFFrame::GetBinIndex(Int_t ivar, Int_t ind) const
208 // getting the bin index on a given dim. ivar for a given element ind
210 //(here the numbering of bin indeces ranges from 0 to N-1)
213 for(Int_t i=fNVar-1;i>=0;i--){
214 index=ind/fProduct[i];
216 ind-=index*fProduct[i];
222 //____________________________________________________________________
223 void AliCFFrame::GetBinIndex(Int_t ind, Int_t *bins ) const
226 // getting the set of bin indeces for a given element ind on the grid
227 // (here the numbering of bin indeces ranges from 0 to N-1)
230 for(Int_t i=fNVar-1;i>=0;i--){
231 index=ind/fProduct[i];
233 ind-=index*fProduct[i];
237 //____________________________________________________________________
238 Double_t AliCFFrame::GetBinCenter(Int_t ivar, Int_t ibin) const
241 // getting the bin center of a given bin ibin along variable ivar
242 // (here the numbering of bin indeces in input
243 // ranges from 1 to N, TH1/2/3 and THnSparse convention)
246 if(ibin>fNVarBins[ivar] || ibin==0){
247 AliWarning(Form("bin index out of range, number of bins in variable %i ranges from 1 to %i", ivar,fNVarBins[ivar]));
250 Double_t binMin=fVarBinLimits[fOffset[ivar]+ibin-1];
251 Double_t binMax=fVarBinLimits[fOffset[ivar]+ibin];
252 Double_t val=0.5*(binMin+binMax);
255 //____________________________________________________________________
256 void AliCFFrame::GetBinCenters(Int_t *ibin, Double_t *binCenter) const
259 // gives the centers of the N-dim bin identified by a set of bin indeces
261 // (here the numbering of bin indeces in input
262 // ranges from 1 to N, TH1/2/3 and THnSparse convention)
264 for(Int_t i=0;i<fNVar;i++){
265 binCenter[i]=GetBinCenter(i,ibin[i]);
267 } //____________________________________________________________________
268 Double_t AliCFFrame::GetBinSize(Int_t ivar, Int_t ibin) const
271 // getting the bin size on axis ivar of a given bin ibin
272 // (here the numbering of bin indeces in input
273 // ranges from 1 to N, TH1/2/3 and THnSparse convention)
276 if(ibin>fNVarBins[ivar] || ibin==0){
277 AliWarning(Form("bin index out of range, number of bins in variable %i ranges from 1 to %i", ivar,fNVarBins[ivar]));
281 Double_t binMin=fVarBinLimits[fOffset[ivar]+ibin-1];
282 Double_t binMax=fVarBinLimits[fOffset[ivar]+ibin];
283 Double_t val=binMax-binMin;
286 //____________________________________________________________________
287 void AliCFFrame::GetBinSizes(Int_t *ibin, Double_t *binSizes) const
290 // gives the sizes of the N-dim bin identified by a set of bin indeces
292 // (here the numbering of bin indeces in input
293 // ranges from 1 to N, TH1/2/3 and THnSparse convention)
295 for(Int_t i=0;i<fNVar;i++){
296 binSizes[i]=GetBinSize(i,ibin[i]);
300 //____________________________________________________________________
301 void AliCFFrame::Copy(TObject& c) const
306 AliCFFrame& target = (AliCFFrame &) c;
310 target.fNVarBinLimits=fNVarBinLimits;
312 target.fNVarBins = fNVarBins;
314 target.fVarBinLimits = fVarBinLimits;
316 target.fProduct = fProduct;
318 target.fOffset = fOffset;
320 //____________________________________________________________________
321 void AliCFFrame::PrintBinLimits()
324 // printing the array containing the bin limits
326 for(Int_t i=0;i<fNVarBinLimits;i++){
327 AliInfo(Form("bin limit index %i is: %f",i, fVarBinLimits[i]));
330 //____________________________________________________________________
331 void AliCFFrame::PrintNBins()
334 // printing the array containing the # of bins
336 for(Int_t i=0;i<fNVar;i++){
337 AliInfo(Form("bins in var %i are: %i",i, fNVarBins[i]));
340 //____________________________________________________________________
341 void AliCFFrame::Save(const Char_t *outfile) const
344 // Save the grid to a root file
347 const char *dirname = "./";
348 TString filename = outfile;
350 if((gSystem->FindFile(dirname,filename))!=NULL){
351 file = new TFile( outfile,"UPDATE");
354 file = new TFile( outfile,"RECREATE");
357 //write the object to a file
358 this->Write(GetName(),TObject::kSingleKey);