Skip to content

Instantly share code, notes, and snippets.

@dciangot
Last active October 20, 2021 06:47
Show Gist options
  • Save dciangot/1885bace54dabc01b816550901609956 to your computer and use it in GitHub Desktop.
Save dciangot/1885bace54dabc01b816550901609956 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b1161db2-6ee1-4b74-b1f0-be4ebd7e5aef",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Welcome to JupyROOT 6.25/01\n"
]
}
],
"source": [
"import ROOT"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "009fc473-31ab-4c0b-9a57-e8d0d1f68de3",
"metadata": {},
"outputs": [],
"source": [
"from dask.distributed import Client\n",
"\n",
"client = Client(address=\"tcp://127.0.0.1:8990\")\n",
"\n",
"import ROOT\n",
"rdf = ROOT.RDF.Experimental.Distributed.Dask.RDataFrame\n",
"\n",
"#df = rdf(\"Events\", \"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root\", daskclient=client, npartitions=2)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dd57f90b-f113-4bcd-af11-b52895d4da59",
"metadata": {},
"outputs": [],
"source": [
"#df.AsNumpy()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "18a02cae-36a2-46de-95fa-a351dcedf3fb",
"metadata": {},
"outputs": [],
"source": [
"df = rdf(1000, npartitions=2, daskclient=client)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "678aac9f-46f5-45f1-b613-dd6cf2cc1c62",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Entries: 1000 \n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in <TCanvas::Print>: png file a1.png has been created\n"
]
}
],
"source": [
"d1 = df.Define(\"x\", \"rdfentry_\").Define(\"y\", \"rdfentry_ * rdfentry_\")\n",
"a1 = d1.Histo1D((\"name\", \"title\", 100, 0, 100), \"y\")\n",
"a2 = d1.Count()\n",
"\n",
"print(\"\\nEntries: \", a2.GetValue(), \"\\n\")\n",
"c = ROOT.TCanvas()\n",
"a1.Draw()\n",
"c.SaveAs(\"a1.png\") "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "336c14ae-6a7d-46c1-b177-5929da137464",
"metadata": {},
"outputs": [],
"source": [
"df = rdf(\"Events\", \"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root\", daskclient=client, npartitions=2)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "240b2dda-a03d-4f5e-a9b8-88446fbcafdb",
"metadata": {},
"outputs": [],
"source": [
"df_ge4m = df.Filter(\"nMuon>=4\", \"At least four muons\").Histo1D((\"name\", \"title\", 100, 0, 100), \"nMuon\")\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "aa18d5b5-cbc6-411a-ab2e-4242bbe4933e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in <TCanvas::Print>: png file a2.png has been created\n"
]
}
],
"source": [
"c = ROOT.TCanvas()\n",
"df_ge4m.Draw()\n",
"c.SaveAs(\"a2.png\") "
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "93d75395-3f93-4cfc-bbbf-3bf69447f4a0",
"metadata": {},
"outputs": [],
"source": [
"df_ge4m_count = df.Filter(\"nMuon>=4\", \"At least four muons\").Count()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "809d5682-e1e1-4812-8a39-0b161eff4420",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"425182\n"
]
}
],
"source": [
"print(df_ge4m_count.GetValue())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c0946c42-4de0-4f63-9bac-733b5fe24e63",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment