DESY Hbb Analysis Framework
Functions | Variables
PlotsCompare.cc File Reference
#include <string>
#include <iostream>
#include <vector>
#include "TFile.h"
#include "TCanvas.h"
#include "TApplication.h"
#include "TH1.h"
#include "TRatioPlot.h"
#include "TLegend.h"
#include "Analysis/Tools/interface/plotscomp_config.h"
#include "Analysis/Tools/interface/tdrstyle.C"
#include "Analysis/Tools/interface/CMS_lumi.h"

Go to the source code of this file.

Functions

int draw_legend ()
 
int main (int argc, char *argv[])
 
int plot_ratio ()
 

Variables

float B
 
TCanvas * c1
 
TFile * f [10]
 
std::string fn [10]
 
int H
 
TH1F * h [10]
 
std::string hn [10]
 
float L
 
std::string leg [10]
 
TLegend * legend
 
float R
 
TRatioPlot * rp
 
float T
 
int W
 

Function Documentation

int draw_legend ( )

Definition at line 193 of file PlotsCompare.cc.

References c1, h, leg, legend, logy_, and rp.

Referenced by main().

194 {
195  std::string var = h[0]->GetName();
196 
197  if ( TString(var).Contains("m_jet") || TString(var).Contains("pt_jet") )
198  legend = rp -> GetUpperPad() -> BuildLegend(0.65,0.65,0.90,0.85);
199  else if ( !TString(var).Contains("deta_jet") && ( TString(var).Contains("eta_jet") || TString(var).Contains("phi_jet") ))
200  legend = rp -> GetUpperPad() -> BuildLegend(0.40,0.05,0.65,0.25);
201 // legend = rp -> GetUpperPad() -> BuildLegend(0.65,0.65,0.90,0.85);
202  else if ( TString(var).Contains("btag_jet") )
203  {
204  if ( logy_ )
205  legend = rp -> GetUpperPad() -> BuildLegend(0.35,0.05,0.60,0.25);
206  else
207  legend = rp -> GetUpperPad() -> BuildLegend(0.35,0.65,0.60,0.85);
208  }
209  else
210  legend = rp -> GetUpperPad() -> BuildLegend(0.15,0.65,0.40,0.85);
211  legend -> Clear();
212 
213  legend ->AddEntry(h[0], leg[0].c_str(), "P");
214  legend ->AddEntry(h[1], leg[1].c_str(), "P");
215 
216  c1->Update();
217 
218  return 0;
219 }
TH1F * h[10]
Definition: PlotsCompare.cc:25
TLegend * legend
Definition: PlotsCompare.cc:27
TRatioPlot * rp
Definition: PlotsCompare.cc:26
std::string leg[10]
Definition: PlotsCompare.cc:29
TCanvas * c1
Definition: PlotsCompare.cc:23
bool logy_
int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file PlotsCompare.cc.

References app_, B, c1, CMS_lumi(), draw_legend(), f, file1_, file2_, file_, fn, H, h, hist1_, hist2_, hist_, hn, L, leg, legend, legend1_, legend2_, logx_, logy_, max_, min_, outplot_, plot_ratio(), plotscomp_config(), R, rp, scale_, T, title_, and W.

