tools.h
Go to the documentation of this file.
1 int colors[6];
2 
3 void SetColors(){
4 
5  colors[0] = kViolet - 5;
6  colors[1] = kAzure - 3;
7  colors[2] = kGreen + 2;
8  colors[3] = kOrange + 1;
9  colors[4] = kMagenta + 1;
10  colors[5] = kBlack;
11 
12 }
13 
14 
15 
16 void Simulation() // for some reason doesn't always remember definition in Style script
17 {
18  TLatex* prelim = new TLatex(.9, .95, "NOvA Simulation");
19  prelim->SetTextColor(kGray+1);
20  prelim->SetNDC();
21  prelim->SetTextSize(2/30.);
22  prelim->SetTextAlign(32);
23  prelim->Draw();
24 }
25 
26 void Preliminary() // for some reason doesn't always remember definition in Style script
27 {
28  TLatex* prelim = new TLatex(.9, .95, "NOvA Preliminary");
29  prelim->SetTextColor(kBlue);
30  prelim->SetNDC();
31  prelim->SetTextSize(2/30.);
32  prelim->SetTextAlign(32);
33  prelim->Draw();
34 }
35 
36 
37 void NumuOnly(){
38  TPaveText *pText1 = new TPaveText(0.73, 0.12, 0.88, 0.22, "NDC");
39  TText *text1 = pText1->AddText("#nu_{#mu} only");
40  text1->SetTextAlign(31);
41  text1->SetTextSize(0.04);
42  pText1->SetBorderSize(0);
43  pText1->SetFillStyle(0);
44  pText1->Draw();
45 }
46 
48  TPaveText *pText1 = new TPaveText(0.73, 0.12, 0.88, 0.22, "NDC");
49  TText *text1 = pText1->AddText("Joint analysis");
50  text1->SetTextAlign(31);
51  text1->SetTextSize(0.04);
52  pText1->SetBorderSize(0);
53  pText1->SetFillStyle(0);
54  pText1->Draw();
55 }
56 
57 
58 
59 TGraph* graphAsymmError(TH1* hDataScaled, TH1* hData){
60 
61  for(int bin = 1; bin <= hData->GetNbinsX(); bin++) {
62  if(hData->GetBinContent(bin)==0){
63  hData->SetBinContent(bin,0.001);
64  hDataScaled->SetBinContent(bin,0.001);
65  }
66  }
67 
68  //TGraph *datapoisson = new TGraphAsymmErrors(hDataScaled);
69  TFeldmanCousins fc(0.6827); // to get correct poisson error bars
70  TGraphAsymmErrors *datapoisson = new TGraphAsymmErrors(hDataScaled);
71  for(int bin = 1; bin <= hData->GetNbinsX(); bin++) {
72  //scale by bin 0.1/width
73  float binWidth = hData->GetBinWidth(bin);
74  float scaleFactor = 0.1/binWidth;
75  float y = hData->GetBinContent(bin);
76  float posup = (fc.CalculateUpperLimit(y,0));
77  float posdn = (fc.CalculateLowerLimit(y,0));
78  float errup0 = (fc.CalculateUpperLimit(y,0)-y);
79  float errdn0 = (y-fc.CalculateLowerLimit(y,0));
80  float errup = scaleFactor * (fc.CalculateUpperLimit(y,0)-y);
81  float errdn = scaleFactor * (y-fc.CalculateLowerLimit(y,0));
82  datapoisson->SetPointEYhigh(bin-1,errup);
83  datapoisson->SetPointEYlow(bin-1,errdn);
84 
85  std::cout << "\nbin " << bin << " has " << y << "events" << std::endl;
86  std::cout << "bin width = " << binWidth << " , scale factor = " << scaleFactor << std::endl;
87  std::cout << "poisson up = " << posup << ", poisson down = " << posdn << std::endl;
88  std::cout << "up error = " << errup0 << ", down error = " << errdn0 << std::endl;
89  std::cout << "up error scaled = " << errup << ", down error scaled = " << errdn << std::endl;
90  }
91 
92  datapoisson->SetMarkerStyle(kFullCircle);
93  datapoisson->SetMarkerColor(1);
94  datapoisson->SetMarkerSize(1);
95  datapoisson->SetLineWidth(2);
96 
97  return datapoisson;
98 
99 }
100 
101 
102 
103 TH1* PlotSystShifts(const SystShifts & shifts){
104 
105  auto systs = shifts.ActiveSysts();
106  int nsysts = systs.size();
107  auto h = new TH1D ("sh",";; Pull (N#sigma)", nsysts, -0.5, nsysts + 0.5);
108  for (int systIdx = 0; systIdx < nsysts; ++systIdx){
109  h->SetBinContent( systIdx + 1, shifts.GetShift(systs[systIdx]));
110  h->GetXaxis()->SetBinLabel( systIdx + 1, systs[systIdx]->ShortName().c_str());
111  }
112 
113  h->SetMarkerStyle(kFullCircle);
114  CenterTitles(h);
115  h->SetTitleOffset(3.5);
116  h->GetXaxis()->SetNdivisions(nsysts,kFALSE);
117  h->GetXaxis()->SetLabelSize(0.07);
118  h->GetXaxis()->LabelsOption("v");
119  h->GetYaxis()->SetRangeUser(-1,1);
120 
121  auto c1 = new TCanvas ("c1","c1",700,350);
122  c1->SetBottomMargin(0.5);
123  h->Draw("lp hist");
124  c1->SaveAs("pulls.png");
125  return h;
126 
127 }
128 
129 
130 
131 
132 void drawLabel(int quantId = 0){
133 
134  TPaveText *pText = new TPaveText(0.12, 0.58, 0.42, 0.85, "NDC");
135  pText->SetBorderSize(0);
136  pText->SetFillStyle(0);
137 
138  TText *text1 = pText->AddText("#splitline{NOvA Normal Hierarchy}{8.85#times10^{20} POT-equiv.}");
139  TText *text2 = pText->AddText(" ");
140  TText *text3 = pText->AddText(" ");
141  text1->SetTextAlign(11);
142  text1->SetTextSize(0.04);
143 
144  if(quantId == 0){
145  TText *text4 = pText->AddText("All Quantiles");
146  text4->SetTextAlign(11);
147  text4->SetTextSize(0.05);
148  }
149  else if(quantId == 1){
150  TText *text4 = pText->AddText(TString::Format("Quantile %d", quantId));
151  text4->SetTextAlign(11);
152  text4->SetTextSize(0.05);
153  TText *text5 = pText->AddText("best resolution");
154  text5->SetTextAlign(11);
155  text5->SetTextSize(0.04);
156  }
157  else if(quantId == 4){
158  TText *text4 = pText->AddText(TString::Format("Quantile %d", quantId));
159  text4->SetTextAlign(11);
160  text4->SetTextSize(0.05);
161  TText *text5 = pText->AddText("worst resolution");
162  text5->SetTextAlign(11);
163  text5->SetTextSize(0.04);
164  }
165  else{
166  TText *text4 = pText->AddText(TString::Format("Quantile %d", quantId));
167  text4->SetTextAlign(11);
168  text4->SetTextSize(0.05);
169  }
170 
171  pText->Draw();
172 
173 
174 }
175 
176 
177 
178 
179 
180 void drawLabelUnosc(int quantId = 0){
181 
182  TPaveText *pText = new TPaveText(0.53, 0.60, 0.88, 0.85, "NDC");
183  TText *text1 = pText->AddText("#splitline{NOvA Normal Hierarchy}{8.85#times10^{20} POT-equiv.}");
184  TText *text2 = pText->AddText(" ");
185  TText *text3 = pText->AddText(" ");
186  text1->SetTextAlign(31);
187  text1->SetTextSize(0.04);
188  pText->SetBorderSize(0);
189  pText->SetFillStyle(0);
190  if(quantId == 0){
191  TText *text4 = pText->AddText("All Quantiles");
192  text4->SetTextAlign(31);
193  text4->SetTextSize(0.05);
194  }
195  else if(quantId == 1){
196  TText *text4 = pText->AddText(TString::Format("Quantile %d", quantId));
197  text4->SetTextAlign(31);
198  text4->SetTextSize(0.05);
199  TText *text5 = pText->AddText(TString::Format("best resolution", quantId));
200  text5->SetTextAlign(31);
201  text5->SetTextSize(0.04);
202  }
203  else if(quantId == 4){
204  TText *text4 = pText->AddText(TString::Format("Quantile %d", quantId));
205  text4->SetTextAlign(31);
206  text4->SetTextSize(0.05);
207  TText *text5 = pText->AddText("worst resolution");
208  text5->SetTextAlign(31);
209  text5->SetTextSize(0.04);
210  }
211  else{
212  TText *text4 = pText->AddText(TString::Format("Quantile %d", quantId));
213  text4->SetTextAlign(31);
214  text4->SetTextSize(0.05);
215  }
216 
217  pText->Draw();
218 
219 }
220 
221 
222 
223 void drawLabelRatio(int quantId = 0){
224 
225  TPaveText *pText = new TPaveText(0.15, 0.58, 0.45, 0.85, "NDC");
226  TText *text = pText->AddText("#splitline{NOvA Normal Hierarchy}{8.85#times10^{20} POT-equiv.}");
227  text->SetTextAlign(11);
228  pText->SetBorderSize(0);
229  pText->SetFillStyle(0);
230  pText->SetTextSize(0.04);
231  if(quantId == 0){
232  TText *text2 = pText->AddText("All Quantiles");
233  text2->SetTextAlign(11);
234  }
235  else if(quantId == 1){
236  TText *text2 = pText->AddText(TString::Format("Quantile %d", quantId));
237  text2->SetTextAlign(11);
238  TText *text3 = pText->AddText("best resolution");
239  text3->SetTextAlign(11);
240  text3->SetTextSize(0.04);
241  }
242  else if(quantId == 4){
243  TText *text2 = pText->AddText(TString::Format("Quantile %d", quantId));
244  text2->SetTextAlign(11);
245  TText *text3 = pText->AddText("worst resolution");
246  text3->SetTextAlign(11);
247  text3->SetTextSize(0.04);
248  }
249  else{
250  TText *text2 = pText->AddText(TString::Format("Quantile %d", quantId));
251  text2->SetTextAlign(11);
252  }
253 
254  pText->Draw();
255 
256 }
257 
258 
259 
260 
261 
262 void DrawLeftArrow(int color, float x, float dx, float ymin, float ymax){
263 
264  TLine line;
265  line.SetLineWidth(3);
266  line.SetLineColor(color);
267  line.DrawLine(x,ymin,x,ymax);
268 
269  TArrow arr;
270  arr.SetLineWidth(3);
271  arr.SetLineColor(color);
272  arr.SetFillColor(color);
273 
274  float ymid = ymin + 0.5*(ymax-ymin);
275  // std::cout << "ymid " << ymid << std::endl;
276  arr.DrawArrow(x - dx, ymid, x, ymid, 0.01, "<");
277 
278 }
279 
280 
281 void DrawRightArrow(int color, float x, float dx, float ymin, float ymax){
282 
283  TLine line;
284  line.SetLineWidth(3);
285  line.SetLineColor(color);
286  line.DrawLine(x,ymin,x,ymax);
287 
288  TArrow arr;
289  arr.SetLineWidth(3);
290  arr.SetLineColor(color);
291  arr.SetFillColor(color);
292 
293  float ymid = ymin + 0.5*(ymax-ymin);
294  arr.DrawArrow(x, ymid, x+dx, ymid, 0.01, ">");
295 
296 }
297 
298 
299 
300 void DrawLegendBF(double bfSin, double bfDm, Color_t color, Style_t style){
301 
302 
303  TGraph* marker = new TGraph();
304  marker->SetPoint(1,bfSin, bfDm);
305  marker->SetMarkerStyle(style);
306  marker->SetMarkerColor(color);
307  marker->SetMarkerSize(1.5);
308  TLegend *legend = new TLegend(0.13,0.12,0.28,0.25);
309  legend->SetHeader("Best fit");
310  legend->AddEntry(marker,TString::Format("(%.2f, %.2f#times10^{-3}eV^{2})", bfSin, bfDm),"p");
311  legend->SetTextSize(0.04); //no border for legend
312  legend->SetBorderSize(0);
313  legend->SetFillStyle(0);
314  legend->Draw();
315 
316 
317 }
318 
319 
320 
321 void DrawLegendBF2(double bfSin, double bfDm, Color_t color, Style_t style, double bfSin2, double bfDm2, Color_t color2, Style_t style2){
322 
323  TLegend *legend = new TLegend(0.13,0.12,0.28,0.30,NULL,"brNDC");
324  legend->SetTextSize(0.04); //no border for legend
325  legend->SetBorderSize(0);
326  legend->SetFillStyle(0);
327  TLegendEntry *entry = legend->AddEntry("NULL","Best fit","h");
328  entry = legend->AddEntry("bestfit",TString::Format("(%.2f, %.2f 10^{-3} eV^{2})", bfSin, bfDm),"P");
329  entry->SetMarkerColor(color);
330  entry->SetMarkerStyle(style);
331  entry->SetTextFont(42);
332  entry = legend->AddEntry("bestfit",TString::Format("(%.2f, %.2f 10^{-3} eV^{2})", bfSin2, bfDm2),"P");
333  entry->SetMarkerColor(color2);
334  entry->SetMarkerStyle(style2);
335  entry->SetTextFont(42);
336  legend->Draw();
337 
338 }
339 
340 
341 
342 void drawBFMirror(double bfSin, double bfDm, Color_t color, Style_t style = kFullCircle)
343 {
344 
345  double mirror = bfSin;
346  TMarker* manMarker = new TMarker(bfSin, bfDm, style);
347  manMarker->SetMarkerSize(1.5);
348  manMarker->SetMarkerColor(color);
349  manMarker->Draw();
350 
351  // uncomment to draw two best fits
352  /*
353  if(bfSin > 0.514) mirror = 0.514 - (bfSin - 0.514);
354  if(bfSin < 0.514) mirror = 0.514 + (0.514 - bfSin );
355  TMarker* mirrorMarker = new TMarker(mirror, bfDm, style);
356  mirrorMarker->SetMarkerSize(1.5);
357  mirrorMarker->SetMarkerColor(color);
358  mirrorMarker->Draw();
359  */
360 }
361 
362 
void Simulation()
Definition: tools.h:16
void drawLabel(int quantId=0)
Definition: tools.h:132
void NumuOnly()
Definition: tools.h:37
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
TGraph * graphAsymmError(TH1 *hDataScaled, TH1 *hData)
Definition: tools.h:59
TH1 * PlotSystShifts(const SystShifts &shifts)
Definition: tools.h:103
void drawLabelRatio(int quantId=0)
Definition: tools.h:223
Double_t ymax
Definition: plot.C:25
void Preliminary()
Definition: tools.h:26
void drawBFMirror(double bfSin, double bfDm, Color_t color, Style_t style=kFullCircle)
Definition: tools.h:342
int colors[6]
Definition: tools.h:1
double dx[NP][NC]
void CenterTitles(TH1 *h)
float bin[41]
Definition: plottest35.C:14
TLatex * prelim
Definition: Xsec_final.C:133
OStream cout
Definition: OStream.cxx:6
void SetColors()
Definition: tools.h:3
void drawLabelUnosc(int quantId=0)
Definition: tools.h:180
c1
Definition: demo5.py:24
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 DrawRightArrow(int color, float x, float dx, float ymin, float ymax)
Definition: tools.h:281
void JointAnalysis()
Definition: tools.h:47
void DrawLegendBF(double bfSin, double bfDm, Color_t color, Style_t style)
Definition: tools.h:300
void DrawLegendBF2(double bfSin, double bfDm, Color_t color, Style_t style, double bfSin2, double bfDm2, Color_t color2, Style_t style2)
Definition: tools.h:321
def entry(str)
Definition: HTMLTools.py:26
void DrawLeftArrow(int color, float x, float dx, float ymin, float ymax)
Definition: tools.h:262