getTimePeakTotal.C
Go to the documentation of this file.
1 #include "TCanvas.h"
2 #include "TF2.h"
3 #include "TFile.h"
4 #include "TGraph.h"
5 #include "TGraphErrors.h"
6 #include "TGraphAsymmErrors.h"
7 #include "TH1D.h"
8 #include "TH2D.h"
9 #include "THStack.h"
10 #include "TLegend.h"
11 #include "TLine.h"
12 #include "TMath.h"
13 #include "TPad.h"
14 #include "TPaveLabel.h"
15 #include "TProfile.h"
16 #include "TStyle.h"
17 #include "TTimeStamp.h"
18 
19 #include "OscLib/OscCalcPMNSOpt.h"
21 
22 #include "CAFAna/Analysis/Calcs.h"
23 #include "CAFAna/Analysis/Plots.h"
24 #include "CAFAna/Core/Binning.h"
25 #include "CAFAna/Core/EventList.h"
28 #include "CAFAna/Core/Spectrum.h"
30 #include "CAFAna/Cuts/Cuts.h"
34 
35 
36 
37 
38 #include "CAFAna/Cuts/TimingCuts.h"
42 #include "CAFAna/Vars/Vars.h"
43 #include "CAFAna/Vars/TruthVars.h"
44 #include "CAFAna/Vars/XsecTunes.h"
47 
50 
51 using namespace ana;
52 
53 
54 struct Plot
55 {
58  Binning bins;
59  Var var;
60 };
61 
62 void getTimePeakTotal(std::string samdef = "" , std::string s_Period = "" )
63 {
64 
65  SpectrumLoader loader(samdef);
66  int timestamp = 1610474064;
67  int nDays = 41;
68  const int kNumPlots = 11;
69 
70 
71  //ADDED THIS SO THAT CAN COUNT NUMBER OF SPILLS.
72  const SpillVar kCountMySpills([](const caf::SRSpillProxy* sp){
73  return sp->isgoodspill;
74  });
75  TH1D *hSpill = new TH1D("hSpill", "hSpill", 2, -0.5, 1.5);
76  loader.AddSpillHistogram(hSpill, kCountMySpills, kNoSpillCut);
77 
78 
79  Spectrum* hData[kNumPlots];
80  Spectrum* hBkg[kNumPlots];
81 
83  {
84  {"Slice time [#mus]", "tus", Binning::Simple(45,1,541), ana::kSliceTime},
85  {"Run", "run", Binning::Simple(15000, 15000, 30000), SIMPLEVAR(hdr.run)},
86  {"Time", "time", Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), SIMPLEVAR(hdr.unixtime)},
87  {"Max y [m]", "maxy", kXYBins, kBoxMaxY},
88  {"Slice time [#mus]", "tighttus", Binning::Simple(360,205,241), ana::kSliceTime},
89  {"No. Kalman tracks", "nkal", Binning::Simple(10, 0, 10), SIMPLEVAR(trk.kalman.ntracks)},
90  {"No. Hits", "nhit", Binning::Simple(10, 0, 500), ana::kNHit},
91  {"Kalman angle", "angkal", Binning::Simple(5, 0, 1), SIMPLEVAR(sel.cosrej.anglekal)},
92  {"Z direction", "dirz", Binning::Simple(5, 0.5, 1), ana::kDirZ},
93  {"BDT", "bdt", Binning::Simple(20, 0, 1), ana::kNumuContPID},
94  {"p_{T}/p", "ptp", Binning::Simple(20, 0, 1), ana::kPtP}
95  };
96 
97  for(int i = 0; i < kNumPlots; ++i){
98  Plot p = plots[i];
99  hData[i] = new Spectrum(p.label, p.bins, loader, p.var, i <= 1 ? kCut : kCut && kInTimeTight, kNoShift, kUnweighted);
100  hBkg[i] = new Spectrum(p.label, p.bins, loader, p.var, kCut && !kInTimeTight, kNoShift, kUnweighted);
101  }
102 
103  Spectrum potTime("Date","POT #times Mass", loader, Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), SIMPLEVAR(hdr.unixtime),
105  Spectrum massDenom("", Binning::Simple(1, 0, 1), loader, kUnweighted, kNoCut, kNoShift, kSpillPOT);
106  Spectrum massNum("", Binning::Simple(1, 0, 1), loader, kUnweighted, kNoCut, kNoShift, kMassFracPOT);
107  Spectrum *hSig_time = new Spectrum("time", Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), loader,
108  SIMPLEVAR(hdr.unixtime),kCut && kInTimeTight,kNoShift,kUnweighted);
109 
110  Spectrum *hBkg_time = new Spectrum("time", Binning::Simple(nDays<3 ? 24*nDays : nDays,timestamp - 86400*nDays,timestamp), loader,
111  SIMPLEVAR(hdr.unixtime),kCut && !kInTimeTight, kNoShift,kUnweighted);
112 
113  loader.Go();
114 
115 
116 
117  std::string fileName = "dataspectra_"+s_Period+".root";
118  TFile *file = TFile::Open(fileName.c_str(), "RECREATE");
119 
120  for(int i = 0; i < kNumPlots; ++i){
121  Plot p = plots[i];
122  hData[i]->SaveTo(file, ("data_"+p.fname).c_str() );
123  hBkg[i]->SaveTo(file, ("bkg_"+p.fname).c_str() );
124  }
125 
126  potTime.SaveTo(file, "potTime");
127  massDenom.SaveTo(file, "massDenom");
128  massNum.SaveTo(file, "massNum");
129  hSig_time->SaveTo(file, "sig_time");
130  hBkg_time->SaveTo(file,"BKG_time");
131  hSpill->Write();
132 
133 
134  file->Close();
135 
136  std::cout << "Spectra made! \n" << std::endl;
137 
138 }
fileName
Definition: plotROC.py:78
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::string label
Definition: CutFlow_Data.C:29
const Var kNumuContPID
Definition: NumuVars.cxx:553
const char * p
Definition: xmltok.h:285
const Var kSliceTime([](const caf::SRProxy *sr){return sr->slc.meantime/1000;})
Definition: NumuVars.h:34
void getTimePeakTotal(std::string samdef="", std::string s_Period="")
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
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
Track finder for cosmic rays.
const Var kPtP
Transverse momentum fraction in slice.
Definition: NueVars.cxx:90
====================================================================== ///
Definition: CutFlow_Data.C:28
caf::Proxy< bool > isgoodspill
Definition: SRProxy.h:1377
virtual void AddSpillHistogram(TH1 *h, const SpillVar &var, const SpillCut &cut, const SpillVar &wei=kSpillUnweighted)
Uses include counting the total POT or spills in a run.
const Var kSpillPOT
Return the POT for the spill.
Definition: SpillVars.cxx:33
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
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
loader
Definition: demo0.py:10
std::vector< float > Spectrum
Definition: Constants.h:728
const SpillCut kNoSpillCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:112
Proxy for caf::SRSpill.
Definition: SRProxy.h:1346
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::string fname
Definition: CutFlow_Data.C:30
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
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
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
enum BeamMode string