Plotting_CompareMultipleContours.C
Go to the documentation of this file.
1 #pragma once
2 
5 #include "colors.h"
6 
7 using namespace ana;
8 
9 std::vector<int> vec_Colors0 = getColors(0);
10 std::vector<int> vec_Colors1 = getColors(1);
11 std::vector<int> vec_MyColors = {vec_Colors1.at(2), vec_Colors1.at(5), vec_Colors1.at(8), vec_Colors0.at(21), vec_Colors0.at(1), vec_Colors1.at(3)};
12 //std::vector<int> vec_MyColors = getColors(4);
13 
15 {
16 
17  TPaveText *pavetext = new TPaveText (0.15,0.92,0.16,0.96,"NDC");
18  pavetext->SetFillStyle(0);
19  pavetext->SetLineColor(0);
20  pavetext->SetLineWidth(0);
21  pavetext->SetBorderSize(1);
22  pavetext->SetTextColor(kGray+2);
23  pavetext->AddText(s.c_str());
24  pavetext->SetTextSize(2/40.);
25  pavetext->SetTextAlign(11);
26  pavetext->Draw();
27 }
28 
30 {
31 
32  TPaveText *pavetext = new TPaveText (0.59,0.92,0.95,0.96,"NDC");
33  pavetext->SetFillStyle(0);
34  pavetext->SetLineColor(0);
35  pavetext->SetLineWidth(0);
36  pavetext->SetBorderSize(1);
37  pavetext->SetTextColor(kBlue);
38  pavetext->AddText("NOvA Preliminary");
39  pavetext->SetTextSize(2/40.); // official is 2/50
40  pavetext->SetTextAlign(11);
41  pavetext->Draw();
42 
43 }
44 
45 std::pair<bool,bool> CheckIfDegen(std::string s_FileName)
46 {
47  std::vector<std::pair<std::string,bool>> vec_DegenFits = {
48  {"/nova/data/users/abooth/Year2/TR_R18-06-11-2018anaa_BoxOpening/RHCOnly/contours/th23_dmsq/stat/hist_contours_2018_numuOnly_realData_RHCOnly_onlyNHcombo_dmsq_stats.root", false},
49  {"/nova/data/users/abooth/Year2/TR_R18-06-11-2018anaa_BoxOpening/RHCOnly/contours/th23_dmsq/syst/hist_contours_2018_numuOnly_realData_RHCOnly_onlyNHcombo_dmsq_systs.root", false},
50  {"/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/190426/RHCOnly/contours/FCInputs/th23_dmsq/stat/hist_contours_2019_numuOnly_realData_RHCOnly_onlyNH_dmsq_stats.root", false},
51  {"/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/190426/RHCOnly/contours/FCInputs/th23_dmsq/syst/hist_contours_2019_numuOnly_realData_RHCOnly_onlyNH_dmsq_systs.root", false},
52  {"/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/190426/RHCOnly/contours/FCInputs/th23_dmsq/stat/hist_contours_2019_numuOnly_realData_RHCOnly_onlyIH_dmsq_stats.root", false},
53  {"/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/190426/RHCOnly/contours/FCInputs/th23_dmsq/syst/hist_contours_2019_numuOnly_realData_RHCOnly_onlyIH_dmsq_systs.root", false},
54  {"/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/Testing/RHCOnly/contours/FCInputs/th23_dmsq/stat/hist_contours_2019_numuOnly_realData_RHCOnly_onlyNH_dmsq_stats.root", false},
55  {"/nova/data/users/abooth/Year2/TR_R19-04-17-2019anaa_BoxOpening/Testing/RHCOnly/contours/FCInputs/th23_dmsq/syst/hist_contours_2019_numuOnly_realData_RHCOnly_onlyNH_dmsq_systs.root", false},
56  {"/nova/ana/nu_mu_ana/Ana2018/Results/surfprof_realdata_cosmics_rhc__extrap_stats_2018calc_nh__numu2018.root", false},
57  {"/nova/ana/nu_mu_ana/Ana2018/Results/surfprof_realdata_cosmics_rhc__extrap_systs_2018calc_nh__numu2018.root", false},
58  };
59 
60  for(unsigned int i = 0; i < vec_DegenFits.size(); i++)
61  {
62  if(s_FileName==vec_DegenFits.at(i).first)
63  {
64  return {true, vec_DegenFits.at(i).second};
65  }
66  }
67 
68  return {false, true};
69 }
70 
71 void DrawDegenBF(double bfth23, double bfdm2, Color_t color, Style_t marker, double size, bool isFHC)
72 {
73  double mirrorPoint = isFHC ? 0.514 : 0.511;
74  double mirror = bfth23;
75 
76  TMarker* manMarker = new TMarker(bfth23, bfdm2, marker);
77  manMarker->SetMarkerSize(size);
78  manMarker->SetMarkerColor(color);
79  manMarker->Draw();
80 
81  if(bfth23 > mirrorPoint) mirror = mirrorPoint - (bfth23 - mirrorPoint);
82  if(bfth23 < mirrorPoint) mirror = mirrorPoint + (mirrorPoint - bfth23);
83  TMarker* mirrorMarker = new TMarker(mirror, bfdm2, marker);
84  mirrorMarker->SetMarkerSize(size);
85  mirrorMarker->SetMarkerColor(color);
86  mirrorMarker->Draw();
87 }
88 
90  std::string s_FileAppend, std::string s_Title,
91  bool includeMinInfo,
92  double dmsqMin = 2.25, double dmsqMax = 3.2,
93  double th23Min = 0.30, double th23Max = 0.70)
94  //double th23Min = 0.18, double th23Max = 0.82)
95 {
96  std::ifstream f_InList;
97  f_InList.open(s_InFile);
98 
99  std::vector<std::pair<std::string,std::string>> vec_FileList;
100  std::string s_Line, s_FileName, s_Label;
101  while(std::getline(f_InList, s_Line))
102  {
103  s_FileName = s_Line.substr(0, s_Line.find(' '));
104  s_Label = s_Line.substr(s_Line.find('"')+1, s_Line.find_last_of('"')-s_Line.find('"')-1);
105  std::cout << std::endl;
106  std::cout << "ADD FILE: " << s_FileName << " WITH LABEL: " << s_Label << std::endl;
107  std::cout << std::endl;
108  vec_FileList.push_back({s_FileName, s_Label});
109  }
110 
111  TLegend *leg;
112  if(includeMinInfo)
113  {
114  leg = new TLegend(0.32, 0.71, 0.85, 0.85);
115  }
116  else
117  {
118  //leg = new TLegend(0.55, 0.71, 0.85, 0.85);
119  leg = new TLegend(0.32, 0.71, 0.85, 0.85);
120  }
121  leg->SetHeader("NOvA NH 90\% CL");
122  leg->SetTextSizePixels(20);
123  leg->SetBorderSize(0);
124  leg->SetFillStyle(0);
125 
126  std::vector<FrequentistSurface*> vec_Surface;
127  TH2 *hAxes;
128  bool haveAxes = false;
129  for(unsigned int i = 0; i < vec_FileList.size(); i++)
130  {
131  TFile *f_File = new TFile(vec_FileList.at(i).first.c_str(), "READ");
132  TIter iter(f_File->GetListOfKeys());
133  TKey *key;
134  while((key=(TKey*)iter()))
135  {
136  TString name1 = ((TObject*)key->ReadObj())->GetName();
137  if(name1.Contains("surf"))
138  {
139  auto surf = FrequentistSurface::LoadFrom(f_File, name1).release();
140  vec_Surface.push_back(surf);
141  if(!haveAxes)
142  {
143  hAxes = (TH2*)((f_File->GetDirectory(name1))->Get("hist"));
144  haveAxes = true;
145  }
146  }
147  }
148  TH1D *h = new TH1D(Form("h%i", i), Form("h%i", i), 1, 0, 1);
149  //h->SetLineStyle(i % 2 == 0 ? kSolid : kDashed);
150  h->SetLineColor(vec_MyColors.at(i));
151  TString s_FitInfo = Form(". Minima: #chi^{2} = %.2f, sin^{2}#theta_{23} = %.2f, #Deltam^{2}_{32} = %.2f",
152  vec_Surface.at(i)->MinChi (),
153  vec_Surface.at(i)->GetMinX(),
154  vec_Surface.at(i)->GetMinY());
155  TString s_ThisLabel = vec_FileList.at(i).second.c_str() + s_FitInfo;
156  leg->AddEntry(h, (includeMinInfo ? s_ThisLabel : (TString)vec_FileList.at(i).second), "L");
157  }
158 
159  TCanvas *c = new TCanvas("c_surface", "c_surface", 800, 600);
160  c->SetBottomMargin(0.14);
161  c->SetLeftMargin (0.12);
162  gStyle->SetTitleOffset(1.02,"x");
163  for(unsigned int i = 0; i < vec_Surface.size(); i++)
164  {
165  if(i == 0)
166  {
167  //hAxes->SetTitle(s_Title.c_str());
168  hAxes->SetTitle("");
169  hAxes->GetXaxis()->CenterTitle();
170  hAxes->GetYaxis()->CenterTitle();
171  hAxes->GetXaxis()->SetRangeUser(th23Min, th23Max);
172  hAxes->GetYaxis()->SetRangeUser(dmsqMin, dmsqMax);
173  hAxes->Draw("AXIS");
174  }
175  //vec_Surface.at(i)->DrawContour(Gaussian90Percent2D(*vec_Surface.at(i)), (i % 2 == 0 ? kSolid : kDashed), vec_MyColors.at(i));
176  vec_Surface.at(i)->DrawContour(Gaussian90Percent2D(*vec_Surface.at(i)), kSolid, vec_MyColors.at(i));
177  //vec_Surface.at(i)->DrawBestFit(vec_MyColors.at(i));
178  std::pair<bool,bool> degenInfo = CheckIfDegen(vec_FileList.at(i).first);
179  /*
180  if(degenInfo.first)
181  {
182  DrawDegenBF(vec_Surface.at(i)->GetMinX(), vec_Surface.at(i)->GetMinY(), vec_MyColors.at(i), kFullCircle, 1.5, degenInfo.second);
183  }*/
184  }
185 
186  std::string s_NFC = "No Feldman-Cousins";
187  leg->Draw();
189  CornerLabel(s_NFC);
190 
191  c->SaveAs((s_OutDir + "surfaces_" + (includeMinInfo ? "FitInfo_" : "") + s_FileAppend + "_NBF.pdf").c_str());
192  TFile *f_Out = new TFile("surfaces_Raw.root", "UPDATE");
193  c->SetName(((includeMinInfo ? "FitInfo_" : "") + s_FileAppend + "_NBF").c_str());
194  c->Write();
195  c->Close();
196 }
197 
std::vector< int > vec_Colors1
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
std::vector< int > vec_Colors0
void PreliminaryBoxOpening()
const XML_Char * s
Definition: expat.h:262
std::string GetName(int i)
std::pair< bool, bool > CheckIfDegen(std::string s_FileName)
static bool isFHC
void DrawDegenBF(double bfth23, double bfdm2, Color_t color, Style_t marker, double size, bool isFHC)
OStream cout
Definition: OStream.cxx:6
const std::vector< int > & getColors(int whichColours)
Definition: colors.h:83
void Plotting_CompareMultipleContours(std::string s_InFile, std::string s_OutDir, std::string s_FileAppend, std::string s_Title, bool includeMinInfo, double dmsqMin=2.25, double dmsqMax=3.2, double th23Min=0.30, double th23Max=0.70)
void CornerLabel(std::string &s)
std::vector< int > vec_MyColors
TH2 * Gaussian90Percent2D(const FrequentistSurface &s)
Up-value surface for 90% confidence in 2D in gaussian approximation.
enum BeamMode kBlue
static std::unique_ptr< FrequentistSurface > LoadFrom(TDirectory *dir, const std::string &name)
surf
Definition: demo5.py:35
enum BeamMode string