Analyse_OverlayStudies.C
Go to the documentation of this file.
5 
7 #include "CAFAna/Core/Spectrum.h"
9 
17 #include "CAFAna/Cuts/SpillCuts.h"
18 #include "CAFAna/Cuts/TimingCuts.h"
19 
21 
22 #include "TFile.h"
23 #include "TH2.h"
24 
25 
26 using namespace ana;
27 
28 
29 void Analyse_OverlayStudies(std::string s_Sample = "default", std::string s_Selection = "numu2020", bool getDetailed = true, bool reweight = true, unsigned int nBins = 30, bool loosePresel = false, std::string s_FileApp = "", std::string s_Condition = "")
30 {
31  Helper help;
32  help.fNbins = nBins;
33 
34  bool isNominal = false;
35  bool isMC = false;
36  if(s_Sample.find("default")!=std::string::npos){
37  std::cout << "\nPLEASE SPECIFY A SAMPLE... SEE HELPER.H\n" << std::endl;
38  std::abort();
39  }
40  if(s_Sample.find("nom")!=std::string::npos){
41  isNominal = true;
42  }
43  if(s_Sample.find("mcmc")!=std::string::npos){
44  isMC = true;
45  }
46  std::string s_Beam;
47  if(help.Def(s_Sample, s_Condition).find("fhc")!=std::string::npos){
48  s_Beam = "fhc";
49  }
50  else if(help.Def(s_Sample, s_Condition).find("rhc")!=std::string::npos){
51  s_Beam = "rhc";
52  }
53  else{
54  std::cout << "\nPLEASE PROVIDE A HORN CURRENT!\n" << std::endl;
55  std::abort();
56  }
57 
58  if(s_FileApp!="") s_FileApp = "_" + s_FileApp;
59  std::string s_OutFile = "Analyse_OverlayStudies_" + s_Sample + "_" + s_Selection + s_FileApp + ".root";
60  TFile *f_Out = new TFile(s_OutFile.c_str(), "RECREATE");
61 
62  SpectrumLoader loader(help.Def(s_Sample, s_Condition));
63  loader.SetSpillCut(kStandardSpillCuts);
64  SpectrumLoader loader_NoSpillCut(help.Def(s_Sample, s_Condition));
65 
66  loader.ReweightNuTree(reweight);
67  loader_NoSpillCut.ReweightNuTree(reweight);
68  const Var kMyWeight = (reweight) ? kSpillPOTRatioWeight : kNoWeight;
69 
70  const Cut kOverlaid = kOverlaidEff51;
71  //const Cut kOverlaid = kOverlaidNoEffCut;
72  const NuTruthCut kOverlaid_Nu = isMC ? kOverlaidMC_Nu : kOverlaidData_Nu;
73 
74  std::map<std::string,const Cut> map_Cuts;
75  std::map<std::string,const NuTruthCut> map_NuCuts;
76  scheduleCuts(map_Cuts, map_NuCuts, kOverlaid, kOverlaid_Nu, s_Selection, isNominal, getDetailed, loosePresel);
77 
78  std::map<std::string,const Var> map_Vars;
79  std::map<std::string,const NuTruthVar> map_NuVars;
80  scheduleVars(map_Vars, map_NuVars, s_Selection);
81 
82  std::map<std::pair<std::string,std::string>,Spectrum*> map_Spectra;
83  for(auto &cut: map_Cuts){
84  for(auto &var: map_Vars){
85  map_Spectra.emplace(std::make_pair(cut.first, var.first), new Spectrum(var.first, help.Bins(var.first), loader,
86  var.second, cut.second, kNoShift, kMyWeight));
87  }
88  }
89 
90  for(auto &nuCut: map_NuCuts ){
91  for(auto &nuVar: map_NuVars){
92  map_Spectra.emplace(std::make_pair(nuCut.first, nuVar.first), new Spectrum(nuVar.first+"_kSpillPOTRatioWeight", help.Bins(nuVar.first), loader,
93  nuVar.second, nuCut.second));
94  }
95  }
96 
97  //SPECIAL PLOTS.
98  const Cut kThisTrueOFiducial = loosePresel ? kTrueOFiducialLoose : kTrueOFiducial;
99  const Cut kSig = help.Sig_Cut(s_Selection);
100  const Cut kSelection = help.Selection_Cut(s_Selection);
101  map_Spectra.emplace(std::make_pair("special_overnoeff_fid_sig", "kSlcEff"),
102  new Spectrum("kSlcEff", help.Bins("kSlcEff"), loader, kSlcEff, kOverlaidNoEffCut && kSig && kThisTrueOFiducial, kNoShift, kMyWeight));
103  map_Spectra.emplace(std::make_pair("special_noweight_notover_rec_sel", "kSpillPOT"),
104  new Spectrum("kSpillPOT", help.Bins("kSpillPOT"), loader, kSpillPOT, kNotOverlaidData && kSelection, kNoShift, kNoWeight));
105 
106  //SPILL TREE PLOTS.
107  std::vector<TH1D*> vec_SpillHists;
108  TH1D *h_kSpillPOT_Sp = new TH1D("kSpillPOT_Sp", "", nBins, 10.e12, 70.e12);
109  vec_SpillHists.push_back(h_kSpillPOT_Sp);
110  TH1D *h_kSpillPOTRatioWeight_Sp = new TH1D("kSpillPOTRatioWeight_Sp", "", nBins, 0.1, 2);
111  vec_SpillHists.push_back(h_kSpillPOTRatioWeight_Sp);
112  TH1D *h_kSpillCount_Sp = new TH1D("kSpillCount_Sp", "", 1, -0.5, 0.5);
113  vec_SpillHists.push_back(h_kSpillCount_Sp);
114  TH1D *h_kSpillPOTNSC_Sp = new TH1D("kSpillPOTNSC_Sp", "", nBins, 10.e12, 70.e12);
115  vec_SpillHists.push_back(h_kSpillPOTNSC_Sp);
116  TH1D *h_kSpillPOTRatioWeightNSC_Sp = new TH1D("kSpillPOTRatioWeightNSC_Sp", "", nBins, 0.1, 2);
117  vec_SpillHists.push_back(h_kSpillPOTRatioWeightNSC_Sp);
118  TH1D *h_kSpillCountNSC_Sp = new TH1D("kSpillCountNSC_Sp", "", 1, -0.5, 0.5);
119  vec_SpillHists.push_back(h_kSpillCountNSC_Sp);
120 
121  loader.AddSpillHistogram(h_kSpillPOT_Sp, kSpillPOT_Sp, kStandardSpillCuts);
122  loader.AddSpillHistogram(h_kSpillPOTRatioWeight_Sp, kSpillPOTRatioWeight_Sp, kStandardSpillCuts);
123  loader.AddSpillHistogram(h_kSpillCount_Sp, kSpillCount_Sp, kStandardSpillCuts);
124  loader_NoSpillCut.AddSpillHistogram(h_kSpillPOTNSC_Sp, kSpillPOT_Sp, kNoCut_Sp);
125  loader_NoSpillCut.AddSpillHistogram(h_kSpillPOTRatioWeightNSC_Sp, kSpillPOTRatioWeight_Sp, kNoCut_Sp);
126  loader_NoSpillCut.AddSpillHistogram(h_kSpillCountNSC_Sp, kSpillCount_Sp, kNoCut_Sp);
127 
128  loader.Go();
129  loader_NoSpillCut.Go();
130 
131  char dirName[256];
132  for(auto spec : map_Spectra){
133  sprintf(dirName, "dir_-CUT-%s-VAR-%s", spec.first.first.c_str(), spec.first.second.c_str());
134  spec.second->SaveTo(f_Out, dirName);
135  }
136 
137  TDirectory *dir_SpillHist = f_Out->mkdir("SpillHists");
138  dir_SpillHist->cd();
139  for(auto spillHist : vec_SpillHists){
140  spillHist->Write();
141  }
142 
143  std::cout << "ANALYSIS DONE" << std::endl;
144 
145  return;
146 }
147 
148 
unsigned int fNbins
Definition: Helper.h:37
void Analyse_OverlayStudies(std::string s_Sample="default", std::string s_Selection="numu2020", bool getDetailed=true, bool reweight=true, unsigned int nBins=30, bool loosePresel=false, std::string s_FileApp="", std::string s_Condition="")
int nBins
Definition: plotROC.py:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Cut Sig_Cut(std::string s_Selection)
Definition: Helper.h:265
std::string Def(std::string const &s_Sample, std::string const &s_Condition)
Definition: Helper.h:48
const NuTruthCut kOverlaidData_Nu([](const caf::SRNeutrinoProxy *nu){return true;})
Definition: OverlayCuts.h:10
const SpillVar kSpillPOTRatioWeight_Sp([](const caf::SRSpillProxy *sp){const double centralValue=40.e12;return sp->spillpot/centralValue;})
Definition: OverlayVars.h:52
const NuTruthCut kOverlaidMC_Nu([](const caf::SRNeutrinoProxy *nu){return(nu->mode > 9999);})
Definition: OverlayCuts.h:9
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:33
const Cut kTrueOFiducialLoose
Definition: OverlayCuts.cxx:57
void scheduleVars(std::map< std::string, const Var > &map_Vars, std::map< std::string, const NuTruthVar > &map_NuVars, std::string s_Selection)
Definition: Scheduling.h:97
const Var kNoWeight([](const caf::SRProxy *sr){return 1.;})
Definition: OverlayVars.h:11
const Cut kOverlaidNoEffCut([](const caf::SRProxy *sr){if(sr->mc.nallnus==0) return false;for(int j=0;j< sr->mc.nallnus;j++) if((sr->mc.allnus[j].mode > 9999 ||!sr->spill.ismc)) return true;return false;})
Definition: OverlayCuts.h:35
const Var kSpillPOT
Return the POT for the spill.
Definition: SpillVars.cxx:33
const Var kSlcEff([](const caf::SRProxy *sr){for(int i=0;i< (int) sr->mc.nallnus;i++) if(sr->mc.allnus[i].mode > 9999||!sr->spill.ismc) return(float) sr->mc.allnus[i].eff;return-5.f;})
Definition: OverlayVars.h:48
const Binning Bins(std::string s_Var)
Definition: Helper.h:418
loader
Definition: demo0.py:10
const SpillVar kSpillCount_Sp([](const caf::SRSpillProxy *sp){return 0.;})
Definition: OverlayVars.h:50
const SystShifts kNoShift
Definition: SystShifts.h:115
OStream cout
Definition: OStream.cxx:6
const Cut kSelection
Definition: SINCpi0_Cuts.h:328
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
const Var kSpillPOTRatioWeight([](const caf::SRProxy *sr){const double centralValue=40.e12;return sr->spill.spillpot/centralValue;})
Definition: OverlayVars.h:12
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const SpillCut kNoCut_Sp([](const caf::SRSpillProxy *sp){return true;})
Definition: OverlayCuts.h:39
const Cut kOverlaidEff51([](const caf::SRProxy *sr){if(sr->mc.nallnus==0) return false;for(int j=0;j< sr->mc.nallnus;j++) if((sr->mc.allnus[j].mode > 9999 ||!sr->spill.ismc) &&sr->mc.allnus[j].eff > 0.51) return true;return false;})
Definition: OverlayCuts.h:33
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:46
Definition: Helper.h:14
const Cut kTrueOFiducial
Definition: OverlayCuts.cxx:44
const SpillVar kSpillPOT_Sp([](const caf::SRSpillProxy *sp){return sp->spillpot;})
Definition: OverlayVars.h:51
const Cut kNotOverlaidData([](const caf::SRProxy *sr){if(sr->mc.nallnus==0) return true;return false;})
Definition: OverlayCuts.h:37
void scheduleCuts(std::map< std::string, const Cut > &map_Cuts, std::map< std::string, const NuTruthCut > &map_NuCuts, const Cut kOverlaid, const NuTruthCut kOverlaid_Nu, std::string const &s_Selection, bool isNominal=false, bool getDetailed=false, bool loosePresel=false)
Definition: Scheduling.h:16
const Cut Selection_Cut(std::string s_Selection)
Definition: Helper.h:399