getData.C
Go to the documentation of this file.
2 #include "CAFAna/Core/Spectrum.h"
3 
4 #include "CAFAna/Cuts/Cuts.h"
9 
10 #include "CAFAna/Vars/Vars.h"
11 #include "CAFAna/Vars/HistAxes.h"
14 
15 #include "TFile.h"
16 
17 
18 using namespace ana;
19 
20 const Var kSliceTimeShift(
21  [](const caf::SRProxy *sr)
22  {
23  const double t = sr->slc.meantime / 1000;
24  if(sr->hdr.ismc)
25  return t;
26  const int run = sr->hdr.run;
28  return t;
29  if (!util::IsInBeamWindow(run, t*1000) )
30  return t;
31  if (t < 250.)
32  return t;
33  else
34  return (t-64.);
35  });
36 
37 void getData(){
38 
39  // Get FD files for HadEFrac vs. neutrino energy distribution
40  std::string quantpath = "/pnfs/nova/persistent/analysis/numu/Ana2017/all_FD_histo_for_quantile_cuts.root";
41  TFile* quantfile = TFile::Open(pnfs2xrootd(quantpath).c_str());
42  TH2* quanthist = (TH2*)quantfile->Get("dir_FDSpec2D/FDSpec2D");
43  std::vector<Cut> QuantCuts = QuantileCutsFromTH2(quanthist, kNumuCCOptimisedAxis, kHadEFracAxis, 4);
44 
45  std::string fd_numi = "/pnfs/nova/persistent/users/bzamoran/CheckEvents/fd_data.root";
46 
47  SpectrumLoader loader(fd_numi);
49 
50  HistAxis kAxis( "#Deltat from t_{0} (#mus)", Binning::Simple(35,25,445), kSliceTimeShift );
51 
52  Spectrum* sData = new Spectrum(loader, kAxis, kNumuCutFD2017);
53 
54  // make a vector with an entry for each quantiles
55  std::vector<Spectrum*> sDataVec;
56 
57  for(auto thisCut : QuantCuts){
58  sDataVec.push_back(new Spectrum(loader, kAxis, kNumuCutFD2017 && thisCut));
59  } // loop over quantiles
60 
61  ////////////////////
62  // GOOOOOOOO!!!!!
63  loader.Go();
64  ////////////////////
65 
66  // Now we should save the predictions
67  std::cerr << "Saving Spectra" << std::endl;
68  std::string OutFileName = "fd_data_AllQuants.root";
69  TFile *fAQ = TFile::Open(OutFileName.c_str(), "RECREATE");
70  sData->SaveTo(fAQ, "fd_data");
71  fAQ->Close();
72  delete fAQ;
73 
74  for(size_t quant=1; quant <= sDataVec.size(); quant++){
75  auto fd_data = sDataVec[quant-1];
76  OutFileName = "Data/fd_data_" + (std::string)Form("Quant%d", quant) + ".root";
77  std::cerr << "Saving Quantile " << quant << " to Spectrum file: " << OutFileName << std::endl;
78  TFile *f = TFile::Open(OutFileName.c_str(), "RECREATE");
79  fd_data -> SaveTo(f, "fd_data");
80  f->Close();
81  delete f;
82  }
83 
84 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void getData(int sampleCut=9, std::string period="full", std::string anaCut="3A", bool energy3a=true, bool optBin=true)
Definition: getData.C:33
void SaveTo(const osc::IOscCalc &x, TDirectory *dir, const std::string &name)
const Cut kNumuCutFD2017
Definition: NumuCuts2017.h:39
const int kLastBadTimingRun
const Var kSliceTimeShift([](const caf::SRProxy *sr){const double t=sr->slc.meantime/1000;if(sr->hdr.ismc) return t;const int run=sr->hdr.run;if(run > util::kLastBadTimingRun) return t;if(!util::IsInBeamWindow(run, t *1000)) return t;if(t< 250.) return t;else return(t-64.);})
caf::Proxy< caf::SRHeader > hdr
Definition: SRProxy.h:2137
static bool IsInBeamWindow(const int run, const double time)
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
const HistAxis kHadEFracAxis("E_{had.} / E_{#nu}", Binning::Simple(200, 0, 1), kHadEFrac)
HistAxis that implements Hadronic Energy fraction binning used by L.Vinton to derive Hadronic Energy ...
Definition: HistAxes.h:30
std::vector< double > Spectrum
Definition: Constants.h:746
OStream cerr
Definition: OStream.cxx:7
void SetSpillCut(const SpillCut &cut)
std::string pnfs2xrootd(std::string loc, bool unauth)
Definition: UtilsExt.cxx:237
caf::Proxy< unsigned int > run
Definition: SRProxy.h:248
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:39
if(dump)
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:534
loader
Definition: demo0.py:10
const HistAxis kNumuCCOptimisedAxis("Reconstructed Neutrino Energy (GeV)", kNumuCCEOptimisedBinning, kCCE)
HistAxis that implements optimised numuCCE from L. Vinton. See docdb 16332. This was close to &#39;custC&#39;...
Definition: HistAxes.h:24
Definition: run.py:1
caf::Proxy< caf::SRSlice > slc
Definition: SRProxy.h:2142
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
caf::Proxy< float > meantime
Definition: SRProxy.h:1311
caf::Proxy< bool > ismc
Definition: SRProxy.h:242
std::vector< Cut > QuantileCutsFromTH2(TH2 *quantileHist, const HistAxis &independentAxis, const HistAxis &quantileAxis, const unsigned int &numQuantiles, const bool verbose)
: Do the same as the QuantileCuts function but taking in the TH2 instead of making it...
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
enum BeamMode string