PAT Examples: Electroweak Analysis



In this tutorial we will show how to make a PAT-based analysis in the context of the EWK PAG. The inclusive Z->mumu analysis, which exploits PAT objects as muons and tracks, will be taken as an example. If you are interested in EWK electron analysis, please refer to the EWK Electron tutorial

The Z->mumu analysis is performed in two steps. In the first step we run the dimuon skim over the original AOD collections. The skim makes a HLT-based preselection of events, creates PAT objects from the "official" muons and tracks provided by the CMS reconstruction, and builds dimuon candidates to be stored into the skim output. In the second step we run an analyzer on the skim output which selects the dimuon candidates compatible with a Z->mumu decay and plots their invariant mass distribution.

You will learn:

  • how to run the dimuon skim
  • how to access some variables from the PAT objects in order to make a signal selection

How to get the dimuon skim code

The tutorial analysis works in CMSSW_4_2_4 release. So, first create a project area based on 4_2_4:
cmsrel CMSSW_4_2_4
cd CMSSW_4_2_4/src/

Then, get the package for the skim and compile:

addpkg ElectroWeakAnalysis/Skimming V01-01-12
cd ElectroWeakAnalysis/Skimming
scram b

How to run the dimuon skim

Go to the test directory of the package:

cd ElectroWeakAnalysis/Skimming/test/

Specify a Z->mumu MC collection to be given in input by editing the following parameter in the cfg file

process.source = cms.Source("PoolSource", 
     fileNames = cms.untracked.vstring(

Specify the number of events to be processed (a few hundred is enough for the tutorial):

process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(200) )

Run the skim [Before running, make sure the input file is accessible and the corresponding global tag]:


At the end you will get a skimmed collection containing AOD + dimuon candidates objects:


Find out more about the skim configuration

Look at files into ElectroWeakAnalysis/Skimming/python/ if you want to inspect the configuration of the dimuon skim.

In order to check the relevant configurations for PAT muons and tracks, have a look at:

Comment lines in this file should help you in following the description below.

PAT muons are created by calling standard PAT configuration files:

Note that there are changes of the default parameters of the module making MC matching of PAT muons to generated muons:
from CMS.PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi import *
muonMatch.maxDeltaR = 0.15
muonMatch.maxDPtRel = 1.0
muonMatch.resolveAmbiguities = True
muonMatch.resolveByMatchQuality = True

We also compute custom tracker, ecal, and hcal isolation variables to be embedded in PAT muons:

from CMS.PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi import *
patMuons.isoDeposits = cms.PSet(
        tracker = cms.InputTag("muIsoDepositTk"),
        ecal    = cms.InputTag("muIsoDepositCalByAssociatorTowers","ecal"),
        hcal    = cms.InputTag("muIsoDepositCalByAssociatorTowers","hcal"),
patMuons.userIsolation = cms.PSet(
        hcal = cms.PSet(
            src = cms.InputTag("muIsoDepositCalByAssociatorTowers","hcal"),
            deltaR = cms.double(0.3)
        tracker = cms.PSet(
            veto = cms.double(0.015),
            src = cms.InputTag("muIsoDepositTk"),
            deltaR = cms.double(0.3),
            threshold = cms.double(1.5)
        ecal = cms.PSet(
            src = cms.InputTag("muIsoDepositCalByAssociatorTowers","ecal"),
            deltaR = cms.double(0.3)

We apply a (dummy) selection to patMuons obtaining the PAT muon objects called selectedPatMuons. Finally we perform trigger matching between selectedPatMuons and the HLT muons firing the HLT_Mu9 trigger path. The collection of PAT muons embedding the trigger matching result is called selectedPatMuonsTriggerMatch.

Standard and custom configuration files are used to make PAT tracks. Intermediate candidates (patAODTrackCands) are first created. Only tracks above a certain pT threshold (10 GeV/c) are considered. Note that at this level, IsoDeposits in tracker and calorimeters associated to the tracks are computed from AOD, and MC matching to generated muons is performed.

PAT tracks (allPatTracks) are built by the standard producer for PAT generic particles:

The following parameters are specified in order to embed some variables into PAT tracks (MC match to generated muons, IsoDeposits, tracker, ecal, and hcal pre-computed isolation values):
allPatTracks = patGenericParticles.clone(
    src = cms.InputTag("patAODTrackCands"),
    # isolation configurables
    userIsolation = cms.PSet(
      tracker = cms.PSet(
        veto = cms.double(0.015),
        src = cms.InputTag("patAODTrackIsoDepositCtfTk"),
        deltaR = cms.double(0.3),
        threshold = cms.double(1.5)
      ecal = cms.PSet(
        src = cms.InputTag("patAODTrackIsoDepositCalByAssociatorTowers","ecal"),
        deltaR = cms.double(0.3)
      hcal = cms.PSet(
        src = cms.InputTag("patAODTrackIsoDepositCalByAssociatorTowers","hcal"),
        deltaR = cms.double(0.3)
    isoDeposits = cms.PSet(
      tracker = cms.InputTag("patAODTrackIsoDepositCtfTk"),
      ecal = cms.InputTag("patAODTrackIsoDepositCalByAssociatorTowers","ecal"),
      hcal = cms.InputTag("patAODTrackIsoDepositCalByAssociatorTowers","hcal")
    addGenMatch = cms.bool(True),
    genParticleMatch = cms.InputTag("trackMuMatch")
We apply a selection to the tracks (again a pT threshold of 10 GeV/c) and thus we are left with the PAT track objects called selectedPatTracks. No track cleaning is applied.

Dimuon candidates are built starting from selectedPatMuonsTriggerMatch and SelectedPatTracks. You can check the following files:,

Event preselection based on HLT is defined in The skim paths are defined into The event content of the skim output is defined into

How to get the analyzer code

The tutorial analyzer has been tested in CMSSW_3_8_2 release. So, in a 3_8_2 project area checkout and compile the analyzer in the CMS.PhysicsTools/PatExamples package:
cvs co -r CMSSW_3_8_2 PhysicsTools/PatExamples
cd PhysicsTools/PatExamples/plugins
scram b

How to run the analyzer

Go to the test directory of the package:
cd PhysicsTools/PatExamples/test/

You can run on the skimmed collection made in the previous step. Alternatively, if you want to run on more events, a skimmed collection (made from 1007 events) is available on castor. Specify the path of the skimmed collection by editing the following parameter in the cfg file

process.source = cms.Source(
    fileNames = 

Run the analysis [The file is dead. The instructions will be updated soon.]:

At the end you will get an output root file containing a few invariant mass histograms:

Find out more about the analyzer

Have a look at CMS.PhysicsTools/PatExamples/plugins/ The comment lines in the file should help you in following the description below.

The module takes as input parameter a certain category of dimuons candidates and applies cuts to the muon daughters in order to select candidates compatible with a Z->mu+mu- decay. The selection is the following:

  • Both muons must be global muons
  • The net charge of the pair must be 0
  • Each muon must satisfy geometrical and kinematical acceptance cuts
  • Each muon must satisfy an isolation cut. Note the two alternative ways to get muon isolation. In the first case we just get the pre-computed tracker isolation variable. In the second case we compute the isolation variable from the embedded IsoDeposits (this is useful when, for instance, you want to test alternative isolation definitions).
  • The invariant mass of the pair must be within a certain interval
The invariant mass of the dimuon candidates passing these cuts is plotted. We study also the generated muons which are MC-matched to the Z candidates daughters: we exploits the mother-daughter relationships of the generated particles in order to identify the Z candidates which correspond to a true Z->mumu(gamma) decay.

The dimuon candidates to be analyzed and the analysis cuts are specified at cfg level in

Make changes by yourself

  • Plot the pT spectrum of the highest momentum muon coming from the Z and the pT spectrum of the lowest momentum muon coming from the Z. Do that for reconstructed muons and generated muons.
  • Plot the pre-computed Ecal isolation for both muons coming from the Z (before applying tracker isolation). Make the same for the sum of Ecal and Tracker isolations. Try also to compute by yourself an Ecal isolation from IsoDeposits by using a dR isolation cone of 0.2.
  • Repeat the analysis but require that one muon must be a global muon and the other muon must be a standalone muon
  • Repeat the analysis but give in input the dimuonsOneTrack collection. Require in the analysis that the PAT muon must be a global muon.

How to get more information

Refer to the EWK twiki for more general informations about PAG analyses and MC collections:

EWK Electron analysis tutorial

Refer to the following twiki:

Review status

Reviewer/Editor and Date (copy from screen) Comments
SamirGuragain - 17 May 2012 Updated tutorial partially for 4_2_4 release and the analyzer part is incomplete and the work is in progress.
FrancescoFabozzi - 03 Sep 2010 Updated tutorial for 3_8_2 release
FrancescoFabozzi - 10 Mar 2010 Updated tutorial for 3_5_4 release
FrancescoFabozzi - 28 Dec 2009 Added link to EWK Electron tutorial
FrancescoFabozzi - 27 Dec 2009 Updated tutorial for 3_3_5 release
FrancescoFabozzi - 03 Sep 2009 Updated tutorial for 3_1_2 release
FrancescoFabozzi - 08 Jun 2009 Added tutorial description
RogerWolf - 13 May 2009 Created the template page

Responsible: FrancescoFabozzi
Last reviewed by: most recent reviewer and date

Edit | Attach | Watch | Print version | History: r26 < r25 < r24 < r23 < r22 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r26 - 2012-05-18 - unknown



    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback