simple-tof-analysis
 All Classes Namespaces Functions Variables Groups Pages
TSSample.h
1 /*
2  * TSSample.h
3  *
4  * Created on: Sep 26, 2014
5  * Author: Silvestro di Luise
6  * Silvestro.Di.Luise@cern.ch
7  *
8  * Generic Data Container
9  *
10  * Normalization
11  *
12  * CategoryCard
13  *
14  * Data Variable
15  *
16  * DataStructure:
17  * Mulit-dim
18  * Binned and/or Unbinned
19  *
20  */
21 
22 #ifndef TSSAMPLE_H_
23 #define TSSAMPLE_H_
24 
25 #include <utility>
26 #include <vector>
27 #include <map>
28 #include <unordered_map>
29 
30 #include <TRandom.h>
31 #include <TString.h>
32 #include <TH1F.h>
33 #include <TH2F.h>
34 #include <THStack.h>
35 #include <TTree.h>
36 #include <TAxis.h>
37 #include <TList.h>
38 
39 #include "TSNamed.h"
40 #include "TSPOTMgr.h"
41 
42 #include "TSArgList.h"
43 #include "TSParamList.h"
44 
45 #include "TSVariable.h"
46 
47 
48 #include "TSCategory.h"
49 #include "TSCategoryCard.h"
50 
51 #include "TSNuiParam.h"
52 #include "TSNuiParamSet.h"
53 #include "TSRespFunc.h"
54 #include "TSHistoNuiParamMgr.h"
55 #include "TSHistoOscillMgr.h"
56 
57 /*
58  *
59  */
60 
61 class TSSample: public TSNamed {
62 
63 public:
64 
65  TSSample();
66  TSSample(TString name, TString label, TString title);
67  virtual ~TSSample();
68 
69  void AddVariable(const TSVariable &, int n, double min, double max, TString opt="");
70  void AddVariable(const TSVariable &, int n, double *bins, TString opt="");
71 
72  void AddVariables(const TSArgList &);//not active
73 
74  int CompareCategoryCard(const TSCategoryCard &, int opt=1);
75 
76  void Disable1D(bool b) {fDisable1D=b;}
77  void Disable2D(bool b) {fDisable2D=b;}
78 
79 
80  void Fill(double w=1);
81 
82  void Fill(std::map<const TSVariable*,double>&, double w=1);
83 
84  void Fill(TTree &, TCut &, TString vars, TString weight="");
85 
86  void Fill(int, double x, double w);
87  void Fill(int, double x, double y, double w);
88 
89 
90  const TSCategoryCard& GetCategoryCard() const {return fCard;}
91 
92  TTree& GetDataTree() {return fDataTree;}
93  TList& GetHistoList() {return hList;}
94 
95  TH1F* GetHistogram(const TSVariable &);
96  TH1F* GetToyHistogram(const TSVariable &);
97  TH2F* GetHistogram2D(const TSVariable &, const TSVariable &);
98  TH2F* GetToyHistogram2D(const TSVariable &, const TSVariable &);
99 
100  int GetVarIdx(const TSVariable &) const;
101 
102  //const TSHistoNuiParamMgr& GetHistoNuiParamMgr() const {return fNuiParamMgr;}
103 
104  float GetPOT() const {return fPOT;}
105  float GetNativePOT() const {return fPOTnative;}
106  float GetNativePOTPower() const {return fPOTnative_pow;}
107  float GetPOTPower() const {return fPOTpower;}
108  float GetPOTScaling() const {return fPOTscaling;}
109  TString GetPOTLabel() const {return fPOTlabel;}
110  TString GetNativePOTLabel() const {return fPOTNativeLabel;}
111  int GetToyId() const {return fToyId;}
112 
113  bool HasCategoryCard() const {return fHasCategory;}
114  bool IsUnbinned() const {return fIsUnbinned;}
115 
116  void Init();
117 
118  void Print();
119 
120  void Randomize(int =0);
121  THStack* RandomizedStack(const TSVariable &var, int ntoy=1000);
122  void Restore();
123 
124  void Reset();
125  void ResetToys();
126 
127  void SetCategoryCard(const TSCategoryCard &);
128 
129  void SetNativePOT(float POT, float Power=20);
130  void ScaleToPOT(float POT, float Power=20);
131  void ScaleToNativePOT();
132 
133 
134  void SetBidimensional(const TSVariable &var_x, const TSVariable &var_y);
135 
136  int SetOscillProbFunction(TSOscProb *);
137 
138  void SetUnbinned(bool b){ fIsUnbinned = b; }
139 
140  int SetWeightParams(const TSNuiParamSet &);
141 
142 
143 
144 private:
145 
146  TRandom fRand;
147 
148  TTree fDataTree;
149  bool fIsUnbinned;
150  void fInitDataTree();
151  void fUpdateDataTreeBranches();
152 
153  void fBuildPOTNames();
154 
155  void fNormalizeAll(int opt=0);
156 
157  float fPOT;
158  float fPOTnative;
159  float fPOTpower;
160  float fPOTnative_pow;
161  float fPOTscaling;
162 
163  TString fPOTlabel;
164  TString fPOTNativeLabel;
165 
166  //
167  bool fHasCategory;
168  TSCategoryCard fCard;
169 
170  //
171 
172  std::map<const TSVariable*, int> fVarIdx;
173 
174  //
175  // Try also with plain C array
176  // for performance optimization
177  //
178  int fNumOfVars;
179  int fNumOfAuxVars;
180 
181  std::vector<const TSVariable*> fVarListAll;
182  std::vector<const TSVariable*> fVarList;
183  std::vector<const TSVariable*> fAuxVarList;
184 
185  std::vector<TAxis*> fVarAxis;
186  std::vector<TAxis*> fAuxVarAxis;
187 
188  std::vector<int> fVarType;
189 
190  std::vector<TH1F*> fVarHisto;
191  std::vector<TH2F*> fVarHisto2D;
192 
193  std::vector<TH1F*> fVarHistoToy;
194  std::vector<TH2F*> fVarHisto2DToy;
195 
196  std::vector<TH1F*> fVarHistoAux;
197  std::vector<TH2F*> fVarHisto2DAux;
198 
199  std::vector<std::pair<int,int> > fHisto2DIdx;
200  std::vector<std::pair<int,int> > fHisto2DAuxIdx;
201 
202  std::vector<TSHistoNuiParamMgr*> fHistoNuiParMgr;
203  std::vector<TSHistoOscillMgr*> fHistoOscillProbMgr;
204  std::vector<TSHistoNuiParamMgr*> fHistoToyNuiParMgr;
205  std::vector<TSHistoOscillMgr*> fHistoToyOscillProbMgr;
206 
207  std::vector<TSHistoNuiParamMgr*> fHisto2DNuiParMgr;
208  std::vector<TSHistoOscillMgr*> fHisto2DOscillProbMgr;
209  std::vector<TSHistoNuiParamMgr*> fHisto2DToyNuiParMgr;
210  std::vector<TSHistoOscillMgr*> fHisto2DToyOscillProbMgr;
211 
212  bool fDisable1D;
213  bool fDisable2D;
214 
215 
216  TList hList;
217  TList hListToy;
218  TList hListAux;
219  TList hListAll;
220 
221  TSVariable *fVars;
222  double **fVarBins;
223 
224  struct fVarSettings{
225 
226  int nbins;
227  double *bins;
228  TAxis *axis;
229  bool IsAux;
230 
231  fVarSettings(): bins(0),axis(0),IsAux(0) {};
232 
233  };
234 
235  //----
236 
237  double *fVarCache;
238  std::vector<TH1F*> fHistoList;
239  std::vector<TH2F*> fHistoList2D;
240  double fEventWeight;
241  int fToyId;
242 
243  //
244  //-----
245  //
246 
247 
248  void fFillFromCache();
249 
250 };
251 
252 #endif /* TSSAMPLE_H_ */
Definition: TSArgList.h:30
Definition: TSCategoryCard.h:27
void Fill(double w=1)
Definition: TSSample.cc:278
void Restore()
Definition: TSSample.cc:735
Definition: TSVariable.h:55
Definition: TSSample.h:61
Definition: TSNuiParamSet.h:36
void SetNativePOT(float POT, float Power=20)
Definition: TSSample.cc:1169
Definition: TSNamed.h:38
Definition: TSOscProb.h:27