2 #include "PlottingUtils/PlottingUtils.h"
3 #include "PlottingUtils/PlottingManager.h"
6 #pragma GCC diagnostic ignored "-Wfloat-conversion"
7 #pragma GCC diagnostic ignored "-Wconversion"
15 const std::string& Title,
16 const std::vector<std::string>& Params,
17 const std::unique_ptr<MaCh3Plotting::PlottingManager>& man)
21 for(
size_t i = 0; i < Params.size(); i++)
23 for(
int j = 0; j < MatrixFull->GetNbinsX(); j++)
25 if(MatrixFull->GetXaxis()->GetBinLabel(j+1) == Params[i])
33 for(
size_t i = 0; i < Params.size(); i++)
36 MACH3LOG_ERROR(
"Didn't find param {} in matrix within {} sub-block", Params[i], Title);
39 auto new_end = std::remove(ParamIndex.begin(), ParamIndex.end(),
M3::_BAD_INT_);
40 ParamIndex.erase(new_end, ParamIndex.end());
42 auto Hist = std::make_unique<TH2D>(Title.c_str(), Title.c_str(), ParamIndex.size(), 0, ParamIndex.size(), ParamIndex.size(), 0, ParamIndex.size());
43 Hist->SetDirectory(
nullptr);
44 Hist->GetZaxis()->SetTitle(
"Correlation");
45 Hist->SetMinimum(-1.);
48 for(
size_t x = 0; x < ParamIndex.size(); x++)
50 for(
size_t y = 0; y < ParamIndex.size(); y++)
52 Hist->SetBinContent(x+1, y+1, MatrixFull->GetBinContent(ParamIndex[x]+1, ParamIndex[y]+1));
55 std::string FancyLabel = man->style().prettifyParamName(MatrixFull->GetXaxis()->GetBinLabel(ParamIndex[x]+1));
56 Hist->GetXaxis()->SetBinLabel(x+1, FancyLabel.c_str());
57 Hist->GetYaxis()->SetBinLabel(x+1, FancyLabel.c_str());
63 if (Hist->GetNbinsX() < 20) {
64 Hist->SetMarkerSize(1.0);
65 Hist->GetXaxis()->SetLabelSize(0.02);
66 Hist->GetYaxis()->SetLabelSize(0.02);
68 Hist->SetMarkerSize(0.5);
69 Hist->GetXaxis()->SetLabelSize(0.015);
70 Hist->GetYaxis()->SetLabelSize(0.015);
74 void SetupInfo(
const std::string& Config, std::vector<std::string>& Title, std::vector<std::vector<std::string>>& Params)
80 YAML::Node settings =
config[
"MatrixPlotter"];
83 Title = settings[
"Titles"].as<std::vector<std::string>>();
84 Params.resize(Title.size());
87 for(
size_t it = 0; it < Title.size(); it++)
89 if (settings[Title[it]]) {
90 Params[it] = settings[Title[it]].as<std::vector<std::string>>();
98 if(Title.size() != Params.size())
105 void PlotMatrix(
const std::unique_ptr<MaCh3Plotting::PlottingManager>& man,
const std::string& Config,
const std::string& File)
108 TFile *file =
M3::Open(File,
"UPDATE", __FILE__, __LINE__);
109 TH2D *MatrixFull =
nullptr;
110 file->GetObject(
"Correlation_plot", MatrixFull);
117 auto MatrixPlot = std::make_unique<TCanvas>(
"MatrixPlot",
"MatrixPlot", 0, 0, 1024, 1024);
118 MatrixPlot->SetGrid();
119 gStyle->SetOptStat(0);
120 gStyle->SetOptTitle(0);
121 MatrixPlot->SetTickx();
122 MatrixPlot->SetTicky();
123 MatrixPlot->SetBottomMargin(0.2);
124 MatrixPlot->SetTopMargin(0.1);
125 MatrixPlot->SetRightMargin(0.15);
126 MatrixPlot->SetLeftMargin(0.15);
127 gStyle->SetOptTitle(1);
128 gStyle->SetPaintTextFormat(
"4.1f");
131 constexpr
int NRGBs = 5;
132 TColor::InitializeColors();
133 Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
134 Double_t red[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50 };
135 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00 };
136 Double_t blue[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00 };
137 TColor::CreateGradientColorTable(5, stops, red, green, blue, 255);
138 gStyle->SetNumberContours(255);
141 gErrorIgnoreLevel = kWarning;
143 MatrixFull->GetXaxis()->LabelsOption(
"v");
144 MatrixPlot->Print(
"MatrixPlot.pdf[");
145 MatrixFull->SetTitle(
"");
146 MatrixFull->Draw(
"COLZ");
147 MatrixPlot->Print(
"MatrixPlot.pdf");
148 std::vector<std::string> Title;
149 std::vector<std::vector<std::string>> Params;
153 for(
size_t it = 0; it < Title.size(); it++)
155 std::unique_ptr<TH2D> Hist =
GetSubMatrix(MatrixFull, Title[it], Params[it], man);
156 Hist->GetXaxis()->LabelsOption(
"v");
159 if(Hist->GetNbinsX() < 50) {
160 Hist->Draw(
"COLZ TEXT");
164 MatrixPlot->Print(
"MatrixPlot.pdf");
167 MatrixPlot->Print(
"MatrixPlot.pdf]");
175 const std::string& Config,
const std::string& File1,
const std::string& Title1,
176 const std::string& File2,
const std::string& Title2)
180 constexpr
int NFiles = 2;
182 file[0] =
M3::Open(File1,
"UPDATE", __FILE__, __LINE__);
183 file[1] =
M3::Open(File2,
"UPDATE", __FILE__, __LINE__);
185 TH2D *MatrixFull[NFiles] = {
nullptr};
186 for(
int i = 0; i < NFiles; i++) {
187 file[i]->GetObject(
"Correlation_plot", MatrixFull[i]);
189 auto MatrixPlot = std::make_unique<TCanvas>(
"MatrixPlot",
"MatrixPlot", 0, 0, 1024, 1024);
190 MatrixPlot->SetGrid();
191 gStyle->SetOptStat(0);
192 gStyle->SetOptTitle(0);
193 MatrixPlot->SetTickx();
194 MatrixPlot->SetTicky();
195 MatrixPlot->SetBottomMargin(0.2);
196 MatrixPlot->SetTopMargin(0.1);
197 MatrixPlot->SetRightMargin(0.15);
198 MatrixPlot->SetLeftMargin(0.15);
199 gStyle->SetOptTitle(1);
202 constexpr
int NRGBs = 10;
203 TColor::InitializeColors();
204 Double_t stops[NRGBs] = { 0.00, 0.10, 0.25, 0.35, 0.50, 0.60, 0.65, 0.75, 0.90, 1.00 };
205 Double_t red[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00, 0.10, 0.50, 1.00, 0.75, 0.55 };
206 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00, 0.60, 0.90, 1.00, 0.75, 0.75 };
207 Double_t blue[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50, 0.60, 0.90, 1.00, 0.05, 0.05 };
208 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, 255);
209 gStyle->SetNumberContours(255);
212 gErrorIgnoreLevel = kWarning;
214 MatrixPlot->Print(
"MatrixComparePlot.pdf[");
216 std::vector<std::string> Title;
217 std::vector<std::vector<std::string>> Params;
221 for(
size_t it = 0; it < Title.size(); it++)
223 std::unique_ptr<TH2D> Hist[2];
224 for(
int i = 0; i < NFiles; i++)
226 Hist[i] =
GetSubMatrix(MatrixFull[i], Title[it], Params[it], man);
228 Hist[0]->GetZaxis()->SetTitle( (Title1 +
"/" + Title2).c_str());
229 Hist[0]->GetXaxis()->LabelsOption(
"v");
230 Hist[0]->Divide(Hist[1].get());
234 Hist[0]->Draw(
"COLZ");
235 MatrixPlot->Print(
"MatrixComparePlot.pdf");
237 MatrixPlot->Print(
"MatrixComparePlot.pdf]");
239 for(
int i = 0; i < NFiles; i++)
241 delete MatrixFull[i];
247 int main(
int argc,
char *argv[])
251 auto man = std::make_unique<MaCh3Plotting::PlottingManager>();
254 if (argc != 3 && argc != 6)
256 MACH3LOG_INFO(
"How to use: {} config.yaml MCMC_Processor_Output.root", argv[0]);
262 PlotMatrix(man, std::string(argv[1]), std::string(argv[2]));
268 CompareMatrices(man, std::string(argv[1]), std::string(argv[2]), std::string(argv[3]), std::string(argv[4]), std::string(argv[5]));
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
void DynamicLabelSize(TH2D *Hist)
int main(int argc, char *argv[])
void SetupInfo(const std::string &Config, std::vector< std::string > &Title, std::vector< std::vector< std::string >> &Params)
void CompareMatrices(const std::unique_ptr< MaCh3Plotting::PlottingManager > &man, const std::string &Config, const std::string &File1, const std::string &Title1, const std::string &File2, const std::string &Title2)
void PlotMatrix(const std::unique_ptr< MaCh3Plotting::PlottingManager > &man, const std::string &Config, const std::string &File)
std::unique_ptr< TH2D > GetSubMatrix(TH2D *MatrixFull, const std::string &Title, const std::vector< std::string > &Params, const std::unique_ptr< MaCh3Plotting::PlottingManager > &man)
Grab large Matrix only only extract submatrix based on label naming.
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class used throughout MaCh3.
TFile * Open(const std::string &Name, const std::string &Type, const std::string &File, const int Line)
Opens a ROOT file with the given name and mode.
constexpr static const int _BAD_INT_
Default value used for int initialisation.