\n",
"This ROOTbook produces a plot of the dimuon spectrum starting from a subset of the CMS collision events of Run2010B. \n",
"\n",
"Dataset Reference: \n",
"McCauley, T. (2014). Dimuon event information derived from the Run2010B public Mu dataset. CERN Open Data Portal. DOI: [10.7483/OPENDATA.CMS.CB8H.MFFA](http://opendata.cern.ch/record/700)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
"require(['notebook'],\n",
" function() {\n",
" IPython.CodeCell.config_defaults.highlight_modes['magic_text/x-c++src'] = {'reg':[/^%%cpp/]};\n",
" console.log(\"JupyROOT - %%cpp magic configured\");\n",
" }\n",
");\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Welcome to JupyROOT 6.07/07\n"
]
}
],
"source": [
"import ROOT"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A little extra: JavaScript visualisation. This command will become a magic very soon."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%jsroot on"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Convert to ROOT format and analyse\n",
"\n",
"First of all we convert the csv file into ROOT format, i.e. filling up a TTree data structure. But first of all we uncompress it if it's not."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"inputFileName = 'MuRun2010B.csv'\n",
"import os\n",
"if not os.path.exists(inputFileName):\n",
" import urllib2\n",
" response = urllib2.urlopen('https://raw.githubusercontent.com/dpiparo/swanExamples/master/notebooks/MuRun2010B.csv')\n",
" filecontent = response.read() \n",
" with open(inputFileName,\"w\") as f_out:\n",
" f_out.write(filecontent)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"100000L"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dimuons = ROOT.TTree(\"MuonPairs\",\"MuonPairs\")\n",
"dimuons.ReadFile(inputFileName)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we create an histogram to hold the invariant mass values. In order to loop on the TTree rows, we use the [TTree::Draw](https://root.cern.ch/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45) method: this is the most straightforward way in which you can loop on a N-tuple in ROOT.\n",
"\n",
"**Notice that the plot is an interactive JavaScript based visualisation**: you can zoom on the resonances to better inspect the result."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
"
\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"invMass = ROOT.TH1F(\"invMass\",\"CMS Opendata: #mu#mu mass;#mu#mu mass [GeV];Events\",512, 2, 110)\n",
"invMassFormula = \"sqrt((E1 + E2)^2 - ((px1 + px2)^2 + (py1 + py2)^2 + (pz1 + pz2)^2))\"\n",
"cut = \"Q1*Q2==-1\"\n",
"c = ROOT.TCanvas()\n",
"dimuons.Draw(invMassFormula + \" >> invMass\",cut,\"hist\")\n",
"c.SetLogx()\n",
"c.SetLogy()\n",
"c.Draw()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"That might have been too fast. We now make the analysis above more explicit producing a plot also for the J/Psi particle."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from math import sqrt\n",
"invMass = ROOT.TH1F(\"Spectrum\",\"Subset of CMS Run 2010B;#mu#mu mass [GeV];Events\",1024, 2, 110)\n",
"jpsiLow = 2.95\n",
"jspiHigh = 3.25\n",
"jpsi = ROOT.TH1F(\"jpsi\",\"Subset of CMS Run 2010B: J/#psi window;#mu#mu mass [GeV];Events\",128, jpsiLow, jspiHigh)\n",
"\n",
"for e in dimuons: # a loop on the events\n",
" if e.Q1 * e.Q2 != -1:\n",
" continue\n",
" m2 = (e.E1 + e.E2)**2 - ((e.px1 + e.px2)**2 + (e.py1 + e.py2)**2 + (e.pz1 + e.pz2)**2)\n",
" m = sqrt(m2)\n",
" invMass.Fill(m)\n",
" if m < jspiHigh and m > jpsiLow:\n",
" jpsi.Fill(m)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now time to draw our plot: this time we will inline an image in the notebook. We will plot on the same canvas the full spectrum and the zoom in the J/psi particle."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"