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
Step 4: Fill histograms and ntuple                               Go to Step 5

Header file: MyNeuAnalysis.hh


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

class MyNeuAnalysis : public AppModule {


  // Constructors
  MyNeuAnalysis( const char* const theName, const char* const theDescription );
  // Destructor
  virtual ~MyNeuAnalysis( );

  // Operations

  virtual AppResult  beginJob( AbsEvent* anEvent );
  virtual AppResult  event( AbsEvent* anEvent );
  virtual AppResult  endJob  ( AbsEvent* anEvent );



HepHistogram *_hpneu;
HepHistogram *_hthetaneu;

HepTuple *_ntuple;



Implementation file:

#include "AbsEnv/AbsEnv.hh"
#include "GenEnv/GenEnv.hh"
#include "BaBar/BaBar.hh"
#include "BetaMiniUser/MyNeuAnalysis.hh"
#include "HepTuple/TupleManager.h"
#include "Beta/BtaCandidate.hh"
#include "CLHEP/Alist/AList.h"
#include "ProxyDict/Ifd.hh"
#include "CLHEP/Alist/AIterator.h"

// Constructors

MyNeuAnalysis::MyNeuAnalysis( const char* const theName,
                  const char* const theDescription )
  : AppModule( theName, theDescription )

// Destructor
MyNeuAnalysis::~MyNeuAnalysis( )

// Operations

AppResult MyNeuAnalysis::beginJob( AbsEvent* anEvent )

  HepTupleManager* manager = gblEnv->getGen()->ntupleManager();

  // book the histograms
  _hpneu = manager->histogram("Cluster momentum",  25, 0., 1.0 );
  _hthetaneu = manager->histogram("Cluster polar angle", 25, 0., 1.571);

  _ntuple = manager->ntuple("MyNtuple");

  return AppResult::OK;

AppResult MyNeuAnalysis::endJob( AbsEvent* anEvent )
  return AppResult::OK;

AppResult MyNeuAnalysis::event( AbsEvent* anEvent )

  // get list of neutral particle candidates
  HepAList<BtaCandidate>* neuList  =
      Ifd<HepAList< BtaCandidate > >::get(anEvent, "CalorNeutral");

  // loop over the neutral list
  HepAListIterator<BtaCandidate> iterNeu(*neuList);
  BtaCandidate* neu(0);
  int nneu(0);
  double eneumax(0.0);
  while ( neu = iterNeu() ) {

    // Get momemtum, theta, and energy
    double pneu = neu->p();
    double thetaneu = neu->p4().theta();
    double eneu = neu->energy();

    // Fill histograms of momentum and theta

    // count the neutrals

    // get energy of the highest-energy neutral in the event
    if (eneu > eneumax) eneumax = eneu;

   // Fill the ntuple with number of neutrals and maximum neutral energy
   _ntuple->column("nneu", nneu, -99);
   _ntuple->column("eneumax", eneumax, -99.0);

   // Dump the ntuple (otherwise it won't be produced!)

  return AppResult::OK;

                                                                                          Go to Step 5