3.5.1 Getting Started with FWLite

Complete: 5


Detailed Review status The goals of this page:

In this section you will learn:

  • what FWLite is.
  • how to download it if you want to install it as a stand-alone package on your personal computer (laptop or desktop).
  • how to set up the ROOT environment (by adding commands to rootlogon.C).
  • how to explore CMS data interactively -- analogous to TTree::Draw().

FWLite can be downloaded with apt-get using instructions from this link. You can also jump directly to instructions how to write ROOT macros that analyze CMS data directly -- analogous to the result of TTree::MakeClass() -- in WorkBookFWLiteEventLoop or to examples in WorkBookFWLiteExamples. What is FWLite

FWLite is plain ROOT that is capable to read CMS DataFormats together with some helper classes. You can use FWLite to analyse the data. CMS uses ROOT to make data objects persistent. CMS data formats are thus "ROOT-aware"; that is, once the shared libraries containing the ROOT-friendly description of CMS data formats are loaded into a ROOT session, these objects can be accessed and used directly from within ROOT like any other ROOT class!

FWLite (pronounced "framework-light") is just that -- a ROOT session with CMS data format libraries loaded. In addition, CMS provides a couple of classes that greatly simplify the access to the collections of CMS data objects. Moreover, these classes (Event and Handle) have the same name as analogous ones in the Full Framework; this mnemonic trick helps in making the code to access CMS collections very similar between the FWLite and the Full Framework (CMSSW). To learn about ROOT have a look to WorkBookBasicROOT or to the ROOT homepage. How to downloading FWLite for your laptop

So now you are curious and would like to try FWLite. You want to analyse your data file -- say, a file with skimmed PAT-tuples that your group has produced -- and you may be in one of these two situations:

  1. You are on a Scientific Linux system with CMSSW installed.
  2. You are on some other machine, your own desktop or even more likely your own laptop.

Read the subsection below which applies to your case.

FWLite on a machine with CMSSW installed

If you are using a machine with CMSSW installed (currently available on either Scientific Linux 4 or Scientific Linux 5), then you don't have to do anything! FWLite is a part of the full framework (CMSSW).

Installing CMSSW Full Framework

If you wish to install the CMSSW full framework, you can follow the link here to install via apt-get.

FWLite on other flavors of Linux, Windows, and Mac

The final stage of the analysis is usually very interactive, does not require access to conditions, and is based on skimmed, stripped (and possibly thinned) data samples. The size of such sample is usually small enough to be copied to your desktop or laptop. Analysis in ROOT is particularly suitable for laptops, and could proceed without a network connection. The traditional way of exploring the data interactively is to make a TTree in the Full Framework, copy the ROOT file with it to one's laptop, install ROOT, and run. Since we want to enhance ROOT with CMS data format libraries, we need to install the CMS version of ROOT (which is safer anyway as CMS patches ROOT when required) and also install the libraries with the CMS data format and with the helper classes.

Most laptops run either Windows, or Mac OS, or one of the modern flavors of Linux (e.g. Ubuntu). The pages below dedicated to installations on each of these systems:

You are encouraged to try them out and give feedback to the Software Development Tools group by sending email to the sw-developmenttool HN. How to setup your environment

