Functions | Variables
make_extrap_figure.C File Reference
#include "TCanvas.h"
#include "TColor.h"
#include "TFile.h"
#include "TGraph.h"
#include "TH2.h"
#include "TLatex.h"
#include "TLegend.h"
#include "TLine.h"
#include "TPad.h"
#include "TStyle.h"
#include <iostream>
#include <vector>

Go to the source code of this file.

Functions

void no_titles (std::vector< TH1 * > hs)
 
TPad * pad (std::string name, double x0, double y0, double x1, double y1)
 
void latex (double x, double y, std::string txt, double ang=0, int align=22)
 
TGraph * rotate_curve (TH1 *h)
 
TGraph * rotate_hist (TH1 *h, bool neg=false)
 
void make_extrap_figure ()
 

Variables

const double kVertSplit = .6
 
const double kLRMargin = .05
 
const double kTopMargin = .05
 
const double kBottomMargin = .1
 
const double kMatrixWidth = .15
 
const double kXPadding = .0025
 
const double kYPadding = .005
 

Function Documentation

void latex ( double  x,
double  y,
std::string  txt,
double  ang = 0,
int  align = 22 
)

Definition at line 50 of file make_extrap_figure.C.

51 {
52  TLatex* ltx = new TLatex(x, y, txt.c_str());
53  ltx->SetNDC();
54  ltx->SetTextAlign(align);
55  ltx->SetTextAngle(ang);
56  ltx->Draw();
57 }
Simple analyzer module to print to text file information required for c++ based block alignment study...
void make_extrap_figure ( )

Definition at line 85 of file make_extrap_figure.C.

References file_size_ana::axes, b, plot_validation_datamc::c, e, MakeMiniprodValidationCuts::f, MECModelEnuComparisons::g, MECModelEnuComparisons::i, kBlue, kBottomMargin, kLRMargin, kMatrixWidth, kRed, kTopMargin, kVertSplit, latex(), no_titles(), pad(), r(), rotate_curve(), and rotate_hist().

