Run Class Reference

Interface to handle a run of events read from a HepMC stream or file. More...

#include <Run.hh>

Collaboration diagram for Run:
Collaboration graph
[legend]

List of all members.

Public Member Functions

Standard constructors and destructors. */

 Run (AnalysisHandler &ah)
 The standard constructor.
 ~Run ()
 The destructor.
Set run properties

RunsetCrossSection (const double xs)
 Get the cross-section for this run.
double crossSection () const
 Get the current cross-section from the analysis handler in pb.
RunsetListAnalyses (const bool dolist)
 Declare whether to list available analyses.
File processing stages

bool init (const std::string &evtfile, double weight=1.0)
 Set up HepMC file readers (using the appropriate file weight for the first file).
bool openFile (const std::string &evtfile, double weight=1.0)
 Open a HepMC GenEvent file (using the appropriate file weight for the first file).
bool readEvent ()
 Read the next HepMC event.
bool processEvent ()
 Handle next event.
bool finalize ()
 Close up HepMC I/O.

Private Attributes

AnalysisHandler_ah
 AnalysisHandler object.
bool _listAnalyses
 Flag to show list of analyses.
Run variables obtained from events or command line

double _fileweight
 An extra event weight scaling per event file. Useful for e.g. AlpGen n-parton event file combination.
double _xs
 Cross-section from command line.
HepMC I/O members

shared_ptr< GenEvent > _evt
 Current event.
shared_ptr< std::istream > _istr
 Output stream for HepMC writer.
shared_ptr< HepMC::IO_GenEvent > _io
 HepMC I/O writer.

Detailed Description

Interface to handle a run of events read from a HepMC stream or file.

Definition at line 17 of file Run.hh.


Constructor & Destructor Documentation

Run ( AnalysisHandler ah  ) 

The standard constructor.

Definition at line 12 of file Run.cc.

00013     : _ah(ah), _fileweight(1.0), _xs(NAN)
00014   { }

~Run (  ) 

The destructor.

Definition at line 17 of file Run.cc.

00017 { }


Member Function Documentation

double crossSection (  )  const

Get the current cross-section from the analysis handler in pb.

Definition at line 26 of file Run.cc.

References Run::_ah, and AnalysisHandler::crossSection().

00026                                  {
00027     return _ah.crossSection();
00028   }

bool finalize (  ) 

Close up HepMC I/O.

Definition at line 133 of file Run.cc.

References Run::_evt, Run::_io, and Run::_istr.

00133                      {
00134     _evt.reset();
00135     _istr.reset();
00136     _io.reset();
00137     return true;
00138   }

bool init ( const std::string &  evtfile,
double  weight = 1.0 
)

Set up HepMC file readers (using the appropriate file weight for the first file).

Definition at line 75 of file Run.cc.

References Run::_ah, Run::_evt, Run::_listAnalyses, Run::_xs, AnalysisHandler::analysisNames(), Log::DEBUG, Log::ERROR, Log::getLog(), AnalysisHandler::init(), Run::openFile(), Run::readEvent(), and AnalysisHandler::setCrossSection().

00075                                                         {
00076     if (!openFile(evtfile, weight)) return false;
00077 
00078     // Read first event to define run conditions
00079     bool ok = readEvent();
00080     if (!ok) return false;
00081     if (_evt->particles_size() == 0) {
00082       Log::getLog("Rivet.Run") << Log::ERROR << "Empty first event." << endl;
00083       return false;
00084     }
00085 
00086     // Initialise AnalysisHandler with beam information from first event
00087     _ah.init(*_evt);
00088 
00089     // Set cross-section from command line
00090     if (_xs >= 0.0) {
00091       Log::getLog("Rivet.Run")
00092         << Log::DEBUG << "Setting user cross-section = " << _xs << " pb" << endl;
00093       _ah.setCrossSection(_xs);
00094     }
00095 
00096     // List the chosen & compatible analyses if requested
00097     if (_listAnalyses) {
00098       foreach (const std::string& ana, _ah.analysisNames()) {
00099         cout << ana << endl;
00100       }
00101     }
00102 
00103     return true;
00104   }

bool openFile ( const std::string &  evtfile,
double  weight = 1.0 
)

Open a HepMC GenEvent file (using the appropriate file weight for the first file).

Definition at line 55 of file Run.cc.

References Run::_fileweight, Run::_io, Run::_istr, Log::ERROR, and Log::getLog().

Referenced by Run::init().

00055                                                             {
00056     // Set current weight-scaling member
00057     _fileweight = weight;
00058 
00059     // Set up HepMC input reader objects
00060     if (evtfile == "-") {
00061       _io.reset(new HepMC::IO_GenEvent(std::cin));
00062     } else {
00063       // Ignore the HepMC::IO_GenEvent(filename, ios) constructor, since it's only available from HepMC 2.4
00064       _istr.reset(new std::fstream(evtfile.c_str(), std::ios::in));
00065       _io.reset(new HepMC::IO_GenEvent(*_istr));
00066     }
00067     if (_io->rdstate() != 0) {
00068       Log::getLog("Rivet.Run") << Log::ERROR << "Read error on file " << evtfile << endl;
00069       return false;
00070     }
00071     return true;
00072   }

bool processEvent (  ) 

Handle next event.

Definition at line 107 of file Run.cc.

References Run::_ah, Run::_evt, Run::_xs, AnalysisHandler::analyze(), Log::DEBUG, Log::ERROR, Log::getLog(), AnalysisHandler::hasCrossSection(), AnalysisHandler::needCrossSection(), and AnalysisHandler::setCrossSection().

00107                          {
00108     // Set cross-section if found in event and not from command line
00109     #ifdef HEPMC_HAS_CROSS_SECTION
00110     if (std::isnan(_xs) && _evt->cross_section()) {
00111       const double xs = _evt->cross_section()->cross_section(); //< in pb
00112       Log::getLog("Rivet.Run")
00113         << Log::DEBUG << "Setting cross-section = " << xs << " pb" << endl;
00114       _ah.setCrossSection(xs);
00115     }
00116     #endif
00117     // Complain about absence of cross-section if required!
00118     if (_ah.needCrossSection() && !_ah.hasCrossSection()) {
00119       Log::getLog("Rivet.Run")
00120         << Log::ERROR
00121         << "Total cross-section needed for at least one of the analyses. "
00122         << "Please set it (on the command line with '-x' if using the 'rivet' program)" << endl;
00123       return false;
00124     }
00125 
00126     // Analyze event
00127     _ah.analyze(*_evt);
00128 
00129     return true;
00130   }

bool readEvent (  ) 

Read the next HepMC event.

Todo:
Clear rather than new the GenEvent object per-event?

Definition at line 38 of file Run.cc.

References Run::_evt, Run::_fileweight, Run::_io, Log::DEBUG, Rivet::fuzzyEquals(), and Log::getLog().

Referenced by Run::init().

00038                       {
00039     /// @todo Clear rather than new the GenEvent object per-event?
00040     _evt.reset(new GenEvent());
00041     if (_io->rdstate() != 0 || !_io->fill_next_event(_evt.get()) ) {
00042       Log::getLog("Rivet.Run") << Log::DEBUG << "Read failed. End of file?" << endl;
00043       return false;
00044     }
00045     // Rescale event weights by file-level weight, if scaling is non-trivial
00046     if (!fuzzyEquals(_fileweight, 1.0)) {
00047       for (size_t i = 0; i < _evt->weights().size(); ++i) {
00048         _evt->weights()[i] *= _fileweight;
00049       }
00050     }
00051     return true;
00052   }

Run & setCrossSection ( const double  xs  ) 

Get the cross-section for this run.

Definition at line 20 of file Run.cc.

References Run::_xs.

00020                                            {
00021     _xs = xs;
00022     return *this;
00023   }

Run & setListAnalyses ( const bool  dolist  ) 

Declare whether to list available analyses.

Definition at line 31 of file Run.cc.

References Run::_listAnalyses.

00031                                              {
00032     _listAnalyses = dolist;
00033     return *this;
00034   }


Member Data Documentation

AnalysisHandler& _ah [private]

AnalysisHandler object.

Definition at line 71 of file Run.hh.

Referenced by Run::crossSection(), Run::init(), and Run::processEvent().

shared_ptr<GenEvent> _evt [private]

Current event.

Definition at line 94 of file Run.hh.

Referenced by Run::finalize(), Run::init(), Run::processEvent(), and Run::readEvent().

double _fileweight [private]

An extra event weight scaling per event file. Useful for e.g. AlpGen n-parton event file combination.

Definition at line 78 of file Run.hh.

Referenced by Run::openFile(), and Run::readEvent().

shared_ptr<HepMC::IO_GenEvent> _io [private]

HepMC I/O writer.

Definition at line 100 of file Run.hh.

Referenced by Run::finalize(), Run::openFile(), and Run::readEvent().

shared_ptr<std::istream> _istr [private]

Output stream for HepMC writer.

Definition at line 97 of file Run.hh.

Referenced by Run::finalize(), and Run::openFile().

bool _listAnalyses [private]

Flag to show list of analyses.

Definition at line 87 of file Run.hh.

Referenced by Run::init(), and Run::setListAnalyses().

double _xs [private]

Cross-section from command line.

Definition at line 81 of file Run.hh.

Referenced by Run::init(), Run::processEvent(), and Run::setCrossSection().


The documentation for this class was generated from the following files: