Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hist/hist/inc/TMultiGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class TMultiGraph : public TNamed {
TAxis *GetXaxis();
TAxis *GetYaxis();
void Paint(Option_t *chopt = "") override;
void PaintPads(Option_t *chopt = "");
void PaintPads(Option_t *chopt = "", Int_t fnx = 0);
void PaintPolyLine3D(Option_t *chopt = "");
void PaintReverse(Option_t *chopt = "");
void Print(Option_t *chopt="") const override;
Expand Down
31 changes: 24 additions & 7 deletions hist/hist/src/THStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,18 @@ void THStack::BuildAndPaint(Option_t *choptin, Bool_t paint, Bool_t rebuild_stac
lclear = kFALSE;
opt.ReplaceAll("noclear","");
}
if (opt.Contains("pads")) {
auto l = strstr(opt.Data(), "pads");
if (l) {
if (!paint)
return;

Int_t fnx = 0;
if (sscanf(&l[4], "%d", &fnx) > 0) {
opt.ReplaceAll(TString::Format("pads%d", fnx), "");
} else {
opt.ReplaceAll("pads", "");
}

Int_t npads = fHists->GetSize();
TVirtualPad *padsav = gPad;
//if pad is not already divided into subpads, divide it
Expand All @@ -773,12 +781,21 @@ void THStack::BuildAndPaint(Option_t *choptin, Bool_t paint, Bool_t rebuild_stac
nps++;
}
if (nps < npads) {
padsav->Clear();
Int_t nx = (Int_t)TMath::Sqrt((Double_t)npads);
if (nx*nx < npads) nx++;
Int_t ny = nx;
if (((nx*ny)-nx) >= npads) ny--;
padsav->Divide(nx,ny);
if (fnx == 0) {
padsav->Clear();
Int_t nx = (Int_t)TMath::Sqrt((Double_t)npads);
if (nx * nx < npads)
nx++;
Int_t ny = nx;
if (((nx * ny) - nx) >= npads)
ny--;
padsav->Divide(nx, ny);
} else {
Int_t ny = (Int_t)((Double_t)npads / fnx);
if (fnx * ny < npads)
ny++;
padsav->Divide(fnx, ny);
}
}

Int_t i = 1;
Expand Down
32 changes: 23 additions & 9 deletions hist/hist/src/TMultiGraph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,13 @@ void TMultiGraph::Paint(Option_t *choptin)

l = strstr(chopt.Data(),"PADS");
if (l) {
chopt.ReplaceAll("PADS","");
PaintPads(chopt.Data());
Int_t fnx = 0;
if (sscanf(&l[4], "%d", &fnx) > 0) {
chopt.ReplaceAll(TString::Format("PADS%d", fnx), "");
} else {
chopt.ReplaceAll("PADS", "");
}
PaintPads(chopt.Data(), fnx);
return;
}

Expand Down Expand Up @@ -1372,11 +1377,11 @@ void TMultiGraph::Paint(Option_t *choptin)
gfit->PaintStats(fit);
}


////////////////////////////////////////////////////////////////////////////////
/// Divides the active pad and draws all Graphs in the Multigraph separately.
/// fnx parameter larger than 0 enforces number of columns for pad division

void TMultiGraph::PaintPads(Option_t *option)
void TMultiGraph::PaintPads(Option_t *option, Int_t fnx)
{
if (!gPad) return;

Expand All @@ -1392,11 +1397,20 @@ void TMultiGraph::PaintPads(Option_t *option)
}
if (existingPads < neededPads) {
curPad->Clear();
Int_t nx = (Int_t)TMath::Sqrt((Double_t)neededPads);
if (nx*nx < neededPads) nx++;
Int_t ny = nx;
if (((nx*ny)-nx) >= neededPads) ny--;
curPad->Divide(nx,ny);
if (fnx == 0) {
Int_t nx = (Int_t)TMath::Sqrt((Double_t)neededPads);
if (nx * nx < neededPads)
nx++;
Int_t ny = nx;
if (((nx * ny) - nx) >= neededPads)
ny--;
curPad->Divide(nx, ny);
} else {
Int_t ny = (Int_t)((Double_t)neededPads / fnx);
if (fnx * ny < neededPads)
ny++;
curPad->Divide(fnx, ny);
}
}
Int_t i = 0;

Expand Down
8 changes: 5 additions & 3 deletions hist/histpainter/src/THistPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ using `TH1::GetOption`:
| "NOSTACK" | Histograms in the stack are all paint in the same pad as if the option `SAME` had been specified.|
| "NOSTACKB" | Histograms are drawn next to each other as bar charts.|
| "PADS" | The current pad/canvas is subdivided into a number of pads equal to the number of histograms in the stack and each histogram is paint into a separate pad.|
| "PADSn" | Like PADS but the current pad/canvas is subdivided into a `n` columns x `m` rows of pads where `n` is given and `m` is calculated.|
| "PFC" | Palette Fill Color: stack's fill color is taken in the current palette. |
| "PLC" | Palette Line Color: stack's line color is taken in the current palette. |
| "PMC" | Palette Marker Color: stack's marker color is taken in the current palette. |
Expand Down Expand Up @@ -2751,9 +2752,10 @@ the same pad as if the option `SAME` had been specified. This allows to
compute X and Y scales common to all the histograms, like
`TMultiGraph` does for graphs.

If the option `PADS` is specified, the current pad/canvas is
subdivided into a number of pads equal to the number of histograms and each
histogram is paint into a separate pad.
If the option `PADS` is specified, the current pad/canvas is subdivided into
a number of pads equal to the number of histograms and each histogram is paint
into a separate pad. With `PADSn`, the current pad/canvas is subdivided into
`n` columns x `m` rows of pads where `n` is given and `m` is calculated.

The following example shows various types of stacks (hist023_THStack_simple.C).

Expand Down