(Note: this is a copy of WorkBookSetComputerNode#RooT, but with additional libraries loaded in rootlogon.C file.)

Before running ROOT on your data file, set up ROOT in order to load all the necessary CMS-specific libraries by default, by creating a file $HOME/rootlogon.C file with the following commands:

  // Set up FW Lite for automatic loading of CMS libraries
  // and data formats.   As you may have other user-defined setup
  // in your rootlogon.C, the CMS setup is executed only if the CMS
  // environment is set up.
  TString cmsswbase = getenv("CMSSW_BASE");
  if (cmsswbase.Length() > 0) {
    // The CMSSW environment is defined (this is true even for FW Lite)
    // so set up the rest.
    cout << "Loading FW Lite setup." << endl;

Then edit your .rootrc file (this file can be in your home directory or in the current working directory, the latter taking the precedence - if it does not exist yet, you can create it) to point to rootlogon.C; e.g., add the line:

#  Tell ROOT where to find rootlogon.C: 
Rint.Logon: $(HOME)/rootlogon.C

Finally, you can start ROOT

$ root -l              #the -l, lower case L, is optional, and if used, omits the logo

and you are ready to play!

Additional information for Mac OS X Users

There are a few additional steps that are useful for Mac OS X users that are outlined in the README.txt of the FWLite tarballs, emphasized here. Instead of the usual CMSSW setup, please use (assuming you downloaded CMSSW_4_1_3_FWLITE and moved that folder under /Applications/FWLite ):

for csh:

setenv SCRAM_ARCH osx106_amd64_gcc421
setenv VO_CMS_SW_DIR /Applications/FWLite/CMSSW_4_1_3_FWLITE/
source $VO_CMS_SW_DIR/fwlite_setup.csh

for bash:

export SCRAM_ARCH=osx106_amd64_gcc421
export VO_CMS_SW_DIR=/Applications/FWLite/CMSSW_4_1_3_FWLITE/
source $VO_CMS_SW_DIR/fwlite_setup.sh

This will allow you to use FWLite effectively on the Mac. You can then do as normal:

cd $VO_CMS_SW_DIR/work/CMSSW_4_1_3_FWLITE/src/

or make a new project area as you prefer.

There are a few tricks you may have to do (depending on your Mac OS X version) to get python working correctly. These must be set again after each "cmsenv" command. These are the known fixes if you have python problems:

setenv PYTHONDIR /Applications/FWLite/CMSSW_3_5_6_FWLITE/osx105_ia32_gcc401/external/python/2.6.4-cms
setenv PYTHONHOME /Applications/FWLite/CMSSW_3_5_6_FWLITE/osx105_ia32_gcc401/external/python/2.6.4
setenv PYTHONPATH $ROOTSYS/lib:$PYTHONPATH Your first plot in FWLite

From the ROOT prompt, open the MYCOPY.root file that you made in WorkBookDataSamples. It contains a collection of RECO objects. Opening the file may take some time.

root[0] TFile f("MYCOPY.root");
Look at the ROOT TBrowser to see which collections are in the file.
root[1] new TBrowser;

Double-click on ROOT Files, then MYCOPY.root, then Events (the event tree). Drill down through recoTracks_generalTracks__RECO to recoTracks_generalTracks__RECO.obj.


What you see here are the methods of the stored recoTracks. Since covariance() returns a class, the icon shows a folder.

While you still have the ROOT browser displayed, go back to your ROOT session and set an alias for each of the branches you want to access (we'll choose recoTracks and recoTrackExtras). Use the branch name that's visible in the TBrowser, and add obj at the end, as follows:

root [8] Events->SetAlias("tracks","recoTracks_generalTracks__RECO.obj");        
root [9] Events->SetAlias("trackExtras","recoTrackExtras_generalTracks__RECO.obj");

Note: SetAlias commands work only if the ROOT browser is still up.

You can look at the examples contained in the file PhysicsTools/RecoExamples/test/trackPlots.C, and see how some of the examples work. Note that name of objects in trackPlots.C could be different. But gives you sense how to Draw etc.

// plot chi-squared divided by n. degrees of freedom
root [10] Events->Draw("tracks.normalizedChi2()", "tracks.chi2()<1000")        

(This image is shown for all the 20 events, each containing several tracks, from the full MYCOPY.root file.)

Now if you run this same "Events.Draw(...)" command in Bare ROOT (after setting the alias), you'll get the message
Part of the Variable "tracks.chi2()" exists but some of it is not accessible or useable.

Now run:

root[5] Events.Draw("trackExtras.recHitsSize()");

Of course, this approach does not scale when you want to simultaneously make more than a couple of histograms, and, especially, if you need to compute anything non-trivial. Eventually, you'll need to have a ROOT macro, which will do all the work. This is covered in section 3.5.2 Event Loop in FWLite.

Review status

Reviewer/Editor and Date (copy from screen) Comments
ElizaMelo - 16 Dec 2018 review & update the input file and rootlogon.C
AntonioMorelosPineda - 13 May 2013 review & update a link
RogerWolf - 22 Mar 2011 Update to CMSSW_4_1_3

Responsible: RogerWolf
Last reviewed by: AntonioMorelosPineda - 15 May 2013

Topic attachments
I Attachment History Action Size Date Who Comment
GIFgif recoTracks_fwlite.gif r1 manage 14.2 K 2009-06-21 - 05:37 PetarMaksimovic  
PNGpng recoTracks_generalTracks_fwlite.png r1 manage 59.8 K 2010-01-29 - 02:13 SudhirMalik  
PNGpng trackExtras_generalTracks_recHitSize.png r1 manage 20.2 K 2010-01-29 - 02:27 SudhirMalik  
GIFgif trackExtras_recHitSize.gif r1 manage 6.6 K 2009-06-21 - 05:36 PetarMaksimovic  
PNGpng tracks_generaltracks_norm_chi2.png r1 manage 21.0 K 2010-01-29 - 02:27 SudhirMalik  
GIFgif tracks_norm_chi2.gif r1 manage 7.5 K 2009-06-21 - 05:36 PetarMaksimovic  
Cascading Style Sheet filecss tutorial.css r1 manage 0.2 K 2011-03-22 - 16:15 RogerWolf  
Edit | Attach | Watch | Print version | History: r37 < r36 < r35 < r34 < r33 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r37 - 2018-12-16 - ElizaMelo



    • 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