3.5.3 Examples of FW Lite Macros

Complete: 2
Detailed Review status

Goals of this page:

In this page you will find working examples of FW Lite macros that can be used as starting points for your own analysis.

To use this tutorial you must use the release described here. We also need to create a PAT-tuple (described in detail in WorkBookPAT):

cvs co PhysicsTools/PatAlgos/test/patLayer1_fromAOD_full_cfg.py
scram b
cmsRun PhysicsTools/PatAlgos/test/patLayer1_fromAOD_full_cfg.py

From there, we will have a file "PATLayer1_Output.fromAOD_full.root" to run over.

The tutorials that follow are contained in PhysicsTools/PatExamples so we will now check out this module.

addpkg PhysicsTools/PatExamples V00-02-04
scram b


Example 1: the Bare Bones -- Plot PAT objects

The first example of plotting using FWLite will be to plot PAT objects. The source for this can be found here. To run this example, type:


(the "rehash" need only be done once after compilation of a new release).

Example 2: Using python configuration

The next example will be to use a python configuration to input parameters to our FWLite macro. The source for this can be found here. This is identical to the previous example, except that it now uses the python interpreter to input parameters to the FWLite macro:

// Get the python configuration
  PythonProcessDesc builder(argv[1]);
  edm::ParameterSet const& fwliteParameters = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("FWLiteParams");

  // Now get each parameter
  edm::InputTag muonLabel( fwliteParameters.getParameter<edm::InputTag>("muonSrc") );

The file now takes an additional input argument on the command line, which is the location of the python configuration

PatBasicFWLiteAnalyzer_PyConfig PhysicsTools/PatExamples/bin/patBasicFWLiteAnalyzer_PyConfig_fwlite.py

This python configuration is, for the moment, extremely simple for demonstration and can be found here.

Example 3: Using Selectors

This example will show some more advanced features of the framework. Here we will be using an EventSelector to make the selection, rather than doing it in the "main loop". This will allow us to keep track of statistics of the event selection.

More details about Selectors can be found in SWGuidePATSelectors.

This particular example will create a "simple" W selector that will select events with muons with pt above 20 GeV/c, and MET above 20 GeV/c. The source is found here. To run this, type

PatBasicFWLiteAnalyzer_Selector PhysicsTools/PatExamples/bin/patBasicFWLiteAnalyzer_Selector_fwlite.py

The new configuration is slightly more complicated than before and can be found here.

At the end of the job should be a snippet like this:

     0 :              Muon Pt         22
     1 :                  MET         86

These correspond to the number of events that pass the muon pt, and MET cuts, respectively. This can be made as complicated as one desires and automatically keeps track of cut flows.

Example 4: Accessing Conditions Database

Coming soon!

Example 5: Access to Runs, LuminosityBlocks, and their products

This macro is a demonstration of the various ways to get at luminosity block and run information.

#if !defined(__CINT__) && !defined(__MAKECINT__)
#include "DataFormats/FWLite/interface/Handle.h"
#include "DataFormats/FWLite/interface/Event.h"

#include "DataFormats/FWLite/interface/LuminosityBlock.h"
#include "DataFormats/FWLite/interface/Run.h"
#include "DataFormats/Luminosity/interface/LumiSummary.h"

#include "TFile.h"

void print_data() {
   TFile file("SomeData.root");

   fwlite::Event ev(&file);
   fwlite::Handle<LumiSummary> summary;

   // We can get run and luminosity blocks from events as well as associated products
   // All this works for ChainEvent and MultiChainEvent as well, not just on one  
   for(ev.toBegin(); !ev.atEnd(); ++ev) {
      // We can get the Luminosity block ID from the event
      std::cout << " Luminosity ID " << ev.getLuminosityBlock().id() << std::endl;
      // or the Run ID from the event
      std::cout <<" Run ID " << ev.getRun().id()<< std::endl;
      // We can get the Run ID from the luminosity block we got from the event
      std::cout << "Run via lumi " << ev.getLuminosityBlock().getRun().id() << std::endl;
      // We can get the integrated luminosity (or any luminosity product) from the event
      std::cout << " Inst.  Luminosity = " << summary->avgInsDelLumi()<<std::endl;

   // We can also loop over luminosity blocks themselves, same as events
   fwlite::LuminosityBlock ls(&file);
   for(ls.toBegin(); !ls.atEnd(); ++ls) {
      std::cout  << ls.id() << " Inst.  Luminosity = " << summary->avgInsDelLumi() << std::endl;
      // And get the associated run from this lumi
      std::cout << "Run from lumi " << ls.getRun().id() << std::endl;

   // And of course do the same for runs.
   fwlite::Run r(&file);
   for(r.toBegin(); !r.atEnd(); ++r) {
      std::cout << "Run " << r.id() <<std::endl;

Review status

Reviewer/Editor and Date (copy from screen) Comments
YourName - 14 Mar 2006 What you did (e.g., created page, reviewed, edited, added/answered questions or comments, etc.) and/or what you think needs to be done next (e.g., "needs review by ...", "still needs content on subject x", etc.)

Responsible: SalvatoreRoccoRappoccio
Last reviewed by: BenediktHegner - 21 Jun 2009

-- SalvatoreRoccoRappoccio - 08-Mar-2010

Edit | Attach | Watch | Print version | History: r6 | r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r2 - 2010-03-08 - SalvatoreRRappoccio
    • 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-2021 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