This tutorial illustrates how to use the highlight mode with trees.
TProfile *hYear = 0, *hMonth = 0, *hDay = 0;
Int_t rMonth[3] = { 12, 1, 13 };
Int_t rDay[3] = { 31, 1, 32 };
Double_t rTemp[3] = { 55.0, -20.0, 35.0 };
void HighlightYear(
Int_t xhb);
void HighlightMonth(
Int_t xhb);
void HighlightDay(
Int_t xhb);
void temperature()
{
auto dir =
gROOT->GetTutorialDir();
if (
tree->ReadFile(
Form(
"%stemperature_Prague.dat",dir.
Data())) == 0)
return;
rYear[1] = (
Int_t)
tree->GetLeaf(
"YEAR")->GetValue();
rYear[2] = (
Int_t)
tree->GetLeaf(
"YEAR")->GetValue();
rYear[2] = rYear[2] + 1;
rYear[0] = rYear[2] - rYear[1];
hYear =
new TProfile(
"hYear",
"temperature (average) by year; year; temp, #circC", rYear[0], rYear[1], rYear[2]);
tree->Draw(
"T:YEAR>>hYear",
"",
"goff");
Canvas =
new TCanvas(
"Canvas",
"Canvas", 0, 0, 700, 900);
Canvas->
Divide(1, 3, 0.001, 0.001);
}
{
if (obj == hYear) HighlightYear(xhb);
if (obj == hMonth) HighlightMonth(xhb);
if (obj == hDay) HighlightDay(xhb);
}
void HighlightYear(
Int_t xhb)
{
if (!hMonth) {
hMonth =
new TProfile(
"hMonth",
"; month; temp, #circC", rMonth[0], rMonth[1], rMonth[2]);
hMonth->SetMinimum(rTemp[1]);
hMonth->SetMaximum(rTemp[2]);
hMonth->GetXaxis()->SetNdivisions(112);
hMonth->GetXaxis()->CenterLabels();
hMonth->GetYaxis()->SetNdivisions(410);
hMonth->SetFillColor(
kGray+1);
hMonth->Draw("HIST, CP");
hMonth->SetHighlight();
}
year = xhb - 1 + rYear[1];
hMonth->SetTitle(
TString::Format(
"temperature by month (year = %d)", year));
HighlightMonth(customhb);
}
void HighlightMonth(
Int_t xhb)
{
if (!hDay) {
hDay =
new TProfile(
"hDay",
"; day; temp, #circC", rDay[0], rDay[1], rDay[2]);
hDay->SetMinimum(rTemp[1]);
hDay->SetMaximum(rTemp[2]);
hDay->GetYaxis()->SetNdivisions(410);
hDay->SetFillColor(
kGray);
hDay->SetHighlight();
}
if (xhb != customhb) month = xhb;
hDay->SetTitle(
TString::Format(
"temperature by day (month = %02d, year = %d)", month, year));
HighlightDay(customhb);
}
void HighlightDay(
Int_t xhb)
{
if (!info) {
}
if (xhb != customhb) day = xhb;
if (hDay->GetBinEntries(day) == 0) temp = " ";
}