FidOpt.C
Go to the documentation of this file.
1 #include "CAFAna/Core/Binning.h"
2 #include "CAFAna/Cuts/Cuts.h"
3 #include "CAFAna/Vars/FitVars.h"
7 #include "CAFAna/Core/Spectrum.h"
10 #include "CAFAna/Vars/Vars.h"
11 
13 
14 #include "TCanvas.h"
15 #include "TH2.h"
16 #include "TStyle.h"
17 #include "TArrow.h"
18 #include "TH1.h"
19 #include "TH3.h"
20 #include "TFile.h"
21 #include "TLegend.h"
22 #include "TGraph.h"
23 #include <cmath>
24 #include <cassert>
25 #include <memory>
26 #include "TProfile.h"
27 #include <fstream>
28 #include <sstream>
29 #include <iostream>
30 #include <iomanip>
31 #include <stdarg.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 
36 using namespace ana;
37 
38 void FidOpt()
39 {
40  const std::string Full_MC = "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.d_nd_genie_nonswap_fhc_nova_v08_full_v1";
41 
42  //Pass the desired file to the spectrum loader.
43  SpectrumLoader loader(Full_MC);
44 
45  const Binning fidxy = Binning::Simple(100,-200,200);
46  const Binning fidz = Binning::Simple(100,0,1200);
47 
48  const Cut kSignal = Signal && kVtx && k1Prong && kremid;
49  const Cut kBkg = Bkg && kVtx && k1Prong && kremid;
50  const Cut kNCBkg = NCBkg && kVtx && k1Prong && kremid;
51  const Cut kCCPi0Bkg = CCPi0Bkg && kVtx && k1Prong && kremid;
52  const Cut kCCNonPi0Bkg = CCNonPi0Bkg && kVtx && k1Prong && kremid;
53 
54  //Define spectra for vertex in X view.
55  Spectrum sigfidx("Vertex in X",fidxy,loader,kVertx,kSignal);
56  Spectrum bkgfidx("Vertex in X",fidxy,loader,kVertx,kBkg);
57  Spectrum ncbkgfidx("Vertex in X",fidxy,loader,kVertx,kNCBkg);
58  Spectrum ccpi0bkgfidx("Vertex in X",fidxy,loader,kVertx,kCCPi0Bkg);
59  Spectrum ccnonpi0bkgfidx("Vertex in X",fidxy,loader,kVertx,kCCNonPi0Bkg);
60 
61  //Define spectra for vertex in Y view.
62  Spectrum sigfidy("Vertex in Y",fidxy,loader,kVerty,kSignal);
63  Spectrum bkgfidy("Vertex in Y",fidxy,loader,kVerty,kBkg);
64  Spectrum ncbkgfidy("Vertex in Y",fidxy,loader,kVerty,kNCBkg);
65  Spectrum ccpi0bkgfidy("Vertex in Y",fidxy,loader,kVerty,kCCPi0Bkg);
66  Spectrum ccnonpi0bkgfidy("Vertex in Y",fidxy,loader,kVerty,kCCNonPi0Bkg);
67 
68  //Define spectra for vertex in Z view.
69  Spectrum sigfidz("Vertex in Z",fidz,loader,kVertz,kSignal);
70  Spectrum bkgfidz("Vertex in Z",fidz,loader,kVertz,kBkg);
71  Spectrum ncbkgfidz("Vertex in Z",fidz,loader,kVertz,kNCBkg);
72  Spectrum ccpi0bkgfidz("Vertex in Z",fidz,loader,kVertz,kCCPi0Bkg);
73  Spectrum ccnonpi0bkgfidz("Vertex in Z",fidz,loader,kVertz,kCCNonPi0Bkg);
74 
75  //Define spectra for shower stop X view.
76  Spectrum sigshwx("Shower in X",fidxy,loader,kShwx,kSignal);
77  Spectrum bkgshwx("Shower in X",fidxy,loader,kShwx,kBkg);
78  Spectrum ncbkgshwx("Shower in X",fidxy,loader,kShwx,kNCBkg);
79  Spectrum ccpi0bkgshwx("Shower in X",fidxy,loader,kShwx,kCCPi0Bkg);
80  Spectrum ccnonpi0bkgshwx("Shower in X",fidxy,loader,kShwx,kCCNonPi0Bkg);
81 
82  //Define spectra for shower stop Y view.
83  Spectrum sigshwy("Shower in Y",fidxy,loader,kShwy,kSignal);
84  Spectrum bkgshwy("Shower in Y",fidxy,loader,kShwy,kBkg);
85  Spectrum ncbkgshwy("Shower in Y",fidxy,loader,kShwy,kNCBkg);
86  Spectrum ccpi0bkgshwy("Shower in Y",fidxy,loader,kShwy,kCCPi0Bkg);
87  Spectrum ccnonpi0bkgshwy("Shower in Y",fidxy,loader,kShwy,kCCNonPi0Bkg);
88 
89  //Define spectra for shower stop Z view.
90  Spectrum sigshwz("Shower in Z",fidz,loader,kShwz,kSignal);
91  Spectrum bkgshwz("Shower in Z",fidz,loader,kShwz,kBkg);
92  Spectrum ncbkgshwz("Shower in Z",fidz,loader,kShwz,kNCBkg);
93  Spectrum ccpi0bkgshwz("Shower in Z",fidz,loader,kShwz,kCCPi0Bkg);
94  Spectrum ccnonpi0bkgshwz("Shower in Z",fidz,loader,kShwz,kCCNonPi0Bkg);
95 
96  //Load the spectra from the dataset.
97  loader.Go();
98 
99  //Create root file and fill it with each spectrum.
100  TFile *fvolumes = new TFile("volumeoptimizationnocuts.root","RECREATE");
101  sigfidx.SaveTo(fvolumes->mkdir("sigfidx"));
102  bkgfidx.SaveTo(fvolumes->mkdir("bkgfidx"));
103  ncbkgfidx.SaveTo(fvolumes->mkdir("ncbkgfidx"));
104  ccpi0bkgfidx.SaveTo(fvolumes->mkdir("ccpi0bkgfidx"));
105  ccnonpi0bkgfidx.SaveTo(fvolumes->mkdir("ccnonpi0bkgfidx"));
106 
107  sigfidy.SaveTo(fvolumes->mkdir("sigfidy"));
108  bkgfidy.SaveTo(fvolumes->mkdir("bkgfidy"));
109  ncbkgfidy.SaveTo(fvolumes->mkdir("ncbkgfidy"));
110  ccpi0bkgfidy.SaveTo(fvolumes->mkdir("ccpi0bkgfidy"));
111  ccnonpi0bkgfidy.SaveTo(fvolumes->mkdir("ccnonpi0bkgfidy"));
112 
113  sigfidz.SaveTo(fvolumes->mkdir("sigfidz"));
114  bkgfidz.SaveTo(fvolumes->mkdir("bkgfidz"));
115  ncbkgfidz.SaveTo(fvolumes->mkdir("ncbkgfidz"));
116  ccpi0bkgfidz.SaveTo(fvolumes->mkdir("ccpi0bkgfidz"));
117  ccnonpi0bkgfidz.SaveTo(fvolumes->mkdir("ccnonpi0bkgfidz"));
118 
119  sigshwx.SaveTo(fvolumes->mkdir("sigshwx"));
120  bkgshwx.SaveTo(fvolumes->mkdir("bkgshwx"));
121  ncbkgshwx.SaveTo(fvolumes->mkdir("ncbkgshwx"));
122  ccpi0bkgshwx.SaveTo(fvolumes->mkdir("ccpi0bkgshwx"));
123  ccnonpi0bkgshwx.SaveTo(fvolumes->mkdir("ccnonpi0bkgshwx"));
124 
125  sigshwy.SaveTo(fvolumes->mkdir("sigshwy"));
126  bkgshwy.SaveTo(fvolumes->mkdir("bkgshwy"));
127  ncbkgshwy.SaveTo(fvolumes->mkdir("ncbkgshwy"));
128  ccpi0bkgshwy.SaveTo(fvolumes->mkdir("ccpi0bkgshwy"));
129  ccnonpi0bkgshwy.SaveTo(fvolumes->mkdir("ccnonpi0bkgshwy"));
130 
131  sigshwz.SaveTo(fvolumes->mkdir("sigshwz"));
132  bkgshwz.SaveTo(fvolumes->mkdir("bkgshwz"));
133  ncbkgshwz.SaveTo(fvolumes->mkdir("ncbkgshwz"));
134  ccpi0bkgshwz.SaveTo(fvolumes->mkdir("ccpi0bkgshwz"));
135  ccnonpi0bkgshwz.SaveTo(fvolumes->mkdir("ccnonpi0bkgshwz"));
136 
137  fvolumes->Write();
138  std::cout << "\nOutput saved to " << fvolumes->GetName() << std::endl ;
139  fvolumes->Close();
140  return;
141 }
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
const Cut Signal
Definition: ncpi0Cuts.h:811
const Cut k1Prong([](const caf::SRProxy *sr){if(sr->vtx.nelastic==0 &&sr->mc.nnu==0) return false;return(sr->vtx.elastic[0].fuzzyk.npng==1);})
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const Cut NCBkg([](const caf::SRProxy *sr){float MassOfPi0=0.135;float kinetic=-10;float en=-99;if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;if(sr->mc.nu[0].prim.size()==0) return false;int nbofprim=sr->mc.nu[0].prim.size();int countpi=0;for(int i=0;i< nbofprim;i++){if(sr->mc.nu[0].prim[i].pdg==111){en=sr->mc.nu[0].prim[i].p.E;kinetic=en-MassOfPi0;countpi++;}}if(countpi==0 &&!sr->mc.nu[0].iscc) return true;return false;})
const Cut CCPi0Bkg([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;if(sr->mc.nu[0].prim.size()==0) return false;int nbofprim=sr->mc.nu[0].prim.size();int countpi=0;for(int i=0;i< nbofprim;i++){if(sr->mc.nu[0].prim[i].pdg==111) countpi++;}if(countpi > 0 &&sr->mc.nu[0].iscc) return true;return false;})
const Cut kNCBkg([](const caf::SRProxy *sr){float MassOfPi0=0.135;float kinetic=-10;float en=-99;if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;if(sr->mc.nu[0].prim.size()==0) return false;int nbofprim=sr->mc.nu[0].prim.size();int countpi=0;for(int i=0;i< nbofprim;i++){if(sr->mc.nu[0].prim[i].pdg==111){en=sr->mc.nu[0].prim[i].p.E;kinetic=en-MassOfPi0;if(kinetic > 0.5) countpi++;}}if(countpi==0 &&!sr->mc.nu[0].iscc) return true;return false;})
const Cut Bkg
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
loader
Definition: demo0.py:10
OStream cout
Definition: OStream.cxx:6
const Cut kCCNonPi0Bkg([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;if(sr->mc.nu[0].prim.size()==0) return false;int nbofprim=sr->mc.nu[0].prim.size();int countpi=0;for(int i=0;i< nbofprim;i++){if(sr->mc.nu[0].prim[i].pdg==111) countpi++;}if(countpi==0 &&sr->mc.nu[0].iscc) return true;return false;})
const Cut kSignal
Definition: SINCpi0_Cuts.h:325
const Cut kremid([](const caf::SRProxy *sr){ return(sr->sel.remid.pid< 0.4125);})
const Var kShwy([](const caf::SRProxy *sr){return sr->vtx.elastic[0].fuzzyk.png[0].shwlid.stop.y;})
const Cut CCNonPi0Bkg([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;if(sr->mc.nu[0].prim.size()==0) return false;int nbofprim=sr->mc.nu[0].prim.size();int countpi=0;for(int i=0;i< nbofprim;i++){if(sr->mc.nu[0].prim[i].pdg==111) countpi++;}if(countpi==0 &&sr->mc.nu[0].iscc) return true;return false;})
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const Cut kVtx([](const caf::SRProxy *sr){if(sr->vtx.nelastic==0 &&sr->mc.nnu==0) return false;return(sr->vtx.nelastic==0);})
const Var kShwx([](const caf::SRProxy *sr){return sr->vtx.elastic[0].fuzzyk.png[0].shwlid.stop.x;})
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
const Var kShwz([](const caf::SRProxy *sr){return sr->vtx.elastic[0].fuzzyk.png[0].shwlid.stop.z;})
void FidOpt()
Definition: FidOpt.C:38
const Cut kCCPi0Bkg([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;if(sr->mc.nu[0].prim.size()==0) return false;int nbofprim=sr->mc.nu[0].prim.size();int countpi=0;for(int i=0;i< nbofprim;i++){if(sr->mc.nu[0].prim[i].pdg==111) countpi++;}if(countpi > 0 &&sr->mc.nu[0].iscc) return true;return false;})
enum BeamMode string