{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# CMS Open Data Example #6: Fitting the J/$\\psi$ fit\n", "\n", "## Import required modules" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from ROOT import TFile, TCanvas, TH1F, TLorentzVector\n", "%jsroot on" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in Data from Input File" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "file = TFile(\"../data/Dimuons.root\",\"READ\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Declare Histograms" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "Jpsi = TH1F(\"Jpsi\",\"#mu#mu mass;#mu#mu mass [GeV];Events\", 1000, 2, 3.5)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Compute Invariant Mass of J/$\\psi$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "for dimu in file.Dimuons:\n", "\n", " if dimu.Muon1_Global and dimu.Muon2_Global: \n", " \n", " muon1 = TLorentzVector(dimu.Muon1_Px, dimu.Muon1_Py, dimu.Muon1_Pz, dimu.Muon1_Energy)\n", " \n", " muon2 = TLorentzVector(dimu.Muon2_Px, dimu.Muon2_Py, dimu.Muon2_Pz, dimu.Muon2_Energy)\n", " \n", " InvariantMass = (muon1 + muon2).M() \n", " \n", " if InvariantMass > 2.0 and InvariantMass < 4.0:\n", "\n", " Jpsi.Fill(InvariantMass)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Fitting the J/$\\psi$ Peak" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from ROOT import TF1, kGreen, kRed\n", "\n", "Canvas = TCanvas()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Possible fitting options:
\n", "\"gaus\" gaussian
\n", "\"pol1\" 1st order polynomial
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "Gaussian = TF1(\"Gaussian\",\"gaus\", 3.03, 3.16)\n", "Background = TF1(\"Background\",\"pol1\", 2, 3.5)\n", "\n", "Gaussian.SetLineColor(kRed)\n", "Background.SetLineColor(kGreen)\n", "\n", "Jpsi.Fit(Gaussian,\"R\")\n", "Jpsi.Fit(Background,\"R+\")\n", "\n", "Canvas.Draw()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from ROOT import TFile, TCanvas, TH1F, TLorentzVector\n", "%jsroot on\n", "\n", "file = TFile(\"../data/Dimuons.root\",\"READ\");\n", "\n", "Z = TH1F(\"Z\",\"#mu#mu mass;#mu#mu mass [GeV];Events\", 1000, 70, 111)\n", "\n", "for dimu in file.Dimuons:\n", "\n", " if dimu.Muon1_Global and dimu.Muon2_Global: \n", " \n", " muon1 = TLorentzVector(dimu.Muon1_Px, dimu.Muon1_Py, dimu.Muon1_Pz, dimu.Muon1_Energy)\n", " \n", " muon2 = TLorentzVector(dimu.Muon2_Px, dimu.Muon2_Py, dimu.Muon2_Pz, dimu.Muon2_Energy)\n", " \n", " InvariantMass = (muon1 + muon2).M() \n", " \n", " if InvariantMass > 70 and InvariantMass < 111:\n", "\n", " Z.Fill(InvariantMass)\n", " \n", "from ROOT import TF1, kGreen, kRed\n", "\n", "Canvas = TCanvas()\n", "\n", "Gaussian = TF1(\"Gaussian\",\"gaus\", 87, 95)\n", "Background = TF1(\"Background\",\"pol1\", 70, 111)\n", "\n", "Gaussian.SetLineColor(kRed)\n", "Background.SetLineColor(kGreen)\n", "\n", "Z.Fit(Gaussian,\"R\")\n", "Z.Fit(Background,\"R+\")\n", "\n", "Canvas.Draw()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from ROOT import TFile, TCanvas, TH1F, TLorentzVector\n", "%jsroot on\n", "\n", "file = TFile(\"../data/Dimuons.root\",\"READ\");\n", "\n", "Upsilon = TH1F(\"Upsilon\",\"#mu#mu mass;#mu#mu mass [GeV];Events\", 1000, 8, 12)\n", "\n", "for dimu in file.Dimuons:\n", "\n", " if dimu.Muon1_Global and dimu.Muon2_Global: \n", " \n", " muon1 = TLorentzVector(dimu.Muon1_Px, dimu.Muon1_Py, dimu.Muon1_Pz, dimu.Muon1_Energy)\n", " \n", " muon2 = TLorentzVector(dimu.Muon2_Px, dimu.Muon2_Py, dimu.Muon2_Pz, dimu.Muon2_Energy)\n", " \n", " InvariantMass = (muon1 + muon2).M() \n", " \n", " if InvariantMass > 8 and InvariantMass < 12:\n", "\n", " Upsilon.Fill(InvariantMass)\n", " \n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " FCN=121.407 FROM MIGRAD STATUS=CONVERGED 69 CALLS 70 TOTAL\n", " EDM=8.61096e-10 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 2.3 per cent\n", " EXT PARAMETER STEP FIRST \n", " NO. NAME VALUE ERROR SIZE DERIVATIVE \n", " 1 Constant 2.07229e+02 2.55805e+00 2.20583e-03 -1.06171e-05\n", " 2 Mean 9.44933e+00 1.41141e-03 -3.00019e-07 6.63166e-03\n", " 3 Sigma 1.16880e-01 1.88188e-03 -5.33296e-06 5.01727e-03\n", " FCN=110.717 FROM MIGRAD STATUS=CONVERGED 113 CALLS 114 TOTAL\n", " EDM=1.77922e-08 STRATEGY= 1 ERROR MATRIX ACCURATE \n", " EXT PARAMETER STEP FIRST \n", " NO. NAME VALUE ERROR SIZE DERIVATIVE \n", " 1 Constant 1.18309e+02 1.71792e+00 6.10826e-03 -6.52346e-05\n", " 2 Mean 1.00221e+01 3.77730e-03 1.79858e-05 -3.37123e-02\n", " 3 Sigma 1.94369e-01 6.85653e-03 5.57284e-05 4.75689e-03\n", " FCN=67.0953 FROM MIGRAD STATUS=CONVERGED 112 CALLS 113 TOTAL\n", " EDM=1.09651e-08 STRATEGY= 1 ERROR MATRIX ACCURATE \n", " EXT PARAMETER STEP FIRST \n", " NO. NAME VALUE ERROR SIZE DERIVATIVE \n", " 1 Constant 1.03373e+02 1.76854e+00 4.89702e-03 -8.22534e-05\n", " 2 Mean 1.03350e+01 8.08859e-03 3.00292e-05 -4.48081e-03\n", " 3 Sigma 2.32207e-01 2.24293e-02 1.56126e-04 -3.78166e-03\n", "\n", "****************************************\n", "Minimizer is Linear\n", "Chi2 = 9741.05\n", "NDf = 998\n", "p0 = -140.444 +/- 1.79423 \n", "p1 = 20.6121 +/- 0.188834 \n" ] }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from ROOT import TF1, kGreen, kRed, kYellow, kPink\n", "\n", "Canvas = TCanvas()\n", "\n", "Gaussian1 = TF1(\"Gaussian1\",\"gaus\", 9.26, 9.61)\n", "Gaussian2 = TF1(\"Gaussian2\",\"gaus\", 9.8, 10.2)\n", "Gaussian3 = TF1(\"Gaussian3\",\"gaus\", 10.2, 10.5)\n", "Background = TF1(\"Background\",\"pol1\", 8, 12)\n", "\n", "Gaussian1.SetLineColor(kYellow)\n", "Gaussian2.SetLineColor(kRed)\n", "Gaussian3.SetLineColor(kPink)\n", "Background.SetLineColor(kGreen)\n", "\n", "Upsilon.Fit(Gaussian1,\"R1\")\n", "Upsilon.Fit(Gaussian2,\"R2+\")\n", "Upsilon.Fit(Gaussian3,\"R3+\")\n", "Upsilon.Fit(Background,\"R+\")\n", "\n", "Canvas.Draw()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }