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

Import required modules

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

Read in Data from Input File

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

Declare Histograms

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

Compute Invariant Mass of J/$\psi$

In [7]:
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 [8]:
from ROOT import TF1, kGreen, kRed

Canvas = TCanvas()

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

In [9]:
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 [3]:
from ROOT import TFile, TCanvas, TH1F, TLorentzVector
%jsroot on

file = TFile("../data/Dimuons.root","READ");

z_boson = TH1F("zboson","#mu#mu mass;#mu#mu mass [GeV];Events", 1000, 70, 120)

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.0 and InvariantMass < 120.0:

            z_boson.Fill(InvariantMass)
            
from ROOT import TF1, kGreen, kRed

Canvas = TCanvas()

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

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

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

Canvas.Draw()
 FCN=268.513 FROM MIGRAD    STATUS=CONVERGED      72 CALLS          73 TOTAL
                     EDM=8.59885e-08    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  Constant     2.36718e+02   2.11587e+00   1.23773e-02   1.59380e-04
   2  Mean         9.08217e+01   1.61174e-02   1.28180e-04   1.90289e-02
   3  Sigma        2.10257e+00   1.75197e-02   1.75692e-05   1.38617e-01

****************************************
Minimizer is Linear
Chi2                      =      24551.1
NDf                       =          943
p0                        =       41.589   +/-   0.584721    
p1                        =    -0.347113   +/-   0.00546932  
In [1]:
from ROOT import TFile, TCanvas, TH1F, TLorentzVector
%jsroot on

file = TFile("../data/Dimuons.root","READ");

upsilon = TH1F("upsilon","#mu#mu mass;#mu#mu mass [GeV];Events", 1000, 8.0, 12.0)

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.0 and InvariantMass < 12.0:

            upsilon.Fill(InvariantMass)
            
Welcome to JupyROOT 6.07/07
In [2]:
from ROOT import TF1, kGreen, kRed

Canvas = TCanvas()

Gaussian = TF1("Gaussian","gaus", 9.3, 9.6)
Gaussian2 = TF1("Gaussian2","gaus", 9.84, 10.16)
Gaussian3 = TF1("Gaussian3","gaus", 10.2, 10.5)
Background  = TF1("Background","pol1", 8, 12)

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

upsilon.Fit(Gaussian,"R")
upsilon.Fit(Gaussian2,"R2+")
upsilon.Fit(Gaussian3,"R3+")
upsilon.Fit(Background,"R+")

Canvas.Draw()
 FCN=79.829 FROM MIGRAD    STATUS=CONVERGED      89 CALLS          90 TOTAL
                     EDM=4.19646e-10    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  Constant     2.12407e+02   2.73248e+00   8.48712e-03   1.08776e-05
   2  Mean         9.45177e+00   1.42689e-03   6.25756e-06   2.67027e-03
   3  Sigma        1.09200e-01   2.04239e-03   2.37270e-05   5.27763e-03
 FCN=75.2579 FROM MIGRAD    STATUS=CONVERGED      84 CALLS          85 TOTAL
                     EDM=7.31957e-10    STRATEGY= 1  ERROR MATRIX UNCERTAINTY   2.6 per cent
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  Constant     1.21647e+02   1.93729e+00   1.66805e-03  -3.12560e-05
   2  Mean         1.00152e+01   3.65123e-03  -2.47985e-06   5.59594e-03
   3  Sigma        1.65543e-01   7.09809e-03  -1.04327e-05  -1.09809e-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 [ ]: