CutFlow_Data.C
Go to the documentation of this file.
1 #include "CAFAna/Cuts/Cuts.h"
6 
8 #include "CAFAna/Core/Spectrum.h"
10 
11 #include "CAFAna/Vars/Vars.h"
14 
17 
18 using namespace ana;
19 
20 #include "TStyle.h"
21 #include "TCanvas.h"
22 #include "TH1.h"
23 #include "TLegend.h"
24 #include "TLatex.h"
25 
26 #include <fstream>
27 
29 {
30  // --- Set my loader.
31  SpectrumLoader FHC_Loader( "prod4_restrictedcaf_fd_numi_fhc_full_goodruns");
32  SpectrumLoader RHC_Loader( "prod4_restrictedcaf_fd_numi_rhc_full_goodruns" );
33  FHC_Loader.SetSpillCut(kStandardSpillCuts);
34  RHC_Loader.SetSpillCut(kStandardSpillCuts);
35 
36  // --- Define my cuts and their names.
37  std::vector<Cut> TieredCuts;
38  std::vector<std::string> CutNames;
39  CutNames.emplace_back("NoCut"); TieredCuts.emplace_back(kNumu2017Veto && kNoCut);
40  CutNames.emplace_back("Quality"); TieredCuts.emplace_back(kNumu2017Veto && kNumuQuality);
41  CutNames.emplace_back("Containment"); TieredCuts.emplace_back(kNumu2017Veto && kNumuQuality && kNumuContainFD2017);
42  CutNames.emplace_back("Cosmic_Rej"); TieredCuts.emplace_back(kNumu2017Veto && kNumuQuality && kNumuContainFD2017 && kNumuCosmicRej2018);
43  CutNames.emplace_back("Particle_ID"); TieredCuts.emplace_back(kNumu2017Veto && kNumuQuality && kNumuContainFD2017 && kNumuCosmicRej2018 && kNumuPID2018 );
44 
45  size_t NCuts = TieredCuts.size();
46 
47  // --- Define my objects.
48  Spectrum* Cosmics_FHC[NCuts];
49  Spectrum* BeamNus_FHC[NCuts];
50  Spectrum* Cosmics_RHC[NCuts];
51  Spectrum* BeamNus_RHC[NCuts];
52 
53  Spectrum* Cosmics_CDir_FHC[NCuts];
54  Spectrum* BeamNus_CDir_FHC[NCuts];
55  Spectrum* Cosmics_CDir_RHC[NCuts];
56  Spectrum* BeamNus_CDir_RHC[NCuts];
57 
58  const Binning RatioBins = Binning::Simple(100, -0.05, 0.05 );
59  const Var kCDirScore([](const caf::SRProxy* sr){
60  return ((float)sr->sel.cosrej.cdirscore);
61  });
62 
63  // --- Set my objects.
64  for(size_t cut = 0; cut < NCuts; ++cut) {
65  const Cut Cut_Cosm = TieredCuts[cut] && kInTimingSideband;
66  const Cut Cut_Beam = TieredCuts[cut] && kInBeamSpill;
67  Cosmics_FHC[cut] = new Spectrum( "Reco Energy (GeV)", kNumuCCEOptimisedBinning, FHC_Loader, kCCE, Cut_Cosm, kNoShift, kTimingSidebandWeight );
68  BeamNus_FHC[cut] = new Spectrum( "Reco Energy (GeV)", kNumuCCEOptimisedBinning, FHC_Loader, kCCE, Cut_Beam, kNoShift, kUnweighted );
69  Cosmics_RHC[cut] = new Spectrum( "Reco Energy (GeV)", kNumuCCEOptimisedBinning, RHC_Loader, kCCE, Cut_Cosm, kNoShift, kTimingSidebandWeight );
70  BeamNus_RHC[cut] = new Spectrum( "Reco Energy (GeV)", kNumuCCEOptimisedBinning, RHC_Loader, kCCE, Cut_Beam, kNoShift, kUnweighted );
71 
72  Cosmics_CDir_FHC[cut] = new Spectrum( "CosRej CDir", RatioBins, FHC_Loader, kCDirScore, Cut_Cosm, kNoShift, kTimingSidebandWeight );
73  BeamNus_CDir_FHC[cut] = new Spectrum( "CosRej CDir", RatioBins, FHC_Loader, kCDirScore, Cut_Beam, kNoShift, kUnweighted );
74  Cosmics_CDir_RHC[cut] = new Spectrum( "CosRej CDir", RatioBins, RHC_Loader, kCDirScore, Cut_Cosm, kNoShift, kTimingSidebandWeight );
75  BeamNus_CDir_RHC[cut] = new Spectrum( "CosRej CDir", RatioBins, RHC_Loader, kCDirScore, Cut_Beam, kNoShift, kUnweighted );
76  }
77 
78  // --- Set the loader off!
79  FHC_Loader.Go();
80  RHC_Loader.Go();
81 
82  // --- Define an outfile.
83  std::string OutName = "DataCutFlow.root";
84  TFile *OutFile = new TFile(OutName.c_str(), "RECREATE");
85  OutFile -> cd();
86  for(size_t cut = 0; cut < NCuts; ++cut){
87  Cosmics_FHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_Cosmics_FHC") ) ;
88  BeamNus_FHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_BeamNus_FHC") ) ;
89  Cosmics_RHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_Cosmics_RHC") ) ;
90  BeamNus_RHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_BeamNus_RHC") ) ;
91 
92  Cosmics_CDir_FHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_Cosmics_CDir_FHC") ) ;
93  BeamNus_CDir_FHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_BeamNus_CDir_FHC") ) ;
94  Cosmics_CDir_RHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_Cosmics_CDir_RHC") ) ;
95  BeamNus_CDir_RHC[cut] -> SaveTo( OutFile, TString(CutNames[cut])+TString("_BeamNus_CDir_RHC") ) ;
96  }
97 } // End of function
size_t NCuts
Definition: MakeCutFlow.C:50
void CutFlow_Data()
Definition: CutFlow_Data.C:35
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 SaveTo(const osc::IOscCalc &x, TDirectory *dir, const std::string &name)
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
void SetSpillCut(const SpillCut &cut)
caf::Proxy< float > cdirscore
Definition: SRProxy.h:860
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
caf::Proxy< caf::SRCosRej > cosrej
Definition: SRProxy.h:1252
const Cut kInTimingSideband([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return(kInTimingSideband_before(sr)|| kInTimingSideband_after(sr));else return(kInTimingSideband_before(sr)|| kInTimingSideband_afterA(sr)|| kInTimingSideband_afterB(sr));}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return(kInTimingSideband_before.Livetime(spill)+ kInTimingSideband_after.Livetime(spill));else return(kInTimingSideband_before.Livetime(spill)+ kInTimingSideband_afterA.Livetime(spill)+ kInTimingSideband_afterB.Livetime(spill));}, [](const caf::SRSpillProxy *spill){return 0;})
Definition: TimingCuts.h:12
const Cut kNumuCosmicRej2018([](const caf::SRProxy *sr){return(sr->sel.cosrej.anglekal > 0.5 && sr->sel.cosrej.numucontpid2019 > 0.53 && sr->slc.nhit< 400 && sr->sel.nuecosrej.pngptp< 0.9 );})
Definition: NumuCuts2018.h:19
const Cut kNumu2017Veto([](const caf::SRProxy *sr){return sr->sel.veto.keep;})
cosmic veto cut for FD
Definition: NumuCuts2017.h:30
const Cut kNumuContainFD2017
Definition: NumuCuts2017.h:21
const Var kCCE
Definition: NumuVars.h:21
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
std::vector< float > Spectrum
Definition: Constants.h:610
const SystShifts kNoShift
Definition: SystShifts.cxx:21
const Cut cut
Definition: exporter_fd.C:30
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const Cut kNumuPID2018([](const caf::SRProxy *sr){std::cout<< "ERROR::kNumuPID2018, cutting on both cvnProd3Train and cvn2017."<< " Neither branch exists anymore. Returning False."<< std::endl;abort();return false;})
Definition: NumuCuts2018.h:22
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
const Cut kInBeamSpill([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return kInBeamSpill_main(sr);else return kInBeamSpill_main(sr)||kInBeamSpill_shifted(sr);}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return kInBeamSpill_main.Livetime(spill);else return kInBeamSpill_main.Livetime(spill)+kInBeamSpill_shifted.Livetime(spill);}, [](const caf::SRSpillProxy *spill) -> double{return spill->spillpot;})
Does the event fall inside the window we call the beam spill?
Definition: TimingCuts.h:8
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
TFile * OutFile
caf::Proxy< caf::SRIDBranch > sel
Definition: SRProxy.h:2141
const Cut kNumuQuality
Definition: NumuCuts.h:18
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:96
c cd(1)
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
const Binning RatioBins
std::vector< std::string > CutNames
Definition: MakeCutFlow.C:49
enum BeamMode string