Classes | Namespaces | Functions | Variables
temp_draw_plots_util.h File Reference
#include "CAFAna/Analysis/Exposures.h"
#include "CAFAna/Analysis/Plots.h"
#include "CAFAna/Analysis/Style.h"
#include "CAFAna/Analysis/NuePlotStyle.h"
#include "CAFAna/Core/LoadFromFile.h"
#include "CAFAna/Prediction/IPrediction.h"
#include "OscLib/func/OscCalculatorDumb.h"
#include "TStyle.h"
#include "TFile.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TGraphAsymmErrors.h"
#include "TGaxis.h"
#include "TLatex.h"
#include "TLegend.h"
#include "TLine.h"
#include "TSystem.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>

Go to the source code of this file.

Classes

struct  ana::NueMCComponents
 

Namespaces

 ana
 Oscillation analysis framework, runs over CAF files outside of ART.
 

Functions

void Prelim ()
 
void CenterTitles (TH1 *histo)
 
void PIDTag (TString pid)
 
void HTag (TString pid)
 
TH1 * RebinToShortAxis (TH1 *h)
 
TString MakeLatexCommandName (TString mystring)
 
void PIDDivisions ()
 
void PIDBinLabels (std::string pid)
 
void PID2DAxis (TH1 *axes, bool third=false)
 
void PIDDivisionsShortAxis ()
 
void PIDBinLabelsShortAxis ()
 
void PID2DShortAxis (TH1 *hist)
 
double FindLimitY (std::vector< TH1 * > histos, bool doMax=true)
 
void ana::ComparisonTable (std::vector< TH1 * > mcnom, std::vector< TH1 * > mcshift, std::vector< TString > labels, TString ltxcommand="")
 
void ana::ComparisonTable (std::vector< TH1 * > mcnom, std::vector< TH1 * > mcplus, std::vector< TH1 * > mcminus, std::vector< TString > labels, TString ltxcommand="")
 
void ana::FixLegend (TLegend *leg, TString opt="default")
 
TLegend * ana::DefaultNueLegend (bool sig=true, bool tot=true, bool data=false, double x1=kLegendDefaultX1, double y1=kLegendDefaultY1, double x2=kLegendDefaultX2, double y2=kLegendDefaultY2)
 
TLegend * ana::CustomLegend (std::vector< TH1 * >h, std::vector< bool >isdata, std::vector< TString >title, double x1=kLegendDefaultX1, double y1=kLegendDefaultY1, double x2=kLegendDefaultX2, double y2=kLegendDefaultY2)
 
TCanvas * ana::ExPIDPlot (std::vector< TH1 * > topHistos, std::vector< TString > topOption)
 
TCanvas * ana::RatioPlot (std::vector< TH1 * > topHistos, std::vector< TString > topOption, std::vector< TH1 * > bottomHistos, std::vector< TString > bottomOption, TString pidtag, bool pidaxis=false)
 
void ana::PlotDataMC (std::vector< TH1 * >vnom, std::vector< bool >isdata, TLegend *leg, TString pidtag="", TString htag="", TString out_name="plot_FD", bool ratioplot=false, bool ratioerrors=false, bool pidaxis=0)
 
void ana::PlotNDDataTotalMCComparison (TH1 *hdata, std::vector< TH1 * > htots, TLegend *leg, TString pidtag="", TString out_name="plot_nd", bool ratioplot=false, bool pidaxis=false)
 
void ana::PlotMCComponentsComparison (std::vector< TH1 * >vnom, std::vector< TH1 * >vshi, TLegend *leg, TString pidtag="", TString out_name="plot_nd", bool ratioplot=false, bool ratioerrors=false, bool pidaxis=0)
 
void ana::CompareNDDataMC (TDirectory *d_no, TDirectory *d_sh, TString plottitle, TString out_name, TString pidtag, bool printtable=true, bool pidaxis=0)
 
void ana::ComparePredictions (IPrediction *pred_no, IPrediction *pred_sh, TString plottitle, TString out_name, TString pidtag, bool printtable=true, bool pidaxis=false)
 
void ana::FormatErrorBand (TH1 *hplus, TH1 *hminus, bool signal=false, bool fixbins=false)
 
void ana::PlotMCComponentsErrorBand (std::vector< TH1 * >vnom, std::vector< TH1 * >vshi, TLegend *leg, TString pidtag="", TString out_name="plot_nd", bool ratioplot=false, bool ratioerrors=false, bool pidaxis=0)
 
struct NueMCComponents ana::GetNDMCComponents (TDirectory *d_no, double kNDPOT, int linestyle=1)
 
void ana::CompareNDDataMC (TDirectory *d_no, TDirectory *d_pl, TDirectory *d_mi, TString plottitle, TString out_name, TString pidtag, bool printtable=true, bool pidaxis=0)
 
struct NueMCComponents ana::GetFDMCComponents (IPrediction *pred_no, int linestyle=1)
 
TString ana::Latexify (TString s)
 
void ana::ComparePredictions (IPrediction *pred_no, IPrediction *pred_pl, IPrediction *pred_mi, TString plottitle, TString out_name, TString pidtag, bool printtable=true, bool pidaxis=false)
 
void ana::MakeNueSystematicsFile (IPrediction *pred_no, IPrediction *pred_sh, TString pid, TString sigma, TFile *nue_syst_file)
 
void ana::PrintRawEventCounts (TDirectory *dpred, TString title)
 

Variables

osc::OscCalculatorDumb calc
 
static const double kFDPOT = ana::kSecondAnaRunMatchedMCPOTScale
 
const bool printratioplots =true
 

Function Documentation

void CenterTitles ( TH1 *  histo)

Definition at line 43 of file temp_draw_plots_util.h.

Referenced by PID2DAxis().

44 {
45  histo->GetXaxis()->CenterTitle();
46  histo->GetYaxis()->CenterTitle();
47  histo->GetZaxis()->CenterTitle();
48 }
TH2D * histo
double FindLimitY ( std::vector< TH1 * >  histos,
bool  doMax = true 
)

Definition at line 288 of file temp_draw_plots_util.h.

References make_mec_shifts_plots::GetMaximum(), MECModelEnuComparisons::i, std::max(), and min().

Referenced by ana::ComparisonTable().

289 {
290  double max = histos[0]->GetMaximum();
291  double min = histos[0]->GetMinimum();
292 
293  for(unsigned int i=0; i<histos.size(); i++){
294  if ( histos[i]->GetMaximum() > max ) max = histos[i]->GetMaximum();
295  if ( histos[i]->GetMinimum() < min ) min = histos[i]->GetMinimum();
296  }
297 
298  if ( doMax ) return max;
299  else return min;
300 
301 }
T max(const caf::Proxy< T > &a, T b)
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
void HTag ( TString  pid)

Definition at line 61 of file temp_draw_plots_util.h.

References getGoodRuns4SAM::tag.

62 {
63  TLatex* tag = new TLatex(.18, .825, pid);
64  if ( pid == "IH") tag->SetTextColor(kOrange+2);
65  if ( pid == "NH") tag->SetTextColor(kAzure+3);
66  tag->SetNDC();
67  tag->SetTextSize(0.043);
68  tag->SetTextFont(42);
69  tag->SetTextAlign(12);
70  tag->Draw();
71 }
TString MakeLatexCommandName ( TString  mystring)

Definition at line 100 of file temp_draw_plots_util.h.

References MECModelEnuComparisons::i, in, hadd_many_files::mystring, and confusionMatrixTree::out.

Referenced by ana::ComparisonTable().

100  {
101  //There must be a better way
102  std::vector<TString> in = {"0","1","2","3","4","5",
103  "6","7","8","9","_"," ","(",")"};
104  std::vector<TString> out = {"zero","one","two","three","four","five",
105  "six","seven","eight","nine","","","",""};
106  for(unsigned int i=0;i<in.size();i++)
107  mystring.ReplaceAll(in[i],out[i]);
108  return mystring;
109 
110  }
ifstream in
Definition: comparison.C:7
void PID2DAxis ( TH1 *  axes,
bool  third = false 
)

Definition at line 153 of file temp_draw_plots_util.h.

References visualisationForPaperMasterPlot::ax, CenterTitles(), gen_flatrecord::size, make_mec_shifts_plots::xmax, make_mec_shifts_plots::xmin, and ymin.

Referenced by ana::ComparisonTable().

154 {
155 
156  double xmax = axes->GetXaxis()->GetXmax();
157  double xmin = axes->GetXaxis()->GetXmin();
158  double xrange = xmax-xmin;
159 
160  double ymin = axes->GetMinimum();
161  TGaxis* gax1 = new TGaxis(0, ymin, 8, ymin, 0, 4, 4, "");
162  TGaxis* gax2 = new TGaxis(10, ymin, 18, ymin, 0, 4, 4, "");
163  TGaxis* gax3 = new TGaxis(20, ymin, 30, ymin, 0, 5, 5, "");
164 
165  float size = axes->GetXaxis()->GetLabelSize();
166  float offs = axes->GetXaxis()->GetLabelOffset();
167  int font = axes->GetXaxis()->GetLabelFont();
168  // And then hide its title
169  axes->GetXaxis()->SetLabelSize(0);
170  // and make all the tick marks the same size
171  axes->GetXaxis()->SetNdivisions(3000);
172  axes->GetXaxis()->SetTitle("Reconstructed Neutrino Energy (GeV)");
173 // axes->GetYaxis()->SetTitle("Events / 6.05 x 10^{20} POT-equiv");
174  axes->GetYaxis()->SetTitleOffset(0.8);
175  axes->SetTitle("");
177 
178  if ( third ){
179  gax1->SetLabelSize(size);
180  gax1->SetLabelOffset(offs);
181  gax1->SetLabelFont(font);
182  gax1->Draw();
183  }
184  else
185  for(TGaxis* ax: {gax1, gax2, gax3}){
186  // Copy settings from pre-existing axis
187  ax->SetLabelSize(size-0.001);
188  ax->SetLabelOffset(offs);
189  ax->SetLabelFont(font);
190  ax->Draw();
191  }
192 
193  TLine* xline = new TLine();
194  xline->SetLineWidth(2);
195  xline->DrawLine(xmin, 0, xmax, 0);
196  gPad->RedrawAxis();
197 }
Double_t ymin
Definition: plot.C:24
void CenterTitles(TH1 *histo)
void PID2DShortAxis ( TH1 *  hist)

Definition at line 246 of file temp_draw_plots_util.h.

References visualisationForPaperMasterPlot::ax, gen_flatrecord::size, and ymin.

247 {
248  double ymin = hist->GetMinimum();
249  // Paint our own x-axis fragments
250  TGaxis* gax1 = new TGaxis(1, ymin, 5, ymin, 1, 3, 3, "");
251  TGaxis* gax2 = new TGaxis(7, ymin, 11, ymin, 1, 3, 3, "");
252  TGaxis* gax3 = new TGaxis(13, ymin, 17, ymin, 1, 3, 3, "");
253 
254  float tick = hist->GetXaxis()->GetTickLength();
255  float size = hist->GetXaxis()->GetLabelSize();
256  float offs = hist->GetXaxis()->GetLabelOffset();
257  int font = hist->GetXaxis()->GetLabelFont();
258  // And then hide its title
259  hist->GetXaxis()->SetLabelSize(0);
260  // and make all the tick marks the same size
261  hist->GetXaxis()->SetNdivisions(1800);
262  hist->GetXaxis()->SetTitle("Reconstructed neutrino energy (GeV)");
263  hist->GetYaxis()->SetTitle("Events / 0.5 GeV Bin");
264  hist->GetYaxis()->SetTitleOffset(0.8);
265  hist->GetXaxis()->CenterTitle();
266  hist->GetYaxis()->CenterTitle();
267  hist->SetTitle("");
268 
269  if (false){// fThird ){
270  gax1->SetTickSize(tick);
271  gax1->SetLabelSize(size);
272  gax1->SetLabelOffset(offs);
273  gax1->SetLabelFont(font);
274  gax1->Draw();
275  }
276  else{
277  for(TGaxis* ax: {gax1, gax2, gax3}){
278  // Copy settings from pre-existing axis
279  ax->SetTickSize(tick);
280  ax->SetLabelSize(size);
281  ax->SetLabelOffset(offs);
282  ax->SetLabelFont(font);
283  ax->Draw();
284  }
285  }
286 }
Double_t ymin
Definition: plot.C:24
void PIDBinLabels ( std::string  pid)

