efficiencySA.C
Go to the documentation of this file.
1 // Fills spectra for systematic error band
2 
3 #include "CAFAna/Cuts/Cuts.h"
5 #include "CAFAna/Core/Binning.h"
6 #include "CAFAna/Core/Loaders.h"
7 #include "CAFAna/Core/Spectrum.h"
8 #include "CAFAna/Core/Var.h"
11 #include "CAFAna/Systs/Systs.h"
15 #include "CAFAna/Cuts/SpillCuts.h"
16 #include "CAFAna/Analysis/Calcs.h"
17 #include "CAFAna/Analysis/Plots.h"
18 #include "CAFAna/Analysis/Style.h"
19 #include "CAFAna/Vars/HistAxes.h"
20 
21 #include "OscLib/OscCalcPMNSOpt.h"
22 
23 #include "TCanvas.h"
24 #include "TFile.h"
25 #include "TGraph.h"
26 #include "TGraphAsymmErrors.h"
27 #include "TH1.h"
28 #include "TH2.h"
29 #include "TMath.h"
30 #include "TGaxis.h"
31 #include "TMultiGraph.h"
32 #include "TLegend.h"
33 #include "TLatex.h"
34 #include "TStyle.h"
35 #include "THStack.h"
36 #include "TPaveText.h"
37 #include "TList.h"
38 #include "TGaxis.h"
39 #include "TAttLine.h"
40 #include "TAttMarker.h"
42 
43 #include <cmath>
44 #include <iostream>
45 #include <vector>
46 #include <list>
47 #include <sstream>
48 #include <string>
49 #include <sstream>
50 #include <fstream>
51 #include <iomanip>
52 
53 const double pot = 6e20;
54 
55 using namespace ana;
56 
58 {
59 
60  std::string fd_nonswap = "bzamoran_prod_caf_R16-03-03-prod2reco.f_fd_genie_nonswap_fhc_nova_v08_epoch1-3c_v1_prod2-snapshot_2pc";
61 
64 
66 
69 
70  const Binning kEnergyBinning = Binning::Simple(20,0,5);
71 
72  //// ------ Now the cuts ------ /////
73 
74  const Cut kAny({"mc.nnu"}, // Any mode
75  [](const caf::StandardRecord* sr)
76  {
77  return (sr->mc.nnu > 0);
78  });
79  const Cut kQE({"mc.nnu", "mc.nu.*"}, // QE
80  [](const caf::StandardRecord* sr)
81  {
82  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 0;
83  });
84  const Cut kRes({"mc.nnu", "mc.nu.*"}, // Res
85  [](const caf::StandardRecord* sr)
86  {
87  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 1;
88  });
89  const Cut kDIS({"mc.nnu", "mc.nu.*"}, // DIS
90  [](const caf::StandardRecord* sr)
91  {
92  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 2;
93  });
94  const Cut kCoh({"mc.nnu", "mc.nu.*"}, // Coh
95  [](const caf::StandardRecord* sr)
96  {
97  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 3;
98  });
99  const Cut kMEC({"mc.nnu", "mc.nu.*"}, // MEC
100  [](const caf::StandardRecord* sr)
101  {
102  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 10;
103  });
104 
105  const Cut kTruthContainFD({"mc.nnu","mc.nu.*","sel.contain.missE"}, // only approx
106  [](const caf::StandardRecord* sr)
107  {
108  return sr->mc.nnu > 0 && sr->mc.nu[0].E > 0 && sr->sel.contain.missE / sr->mc.nu[0].E < 0.01;
109  });
110 
111  struct Modes
112  {
114  Cut cut;
115  };
116 
117  const int kNumModes = 6;
118 
119  Modes modes[kNumModes] = {
120  {"All", kAny},
121  {"QE", kQE},
122  {"Res", kRes},
123  {"DIS", kDIS},
124  {"Coh", kCoh},
125  {"MEC", kMEC}
126  };
127 
128  struct Plot
129  {
132  Binning bins;
133  Var var;
134  };
135 
136  const int kNumPlots = 2;
137 
138  Plot plots[kNumPlots] = {
139  {";Reconstructed Neutrino Energy (GeV);Efficiency", "kCCE", kEnergyBinning, kCCE},
140  {";True Neutrino Energy (GeV);Efficiency", "kTrueE", kEnergyBinning, kTrueE}
141  };
142 
143  struct Selection
144  {
147  Cut cut;
148  };
149 
150  const int kNumCuts = 5;
151 
152  const Cut kBasicCut = kIsNumuCC && kTruthContainFD;
153 
154  Selection cuts[kNumCuts] = {
155  {"No cuts","NoCut", kBasicCut},
156  {"Data quality","DQ", kBasicCut && kNumuQuality},
157  {"+ containment","DQ_contain", kBasicCut && kNumuQuality && kNumuContainFD},
158  {"+ PID","DQ_contain_NCRej", kBasicCut && kNumuQuality && kNumuContainFD && kNumuNCRej},
159  {"+ cosmic rej.","NumuFD", kBasicCut &&kNumuQuality && kNumuContainFD && kNumuNCRej && kNumuCosmicRej}
160  };
161 
162  int colours[kNumCuts] = {kBlack, kBlue, kGreen+2, kOrange-2, kRed};
163 
164  PredictionNoExtrap* sSpect[kNumPlots][kNumCuts][kNumModes];
165 
166  for(int k = 0; k < kNumModes; k++)
167  {
168  Cut mode = modes[k].cut;
169 
170  for(int i = 0; i < kNumPlots; i++)
171  {
172  Plot p = plots[i];
173 
174  for(int j = 0; j < kNumCuts; j++)
175  {
176  Cut cut = cuts[j].cut;
177 
178  sSpect[i][j][k] = new PredictionNoExtrap(loaders, p.label, p.bins, p.var, cut && mode, kNoShift, kTuftsWeightCC );
179  } // loop over cuts
180  } // loop over plots
181  } // loop over modes
182 
183  loaders.Go();
184 
185  TH1* hHist[kNumPlots][kNumCuts][kNumModes];
186 
187  for(int k = 0; k < kNumModes; k++)
188  {
189  for(int i = 0; i < kNumPlots; i++)
190  {
191  for(int j = 0; j < kNumCuts; j++)
192  {
193  std::string histName = plots[i].fname+"_"+cuts[j].fname;
194 
195  // hHist[i][j][k] = sSpect[i][j][k]->Predict(&calc).ToTH1(pot);
196  hHist[i][j][k] = sSpect[i][j][k]->PredictUnoscillated().ToTH1(pot);
197  hHist[i][j][k]->SetName(histName.c_str());
198 
199  hHist[i][j][k]->SetMarkerColor(colours[j]);
200  hHist[i][j][k]->SetLineColor(colours[j]);
201  } // end loop over cuts
202  } // end loop over plots
203  } // end loop over modes
204 
205  for(int k = 0; k < kNumModes; k++)
206  {
207  for(int i = 0; i < kNumPlots; i++)
208  {
209  std::string canvasName = plots[i].fname+"_"+modes[k].fname;
210  TCanvas* c1 = new TCanvas("",canvasName.c_str());
211 
212  TLegend* leg = new TLegend(0.65,0.18,0.85,0.40);
213  leg->SetFillColor(10);
214  leg->SetLineWidth(0);
215  leg->SetLineColor(10);
216 
217  for (int j = 1; j < kNumCuts; j++)
218  {
219  hHist[i][j][k]->Divide(hHist[i][0][k]);
220 
221  std::cout << modes[k].fname.c_str() << " "
222  << plots[i].fname.c_str() << " "
223  << cuts[j].fname.c_str() << " : "
224  << hHist[i][j][k]->Integral() << std::endl;
225 
226  if(j == 1) hHist[i][j][k]->Draw("hist");
227  else hHist[i][j][k]->Draw("hist same");
228  leg->AddEntry(hHist[i][j][k], cuts[j].label.c_str(), "l");
229  } // loop over cuts
230 
231  leg->Draw();
232  c1->SaveAs(("effSA/"+canvasName+".pdf").c_str());
233  c1->SaveAs(("effSA/"+canvasName+".root").c_str());
234  } // loop over plots
235  } // loop over modes
236 
237 }
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
Far Detector at Ash River.
Definition: SREnums.h:11
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
void ResetOscCalcToDefault(osc::IOscCalcAdjustable *calc)
Reset calculator to default assumptions for all parameters.
Definition: Calcs.cxx:23
float missE
sum of energy of particles that leave detector. example cut: missE/trueE > 0.01 is truly uncontained ...
Definition: SRContain.h:21
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:209
std::string label
Definition: CutFlow_Data.C:29
std::string fname
Definition: getTimePeak.C:84
const char * p
Definition: xmltok.h:285
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
virtual Spectrum PredictUnoscillated() const
Definition: IPrediction.cxx:56
const Cut kNumuCosmicRej([](const caf::SRProxy *sr){return(sr->sel.cosrej.anglekal > 0.5 && sr->sel.cosrej.numucontpid2019 > 0.535 && sr->slc.nhit< 400);})
Definition: NumuCuts.h:32
const Cut kNumuContainFD([](const caf::SRProxy *sr){ std::pair< int, int > planes=calcFirstLastLivePlane(sr->slc.firstplane, std::bitset< 14 >(sr->hdr.dibmask));int planestofront=sr->slc.firstplane-planes.first;int planestoback=planes.second-sr->slc.lastplane;return( sr->slc.ncellsfromedge > 1 &&planestofront > 1 &&planestoback > 1 &&sr->sel.contain.kalfwdcell > 10 &&sr->sel.contain.kalbakcell > 10 &&sr->sel.contain.cosfwdcell > 0 &&sr->sel.contain.cosbakcell > 0);})
Definition: NumuCuts.h:20
osc::OscCalcDumb calc
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:162
const char * label
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
====================================================================== ///
Definition: CutFlow_Data.C:28
void efficiencySA()
Definition: efficiencySA.C:57
const Var kTrueE([](const caf::SRProxy *sr){return(sr->mc.nnu==0)?0.:float(sr->mc.nu[0].E);})
Definition: Vars.cxx:85
const double pot
Definition: efficiencySA.C:53
const int kNumPlots
Definition: GetSpectra.h:1
const std::vector< Plot > plots
Optimized version of OscCalcPMNS.
Definition: StanTypedefs.h:31
const Var kCCE
Definition: NumuVars.h:21
const Binning kEnergyBinning
caf::StandardRecord * sr
const double j
Definition: BetheBloch.cxx:29
const Cut kNumuNCRej([](const caf::SRProxy *sr){return(sr->sel.remid.pid >0.75);})
Definition: NumuCuts.h:24
short nnu
Number of neutrinos in nu vector (0 or 1)
Definition: SRTruthBranch.h:37
const SystShifts kNoShift
Definition: SystShifts.h:115
OStream cout
Definition: OStream.cxx:6
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::string fname
Definition: CutFlow_Data.C:30
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
The StandardRecord is the primary top-level object in the Common Analysis File trees.
const Cut cut
Definition: exporter_fd.C:30
const Var kTuftsWeightCC
Definition: XsecTunes.h:31
std::vector< Loaders * > loaders
Definition: syst_header.h:386
SRIDBranch sel
Selector (PID) branch.
c1
Definition: demo5.py:24
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:46
Binning bins
Definition: CutFlow_Data.C:31
Prediction that just uses FD MC, with no extrapolation.
const Cut kNumuQuality
Definition: NumuCuts.h:18
Var var
Definition: CutFlow_Data.C:32
void SetLoaderPath(const std::string &path, caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Configure loader via wildcard path.
Definition: Loaders.cxx:25
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:114
SRContain contain
Output from SRContain (containment related variables)
Definition: SRIDBranch.h:51
std::vector< SRNeutrino > nu
implemented as a vector to maintain mc.nu structure, i.e. not a pointer, but with 0 or 1 entries...
Definition: SRTruthBranch.h:25