//-------------------------------------------------------------------------- // ParmExample: Example analysis module for the Offline Workbook. // A module with 4 run-time parameters. // The workbook can be found on the web at: // http://www.slac.stanford.edu/BFROOT/www/doc/workbook/workbook.html //------------------------------------------------------------------------ #include "BaBar/BaBar.hh" #include "BetaMiniUser/ParmExample.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 ParmExample::ParmExample( const char* const theName, const char* const theDescription ) : AppModule( theName, theDescription ), _nbins("nbins",this,25), _pMin("pMin",this, 0.), _pMax("pMax",this, 1.0), _trackList("trackList", this, "ChargedTracks") { commands()->append( & _nbins ); commands()->append( & _pMin ); commands()->append( & _pMax ); commands()->append( & _trackList ); } //-------------- // Destructor -- //-------------- // The destructor should be limited to undoing the work of the constructor ParmExample::~ParmExample( ) { } //-------------- // 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 ParmExample::beginJob( AbsEvent* anEvent ) { HepTupleManager* manager = gblEnv->getGen()->ntupleManager(); // book the number-of-tracks histogram _numTrkHisto = manager->histogram("nTrack", 20, 0., 20. ); _pHisto = manager->histogram("pTrack", _nbins.value() , _pMin.value(), _pMax.value() ); return AppResult::OK; } // The endJob function is called after all events have been processed. AppResult ParmExample::endJob( AbsEvent* anEvent ) { return AppResult::OK; } // event function is called once per event AppResult ParmExample::event( AbsEvent* anEvent ) { // get list of input track candidates HepAList* trkList = Ifd >::get(anEvent, _trackList.value()); //histogram number of tracks in event _numTrkHisto->accumulate( trkList->length() ); // Loop over track candidates to plot momentum HepAListIterator iterTrk(*trkList); BtaCandidate* trk(0); while ( trk = iterTrk()) { _pHisto->accumulate( trk->p() ); } // done return AppResult::OK; }