#!/usr/bin/env python
# coding: utf-8
#
# # CMS Open Data Example #6: Fitting the J/$\psi$ fit
#
# ## Import required modules
# In[1]:
from ROOT import TFile, TCanvas, TH1F, TLorentzVector
get_ipython().run_line_magic('jsroot', 'on')
# ## 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()
# In[ ]: