resolutionspectrums.C
Go to the documentation of this file.
1 
2 #ifdef __CINT__
4 {
5  std::cout << "Sorry, you must run in compiled mode" << std::endl;
6 }
7 #else
8 
9 
10 #include "CAFAna/Cuts/Cuts.h"
11 #include "CAFAna/Analysis/Plots.h"
12 #include "CAFAna/Core/SpectrumLoaderMockData.h"
15 #include "CAFAna/Core/Spectrum.h"
17 #include "CAFAna/Vars/Vars.h"
19 #include "CAFAna/Core/HistAxis.h"
20 #include "CAFAna/Core/Binning.h"
23 #include "CAFAna/Core/Cut.h"
24 #include "CAFAna/Cuts/SpillCuts.h"
26 #include "CAFAna/Cuts/TruthCuts.h"
27 #include "CAFAna/Core/Utilities.h"
28 #include "CAFAna/Vars/Vars.h"
29 
30 #include "TCanvas.h"
31 #include "TH2.h"
32 #include "TH1.h"
33 #include "TFitResultPtr.h"
34 #include "TLegend.h"
35 #include "TStyle.h"
36 #include "TArrow.h"
37 #include "TH3.h"
38 #include "TFile.h"
39 #include "TGraph.h"
40 #include <cmath>
41 #include <cassert>
42 #include <memory>
43 #include "TProfile.h"
44 #include <fstream>
45 #include <sstream>
46 #include <iostream>
47 #include <iomanip>
48 #include <stdarg.h>
49 #include <stdlib.h>
50 #include <stdio.h>
51 #include <string.h>
52 
53 #include "NDAna/ncpi0/Headers/singleprongVars.h"
55 
56 
57 using namespace ana;
58 const double pot = 8.08988e+20;
59 
60 void saveS(Spectrum s, string name)
61 {
62  TH1D *h = s.ToTH1(s.POT());
63  h->SetName(name.c_str());
64  h->SetLineColor(kRed);
65  h->Write();
66 }
67 
68 void saveS1(Spectrum s, string name)
69 {
70  TH2 *h1 = s.ToTH2(s.POT());
71  h1->SetName(name.c_str());
72  h1->SetLineColor(kRed);
73  h1->Write();
74 }
75 
76 //void checkBdt(const std::string fGENIE, const std::string fout)
78 {
79  const std::string fGENIE = "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.d_nd_genie_nonswap_fhc_nova_v08_full_v1";
80 
81  SpectrumLoader loader(fGENIE);
83 
84  const Binning DeltaEBins = Binning::Simple(100,-1.5,1.5);
85  const Binning Pi0EBins = Binning::Simple(60,0,3);
86 
87 
88  //Make spectra for Resolution (Delta vs True) plots.
89  Spectrum SelEnResolution("SelEnResolution",loader,Pi0EBins,kTruePi0Energy,DeltaEBins,kDeltaEnergy,Preselection && kNCPi0BDTID>.85);
90  Spectrum SigEnResolution("SigEnResolution",loader,Pi0EBins,kTruePi0Energy,DeltaEBins,kDeltaEnergy,Preselection && Signal && kNCPi0BDTID>.85);
91  Spectrum BkgEnResolution("BkgEnResolution",loader,Pi0EBins,kTruePi0Energy,DeltaEBins,kDeltaEnergy,Preselection && Bkg && kNCPi0BDTID>.85);
92 
93 
94  //Make Spectra for Bias (Delta vs Reco) plots.
95  Spectrum SelEnBias("SelEnBias", loader, Pi0EBins,k1ProngEn,DeltaEBins, kDeltaEnergy, Preselection && kNCPi0BDTID>.85);
96  Spectrum SigEnBias("SigEnBias",loader, Pi0EBins,k1ProngEn,DeltaEBins, kDeltaEnergy, Preselection && Signal && kNCPi0BDTID>.85);
97  Spectrum BkgEnBias("BkgEnBias",loader, Pi0EBins,k1ProngEn,DeltaEBins, kDeltaEnergy, Preselection && Bkg && kNCPi0BDTID>.85);
98 
99  loader.Go();
100 
101  std::string fname = "resolutionstudybiashighbdtcut.root";
102 
103  TFile fout(fname.c_str(),"RECREATE");
104 
105  saveS1(SelEnResolution, "SelEnRes");
106  saveS1(SigEnResolution, "SigEnRes");
107  saveS1(BkgEnResolution, "BkgEnRes");
108 
109  saveS1(SelEnBias, "SelEnBias");
110  saveS1(SigEnBias, "SigEnBias");
111  saveS1(BkgEnBias, "BkgEnBias");
112 
113  fout.Write();
114  fout.Close();
115 
116  std::cout<<"****Compiled Successfully*****"<<std::endl;
117 
118 }
119 
120 
121 #endif
const XML_Char * name
Definition: expat.h:151
const Var kNCPi0BDTID
Definition: NDNCPi0Xsec.h:23
enum BeamMode kRed
TH2 * ToTH2(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 2D to obtain TH2.
Definition: Spectrum.cxx:165
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
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
const Var k1ProngEn([](const caf::SRProxy *sr){if(sr->vtx.nelastic==0) return 0.f;if(sr->vtx.elastic[0].fuzzyk.npng< 2) return float(-1);return float(sr->vtx.elastic[0].fuzzyk.png[0].shwlid.calE);})
void saveS(Spectrum s, string name)
const Var kTruePi0Energy([](const caf::SRProxy *sr){float MassOfPi0=0.135;float kinetic=-10;float en=-99;if(sr->vtx.nelastic==0) return 0.0f;if(sr->mc.nnu==0) return 0.0f;if(sr->mc.nu[0].prim.size()==0) return 0.0f;int nbofprim=sr->mc.nu[0].prim.size();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;}}return en;})
const double pot
void SetSpillCut(const SpillCut &cut)
const Cut Preselection
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const SpillCut kTightBeamQualityCuts([](const caf::SRSpillProxy *s){if(s->ismc) return true; if(s->trigger==2) return true;if(s->spilltimesec==0 &&s->deltaspilltimensec==0 &&s->widthx==0) return bool(s->isgoodspill);if(std::abs(s->deltaspilltimensec) > 0.5e9) return false;if(s->spillpot< 2e12) return false;if(s->hornI< -202|| s->hornI >-198) return false;if(s->posx< -2.00|| s->posx >+2.00) return false;if(s->posy< -2.00|| s->posy >+2.00) return false;return kBeamWidthCut(s);})
Definition: SpillCuts.h:10
const XML_Char * s
Definition: expat.h:262
const SpillCut kStandardDQCuts([](const caf::SRSpillProxy *spill){if(spill->dcmedgematchfrac==0 &&spill->fracdcm3hits==0 &&spill->nmissingdcmslg==0) return bool(spill->isgoodspill); if(spill->det==caf::kNEARDET && (spill->fracdcm3hits > 0.45|| spill->nmissingdcms > 0)) return false; if(spill->eventincomplete) return false; if(spill->det==caf::kFARDET && spill->nmissingdcmslg > 0) return false; if(spill->det==caf::kFARDET && !spill->ismc && spill->dcmedgematchfrac<=0.2) return false;return true;})
Cut out events with a noisy detector or with parts missing.
Definition: SpillCuts.h:16
const Cut Bkg
virtual void Go() override
Load all the registered spectra.
loader
Definition: demo0.py:10
double POT() const
Definition: Spectrum.h:227
OStream cout
Definition: OStream.cxx:6
TH1F * h1
void resolutionspectrums()
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
void saveS1(Spectrum s, string name)
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
enum BeamMode string