HighLAND
DrawingToolsBase.hxx
1 #ifndef DrawingToolsBase_h
2 #define DrawingToolsBase_h
3 
4 #include <stdio.h>
5 #include <iostream>
6 #include <map>
7 #include <vector>
8 #include <math.h>
9 #include <TROOT.h>
10 #include <TChain.h>
11 #include <TFile.h>
12 #include <TH1F.h>
13 #include <TH2F.h>
14 #include <TH3F.h>
15 #include <TProfile.h>
16 #include "TLine.h"
17 #include "TVectorD.h"
18 #include "TMatrixD.h"
19 #include <TLegend.h>
20 #include <TStyle.h>
21 #include <TCanvas.h>
22 #include <TVector3.h>
23 #include <TDirectory.h>
24 #include <TList.h>
25 #include <TPaveStats.h>
26 #include <TGraph.h>
27 #include <TGraphAsymmErrors.h>
28 #include <THStack.h>
29 #include <TLegendEntry.h>
30 #include "HistoStack.hxx"
31 #include "Header.hxx"
32 #include <sstream>
33 #include <sys/stat.h>
34 
35 #include "CategoryManager.hxx"
36 #include "SelectionManager.hxx"
37 #include "CorrectionManager.hxx"
38 #include "ConfigurationManager.hxx"
39 #include "SystematicManager.hxx"
40 #include "DocStringManager.hxx"
41 #include "VersionManager.hxx"
42 
43 #include "SystematicTools.hxx"
44 #include "ConfigTreeTools.hxx"
45 
46 
47 const int NAUTOCOLORS=10;
48 const int NMAXAUTOCOLORS=30;
49 const int NMAXTYPES = 30;
50 const int NMAXBINS = 5001; // it allows NMAXBINS-1 bins
51 
52 /// This is the base class for the DrawingTools, and uses a single TTree to
53 /// as input, rather than a DataSample object. It handles color code
54 /// drawing and variable binning.
55 ///
56 /// Users generally shouldn't instantiate this class directly, but use the
57 /// DrawingTools class instead. See the DrawingTools class documentation for
58 /// more details.
59 ///
60 /// TODO: This class must be properly documented.
61 
63 public :
64 
65  DrawingToolsBase(const std::string& file="", Int_t T2KstyleIndex=1);
66  virtual ~DrawingToolsBase(){}
67 
68  //---------- Utility functions ---------------
69 
70  TH1_h* AddErrorsInQuadrature(TH1_h* h1,TH1_h* h2,const std::string& opt="");
71 
72  /// extract the same or sames option from the full root option
73  std::string GetSameRootOption(const std::string& root_opt);
74 
75  /// remove same and sames options from the root option
76  std::string GetNoSameRootOption(const std::string& root_opt);
77 
78  /// reset all saved histograms
79  void Reset();
80 
81  /// Get number (sum of weights) of events (i.e. bunches) passing "cut"
82  double GetEntries(TTree* tree, const std::string& cut);
83 
84  /// Get number (sum of weights) for variable var pasing "cut" (useful for vector variables, which number can be different than number of events/bunches)
85  double GetEntries(TTree* tree, const std::string& cut, const std::string& var, const std::string& opt = "", int toy_ref = -1);
86 
87  /// Scale an histogram and its errors(when requested)
88  void ScaleHisto(TH1* h, double scale, bool scale_errors=true);
89 
90  /// Get a vector with variable binning
91  double* GetVariableBins(int nx, double xmin, double xmax, double*);
92 
93  /// Get the superposition level
94  std::string GetSameLevel(const std::string& root_opt);
95 
96  /// Get a unique name for a histogram, to avoid name clashes when drawing on
97  /// multiple canvases.
98  std::string GetUniqueName(const std::string& name);
99 
100  /// create the legend
101  void CreateLegend(const std::string& uopt="");
102 
103  /// Print the event number of a specific selection
104  void PrintEventNumbers(TTree* tree, const std::string& cut, const std::string& file="", int toy_ref=-1);
105 
106  /// Give the appropriate format to any cut
107  std::string FormatCut(const std::string& cut);
108 
109  /// Add cut on range shown on plot
110  std::string AddRangeCut(const std::string& var, int nx, double* xbins, int ny, double* ybins, const std::string& cut, const std::string& uopt);
111 
112  //------------------------------------------
113  //---------- Drawing functions -------------
114  //------------------------------------------
115 
116  //---------- Single distributions -------------
117 
118  // Draw a single variable "var" in given tree with the specified binning. A cut can be applied using variables in the tree. The stacked histogram colors will refer
119  // to the specified category. If no category is specified only the total will be plotted. A normalization factor can be applied to the histogram contents.
120  // By default errors are scaled when the normalization factor is not 1.
121 
122  /// 1D histos
123  TH1* Draw(TTree* tree, const std::string& var, int nbins, double* xbins, const std::string& categ="all",
124  const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1,bool scale_errors=true);
125  TH1* Draw(TTree* tree, const std::string& var, int nbins, double xmin, double xmax, const std::string& categ="all",
126  const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1,bool scale_errors=true);
127 
128  /// 2D histos
129  TH1* Draw(TTree* tree, const std::string& var, int nx, double* xbins, int ny, double* ybins,
130  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1,bool scale_errors=true);
131  TH1* Draw(TTree* tree, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax,
132  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1,bool scale_errors=true);
133 
134 
135  void Draw(TTree* tree, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax, const std::string& idVar, std::vector<int> idSel, std::vector<std::string> idName, std::vector<int> idColor, const std::string& cut="", const std::string& root_opt = "", const std::string& opt = "", double norm = 1., bool scale_errors = true);
136 
137 
138  void Draw(TTree* tree_mc, TTree* tree_data, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax, const std::string& idVar, std::vector<int> idSel, std::vector<std::string> idName, std::vector<int> idColor, const std::string& cut="", const std::string& root_opt = "", const std::string& opt = "", double norm = 1., bool scale_errors = true);
139 
140  void Draw(TTree* tree, const std::string& var, int nx, double* xbins, int ny, double* ybins,
141  const std::string& idvar, std::vector<int> idSel, std::vector<std::string> idName, std::vector<int> idColor,
142  const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1, bool scale_errors=true);
143 
144 
145  void Draw(TTree* tree_mc, TTree* tree_data, const std::string& var, int nx, double* xbins, int ny, double* ybins,
146  const std::string& idvar, std::vector<int> idSel, std::vector<std::string> idName, std::vector<int> idColor,
147  const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1, bool scale_errors=true);
148 
149  //---------- Ratios, efficiencies, purities and significances -------------
150 
151  /// Get the efficiency (BayesDivide ratio) of two histograms in which the numerator (cut1+cut2) is a subset of the denominator (cut2).
152  /// Integrate over "var" between xmin and xmax. This is useful for doing quick optimisation studies,
153  /// where one can loop over several cut options to see the effect they have.
154  double GetEff(TTree* tree, const std::string& var, double xmin, double xmax,
155  const std::string& cut1, const std::string& cut2, const std::string& root_opt = "", const std::string& opt = "");
156 
157  /// See other GetEff() interface for documentation. In this interface,
158  /// errlow and errhigh will be filled with the upper and lower errors on the efficiency.
159  double GetEff(TTree* tree, const std::string& var, double xmin, double xmax, double& errlow, double& errhigh,
160  const std::string& cut1, const std::string& cut2, const std::string& root_opt = "", const std::string& opt = "");
161 
162 
163  //! [DrawingToolsBase_eff_ratio]
164  /// 1D Ratio between two independent cuts (the denominator cut is cut2, the numerator cut is cut1)
165  void DrawRatio(TTree* tree, const std::string& var, int nbins, double* xbins,
166  const std::string& cut1, const std::string& cut2, const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
167  void DrawRatio(TTree* tree, const std::string& var, int nx, double xmin, double xmax,
168  const std::string& cut1, const std::string& cut2, const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
169 
170  // 1D Efficiency (ratio between dependent cuts: the denominator cut is cut2, the numerator cut is cut1+cut2, meaning
171  // that the numerator is a subsample of the denominator and multinomial errors should be used)
172  // This method can be used to plot the efficiency of a given cut (default tree),
173  // the selection efficiency (truth tree) or the selection purity (default tree).
174  // This method uses TGraphAsymmErrors
175  void DrawEff(TTree* tree, const std::string& var, int nbins, double* xbins, const std::string& cut1, const std::string& cut2,
176  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
177  void DrawEff(TTree* tree, const std::string& var, int nx, double xmin, double xmax, const std::string& cut1, const std::string& cut2,
178  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
179 
180 
181  /// ratio between two Efficiencies
182  void DrawDoubleEff(TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins,
183  const std::string& cut1, const std::string& cut2, const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
184 
185  void DrawDoubleEff(TTree* tree1, TTree* tree2, const std::string& var, int nx, double xmin, double xmax,
186  const std::string& cut1, const std::string& cut2, const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
187 
188 
189  /// 1D significance
190  void DrawSignificance(TTree* tree, const std::string& var, int nbins, double* xbins, const std::string& cut1, const std::string& cut2,
191  double norm=1, double rel_syst=0,const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
192  void DrawSignificance(TTree* tree, const std::string& var, int nbins, double xmin, double xmax, const std::string& cut1, const std::string& cut2,
193  double norm=1, double rel_syst=0,const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
194  //! [DrawingToolsBase_eff_ratio]
195 
196 
197  void DrawGraph(TGraphAsymmErrors* eff, int nbins, double* xbins,
198  const std::string& uroot_opt, const std::string& uopt, const std::string& leg, double ymax=1.05);
199 
200  void DumpGraph(TGraphAsymmErrors* graph, int nbins, const std::string& uopt);
201 
202 
203  //---------- Events, Ratios, efficiencies and purities VS cuts -------------
204 
205  /// Get a TH1 containing the number of events passing the selection as a function of the cut
206  TH1_h* GetEventsVSCut(TTree* tree, const std::string& var, const std::string& cut_norm, int isel, int branch, int& first_cut, int& last_cut,
207  const std::string& root_opt="", const std::string& opt="");
208 
209  //! [DrawingToolsBaseVsCutsMethods]
210  /// Draw the number of events passing the selection as a function of the cut
211  void DrawEventsVSCut(TTree* tree, const std::string& cut_norm="", int first_cut=-1, int last_cut=-1,
212  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
213 
214  /// Draw the number of events passing the selection as a function of the cut, for a given branch
215  void DrawEventsVSCut(TTree* tree, int branch, const std::string& cut_norm="", int first_cut=-1, int last_cut=-1,
216  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
217 
218  /// Draw the number of events passing the selection as a function of the cut, for a given selection and branch
219  void DrawEventsVSCut(TTree* tree, int isel, int branch, const std::string& cut_norm="", int first_cut=-1, int last_cut=-1,
220  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
221 
222 
223  /// Draw the ratio between two trees as a function of the cut
224  void DrawRatioVSCut(TTree* tree1, TTree* tree2, const std::string& precut="", int first_cut=-1, int last_cut=-1,
225  const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1.);
226 
227  /// Draw the ratio between two trees as a function of the cut for a given branch
228  void DrawRatioVSCut(TTree* tree1, TTree* tree2, int branch, const std::string& precut="", int first_cut=-1, int last_cut=-1,
229  const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1.);
230 
231  /// Draw the ratio between two trees as a function of the cut for a given selection and branch
232  void DrawRatioVSCut(TTree* tree1, TTree* tree2, int isel, int branch, const std::string& precut="", int first_cut=-1, int last_cut=-1,
233  const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1.);
234 
235 
236  /// Draw the selection efficiency as a function of the cut. Must use the truth tree as input
237  void DrawEffVSCut(TTree* tree, const std::string& signal="", const std::string& precut="", int first_cut=-1, int last_cut=-1,
238  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
239 
240  /// Draw the selection efficiency as a function of the cut for a given branch. Must use the truth tree as input
241  void DrawEffVSCut(TTree* tree, int branch, const std::string& signal="", const std::string& precut="", int first_cut=-1, int last_cut=-1,
242  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
243 
244  /// Draw the selection efficiency as a function of the cut for a given selection and branch. Must use the truth tree as input
245  void DrawEffVSCut(TTree* tree, int isel, int branch, const std::string& signal="", const std::string& precut="", int first_cut=-1, int last_cut=-1,
246  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
247 
248 
249  /// Draw the selection purity as a function of the cut. Must use the default tree as input
250  void DrawPurVSCut(TTree* tree, const std::string& signal="", const std::string& precut="", int first_cut=-1, int last_cut=-1,
251  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
252 
253  /// Draw the selection purity as a function of the cut for a given branch. Must use the default tree as input
254  void DrawPurVSCut(TTree* tree, int branch, const std::string& signal="", const std::string& precut="", int first_cut=-1, int last_cut=-1,
255  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
256 
257  /// Draw the selection purity as a function of the cut for a given selection and branch. Must use the default tree as input
258  void DrawPurVSCut(TTree* tree, int isel, int branch, const std::string& signal="", const std::string& precut="", int first_cut=-1, int last_cut=-1,
259  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
260  //! [DrawingToolsBaseVsCutsMethods]
261 
262  /// Draw the ratio between two samples as a function of the cut
263  void DrawRatioVSCut(TH1_h* h1, TH1_h* h2, int isel, int branch, int first_cut,
264  const std::string& root_opt, const std::string& opt, const std::string& leg);
265 
266 
267  //---------- Toy experiments methods -------------
268 
269  //! [DrawingToolsBaseDrawToyMethods]
270  /// This method draws the distribution of the number of selected events for all toys (one entry per toy in the histogram), provided a cut
271  /// This is useful to check that the systematic error bars correspond to the RMS of this distribution
272  void DrawToys(TTree* tree, const std::string& cut="", const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
273 
274  /// This method draws the distribution of the ratio of number of selected events between two samples for all toys (one entry per toy in the histogram),
275  /// provided a cut (the same for numerator and denominator)
276  void DrawToysRatio(TTree* tree1, TTree* tree2, const std::string& cut="",
277  const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1);
278 
279  /// This method draws the distribution of the ratio of number of selected events between two samples for all toys (one entry per toy in the histogram),
280  /// provided two cuts, one for the numerator and another for the denominator
281  void DrawToysRatioTwoCuts(TTree* tree1, TTree* tree2, const std::string& cut1, const std::string& cut2,
282  const std::string& root_opt="", const std::string& opt="", const std::string& leg="",double norm=1);
283  //! [DrawingToolsBaseDrawToyMethods]
284 
285 
286  /// Basic method used by the ones above
287  void DrawToysBase(TH1_h& result, TH1_h& entries, const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
288 
289  /// Draw the variations for systematic parameter ipar
290  void DrawVariations(const std::string& name, Int_t ipar=-1, int nx=100, double xmin=-5, double xmax=5,
291  const std::string& root_opt="", const std::string& opt="", const std::string& leg="");
292 
293  ///------------------------------------------------------------------------------
294  /// ---------- comparisons between two data samples (two trees) -----------------
295  ///------------------------------------------------------------------------------
296 
297  /// 1D comparison
298  void Draw(TTree* tree1, TTree* tree2, const std::string& var, int nx, double xmin, double xmax,
299  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1, bool scale_errors=false);
300  void Draw(TTree* tree1, TTree* tree2, const std::string& var, int nbins, double* xbins,
301  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1, bool scale_errors=false);
302 
303  /// 2D comparison
304  void Draw(TTree* tree1, TTree* tree2, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax,
305  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1, bool scale_errors=false);
306  void Draw(TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins, int ny, double* ybins,
307  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1, bool scale_errors=false);
308 
309 
310  /// Ratio between the two data samples with the same cut
311  void DrawRatio(TTree* tree1, TTree* tree2, const std::string& var, int nx, double xmin, double xmax,
312  const std::string& cut="", const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1);
313  void DrawRatio(TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins,
314  const std::string& cut="", const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1);
315 
316  void DrawRatioTwoCuts(TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins, int ny, double* ybins,
317  const std::string& cut1="", const std::string& cut2="", const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1, bool scale_errors=false);
318 
319 
320  /// Ratio between the two data samples with different cuts
321  void DrawRatioTwoCuts(TTree* tree1, TTree* tree2, const std::string& var, int nx, double xmin, double xmax,
322  const std::string& cut1, const std::string& cut2, const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1);
323  virtual void DrawRatioTwoCuts(TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins,
324  const std::string& cut1,const std::string& cut2, const std::string& root_opt="", const std::string& opt="", const std::string& leg="", double norm=1);
325 
326  /// just Draw the ratio histogram
327  void DrawRatio(TH1_h* ratio, const std::string& root_opt, const std::string& uopt, const std::string& leg);
328 
329  void Project(HistoStack* hs1, HistoStack* hs2, TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins, int ny, double* ybins,
330  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm2=1,bool scale_errors=true);
331 
332 
333  void ProjectNew(HistoStack* hs1, HistoStack* hs2, TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins, int ny, double* ybins,
334  const std::string& categ="all", const std::string& cut1="", const std::string& cut2="", const std::string& root_opt="", const std::string& opt="", double norm2=1,bool scale_errors=true);
335 
336  //------- Basic drawing functions -------------
337 
338  /// dump histo contents
339  void DumpHisto(TH1* histo, const std::string& uopt);
340 
341  /// Dump integral, underflow and overflow
342  void DumpHistoInfo(TH1* histo, const std::string& uopt);
343 
344  void DrawHisto(TH1* h, int lc, int lw, int fc, int fs, const std::string& root_opt="", const std::string& opt="",const std::string& leg_opt="",int mode=0);
345  void DrawHisto(TH1* h, int lw, int fc, int fs, const std::string& root_opt="", const std::string& opt="",const std::string& leg_opt="",int mode=0);
346  void DrawHisto(TH2* h, int lc, int lw, int fc, int fs, const std::string& root_opt="", const std::string& opt="",const std::string& leg_opt="",int mode=0);
347  void DrawHisto(TH3F* h, int lc, int lw, int fc, int fs, const std::string& opt="");
348 
349  void DrawHistoStack(HistoStack* hs, const std::string& categ, const std::string& root_opt, const std::string& opt,const std::string& leg_opt="",int mode=2);
350 
351  void DrawHistoStack(HistoStack* hs, const std::string& categ, const std::string& root_opt, const std::string& opt, int lc, int lw, int fc, int fs, const std::string& leg_opt="",int mode=2);
352 
353  void DrawHistoStacks(HistoStack* hs1, HistoStack* hs2,
354  const std::string& categ, const std::string& root_opt, const std::string& opt, double norm);
355 
356  void DrawRatioHistoStacks(HistoStack* hs1, HistoStack* hs2,
357  const std::string& root_opt, const std::string& opt, double norm, const std::string& leg="");
358 
359 
360  void Project(HistoStack* hs, const std::string& sample_name, TTree* tree, const std::string& var, int nx, double* xbins, int ny, double* ybins,
361  const std::string& categ="all", const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1,bool scale_errors=true);
362 
363  void Project(HistoStack* hs, TTree* tree, const std::string& var, int nx, double* xbins, int ny, double* ybins,
364  const std::string& idVar, std::vector<int> idSel, std::vector<std::string> idName, std::vector<int> idColor,
365  const std::string& cut="", const std::string& root_opt="", const std::string& opt="", double norm=1, bool scale_errors=true);
366 
367  //------- Project the trees into histograms -------------
368 
369  TH1_h* GetHisto(TTree* tree, const std::string& name, const std::string& var, int nx, double* xbins,
370  const std::string& cut, const std::string& root_opt, const std::string& opt, double scale, bool scale_errors=true, int toy_ref=-1);
371 
372  virtual TH2_h* GetHisto(TTree* tree, const std::string& name, const std::string& var, int nx, double* xbins, int ny, double* ybins,
373  const std::string& cut, const std::string& root_opt, const std::string& opt, double scale, bool scale_errors=true, int toy_ref=-1);
374 
375  virtual TH1_h* GetHisto(HistoStack* hs, TTree* tree, const std::string& name, const std::string& var, int nx, double* xbins,
376  const std::string& cut, const std::string& root_opt, const std::string& opt, TH1_h*& hsyst, double scale, bool scale_errors=true, int toy_ref=-1);
377 
378  TH1_h* GetHisto(HistoStack* hs, TTree* tree, const std::string& name, const std::string& var, int nx, double* xbins,
379  const std::string& cut, const std::string& root_opt, const std::string& opt, double scale, bool scale_errors=true, int toy_ref=-1);
380 
381 
382  TH1_h* GetRatioHisto(HistoStack* hs1, HistoStack* hs2, const std::string& opt);
383 
384  virtual TH1_h* GetRatioHisto(TTree* tree1, TTree* tree2, const std::string& name, const std::string& var, int nx, double* xbins,
385  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, double norm, double scale, bool scale_errors=true, int toy_ref=-1);
386 
387  virtual void FillHistoErrors(HistoStack* hs1, HistoStack* hs2, TTree* tree1,TTree* tree2, const std::string& name, const std::string& var, int nx, double* xbins,
388  const std::string& cut1, const std::string& cut2, const std::string& opt, double norm, TH1_h* hstat, TH1_h*& hsyst);
389 
390  virtual void FillHistoErrors(HistoStack* hs1, HistoStack* hs2, TH1_h* histo, const std::string uopt);
391 
392  /// fill/update systematics information (fill appopriate histograms) for the stacks
393  virtual void UpdateSystInfo(HistoStack* hs1, HistoStack* hs2, TTree* tree1,TTree* tree2, const std::string& var, int nx, double* xbins,
394  const std::string& cut1, const std::string& cut2, const std::string& opt, double norm);
395 
396  virtual void FillGraphErrors(HistoStack* hs1, HistoStack* hs2, TGraphAsymmErrors* graph, const std::string uopt);
397 
398  //------ Drawing style ---------------
399 
400 
401  /// Dump position and size of the legend/small legend
402  void DumpLegendPos() {
403  std::cout << "x = " << _legendPos[0]
404  << ", y = " << _legendPos[1]
405  << ", width = " << _legendSize[0]
406  << ", height = " << _legendSize[1]
407  << std::endl;
408  }
409  void DumpSmallLegendPos() {
410  std::cout << "x = " << _legendPos[0]
411  << ", y = " << _legendPos[1]
412  << ", width = " << _legendSmallSize[0]
413  << ", height = " << _legendSmallSize[1]
414  << std::endl;
415  }
416 
417  //! [DrawingToolsCommandLineOptions]
418 
419  /// Set the height (in normalized coordinates: NDC) of each legend entry
420  void SetLegendEntryHeight(double h){drawUtils::legendEntryHeight=h;}
421 
422  /// Set position and size of the legend
423  void SetLegendParam(double a, double b, double c, double d);
424 
425  /// Set legend/small legend position by double (-999 keep current value)
426  /// or by string ("l"=left, "r"=right , "c"=center, "t"=top, "b"=bottom)
427  void SetLegendPos(double x=-999, double y=-999);
428  void SetLegendPos(std::string pos);
429 
430  /// Set legend/small legend size, width and height (if -999 keep same value)
431  void SetLegendSize(double w = -999, double h = -999);
432  void SetSmallLegendSize(double w = -999, double h = -999){if (w != -999) _legendSmallSize[0] = w; if (h != -999) _legendSmallSize[1] = h;}
433 
434  /// Get position/size of the legend/small legend
435  double GetLegendX() { return _legendPos[0]; }
436  double GetLegendY() { return _legendPos[1]; }
437  double GetLegendW() { return _legendSize[0]; }
438  double GetLegendH() { return _legendSize[1]; }
439  double GetSmallLegendX() { return _legendPos[0]+_legendSize[0]-_legendSmallSize[0]; }
440  double GetSmallLegendY() { return _legendPos[1]+_legendSize[1]-_legendSmallSize[1]; }
441  double GetSmallLegendW() { return _legendSmallSize[0]; }
442  double GetSmallLegendH() { return _legendSmallSize[1]; }
443 
444  /// Set the stat option (by int or string)
445  void SetOptStat(int opt){ _stat_option=opt; }
446  void SetOptStat(Option_t *stat);
447 
448  /// Set/Get the stat box size
449  double GetStatW() { return gStyle->GetStatH(); }
450  double GetStatH() { return gStyle->GetStatW(); }
451  void SetStatSize(double w = -999, double h = -999) {if (w != -999) gStyle->SetStatW(w); if (h != -999) gStyle->SetStatH(h);}
452 
453  /// Set/Get the stat box position (if -999 keep same value)
454  double GetStatX() { return gStyle->GetStatX(); }
455  double GetStatY() { return gStyle->GetStatY(); }
456  void SetStatPos(double x = -999, double y = -999);
457 
458  /// Change the fill style
459  void SetStackFillStyle(int FillStyle) { _stack_fill_style= FillStyle;};
460 
461  /// Make each histogram in the stack have a different fill style.
462  void SetDifferentStackFillStyles(bool diff = true) { _different_fill_styles = diff; };
463 
464  /// change the marker style
465  void SetMarkerStyle(int style) { _marker_style = style; }
466 
467  /// change the marker size
468  void SetMarkerSize(double size) { _marker_size = size; }
469 
470  /// Set the fill style of the current histogram..
471  void SetFillStyle(int style) { _fill_style = style; }
472 
473  /// Set the line width of the current histogram..
474  void SetLineWidth(int width) { _line_width = width; }
475 
476  /// Set the line color of the current histogram..
477  void SetLineColor(int color) { _line_color = color; }
478  void SetLineColor(EColor kColor) { _line_color = kColor; }
479 
480  /// Set the line color of the current histogram..
481  void SetFillColor(int color) { _fill_color = color; }
482  void SetFillColor(EColor kColor) { _fill_color = kColor; }
483 
484  /// Set the color for the MC error bars
485  void SetMCErrorColor(EColor kColor) { _mcerror_color = kColor; }
486  void SetMCErrorColor(int color) { _mcerror_color = color; }
487 
488  void SetMCStatErrorColor(EColor kColor) { _mcstaterror_color = kColor; }
489  void SetMCStatErrorColor(int color) { _mcstaterror_color = color; }
490 
491  /// Set the auto colors when superimposing histograms
492  void SetAutoColors(int colors[],int ncolors);
493 
494  /// Set the auto Markers when superimposing histograms
495  void SetAutoMarkers(int markers[], int nmarkers);
496 
497  /// Setter and Getter for params controlling the efficiency calculation
498  const std::string& GetEffDivideParams() { return _eff_params;}
499  void SetEffDivideParams(const std::string& params);
500 
501  /// Setter of default params
503 
504  /// Set the title in X
505  void SetTitleX(const std::string& titleX){_titleX=titleX;}
506 
507  /// Set the title in Y
508  void SetTitleY(const std::string& titleY){_titleY=titleY;}
509 
510  /// Set the title that appears at the top of the plot.
511  void SetTitle(const std::string& title){_title=title;}
512 
513  /// Set the label for the data when drawing comparison plots. Defaults to "Data".
514  /// Setting it to "" (empty string) will disable adding it to the legend.
515  void SetDataLabel(const std::string& label, Color_t color = kBlack) {_data_label = label; _data_color = color;}
516 
517  /// Set the label for the mc when drawing comparison plots. Defaults to "MC all".
518  /// Setting it to "" (empty string) will disable adding it to the legend.
519  void SetAllMCLabel(const std::string& label, Color_t color = kBlack) {_allmc_label = label; _allmc_color = color;}
520 
521  /// Set the label for the mc with only statistical errors when drawing comparison plots. Defaults to "MC all (stat)".
522  /// Setting it to "" (empty string) will disable adding it to the legend.
523  void SetAllMCStatLabel(const std::string& label){_allmcstat_label=label;}
524 
525  /// Set the label for the mc with only systematic errors when drawing comparison plots. Defaults to "MC all (syst)".
526  /// Setting it to "" (empty string) will disable adding it to the legend.
527  void SetAllMCSystLabel(const std::string& label){_allmcstat_label=label;}
528 
529  /// Set the minimum of the Y-axis. By default the minimum is set to 0.
530  /// Call SetMinY() to revert to the default behaviour.
531  void SetMinY(double minY=0);
532 
533  /// Set the maximum of the Y-axis. By default the maximum is set automatically by the DrawingTools.
534  /// Call SetMaxY() to revert to the default behaviour.
535  void SetMaxY(double maxY=0){_maxY = maxY;}
536 
537  /// Set the minimum and maximum of the Y-axis. See the documentation of SetMinY and SetMaxY for the
538  /// default behaviour. Call SetRangeY() to revert to the default behaviour.
539  void SetRangeY(double minY=0, double maxY=0) {SetMinY(minY); SetMaxY(maxY);}
540 
541  /// Set the current histogram to be drawn with a logarithmic Y axis.
542  void SetLogY(bool logY = true);
543 
544  /// Set the current 2D histogram to be drawn with a logarithmic Z axis (works only for category "all").
545  void SetLogZ(bool logZ = true);
546 
547  /// Set the maximum value in Y relative to the bin with maximum content
548  void SetRelativeMaxY(double maxY){_relativeMaxY=maxY;}
549 
550  /// Gets the root error style from the user option
551  std::string GetErrorStyle(const std::string& opt);
552 
553  /// switch on/off 2p2h type for reaction histos
554  void SetDraw2p2h(bool draw = true){_draw_2p2h=draw;}
555 
556  //! [DrawingToolsCommandLineOptions]
557 
558  //------ Draw cut lines --------------
559 
560  //! [DrawingToolsBaseDrawCutLineMethods]
561  /// Draw a vertical line at the specified X value, spanning the currently-drawn histogram.
562  /// See note in DrawCutLine() about legends being re-drawn when calling this function.
563  /// If addarrow is set to true, then an arrow indicating the direction of the cut is drawn.
564  /// arrowdir respects the following options:
565  /// l : Draw the arrow pointing to the left
566  /// r : Draw the arrow pointing to the right (default)
567  /// arrowpos specifies the fractional length along the cut line to draw the arrow at, measuring
568  /// from the bottom of the line. Defaults to half way along.
569  void DrawCutLineVertical(double xval, bool addarrow = false, std::string arrowdir = "l", double arrowpos = 0.5);
570 
571  /// Draw a horizontal line at the specified Y value, spanning the currently-drawn histogram.
572  /// See note in DrawCutLine() about legends being re-drawn when calling this function.
573  /// If addarrow is set to true, then an arrow indicating the direction of the cut is drawn.
574  /// arrowdir respects the following options:
575  /// u : Draw the arrow pointing upwards (default)
576  /// d : Draw the arrow pointing downwards
577  /// arrowpos specifies the fractional length along the cut line to draw the arrow at, measuring
578  /// from the left end of the line. Defaults to half way along.
579  void DrawCutLineHorizontal(double yval, bool addarrow = false, std::string arrowdir = "u", double arrowpos = 0.5);
580 
581  /// Draw an abritary line between two points. If a legend had already been created by the
582  /// DrawingTools, and drawn on the current pad, it is re-drawn. This means that the line
583  /// does not cover it up.
584  void DrawCutLine(double xmin, double ymin, double xmax, double ymax);
585 
586  /// Draw a box defined by the minimum and maximum points. The opt parameter specifies,
587  /// among other things, which sides of the box to draw:
588  /// t : draw the (t)op of the box
589  /// b : draw the (b)ottom of the box
590  /// l : draw the (l)eft of the box
591  /// r : draw the (r)ight of the box
592  /// nochop : Don't constrain the sides of the box to stay within the current axes.
593  ///
594  /// See note in DrawCutLine() about legends being re-drawn when calling this function.
595  void DrawCutRegion(double xmin, double ymin, double xmax, double ymax, std::string opt = "tblr");
596 
597  /// Draw an arrow between two points. If a legend had already been created by the
598  /// DrawingTools, and drawn on the current pad, it is re-drawn. This means that the line
599  /// does not cover it up.
600  void DrawCutArrow(double xmin, double ymin, double xmax, double ymax);
601 
602  /// Set the color of lines drawn with the DrawCut* functions.
603  void SetCutLineColor(int col) { _cut_line_col = col; }
604  void SetCutLineColor(EColor kCol) { _cut_line_col = kCol; }
605 
606  /// Set the width of lines drawn with the DrawCut* functions.
607  void SetCutLineWidth(int width) {_cut_line_width = width;}
608  //! [DrawingToolsBaseDrawCutLineMethods]
609 
610  //------ Toy Experiments ---------------
611 
612  /// Provide easy access to the managers.
613  CorrectionManager& corr(){return _corrections;}
614  SystematicManager& syst(){return _systematics;}
615  SelectionManager& sel() {return _selections;}
616  ConfigurationManager& conf(){return _configurations;}
617  CategoryManager& cat() {return _categories;}
618  DocStringManager& doc() {return _docStrings;}
619 
620  /*
621  void ReadManager(const std::string& file, const std::string& name, void* address){
622  TChain* _chain = new TChain("config");
623  _chain->AddFile(file.c_str());
624  // Set the branch addresses to read the tree
625  _chain->SetBranchAddress(name.c_str(), address);
626  Long64_t centry = _chain->LoadTree(0);
627  Int_t nb = _chain->GetEntry(0);
628  }
629  */
630  Header& header(){return _header;}
631 
632  /// an access to tools instance
633  SystematicsTools& syst_tools() {return _syst_tools;}
634  ConfigTreeTools& config_tools() {return _configTree_tools;}
635 
636  /// Print out the Standard Systematics for a given configuration
639  syst().DumpVariationSystematics();
640  }
641 
642  /// Print out the Weight Systematics for a given configuration
645  syst().DumpWeightSystematics();
646  }
647 
648  /// Print out all Systematics for a given configuration
650  syst().DumpSystematics();
651  }
652 
653  /// Print out the Corrections
654  void DumpCorrections(const std::string& file=""){
655  if (file!="") ReadCorrections(file);
656  corr().DumpCorrections();
657  if (_config_file!="") ReadCorrections(_config_file);
658  }
659 
660  /// Read the list of Corrections
661  void ReadCorrections(const std::string& file){
662  // ReadManager(file,"CorrMan", &_corrections);
663  corr().ReadCorrections(file);
664  }
665 
666  void ReadSystematics(const std::string& file){
667  // ReadManager(file,"SystMan", &_systematics);
668  syst().ReadSystematics(file);
669  }
670 
671  /// Print out the Configurations
672  void DumpConfigurations(const std::string& file=""){
673  if (file!="") ReadConfigurations(file);
674  conf().DumpConfigurations();
675  if (_config_file!="") ReadConfigurations(_config_file);
676  }
677 
678  /// Print out the Configuration
679  void DumpConfiguration(const std::string& name);
680 
681 
682  /// Read the list of Configurations
683  void ReadConfigurations(const std::string& file){
684  // ReadManager(file,"ConfMan", &_configurations);
685  conf().ReadConfigurations(file);
686  }
687 
688  ///------ Package versions -------------
689 
690  /// Dumps on the screen the highland/psyche software versions used to produce this file
691  void DumpSoftwareVersions(const std::string& file="");
692 
693  /// Dumps on the screen the software version of the original file (i.e. output of recon)
694  void DumpOriginalSoftwareVersion(const std::string& file="", bool all=true);
695 
696  ///------ Package versions -------------
697 
698 
699  void DumpFileInfo(const std::string& file="");
700 
701  //------ Track Categories ---------------
702 
703  /// Read the list of categories stored in the given file which can be used when plotting
704  /// stacked histograms
705  void ReadCategories(const std::string& file){cat().ReadCategories(file);}
706 
707  //! [DrawingToolsBase_categ]
708  /// Print out the list of categories which can be used when plotting stacked histograms
710 
711  /// Print out the list of categories stored in the given file which can be used when plotting
712  /// stacked histograms
713  void DumpCategories(const std::string& file){ReadCategories(file);cat().DumpCategories();if (_config_file!="") ReadCategories(_config_file);}
714 
715  /// Print the options saved for the given category, including the name of each category, the value
716  /// stored in the output file for that category, and the colour used to plot the category.
717  void DumpCategory(std::string category) {cat().DumpCategory(category);}
718  //! [DrawingToolsBase_categ]
719 
720  /// Update or add a category.
721  /// * categ_name is the name this category will have. This must be a variable that is stored in the
722  /// output file, such as "particle" (you can of course save your own variables).
723  /// * ntypes is the number of options your category will have.
724  /// * names is an array of length ntypes of the name of each option.
725  /// * codes is an array of length ntypes of the value stored in the output file for this option.
726  /// * colors is an array of length ntypes of the colour to plot each option with.
727  void ChangeCategory(const std::string& categ_name, int ntypes, std::string* names, int* codes, int* colors);
728 
729  /// Check whether a category has been defined
730  bool HasCategory(const std::string& categ_name);
731 
732  //------ Cuts ---------------
733 
734  /// Read the list of Selections
735  void ReadSelections(const std::string& file){
736  // _selections = NULL;
737  // ReadManager(file,"SelMan", &_selections);
738  sel().ReadSelections(file);
739 
740  }
741 
742  //! [DrawingToolsBase_DumpSelections]
743  /// Dump the list of Selections
744  void DumpSelections(const std::string& file="");
745 
746  /// Dump the list of branches in the selection provided selection index
747  void DumpBranches(Int_t sel_index=0);
748 
749  /// Dump the list of branches in the selection provided selection name
750  void DumpBranches(const std::string& sel_name);
751  //! [DrawingToolsBase_DumpSelections]
752 
753  //! [DrawingToolsBase_DumpSteps]
754  /// Print to screen the details of cuts for a given branch or selection. Specifying a branch of
755  /// -1 (the default) will print details for all branches.
756  /// When there are multiple selections the input index is for the selection
757  void DumpCuts(int branch=-1);
758 
759  /// Print to screen the details of steps for a given branch or selection. Specifying a branch of
760  /// -1 (the default) will print details for all branches.
761  /// When there are multiple selections the input index is for the selection
762  void DumpSteps(int branch=-1);
763 
764  /// Print to screen the details of cuts for a given branch and selection (name). Specifying a branch of
765  /// -1 (the default) will print details for all branches.
766  void DumpCuts(const std::string& sel_name, int branch=-1);
767 
768  /// Print to screen the details of steps for a given branch and selection (name). Specifying a branch of
769  /// -1 (the default) will print details for all branches.
770  void DumpSteps(const std::string& sel_name,int branch=-1);
771 
772  /// Print to screen the details of cuts for a given branch and selection (index). Specifying a branch of
773  /// -1 (the default) will print details for all branches.
774  void DumpCuts(Int_t sel_index, int branch);
775 
776  /// Print to screen the details of steps for a given branch and selection (index). Specifying a branch of
777  /// -1 (the default) will print details for all branches.
778  void DumpSteps(Int_t sel_index,int branch);
779  //! [DrawingToolsBase_DumpSteps]
780 
781  /// Get a vector of cut names for a given branch (in order) in a selection with a given name
782  std::vector<std::string> GetCutNames(const std::string& sel_name, int branch=0) {
783  if (sel().GetSelection(sel_name)) return sel().GetSelection(sel_name)->GetCutNames(branch);
784  return std::vector<std::string>();
785  }
786 
787  /// Get a vector of steps names for a given branch (in order) in a selection with a given name
788  std::vector<std::string> GetStepNames(const std::string& sel_name, int branch=0) {
789  if (sel().GetSelection(sel_name)) return sel().GetSelection(sel_name)->GetStepNames(branch);
790  return std::vector<std::string>();
791  }
792 
793  /// Get a vector of cut names for a given branch (in order) in a selection with a given index
794  std::vector<std::string> GetCutNames(Int_t sel_index, int branch) {
795  if (sel().GetSelection(sel_index)) return sel().GetSelection(sel_index)->GetCutNames(branch);
796  return std::vector<std::string>();
797  }
798 
799  /// Get a vector of steps names for a given branch (in order) in a selection with a given index
800  std::vector<std::string> GetStepNames(Int_t sel_index, int branch) {
801  if (sel().GetSelection(sel_index)) return sel().GetSelection(sel_index)->GetStepNames(branch);
802  return std::vector<std::string>();
803  }
804 
805  //------ Documentation -----
806 
807  //! [DrawingToolsBase_ops]
808  /// Explain the user drawing options
809  void ExplainOption(std::string name) {drawUtils::ExplainOption(name);}
810 
811  /// List all drawing options
813  //! [DrawingToolsBase_ops]
814 
815  //! [DrawingToolsBase_vars]
816  /// Explain the meaning of a variable stored in a tree. If no tree name is provided the "default" tree is used
817  void ExplainVar(std::string name, std::string tree_name = "default") {doc().ExplainVar(name, tree_name);}
818 
819  /// List all the variables stored in a tree. If no tree name is provided the "default" tree is used
820  void ListVars(std::string tree_name = "default") {doc().ListVars(tree_name);}
821  //! [DrawingToolsBase_vars]
822 
823  /// Read the details of docstrings from a given file. The details will have been read automatically
824  /// if you passed the path to a valid highland file in the DrawingTools or DrawingToolsBase constructor.
825  void ReadDocStrings(const std::string& file){
826  // ReadManager(file,"DocMan", &_docStrings);
827  doc().ReadDocStrings(file);
828  }
829 
830  //------ POT ---------------
831 
832  //! [DrawingToolsBase_POT]
833  /// Dump the POT information for this sample, provided the header tree
834  void DumpPOT(TTree* tree);
835 
836  /// Dump the POT information for this sample, provided an input file name
837  void DumpPOT(const std::string& file);
838  //! [DrawingToolsBase_POT]
839 
840  //--------------------------
841 
842  /// Read config tree
843  void ReadConfig(const std::string& file);
844 
845  /// Read any other variables in the config tree
846  void ReadOther(const std::string& file);
847  void ReadOther(TTree* chain);
848 
849  /// Print on the screen the purities for the different categories defined by "categ" and with cuts "cut".
850  /// The expected number of events are also printed, after scaling by events_ratio.
851  void PrintPurities(TTree* tree, const std::string& categ, const std::string& cut, double events_ratio = 1);
852 
853  /// Get all the graphs that have been drawn. Useful if you want to save them to file.
854  std::vector< TGraph* > GetGraphs() { return _saved_graphs; }
855 
856  /// Get the last graph that was drawn. Useful if you want to modify its appearance.
857  TGraph* GetLastGraph() { return _saved_graphs.back(); }
858 
859  /// Get all the 1D histos that have been drawn. Useful if you want to save them to file.
860  /// NOTE! The "same" plot may appear multiple times due to the way the comparison
861  /// histograms are drawn.
862  std::vector< TH1* > GetHistos() { return _saved_histos; }
863 
864  /// Get the last legend that was drawn. Useful if you want to modify its appearance.
865  TLegend* GetLastLegend() { return _legends.back(); }
866 
867  /// Change the label or drawing style of a entry in the legend provided the entry number
868  void ChangeLegendEntry(Int_t index, const std::string& new_label="", const std::string& new_opt="");
869 
870  /// Delete a given Legent entry provided its index
871  void DeleteLegendEntry(Int_t index);
872 
873  /// Get all the 1D histos that have been drawn. Useful if you want to save them to file.
874  /// NOTE! The "same" plot may appear multiple times due to the way the comparison
875  /// histograms are drawn.
876  std::vector< TH1* > Get2DHistos() { return _saved_histos; }
877 
878  /// Get all the last Histo that was drawn. Useful if you want to modify its appearance.
879  TH1* GetLastHisto() {
880  std::cout << "If it crashes you should maybe use GetLastStackTotal instead.\n";
881  if (_saved_histos.back()) return _saved_histos.back();
882  else std::cout << "No histos found. You can try GetLastStackTotal \n"; return NULL;
883  }
884 
885  /// Get the total from the most recently-drawn stacked histogram. Useful if you want to
886  /// save it to file.
887  TH1* GetLastStackTotal(int nexttolast=0) {
888  std::cout << "If it crashes you should maybe use GetLastHisto instead.\n";
889  if ( ! _saved_histoStacks.back()) {
890  std::cout << "No histoStacks found. You can try GetLastHisto\n"; return NULL; }
891  if (nexttolast>0){
892  if ((int)_saved_histoStacks.size() <= nexttolast) {
893  return NULL;
894  } else {
895  HistoStack* s = _saved_histoStacks[(int)_saved_histoStacks.size() - nexttolast - 1];
896  return s->GetTotal1D();
897  }
898  }
899  else{
900  HistoStack* s = _saved_histoStacks.back();
901  return s->GetTotal1D();
902  }
903  }
904 
905  /// Get the most recently-drawn stacked histogram. Useful to access its histograms
906  HistoStack* GetLastStack(int nexttolast=0) {
907  if ( ! _saved_histoStacks.back()) {
908  std::cout << "No histoStacks found. You can try GetLastHisto\n"; return NULL; }
909  if (nexttolast>0){
910  if ((int)_saved_histoStacks.size() <= nexttolast) {
911  return NULL;
912  } else {
913  return _saved_histoStacks[(int)_saved_histoStacks.size() - nexttolast - 1];
914  }
915  }
916  else{
917  return _saved_histoStacks.back();
918  }
919  }
920 
921 
922 
923  /// Start the creation of a PDF document and/or webpage which will contain the plots you make.
924  /// This makes it particularly easy to share many plots.
925  /// pdffile is the path to the PDF FILE that will be created
926  /// webpath is the path to the DIRECTORY in which the webpage and images will be placed.
927  ///
928  ///
929  /// There are two possible use cases for these functions:
930  /// draw.StartDocument(...); // Will create a canvas for you
931  /// draw.Draw(...); // Will draw on the right canvas
932  /// draw.AddDocumentPage(...); // Will save the current page
933  /// ...
934  /// draw.FinishDocument(); // Finish and close
935  ///
936  /// OR
937  ///
938  /// TCanvas canvas(...); // Create your own canvas
939  /// draw.StartDocument(...); // Won't create a canvas for you
940  /// draw.Draw(...); // Will draw on your canvas
941  /// draw.AddDocumentPage(...); // Will save the current page
942  /// ...
943  /// draw.FinishDocument(); // Finish and close
944  ///
945  /// In the first case, a canvas was automatically created. This canvas is
946  /// split into two sections - a header and a body. The header will be populated
947  /// with the "name" you provide in AddDocumentPage. This makes it easier to
948  /// understand what each plot is.
949  /// In the second case, it is assumed you know what you want, so we don't create
950  /// this header section.
951  void StartDocument(const std::string& title, bool pdf = true, bool web = false, const std::string& pdffile = "plots.pdf", const std::string& webpath = "plots");
952 
953  /// Add a page to the PDF document and/or webpage that was opened with StartDocument().
954  /// "name" will appear on web pages to give context to what each plot is. If StartDocument()
955  /// createdg a canvas for you, "name" will also appear in the header section of the PDF page.
956  void AddDocumentPage(const std::string& name);
957 
958  /// Close the PDF document / webpage that was opened with StartDocument. Note that you MUST call this
959  /// function or your PDF document will be corrupt / the webpage will be empty.
960  void FinishDocument();
961 
962  /// Make a directory on the filesystem.
963  int MakeDirectory(const std::string& path, mode_t mode);
964 
965 
966  //------ UTILS ---------------
967 
968  // replace accum_level[] with accum_level and selmu_ with truemu_
969  std::string ConvertCutForTruthTree(const std::string cut, bool replace_selmu = true);
970 
971  /// Compute the Chi2 without normalizing by area (as Chi2Test of root does)
972  /// h1/h2 should be already normalized by POT, with errors properly propagated: just get them from your DATA-mc plot with GetLastStackTotal(0) and GetLastStackTotal(1)
973  double GetChi2(const TH1* h1, const TH1* h2);
974  int GetNDOF(const TH1* h1, const TH1* h2);
975  double GetPvalue(double chi2, int ndof) {return TMath::Prob(chi2,ndof);}
976  double GetPvalue(const TH1* h1, const TH1* h2) {
977  double chi2 = GetChi2(h1, h2);
978  int ndof = GetNDOF(h1, h2);
979  return TMath::Prob(chi2,ndof);
980  }
981 
982 
983  protected:
984 
985  /// Get the fill style to apply to the i'th histogram in a stack. Depends on whether
986  /// SetDifferentStackFillStyles() has been called.
987  int GetFillStyle(int i);
988 
989  /// Counter for ensuring all histograms get a unique name
990  int _unique;
991 
992  bool _drawleg;
993  std::vector<TLegend*> _legends;
994 
995  // appearence parameters
996  double _legendParam[4];
997  double _legendSize[2];
998  double _legendPos[2];
999  double _legendSmallSize[2];
1000  double _statPos[2];
1001  std::string _legendPosS;
1002  int _stat_option;
1003  int _stack_fill_style;
1004  bool _different_fill_styles;
1005  int _marker_style;
1006  int _fill_style;
1007  int _fill_color;
1008  int _line_width;
1009  int _line_color;
1010  int _mcerror_color;
1011  int _mcstaterror_color;
1012  double _marker_size;
1013  int _cut_line_col;
1014  int _cut_line_width;
1015  std::string _titleX;
1016  std::string _titleY;
1017  std::string _title;
1018  Color_t _data_color;
1019  Color_t _allmc_color;
1020  std::string _data_label;
1021  std::string _allmc_label;
1022  std::string _allmcstat_label;
1023  std::string _allmcsyst_label;
1024  double _minY;
1025  double _maxY;
1026  double _relativeMaxY;
1027  bool _logY;
1028  bool _logZ;
1029 
1030  /// parameter to control options for TGraphAsymmErrors::Divide() method, the one used to get the efficiencies
1031  std::string _eff_params;
1032 
1033  // switch on/off 2p2h type for reaction histos
1034  bool _draw_2p2h;
1035 
1036  // input file
1037  TFile *_file;
1038 
1039  int _same_level;
1040  int _same_level_tot;
1041  int _auto_colors[NMAXAUTOCOLORS];
1042  int _auto_markers[NMAXAUTOCOLORS];
1043 
1044  // keep pointers to avoid memory leaks
1045  std::vector< TH1* > _saved_histos;
1046  std::vector< TH2* > _saved_histos2D;
1047  std::vector< HistoStack* > _saved_histoStacks;
1048  std::vector< TGraph* > _saved_graphs;
1049  std::vector< TLine* > _cut_lines;
1050 
1051  TPad* _MainPad;
1052  TPad* _RatioPad;
1053 
1054  TCanvas* _pdfcanvas;
1055  TPad* _bodypad;
1056  TPad* _headpad;
1057  std::string _pdfpath;
1058  std::string _webpath;
1059  std::string _webheader;
1060  std::string _webbody;
1061 
1062  std::string _config_file;
1063 
1064  DocStringManager _docStrings;
1065  CategoryManager _categories;
1066  ConfigurationManager _configurations;
1067  CorrectionManager _corrections;
1068  SystematicManager _systematics;
1069  SelectionManager _selections;
1070  SystematicsTools _syst_tools;
1071  ConfigTreeTools _configTree_tools;
1072  Header _header;
1073 
1074  Int_t _minAccumLevelToSave;
1075 
1076 };
1077 
1078 
1079 #endif
1080 
TH1_h * GetEventsVSCut(TTree *tree, const std::string &var, const std::string &cut_norm, int isel, int branch, int &first_cut, int &last_cut, const std::string &root_opt="", const std::string &opt="")
Get a TH1 containing the number of events passing the selection as a function of the cut...
void DumpConfigurations(SystematicManager *syst=NULL)
Dump summary info about all configurations.
void ChangeLegendEntry(Int_t index, const std::string &new_label="", const std::string &new_opt="")
Change the label or drawing style of a entry in the legend provided the entry number.
void SetAllMCStatLabel(const std::string &label)
HistoStack * GetLastStack(int nexttolast=0)
Get the most recently-drawn stacked histogram. Useful to access its histograms.
int _unique
Counter for ensuring all histograms get a unique name.
void DumpFileInfo(const std::string &file="")
---— Package versions ----------—
void PrintEventNumbers(TTree *tree, const std::string &cut, const std::string &file="", int toy_ref=-1)
Print the event number of a specific selection.
std::string GetSameLevel(const std::string &root_opt)
Get the superposition level.
TLegend * GetLastLegend()
Get the last legend that was drawn. Useful if you want to modify its appearance.
void AddDocumentPage(const std::string &name)
void SetMarkerSize(double size)
change the marker size
TGraph * GetLastGraph()
Get the last graph that was drawn. Useful if you want to modify its appearance.
double GetEff(TTree *tree, const std::string &var, double xmin, double xmax, const std::string &cut1, const std::string &cut2, const std::string &root_opt="", const std::string &opt="")
void SetLegendSize(double w=-999, double h=-999)
Set legend/small legend size, width and height (if -999 keep same value)
void DumpSoftwareVersions(const std::string &file="")
—— Package versions -------——
void DumpCategories(const std::string &file)
void SetCutLineColor(int col)
Set the color of lines drawn with the DrawCut* functions.
std::vector< std::string > GetStepNames(Int_t ibranch=0) const
Return all the names of the steps, in the order they were added.
void DrawPurVSCut(TTree *tree, const std::string &signal="", const std::string &precut="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
Draw the selection purity as a function of the cut. Must use the default tree as input.
void DrawCutArrow(double xmin, double ymin, double xmax, double ymax)
void ReadCorrections(const std::string &file)
Read the list of Corrections.
void SetLogY(bool logY=true)
Set the current histogram to be drawn with a logarithmic Y axis.
const std::string & GetEffDivideParams()
Setter and Getter for params controlling the efficiency calculation.
std::vector< TGraph *> GetGraphs()
Get all the graphs that have been drawn. Useful if you want to save them to file. ...
void SetLegendEntryHeight(double h)
[DrawingToolsCommandLineOptions]
double GetLegendX()
Get position/size of the legend/small legend.
TH1 * GetLastStackTotal(int nexttolast=0)
void SetDifferentStackFillStyles(bool diff=true)
Make each histogram in the stack have a different fill style.
void ExplainVar(std::string name, std::string tree_name="default")
[DrawingToolsBase_ops]
void DrawToysRatioTwoCuts(TTree *tree1, TTree *tree2, const std::string &cut1, const std::string &cut2, const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=1)
TH1 * Draw(TTree *tree, const std::string &var, int nbins, double *xbins, const std::string &categ="all", const std::string &cut="", const std::string &root_opt="", const std::string &opt="", double norm=1, bool scale_errors=true)
1D histos
void DumpCategory(std::string category)
void DumpVariationSystematics()
Dump all variationSystematics.
std::string FormatCut(const std::string &cut)
Give the appropriate format to any cut.
void SetRelativeMaxY(double maxY)
Set the maximum value in Y relative to the bin with maximum content.
void ExplainVar(const std::string &name, const std::string &tree_name)
Print the details of the specified variable in the given tree.
std::string AddRangeCut(const std::string &var, int nx, double *xbins, int ny, double *ybins, const std::string &cut, const std::string &uopt)
Add cut on range shown on plot.
void ReadSelections(const std::string &file)
Read the list of Selections.
void DrawToysRatio(TTree *tree1, TTree *tree2, const std::string &cut="", const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=1)
double GetChi2(const TH1 *h1, const TH1 *h2)
std::string GetErrorStyle(const std::string &opt)
Gets the root error style from the user option.
void Reset()
reset all saved histograms
virtual void UpdateSystInfo(HistoStack *hs1, HistoStack *hs2, TTree *tree1, TTree *tree2, const std::string &var, int nx, double *xbins, const std::string &cut1, const std::string &cut2, const std::string &opt, double norm)
fill/update systematics information (fill appopriate histograms) for the stacks
void StartDocument(const std::string &title, bool pdf=true, bool web=false, const std::string &pdffile="plots.pdf", const std::string &webpath="plots")
double * GetVariableBins(int nx, double xmin, double xmax, double *)
Get a vector with variable binning.
void SetFillColor(int color)
Set the line color of the current histogram..
This class handles POT info, SoftwareVersion and IsMC.
Definition: Header.hxx:10
void DrawEffVSCut(TTree *tree, const std::string &signal="", const std::string &precut="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
Draw the selection efficiency as a function of the cut. Must use the truth tree as input...
void DumpSystematics()
Dump all systematics.
void SetMinY(double minY=0)
TH1 * GetLastHisto()
Get all the last Histo that was drawn. Useful if you want to modify its appearance.
void SetAutoColors(int colors[], int ncolors)
Set the auto colors when superimposing histograms.
std::string GetSameRootOption(const std::string &root_opt)
extract the same or sames option from the full root option
void DumpCategories()
Dump the map of track categories.
void SetLogZ(bool logZ=true)
Set the current 2D histogram to be drawn with a logarithmic Z axis (works only for category "all")...
void DrawCutLine(double xmin, double ymin, double xmax, double ymax)
void SetMarkerStyle(int style)
change the marker style
void DrawCutLineHorizontal(double yval, bool addarrow=false, std::string arrowdir="u", double arrowpos=0.5)
void SetCutLineWidth(int width)
Set the width of lines drawn with the DrawCut* functions.
The maximum number of systematics that is supported.
void DumpSteps(int branch=-1)
void ReadSelections(const std::string &file)
void ReadConfigurations(const std::string &file)
Read the list of Configurations.
std::vector< std::string > GetCutNames(const std::string &sel_name, int branch=0)
[DrawingToolsBase_DumpSteps]
std::string _eff_params
parameter to control options for TGraphAsymmErrors::Divide() method, the one used to get the efficien...
void CreateLegend(const std::string &uopt="")
create the legend
void PrintPurities(TTree *tree, const std::string &categ, const std::string &cut, double events_ratio=1)
void SetDataLabel(const std::string &label, Color_t color=kBlack)
void DrawDoubleEff(TTree *tree1, TTree *tree2, const std::string &var, int nx, double *xbins, const std::string &cut1, const std::string &cut2, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
ratio between two Efficiencies
void SetStackFillStyle(int FillStyle)
Change the fill style.
std::vector< TH1 *> Get2DHistos()
void ChangeCategory(const std::string &categ_name, int ntypes, std::string *names, int *codes, int *colors)
[DrawingToolsBase_categ]
std::vector< std::string > GetCutNames(Int_t sel_index, int branch)
Get a vector of cut names for a given branch (in order) in a selection with a given index...
double GetStatW()
Set/Get the stat box size.
void DumpBranches(Int_t sel_index=0)
Dump the list of branches in the selection provided selection index.
void ListVars(const std::string &tree_name)
List all the variables that were stored in this tree.
void DumpLegendPos()
Dump position and size of the legend/small legend.
void DumpConfiguration(const std::string &name)
Print out the Configuration.
std::vector< std::string > GetStepNames(const std::string &sel_name, int branch=0)
Get a vector of steps names for a given branch (in order) in a selection with a given name...
int MakeDirectory(const std::string &path, mode_t mode)
Make a directory on the filesystem.
double GetStatX()
Set/Get the stat box position (if -999 keep same value)
void DrawSignificance(TTree *tree, const std::string &var, int nbins, double *xbins, const std::string &cut1, const std::string &cut2, double norm=1, double rel_syst=0, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
1D significance
std::string GetNoSameRootOption(const std::string &root_opt)
remove same and sames options from the root option
CorrectionManager & corr()
[DrawingToolsBaseDrawCutLineMethods]
std::string GetUniqueName(const std::string &name)
void ReadOther(const std::string &file)
Read any other variables in the config tree.
void SetAllMCSystLabel(const std::string &label)
void DumpConfigurations(const std::string &file="")
Print out the Configurations.
void ScaleHisto(TH1 *h, double scale, bool scale_errors=true)
Scale an histogram and its errors(when requested)
void DumpWeightSystematics()
Dump all weightSystematics.
void SetLegendPos(double x=-999, double y=-999)
void SetAutoMarkers(int markers[], int nmarkers)
Set the auto Markers when superimposing histograms.
void DumpOriginalSoftwareVersion(const std::string &file="", bool all=true)
Dumps on the screen the software version of the original file (i.e. output of recon) ...
std::vector< std::string > GetStepNames(Int_t sel_index, int branch)
Get a vector of steps names for a given branch (in order) in a selection with a given index...
void ExplainOption(OptionEnum opt)
Explain a given option given as enum.
void ReadDocStrings(const std::string &file)
[DrawingToolsBase_vars]
void ReadDocStrings(const std::string &file)
void DrawGraph(TGraphAsymmErrors *eff, int nbins, double *xbins, const std::string &uroot_opt, const std::string &uopt, const std::string &leg, double ymax=1.05)
[DrawingToolsBase_eff_ratio]
void SetLegendParam(double a, double b, double c, double d)
Set position and size of the legend.
void ReadConfig(const std::string &file)
[DrawingToolsBase_POT]
void SetRangeY(double minY=0, double maxY=0)
void DumpSelections(const std::string &file="")
void SetMCErrorColor(EColor kColor)
Set the color for the MC error bars.
void DrawToysBase(TH1_h &result, TH1_h &entries, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
[DrawingToolsBaseDrawToyMethods]
double GetEntries(TTree *tree, const std::string &cut)
Get number (sum of weights) of events (i.e. bunches) passing "cut".
void ListVars(std::string tree_name="default")
List all the variables stored in a tree. If no tree name is provided the "default" tree is used...
void DumpSystematics()
Print out all Systematics for a given configuration.
SystematicsTools & syst_tools()
an access to tools instance
void DumpVariationSystematics()
Print out the Standard Systematics for a given configuration.
void DrawEventsVSCut(TTree *tree, const std::string &cut_norm="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
void DumpPOT(TTree *tree)
void DumpCorrections()
Dump all corrections.
void ListOptions()
List sll valid options and a description of each of them.
void ExplainOption(std::string name)
void DumpCuts(int branch=-1)
[DrawingToolsBase_DumpSelections]
void SetLineColor(int color)
Set the line color of the current histogram..
void SetMaxY(double maxY=0)
void DumpHistoInfo(TH1 *histo, const std::string &uopt)
Dump integral, underflow and overflow.
void SetFillStyle(int style)
Set the fill style of the current histogram..
void ReadConfigurations(const std::string &file)
Read configurations from a file.
void SetAllMCLabel(const std::string &label, Color_t color=kBlack)
std::vector< std::string > GetCutNames(Int_t ibranch=0) const
Return all the names of the cuts, in the order they were added.
void DeleteLegendEntry(Int_t index)
Delete a given Legent entry provided its index.
void SetTitle(const std::string &title)
Set the title that appears at the top of the plot.
void DrawToys(TTree *tree, const std::string &cut="", const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
void DrawRatioVSCut(TTree *tree1, TTree *tree2, const std::string &precut="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=1.)
Draw the ratio between two trees as a function of the cut.
void DumpCorrections(const std::string &file="")
Print out the Corrections.
void DrawCutRegion(double xmin, double ymin, double xmax, double ymax, std::string opt="tblr")
void DumpCategory(const std::string &categ)
Dump the options stored for the given category.
void SetDefaultEffDivideParams()
Setter of default params.
void ReadSystematics(const std::string &file)
Read the systematics from a file.
void SetOptStat(int opt)
Set the stat option (by int or string)
SelectionBase * GetSelection(const std::string &name, bool print_error=true)
Return the selection that was registered with the given name. NULL if it does not exist...
std::vector< TH1 *> GetHistos()
void SetLineWidth(int width)
Set the line width of the current histogram..
void EnableAllWeightSystematics()
Enable all systematic weightSystematics.
TH1_h * GetTotal1D()
Return the total 1D histo.
Definition: HistoStack.hxx:67
void DrawRatio(TTree *tree, const std::string &var, int nbins, double *xbins, const std::string &cut1, const std::string &cut2, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
void ReadCategories(const std::string &file)
void SetTitleX(const std::string &titleX)
Set the title in X.
void ReadCategories(const std::string &file)
Build the categories from a root file.
void DumpHisto(TH1 *histo, const std::string &uopt)
dump histo contents
bool HasCategory(const std::string &categ_name)
Check whether a category has been defined.
void SetDraw2p2h(bool draw=true)
switch on/off 2p2h type for reaction histos
void DrawVariations(const std::string &name, Int_t ipar=-1, int nx=100, double xmin=-5, double xmax=5, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
Draw the variations for systematic parameter ipar.
void EnableAllVariationSystematics()
Enable all variationSystematics.
void ReadCorrections(const std::string &file, bool input=false)
Readthe corrections from a file.
void DumpWeightSystematics()
Print out the Weight Systematics for a given configuration.
void SetTitleY(const std::string &titleY)
Set the title in Y.
void DrawCutLineVertical(double xval, bool addarrow=false, std::string arrowdir="l", double arrowpos=0.5)
[DrawingToolsCommandLineOptions]
void ListOptions()
List all drawing options.