Definition at line 128 of file temp_draw_plots_util.h.

References bins, ana::Binning::Edges(), genie::utils::style::Format(), MECModelEnuComparisons::i, ana::kCVNNLBinning, ana::kLEMNLBinning, ana::kLIDNLBinning, and submit_syst::y.

Referenced by ana::ComparisonTable().

128  {
129  // Put the labels near the top of the plot
130  gPad->Update();
131  const double y = gPad->GetUymax() * 0.955;
132 
133  const ana::Binning* bins = 0;
134  if(pid == "LID") bins = &ana::kLIDNLBinning;
135  if(pid == "LEM") bins = &ana::kLEMNLBinning;
136  if(pid == "CVN") bins = &ana::kCVNNLBinning;
137  assert(bins);
138 
139  for(int i = 0; i < 3; ++i){
140 // TLatex* ltx = new TLatex(3+6*i, y, TString::Format("%g < %s < %g",
141  TLatex* ltx = new TLatex(5+10*i, y, TString::Format("%g < %s < %g",
142  bins->Edges()[i],
143  pid.c_str(),
144  bins->Edges()[i+1]));
145  ltx->SetTextSize(0.032);
146  ltx->SetTextColor(kGray+3);
147  ltx->SetTextAlign(22);
148  ltx->Draw();
149  }
150 
151 }
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
const Binning kCVNNLBinning
Nonlinear binning for CVN.
Definition: Binning.h:121
const Binning bins
Definition: sa_fd_arrays.h:120
const std::vector< double > & Edges() const
Definition: Binning.h:30
const Binning kLIDNLBinning
Nonlinear binning for LID.
Definition: Binning.h:114
const Binning kLEMNLBinning
Nonlinear binning for LEM.
Definition: Binning.h:107
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void PIDBinLabelsShortAxis ( )

Definition at line 221 of file temp_draw_plots_util.h.

References bins, ana::Binning::Edges(), genie::utils::style::Format(), MECModelEnuComparisons::i, ana::kCVNNLBinning, ana::kLEMNLBinning, ana::kLIDNLBinning, BlessedPlots::pid, and submit_syst::y.

222 {
223  const std::string fPID = "CVN"; // HACK
224 
225  // Put the labels near the top of the plot
226  std::string pid = (std::string)fPID;
227  gPad->Update();
228  const double y = gPad->GetUymax() * .94;
229 
230  const ana::Binning* bins = 0;
231  if(fPID == "LID") bins = &ana::kLIDNLBinning;
232  if(fPID == "LEM") bins = &ana::kLEMNLBinning;
233  if(fPID == "CVN") bins = &ana::kCVNNLBinning;
234  assert(bins);
235 
236  for(int i = 0; i < 3; ++i){
237  TLatex* ltx = new TLatex(3+6*i, y, TString::Format("%g < %s < %g",
238  bins->Edges()[i],
239  pid.c_str(),
240  bins->Edges()[i+1]));
241  ltx->SetTextSize(.04);//0.035);
242  ltx->SetTextAlign(22);
243  ltx->Draw();
244  }
245 }
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
const Binning kCVNNLBinning
Nonlinear binning for CVN.
Definition: Binning.h:121
const Binning bins
Definition: sa_fd_arrays.h:120
const std::vector< double > & Edges() const
Definition: Binning.h:30
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Binning kLIDNLBinning
Nonlinear binning for LID.
Definition: Binning.h:114
const Binning kLEMNLBinning
Nonlinear binning for LEM.
Definition: Binning.h:107
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void PIDDivisions ( )

Definition at line 112 of file temp_draw_plots_util.h.

References submit_hadd::l, and central_limit::l1.

Referenced by ana::ComparisonTable().

112  {
113  // Separators between the different PID ranges
114  // TGraph not TLine because TGraph is properly clipped by frame
115  TGraph* l1 = new TGraph;
116  l1->SetPoint(0, 10, 0);
117  l1->SetPoint(1, 10, 50000);
118  TGraph* l2 = new TGraph;
119  l2->SetPoint(0, 20, 0);
120  l2->SetPoint(1, 20, 50000);
121  for(TGraph* l: {l1, l2}){
122  l->SetLineWidth(1);
123  l->SetLineColor(kGray+3);
124  l->Draw("l same");
125  }
126 }
void PIDDivisionsShortAxis ( )

Definition at line 199 of file temp_draw_plots_util.h.

References submit_hadd::l, and central_limit::l1.

200 {
201  // Separators between the different PID ranges
202  // TGraph not TLine because TGraph is properly clipped by frame
203  TGraph* l1 = new TGraph;
204  l1->SetPoint(0, 6, 0);
205  l1->SetPoint(1, 6, 50000);
206  TGraph* l2 = new TGraph;
207  l2->SetPoint(0, 12, 0);
208  l2->SetPoint(1, 12, 50000);
209  for(TGraph* l: {l1, l2}){
210  // l->SetLineStyle(3);
211  l->SetLineWidth(1);
212  l->SetLineColor(kGray+3);
213  l->Draw("l same");
214  }
215 
216  // Hardcoding maxy is obviously unsustainable
217  TGaxis* gax1 = new TGaxis(6, 0, 6, 18, 0, 18, 504, "U+-");
218  TGaxis* gax2 = new TGaxis(12, 0, 12, 18, 0, 18, 504, "U+-");
219 }
void PIDTag ( TString  pid)

Definition at line 50 of file temp_draw_plots_util.h.

References getGoodRuns4SAM::tag.

Referenced by ana::ComparisonTable().

51 {
52  TLatex* tag = new TLatex(.83, .92, pid);
53  tag->SetTextColor(kAzure+3);
54  tag->SetNDC();
55  tag->SetTextSize(0.038);
56  tag->SetTextFont(42);
57  tag->SetTextAlign(12);
58  tag->Draw();
59 }
void Prelim ( )

Definition at line 33 of file temp_draw_plots_util.h.

References prelim.

34 {
35  TLatex* prelim = new TLatex(.9, .95, "NOvA Preliminary");
36  prelim->SetTextColor(kBlue);
37  prelim->SetNDC();
38  prelim->SetTextSize(2/36.);
39  prelim->SetTextAlign(32);
40  prelim->Draw();
41 }
TLatex * prelim
Definition: Xsec_final.C:133
TH1* RebinToShortAxis ( TH1 *  h)

Definition at line 74 of file temp_draw_plots_util.h.

References it, runNovaSAM::ret, and ana::UniqueName().

75 {
76  TH1* ret = new TH1D(ana::UniqueName().c_str(), h->GetTitle(),
77  18, 0, 18);
78  ret->GetXaxis()->SetTitle(h->GetXaxis()->GetTitle());
79  ret->GetYaxis()->SetTitle(h->GetYaxis()->GetTitle());
80 
81  std::vector<std::pair<int, int>> binMap = {{3, 2},
82  {4, 3},
83  {5, 4},
84  {6, 5}, // end of 1st spectrum
85  {13, 8},
86  {14, 9},
87  {15, 10},
88  {16, 11}, // end of 2nd
89  {23, 14},
90  {24, 15},
91  {25, 16},
92  {26, 17}};
93 
94  for(auto it: binMap) ret->SetBinContent(it.second, h->GetBinContent(it.first));
95 
96  return ret;
97 }
set< int >::iterator it
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
h
Definition: demo3.py:41

Variable Documentation

Definition at line 28 of file temp_draw_plots_util.h.

const double kFDPOT = ana::kSecondAnaRunMatchedMCPOTScale
static

Definition at line 29 of file temp_draw_plots_util.h.

Referenced by ana::ComparisonTable().

const bool printratioplots =true

Definition at line 30 of file temp_draw_plots_util.h.

Referenced by ana::ComparisonTable().