Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-25 02:40:36

0001 #! /usr/bin/env python3
0002 
0003 from builtins import range
0004 import ROOT
0005 import sys
0006 from DataFormats.FWLite import Events, Handle
0007 
0008 # Make VarParsing object
0009 # https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideAboutPythonConfigFile#VarParsing_Example
0010 from FWCore.ParameterSet.VarParsing import VarParsing
0011 options = VarParsing ('python')
0012 options.parseArguments()
0013 
0014 # Events takes either
0015 # - single file name
0016 # - list of file names
0017 # - VarParsing options
0018 
0019 # use Varparsing object
0020 events = Events (options)
0021 # use single file name
0022 #events = Events ("root://cmsxrootd.fnal.gov///store/mc/RunIISummer20UL17MiniAODv2/DYJetsToMuMu_M-50_TuneCP5_13TeV-madgraphMLM-pythia8/MINIAODSIM/PUForMUOVal_106X_mc2017_realistic_v9-v2/100000/002FD620-0EF8-F044-9D21-7303C48FF2A0.root")
0023 
0024 # create handle outside of loop
0025 handle  = Handle ("std::vector<pat::Muon>")
0026 
0027 # for now, label is just a tuple of strings that is initialized just
0028 # like and edm::InputTag
0029 label = ("slimmedMuons")
0030 
0031 # Create histograms, etc.
0032 ROOT.gROOT.SetBatch()        # don't pop up canvases
0033 ROOT.gROOT.SetStyle('Plain') # white background
0034 zmassHist = ROOT.TH1F ("zmass", "Z Candidate Mass", 50, 20, 220)
0035 
0036 # loop over events
0037 for event in events:
0038     # use getByLabel, just like in cmsRun
0039     event.getByLabel (label, handle)
0040     # get the product
0041     muons = handle.product()
0042     # use muons to make Z peak
0043     numMuons = len (muons)
0044     if numMuons < 2: continue
0045     for outer in range (numMuons - 1):
0046         outerMuon = muons[outer]
0047         for inner in range (outer + 1, numMuons):
0048             innerMuon = muons[inner]
0049             if outerMuon.charge() * innerMuon.charge() >= 0:
0050                 continue
0051             inner4v = ROOT.TLorentzVector (innerMuon.px(), innerMuon.py(),
0052                                            innerMuon.pz(), innerMuon.energy())
0053             outer4v = ROOT.TLorentzVector (outerMuon.px(), outerMuon.py(),
0054                                            outerMuon.pz(), outerMuon.energy())
0055             zmassHist.Fill( (inner4v + outer4v).M() )
0056 
0057 # make a canvas, draw, and save it
0058 c1 = ROOT.TCanvas()
0059 zmassHist.Draw()
0060 c1.Print ("zmass_py.png")
0061