added functions to define uniform axis binning
[u/mrichter/AliRoot.git] / CORRFW / AliCFGridSparse.h
CommitLineData
db6722a5 1#ifndef ALICFGRIDSPARSE_H
2#define ALICFGRIDSPARSE_H
3//--------------------------------------------------------------------//
4// //
5// AliCFGridSparse.cxx Class //
6// Class to handle N-dim maps for the correction Framework //
7// uses a THnSparse to store the grid //
8// Author:S.Arcelli, silvia.arcelli@cern.ch
9//--------------------------------------------------------------------//
10
fb494025 11#include "AliCFFrame.h"
db6722a5 12#include "THnSparse.h"
13#include "AliLog.h"
fb494025 14#include "TAxis.h"
15
db6722a5 16class TH1D;
17class TH2D;
18class TH3D;
19
fb494025 20class AliCFGridSparse : public AliCFFrame
db6722a5 21{
22 public:
23 AliCFGridSparse();
fb494025 24 AliCFGridSparse(const Char_t* name, const Char_t* title);
25 AliCFGridSparse(const Char_t* name, const Char_t* title, Int_t nVarIn, const Int_t* nBinIn);
26 AliCFGridSparse(const AliCFGridSparse& c);
db6722a5 27 virtual ~AliCFGridSparse();
fb494025 28 AliCFGridSparse& operator=(const AliCFGridSparse& c);
29 virtual void Copy(TObject& c) const;
db6722a5 30
fb494025 31 // AliCFFrame functions
32 virtual Int_t GetNVar() const {return fData->GetNdimensions();}
33 virtual void PrintBinLimits() const ;
34 virtual void PrintNBins() const ;
aa29aca9 35 virtual void SetBinLimits(Int_t ivar, Double_t min, Double_t max); // for uniform bin width only
36 virtual void SetBinLimits(Int_t ivar, const Double_t * array); // for variable or uniform bin width
fb494025 37 virtual void GetBinLimits(Int_t ivar, Double_t * array) const ;
38 virtual Double_t * GetBinLimits(Int_t ivar) const ;
39 virtual Long_t GetNBinsTotal() const ;
40 virtual Long_t GetNFilledBins() const {return fData->GetNbins();}
41 virtual Int_t GetNBins(Int_t ivar) const {return fData->GetAxis(ivar)->GetNbins();}
42 virtual Int_t * GetNBins() const ;
43 virtual Float_t GetBinCenter(Int_t ivar,Int_t ibin) const ;
44 virtual Float_t GetBinSize (Int_t ivar,Int_t ibin) const ;
45 //virtual void GetBinCenters(const Int_t *ibin, Float_t *binCenter) const ;
46 //virtual void GetBinSizes (const Int_t *ibin, Float_t *binSizes) const ;
47 virtual TAxis * GetAxis(Int_t ivar) const {return fData->GetAxis(ivar);}
db6722a5 48
fb494025 49 virtual void SetVarTitle(Int_t ivar, const Char_t* lab) {fData->GetAxis(ivar)->SetTitle(lab);}
50 virtual const Char_t* GetVarTitle(Int_t ivar) const {return GetAxis(ivar)->GetTitle();}
51 virtual Int_t GetVar(const Char_t* title) const ; // returns the variable corresponding to the given title
db6722a5 52
fb494025 53 // probably not needed anymore
54 //virtual Int_t GetBinIndex(const Int_t *ibin) const ;
55 //virtual void GetBinIndex(Int_t iel, const Int_t *ibin) const ;
56 //virtual Int_t GetBinIndex(Int_t ivar, Int_t ind) const ;
db6722a5 57
fb494025 58 virtual void Fill(const Double_t *var, Double_t weight=1.);
59 virtual Float_t GetEntries()const;
60 virtual Float_t GetElement(Long_t iel) const;
61 virtual Float_t GetElement(const Int_t *bin) const;
62 virtual Float_t GetElement(const Double_t *var) const;
63 virtual Float_t GetElementError(Long_t iel) const;
64 virtual Float_t GetElementError(const Int_t *bin) const;
65 virtual Float_t GetElementError(const Double_t *var) const;
66 virtual void SetElement(Long_t iel, Float_t val);
67 virtual void SetElement(const Int_t *bin, Float_t val);
68 virtual void SetElement(const Double_t *var, Float_t val);
69 virtual void SetElementError(Long_t iel, Float_t val);
70 virtual void SetElementError(const Int_t *bin, Float_t val) ;
71 virtual void SetElementError(const Double_t *var, Float_t val);
db6722a5 72
9105291d 73 virtual TH1D* Project( Int_t ivar) const;
74 virtual TH2D* Project( Int_t ivar1, Int_t ivar2) const;
75 virtual TH3D* Project( Int_t ivar1, Int_t ivar2,Int_t ivar3) const;
98a5f772 76 virtual AliCFGridSparse* Project(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax, Bool_t useBins=0) const ;
77 virtual TH1D* Slice(Int_t ivar, const Double_t* varMin, const Double_t* varMax, Bool_t useBins=0) const ;
78 virtual TH2D* Slice(Int_t ivar1, Int_t ivar2, const Double_t *varMin, const Double_t *varMax, Bool_t useBins=0) const ;
79 virtual TH3D* Slice(Int_t ivar1, Int_t ivar2, Int_t ivar3, const Double_t *varMin, const Double_t *varMax, Bool_t useBins=0) const ;
fb494025 80 virtual void SetRangeUser(Int_t iVar, Double_t varMin, Double_t varMax) ;
81 virtual void SetRangeUser(const Double_t* varMin, const Double_t* varMax) ;
82 virtual void UseAxisRange(Bool_t b) const ;
db6722a5 83
84 //basic operations
fb494025 85 virtual void SumW2();
86 virtual void Add(const AliCFGridSparse* aGrid, Double_t c=1.);
87 virtual void Add(const AliCFGridSparse* aGrid1 ,const AliCFGridSparse* aGrid2, Double_t c1=1.,Double_t c2=1.);
88 virtual void Multiply(const AliCFGridSparse* aGrid, Double_t c=1.);
89 virtual void Multiply(const AliCFGridSparse* aGrid1,const AliCFGridSparse* aGrid2, Double_t c1=1.,Double_t c2=1.);
90 virtual void Divide(const AliCFGridSparse* aGrid, Double_t c=1.);
91 virtual void Divide(const AliCFGridSparse* aGrid1, const AliCFGridSparse* aGrid2, Double_t c1=1., Double_t c2=1.,Option_t *option=0);
92 virtual void Rebin(const Int_t* group);
93 virtual void Scale(Long_t iel, const Double_t *fact);
94 virtual void Scale(const Int_t* bin, const Double_t *fact);
95 virtual void Scale(const Double_t* var, const Double_t *fact);
96 virtual void Scale(const Double_t *fact); // To normalize MC to int lumi, for ex.
97 virtual Int_t CheckStats(Double_t thr) const;
98 virtual Int_t GetSumW2() const {return fSumW2;};
99 virtual Double_t GetIntegral() const;
100 //virtual Double_t GetIntegral(const Double_t *varMin, const Double_t *varMax) const;
101 virtual Long64_t Merge(TCollection* list);
db6722a5 102
fb494025 103 virtual void SetGrid(THnSparse* grid) {fData=grid;}
104 THnSparse * GetGrid() const {return fData;}
db6722a5 105
fb494025 106 virtual Float_t GetOverFlows (Int_t var, Bool_t excl=kFALSE) const;
107 virtual Float_t GetUnderFlows(Int_t var, Bool_t excl=kFALSE) const;
108 virtual Long_t GetEmptyBins() const;
db6722a5 109
fb494025 110 // to be implemented
111 //------------------
112 //virtual Int_t GetEmptyBins(Double_t *varMin,Double_t *varMax) const;
113 //virtual Double_t GetIntegral(Int_t *binMin,Int_t *binMax) const;
db6722a5 114
db6722a5 115 protected:
116
fb494025 117 //protected functions
118 //Float_t GetSum(Int_t ivar, const Int_t *binMin, const Int_t* binMax) const;
119 void GetScaledValues(const Double_t *fact, const Double_t *in, Double_t *out) const;
120
121 // data members:
122 Bool_t fSumW2 ; // Flag to check if calculation of squared weights enabled
123 THnSparse *fData ; // The data Container: a THnSparse
124
125 ClassDef(AliCFGridSparse,3);
db6722a5 126};
fb494025 127
128
129//inline functions :
130
131inline Long_t AliCFGridSparse::GetNBinsTotal() const {
132 Long_t n=1;
133 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
134 n *= fData->GetAxis(iVar)->GetNbins();
135 }
136 return n ;
137}
138
139inline void AliCFGridSparse::PrintNBins() const
140{
141 //
142 // printing the array containing the # of bins
143 //
144 for (Int_t i=0;i<GetNVar();i++) {
145 AliInfo(Form("bins in axis %i are: %i",i,fData->GetAxis(i)->GetNbins()));
146 }
147}
148
149inline void AliCFGridSparse::PrintBinLimits() const
150{
151 //
152 // printing the bin limits for each variable
153 //
154 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
155 AliInfo(Form("variable %d :",iVar));
156 const Int_t nBins = GetNBins(iVar) ;
157 Double_t *array = new Double_t[nBins+1];
158 GetBinLimits(iVar,array);
159 for (Int_t iBin=0; iBin<nBins; iBin++) {
160 AliInfo(Form(" bin limit index %i is: %e",iBin,array[iBin]));
161 }
162 delete [] array ;
163 }
164}
165
166inline void AliCFGridSparse::GetBinLimits(Int_t ivar, Double_t * array) const {
167 TAxis * axis = fData->GetAxis(ivar) ;
168 Int_t nBins = axis->GetNbins();
169 for (Int_t iBin=0; iBin<nBins; iBin++) array[iBin] = axis->GetBinLowEdge(iBin+1);
170 array[nBins] = axis->GetBinUpEdge(nBins);
171}
172
173inline Int_t* AliCFGridSparse::GetNBins() const {
89ed7ae9 174 Int_t *bins = new Int_t[GetNVar()];
fb494025 175 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
176 bins[iVar] = GetNBins(iVar) ;
177 }
178 return bins;
179}
180
181inline Double_t* AliCFGridSparse::GetBinLimits(Int_t ivar) const {
182 Double_t * binLimits = new Double_t[GetNBins(ivar)+1] ;
183 GetBinLimits(ivar,binLimits);
184 return binLimits;
185}
186
187inline Int_t AliCFGridSparse::GetVar(const Char_t* title) const {
188 TString str(title);
189 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
190 if (!str.CompareTo(GetVarTitle(iVar))) return iVar;
191 }
192 AliError("Variable not found");
193 return -1;
194}
195
db6722a5 196#endif
197