|
@@ -0,0 +1,62 @@
|
|
|
+std::vector<TPad*> MakePadGrid(int Ncolumns=1, int Nrows=1, double left_margin=0.2, double right_margin=0.02, double bottom_margin=0.2, double top_margin=0.02)
|
|
|
+{
|
|
|
+ std::vector<TPad*> vpads;
|
|
|
+ double xl, xh, yl, yh; //(x,y) low and high coordinates for pads
|
|
|
+ double ml, mr, mt, mb; // margins for pads (left, right, top, bottom)
|
|
|
+ const double min_margin = 0.002; // minimal margin to avoid cropping drawn axes
|
|
|
+ int Nsize = Ncolumns*Nrows;
|
|
|
+
|
|
|
+ for (int iRow=0; iRow<Nrows; iRow++)
|
|
|
+ {
|
|
|
+ for (int iColumn=0; iColumn<Ncolumns; iColumn++)
|
|
|
+ {
|
|
|
+ xl = (iColumn == 0) ? 0. : (double)( iColumn+left_margin ) / (double) ( Ncolumns+left_margin+right_margin );
|
|
|
+ xh = (iColumn == Ncolumns-1) ? 1. : (double)( iColumn+1+left_margin ) / (double) ( Ncolumns+left_margin+right_margin );
|
|
|
+ yl = (iRow == Nrows-1) ? 0. : 1. - (double)( iRow+1+top_margin ) / (double) ( Nrows+top_margin+bottom_margin );
|
|
|
+ yh = (iRow == 0) ? 1. : 1. - (double)( iRow+top_margin ) / (double) ( Nrows+top_margin+bottom_margin );
|
|
|
+
|
|
|
+ ml = (iColumn == 0) ? left_margin/(1.+left_margin) : min_margin;
|
|
|
+ mr = (iColumn == Ncolumns-1) ? right_margin/(1.+right_margin) : min_margin;
|
|
|
+ mb = (iRow == Nrows-1) ? bottom_margin/(1.+bottom_margin) : min_margin;
|
|
|
+ mt = (iRow == 0) ? top_margin/(1.+top_margin) : min_margin;
|
|
|
+
|
|
|
+ std::cout << Form("\t%3i (Column %2i, Row %2i ): Pad coordinates (xlow, ylow, xhigh,yhigh) in NDC: (%1.2f, %1.2f, %1.2f, %1.2f)", iColumn+Ncolumns*iRow, iColumn, iRow, xl, yl, xh, yh) << std::endl;
|
|
|
+
|
|
|
+ vpads.push_back(new TPad(Form("pad_%i", iColumn+Ncolumns*iRow), Form("pad %i: %i column, %i row", iColumn+Ncolumns*iRow, iColumn, iRow), xl, yl, xh, yh));
|
|
|
+ if (!vpads.at(vpads.size()-1))
|
|
|
+ {
|
|
|
+ std::cerr << "Error: something has gone wrong, vector has nullptr at " << vpads.at(vpads.size()-1) << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ vpads.at(vpads.size()-1)->SetMargin(ml, mr, mb, mt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return vpads;
|
|
|
+}
|
|
|
+
|
|
|
+void DrawPads(int Ncolumns=1, int Nrows=1, double left_margin=0.2, double right_margin=0.02, double bottom_margin=0.2, double top_margin=0.02)
|
|
|
+{
|
|
|
+ TCanvas *canvas = new TCanvas("canvas", "", 900, 900);
|
|
|
+ TLatex tex;
|
|
|
+ canvas->cd();
|
|
|
+ std::vector<TPad*> vpads = MakePadGrid(Ncolumns, Nrows, left_margin, right_margin, bottom_margin, top_margin);
|
|
|
+ TH1D* hist = new TH1D("hist","hist;x;y",100,-5.,5.);
|
|
|
+ hist->GetXaxis()->SetRangeUser(-4.9,4.9);
|
|
|
+ hist->GetYaxis()->SetRangeUser(-0.1,9.9);
|
|
|
+
|
|
|
+ for (int i=0; i<vpads.size(); i++)
|
|
|
+ {
|
|
|
+ vpads.at(i)->Draw();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i=0; i<vpads.size(); i++)
|
|
|
+ {
|
|
|
+ vpads.at(i)->cd();
|
|
|
+ hist->Draw();
|
|
|
+ tex.SetTextSize(0.2);
|
|
|
+ tex.DrawLatexNDC(0.48, 0.45, Form("%i", i));
|
|
|
+ }
|
|
|
+}
|