test_beam_errorband.C
Go to the documentation of this file.
1 /*
2 Gets ND Data/MC LEM spectra including the Flux Uncertainty error band
3 (AllBeam = combined Beam Transport and NA49 systematics)
4 Uses the color scheme favored by the nue group (Style.h)
5 */
6 
8 #include "CAFAna/Core/Binning.h"
9 #include "CAFAna/Cuts/Cuts.h"
10 #include "CAFAna/Cuts/NueCutsFirstAna.h"
11 #include "CAFAna/Core/Spectrum.h"
14 #include "CAFAna/Vars/Vars.h"
15 #include "CAFAna/Analysis/Style.h"
16 #include "CAFAna/Systs/Systs.h"
17 
18 #include "TCanvas.h"
19 #include "TH1.h"
20 #include "TFile.h"
21 #include "TLegend.h"
22 #include "TLine.h"
23 #include "TLatex.h"
24 
25 using namespace ana;
26 
27 // Just in case, copied from rootlogon.C
28 // Put a "NOvA Preliminary" tag in the corner
30 {
31  TLatex* prelim = new TLatex(.9, .95, "NO#nuA Preliminary");
32  prelim->SetTextColor(kBlue);
33  prelim->SetNDC();
34  prelim->SetTextSize(2/30.);
35  prelim->SetTextAlign(32);
36  prelim->Draw();
37 }
38 
40 
41  //Set +- 1 sigma AllBeam systematic shift
42  SystShifts beamPlus(&kBeamAll, 1.);
43  SystShifts beamMinus(&kBeamAll, -1);
44 
45  //Specify which files to load
46  SpectrumLoader loaderNDData("/pnfs/nova/persistent/production/concat/R16-03-03-prod2reco.d/prod_decaf_R16-03-03-prod2reco.d_nd_numi_fhc_full_nue_contain_v1_goodruns.root");
47  SpectrumLoader loaderNDMC("/pnfs/nova/persistent/production/concat/R16-03-03-prod2reco.d/prod_decaf_R16-03-03-prod2reco.d_nd_genie_nonswap_genierw_fhc_nova_v08_full_nue_contain_v1/prod_decaf_R16-03-03-prod2reco.d_nd_genie_nonswap_genierw_fhc_nova_v08_full_nue_contain_v1_1_of_10.root");
48 
49  //Define spectra to fill.
50  //For MC with flux uncertainty define the triplet Nominal, Plus/Minus shift
51 
52  const Binning binsLEM = Binning::Simple(28,-0.2,1.2);
53 
54  Spectrum spLEM_data
55  ("LEM", binsLEM, loaderNDData,kLEM, kNueNDFirstAnaPresel);
56  Spectrum spLEM_MC_nom
57  ("LEM", binsLEM, loaderNDMC,kLEM, kNueNDFirstAnaPresel);
58  Spectrum spLEM_MC_plus
59  ("LEM", binsLEM, loaderNDMC,kLEM, kNueNDFirstAnaPresel,beamPlus);
60  Spectrum spLEM_MC_minus
61  ("LEM", binsLEM, loaderNDMC,kLEM, kNueNDFirstAnaPresel,beamMinus);
62 
63  //Add decomposition to get NC/CC/beam and test the color scheme
64  CheatDecomp decoLEM
65  (loaderNDMC, "LEM", binsLEM, kLEM, kNueNDFirstAnaPresel);
66 
67  //Go!
68  loaderNDMC.Go();
69  loaderNDData.Go();
70 
71  //Open output file and save all
72  TFile * file = new TFile("spectra_NDAllBeamLEM_test.root","recreate");
73 
74  spLEM_data.SaveTo(file, "LEM_data");
75  spLEM_MC_nom.SaveTo(file, "LEM_MC_nom");
76  spLEM_MC_plus.SaveTo(file, "LEM_MC_plus");
77  spLEM_MC_minus.SaveTo(file, "LEM_MC_minus");
78  decoLEM.SaveTo(file, "deco_LEM_MC");
79 
80  std::cout << "\nOutput saved to " << file->GetName() << std::endl ;
81  //file->Close();
82  //return;
83 
84  //*****************************************************************//
85  //Split here if you only want to save the spectra
86  //(uncomment 2 lines above)
87  //*****************************************************************//
88 
89  //Get Histograms from Spectra, normalized to Data; format and plot
90  double thePOT = spLEM_data.POT();
91 
92  auto hdata = spLEM_data.ToTH1(thePOT);
93  auto hplus = spLEM_MC_plus.ToTH1(thePOT);
94  auto hminus = spLEM_MC_minus.ToTH1(thePOT);
95  auto hnom = spLEM_MC_nom.ToTH1(thePOT);
96  auto hNC = decoLEM.NCTotalComponent().ToTH1(thePOT);
97  auto hCC = (decoLEM.NumuComponent()
98  +decoLEM.AntiNumuComponent()).ToTH1(thePOT);
99  auto hBeam = (decoLEM.NueComponent()
100  +decoLEM.AntiNueComponent() ).ToTH1(thePOT);
101 
102 
103  hdata ->SetMarkerStyle(kFullCircle);
104  hnom ->SetLineColor(kTotalMCColor);
105 
106  hplus ->SetFillColor(kTotalMCErrorBandColor);
107  hminus->SetFillColor(10);
108  hplus ->SetLineColor(kTotalMCErrorBandColor);
109  hminus->SetLineColor(kTotalMCErrorBandColor);
110 
111  hNC ->SetLineColor(kNCBackgroundColor);
112  hCC ->SetLineColor(kNumuBackgroundColor);
113  hBeam ->SetLineColor(kBeamNueBackgroundColor);
114 
115  TCanvas *c2 =new TCanvas("c2","c2",500,500);
116 
117  hplus->GetXaxis()->CenterTitle();
118  hplus->GetYaxis()->CenterTitle();
119 
120  hplus->GetXaxis()->SetRangeUser(-0.05,1.05);
121  hplus ->DrawCopy("hist");
122  hminus->Draw("hist same ");
123  hNC ->Draw("hist same ][");
124  hCC ->Draw("hist same ][");
125  hBeam ->Draw("hist same ][");
126  hnom ->Draw("hist same ");
127  hdata ->Draw("same");
128 
129  c2->SetLogy();
130 
131  //White histogram messes with the axes; force to fix
132  c2->RedrawAxis();
133 
134 
135  TLegend * leg = new TLegend(0.5,0.6,0.8,0.85);;
136  leg->AddEntry(hdata,"ND Data","pl");
137  leg->AddEntry(hNC,"MC NC background","l");
138  leg->AddEntry(hCC,"MC #nu_{#mu} background","l");
139  leg->AddEntry(hBeam,"MC Beam #nu_{e}","l");
140  leg->AddEntry(hnom,"Total MC","l");
141  leg->AddEntry(hplus,"Flux uncertainty","f");
142  leg->Draw("same");
143 
144  Preliminary(); //from rootlogon.C
145 
146  c2->Print(("nd_plot_LEM_test.png"),"png");
147  file->cd();
148  c2->Write(("Plot_LEM_test"));
149  file->Close();
150 
151 }
void SaveTo(TDirectory *dir, const std::string &name) const override
Definition: CheatDecomp.cxx:47
const Var kLEM
PID
Definition: Vars.cxx:26
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
Spectrum NCTotalComponent() const override
Definition: CheatDecomp.h:27
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:148
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
void Preliminary()
TH1F * hplus
Definition: Xsec_final.C:75
void test_beam_errorband()
const Color_t kTotalMCErrorBandColor
Definition: Style.h:17
const Color_t kNumuBackgroundColor
Definition: Style.h:30
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
c2
Definition: demo5.py:33
Spectrum NueComponent() const override
Definition: CheatDecomp.h:32
Spectrum AntiNumuComponent() const override
Definition: CheatDecomp.h:33
const Color_t kBeamNueBackgroundColor
Definition: Style.h:24
static const BeamSyst & kBeamAll
Definition: BeamSysts.h:133
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
Spectrum NumuComponent() const override
Definition: CheatDecomp.h:31
TLatex * prelim
Definition: Xsec_final.C:133
double POT() const
Definition: Spectrum.h:227
OStream cout
Definition: OStream.cxx:6
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
TH1F * hminus
Definition: Xsec_final.C:76
TFile * file
Definition: cellShifts.C:17
const Color_t kTotalMCColor
Definition: Style.h:16
const Color_t kNCBackgroundColor
Definition: Style.h:22
enum BeamMode kBlue
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
Just return the ND truth spectra as the decomposition.
Definition: CheatDecomp.h:10
Spectrum AntiNueComponent() const override
Definition: CheatDecomp.h:34