NuePlotStyle.cxx
Go to the documentation of this file.
3 #include "CAFAna/Core/Binning.h"
5 
6 #include "TH1.h"
7 #include "THStack.h"
8 #include "TString.h"
9 #include "TCanvas.h"
10 #include "TColor.h"
11 #include "TLatex.h"
12 #include "TGraph.h"
13 #include "TGaxis.h"
14 #include "TPaveText.h"
15 #include "TROOT.h"
16 #include "TRint.h"
17 
18 #include <cassert>
19 
20 namespace ana
21 {
22  //----------------------------------------------------------------------------
23  NuePlotStyle::NuePlotStyle(TString pid, bool third)
24  : fPID(pid), fThird(third)
25  {}
26 
27  //----------------------------------------------------------------------------
29  {}
30 
31  //----------------------------------------------------------------------------
32  TCanvas* NuePlotStyle::MakeSACanvas(std::vector<TH1*> hists)
33  {
34  assert(hists.size() > 0 && "You must provide at least one histogram");
35  TCanvas* can = new TCanvas();
36  CenterTitles(hists[0]);
37  // for (int i = 0; i < (int)hists.size(); i++)
38  // hists[i]->Draw("same");
39  hists[0]->Draw("axis");
40  PIDTag();
41  PIDDivisions(false);
42  PIDBinLabels(false);
43  PID2DAxis(hists[0],false);
44  return can;
45  }
46 
47  //----------------------------------------------------------------------------
49  {
50  std::vector<TH1*> hists = {hist};
51  return MakeSACanvas(hists);
52  }
53 
54  //----------------------------------------------------------------------------
55  void FillWithDimColor(TH1* h, bool usealpha, float dim)
56  {
57  if ( usealpha ){
58  h->SetFillColorAlpha(h->GetLineColor(),dim);
59  return;
60  }
61 
62  TColor *color = gROOT->GetColor(h->GetLineColor());
63  float R,G,B,hR,hG,hB,hHue,hSat,hVal;
64 
65  color->GetRGB(hR,hG,hB);
66  color->RGB2HSV(hR,hG,hB,hHue,hSat,hVal);
67  color->HSV2RGB(hHue,dim*hSat,hVal,R,G,B);
68 
69  h->SetFillColor(color->GetColor(R,G,B));
70  }
71 
72  //----------------------------------------------------------------------------
74  {
75  hist->GetXaxis()->CenterTitle();
76  hist->GetYaxis()->CenterTitle();
77  hist->GetZaxis()->CenterTitle();
78  }
79 
80  //----------------------------------------------------------------------------
82  {
83  TLatex* tag = new TLatex(.83, .92, fPID);
84  tag->SetTextColor(kGray+1);
85  tag->SetNDC();
86  tag->SetTextSize(0.038);
87  tag->SetTextFont(42);
88  tag->SetTextAlign(12);
89  tag->Draw();
90  }
91 
92  //----------------------------------------------------------------------------
93  void NuePlotStyle::PIDDivisions( bool shortaxis ){
94  // Separators between the different PID ranges
95  // TGraph not TLine because TGraph is properly clipped by frame
96  int div1 = (shortaxis) ? 6 : 10;
97  int div2 = (shortaxis) ? 12 : 20;
98 
99  TGraph* l1 = new TGraph;
100  l1->SetPoint(0, div1, 0);
101  l1->SetPoint(1, div1, 50000);
102  TGraph* l2 = new TGraph;
103  l2->SetPoint(0, div2, 0);
104  l2->SetPoint(1, div2, 50000);
105  for(TGraph* l: {l1, l2}){
106  l->SetLineWidth(1);
107  l->Draw("l same");
108  }
109  }
110 
111  //----------------------------------------------------------------------------
112  void NuePlotStyle::PIDBinLabels( bool shortaxis ){
113  // Put the labels near the top of the plot
115  gPad->Update();
116  const double y = gPad->GetUymax() * .95;
117 
118  const ana::Binning* bins = 0;
119  if(fPID == "LID") bins = &ana::kLIDNLBinning;
120  if(fPID == "LEM") bins = &ana::kLEMNLBinning;
121  if(fPID == "CVN") bins = &ana::kCVNNLBinning;
122  assert(bins);
123 
124  int v1 = (shortaxis) ? 3 : 5;
125  int v2 = (shortaxis) ? 6 : 10;
126 
127  for(int i = 0; i < 3; ++i){
128  TLatex* ltx = new TLatex(v1+v2*i, y, TString::Format("%g < %s < %g",
129  bins->Edges()[i],
130  pid.c_str(),
131  bins->Edges()[i+1]));
132  ltx->SetTextSize(0.041);
133  ltx->SetTextColor(kBlack);
134  ltx->SetTextAlign(22);
135  ltx->Draw();
136  }
137  }
138 
139  //----------------------------------------------------------------------------
140  void NuePlotStyle::POTLabel( bool shortaxis){
141  // to do: pass a double and make label for that pot
142  int v1 = (shortaxis) ? 3 : 5;
143 
144  const double y = gPad->GetUymax() * .84;
145 
146  TLatex* pot = new TLatex(v1/2.5,y,"3.72#times10^{20} POT");
147  pot->SetTextSize(0.04);
148  pot->SetTextAlign(12);
149  pot->Draw();
150  }
151 
152  //----------------------------------------------------------------------------
153  void NuePlotStyle::PID2DAxis(TH1* hist, bool shortaxis)
154  {
155  int xmax1 = (shortaxis) ? 5 : 8;
156  int xmax2 = (shortaxis) ? 11 : 18;
157  int xmax3 = (shortaxis) ? 17 : 30;
158  int xmin1 = (shortaxis) ? 1 : 0;
159  int xmin2 = (shortaxis) ? 7 : 10;
160  int xmin3 = (shortaxis) ? 13 : 20;
161  int gmin1 = (shortaxis) ? 1 : 0;
162  int gmax1 = (shortaxis) ? 3 : 4;
163  int gmax2 = (shortaxis) ? 3 : 5;
164 
165  double ymin = hist->GetMinimum();
166  // Paint our own x-axis fragments
167  TGaxis* gax1 = new TGaxis(xmin1, ymin, xmax1, ymin, gmin1, gmax1, gmax1, "");
168  TGaxis* gax2 = new TGaxis(xmin2, ymin, xmax2, ymin, gmin1, gmax1, gmax1, "");
169  TGaxis* gax3 = new TGaxis(xmin3, ymin, xmax3, ymin, gmin1, gmax2, gmax2, "");
170 
171  float size = 0.05;
172  float offs = hist->GetXaxis()->GetLabelOffset();
173  int font = hist->GetXaxis()->GetLabelFont();
174  // And then hide its title
175  hist->GetXaxis()->SetLabelSize(0);
176  hist->GetYaxis()->SetLabelSize(0.05);
177  // and make all the tick marks the same size
178  hist->GetXaxis()->SetNdivisions(1800);
179  hist->GetXaxis()->SetTitle("Reconstructed energy (GeV)");
180  hist->GetYaxis()->SetTitle("Events / 0.5 GeV");
181  hist->GetXaxis()->CenterTitle();
182  hist->GetYaxis()->CenterTitle();
183  hist->SetTitle("");
184 
185  if ( fThird ){
186  gax1->SetLabelSize(size);
187  gax1->SetLabelOffset(offs);
188  gax1->SetLabelFont(font);
189  gax1->Draw();
190  }
191  else
192  for(TGaxis* ax: {gax1, gax2, gax3}){
193  // Copy settings from pre-existing axis
194  ax->SetLabelSize(size);
195  ax->SetLabelOffset(offs);
196  ax->SetLabelFont(font);
197  ax->Draw();
198  }
199 
200  }
201 
202  //----------------------------------------------------------------------------
203  void XAxisDeltaCPLabels(TH1* axes, bool t2kunits)
204  {
205  const double minx = gPad->GetLeftMargin();
206  const double dx = 1-(gPad->GetRightMargin()+minx);
207 
208  const double y = gPad->GetBottomMargin();
209 
210  const double fudge = .01;
211 
212  std::vector<std::pair<double, std::string>> labels;
213  if (t2kunits==false){
214  labels.push_back({minx, "0"});
215  labels.push_back({minx+0.25*dx, "#frac{#pi}{2}"});
216  labels.push_back({minx+0.50*dx, "#pi"});
217  labels.push_back({minx+0.75*dx, "#frac{3#pi}{2}"});
218  labels.push_back({minx+1.00*dx, "2#pi"});}
219  else{
220  labels.push_back({minx, "-#pi"});
221  labels.push_back({minx+0.25*dx, "-#frac{#pi}{2}"});
222  labels.push_back({minx+0.50*dx, "0"});
223  labels.push_back({minx+0.75*dx, "#frac{#pi}{2}"});
224  labels.push_back({minx+1.00*dx, "#pi"});
225  }
226 
227  for(auto it: labels){
228  TLatex* ltx = new TLatex(it.first, y-fudge, it.second.c_str());
229  ltx->SetNDC();
230  ltx->SetTextAlign(23);
231  ltx->SetTextSize(axes->GetXaxis()->GetLabelSize());
232  ltx->Draw();
233  }
234 
235  axes->GetXaxis()->SetLabelSize(0);
236  axes->GetXaxis()->SetTitle("#delta_{CP}");
237  axes->GetXaxis()->CenterTitle();
238  }
239 
240  //----------------------------------------------------------------------------
241 
243  const int style)
244  {
245  // Separators between the different PID ranges
246  // TGraph not TLine because TGraph is properly clipped by frame
247  for (int v:{9,18}){
248  TGraph* l = new TGraph;
249  l->SetPoint(0, v, 0);
250  l->SetPoint(1, v, 50000);
251  l->SetLineWidth(1);
252  l->SetLineStyle(style);
253  l->SetLineColor(color);
254  l->Draw("l same");
255  }
256  // Thick line between peripheral and core samples
257  TGraph* tl = new TGraph;
258  tl->SetPoint(0, 27, 0);
259  tl->SetPoint(1, 27, 50000);
260  tl->SetLineWidth(3);
261  tl->SetLineColor(color);
262  tl->Draw("l same");
263 
264  }
265 
266  //----------------------------------------------------------------------------
267  void Nue2017FourBinLabels(const double yNDC,
268  const double textsize,
269  const int color,
270  const bool merged)
271  {
272  // Put the labels near the top of the plot
273  gPad->Update();
274  const double y1 = gPad->GetUymax() * yNDC;
275  const double y2 = gPad->GetUymax() * yNDC;
276 
277  std::vector < TString > binlabels = {
278  {"Low PID"},
279  {"Mid. PID"},
280  {"High PID"},
281  };
282 
283  for(int i = 0; i < 3; ++i){
284  auto ltx = new TPaveText(i * 9, y1, (i+1)*9, y2, "NB");
285  ltx->SetFillStyle(0);
286  ltx->SetLineColorAlpha(kWhite,0);
287  ltx->AddText(binlabels[i]);
288  ltx->SetTextSize(textsize);
289  ltx->SetTextColor(color);
290  ltx->SetTextAlign(23);
291  ltx->Draw();
292  }
293 
294  if(merged){
295  std::vector < TString > samplelabels = {
296  {"Core"},
297  {"Peripheral"},
298  };
299 
300  for(int i = 0; i < 2; ++i){
301  auto ltx = new TPaveText(24.5+i*3, y1-3.5, 26+i*2, y1-3.0, "NB");
302  ltx->SetFillStyle(0);
303  ltx->SetLineColorAlpha(kWhite,0);
304  TText *tltx = ltx->AddText(samplelabels[i]);
305  tltx->SetTextAngle(90.0);
306  ltx->SetTextSize(textsize+0.01);
307  ltx->SetTextColor(color);
308  ltx->SetTextAlign(23);
309  ltx->Draw();
310  }
311  }
312  }
313 
314  //----------------------------------------------------------------------------
315  void Nue2017FourBinAxis(TH1* axes, bool drawLabels, bool merged)
316  {
317  float size = axes->GetXaxis()->GetLabelSize();
318  float offs = axes->GetXaxis()->GetLabelOffset();
319  int font = axes->GetXaxis()->GetLabelFont();
320 
321  float title_size = axes->GetXaxis()->GetTitleSize();
322  float title_offs = axes->GetXaxis()->GetTitleOffset();
323  int title_font = axes->GetXaxis()->GetTitleFont();
324 
325  axes->GetXaxis()->SetNdivisions(904,kFALSE);
326  if(merged) axes->GetXaxis()->SetNdivisions(3200,kFALSE);
327  axes->GetXaxis()->SetLabelSize(0);
328  axes->GetXaxis()->SetTitle("");
329  if(!merged) {axes->GetXaxis()->SetTitle("Reconstructed Neutrino Energy (GeV)");
330  CenterTitles(axes);
331  }
332  axes->GetXaxis()->SetTickLength(0.);
333  double ymin = axes->GetMinimum();
334  if(merged) {
335  TGaxis* gax = new TGaxis(0.001, ymin, 27, ymin, 0.001, 27);
336  gax->SetTickLength(0.);
337  gax->SetLabelSize(0);
338  gax->SetTitle("Reconstructed Neutrino Energy (GeV)");
339  gax->SetTitleSize(title_size);
340  gax->SetTitleOffset(title_offs);
341  gax->SetTitleFont(title_font);
342  gax->CenterTitle(true);
343  gax->Draw();
344  }
345 
346  if(!drawLabels) return;
347 
348  TGaxis* gax1 = new TGaxis(0.001, ymin, 9, ymin, 0.001, 4.5, 205, "S L");
349  TGaxis* gax2 = new TGaxis(9.001, ymin, 18, ymin, 0.001, 4.5, 205, "S L");
350  TGaxis* gax3 = new TGaxis(18.001, ymin, 27, ymin, 0.001, 4.5, 205, "S L");
351 
352  for(TGaxis* ax: {gax1, gax2, gax3}){
353  ax->SetTickLength(0);
354  ax->SetLabelSize(size);
355  ax->SetLabelOffset(offs);
356  ax->SetLabelFont(font);
357  ax->Draw();
358  }
359  gPad->RedrawAxis();
360  }
361 
362  // 2018 plot style - 3 bins
363  //----------------------------------------------------------------------------
364  void Nue2018ThreeBinDivisions(bool coreOnly, const int color, const int style)
365  {
366  // Separators between the different PID ranges
367  // TGraph not TLine because TGraph is properly clipped by frame
368 
369  double v = 9;
370  TGraph* l = new TGraph;
371  l->SetPoint(0, v, 0);
372  l->SetPoint(1, v, 50000);
373  l->SetLineWidth(1);
374  l->SetLineStyle(style);
375  l->SetLineColor(color);
376  l->Draw("l same");
377 
378 
379  // Thick line between peripheral and core samples
380  if(!coreOnly) {
381  TGraph* tl = new TGraph;
382  tl->SetPoint(0, 18, 0);
383  tl->SetPoint(1, 18, 50000);
384  tl->SetLineWidth(3);
385  tl->SetLineColor(color);
386  tl->Draw("l same");
387  }
388 
389  }
390 
391  //----------------------------------------------------------------------------
392  void Nue2018ThreeBinLabels(const double yNDC, const double textsize,
393  const int color, const bool nd)
394  {
395  // Put the labels near the top of the plot
396  gPad->Update();
397  const double y1 = gPad->GetUymax() * yNDC;
398  const double y2 = y1;
399 
400  std::vector <TString> binlabels = {
401  {"Low PID"},
402  {"High PID"},
403  };
404 
405  for(int i = 0; i < 2; i++) {
406  auto ltx = new TPaveText(i*9, y1, (i+1)*9, y2, "NB");
407  ltx->SetFillStyle(0);
408  ltx->SetLineColorAlpha(kWhite,0);
409  ltx->AddText(binlabels[i]);
410  ltx->SetTextSize(textsize);
411  ltx->SetTextColor(color);
412  ltx->SetTextAlign(23);
413  ltx->Draw();
414  }
415 
416  if(!nd) {
417  std::vector <TString> samplelabels = {
418  {"Core"},
419  {"Peripheral"},
420  };
421 
422  for(int i = 0; i < 2; i++) {
423  auto ltx = new TPaveText(16.7+i*1.4, y1*0.5, 16.7 + i*1.9, y1*0.85, "NB");
424  ltx->SetFillStyle(0);
425  ltx->SetLineColorAlpha(kWhite,0);
426  TText *tltx = ltx->AddText(samplelabels[i]);
427  tltx->SetTextAngle(90.0);
428  ltx->SetTextSize(textsize+0.01);
429  ltx->SetTextColor(color);
430  ltx->SetTextAlign(23);
431  ltx->Draw();
432  }
433  }
434  }
435 
436  //----------------------------------------------------------------------------
437  void Nue2018ThreeBinAxis(THStack* axes, bool drawLabels, bool merged, bool coreOnly)
438  {
439  // Make pretty plots for 2018 3 analysis bin scheme.
440  // ********** For ND use coreOnly = merged = true ***************
441 
442  // Pad the top of the plot for labels
443  gPad->Update();
444  const float maxy = axes->GetMaximum();
445  const float ymin = axes->GetMinimum();
446  axes->SetMaximum(maxy*1.2);
447 
448  // For ND, use merged = false option
449  float size = axes->GetXaxis()->GetLabelSize();
450  float offs = axes->GetXaxis()->GetLabelOffset();
451  int font = axes->GetXaxis()->GetLabelFont();
452 
453  axes->GetXaxis()->SetNdivisions(2700,kFALSE);
454  if(merged) axes->GetXaxis()->SetNdivisions(2300, kTRUE);
455  if(coreOnly) {
456  axes->GetXaxis()->SetRangeUser(0,19);
457  axes->GetXaxis()->SetNdivisions(1900, kFALSE);
458  }
459 
460  axes->GetXaxis()->SetLabelSize(0);
461  axes->GetXaxis()->SetTitle("");
462  axes->GetXaxis()->SetTitle("Reconstructed Neutrino Energy (GeV)");
463  axes->GetXaxis()->CenterTitle();
464  axes->GetYaxis()->CenterTitle();
465 
466  if(!drawLabels) return;
467  TGaxis* gax1 = new TGaxis(0, ymin, 9, ymin, 0.0001, 4.5, 205, "S L");
468  TGaxis* gax2 = new TGaxis(9, ymin, 18, ymin, 0.0001, 4.5, 205, "S L");
469  TGaxis* gax3 = new TGaxis(18.001, ymin, 27, ymin, 0.0001, 4.5, 205, "S L");
470 
471  std::vector <TGaxis*> gaxes = {gax1, gax2, gax3};
472  int numAxes = 3;
473  if( merged || coreOnly) numAxes = 2;
474  for(int a = 0; a < numAxes; a++){
475  gaxes[a]->SetTickLength(0.);
476  gaxes[a]->SetLabelSize(size);
477  gaxes[a]->SetLabelOffset(offs);
478  gaxes[a]->SetLabelFont(font);
479  gaxes[a]->Draw();
480  }
481  //gPad->RedrawAxis();
482  }
483 
484  //----------------------------------------------------------------------------
485  void Nue2018ThreeBinAxis(TH1* axes, bool drawLabels, bool merged, bool coreOnly)
486  {
487  // Make pretty plots for 2018 3 analysis bin scheme.
488  // ********** For ND use coreOnly = merged = true ***************
489 
490  gPad->Update();
491  const float maxy = axes->GetMaximum();
492  const float ymin = axes->GetMinimum();
493  axes->SetMaximum(maxy*1.2);
494 
495 
496  float size = axes->GetXaxis()->GetLabelSize();
497  float offs = axes->GetXaxis()->GetLabelOffset();
498  int font = axes->GetXaxis()->GetLabelFont();
499  float title_size = axes->GetXaxis()->GetTitleSize();
500  float title_offs = axes->GetXaxis()->GetTitleOffset();
501  int title_font = axes->GetXaxis()->GetTitleFont();
502  axes->GetXaxis()->SetNdivisions(2700,kFALSE);
503  if(merged) axes->GetXaxis()->SetNdivisions(2300, kTRUE);
504  if(coreOnly) {
505  axes->GetXaxis()->SetRangeUser(0,19);
506  axes->GetXaxis()->SetNdivisions(1900, kFALSE);
507  }
508 
509  axes->GetXaxis()->SetLabelSize(0);
510  axes->GetXaxis()->SetTitle("");
511  axes->GetXaxis()->SetTitle("Reconstructed Neutrino Energy (GeV)");
512  CenterTitles(axes);
513  axes->SetTitleSize(title_size);
514  axes->SetTitleOffset(title_offs);
515  axes->SetTitleFont(title_font);
516 
517  if(!drawLabels) return;
518  TGaxis* gax1 = new TGaxis(0, ymin, 9, ymin, 0.0001, 4.5, 205, "S L");
519  TGaxis* gax2 = new TGaxis(9, ymin, 18, ymin, 0.0001, 4.5, 205, "S L");
520  TGaxis* gax3 = new TGaxis(18.001, ymin, 27, ymin, 0.0001, 4.5, 205, "S L");
521  std::vector <TGaxis*> gaxes = {gax1, gax2, gax3};
522  int numAxes = 3;
523  if( merged || coreOnly) numAxes = 2;
524  for(int a = 0; a < numAxes; a++){
525  gaxes[a]->SetTickLength(0.);
526  gaxes[a]->SetLabelSize(size);
527  gaxes[a]->SetLabelOffset(offs);
528  gaxes[a]->SetLabelFont(font);
529  gaxes[a]->Draw();
530  }
531  gPad->RedrawAxis();
532  }
533 
534  //----------------------------------------------------------------------------
535  void Nue2018ThreeBinDivisions_Reduced(bool coreOnly, const int color, const int style)
536  {
537  // Separators between the different PID ranges
538  // TGraph not TLine because TGraph is properly clipped by frame
539  double v = 8;
540  TGraph* l = new TGraph;
541  l->SetPoint(0, v, 0);
542  l->SetPoint(1, v, 50000);
543  l->SetLineWidth(1);
544  l->SetLineStyle(style);
545  l->SetLineColor(color);
546  l->Draw("l same");
547  // Thick line between peripheral and core samples
548  if(!coreOnly) {
549  TGraph* tl = new TGraph;
550  tl->SetPoint(0, 16, 0);
551  tl->SetPoint(1, 16, 50000);
552  tl->SetLineWidth(3);
553  tl->SetLineColor(color);
554  tl->Draw("l same");
555  }
556  }
557 
558  //----------------------------------------------------------------------------
559  void Nue2018ThreeBinLabels_Reduced(const double yNDC, const double textsize,
560  const int color, const bool nd)
561  {
562  // Put the labels near the top of the plot
563  gPad->Update();
564  const double y1 = gPad->GetUymax() * yNDC;
565  const double y2 = y1;
566  std::vector <TString> binlabels = {
567  {"Low PID"},
568  {"High PID"},
569  //{"#bf{Peripheral}"},
570  };
571  for(int i = 0; i < 2; i++) {
572  auto ltx = new TPaveText(i*8, y1, (i+1)*8, y2, "NB");
573  ltx->SetFillStyle(0);
574  ltx->SetLineColorAlpha(kWhite,0);
575  ltx->AddText(binlabels[i]);
576  ltx->SetTextSize(textsize);
577  ltx->SetTextColor(color);
578  ltx->SetTextAlign(23);
579  ltx->SetTextFont(62);
580  ltx->Draw();
581  }
582  if(!nd) {
583  std::vector <TString> samplelabels = {
584  {"#bf{Core}"},
585  {"#bf{Peripheral}"},
586  };
587  for(int i = 0; i < 2; i++) {
588  auto ltx = new TPaveText(15.25+i*1.5, y1*0.5, 15.25+i*1.5, y1*0.85, "NB");
589  ltx->SetFillStyle(0);
590  ltx->SetLineColorAlpha(kWhite,0);
591  TText *tltx = ltx->AddText(samplelabels[i]);
592  tltx->SetTextAngle(90.0);
593  ltx->SetTextSize(textsize);
594  ltx->SetTextColor(color);
595  ltx->SetTextAlign(22);
596  ltx->Draw();
597 
598 
599  }
600  }
601  }
602 
603  //----------------------------------------------------------------------------
604  void Nue2018ThreeBinAxis_Reduced(TH1* axes, bool drawLabels, bool merged, bool coreOnly, bool drawTitle)
605  {
606  // Make pretty plots for 2018 3 analysis bin scheme.
607  // ********** For ND use coreOnly = merged = true ***************
608 
609  gPad->Update();
610  const float ymin = axes->GetMinimum();
611 
612  float size = axes->GetXaxis()->GetLabelSize();
613  float offs = axes->GetXaxis()->GetLabelOffset();
614  int font = axes->GetXaxis()->GetLabelFont();
615  //float title_size = axes->GetXaxis()->GetTitleSize();
616  //float title_offs = axes->GetXaxis()->GetTitleOffset();
617  //int title_font = axes->GetXaxis()->GetTitleFont();
618  axes->GetXaxis()->SetNdivisions(2700,kFALSE);
619  if(merged) axes->GetXaxis()->SetNdivisions(2100, kFALSE);
620  if(coreOnly) {
621  axes->GetXaxis()->SetRangeUser(0,21);
622  axes->GetXaxis()->SetNdivisions(2100, kFALSE);
623  }
624 
625  axes->GetXaxis()->SetLabelSize(0);
626  axes->GetXaxis()->SetTitle("");
627  axes->GetYaxis()->CenterTitle();
628  // Fix x-axis title
629  if(drawTitle) {
630  TString xTitle = "Reconstructed neutrino energy (GeV)";
631  double left = gPad->GetLeftMargin();
632  double right = 1-gPad->GetRightMargin();
633  double bottom = gPad->GetBottomMargin();
634  double x = left + (right-left)*8/21;
635  double y = bottom * 0.35;
636  TLatex *tex = new TLatex(x,y,xTitle);
637  tex->SetNDC();
638  tex->SetTextAlign(22);
639  tex->Draw();
640  }
641 
642  if(!drawLabels) return;
643  TGaxis* gax1 = new TGaxis(0, ymin, 8, ymin, 0.5, 4.5, 204, "");
644  TGaxis* gax2 = new TGaxis(8, ymin, 16, ymin, 0.5, 4.5, 204, "");
645  TGaxis* gax3 = new TGaxis(16, ymin, 21, ymin, 0.0001, 4, 204, "");
646  std::vector <TGaxis*> gaxes = {gax1, gax2, gax3};
647  int numAxes = 3;
648  if( merged || coreOnly) numAxes = 2;
649  for(int a = 0; a < numAxes; a++){
650  gaxes[a]->SetTickLength(0.);
651  gaxes[a]->SetLabelSize(size);
652  gaxes[a]->SetLabelOffset(offs);
653  gaxes[a]->SetLabelFont(font);
654  gaxes[a]->Draw();
655  }
656  gPad->Update();
657  }
658 
659  //----------------------------------------------------------------------------
660  void Nue2018ThreeBinAxis_Reduced(THStack* axes, bool drawLabels, bool merged, bool coreOnly, bool drawTitle)
661  {
662  // Make pretty plots for 2018 3 analysis bin scheme.
663  // ********** For ND use coreOnly = merged = true ***************
664 
665  gPad->Update();
666  const float ymin = axes->GetMinimum();
667 
668  float size = axes->GetXaxis()->GetLabelSize();
669  float offs = axes->GetXaxis()->GetLabelOffset();
670  int font = axes->GetXaxis()->GetLabelFont();
671  //float title_size = axes->GetXaxis()->GetTitleSize();
672  //float title_offs = axes->GetXaxis()->GetTitleOffset();
673  //int title_font = axes->GetXaxis()->GetTitleFont();
674  axes->GetXaxis()->SetNdivisions(2700,kFALSE);
675  if(merged) axes->GetXaxis()->SetNdivisions(2100, kFALSE);
676  if(coreOnly) {
677  axes->GetXaxis()->SetRangeUser(0,21);
678  axes->GetXaxis()->SetNdivisions(2100, kFALSE);
679  }
680 
681  axes->GetXaxis()->SetLabelSize(0);
682  axes->GetXaxis()->SetTitle("");
683  axes->GetYaxis()->CenterTitle();
684  // Fix x-axis title
685  if(drawTitle) {
686  TString xTitle = "Reconstructed neutrino energy (GeV)";
687  double left = gPad->GetLeftMargin();
688  double right = 1-gPad->GetRightMargin();
689  double bottom = gPad->GetBottomMargin();
690  double x = left + (right-left)*8/21;
691  double y = bottom * 0.35;
692  TLatex *tex = new TLatex(x,y,xTitle);
693  tex->SetNDC();
694  tex->SetTextAlign(22);
695  tex->Draw();
696  }
697 
698  if(!drawLabels) return;
699  TGaxis* gax1 = new TGaxis(0, ymin, 8, ymin, 0.5, 4.5, 204, "");
700  TGaxis* gax2 = new TGaxis(8, ymin, 16, ymin, 0.5, 4.5, 204, "");
701  TGaxis* gax3 = new TGaxis(16, ymin, 21, ymin, 0.0001, 4, 204, "");
702  std::vector <TGaxis*> gaxes = {gax1, gax2, gax3};
703  int numAxes = 3;
704  if( merged || coreOnly) numAxes = 2;
705  for(int a = 0; a < numAxes; a++){
706  gaxes[a]->SetTickLength(0.);
707  gaxes[a]->SetLabelSize(size);
708  gaxes[a]->SetLabelOffset(offs);
709  gaxes[a]->SetLabelFont(font);
710  gaxes[a]->Draw();
711  }
712  gPad->Update();
713  }
714 
715  //----------------------------------------------------------------------------
716  TH1* RemoveBins(TH1* h, bool sum){
717  int bins = sum ? 8 : 21;
718  TH1* ret = new TH1D(UniqueName().c_str(), h->GetTitle(), bins,0,bins);
719  ret->GetXaxis()->SetTitle(h->GetXaxis()->GetTitle());
720  ret->GetYaxis()->SetTitle(h->GetYaxis()->GetTitle());
721  std::vector<std::pair<int, int>> binMap;
722  if(sum) binMap =
723  {{3, 2},
724  {4, 3},
725  {5, 4},
726  {6, 5},
727  {7, 6},
728  {8, 7}, // end of 1st spectrum
729  {12, 2},
730  {13, 3},
731  {14, 4},
732  {15, 5},
733  {16, 6},
734  {17, 7}}; // end of 2nd
735  else binMap =
736  {{3, 2},
737  {4, 3},
738  {5, 4},
739  {6, 5},
740  {7, 6},
741  {8, 7}, // end of 1st spectrum
742  {12, 10},
743  {13, 11},
744  {14, 12},
745  {15, 13},
746  {16, 14},
747  {17, 15}, // end of 2nd
748  {21, 19}}; // peripheral
749  for(auto it: binMap) ret->SetBinContent(it.second, ret->GetBinContent(it.second)+h->GetBinContent(it.first));
750  return ret;
751  }
752 
753  //----------------------------------------------------------------------------
754  TGraphAsymmErrors* PlotErrorBand(TH1*& center, TH1*& nom, std::vector<TH1*>& ups, std::vector<TH1*>& dns, int col, int errCol)
755  {
756  nom->SetLineColor(col);
757  nom->GetXaxis()->CenterTitle();
758  nom->GetYaxis()->CenterTitle();
759  TGraphAsymmErrors* g = new TGraphAsymmErrors;
760  for(int binIdx = 0; binIdx < nom->GetNbinsX()+2; ++binIdx){
761  const double y = nom->GetBinContent(binIdx);
762  g->SetPoint(binIdx, nom->GetXaxis()->GetBinCenter(binIdx), center->GetBinContent(binIdx));
763  const double w = nom->GetXaxis()->GetBinWidth(binIdx);
764  double errUp = 0;
765  double errDn = 0;
766  for(unsigned int systIdx = 0; systIdx < ups.size(); ++systIdx){
767  double hi = ups[systIdx]->GetBinContent(binIdx)-y;
768  double lo = dns[systIdx]->GetBinContent(binIdx)-y;
769  double min = std::min(hi,lo);
770  double max = std::max(hi,lo);
771  if(max < 0) max=0;
772  if(min > 0) min=0;
773  errUp += max*max;
774  errDn += min*min;
775  } // end for systIdx
776  g->SetPointError(binIdx, w/2, w/2, sqrt(errDn), sqrt(errUp));
777  } // end for i
778  g->SetFillColor(errCol);
779  g->Draw("e2 same");
780  center->Draw("hist same");
781  return g;
782  }
783 
784 }
void Nue2017FourBinLabels(const double yNDC, const double textsize, const int color, const bool merged)
void Nue2018ThreeBinAxis(THStack *axes, bool drawLabels, bool merged, bool coreOnly)
T max(const caf::Proxy< T > &a, T b)
void Nue2017FourBinAxis(TH1 *axes, bool drawLabels, bool merged)
TSpline3 lo("lo", xlo, ylo, 12,"0")
TH1 * RemoveBins(TH1 *h, bool sum)
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
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
set< int >::iterator it
Float_t y1[n_points_granero]
Definition: compare.C:5
double maxy
const Binning kCVNNLBinning
Definition: Binnings.cxx:20
void XAxisDeltaCPLabels(TH1 *axes, bool t2kunits)
Label the x-axis with fractions of pi.
T sqrt(T number)
Definition: d0nt_math.hpp:156
void PIDBinLabels(bool shortaxis)
void Nue2018ThreeBinDivisions_Reduced(bool coreOnly, const int color, const int style)
TString hists[nhists]
Definition: bdt_com.C:3
void POTLabel(bool shortaxis)
TGraphAsymmErrors * PlotErrorBand(TH1 *&center, TH1 *&nom, std::vector< TH1 * > &ups, std::vector< TH1 * > &dns, int col, int errCol)
void CenterTitles(TH1 *hist)
void drawLabels(std::vector< std::string > labels)
TSpline3 hi("hi", xhi, yhi, 18,"0")
void Nue2018ThreeBinDivisions(bool coreOnly, const int color, const int style)
double dx[NP][NC]
Int_t col[ntarg]
Definition: Style.C:29
const double a
#define pot
#define R(x)
const std::vector< double > & Edges() const
Definition: Binning.h:34
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
const Binning bins
Definition: NumuCC_CPiBin.h:8
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:96
NuePlotStyle(TString pid, bool third=false)
const Binning kLIDNLBinning
Definition: Binnings.cxx:19
TCanvas * MakeSACanvas(std::vector< TH1 * > hists)
const Binning kLEMNLBinning
Definition: Binnings.cxx:18
TLatex * tex
Definition: f2_nu.C:499
void Nue2018ThreeBinLabels(const double yNDC, const double textsize, const int color, const bool nd)
assert(nhit_max >=nhit_nbins)
Double_t ymin
Definition: plot.C:24
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void Nue2017FourBinDivisions(const int color, const int style)
T min(const caf::Proxy< T > &a, T b)
void Nue2018ThreeBinAxis_Reduced(TH1 *axes, bool drawLabels, bool merged, bool coreOnly, bool drawTitle)
Double_t sum
Definition: plot.C:31
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:66
Float_t w
Definition: plot.C:20
void Nue2018ThreeBinLabels_Reduced(const double yNDC, const double textsize, const int color, const bool nd)
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:28
void FillWithDimColor(TH1 *h, bool usealpha, float dim)
void PID2DAxis(TH1 *hist, bool shortaxis)
void PIDDivisions(bool shortaxis)
enum BeamMode string