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"
17 #include "CAFAna/Cuts/SpillCuts.h"
18 #include "CAFAna/Analysis/Calcs.h"
19 #include "CAFAna/Analysis/Plots.h"
20 #include "CAFAna/Analysis/Style.h"
21 #include "CAFAna/Vars/HistAxes.h"
22 
23 #include "OscLib/OscCalcPMNSOpt.h"
24 
25 #include "TCanvas.h"
26 #include "TFile.h"
27 #include "TGraph.h"
28 #include "TGraphAsymmErrors.h"
29 #include "TH1.h"
30 #include "TH2.h"
31 #include "TMath.h"
32 #include "TGaxis.h"
33 #include "TMultiGraph.h"
34 #include "TLegend.h"
35 #include "TLatex.h"
36 #include "TStyle.h"
37 #include "THStack.h"
38 #include "TPaveText.h"
39 #include "TList.h"
40 #include "TGaxis.h"
41 #include "TAttLine.h"
42 #include "TAttMarker.h"
43 
44 #include <cmath>
45 #include <iostream>
46 #include <vector>
47 #include <list>
48 #include <sstream>
49 #include <string>
50 #include <sstream>
51 #include <fstream>
52 #include <iomanip>
53 
54 const double pot = 6e20;
55 
56 using namespace ana;
57 
58 void efficiency()
59 {
60 
61  std::string fd_nonswap = "prod_caf_R17-03-01-prod3reco.l_fd_genie_nonswap_fhc_nova_v08_full_v1";
62 
65 
67 
70 
71 
72  //// ------ Now the cuts ------ /////
73 
74  const Cut kAny(// Any mode
75  [](const caf::SRProxy* sr)
76  {
77  return (sr->mc.nnu > 0);
78  });
79  const Cut kQE( // QE
80  [](const caf::SRProxy* sr)
81  {
82  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 0;
83  });
84  const Cut kRes( // Res
85  [](const caf::SRProxy* sr)
86  {
87  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 1;
88  });
89  const Cut kDIS( // DIS
90  [](const caf::SRProxy* sr)
91  {
92  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 2;
93  });
94  const Cut kCoh( // Coh
95  [](const caf::SRProxy* sr)
96  {
97  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 3;
98  });
99  const Cut kMEC( // MEC
100  [](const caf::SRProxy* sr)
101  {
102  return sr->mc.nnu > 0 && sr->mc.nu[0].mode == 10;
103  });
104 
105  const Cut kTruthContainFD( // only approx
106  [](const caf::SRProxy* 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", kNumuCCEOptimisedBinning, kCCE},
140  {";True Neutrino Energy (GeV);Efficiency", "kTrueE", kNumuCCEOptimisedBinning, kTrueE}
141  };
142 
143  struct Selection
144  {
147  Cut cut;
148  };
149 
150  const int kNumCuts = 5;
151 
152 
153  const Cut kBasicCut = kIsNumuCC && kTruthContainFD;
154 
155  Selection cuts[kNumCuts] = {
156  {"No cuts","NoCut", kBasicCut},
157  {"Data quality","DQ", kBasicCut && kNumuQuality},
158  {"+ containment","DQ_contain", kBasicCut && kNumuQuality && kNumuContainFD2017},
159  {"+ PIDs","DQ_contain_NCRej", kBasicCut && kNumuQuality && kNumuContainFD2017 && kNumuPID2017},
160  {"+ Cosmic rej.","NumuFD", kBasicCut && kNumuQuality && kNumuContainFD2017 && kNumuPID2017 && kNumuCosmicRej2017}
161  };
162 
163  int colours[kNumCuts] = {kBlack, kBlue, kGreen+2, kOrange-3, kRed};
164 
165  PredictionNoExtrap* sSpect[kNumPlots][kNumCuts][kNumModes];
166 
167  for(int k = 0; k < kNumModes; k++)
168  {
169  Cut mode = modes[k].cut;
170 
171  for(int i = 0; i < kNumPlots; i++)
172  {
173  Plot p = plots[i];
174 
175  for(int j = 0; j < kNumCuts; j++)
176  {
177  Cut cut = cuts[j].cut;
178 
179  sSpect[i][j][k] = new PredictionNoExtrap(loaders, p.label, p.bins, p.var, cut && mode, kNoShift, kPPFXFluxCVWgt * kXSecCVWgt2017 );
180  } // loop over cuts
181  } // loop over plots
182  } // loop over modes
183 
184  loaders.Go();
185 
186  TH1* hHist[kNumPlots][kNumCuts][kNumModes];
187 
188  for(int k = 0; k < kNumModes; k++)
189  {
190  for(int i = 0; i < kNumPlots; i++)
191  {
192  for(int j = 0; j < kNumCuts; j++)
193  {
194  std::string histName = plots[i].fname+"_"+cuts[j].fname;
195 
196  // hHist[i][j][k] = sSpect[i][j][k]->Predict(&calc).ToTH1(pot);
197  hHist[i][j][k] = sSpect[i][j][k]->PredictUnoscillated().ToTH1(pot);
198  hHist[i][j][k]->SetName(histName.c_str());
199 
200  hHist[i][j][k]->SetMarkerColor(colours[j]);
201  hHist[i][j][k]->SetLineColor(colours[j]);
202  } // end loop over cuts
203  } // end loop over plots
204  } // end loop over modes
205 
206  for(int k = 0; k < kNumModes; k++)
207  {
208  for(int i = 0; i < kNumPlots; i++)
209  {
210  std::string canvasName = plots[i].fname+"_"+modes[k].fname;
211  TCanvas* c1 = new TCanvas("",canvasName.c_str());
212 
213  TLegend* leg = new TLegend(0.65,0.18,0.85,0.40);
214  leg->SetFillColor(10);
215  leg->SetLineWidth(0);
216  leg->SetLineColor(10);
217 
218  for (int j = 1; j < kNumCuts; j++)
219  {
220  hHist[i][j][k]->Divide(hHist[i][0][k]);
221 
222  std::cout << modes[k].fname.c_str() << " "
223  << plots[i].fname.c_str() << " "
224  << cuts[j].fname.c_str() << " : "
225  << hHist[i][j][k]->Integral() << std::endl;
226 
227  if(j == 1) hHist[i][j][k]->Draw("hist");
228  else hHist[i][j][k]->Draw("hist same");
229  leg->AddEntry(hHist[i][j][k], cuts[j].label.c_str(), "l");
230  } // loop over cuts
231 
232  leg->Draw();
233  c1->SaveAs(("eff/"+canvasName+".pdf").c_str());
234  c1->SaveAs(("eff/"+canvasName+".root").c_str());
235  } // loop over plots
236  } // loop over modes
237 
238 }
enum BeamMode kOrange
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
enum BeamMode kRed
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
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
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
std::string label
Definition: CutFlow_Data.C:29
std::string fname
Definition: getTimePeak.C:84
const double pot
Definition: efficiency.C:54
caf::Proxy< caf::SRContain > contain
Definition: SRProxy.h:1250
const char * p
Definition: xmltok.h:285
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2125
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:617
virtual Spectrum PredictUnoscillated() const
Definition: IPrediction.cxx:33
caf::Proxy< short int > nnu
Definition: SRProxy.h:616
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
const Var kTrueE([](const caf::SRProxy *sr){assert(sr->mc.nnu==1);return sr->mc.nu[0].E;})
Definition: Vars.cxx:85
====================================================================== ///
Definition: CutFlow_Data.C:28
const Cut kNumuContainFD2017
Definition: NumuCuts2017.h:21
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
caf::StandardRecord * sr
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.cxx:21
OStream cout
Definition: OStream.cxx:6
caf::Proxy< float > missE
Definition: SRProxy.h:826
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2137
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::string fname
Definition: CutFlow_Data.C:30
const Cut cut
Definition: exporter_fd.C:30
std::vector< Loaders * > loaders
Definition: syst_header.h:386
const Binning kNumuCCEOptimisedBinning
Optimised binning for numuCCE from L. Vinton. See docdb 16332. This was close to &#39;custC&#39; in that talk...
Definition: Binnings.cxx:28
c1
Definition: demo5.py:24
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
Binning bins
Definition: CutFlow_Data.C:31
Prediction that just uses FD MC, with no extrapolation.
caf::Proxy< caf::SRIDBranch > sel
Definition: SRProxy.h:2140
const Cut kNumuQuality
Definition: NumuCuts.h:18
const Var kXSecCVWgt2017
Definition: XsecTunes.h:37
Var var
Definition: CutFlow_Data.C:32
enum BeamMode kGreen
enum BeamMode kBlue
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
void efficiency()
Definition: efficiency.C:58
enum BeamMode string