Using EDProducers for Analysis

Complete: 3


EDProducer modules can create new data and store it in the Event for the final analysis. This can be useful in analysis for different reasons:

  • you want to (re-)run an existing algorithm (EDProducer) and store the result in a new output file
    • e.g.: you want to run a Jet clustering algoritm with non-default parameters
  • you want to run your own algorithm, and store one of the data types supported in CMSSW
    • e.g.: you want to run your new algorithm to compute missing Et and store it in the event
  • you want to select (and clone) only a subset of an existing collection
    • e.g.: select only tracks passing some quality criteria, or muon that are with low probability puhch through
  • you want to save summary information of your computation in order to save CPU time in further step processing
    • e.g.: you want to save your definition of isolation associated to leptons

Writing an EDProducer to Store New Products in the Event

The following example reads a file containing events in the RECO formats, and stores track innermost and outermost points (available in RECO, not in AOD) together with the reco::Track collection (available in the AOD) for interactive analysis.

Track innermost and outermost points are stored as vectors of points.

You should follow the general guidelines on writing and EDProducer. The basic points are:

  • make your class inherit from edm::EDProducer;
  • define a constructor that takes a edm::ParameterSet argument;
  • define the following methods (if not empty) that are called at the begin of the job, for evey event, and end of job respectively:
  void beginJob( const edm::EventSetup & );
  void produce( edm::Event& , const edm::EventSetup& );
  void endJob();

If you have information that you need to share among these three methods, you should declare them as data members of the EDProducer. This is the case, for instance, for the labels of collections you use for input. You need to:

  • declare the products you will produce at the begin of the job;
  • create the actual products for every Event and put them in the Event;

Declaring Output Products

For instance, if you want to store a collection of points, you have to call in the module's contructor:

  typedef math::XYZPointD Point;
  typedef std::vector<Point> PointCollection;

If you have more products of the same type you have to disentalgle the ambiguity of having the same module label adding a secondary label, called instance name. You can also specify your branch alias:

  produces<PointCollection>( "vertex" ).setBranchAlias( "vertexPoints" );
  produces<PointCollection>( "outer" ).setBranchAlias( "outerPoints" );

Creating and Storing Output Products

In the module's method produce(...) you have to create products first:

  auto_ptr<PointCollection> vertexPoints( new PointCollection );
  auto_ptr<PointCollection> outerPoints( new PointCollection );

Then you have to fill them:

  for( TrackCollection::const_iterator track = tracks->begin(); 
    track != tracks->end(); ++ track ) {
    vertexPoints->push_back( track->vertex() );
    outerPoints->push_back( track->outerPosition() );

Then, eventually, put them in the event (you may need to specify the instance name if it is the case):

  evt.put( vertexPoints, "vertex" );
  evt.put( outerPoints, "outer" );

The complete example can be found in the following module:

Saving a Subsample of the AOD plus the User Data

  module trackPoints = TrackPointsProducer {
    InputTag src = ctfWithMaterialTracks

  module MicroAOD = PoolOutputModule { 
    untracked string fileName = "ntp.root" 
    untracked vstring outputCommands = {
      "drop *",
      "keep recoTracks_ctfWithMaterialTracks_*_*",
      "keep *_trackPoints_*_*"

The complete .cfg can be found below:

Interactive Plots with AOD and User Data

The stored quantities can be plotted. Below an example of a scatter plot of Δφ (outermost point - innermost point) vs the track pt:

  TH2F deltaPhiVsPt( "deltaPhiVsPt", "#Delta #phi vs pt", 70, 0, 20, 40, -1.5, 1.5 );
  Events.Project( "deltaPhiVsPt", 
                  "fabs(outer.eta())<1" );
  deltaPhiVsPt.Draw( "box" );

The complete ROOT macro can be found below:

More details can be found in the following EDM document:

Selecting the Appropriate Object Container

An object produced within a CMSSW application must be stored according to the Event Data Model (EDM) and inserted into the Event. Most of the simplest objects can be stored just as:


Where T is the object type.

In cases where more advanced features are required, more specialized containers are appropriate. Some common generic containers have been developed for the most common of these cases. The class templates are defined under CMSSW in the package:

The main generic containers are documented in the page linked below.

Create new Product Types

If you want to create new product types and place them in the event, you need to define a REFLEX dictionay that allows ROOT to store the objects to files.

More details can be found in the following EDM document:

Combinatorial Analysis Producers

Combinatorial analysis, for instance to reconstruct Z→μ+μ-, can be done without need of rewriting the combinatorial algorithm using Particle Candidates. More details are described in the following section of the Workbook:

Selecting a Subset of a Collection

It is possible to select only a subset of a collection. For instance, selecting all tracks with pt greater than 5 GeV/c can be done with the following configuration:

  module goodTracks = PtMinTrackSelector {
    InputTag src = ctfWithMaterialTracks
    double ptMin = 5.0
    bool filter = false

The boolean flag filter, if set to true, enables the module to work as EDFilter rather than just EDProducer.

Predefined configurable selectors are available for some of the simplest and most commonly used selection conditions in the directory:

A generic selector toolkit allows to define easily selector module that select:

  • objects passing simple selections based on a combination of cuts on some of the object variables
  • object pairs whose combination passes a specified set of cuts

The specific cuts are configurable parameters. More details on generic filter modules can be found in the following Workbook section:

Review Status

Reviewer/Editor and Date (copy from screen) Comments
LucaLista - 02 Feb 2007 page author
JennyWilliams - 05 Feb 2007 editing to include in SWGuide

Responsible: LucaLista
Last reviewed by: Reviewer

Edit | Attach | Watch | Print version | History: r14 < r13 < r12 < r11 < r10 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r14 - 2008-11-22 - SudhirMalik

    • 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-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback