# CMS Open Data Example #6: Fitting the J/$\psi$ fit¶

## Import required modules¶

In [2]:
from ROOT import TFile, TCanvas, TH1F, TLorentzVector
%jsroot on

Welcome to JupyROOT 6.07/07


## Read in Data from Input File¶

In [3]:
file = TFile("../data/Dimuons.root","READ");


## Declare Histograms¶

In [8]:
Jpsi = TH1F("Jpsi","#mu#mu mass;#mu#mu mass [GeV];Events", 1000, 2, 3.5)

Epsilon = TH1F("Epsilon", "#mu#mu mass;#mu#mu mass [GeV];Events", 1000, 8, 11)


# Compute Invariant Mass of J/$\psi$¶

In [9]:
for dimu in file.Dimuons:

if dimu.Muon1_Global and dimu.Muon2_Global:

muon1 = TLorentzVector(dimu.Muon1_Px, dimu.Muon1_Py, dimu.Muon1_Pz, dimu.Muon1_Energy)

muon2 = TLorentzVector(dimu.Muon2_Px, dimu.Muon2_Py, dimu.Muon2_Pz, dimu.Muon2_Energy)

InvariantMass = (muon1 + muon2).M()

if InvariantMass > 2.0 and InvariantMass < 4.0:

Jpsi.Fill(InvariantMass)

if InvariantMass > 2.0 and InvariantMass < 11:

Epsilon.Fill(InvariantMass)


## Fitting the J/$\psi$ Peak¶

In [11]:
from ROOT import TF1, kGreen, kRed

Canvas = TCanvas()


Possible fitting options:
"gaus" gaussian
"pol1" 1st order polynomial

In [7]:
Gaussian = TF1("Gaussian","gaus", 3.03, 3.16)
Background  = TF1("Background","pol1", 2, 3.5)

Gaussian.SetLineColor(kRed)
Background.SetLineColor(kGreen)

Jpsi.Fit(Gaussian,"R")
Jpsi.Fit(Background,"R+")

Canvas.Draw()

 FCN=238.61 FROM MIGRAD    STATUS=CONVERGED      71 CALLS          72 TOTAL
EDM=7.76303e-09    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     5.82050e+02   4.65629e+00   2.59691e-02  -1.64617e-05
2  Mean         3.09292e+00   2.01159e-04   1.51576e-06   9.89004e-02
3  Sigma        3.05871e-02   2.03936e-04   1.30856e-05   2.50483e-02

****************************************
Minimizer is Linear
Chi2                      =      28549.5
NDf                       =          998
p0                        =      65.9587   +/-   0.923571
p1                        =     -15.3932   +/-   0.313802

In [31]:
Canvas.Clear()

Gaussian = TF1("Gaussian","gaus", 9.32, 9.57)
Background  = TF1("Background","pol1", 8, 10.5)
Gaussian2 = TF1("Gaussian2","gaus", 9.93, 10.08)

Gaussian.SetLineColor(kRed)
Background.SetLineColor(kGreen)
Gaussian2.SetLineColor(kRed)

Epsilon.Fit(Gaussian,"R")
Epsilon.Fit(Background,"R+")
Epsilon.Fit(Gaussian2, "R+")

Canvas.Draw()

 FCN=65.5027 FROM MIGRAD    STATUS=CONVERGED      90 CALLS          91 TOTAL
EDM=3.86517e-07    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     1.61806e+02   2.21007e+00   6.21240e-03   3.70006e-04
2  Mean         9.45090e+00   1.59014e-03   6.24777e-06   2.42948e-01
3  Sigma        1.02936e-01   2.50323e-03   2.93666e-05   9.81831e-02

****************************************
Minimizer is Linear
Chi2                      =      5622.98
NDf                       =          831
p0                        =     -245.506   +/-   2.57463
p1                        =      31.6512   +/-   0.291605
FCN=32.0052 FROM MIGRAD    STATUS=CONVERGED     126 CALLS         127 TOTAL
EDM=6.58228e-08    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     9.57450e+01   2.09517e+00   4.01398e-03  -1.04249e-04
2  Mean         1.00128e+01   5.38306e-03   1.38239e-05   6.34696e-02
3  Sigma        1.18832e-01   1.53719e-02   1.46383e-04  -5.42312e-03

In [ ]: