plot_spectra_2dplots.C
Go to the documentation of this file.
3 #include "CAFAna/Core/Spectrum.h"
8 #include "OscLib/IOscCalc.h"
9 
10 #include "TCanvas.h"
11 #include "TPolyLine.h"
12 #include "TGraph.h"
13 #include "TFile.h"
14 #include "TLine.h"
15 #include "TLatex.h"
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TLegend.h"
19 #include "TPad.h"
20 #include "TColor.h"
21 #include "TStyle.h"
22 
23 
24 #include <fstream>
25 
26 using namespace ana;
27 
28 // Put a "NOvA Preliminary" tag in the corner
30 {
31  TLatex* prelim = new TLatex(.9, .95, "NOvA Preliminary");
32  prelim->SetTextColor(kAzure);
33  prelim->SetNDC();
34  prelim->SetTextSize(0.05);
35  prelim->SetTextAlign(32);
36  prelim->Draw();
37 }
38 
39 void BeamLabel(std::string s,double x=0.12,double y=0.95){
40  TLatex *tex = new TLatex(x,y,s.c_str());
41  tex->SetTextColor(kGray+2);
42  tex->SetTextSize(0.05);
43  tex->SetNDC();
44  tex->SetTextAlign(12);
45  tex->Draw();
46 }
47 
48 void SampleLabel(TString defname){
49  TLatex *tex = new TLatex();
50  tex->SetTextColor(kPink -6);
51  tex->SetTextSize(0.035);
52  tex->SetTextAlign(11);
53 
54  if(defname.Contains("core")){
55  tex->DrawLatex(0.972, 0.685, "High PID");
56 
57  tex->SetTextAlign(31);
58  tex->DrawLatex(0.968, 0.685, "Low PID");
59  }
60  if(defname.Contains("peri")){
61  tex->DrawLatex(0.971, 0.685, "Peripheral");
62  }
63 }
64 
65 TCanvas * Make2DCanvas(TString beam){
66 //http://colorbrewer2.org/?type=sequential&scheme=PuBu&n=5
67  Double_t stops[5] = { 0.,0.25,0.5,.75,1};
68  Double_t red[5] = {241./255.,189./255.,116./255.,43./255.,4./255.};
69  Double_t green[5] ={238./255.,201./255.,169./255.,140./255.,90./255.};
70  Double_t blue[5] ={246./255.,225./255.,207./255.,190./255.,141./255.};
71 
72  double alpha=1.;
73  TColor::CreateGradientColorTable(5, stops, red, green, blue, 255, alpha);
74 
75  auto c1=new TCanvas();
76  c1->SetRightMargin(0.08);
77  c1->SetLeftMargin(0.12);
78  c1->SetBottomMargin(0.12);
79 
80  return c1;
81 }
82 
83 void Prettify2DHistogram(TH2* hist, TString type, TString defname){
84  hist->GetXaxis()->CenterTitle();
85  hist->GetYaxis()->CenterTitle();
86  hist->SetTitle("");
87 
88  if(defname.Contains("core")){
89  hist->GetXaxis()->SetRangeUser(0.8,1);
90  hist->GetYaxis()->SetRangeUser(0.41,0.7);
91  }
92  if(defname.Contains("peri")){
93  hist->GetXaxis()->SetRangeUser(0.95,1);
94  hist->GetYaxis()->SetRangeUser(0.51,0.7);
95  }
96 
97  hist->GetXaxis()->SetTitle("CVN PID");
98  hist->GetYaxis()->SetTitle("Cosmic BDT");
99 
100  if(type.Contains("cosm")){
101  hist->SetLineColor(kGray+3);
102  //if(defname.Contains("maxy")) hist->SetFillColor(kGray+3);
103  //hist->SetFillColor(kGray+3);
104  }
105  else{
106  hist->Smooth();
107  }
108 
109 }
110 
111 void PrettifyDataPoints(TGraph* graph){
112  auto markercolor = kPink+7;
113  graph->SetMarkerColor(markercolor);
114  graph->SetMarkerStyle(20);
115  graph->SetMarkerSize(1.0);
116 }
117 
118 TGraph* ImportDataGraph(TString filename, TString defname){
119  TGraph* graph = new TGraph(1);
120  //format is run subrun event slice cvn bdt maxy ptp
121  if(defname.Contains("core")){
122  graph = new TGraph(filename,
123  "%*d %*d %*d %*d %lg %lg %*lg");
124  }
125  if(defname.Contains("peri")){
126  graph = new TGraph(filename,
127  "%*d %*d %*d %*d %lg %*lg %lg" );
128  }
129  std::cout << "Loaded graph with " << graph->GetN() << " points\n";
130 
131  return graph;
132 }
133 
134 TPolyLine * DrawBoundaryLines(TString beam,TString defname){
135  TPolyLine *pline = new TPolyLine();
136 
137  if(beam == "fhc" && defname.Contains("core")){
138  const int n = 6;
139  double x[n] = {0.84, 0.84, 0.97, 0.97, 0.97, 1.0};
140  double y[n] = {0.70, 0.49, 0.49, 0.70, 0.49, 0.49};
141  pline = new TPolyLine(n,x,y);
142  }
143  if(beam == "rhc" && defname.Contains("core")){
144  const int n = 6;
145  double x[n] = {0.85, 0.85, 0.97, 0.97, 0.97, 1.0};
146  double y[n] = {0.70, 0.47, 0.47, 0.70, 0.47, 0.47};
147  pline = new TPolyLine(n,x,y);
148  }
149  if(beam == "fhc" && defname.Contains("peri")){
150  double x[5] = {0.97, 0.97, 0.995, 0.995, 1.00};
151  double y[5] = {0.7, 0.61, 0.61, 0.57, 0.57};
152  pline = new TPolyLine(5,x,y);
153  }
154  if(beam == "rhc" && defname.Contains("peri")){
155  double x[5] = {0.97, 0.97, 0.995, 0.995, 1.00};
156  double y[5] = {0.7, 0.60, 0.60, 0.56, 0.56};
157  pline = new TPolyLine(5,x,y);
158  }
159 
160  pline->SetFillColorAlpha(kWhite, 0.0);
161  auto linecolor = kPink -6;
162  pline->SetLineColor(linecolor);
163  pline->SetLineWidth(5);
164  pline->Draw();
165  return pline;
166 }
167 
168 TLegend * MakeLegend (TString beam, TString defname,
169  TH2* hpred, TH2* hcosm,
170  TPolyLine* line, TGraph* gr){
171  auto leg = new TLegend(0.15,0.14,0.5,0.24);
172  leg->SetNColumns(2);
173  leg->SetFillColor( gStyle->GetColorPalette(12));
174  leg->SetFillStyle(1001);
175  leg->SetTextSize(0.04);
176  leg->SetLineColor(kGray+1);
177  leg->SetBorderSize(1);
178 
179  auto h1 = (TH2*) hpred->Clone();
180  auto color = gStyle->GetColorPalette(200);
181  h1->SetFillColor(color);
182  h1->SetLineColor(color);
183  if(beam=="rhc")
184  leg->AddEntry(h1,"#bar{#nu}_{#mu}#rightarrow#bar{#nu}_{e} Pred.","f");
185  else
186  leg->AddEntry(h1,"#nu_{#mu}#rightarrow#nu_{e} Pred.","f");
187  leg->AddEntry(hcosm,"Cosmics","box f");
188  leg->AddEntry(line,"Cut Boundary","l");
189  leg->AddEntry(gr,"FD Data","p");
190 
191 
192  return leg;
193 }
194 
195 
196 void plot_spectra_2dplots(TString beam = "fhc")
197 {
198 
199  std::vector <TString> defnames = {"core_no_pid",
200  "peri_no_pid"};
201  auto calc = DefaultOscCalc();
203  auto pot = beam == "fhc" ? kAna2020FHCPOT : kAna2020RHCPOT;
204 
205  for (const auto & defname:defnames){
206  //load appearance prediction
207  TString filename_pred = "preds_"+ beam + "_prediction.root";
208  auto file_pred = new TFile(filename_pred,"read");
210  (file_pred->GetDirectory("pred_"+defname));
211  auto sign = Sign::kNu;
212  if(beam=="rhc") sign=Sign::kAntiNu;
213  auto sp_pred = pred->PredictComponent(calc->Copy(), Flavors::kNuMuToNuE,
214  Current::kCC, sign);
215 
216  //load cosmic trigger
217  TString filename_cosm = "spectra_"+ beam + "_cosmics.root";
218  auto file_cosm = new TFile(filename_cosm,"read");
219  auto sp_cosm = Spectrum::LoadFrom
220  (file_cosm->GetDirectory("cosm_"+defname));
221 
222  //load data points
223  TString filename_data;
224  if(defname.Contains("core")){
225  filename_data = "core_search_"+beam+"_2020.txt";
226  }
227  if(defname.Contains("peri")){
228  filename_data = "peri_search_"+beam+"_2020.txt";
229  }
230  auto g_data = ImportDataGraph(filename_data,defname);
231 
232  //Plot it
233  auto c1 = Make2DCanvas(beam);
234  auto h_pred = sp_pred.ToTH2(pot, kPOT);
235  auto h_cosm = sp_cosm->ToTH2(livetime, kLivetime);
236  Prettify2DHistogram(h_pred,"pred",defname);
237  Prettify2DHistogram(h_cosm,"cosm",defname);
238  PrettifyDataPoints(g_data);
239 
240  h_pred->Draw("col");
241  h_cosm->Draw("box same");
243  gPad->RedrawAxis();
244  g_data->Draw("p+same");
245  if(beam=="fhc") BeamLabel("#nu-beam");
246  if(beam=="rhc") BeamLabel("#bar{#nu}-beam");
247  auto leg = MakeLegend(beam,defname,h_pred,h_cosm,line,g_data);
248  leg->Draw();
250  preliminary();
251  gPad->Print("plot_"+beam+"_"+defname+".pdf");
252  }
253 
254 }
void Prettify2DHistogram(TH2 *hist, TString type, TString defname)
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
Antineutrinos-only.
Definition: IPrediction.h:50
(&#39; appearance&#39;)
Definition: IPrediction.h:18
TPolyLine * DrawBoundaryLines(TString beam, TString defname)
string filename
Definition: shutoffs.py:106
osc::OscCalcDumb calc
osc::IOscCalcAdjustable * DefaultOscCalc()
Create a new calculator with default assumptions for all parameters.
Definition: Calcs.cxx:49
const XML_Char * s
Definition: expat.h:262
Charged-current interactions.
Definition: IPrediction.h:39
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
tuple blue
Definition: rootlogon.py:65
void PrettifyDataPoints(TGraph *graph)
TCanvas * Make2DCanvas(TString beam)
#define pot
const double kAna2020FHCLivetime
Definition: Exposures.h:237
const double kAna2020FHCPOT
Definition: Exposures.h:233
void plot_spectra_2dplots(TString beam="fhc")
void BeamLabel(std::string s, double x=0.12, double y=0.95)
TLatex * prelim
Definition: Xsec_final.C:133
const double kAna2020RHCPOT
Definition: Exposures.h:235
Neutrinos-only.
Definition: IPrediction.h:49
OStream cout
Definition: OStream.cxx:6
TH1F * h1
double livetime
Definition: saveFDMCHists.C:21
const double kAna2020RHCLivetime
Definition: Exposures.h:238
TGraph * ImportDataGraph(TString filename, TString defname)
TLatex * tex
Definition: f2_nu.C:499
c1
Definition: demo5.py:24
static std::unique_ptr< PredictionNoExtrap > LoadFrom(TDirectory *dir, const std::string &name)
void preliminary()
virtual IOscCalc * Copy() const override
Definition: OscCalcDumb.h:19
TLegend * MakeLegend(TString beam, TString defname, TH2 *hpred, TH2 *hcosm, TPolyLine *line, TGraph *gr)
void SampleLabel(TString defname)
def sign(x)
Definition: canMan.py:197
enum BeamMode string