{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7416ec8e",
   "metadata": {},
   "source": [
    "# df033_Describe\n",
    "Get information about the dataframe with the convenience method Describe.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "**Author:** Stefan Wunsch (KIT, CERN)  \n",
    "<i><small>This notebook tutorial was automatically generated with <a href= \"https://github.com/root-project/root/blob/master/documentation/doxygen/converttonotebook.py\">ROOTBOOK-izer</a> from the macro found in the ROOT repository  on Tuesday, May 19, 2026 at 08:10 PM.</small></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a75e768a",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:10:10.864041Z",
     "iopub.status.busy": "2026-05-19T20:10:10.863909Z",
     "iopub.status.idle": "2026-05-19T20:10:11.871053Z",
     "shell.execute_reply": "2026-05-19T20:10:11.866455Z"
    }
   },
   "outputs": [],
   "source": [
    "import ROOT"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "815045e4",
   "metadata": {},
   "source": [
    "Create a dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0148a0e0",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:10:11.883946Z",
     "iopub.status.busy": "2026-05-19T20:10:11.883802Z",
     "iopub.status.idle": "2026-05-19T20:10:12.511991Z",
     "shell.execute_reply": "2026-05-19T20:10:12.511505Z"
    }
   },
   "outputs": [],
   "source": [
    "path = 'root://eospublic.cern.ch//eos/opendata/cms/derived-data/AOD2NanoAODOutreachTool/Run2012BC_DoubleMuParked_Muons.root'\n",
    "df = ROOT.RDataFrame('Events', path)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c94fc6f",
   "metadata": {},
   "source": [
    "Describe the state of the dataframe.\n",
    "Note that this operation is not running the event loop.\n",
    "Describe returns a DFDescription object, which has e.g. a Print method. See its docs for more information."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ec38407d",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:10:12.524346Z",
     "iopub.status.busy": "2026-05-19T20:10:12.524203Z",
     "iopub.status.idle": "2026-05-19T20:10:12.642299Z",
     "shell.execute_reply": "2026-05-19T20:10:12.641918Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataframe from TChain Events in file root://eospublic.cern.ch//eos/opendata/cms/derived-data/AOD2NanoAODOutreachTool/Run2012BC_DoubleMuParked_Muons.root\n",
      "\n",
      "Property                Value\n",
      "--------                -----\n",
      "Columns in total            6\n",
      "Columns from defines        0\n",
      "Event loops run             0\n",
      "Processing slots            1\n",
      "\n",
      "Column          Type                            Origin\n",
      "------          ----                            ------\n",
      "Muon_charge     ROOT::VecOps::RVec<Int_t>       Dataset\n",
      "Muon_eta        ROOT::VecOps::RVec<Float_t>     Dataset\n",
      "Muon_mass       ROOT::VecOps::RVec<Float_t>     Dataset\n",
      "Muon_phi        ROOT::VecOps::RVec<Float_t>     Dataset\n",
      "Muon_pt         ROOT::VecOps::RVec<Float_t>     Dataset\n",
      "nMuon           UInt_t                          Dataset\n"
     ]
    }
   ],
   "source": [
    "df.Describe().Print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a5233ee",
   "metadata": {},
   "source": [
    "Build a small analysis studying the invariant mass of dimuon systems.\n",
    "See tutorial df102_NanoAODDimuonAnalysis for more information."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9e04c364",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:10:12.665261Z",
     "iopub.status.busy": "2026-05-19T20:10:12.665070Z",
     "iopub.status.idle": "2026-05-19T20:10:13.147704Z",
     "shell.execute_reply": "2026-05-19T20:10:13.147259Z"
    }
   },
   "outputs": [],
   "source": [
    "df = df.Filter('nMuon == 2')\\\n",
    "       .Filter('Muon_charge[0] != Muon_charge[1]')\\\n",
    "       .Define('Dimuon_mass', 'InvariantMass(Muon_pt, Muon_eta, Muon_phi, Muon_mass)')\\\n",
    "       .Filter('Dimuon_mass > 70')\\\n",
    "       .Range(1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b98f289a",
   "metadata": {},
   "source": [
    "Trigger the event loop by asking for the mean of the dimuon mass."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8208348f",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:10:13.157218Z",
     "iopub.status.busy": "2026-05-19T20:10:13.157081Z",
     "iopub.status.idle": "2026-05-19T20:10:14.654286Z",
     "shell.execute_reply": "2026-05-19T20:10:14.653834Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Approximate mass of the Z boson: 91.44 GeV\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print('\\nApproximate mass of the Z boson: {:.2f} GeV\\n'.format(\n",
    "    df.Mean('Dimuon_mass').GetValue()))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df010aea",
   "metadata": {},
   "source": [
    "This time we ask for the `shortFormat`, which only prints a brief description of the dataset:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e7dfd4d2",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:10:14.670377Z",
     "iopub.status.busy": "2026-05-19T20:10:14.670224Z",
     "iopub.status.idle": "2026-05-19T20:10:14.774285Z",
     "shell.execute_reply": "2026-05-19T20:10:14.773722Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataframe from TChain Events in file root://eospublic.cern.ch//eos/opendata/cms/derived-data/AOD2NanoAODOutreachTool/Run2012BC_DoubleMuParked_Muons.root"
     ]
    }
   ],
   "source": [
    "df.Describe().Print(shortFormat=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45d87724",
   "metadata": {},
   "source": [
    "Draw all canvases "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d2ba4ebf",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:10:14.775899Z",
     "iopub.status.busy": "2026-05-19T20:10:14.775747Z",
     "iopub.status.idle": "2026-05-19T20:10:14.893159Z",
     "shell.execute_reply": "2026-05-19T20:10:14.892489Z"
    }
   },
   "outputs": [],
   "source": [
    "from ROOT import gROOT \n",
    "gROOT.GetListOfCanvases().Draw()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
