efficiency.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"
12 #include "CAFAna/Systs/NumuSysts.h"
13 #include "CAFAna/Vars/NumuVars.h"
16 #include "CAFAna/Cuts/SpillCuts.h"
17 #include "CAFAna/Analysis/Calcs.h"
18 #include "CAFAna/Analysis/Plots.h"
19 #include "CAFAna/Analysis/Style.h"
20 #include "CAFAna/Vars/HistAxes.h"
21 
23 
24 #include "TCanvas.h"
25 #include "TFile.h"
26 #include "TGraph.h"
27 #include "TGraphAsymmErrors.h"
28 #include "TH1.h"
29 #include "TH2.h"
30 #include "TMath.h"
31 #include "TGaxis.h"
32 #include "TMultiGraph.h"
33 #include "TLegend.h"
34 #include "TLatex.h"
35 #include "TStyle.h"
36 #include "THStack.h"
37 #include "TPaveText.h"
38 #include "TList.h"
39 #include "TGaxis.h"
40 #include "TAttLine.h"
41 #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 
57 void efficiency()
58 {
59 
60  std::string fd_nonswap = "prod_caf_R17-03-01-prod3reco.l_fd_genie_nonswap_fhc_nova_v08_full_v1";
61 
64 
66 
69 
70 
71  //// ------ Now the cuts ------ /////
72 
73  const Cut kAny(// Any mode
74  [](const caf::SRProxy* sr)
75  {
76  return (sr->mc.nnu > 0);
77  });
78  const Cut kQE( // QE
79  [](const caf::SRProxy* sr)
80  {
81  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 0;
82  });
83  const Cut kRes( // Res
84  [](const caf::SRProxy* sr)
85  {
86  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 1;
87  });
88  const Cut kDIS( // DIS
89  [](const caf::SRProxy* sr)
90  {
91  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 2;
92  });
93  const Cut kCoh( // Coh
94  [](const caf::SRProxy* sr)
95  {
96  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 3;
97  });
98  const Cut kMEC( // MEC
99  [](const caf::SRProxy* sr)
100  {
101  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 10;
102  });
103 
104  const Cut kTruthContainFD( // only approx
105  [](const caf::SRProxy* sr)
106  {
107  return sr->mc.nnu > 0 && sr->mc.nu[0].E > 0 && sr->sel.contain.missE/sr->mc.nu[0].E < 0.01;
108  });
109 
110  struct Modes
111  {
113  Cut cut;
114  };
115 
116  const int kNumModes = 6;
117 
118  Modes modes[kNumModes] = {
119  {"All", kAny},
120  {"QE", kQE},
121  {"Res", kRes},
122  {"DIS", kDIS},
123  {"Coh", kCoh},
124  {"MEC", kMEC}
125  };
126 
127  struct Plot
128  {
131  Binning bins;
132  Var var;
133  };
134 
135  const int kNumPlots = 2;
136 
137  Plot plots[kNumPlots] = {
138  {";Reconstructed Neutrino Energy (GeV);Efficiency", "kCCE", kNumuCCEOptimisedBinning, kCCE},
139  {";True Neutrino Energy (GeV);Efficiency", "kTrueE", kNumuCCEOptimisedBinning, kTrueE}
140  };
141 
142  struct Selection
143  {
146  Cut cut;
147  };
148 
149  const int kNumCuts = 5;
150 
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 && kNumuContainFD2017},
158  {"+ PIDs","DQ_contain_NCRej", kBasicCut && kNumuQuality && kNumuContainFD2017 && kNumuPID2017},
159  {"+ Cosmic rej.","NumuFD", kBasicCut && kNumuQuality && kNumuContainFD2017 && kNumuPID2017 && kNumuCosmicRej2017}
160  };
161 
162  int colours[kNumCuts] = {kBlack, kBlue, kGreen+2, kOrange-3, 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, kPPFXFluxCVWgt * kXSecCVWgt2017 );
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(("eff/"+canvasName+".pdf").c_str());
233  c1->SaveAs(("eff/"+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
osc::OscCalculatorDumb calc
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Oscillation analysis framework, runs over CAF files outside of ART.
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
VectorProxy< SRNeutrinoProxy > nu
Definition: SRProxy.h:1890
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:553
std::string label
Definition: CutFlow_Data.C:28
std::string fname
Definition: getTimePeak.C:83
Optimized version of OscCalculatorPMNS.
Definition: StanTypedefs.h:28
const double pot
Definition: efficiency.C:53
const char * p
Definition: xmltok.h:285
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:17
virtual Spectrum PredictUnoscillated() const
Definition: IPrediction.cxx:82
var
void ResetOscCalcToDefault(osc::IOscCalculatorAdjustable *calc)
Reset calculator to default assumptions for all parameters.
Definition: Calcs.cxx:23
Proxy for StandardRecord.
Definition: SRProxy.h:2237
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:170
const char * label
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
====================================================================== ///
Definition: CutFlow_Data.C:27
Proxy< short int > nnu
Definition: SRProxy.h:1899
const Var kTrueE([](const caf::SRProxy *sr){return(sr->mc.nnu==0)?0.:float(sr->mc.nu[0].E);})
Definition: Vars.cxx:87
const Cut kNumuContainFD2017
Definition: NumuCuts2017.h:21
void efficiency()
Definition: efficiency.C:57
const int kNumPlots
Definition: GetSpectra.h:1
const Var kCCE
Definition: Vars.h:90
const double j
Definition: BetheBloch.cxx:29
const Cut kNumuPID2017([](const caf::SRProxy *sr){return(sr->sel.remid.pid > 0.5 &&sr->sel.cvn.numuid > 0.5);})
Definition: NumuCuts2017.h:27
const Cut kNumuCosmicRej2017([](const caf::SRProxy *sr){return(sr->sel.cosrej.anglekal > 0.5 && sr->sel.cosrej.numucontpid2020 > 0.5 && sr->slc.nhit< 400);})
Definition: NumuCuts2017.h:24
const SystShifts kNoShift
Definition: SystShifts.h:112
OStream cout
Definition: OStream.cxx:6
const std::vector< PlotDef > plots
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::string fname
Definition: CutFlow_Data.C:29
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
std::vector< Loaders * > loaders
Definition: syst_header.h:385
const Binning kNumuCCEOptimisedBinning
Optimised binning for numuCCE from L. Vinton. See docdb 16332. This was close to &#39;custC&#39; in that talk...
Definition: Binning.h:135
SRTruthBranchProxy mc
Definition: SRProxy.h:2253
c1
Definition: demo5.py:24
SRContainProxy contain
Definition: SRProxy.h:1706
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:28
Binning bins
Definition: CutFlow_Data.C:30
Prediction that just uses FD MC, with no extrapolation.
const Cut kNumuQuality
Definition: NumuCuts.h:17
const Var kXSecCVWgt2017
Definition: XsecTunes.h:38
Var var
Definition: CutFlow_Data.C:31
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
Proxy< float > missE
Definition: SRProxy.h:319
static constexpr Double_t sr
Definition: Munits.h:164
SRIDBranchProxy sel
Definition: SRProxy.h:2252