PlotMCOnly.C
Go to the documentation of this file.
1 #include "TH1D.h"
2 #include "TFile.h"
3 #include "TCanvas.h"
4 #include "TLegend.h"
5 #include "TStyle.h"
6 #include "TSystem.h"
7 
8 #include "CAFAna/Core/Binning.h"
9 #include "CAFAna/Core/Spectrum.h"
11 #include "CAFAna/nus/NuSPlotFunctions.h"
12 
14 
15 #include <iostream>
16 #include <sstream>
17 #include <fstream>
18 #include <vector>
19 #include <string>
20 
21 using namespace ana;
22 //......................................................
23 TH1D* GetSpectToHist( TFile* MyF, std::string Path, int Col, std::string Axis );
24 //......................................................
25 
26 //......................................................
27 void PlotMCOnly() {
28  // ---- First off, lets set the styles...
29  gStyle->SetOptStat(0);
30 
31  // --- Load all of my files.
32  std::string BaseCAFFileDir="/nova/app/users/karlwarb/Tag_S17-10-09/Workspace/BoxOpening/Comparison/";
33  std::string InputCAFFileNa="Concat_MC_Short_AP.root";
34  std::string InputCAFLoc = BaseCAFFileDir + InputCAFFileNa;
35 
36  TFile *MCFile = TFile::Open( InputCAFLoc.c_str() );
37 
38  // -------- Set some basic parameters -------
39  const int Colours[4] = { 1, 2, 4, 6 };
40  // --- Cuts
41  const int NumCut = 1;
42  const std::string CutNames[NumCut] = {
43  //"_QualCuts",
44  //"_DetCuts" ,
45  //"_CosmCuts",
46  "_NeuCCuts"
47  };
48  // --- Quantiles
49  const int NumQuant = 1;
51  "_AllQuants"
52  //,"_Quant1"
53  //,"_Quant2"
54  //,"_Quant3"
55  //,"_Quant4"
56  };
57  // --- Calibration labels.
58  const int NumCorn = 4;
59  const std::string CornName[NumCorn] = { "TopL", "TopR", "BotL", "BotR" };
60 
61  // --- Define my histograms.
62  TH1D* hCor_RecTr[NumCut][NumQuant][4];
63  TH1D* hCor_MuoTr[NumCut][NumQuant][4];
64  TH1D* hCor_HadTr[NumCut][NumQuant][4];
65  TH1D* hCor_HFrTr[NumCut][NumQuant][4];
66  TH1D* hCor_ReTr [NumCut][NumQuant][4];
67 
68  for (int cc=0; cc<NumCut; ++cc) {
69  for (int qq=0; qq<NumQuant; ++qq) {
70  for (int cor=0; cor<NumCorn; ++cor) {
71  std::string LoadPath = CutNames[cc] + QuantNames[qq] + "_" + CornName[cor];
72  std::cerr << "Want to load " << LoadPath << std::endl;
73  hCor_RecTr[cc][qq][cor] = GetSpectToHist( MCFile, "sCor_RecTr"+LoadPath, Colours[cor], "Reconstructed Energy; Energy (GeV); Number of events" );
74  hCor_MuoTr[cc][qq][cor] = GetSpectToHist( MCFile, "sCor_MuoTr"+LoadPath, Colours[cor], "Muon Energy; Energy (GeV); Number of events" );
75  hCor_HadTr[cc][qq][cor] = GetSpectToHist( MCFile, "sCor_HadTr"+LoadPath, Colours[cor], "Hadronic Energy; Energy (GeV); Number of events" );
76  hCor_HFrTr[cc][qq][cor] = GetSpectToHist( MCFile, "sCor_HFrTr"+LoadPath, Colours[cor], "Hadronic Energy Frac; Energy (GeV); Number of events" );
77  hCor_ReTr [cc][qq][cor] = GetSpectToHist( MCFile, "sCor_ReTr" +LoadPath, Colours[cor], "Reco-True/True Energy; Energy (GeV); Number of events" );
78  }
79 
80  TLegend *lCorner = new TLegend( 0.72, 0.15, 0.9, 0.9 );
81  lCorner -> SetFillStyle (0);
82  lCorner -> SetBorderSize(0);
83 
84  // --- Reconst Energy
85  TCanvas* cCor_RecTr = new TCanvas( ("cCor_RecTr"+CutNames[cc]+QuantNames[qq]).c_str(), "Reconstructed Energy" );
86  cCor_RecTr->cd();
87  for (int cor=0; cor<NumCorn; ++cor) {
88  if (cor==0) hCor_RecTr[cc][qq][cor] -> Draw("hist ");
89  else hCor_RecTr[cc][qq][cor] -> Draw("hist same");
90  lCorner -> AddEntry( hCor_RecTr[cc][qq][cor], CornName[cor].c_str(), "l" );
91  }
92  lCorner -> Draw();
93  cCor_RecTr -> SaveAs( ("Plots/MCOnly/cCor_RecTr"+CutNames[cc]+QuantNames[qq]+".pdf").c_str() );
94  cCor_RecTr -> SaveAs( ("Plots/MCOnly/cCor_RecTr"+CutNames[cc]+QuantNames[qq]+".png").c_str() );
95 
96  // ---- Muon Energy
97  TCanvas* cCor_MuoTr = new TCanvas( ("cCor_MuoTr"+CutNames[cc]+QuantNames[qq]).c_str(), "Muon Energy" );
98  cCor_MuoTr->cd();
99  for (int cor=0; cor<NumCorn; ++cor) {
100  if (cor==0) hCor_MuoTr[cc][qq][cor] -> Draw("hist ");
101  else hCor_MuoTr[cc][qq][cor] -> Draw("hist same");
102  }
103  lCorner -> Draw();
104  cCor_MuoTr -> SaveAs( ("Plots/MCOnly/cCor_MuoTr"+CutNames[cc]+QuantNames[qq]+".pdf").c_str() );
105  cCor_MuoTr -> SaveAs( ("Plots/MCOnly/cCor_MuoTr"+CutNames[cc]+QuantNames[qq]+".png").c_str() );
106 
107  // ---- Hadronic Energy
108  TCanvas* cCor_HadTr = new TCanvas( ("cCor_HadTr"+CutNames[cc]+QuantNames[qq]).c_str(), "Hadronic Energy" );
109  cCor_HadTr->cd();
110  for (int cor=0; cor<NumCorn; ++cor) {
111  if (cor==0) hCor_HadTr[cc][qq][cor] -> Draw("hist ");
112  else hCor_HadTr[cc][qq][cor] -> Draw("hist same");
113  }
114  lCorner -> Draw();
115  cCor_HadTr -> SaveAs( ("Plots/MCOnly/cCor_HadTr"+CutNames[cc]+QuantNames[qq]+".pdf").c_str() );
116  cCor_HadTr -> SaveAs( ("Plots/MCOnly/cCor_HadTr"+CutNames[cc]+QuantNames[qq]+".png").c_str() );
117 
118  // ---- Hadronic Energy Fraction
119  TCanvas* cCor_HFrTr = new TCanvas( ("cCor_HFrTr"+CutNames[cc]+QuantNames[qq]).c_str(), "Hadronic Energy Fraction" );
120  cCor_HFrTr->cd();
121  for (int cor=0; cor<NumCorn; ++cor) {
122  if (cor==0) hCor_HFrTr[cc][qq][cor] -> Draw("hist ");
123  else hCor_HFrTr[cc][qq][cor] -> Draw("hist same");
124  }
125  lCorner -> Draw();
126  cCor_HFrTr -> SaveAs( ("Plots/MCOnly/cCor_HFrTr"+CutNames[cc]+QuantNames[qq]+".pdf").c_str() );
127  cCor_HFrTr -> SaveAs( ("Plots/MCOnly/cCor_HFrTr"+CutNames[cc]+QuantNames[qq]+".png").c_str() );
128 
129  // ---- Reco - True / True
130  TCanvas* cCor_ReTr = new TCanvas( ("cCor_ReTr"+CutNames[cc]+QuantNames[qq]).c_str(), "Reco - True / True" );
131  cCor_ReTr->cd();
132  for (int cor=0; cor<NumCorn; ++cor) {
133  if (cor==0) hCor_ReTr[cc][qq][cor] -> Draw("hist ");
134  else hCor_ReTr[cc][qq][cor] -> Draw("hist same");
135  }
136  lCorner -> Draw();
137  cCor_ReTr -> SaveAs( ("Plots/MCOnly/cCor_ReTr"+CutNames[cc]+QuantNames[qq]+".pdf").c_str() );
138  cCor_ReTr -> SaveAs( ("Plots/MCOnly/cCor_ReTr"+CutNames[cc]+QuantNames[qq]+".png").c_str() );
139  }
140  }
141 
142 
143 
144 
145 } // PlotMCOnly
146 
147 //......................................................
148 TH1D* GetSpectToHist( TFile* MyF, std::string Path, int Col, std::string Axis ) {
149  std::cerr << "\tPath is " << Path << std::endl;
150  std::unique_ptr<Spectrum> TempSpec = Spectrum::LoadFrom(MyF, Path.c_str() ) ;
151  TH1D* MyHist = TempSpec -> ToTH1( kAna2017POT );
152  if ( !(Path.find("Cor_HFrTr") != std::string::npos) ) MyHist -> Rebin( 5 );
153  SetHistOptions( MyHist, 1.2*MyHist->GetMaximum(), Axis, 0, 1, false );
154  if ( (Path.find("Cor_HFrTr") != std::string::npos) ) MyHist -> GetXaxis() -> SetRangeUser( 0, 1 );
155  MyHist -> SetLineColor( Col );
156  return MyHist;
157 } // GetSpectToHist
158 
159 //......................................................
void SetHistOptions(TH1 *h, double max, std::string title, int ndiv, Color_t col, bool fill)
Set common options for a TLegend.
tree Draw("slc.nhit")
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void PlotMCOnly()
Definition: PlotMCOnly.C:27
const int Colours[4]
Definition: DoThePlots.C:193
TH2 * Rebin(TH2 *hist, std::vector< double > edges)
OStream cerr
Definition: OStream.cxx:7
const double kAna2017POT
Definition: Exposures.h:174
ntuple SetFillStyle(1001)
legend SetBorderSize(0)
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
correl_xv GetXaxis() -> SetDecimals()
leg AddEntry(GRdata,"data","p")
hmean SetLineColor(4)
const int NumQuant
Definition: DoThePlots.C:206
const std::string QuantNames[NumQuant]
Definition: DoThePlots.C:207
const std::string CornName[4]
Definition: DoThePlots.C:226
const int NumCut
Definition: DoThePlots.C:198
void cc()
Definition: test_ana.C:28
TH1D * GetSpectToHist(TFile *MyF, std::string Path, int Col, std::string Axis)
Definition: PlotMCOnly.C:148
cosmicTree SaveAs("cosmicTree.root")
std::vector< std::string > CutNames
Definition: MakeCutFlow.C:49
enum BeamMode string