NDDataMCSystBandLoad.C
Go to the documentation of this file.
1 // Macro to plot ND Data/MC spectra with systematic error band
2 // To properly include NusFlatSysts (MC Stat, Norm, ND Cont),
3 // comment out the line in NusSysts.cxx, NusFlatSyst::Shift
4 // that only shifts the FD
5 
7 #include "CAFAna/Core/Spectrum.h"
8 #include "CAFAna/Cuts/Cuts.h"
9 #include "NuXAna/Cuts/NusCuts.h"
10 #include "CAFAna/Cuts/SpillCuts.h"
12 #include "NuXAna/Systs/NusSysts.h"
13 #include "CAFAna/Systs/Systs.h"
14 #include "CAFAna/Vars/HistAxes.h"
15 #include "NuXAna/Vars/HistAxes.h"
17 
18 #include "TFile.h"
19 
20 #include <iostream>
21 #include <string>
22 #include <vector>
23 
24 using namespace ana;
25 
27 {
28  TH1::AddDirectory(0);
29 
31  SpectrumLoader floadneardata(fnameneardata_concat);
32 
33  floadnear .SetSpillCut(kStandardSpillCuts);
34  floadneardata.SetSpillCut(kStandardSpillCuts);
35 
36  std::string labelHits = "Number of Hits";
37  Binning kHitBins = Binning::Simple(220, 0., 220.);
38  const HistAxis kAxisNHit(labelHits, kHitBins, kNHit);
39 
40  // Set up nominal spectra
41  Spectrum sMCCalE(floadnear, kNCAxis, kNusND, kNoShift, kTuftsWeightCC);
42  Spectrum sDtCalE(floadneardata, kNCAxis, kNusND);
43  CheatDecomp dcCalE(floadnear, kNCAxis, kNusND, kNoShift, kTuftsWeightCC);
44 
45  Spectrum sMCNHit(floadnear, kAxisNHit, kNusND, kNoShift, kTuftsWeightCC);
46  Spectrum sDtNHit(floadneardata, kAxisNHit, kNusND);
47  CheatDecomp dcNHit(floadnear, kAxisNHit, kNusND, kNoShift, kTuftsWeightCC);
48 
49  // Create vector of systematics
50  std::vector<const ISyst*> systs;
51  systs.push_back(&kNusOscParamSysts);
52  systs.push_back(&kNusNDBeamSysts);
53  systs.push_back(&kNusNDBirksSyst);
54  systs.push_back(&kNusNDCalibFlatSyst);
55  systs.push_back(&kNusNDCalibSlopeXSyst);
56  systs.push_back(&kNusNDCalibSlopeYSyst);
57  systs.push_back(&kNusNDGENIESmallSysts);
58  systs.push_back(&kNusNDNDRockSyst);
59  systs.push_back(&kNusNDNueCCSyst);
60  systs.push_back(&kNusNDNumuCCSyst);
61  systs.push_back(&kNusMCStatsSyst);
62  systs.push_back(&kNusNDContSyst);
63  systs.push_back(&kNusNormSyst);
64 
65  // Declare vectors for shifted spectra
66  std::vector<Spectrum> upsCalE, dnsCalE;
67  std::vector<Spectrum> upsNHit, dnsNHit;
68 
69  // These are important... without this the entire vector gets copied when
70  // resized and triggers an assertion in the Spectrum copy constructor
71  upsCalE.reserve(systs.size());
72  dnsCalE.reserve(systs.size());
73  upsNHit.reserve(systs.size());
74  dnsNHit.reserve(systs.size());
75 
76  // Set up the shifted spectra
77  for(const ISyst* syst:systs)
78  {
79  upsCalE.emplace_back(floadnear, kNCAxis, kNusND, SystShifts(syst, +1), kTuftsWeightCC);
80  dnsCalE.emplace_back(floadnear, kNCAxis, kNusND, SystShifts(syst, -1), kTuftsWeightCC);
81  upsNHit.emplace_back(floadnear, kAxisNHit, kNusND, SystShifts(syst, +1), kTuftsWeightCC);
82  dnsNHit.emplace_back(floadnear, kAxisNHit, kNusND, SystShifts(syst, -1), kTuftsWeightCC);
83  }
84 
85  floadnear.Go();
86  floadneardata.Go();
87 
88 
89  TFile* rootF = new TFile("NDDataMCSystBand.root", "RECREATE");
90 
91  TDirectory* tmp = gDirectory;
92  TDirectory* saveDir = gDirectory;
93 
94  // Save nominal spectra
95  saveDir = rootF->mkdir("sMCCalE");
96  sMCCalE.SaveTo(saveDir);
97  saveDir = rootF->mkdir("sDtCalE");
98  sDtCalE.SaveTo(saveDir);
99  saveDir = rootF->mkdir("dcCalE");
100  dcCalE.SaveTo(saveDir);
101  saveDir = rootF->mkdir("sMCNHit");
102  sMCNHit.SaveTo(saveDir);
103  saveDir = rootF->mkdir("sDtNHit");
104  sDtNHit.SaveTo(saveDir);
105  saveDir = rootF->mkdir("dcNHit");
106  dcNHit.SaveTo(saveDir);
107 
108  // Save shifted spectra
109  std::string specName = "";
110  for(unsigned int i = 0, n = systs.size(); i < n; ++i) {
111  specName = "sUpCalE" + systs[i]->ShortName();
112  saveDir = rootF->mkdir(specName.c_str());
113  upsCalE[i].SaveTo(saveDir);
114  specName = "sDnCalE" + systs[i]->ShortName();
115  saveDir = rootF->mkdir(specName.c_str());
116  dnsCalE[i].SaveTo(saveDir);
117 
118  specName = "sUpNHit" + systs[i]->ShortName();
119  saveDir = rootF->mkdir(specName.c_str());
120  upsNHit[i].SaveTo(saveDir);
121  specName = "sDnNHit" + systs[i]->ShortName();
122  saveDir = rootF->mkdir(specName.c_str());
123  dnsNHit[i].SaveTo(saveDir);
124  }
125 
126  rootF->Close();
127 }
void SaveTo(TDirectory *dir, const std::string &name) const override
Definition: CheatDecomp.cxx:47
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
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
const NusSystFromHist kNusNDBirksSyst(kNusAna01SystFile,"ND","NDBirks","Birks C")
Definition: NusSysts.h:81
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
const NusFlatSyst kNusNDContSyst("ndcont","ND Containment", 1.0, 0.6)
Definition: NusSysts.h:92
Float_t tmp
Definition: plot.C:36
void SetSpillCut(const SpillCut &cut)
const NusSystFromHist kNusNDCalibSlopeYSyst(kNusAna01SystFile,"ND","NDCalSlopeY","Sloped Miscalibration, Y")
Definition: NusSysts.h:84
Encapsulate code to systematically shift a caf::SRProxy.
Definition: ISyst.h:14
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const NusSystFromHist kNusNDNDRockSyst(kNusAna01SystFile,"ND","NDRock","ND Rock")
Definition: NusSysts.h:86
const NusSystFromHist kNusNDCalibSlopeXSyst(kNusAna01SystFile,"ND","NDCalSlopeX","Sloped Miscalibration, X")
Definition: NusSysts.h:83
const std::string fnamenear_concat
const std::string fnameneardata_concat
const Var kNHit
Definition: Vars.cxx:71
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
const HistAxis kNCAxis("Calorimetric Energy (GeV)", kNCDisappearanceEnergyBinning, kCaloE)
Axes used in Ana01 analysis by nus group.
Definition: HistAxes.h:8
const NusFlatSyst kNusMCStatsSyst("mcstat","MC Stats", 2.0, 4.8)
Definition: NusSysts.h:91
const SystShifts kNoShift
Definition: SystShifts.cxx:21
const NusSystFromHist kNusNDGENIESmallSysts(kNusAna01SystFile,"ND","NDGENIESm","Summed small GENIE Systs")
Definition: NusSysts.h:85
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Var kTuftsWeightCC
Definition: XsecTunes.h:31
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const NusFlatSyst kNusNormSyst("normNus","Normalization", 4.9, 4.9)
Definition: NusSysts.h:93
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
const NusSystFromHist kNusNDNumuCCSyst(kNusAna01SystFile,"ND","NDNumuCC","#nu_{#mu} CC Background")
Definition: NusSysts.h:88
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:114
Just return the ND truth spectra as the decomposition.
Definition: CheatDecomp.h:10
const Cut kNusND
Definition: NusCuts.h:71
const NusSystFromHist kNusNDBeamSysts(kNusAna01SystFile,"ND","NDBeam","All Beam")
Definition: NusSysts.h:80
const NusSystFromHist kNusNDCalibFlatSyst(kNusAna01SystFile,"ND","NDCalFlat","Flat Miscalibration")
Definition: NusSysts.h:82
void NDDataMCSystBandLoad()
const NusSystFromHist kNusNDNueCCSyst(kNusAna01SystFile,"ND","NDNueCC","#nu_{e} CC Background")
Definition: NusSysts.h:87