The StarterKit is in the process of being replaced. The functionality in the StarterKit will be ported to FWLite in the very near future.
This page contains old information. Please see Chapters 3 and 4 of the Offline Workbook for the most up to date tutorials.
4.3 CMSSW Analysis Starter Kit
Complete:
Detailed Review status
See the starter kit in the news!
Symmetry Magazine article on Starter Kit.
Link to latest prescriptions for various releases.
This page is intended for pedagogical introduction to the
StarterKit and PAT. If you want the latest, greatest prescription, please see:
https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideStarterKit
Authors (alpha order):
- Steven Lowette <steven.lowette@cernSPAMNOT.ch>
- Petar Maksimovic <petar@jhuSPAMNOT.edu>
- Salvatore Rappoccio <rappocc@fnalSPAMNOT.gov>
- Elizabeth Sexton-Kennedy <sexton@fnalSPAMNOT.gov>
- Eric Vaandering <ewv@fnalSPAMNOT.gov>
- Guofan Hu <Guofan.Hu@cernSPAMNOT.ch>
- David Bjergaard <davidb@cernSPAMNOT.ch>
- Sudhir Malik <malik@fnalSPAMNOT.gov>
Acknowledgements:
What is the StarterKit?
- Focus: to create and implement the StarterKit, designed to facilitate "fast" analysis, to move from conception to a "reasonable" histogram within a day.
- Who is the target audience?: Anyone who wants to get a reasonable start on analysis, including professors, new grad students, theorists, postdocts, those unfamiliar with C++/ROOT/CMSSW, and many more!
- What other tools are available?: There are many other tools available for analysis in CMSSW, and the Physics Analysis Toolkit (PAT) is an attempt to consolidate them. We utilize the PAT as an analysis model. While there are other options available, this is the recommended versions for newcomers. We strongly encourage people to use the PAT for all of their analysis efforts, to avoid duplication of effort and to use well-understood objects and algorithms that are "blessed" by the Detector Performance Groups (DPG), Physics Object Groups (POG) and Physics Analysis Groups (PAG).
- See us in the news!: Symmetry magazine has run a piece on the CMS Starter Kit here: http://www.symmetrymagazine.org/cms/?pid=1000590
Structure of the StarterKit
The StarterKit is a group of C++ objects along with corresponding plugins and configuration files to plot specific examples. It is based on the Physics Analysis Toolkit (PAT) described in detail here:
The prescriptions are based on the PAT prescriptions as shown here:
The
StarterKit has the following functionality:
- Will perform "common" plots for variables in the analysis such as 4-vector quantities and matching variables for detector objects.
- A tiered structure of output, whereas the user can specify to simply make plots, perform simple skims, or write out a subset of the PAT and/or AOD.
- Can automatically make plots for CompositeCandidate objects and "drill down" to the constituents recursively.
- Provides user control for histogram binning, etc. This will eventually be generalized using the ExpressionParser functionality.
Our programming to do list includes:
- Implementation of more complex examples.
- Generic kinematic fitting of arbitrary constituents.
- A validation suite to perform CRON jobs for day-to-day monitoring.
- Extensive FWLite examples for performing analysis.
- Automatic ntuplization of composite candidates.
CMSSW in 90 seconds or less
If you've been following the workbook all along, this should be "old news" to you, but here is the "quick and dirty" introduction for the impatient user. CMSSW stands for "CMS Software", and is a coding framework for the high level trigger, the reconstruction, and the analysis all at the same time. This is a novel approach for a collaboration of this size. It creates "projects" in subdirectories based on static code "tags" (from CVS). It allows us to modularize the performance so that specific tags can be studied and compared.
The
StarterKit makes a new "package" in a directory in your home area. It will check out some code and compile it, and you can run a program on a predefined set of output and check against the "correct" answer to make sure you're starting from a good place.
Full details on the CMSSW framework can be found here:
https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookCMSSWFramework
A 30 second introduction to scram and some commands can be found here:
https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookScramV1Intro
Updated infrastructure
The StarterKit has undergone an infrastructure change in 2.1.4. We have now separated the StarterKit into three different plugins:
-
PatAnalyzerSkeleton
: This provides a skeleton analyzer that will loop over PAT objects and make a simple histogram.
-
PatAnalyzerKit
: This provides the functionality of the 1.6.x version of the StarterKit
plugin.
-
CompositeKit
: This will histogram an arbitrary collection of CompositeCandidates
.
There has also been a restructuring of the code status. Previously it was designed such that the user would inherit directly from the
EDM plugin
StarterKit
, and enhance plots using that hierarchy. This was not very performant and required users to carry around large libraries that contained the EDProducer libraries. Instead, a better solution has been worked out, so now the
StarterKit
has a "helper" class,
PatKitHelper
, which will do the majority of the plotting legwork for the plugins. To obtain the plots from this package, it is recommended to simply include this class as described below.
Class structure:
- PatAnalyzerSkeleton: EDAnalyzer to show how to only pull out the PAT objects and loop over them.
- PatAnalyzerKit: EDProducer to drive
PatKitHelper
.
- PatKitHelper: Workhorse to do the plotting for plugins.
- PhysicsHistograms: Contains and drives standard
Histo
objects for the various object types.
- HistoMuon, HistoElectron, HistoMET, HistoJet, HistoPhoton, HistoTau: Classes derived from
HistoGroup
to implement specific objects including PhysVarHisto
matching variables.
- HistoGroup: Object to plot 4-vectors using
PhysVarHisto
.
- PhysVarHisto: "Smart" histogram which can also ntuplize.
Code overview
The
StarterKit
code overview can be found here:
https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookAnalysisStarterKitCodeDescription
Prescription
We assume here that a user has gone through the following workbook that talks about setup:
https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookSetComputerNode
https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookRemoteSiteSpecifics
To set up a new area and run
#If you are working at Fermilab's cmslpc cluster you need to execute the following command before you start
source /uscms/home/malik/cshrc prod
# set up CVS environment
cmscvsroot CMSSW
# login to CVS server. Password is "98passwd"
cvs login
# make a directory for the Starter Kit
mkdir StarterKit
cd StarterKit
# create a new project area
scramv1 p CMSSW CMSSW_2_2_8
cd CMSSW_2_2_8/src/
cmsenv
# Get the Starter Kit and the PAT setup by adding following package
addpkg PhysicsTools/PatAlgos V04-14-29
addpkg PhysicsTools/PatUtils V03-05-02
addpkg DataFormats/PatCandidates V03-18-10
addpkg CondFormats/JetMETObjects V01-08-04
addpkg PhysicsTools/StarterKit V02-03-08
# build
scramv1 b
# run
cd PhysicsTools/StarterKit/test
cmsRun PatAnalyzerSkeleton_cfg.py >& skoutput.txt &
tail -f skoutput.txt &
Please note the following three comments.
Comment 1: One needs to drop particle flow on input. To achieve this the config files like
PatAnalyzerSkeleton_cfg.py have additional code lines like below
## Necessary fixes to run 2.2.X on 2.1.X data
from CMS.PhysicsTools.PatAlgos.tools.cmsswVersionTools import run22XonSummer08AODSIM
run22XonSummer08AODSIM (process)
This comes from PAT recipes given at the twiki:
https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATRecipes#PAT_for_2_2_X
Because of this you will see messages like this in the output like below:
WARNING: to run on Summer08AODSIM from 2.2.X requirs to drop CMS.ParticleFlow,
so PAT will switch from PFTau to CaloTau
Replaced tauTrigMatchHLT1Tau.src: cms.InputTag("allLayer0Taus") => cms.InputTag("allLayer0CaloTaus")
Replaced tauTrigMatchHLTLooseIsoTauMET30L1MET.src: cms.InputTag("allLayer0Taus") => cms.InputTag("allLayer0CaloTaus")
Replaced tauTrigMatchHLTDoubleIsoTauTrk3.src: cms.InputTag("allLayer0Taus") => cms.InputTag("allLayer0CaloTaus")
11-May-2009 16:50:37 CDT Initiating request to open file dcap://cmsdca1.fnal.gov:24140/pnfs/fnal.gov/usr/cms/WAX/11/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SI$
11-May-2009 16:50:54 CDT Successfully opened file dcap://cmsdca1.fnal.gov:24140/pnfs/fnal.gov/usr/cms/WAX/11/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/$
%MSG-w CMS.RootFile: PoolSource:source{*ctor*} 11-May-2009 16:50:58 CDT pre-events
Branch 'recoJetedmRefToBaseProdrecoTracksrecoTrackrecoTracksTorecoTrackedmrefhelperFindUsingAdvanceedmRefVectorsAssociationVector_ic5PFJetTracksAssociatorAtVe$
of file 'dcap://cmsdca1.fnal.gov:24140/pnfs/fnal.gov/usr/cms/WAX/11/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/6820DE4B-BE2C-DE11-975D$
that was explicitly dropped.
%MSG
%MSG-w CMS.RootFile: PoolSource:source{*ctor*} 11-May-2009 16:50:58 CDT pre-events
Branch 'recoPFJets_iterativeCone5PFJets__VALIDATION.' is being dropped from the input
of file 'dcap://cmsdca1.fnal.gov:24140/pnfs/fnal.gov/usr/cms/WAX/11/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/6820DE4B-BE2C-DE11-975D$
that was explicitly dropped.
%MSG
%MSG-w CMS.RootFile: PoolSource:source{*ctor*} 11-May-2009 16:50:58 CDT pre-events
Branch 'recoPFJets_kt4PFJets__VALIDATION.' is being dropped from the input
of file 'dcap://cmsdca1.fnal.gov:24140/pnfs/fnal.gov/usr/cms/WAX/11/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/6820DE4B-BE2C-DE11-975D$
that was explicitly dropped.
Comment 2: The process to open, read and run over a data file is not instantaneous. It takes few seconds to open and begin reading the file. So keep looking at the output of the
file
skoutput.txt
as it grows. If your job is complete, then
skoutput.txt
file should read the following at the end (By the way, you can look straight at the end of this file by doing
tail
skoutput.txt
otherwise you have to open the file and scroll down).
MessageLogger Summary
type category sev module subroutine count total
---- -------------------- -- ---------------- ---------------- ----- -----
1 CMS.RootFile -w PoolSource:sourc 32 32
2 fileAction -s PoolSource:sourc 2 2
3 fileAction -s PostModule 1 1
type category Examples: run/evt run/evt run/evt
---- -------------------- ---------------- ---------------- ----------------
1 CMS.RootFile pre-events pre-events pre-events
2 fileAction pre-events pre-events
3 fileAction 1/700
Severity # Occurrences Total Occurrences
-------- ------------- -----------------
Warning 32 32
System 3 3
Comment 3: If you want to
turn off the per event messages, like below, during processing a
run,
Begin processing the 1st record. Run 1, Event 1, LumiSection 666666 at 11-May-2009 16:52:31 CDT
Begin processing the 2nd record. Run 1, Event 2, LumiSection 666666 at 11-May-2009 16:53:05 CDT
Begin processing the 3rd record. Run 1, Event 3, LumiSection 666666 at 11-May-2009 16:53:05 CDT
Begin processing the 4th record. Run 1, Event 4, LumiSection 666666 at 11-May-2009 16:53:05 CDT
Begin processing the 5th record. Run 1, Event 5, LumiSection 666666 at 11-May-2009 16:53:05 CDT
Begin processing the 6th record. Run 1, Event 6, LumiSection 666666 at 11-May-2009 16:53:05 CDT
you can change the option
INFO
to
ERROR
, as shown below, in
PatAnalyzerKitSkeleton_cfg.py
#process.MessageLogger.cerr.threshold = 'INFO'
process.MessageLogger.cerr.threshold = 'ERROR'
To write every 10th event, for example, add/comment out the line as below
#process.MessageLogger.cerr.threshold = 'INFO'
process.MessageLogger.cerr.FwkReport.reportEvery = 10
#process.MessageLogger.cerr.threshold = 'ERROR'
Comment 3: You can run similarly the python scripts
PatAnalyzerKitDemo_cfg.py
and
CompositeKitDemo_cfg.py
.
To re-setup an old area and run
If you've already made a package and want to start again in the same package:
cd StarterKit/CMSSW_2_2_8/src
cmsenv
cd PhysicsTools/StarterKit/test
cmsRun PatAnalyzerSkeleton_cfg.py >& skoutput.txt &
To update to a new Starter Kit CVS tag
If you've already built an older version of the Starter Kit, and would like to update to the most recent version, you can do
cmscvsroot CMSSW
# login to CVS server. Password is "98passwd"
cvs login
cd StarterKit/CMSSW_2_2_8/src
cvs update -r PhysicsTools/PatAlgos V04-14-29
cvs update -r PhysicsTools/PatUtils V03-05-02
cvs update -r DataFormats/PatCandidates V03-18-10
cvs update -r CondFormats/JetMETObjects V01-08-04
scramv1 b
Detailed description of output and running
PatAnalyzerSkeleton
The configuration file is here:
http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/PhysicsTools/StarterKit/test/PatAnalyzerSkeleton_cfg.py?view=markup
Expected output will be:
- PatAnalyzerSkeletonHistos.root : Root file containing output histograms.
- skoutput.txt: Text file containing program output
- PatAnalyzerSkeletonSkim.root: Root file containing skimmed events.
* If you run over hundreds of events you want to change the location of the output directory to a scratch area. For this you must edit the file
PatAnalyzerSkeleton_cfg.py
. To change number of events the relevant portion to change is the following. That is, change 200 events, to whatever number you want. Use -1 if you want to run over all the events.
# set the number of events
process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(200)
)
But where is the input data file hidden. Look at
# this defines the input files
from CMS.PhysicsTools.StarterKit.RecoInput_cfi import *
The file
RecoInput_cfi.py
is in ../python directory. Replace the data files there in by the following
/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/6820DE4B-BE2C-DE11-975D-000423D99658.root
/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/7CB3E361-BA2C-DE11-8D51-001617C3B710.root
/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/80069F07-B72C-DE11-BECB-000423D98E54.root
/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/E81D418B-E42C-DE11-8125-001D09F24259.root
so tha tit looks like this instead
import FWCore.ParameterSet.Config as cms
# from
def RecoInput() :
return cms.Source("PoolSource",
debugVerbosity = cms.untracked.uint32(200),
debugFlag = cms.untracked.bool(True),
fileNames = cms.untracked.vstring(
'/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/6820DE4B-BE2C-DE11-975D-000423D99658.root',
'/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/7CB3E361-BA2C-DE11-8D51-001617C3B710.root',
'/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/80069F07-B72C-DE11-BECB-000423D98E54.root',
'/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/E81D418B-E42C-DE11-8125-001D09F24259.root'
)
)
The path of the file in
RecoInput_cfi.py
iscalled Logical File Name (LFN). This is a site-independent name for a file. At cmslpc cluster this file is located at
[malik@cmslpc02 test]$ ll
/pnfs/cms/WAX/11/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/6820DE4B-BE2C-DE11-975D-000423D99658.root
To look at this file directly in ROOT use the following command (you cannot browse and look at it just by browsing to it in ROOT)
TDCacheFile *_file0 = TDCacheFile::Open("/pnfs/cms/WAX/11/store/relval/CMSSW_2_2_8/RelValZMM/GEN-SIM-RECO/STARTUP_V9_v1/0000/6820DE4B-BE2C-DE11-975D-000423D99658.root");
NOTE: The input data files may get deprecated/deleted. It is not necessary to use the data files listed in
RecoInput_cfi.py. Whatever RECO file you use must exist and readable.
To change the location of the output directory, the relevant portion is the following:
# talk to output module
process.out = cms.OutputModule("PoolOutputModule",
process.patEventSelection,
process.patEventContent,
verbose = cms.untracked.bool(False),
fileName = cms.untracked.string('PatAnalyzerSkeletonSkim.root')
)
Change this to read
# talk to output module
process.out = cms.OutputModule("PoolOutputModule",
process.patEventSelection,
process.patEventContent,
verbose = cms.untracked.bool(False),
fileName = cms.untracked.string('/my_scratch/username/PatAnalyzerSkeletonSkim.root')
)
where "/my_scratch/username/" is the name of your scratch directory. For instance, if you are using lxplus, you can use "/tmp/[username]", and at Fermilab, you can use "/uscms_data/d1/[username]" after you create those directories.
Histogram Output
The first thing you should check is the Histogram file PatAnalyzerSkeletonHistos.root. If you copy the
rootlogon.C file into your current directory, you can open root like this:
your_pc:%> root PatAnalyzerSkeletonHistos.root
The output will look something like this:
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 5.18/00a 20 February 2008 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
ROOT 5.18/00a (branches/v5-18-00-patches@22235, Apr 17 2009, 13:51:00 on linux)
CINT/ROOT C/C++ Interpreter version 5.16.29, Jan 08, 2008
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
TDR Style initialized
root [0]
Attaching file PatAnalyzerSkeletonHistos.root as _file0...
You are now in the command line for the ROOT program. If you wish, you can turn on the statistics box by doing the following:
root [1] gStyle->SetOptStat(111111);
You can specify between one and six "1's", which correspond to the name, number of entries, mean, standard deviation, underflow, and overflow bins.
You can now execute the following command:
root [2] TBrowser b;
This will bring up a browser so that you can examine your PatAnalyzerSkeletonHistos.root file. It should look like this:
Click on the "ROOT Files" directory to descend into the next level, which should look like this:
Next click on PatAnalyzerSkeletonHistos.root.
Next click on "patAnalyzerSkeleton"
Finally click on "nmuons". This plots the number of muons in the sample.
PatAnalyzerKit
If you execute the
PatAnalyzerKit
configuration file
PatAnalyzerKitDemo_cfg.py
, you'll obtain a different histogram and skim files, namely,
PatAnalyzerKitHistos.root
and
PatAnalyzerKitSkim.root
. We won't spend a lot of time on the clicking details since it is now assumed that you are familiar with them. Drill down
PatAnalyzerKitHistos.root
until you find a window that looks like this:
If you click on "muons", you see:
You'll notice that there are a great number of histograms here. This is what you get for free when using the
PatKitHelper
! These histograms are made to match the
DQMOffline
package here:
http://cmslxr.fnal.gov/lxr/source/DQMOffline/
This allows the user to trivially examine the data quality of objects in their analysis.
Skim File Output
We now turn to the file in the scratch directory that you have been ignoring until now, /my_scratch/username/PatAnalyzerSkeletonSkim.root. This file (as all CMSSW files) can be opened directly in ROOT to examine its contents. First, we make sure that we have copied the
rootlogon.C file to your home directory, and then type the following commands:
your_pc:%> root /my_scratch/username/PatAnalyzerSkeletonSkim.root
Be sure to substitute your scratch area that you wrote to before instead of "/my_scratch/username/PatAnalyzerSkeletonSkim.root".
Within ROOT, we type
root [1] TBrowser b;
You will see TBrowser window that looks like this:
If you click on "ROOT files" again and click on "/my_scratch/username/PatAnalyzerSkeletonSkim.root", you will see a window that looks like this:
Click on "Events" and you will see this:
The names follow this pattern
type_label_instance_process
This is an image of the PAT Layer 1 output that we defined in our config files earlier. If you select a leaf (say, "selectedLayer1Muons"), you see something like this:
The actual object itself is stored on the leaf ending in ".obj". If you click that, you see
Finally, if you click on "caloIso", for instance, you see a plot of the calorimeter isolation of the muons in the sample:
Command Line Analysis
At this point, we can go back to the ROOT command line and do some more interesting things. If you type
root [3] Events->SetAlias("muons", "patMuons_selectedLayer1Muons__StarterKit.obj");
root [4] Events->Scan("muons.pt()");
***********************************
* Row * Instance * muons.pt( *
***********************************
* 0 * 0 * 6.1444063 *
* 1 * 0 * 85.423522 *
* 1 * 1 * 15.493708 *
* 2 * 0 * 53.2528 *
* 2 * 1 * 41.444122 *
* 3 * 0 * *
* 4 * 0 * 23.130413 *
* 5 * 0 * 78.275489 *
* 5 * 1 * 8.9454069 *
* 6 * 0 * *
* 7 * 0 * 53.046157 *
* 7 * 1 * 42.688365 *
* 8 * 0 * 45.450954 *
* 8 * 1 * 43.736446 *
* 9 * 0 * 30.245582 *
* 9 * 1 * 26.314161 *
* 10 * 0 * *
* 11 * 0 * *
* 12 * 0 * 42.888347 *
* 13 * 0 * *
* 14 * 0 * 13.324078 *
* 15 * 0 * 44.617420 *
* 15 * 1 * 42.307502 *
* 16 * 0 * 15.144822 *
* 17 * 0 * 38.056137 *
Type <CR> to continue or q to quit ==>
This starts to scan through the objects in the "muon pt" branch. You can also start making more advanced plots in principle, but we'll just plot the muon pt of the first muon. Hit "q" to "quit" the scan over the muon pt, and type
root [5] Events->Draw("muons[0].pt()", "muons[0].pt() < 1000");
You should obtain a plot that looks like this:
Now, you can also make cuts on your ntuple as follows:
root [6] Events->Draw("muons[0].pt()", "muons[0].pt() > 30 && muons[0].pt() < 1000");
This cuts on the muon pt to be greater than 30
GeV/c. You should obtain something that looks like this:
This should give you the flavor of the types of things that can be done with the command line interface. This behaves exactly like a standard ROOT TTree after you have made these alias commands, and you should be able to do whatever you like with the TTree functionality on the command line.
We now turn to using derivatives of TSelectors, the FWLite::Event model.
Using FWLite::Event
To do any sort of "meaningfully complicated" analysis, it will be necessary to use a macro instead of a command line argument. To do so, Chris Jones and others have developed utilities to do this, which you can read about here:
https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideEDMWithRoot
The
StarterKit is (in principle) fully compatible with FWLite but at the moment we have not yet implemented a test suite for those tools. However there are easily available tools for running on the "ntuple" output of the
StarterKit which can be derived simply from the above link.
For the following example, be sure that you use the attached
rootlogon.C file. This will set up the environment. Then, you can open the file sk_fwlite.C, and edit it to point to the proper skim file (/my_scratch/username/PatAnalyzerSkeletonSkim.root).
The file is here:
http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/PhysicsTools/StarterKit/test/sk_fwlite.C?view=markup
To get this file to your directory in your cmslpc account (either cut paste in a new file) or use
wget -nc http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/CMS.PhysicsTools/StarterKit/test/sk_fwlite.C
In its entirety, it is here:
#include "DataFormats/FWLite/interface/Handle.h"
#include "DataFormats/FWLite/interface/Event.h"
#include "TFile.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TLegend.h"
#if !defined(__CINT__) && !defined(__MAKECINT__)
#include "DataFormats/PatCandidates/interface/Muon.h"
#endif
#include <iostream>
using namespace std;
void sk_fwlite()
{
TFile * file = new TFile("PatAnalyzerSkeletonSkim.root");
using namespace std;
TH1D * hist_muPt = new TH1D("hist_muPt", "Muon p_{T}", 20, 0, 100 );
fwlite::Event ev(file);
for( ev.toBegin();
! ev.atEnd();
++ev) {
fwlite::Handle<std::vector<pat::Muon> > h_mu;
h_mu .getByLabel(ev,"selectedLayer1Muons");
for ( int i = 0; i < h_mu.ptr()->size(); ++i ) {
vector<pat::Muon> const & muons = *h_mu;
hist_muPt->Fill( muons[i].pt() );
}
}
hist_muPt->Draw();
}
Then, you can type
root -l PatAnalyzerSkeletonSkim.root
root[1] .L sk_fwlite.C++
root[2] sk_fwlite();
To run our example. You should obtain a plot that looks like this:
You can extend this file to do whatever analysis you'd like.
SOME USEFUL TIPS ( though random)
Another fwlite macro showing how to plot Pt of Jet, Electrons, Taus, Photon, Track and MET is here:
sk_fwlite_JetMuonPhotonMETTrack.C
The output of root plot looks like this (enable gStyle->SetOptStat(111111) on root prompt)
OutputOf_sk_fwlite_JetMuonPhotonMETTrack_223.png
Another script to plot Muon Pt,Eta and Phi is here:
sk_fwlite_MuonPtPxPyPzEtaPhi.C
The plots of Muon Pt, Eta and Phi are here
Muon_Pt_Phi_Eta_223.png
Plots of Muon Pt computed from Px, Py and Pz (see the macro for the formula) and also Px,Py,Pz are here
Muon_PtFromPxPyPz_and-Px_Py_Pz_223.png.
Compare this Pt to Pt above. They should be identical and this is the case.
If one wants to put cuts on, for example on pT, Eta, No. of muons in an event, one can put the following kind of snippet in the python script(
PatAnalyzerSkeleton_cfg.py
or
PatAnalyzerKitDemo_cfg.py
)and have only such muons written to your skim file
# input pat sequences
process.selectedLayer1Muons.cut = cms.string('pt > 30. & abs(eta) < 2.1')
process.minLayer1Muons.minNumber =cms.uint32(5)
process.maxLayer1Muons.maxNumber =cms.uint32(5)
The default file having muon pT,eta selction cuts is at here:
http://cmslxr.fnal.gov/lxr/source/CMS.PhysicsTools/PatAlgos/python/selectionLayer1/muonSelector_cfi.py
The default files for other objects like Jets, taus, Photons are here:
http://cmslxr.fnal.gov/lxr/source/CMS.PhysicsTools/PatAlgos/python/selectionLayer1/
The plot with muon with no pT cut (i.e. pT>0
GeV) and with pT>30
GeV are below
MuonWith_pT_greater_than0GeV_223.png
MuonWith_pT_greater_than30GeV_223.png
Cosmics example with FWLite
It is possible to run cosmics data with PAT and FWLite as well. We provide an example configuration which is
cosmics_cfg_223.py. This config is different from the default file which is
here
and which you get by default when you check out the
StarterKit in CMSSW_2_2_3. The differences are that
I had removed some of the processes in patLayer0 as follows. It works and makes the root file
patcosmics.root
. Once it creates the
patcosmics.root
file, you can run the macro called sk_fwlite_cosmics to make the eta_phi plots for muons for CRUZET and CRAFT data as mentioned below.
process.patLayer0.remove(process.caloRecoTauProducer)
process.patLayer0.remove(process.caloRecoTauDiscriminationByIsolation)
process.patLayer0.remove(process.pfRecoTauDiscriminationByIsolation)
process.patLayer0.remove(process.gamIsoDepositTk)
process.patLayer0.remove(process.gamIsoDepositEcalFromClusts)
process.patLayer0.remove(process.allLayer0Photons)
NOTE from PAT experts:The default PAT config is not expected to run on the Cosmic events,
which have a completely different event content.
Either you run the LHC reconstruction sequence on them, or you'll have
to take care to remove most of the functionalities and replace all
input tags correctly (and in any case I think in the end you'll get
very little from it: PAT is not designed with that usecase)
As mentioned above, we also provide a modified FWLite macro to make a simple muon eta-vs-phi plot
here
.
It can be run as follows:
cmsRun cosmics_cfg.py
root -l
root[1] .L sk_fwlite_cosmics.C++
root[2] sk_fwlite_cosmics();
This will produce a plot that looks like this:
Here is also an eta_vs_phi plot produced using CRAFT data
For the CRAFT data you have to select the right data file and replace it in
cosmics_cfg.py
This means replace the FOLLOWING
# source
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
'/store/data/Commissioning08/Cosmics/RECO/CRUZET4_V4P_multiCosmicMuon_v1/0000/02AC0387-1181-DD11-9E5E-0018F3D096EC.root',
'/store/data/Commissioning08/Cosmics/RECO/CRUZET4_V4P_multiCosmicMuon_v1/0000/0465ED82-1181-DD11-A198-001731A28585.root',
'/store/data/Commissioning08/Cosmics/RECO/CRUZET4_V4P_multiCosmicMuon_v1/0000/04E10B9A-4A82-DD11-A57E-0018F3D096B4.root',
'/store/data/Commissioning08/Cosmics/RECO/CRUZET4_V4P_multiCosmicMuon_v1/0000/08F1A76D-7281-DD11-A542-001A92971BC8.root',
'/store/data/Commissioning08/Cosmics/RECO/CRUZET4_V4P_multiCosmicMuon_v1/0000/0E739F9A-1181-DD11-A433-001A928116C6.root',
.........
.........
.........
)
)
WITH
# source
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
'/store/data/Commissioning08/Cosmics/RECO/CRAFT_ALL_V4_ReReco-v1/0000/60FD96C9-64C1-DD11-9539-001D0967D1DE.root'
)
)
To add more data files, first look at the directories below. Pick ONLY the ones with size in G like 2.0G and NOT empty files
/pnfs/cms/WAX/11/store/data/Commissioning08/Cosmics/RECO/CRAFT_ALL_V4_ReReco-v1/0000/
/pnfs/cms/WAX/11/store/data/Commissioning08/Cosmics/RECO/CRAFT_ALL_V4_ReReco-v1/0001/
/pnfs/cms/WAX/11/store/data/Commissioning08/Cosmics/RECO/CRAFT_ALL_V4_ReReco-v1/0002/
/pnfs/cms/WAX/11/store/data/Commissioning08/Cosmics/RECO/CRAFT_ALL_V4_ReReco-v1/0003/
..........
..........
..........
CompositeKitDemo
Now we examine the output of the
CompositeKitDemo
. To run it, do
cmsRun CompositeKitDemo_cfg.py
If you open the root file
CompositeKitHistos.root
, open a
TBrowser
and drill down, you'll see a screen that looks like this:
You'll notice that in addition to the physics object directories, there is a directory called "hToZZ". Clicking on this yields
If you click on "hToZZMass_1" you get
This is the invariant mass of all the candidates in question.
You can also look at the invariant masses of the constituents, for instance you can click on the folder called "Z1" to see:
Clicking on the mass, you see
Now you can click on the constituents of the Z's, for instance "muon1" to see:
You have access to all the histograms for all the constituents. This is helpful in making sideband subtraction plots, for instance, since you can plot the histogram for the objects under the Z peak, and those outside.
For instance, clicking on "muon1Pt_1", you obtain
Common Errors
Here we discuss some common errors from users.
scram project errors
If you see something like
Can't locate XML/Parser/Expat.pm in @INC (@INC contains: /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2 /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2 /uscmst1/prod/sw/cms/slc4_ia32_gcc345/external/p5-libwww-perl/1.41-CMS19/lib/site_perl/5.8.5 /uscmst1/prod/sw/cms/slc4_ia32_gcc345/external/p5-xml-parser/2.34-CMS19/lib/site_perl/5.8.5 /uscmst1/prod/sw/cms/slc4_ia32_gcc345/external/p5-uri/1.35-CMS19/lib/site_perl/5.8.5 /uscmst1/prod/sw/cms/slc4_ia32_gcc345/external/p5-template-toolkit/2.15-CMS19/lib/site_perl/5.8.5 /uscmst1/prod/sw/cms/slc4_ia32_gcc345/external/p5-template-toolkit/2.15-CMS3/lib/site_perl/5.8.5 /opt/gLite/lcg/lib/perl /opt/gLite/external/usr/lib/perl5/vendor_perl/5.8.5 /opt/rocks/lib/perl5/5.8.8/x86_64-linux /opt/rocks/lib/perl5/5.8.8 /opt/rocks/lib/perl5/site_perl/5.8.8/x86_64-linux /opt/rocks/lib/perl5/site_perl/5.8.8 /opt/rocks/lib/perl5/site_perl .) at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/ActiveDoc/SimpleXMLDoc.pm line 33.
BEGIN failed--compilation aborted at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/ActiveDoc/SimpleXMLDoc.pm line 33.
Compilation failed in require at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/BuildSystem/XMLBuildFile.pm line 17.
BEGIN failed--compilation aborted at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/BuildSystem/XMLBuildFile.pm line 17.
Compilation failed in require at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/BuildSystem/BuildDataStorage.pm line 195.
BEGIN failed--compilation aborted at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/BuildSystem/BuildDataStorage.pm line 195.
Compilation failed in require at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/SCRAM/CMD.pm line 1005.
BEGIN failed--compilation aborted at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/SCRAM/CMD.pm line 1005.
Compilation failed in require at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/SCRAM/SCRAM.pm line 40.
BEGIN failed--compilation aborted at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/src/SCRAM/SCRAM.pm line 40.
Compilation failed in require at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/bin/scramv1 line 444.
BEGIN failed--compilation aborted at /uscmst1/prod/sw/cms/slc4_ia32_gcc345/lcg/SCRAMV1/V1_0_3-p2/bin/scramv1 line 444.
Thanks to Patrick Gartung and Catalin Dumitrescu, we have a solution for this.
Ensure that the following lines are
not in your .cshrc file:
if ( -f "/afs/fnal.gov/ups/etc/setups.csh" ) then
source "/afs/fnal.gov/ups/etc/setups.csh"
endif
if ( { ups exist shrc } ) then
setup shrc
endif
Feedback
We have developed a questionnaire for you to fill out to help us help you! Please copy and paste the following into an email to the authors above when you are finished with the Requests, and give us your feedback. This is text-only, so be patient with us!
These are exclusive categories, so please select the one that most describes you:
1) How familiar are you with C++
[ ] a) I could code a std::map<std::string,std::vector<int> > and have no problem.
[ ] b) I know what public inheritance means but I can't figure out what you're talking
about in (a).
[ ] c) I'm still mad we went away from F77.
2) How familiar are you with ROOT?
[ ] a) I've successfully added my own classes to ROOT.
[ ] b) I can book my own histograms and plot them without trouble.
[ ] c) I still use PAW.
3) Have you performed CMSSW analyses before?
[ ] a) Yes, and I probably could actually have written this better than you.
[ ] b) Yes, but not at the expert level.
[ ] c) Are you kidding? You're supposed to be doing this for me!
4) Have you used FWLite?
[ ] a) Yes, I've used it and I love it!
[ ] b) Yes, I've used it but it needs some work.
[ ] c) No.
5) How long did it take you to get from cvs checkout procedure to a plot?
[ ] a) Less than an hour.
[ ] b) Between an hour and a day.
[ ] c) More than a day.
6) What analysis are you planning on doing in CMS?
Comment:
7) Did you like this type of framework?
[ ] a) This will be great when you get it working. Suggestions below.
[ ] b) This is too complicated, make it simpler. Suggestions below.
[ ] c) I thought it was awful and didn't accomplish any of the goals I needed it to do.
Suggestions below.
Suggestions:
8) Any further comments or questions:
Comment:
#CMS.ToDoList
Starter Kit To-Do List
As you can see, we have a fairly functional Starter Kit to start you off with. The last pieces are coming together in the coming weeks. They include
- Generic histogramming utilities. These will include the following capabilities:
- Config file booking of simple and more complex variables (pt(jet1) / pt(jet2), for instance).
- More user control over histogram binning and axis limits.
- "Before and after" plots given some cuts.
- Automated nightly validation scripts for monitoring purposes.
Review status
Responsible:
Salvatore Rappoccio and
Sudhir Malik
Last reviewed by:
Sudhir Malik- 5 November 2008.