CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DataFormats/FWLite/examples/patZpeak.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import ROOT
00004 import sys
00005 from DataFormats.FWLite import Events, Handle
00006 
00007 # Make VarParsing object
00008 # https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideAboutPythonConfigFile#VarParsing_Example
00009 from FWCore.ParameterSet.VarParsing import VarParsing
00010 options = VarParsing ('python')
00011 options.parseArguments()
00012 
00013 # Events takes either
00014 # - single file name
00015 # - list of file names
00016 # - VarParsing options
00017 
00018 # use Varparsing object
00019 events = Events (options)
00020 
00021 # create handle outside of loop
00022 handle  = Handle ("std::vector<pat::Muon>")
00023 
00024 # for now, label is just a tuple of strings that is initialized just
00025 # like and edm::InputTag
00026 label = ("selectedLayer1Muons")
00027 
00028 # Create histograms, etc.
00029 ROOT.gROOT.SetBatch()        # don't pop up canvases
00030 ROOT.gROOT.SetStyle('Plain') # white background
00031 zmassHist = ROOT.TH1F ("zmass", "Z Candidate Mass", 50, 20, 220)
00032 
00033 # loop over events
00034 for event in events:
00035     # use getByLabel, just like in cmsRun
00036     event.getByLabel (label, handle)
00037     # get the product
00038     muons = handle.product()
00039     # use muons to make Z peak
00040     numMuons = len (muons)
00041     if muons < 2: continue
00042     for outer in xrange (numMuons - 1):
00043         outerMuon = muons[outer]
00044         for inner in xrange (outer + 1, numMuons):
00045             innerMuon = muons[inner]
00046             if outerMuon.charge() * innerMuon.charge() >= 0:
00047                 continue
00048             inner4v = ROOT.TLorentzVector (innerMuon.px(), innerMuon.py(),
00049                                            innerMuon.pz(), innerMuon.energy())
00050             outer4v = ROOT.TLorentzVector (outerMuon.px(), outerMuon.py(),
00051                                            outerMuon.pz(), outerMuon.energy())
00052             zmassHist.Fill( (inner4v + outer4v).M() )
00053 
00054 # make a canvas, draw, and save it
00055 c1 = ROOT.TCanvas()
00056 zmassHist.Draw()
00057 c1.Print ("zmass_py.png")