| 1 | // ==========================================================================
|
|---|
| 2 | // ============ see plot_ranger function at the end of the file =============
|
|---|
| 3 | // ==========================================================================
|
|---|
| 4 | void plot_resolution()
|
|---|
| 5 | {
|
|---|
| 6 | // Get the profile produced by Draw from the current pad
|
|---|
| 7 | TProfile *p = (TProfile*)gPad->FindObject("htemp");
|
|---|
| 8 | if (!p)
|
|---|
| 9 | return;
|
|---|
| 10 |
|
|---|
| 11 | // Change errors from error of mean to sqrt(variance) ("spread")
|
|---|
| 12 | p->SetErrorOption("s");
|
|---|
| 13 |
|
|---|
| 14 | // Create a new histogram with the errors as entries
|
|---|
| 15 | TH1D *h = p->ProjectionX("ptemp", "C=E");
|
|---|
| 16 |
|
|---|
| 17 | // Remove the profile from the pad and from memory
|
|---|
| 18 | delete p;
|
|---|
| 19 |
|
|---|
| 20 | // Split the title into x- and y-axis title and set them accordingly
|
|---|
| 21 | TObjArray *arr = TString(h->GetTitle()).Tokenize(":");
|
|---|
| 22 | h->SetXTitle(arr->At(1)->GetName());
|
|---|
| 23 | h->SetYTitle(arr->At(0)->GetName());
|
|---|
| 24 | delete arr;
|
|---|
| 25 |
|
|---|
| 26 | // Some additional configuration
|
|---|
| 27 | h->SetDirectory(0);
|
|---|
| 28 | h->SetStats(kFALSE);
|
|---|
| 29 | h->SetMinimum(0);
|
|---|
| 30 |
|
|---|
| 31 | // Draw the new histogram into the current pad
|
|---|
| 32 | h->Draw();
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | // ==========================================================================
|
|---|
| 36 | //
|
|---|
| 37 | // Run the macro with
|
|---|
| 38 | //
|
|---|
| 39 | // root hawc/plot_ranger.C
|
|---|
| 40 | //
|
|---|
| 41 | // The default file name is "ranger.csv.root", To change this use
|
|---|
| 42 | //
|
|---|
| 43 | // root -b -q hawc/ratescan.C\(\"myfile.root\"\)
|
|---|
| 44 | //
|
|---|
| 45 | // The defaul ttree name is "Events", To change this use
|
|---|
| 46 | //
|
|---|
| 47 | // root -b -q hawc/ratescan.C\(\"myfile.root\",\"MyTree\"\)
|
|---|
| 48 | //
|
|---|
| 49 | // From within root, the escape characters can be omitted, e.g.
|
|---|
| 50 | //
|
|---|
| 51 | // root
|
|---|
| 52 | // [0] .x hawc/ratescan.C("myfile.root","MyTree")
|
|---|
| 53 | //
|
|---|
| 54 | // ==========================================================================
|
|---|
| 55 |
|
|---|
| 56 | void plot_ranger(const char *filename="ranger.csv.root", const char *tree="Events")
|
|---|
| 57 | {
|
|---|
| 58 | // Crate a chian to read the trees and add the file
|
|---|
| 59 | // (or all files if wildcards are used)
|
|---|
| 60 | TChain c(tree);
|
|---|
| 61 | c.Add(filename);
|
|---|
| 62 |
|
|---|
| 63 | // Create the display and set a title
|
|---|
| 64 | MStatusDisplay *d = new MStatusDisplay;
|
|---|
| 65 | d->SetTitle(filename);
|
|---|
| 66 |
|
|---|
| 67 | // ------------------------------------------------------------------
|
|---|
| 68 |
|
|---|
| 69 | TCanvas &c0 = d->AddTab("Pediction");
|
|---|
| 70 | gPad->SetGrid();
|
|---|
| 71 | c.Draw("Predictions:True", "", "col");
|
|---|
| 72 | c.Draw("Predictions:True", "", "same");
|
|---|
| 73 |
|
|---|
| 74 | TGraph *g = (TGraph*)gPad->FindObject("Graph");
|
|---|
| 75 | if (!g)
|
|---|
| 76 | return;
|
|---|
| 77 |
|
|---|
| 78 | TF1 equal("equal", "x", -1e100, 1e100);
|
|---|
| 79 | equal.DrawCopy("same");
|
|---|
| 80 |
|
|---|
| 81 | // ------------------------------------------------------------------
|
|---|
| 82 |
|
|---|
| 83 | TF1 zero("zero", "0", -1e100, 1e100);
|
|---|
| 84 | zero.SetLineStyle(kDashed);
|
|---|
| 85 | zero.SetLineWidth(1);
|
|---|
| 86 | zero.SetLineColor(kBlue);
|
|---|
| 87 |
|
|---|
| 88 | TCanvas &c1 = d->AddTab("Bias");
|
|---|
| 89 | c1.Divide(2,2);
|
|---|
| 90 |
|
|---|
| 91 | c1.cd(1);
|
|---|
| 92 | c.Draw("Predictions-True:True", "", "col");
|
|---|
| 93 | c.Draw("Predictions-True:True", "", "same");
|
|---|
| 94 | zero.DrawCopy("same");
|
|---|
| 95 |
|
|---|
| 96 | c1.cd(2);
|
|---|
| 97 | c.Draw("Predictions-True:Predictions", "", "col");
|
|---|
| 98 | c.Draw("Predictions-True:Predictions", "", "same");
|
|---|
| 99 | zero.DrawCopy("same");
|
|---|
| 100 |
|
|---|
| 101 | c1.cd(3);
|
|---|
| 102 | c.Draw("(Predictions-True)/True:True", "", "col");
|
|---|
| 103 | c.Draw("(Predictions-True)/True:True", "", "same");
|
|---|
| 104 | zero.DrawCopy("same");
|
|---|
| 105 |
|
|---|
| 106 | c1.cd(4);
|
|---|
| 107 | c.Draw("(Predictions-True)/Predictions:Predictions", "", "col");
|
|---|
| 108 | c.Draw("(Predictions-True)/Predictions:Predictions", "", "same");
|
|---|
| 109 | zero.DrawCopy("same");
|
|---|
| 110 |
|
|---|
| 111 | // ------------------------------------------------------------------
|
|---|
| 112 |
|
|---|
| 113 | TCanvas &c2 = d->AddTab("Resolution");
|
|---|
| 114 | c2.Divide(2,2);
|
|---|
| 115 |
|
|---|
| 116 | c2.cd(1);
|
|---|
| 117 | c.Draw("Predictions-True:True", "", "prof");
|
|---|
| 118 | plot_resolution();
|
|---|
| 119 |
|
|---|
| 120 | c2.cd(2);
|
|---|
| 121 | c.Draw("Predictions-True:Predictions", "", "prof");
|
|---|
| 122 | plot_resolution();
|
|---|
| 123 |
|
|---|
| 124 | c2.cd(3);
|
|---|
| 125 | c.Draw("(Predictions-True)/True:True", "", "prof");
|
|---|
| 126 | plot_resolution();
|
|---|
| 127 |
|
|---|
| 128 | c2.cd(4);
|
|---|
| 129 | c.Draw("(Predictions-True)/Predictions:Predictions", "", "prof");
|
|---|
| 130 | plot_resolution();
|
|---|
| 131 |
|
|---|
| 132 | // ------------------------------------------------------------------
|
|---|
| 133 |
|
|---|
| 134 | TObjArray *leaves = c.GetListOfLeaves();
|
|---|
| 135 |
|
|---|
| 136 | TIter Next(leaves);
|
|---|
| 137 | TObject *o=0;
|
|---|
| 138 | while ((o=Next()))
|
|---|
| 139 | {
|
|---|
| 140 | TString name = o->GetName();
|
|---|
| 141 | if (name=="True" || name=="Predictions")
|
|---|
| 142 | continue;
|
|---|
| 143 |
|
|---|
| 144 | TCanvas &cc = d->AddTab(name);
|
|---|
| 145 | cc.Divide(2,2);
|
|---|
| 146 |
|
|---|
| 147 | cc.cd(1);
|
|---|
| 148 | c.Draw("Predictions-True:"+name, "", "col");
|
|---|
| 149 | c.Draw("Predictions-True:"+name, "", "same");
|
|---|
| 150 | zero.DrawCopy("same");
|
|---|
| 151 |
|
|---|
| 152 | cc.cd(2);
|
|---|
| 153 | c.Draw("(Predictions-True)/Predictions:"+name, "", "col");
|
|---|
| 154 | c.Draw("(Predictions-True)/Predictions:"+name, "", "same");
|
|---|
| 155 | zero.DrawCopy("same");
|
|---|
| 156 |
|
|---|
| 157 | cc.cd(3);
|
|---|
| 158 | c.Draw("Predictions-True:"+name, "", "prof");
|
|---|
| 159 | plot_resolution();
|
|---|
| 160 |
|
|---|
| 161 | cc.cd(4);
|
|---|
| 162 | c.Draw("(Predictions-True)/Predictions:"+name, "", "prof");
|
|---|
| 163 | plot_resolution();
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | // ------------------------------------------------------------------
|
|---|
| 167 | // To store the display into a root or pdf file do
|
|---|
| 168 |
|
|---|
| 169 | //d->SaveAs("display.root");
|
|---|
| 170 | d->SaveAs("display.pdf");
|
|---|
| 171 | }
|
|---|