36 {
37  if ( plotscomp_config(argc, argv) != 0 ) return -1;
38 
39  W = 800;
40  H = 600;
41  // for the margins
42  T = 0.1*H;
43  B = 0.48*H;
44  L = 0.12*W;
45  R = 0.04*W;
46 
47  setTDRStyle();
48  gStyle->SetOptStat(0);
49  TApplication theApp("App", 0, 0);
50 
51  hn[0] = hist1_;
52  hn[1] = hist2_;
53 
54  fn[0] = file1_;
55  fn[1] = file2_;
56 
57  leg[0] = legend1_;
58  leg[1] = legend2_;
59 
60  int color[10] = {kBlack,kRed};
61 
62  TString out = TString(outplot_);
63 
64 // if ( outplot_ == "" ) outplot_ = "comparison_plot.png";
65 
66  // read 2 histograms from the same file
67  if ( file_ != "" )
68  {
69  f[0] = new TFile(file_.c_str(),"old");
70  for ( int i = 0; i < 2 ; ++i )
71  {
72  if ( hn[i] == "" ) return -1;
73  h[i] = (TH1F*) f[0] -> Get(hn[i].c_str());
74  h[i] -> SetNameTitle(Form("%s_%d",hn[i].c_str(),i), Form("%s (%s)",leg[i].c_str(),h[i]->GetXaxis()->GetTitle()));
75  h[i] -> GetYaxis() -> SetTitle("entries");
76  }
77  }
78  // read same histogram from 2 different files
79  else
80  {
81  if ( hist_ == "" ) return -1;
82  for ( int i = 0; i < 2 ; ++i )
83  {
84  if ( fn[i] == "" ) return -1;
85  f[i] = new TFile(fn[i].c_str(),"old");
86  h[i] = (TH1F*) f[i] -> Get(hist_.c_str());
87  h[i] -> SetNameTitle(Form("%s_%d",hist_.c_str(),i), Form("%s (%s)",title_.c_str(),h[i]->GetXaxis()->GetTitle()));
88  }
89  }
90  if ( outplot_ == "" )
91  {
92  out = TString(std::string(h[0]->GetName()) + "_versus_" + std::string(h[1]->GetName()) + ".png");
93  out.ReplaceAll("/","_");
94  }
95 
96  for ( int i = 0; i < 2 ; ++i )
97  {
98  h[i] -> SetMarkerStyle(20);
99  h[i] -> SetMarkerSize(1.2);
100  h[i] -> SetMarkerColor(color[i]);
101  h[i] -> SetLineColor(color[i]);
102  h[i] -> SetLineWidth(2);
103  h[i] -> GetYaxis() -> SetTitle("entries");
104  if ( max_ > min_ )
105  {
106  h[i] -> GetXaxis()->SetRangeUser(min_,max_);
107  }
108  h[i] -> SetMinimum(0);
109  if ( logy_ ) h[i] -> SetMinimum(0.8);
110  }
111  h[1] -> Scale(scale_);
112 
113  // Ratio plot
114  plot_ratio();
115  draw_legend();
116 
117 //
118  if ( logx_ ) c1 -> SetLogx();
119  if ( logy_ ) c1 -> SetLogy();
120 
121  CMS_lumi(rp->GetUpperPad(),"private");
122 
123  legend -> SetShadowColor(0);
124 
125 // if ( outplot_ == "" ) outplot_ = "comparison_plot.png";
126  c1 -> SaveAs(out);
127 
128  if ( app_ ) theApp.Run(); // will not return
129 
130  delete rp;
131  delete c1;
132  delete f[0];
133  delete f[1];
134 
135  return 0;
136 }
std::string hist1_
std::string file1_
TH1F * h[10]
Definition: PlotsCompare.cc:25
float R
Definition: PlotsCompare.cc:21
float min_
std::string file2_
TLegend * legend
Definition: PlotsCompare.cc:27
std::string legend2_
TRatioPlot * rp
Definition: PlotsCompare.cc:26
std::string title_
std::string leg[10]
Definition: PlotsCompare.cc:29
void CMS_lumi(TPad *pad, TString mytxt="", int iPeriod=20, int iPosX=0)
Definition: CMS_lumi.cc:5
std::string legend1_
float L
Definition: PlotsCompare.cc:20
std::string fn[10]
Definition: PlotsCompare.cc:30
std::string outplot_
int draw_legend()
int plot_ratio()
int H
Definition: PlotsCompare.cc:16
std::string file_
std::string hist_
float T
Definition: PlotsCompare.cc:18
int W
Definition: PlotsCompare.cc:15
float max_
TFile * f[10]
Definition: PlotsCompare.cc:24
bool app_
float B
Definition: PlotsCompare.cc:19
TCanvas * c1
Definition: PlotsCompare.cc:23
std::string hn[10]
Definition: PlotsCompare.cc:28
int plotscomp_config(int argc, char *argv[])
float scale_
std::string hist2_
bool logx_
bool logy_
int plot_ratio ( )

Definition at line 138 of file PlotsCompare.cc.

References B, c1, H, h, L, logx_, logy_, R, rp, T, and W.

Referenced by main().

139 {
140  // Prepare a Canvas
141  c1 = new TCanvas("c1","test", W, H);
142  c1 -> SetFillColor(0);
143  c1 -> SetBorderMode(0);
144  c1 -> SetFrameFillStyle(0);
145  c1 -> SetFrameBorderMode(0);
146  c1 -> SetTickx(0);
147  c1 -> SetTicky(0);
148 
149  // The ratio plot
150  rp = new TRatioPlot(h[0], h[1]);
151 
152  rp -> SetH1DrawOpt("E");
153  rp -> SetH2DrawOpt("E");
154  rp -> SetGraphDrawOpt("P");
155  rp -> SetSeparationMargin(0.03);
156 
157  rp -> SetLeftMargin( L/W );
158  rp -> SetRightMargin( R/W );
159  rp -> SetUpTopMargin( T/H );
160  rp -> SetLowBottomMargin( B/H );
161 
162  rp->Draw();
163 
164  rp -> GetLowYaxis() -> SetNdivisions(503);
165  rp -> GetLowerRefGraph() -> GetXaxis() -> SetTitleOffset(1.1);
166  rp -> GetLowerRefGraph() -> GetYaxis() -> SetTitle("ratio");
167  rp -> GetLowerRefYaxis() -> SetTitleOffset(1.2);
168  rp -> GetLowerRefYaxis() -> SetLabelSize(0.05);
169  rp -> GetLowerRefYaxis() -> SetTitleSize(0.05);
170  rp->GetLowerRefGraph()->SetMarkerStyle(20);
171  rp->GetLowerRefGraph()->SetMarkerColor(kGray+2);
172  rp->GetLowerRefGraph()->SetMarkerSize(1.2);
173  rp->GetLowerRefGraph()->SetLineWidth(2);
174  rp->GetLowerRefGraph()->SetLineColor(kGray+2);
175  rp->GetLowerRefGraph()->SetMinimum(0.);
176  rp->GetLowerRefGraph()->SetMaximum(2.4);
177 
178  rp -> GetUpperRefXaxis() -> SetLabelSize(0.05);
179  rp -> GetUpperRefXaxis() -> SetTitleSize(0.05);
180 
181  rp -> GetUpperRefYaxis() -> SetLabelSize(0.05);
182  rp -> GetUpperRefYaxis() -> SetTitleSize(0.05);
183  rp -> GetUpperRefYaxis() -> SetTitleOffset(1.2);
184 
185  if ( logx_ ) rp -> GetUpperPad() -> SetLogx();
186  if ( logy_ ) rp -> GetUpperPad() -> SetLogy();
187 
188  c1->Update();
189 
190  return 0;
191 }
TH1F * h[10]
Definition: PlotsCompare.cc:25
float R
Definition: PlotsCompare.cc:21
TRatioPlot * rp
Definition: PlotsCompare.cc:26
float L
Definition: PlotsCompare.cc:20
int H
Definition: PlotsCompare.cc:16
float T
Definition: PlotsCompare.cc:18
int W
Definition: PlotsCompare.cc:15
float B
Definition: PlotsCompare.cc:19
TCanvas * c1
Definition: PlotsCompare.cc:23
bool logx_
bool logy_

Variable Documentation

float B

Definition at line 19 of file PlotsCompare.cc.

Referenced by main(), and plot_ratio().

TCanvas* c1

Definition at line 23 of file PlotsCompare.cc.

Referenced by draw_legend(), main(), and plot_ratio().

TFile* f[10]
std::string fn[10]

Definition at line 30 of file PlotsCompare.cc.

Referenced by main().

int H

Definition at line 16 of file PlotsCompare.cc.

Referenced by CMS_lumi(), main(), and plot_ratio().

TH1F* h[10]
std::string hn[10]

Definition at line 28 of file PlotsCompare.cc.

Referenced by main().

float L

Definition at line 20 of file PlotsCompare.cc.

Referenced by main(), and plot_ratio().

std::string leg[10]

Definition at line 29 of file PlotsCompare.cc.

Referenced by draw_legend(), main(), and PlotTanBetaLimit().

TLegend* legend

Definition at line 27 of file PlotsCompare.cc.

Referenced by draw_legend(), and main().

float R

Definition at line 21 of file PlotsCompare.cc.

Referenced by main(), and plot_ratio().

TRatioPlot* rp

Definition at line 26 of file PlotsCompare.cc.

Referenced by draw_legend(), main(), and plot_ratio().

float T
int W

Definition at line 15 of file PlotsCompare.cc.

Referenced by CMS_lumi(), main(), and plot_ratio().