Rivet is hosted by Hepforge, IPPP Durham
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:

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 skipEvent ()
 Read the next HepMC event only to skip it.
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
std::shared_ptr< GenEvent > _evt
 Current event.
std::shared_ptr< std::istream > _istr
 Output stream for HepMC writer.
std::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 16 of file Run.hh.


Constructor & Destructor Documentation

Run ( AnalysisHandler ah)

The standard constructor.

Definition at line 11 of file Run.cc.

    : _ah(ah), _fileweight(1.0), _xs(NAN)
  { }
~Run ( )

The destructor.

Definition at line 16 of file Run.cc.

{ }

Member Function Documentation

double crossSection ( ) const

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

Definition at line 25 of file Run.cc.

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

                                 {
    return _ah.crossSection();
  }
bool finalize ( )

Close up HepMC I/O.

Definition at line 141 of file Run.cc.

References Run::_ah, Run::_evt, Run::_io, Run::_istr, Run::_xs, AnalysisHandler::finalize(), and AnalysisHandler::setCrossSection().

                     {
    _evt.reset();
    _istr.reset();
    _io.reset();

    if (!std::isnan(_xs)) _ah.setCrossSection(_xs);
    _ah.finalize();

    return true;
  }
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 83 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().

                                                        {
    if (!openFile(evtfile, weight)) return false;

    // Read first event to define run conditions
    bool ok = readEvent();
    if (!ok) return false;
    if (_evt->particles_size() == 0) {
      Log::getLog("Rivet.Run") << Log::ERROR << "Empty first event." << endl;
      return false;
    }

    // Initialise AnalysisHandler with beam information from first event
    _ah.init(*_evt);

    // Set cross-section from command line
    if (!std::isnan(_xs)) {
      Log::getLog("Rivet.Run")
        << Log::DEBUG << "Setting user cross-section = " << _xs << " pb" << endl;
      _ah.setCrossSection(_xs);
    }

    // List the chosen & compatible analyses if requested
    if (_listAnalyses) {
      foreach (const std::string& ana, _ah.analysisNames()) {
        cout << ana << endl;
      }
    }

    return true;
  }
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 63 of file Run.cc.

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

Referenced by Run::init().

                                                            {
    // Set current weight-scaling member
    _fileweight = weight;

    // Set up HepMC input reader objects
    if (evtfile == "-") {
      _io.reset(new HepMC::IO_GenEvent(std::cin));
    } else {
      // Ignore the HepMC::IO_GenEvent(filename, ios) constructor, since it's only available from HepMC 2.4
      _istr.reset(new std::fstream(evtfile.c_str(), std::ios::in));
      _io.reset(new HepMC::IO_GenEvent(*_istr));
    }
    if (_io->rdstate() != 0) {
      Log::getLog("Rivet.Run") << Log::ERROR << "Read error on file " << evtfile << endl;
      return false;
    }
    return true;
  }
bool processEvent ( )

Handle next event.

Definition at line 115 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().

                         {
    // Set cross-section if found in event and not from command line
    #ifdef HEPMC_HAS_CROSS_SECTION
    if (std::isnan(_xs) && _evt->cross_section()) {
      const double xs = _evt->cross_section()->cross_section(); ///< in pb
      Log::getLog("Rivet.Run")
        << Log::DEBUG << "Setting cross-section = " << xs << " pb" << endl;
      _ah.setCrossSection(xs);
    }
    #endif
    // Complain about absence of cross-section if required!
    if (_ah.needCrossSection() && !_ah.hasCrossSection()) {
      Log::getLog("Rivet.Run")
        << Log::ERROR
        << "Total cross-section needed for at least one of the analyses. "
        << "Please set it (on the command line with '-x' if using the 'rivet' program)" << endl;
      return false;
    }

    // Analyze event
    _ah.analyze(*_evt);

    return true;
  }
bool readEvent ( )

Read the next HepMC event.

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

Definition at line 37 of file Run.cc.

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

Referenced by Run::init().

                      {
    /// @todo Clear rather than new the GenEvent object per-event?
    _evt.reset(new GenEvent());
    if (_io->rdstate() != 0 || !_io->fill_next_event(_evt.get()) ) {
      Log::getLog("Rivet.Run") << Log::DEBUG << "Read failed. End of file?" << endl;
      return false;
    }
    // Rescale event weights by file-level weight, if scaling is non-trivial
    if (!fuzzyEquals(_fileweight, 1.0)) {
      for (size_t i = 0; i < (size_t) _evt->weights().size(); ++i) {
        _evt->weights()[i] *= _fileweight;
      }
    }
    return true;
  }
Run & setCrossSection ( const double  xs)

Get the cross-section for this run.

Definition at line 19 of file Run.cc.

References Run::_xs.

                                           {
    _xs = xs;
    return *this;
  }
Run & setListAnalyses ( const bool  dolist)

Declare whether to list available analyses.

Definition at line 30 of file Run.cc.

References Run::_listAnalyses.

                                             {
    _listAnalyses = dolist;
    return *this;
  }
bool skipEvent ( )

Read the next HepMC event only to skip it.

Definition at line 54 of file Run.cc.

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

                      {
    if (_io->rdstate() != 0 || !_io->fill_next_event(_evt.get()) ) {
      Log::getLog("Rivet.Run") << Log::DEBUG << "Read failed. End of file?" << endl;
      return false;
    }
    return true;
  }

Member Data Documentation

AnalysisHandler& _ah [private]

AnalysisHandler object.

Definition at line 73 of file Run.hh.

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

std::shared_ptr<GenEvent> _evt [private]

Current event.

Definition at line 96 of file Run.hh.

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

double _fileweight [private]

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

Definition at line 80 of file Run.hh.

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

std::shared_ptr<HepMC::IO_GenEvent> _io [private]

HepMC I/O writer.

Definition at line 102 of file Run.hh.

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

std::shared_ptr<std::istream> _istr [private]

Output stream for HepMC writer.

Definition at line 99 of file Run.hh.

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

bool _listAnalyses [private]

Flag to show list of analyses.

Definition at line 89 of file Run.hh.

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

double _xs [private]

Cross-section from command line.

Definition at line 83 of file Run.hh.

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


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