Step 4: Fill histograms and ntuple
Go to Step 5
Header file: MyNeuAnalysis.hh
#ifndef MYNEUANALYSIS_HH
#define MYNEUANALYSIS_HH
#include "Framework/AppModule.hh"
#include "AbsEvent/AbsEvent.hh"
#include "HepTuple/Histogram.h"
#include "HepTuple/Tuple.h"
class MyNeuAnalysis : public AppModule {
public:
// 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 );
protected:
private:
HepHistogram *_hpneu;
HepHistogram *_hthetaneu;
HepTuple *_ntuple;
};
#endif
Implementation file: MyNeuAnalysis.cc
#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
_hpneu->accumulate(pneu);
_hthetaneu->accumulate(thetaneu);
// count the neutrals
nneu++;
// 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!)
_ntuple->dumpData();
return AppResult::OK;
}
Go to Step 5