6#pragma GCC diagnostic ignored "-Wfloat-conversion"
7#pragma GCC diagnostic ignored "-Wconversion"
9TH2D*
GetSubMatrix(TH2D *MatrixFull,
const std::string& Title,
const std::vector<std::string>& Params)
11 std::vector<int> ParamIndex(Params.size(), -999);
13 for(
size_t i = 0; i < Params.size(); i++)
15 for(
int j = 0; j < MatrixFull->GetNbinsX(); j++)
17 if(MatrixFull->GetXaxis()->GetBinLabel(j+1) == Params[i])
25 for(
size_t i = 0; i < Params.size(); i++)
27 if(ParamIndex[i] == -999 )
28 MACH3LOG_ERROR(
"Didn't find param {} in matrix within {} sub-block", Params[i], Title);
31 auto new_end = std::remove(ParamIndex.begin(), ParamIndex.end(), -999);
32 ParamIndex.erase(new_end, ParamIndex.end());
34 TH2D* Hist =
new TH2D(Title.c_str(), Title.c_str(), ParamIndex.size(), 0, ParamIndex.size(), ParamIndex.size(), 0, ParamIndex.size());
35 Hist->GetZaxis()->SetTitle(
"Correlation");
38 Hist->GetXaxis()->SetLabelSize(0.015);
39 Hist->GetYaxis()->SetLabelSize(0.015);
41 for(
size_t x = 0; x < ParamIndex.size(); x++)
43 for(
size_t y = 0; y < ParamIndex.size(); y++)
45 Hist->SetBinContent(x+1, y+1, MatrixFull->GetBinContent(ParamIndex[x]+1, ParamIndex[y]+1));
47 Hist->GetXaxis()->SetBinLabel(x+1, MatrixFull->GetXaxis()->GetBinLabel(ParamIndex[x]+1));
48 Hist->GetYaxis()->SetBinLabel(x+1, MatrixFull->GetXaxis()->GetBinLabel(ParamIndex[x]+1));
53void SetupInfo(
const std::string& Config, std::vector<std::string>& Title, std::vector<std::vector<std::string>>& Params)
59 YAML::Node settings =
config[
"MatrixPlotter"];
62 Title = settings[
"Titles"].as<std::vector<std::string>>();
63 Params.resize(Title.size());
66 for(
size_t it = 0; it < Title.size(); it++)
68 if (settings[Title[it]]) {
69 Params[it] = settings[Title[it]].as<std::vector<std::string>>();
77 if(Title.size() != Params.size())
87 TFile *file = TFile::Open(File.c_str());
88 if (!file || file->IsZombie()) {
93 TH2D *MatrixFull =
nullptr;
94 file->GetObject(
"Correlation_plot", MatrixFull);
101 auto MatrixPlot = std::make_unique<TCanvas>(
"MatrixPlot",
"MatrixPlot", 0, 0, 1024, 1024);
102 MatrixPlot->SetGrid();
103 gStyle->SetOptStat(0);
104 gStyle->SetOptTitle(0);
105 MatrixPlot->SetTickx();
106 MatrixPlot->SetTicky();
107 MatrixPlot->SetBottomMargin(0.2);
108 MatrixPlot->SetTopMargin(0.1);
109 MatrixPlot->SetRightMargin(0.15);
110 MatrixPlot->SetLeftMargin(0.15);
112 gStyle->SetOptTitle(1);
113 gStyle->SetPaintTextFormat(
"4.1f");
117 TColor::InitializeColors();
118 Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
119 Double_t red[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50 };
120 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00 };
121 Double_t blue[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00 };
122 TColor::CreateGradientColorTable(5, stops, red, green, blue, 255);
123 gStyle->SetNumberContours(255);
126 gErrorIgnoreLevel = kWarning;
128 MatrixPlot->Print(
"MatrixPlot.pdf[");
130 MatrixFull->Draw(
"COLZ");
131 MatrixPlot->Print(
"MatrixPlot.pdf");
132 std::vector<std::string> Title;
133 std::vector<std::vector<std::string>> Params;
137 for(
size_t it = 0; it < Title.size(); it++)
139 TH2D* Hist =
GetSubMatrix(MatrixFull, Title[it], Params[it]);
140 Hist->GetXaxis()->LabelsOption(
"v");
141 Hist->Draw(
"COLZ TEXT");
142 MatrixPlot->Print(
"MatrixPlot.pdf");
145 MatrixPlot->Print(
"MatrixPlot.pdf]");
152void CompareMatrices(std::string Config, std::string File1, std::string Title1, std::string File2, std::string Title2)
155 const int NFiles = 2;
157 file[0] = TFile::Open(File1.c_str());
158 file[1] = TFile::Open(File2.c_str());
160 TH2D *MatrixFull[2] = {
nullptr};
161 for(
int i = 0; i < NFiles; i++) {
162 file[i]->GetObject(
"Correlation_plot", MatrixFull[i]);
164 auto MatrixPlot = std::make_unique<TCanvas>(
"MatrixPlot",
"MatrixPlot", 0, 0, 1024, 1024);
165 MatrixPlot->SetGrid();
166 gStyle->SetOptStat(0);
167 gStyle->SetOptTitle(0);
168 MatrixPlot->SetTickx();
169 MatrixPlot->SetTicky();
170 MatrixPlot->SetBottomMargin(0.2);
171 MatrixPlot->SetTopMargin(0.1);
172 MatrixPlot->SetRightMargin(0.15);
173 MatrixPlot->SetLeftMargin(0.15);
175 gStyle->SetOptTitle(1);
178 const int NRGBs = 10;
179 TColor::InitializeColors();
180 Double_t stops[NRGBs] = { 0.00, 0.10, 0.25, 0.35, 0.50, 0.60, 0.65, 0.75, 0.90, 1.00 };
181 Double_t red[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00, 0.10, 0.50, 1.00, 0.75, 0.55 };
182 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00, 0.60, 0.90, 1.00, 0.75, 0.75 };
183 Double_t blue[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50, 0.60, 0.90, 1.00, 0.05, 0.05 };
184 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, 255);
185 gStyle->SetNumberContours(255);
188 gErrorIgnoreLevel = kWarning;
190 MatrixPlot->Print(
"MatrixComparePlot.pdf[");
192 std::vector<std::string> Title;
193 std::vector<std::vector<std::string>> Params;
197 for(
size_t it = 0; it < Title.size(); it++)
199 TH2D* Hist[2] = {
nullptr};
200 for(
int i = 0; i < NFiles; i++)
202 Hist[i] =
GetSubMatrix(MatrixFull[i], Title[it], Params[it]);
204 Hist[0]->GetZaxis()->SetTitle( (Title1 +
"/" + Title2).c_str());
205 Hist[0]->GetXaxis()->LabelsOption(
"v");
207 Hist[0]->Draw(
"COLZ");
208 MatrixPlot->Print(
"MatrixComparePlot.pdf");
210 for(
int i = 0; i < NFiles; i++)
215 MatrixPlot->Print(
"MatrixComparePlot.pdf]");
217 for(
int i = 0; i < NFiles; i++)
219 delete MatrixFull[i];
225int main(
int argc,
char *argv[])
229 if (argc != 3 && argc != 6)
231 MACH3LOG_INFO(
"How to use: {} MCMC_Processor_Output.root config", argv[0]);
237 PlotMatrix(std::string(argv[1]), std::string(argv[2]));
243 CompareMatrices(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 SetupInfo(const std::string &Config, std::vector< std::string > &Title, std::vector< std::vector< std::string > > &Params)
int main(int argc, char *argv[])
TH2D * GetSubMatrix(TH2D *MatrixFull, const std::string &Title, const std::vector< std::string > &Params)
void PlotMatrix(std::string Config, std::string File)
void CompareMatrices(std::string Config, std::string File1, std::string Title1, std::string File2, std::string Title2)
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class for MaCh3 errors.