Crombie Tools
PlotBrazil.cc
Go to the documentation of this file.
1 /**
2  @file PlotBrazil.cc
3  Defines the PlotBrazil class.
4  @author Daniel Abercrombie <dabercro@mit.edu>
5 */
6 
7 #include <vector>
8 #include <fstream>
9 
10 #include "PlotBrazil.h"
11 
13 
14 //--------------------------------------------------------------------
15 PlotBrazil::PlotBrazil( TString fileName )
16 {
17 
18  if (fileName != "")
19  ReadConfig(fileName);
20 
21  AddLegendEntry("2-#sigma band", 5);
22  AddLegendEntry("1-#sigma band", 3);
23  AddLegendEntry("Expected", 1, 3, 2);
24  AddLegendEntry("Observed", 1, 3, 1);
25 
26 }
27 
28 //--------------------------------------------------------------------
30 { }
31 
32 
33 //--------------------------------------------------------------------
34 void
35 PlotBrazil::AddPoint ( Double_t point, Double_t observed, Double_t lowest, Double_t low,
36  Double_t mid, Double_t high, Double_t highest )
37 {
38 
39  DisplayFunc(__func__);
40  Message(eDebug, "Adding point at %f, observed: %f, limit band: %f, %f, %f, %f, %f",
41  point, observed, lowest, low, mid, high, highest);
42 
43  Int_t Npoint = fObserved.GetN();
44 
45  // Set the single lines
46 
47  fObserved.SetPoint(Npoint, point, observed);
48  fObserved.SetPointError(Npoint, 0.0, 0.0);
49  fExpected.SetPoint(Npoint, point, mid);
50  fExpected.SetPointError(Npoint, 0.0, 0.0);
51 
52  // Make the bands
53 
54  fOneSigma.SetPoint(Npoint, point, (low + high)/2);
55  fOneSigma.SetPointError(Npoint, 0.0, (high - low)/2);
56 
57  fTwoSigma.SetPoint(Npoint, point, (lowest + highest)/2);
58  fTwoSigma.SetPointError(Npoint, 0.0, (highest - lowest)/2);
59 
60  // Sort everything, just in case
61 
62  fExpected.Sort();
63  fObserved.Sort();
64  fOneSigma.Sort();
65  fTwoSigma.Sort();
66 
67 }
68 
69 //--------------------------------------------------------------------
70 void
72 {
73 
74  DisplayFunc(__func__);
75  Message(eInfo, "Reading config file: %s", filename.Data());
76 
77  std::ifstream configFile;
78  configFile.open(filename.Data());
79  TString xVal;
80  TString observed;
81  TString lowest, low, mid, high, highest;
82  Bool_t reading = true;
83 
84  while (reading) {
85  configFile >> xVal >> observed >> lowest >> low >> mid >> high >> highest;
86  if (highest != "")
87  AddPoint(xVal.Atof(), observed.Atof(), lowest.Atof(), low.Atof(),
88  mid.Atof(), high.Atof(), highest.Atof());
89  else
90  reading = false;
91  }
92 
93  configFile.close();
94 
95 }
96 
97 //--------------------------------------------------------------------
98 void
99 PlotBrazil::MakePlot(TString FileBase, TString XLabel, TString YLabel,
100  Bool_t logY, Bool_t logX)
101 {
102 
103  std::vector<TGraphErrors*> theLines;
104 
105  fTwoSigma.SetFillColor(5);
106  fOneSigma.SetFillColor(3);
107  fTwoSigma.SetFillStyle(1001);
108  fOneSigma.SetFillStyle(1001);
109 
110  theLines.push_back(&fTwoSigma);
111  theLines.push_back(&fOneSigma);
112  theLines.push_back(&fExpected);
113  theLines.push_back(&fObserved);
114 
115  SetDrawFirst(0);
116 
117  BaseCanvas(FileBase, theLines, XLabel, YLabel, logY, logX);
118 
119 }