{ "cells": [ { "cell_type": "markdown", "id": "cca9479b", "metadata": {}, "source": [ "# df101_h1Analysis\n", "Show how to express ROOT's standard H1 analysis with RDataFrame.\n", "\n", "\n", "\n", "\n", "**Author:** Axel Naumann, Danilo Piparo (CERN) \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:10 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "7c224420", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:25.213561Z", "iopub.status.busy": "2026-05-19T20:10:25.213442Z", "iopub.status.idle": "2026-05-19T20:10:25.551641Z", "shell.execute_reply": "2026-05-19T20:10:25.551260Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "\n", "auto Select = [](ROOT::RDataFrame &dataFrame) {\n", " using namespace ROOT;\n", "\n", " auto ret = dataFrame.Filter(\"TMath::Abs(md0_d - 1.8646) < 0.04\")\n", " .Filter(\"ptds_d > 2.5\")\n", " .Filter(\"TMath::Abs(etads_d) < 1.5\")\n", " .Filter([](int ik, int ipi, RVecI& nhitrp) { return nhitrp[ik - 1] * nhitrp[ipi - 1] > 1; },\n", " {\"ik\", \"ipi\", \"nhitrp\"})\n", " .Filter([](int ik, RVecF& rstart, RVecF& rend) { return rend[ik - 1] - rstart[ik - 1] > 22; },\n", " {\"ik\", \"rstart\", \"rend\"})\n", " .Filter([](int ipi, RVecF& rstart, RVecF& rend) { return rend[ipi - 1] - rstart[ipi - 1] > 22; },\n", " {\"ipi\", \"rstart\", \"rend\"})\n", " .Filter([](int ik, RVecF& nlhk) { return nlhk[ik - 1] > 0.1; }, {\"ik\", \"nlhk\"})\n", " .Filter([](int ipi, RVecF& nlhpi) { return nlhpi[ipi - 1] > 0.1; }, {\"ipi\", \"nlhpi\"})\n", " .Filter([](int ipis, RVecF& nlhpi) { return nlhpi[ipis - 1] > 0.1; }, {\"ipis\", \"nlhpi\"})\n", " .Filter(\"njets >= 1\");\n", "\n", " return ret;\n", "};\n", "\n", "const Double_t dxbin = (0.17 - 0.13) / 40; // Bin-width" ] }, { "cell_type": "markdown", "id": "5179519d", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 2, "id": "9ad63a1f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:25.558273Z", "iopub.status.busy": "2026-05-19T20:10:25.558137Z", "iopub.status.idle": "2026-05-19T20:10:25.561594Z", "shell.execute_reply": "2026-05-19T20:10:25.561186Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "Double_t fdm5(Double_t *xx, Double_t *par)\n", "{\n", " Double_t x = xx[0];\n", " if (x <= 0.13957)\n", " return 0;\n", " Double_t xp3 = (x - par[3]) * (x - par[3]);\n", " Double_t res =\n", " dxbin * (par[0] * pow(x - 0.13957, par[1]) + par[2] / 2.5066 / par[4] * exp(-xp3 / 2 / par[4] / par[4]));\n", " return res;\n", "}" ] }, { "cell_type": "markdown", "id": "973cd0b7", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 3, "id": "746d039a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:25.562707Z", "iopub.status.busy": "2026-05-19T20:10:25.562533Z", "iopub.status.idle": "2026-05-19T20:10:25.565219Z", "shell.execute_reply": "2026-05-19T20:10:25.564854Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "Double_t fdm2(Double_t *xx, Double_t *par)\n", "{\n", " static const Double_t sigma = 0.0012;\n", " Double_t x = xx[0];\n", " if (x <= 0.13957)\n", " return 0;\n", " Double_t xp3 = (x - 0.1454) * (x - 0.1454);\n", " Double_t res = dxbin * (par[0] * pow(x - 0.13957, 0.25) + par[1] / 2.5066 / sigma * exp(-xp3 / 2 / sigma / sigma));\n", " return res;\n", "}" ] }, { "cell_type": "markdown", "id": "bf0f3dd2", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 4, "id": "254b88f9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:25.566249Z", "iopub.status.busy": "2026-05-19T20:10:25.566138Z", "iopub.status.idle": "2026-05-19T20:10:25.579043Z", "shell.execute_reply": "2026-05-19T20:10:25.578625Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void FitAndPlotHdmd(TH1 &hdmd)\n", "{\n", " // create the canvas for the h1analysis fit\n", " gStyle->SetOptFit();\n", " auto c1 = new TCanvas(\"c1\", \"h1analysis analysis\", 10, 10, 800, 600);\n", "\n", " hdmd.GetXaxis()->SetTitleOffset(1.4);\n", "\n", " auto hdraw = (TH1 *) hdmd.DrawClone();\n", "\n", " // fit histogram hdmd with function f5 using the loglikelihood option\n", " auto f5 = new TF1(\"f5\", fdm5, 0.139, 0.17, 5);\n", " f5->SetParameters(1000000, .25, 2000, .1454, .001);\n", " hdraw->Fit(\"f5\", \"lr\");\n", "}" ] }, { "cell_type": "markdown", "id": "e4cf6a7b", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 5, "id": "83ee01b1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:25.583475Z", "iopub.status.busy": "2026-05-19T20:10:25.583353Z", "iopub.status.idle": "2026-05-19T20:10:25.591049Z", "shell.execute_reply": "2026-05-19T20:10:25.590451Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void FitAndPlotH2(TH2 &h2)\n", "{\n", " // create the canvas for tau d0\n", " auto c2 = new TCanvas(\"c2\", \"tauD0\", 100, 100, 800, 600);\n", "\n", " c2->SetGrid();\n", " c2->SetBottomMargin(0.15);\n", "\n", " // Project slices of 2-d histogram h2 along X , then fit each slice\n", " // with function f2 and make a histogram for each fit parameter\n", " // Note that the generated histograms are added to the list of objects\n", " // in the current directory.\n", " auto f2 = new TF1(\"f2\", fdm2, 0.139, 0.17, 2);\n", " f2->SetParameters(10000, 10);\n", " h2.FitSlicesX(f2, 0, -1, 1, \"qln\");\n", "\n", " // See TH2::FitSlicesX documentation why h2_1 name is used\n", " auto h2_1 = (TH1D *)gDirectory->Get(\"h2_1\");\n", " h2_1->SetDirectory(nullptr);\n", " h2_1->GetXaxis()->SetTitle(\"#tau [ps]\");\n", " h2_1->SetMarkerStyle(21);\n", " h2_1->Draw();\n", " c2->Update();\n", "\n", " auto line = new TLine(0, 0, 0, c2->GetUymax());\n", " line->Draw();\n", "}" ] }, { "cell_type": "code", "execution_count": 6, "id": "5a7deed0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:25.592311Z", "iopub.status.busy": "2026-05-19T20:10:25.592191Z", "iopub.status.idle": "2026-05-19T20:10:26.761156Z", "shell.execute_reply": "2026-05-19T20:10:26.751040Z" } }, "outputs": [], "source": [ "TChain chain(\"h42\");\n", "chain.Add(\"root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root\");\n", "chain.Add(\"root://eospublic.cern.ch//eos/root-eos/h1/dstarp1a.root\");\n", "chain.Add(\"root://eospublic.cern.ch//eos/root-eos/h1/dstarp1b.root\");\n", "chain.Add(\"root://eospublic.cern.ch//eos/root-eos/h1/dstarp2.root\");\n", "\n", "ROOT::EnableImplicitMT(4);\n", "\n", "ROOT::RDataFrame dataFrame(chain);\n", "auto selected = Select(dataFrame);" ] }, { "cell_type": "markdown", "id": "300a47be", "metadata": {}, "source": [ "Note: The title syntax is \"