GetSpectra.h
Go to the documentation of this file.
1 
2 const int kNumPlots = 11;
3 
4 struct Plot
5 {
9  Var var;
10 };
11 
12 
13 void getPredictions(unsigned int timestamp, unsigned int nDays, std::string naming){
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
72 
73 
74 
75 void getData(unsigned int timestamp, unsigned int nDays, std::string naming, std::string samdef){
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);
122  Spectrum massDenom("", ana::Binning::Simple(1, 0, 1), loader, kUnweighted, kNoCut, kNoShift, kSpillPOT);
123  Spectrum massNum("", ana::Binning::Simple(1, 0, 1), loader, kUnweighted, kNoCut, kNoShift, kMassFracPOT);
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
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
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
ana::Binning bins
Definition: GetSpectra.h:8
std::vector< double > Spectrum
Definition: Constants.h:746
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
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
void getData(unsigned int timestamp, unsigned int nDays, std::string naming, std::string samdef)
Definition: GetSpectra.h:75
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
_Var< caf::SRProxy > Var
Definition: Var.h:7
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);})
loader
Definition: demo0.py:10
std::string file
Definition: DrawUtils.h:17
const SpillVar kSpillPOT([](const caf::SRSpillProxy *spill){return spill->spillpot;})
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
void getPredictions(unsigned int timestamp, unsigned int nDays, std::string naming)
Definition: GetSpectra.h:13
std::string fname
Definition: CutFlow_Data.C:30
const Cut kCut
Definition: VarsAndCuts.h:36
#define SIMPLEVAR(CAFNAME)
Definition: Var.h:11
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
Definition: Var.h:14
const Cut kNoCut
Definition: Cut.h:13
static NullLoader kNullLoader
Dummy loader that doesn&#39;t load any files.
const Var kXSecCVWgt2020
Definition: XsecTunes.h:105
enum BeamMode string