AddTaskFemto for train update
[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
d91baff0 73 virtual TH1* Project(Int_t ivar1, Int_t ivar2=-1, Int_t ivar3=-1) const {return Slice(ivar1,ivar2,ivar3,0x0,0x0,kFALSE);}
74 virtual TH1* Slice(Int_t ivar1, Int_t ivar2=-1, Int_t ivar3=-1,
75 const Double_t *varMin=0x0, const Double_t *varMax=0x0, Bool_t useBins=0) const ;
76 virtual AliCFGridSparse* MakeSlice(Int_t nVars, const Int_t* vars,
77 const Double_t* varMin, const Double_t* varMax, Bool_t useBins=0) const ;
78
79 virtual void SetRangeUser(Int_t iVar, Double_t varMin, Double_t varMax, Bool_t useBins=kFALSE) const ;
80 virtual void SetRangeUser(const Double_t* varMin, const Double_t* varMax, Bool_t useBins=kFALSE) const ;
7036630f 81 virtual void Smooth() ;
db6722a5 82
83 //basic operations
fb494025 84 virtual void SumW2();
85 virtual void Add(const AliCFGridSparse* aGrid, Double_t c=1.);
86 virtual void Add(const AliCFGridSparse* aGrid1 ,const AliCFGridSparse* aGrid2, Double_t c1=1.,Double_t c2=1.);
87 virtual void Multiply(const AliCFGridSparse* aGrid, Double_t c=1.);
88 virtual void Multiply(const AliCFGridSparse* aGrid1,const AliCFGridSparse* aGrid2, Double_t c1=1.,Double_t c2=1.);
89 virtual void Divide(const AliCFGridSparse* aGrid, Double_t c=1.);
90 virtual void Divide(const AliCFGridSparse* aGrid1, const AliCFGridSparse* aGrid2, Double_t c1=1., Double_t c2=1.,Option_t *option=0);
91 virtual void Rebin(const Int_t* group);
92 virtual void Scale(Long_t iel, const Double_t *fact);
93 virtual void Scale(const Int_t* bin, const Double_t *fact);
94 virtual void Scale(const Double_t* var, const Double_t *fact);
95 virtual void Scale(const Double_t *fact); // To normalize MC to int lumi, for ex.
96 virtual Int_t CheckStats(Double_t thr) const;
97 virtual Int_t GetSumW2() const {return fSumW2;};
98 virtual Double_t GetIntegral() const;
99 //virtual Double_t GetIntegral(const Double_t *varMin, const Double_t *varMax) const;
100 virtual Long64_t Merge(TCollection* list);
db6722a5 101
4b7819c4 102 virtual void SetGrid(THnSparse* grid) {if (fData) delete fData ; fData=grid;}
fb494025 103 THnSparse * GetGrid() const {return fData;}
db6722a5 104
fb494025 105 virtual Float_t GetOverFlows (Int_t var, Bool_t excl=kFALSE) const;
106 virtual Float_t GetUnderFlows(Int_t var, Bool_t excl=kFALSE) const;
107 virtual Long_t GetEmptyBins() const;
db6722a5 108
d91baff0 109 /* FUNCTIONS TO REMOVE */
110 virtual AliCFGridSparse* Project(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax, Bool_t useBins=0) const
111 {return MakeSlice(nVars,vars,varMin,varMax,useBins);}
112
db6722a5 113
db6722a5 114 protected:
115
fb494025 116 //protected functions
fb494025 117 void GetScaledValues(const Double_t *fact, const Double_t *in, Double_t *out) const;
d91baff0 118 void SetAxisRange(TAxis* axis, Double_t min, Double_t max, Bool_t useBins) const;
119 void GetProjectionName (TString& s,Int_t var0, Int_t var1=-1, Int_t var2=-1) const;
120 void GetProjectionTitle(TString& s,Int_t var0, Int_t var1=-1, Int_t var2=-1) const;
fb494025 121
122 // data members:
123 Bool_t fSumW2 ; // Flag to check if calculation of squared weights enabled
124 THnSparse *fData ; // The data Container: a THnSparse
125
126 ClassDef(AliCFGridSparse,3);
db6722a5 127};
fb494025 128
129
130//inline functions :
131
132inline Long_t AliCFGridSparse::GetNBinsTotal() const {
133 Long_t n=1;
134 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
135 n *= fData->GetAxis(iVar)->GetNbins();
136 }
137 return n ;
138}
139
140inline void AliCFGridSparse::PrintNBins() const
141{
142 //
143 // printing the array containing the # of bins
144 //
145 for (Int_t i=0;i<GetNVar();i++) {
146 AliInfo(Form("bins in axis %i are: %i",i,fData->GetAxis(i)->GetNbins()));
147 }
148}
149
150inline void AliCFGridSparse::PrintBinLimits() const
151{
152 //
153 // printing the bin limits for each variable
154 //
155 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
156 AliInfo(Form("variable %d :",iVar));
157 const Int_t nBins = GetNBins(iVar) ;
158 Double_t *array = new Double_t[nBins+1];
159 GetBinLimits(iVar,array);
160 for (Int_t iBin=0; iBin<nBins; iBin++) {
161 AliInfo(Form(" bin limit index %i is: %e",iBin,array[iBin]));
162 }
163 delete [] array ;
164 }
165}
166
167inline void AliCFGridSparse::GetBinLimits(Int_t ivar, Double_t * array) const {
168 TAxis * axis = fData->GetAxis(ivar) ;
169 Int_t nBins = axis->GetNbins();
170 for (Int_t iBin=0; iBin<nBins; iBin++) array[iBin] = axis->GetBinLowEdge(iBin+1);
171 array[nBins] = axis->GetBinUpEdge(nBins);
172}
173
174inline Int_t* AliCFGridSparse::GetNBins() const {
89ed7ae9 175 Int_t *bins = new Int_t[GetNVar()];
fb494025 176 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
177 bins[iVar] = GetNBins(iVar) ;
178 }
179 return bins;
180}
181
182inline Double_t* AliCFGridSparse::GetBinLimits(Int_t ivar) const {
183 Double_t * binLimits = new Double_t[GetNBins(ivar)+1] ;
184 GetBinLimits(ivar,binLimits);
185 return binLimits;
186}
187
188inline Int_t AliCFGridSparse::GetVar(const Char_t* title) const {
189 TString str(title);
190 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
191 if (!str.CompareTo(GetVarTitle(iVar))) return iVar;
192 }
193 AliError("Variable not found");
194 return -1;
195}
196
d91baff0 197inline void AliCFGridSparse::GetProjectionName (TString& s, Int_t var0, Int_t var1, Int_t var2) const {
198 s.Form("%s_proj-%s",GetName(),GetVarTitle(var0));
199 if (var1>=0) {
200 s.Append(Form("-%s",GetVarTitle(var1)));
201 if (var2>=0) s.Append(Form("-%s",GetVarTitle(var2)));
202 }
203}
204
205inline void AliCFGridSparse::GetProjectionTitle(TString& s, Int_t var0, Int_t var1, Int_t var2) const {
206 s.Form("%s: projection on %s",GetTitle(),GetVarTitle(var0));
207 if (var1>=0) {
208 s.Append(Form("-%s",GetVarTitle(var1)));
209 if (var2>=0) s.Append(Form("-%s",GetVarTitle(var2)));
210 }
211}
212
db6722a5 213#endif
214