86 {
87  TFile* f = new TFile("extrap_hists.root");
88 
89  // f->GetDirectory("extrap/MMextrap")->ls();
90 
91  TH1* h_reco_dat_nd = (TH1*)f->Get("MMextrap/NDDatReco");
92  TH1* h_reco_mc_nd = (TH1*)f->Get("MMextrap/NDMCReco");
93 
94  TH1* h_true_mc_nd = (TH1*)f->Get("MMextrap/NDMCTrue");
95  TH1* h_true_rwt_nd = (TH1*)f->Get("MMextrap/NDRwtTrue");
96 
97  TH1* h_true_mc_fd = (TH1*)f->Get("MMextrap/FDMCTrue");
98  TH1* h_true_ext_fd = (TH1*)f->Get("MMextrap/FDExtTrue");
99 
100  TH1* h_reco_ext_fd = (TH1*)f->Get("MMextrap/FDExtReco");
101  TH1* h_reco_mc_fd = (TH1*)f->Get("MMextrap/FDMCReco");
102 
103  // This is very fragile. Would be better if SavePlotsNumu() put out a
104  // histogram rather than a canvas here.
105  TH2* h_nd_matrix = (TH2*)((TCanvas*)f->Get("MMextrap/NDRecoToTrue"))->FindObject("cafanauniq20");
106  TH2* h_fd_matrix = (TH2*)((TCanvas*)f->Get("MMextrap/FDTrueToReco"))->FindObject("cafanauniq21");
107 
108  TH1* h_osc = (TH1*)f->Get("osc");
109 
110  TH1* h_fn = (TH1*)h_true_mc_fd->Clone();
111  h_fn->Divide(h_true_mc_nd);
112 
113  // Now that we have the F/N ratio it's safe to oscillate the FD plots
114  h_true_mc_fd->Multiply(h_osc);
115  h_true_ext_fd->Multiply(h_osc);
116 
117  h_reco_dat_nd->Scale(1e-3);
118  h_reco_mc_nd->Scale(1e-3);
119 
120  h_true_mc_nd->Scale(1e-3);
121  h_true_rwt_nd->Scale(1e-3);
122 
123  no_titles({h_reco_dat_nd, h_reco_mc_nd, h_true_mc_nd, h_true_rwt_nd,
124  h_true_mc_fd, h_true_ext_fd, h_reco_ext_fd, h_reco_mc_fd,
125  h_nd_matrix, h_fd_matrix, h_osc, h_fn});
126 
127 
128  TCanvas* c = new TCanvas("a", "b", 1800, 600);
129 
130  TPad* pNDReco = pad("NDReco", kLRMargin, kVertSplit, kLRMargin+kMatrixWidth, 1-kTopMargin);
131  TPad* pFDReco = pad("FDReco", 1-kLRMargin-kMatrixWidth, kVertSplit, 1-kLRMargin, 1-kTopMargin);
132 
133  TPad* pNDMatrix = pad("NDMatrix", kLRMargin, kBottomMargin, kLRMargin+kMatrixWidth, kVertSplit);
134  TPad* pFDMatrix = pad("FDMatrix", 1-kLRMargin-kMatrixWidth, kBottomMargin, 1-kLRMargin, kVertSplit);
135 
136  // Split the middle 4 panels equally
137  const double kNDTrueEdge = (.5+(kLRMargin+kMatrixWidth))/2.;
138  const double kCenterPlotWidth = .5-kNDTrueEdge;
139 
140  TPad* pNDTrue = pad("NDTrue", kLRMargin+kMatrixWidth, kBottomMargin, kNDTrueEdge, kVertSplit);
141  TPad* pFDTrue = pad("FDTrue", 1-kNDTrueEdge, kBottomMargin, 1-kLRMargin-kMatrixWidth, kVertSplit);
142 
143  TPad* pFN = pad("FN", kNDTrueEdge, kBottomMargin, .5, kVertSplit);
144  TPad* pOsc = pad("Osc", .5, kBottomMargin, 1-kNDTrueEdge, kVertSplit);
145 
146 
147  Int_t myPalette[1000];
148  // Double_t r[] = {.95, 1, .5};
149  // Double_t g[] = {.95, 0, 0.};
150  // Double_t b[] = {.95, 0, 0.};
151  Double_t r[] = {1, 1, .5};
152  Double_t g[] = {1, 0, 0.};
153  Double_t b[] = {1, 0, 0.};
154  Double_t stop[] = {0., .25, 1.0};
155  Int_t FI = TColor::CreateGradientColorTable(3, stop, r, g, b, 1000);
156  for (int i=0;i<1000;i++) myPalette[i] = FI+i;
157  gStyle->SetPalette(1000, myPalette);
158 
159 
160  pNDReco->cd();
161  h_reco_mc_nd->SetLineColor(kRed);
162  h_reco_mc_nd->GetXaxis()->SetLabelSize(0);
163  h_reco_mc_nd->Draw("hist");
164  h_reco_dat_nd->Draw("ep same");
165 
166  pFDReco->cd();
167  h_reco_mc_fd->SetLineColor(kRed);
168  h_reco_mc_fd->GetXaxis()->SetLabelSize(0);
169  h_reco_mc_fd->Draw("hist Y+");
170  h_reco_ext_fd->SetLineColor(kBlue);
171  h_reco_ext_fd->Draw("hist same");
172 
173  pNDTrue->cd();
174  h_true_mc_nd->SetLineColor(kRed);
175  h_true_rwt_nd->SetLineColor(kBlue);
176 
177  TH2* axes = new TH2F("", "", 100, 0, 3, 100, 0, 5);
178  axes->GetYaxis()->SetLabelSize(0);
179  axes->Draw();
180  rotate_hist(h_true_mc_nd)->Draw("l same");
181  rotate_hist(h_true_rwt_nd)->Draw("l same");
182 
183  pFDTrue->cd();
184  h_true_mc_fd->SetLineColor(kRed);
185  h_true_ext_fd->SetLineColor(kBlue);
186 
187  axes = new TH2F("", "", 100, -6, 0, 100, 0, 5);
188  axes->GetYaxis()->SetLabelSize(0);
189  axes->Draw();
190  rotate_hist(h_true_mc_fd, true)->Draw("l same");
191  rotate_hist(h_true_ext_fd, true)->Draw("l same");
192 
193  pNDMatrix->cd();
194  axes = new TH2F("", "", 100, 0, 5, 100, 0, 5);
195  axes->Draw();
196  h_nd_matrix->Draw("col same");
197 
198  pFDMatrix->cd();
199  axes = new TH2F("", "", 100, 0, 5, 100, 0, 5);
200  axes->Draw("Y+");
201  h_fd_matrix->Draw("col same");
202 
203  pFN->cd();
204  h_fn->SetLineColor(kRed);
205  axes = new TH2F("", "", 100, 0, .03, 100, 0, 5);
206  axes->GetYaxis()->SetLabelSize(0);
207  axes->Draw();
208  rotate_curve(h_fn)->Draw("l same");
209 
210  pOsc->cd();
211  h_osc->SetLineColor(kRed);
212  axes = new TH2F("", "", 100, 0, 1, 100, 0, 5);
213  axes->GetYaxis()->SetLabelSize(0);
214  axes->Draw();
215  rotate_curve(h_osc)->Draw("l same");
216 
217  c->cd();
218 
219  latex(.5*kLRMargin, .5*kVertSplit + .5*(1-kTopMargin), "10^{3} ND Events", 90);
220  latex(1-.5*kLRMargin, .5*kVertSplit + .5*(1-kTopMargin), "FD Events", 90);
221 
222  latex(.5*kLRMargin, .5*kVertSplit + .5*(kBottomMargin), "True Energy (GeV)", 90);
223  latex(1-.5*kLRMargin, .5*kVertSplit + .5*(kBottomMargin), "True Energy (GeV)", 90);
224 
225  latex(kLRMargin+kMatrixWidth/2, .5*kBottomMargin, "ND Reco Energy (GeV)");
226  latex(1-kLRMargin-kMatrixWidth/2, .5*kBottomMargin, "FD Reco Energy (GeV)");
227 
228  latex(kNDTrueEdge-.5*kCenterPlotWidth, .5*kBottomMargin, "10^{3} ND Events");
229  latex(1-kNDTrueEdge+.5*kCenterPlotWidth, .5*kBottomMargin, "FD Events");
230 
231  latex(.5-kCenterPlotWidth/2, .5*kBottomMargin, "F/N Ratio");
232  latex(.5+kCenterPlotWidth/2, .5*kBottomMargin, "P(#nu_{#mu}#rightarrow#nu_{#mu})");
233 
234  // Draw legend by hand
235  TLine* lin = new TLine(.37, .85, .395, .85);
236  lin->SetLineWidth(2);
237  lin->Draw();
238  lin = new TLine(.37, .8, .395, .8);
239  lin->SetLineWidth(2);
240  lin->SetLineColor(kRed);
241  lin->Draw();
242  lin = new TLine(.37, .75, .395, .75);
243  lin->SetLineWidth(2);
244  lin->SetLineColor(kBlue);
245  lin->Draw();
246 
247  latex(.4, .85, "ND data", 0, 12);
248  latex(.4, .8, "Base Simulation", 0, 12);
249  latex(.4, .75, "Data-Driven Prediction", 0, 12);
250 
251  gPad->Print("extrap.pdf");
252  gPad->Print("extrap.png");
253 }
void latex(double x, double y, std::string txt, double ang=0, int align=22, double size=0.042)
enum BeamMode kRed
const double kTopMargin
TGraph * rotate_hist(TH1 *h, bool neg=false)
void no_titles(std::vector< TH1 * > hs)
TPad * pad(std::string name, double x0, double y0, double x1, double y1)
const double kLRMargin
const double kVertSplit
TGraph * rotate_curve(TH1 *h)
const hit & b
Definition: hits.cxx:21
const double kBottomMargin
TRandom3 r(0)
Float_t e
Definition: plot.C:35
enum BeamMode kBlue
const double kMatrixWidth
void no_titles ( std::vector< TH1 * >  hs)

