drawShortTerm_2019.C
Go to the documentation of this file.
1 #include "CAFAna/Cuts/Cuts.h"
4 #include "CAFAna/Cuts/NumuCuts2018.h"
5 #include "CAFAna/Core/Loaders.h"
7 #include "CAFAna/Core/Spectrum.h"
9 #include "CAFAna/Vars/NumuVars.h"
10 #include "CAFAna/Vars/Vars.h"
11 #include "CAFAna/Analysis/Calcs.h"
12 #include "CAFAna/Analysis/Plots.h"
13 
15 
16 #include "TStyle.h"
17 #include "TCanvas.h"
18 #include "TGraph.h"
19 #include "TGraphAsymmErrors.h"
20 #include "TFile.h"
21 #include "TH1.h"
22 #include "TH2.h"
23 #include "TLegend.h"
24 #include "TLatex.h"
25 #include "TProfile.h"
26 
27 #include "VarsAndCuts_2019.h"
28 #include "Periods_2019.h"
29 #include "CustomFunctions_2019.h"
30 
31 
32 using namespace ana;
33 
34 void drawShortTerm_2019(std::string samDef, unsigned int endTime, unsigned int nDays, std::string s_PeriodLength, std::string outDir)
35 {
36  //SET SIG FIGS.
37  gStyle->SetStatFormat("6.3g");
38  gStyle->SetPaintTextFormat("6.3g");
39  gStyle->SetFitFormat("6.3g");
40 
41  //DEFINE A TFILE TO WRITE ALL CANVASES TO.
42  TFile *f_Out = new TFile((TString)(outDir+"BeamMonitoring_"+s_PeriodLength+"_ShortTerm.root"),"RECREATE");
43 
44  //APPLY TIME CUTS TO DATASET, DEFINE THE LOADER AND SET SPILL CUTS.
45  unsigned int startTime = endTime - 86400*nDays;
46  const std::string fFiles = "dataset_def_name_newest_snapshot " + samDef + Form(" and online.subrunendtime >= '%u' and online.subrunendtime <= '%u'", startTime, endTime);
47  SpectrumLoader loader(fFiles);
49 
50  const Binning kTimeBinning = Binning::Simple(nDays < 3 ? 24*nDays : nDays+1, startTime, startTime + 86400*(nBins+1));
51  const Cut kNumuNDCut = kNumuCutND2018;
52 
53  //DEFINE PLOTS OF THE VARIABLES WE WANT TO SHOW.
54  std::vector<Plot> vec_Plots = {
55  {"Central Time", "Spill POT (#times10^{12})", "spillPOT", Binning::Simple(100,0,100), kSpillPOT, kNoCut, 1.0, 1. },
56  {"Central Time", "Reconstructed Neutrino Energy, (GeV)", "ccE", Binning::Simple(20,0,5), kCCE, kNumuNDCut, 1.5, 2.2 },
57  {"Central Time", "Reconstructed Hadronic Energy, (GeV)", "hadE", Binning::Simple(30,0,3), kHadE, kNumuNDCut, 0.15, 0.50},
58  {"Central Time", "Reconstructed Muon Energy, (GeV)", "muonE", Binning::Simple(45,0,4.5), kMuE, kNumuNDCut, 1.0, 2.0 },
59  {"Central Time", "Hadronic Energy Fraction", "hadEfrac", Binning::Simple(20,0,1.0), kHadEFrac, kNumuNDCut, 0.05, 0.3 },
60  {"Central Time", "No. of Hits", "nhit", Binning::Simple(25,0,250), kNHit, kNumuNDCut, 90, 110 },
61  {"Central Time", "Vertex X, (m)", "startX", Binning::Simple(40,-2,2), kTrkStartX, kNumuNDCut, -0.40, 0.0 },
62  {"Central Time", "Vertex Y, (m)", "startY", Binning::Simple(40,-2,2), kTrkStartY, kNumuNDCut, -0.25, 0.15},
63  {"Central Time", "Vertex Z, (m)", "startZ", Binning::Simple(24,0,12), kTrkStartZ, kNumuNDCut, 4.8, 6.25}
64  };
65 
66  std::vector<Spectrum*> vec_Spectrum;
67  std::vector<TCanvas*> vec_Canvas;
68 
69  for(unsigned int i = 0; i < vec_Plots.size(); i++)
70  {
71  Spectrum *h_Spectrum = new Spectrum(vec_Plots.at(i).fLabelX, vec_Plots.at(i).fLabelY, loader, kTimeBinning, kTime, vec_Plots.at(i).fBins, vec_Plots.at(i).fVar, vec_Plots.at(i).fCut);
72  vec_Spectrum.push_back(h_Spectrum);
73  TCanvas *c_Spectrum = new TCanvas((TString)("c_"+vec_Plots.at(i).fName+"_"+s_PeriodLength),(TString)("c_"+vec_Plots.at(i).fName+"_"+s_PeriodLength));
74  c_Spectrum->SetBottomMargin(0.15);
75  c_Spectrum->SetLeftMargin (0.15);
76  c_Spectrum->SetRightMargin (0.15);
77  vec_Canvas.push_back(c_Spectrum);
78  }
79 
80  loader.Go();
81 
82  for(unsigned int i = 0; i < vec_Plots.size(); i++)
83  {
84  vec_Canvas.at(i)->cd();
85  TH2 *h_2D = vec_Spectrum.at(i)->ToTH2(vec_Spectrum.at(i)->POT());
86  h_2D->SetName((TString)("h_2D_"+vec_Plots.at(i).fName+s_PeriodLength));
87  h_2D->SetTitle("");
88  h_2D->GetXaxis()->CenterTitle();
89  h_2D->GetYaxis()->CenterTitle();
90  h_2D->GetXaxis()->SetTimeDisplay(1);
91  if (nDays >= 15) {h_2D->GetXaxis()->SetTimeFormat("%y-%m-%d%F1970-01-01 00:00:00"); }
92  else if(nDays > 3 && nDays < 15){h_2D->GetXaxis()->SetTimeFormat("%y-%m-%d-%H:%M%F1970-01-01 00:00:00");}
93  else {h_2D->GetXaxis()->SetTimeFormat("%H:%M%F1970-01-01 00:00:00"); }
94 
95  unsigned int minBin = h_2D->GetXaxis()->FindBin(startTime);
96  unsigned int maxBin = h_2D->GetXaxis()->FindBin(endTime);
97 
98  double minZoom = h_2D->GetXaxis()->GetBinLowEdge(minBin-1);
99  double maxZoom = h_2D->GetXaxis()->GetBinLowEdge(maxBin+2);
100 
101  h_2D->GetXaxis()->SetRangeUser(minZoom, maxZoom);
102 
103  TProfile *h_Prof1 = h_2D->ProfileX((TString)("h_Prof1_"+vec_Plots.at(i).fName+"_"+s_PeriodLength));
104  TProfile *h_Prof2 = h_2D->ProfileX((TString)("h_Prof2_"+vec_Plots.at(i).fName+"_"+s_PeriodLength));
105  h_Prof1->SetMarkerStyle(24);
106  h_Prof1->SetMarkerColor(kBlack);
107  h_Prof1->SetLineColor (kBlack);
108  h_Prof1->SetMarkerSize(1.4);
109  h_Prof2->SetMarkerStyle(20);
110  h_Prof2->SetMarkerColor(kYellow);
111  h_Prof2->SetLineColor (kYellow);
112  h_Prof2->SetMarkerSize(1.4);
113 
114  h_2D ->Draw("COLZ");
115  h_Prof2->Draw("SAME");
116  h_Prof1->Draw("SAME");
117 
118  TLatex *txt_Exposure = new TLatex(0.2, 0.8, Form("%6.3g POT", vec_Spectrum.at(i)->POT()));
119  txt_Exposure->SetNDC();
120  txt_Exposure->SetTextSize(0.04);
121  txt_Exposure->Draw();
122  lastUpdated(endTime);
123 
124  vec_Canvas.at(i)->SaveAs((TString)(outDir+vec_Plots.at(i).fName+"_"+s_PeriodLength+"_ShortTerm.png"));
125  f_Out->cd();
126  vec_Canvas.at(i)->Write();
127  vec_Canvas.at(i)->Clear();
128  vec_Canvas.at(i)->SetName((TString)("c_1D_"+vec_Plots.at(i).fName+"_"+s_PeriodLength));
129 
130  TH1D *h_1D = h_2D->ProjectionY((TString)("h_1D_"+vec_Plots.at(i).fName+s_PeriodLength));
131  h_1D->Draw("HIST");
132  vec_Canvas.at(i)->Write();
133  }
134 
135  std::cout << "ALL PLOTS MADE" << std::endl;
136 }
const Var kHadE
Definition: NumuVars.h:23
int nBins
Definition: plotROC.py:16
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
const Cut kNumuCutND2018
Definition: NumuCuts2018.h:41
const Var kTrkStartY([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-10.0f;return sr->trk.kalman.tracks[0].start.Y()/100;})
Definition: NumuVars.h:52
void SetSpillCut(const SpillCut &cut)
std::string outDir
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:33
void drawShortTerm_2019(std::string samDef, unsigned int endTime, unsigned int nDays, std::string s_PeriodLength, std::string outDir)
const Var kTime
Definition: VarsAndCuts.h:33
void lastUpdated(unsigned int timestamp)
const Var kSpillPOT
Return the POT for the spill.
Definition: SpillVars.cxx:33
const Var kHadEFrac
Definition: NumuVars.h:24
const Var kNHit
Definition: Vars.cxx:71
const Var kTrkStartZ([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-10.0f;return sr->trk.kalman.tracks[0].start.Z()/100;})
Definition: NumuVars.h:53
const Var kCCE
Definition: NumuVars.h:21
virtual void Go() override
Load all the registered spectra.
loader
Definition: demo0.py:10
const Var kTrkStartX([](const caf::SRProxy *sr){if(sr->trk.kalman.ntracks< 1) return-10.0f;return sr->trk.kalman.tracks[0].start.X()/100;})
Definition: NumuVars.h:51
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:46
const Var kMuE
Definition: NumuVars.h:22
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:38
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:117
std::vector< Plot > vec_Plots