Classes | Functions | Variables
GetSpectra.h File Reference

Go to the source code of this file.

Classes

struct  Plot
 ====================================================================== /// More...
 

Functions

void getPredictions (unsigned int timestamp, unsigned int nDays, std::string naming)
 
void getData (unsigned int timestamp, unsigned int nDays, std::string naming, std::string samdef)
 

Variables

const int kNumPlots = 11
 

Function Documentation

void getData ( unsigned int  timestamp,
unsigned int  nDays,
std::string  naming,
std::string  samdef 
)

Definition at line 75 of file GetSpectra.h.

References Plot::bins, om::cerr, om::cout, allTimeWatchdog::endl, Plot::file, plotROC::fileName, Plot::fname, MECModelEnuComparisons::i, kBoxMaxY(), kCut, ana::kDirZ, kInTimeTight, kMassFracPOT(), ana::kNHit, kNoCut, ana::kNoShift, kNumPlots, ana::kNumuContPID, ana::kPtP, ana::kSliceTime, kSpillPOT, ana::kUnweighted, kXYBins, Plot::label, demo0::loader, plots, ana::Binning::Simple(), SIMPLEVAR, string, and Plot::var.

75  {
76 
77  std::cout << "\n=================" << std::endl;
78  std::cout << "getData.C" << std::endl;
79  std::cout << "=================\n" <<std::endl;
80 
81  std::cout << "Setting loaders ..." << std::endl;
82 
83  unsigned int fhcStart = 1551204000; //12pm Central time, Feb 26th 2019.
84  std::string fFiles;
85 
86  if(naming == "All")
87  fFiles = "defname: " + samdef + Form(" and online.subrunendtime <= '%u' and online.subrunendtime >= '%u'", timestamp, fhcStart);
88  else
89  fFiles = "defname: " + samdef + Form(" and online.subrunendtime >= '%u' and online.subrunendtime <= '%u' and online.subrunendtime >= '%u'", timestamp - 86400*nDays, timestamp, fhcStart);
90 
91 
92  fFiles = "defname: " + samdef;
93  SpectrumLoader loader(fFiles);
94 
95  std::cout << "Defining spectrums ..." << std::endl;
96  Spectrum* hData[kNumPlots];
97  Spectrum* hBkg[kNumPlots];
98 
100  {
101  {"Slice time [#mus]", "tus", ana::Binning::Simple(45,1,541), ana::kSliceTime},
102  {"Run", "run", ana::Binning::Simple(15000, 15000, 30000), SIMPLEVAR(hdr.run)},
103  {"Time", "time", ana::Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), SIMPLEVAR(hdr.unixtime)},
104  {"Max y [m]", "maxy", kXYBins, kBoxMaxY},
105  {"Slice time [#mus]", "tighttus", ana::Binning::Simple(360,205,241), ana::kSliceTime},
106  {"No. Kalman tracks", "nkal", ana::Binning::Simple(10, 0, 10), SIMPLEVAR(trk.kalman.ntracks)},
107  {"No. Hits", "nhit", ana::Binning::Simple(10, 0, 500), ana::kNHit},
108  {"Kalman angle", "angkal", ana::Binning::Simple(5, 0, 1), SIMPLEVAR(sel.cosrej.anglekal)},
109  {"Z direction", "dirz", ana::Binning::Simple(5, 0.5, 1), ana::kDirZ},
110  {"BDT", "bdt", ana::Binning::Simple(20, 0, 1), ana::kNumuContPID},
111  {"p_{T}/p", "ptp", ana::Binning::Simple(20, 0, 1), ana::kPtP}
112  };
113 
114 
115  for(int i = 0; i < kNumPlots; ++i){
116  Plot p = plots[i];
117  hData[i] = new Spectrum(p.label, p.bins, loader, p.var, i <= 1 ? kCut : kCut && kInTimeTight, kNoShift, kUnweighted);
118  hBkg[i] = new Spectrum(p.label, p.bins, loader, p.var, kCut && !kInTimeTight, kNoShift, kUnweighted);
119  }
120 
121  Spectrum potTime("Date","POT #times Mass", loader, ana::Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), SIMPLEVAR(hdr.unixtime), ana::Binning::Simple(500,0,50e12),kMassFracPOT, kNoCut, kNoShift, kUnweighted);
124 
125  std::cout << "Loaders Go ..." << std::endl;
126  loader.Go();
127 
128 
129  std::string fileName = "dataspectra_" + naming + ".root";
130  std::cerr << "Saving predictions to file: " << fileName << std::endl;
131  TFile *file = TFile::Open(fileName.c_str(), "RECREATE");
132 
133  for(int i = 0; i < kNumPlots; ++i){
134  Plot p = plots[i];
135  hData[i]->SaveTo(file , ("data_"+p.fname).c_str() );
136  hBkg[i]->SaveTo(file, ("bkg_"+p.fname).c_str() );
137  }
138 
139  potTime.SaveTo(file , "potTime" );
140  massDenom.SaveTo(file, "massDenom");
141  massNum.SaveTo(file, "massNum");
142 
143  file->Close();
144 
145  std::cout << "Spectra made! \n" << std::endl;
146 
147 }// getData
fileName
Definition: plotROC.py:78
std::string label
Definition: CutFlow_Data.C:29
const Var kNumuContPID
Definition: NumuVars.cxx:553
const char * p
Definition: xmltok.h:285
std::vector< double > Spectrum
Definition: Constants.h:743
const Var kSliceTime([](const caf::SRProxy *sr){return sr->slc.meantime/1000;})
Definition: NumuVars.h:34
OStream cerr
Definition: OStream.cxx:7
const Var kMassFracPOT([](const caf::SRProxy *sr){return sr->spill.spillpot *(sr->hdr.diblast-sr->hdr.dibfirst+1)/14.;})
const Var kDirZ([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-5.f;return sr->trk.kalman.tracks[0].dir.Z();})
Definition: NumuVars.h:39
#define SIMPLEVAR(CAFNAME)
For Vars where literally all you need is a single CAF variable.
Definition: Var.h:88
const Cut kInTimeTight
Definition: VarsAndCuts.h:34
Track finder for cosmic rays.
const Var kPtP
Transverse momentum fraction in slice.
Definition: NueVars.cxx:90
====================================================================== ///
Definition: CutFlow_Data.C:28
const Var kBoxMaxY([](const caf::SRProxy *sr){return sr->slc.boxmax.Y()/100;})
const int kNumPlots
Definition: GetSpectra.h:2
const Var kNHit
Definition: Vars.cxx:71
const std::vector< Plot > plots
const Binning kXYBins
Definition: VarsAndCuts.h:102
loader
Definition: demo0.py:10
const SpillVar kSpillPOT([](const caf::SRSpillProxy *spill){return spill->spillpot;})
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
std::string fname
Definition: CutFlow_Data.C:30
const Cut kCut
Definition: VarsAndCuts.h:36
TFile * file
Definition: cellShifts.C:17
Binning bins
Definition: CutFlow_Data.C:31
Var var
Definition: CutFlow_Data.C:32
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
enum BeamMode string
void getPredictions ( unsigned int  timestamp,
unsigned int  nDays,
std::string  naming 
)

