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

Import required modules¶

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


Read in Data from Input File¶

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


Declare Histograms¶

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


Compute Invariant Mass of J/$\psi$¶

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


Fitting the J/$\psi$ Peak¶

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

Canvas = TCanvas()


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

In [ ]:
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()

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

Z = TH1F("Z","#mu#mu mass;#mu#mu mass [GeV];Events", 1000, 70, 111)

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 > 70 and InvariantMass < 111:

Z.Fill(InvariantMass)

from ROOT import TF1, kGreen, kRed

Canvas = TCanvas()

Gaussian = TF1("Gaussian","gaus", 87, 95)
Background  = TF1("Background","pol1", 70, 111)

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

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

Canvas.Draw()

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

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

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 > 8 and InvariantMass < 12:

Upsilon.Fill(InvariantMass)


In [3]:
from ROOT import TF1, kGreen, kRed, kYellow, kPink

Canvas = TCanvas()

Gaussian1 = TF1("Gaussian1","gaus", 9.26, 9.61)
Gaussian2 = TF1("Gaussian2","gaus", 9.8, 10.2)
Gaussian3 = TF1("Gaussian3","gaus", 10.2, 10.5)
Background  = TF1("Background","pol1", 8, 12)

Gaussian1.SetLineColor(kYellow)
Gaussian2.SetLineColor(kRed)
Gaussian3.SetLineColor(kPink)
Background.SetLineColor(kGreen)

Upsilon.Fit(Gaussian1,"R1")
Upsilon.Fit(Gaussian2,"R2+")
Upsilon.Fit(Gaussian3,"R3+")
Upsilon.Fit(Background,"R+")

Canvas.Draw()

 FCN=121.407 FROM MIGRAD    STATUS=CONVERGED      69 CALLS          70 TOTAL
EDM=8.61096e-10    STRATEGY= 1  ERROR MATRIX UNCERTAINTY   2.3 per cent
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     2.07229e+02   2.55805e+00   2.20583e-03  -1.06171e-05
2  Mean         9.44933e+00   1.41141e-03  -3.00019e-07   6.63166e-03
3  Sigma        1.16880e-01   1.88188e-03  -5.33296e-06   5.01727e-03
FCN=110.717 FROM MIGRAD    STATUS=CONVERGED     113 CALLS         114 TOTAL
EDM=1.77922e-08    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     1.18309e+02   1.71792e+00   6.10826e-03  -6.52346e-05
2  Mean         1.00221e+01   3.77730e-03   1.79858e-05  -3.37123e-02
3  Sigma        1.94369e-01   6.85653e-03   5.57284e-05   4.75689e-03
FCN=67.0953 FROM MIGRAD    STATUS=CONVERGED     112 CALLS         113 TOTAL
EDM=1.09651e-08    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Constant     1.03373e+02   1.76854e+00   4.89702e-03  -8.22534e-05
2  Mean         1.03350e+01   8.08859e-03   3.00292e-05  -4.48081e-03
3  Sigma        2.32207e-01   2.24293e-02   1.56126e-04  -3.78166e-03

****************************************
Minimizer is Linear
Chi2                      =      9741.05
NDf                       =          998
p0                        =     -140.444   +/-   1.79423
p1                        =      20.6121   +/-   0.188834

In [ ]: