makeContourPlots.C
Go to the documentation of this file.
1 // script to make some contour plots for CMF sterile analysis.
2 //
3 // run : root -l -b 'makeContourPlots.C("/path/to/input/file", {1,2,3}, "xpar", "ypar")'
4 // where:
5 // -- arg1: a histogram file
6 // -- arg2: a vector of the contour levels to run, 1 sigma, 2 sigma, etc.
7 // -- arg3/4: parameter names - must match those in the file _exactly_
8 //
9 // author: Adam Lister
10 // email : alister1@fnal.gov
11 
12 #include "Utilities.h"
13 
14 //------------------------------------------------------------------------------
15 TCanvas* InitialiseCanvas(){
16 
17  TCanvas* canv = new TCanvas("canv", "", 100, 100);
18  int canvx = 500;
19  int canvy = 500;
20  if (xaxis == "Th24" && yaxis == "Dmsq41"){
21  canvx = 400;
22  canvy = 600;
23  canv->SetLogx();
24  canv->SetLogy();
25  }
26  if (xaxis == "Th23" && yaxis == "Dmsq32"){
27  canvx = 600;
28  canvy = 400;
29  }
30 
31  canv->SetCanvasSize(canvx, canvy);
32  canv->SetRightMargin(0.18);
33 
34  return canv;
35 }
36 
37 //------------------------------------------------------------------------------
38 void DrawLegend(LegendMap& legobj, int textCol = kBlack){
39  TLegend* leg = new TLegend(0.65, 0.15, 0.85, 0.15+(0.05*legobj.size()));
40  leg->SetLineWidth(0);
41  leg->SetFillStyle(0);
42  leg->SetTextColor(textCol);
43 
44  for (auto& lo : legobj){
45  if (lo.first == "Best Fit")
46  leg->AddEntry(lo.second, lo.first.c_str(), "p");
47  else
48  leg->AddEntry(lo.second, lo.first.c_str(), "l");
49  }
50 
51  leg->Draw("same");
52 }
53 
54 //------------------------------------------------------------------------------
55 void DrawDelChisqAndContours(TH2D* delchisq,
56  ContourCollection& contours)
57 {
58  TCanvas* canv = InitialiseCanvas();
59  delchisq->Draw("colz");
60  DrawContour(contours, CLNumber::kEmpty, kWhite);
61 
62  LegendMap legmap = {
63  {contours[0].clnLatex, contours[0].contours[0]},
64  {contours[1].clnLatex, contours[1].contours[0]},
65  {contours[2].clnLatex, contours[2].contours[0]},
66  };
67 
68  TGraph* bfp = nullptr;
69  if (contours[0].clt == CLType::kAsimov){
71  bfp->SetMarkerStyle(29);
72  //bfp->SetMarkerSize(0.5);
73  bfp->SetMarkerColor(kPTRed);
74  bfp->Draw("same p");
75  legmap["Best Fit"] = bfp;
76  }
77 
78  DrawLegend(legmap, kWhite);
79 
80  std::string name =
81  "DelChiSqAndContours" +
82  contours[0].cltName +
83  xaxis + yaxis;
84 
85 
86  canv->SaveAs((std::string(name+".png")).c_str());
87  canv->SaveAs((std::string(name+".pdf")).c_str());
88  delete canv;
89 }
90 
91 //------------------------------------------------------------------------------
92 void DrawUniverses(TH2D* background,
93  std::vector<ContourCollection>& uniContours,
94  ContourCollection& asimov,
96  CLNumber cln)
97 {
98  // set the title for the background histogram to reflect the confidence level
99  background->SetTitle(("Universe Contours - " + CLNameLaTeX[cln]).c_str());
100 
101  TCanvas* canv = InitialiseCanvas();
102  background->Draw();
103  for (int i = 0; i < uniContours.size(); ++i){
104  DrawContour(uniContours[i], cln, -1, 1);
105  }
106  DrawContour(asimov, cln, -1, 1);
107  DrawContour(median, cln, -1, 1);
108 
109  //TGraph* bfp = nullptr;
110  //bfp = GetUniverseBestFitPoints();
111  //bfp->SetMarkerStyle(29);
112  //bfp->SetMarkerColor(kPTRed);
113  //bfp->Draw("same p");
114 
115  LegendMap legmap = {
116  {"Asimov", asimov[0].contours[0]},
117  {"Median", median[0].contours[0]},
118  {"Universes", uniContours[0][0].contours[0]},
119  //{"Best Fit", bfp}
120  };
121 
122  DrawLegend(legmap);
123 
124  std::string name = xaxis + yaxis + CLName[cln] + "UniverseContours";
125 
126  canv->SaveAs((std::string(name+".png")).c_str());
127  canv->SaveAs((std::string(name+".pdf")).c_str());
128  delete canv;
129 }
130 
131 //------------------------------------------------------------------------------
132 void DrawHeatMaps(std::vector<TH2F*> heatMaps,
133  ContourCollection asimovContours,
134  ContourCollection medianContours,
135  CLNumber cln,
136  int max)
137 {
138  TCanvas* canv = InitialiseCanvas();
139  heatMaps[cln]->SetMaximum(max);
140  heatMaps[cln]->Draw("colz");
141  DrawContour(asimovContours, cln, kPTOrange);
142  DrawContour(medianContours, cln, kPTRed);
143 
144  LegendMap legmap = {
145  {"Asimov", asimovContours[0].contours[0]},
146  {"Median", medianContours[0].contours[0]}
147  };
148  DrawLegend(legmap);
149 
150  std::string name = xaxis + yaxis + CLName[cln] + "HeatMaps";
151 
152  canv->SaveAs((std::string(name + ".png")).c_str());
153  canv->SaveAs((std::string(name + ".pdf")).c_str());
154  delete canv;
155 
156 }
157 
158 //------------------------------------------------------------------------------
160  std::pair<float, float> const& range){
161  gStyle->SetPalette(kCandy);
162  TCanvas* canv = InitialiseCanvas();
163  h->SetMaximum(range.second);
164  h->SetMinimum(range.first);
165  h->SetContour(1000);
166  h->Draw("colz");
167 
168  std::string name = (std::string)h->GetName();
169  canv->SaveAs((std::string(xaxis + yaxis + name + ".png")).c_str());
170  canv->SaveAs((std::string(xaxis + yaxis + name + ".pdf")).c_str());
171 }
172 
173 // main function
174 //.............................................................................
176  std::vector<int> contours,
177  std::string xlabel,
178  std::string ylabel){
179 
180  SetGlobalVariables(file, xlabel, ylabel, contours);
182 
183  // get the contours and other plots we're going to want to use
184  TH2D* background = GetDeltaChiSqr(CLType::kNoType);
185  TH2D* asimovDeltaChisq = GetDeltaChiSqr(CLType::kAsimov);
186  TH2D* medianDeltaChisq = GetDeltaChiSqr(CLType::kMedian);
189  std::vector<ContourCollection> uniContours = GetUniverseContours();
190  std::vector<TH2F*> heatMaps = GetHeatMaps();
191  TGraph* uniBestFitPoints = GetUniverseBestFitPoints();
192  TGraph* asimovBestFit = GetBestFitPoint(CLType::kAsimov);
193  std::vector<TH2D*> hiddenParVec;
194  std::vector<std::pair<float, float>> hiddenParRange;
195 
196  if(xlabel == "Th23" && ylabel == "Dmsq32"){
197  hiddenParVec.emplace_back(GetHiddenParameter("Th13"));
198  hiddenParRange.emplace_back(std::make_pair(0.14, 0.15));
199  hiddenParVec.emplace_back(GetHiddenParameter("dCP"));
200  hiddenParRange.emplace_back(std::make_pair(0, 6.283185));
201  }
202  else if(xlabel == "Th24" && ylabel == "Dmsq41"){
203  hiddenParVec.emplace_back(GetHiddenParameter("Th34"));
204  hiddenParRange.emplace_back(std::make_pair(0., 0.76));
205  hiddenParVec.emplace_back(GetHiddenParameter("Th23"));
206  hiddenParRange.emplace_back(std::make_pair(0.4, 0.65));
207  hiddenParVec.emplace_back(GetHiddenParameter("Dmsq32"));
208  hiddenParRange.emplace_back(std::make_pair(2.45, 2.57));
209  }
210  else if(xlabel == "Th24" && ylabel == "Th34"){
211  hiddenParVec.emplace_back(GetHiddenParameter("Dmsq41"));
212  hiddenParRange.emplace_back(std::make_pair(0., 100.));
213  hiddenParVec.emplace_back(GetHiddenParameter("Th23"));
214  hiddenParRange.emplace_back(std::make_pair(0.4, 0.65));
215  hiddenParVec.emplace_back(GetHiddenParameter("Dmsq32"));
216  hiddenParRange.emplace_back(std::make_pair(2.45e-3, 2.57e-3));
217  }
220 
221  DrawDelChisqAndContours(asimovDeltaChisq, asimovContours);
222  DrawDelChisqAndContours(medianDeltaChisq, medianContours);
223  DrawUniverses(background, uniContours, asimovContours, medianContours, kOneSigma);
224  DrawUniverses(background, uniContours, asimovContours, medianContours, kTwoSigma);
225  DrawUniverses(background, uniContours, asimovContours, medianContours, kThreeSigma);
226  DrawHeatMaps(heatMaps, asimovContours, medianContours, kOneSigma, uniContours.size());
227  DrawHeatMaps(heatMaps, asimovContours, medianContours, kTwoSigma, uniContours.size());
228  DrawHeatMaps(heatMaps, asimovContours, medianContours, kThreeSigma, uniContours.size());
229 
230  for(size_t hp = 0; hp < hiddenParVec.size(); ++hp)
231  DrawHiddenParameter(hiddenParVec[hp], hiddenParRange[hp]);
232 
233 }
const XML_Char * name
Definition: expat.h:151
TSpline3 lo("lo", xlo, ylo, 12,"0")
void DrawDelChisqAndContours(TH2D *delchisq, ContourCollection &contours)
std::vector< Contour > ContourCollection
Definition: Utilities.h:134
TH2D * GetDeltaChiSqr(CLType clt, int universeNum=-1)
Definition: Utilities.h:381
void SetCMFColorPalette()
Definition: Utilities.h:138
std::string yaxis
TH2D * GetHiddenParameter(std::string hiddenParName)
Definition: Utilities.h:539
TCanvas * canv
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
std::map< std::string, TObject * > LegendMap
Definition: Utilities.h:135
std::string xaxis
std::vector< ContourCollection > GetUniverseContours()
Definition: Utilities.h:509
void DrawUniverses(TH2D *background, std::vector< ContourCollection > &uniContours, ContourCollection &asimov, ContourCollection &median, CLNumber cln)
std::vector< TH2F * > GetHeatMaps()
Definition: Utilities.h:523
TGraph * GetBestFitPoint(CLType clt, int universeNum=-1)
Definition: Utilities.h:436
std::vector< std::string > CLNameLaTeX
Definition: Utilities.h:24
TGraph * GetUniverseBestFitPoints()
Definition: Utilities.h:456
void DrawLegend(LegendMap &legobj, int textCol=kBlack)
void DrawHiddenParameter(TH2D *h, std::pair< float, float > const &range)
std::vector< std::string > CLName
Definition: Utilities.h:15
void DrawHeatMaps(std::vector< TH2F * > heatMaps, ContourCollection asimovContours, ContourCollection medianContours, CLNumber cln, int max)
double median(TH1D *h)
Definition: absCal.cxx:524
Int_t kPTRed
Definition: Utilities.h:50
void makeContourPlots(std::string file, std::vector< int > contours, std::string xlabel, std::string ylabel)
void DrawContour(ContourCollection cc, CLNumber cln=CLNumber::kEmpty, int colorOverride=-1, int styleOverride=-1)
Definition: Utilities.h:180
TCanvas * InitialiseCanvas()
TFile * file
Definition: cellShifts.C:17
void SetGlobalVariables(std::string f, std::string xax, std::string yax, std::vector< int > contours)
Definition: Utilities.h:52
Float_t e
Definition: plot.C:35
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
void Save1DContour(CLType clt, std::string var, int universeNum=-1)
Definition: Utilities.h:217
ContourCollection GetContours(CLType clt, int universeNum=-1)
Definition: Utilities.h:469
Int_t kPTOrange
Definition: Utilities.h:50
enum BeamMode string