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
197 Int_t ind=ibin[fNVar-1];
198 for(Int_t i=fNVar-1;i>0;i--){
199 ind=ibin[i-1]+ind*fNVarBins[i-1];
203 //____________________________________________________________________
204 Int_t AliCFFrame::GetBinIndex(Int_t ivar, Int_t ind) const
207 // getting the bin index on a given dim. ivar for a given element ind on the grid
210 for(Int_t i=fNVar-1;i>=0;i--){
211 index=ind/fProduct[i];
213 ind-=index*fProduct[i];
219 //____________________________________________________________________
220 void AliCFFrame::GetBinIndex(Int_t ind, Int_t *bins ) const
223 // getting the set of bin indeces for a given element ind on the grid
226 for(Int_t i=fNVar-1;i>=0;i--){
227 index=ind/fProduct[i];
229 ind-=index*fProduct[i];
233 //____________________________________________________________________
234 Double_t AliCFFrame::GetBinCenter(Int_t ivar, Int_t ibin) const
237 // getting the bin center of a given bin ibin along variable ivar
240 Double_t binMin=fVarBinLimits[fOffset[ivar]+ibin];
241 Double_t binMax=fVarBinLimits[fOffset[ivar]+ibin+1];
242 Double_t val=0.5*(binMin+binMax);
245 //____________________________________________________________________
246 void AliCFFrame::GetBinCenters(Int_t *ibin, Double_t *binCenter) const
249 // gives the centers of the N-dim bin identified by a set of bin indeces
252 for(Int_t i=0;i<fNVar;i++){
253 binCenter[i]=GetBinCenter(i,ibin[i]);
255 } //____________________________________________________________________
256 Double_t AliCFFrame::GetBinSize(Int_t ivar, Int_t ibin) const
259 // getting the bin size on axis ivar of a given bin ibin
262 if(ibin>=fNVarBins[ivar]){
263 AliWarning(Form("bin index out of range, number of bins in variable %i is %i", ivar,fNVarBins[ivar]));
267 Double_t binMin=fVarBinLimits[fOffset[ivar]+ibin];
268 Double_t binMax=fVarBinLimits[fOffset[ivar]+ibin+1];
269 Double_t val=binMax-binMin;
272 //____________________________________________________________________
273 void AliCFFrame::GetBinSizes(Int_t *ibin, Double_t *binSizes) const
276 // gives the sizes of the N-dim bin identified by a set of bin indeces
279 for(Int_t i=0;i<fNVar;i++){
280 binSizes[i]=GetBinSize(i,ibin[i]);
284 //____________________________________________________________________
285 void AliCFFrame::Copy(TObject& c) const
290 AliCFFrame& target = (AliCFFrame &) c;
294 target.fNVarBinLimits=fNVarBinLimits;
296 target.fNVarBins = fNVarBins;
298 target.fVarBinLimits = fVarBinLimits;
300 target.fProduct = fProduct;
302 target.fOffset = fOffset;
304 //____________________________________________________________________
305 void AliCFFrame::PrintBinLimits()
308 // printing the array containing the bin limits
310 for(Int_t i=0;i<fNVarBinLimits;i++){
311 AliInfo(Form("bin limit index %i is: %f",i, fVarBinLimits[i]));
314 //____________________________________________________________________
315 void AliCFFrame::PrintNBins()
318 // printing the array containing the # of bins
320 for(Int_t i=0;i<fNVar;i++){
321 AliInfo(Form("bins in var %i are: %i",i, fNVarBins[i]));
324 //____________________________________________________________________
325 void AliCFFrame::Save(const Char_t *outfile) const
328 // Save the grid to a root file
331 const char *dirname = "./";
332 TString filename = outfile;
334 if((gSystem->FindFile(dirname,filename))!=NULL){
335 file = new TFile( outfile,"UPDATE");
338 file = new TFile( outfile,"RECREATE");
341 //write the object to a file
342 this->Write(GetName(),TObject::kSingleKey);