Definition at line 29 of file make_extrap_figure.C.

References make_syst_table_plots::h.

30 {
31  for(TH1* h: hs){
32  h->SetTitle("");
33  h->GetXaxis()->SetTitleSize(0);
34  h->GetYaxis()->SetTitleSize(0);
35  }
36 }
TPad* pad ( std::string  name,
double  x0,
double  y0,
double  x1,
double  y1 
)

Definition at line 38 of file make_extrap_figure.C.

References kXPadding, and kYPadding.

39 {
40  TPad* p = new TPad(name.c_str(), "", 0, 0, 1, 1);
41  p->SetLeftMargin(x0+kXPadding);
42  p->SetRightMargin(1-x1+kXPadding);
43  p->SetTopMargin(1-y1+kYPadding);
44  p->SetBottomMargin(y0+kYPadding);
45  p->SetFillStyle(0);
46  p->Draw();
47  return p;
48 }
const XML_Char * name
Definition: expat.h:151
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
const char * p
Definition: xmltok.h:285
const double kXPadding
const double kYPadding
TGraph* rotate_curve ( TH1 *  h)

Definition at line 59 of file make_extrap_figure.C.

References MECModelEnuComparisons::g, and MECModelEnuComparisons::i.

60 {
61  TGraph* g = new TGraph;
62  for(int i = 0; i < h->GetNbinsX()+2; ++i){
63  g->SetPoint(i, h->GetBinContent(i), h->GetXaxis()->GetBinCenter(i));
64  }
65  g->SetLineWidth(2);
66  g->SetLineColor(h->GetLineColor());
67  return g;
68 }
TGraph* rotate_hist ( TH1 *  h,
bool  neg = false 
)

Definition at line 70 of file make_extrap_figure.C.

References MECModelEnuComparisons::g, MECModelEnuComparisons::i, and canMan::sign().

71 {
72  int sign = neg ? -1 : +1;
73 
74  TGraph* g = new TGraph;
75  for(int i = 0; i < h->GetNbinsX()+2; ++i){
76  g->SetPoint(2*i, sign*h->GetBinContent(i), h->GetXaxis()->GetBinLowEdge(i));
77  g->SetPoint(2*i+1, sign*h->GetBinContent(i), h->GetXaxis()->GetBinUpEdge(i));
78  }
79  g->SetLineWidth(2);
80  g->SetLineColor(h->GetLineColor());
81 
82  return g;
83 }
def sign(x)
Definition: canMan.py:197

Variable Documentation

const double kBottomMargin = .1

Definition at line 22 of file make_extrap_figure.C.

const double kLRMargin = .05

Definition at line 20 of file make_extrap_figure.C.

const double kMatrixWidth = .15

Definition at line 24 of file make_extrap_figure.C.

const double kTopMargin = .05

Definition at line 21 of file make_extrap_figure.C.

const double kVertSplit = .6

Definition at line 18 of file make_extrap_figure.C.

const double kXPadding = .0025

Definition at line 26 of file make_extrap_figure.C.

const double kYPadding = .005

Definition at line 27 of file make_extrap_figure.C.