NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
NGFigure.cxx
Go to the documentation of this file.
1
4//***************************************************************************************
5
6#include "NAGASH/NGFigure.h"
7
8using namespace std;
9using namespace NAGASH;
10
24NGFigure::NGFigure(std::shared_ptr<MSGTool> msg, const char *FigureName, const char *TitleX, const char *TitleY)
25 : Tool(msg), SaveFileName(FigureName), Y_Title_Main_Pad(TitleY), X_Title_Main_Pad(TitleX), X_Title_Sub_Pad(TitleX), unc(msg), histtool(msg)
26{
27}
28
33void NGFigure::SetMode(const char *main_mode_tag, const char *sub_mode_tag, const char *SubTitleY)
34{
35 Mode_Tag_Main = (TString)main_mode_tag;
36 Mode_Tag_Sub = (TString)sub_mode_tag;
37
38 Y_Title_Sub_Pad = (TString)SubTitleY;
39 if (Mode_Tag_Main == "HIST2D")
40 isFor_Hist2D = true;
41
42 isSet_Mode = true;
43}
44
46void NGFigure::SetXRange(double min, double max)
47{
48 if (min >= max)
49 {
50 MSGUser()->StartTitle("NGFigure::SetXRange");
51 MSGUser()->MSG(MSGLevel::ERROR, "Min value is larger than Max value!");
52 MSGUser()->EndTitle();
53 return;
54 }
55 isSet_X_Range = true;
56 Max_X_Range = max;
57 Min_X_Range = min;
58}
59
66void NGFigure::SetInputHist(const char *filename, const char *histname, const char *legendname, int rebinnum, double scale)
67{
68 auto titlegurad = MSGUser()->StartTitleWithGuard("NGFigure::SetInputHist");
69 TFile *file = nullptr;
70 file = new TFile(filename);
71 if (file == nullptr)
72 {
73 MSGUser()->MSG(MSGLevel::ERROR, "File ", filename, " Cannot be opened!");
74 return;
75 }
76
77 TH1D *hist = nullptr;
78 hist = (TH1D *)file->Get(histname);
79 if (hist == nullptr)
80 {
81 MSGUser()->MSG(MSGLevel::ERROR, "Hist ", histname, " Cannot be found!");
82 file->Close();
83 return;
84 }
85
86 hist->SetDirectory(0);
87 file->Close();
88 Main_Hist.push_back(hist);
89 if (scale > 0)
90 hist->Scale(scale);
91 else
92 MSGUser()->MSG_WARNING("scale factor is negative, hist will not be scaled!");
93 LegendName.push_back((TString)legendname);
94 RebinNum.push_back(rebinnum);
95}
96
103void NGFigure::SetInputHist(TFile *infile, const char *histname, const char *legendname, int rebinnum, double scale)
104{
105 auto titlegurad = MSGUser()->StartTitleWithGuard("NGFigure::SetInputHist");
106 TFile *file = nullptr;
107 file = infile;
108 if (file == nullptr)
109 {
110 MSGUser()->MSG(MSGLevel::ERROR, "Input File Does Not Exist!");
111 return;
112 }
113
114 TH1D *hist = nullptr;
115 hist = (TH1D *)file->Get(histname);
116 if (hist == nullptr)
117 {
118 MSGUser()->MSG(MSGLevel::ERROR, "Hist ", histname, " Cannot be found!");
119 return;
120 }
121
122 hist->SetDirectory(0);
123 Main_Hist.push_back(hist);
124
125 if (scale > 0)
126 hist->Scale(scale);
127 else
128 MSGUser()->MSG_WARNING("scale factor is negative, hist will not be scaled!");
129
130 LegendName.push_back((TString)legendname);
131 RebinNum.push_back(rebinnum);
132}
133
139void NGFigure::SetInputHist(TH1D *hist, const char *legendname, int rebinnum, double scale)
140{
141 auto titlegurad = MSGUser()->StartTitleWithGuard("NGFigure::SetInputHist");
142 if (hist == nullptr)
143 {
144 MSGUser()->MSG_ERROR("Input Hist Cannot be found!");
145 return;
146 }
147
148 auto histcopy = (TH1D *)hist->Clone((TString)hist->GetName() + "_copy");
149 histcopy->SetDirectory(0);
150
151 Main_Hist.push_back(histcopy);
152
153 if (scale > 0)
154 histcopy->Scale(scale);
155 else
156 MSGUser()->MSG_WARNING("scale factor is negative, hist will not be scaled!");
157
158 LegendName.push_back((TString)legendname);
159 RebinNum.push_back(rebinnum);
160}
161
168void NGFigure::SetInputHist2D(const char *filename, const char *histname, const char *legendname, int rebinnumx, int rebinnumy)
169{
170 auto titlegurad = MSGUser()->StartTitleWithGuard("NGFigure::SetInputHist2D");
171 TFile *file = nullptr;
172 file = new TFile(filename);
173 if (file == nullptr)
174 {
175 MSGUser()->MSG(MSGLevel::ERROR, "File ", filename, " Cannot be opened!");
176 return;
177 }
178
179 TH2D *hist = nullptr;
180 hist = (TH2D *)file->Get(histname);
181 if (hist == nullptr)
182 {
183 MSGUser()->MSG(MSGLevel::ERROR, "Hist ", histname, " Cannot be found!");
184 file->Close();
185 return;
186 }
187 hist->SetDirectory(0);
188 file->Close();
189 Hist2D = hist;
190 LegendName.push_back((TString)legendname);
191 RebinNumX = rebinnumx;
192 RebinNumY = rebinnumy;
193}
194
201void NGFigure::SetInputHist2D(TFile *infile, const char *histname, const char *legendname, int rebinnumx, int rebinnumy)
202{
203 auto titleguard = MSGUser()->StartTitleWithGuard("NGFigure::SetInputHist2D");
204
205 TFile *file = nullptr;
206 file = infile;
207 if (file == nullptr)
208 {
209 MSGUser()->MSG(MSGLevel::ERROR, "Input File Does Not Exist!");
210 return;
211 }
212
213 TH2D *hist = nullptr;
214 hist = (TH2D *)file->Get(histname);
215 if (hist == nullptr)
216 {
217 MSGUser()->MSG(MSGLevel::ERROR, "Hist ", histname, " Cannot be found!");
218 return;
219 }
220 hist->SetDirectory(0);
221 Hist2D = hist;
222 LegendName.push_back((TString)legendname);
223 RebinNumX = rebinnumx;
224 RebinNumY = rebinnumy;
225}
226
232void NGFigure::SetInputHist2D(TH2D *hist, const char *legendname, int rebinnumx, int rebinnumy)
233{
234 if (hist == nullptr)
235 {
236 MSGUser()->StartTitle("NGFigure::SetInputHist2D");
237 MSGUser()->MSG(MSGLevel::ERROR, "Input Hist Cannot be found!");
238 MSGUser()->EndTitle();
239 return;
240 }
241
242 Hist2D = (TH2D *)hist->Clone((TString)hist->GetName() + "_copy");
243 Hist2D->SetDirectory(0);
244 LegendName.push_back((TString)legendname);
245 RebinNumX = rebinnumx;
246 RebinNumY = rebinnumy;
247}
248
253void NGFigure::SetInputGraph(TGraph *graph, const char *legendname, const char *drawoption)
254{
255 if (graph == nullptr)
256 {
257 MSGUser()->StartTitle("NGFigure::SetInputGraph");
258 MSGUser()->MSG(MSGLevel::ERROR, "Input Graph Cannot be found!");
259 MSGUser()->EndTitle();
260 return;
261 }
262 Main_Graph.push_back((TGraph *)graph->Clone((TString)graph->GetName() + "_copy"));
263 LegendName_Graph.push_back((TString)legendname);
264 DrawOption_Graph.push_back((TString)drawoption);
265
266 if (Main_Graph.size() == 1)
267 {
268 Graph_Marker_Style.push_back(20);
269 Graph_Marker_Size.push_back(8);
270 Graph_Marker_Color.push_back(2);
271
272 Graph_Line_Style.push_back(1);
273 Graph_Line_Width.push_back(2);
274 Graph_Line_Color.push_back(2);
275 }
276 else if (Main_Graph.size() == 2)
277 {
278 Graph_Marker_Style.push_back(21);
279 Graph_Marker_Size.push_back(8);
280 Graph_Marker_Color.push_back(3);
281
282 Graph_Line_Style.push_back(1);
283 Graph_Line_Width.push_back(2);
284 Graph_Line_Color.push_back(3);
285 }
286 else if (Main_Graph.size() == 3)
287 {
288 Graph_Marker_Style.push_back(22);
289 Graph_Marker_Size.push_back(8);
290 Graph_Marker_Color.push_back(4);
291
292 Graph_Line_Style.push_back(1);
293 Graph_Line_Width.push_back(2);
294 Graph_Line_Color.push_back(4);
295 }
296 else if (Main_Graph.size() == 4)
297 {
298 Graph_Marker_Style.push_back(23);
299 Graph_Marker_Size.push_back(8);
300 Graph_Marker_Color.push_back(5);
301
302 Graph_Line_Style.push_back(1);
303 Graph_Line_Width.push_back(2);
304 Graph_Line_Color.push_back(5);
305 }
306 else if (Main_Graph.size() == 5)
307 {
308 Graph_Marker_Style.push_back(29);
309 Graph_Marker_Size.push_back(8);
310 Graph_Marker_Color.push_back(6);
311
312 Graph_Line_Style.push_back(1);
313 Graph_Line_Width.push_back(2);
314 Graph_Line_Color.push_back(6);
315 }
316 else
317 {
318 Graph_Marker_Style.push_back(33);
319 Graph_Marker_Size.push_back(8);
320 Graph_Marker_Color.push_back(7);
321
322 Graph_Line_Style.push_back(1);
323 Graph_Line_Width.push_back(2);
324 Graph_Line_Color.push_back(7);
325 }
326}
327
328void NGFigure::SetGraphMarker(int marker_style, int marker_size, int marker_color)
329{
330 if (Graph_Marker_Style.size() > 0)
331 {
332 Graph_Marker_Style.back() = marker_style;
333 Graph_Marker_Size.back() = marker_size;
334 Graph_Marker_Color.back() = marker_color;
335 }
336 else
337 {
338 MSGUser()->StartTitle("NGFigure::SetGraphMarker");
339 MSGUser()->MSG(MSGLevel::ERROR, "Graph Not Set!");
340 MSGUser()->EndTitle();
341 }
342}
343
344void NGFigure::SetGraphLine(int line_style, int line_width, int line_color)
345{
346 if (Graph_Line_Style.size() > 0)
347 {
348 Graph_Line_Style.back() = line_style;
349 Graph_Line_Width.back() = line_width;
350 Graph_Line_Color.back() = line_color;
351 }
352 else
353 {
354 MSGUser()->StartTitle("NGFigure::SetGraphMarker");
355 MSGUser()->MSG(MSGLevel::ERROR, "Graph Not Set!");
356 MSGUser()->EndTitle();
357 }
358}
359
361{
362 auto titlegurad = MSGUser()->StartTitleWithGuard("NGFigure::RebinHist");
363 if (isFor_Hist2D)
364 {
365 if (Hist2D == nullptr)
366 {
367 MSGUser()->MSG(MSGLevel::ERROR, "No Input Hist!");
368 return false;
369 }
370 binnumx = Hist2D->GetXaxis()->GetNbins();
371 binnumy = Hist2D->GetYaxis()->GetNbins();
372 if (RebinNumX > 0)
373 {
374 if ((binnumx % (RebinNumX)) != 0)
375 {
376 MSGUser()->MSG(MSGLevel::ERROR, "Input Hist2D X axis can not rebin ", RebinNumX, "!");
377 return false;
378 }
379 Hist2D->RebinX(RebinNumX);
380 }
381 if (RebinNumY > 0)
382 {
383 if ((binnumy % (RebinNumY)) != 0)
384 {
385 MSGUser()->MSG(MSGLevel::ERROR, "Input Hist2D Y axis can not rebin ", RebinNumY, "!");
386 return false;
387 }
388
389 Hist2D->RebinY(RebinNumY);
390 }
391 }
392 else
393 {
394 if (Main_Hist.size() == 0)
395 {
396 MSGUser()->MSG(MSGLevel::ERROR, "No Input Hist!");
397 return false;
398 }
399
400 Num_Main_Hist = Main_Hist.size();
401 MSGUser()->MSG(MSGLevel::DEBUG, "Total Input Hist Number: ", Num_Main_Hist);
402
403 for (size_t i = 0; i < Num_Main_Hist; i++)
404 {
405 int binnum = Main_Hist[i]->GetXaxis()->GetNbins();
406 if (RebinNum[i] > 0)
407 {
408 if ((binnum % (RebinNum[i])) != 0)
409 {
410 MSGUser()->MSG(MSGLevel::ERROR, "Input Hist ", i, " Can not rebin ", RebinNum[i], " !");
411 return false;
412 }
413 Main_Hist[i]->Rebin(RebinNum[i]);
414 }
415
416 if (isSet_X_Range)
417 Main_Hist[i]->GetXaxis()->SetRangeUser(Min_X_Range, Max_X_Range);
418 }
419 }
420
421 return true;
422}
423
425{
426 auto titlegurad = MSGUser()->StartTitleWithGuard("NGFigure::Check");
427 Num_X_Bin = Main_Hist[0]->GetXaxis()->GetNbins();
428 MSGUser()->MSG(MSGLevel::DEBUG, "X Axis Bin Number : ", Num_X_Bin);
429 X_Binning = new double[Num_X_Bin + 1];
430 for (int i = 0; i < Num_X_Bin; i++)
431 X_Binning[i] = Main_Hist[0]->GetBinLowEdge(i + 1);
432 MSGUser()->MSG(MSGLevel::DEBUG, "Binning Checked!");
433 X_Binning[Num_X_Bin] = Main_Hist[0]->GetBinLowEdge(Num_X_Bin) + Main_Hist[0]->GetBinWidth(Num_X_Bin);
434
435 for (size_t i = 0; i < Num_Main_Hist; i++)
436 {
437 if (Main_Hist[i]->GetXaxis()->GetNbins() != Num_X_Bin)
438 {
439 MSGUser()->MSG(MSGLevel::ERROR, "Input Hist ", i, " Bin Number Incorrect!");
440 return false;
441 }
442
443 for (int j = 0; j < Main_Hist[i]->GetXaxis()->GetNbins(); j++)
444 {
445 if (fabs(Main_Hist[i]->GetBinLowEdge(j + 1) - X_Binning[j]) > 1e-5)
446 {
447 MSGUser()->MSG(MSGLevel::ERROR, "Input Hist ", i, " Bin ", j, " low edge incorrect");
448 return false;
449 }
450 }
451
452 if (fabs(Main_Hist[i]->GetBinLowEdge(Num_X_Bin) + Main_Hist[i]->GetBinWidth(Num_X_Bin) - X_Binning[Num_X_Bin]) > 1e-5)
453 {
454 MSGUser()->MSG(MSGLevel::ERROR, "Input Hist ", i, " Last Bin High Edge Incorrect");
455 return false;
456 }
457 }
458 MSGUser()->MSG(MSGLevel::DEBUG, "Check finished!");
459 return true;
460}
461
463{
464 auto titlegurad = MSGUser()->StartTitleWithGuard("NGFigure::Normalize");
465 if (!isSet_Norm_Range)
466 {
467 if (isSet_X_Range)
468 {
471 }
472 else
473 {
476 }
477 }
478
479 if (Mode_Tag_Main == "HSTACK")
480 {
481 Total_Hist = (TH1D *)Main_Hist[0]->Clone("Total_Hist");
482 Total_Hist->Reset();
483
484 Total_Hist_With_Error = (TH1D *)Main_Hist[0]->Clone("Total_Hist_With_Error");
485 Total_Hist_With_Error->Reset();
486
487 if (Mode_Tag_Sub == "PERCENTAGE" || Mode_Tag_Sub == "UNKNOWN")
488 {
489 if (Num_Main_Hist < 2)
490 {
491 MSGUser()->MSG(MSGLevel::ERROR, "Only 1 Hist Defined for HSTACK please use SINGLE");
492 return false;
493 }
494 }
495 else
496 {
497 if (Num_Main_Hist < 3)
498 {
499 MSGUser()->MSG(MSGLevel::ERROR, "Only 2 Hist Defined for HSTACK please use MULTI");
500 return false;
501 }
502 }
503
504 for (size_t i = 1; i < Num_Main_Hist; i++)
505 {
507 for (int j = 0; j < Main_Hist[i]->GetXaxis()->GetNbins(); j++)
508 Main_Hist[i]->SetBinError(j + 1, 0);
509
510 Total_Hist->Add(Main_Hist[i]);
511 }
512
513 if (Mode_Tag_Sub == "PERCENTAGE" || Mode_Tag_Sub == "UNKNOWN")
514 {
516 for (int j = 0; j < Main_Hist[0]->GetXaxis()->GetNbins(); j++)
517 Main_Hist[0]->SetBinError(j + 1, 0);
518
519 Total_Hist->Add(Main_Hist[0]);
520 }
521 }
522
523 if (Num_Main_Hist < 2)
524 return true;
525
526 if (isNeed_Norm)
527 {
528 double inte = 1;
529 if (Mode_Tag_Main == "HSTACK" && Mode_Tag_Sub != "UNKNOWN" && Mode_Tag_Sub != "PERCENTAGE")
530 {
531 for (size_t i = 0; i < Num_Main_Hist; i++)
532 {
533 int StartBin = Main_Hist[i]->FindBin(Min_Norm_Range);
534 int EndBin = Main_Hist[i]->FindBin(Max_Norm_Range);
535
536 if (Max_Norm_Range == Main_Hist[i]->GetBinLowEdge(EndBin))
537 EndBin = EndBin - 1;
538
539 if (i == 0)
540 inte = Main_Hist[i]->Integral(StartBin, EndBin);
541
542 if (!isExtern_Norm && i != 0)
543 Norm_Factor = inte / (Total_Hist->Integral(StartBin, EndBin));
544
545 if (i != 0)
546 Main_Hist[i]->Scale(Norm_Factor);
547 }
548
549 Total_Hist->Scale(Norm_Factor);
551 }
552 if (Mode_Tag_Main == "MULTI")
553 {
555 {
556 MSGUser()->MSG(MSGLevel::ERROR, "Unclear Normalization Setting!");
557 return false;
558 }
559
560 for (size_t i = 0; i < Num_Main_Hist; i++)
561 {
562 int StartBin = Main_Hist[i]->FindBin(Min_Norm_Range);
563 int EndBin = Main_Hist[i]->FindBin(Max_Norm_Range);
564
565 if (Max_Norm_Range == Main_Hist[i]->GetBinLowEdge(EndBin))
566 EndBin = EndBin - 1;
567
568 if (i == 0)
569 inte = Main_Hist[i]->Integral(StartBin, EndBin);
570
571 if (isFixed_Norm && (!isExtern_Norm) && i == 1)
572 Norm_Factor = inte / (Main_Hist[i]->Integral(StartBin, EndBin));
573
574 if (isFixed_Norm && i != 0)
575 Main_Hist[i]->Scale(Norm_Factor);
576
577 /*
578 if (!isFixed_Norm && isExtern_Norm && isNeed_ExternNorm[i])
579 Main_Hist[i]->Scale(ExternNorm_Factor[i]);
580 */
581
582 if (isUnity_Norm)
583 Main_Hist[i]->Scale(1.0 / (Main_Hist[i]->Integral(StartBin, EndBin)));
584
585 if (!isFixed_Norm && !isExtern_Norm && !isUnity_Norm && i != 0)
586 Main_Hist[i]->Scale(inte / (Main_Hist[i]->Integral(StartBin, EndBin)));
587 }
588 }
589 }
590
591 return true;
592}
593
595{
596 auto msgguard = MSGUser()->StartTitleWithGuard("NGFigure::ConfigParameters");
597 if (Mode_Tag_Main == "SINGLE")
598 {
599 Main_Pad_isNeeded = true;
600 Sub_Pad_isNeeded = false;
601 }
602 else if (Mode_Tag_Main == "MULTI")
603 {
604 Main_Pad_isNeeded = true;
605 if (Mode_Tag_Sub == "UNKNOWN")
606 Sub_Pad_isNeeded = false;
607 else
608 Sub_Pad_isNeeded = true;
609 }
610 else if (Mode_Tag_Main == "HIST2D")
611 {
612 Main_Pad_isNeeded = true;
613 Sub_Pad_isNeeded = false;
614 }
615 else if (Mode_Tag_Main == "HSTACK")
616 {
617 Main_Pad_isNeeded = true;
618 if (Mode_Tag_Sub == "UNKNOWN")
619 Sub_Pad_isNeeded = false;
620 else
621 Sub_Pad_isNeeded = true;
622 }
623 if (isFor_Hist2D)
624 {
625 if (DoMatrix)
626 {
627 TH2D *matrix = new TH2D("_matrix_", "_matrix_", binnumx, 0, binnumx, binnumy, 0, binnumy);
628 matrix->Sumw2();
630 Hist2D = matrix;
631
632 for (int i = 0; i < binnumx; i++)
633 {
634 for (int j = 0; j < binnumy; j++)
635 {
636 Hist2D->SetBinContent(i + 1, j + 1, Matrix_Save->GetBinContent(i + 1, j + 1));
637 Hist2D->SetBinError(i + 1, j + 1, Matrix_Save->GetBinError(i + 1, j + 1));
638 }
639 }
640 }
641
642 Hist2D->SetTitle("");
643 Hist2D->SetStats(0);
644
645 Text2D = (TH2D *)Hist2D->Clone("_Text2D_");
646 for (int i = 0; i < binnumx; i++)
647 {
648 for (int j = 0; j < binnumy; j++)
649 {
650 Text2D->SetBinContent(i + 1, j + 1, (int)((Text2D->GetBinContent(i + 1, j + 1)) * pow(10, asmb)) / pow(10, asmb));
651 Text2D->SetBinError(i + 1, j + 1, (int)((Text2D->GetBinError(i + 1, j + 1)) * pow(10, asmb)) / pow(10, asmb));
652 }
653 }
654 Text2D->SetTitle("");
655 Text2D->SetStats(0);
656
657 if (!isSet_X_Range)
658 {
659 Max_X_Range = Hist2D->GetXaxis()->GetBinLowEdge(binnumx) + 0.9 * Hist2D->GetXaxis()->GetBinWidth(binnumx);
660 Min_X_Range = Hist2D->GetXaxis()->GetBinLowEdge(1) + 0.1 * Hist2D->GetXaxis()->GetBinWidth(1);
661 }
662
664 {
665 Max_Y_Range_Main = Hist2D->GetYaxis()->GetBinLowEdge(binnumy) + 0.9 * Hist2D->GetYaxis()->GetBinWidth(binnumy);
666 Min_Y_Range_Main = Hist2D->GetYaxis()->GetBinLowEdge(1) + 0.1 * Hist2D->GetYaxis()->GetBinWidth(1);
667 }
668 }
669 else
670 {
671 if (DoSeparate)
672 {
673 if (Mode_Tag_Main == "MULTI")
674 {
675 if (Num_Main_Hist < 2)
676 {
677 MSGUser()->MSG(MSGLevel::ERROR, "Only One Hist is Set! Please use SINGLE");
678 return false;
679 }
680 for (int i = 0; i < Num_X_Bin; i++)
681 {
682 double sum_err2 = 0;
683 for (int j = 0; j < 2; j++)
684 {
685 sum_err2 = sum_err2 + Main_Hist[j]->GetBinError(i + 1) * Main_Hist[j]->GetBinError(i + 1);
686 }
687 for (size_t j = 0; j < Num_Main_Hist; j++)
688 {
689 Main_Hist[j]->SetBinError(i + 1, 0.0001 * Main_Hist[j]->GetBinContent(i + 1));
690 }
691 Main_Hist[0]->SetBinError(i + 1, sqrt(sum_err2));
692 }
693 }
694 }
695 // Calculate Sub Hist
696 if (Mode_Tag_Main == "MULTI" && Mode_Tag_Sub != "UNKNOWN")
697 {
698 if (Num_Main_Hist < 2)
699 {
700 MSGUser()->MSG(MSGLevel::ERROR, "Only One Hist is Set! Please use SINGLE");
701 return false;
702 }
703
704 for (size_t i = 0; i < Num_Main_Hist; i++)
705 {
706 sprintf(name, "SubHist_%lu", i);
707 TH1D *sub_hist = new TH1D(name, name, Num_X_Bin, X_Binning);
708 sub_hist->Sumw2();
709
710 if (Mode_Tag_Sub == "RATIO")
711 histtool.Ratio(Main_Hist[0], Main_Hist[i], sub_hist, DoSeparate);
712 else if (Mode_Tag_Sub == "PULL")
713 histtool.Pull(Main_Hist[0], Main_Hist[i], sub_hist);
714 else if (Mode_Tag_Sub == "DELTA")
715 histtool.Delta(Main_Hist[0], Main_Hist[i], sub_hist, DoSeparate);
716 else
717 {
718 MSGUser()->MSG(MSGLevel::ERROR, "Unknown Sub Tag");
719 return false;
720 }
721
722 Sub_Hist.push_back(sub_hist);
723 }
724
725 if (ShowChi2)
726 {
727 for (size_t i = 1; i < Num_Main_Hist; i++)
728 {
729 double chi2 = 0;
730 int ndof = 0;
731
732 for (int j = 0; j < Num_X_Bin; j++)
733 {
734 if (isSet_X_Range)
735 {
736 int StartBin = Main_Hist[0]->FindBin(Min_X_Range);
737 int EndBin = Main_Hist[0]->FindBin(Max_X_Range);
738
739 if (Max_X_Range == Main_Hist[0]->GetBinLowEdge(EndBin))
740 EndBin = EndBin - 1;
741
742 if (j + 1 < StartBin || j + 1 > EndBin)
743 continue;
744 }
745
746 double val = Main_Hist[0]->GetBinContent(j + 1) - Main_Hist[i]->GetBinContent(j + 1);
747 double val_err = sqrt(Main_Hist[0]->GetBinError(j + 1) * Main_Hist[0]->GetBinError(j + 1) +
748 Main_Hist[i]->GetBinError(j + 1) * Main_Hist[i]->GetBinError(j + 1));
749 if (val_err == 0)
750 continue;
751
752 ndof = ndof + 1;
753 chi2 = chi2 + val * val / val_err / val_err;
754 }
755 MSGUser()->MSG(MSGLevel::INFO, "Chi Square Value: ", chi2);
756 sprintf(name, "#chi^{2}/ndf=%.1f/%d", chi2, ndof);
757 for (int j = 0; j < 3; j++)
758 LegendName[i] = LegendName[i] + " ";
759 int overlimit = 0;
760 if (((TString)name).Length() > 22)
761 overlimit = ((TString)name).Length() - 22;
762 while (LegendName[i].Length() < 16 - overlimit)
763 LegendName[i] = LegendName[i] + " ";
764 LegendName[i] = LegendName[i] + (TString)name;
765 }
766 }
767 }
768
769 if (Mode_Tag_Main == "HSTACK" && Mode_Tag_Sub != "UNKNOWN")
770 {
771 if (Num_Main_Hist < 3)
772 {
773 MSGUser()->MSG(MSGLevel::ERROR, "Only 2 Hist is Set! Please use MULTI");
774 return false;
775 }
776
777 if (Mode_Tag_Sub == "PERCENTAGE")
778 {
779 for (size_t i = 0; i < Num_Main_Hist; i++)
780 {
781 sprintf(name, "SubHist_%lu", i);
782 TH1D *sub_hist = new TH1D(name, name, Num_X_Bin, X_Binning);
783 sub_hist->Sumw2();
784
785 histtool.Ratio(Main_Hist[i], Total_Hist, sub_hist);
786 Sub_Hist.push_back(sub_hist);
787 }
788 }
789 else
790 {
791 sprintf(name, "SubHist_%d", 0);
792 TH1D *sub_hist = new TH1D(name, name, Num_X_Bin, X_Binning);
793 sub_hist->Sumw2();
794
795 if (Mode_Tag_Sub == "RATIO")
796 histtool.Ratio(Main_Hist[0], Main_Hist[0], sub_hist, DoSeparate);
797 else if (Mode_Tag_Sub == "PULL")
798 histtool.Pull(Main_Hist[0], Main_Hist[0], sub_hist);
799 else if (Mode_Tag_Sub == "DELTA")
800 histtool.Delta(Main_Hist[0], Main_Hist[0], sub_hist, DoSeparate);
801 else
802 {
803 MSGUser()->MSG_ERROR("Unknown Sub Tag");
804 return false;
805 }
806 Sub_Hist.push_back(sub_hist);
807
808 sprintf(name, "SubHist_%d", 1);
809 sub_hist = new TH1D(name, name, Num_X_Bin, X_Binning);
810 sub_hist->Sumw2();
811
812 if (Mode_Tag_Sub == "RATIO")
814 else if (Mode_Tag_Sub == "PULL")
816 else if (Mode_Tag_Sub == "DELTA")
818 else
819 {
820 MSGUser()->MSG_ERROR("Unknown Sub Tag");
821 return false;
822 }
823
824 Sub_Hist.push_back(sub_hist);
825
826 if (DoSeparate)
827 {
828 for (int i = 0; i < Num_X_Bin; i++)
829 {
830 double temp_err1 = Sub_Hist[1]->GetBinError(i + 1);
831 double temp_err0 = Sub_Hist[0]->GetBinError(i + 1);
832
833 Sub_Hist[1]->SetBinError(i + 1, temp_err0);
834 Sub_Hist[0]->SetBinError(i + 1, temp_err1);
835 }
836 }
837
838 if (ShowChi2)
839 {
840 double chi2 = 0;
841 int ndof = 0;
842
843 for (int i = 0; i < Num_X_Bin; i++)
844 {
845 if (isSet_X_Range)
846 {
847 int StartBin = Main_Hist[0]->FindBin(Min_X_Range);
848 int EndBin = Main_Hist[0]->FindBin(Max_X_Range);
849
850 if (Max_X_Range == Main_Hist[0]->GetBinLowEdge(EndBin))
851 EndBin = EndBin - 1;
852
853 if (i + 1 < StartBin || i + 1 > EndBin)
854 continue;
855 }
856
857 double val = Main_Hist[0]->GetBinContent(i + 1) - Total_Hist_With_Error->GetBinContent(i + 1);
858 double val_err = sqrt(Main_Hist[0]->GetBinError(i + 1) * Main_Hist[0]->GetBinError(i + 1) +
859 Total_Hist_With_Error->GetBinError(i + 1) * Total_Hist_With_Error->GetBinError(i + 1));
860 if (val_err == 0)
861 continue;
862
863 ndof = ndof + 1;
864 chi2 = chi2 + val * val / val_err / val_err;
865 }
866 MSGUser()->MSG_INFO("Chi Square Value: ", chi2);
867 sprintf(name, "#chi^{2}/ndf=%.1f/%d", chi2, ndof);
868 for (int i = 0; i < 2; i++)
869 LegendName[0] = LegendName[0] + " ";
870 int overlimit = 0;
871 if (((TString)name).Length() > 20)
872 overlimit = ((TString)name).Length() - 20;
873 while (LegendName[0].Length() < 14 - overlimit)
874 LegendName[0] = LegendName[0] + " ";
875 LegendName[0] = LegendName[0] + (TString)name;
876 }
877 }
878 }
879
880 if (Mode_Tag_Main == "HSTACK")
881 {
882 Main_Stack = new THStack("Main_Stack", "");
883 if (Mode_Tag_Sub == "PERCENTAGE")
884 Sub_Stack = new THStack("Sub_Stack", "");
885
886 for (int i = Num_Main_Hist - 1; i >= 1; i--)
887 {
888 Main_Stack->Add(Main_Hist[i]);
889 if (Mode_Tag_Sub == "PERCENTAGE")
890 Sub_Stack->Add(Sub_Hist[i]);
891 }
892 if (Mode_Tag_Sub == "PERCENTAGE")
893 Sub_Stack->Add(Sub_Hist[0]);
894
895 if (Mode_Tag_Sub == "PERCENTAGE" || Mode_Tag_Sub == "UNKNOWN")
896 {
897 Main_Stack->Add(Main_Hist[0]);
898 Empty_Hist = new TH1D("Empty_Hist", "Empty_Hist", Num_X_Bin, X_Binning);
899 Empty_Hist->Sumw2();
900 Empty_Hist->SetTitle("");
901 Empty_Hist->SetStats(0);
902 if (Mode_Tag_Sub == "PERCENTAGE")
903 {
904 Empty_Hist_Sub = new TH1D("Empty_Hist_Sub", "Empty_Hist_Sub", Num_X_Bin, X_Binning);
905 Empty_Hist_Sub->Sumw2();
906 Empty_Hist_Sub->SetTitle("");
907 Empty_Hist_Sub->SetStats(0);
908 }
909 }
910 }
911
912 double max_main = 0;
913 double min_main = 0;
914 double max_sub = 0;
915 double min_sub = 0;
916
917 for (size_t i = 0; i < Num_Main_Hist; i++)
918 {
919 for (int j = 0; j < Num_X_Bin; j++)
920 {
921 double val_up = Main_Hist[i]->GetBinContent(j + 1) + Main_Hist[i]->GetBinError(j + 1);
922 double val_down = Main_Hist[i]->GetBinContent(j + 1) - Main_Hist[i]->GetBinError(j + 1);
923
924 if (isSet_X_Range)
925 {
926 int StartBin = Main_Hist[i]->FindBin(Min_X_Range);
927 int EndBin = Main_Hist[i]->FindBin(Max_X_Range);
928
929 if (Max_X_Range == Main_Hist[i]->GetBinLowEdge(EndBin))
930 EndBin = EndBin - 1;
931
932 if (j + 1 < StartBin || j + 1 > EndBin)
933 continue;
934 }
935
936 if (i == 0 && j == 0 && !isSet_X_Range)
937 {
938 max_main = val_up;
939 min_main = val_down;
940 }
941
942 if (i == 0 && j + 1 == Main_Hist[i]->FindBin(Min_X_Range) && isSet_X_Range)
943 {
944 max_main = val_up;
945 min_main = val_down;
946 }
947
948 if (val_up > max_main)
949 max_main = val_up;
950 if (val_down < min_main)
951 min_main = val_down;
952 }
953 }
954
955 if (Mode_Tag_Main == "HSTACK")
956 {
957 for (int j = 0; j < Num_X_Bin; j++)
958 {
959 double val_up = Total_Hist->GetBinContent(j + 1) + Total_Hist->GetBinError(j + 1);
960 double val_down = Total_Hist->GetBinContent(j + 1) - Total_Hist->GetBinError(j + 1);
961
962 if (isSet_X_Range)
963 {
964 int StartBin = Total_Hist->FindBin(Min_X_Range);
965 int EndBin = Total_Hist->FindBin(Max_X_Range);
966
967 if (Max_X_Range == Total_Hist->GetBinLowEdge(EndBin))
968 EndBin = EndBin - 1;
969
970 if (j + 1 < StartBin || j + 1 > EndBin)
971 continue;
972 }
973
974 if (val_up > max_main)
975 max_main = val_up;
976 if (val_down < min_main)
977 min_main = val_down;
978 }
979 }
980
981 if (Sub_Hist.size() > 0)
982 {
983 for (size_t i = 0; i < Sub_Hist.size(); i++)
984 {
985 for (int j = 0; j < Num_X_Bin; j++)
986 {
987 double val_up = Sub_Hist[i]->GetBinContent(j + 1) + Sub_Hist[i]->GetBinError(j + 1);
988 double val_down = Sub_Hist[i]->GetBinContent(j + 1) - Sub_Hist[i]->GetBinError(j + 1);
989
990 if (isSet_X_Range)
991 {
992 int StartBin = Sub_Hist[i]->FindBin(Min_X_Range);
993 int EndBin = Sub_Hist[i]->FindBin(Max_X_Range);
994
995 if (Max_X_Range == Sub_Hist[i]->GetBinLowEdge(EndBin))
996 EndBin = EndBin - 1;
997
998 if (j + 1 < StartBin || j + 1 > EndBin)
999 continue;
1000 }
1001
1002 if (i == 0 && j == 0 && !isSet_X_Range)
1003 {
1004 max_sub = val_up;
1005 min_sub = val_down;
1006 }
1007
1008 if (i == 0 && j + 1 == Sub_Hist[i]->FindBin(Min_X_Range) && isSet_X_Range)
1009 {
1010 max_sub = val_up;
1011 min_sub = val_down;
1012 }
1013
1014 if (val_up > max_sub)
1015 max_sub = val_up;
1016 if (val_down < min_sub)
1017 min_sub = val_down;
1018 }
1019 }
1020 }
1021
1022 double length_main;
1023 if ((Num_Main_Hist + 3) * LeftPercentage + 0.04 < 0.5)
1024 length_main = (max_main - min_main) / (1 - (Num_Main_Hist + 3) * LeftPercentage - 0.04);
1025 else
1026 length_main = (max_main - min_main) / 0.5;
1027
1028 double length_sub;
1029 if (2 * LeftPercentage + 0.08 < 0.5)
1030 length_sub = (max_sub - min_sub) / (1 - 2 * LeftPercentage - 0.08);
1031 else
1032 length_sub = (max_sub - min_sub) / 0.5;
1033
1034 if (!isSet_X_Range)
1035 {
1038 }
1039 else
1040 {
1041 // X Range Check
1043 {
1044 MSGUser()->MSG_ERROR("Max is Smaller Than Min!");
1045 return false;
1046 }
1047 if (Max_X_Range < X_Binning[0])
1048 {
1049 MSGUser()->MSG_ERROR("Hist is not defined in the ordered range!");
1050 return false;
1051 }
1053 {
1054 MSGUser()->MSG_ERROR("Hist is not defined in the ordered range!");
1055 return false;
1056 }
1057 if (Min_X_Range < X_Binning[0])
1058 {
1059 MSGUser()->MSG_ERROR("Min value too small!");
1061 }
1063 {
1064 MSGUser()->MSG_ERROR("Max value too large!");
1066 }
1067 }
1068
1069 if (!isSet_Y_Range_Main)
1070 {
1071 Max_Y_Range_Main = max_main + (0.04 + (Num_Main_Hist + 2) * LeftPercentage) * length_main;
1072 Min_Y_Range_Main = min_main - LeftPercentage * length_main;
1073 }
1074
1076 {
1077 Max_Y_Range_Sub = max_sub + (LeftPercentage + 0.04) * length_sub;
1078 Min_Y_Range_Sub = min_sub - (LeftPercentage + 0.04) * length_sub;
1079 }
1080
1081 // For Some Mode Fix Range
1082 if (Mode_Tag_Main == "HSTACK")
1083 {
1084 Min_Y_Range_Main = 2e-5;
1085 if (Mode_Tag_Sub == "PERCENTAGE")
1086 {
1087 Max_Y_Range_Sub = 1.07;
1088 Min_Y_Range_Sub = 0;
1089 }
1090 }
1091 }
1092
1093 // Load Parameters for Style
1094 RightMargin_Main = 0.05;
1095 LeftMargin_Main = 0.15;
1096 TopMargin_Main = 0.07;
1097
1098 RightMargin_Sub = 0.05;
1099 LeftMargin_Sub = 0.15;
1100 TopMargin_Sub = 0;
1101 BottomMargin_Sub = 0.35;
1102
1103 if (Sub_Pad_isNeeded)
1105 else
1106 BottomMargin_Main = 0.19;
1107
1108 if (isFor_Hist2D)
1109 {
1110 RightMargin_Main = 0.16;
1111 LeftMargin_Main = 0.15;
1112 TopMargin_Main = 0.13;
1113 BottomMargin_Main = 0.10;
1114
1116 {
1117 LeftMargin_Main = 0.19;
1118 BottomMargin_Main = 0.19;
1119 }
1120
1121 if (DoTextOnly)
1122 RightMargin_Main = 0.05;
1123 }
1124
1125 X_Label_Size_Main = 175;
1126 X_Label_Font_Main = 73;
1127 X_Title_Size_Main = 175;
1128 X_Title_Font_Main = 73;
1129 X_Title_Offset_Main = 1.1;
1130
1131 Y_Label_Size_Main = 175;
1132 Y_Label_Font_Main = 73;
1133 Y_Title_Size_Main = 175;
1134 Y_Title_Font_Main = 73;
1135 if (Sub_Pad_isNeeded)
1136 Y_Title_Offset_Main = 2.2;
1137 else
1138 Y_Title_Offset_Main = 1.1;
1139
1140 if (isFor_Hist2D)
1141 {
1142 Y_Title_Offset_Main = 2.2;
1143 }
1144
1145 Z_Label_Size_Main = 175;
1146 Z_Label_Font_Main = 73;
1147 Z_Label_Offset_Main = 0.01;
1148
1149 X_Label_Size_Sub = 175;
1150 X_Label_Font_Sub = 73;
1151 X_Title_Size_Sub = 175;
1152 X_Title_Font_Sub = 73;
1154
1155 Y_Label_Size_Sub = 175;
1156 Y_Label_Font_Sub = 73;
1157 Y_Title_Size_Sub = 175;
1158 Y_Title_Font_Sub = 73;
1160
1161 Hist_Line_Width = 2;
1162 Hist_Marker_Size = 0;
1163 Sub_Fill_Style = 0;
1164 Hist_Fill_Style = 0;
1167 if (Mode_Tag_Main == "HSTACK")
1168 {
1169 Hist_Fill_Style = 1001; // Solid Filling
1170 if (Mode_Tag_Sub == "UNKNOWN")
1171 Hist_Fill_Style_First = 1001;
1172
1173 if (Mode_Tag_Sub == "PERCENTAGE")
1174 {
1175 Hist_Fill_Style_First = 1001;
1176 Sub_Fill_Style = 1001;
1177 Sub_Fill_Style_First = 1001;
1178 }
1179 }
1180 if (DoSeparate)
1181 {
1182 Hist_Fill_Style_First = 3544;
1183 Sub_Fill_Style_First = 3544;
1184 Hist_Line_Width = 2;
1185
1186 if (Mode_Tag_Main == "HSTACK")
1187 {
1189 Hist_Line_Width = 2;
1190 }
1191 }
1192
1193 Legend_Text_Size = 0.05;
1194 Legend_Text_Font = 72;
1195
1196 if (Style_Index == 1)
1197 {
1198 X_Label_Size_Main = 0.05;
1199 X_Label_Font_Main = 42;
1200 X_Title_Size_Main = 0.07;
1201 X_Title_Font_Main = 42;
1202 X_Title_Offset_Main = 1.1;
1203
1204 Y_Label_Size_Main = 0.05;
1205 Y_Label_Font_Main = 42;
1206 Y_Title_Size_Main = 0.07;
1207 Y_Title_Font_Main = 42;
1208 if (Sub_Pad_isNeeded)
1209 Y_Title_Offset_Main = 1.1;
1210 else
1211 Y_Title_Offset_Main = 1.1;
1212
1213 Z_Label_Size_Main = 0.03;
1214 Z_Label_Font_Main = 42;
1215 Z_Label_Offset_Main = 0.01;
1216
1217 X_Label_Size_Sub = 0.13;
1218 X_Label_Font_Sub = 42;
1219 X_Title_Size_Sub = 0.15;
1220 X_Title_Font_Sub = 42;
1221 X_Title_Offset_Sub = 1.;
1222
1223 Y_Label_Size_Sub = 0.13;
1224 Y_Label_Font_Sub = 42;
1225 Y_Title_Size_Sub = 0.15;
1226 Y_Title_Font_Sub = 42;
1227 Y_Title_Offset_Sub = 0.43;
1228
1229 Legend_Text_Size = 0.05;
1230 Legend_Text_Font = 42;
1231 }
1232
1233 return true;
1234}
1235
1237{
1238 // Define the Canvas
1239 if (Sub_Pad_isNeeded)
1240 {
1241 figure = new TCanvas("canvas", "canvas", 5000, 5000);
1242 Main_Pad = new TPad("Main_Pad", "Main_Pad", 0, 0.3, 1, 1.0);
1243 figure->cd();
1244 Main_Pad->Draw();
1245 Sub_Pad = new TPad("Sub_Pad", "Sub_Pad", 0, 0, 1, 0.3);
1246 figure->cd();
1247 Sub_Pad->Draw();
1248 }
1249 else
1250 {
1251 if (isFor_Hist2D)
1252 figure = new TCanvas("canvas", "canvas", 5000, 5000);
1253 else
1254 figure = new TCanvas("canvas", "canvas", 5000, 3500); // 3500
1255 Main_Pad = new TPad("Main_Pad", "Main_Pad", 0, 0, 1, 1.0);
1256
1257 figure->cd();
1258 Main_Pad->Draw();
1259 }
1260
1261 return true;
1262}
1263
1265{
1266 figure->cd();
1267 Main_Pad->cd();
1268 // Go to Main Pad
1269
1270 if (Num_Main_Hist % Legend_Column == 0)
1271 Main_Legend = new TLegend(LeftMargin_Main + 0.04, 1 - TopMargin_Main - 0.04 - (1 + (int)(Num_Main_Hist / Legend_Column)) * LeftPercentage,
1272 1 - RightMargin_Main - 0.04, 1 - TopMargin_Main - 0.04);
1273 else
1274 Main_Legend = new TLegend(LeftMargin_Main + 0.04, 1 - TopMargin_Main - 0.04 - (2 + (int)(Num_Main_Hist / Legend_Column)) * LeftPercentage,
1275 1 - RightMargin_Main - 0.04, 1 - TopMargin_Main - 0.04);
1276
1277 Main_Legend->SetFillColor(0);
1278 Main_Legend->SetFillStyle(0);
1279 Main_Legend->SetLineColor(0);
1280 Main_Legend->SetLineWidth(0);
1281 Main_Legend->SetTextSize(Legend_Text_Size);
1282 Main_Legend->SetTextFont(Legend_Text_Font);
1283 if (Legend_Column != 1)
1284 Main_Legend->SetNColumns(Legend_Column);
1285
1286 if (Mode_Tag_Main == "HSTACK")
1287 {
1288 if (Mode_Tag_Sub == "UNKNOWN" || Mode_Tag_Sub == "PERCENTAGE")
1289 {
1290 Empty_Hist->Draw("E");
1291 Main_Pad_Y_Axis = Empty_Hist->GetYaxis();
1292 Main_Pad_X_Axis = Empty_Hist->GetXaxis();
1293 }
1294 else
1295 {
1296 Main_Hist[0]->Draw("E");
1297 Main_Pad_Y_Axis = Main_Hist[0]->GetYaxis();
1298 Main_Pad_X_Axis = Main_Hist[0]->GetXaxis();
1299 }
1300
1301 for (size_t i = 0; i < Num_Main_Hist; i++)
1302 Main_Legend->AddEntry(Main_Hist[i], LegendName[i], "lpfe");
1303
1304 if (DoSeparate && Mode_Tag_Sub != "UNKNOWN" && Mode_Tag_Sub != "PERCENTAGE")
1305 Main_Legend->AddEntry(Sub_Hist[0], "Syst. Unc.", "lpfe");
1306 }
1307 else
1308 {
1309 for (size_t i = 0; i < Num_Main_Hist; i++)
1310 {
1311 if (i == 0)
1312 {
1313 if (DoSeparate)
1314 Main_Hist[i]->Draw("E2");
1315 else
1316 Main_Hist[i]->Draw("E0");
1317 }
1318 else
1319 {
1320 Main_Pad->cd();
1321 Main_Hist[i]->Draw("E0 same");
1322 Main_Pad->Update();
1323 }
1324 if (Num_Main_Hist != 1)
1325 Main_Legend->AddEntry(Main_Hist[i], LegendName[i], "lpfe");
1326 }
1327 Main_Pad_Y_Axis = Main_Hist[0]->GetYaxis();
1328 Main_Pad_X_Axis = Main_Hist[0]->GetXaxis();
1329 }
1330
1331 if (Main_Graph.size() > 0)
1332 {
1333 for (size_t i = 0; i < Main_Graph.size(); i++)
1334 {
1335 Main_Graph[i]->Draw(DrawOption_Graph[i]);
1336 Main_Legend->AddEntry(Main_Graph[i], LegendName_Graph[i], "lpfe");
1337 }
1338 }
1339
1340 Main_Legend->SetHeader(HeaderName);
1341 if (DoLegend)
1342 Main_Legend->Draw("same");
1343
1344 figure->cd();
1345 // Return to Canvas
1346
1347 if (Sub_Pad_isNeeded)
1348 {
1349 Sub_Pad->cd();
1350 // Go to Sub Pad
1351
1352 if (Mode_Tag_Main == "HSTACK" && Mode_Tag_Sub == "PERCENTAGE")
1353 {
1354 Empty_Hist_Sub->Draw("E");
1355 Sub_Pad_Y_Axis = Empty_Hist_Sub->GetYaxis();
1356 Sub_Pad_X_Axis = Empty_Hist_Sub->GetXaxis();
1357 }
1358 else
1359 {
1360 for (size_t i = 0; i < Sub_Hist.size(); i++)
1361 {
1362 if (i == 0)
1363 {
1364 if (DoSeparate)
1365 Sub_Hist[i]->Draw("E2");
1366 else
1367 Sub_Hist[i]->Draw("E0");
1368 }
1369 else
1370 Sub_Hist[i]->Draw("E same");
1371 }
1372 Sub_Pad_Y_Axis = Sub_Hist[0]->GetYaxis();
1373 Sub_Pad_X_Axis = Sub_Hist[0]->GetXaxis();
1374 }
1375
1376 figure->cd();
1377 }
1378
1379 return true;
1380}
1381
1383{
1384 figure->SaveAs(SaveFileName);
1385 return true;
1386}
1387
1389{
1390 Main_Pad->SetTopMargin(TopMargin_Main);
1391 Main_Pad->SetBottomMargin(BottomMargin_Main);
1392 Main_Pad->SetLeftMargin(LeftMargin_Main);
1393 Main_Pad->SetRightMargin(RightMargin_Main);
1394 Main_Pad->SetTicks();
1395 Main_Pad->SetGridx(NeedGridX_Main);
1396 Main_Pad->SetGridy(NeedGridY_Main);
1397 if (DoMainLogY)
1398 {
1399 Main_Pad->SetLogy();
1400 }
1401
1402 if (Sub_Pad_isNeeded)
1403 {
1404 Sub_Pad->SetTopMargin(TopMargin_Sub);
1405 Sub_Pad->SetBottomMargin(BottomMargin_Sub);
1406 Sub_Pad->SetLeftMargin(LeftMargin_Sub);
1407 Sub_Pad->SetRightMargin(RightMargin_Sub);
1408 Sub_Pad->SetTicks();
1409 Sub_Pad->SetGridx(NeedGridX_Sub);
1410 Sub_Pad->SetGridy(NeedGridY_Sub);
1411 }
1412}
1413
1414void NGFigure::SetMainLogY(bool dosetlogY)
1415{
1416 DoMainLogY = dosetlogY;
1417}
1418
1420{
1421 Main_Pad_Y_Axis->SetLabelFont(Y_Label_Font_Main);
1422 Main_Pad_Y_Axis->SetLabelSize(Y_Label_Size_Main);
1423 Main_Pad_Y_Axis->SetTitleFont(Y_Title_Font_Main);
1424 Main_Pad_Y_Axis->SetTitleSize(Y_Title_Size_Main);
1425 Main_Pad_Y_Axis->SetTitleOffset(Y_Title_Offset_Main);
1426 Main_Pad_Y_Axis->SetMaxDigits(4);
1429
1430 Main_Pad_X_Axis->SetLabelFont(X_Label_Font_Main);
1431 Main_Pad_X_Axis->SetLabelSize(X_Label_Size_Main);
1432 Main_Pad_X_Axis->SetTitleFont(X_Title_Font_Main);
1433 Main_Pad_X_Axis->SetTitleSize(X_Title_Size_Main);
1434 Main_Pad_X_Axis->SetTitleOffset(X_Title_Offset_Main);
1435 Main_Pad_X_Axis->SetMaxDigits(4);
1436 Main_Pad_X_Axis->SetRangeUser(Min_X_Range + 1e-9, Max_X_Range - 1e-9);
1437
1438 if (isFor_Hist2D)
1439 {
1440 Main_Pad_Z_Axis->SetLabelFont(Z_Label_Font_Main);
1441 Main_Pad_Z_Axis->SetLabelSize(Z_Label_Size_Main);
1442 Main_Pad_Z_Axis->SetLabelOffset(Z_Label_Offset_Main);
1443 Main_Pad_Z_Axis->SetMaxDigits(3);
1444
1446 {
1447 for (size_t i = 0; i < Name_X_Bin.size(); i++)
1448 Main_Pad_X_Axis->SetBinLabel(i + 1, Name_X_Bin[i]);
1449 Hist2D->LabelsOption("v");
1450 Main_Pad_X_Axis->SetTitle("");
1451 }
1453 {
1454 for (size_t i = 0; i < Name_Y_Bin.size(); i++)
1455 Main_Pad_Y_Axis->SetBinLabel(i + 1, Name_Y_Bin[i]);
1456 Hist2D->LabelsOption("v");
1457 Main_Pad_Y_Axis->SetTitle("");
1458 }
1459
1462 }
1463
1464 if (Sub_Pad_isNeeded)
1465 {
1466 Sub_Pad_Y_Axis->SetLabelFont(Y_Label_Font_Sub);
1467 Sub_Pad_Y_Axis->SetLabelSize(Y_Label_Size_Sub);
1468 Sub_Pad_Y_Axis->SetTitleFont(Y_Title_Font_Sub);
1469 Sub_Pad_Y_Axis->SetTitleSize(Y_Title_Size_Sub);
1470 Sub_Pad_Y_Axis->SetTitleOffset(Y_Title_Offset_Sub);
1471 Sub_Pad_Y_Axis->SetMaxDigits(3);
1472 Sub_Pad_Y_Axis->SetNdivisions(505);
1475
1476 Sub_Pad_X_Axis->SetLabelFont(X_Label_Font_Sub);
1477 Sub_Pad_X_Axis->SetLabelSize(X_Label_Size_Sub);
1478 Sub_Pad_X_Axis->SetTitleFont(X_Title_Font_Sub);
1479 Sub_Pad_X_Axis->SetTitleSize(X_Title_Size_Sub);
1480 Sub_Pad_X_Axis->SetTitleOffset(X_Title_Offset_Sub);
1481 Sub_Pad_X_Axis->SetMaxDigits(4);
1483 Sub_Pad_X_Axis->SetRangeUser(Min_X_Range + 1e-9, Max_X_Range - 1e-9);
1484 }
1485 else
1487
1489 Main_Pad_X_Axis->SetTitle("");
1490
1491 MSGUser()->StartTitle("NGFigure::SetAxis");
1492 MSGUser()->MSG_DEBUG("X Range Max: ", Max_X_Range, " Min: ", Min_X_Range);
1493 MSGUser()->MSG_DEBUG("Y Range Main Max: ", Max_Y_Range_Main, " Min: ", Min_Y_Range_Main);
1494 MSGUser()->MSG_DEBUG("Y Range Sub Max: ", Max_Y_Range_Sub, " Min: ", Min_Y_Range_Sub);
1495 MSGUser()->EndTitle();
1496}
1497
1499{
1500 for (size_t i = 0; i < Num_Main_Hist; i++)
1501 {
1502 Main_Hist[i]->SetLineWidth(Hist_Line_Width);
1503 Main_Hist[i]->SetMarkerSize(Hist_Marker_Size);
1504 if (i == 0)
1505 Main_Hist[i]->SetFillStyle(Hist_Fill_Style_First);
1506 else
1507 Main_Hist[i]->SetFillStyle(Hist_Fill_Style);
1508
1509 Main_Hist[i]->SetTitle("");
1510 Main_Hist[i]->SetStats(0);
1511
1512 int index = i % 12;
1513 int round = (i - index) / 12 * 2 + 1;
1514
1515 if (index == 0)
1516 {
1517 Main_Hist[i]->SetLineColor(kRed + round);
1518 Main_Hist[i]->SetMarkerColor(kRed + round);
1519 if (Mode_Tag_Main == "HSTACK" && (Mode_Tag_Sub == "UNKNOWN" || Mode_Tag_Sub == "PERCENTAGE"))
1520 Main_Hist[i]->SetFillColor(kRed + round);
1521 if (Mode_Tag_Main == "MULTI" && DoSeparate)
1522 Main_Hist[i]->SetFillColor(kRed + round);
1523
1524 if (Style_Index == 1)
1525 {
1526 if (Mode_Tag_Main == "MULTI" && DoSeparate)
1527 Main_Hist[i]->SetFillColor(kGray + 2);
1528 // Main_Hist[i]->SetFillColor(0); // Hacked
1529
1530 Main_Hist[i]->SetMarkerStyle(20);
1531 Main_Hist[i]->SetMarkerSize(12);
1532 Main_Hist[i]->SetLineColor(kGray + 2);
1533 Main_Hist[i]->SetMarkerColor(kGray + 2);
1534 }
1535 }
1536 if (index == 1)
1537 {
1538 Main_Hist[i]->SetLineColor(kBlue + round);
1539 Main_Hist[i]->SetMarkerColor(kBlue + round);
1540 if (Mode_Tag_Main == "HSTACK")
1541 Main_Hist[i]->SetFillColor(kBlue + round);
1542
1543 if (Style_Index == 1)
1544 {
1545 Main_Hist[i]->SetMarkerStyle(21);
1546 Main_Hist[i]->SetMarkerSize(12);
1547 Main_Hist[i]->SetLineColor(kAzure + 1);
1548 Main_Hist[i]->SetMarkerColor(kAzure + 1);
1549 if (Mode_Tag_Main == "HSTACK")
1550 Main_Hist[i]->SetFillColor(kAzure + 1);
1551 }
1552 }
1553 if (index == 2)
1554 {
1555 Main_Hist[i]->SetLineColor(kGreen + round);
1556 Main_Hist[i]->SetMarkerColor(kGreen + round);
1557 if (Mode_Tag_Main == "HSTACK")
1558 Main_Hist[i]->SetFillColor(kGreen + round);
1559
1560 if (Style_Index == 1)
1561 {
1562 Main_Hist[i]->SetMarkerStyle(22);
1563 Main_Hist[i]->SetMarkerSize(12);
1564 Main_Hist[i]->SetLineColor(kOrange + 1);
1565 Main_Hist[i]->SetMarkerColor(kOrange + 1);
1566 if (Mode_Tag_Main == "HSTACK")
1567 Main_Hist[i]->SetFillColor(kOrange + 1);
1568 }
1569 }
1570 if (index == 3)
1571 {
1572 Main_Hist[i]->SetLineColor(kPink + round);
1573 Main_Hist[i]->SetMarkerColor(kPink + round);
1574 if (Mode_Tag_Main == "HSTACK")
1575 Main_Hist[i]->SetFillColor(kPink + round);
1576
1577 if (Style_Index == 1)
1578 {
1579 Main_Hist[i]->SetMarkerStyle(23);
1580 Main_Hist[i]->SetMarkerSize(12);
1581 Main_Hist[i]->SetLineColor(kRed + 1);
1582 Main_Hist[i]->SetMarkerColor(kRed + 1);
1583 }
1584 }
1585 if (index == 4)
1586 {
1587 Main_Hist[i]->SetLineColor(kAzure + round);
1588 Main_Hist[i]->SetMarkerColor(kAzure + round);
1589 if (Mode_Tag_Main == "HSTACK")
1590 Main_Hist[i]->SetFillColor(kAzure + round);
1591
1592 if (Style_Index == 1)
1593 {
1594 Main_Hist[i]->SetMarkerStyle(33);
1595 Main_Hist[i]->SetMarkerSize(12);
1596 Main_Hist[i]->SetLineColor(kGreen + 1);
1597 Main_Hist[i]->SetMarkerColor(kGreen + 1);
1598 }
1599 }
1600 if (index == 5)
1601 {
1602 Main_Hist[i]->SetLineColor(kSpring + round);
1603 Main_Hist[i]->SetMarkerColor(kSpring + round);
1604 if (Mode_Tag_Main == "HSTACK")
1605 Main_Hist[i]->SetFillColor(kSpring + round);
1606 }
1607 if (index == 6)
1608 {
1609 Main_Hist[i]->SetLineColor(kMagenta + round);
1610 Main_Hist[i]->SetMarkerColor(kMagenta + round);
1611 if (Mode_Tag_Main == "HSTACK")
1612 Main_Hist[i]->SetFillColor(kMagenta + round);
1613 }
1614 if (index == 7)
1615 {
1616 Main_Hist[i]->SetLineColor(kCyan + round);
1617 Main_Hist[i]->SetMarkerColor(kCyan + round);
1618 if (Mode_Tag_Main == "HSTACK")
1619 Main_Hist[i]->SetFillColor(kCyan + round);
1620 }
1621 if (index == 8)
1622 {
1623 Main_Hist[i]->SetLineColor(kYellow + round);
1624 Main_Hist[i]->SetMarkerColor(kYellow + round);
1625 if (Mode_Tag_Main == "HSTACK")
1626 Main_Hist[i]->SetFillColor(kYellow + round);
1627 }
1628 if (index == 9)
1629 {
1630 Main_Hist[i]->SetLineColor(kViolet + round);
1631 Main_Hist[i]->SetMarkerColor(kViolet + round);
1632 if (Mode_Tag_Main == "HSTACK")
1633 Main_Hist[i]->SetFillColor(kViolet + round);
1634 }
1635 if (index == 10)
1636 {
1637 Main_Hist[i]->SetLineColor(kTeal + round);
1638 Main_Hist[i]->SetMarkerColor(kTeal + round);
1639 if (Mode_Tag_Main == "HSTACK")
1640 Main_Hist[i]->SetFillColor(kTeal + round);
1641 }
1642 if (index == 11)
1643 {
1644 Main_Hist[i]->SetLineColor(kOrange + round);
1645 Main_Hist[i]->SetMarkerColor(kOrange + round);
1646 if (Mode_Tag_Main == "HSTACK")
1647 Main_Hist[i]->SetFillColor(kOrange + round);
1648 }
1649 Main_Pad->Update();
1650 }
1651 if (Main_Graph.size() > 0)
1652 {
1653 for (size_t i = 0; i < Main_Graph.size(); i++)
1654 {
1655 Main_Graph[i]->SetMarkerSize(Graph_Marker_Size[i]);
1656 Main_Graph[i]->SetMarkerStyle(Graph_Marker_Style[i]);
1657 Main_Graph[i]->SetMarkerColor(Graph_Marker_Color[i]);
1658
1659 Main_Graph[i]->SetLineWidth(Graph_Line_Width[i]);
1660 Main_Graph[i]->SetLineStyle(Graph_Line_Style[i]);
1661 Main_Graph[i]->SetLineColor(Graph_Line_Color[i]);
1662
1663 Main_Graph[i]->SetFillStyle(0);
1664 }
1665
1666 Main_Pad->Update();
1667 }
1668 if (Sub_Pad_isNeeded)
1669 {
1670 if (Sub_Hist.size() == Num_Main_Hist)
1671 {
1672 for (size_t i = 0; i < Sub_Hist.size(); i++)
1673 {
1674 Sub_Hist[i]->SetLineWidth(Hist_Line_Width);
1675 Sub_Hist[i]->SetMarkerSize(Hist_Marker_Size);
1676 if (i == 0)
1677 Sub_Hist[i]->SetFillStyle(Sub_Fill_Style_First);
1678 else
1679 Sub_Hist[i]->SetFillStyle(Sub_Fill_Style);
1680
1681 if (DoSeparate && i == 0)
1682 Sub_Hist[i]->SetLineWidth(0);
1683
1684 Sub_Hist[i]->SetTitle("");
1685 Sub_Hist[i]->SetStats(0);
1686
1687 int index = i % 12;
1688 int round = (i - index) / 12 * 2 + 1;
1689
1690 if (index == 0)
1691 {
1692 Sub_Hist[i]->SetLineColor(kRed + round);
1693 Sub_Hist[i]->SetMarkerColor(kRed + round);
1694 if (Mode_Tag_Main == "HSTACK")
1695 Sub_Hist[i]->SetFillColor(kRed + round);
1696 if (DoSeparate)
1697 {
1698 Sub_Hist[i]->SetFillColor(kGray + round);
1699 Sub_Hist[i]->SetLineColor(kGray + 2);
1700 Sub_Hist[i]->SetMarkerColor(kGray + 2);
1701 }
1702
1703 if (Style_Index == 1)
1704 {
1705 Sub_Hist[i]->SetLineColor(kGray + 2);
1706 Sub_Hist[i]->SetMarkerColor(kGray + 2);
1707 }
1708 }
1709 if (index == 1)
1710 {
1711 Sub_Hist[i]->SetLineColor(kBlue + round);
1712 Sub_Hist[i]->SetMarkerColor(kBlue + round);
1713 if (Mode_Tag_Main == "HSTACK")
1714 Sub_Hist[i]->SetFillColor(kBlue + round);
1715
1716 if (Style_Index == 1)
1717 {
1718 Sub_Hist[i]->SetMarkerStyle(21);
1719 Sub_Hist[i]->SetMarkerSize(12);
1720 Sub_Hist[i]->SetLineColor(kAzure + 1);
1721 Sub_Hist[i]->SetMarkerColor(kAzure + 1);
1722 }
1723 }
1724 if (index == 2)
1725 {
1726 Sub_Hist[i]->SetLineColor(kGreen + round);
1727 Sub_Hist[i]->SetMarkerColor(kGreen + round);
1728 if (Mode_Tag_Main == "HSTACK")
1729 Sub_Hist[i]->SetFillColor(kGreen + round);
1730
1731 if (Style_Index == 1)
1732 {
1733 Sub_Hist[i]->SetMarkerStyle(22);
1734 Sub_Hist[i]->SetMarkerSize(12);
1735 Sub_Hist[i]->SetLineColor(kOrange + 1);
1736 Sub_Hist[i]->SetMarkerColor(kOrange + 1);
1737 }
1738 }
1739 if (index == 3)
1740 {
1741 Sub_Hist[i]->SetLineColor(kPink + round);
1742 Sub_Hist[i]->SetMarkerColor(kPink + round);
1743 if (Style_Index == 1)
1744 {
1745 Sub_Hist[i]->SetMarkerStyle(23);
1746 Sub_Hist[i]->SetMarkerSize(12);
1747 Sub_Hist[i]->SetLineColor(kRed + 1);
1748 Sub_Hist[i]->SetMarkerColor(kRed + 1);
1749 }
1750 }
1751 if (index == 4)
1752 {
1753 Sub_Hist[i]->SetLineColor(kAzure + round);
1754 Sub_Hist[i]->SetMarkerColor(kAzure + round);
1755
1756 if (Style_Index == 1)
1757 {
1758 Sub_Hist[i]->SetMarkerStyle(33);
1759 Sub_Hist[i]->SetMarkerSize(12);
1760 Sub_Hist[i]->SetLineColor(kGreen + 1);
1761 Sub_Hist[i]->SetMarkerColor(kGreen + 1);
1762 }
1763 }
1764 if (index == 5)
1765 {
1766 Sub_Hist[i]->SetLineColor(kSpring + round);
1767 Sub_Hist[i]->SetMarkerColor(kSpring + round);
1768 }
1769 if (index == 6)
1770 {
1771 Sub_Hist[i]->SetLineColor(kMagenta + round);
1772 Sub_Hist[i]->SetMarkerColor(kMagenta + round);
1773 }
1774 if (index == 7)
1775 {
1776 Sub_Hist[i]->SetLineColor(kCyan + round);
1777 Sub_Hist[i]->SetMarkerColor(kCyan + round);
1778 }
1779 if (index == 8)
1780 {
1781 Sub_Hist[i]->SetLineColor(kYellow + round);
1782 Sub_Hist[i]->SetMarkerColor(kYellow + round);
1783 }
1784 if (index == 9)
1785 {
1786 Sub_Hist[i]->SetLineColor(kViolet + round);
1787 Sub_Hist[i]->SetMarkerColor(kViolet + round);
1788 }
1789 if (index == 10)
1790 {
1791 Sub_Hist[i]->SetLineColor(kTeal + round);
1792 Sub_Hist[i]->SetMarkerColor(kTeal + round);
1793 }
1794 if (index == 11)
1795 {
1796 Sub_Hist[i]->SetLineColor(kOrange + round);
1797 Sub_Hist[i]->SetMarkerColor(kOrange + round);
1798 }
1799 }
1800 }
1801 else
1802 {
1803 for (size_t i = 0; i < Sub_Hist.size(); i++)
1804 {
1805 Sub_Hist[i]->SetLineWidth(Hist_Line_Width);
1806 Sub_Hist[i]->SetMarkerSize(Hist_Marker_Size);
1807 if (i == 0)
1808 Sub_Hist[i]->SetFillStyle(Sub_Fill_Style_First);
1809 else
1810 Sub_Hist[i]->SetFillStyle(Sub_Fill_Style);
1811
1812 if (DoSeparate && i == 0)
1813 Sub_Hist[i]->SetLineWidth(0);
1814
1815 Sub_Hist[i]->SetTitle("");
1816 Sub_Hist[i]->SetStats(0);
1817
1818 int index = i % 12;
1819 int round = (i - index) / 12 * 2 + 1;
1820
1821 if (index == 0)
1822 {
1823 Sub_Hist[i]->SetLineColor(kRed + round);
1824 Sub_Hist[i]->SetMarkerColor(kRed + round);
1825 if (Mode_Tag_Main == "HSTACK")
1826 Sub_Hist[i]->SetFillColor(kRed + round);
1827 if (DoSeparate)
1828 Sub_Hist[i]->SetFillColor(kRed + round);
1829 }
1830
1831 if (index == 1)
1832 {
1833 Sub_Hist[i]->SetLineColor(kBlue + round);
1834 Sub_Hist[i]->SetMarkerColor(kBlue + round);
1835 if (Mode_Tag_Main == "HSTACK")
1836 Sub_Hist[i]->SetFillColor(kBlue + round);
1837
1838 if (Style_Index == 1)
1839 {
1840 Sub_Hist[i]->SetMarkerStyle(20);
1841 Sub_Hist[i]->SetMarkerSize(8);
1842 Sub_Hist[i]->SetLineColor(kGray + 2);
1843 Sub_Hist[i]->SetMarkerColor(kGray + 2);
1844 }
1845 }
1846 }
1847 }
1848
1849 Sub_Pad->Update();
1850 }
1851}
1852
1854{
1855 if (Mode_Tag_Main == "HSTACK")
1856 {
1857 figure->cd();
1858 Main_Pad->cd();
1859
1860 Main_Stack->Draw("same");
1861 if (Mode_Tag_Sub != "PERCENTAGE" && Mode_Tag_Sub != "UNKNOWN")
1862 Main_Hist[0]->Draw("E same");
1863
1864 figure->cd();
1865
1866 if (Mode_Tag_Sub == "PERCENTAGE")
1867 {
1868 figure->cd();
1869 Sub_Pad->cd();
1870
1871 Sub_Stack->Draw("same");
1872
1873 figure->cd();
1874 }
1875 }
1876
1877 return true;
1878}
1879
1881{
1882 if (Mode_Tag_Main == "HIST2D")
1883 {
1884 figure->cd();
1885 Main_Pad->cd();
1886
1887 Main_Legend = new TLegend(LeftMargin_Main + 0.02, 1 - TopMargin_Main - 0.02,
1888 1 - RightMargin_Main - 0.02, 1 - 0.02);
1889
1890 Main_Legend->SetFillColor(0);
1891 Main_Legend->SetFillStyle(0);
1892 Main_Legend->SetLineColor(0);
1893 Main_Legend->SetLineWidth(0);
1894 Main_Legend->SetTextSize(Legend_Text_Size);
1895 Main_Legend->SetTextFont(Legend_Text_Font);
1896
1897 if (DoTextOnly)
1898 {
1899 Text2D->Draw("TEXT,ERROR");
1900 Main_Pad_X_Axis = Text2D->GetXaxis();
1901 Main_Pad_Y_Axis = Text2D->GetYaxis();
1902 Main_Pad_Z_Axis = Text2D->GetZaxis();
1903
1904 TH2D *temp = Text2D;
1905 Text2D = Hist2D;
1906 Hist2D = temp;
1907 }
1908 else
1909 {
1910 Hist2D->Draw("COLZ");
1911
1912 Main_Pad_X_Axis = Hist2D->GetXaxis();
1913 Main_Pad_Y_Axis = Hist2D->GetYaxis();
1914 Main_Pad_Z_Axis = Hist2D->GetZaxis();
1915
1916 if (!DoColorOnly)
1917 Text2D->Draw("TEXT,ERROR same");
1918 }
1919
1920 Main_Legend->SetHeader(LegendName[0]);
1921 if (DoLegend)
1922 Main_Legend->Draw("same");
1923
1924 figure->cd();
1925 }
1926
1927 return true;
1928}
1929
1931{
1932 if (DoStagger && Mode_Tag_Main == "MULTI")
1933 {
1934 if (Num_Main_Hist > 2)
1935 {
1937 Stagger_X_Binning = new double[Stagger_Num_X_Bin + 1];
1938 for (int i = 0; i < Num_X_Bin; i++)
1939 {
1940 for (size_t j = 0; j < Num_Main_Hist + 1; j++)
1941 Stagger_X_Binning[i * (Num_Main_Hist + 1) + j] = X_Binning[i] + (X_Binning[i + 1] - X_Binning[i]) / (Num_Main_Hist + 1) * j;
1942 }
1944
1945 for (size_t i = 1; i < Num_Main_Hist; i++)
1946 {
1947 Stagger_Save_Main_Hist.push_back(Main_Hist[i]);
1948 sprintf(name, "Stagger_Main_Hist_%lu", i);
1950 Main_Hist[i]->Sumw2();
1951
1952 for (int j = 0; j < Num_X_Bin; j++)
1953 {
1954 double val = Stagger_Save_Main_Hist[i - 1]->GetBinContent(j + 1);
1955 double val_err = Stagger_Save_Main_Hist[i - 1]->GetBinError(j + 1);
1956
1957 Main_Hist[i]->SetBinContent(j * (Num_Main_Hist + 1) + i + 1, val);
1958 Main_Hist[i]->SetBinError(j * (Num_Main_Hist + 1) + i + 1, val_err);
1959 }
1960 }
1961 }
1962 if (Sub_Hist.size() > 2)
1963 {
1964 for (size_t i = 1; i < Sub_Hist.size(); i++)
1965 {
1966 Stagger_Save_Sub_Hist.push_back(Sub_Hist[i]);
1967 sprintf(name, "Stagger_Sub_Hist_%lu", i);
1969 Sub_Hist[i]->Sumw2();
1970
1971 for (int j = 0; j < Num_X_Bin; j++)
1972 {
1973 double val = Stagger_Save_Sub_Hist[i - 1]->GetBinContent(j + 1);
1974 double val_err = Stagger_Save_Sub_Hist[i - 1]->GetBinError(j + 1);
1975
1976 Sub_Hist[i]->SetBinContent(j * (Num_Main_Hist + 1) + i + 1, val);
1977 Sub_Hist[i]->SetBinError(j * (Num_Main_Hist + 1) + i + 1, val_err);
1978 }
1979 }
1980 }
1981 }
1982
1983 return true;
1984}
1985
1987{
1988 auto msgguard = MSGUser()->StartTitleWithGuard("NGFigure::DrawFigure");
1989 if (isSet_Mode == false)
1990 {
1991 MSGUser()->MSG_ERROR("Mode not Set!");
1992 return;
1993 }
1994
1995 if (isFor_Hist2D)
1996 {
1997 RebinHist();
1998 ConfigParameters(); // Set Every Numbers Needed
1999 DefinePad();
2000 DrawHist2D();
2001 SetMargin();
2002 }
2003 else
2004 {
2005 RebinHist();
2006 Check(); // Check If Everything OK
2007 Normalize(); // Do Changes On Hist
2008 ConfigParameters(); // Set Every Numbers Needed
2009 HackStagger();
2010 DefinePad();
2011 DrawHist(); // Basic hist on canvas
2012 SetMargin();
2013 SetHist();
2014 }
2015
2016 SetAxis();
2017 if (Mode_Tag_Main == "HSTACK")
2018 DrawHStack();
2019
2020 // Set All kinds of style
2021 SaveHist();
2022}
2023
2025{
2026 if (figure != nullptr)
2027 delete figure;
2028
2029 for (size_t i = 0; i < Sub_Hist.size(); i++)
2030 delete Sub_Hist[i];
2031 for (size_t i = 0; i < Stagger_Save_Sub_Hist.size(); i++)
2032 delete Stagger_Save_Sub_Hist[i];
2033 if (Stagger_Save_Main_Hist.size() > 0)
2034 {
2035 for (size_t i = 1; i < Main_Hist.size(); i++)
2036 {
2037 if (Main_Hist[i])
2038 delete Main_Hist[i];
2039 }
2040 }
2041
2042 if (Total_Hist_With_Error != nullptr)
2043 delete Total_Hist_With_Error;
2044 if (Total_Hist != nullptr)
2045 delete Total_Hist;
2046 if (Empty_Hist != nullptr)
2047 delete Empty_Hist;
2048 if (Empty_Hist_Sub != nullptr)
2049 delete Empty_Hist_Sub;
2050
2051 if (Main_Stack != nullptr)
2052 delete Main_Stack;
2053 if (Sub_Stack != nullptr)
2054 delete Sub_Stack;
2055 if (Stagger_X_Binning != nullptr)
2056 delete[] Stagger_X_Binning;
2057 if (X_Binning != nullptr)
2058 delete[] X_Binning;
2059
2060 if (Matrix_Save != nullptr)
2061 delete Hist2D;
2062 if (Text2D != nullptr)
2063 delete Text2D;
2064}
2065
2066void NGFigure::SetStagger(bool dostagger)
2067{
2068 DoStagger = dostagger;
2069}
2070
2071void NGFigure::SetMainYRange(double min, double max)
2072{
2073 if (min > max)
2074 {
2075 MSGUser()->StartTitle("NGFigure::SetMainYRange");
2076 MSGUser()->MSG_ERROR("Max value is smaller than Min value!");
2077 MSGUser()->EndTitle();
2078 return;
2079 }
2080 isSet_Y_Range_Main = true;
2081 Max_Y_Range_Main = max;
2082 Min_Y_Range_Main = min;
2083}
2084
2085void NGFigure::SetMainZRange(double min, double max)
2086{
2087 if (min > max)
2088 {
2089 MSGUser()->StartTitle("NGFigure::SetMainZRange");
2090 MSGUser()->MSG_ERROR("Max value is smaller than Min value!");
2091 MSGUser()->EndTitle();
2092 return;
2093 }
2094 isSet_Z_Range_Main = true;
2095 Max_Z_Range_Main = max;
2096 Min_Z_Range_Main = min;
2097}
2098
2099void NGFigure::SetSubYRange(double min, double max)
2100{
2101 if (min > max)
2102 {
2103 MSGUser()->StartTitle("NGFigure::SetSubYRange");
2104 MSGUser()->MSG_ERROR("Max value is smaller than Min value!");
2105 MSGUser()->EndTitle();
2106 return;
2107 }
2108 isSet_Y_Range_Sub = true;
2109 Max_Y_Range_Sub = max;
2110 Min_Y_Range_Sub = min;
2111}
2112
2113void NGFigure::SetNormRange(double min, double max)
2114{
2115 if (min > max)
2116 {
2117 MSGUser()->StartTitle("NGFigure::SetNormRange");
2118 MSGUser()->MSG_ERROR("Max value is smaller than Min value!");
2119 MSGUser()->EndTitle();
2120 return;
2121 }
2122 isSet_Norm_Range = true;
2123 Max_Norm_Range = max;
2124 Min_Norm_Range = min;
2125}
2126
2128{
2129 NeedGridX_Sub = grid;
2130}
2131
2133{
2134 NeedGridY_Sub = grid;
2135}
2136
2138{
2139 NeedGridX_Main = grid;
2140}
2141
2143{
2144 NeedGridY_Main = grid;
2145}
2146
2147void NGFigure::SetGridX(bool grid)
2148{
2149 SetSubGridX(grid);
2150 SetMainGridX(grid);
2151}
2152
2153void NGFigure::SetGridY(bool grid)
2154{
2155 SetSubGridY(grid);
2156 SetMainGridY(grid);
2157}
2158
2159void NGFigure::SetGrid(bool grid)
2160{
2161 SetGridX(grid);
2162 SetGridY(grid);
2163}
2164
2165void NGFigure::SetAsmble(int index)
2166{
2167 asmb = index;
2168}
2169
2171{
2172 Style_Index = index;
2173}
2174
2176{
2177 LeftPercentage = percent;
2178}
2179
2180void NGFigure::SetMatrixStyle(bool domatrix)
2181{
2182 DoMatrix = domatrix;
2183}
2184
2185void NGFigure::SetFixedNormFactor(bool fix, double scale)
2186{
2187 isFixed_Norm = fix;
2188 Norm_Factor = scale;
2189}
2190
2191void NGFigure::SetHeaderName(const char *header)
2192{
2193 HeaderName = (TString)header;
2194}
2195
2197{
2198 ShowChi2 = show;
2199}
2200
2201void NGFigure::SetXBinName(const char *binname)
2202{
2203 Name_X_Bin.push_back((TString)binname);
2204 isNeed_SetBinNameX = true;
2205}
2206
2207void NGFigure::SetYBinName(const char *binname)
2208{
2209 Name_Y_Bin.push_back((TString)binname);
2210 isNeed_SetBinNameY = true;
2211}
2212
2214{
2215 DoSeparate = doseparate;
2216}
2217
2218void NGFigure::Set2DTextOnly(bool dotextonly)
2219{
2220 DoTextOnly = dotextonly;
2221}
2222
2223void NGFigure::Set2DColorOnly(bool docoloronly)
2224{
2225 DoColorOnly = docoloronly;
2226}
2227
2229{
2230 isNeed_Norm = false;
2231}
2232
2234{
2235 Legend_Column = num;
2236}
2237
2238void NGFigure::SetLegend(bool dolegend)
2239{
2240 DoLegend = dolegend;
2241}
void Ratio(TH1 *A, TH1 *B, TH1 *R, bool dosep=false)
Calculate the ratio between two histograms.
Definition HistTool.cxx:253
void Pull(TH1 *A, TH1 *B, TH1 *P)
Calculate the pull between two histograms.
Definition HistTool.cxx:386
void Delta(TH1 *A, TH1 *B, TH1 *D, bool dosep=false)
Calculate the difference between two histograms.
Definition HistTool.cxx:197
TPad * Main_Pad
Definition NGFigure.h:40
void SetSubYRange(double min, double max)
double X_Title_Offset_Main
Definition NGFigure.h:115
std::vector< TString > Name_X_Bin
Definition NGFigure.h:34
std::vector< TString > LegendName_Graph
Definition NGFigure.h:79
void SetNormRange(double min, double max)
TLegend * Main_Legend
Definition NGFigure.h:42
double Max_Y_Range_Main
Definition NGFigure.h:132
TH1D * Total_Hist_With_Error
Definition NGFigure.h:88
double X_Title_Size_Sub
Definition NGFigure.h:168
void Set2DTextOnly(bool dotextonly=true)
bool Main_Pad_isNeeded
Definition NGFigure.h:38
void SetLeftPercentage(double percent)
double Max_Y_Range_Sub
Definition NGFigure.h:158
void SetAsmble(int index)
double BottomMargin_Main
Definition NGFigure.h:109
bool ConfigParameters()
Definition NGFigure.cxx:594
double X_Label_Size_Sub
Definition NGFigure.h:166
TH1D * Empty_Hist_Sub
Definition NGFigure.h:91
TH2D * Matrix_Save
Definition NGFigure.h:22
double X_Title_Size_Main
Definition NGFigure.h:113
double * X_Binning
Definition NGFigure.h:103
double Min_X_Range
Definition NGFigure.h:54
THStack * Sub_Stack
Definition NGFigure.h:94
void SetMainGridY(bool grid=true)
void SetMainLogY(bool dosetlogy=true)
void SetHeaderName(const char *header)
TString HeaderName
Definition NGFigure.h:43
double * Stagger_X_Binning
Definition NGFigure.h:182
double Norm_Factor
Definition NGFigure.h:63
double Y_Title_Font_Main
Definition NGFigure.h:120
void SetGraphLine(int line_style, int line_width, int line_color)
Definition NGFigure.cxx:344
bool isSet_Norm_Range
Definition NGFigure.h:56
TCanvas * figure
Definition NGFigure.h:37
TAxis * Sub_Pad_Y_Axis
Definition NGFigure.h:49
bool isSet_Y_Range_Main
Definition NGFigure.h:131
double Min_Norm_Range
Definition NGFigure.h:62
double RightMargin_Main
Definition NGFigure.h:106
double Z_Label_Offset_Main
Definition NGFigure.h:125
TAxis * Main_Pad_Y_Axis
Definition NGFigure.h:47
double Z_Label_Size_Main
Definition NGFigure.h:123
THStack * Main_Stack
Definition NGFigure.h:93
double Y_Title_Offset_Main
Definition NGFigure.h:121
void SetGridX(bool grid=true)
std::vector< int > Graph_Line_Style
Definition NGFigure.h:84
void SetGridY(bool grid=true)
double TopMargin_Sub
Definition NGFigure.h:163
TString Y_Title_Sub_Pad
Definition NGFigure.h:153
double LeftMargin_Main
Definition NGFigure.h:107
double Y_Label_Font_Main
Definition NGFigure.h:118
TH1D * Empty_Hist
Definition NGFigure.h:90
TString Mode_Tag_Sub
Definition NGFigure.h:149
bool isSet_Y_Range_Sub
Definition NGFigure.h:157
void SetMainGridX(bool grid=true)
TString Mode_Tag_Main
Definition NGFigure.h:71
double Y_Title_Size_Main
Definition NGFigure.h:119
void SetXBinName(const char *binname)
std::vector< TH1D * > Stagger_Save_Main_Hist
Definition NGFigure.h:184
bool isSet_Z_Range_Main
Definition NGFigure.h:135
double Min_Y_Range_Main
Definition NGFigure.h:133
int Hist_Fill_Style_First
Definition NGFigure.h:101
size_t Num_Main_Hist
Definition NGFigure.h:146
double Max_X_Range
Definition NGFigure.h:53
void SetStyleIndex(int index)
void SetMode(const char *main_mode_tag, const char *sub_mode_tag="UNKNOWN", const char *SubTitleY="UNKNOWN")
The mode of the figure.
Definition NGFigure.cxx:33
std::vector< int > Graph_Marker_Style
Definition NGFigure.h:81
std::vector< int > Graph_Line_Width
Definition NGFigure.h:85
bool Sub_Pad_isNeeded
Definition NGFigure.h:39
double Max_Norm_Range
Definition NGFigure.h:61
std::vector< TH1D * > Stagger_Save_Sub_Hist
Definition NGFigure.h:185
void SetLegend(bool)
double LeftPercentage
Definition NGFigure.h:68
double X_Title_Font_Main
Definition NGFigure.h:114
TAxis * Main_Pad_X_Axis
Definition NGFigure.h:48
double Z_Label_Font_Main
Definition NGFigure.h:124
TString Y_Title_Main_Pad
Definition NGFigure.h:127
void Set2DColorOnly(bool docoloronly=true)
double Max_Z_Range_Main
Definition NGFigure.h:136
void SetYBinName(const char *binname)
double Y_Label_Size_Sub
Definition NGFigure.h:172
void SetInputHist(const char *filename, const char *histname, const char *legendname, int rebinnum=-1, double scale=1)
Set input histogram.
Definition NGFigure.cxx:66
void SetInputGraph(TGraph *graph, const char *legendname, const char *drawoption)
Set input graph.
Definition NGFigure.cxx:253
void SetSubGridX(bool grid=true)
TString SaveFileName
Definition NGFigure.h:18
std::vector< TH1D * > Main_Hist
Definition NGFigure.h:72
std::vector< TGraph * > Main_Graph
Definition NGFigure.h:78
double Y_Title_Size_Sub
Definition NGFigure.h:174
TAxis * Sub_Pad_X_Axis
Definition NGFigure.h:50
TH1D * Total_Hist
Definition NGFigure.h:89
TAxis * Main_Pad_Z_Axis
Definition NGFigure.h:46
TString X_Title_Sub_Pad
Definition NGFigure.h:154
double RightMargin_Sub
Definition NGFigure.h:161
void SetLegendColumn(int num)
double X_Label_Font_Sub
Definition NGFigure.h:167
double TopMargin_Main
Definition NGFigure.h:108
std::vector< TString > LegendName
Definition NGFigure.h:75
void SetStagger(bool dostagger=true)
void SetGrid(bool grid=true)
bool isNeed_SetBinNameX
Definition NGFigure.h:32
double X_Title_Font_Sub
Definition NGFigure.h:169
void SetMainZRange(double min, double max)
double Legend_Text_Size
Definition NGFigure.h:142
double BottomMargin_Sub
Definition NGFigure.h:164
double X_Label_Font_Main
Definition NGFigure.h:112
bool isNeed_SetBinNameY
Definition NGFigure.h:33
double X_Title_Offset_Sub
Definition NGFigure.h:170
TString X_Title_Main_Pad
Definition NGFigure.h:128
double X_Label_Size_Main
Definition NGFigure.h:111
double Y_Label_Font_Sub
Definition NGFigure.h:173
NGFigure(std::shared_ptr< MSGTool > msg, const char *FigureName, const char *TitleX, const char *TitleY)
Constructor.
Definition NGFigure.cxx:24
void SetGraphMarker(int marker_style, int marker_size, int marker_color)
Definition NGFigure.cxx:328
std::vector< int > RebinNum
Definition NGFigure.h:76
void SetMatrixStyle(bool domatrix=true)
std::vector< TH1D * > Sub_Hist
Definition NGFigure.h:150
std::vector< int > Graph_Marker_Size
Definition NGFigure.h:82
void SeparateUncertainty(bool doseparate=true)
double Y_Title_Font_Sub
Definition NGFigure.h:175
std::vector< int > Graph_Marker_Color
Definition NGFigure.h:83
double Min_Y_Range_Sub
Definition NGFigure.h:159
char name[200]
Definition NGFigure.h:192
void SetFixedNormFactor(bool fix=true, double scale=-1)
double Y_Title_Offset_Sub
Definition NGFigure.h:176
double Y_Label_Size_Main
Definition NGFigure.h:117
void SetShowChi2(bool show=true)
double Min_Z_Range_Main
Definition NGFigure.h:137
void SetInputHist2D(const char *filename, const char *histname, const char *legendname, int rebinnumx=-1, int rebinnumy=-1)
Set input 2D histogram.
Definition NGFigure.cxx:168
std::vector< int > Graph_Line_Color
Definition NGFigure.h:86
void SetSubGridY(bool grid=true)
void SetMainYRange(double min, double max)
double LeftMargin_Sub
Definition NGFigure.h:162
std::vector< TString > DrawOption_Graph
Definition NGFigure.h:80
int Sub_Fill_Style_First
Definition NGFigure.h:100
void SetXRange(double min, double max)
Draw range of the xaxis.
Definition NGFigure.cxx:46
std::vector< TString > Name_Y_Bin
Definition NGFigure.h:35
HistTool histtool
Definition NGFigure.h:196
Provide interface for all tools in NAGASH.
Definition Tool.h:72
std::shared_ptr< MSGTool > MSGUser()
return the MSGTool inside.
Definition Tool.h:91