//-------------------------------------------------------------------------- // File and Version Information: // $Id: WorkBook1.cc,v 1.6 1999/02/08 07:03:32 jake Exp $ // // Description: // Class WorkBook1 // // Environment: // Software developed for the BaBar Detector at the SLAC B-Factory. // // Author List: // Charlie Young Original Author // // Copyright Information: // Copyright (C) 1997 // //------------------------------------------------------------------------ #include "BaBar/BaBar.hh" //----------------------- // This Class's Header -- //----------------------- #include "BetaUser/WorkBook1.hh" //------------- // C Headers -- //------------- #include //--------------- // C++ Headers -- //--------------- #include #include //------------------------------- // Collaborating Class Headers -- //------------------------------- #include "CLHEP/Alist/ConstAList.h" #include "CLHEP/Alist/ConstAIterator.h" #include "AbsEvent/AbsEvent.hh" #include "AbsEvent/getTmpAList.hh" #include "AbsEnv/AbsEnv.hh" #include "GenEnv/GenEnv.hh" #include "ErrLogger/ErrLog.hh" #include "ProxyDict/IfdHepAList.hh" #include "ProxyDict/IfdStrKey.hh" #include "ProxyDict/IfdKey.hh" #include "Beta/BtaCandidate.hh" #include "HepTuple/TupleManager.h" #include "HepTuple/Tuple.h" #include "HepTuple/Histogram.h" // -- ROOT #include "BetaUser/TMyCand.hh" #include "BetaUser/TMyEvent.hh" #include "TTree.h" #include "TBranch.h" // -- ROOT //----------------------------------------------------------------------- // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- //----------------------------------------------------------------------- //---------------- // Constructors -- //---------------- // in general, a module constructor should not do much. The begin(job) or // begin(run) members are better places to put initialization WorkBook1::WorkBook1( const char* const theName, const char* const theDescription ) : AppModule( theName, theDescription ) , _btaChargedList("trackCandidates",this,"ChargedTracks") , _nbins("nbins",this,100) , _xlow("xlow",this,0.) , _xhigh("xhigh",this,5.) , _fillNtp("fillNtuple",this,false) { commands()->append(& _btaChargedList); commands()->append(& _nbins); commands()->append(& _xlow); commands()->append(& _xhigh); commands()->append(& _fillNtp); } //-------------- // Destructor -- //-------------- // The destructor should be limited to undoing the work of the constructor WorkBook1::~WorkBook1( ) { } //-------------- // Operations -- //-------------- // The begin(AppJob*) member function is run before any events are // processed. In sample code, it opens the output histogram file // and then books a histogram and optionally an ntuple. APPMODULERETURNTYPE2 WorkBook1::beginJob( AbsEvent* anEvent ) { ErrMsg(routine)<<"Begin job"<getGen()->ntupleManager(); assert(manager != 0); // book an n-tuple if enabled via tcl parameter if( _fillNtp.value() ) { _ntuple = manager->ntuple(name()); } // book the momentum distribution histogram // parameters controllable via tcl _pHisto = manager->histogram("momentum", _nbins.value(), _xlow.value(), _xhigh.value() ); // -- ROOT HepTupleManager* manager = gblEnv->getGen()->ntupleManager(); // Thanks to Jane for this (Kanga) fix assert(0 != manager); // Added on 06/28/00 manager->setDir("/"); _Tree= new TTree("MyTree","My analysis tree"); if (!_Tree) {ErrMsg(routine) << "Unable to create ROOT tree?" << endmsg; } _Event = new TMyEvent(0); _Tree->Branch("TMyEvent", "TMyEvent", &_Event, 256000/8, 1); // -- ROOT return APPMODULERETURNVAL2; } // end(AppJob*) function is called after all events have been processed. APPMODULERETURNTYPE2 WorkBook1::endJob( AbsEvent* anEvent ) { ErrMsg(routine) << "End job" << endmsg; // -- ROOT HepTupleManager* manager = gblEnv->getGen()->ntupleManager(); assert(0 != manager); manager->setDir("/"); _Tree->Write(); // -- ROOT return APPMODULERETURNVAL2; } // event function is called once per event APPMODULERETURNTYPE1 WorkBook1::event( AbsEvent* anEvent ) { ErrMsg(routine) << "event" << endmsg; // get list of input track candidates HepAList* trkList; trkList = Ifd< IfdHepAList >::get(anEvent, _btaChargedList.value() ); if ( 0 == trkList ) { ErrMsg(warning) << "no trkList found, skipping event" << endmsg; return APPMODULERETURNVAL1; } // -- ROOT int nCand(0); _Event->Clear(); // -- ROOT // Optionally, loop over candidates to fill ntuple. if ( _fillNtp.value() ) { HepAListIterator iterTrk(*trkList); BtaCandidate* trk; while ( 0 != ( trk = iterTrk()) ) { _ntuple->column("p",trk->p()); _ntuple->column("px",trk->p3().x()); _ntuple->column("py",trk->p3().y()); _ntuple->column("pz",trk->p3().z()); _ntuple->dumpData(); // -- ROOT TMyCand *pCand; pCand = _Event->AddCand(); ++nCand; pCand->setEraw(3.1415); pCand->setCharge((int)trk->charge()); pCand->setPlab((float)(trk->p3().x()),(float)(trk->p3().y()),(float)(trk->p3().z())); pCand->setPcms((float)1., (float)2., (float)3., (float)4.); // -- ROOT } // -- ROOT _Event->SetNCand(nCand); _Tree->Fill(); // -- ROOT } // Loop over track candidates to plot momentum HepAListIterator iterTrk(*trkList); BtaCandidate* trk; while ( 0 != ( trk = iterTrk()) ) { _pHisto->accumulate( trk->p() ); } // done return APPMODULERETURNVAL1; }