1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 //--------------------------------------------------------------------//
17 // AliCFVGrid Class //
18 // Just an interface to handle both AliCFGrid and AliCFGridSparse //
21 // -- Author : S.Arcelli //
22 //--------------------------------------------------------------------//
25 #include "AliCFVGrid.h"
29 //____________________________________________________________________
32 //____________________________________________________________________
33 AliCFVGrid::AliCFVGrid() :
37 // default constructor
39 //____________________________________________________________________
40 AliCFVGrid::AliCFVGrid(const Char_t* name, const Char_t* title) :
41 AliCFFrame(name,title),
44 // default constructor
47 //____________________________________________________________________
48 AliCFVGrid::AliCFVGrid(const Char_t* name, const Char_t* title, const Int_t nVarIn, const Int_t * nBinIn, const Double_t *binLimitsIn) :
49 AliCFFrame(name,title,nVarIn,nBinIn,binLimitsIn),
58 //____________________________________________________________________
59 AliCFVGrid::AliCFVGrid(const AliCFVGrid& c) :
66 ((AliCFVGrid &)c).Copy(*this);
69 //____________________________________________________________________
70 AliCFVGrid::~AliCFVGrid()
77 //____________________________________________________________________
78 AliCFVGrid &AliCFVGrid::operator=(const AliCFVGrid &c)
84 AliCFFrame::operator=(c);
88 //____________________________________________________________________
89 void AliCFVGrid::Copy(TObject& c) const
94 AliCFVGrid& target = (AliCFVGrid &) c;
99 //____________________________________________________________________
100 void AliCFVGrid::Scale(Int_t index, Double_t *fact)
103 //scale content of a certain cell by (positive) fact (with error)
105 if(GetElement(index)==0 || fact[0]==0)return;
107 Double_t in[2], out[2];
108 in[0]=GetElement(index);
109 in[1]=GetElementError(index);
110 GetScaledValues(fact,in,out);
111 SetElement(index,out[0]);
112 if(fSumW2)SetElementError(index,out[1]);
114 //____________________________________________________________________
115 void AliCFVGrid::Scale(Int_t *bin, Double_t *fact)
118 //scale content of a certain cell by (positive) fact (with error)
120 if(GetElement(bin)==0 || fact[0]==0)return;
122 Double_t in[2], out[2];
123 in[0]=GetElement(bin);
124 in[1]=GetElementError(bin);
125 GetScaledValues(fact,in,out);
126 SetElement(bin,out[0]);
127 if(fSumW2)SetElementError(bin,out[1]);
130 //____________________________________________________________________
131 void AliCFVGrid::Scale(Double_t *var, Double_t *fact)
134 //scale content of a certain cell by (positive) fact (with error)
136 if(GetElement(var)==0 || fact[0]==0)return;
138 Double_t in[2], out[2];
139 in[0]=GetElement(var);
140 in[1]=GetElementError(var);
141 GetScaledValues(fact,in,out);
142 SetElement(var,out[0]);
143 if(fSumW2)SetElementError(var,out[1]);
146 //____________________________________________________________________
147 void AliCFVGrid::Scale( Double_t *fact)
150 //scale contents of the whole grid by fact
153 for(Int_t iel=0;iel<fNDim;iel++){
158 //____________________________________________________________________
159 Int_t AliCFVGrid::GetEmptyBins() const {
164 for(Int_t i=0;i<fNDim;i++){
165 if(GetElement(i)<=0)val++;
169 //_____________________________________________________________________
170 Int_t AliCFVGrid::GetEmptyBins( Double_t *varMin, Double_t* varMax ) const
173 // Get empty bins in a range
176 Int_t *indexMin=new Int_t[fNVar];
177 Int_t *indexMax=new Int_t[fNVar];
179 //Find out the min and max bins
181 for(Int_t i=0;i<fNVar;i++){
182 Double_t xmin=varMin[i]; // the min values
183 Double_t xmax=varMax[i]; // the min values
184 Int_t nbins=fNVarBins[i]+1;
185 Double_t *bins=new Double_t[nbins];
186 for(Int_t ibin =0;ibin<nbins;ibin++){
187 bins[ibin] = fVarBinLimits[ibin+fOffset[i]];
189 indexMin[i] = TMath::BinarySearch(nbins,bins,xmin);
190 indexMax[i] = TMath::BinarySearch(nbins,bins,xmax);
195 for(Int_t i=0;i<fNDim;i++){
196 for (Int_t j=0;j<fNVar;j++)fIndex[j]=GetBinIndex(j,i);
198 for (Int_t j=0;j<fNVar;j++){
199 if(!(fIndex[j]>=indexMin[j] && fIndex[j]<=indexMax[j]))isIn=kFALSE;
201 if(isIn && GetElement(i)<=0)val++;
203 AliInfo(Form(" the empty bins = %i ",val));
209 //____________________________________________________________________
210 Int_t AliCFVGrid::CheckStats(Double_t thr) const
213 // Count the cells below a certain threshold
216 for(Int_t i=0;i<fNDim;i++){
217 if(GetElement(i)<thr)ncellsLow++;
221 //_____________________________________________________________________
222 Double_t AliCFVGrid::GetIntegral() const
228 for(Int_t i=0;i<fNDim;i++){
233 //_____________________________________________________________________
234 Double_t AliCFVGrid::GetIntegral(Int_t *binMin, Int_t* binMax ) const
237 // Get Integral in a range of bin indeces (extremes included)
242 for(Int_t i=0;i<fNVar;i++){
243 if(binMin[i]<1)binMin[i]=1;
244 if(binMax[i]>fNVarBins[i])binMax[i]=fNVarBins[i];
245 if((binMin[i]>binMax[i])){
246 AliInfo(Form(" Bin indeces in variable %i in reverse order, please check!", i));
250 val=GetSum(0,binMin,binMax);
255 //_____________________________________________________________________
256 Double_t AliCFVGrid::GetIntegral(Double_t *varMin, Double_t* varMax ) const
259 // Get Integral in a range (extremes included)
262 Int_t *indexMin=new Int_t[fNVar];
263 Int_t *indexMax=new Int_t[fNVar];
265 //Find out the min and max bins
267 for(Int_t i=0;i<fNVar;i++){
268 Double_t xmin=varMin[i]; // the min values
269 Double_t xmax=varMax[i]; // the min values
270 Int_t nbins=fNVarBins[i]+1;
271 Double_t *bins=new Double_t[nbins];
272 for(Int_t ibin =0;ibin<nbins;ibin++){
273 bins[ibin] = fVarBinLimits[ibin+fOffset[i]];
275 indexMin[i] = TMath::BinarySearch(nbins,bins,xmin);
276 indexMax[i] = TMath::BinarySearch(nbins,bins,xmax);
280 //move to the TH/THnSparse convention in N-dim bin numbering
281 for(Int_t i=0;i<fNVar;i++){
286 Double_t val=GetIntegral(indexMin,indexMax);
294 //_____________________________________________________________________
295 Double_t AliCFVGrid::GetSum(Int_t ivar, Int_t *binMin, Int_t* binMax) const
298 // recursively add over nested loops....
302 for(Int_t ibin=binMin[ivar]-1;ibin<=binMax[ivar]-1;ibin++){
303 //-1 is to move from TH/ThnSparse N-dim bin convention to one in AliCFFrame
306 val=GetSum(ivar+1,binMin,binMax);
309 Int_t iel=GetBinIndex(fIndex);
310 val+=GetElement(iel);
317 //____________________________________________________________________
318 Long64_t AliCFVGrid::Merge(TCollection* list)
320 // Merge a list of AliCF grids with this (needed for
322 // Returns the number of merged objects (including this).
330 TIterator* iter = list->MakeIterator();
334 while ((obj = iter->Next())) {
335 AliCFVGrid* entry = dynamic_cast<AliCFVGrid*> (obj);
345 //____________________________________________________________________
346 void AliCFVGrid::GetScaledValues(Double_t *fact, Double_t *in, Double_t *out) const{
348 // scale input *in and it error by (positive) fact (with error)
349 // and erite it to *out
351 out[0]=in[0]*fact[0];
352 out[1]=TMath::Sqrt(in[1]*in[1]/in[0]/in[0]
353 +fact[1]*fact[1]/fact[0]/fact[0])*out[0];