Definition at line 13 of file GetSpectra.h.

References Plot::bins, om::cerr, om::cout, allTimeWatchdog::endl, Plot::file, plotROC::fileName, Plot::fname, MECModelEnuComparisons::i, kBoxMaxY(), kCut, ana::kDirZ, ana::kNHit, kNoCut, ana::kNoShift, ana::kNullLoader, kNumPlots, ana::kNumuContPID, ana::kPPFXFluxCVWgt, ana::kPtP, ana::kSliceTime, kWOscDumbHere(), ana::kXSecCVWgt2020, kXYBins, Plot::label, plots, ana::Binning::Simple(), SIMPLEVAR, string, and Plot::var.

13  {
14 
15  std::cout << "\n=================" << std::endl;
16  std::cout << "getPredictions.C" << std::endl;
17  std::cout << "=================\n" <<std::endl;
19  {
20  {"Slice time [#mus]", "tus", ana::Binning::Simple(45,1,541), ana::kSliceTime},
21  {"Run", "run", ana::Binning::Simple(15000, 15000, 30000), SIMPLEVAR(hdr.run)},
22  {"Time", "time", ana::Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), SIMPLEVAR(hdr.unixtime)},
23  {"Max y [m]", "maxy", kXYBins, kBoxMaxY},
24  {"Slice time [#mus]", "tighttus", ana::Binning::Simple(360,205,241), ana::kSliceTime},
25  {"No. Kalman tracks", "nkal", ana::Binning::Simple(10, 0, 10), SIMPLEVAR(trk.kalman.ntracks)},
26  {"No. Hits", "nhit", ana::Binning::Simple(10, 0, 500), ana::kNHit},
27  {"Kalman angle", "angkal", ana::Binning::Simple(5, 0, 1), SIMPLEVAR(sel.cosrej.anglekal)},
28  {"Z direction", "dirz", ana::Binning::Simple(5, 0.5, 1), ana::kDirZ},
29  {"BDT", "bdt", ana::Binning::Simple(20, 0, 1), ana::kNumuContPID},
30  {"p_{T}/p", "ptp", ana::Binning::Simple(20, 0, 1), ana::kPtP}
31  };
32 
33 
34  std::cout << "Setting loaders ..." << std::endl;
35  //SpectrumLoader fd_nonswap("prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_nonswap_rhc_nova_v08_full_v1");
36  //SpectrumLoader fd_fluxswap("prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_fluxswap_rhc_nova_v08_full_v1");
37  SpectrumLoader fd_nonswap("prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_nonswap_fhc_nova_v08_full_v1");
38  SpectrumLoader fd_fluxswap("prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_fluxswap_fhc_nova_v08_full_v1");
39 
40  PredictionNoExtrap* hPred[kNumPlots];
41 
42  for(int i = 0; i < kNumPlots; ++i){
43  Plot p = plots[i];
44  std::cout << "Defining PredictionNoExtrap " << i << std::endl;
45  hPred[i]=new PredictionNoExtrap(fd_nonswap,fd_fluxswap,kNullLoader,p.label, p.bins, p.var, kCut, kNoShift , kPPFXFluxCVWgt*kXSecCVWgt2020);
46  }
47 
48  Spectrum nonSwapDenom("NHits", ana::Binning::Simple(100, 0, 1000), fd_nonswap, ana::kNHit, kNoCut, kNoShift, kWOscDumbHere);
49  Spectrum swapDenom("NHits", ana::Binning::Simple(100, 0, 1000), fd_fluxswap, ana::kNHit, kNoCut, kNoShift, kWOscDumbHere);
50 
51  std::cout << "Loaders Go ..." << std::endl;
52  fd_nonswap.Go();
53  fd_fluxswap.Go();
54 
55 
56  std::string fileName = "predictions_" + naming + ".root";
57  std::cerr << "Saving predictions to file: " << fileName << std::endl;
58  TFile *file = TFile::Open(fileName.c_str(), "RECREATE");
59  for(int i = 0; i < kNumPlots; ++i){
60  Plot p = plots[i];
61  hPred[i]->SaveTo(file , (p.fname).c_str() );
62  }
63 
64  nonSwapDenom.SaveTo(file, "nonSwapDenom");
65  swapDenom.SaveTo(file,"swapDenom");
66  file->Close();
67 
68  std::cout << "Predictions made! \n" << std::endl;
69 
70 
71 } // getPredictions
fileName
Definition: plotROC.py:78
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
std::string label
Definition: CutFlow_Data.C:29
const Var kNumuContPID
Definition: NumuVars.cxx:553
const char * p
Definition: xmltok.h:285
std::vector< double > Spectrum
Definition: Constants.h:743
const Var kSliceTime([](const caf::SRProxy *sr){return sr->slc.meantime/1000;})
Definition: NumuVars.h:34
OStream cerr
Definition: OStream.cxx:7
const Var kDirZ([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-5.f;return sr->trk.kalman.tracks[0].dir.Z();})
Definition: NumuVars.h:39
#define SIMPLEVAR(CAFNAME)
For Vars where literally all you need is a single CAF variable.
Definition: Var.h:88
Track finder for cosmic rays.
const Var kPtP
Transverse momentum fraction in slice.
Definition: NueVars.cxx:90
====================================================================== ///
Definition: CutFlow_Data.C:28
const Var kBoxMaxY([](const caf::SRProxy *sr){return sr->slc.boxmax.Y()/100;})
const int kNumPlots
Definition: GetSpectra.h:2
const Var kNHit
Definition: Vars.cxx:71
const std::vector< Plot > plots
const Binning kXYBins
Definition: VarsAndCuts.h:102
const Var kWOscDumbHere([](const caf::SRProxy *sr){if(sr->mc.nu.size()==0) return 0.;return kWOscDumb(sr);})
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
std::string fname
Definition: CutFlow_Data.C:30
const Cut kCut
Definition: VarsAndCuts.h:36
TFile * file
Definition: cellShifts.C:17
Binning bins
Definition: CutFlow_Data.C:31
Var var
Definition: CutFlow_Data.C:32
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
static NullLoader kNullLoader
Dummy loader that doesn&#39;t load any files.
const Var kXSecCVWgt2020
Definition: XsecTunes.h:105
enum BeamMode string

Variable Documentation

const int kNumPlots = 11