Revert unwanted changes concerning PID in HLT
[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 ;
35 virtual void SetBinLimits(Int_t ivar, const Double_t * array);
36 virtual void GetBinLimits(Int_t ivar, Double_t * array) const ;
37 virtual Double_t * GetBinLimits(Int_t ivar) const ;
38 virtual Long_t GetNBinsTotal() const ;
39 virtual Long_t GetNFilledBins() const {return fData->GetNbins();}
40 virtual Int_t GetNBins(Int_t ivar) const {return fData->GetAxis(ivar)->GetNbins();}
41 virtual Int_t * GetNBins() const ;
42 virtual Float_t GetBinCenter(Int_t ivar,Int_t ibin) const ;
43 virtual Float_t GetBinSize (Int_t ivar,Int_t ibin) const ;
44 //virtual void GetBinCenters(const Int_t *ibin, Float_t *binCenter) const ;
45 //virtual void GetBinSizes (const Int_t *ibin, Float_t *binSizes) const ;
46 virtual TAxis * GetAxis(Int_t ivar) const {return fData->GetAxis(ivar);}
db6722a5 47
fb494025 48 virtual void SetVarTitle(Int_t ivar, const Char_t* lab) {fData->GetAxis(ivar)->SetTitle(lab);}
49 virtual const Char_t* GetVarTitle(Int_t ivar) const {return GetAxis(ivar)->GetTitle();}
50 virtual Int_t GetVar(const Char_t* title) const ; // returns the variable corresponding to the given title
db6722a5 51
fb494025 52 // probably not needed anymore
53 //virtual Int_t GetBinIndex(const Int_t *ibin) const ;
54 //virtual void GetBinIndex(Int_t iel, const Int_t *ibin) const ;
55 //virtual Int_t GetBinIndex(Int_t ivar, Int_t ind) const ;
db6722a5 56
fb494025 57 virtual void Fill(const Double_t *var, Double_t weight=1.);
58 virtual Float_t GetEntries()const;
59 virtual Float_t GetElement(Long_t iel) const;
60 virtual Float_t GetElement(const Int_t *bin) const;
61 virtual Float_t GetElement(const Double_t *var) const;
62 virtual Float_t GetElementError(Long_t iel) const;
63 virtual Float_t GetElementError(const Int_t *bin) const;
64 virtual Float_t GetElementError(const Double_t *var) const;
65 virtual void SetElement(Long_t iel, Float_t val);
66 virtual void SetElement(const Int_t *bin, Float_t val);
67 virtual void SetElement(const Double_t *var, Float_t val);
68 virtual void SetElementError(Long_t iel, Float_t val);
69 virtual void SetElementError(const Int_t *bin, Float_t val) ;
70 virtual void SetElementError(const Double_t *var, Float_t val);
db6722a5 71
9105291d 72 virtual TH1D* Project( Int_t ivar) const;
73 virtual TH2D* Project( Int_t ivar1, Int_t ivar2) const;
74 virtual TH3D* Project( Int_t ivar1, Int_t ivar2,Int_t ivar3) const;
fb494025 75 virtual AliCFGridSparse* Project(Int_t nVars, const Int_t* vars, const Double_t* varMin, const Double_t* varMax) const ;
76 virtual TH1D* Slice(Int_t ivar, const Double_t* varMin, const Double_t* varMax) const ;
77 virtual TH2D* Slice(Int_t ivar1, Int_t ivar2, const Double_t *varMin, const Double_t *varMax) const ;
78 virtual TH3D* Slice(Int_t ivar1, Int_t ivar2, Int_t ivar3, const Double_t *varMin, const Double_t *varMax) const ;
79 virtual void SetRangeUser(Int_t iVar, Double_t varMin, Double_t varMax) ;
80 virtual void SetRangeUser(const Double_t* varMin, const Double_t* varMax) ;
81 virtual void UseAxisRange(Bool_t b) const ;
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
fb494025 102 virtual void SetGrid(THnSparse* grid) {fData=grid;}
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
fb494025 109 // to be implemented
110 //------------------
111 //virtual Int_t GetEmptyBins(Double_t *varMin,Double_t *varMax) const;
112 //virtual Double_t GetIntegral(Int_t *binMin,Int_t *binMax) const;
db6722a5 113
db6722a5 114 protected:
115
fb494025 116 //protected functions
117 //Float_t GetSum(Int_t ivar, const Int_t *binMin, const Int_t* binMax) const;
118 void GetScaledValues(const Double_t *fact, const Double_t *in, Double_t *out) const;
119
120 // data members:
121 Bool_t fSumW2 ; // Flag to check if calculation of squared weights enabled
122 THnSparse *fData ; // The data Container: a THnSparse
123
124 ClassDef(AliCFGridSparse,3);
db6722a5 125};
fb494025 126
127
128//inline functions :
129
130inline Long_t AliCFGridSparse::GetNBinsTotal() const {
131 Long_t n=1;
132 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
133 n *= fData->GetAxis(iVar)->GetNbins();
134 }
135 return n ;
136}
137
138inline void AliCFGridSparse::PrintNBins() const
139{
140 //
141 // printing the array containing the # of bins
142 //
143 for (Int_t i=0;i<GetNVar();i++) {
144 AliInfo(Form("bins in axis %i are: %i",i,fData->GetAxis(i)->GetNbins()));
145 }
146}
147
148inline void AliCFGridSparse::PrintBinLimits() const
149{
150 //
151 // printing the bin limits for each variable
152 //
153 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
154 AliInfo(Form("variable %d :",iVar));
155 const Int_t nBins = GetNBins(iVar) ;
156 Double_t *array = new Double_t[nBins+1];
157 GetBinLimits(iVar,array);
158 for (Int_t iBin=0; iBin<nBins; iBin++) {
159 AliInfo(Form(" bin limit index %i is: %e",iBin,array[iBin]));
160 }
161 delete [] array ;
162 }
163}
164
165inline void AliCFGridSparse::GetBinLimits(Int_t ivar, Double_t * array) const {
166 TAxis * axis = fData->GetAxis(ivar) ;
167 Int_t nBins = axis->GetNbins();
168 for (Int_t iBin=0; iBin<nBins; iBin++) array[iBin] = axis->GetBinLowEdge(iBin+1);
169 array[nBins] = axis->GetBinUpEdge(nBins);
170}
171
172inline Int_t* AliCFGridSparse::GetNBins() const {
89ed7ae9 173 Int_t *bins = new Int_t[GetNVar()];
fb494025 174 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
175 bins[iVar] = GetNBins(iVar) ;
176 }
177 return bins;
178}
179
180inline Double_t* AliCFGridSparse::GetBinLimits(Int_t ivar) const {
181 Double_t * binLimits = new Double_t[GetNBins(ivar)+1] ;
182 GetBinLimits(ivar,binLimits);
183 return binLimits;
184}
185
186inline Int_t AliCFGridSparse::GetVar(const Char_t* title) const {
187 TString str(title);
188 for (Int_t iVar=0; iVar<GetNVar(); iVar++) {
189 if (!str.CompareTo(GetVarTitle(iVar))) return iVar;
190 }
191 AliError("Variable not found");
192 return -1;
193}
194
db6722a5 195#endif
196