getBNBPlots.C
Go to the documentation of this file.
1 #ifdef __CINT__
2 void getBNBPlots(std::string samdef, unsigned int timestamp, unsigned int nDays, std::string naming)
3 {
4  std::cout << "Sorry, you must run in compiled mode" << std::endl;
5 }
6 #else
7 
10 #include "CAFAna/Core/EventList.h"
13 #include "CAFAna/Core/Spectrum.h"
14 #include "CAFAna/Cuts/Cuts.h"
15 #include "CAFAna/Vars/Vars.h"
16 // give the full path; jobs die in the grid if not
17 #include "CustomFunctions.h"
18 #include "VarsAndCuts.h"
19 
20 using namespace ana;
21 
22 #include "TCanvas.h"
23 #include "TF2.h"
24 #include "TFile.h"
25 #include "TGraph.h"
26 #include "TGraphAsymmErrors.h"
27 #include "TGraphErrors.h"
28 #include "TH1D.h"
29 #include "TH2D.h"
30 #include "TLatex.h"
31 #include "TLegend.h"
32 #include "TMath.h"
33 #include "TPad.h"
34 #include "TPaveLabel.h"
35 #include "TProfile.h"
36 #include "TStyle.h"
37 #include "TTimeStamp.h"
38 
39 void lastUpdated(unsigned int timestamp);
40 
41 void getBNBPlots(std::string samdef, unsigned int timestamp, unsigned int nDays, std::string naming)
42 {
43  unsigned int fhcStart = 1551204000; //12pm Central time, Feb 26th 2019.
44  const std::string fFiles = "defname: " + samdef + Form(" and online.subrunendtime >= '%u' and online.subrunendtime <= '%u' and online.subrunendtime >= '%u'", timestamp - 86400*nDays, timestamp, fhcStart);
45  SpectrumLoader loader(fFiles);
46 
47  // Hacky way of getting the livetime. Do as I say...
48  TH1D* hLiveTime = new TH1D("hLiveTime",";Livetime (s)", 1, 0, 1);
50 
51  struct Plot
52  {
55  Binning bins;
56  Var var;
57  };
58 
59  const int kNumPlots = 1;
61  {
62  {"Slice time [#mus]", "tus", Binning::Simple(45,25,475), kSliceTime}
63  };
64 
65  Spectrum* hData[kNumPlots];
66  Spectrum* hBkg[kNumPlots];
67 
68  for(int i = 0; i < kNumPlots; ++i){
69  Plot p = plots[i];
70  // Don't apply time cut for timing and runs plots, do for everything else
71  hData[i] = new Spectrum(p.label, p.bins, loader, p.var, kCut);
72  }
73 
74  loader.Go();
75 
76  for(int i = 0; i < kNumPlots; ++i){
77 
78  hData[0]->OverrideLivetime(hLiveTime->Integral());
79 
80  std::cout << "Calculated livetime: " << hData[0]->Livetime() << std::endl;
81 
82  new TCanvas;
83  TH1* hSig = hData[i]->ToTH1(hData[i]->Livetime(), kLivetime);
84  hSig->SetName(("sig_"+plots[i].fname).c_str());
85  // hSig->GetYaxis()->SetNdivisions(0);
86 
87  // TGraphAsymmErrors* grSig = GraphWithPoissonErrors(hSig, true, false);
88  hSig->SetLineColor(kBlue);
89  hSig->SetLineWidth(1);
90  hSig->SetMarkerColor(kBlue);
91  // hSig->GetYaxis()->SetRangeUser(0,hSig->GetMaximum()*1.12+4.);
92  hSig->Draw("hist");
93  // grSig->SetMarkerColor(kBlack);
94  // grSig->SetLineColor(kBlack);
95  // grSig->SetLineWidth(2);
96  // grSig->SetName(("grSig_"+plots[i].fname).c_str());
97  // grSig->Draw("P");
98 
99  int fSignal = (int) hSig->GetBinContent(30);
100  double fBKG = (hSig->Integral() - fSignal)*1./(44);
101  double prob = TMath::PoissonI(fSignal,fBKG);
102 
103  TLatex p1(0.15,0.80,Form("Evts. in time peak: %i",fSignal));
104  TLatex p2(0.15,0.75,Form("BKG. estimate: %6.2g", fBKG));
105  TLatex p3(0.15,0.70,Form("Probability: %6.2g", prob));
106 
107  p1.SetNDC();
108  p1.SetTextSize(0.04);
109  p1.Draw();
110  p2.SetNDC();
111  p2.SetTextSize(0.04);
112  p2.Draw();
113  p3.SetNDC();
114  p3.SetTextSize(0.04);
115  p3.Draw();
116 
117  TGraph g1,g2,g3;
118  g1.SetPoint(0,315,0);
119  g1.SetPoint(1,315,1e99);
120  g2.SetPoint(0,325,0);
121  g2.SetPoint(1,325,1e99);
122  g3.SetPoint(0,0,fBKG);
123  g3.SetPoint(1,500,fBKG);
124 
125  g1.SetLineColor(kRed);
126  g2.SetLineColor(kRed);
127  g3.SetLineColor(kPink);
128  g1.SetLineStyle(7);
129  g2.SetLineStyle(7);
130  g3.SetLineStyle(2);
131  g1.Draw("L");
132  g2.Draw("L");
133  g3.Draw("L");
134 
135  lastUpdated(timestamp);
136  gPad->SaveAs(("/nova/ana/users/novadq/TimePeak/BNB/plots/" + plots[i].fname + "_" + naming + ".root").c_str());
137  gPad->SaveAs(("/nova/ana/users/novadq/TimePeak/BNB/plots/" + plots[i].fname + "_" + naming + ".png").c_str());
138 
139  } // End loop over i
140 
141 }
142 
143 #endif
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
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:209
std::string label
Definition: CutFlow_Data.C:29
const char * p
Definition: xmltok.h:285
const Var kSliceTime([](const caf::SRProxy *sr){return sr->slc.meantime/1000;})
Definition: NumuVars.h:34
void lastUpdated(unsigned int timestamp)
void getBNBPlots(std::string samdef, unsigned int timestamp, unsigned int nDays, std::string naming)
Definition: getBNBPlots.C:41
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:33
const char * label
const SpillVar kSpillUnweighted
Definition: Var.h:102
====================================================================== ///
Definition: CutFlow_Data.C:28
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 int kNumPlots
Definition: GetSpectra.h:1
const std::vector< Plot > plots
virtual void Go() override
Load all the registered spectra.
void OverrideLivetime(double newlive)
DO NOT USE UNLESS YOU ARE 110% CERTAIN THERE ISN&#39;T A BETTER WAY!
Definition: Spectrum.h:240
loader
Definition: demo0.py:10
std::vector< float > Spectrum
Definition: Constants.h:527
const SpillCut kNoSpillCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:120
OStream cout
Definition: OStream.cxx:6
const Binning bins
Definition: NumuCC_CPiBin.h:8
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const Cut kCut
Definition: VarsAndCuts.h:36
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:38
double Livetime() const
Seconds. For informational purposes only. No calculations use this.
Definition: Spectrum.h:234
const Var kSpillLivetime
Return the Livetime for the spill.
Definition: SpillVars.cxx:36