FidWithShwCuts.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 
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 && kContainment;
49  const Cut kBkg = Bkg && kVtx && k1Prong && kContainment;
50  const Cut kNCBkg = NCBkg && kVtx && k1Prong && kContainment;
51  const Cut kCCPi0Bkg = CCPi0Bkg && kVtx && k1Prong && kContainment;
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  //Load the spectra from the dataset.
76  loader.Go();
77 
78  //Create root file and fill it with each spectrum.
79  TFile *fvolumes = new TFile("fiducialoptwithshowercuts.root","RECREATE");
80  sigfidx.SaveTo(fvolumes->mkdir("sigfidx"));
81  bkgfidx.SaveTo(fvolumes->mkdir("bkgfidx"));
82  ncbkgfidx.SaveTo(fvolumes->mkdir("ncbkgfidx"));
83  ccpi0bkgfidx.SaveTo(fvolumes->mkdir("ccpi0bkgfidx"));
84  ccnonpi0bkgfidx.SaveTo(fvolumes->mkdir("ccnonpi0bkgfidx"));
85 
86  sigfidy.SaveTo(fvolumes->mkdir("sigfidy"));
87  bkgfidy.SaveTo(fvolumes->mkdir("bkgfidy"));
88  ncbkgfidy.SaveTo(fvolumes->mkdir("ncbkgfidy"));
89  ccpi0bkgfidy.SaveTo(fvolumes->mkdir("ccpi0bkgfidy"));
90  ccnonpi0bkgfidy.SaveTo(fvolumes->mkdir("ccnonpi0bkgfidy"));
91 
92  sigfidz.SaveTo(fvolumes->mkdir("sigfidz"));
93  bkgfidz.SaveTo(fvolumes->mkdir("bkgfidz"));
94  ncbkgfidz.SaveTo(fvolumes->mkdir("ncbkgfidz"));
95  ccpi0bkgfidz.SaveTo(fvolumes->mkdir("ccpi0bkgfidz"));
96  ccnonpi0bkgfidz.SaveTo(fvolumes->mkdir("ccnonpi0bkgfidz"));
97 
98  fvolumes->Write();
99  std::cout << "\nOutput saved to " << fvolumes->GetName() << std::endl ;
100  fvolumes->Close();
101  return;
102 }
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;})
void FidWShwCuts()
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
const Cut kContainment([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;if(sr->vtx.nelastic==0) return false;if(sr->vtx.elastic[0].fuzzyk.nshwlid==0) return false;if(sr->vtx.elastic[0].fuzzyk.npng==0) return false;for(unsigned int i=0;i< sr->vtx.elastic[0].fuzzyk.nshwlid;i++){if((sr->vtx.elastic[0].fuzzyk.png[i].shwlid.stop.x)< -160.0) return false;if((sr->vtx.elastic[0].fuzzyk.png[i].shwlid.stop.x) > 120.0) return false;if((sr->vtx.elastic[0].fuzzyk.png[i].shwlid.stop.y)< -180.0) return false;if((sr->vtx.elastic[0].fuzzyk.png[i].shwlid.stop.y) > 155.0) return false;if((sr->vtx.elastic[0].fuzzyk.png[i].shwlid.stop.z)< 200.0) return false;if((sr->vtx.elastic[0].fuzzyk.png[i].shwlid.stop.z) > 1200.0) return false;}return true;})
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 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);})
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
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