SLAC PEP-II
BABAR
SLAC<->RAL
Babar logo
HEPIC E,S & H Databases PDG HEP preprints
Organization Detector Computing Physics Documentation
Personnel Glossary Sitemap Search Hypernews
Workbook Home Introduction Account Setup QuickTour Packages Modules Unwrap page!
Event Information Tcl Commands Editing Compile and Link Run the Job Debugging
Check this page with the
W3C Validator
(More checks...)
Parameters Tcl Files Find Data Batch Analysis ROOT Tutorial

Modified QExample for Example 2


Header file: QExample.hh



//--------------------------------------------------------------------------
// QExample: Example analysis module for the Offline Workbook
// Modified to add a momentum histogram.
// The workbook can be found on the web at:
//   /BFROOT/www/doc/workbook/workbook.html
//------------------------------------------------------------------------

#ifndef QEXAMPLE_HH
#define QEXAMPLE_HH

#include "Framework/AppModule.hh"
#include "AbsEvent/AbsEvent.hh"
#include "HepTuple/Histogram.h"

class QExample : public AppModule {

public:

  // Constructors
  QExample( const char* const theName, const char* const theDescription );

  // Destructor
  virtual ~QExample( );

  // Operations

  virtual AppResult  beginJob( AbsEvent* anEvent );
  virtual AppResult  event( AbsEvent* anEvent );
  virtual AppResult  endJob  ( AbsEvent* anEvent );
    
protected:
  
private:

  HepHistogram* _numTrkHisto;
  HepHistogram* _pHisto;
};

#endif

Implementation file: QExample.cc



//--------------------------------------------------------------------------
// QExample: Example analysis module for the Offline Workbook.
// Modified to add a momentum histogram.
// The workbook can be found on the web at:
//   /BFROOT/www/doc/workbook/workbook.html
//------------------------------------------------------------------------

#include "BaBar/BaBar.hh"

#include "BetaMiniUser/QExample.hh"

#include "AbsEnv/AbsEnv.hh"
#include "Beta/BtaCandidate.hh"
#include "GenEnv/GenEnv.hh"
#include "HepTuple/TupleManager.h"
#include "CLHEP/Alist/AIterator.h"

//----------------
// Constructors --
//----------------

// in general, a module constructor should not do much.  The beginJob
// function is a better place to put initialization

QExample::QExample( const char* const theName, 
		  const char* const theDescription )
  : AppModule( theName, theDescription )
{
}

//--------------
// Destructor --
//--------------

// The destructor should be limited to undoing the work of the constructor

QExample::~QExample( )
{
}


//--------------
// Operations --
//--------------

// The beginJob member function is run before any events are
// processed.  In this example code, it opens the output histogram file
// and then books a histogram.

AppResult
QExample::beginJob( AbsEvent* anEvent )
{
      
  HepTupleManager* manager = gblEnv->getGen()->ntupleManager();

  // book the number-of-tracks histogram
  _numTrkHisto = manager->histogram("Tracks per Event",  20, 0., 20. ); 
  _pHisto = manager->histogram("Momentum",  25, 0., 1. ); 

  return AppResult::OK;
}

// The endJob function is called after all events have been processed.

AppResult
QExample::endJob( AbsEvent* anEvent ) 
{
  return AppResult::OK;
}

// event function is called once per event


AppResult
QExample::event( AbsEvent* anEvent )
  {  

  // get list of input track candidates
  HepAList<BtaCandidate>* trkList  =
    Ifd<HepAList< BtaCandidate > >::get(anEvent, "ChargedTracks");
  
  //histogram number of tracks in event
  _numTrkHisto->accumulate( trkList->length() );

  // Loop over track candidates to plot momentum 
   HepAListIterator>BtaCandidate> iterTrk(*trkList);
   BtaCandidate* trk(0);
   while ( trk = iterTrk()) {
    _pHisto->accumulate( trk->p() );
   }
  
  // done
  return AppResult::OK;
}