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 11 of file Run.cc.

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

~Run (  ) 

The destructor.

Definition at line 16 of file Run.cc.

00016 { }


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().

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

bool finalize (  ) 

Close up HepMC I/O.

Definition at line 132 of file Run.cc.

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

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

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 74 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().

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

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 54 of file Run.cc.

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

Referenced by Run::init().

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

bool processEvent (  ) 

Handle next event.

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

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

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().

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

Run & setCrossSection ( const double  xs  ) 

Get the cross-section for this run.

Definition at line 19 of file Run.cc.

References Run::_xs.

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

Run & setListAnalyses ( const bool  dolist  ) 

Declare whether to list available analyses.

Definition at line 30 of file Run.cc.

References Run::_listAnalyses.

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


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: