{ "cells": [ { "cell_type": "markdown", "id": "9a2798b7", "metadata": {}, "source": [ "# tree501_cernstaff\n", "Playing with a Tree containing variables of type character\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:20 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "1ca47428", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:20:04.847232Z", "iopub.status.busy": "2026-05-19T20:20:04.847118Z", "iopub.status.idle": "2026-05-19T20:20:05.319937Z", "shell.execute_reply": "2026-05-19T20:20:05.319100Z" } }, "outputs": [], "source": [ "TString dir = gROOT->GetTutorialDir();\n", "dir.Append(\"/io/tree/cernstaff.C\");\n", "if (gSystem->AccessPathName(\"cernstaff.root\")) {\n", " gROOT->SetMacroPath(dir);\n", " gROOT->ProcessLine(\".x tree500_cernbuild.C\");\n", "}\n", "auto f = TFile::Open(\"cernstaff.root\");\n", "auto T = f->Get(\"T\");\n", "auto c1 = new TCanvas(\"c1\", \"CERN staff\", 10, 10, 1000, 750);\n", "c1->Divide(2, 2);" ] }, { "cell_type": "markdown", "id": "54cd6625", "metadata": {}, "source": [ "make table of number of people per Nation & Division" ] }, { "cell_type": "code", "execution_count": 2, "id": "1054df16", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:20:05.321905Z", "iopub.status.busy": "2026-05-19T20:20:05.321771Z", "iopub.status.idle": "2026-05-19T20:20:05.527517Z", "shell.execute_reply": "2026-05-19T20:20:05.526759Z" } }, "outputs": [], "source": [ "c1->cd(1);\n", "gPad->SetGrid();\n", "T->Draw(\"Nation:Division>>hN\", \"\", \"text\");\n", "TH2F *hN = (TH2F*)gDirectory->Get(\"hN\");\n", "hN->SetMarkerSize(1.6);\n", "hN->SetStats(0);" ] }, { "cell_type": "markdown", "id": "0aa3ebc9", "metadata": {}, "source": [ "make profile of Average cost per Nation" ] }, { "cell_type": "code", "execution_count": 3, "id": "7052becb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:20:05.529340Z", "iopub.status.busy": "2026-05-19T20:20:05.529219Z", "iopub.status.idle": "2026-05-19T20:20:05.735056Z", "shell.execute_reply": "2026-05-19T20:20:05.734268Z" } }, "outputs": [], "source": [ "c1->cd(2);\n", "gPad->SetGrid();\n", "gPad->SetLeftMargin(0.12);\n", "T->Draw(\"Cost:Nation>>hNation\", \"\", \"prof,goff\");\n", "TH1F *hNation = (TH1F*)gDirectory->Get(\"hNation\");\n", "hNation->SetTitle(\"Average Cost per Nation\");\n", "hNation->LabelsOption(\">\"); //sort by decreasing bin contents\n", "hNation->SetMaximum(13000);\n", "hNation->SetMinimum(7000);\n", "hNation->SetStats(0);\n", "hNation->SetMarkerStyle(21);\n", "hNation->Draw();" ] }, { "cell_type": "markdown", "id": "46fbb3df", "metadata": {}, "source": [ "make stacked plot of Nations versus Grade" ] }, { "cell_type": "code", "execution_count": 4, "id": "cdfdb055", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:20:05.736908Z", "iopub.status.busy": "2026-05-19T20:20:05.736791Z", "iopub.status.idle": "2026-05-19T20:20:05.942352Z", "shell.execute_reply": "2026-05-19T20:20:05.941744Z" } }, "outputs": [], "source": [ "c1->cd(3);\n", "gPad->SetGrid();\n", "auto hGrades = new THStack(\"hGrades\", \"Nations versus Grade\");\n", "auto hFR = new TH1F(\"hFR\", \"FR\", 12, 3, 15);\n", "hFR->SetFillColor(kCyan);\n", "hGrades->Add(hFR);\n", "T->Draw(\"Grade>>hFR\", \"Nation==\\\"FR\\\"\");\n", "auto hCH = new TH1F(\"hCH\", \"CH\", 12, 3, 15);\n", "hCH->SetFillColor(kRed);\n", "hGrades->Add(hCH);\n", "T->Draw(\"Grade>>hCH\",\"Nation==\\\"CH\\\"\");\n", "auto hIT = new TH1F(\"hIT\", \"IT\", 12, 3, 15);\n", "hIT->SetFillColor(kGreen);\n", "hGrades->Add(hIT);\n", "T->Draw(\"Grade>>hIT\",\"Nation==\\\"IT\\\"\");\n", "auto hDE = new TH1F(\"hDE\",\"DE\", 12, 3, 15);\n", "hDE->SetFillColor(kYellow);\n", "hGrades->Add(hDE);\n", "T->Draw(\"Grade>>hDE\",\"Nation==\\\"DE\\\"\");\n", "auto hGB = new TH1F(\"hGB\",\"GB\", 12, 3, 15);\n", "hGB->SetFillColor(kBlue);\n", "hGrades->Add(hGB);\n", "T->Draw(\"Grade>>hGB\",\"Nation==\\\"GB\\\"\");\n", "hGrades->Draw();\n", "auto legend = new TLegend(0.7, 0.65, 0.86, 0.88);\n", "legend->AddEntry(hGB,\"GB\",\"f\");\n", "legend->AddEntry(hDE,\"DE\",\"f\");\n", "legend->AddEntry(hIT,\"IT\",\"f\");\n", "legend->AddEntry(hCH,\"CH\",\"f\");\n", "legend->AddEntry(hFR,\"FR\",\"f\");\n", "legend->Draw();" ] }, { "cell_type": "markdown", "id": "9e1e48c1", "metadata": {}, "source": [ "make histogram of age distribution" ] }, { "cell_type": "code", "execution_count": 5, "id": "cce53e17", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:20:05.944669Z", "iopub.status.busy": "2026-05-19T20:20:05.944530Z", "iopub.status.idle": "2026-05-19T20:20:06.150099Z", "shell.execute_reply": "2026-05-19T20:20:06.149442Z" } }, "outputs": [], "source": [ "c1->cd(4); gPad->SetGrid();\n", "T->Draw(\"Age\");\n", "T->Draw(\"Age>>hRetired\", \"Age>(65-2002+1988)\", \"same\");\n", "TH1F *hRetired = (TH1F*)gDirectory->Get(\"hRetired\");\n", "hRetired->SetFillColor(kRed);\n", "hRetired->SetFillStyle(3010);\n", "\n", "auto arrow = new TArrow(32, 169, 55, 74, 0.03, \"|>\");\n", "arrow->SetFillColor(1);\n", "arrow->SetFillStyle(1001);\n", "arrow->Draw();\n", "\n", "auto pt = new TPaveText(0.12, 0.8, 0.55, 0.88, \"brNDC\");\n", "pt->SetFillColor(kWhite);\n", "pt->AddText(\"People at CERN in 1988\");\n", "pt->AddText(\"and retired in 2002\");\n", "pt->Draw();\n", "\n", "c1->cd();" ] }, { "cell_type": "markdown", "id": "739c8ac4", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "07affe51", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:20:06.152408Z", "iopub.status.busy": "2026-05-19T20:20:06.152289Z", "iopub.status.idle": "2026-05-19T20:20:06.357635Z", "shell.execute_reply": "2026-05-19T20:20:06.357059Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }