4 #include "CAFAna/Cuts/NumuCuts2018.h" 16 #include "TGraphErrors.h" 17 #include "TGraphAsymmErrors.h" 24 #include "TTimeStamp.h" 25 #include "TPaveLabel.h" 35 gStyle->SetOptFit(1111);
38 TFile *f_Out =
new TFile((TString)(outDir+
"BeamMonitoring_IntensityEffect.root"),
"RECREATE");
41 unsigned int startTime = endTime - 86400*nDays;
42 const std::string fFiles =
"dataset_def_name_newest_snapshot " + samdef + Form(
" and online.subrunendtime >= '%u' and online.subrunendtime <= '%u'", startTime, endTime);
52 std::vector<TH1D*> vec_hPOT;
53 std::vector<TH1D*> vec_hNumPOT;
57 TH1D *hPOT =
new TH1D(Form(
"hPOT_Period%i",
i),
";POT (10^{15});POT (10^{15})", 1000, 0, 100);
58 TH1D *hNumPOT =
new TH1D(Form(
"hNumPOT_Period%i",
i),
";POT (10^{15});POT (10^{15})", 1, 0.5, 1.5);
59 vec_hPOT .push_back(hPOT);
60 vec_hNumPOT.push_back(hNumPOT);
69 {
"Central Time",
"Number of slices / 10^{15} POT",
"slices", kSingleBin,
kUnweighted, kNumuNDCut, 0, 2.0}
72 std::map<std::pair<unsigned int,unsigned int>,
Spectrum*> map_PeriodAndVarToSpectrum;
73 std::map<std::string,TCanvas*> map_VarToCanvas;
75 for(
unsigned int i = 0;
i < vec_hPOT.size();
i++)
77 for(
unsigned int j = 0;
j < vec_Plots.size();
j++)
81 map_PeriodAndVarToSpectrum[{
i,
j}] = h_Spectrum;
84 map_VarToCanvas[vec_Plots.at(
j).fName] =
new TCanvas((TString)(
"c_"+vec_Plots.at(
j).fName+
"_IntensityEffect"),(TString)(
"c_"+vec_Plots.at(
j).fName+
"_IntensityEffect"));
85 map_VarToCanvas[vec_Plots.at(
j).fName]->SetBottomMargin(0.15);
86 map_VarToCanvas[vec_Plots.at(
j).fName]->SetLeftMargin (0.15);
87 map_VarToCanvas[vec_Plots.at(
j).fName]->SetRightMargin (0.15);
88 map_VarToCanvas[vec_Plots.at(
j).fName+
"_AllPeriods"] =
new TCanvas((TString)(
"c_"+vec_Plots.at(
j).fName+
"_AllPeriods_IntensityEffect"),
89 (TString)(
"c_"+vec_Plots.at(
j).fName+
"_AllPeriods_IntensityEffect"));
90 map_VarToCanvas[vec_Plots.at(
j).fName+
"_AllPeriods"]->SetBottomMargin(0.15);
91 map_VarToCanvas[vec_Plots.at(
j).fName+
"_AllPeriods"]->SetLeftMargin (0.15);
92 map_VarToCanvas[vec_Plots.at(
j).fName+
"_AllPeriods"]->SetRightMargin (0.15);
99 TLegend*
leg =
new TLegend(0.17,0.17,0.83,0.4);
100 leg->SetFillColor(0);
103 TGraphErrors *g_AllPeriods =
new TGraphErrors;
104 g_AllPeriods->SetTitle(
"");
105 g_AllPeriods->SetMarkerStyle(20);
106 g_AllPeriods->SetMarkerColor(kBlack);
107 g_AllPeriods->SetLineColor(kBlack);
108 g_AllPeriods->GetXaxis()->CenterTitle();
109 g_AllPeriods->GetYaxis()->CenterTitle();
110 g_AllPeriods->GetXaxis()->SetTitle(
"Slices / 10^{9} POT");
111 g_AllPeriods->GetYaxis()->SetTitle(
"Average POT / 10^{12}");
114 for(
auto spectrum : map_PeriodAndVarToSpectrum)
116 TH2 *h_2D = spectrum.second->ToTH2(spectrum.second->POT());
117 TProfile *h_Prof = h_2D->ProfileX((TString)(
"prof_"+vec_Plots.at(spectrum.first.second).fName+
"_"+Form(
"%i_%i",
datasets[spectrum.first.first].fYear,
datasets[spectrum.first.first].fMonth)));
118 h_Prof->SetMarkerStyle(
datasets[spectrum.first.first].fStyle);
119 h_Prof->SetMarkerColor(
datasets[spectrum.first.first].fColor);
120 h_Prof->SetLineColor (
datasets[spectrum.first.first].fColor);
121 h_Prof->SetMarkerSize (1.4);
122 if(spectrum.first.first==0)
124 map_VarToCanvas[vec_Plots.at(spectrum.first.second).fName]->cd();
125 h_Prof->SetTitle(
"");
126 h_Prof->GetXaxis()->SetTitle((TString)spectrum.second->GetLabels().at(0));
127 h_Prof->GetYaxis()->SetTitle((TString)spectrum.second->GetLabels().at(1));
128 h_Prof->GetXaxis()->CenterTitle();
129 h_Prof->GetYaxis()->CenterTitle();
133 TGraphErrors *
g =
new TGraphErrors;
134 g->SetName((TString)(
"1D_"+vec_Plots.at(spectrum.first.second).fName+
"_"+Form(
"%i_%i",
datasets[spectrum.first.first].fYear,
datasets[spectrum.first.first].fMonth)));
135 double y = h_2D->Integral();
137 double x = vec_hPOT.at(spectrum.first.first) ->GetMean();
138 double npot = vec_hNumPOT.at(spectrum.first.first)->Integral()/1000.;
140 g->SetMarkerStyle(
datasets[spectrum.first.first].fStyle);
141 g->SetMarkerColor(
datasets[spectrum.first.first].fColor);
142 g->SetLineColor (
datasets[spectrum.first.first].fColor);
143 if(x > 0 && npot > 0)
145 g->SetPoint (0, x, y/npot);
146 g->SetPointError(0, 0, dy/npot);
148 g_AllPeriods->SetPoint (g_AllPeriods->GetN(),
x, y/npot );
149 g_AllPeriods->SetPointError(g_AllPeriods->GetN()-1, 0, dy/npot);
152 if(spectrum.first.first==0)
154 TH2D* h_Canvas =
new TH2D(
"h_Canvas",
"",100, 20, 70, 100, vec_Plots.at(spectrum.first.second).fYRangeLow, vec_Plots.at(spectrum.first.second).fYRangeHigh);
155 h_Canvas->GetXaxis()->CenterTitle();
156 h_Canvas->GetYaxis()->CenterTitle();
157 h_Canvas->GetYaxis()->SetTitle(
"Slices / 10^{9} POT");
158 h_Canvas->GetXaxis()->SetTitle(
"Average POT / 10^{12}");
159 h_Canvas->SetLineColor(0);
160 h_Canvas->SetLineWidth(0);
162 map_VarToCanvas[vec_Plots.at(spectrum.first.second).fName+
"_AllPeriods"]->cd();
164 map_VarToCanvas[vec_Plots.at(spectrum.first.second).fName]->cd();
171 map_VarToCanvas[vec_Plots.at(spectrum.first.second).fName]->cd();
174 if(spectrum.first.second==0)
176 map_VarToCanvas[vec_Plots.at(spectrum.first.second).fName]->cd();
177 leg->AddEntry(g, (TString)
datasets[spectrum.first.first].fLabel,
"P");
179 if(spectrum.first.first==
datasets.size()-1)
183 map_VarToCanvas[vec_Plots.at(spectrum.first.second).fName+
"_AllPeriods"]->cd();
184 g_AllPeriods->Draw(
"P");
185 g_AllPeriods->Fit(
"pol1");
190 for(
auto it : map_VarToCanvas)
192 it.second->SaveAs((TString)(outDir+
it.first+
"_IntensityEffect.png"));
const SpillVar kPOTe12([](const caf::SRSpillProxy *spill){return spill->spillpot/1e12;})
Represent the binning of a Spectrum's x-axis.
Cuts and Vars for the 2020 FD DiF Study.
std::vector< Plot > vec_Plots
std::vector< Dataset > datasets
void SetSpillCut(const SpillCut &cut)
Representation of a spectrum in any variable, with associated POT.
const SpillVar kSpillUnweighted
void lastUpdated(unsigned int timestamp)
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.
SpillCut getYearAndMonth(unsigned int iYear, unsigned int iMonth)
virtual void Go() override
Load all the registered spectra.
std::vector< float > Spectrum
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
const SpillCut kStandardSpillCuts
Apply this unless you're doing something special.
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
void drawIntensityEffect_2019(std::string samdef, unsigned int endTime, unsigned int nDays, std::string outDir)