Analysis with EDAnalyzer Framework Modules

Complete: 3

Introduction

EDAnalyzer modules allow a read-only access to the Event. EDAnalyzers are useful to produce histograms, reports, statistics, etc.

Writing an EDAnalyzer to access RECO/AOD Data

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

  • make your class inherit from edm::EDAnalyzer;
  • 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 analyze( const 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 EDAnalyzer. This is the case, for instance, for histograms. You may want to:

  • book histograms at the begin of the job;
  • fill the histograms for every event;
  • plot/save the histograms at the end of the job.

You can have a look at a quick-start introduction on how to write and run an EDAnalyzer module.

An example of declaration of a analyzer that fill histograms is the following:

class TrackPlotsExample : public edm::EDAnalyzer {
public:
  TrackPlotsExample( const edm::ParameterSet & );

private:
  void beginJob( const edm::EventSetup & );
  void analyze( const edm::Event & event, const edm::EventSetup & );
  void endJob();
  edm::InputTag src_;
  TFile * outputFile_;
  TH1F * h_pt, * h_eta, * h_phi;
};

The data member src_, declared as edm::InputTag, is used to make the input collection configurable, as you can see below.

In the implementation of the method analyze(...) you need to access RECO/AOD data from the Event. How this is done in general in the EDM is described in a general introduction on accessing data from Event.

In order to access a track collection, we will use the following:

  Handle<TrackCollection> tracks;
  event.getByLabel( src_, tracks );

An example of implementation of the analyzer is the following:

TrackPlotsExample::TrackPlotsExample( const ParameterSet & cfg ) :
  src_( cfg.getParameter<edm::InputTag>( "src" ) ) {
}

void TrackPlotsExample::beginJob( const EventSetup & ) {
  outputFile_ = new TFile( "histo.root", "RECREATE" );  
  h_pt  = new TH1F( "pt", "p_{t}", 50, 0, 20 );
  h_eta = new TH1F( "eta", "#eta", 50, -3, 3 );
  h_phi = new TH1F( "phi", "#phi", 50, -M_PI, M_PI );
}

void TrackPlotsExample::analyze( const Event& event, const EventSetup& es ) {
  Handle<TrackCollection> tracks;
  event.getByLabel( src_, tracks );

  for( TrackCollection::const_iterator track = tracks->begin(); 
       track != tracks->end(); ++ track ) {
    h_pt->Fill( track->pt() );
    h_eta->Fill( track->eta() );
    h_phi->Fill( track->phi() );
  }
}

void TrackPlotsExample::endJob() {
  cout << ">> saving histograms" << endl;
  outputFile_->Write();
  outputFile_->Close();
}

The complete code is available in the following module:

Running the EDAnalyzer in a Batch Application

The EDAnalyzer has only one parameter, specifying the track collection source. It can be configured as follows:

  module plots = TrackPlotsExample {
    InputTag src = ctfWithMaterialTracks
  }

The full configuration file is available below:

A more Complex Example

A more complex example of analyzer module accessing a larger variety of RECO objects can be found in the module below:

That can be ran using the configuration script below:

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: r15 < r14 < r13 < r12 < r11 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r15 - 2007-02-07 - JennyWilliams



 
    • 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