CMS 3D CMS Logo

Comparator.h
Go to the documentation of this file.
1 #ifndef __Validation_RecoParticleFlow_Comparator__
2 #define __Validation_RecoParticleFlow_Comparator__
3 
4 #include <cmath>
5 
6 #include <TF1.h>
7 #include <TFile.h>
8 #include <TH1.h>
9 #include <TLegend.h>
10 
11 /* #include <string> */
12 
13 class Style;
14 
15 class Comparator {
16 public:
17  enum Mode { NORMAL, SCALE, RATIO, GRAPH, EFF };
18 
19  Comparator() : rebin_(-1), xMin_(0), xMax_(0), resetAxis_(false), s0_(nullptr), s1_(nullptr), legend_(0, 0, 1, 1) {}
20 
21  Comparator(const char *file0, const char *dir0, const char *file1, const char *dir1)
22  : rebin_(-1), xMin_(0), xMax_(0), resetAxis_(false), s0_(nullptr), s1_(nullptr), legend_(0, 0, 1, 1) {
23  SetDirs(file0, dir0, file1, dir1);
24  }
25 
28  void SetDirs(const char *file0, const char *dir0, const char *file1, const char *dir1);
29 
30  // set the rebinning factor and the range
31  void SetAxis(int rebin, float xmin, float xmax) {
32  rebin_ = rebin;
33  xMin_ = xmin;
34  xMax_ = xmax;
35  resetAxis_ = true;
36  }
37 
38  // set the rebinning factor, unset the range
39  void SetAxis(int rebin) {
40  rebin_ = rebin;
41  resetAxis_ = false;
42  }
43 
44  // draws a Y projection of a slice along X
45  void DrawSlice(const char *key, int binxmin, int binxmax, Mode mode);
46 
47  void DrawMeanSlice(const char *key, const int rebinFactor, Mode mode);
48  void DrawSigmaSlice(const char *key, const int rebinFactor, Mode mode);
49  void DrawGaussSigmaSlice(const char *key, const int rebinFactor, Mode mode);
51  const char *key, const int rebinFactor, const int binxmin, const int binxmax, const bool cst_binning, Mode mode);
53  const char *key, const int rebinFactor, const int binxmin, const int binxmax, const bool cst_binning, Mode mode);
54  void DrawGaussSigmaOverMeanSlice(const char *key, const char *key2, const int rebinFactor, Mode mode);
55 
56  void Draw(const char *key, Mode mode);
57 
58  void Draw(const char *key0, const char *key1, Mode mode);
59 
60  // return the two temporary 1d histograms, that have just
61  // been plotted
62  TH1 *h0() { return h0_; }
63  TH1 *h1() { return h1_; }
64 
65  TLegend &Legend() { return legend_; }
66  const TLegend &Legend() const { return legend_; }
67 
68  // set the styles for further plots
69  void SetStyles(Style *s0, Style *s1, const char *leg0, const char *leg1);
70 
71  TH1 *Histo(const char *key, unsigned dirIndex);
72 
73  TDirectory *dir0() { return dir0_; }
74  TDirectory *dir1() { return dir1_; }
75 
76 private:
77  // retrieve an histogram in one of the two directories
78 
79  // draw 2 1D histograms.
80  // the histograms can be normalized to the same number of entries,
81  // or plotted as a ratio.
82  void Draw(TH1 *h0, TH1 *h1, Mode mode);
83 
84  int rebin_;
85  float xMin_;
86  float xMax_;
87  bool resetAxis_;
88 
89  TFile *file0_;
90  TDirectory *dir0_;
91  TFile *file1_;
92  TDirectory *dir1_;
93 
94  TH1 *h0_;
95  TH1 *h1_;
96 
99 
100  TLegend legend_;
101 };
102 
103 #endif
void SetStyles(Style *s0, Style *s1, const char *leg0, const char *leg1)
Definition: Comparator.cc:33
TLegend & Legend()
Definition: Comparator.h:65
TDirectory * dir1()
Definition: Comparator.h:74
void DrawSigmaSlice(const char *key, const int rebinFactor, Mode mode)
Definition: Comparator.cc:89
void SetAxis(int rebin, float xmin, float xmax)
Definition: Comparator.h:31
#define nullptr
const TLegend & Legend() const
Definition: Comparator.h:66
TFile * file0_
Definition: Comparator.h:89
bool resetAxis_
Definition: Comparator.h:87
Comparator(const char *file0, const char *dir0, const char *file1, const char *dir1)
Definition: Comparator.h:21
void Draw(const char *key, Mode mode)
Definition: Comparator.cc:306
TH1 * h1()
Definition: Comparator.h:63
TDirectory * dir0()
Definition: Comparator.h:73
Style * s0_
Definition: Comparator.h:97
void DrawGaussSigmaOverMeanXSlice(const char *key, const int rebinFactor, const int binxmin, const int binxmax, const bool cst_binning, Mode mode)
Definition: Comparator.cc:195
TDirectory * dir0_
Definition: Comparator.h:90
void DrawMeanSlice(const char *key, const int rebinFactor, Mode mode)
Definition: Comparator.cc:73
void SetDirs(const char *file0, const char *dir0, const char *file1, const char *dir1)
Definition: Comparator.cc:17
Style * s1_
Definition: Comparator.h:98
float xMin_
Definition: Comparator.h:85
float xMax_
Definition: Comparator.h:86
TDirectory * dir1_
Definition: Comparator.h:92
Definition: Style.py:1
TH1 * h1_
Definition: Comparator.h:95
TH1 * Histo(const char *key, unsigned dirIndex)
Definition: Comparator.cc:349
TLegend legend_
Definition: Comparator.h:100
TH1 * h0()
Definition: Comparator.h:62
void DrawSlice(const char *key, int binxmin, int binxmax, Mode mode)
Definition: Comparator.cc:42
TFile * file1_
Definition: Comparator.h:91
void DrawGaussSigmaOverMeanSlice(const char *key, const char *key2, const int rebinFactor, Mode mode)
Definition: Comparator.cc:276
int rebin_
Definition: Comparator.h:84
void DrawGaussSigmaSlice(const char *key, const int rebinFactor, Mode mode)
Definition: Comparator.cc:105
TH1 * h0_
Definition: Comparator.h:94
void SetAxis(int rebin)
Definition: Comparator.h:39