GetSpectra.h
Go to the documentation of this file.
1 const int kNumPlots = 11;
2 
3 struct Plot
4 {
7  Binning bins;
8  Var var;
9 };
10 
11 
12 void getPredictions(unsigned int timestamp, unsigned int nDays, std::string naming){
13 
14  std::cout << "\n=================" << std::endl;
15  std::cout << "getPredictions.C" << std::endl;
16  std::cout << "=================\n" <<std::endl;
17 
19  {
20  {"Slice time [#mus]", "tus", Binning::Simple(25,73,373), kSliceTime},
21  {"Run", "run", Binning::Simple(15000, 15000, 30000), SIMPLEVAR(hdr.run)},
22  {"Time", "time", 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", Binning::Simple(360,205,241), kSliceTime},
25  {"No. Kalman tracks", "nkal", Binning::Simple(10, 0, 10), SIMPLEVAR(trk.kalman.ntracks)},
26  {"No. Hits", "nhit", Binning::Simple(10, 0, 500), kNHit},
27  {"Kalman angle", "angkal", Binning::Simple(5, 0, 1), SIMPLEVAR(sel.cosrej.anglekal)},
28  {"Z direction", "dirz", Binning::Simple(5, 0.5, 1), kDirZ},
29  {"BDT", "bdt", Binning::Simple(20, 0, 1), kNumuContPID},
30  {"p_{T}/p", "ptp", Binning::Simple(20, 0, 1), kPtP}
31  };
32 
33 
34  std::cout << "Setting loaders ..." << std::endl;
35  //SpectrumLoader fd_nonswap("prod_caf_R17-11-14-prod4reco.e_fd_genie_nonswap_rhc_nova_v08_full_v1");
36  //SpectrumLoader fd_fluxswap("prod_caf_R17-11-14-prod4reco.e_fd_genie_fluxswap_rhc_nova_v08_full_v1");
37  SpectrumLoader fd_nonswap("prod_caf_R17-11-14-prod4reco.d_fd_genie_nonswap_fhc_nova_v08_full_v1");
38  SpectrumLoader fd_fluxswap("prod_caf_R17-11-14-prod4reco.d_fd_genie_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*kXSecCVWgt2018);
46  }
47 
48  Spectrum nonSwapDenom("NHits", Binning::Simple(100, 0, 1000), fd_nonswap, kNHit, kNoCut, kNoShift, kWOscDumbHere);
49  Spectrum swapDenom("NHits", Binning::Simple(100, 0, 1000), fd_fluxswap, 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->mkdir( (p.fname).c_str() ));
62  }
63 
64  nonSwapDenom.SaveTo(file->mkdir("nonSwapDenom"));
65  swapDenom.SaveTo(file->mkdir("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  //fFiles = "defname: " + samdef;
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  SpectrumLoader loader(fFiles);
92 
93  std::cout << "Defining spectrums ..." << std::endl;
94  Spectrum* hData[kNumPlots];
95  Spectrum* hBkg[kNumPlots];
96 
98  {
99  {"Slice time [#mus]", "tus", Binning::Simple(25,73,373), kSliceTime},
100  {"Run", "run", Binning::Simple(15000, 15000, 30000), SIMPLEVAR(hdr.run)},
101  {"Time", "time", Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), SIMPLEVAR(hdr.unixtime)},
102  {"Max y [m]", "maxy", kXYBins, kBoxMaxY},
103  {"Slice time [#mus]", "tighttus", Binning::Simple(360,205,241), kSliceTime},
104  {"No. Kalman tracks", "nkal", Binning::Simple(10, 0, 10), SIMPLEVAR(trk.kalman.ntracks)},
105  {"No. Hits", "nhit", Binning::Simple(10, 0, 500), kNHit},
106  {"Kalman angle", "angkal", Binning::Simple(5, 0, 1), SIMPLEVAR(sel.cosrej.anglekal)},
107  {"Z direction", "dirz", Binning::Simple(5, 0.5, 1), kDirZ},
108  {"BDT", "bdt", Binning::Simple(20, 0, 1), kNumuContPID},
109  {"p_{T}/p", "ptp", Binning::Simple(20, 0, 1), kPtP}
110  };
111 
112 
113  for(int i = 0; i < kNumPlots; ++i){
114  Plot p = plots[i];
115  hData[i] = new Spectrum(p.label, p.bins, loader, p.var, i <= 1 ? kCut : kCut && kInTimeTight, kNoShift, kUnweighted);
116  hBkg[i] = new Spectrum(p.label, p.bins, loader, p.var, kCut && !kInTimeTight, kNoShift, kUnweighted);
117  }
118 
119  Spectrum potTime(";Date;POT #times Mass", loader, Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), SIMPLEVAR(hdr.unixtime), Binning::Simple(500,0,50e12),kMassFracPOT, kNoCut, kNoShift, kUnweighted);
120  Spectrum massDenom("", Binning::Simple(1, 0, 1), loader, kUnweighted, kNoCut, kNoShift, kSpillPOT);
121  Spectrum massNum("", Binning::Simple(1, 0, 1), loader, kUnweighted, kNoCut, kNoShift, kMassFracPOT);
122 
123  std::cout << "Loaders Go ..." << std::endl;
124  loader.Go();
125 
126 
127  std::string fileName = "dataspectra_" + naming + ".root";
128  std::cerr << "Saving predictions to file: " << fileName << std::endl;
129  TFile *file = TFile::Open(fileName.c_str(), "RECREATE");
130 
131  for(int i = 0; i < kNumPlots; ++i){
132  Plot p = plots[i];
133  hData[i]->SaveTo(file->mkdir( ("data_"+p.fname).c_str() ));
134  hBkg[i]->SaveTo(file->mkdir( ("bkg_"+p.fname).c_str() ));
135  }
136 
137  potTime.SaveTo(file->mkdir("potTime"));
138  massDenom.SaveTo(file->mkdir("massDenom"));
139  massNum.SaveTo(file->mkdir("massNum"));
140 
141  file->Close();
142 
143  std::cout << "Spectra made! \n" << std::endl;
144 
145 }// getData
const Var kDirZ([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return 0.f;return sr->trk.kalman.tracks[0].dir.Z();})
fileName
Definition: plotROC.py:78
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
GenericVar< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:76
std::string label
Definition: CutFlow_Data.C:29
const char * p
Definition: xmltok.h:285
const Var kSliceTime([](const caf::SRProxy *sr){return sr->hdr.unixtime;})
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 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 Var kNumuContPID
Definition: VarsAndCuts.h:36
const int kNumPlots
Definition: GetSpectra.h:1
const std::vector< Plot > plots
const Binning kXYBins
Definition: VarsAndCuts.h:95
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.h:115
OStream cout
Definition: OStream.cxx:6
#define SIMPLEVAR(CAFNAME)
For Vars where literally all you need is a single CAF variable.
Definition: Var.h:94
void getPredictions(unsigned int timestamp, unsigned int nDays, std::string naming)
Definition: GetSpectra.h:12
std::string fname
Definition: CutFlow_Data.C:30
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Var kXSecCVWgt2018
Definition: XsecTunes.h:49
const Cut kCut
Definition: VarsAndCuts.h:36
Binning bins
Definition: CutFlow_Data.C:31
Var var
Definition: CutFlow_Data.C:32
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:100
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:117
kNHit
Definition: demo1.py:19
static NullLoader kNullLoader
Dummy loader that doesn&#39;t load any files.