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 [3]:
Jpsi = TH1F("Jpsi","#mu#mu mass;#mu#mu mass [GeV];Events", 1000, 2, 3.5)

Compute Invariant Mass of J/$\psi$

In [4]:
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 [5]:
from ROOT import TF1, kBlack, kOrange

Canvas = TCanvas()

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

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

Gaussian.SetLineColor(kOrange)
Background.SetLineColor(kBlack)

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