PlottI
 All Classes Files Functions Variables Enumerations Enumerator Pages
Examples

Table of Contents

Collection of examples for different features of the interface.

Basic Layout of Plotting Code

The following example will demonstrate the basic syntax of the interface. Assume you have two histograms called black and white and a ratio called grey.

TH1D* black = new TH1D("black", "", 100, -3, 3);
black->Sumw2();
black->FillRandom("gaus", 10000);
TH1D* white = new TH1D("white", "", 100, -3, 3);
white->Sumw2();
white->FillRandom("gaus", 10000);
TH1D* grey = (TH1D*)black->Clone("grey");
grey->Divide(white);

First create two object arrays for the main plot and the ratio.

TObjArray* main = new TObjArray();
main->Add(black);
main->Add(white);
TObjArray* ratio = new TObjArray();
ratio->Add(grey);

Now we generate legends for this plot:

Legend* l = new Legend(main, "Black Histo\n White Histo\n", "lp lp", "", "l");
Legend* ll = new Legend(l, "ll"); //Copy first legend so that we can place it seperately
TString info = TString("Black and White Histogram\n");
info.Append("Example\n");
TLegend* lInfo = new Legend(info.Data(), 2);
main->Add(lInfo);

Then we define marker colors and styles. The ones for the ratios will be added after the ones for the main pad.

vector<Color_t> colors = {kBlack, kBlack, kBlack+3};
vector<Style_t> markers = {kFullCircle, kOpenCircle, kFullCircle};
vector<Size_t> sizes = {2., 2., 2.};

Adjusting the legend position:

Legend::SetPosition(lInfo, 0.2, 0.3, 0.85, 0.75); // static function
Legend::SetPosition(l, 0.43, 0.6, 0.2, 0.32);
ll->SetPosition(0.43, 0.6, 0.05, 0.22); // non-static function

And finally create the Canvasses:

SquarePlot square = SquarePlot(main, "x", "count");
square.SetStyle(colors, markers, sizes);
square.SetRanges(3, -3, 400, 0);
square.Draw(TString("Square.pdf"));
main->AddBefore(lInfo, ll); // replace l in main with ll
SingleRatioPlot rat = SingleRatioPlot(main, ratio, "x", "count", "ratio");
rat.SetOffset(2); // determines where the ratio entries start in the style arrays
rat.SetRanges(3, -3, 400, -10, 3.2, 0.5);
rat.Draw(TString("Ratio.pdf"));

Results:

Square.png
Square Plot
Ratio.png
Ratio Plot

RatioPlot

The syntax for a RatioPlot is very similar to that of a SquarePlot:

RatioPlot just_the_ratio = RatioPlot(ratio, "x", "ratio");
just_the_ratio.SetOffset(2);
just_the_ratio.SetRanges(-3, 3, 0.5, 3.2);
just_the_ratio.Draw("just_ratio.png");
just_ratio.png
Example of Ratio Plot using the grey array from above

HeatMapPlot

The syntax for a HeatMapPlot is also quite similar to that of a SquarePlot. The main difference to a SquarePlot is that the first entry of the array that is to be plotted must be a TH2.

TH2I* heat = new TH2I("heat", "", 20, 1, 20, 20, 1, 20);
for (Int_t binx = 1; binx < 20; binx++){
for (Int_t biny = 1; biny < 20; biny++){
heat->SetBinContent(binx, biny, binx + biny + binx*biny);
}
}
Legend* legend = new Legend("This is a heatmap!\n", 1);
legend->SetPosition(0.2, 0.75, 0.8, 0.87);
TObjArray* heatArray = new TObjArray();
heatArray->Add(heat);
heatArray->Add(legend);
HeatMapPlot heatMap = HeatMapPlot(heatArray, "X", "Y", "Z");
heatMap.SetRanges(0, 20, 0, 20, 1, 1E3);
heatMap.SetPalette(kPastel, kTRUE);
heatMap.SetLog(kFALSE, kFALSE, kTRUE);
heatMap.Draw("heat.png");
heat.png
Example of a HeatMapPlot

Defining Colors and Color Gradients

Before defining the colors, we define some histograms we can use for testing:

TObjArray* pal = new TObjArray();
TObjArray* indices = new TObjArray();
palette[0] = new TH1I("palette", "", 20, 1, 20);
pal->Add(palette[0]);
for (Int_t bin = 1; bin < palette[0]->GetNbinsX(); bin++){
palette[0]->SetBinContent(bin, 1);
palette[0]->SetBinError(bin, 0.00001);
}
for (Int_t hist = 1; hist < 20; hist++){
palette[hist] = (TH1I*)palette[0]->Clone(Form("palette_%d", hist));
palette[hist]->Scale(hist+1);
pal->Add(palette[hist]);
}
indices->Add(palette[0]);
indices->Add(palette[1]);
indices->Add(palette[2]);

Colors can then be defined as follows:

color blue {0.00, 0.00, 1.00};
color green {0.00, 1.00, 0.00};
color red {1.00, 0.00, 0.00};

The ROOT color index of these colors can then be accessed by the index attribute of color:

Color_t index_of_color_blue = blue.index;
Color_t index_of_color_red = red.index;
Color_t index_of_color_green = green.index;

This color index can then be used like any other ROOT color index:

vector<Style_t> markersPal (20, kFullCircle);
vector<Size_t> sizesPal (20, 3.);
TMarker* marker = new TMarker();
Plot::SetMarkerProperties(marker, blue.index, kFullSquare, 3.);
std::vector<Color_t> RGB_Colors = {blue.index, red.index, green.index};
SquarePlot indices_usage = SquarePlot(indices, "", "");
indices_usage.SetStyle(RGB_Colors, markersPal, sizesPal);
indices_usage.SetRanges(0, 20, 0, 4);
indices_usage.Draw("indices.png");
indices.png
Example: Usage of user defined colors with color indices

Color gradients can be defined from color points via the ColorGradient class as follows:

vector<color> rgbRainbow = {blue, green, red};
ColorGradient rainbow = ColorGradient(20, rgbRainbow);
vector<Double_t> spacing = {0., 0.8, 1.};
ColorGradient blue_green_somered = ColorGradient(20, rgbRainbow, spacing);

They can be used either directly as the color array or set as the current palette:

vector<Color_t> colors_rainbow = rgb_rainbow.GetGradient();
SquarePlot direct_usage = SquarePlot(pal, "", "");
direct_usage.SetStyle(colors_rainbow, markersPal, sizesPal);
direct_usage.SetRanges(0, 20, 0, 21);
direct_usage.SetOptions("SAME");
direct_usage.Draw("direct.png");
SquarePlot palette_usage = SquarePlot(pal, "", "");
palette_usage.SetRanges(0, 20, 0, 21);
palette_usage.SetPalette(blue_green_somered, kFALSE);
palette_usage.SetOptions("SAME PMC PLC PFC");
palette_usage.Draw("palette.png");
direct.png
Example: Usage of user defined palette colors_rainbow via color vector
palette.png
Example: Usage of user defined palette blue_green_somered via ColorGradient

Legend Usage

Generate a legend from a TObjArray:

TLegend* lIndices = new Legend(indices, "First Histogram\n Second\n and Third", "lp lp lp", "", 3,"indices");
indices->Add(lIndices);

Or with dummy markers from a string with marker specifications:

std::string marker_information = Form("%d %d %f \n %d %d %f \n %d %d %f", kBlack, kFullCircle, 3., kBlue+2, kFullSquare, 3., kMagenta+2, kFullDiamond, 4.);
TLegend* lDummyMarkers = new Legend(marker_information.data(), "Black Full Circle\n Blue Full Square\n Magenta Full Diamond", "lp p lp", 3, "lDummyMarkers");
indices->Add(lDummyMarkers);

Or a legend containing information about your plot:

TLegend* lInformation = new Legend("Some information \n about your histograms \n or your data", 3, "lInformation");
indices->Add(lInformation);

Each legend can be placed individually:

Legend::SetPosition(lIndices, 0.45, 0.8, 0.4, 0.55);
Legend::SetPosition(lDummyMarkers, 0.45, 0.8, 0.6, 0.75);
Legend::SetPosition(lInformation, 0.2, 0.21, 0.77, 0.87);

And plotted by adding them to the array:

SquarePlot legends = SquarePlot(indices, "", "");
legends.SetRanges(0, 20, 0, 21);
legends.SetPalette(kAvocado);
legends.SetOptions("SAME PMC PLC PFC");
legends.Draw("legends.png");
legends.png
Example: Different Methods for defining a legend