// -*- C++ -*- // compile with g++ `root-config --cflags --glibs` -std=c++14 -O3 -o exec/testroot exec/testroot.cc #include #include #include #include "TROOT.h" #include "TFile.h" #include "TObject.h" #include "TClass.h" #include "TKey.h" #include "TCanvas.h" #include "TPad.h" #include "TStyle.h" #include "TColor.h" #include "TH1.h" #include "TH1D.h" #include "TH2.h" #include "TH2D.h" #include "TGraph.h" #include "TAxis.h" #include "TLatex.h" #include "TLegend.h" #include "TGaxis.h" void stylePlot(const std::unique_ptr &plot, const int useColor, const double colorAlpha, const int fillStyle, const int markStyle, const double markSize, const int lineStyle, const int lineWidth, const std::string &mainTitle = "") { plot->SetFillColorAlpha(useColor, colorAlpha); plot->SetFillStyle(fillStyle); plot->SetMarkerColor(useColor); plot->SetMarkerStyle(markStyle); plot->SetMarkerSize(markSize); plot->SetLineStyle(lineStyle); plot->SetLineColor(useColor); plot->SetLineWidth(lineWidth); plot->SetTitle( mainTitle.c_str() ); } void axisPlot(const std::unique_ptr &plot, /*TGraph *plot,*/ const double yMin, const double yMax, const std::string &yTxt, const double ySiz, const double yOff, const double yLab, const double xMin, const double xMax, const std::string &xTxt, const double xSiz, const double xOff, const double xLab) { if (yMin < yMax) { plot->GetHistogram()->SetMinimum(yMin); plot->GetHistogram()->SetMaximum(yMax); } if (xMin < xMax) plot->GetXaxis()->SetLimits(xMin, xMax); plot->GetYaxis()->SetTitle(yTxt.c_str()); plot->GetYaxis()->SetTitleSize(ySiz); plot->GetYaxis()->SetTitleOffset(yOff); plot->GetYaxis()->SetLabelSize(yLab); plot->GetXaxis()->SetTitle(xTxt.c_str()); plot->GetXaxis()->SetTitleSize(xSiz); plot->GetXaxis()->SetTitleOffset(xOff); plot->GetXaxis()->SetLabelSize(xLab); } void setH1Style() { // always reset everything first gStyle->Reset(); gROOT->SetStyle("Plain"); gStyle->SetFrameBorderMode(0); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); //gStyle->SetFrameColor(0); gStyle->SetPadColor(0); gStyle->SetCanvasColor(0); gStyle->SetStatColor(0); gStyle->SetFillColor(0); //gStyle->SetPaperSize(20, 26); //gStyle->SetPadTopMargin(0.1); gStyle->SetPadBottomMargin(0.085); gStyle->SetPadRightMargin(0.03); gStyle->SetPadLeftMargin(0.06); //gStyle->SetCanvasDefH(800); //gStyle->SetCanvasDefW(800); //gStyle->SetPadGridX(1); //gStyle->SetPadGridY(1); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetTextFont(42); gStyle->SetTextSize(0.03); gStyle->SetLabelFont(42, "xyz"); gStyle->SetTitleFont(42, "xyz"); gStyle->SetLabelSize(0.025, "xyz"); gStyle->SetTitleSize(0.027, "xyz"); gStyle->SetTitleOffset(1.1, "y"); gStyle->SetTitleOffset(1.1, "x"); gStyle->SetTitleX(0.5); // suit the plot gStyle->SetTitleY(0.97); gStyle->SetTitleAlign(23); gStyle->SetTitleColor(1); gStyle->SetTitleTextColor(1); gStyle->SetTitleFillColor(0); gStyle->SetTitleBorderSize(0); gStyle->SetTitleFontSize(0.035); //gStyle->SetTitleStyle(1001); //gStyle->SetPadTopMargin(0.05); //gStyle->SetPadBottomMargin(0.10); //gStyle->SetPadLeftMargin(0.13); //gStyle->SetPadRightMargin(0.02); // use bold lines and markers gStyle->SetMarkerSize(4); gStyle->SetHistLineWidth(2); gStyle->SetLineWidth(2); //gStyle->SetOptTitle(kFALSE); gStyle->SetOptStat(0); } void setH2Style() { // always reset everything first gStyle->Reset(); setH1Style(); gStyle->SetPalette( kBird ); // https://root.cern.ch/doc/master/classTColor.html#C06 gStyle->SetOptStat(0); gStyle->SetTextFont(42); gStyle->SetTextSizePixels(23); gStyle->SetPaintTextFormat(".3g"); } int main() { auto file = std::unique_ptr(TFile::Open("h_covMat.root")); auto hMat = std::unique_ptr(dynamic_cast(( (file->Get( "covMat_statErr" ))->Clone() ))); for (int iG = 0; iG < 2; ++iG) { std::unique_ptr can =std::make_unique("can", "can", 200, 10, 1000, 1000); setH2Style(); can->SetTopMargin(0.045); can->SetBottomMargin(0.11); can->SetLeftMargin(0.11); can->SetRightMargin(0.025); //styleLegend(leg, 1, 0, 0, 42, 0.041, ""); //putLegend(leg, 0.685, 0.945, 0.155, 0.435); const std::string topRight = "Many /fb @ 13 TeV"; TLatex txt; txt.SetTextSize(0.039); txt.SetTextAlign(13); can->cd(); hMat->Draw("coltext"); txt.DrawLatexNDC(0.651, 0.923, topRight.c_str()); can->SaveAs(("xxx_" + std::to_string(iG) + ".pdf").c_str()); } return 0; }