6 #pragma GCC diagnostic ignored "-Wfloat-conversion"
7 #pragma GCC diagnostic ignored "-Wconversion"
13 std::unique_ptr<TH2D>
GetSubMatrix(TH2D *MatrixFull,
const std::string& Title,
const std::vector<std::string>& Params)
17 for(
size_t i = 0; i < Params.size(); i++)
19 for(
int j = 0; j < MatrixFull->GetNbinsX(); j++)
21 if(MatrixFull->GetXaxis()->GetBinLabel(j+1) == Params[i])
29 for(
size_t i = 0; i < Params.size(); i++)
32 MACH3LOG_ERROR(
"Didn't find param {} in matrix within {} sub-block", Params[i], Title);
35 auto new_end = std::remove(ParamIndex.begin(), ParamIndex.end(),
M3::_BAD_INT_);
36 ParamIndex.erase(new_end, ParamIndex.end());
38 auto Hist = std::make_unique<TH2D>(Title.c_str(), Title.c_str(), ParamIndex.size(), 0, ParamIndex.size(), ParamIndex.size(), 0, ParamIndex.size());
39 Hist->SetDirectory(
nullptr);
40 Hist->GetZaxis()->SetTitle(
"Correlation");
43 Hist->GetXaxis()->SetLabelSize(0.015);
44 Hist->GetYaxis()->SetLabelSize(0.015);
46 for(
size_t x = 0; x < ParamIndex.size(); x++)
48 for(
size_t y = 0; y < ParamIndex.size(); y++)
50 Hist->SetBinContent(x+1, y+1, MatrixFull->GetBinContent(ParamIndex[x]+1, ParamIndex[y]+1));
52 Hist->GetXaxis()->SetBinLabel(x+1, MatrixFull->GetXaxis()->GetBinLabel(ParamIndex[x]+1));
53 Hist->GetYaxis()->SetBinLabel(x+1, MatrixFull->GetXaxis()->GetBinLabel(ParamIndex[x]+1));
58 void SetupInfo(
const std::string& Config, std::vector<std::string>& Title, std::vector<std::vector<std::string>>& Params)
64 YAML::Node settings =
config[
"MatrixPlotter"];
67 Title = settings[
"Titles"].as<std::vector<std::string>>();
68 Params.resize(Title.size());
71 for(
size_t it = 0; it < Title.size(); it++)
73 if (settings[Title[it]]) {
74 Params[it] = settings[Title[it]].as<std::vector<std::string>>();
82 if(Title.size() != Params.size())
89 void PlotMatrix(
const std::string& Config,
const std::string& File)
92 TFile *file =
M3::Open(File,
"UPDATE", __FILE__, __LINE__);
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);
111 gStyle->SetOptTitle(1);
112 gStyle->SetPaintTextFormat(
"4.1f");
115 constexpr
int NRGBs = 5;
116 TColor::InitializeColors();
117 Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
118 Double_t red[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50 };
119 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00 };
120 Double_t blue[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00 };
121 TColor::CreateGradientColorTable(5, stops, red, green, blue, 255);
122 gStyle->SetNumberContours(255);
125 gErrorIgnoreLevel = kWarning;
127 MatrixPlot->Print(
"MatrixPlot.pdf[");
128 MatrixFull->SetTitle(
"");
129 MatrixFull->Draw(
"COLZ");
130 MatrixPlot->Print(
"MatrixPlot.pdf");
131 std::vector<std::string> Title;
132 std::vector<std::vector<std::string>> Params;
136 for(
size_t it = 0; it < Title.size(); it++)
138 std::unique_ptr<TH2D> Hist =
GetSubMatrix(MatrixFull, Title[it], Params[it]);
139 Hist->GetXaxis()->LabelsOption(
"v");
141 if (Hist->GetNbinsX() < 20) {
142 Hist->SetMarkerSize(1.0);
144 Hist->SetMarkerSize(0.5);
147 if(Hist->GetNbinsX() < 50) {
148 Hist->Draw(
"COLZ TEXT");
152 MatrixPlot->Print(
"MatrixPlot.pdf");
155 MatrixPlot->Print(
"MatrixPlot.pdf]");
162 void CompareMatrices(std::string Config, std::string File1, std::string Title1, std::string File2, std::string Title2)
165 constexpr
int NFiles = 2;
167 file[0] =
M3::Open(File1,
"UPDATE", __FILE__, __LINE__);
168 file[1] =
M3::Open(File2,
"UPDATE", __FILE__, __LINE__);
170 TH2D *MatrixFull[2] = {
nullptr};
171 for(
int i = 0; i < NFiles; i++) {
172 file[i]->GetObject(
"Correlation_plot", MatrixFull[i]);
174 auto MatrixPlot = std::make_unique<TCanvas>(
"MatrixPlot",
"MatrixPlot", 0, 0, 1024, 1024);
175 MatrixPlot->SetGrid();
176 gStyle->SetOptStat(0);
177 gStyle->SetOptTitle(0);
178 MatrixPlot->SetTickx();
179 MatrixPlot->SetTicky();
180 MatrixPlot->SetBottomMargin(0.2);
181 MatrixPlot->SetTopMargin(0.1);
182 MatrixPlot->SetRightMargin(0.15);
183 MatrixPlot->SetLeftMargin(0.15);
184 gStyle->SetOptTitle(1);
187 constexpr
int NRGBs = 10;
188 TColor::InitializeColors();
189 Double_t stops[NRGBs] = { 0.00, 0.10, 0.25, 0.35, 0.50, 0.60, 0.65, 0.75, 0.90, 1.00 };
190 Double_t red[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00, 0.10, 0.50, 1.00, 0.75, 0.55 };
191 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00, 0.60, 0.90, 1.00, 0.75, 0.75 };
192 Double_t blue[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50, 0.60, 0.90, 1.00, 0.05, 0.05 };
193 TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, 255);
194 gStyle->SetNumberContours(255);
197 gErrorIgnoreLevel = kWarning;
199 MatrixPlot->Print(
"MatrixComparePlot.pdf[");
201 std::vector<std::string> Title;
202 std::vector<std::vector<std::string>> Params;
206 for(
size_t it = 0; it < Title.size(); it++)
208 std::unique_ptr<TH2D> Hist[2];
209 for(
int i = 0; i < NFiles; i++)
211 Hist[i] =
GetSubMatrix(MatrixFull[i], Title[it], Params[it]);
213 Hist[0]->GetZaxis()->SetTitle( (Title1 +
"/" + Title2).c_str());
214 Hist[0]->GetXaxis()->LabelsOption(
"v");
215 Hist[0]->Divide(Hist[1].get());
217 Hist[0]->Draw(
"COLZ");
218 MatrixPlot->Print(
"MatrixComparePlot.pdf");
220 MatrixPlot->Print(
"MatrixComparePlot.pdf]");
222 for(
int i = 0; i < NFiles; i++)
224 delete MatrixFull[i];
230 int main(
int argc,
char *argv[])
234 if (argc != 3 && argc != 6)
236 MACH3LOG_INFO(
"How to use: {} config.yaml MCMC_Processor_Output.root", argv[0]);
242 PlotMatrix(std::string(argv[1]), std::string(argv[2]));
248 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.
int main(int argc, char *argv[])
void SetupInfo(const std::string &Config, std::vector< std::string > &Title, std::vector< std::vector< std::string >> &Params)
std::unique_ptr< TH2D > GetSubMatrix(TH2D *MatrixFull, const std::string &Title, const std::vector< std::string > &Params)
void CompareMatrices(std::string Config, std::string File1, std::string Title1, std::string File2, std::string Title2)
void PlotMatrix(const std::string &Config, const std::string &File)
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class for MaCh3 errors.
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.