makeRandomUniverseHistograms.C
Go to the documentation of this file.
1 // ROOT macro to plot poisson fluctuations from a Random Universe file
2 //
3 // usage:
4 // root -l my_random_universe_hist_file.root makeRandomUniverseHistograms.C
5 //
6 // author: Adam Lister
7 // date : 2020-06-26
8 
9 void StyleHistograms(std::vector<TH1D*> hists){
10 
11  hists.at(0)->SetLineColor(kRed+1);
12  hists.at(1)->SetLineColor(kOrange+8);
13  hists.at(2)->SetLineColor(kYellow+1);
14  hists.at(3)->SetLineColor(kSpring-9);
15  hists.at(4)->SetLineColor(kGreen+1);
16  hists.at(5)->SetLineColor(kTeal+1);
17  hists.at(6)->SetLineColor(kCyan-9);
18  hists.at(7)->SetLineColor(kAzure+1);
19  hists.at(8)->SetLineColor(kViolet+1);
20  hists.at(9)->SetLineColor(kPink+10);
21 
22  hists.at(0)->SetMarkerColor(kRed+1);
23  hists.at(1)->SetMarkerColor(kOrange+8);
24  hists.at(2)->SetMarkerColor(kYellow+1);
25  hists.at(3)->SetMarkerColor(kSpring-9);
26  hists.at(4)->SetMarkerColor(kGreen+1);
27  hists.at(5)->SetMarkerColor(kTeal+1);
28  hists.at(6)->SetMarkerColor(kCyan-9);
29  hists.at(7)->SetMarkerColor(kAzure+1);
30  hists.at(8)->SetMarkerColor(kViolet+1);
31  hists.at(9)->SetMarkerColor(kPink+10);
32 
33  hists.at(0)->SetMarkerStyle(7);
34  hists.at(1)->SetMarkerStyle(7);
35  hists.at(2)->SetMarkerStyle(7);
36  hists.at(3)->SetMarkerStyle(7);
37  hists.at(4)->SetMarkerStyle(7);
38  hists.at(5)->SetMarkerStyle(7);
39  hists.at(6)->SetMarkerStyle(7);
40  hists.at(7)->SetMarkerStyle(7);
41  hists.at(8)->SetMarkerStyle(7);
42  hists.at(9)->SetMarkerStyle(7);
43 
44 }
45 
46 void DrawHistograms(std::vector<TH1D*> hists, std::string style){
47 
48  hists.at(0)->Draw(("same"+style).c_str());
49  hists.at(1)->Draw(("same"+style).c_str());
50  hists.at(2)->Draw(("same"+style).c_str());
51  hists.at(3)->Draw(("same"+style).c_str());
52  hists.at(4)->Draw(("same"+style).c_str());
53  hists.at(5)->Draw(("same"+style).c_str());
54  hists.at(6)->Draw(("same"+style).c_str());
55  hists.at(7)->Draw(("same"+style).c_str());
56  hists.at(8)->Draw(("same"+style).c_str());
57  hists.at(9)->Draw(("same"+style).c_str());
58 
59 }
60 
62 
63  // get asimov histogram
64  TH1D* asimovSpectra = (TH1D*)_file0->Get("fake/Universe_0/AsimovUniverse_0");
65 
66  // just get the first 10 histograms
67  std::vector<TH1D*> poissonUniverses;
68  std::vector<TH1D*> ratios;
69  std::string prePath, poissonName, ratioName;
70  for (int i = 0; i < 10; ++i){
71 
72  prePath = "fake/Universe_" + std::to_string(i) + "/";
73  poissonName = "PoissonUniverse_" + std::to_string(i);
74  ratioName = "RatioToAsimovUniverse_" + std::to_string(i);
75 
76  poissonUniverses.push_back((TH1D*)_file0->Get((prePath+poissonName).c_str()));
77  ratios.push_back((TH1D*)_file0->Get((prePath+ratioName).c_str()));
78 
79  }
80 
81  // style histograms
82  StyleHistograms(poissonUniverses);
83  StyleHistograms(ratios);
84  asimovSpectra->SetLineColor(kBlack);
85  asimovSpectra->SetLineWidth(2);
86  asimovSpectra->SetTitle("Asimov Spectra and Poisson Fluctuations;Bin;Events");
87 
88  TCanvas* c1 = new TCanvas("c1", "", 600, 800);
89  TPad* topPad = new TPad("topPad", "", 0.005, 0.5 , 0.995, 0.995);
90  TPad* botPad = new TPad("botPad", "", 0.005, 0.005, 0.995, 0.5 );
91  topPad->Draw();
92  botPad->Draw();
93  topPad->cd();
94  topPad->SetLogy();
95 
96  asimovSpectra->GetYaxis()->SetRangeUser(0.1, asimovSpectra->GetMaximum()*1.4);
97  asimovSpectra->Draw("hist");
98  DrawHistograms(poissonUniverses, "hist");
99  asimovSpectra->Draw("hist same");
100 
101  botPad->cd();
102  ratios.at(0)->SetTitle(";Bin;Poisson Universe/Asimov Universe");
103  DrawHistograms(ratios, "p");
104 
105  c1->SaveAs("RandomUniverses.pdf");
106  c1->SaveAs("RandomUniverses.png");
107 
108 }
enum BeamMode kOrange
enum BeamMode kRed
TPad * botPad
Definition: PlotSpectra.h:75
void DrawHistograms(std::vector< TH1D * > hists, std::string style)
TPad * topPad
Definition: PlotSpectra.h:74
TString hists[nhists]
Definition: bdt_com.C:3
void makeRandomUniverseHistograms()
enum BeamMode kViolet
c1
Definition: demo5.py:24
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
enum BeamMode kGreen
void StyleHistograms(std::vector< TH1D * > hists)
enum BeamMode string