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

## Import required modules¶

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

Welcome to JupyROOT 6.07/07


## Read in Data from Input File¶

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


## Declare Histograms¶

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


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

In [26]:
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 < 12.0:

Jpsi.Fill(InvariantMass)


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

In [40]:
#Importing colors. All colors can be found at: https://root.cern.ch/doc/master/pict1_TColor_002.png
from ROOT import TF1, kGreen, kRed, kBlack, kBlue, kMagenta, kSpring, kOrange

Canvas = TCanvas()


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

In [48]:
Gaussian = TF1("Gaussian","gaus", 3.03, 3.16)
Gaussian2 = TF1("Gaussian2","gaus", 3.61, 3.73)
Gaussian3 = TF1("Gaussian3","gaus", 9.30, 9.60)
Gaussian4 = TF1("Gaussian4","gaus", 9.90, 10.10)
Background  = TF1("Background","pol1", 2, 3.5)
Background2 = TF1("Background2","pol1", 3.5, 4.5)
Background3 = TF1("Background3","pol1", 9.0,9.80)
Background4 = TF1("Background4","pol1", 9.8,10.2)

Gaussian.SetLineColor(kMagenta)
Gaussian2.SetLineColor(kRed)
Gaussian3.SetLineColor(kGreen)
Gaussian4.SetLineColor(kOrange)
Background.SetLineColor(kMagenta-3)
Background2.SetLineColor(kRed-3)
Background3.SetLineColor(kGreen-3)
Background4.SetLineColor(kOrange-3)

#Adding all of the ranges to the graph. "R" adds one range, "R+" adds any more desired ranges on top of the graph.

Jpsi.Fit(Gaussian, "R")
Jpsi.Fit(Gaussian2,"R+")
Jpsi.Fit(Gaussian3,"R+")
Jpsi.Fit(Gaussian4,"R+")
Jpsi.Fit(Background,"R+")
Jpsi.Fit(Background2, "R+")
Jpsi.Fit(Background3, "R+")
Jpsi.Fit(Background4, "R+")

Canvas.Draw()

 FCN=149.029 FROM MIGRAD    STATUS=CONVERGED      72 CALLS          73 TOTAL
EDM=1.40552e-08    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     3.87217e+03   3.08784e+01   1.36350e-01  -4.17442e-06
2  Mean         3.09296e+00   2.01458e-04   1.47484e-06   6.38239e-01
3  Sigma        3.07769e-02   2.03771e-04   1.02893e-05  -5.38318e-02
FCN=8.48386 FROM MIGRAD    STATUS=CONVERGED      81 CALLS          82 TOTAL
EDM=4.55485e-08    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     2.02642e+02   6.59361e+00   7.27255e-03   2.53700e-05
2  Mean         3.68088e+00   1.46786e-03   1.99949e-06  -8.89178e-02
3  Sigma        4.09420e-02   1.78075e-03   1.78405e-05   2.41617e-02
FCN=42.858 FROM MIGRAD    STATUS=CONVERGED      81 CALLS          82 TOTAL
EDM=2.05062e-07    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     5.31770e+02   6.83870e+00   1.56278e-02   5.69628e-05
2  Mean         9.45177e+00   1.43259e-03   4.62733e-06  -6.96265e-03
3  Sigma        1.09536e-01   2.06032e-03   1.75886e-05   1.10902e-01
FCN=21.9992 FROM MIGRAD    STATUS=CONVERGED     113 CALLS         114 TOTAL
EDM=4.24603e-08    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     3.16395e+02   6.14258e+00   9.78039e-03  -4.38850e-05
2  Mean         1.00088e+01   4.11976e-03   9.22171e-06  -4.50788e-02
3  Sigma        1.29048e-01   1.00618e-02   6.63857e-05  -1.05958e-03

****************************************
Minimizer is Linear
Chi2                      =      27583.4
NDf                       =          148
p0                        =      440.809   +/-   6.31772
p1                        =     -100.673   +/-   2.15527

****************************************
Minimizer is Linear
Chi2                      =      868.298
NDf                       =           98
p0                        =      226.733   +/-   10.01
p1                        =     -45.0541   +/-   2.45115

****************************************
Minimizer is Linear
Chi2                      =      3873.43
NDf                       =           78
p0                        =     -1161.29   +/-   56.4754
p1                        =      145.267   +/-   6.0377

****************************************
Minimizer is Linear
Chi2                      =      275.335
NDf                       =           38
p0                        =     -1195.13   +/-   201.499
p1                        =      144.083   +/-   20.1662

In [ ]: