Classes | Namespaces | Enumerations | Functions | Variables
draw_plots_util.h File Reference
#include "CAFAna/Analysis/Exposures.h"
#include "CAFAna/Analysis/Plots.h"
#include "CAFAna/Analysis/Calcs.h"
#include "3FlavorAna/Plotting/NuePlotStyle.h"
#include "CAFAna/Analysis/Style.h"
#include "CAFAna/Core/Binning.h"
#include "CAFAna/Core/HistAxis.h"
#include "CAFAna/Core/LoadFromFile.h"
#include "CAFAna/Prediction/IPrediction.h"
#include "CAFAna/Prediction/PredictionInterp.h"
#include "CAFAna/Prediction/PredictionExtrap.h"
#include "CAFAna/Prediction/PredictionNoExtrap.h"
#include "3FlavorAna/Prediction/PredictionExtendToPeripheral.h"
#include "3FlavorAna/Prediction/PredictionSystJoint2018.h"
#include "3FlavorAna/Prediction/PredictionSyst3Flavor2020.h"
#include "CAFAna/Vars/FitVars.h"
#include "CAFAna/Decomp/IDecomp.h"
#include "CAFAna/Extrap/IExtrap.h"
#include "CAFAna/Extrap/ModularExtrap.h"
#include "CAFAna/Extrap/ModularExtrapComponent.h"
#include "OscLib/OscCalcDumb.h"
#include "OscLib/IOscCalc.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 "TPaveText.h"
#include "TLegend.h"
#include "TLine.h"
#include "TSystem.h"
#include "TError.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cxxabi.h>
#include <string.h>
#include "tex_tables_util.h"

Go to the source code of this file.

Classes

struct  ana::DataMCComponents
 

Namespaces

 ana
 Cuts and Vars for the 2020 FD DiF Study.
 

Enumerations

enum  ana::EModExtrapComps {
  ana::kEEextrap, ana::kEEAntiextrap, ana::kMMextrap, ana::kMMAntiextrap,
  ana::kMEextrap, ana::kMEAntiextrap, ana::kEMextrap, ana::kEMAntiextrap,
  ana::kNCTotalextrap, ana::kNCextrap, ana::kNCAntiextrap, ana::kMTextrap,
  ana::kMTAntiextrap, ana::kETextrap, ana::kETAntiextrap, ana::kEEextrap,
  ana::kEEAntiextrap, ana::kMMextrap, ana::kMMAntiextrap, ana::kMEextrap,
  ana::kMEAntiextrap, ana::kEMextrap, ana::kEMAntiextrap, ana::kNCTotalextrap,
  ana::kNCextrap, ana::kNCAntiextrap, ana::kMTextrap, ana::kMTAntiextrap,
  ana::kETextrap, ana::kETAntiextrap, ana::kEEextrap, ana::kEEAntiextrap,
  ana::kMMextrap, ana::kMMAntiextrap, ana::kMEextrap, ana::kMEAntiextrap,
  ana::kEMextrap, ana::kEMAntiextrap, ana::kNCTotalextrap, ana::kNCextrap,
  ana::kNCAntiextrap, ana::kMTextrap, ana::kMTAntiextrap, ana::kETextrap,
  ana::kETAntiextrap
}
 

Functions

osc::IOscCalcGetCalculator (bool usingdumb)
 
TH1 * PrettyRatio (TH1 *shi, TH1 *nom, int color, double alpha=1., TString titley="1#sigma Shift / Nom")
 
double FindLimitY (std::vector< TH1 * > histos, bool doMax=true)
 
void FormatErrorBand (TH1 *hnom, TH1 *hplus, TH1 *hminus, TString signal="bkg", bool fixbins=false)
 
TH1 * HistNumuOpt (TH1 *orig)
 
void PrettyTag (TString pid, int color, double xndc, double yndc)
 
void PIDTag (TString pid)
 
void HTag (TString hie)
 
TLegend * CustomLegend (std::vector< TH1 * >h, std::vector< TString > titles, std::vector< TString > option, int n=1, double x1=kLegendDefaultX1, double y1=kLegendDefaultY1, double x2=kLegendDefaultX2, double y2=kLegendDefaultY2)
 
void FixLegend (TLegend *leg, TString opt="default")
 
TGraph * DummyGraph (int color=kBlack, int style=1, int linewidth=2, int markerstyle=kFullCircle)
 
TLegend * DefaultNueLegend (bool sig=true, bool tot=true, bool data=false, double x1=kLegendDefaultX1, double y1=kLegendDefaultY1, double x2=kLegendDefaultX2, double y2=kLegendDefaultY2)
 
TLegend * DefaultNumuLegend (bool sig=true, bool tot=true, bool data=false, double x1=kLegendDefaultX1, double y1=kLegendDefaultY1, double x2=kLegendDefaultX2, double y2=kLegendDefaultY2)
 
void PrintCanvasAll (TCanvas *c, const TString outname, const TString outdir="plots/", const std::vector< TString > exts={"pdf","png","root"})
 
void NuePID3bin (TH1 *h, bool coreOnlyND=false, bool binLabels=true, const double textSize=0.04, const int textColor=kGray+3, const int lineColor=kBlack, const int lineStyle=3, const double yNDC=0.96)
 
TCanvas * RatioPlot (std::vector< TH1 * > topHistos, std::vector< TString > topOption, std::vector< TH1 * > bottomHistos, std::vector< TString > bottomOption, TString pidtag, AxisType pidaxis=kNue1bin, const bool nearDet=false)
 
void PlotNDDataTotalMCComparison (TH1 *hdata, std::vector< TH1 * > htots, TLegend *leg, TString pidtag="", TString out_name="plot_nd", bool ratioplot=false, AxisType pidaxis=kNue1bin)
 
void PlotMCComponentsComparison (std::vector< TH1 * >vnom, std::vector< TH1 * >vshi, TLegend *leg, TString pidtag="", TString out_name="plot_nd", bool ratioplot=false, bool ratioerrors=false, AxisType pidaxis=kNue1bin)
 
void PlotMCComponentsErrorBand (std::vector< TH1 * >vnom, std::vector< TH1 * >vshi, TLegend *leg, TString pidtag="", TString out_name="plot_nd", bool ratioplot=false, bool ratioerrors=false, AxisType pidaxis=kNue1bin)
 
void ana::DefaultFormatNue (DataMCComponents &comp, int linestyle=1)
 
const DataMCComponents ana::GetNDCompsFromDecomp (const IDecomp *decomp)
 
const DataMCComponents ana::GetNDDecompsFromDecomp (const IDecomp *decomp)
 
struct DataMCComponets ana::GetFDMCComponents (osc::IOscCalc *calc, IPrediction *pred_no, TString output_name="nue", int linestyle=1, bool bkgdetails=false)
 
void ana::CompareNDDataOneMC (DataMCComponents h_no, DataMCComponents h_sh, TString plottitle, TString out_name, TString pidtag, AxisType pidaxis, bool printtable=true)
 
void ana::CompareNDDataTwoMC (DataMCComponents hnom, DataMCComponents hplu, DataMCComponents hmin, TString plottitle, TString out_name, TString pidtag, AxisType pidaxis, bool printtable=true, bool decomps=false)
 
const IDecomp * ana::GetDecomp (IPrediction *prediction, EModExtrapComps modExtrapComp)
 
void ana::CompareNDDataMCFromVector (PredictionSyst3Flavor2020 *predictionSyst, const ISyst *syst, EModExtrapComps modExtrapComp, TString plottitle, TString out_name, TString tag, AxisType pidaxis, bool printtable=true)
 
void ana::CompareOneShiftPred (IPrediction *pred_no, IPrediction *pred_sh, TString plottitle, TString out_name, TString pidtag, bool printtable=true, AxisType pidaxis=kNue1bin, bool PrintParams=false)
 
void ana::CompareTwoShiftPred (IPrediction *pred_no, IPrediction *pred_pl, IPrediction *pred_mi, TString plottitle, TString out_name, TString pidtag, bool printtable=true, AxisType pidaxis=kNue1bin, bool PrintParams=false)
 
void ana::ComparePredictionsFromVector (PredictionSyst3Flavor2020 *predictionSyst, const ISyst *syst, TString plottitle, TString out_name, bool printtable=true, AxisType pidaxis=kNue3bin)
 

Variables

static bool isFHC =true
 
const bool printratioplots =true
 
bool usedumb = false
 
bool mergePeripheral =false
 
const double kLegendDefaultX1 = 0.63
 
const double kLegendDefaultX2 = 0.85
 
const double kLegendDefaultY1 = 0.68
 
const double kLegendDefaultY2 = 0.88
 

Function Documentation

TLegend* CustomLegend ( std::vector< TH1 * >  h,
std::vector< TString >  titles,
std::vector< TString >  option,
int  n = 1,
double  x1 = kLegendDefaultX1,
double  y1 = kLegendDefaultY1,
double  x2 = kLegendDefaultX2,
double  y2 = kLegendDefaultY2 
)

Definition at line 186 of file draw_plots_util.h.

References MECModelEnuComparisons::leg, getGoodRuns4SAM::n, registry_explorer::v, x1, submit_syst::x2, y1, and submit_syst::y2.

190 {
191  TLegend* leg = new TLegend(x1, y1, x2, y2);
192  leg->SetFillStyle(0);
193  leg->SetNColumns(n);
194  for (unsigned int v = 0; v < h.size(); ++v)
195  leg->AddEntry(h[v], titles[v], option[v]);
196  leg->SetBit(kCanDelete);
197  return leg;
198 }
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
TLegend* DefaultNueLegend ( bool  sig = true,
bool  tot = true,
bool  data = false,
double  x1 = kLegendDefaultX1,
double  y1 = kLegendDefaultY1,
double  x2 = kLegendDefaultX2,
double  y2 = kLegendDefaultY2 
)

Definition at line 251 of file draw_plots_util.h.

References DummyGraph(), ana::kBeamNueBackgroundColor, ana::kNCBackgroundColor, ana::kNueSignalColor, ana::kNumuBackgroundColor, ana::kTotalMCColor, MECModelEnuComparisons::leg, PandAna.Demos.pi0_spectra::tot, x1, submit_syst::x2, y1, and submit_syst::y2.

255 {
256  TLegend* leg = new TLegend(x1,y1,x2,y2);
257  leg->SetFillStyle(0);
258  if(sig) leg->AddEntry( DummyGraph(kNueSignalColor), "#nu_{e} Signal","l");
259  if(data) leg->AddEntry( DummyGraph(), "ND Data","epl");
260  if(tot) leg->AddEntry( DummyGraph(kTotalMCColor), "Total Bkg","l");
261  leg->AddEntry( DummyGraph(kBeamNueBackgroundColor), "Beam #nu_{e}","l");
262  leg->AddEntry( DummyGraph(kNCBackgroundColor), "NC","l");
263  leg->AddEntry( DummyGraph(kNumuBackgroundColor), "#nu_{#mu} CC","l");
264  leg->SetBit(kCanDelete);
265  return leg;
266 
267 }
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
const Color_t kNumuBackgroundColor
Definition: Style.h:30
const Color_t kNueSignalColor
Definition: Style.h:19
const XML_Char const XML_Char * data
Definition: expat.h:268
const Color_t kBeamNueBackgroundColor
Definition: Style.h:24
TGraph * DummyGraph(int color=kBlack, int style=1, int linewidth=2, int markerstyle=kFullCircle)
const Color_t kTotalMCColor
Definition: Style.h:16
const Color_t kNCBackgroundColor
Definition: Style.h:22
TLegend* DefaultNumuLegend ( bool  sig = true,
bool  tot = true,
bool  data = false,
double  x1 = kLegendDefaultX1,
double  y1 = kLegendDefaultY1,
double  x2 = kLegendDefaultX2,
double  y2 = kLegendDefaultY2 
)

Definition at line 270 of file draw_plots_util.h.

References DummyGraph(), isNumuAna, ana::kBeamNueBackgroundColor, ana::kNCBackgroundColor, ana::kNueSignalColor, ana::kNumuBackgroundColor, ana::kNuTauBackgroundColor, ana::kTotalMCColor, MECModelEnuComparisons::leg, PandAna.Demos.pi0_spectra::tot, x1, submit_syst::x2, y1, and submit_syst::y2.

274 {
275  TLegend* leg = new TLegend(x1,y1,x2,y2);
276  leg->SetFillStyle(0);
277  if(sig)
278  leg->AddEntry(DummyGraph(kNueSignalColor), "#nu_{#mu} Signal", "l");
279  if(data)
280  leg->AddEntry(DummyGraph(), "ND Data", "epl");
281  if(tot)
282  leg->AddEntry(DummyGraph(kTotalMCColor), "Total Bkg", "l");
283  if(isNumuAna)
284  leg->AddEntry(DummyGraph(kNumuBackgroundColor), "#nu_{#mu} app", "l");
285  else
286  leg->AddEntry(DummyGraph(kNumuBackgroundColor), "#nu_{#mu} CC", "l");
287  leg->AddEntry(DummyGraph(kNCBackgroundColor), "NC","l");
288  leg->AddEntry(DummyGraph(kBeamNueBackgroundColor), "#nu_{e} CC","l");
289  leg->AddEntry(DummyGraph(kNuTauBackgroundColor), "#nu_{#tau} CC","l");
290  leg->SetBit(kCanDelete);
291  return leg;
292 }
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
const Color_t kNumuBackgroundColor
Definition: Style.h:30
const Color_t kNueSignalColor
Definition: Style.h:19
const XML_Char const XML_Char * data
Definition: expat.h:268
const Color_t kNuTauBackgroundColor
Definition: Style.h:26
bool isNumuAna
const Color_t kBeamNueBackgroundColor
Definition: Style.h:24
TGraph * DummyGraph(int color=kBlack, int style=1, int linewidth=2, int markerstyle=kFullCircle)
const Color_t kTotalMCColor
Definition: Style.h:16
const Color_t kNCBackgroundColor
Definition: Style.h:22
TGraph* DummyGraph ( int  color = kBlack,
int  style = 1,
int  linewidth = 2,
int  markerstyle = kFullCircle 
)

Definition at line 239 of file draw_plots_util.h.

References plot_validation_datamc_2018::color.

240 {
241  auto gr = new TGraph();
242  gr->SetLineColor(color);
243  gr->SetLineStyle(style);
244  gr->SetLineWidth(linewidth);
245  gr->SetMarkerStyle(markerstyle);
246  gr->SetMarkerColor(color);
247  return gr;
248 }
double FindLimitY ( std::vector< TH1 * >  histos,
bool  doMax = true 
)

Definition at line 98 of file draw_plots_util.h.

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

99 {
100  double max = histos[0]->GetMaximum();
101  double min = histos[0]->GetMinimum();
102 
103  for(unsigned int i=0; i<histos.size(); i++){
104  if ( histos[i]->GetMaximum() > max ) max = histos[i]->GetMaximum();
105  if ( histos[i]->GetMinimum() < min ) min = histos[i]->GetMinimum();
106  }
107 
108  if ( doMax ) return max;
109  else return min;
110 }
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
void FixLegend ( TLegend *  leg,
TString  opt = "default" 
)

Definition at line 202 of file draw_plots_util.h.

References kLegendDefaultX1, kLegendDefaultX2, kLegendDefaultY1, kLegendDefaultY2, and MECModelEnuComparisons::opt.

203 {
204  leg->SetFillStyle(0);
205  if(opt=="default")
206  {
207  leg->SetX1(kLegendDefaultX1); leg->SetX2(kLegendDefaultX2);
208  leg->SetY1(kLegendDefaultY1); leg->SetY2(kLegendDefaultY2);
209  }
210  if(opt=="ExPID")
211  {
212  leg->SetX1(0.355); leg->SetX2(0.515);
213  leg->SetY1(0.65); leg->SetY2(0.82);
214  leg->SetBorderSize(0);
215  leg->SetTextSize(0.03);
216  }
217  if(opt=="ExPIDNearDet")
218  {
219  leg->SetX1(0.695); leg->SetX2(0.855);
220  leg->SetY1(0.65); leg->SetY2(0.82);
221  leg->SetBorderSize(0);
222  leg->SetTextSize(0.03);
223  }
224  if(opt=="ExPIDPads")
225  {
226  leg->SetX1(0.55); leg->SetX2(0.89);
227  leg->SetY1(0.75); leg->SetY2(0.89);
228  leg->SetTextSize(0.045);
229  }
230  if(opt=="ExRatio")
231  {
232  leg->SetTextSize(0.035);
233  leg->SetX1(0.1); leg->SetX2(0.3);
234  leg->SetY1(0.05); leg->SetY2(0.35);
235  }
236 }
const double kLegendDefaultY2
const double kLegendDefaultY1
const double kLegendDefaultX2
const double kLegendDefaultX1
void FormatErrorBand ( TH1 *  hnom,
TH1 *  hplus,
TH1 *  hminus,
TString  signal = "bkg",
bool  fixbins = false 
)

Definition at line 113 of file draw_plots_util.h.

References om::cout, allTimeWatchdog::endl, MECModelEnuComparisons::i, ana::kBeamNueBackgroundColor, kBlue, ana::kNCBackgroundColor, ana::kNumuBackgroundColor, kRed, ana::kTotalMCErrorBandColor, kViolet, cet::sqlite::max(), and min().

115 {
116  int mccolor;
117  // why oh why the switch does not work for strings
118  if(signal == "sig") mccolor = kViolet -9; // signal color
119  else if(signal == "bkg") mccolor = kTotalMCErrorBandColor; // total bkg color
120  else if(signal == "beam") mccolor = kBeamNueBackgroundColor -10; // beam bkg color
121  else if(signal == "numu") mccolor = kNumuBackgroundColor -10; // numu bkg color
122  else if(signal == "nc") mccolor = kNCBackgroundColor -9; // nc bkg color
123  else mccolor = kTotalMCErrorBandColor;
124 
125  std::cout << "hplus: " << hplus->Integral() << std::endl;
126  std::cout << "hminus: " << hminus->Integral() << std::endl;
127  hplus ->SetLineColor(mccolor);
128  hminus->SetLineColor(mccolor);
129  hplus ->SetFillColor(mccolor);
130  hminus->SetFillColor(10);
131  hplus ->SetMarkerColor(kRed-7);
132  hminus->SetMarkerColor(kBlue-7);
133 
134  if (fixbins)
135  {
136  for(int i=1; i <= hplus->GetNbinsX(); i++)
137  {
138  double tnom = hnom->GetBinContent(i);
139  double tplus = hplus->GetBinContent(i);
140  double tminus = hminus->GetBinContent(i);
141  hplus->SetBinContent(i,max(tplus, max(tnom, tminus)));
142  hminus->SetBinContent(i,min(tplus, min(tnom, tminus)));
143  //hplus->SetBinContent(i,max(tplus, tminus));
144  //hminus->SetBinContent(i,min(tplus, tminus));
145  }
146  }
147 }
enum BeamMode kRed
TH1F * hplus
Definition: Xsec_final.C:75
const Color_t kTotalMCErrorBandColor
Definition: Style.h:17
const Color_t kNumuBackgroundColor
Definition: Style.h:30
const Color_t kBeamNueBackgroundColor
Definition: Style.h:24
OStream cout
Definition: OStream.cxx:6
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
TH1F * hminus
Definition: Xsec_final.C:76
enum BeamMode kViolet
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
const Color_t kNCBackgroundColor
Definition: Style.h:22
enum BeamMode kBlue
osc::IOscCalc* GetCalculator ( bool  usingdumb)

Definition at line 58 of file draw_plots_util.h.

References calc, osc::OscCalcDumb::Copy(), osc::_IOscCalc< T >::Copy(), ana::DefaultOscCalc(), dmsq32, ana::kFitDeltaInPiUnits, ana::kFitDmSq32, ana::kFitSinSqTheta23, ana::FitVarWithPrior::SetValue(), ana::ConstrainedFitVarWithPrior::SetValue(), ana::FitDmSq32::SetValue(), and ssth23.

58  {
59  double dCP_Pi = .0;
60  double ssth23 = 0.56;
61  double dmsq32 = 2.48e-3;
62 
64  if(usingdumb){
65  osc::OscCalcDumb dumb;
66  calc = dumb.Copy();
67  }
68  else{
69  auto calc2 = DefaultOscCalc();
70  kFitDeltaInPiUnits.SetValue(calc2, dCP_Pi);
71  kFitSinSqTheta23.SetValue(calc2, ssth23);
72  kFitDmSq32.SetValue(calc2, dmsq32);
73  calc = calc2->Copy();
74  }
75  return calc;
76 }
double ssth23
const FitDmSq32 kFitDmSq32
Definition: FitVars.cxx:18
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
Definition: FitVars.cxx:177
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
Forward to wrapped Var&#39;s SetValue()
osc::OscCalcDumb calc
osc::IOscCalcAdjustable * DefaultOscCalc()
Create a new calculator with default assumptions for all parameters.
Definition: Calcs.cxx:49
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
Simple oscillation probability calculator that has no solar term or mass hierarchy or delta so it&#39;s s...
Definition: OscCalcDumb.h:16
virtual _IOscCalc * Copy() const =0
double dmsq32
const ConstrainedFitVarWithPrior fitSsqTh23_UniformPriorSsqTh23 & kFitSinSqTheta23
const FitVarWithPrior fitDeltaInPiUnits_UniformPriordCP & kFitDeltaInPiUnits
virtual IOscCalc * Copy() const override
Definition: OscCalcDumb.h:19
TH1* HistNumuOpt ( TH1 *  orig)

Definition at line 150 of file draw_plots_util.h.

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

150  {
151  auto ret = (TH1*) orig->Clone(UniqueName().c_str());
152  ret->Scale(0.1,"width");
153  ret->GetYaxis()->SetTitle("Events / 0.1 GeV");
154  ret->SetBit(kCanDelete);
155  ret->SetDirectory(gROOT);
156  return ret;
157 }
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
void HTag ( TString  hie)

Definition at line 175 of file draw_plots_util.h.

References kOrange, and PrettyTag().

175 { PrettyTag (hie, (hie=="NH")?kAzure+3:kOrange+2, .18, .825);}
enum BeamMode kOrange
void PrettyTag(TString pid, int color, double xndc, double yndc)
void NuePID3bin ( TH1 *  h,
bool  coreOnlyND = false,
bool  binLabels = true,
const double  textSize = 0.04,
const int  textColor = kGray+3,
const int  lineColor = kBlack,
const int  lineStyle = 3,
const double  yNDC = 0.96 
)

Definition at line 339 of file draw_plots_util.h.

References plot_validation_datamc_2018::lineStyle, ana::Nue2018ThreeBinDivisions(), and ana::Nue2018ThreeBinLabels().

343 {
344  if (coreOnlyND)
345  Info("NuePID3bin", "specified core only/ND.");
346 
347  Nue2018ThreeBinDivisions(coreOnlyND, lineColor, lineStyle);
348  if (binLabels)
349  {
350  Nue2018ThreeBinLabels(yNDC, textSize, textColor, coreOnlyND);
351  }
352  else
353  {
354  if (textSize != 0.04)
355  Warning("NuePID3bin",
356  "binLabels == false --> specified text size has no effect");
357  if (textColor != kGray+3)
358  Warning("NuePID3bin",
359  "binLabels == false --> specified text color has no effect");
360  if (yNDC != 0.96)
361  Warning("NuePID3bin",
362  "binLabels == false --> specified yNDC has no effect");
363  }
364 }
void Nue2018ThreeBinDivisions(bool coreOnly, const int color, const int style)
void Nue2018ThreeBinLabels(const double yNDC, const double textsize, const int color, const bool nd)
void PIDTag ( TString  pid)

Definition at line 174 of file draw_plots_util.h.

References PrettyTag().

174 { PrettyTag (pid, kAzure+3, .83, .92); }
void PrettyTag(TString pid, int color, double xndc, double yndc)
void PlotMCComponentsComparison ( std::vector< TH1 * >  vnom,
std::vector< TH1 * >  vshi,
TLegend *  leg,
TString  pidtag = "",
TString  out_name = "plot_nd",
bool  ratioplot = false,
bool  ratioerrors = false,
AxisType  pidaxis = kNue1bin 
)

Definition at line 668 of file draw_plots_util.h.

References demo5::c2, FixLegend(), kNue3bin, NuePID3bin(), submit_concat_project::out_name, PIDTag(), PrettyRatio(), PrintCanvasAll(), ana::PrintLatexFigure(), RatioPlot(), ana::UniqueName(), and registry_explorer::v.

673 {
674  // Is it NearDet?
675  Info("PlotMCComponentsErrorBand", "out_name = " + out_name);
676  const auto isNearDet = out_name.Contains("_ND_", TString::kIgnoreCase) && !out_name.Contains("_pred_", TString::kIgnoreCase);
677  if (isNearDet)
678  Info("PlotMCComponentsErrorBand", "isNearDet = true");
679  else
680  Info("PlotMCComponentsErrorBand", "isNearDet = false");
681 
682  if(pidaxis==kNue3bin)
683  {
684  if (isNearDet)
685  FixLegend(leg, "ExPIDNearDet");
686  else
687  FixLegend(leg, "ExPID");
688  }
689 
690 
691  if(!ratioplot)
692  {
693  auto c2 = new TCanvas(UniqueName().c_str(), "c2");
694  for(auto const & v:vnom)
695  v->Draw("hist same");
696  for(auto const & v:vshi)
697  v->Draw("hist same");
698  if(pidaxis==kNue3bin)
699  NuePID3bin(vnom[0], isNearDet);
700  PIDTag(pidtag);
701  leg->Draw("same");
702  PrintCanvasAll(c2, out_name+"_mccomp");
703  PrintLatexFigure("/png_"+out_name+"_mccomp");
704  c2->Close();
705  }
706  else
707  {
708  std::vector<TH1*> vratio;
709  for(unsigned int ii=0; ii<vshi.size();ii++)
710  {
711  auto htemp = PrettyRatio(vshi[ii], vnom[ii],
712  vnom[ii]->GetLineColor(), ii>0 ? 0.4:1.);
713  htemp->GetYaxis()->SetRangeUser(0.5, 1.5);
714  vratio.push_back (htemp);
715  }
716  vnom.insert(vnom.end(), vshi.begin(), vshi.end());
717  std::vector<TString>topOption(vnom.size(), "hist");
718  std::vector<TString>bottomOption(vratio.size(),
719  ratioerrors ? "p":"hist p");
720  auto cratio2 = RatioPlot(
721  vnom, topOption, vratio, bottomOption, pidtag, pidaxis, isNearDet);
722  cratio2->cd();
723  leg->Draw("same");
724  PIDTag(pidtag);
725  PrintCanvasAll(cratio2, out_name+"_mccomp_ratio");
726  PrintLatexFigure("/png_"+out_name+"_mccomp_ratio");
727  }
728 }
c2
Definition: demo5.py:33
void PIDTag(TString pid)
void NuePID3bin(TH1 *h, TString pidtag, bool binlabels=true)
void PrintLatexFigure(TString name, TString plotdir="plots/")
TH1 * PrettyRatio(TH1 *shi, TH1 *nom, int color, double alpha=1., TString titley="Shift / Nom")
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
TCanvas * RatioPlot(std::vector< TH1 * > topHistos, std::vector< TString > topOption, std::vector< TH1 * > bottomHistos, std::vector< TString > bottomOption, TString pidtag, AxisType pidaxis=kNue1bin)
void FixLegend(TLegend *leg, TString opt="default")
void PrintCanvasAll(TCanvas *c, const TString outname, const TString outdir="plots/", const std::vector< TString > exts={"pdf","png","root"})
void PlotMCComponentsErrorBand ( std::vector< TH1 * >  vnom,
std::vector< TH1 * >  vshi,
TLegend *  leg,
TString  pidtag = "",
TString  out_name = "plot_nd",
bool  ratioplot = false,
bool  ratioerrors = false,
AxisType  pidaxis = kNue1bin 
)

Definition at line 732 of file draw_plots_util.h.

References ana::DataMCComponents::beam, ana::DataMCComponents::bkg, demo5::c2, ana::CenterTitles(), om::cout, ana::DataMCComponents::data, plot_validation_datamc_2018::decomp, ana::DefaultFormatNue(), allTimeWatchdog::endl, FixLegend(), FormatErrorBand(), make_mec_shifts_plots::GetMaximum(), ana::GetNDCompsFromDecomp(), isFHC, ana::kAna2020FHCPOT, ana::kAna2020RHCPOT, ana::kBeamNueBackgroundColor, ana::kNCBackgroundColor, kNue3bin, ana::kNueSignalColor, ana::kNueSignalWSColor, ana::kNumuBackgroundColor, ana::kTotalMCColor, ana::DataMCComponents::mcTotal, ana::DataMCComponents::nc, NuePID3bin(), ana::DataMCComponents::nuetonumu, ana::DataMCComponents::nuetonutau, ana::DataMCComponents::numu, ana::DataMCComponents::numutonumu, ana::DataMCComponents::numutonutau, confusionMatrixTree::out, submit_concat_project::out_name, PIDTag(), PrettyRatio(), PrintCanvasAll(), ana::PrintLatexFigure(), RatioPlot(), runNovaSAM::ret, ana::DataMCComponents::sig, ana::DataMCComponents::tau, registry_explorer::v, and ana::DataMCComponents::wrongSign.

736 {
737  // Is it NearDet?
738  Info("PlotMCComponentsErrorBand", "out_name = " + out_name);
739  const auto isNearDet = out_name.Contains("_ND_", TString::kIgnoreCase) && !out_name.Contains("_pred_", TString::kIgnoreCase);
740  if (isNearDet)
741  Info("PlotMCComponentsErrorBand", "isNearDet = true");
742  else
743  Info("PlotMCComponentsErrorBand", "isNearDet = false");
744 
745  auto hplu_band = reinterpret_cast<TH1*>(vshi[0]->Clone());
746  auto hmin_band = reinterpret_cast<TH1*>(vshi[1]->Clone());
747  auto const hplu_hist = reinterpret_cast<TH1*>(vshi[0]->Clone());
748  auto const hmin_hist = reinterpret_cast<TH1*>(vshi[1]->Clone());
749 
750  TString out = "bkg";
751  if(out_name.Contains("_sig")) out = "sig";
752  else if(out_name.Contains("decomp_beam")) out = "beam";
753  else if(out_name.Contains("decomp_nc")) out = "nc";
754  else if(out_name.Contains("decomp_numu")) out = "numu";
755 
756  FormatErrorBand(vnom[0], hplu_band, hmin_band, out, true);
757 
758  std::vector<TH1*>vshi_band={hplu_band,hmin_band};
759  std::vector<TH1*>vshi_hist={hplu_hist,hmin_hist};
760 
761  if(pidaxis==kNue3bin)
762  {
763  if (isNearDet)
764  FixLegend(leg, "ExPIDNearDet");
765  else
766  FixLegend(leg, "ExPID");
767  }
768 
769  if(!ratioplot)
770  {
771  auto c2 = new TCanvas ("c2","c2");
772  vnom[0]->SetMaximum(1.2*vnom[0]->GetMaximum());
773  vnom[0]->Draw("hist");
774  for(auto v:vshi_band) v->Draw("hist same");
775  for(auto v:vshi_hist) v->Draw("e same");
776  for(auto v:vnom) v->Draw("hist same");
777  if(pidaxis==kNue3bin)
778  NuePID3bin(vnom[0], isNearDet);
779  PIDTag(pidtag);
780  leg->Draw("same");
781  PrintCanvasAll(c2, out_name+"_mccomp");
782  PrintLatexFigure("/png_"+out_name+"_mccomp");
783  c2->Close();
784  }
785  else
786  {
787  std::vector<TH1*> vratio;
788  for(unsigned int ii=0; ii<vshi.size(); ii++)
789  {
790  auto htemp = PrettyRatio(vshi[ii], vnom[0], vshi[ii]->GetMarkerColor());
791  vratio.push_back(htemp);
792  }
793  vratio[0]->GetYaxis()->SetRangeUser(0.5,1.5);
794  vnom.insert(vnom.begin()+1,vshi_band.begin(),vshi_band.end());
795  std::vector<TString> topOption (vnom.size(), "hist");
796  std::vector<TString> bottomOption (vratio.size(),ratioerrors ?"p":"hist p");
797  auto cratio2= RatioPlot(
798  vnom, topOption, vratio, bottomOption, pidtag, pidaxis, isNearDet);
799  cratio2->cd();
800  leg->Draw("same");
801  PIDTag(pidtag);
802  PrintCanvasAll(cratio2, out_name+"_mccomp_ratio");
803  PrintLatexFigure("/png_"+out_name+"_mccomp_ratio");
804  }
805 }
c2
Definition: demo5.py:33
void PIDTag(TString pid)
void FormatErrorBand(TH1 *hplus, TH1 *hminus, bool signal=false, bool fixbins=false)
void NuePID3bin(TH1 *h, TString pidtag, bool binlabels=true)
void PrintLatexFigure(TString name, TString plotdir="plots/")
TH1 * PrettyRatio(TH1 *shi, TH1 *nom, int color, double alpha=1., TString titley="Shift / Nom")
TCanvas * RatioPlot(std::vector< TH1 * > topHistos, std::vector< TString > topOption, std::vector< TH1 * > bottomHistos, std::vector< TString > bottomOption, TString pidtag, AxisType pidaxis=kNue1bin)
void FixLegend(TLegend *leg, TString opt="default")
void PrintCanvasAll(TCanvas *c, const TString outname, const TString outdir="plots/", const std::vector< TString > exts={"pdf","png","root"})
void PlotNDDataTotalMCComparison ( TH1 *  hdata,
std::vector< TH1 * >  htots,
TLegend *  leg,
TString  pidtag = "",
TString  out_name = "plot_nd",
bool  ratioplot = false,
AxisType  pidaxis = kNue1bin 
)

Definition at line 614 of file draw_plots_util.h.

References demo5::c1, FixLegend(), genie::utils::style::Format(), make_mec_shifts_plots::GetMaximum(), make_syst_table_plots::h, compare_h5_caf::idx, kNue3bin, NuePID3bin(), submit_concat_project::out_name, PIDTag(), PrettyRatio(), PrintCanvasAll(), ana::PrintLatexFigure(), PandAna.reco_validation.prod5_pid_validation::ratio(), and RatioPlot().

618 {
619  Info("PlotNDDataTotalMCComparison",
620  TString::Format("pidaxis = %d", pidaxis));
621 
622  if(pidaxis==kNue3bin)
623  FixLegend(leg, "ExPIDNearDet");
624  std::vector<TString> h_opt;
625  for(auto const & h:htots) h_opt.push_back("hist");
626  h_opt.push_back("p");
627 
628  if(!ratioplot)
629  {
630  auto c1 = new TCanvas ("c1","c1");
631  htots[0]->SetMaximum(1.3*htots[0]->GetMaximum());
632  for(auto const & h:htots) h->Draw("hist same");
633  htots[0]->Draw("hist same"); //need to redraw for error bands
634  hdata->Draw("p same");
635  PIDTag(pidtag);
636  if(pidaxis==kNue3bin)
637  NuePID3bin(htots[0], true); // hist, coreOnlyND, binLabels
638  leg->Draw("same");
639  PrintCanvasAll(c1, out_name+"_datamc");
640  PrintLatexFigure("/png_"+out_name+"_datamc");
641  }
642  else
643  {
644  std::vector<TH1*> ratios;
645  std::vector<TString> r_opt;
646  auto idx = 0;
647  for(auto const & h:htots)
648  {
649  auto ratio = PrettyRatio(hdata, h, h->GetLineColor(),
650  idx>0 ? 0.4:1., "Data / MC");
651  ratio->GetYaxis()->SetRangeUser(0.5,1.5);
652  ratios.push_back(ratio);
653  r_opt.push_back("e");
654  idx++;
655  }
656  htots.push_back(hdata);
657  auto cratio1 = RatioPlot(htots, h_opt, ratios,
658  r_opt, pidtag, pidaxis, true);
659  cratio1->cd();
660  leg->Draw("same");
661  PIDTag(pidtag);
662 
663  PrintCanvasAll(cratio1,out_name+"_datamc_ratio");
664  PrintLatexFigure("/png_"+out_name+"_datamc_ratio");
665  }
666 }
def ratio(spec1, spec2, nbins, pot, binrange=(0, 1))
void PIDTag(TString pid)
void NuePID3bin(TH1 *h, TString pidtag, bool binlabels=true)
void PrintLatexFigure(TString name, TString plotdir="plots/")
TH1 * PrettyRatio(TH1 *shi, TH1 *nom, int color, double alpha=1., TString titley="Shift / Nom")
c1
Definition: demo5.py:24
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
TCanvas * RatioPlot(std::vector< TH1 * > topHistos, std::vector< TString > topOption, std::vector< TH1 * > bottomHistos, std::vector< TString > bottomOption, TString pidtag, AxisType pidaxis=kNue1bin)
void FixLegend(TLegend *leg, TString opt="default")
void PrintCanvasAll(TCanvas *c, const TString outname, const TString outdir="plots/", const std::vector< TString > exts={"pdf","png","root"})
TH1* PrettyRatio ( TH1 *  shi,
TH1 *  nom,
int  color,
double  alpha = 1.,
TString  titley = "1#sigma Shift / Nom" 
)

Definition at line 83 of file draw_plots_util.h.

References ana::UniqueName().

85 {
86  auto htemp = reinterpret_cast<TH1*>(nom->Clone(ana::UniqueName().c_str()));
87  htemp->Divide(shi,nom);
88  htemp->SetMarkerColorAlpha(color,alpha);
89  htemp->SetLineColorAlpha(color,alpha);
90  htemp->SetMarkerStyle(34);
91  htemp->SetMarkerSize(1.4);
92  htemp->GetYaxis()->SetTitle(titley);
93  return htemp;
94 }
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
void PrettyTag ( TString  pid,
int  color,
double  xndc,
double  yndc 
)

Definition at line 163 of file draw_plots_util.h.

References getGoodRuns4SAM::tag.

163  {
164  TLatex* tag = new TLatex(xndc, yndc, pid);
165  tag->SetTextColor(color);
166  tag->SetNDC();
167  tag->SetTextSize(0.04);
168  tag->SetTextFont(42);
169  tag->SetTextAlign(22);
170  tag->Draw();
171  tag->SetBit(kCanDelete);
172 }
void PrintCanvasAll ( TCanvas *  c,
const TString  outname,
const TString  outdir = "plots/",
const std::vector< TString >  exts = {"pdf","png","root"} 
)

Definition at line 295 of file draw_plots_util.h.

References plot_validation_datamc::c, galleryMaker::ext, and outdir.

296  {"pdf","png","root"} )
297 {
298  for(auto const & ext:exts){
299  gSystem -> MakeDirectory( outdir );
300  gSystem -> MakeDirectory( outdir+"rootfiles/" );
301  if(ext=="png") c->SaveAs(outdir+"png_"+outname + "." + ext);
302  else if(ext=="root") c->SaveAs(outdir+"rootfiles/"+outname + "." + ext);
303  else c->SaveAs(outdir+outname + "." + ext);
304  }
305  delete c;
306 }
const std::string outdir
TCanvas* RatioPlot ( std::vector< TH1 * >  topHistos,
std::vector< TString >  topOption,
std::vector< TH1 * >  bottomHistos,
std::vector< TString >  bottomOption,
TString  pidtag,
AxisType  pidaxis = kNue1bin,
const bool  nearDet = false 
)

Definition at line 430 of file draw_plots_util.h.

References plot_validation_datamc::c, plot_validation_datamc::Clone(), CustomLegend(), Draw(), FindLimitY(), FixLegend(), make_syst_table_plots::h, h1, h3, kNue3bin, cet::sqlite::max(), NuePID3bin(), plot_validation_datamc::p1, and plot_validation_datamc::p2.

434 {
435  gStyle->SetTitleStyle(0);
436  TCanvas *c = new TCanvas("c", "canvas", 600, 700);
437  // if(pidaxis == kNue3bin) c->SetCanvasSize(750,650);
438  //define top and bottom pads
439  TPad* p1 = new TPad("", "", 0, 0, 1, 1);
440  TPad* p2 = new TPad("", "", 0, 0, 1, 1);
441  p1->SetBottomMargin(.3);
442  p2->SetTopMargin(.7);
443 
444  for(auto p:{p1,p2}){
445  p->SetFillStyle(0);
446  p->Draw();
447  }
448 
449  // format histograms
450  auto h1 = (TH1*) topHistos[0]->Clone();
451  auto h3 = (TH1*) bottomHistos[0]->Clone();
452 
453  for(auto & h:{h1,h3}){
454  h->SetStats(0);
455 
456  h->GetYaxis()->SetTitleSize(26);
457  h->GetYaxis()->SetTitleFont(43);
458  h->GetYaxis()->SetTitleOffset(1.3);
459  h->GetYaxis()->SetLabelFont(43);
460 
461  h->GetXaxis()->SetTitleOffset(1.2);
462  h->GetXaxis()->SetTitleSize(28);
463  h->GetXaxis()->SetTitleFont(43);
464  h->GetXaxis()->SetLabelFont(43);
465  }
466 
467  if (pidaxis == kNue3bin)
468  h1->GetYaxis()->SetRangeUser(
469  FindLimitY(topHistos,0), 1.5*FindLimitY(topHistos, 1));
470  else
471  h1->GetYaxis()->SetRangeUser(
472  FindLimitY(topHistos,0), 1.2*FindLimitY(topHistos, 1));
473  h1->GetYaxis()->SetLabelSize(18);
474 
475  h1->GetXaxis()->SetLabelSize(0);
476  h1->GetXaxis()->SetTitleSize(0);
477 
478  h3->SetTitle("");
479  h3->GetYaxis()->SetRangeUser(max(0.,2-FindLimitY(bottomHistos,1)),
480  1.01*FindLimitY(bottomHistos,1));
481  h3->GetYaxis()->SetLabelSize(15);
482  h3->GetYaxis()->SetDecimals();
483 
484  h3->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
485  h3->GetXaxis()->SetLabelSize(18);
486  h3->GetXaxis()->SetLabelOffset(0.005);
487 
488  p1->cd();
489 
490  h1->Draw(topOption[0]);
491 
492  for(unsigned int ii = 1; ii < topHistos.size(); ++ii) {
493  topHistos[ii]->Draw("same "+topOption[ii]);}
494  h1->Draw("same "+topOption[0]);
495 
496  p1->RedrawAxis(); //white histograms cover axes
497 
498  if(pidaxis==kNue3bin)
499  NuePID3bin(h1, nearDet);
500 
501  p2->cd();
502  h3->Draw(bottomOption[0]);
503  for(unsigned int ii = 1; ii < bottomHistos.size(); ++ii){
504  bottomHistos[ii]->Draw("same " + bottomOption[ii]);}
505  h3->Draw("same " + bottomOption[0]);
506  if(bottomHistos.size() == 2 && strcmp(h3->GetYaxis()->GetTitle(),"Data / MC") != 0)
507  {
508  TLegend * leg_ratio = CustomLegend(bottomHistos,{" +1#sigma"," -1#sigma"},{bottomOption[0],bottomOption[0]});
509  FixLegend(leg_ratio, "ExRatio");
510  leg_ratio -> Draw();
511  }
512  auto lone = new TLine();
513  lone->SetLineStyle(3);
514  lone->SetLineColor(kGray+3);
515  p2->Update();
516  lone->DrawLine(p2->GetUxmin(),1.0,p2->GetUxmax(),1.0);
517  lone->DrawLine(p2->GetUxmin(),1.2,p2->GetUxmax(),1.2);
518  lone->DrawLine(p2->GetUxmin(),0.8,p2->GetUxmax(),0.8);
519  float p2Y = p2->GetUymax()-p2->GetUymin();
520  h3->GetYaxis()->SetRangeUser(p2->GetUymin()-(0.01*p2Y),p2->GetUymax()+(0.01*p2Y));
521  p2->RedrawAxis();
522  if(pidaxis==kNue3bin)
523  NuePID3bin(h3, nearDet, false); // hist, coreOnlyND, binLabels
524 
525  return c;
526 }
tree Draw("slc.nhit")
TH1F * h3
Definition: berger.C:36
const char * p
Definition: xmltok.h:285
TLegend * CustomLegend(std::vector< TH1 * >h, std::vector< TString > title, std::vector< TString > option, double x1=kLegendDefaultX1, double y1=kLegendDefaultY1, double x2=kLegendDefaultX2, double y2=kLegendDefaultY2)
double FindLimitY(std::vector< TH1 * > histos, bool doMax=true)
void NuePID3bin(TH1 *h, TString pidtag, bool binlabels=true)
TH1F * h1
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
void FixLegend(TLegend *leg, TString opt="default")

Variable Documentation

bool isFHC =true
static

Definition at line 48 of file draw_plots_util.h.

Referenced by ana::GetNDDecompsFromDecomp(), and PlotMCComponentsErrorBand().

const double kLegendDefaultX1 = 0.63

Definition at line 181 of file draw_plots_util.h.

const double kLegendDefaultX2 = 0.85

Definition at line 182 of file draw_plots_util.h.

const double kLegendDefaultY1 = 0.68

Definition at line 183 of file draw_plots_util.h.

const double kLegendDefaultY2 = 0.88

Definition at line 184 of file draw_plots_util.h.

bool mergePeripheral =false

Definition at line 56 of file draw_plots_util.h.

const bool printratioplots =true

Definition at line 51 of file draw_plots_util.h.

bool usedumb = false

Definition at line 55 of file draw_plots_util.h.