diff --git a/Analysis/RivetAnalysis.cc b/Analysis/RivetAnalysis.cc --- a/Analysis/RivetAnalysis.cc +++ b/Analysis/RivetAnalysis.cc @@ -1,227 +1,235 @@ // -*- C++ -*- // // This is the implementation of the non-inlined, non-templated member // functions of the RivetAnalysis class. // #include #include "ThePEG/Interface/Interfaced.h" #include "ThePEG/Interface/ClassDocumentation.h" #include "ThePEG/Interface/ParVector.h" #include "ThePEG/Interface/Parameter.h" #include "ThePEG/Interface/Switch.h" #include "ThePEG/Persistency/PersistentOStream.h" #include "ThePEG/Persistency/PersistentIStream.h" #include "ThePEG/Vectors/HepMCConverter.h" #include "ThePEG/Config/HepMCHelper.h" #include "ThePEG/Repository/EventGenerator.h" #include "ThePEG/Repository/CurrentGenerator.h" #include "RivetAnalysis.h" #include "Rivet/AnalysisHandler.hh" #include "Rivet/Tools/RivetPaths.hh" #include "Rivet/Tools/Logging.hh" #include "ThePEG/Utilities/DescribeClass.h" using namespace ThePEG; RivetAnalysis::RivetAnalysis() : _debug(false), _rivet(), _nevent(0), _checkBeams(true) {} void RivetAnalysis::analyze(ThePEG::tEventPtr event, long ieve, int loop, int state) { ++_nevent; AnalysisHandler::analyze(event, ieve, loop, state); // Rotate to CMS, extract final state particles and call analyze(particles). // convert to hepmc HepMC::GenEvent * hepmc = ThePEG::HepMCConverter::convert(*event); // analyse the event if(_nevent>1) CurrentGenerator::Redirect stdout(cout); if ( _rivet ){ #if ThePEG_RIVET_VERSION > 1 try { _rivet->analyze(*hepmc); } catch (const YODA::Exception & e) { Throw() << "Warning: Rivet/Yoda got the exception: "<< e.what()<<"\n" << Exception::warning; } #else #error "Unknown ThePEG_RIVET_VERSION" #endif } if(_nevent<=1) { // check that analysis list is still available if ( _rivet->analysisNames().size() != _analyses.size() ) { throw ThePEG::Exception() << "Rivet could not find all requested analyses.\n" << "Use 'rivet --list-analyses' to check availability.\n" << ThePEG::Exception::runerror; } } // delete hepmc event delete hepmc; } ThePEG::IBPtr RivetAnalysis::clone() const { return new_ptr(*this); } ThePEG::IBPtr RivetAnalysis::fullclone() const { return new_ptr(*this); } void RivetAnalysis::persistentOutput(ThePEG::PersistentOStream & os) const { os << _analyses << _preload << _paths << _filename << _debug << _checkBeams; } void RivetAnalysis::persistentInput(ThePEG::PersistentIStream & is, int) { is >> _analyses >> _preload >> _paths >> _filename >> _debug >> _checkBeams; } // The following static variable is needed for the type // description system in ThePEG. DescribeClass describeRivetAnalysis("ThePEG::RivetAnalysis", "RivetAnalysis.so"); void RivetAnalysis::Init() { static ThePEG::ClassDocumentation documentation ("The RivetAnalysis class is a simple class to allow analyses" " from the Rivet library to be called from ThePEG"); static ThePEG::ParVector interfaceAnalyses ("Analyses", "The names of the Rivet analyses to use", &RivetAnalysis::_analyses, -1, "", "","" "", false, false, ThePEG::Interface::nolimits); static ParVector interfacePreLoad ("PreLoad", "The yoda files to be preloaded", &RivetAnalysis::_preload, -1, "", "", "", false, false, Interface::nolimits); static ThePEG::ParVector interfacePaths ("Paths", "The directory paths where Rivet should look for analyses.", &RivetAnalysis::_paths, -1, "", "","" "", false, false, ThePEG::Interface::nolimits); static Parameter interfaceFilename ("Filename", #if ThePEG_RIVET_VERSION > 1 "The name of the file where the YODA histograms are put. If empty, " "the run name will be used instead. '.yoda' will in any case be " "appended to the file name.", #else #error "Unknown ThePEG_RIVET_VERSION" #endif &RivetAnalysis::_filename, "", true, false); static Switch interfaceDebug ("Debug", "Enable debug information from Rivet", &RivetAnalysis::_debug, false, true, false); static SwitchOption interfaceDebugNo (interfaceDebug, "No", "Disable debug information.", false); static SwitchOption interfaceDebugYes (interfaceDebug, "Yes", "Enable debug information from Rivet.", true); static Switch interfaceCheckBeams ("CheckBeams", "Whether or not to get rivet to check the beams for the analyses", &RivetAnalysis::_checkBeams, true, false, false); static SwitchOption interfaceCheckBeamsYes (interfaceCheckBeams, "Yes", "Check the beams(default)", true); static SwitchOption interfaceCheckBeamsNo (interfaceCheckBeams, "No", "Don't check the beams", false); interfaceAnalyses.rank(10); } void RivetAnalysis::dofinish() { AnalysisHandler::dofinish(); if( _nevent > 0 && _rivet ) { CurrentGenerator::Redirect stdout(cout); #if ThePEG_RIVET_VERSION > 2 _rivet->setCrossSection(make_pair(generator()->integratedXSec()/picobarn, generator()->integratedXSecErr()/picobarn)); #else _rivet->setCrossSection(generator()->integratedXSec()/picobarn); #endif _rivet->finalize(); string fname = _filename; #if ThePEG_RIVET_VERSION > 1 if ( fname.empty() ) fname = generator()->path() + "/" + generator()->runName() + ".yoda"; #else #error "Unknown ThePEG_RIVET_VERSION" #endif _rivet->writeData(fname); } delete _rivet; _rivet = nullptr; } void RivetAnalysis::doinit() { AnalysisHandler::doinit(); if(_analyses.empty()) throw ThePEG::Exception() << "Must have at least one analysis loaded in " << "RivetAnalysis::doinitrun()" << ThePEG::Exception::runerror; // check that analysis list is available _rivet = new Rivet::AnalysisHandler; //(fname); +#if ThePEG_RIVET_VERSION > 3 + _rivet->setCheckBeams(_checkBeams); +#else _rivet->checkBeams(_checkBeams); +#endif for ( int i = 0, N = _paths.size(); i < N; ++i ) Rivet::addAnalysisLibPath(_paths[i]); _rivet->addAnalyses(_analyses); if ( _rivet->analysisNames().size() != _analyses.size() ) { throw ThePEG::Exception() << "Rivet could not find all requested analyses.\n" << "Use 'rivet --list-analyses' to check availability.\n" << ThePEG::Exception::runerror; } delete _rivet; _rivet = 0; } void RivetAnalysis::doinitrun() { AnalysisHandler::doinitrun(); // create Rivet analysis handler CurrentGenerator::Redirect stdout(cout); _rivet = new Rivet::AnalysisHandler; +#if ThePEG_RIVET_VERSION > 3 + _rivet->setCheckBeams(_checkBeams); +#else _rivet->checkBeams(_checkBeams); +#endif for ( int i = 0, N = _paths.size(); i < N; ++i ) Rivet::addAnalysisLibPath(_paths[i]); _rivet->addAnalyses(_analyses); // check that analysis list is still available if ( _rivet->analysisNames().size() != _analyses.size() ) { throw ThePEG::Exception() << "Rivet could not find all requested analyses.\n" << "Use 'rivet --list-analyses' to check availability.\n" << ThePEG::Exception::runerror; } // preload files #if ThePEG_RIVET_VERSION > 2 for(string fname : _preload) { _rivet->readData(fname); } #else if(!_preload.empty()) throw Exception() << "You have requested yoda files are preloaded by Rivet but this only supported for Rivet 3 and above"; #endif // debugging if ( _debug ) Rivet::Log::setLevel("Rivet",Rivet::Log::DEBUG); } diff --git a/m4/rivet.m4 b/m4/rivet.m4 --- a/m4/rivet.m4 +++ b/m4/rivet.m4 @@ -1,81 +1,83 @@ dnl ##### RIVET ##### AC_DEFUN([THEPEG_CHECK_RIVET], [ AC_REQUIRE([THEPEG_CHECK_HEPMC]) AC_REQUIRE([THEPEG_CHECK_GSL]) AC_MSG_CHECKING([for Rivet location]) RIVETINCLUDE="" LOAD_RIVET="" RIVETLIBS="-lRivet" AC_ARG_WITH(rivet, AC_HELP_STRING([--with-rivet=DIR],[Location of Rivet installation @<:@default=system libs@:>@]), [], [with_rivet=system]) if test "x$with_hepmc" = "xno"; then with_rivet=no fi if test "x$with_rivet" = "xno"; then AC_MSG_RESULT([Rivet support disabled.]) elif test "x$with_rivet" = "xsystem"; then AC_MSG_RESULT([in system libraries]) oldlibs="$LIBS" LIBS="$LIBS $HEPMCLIBS" AC_CHECK_LIB(Rivet,main, [], [with_rivet=no AC_MSG_WARN([Rivet >= 1.3 not found in system libraries]) ]) RIVETLIBS="$LIBS" LIBS=$oldlibs else AC_MSG_RESULT([$with_rivet]) RIVETINCLUDE="$( $with_rivet/bin/rivet-config --cppflags )" RIVETLIBS="-L$with_rivet/lib -R$with_rivet/lib -lRivet" if test "${host_cpu}" == "x86_64" -a -e $with_rivet/lib64/libRivet.so ; then RIVETLIBS="-L$with_rivet/lib64 -R$with_rivet/lib64 -lRivet" fi fi if test "x$with_rivet" != "xno"; then LOAD_RIVET="library RivetAnalysis.so" # Now lets see if the libraries work properly oldLIBS="$LIBS" oldLDFLAGS="$LDFLAGS" oldCPPFLAGS="$CPPFLAGS" LIBS="$LIBS `echo $HEPMCLIBS | sed -e 's! -R.* ! !'` `echo $RIVETLIBS | sed -e 's! -R.* ! !'` `echo $GSLLIBS | sed -e 's! -R.* ! !'`" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS $HEPMCINCLUDE $RIVETINCLUDE $GSLINCLUDE" # check Rivet AC_MSG_CHECKING([that Rivet works]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]],[[Rivet::AnalysisHandler foo; foo.writeData("foo");]])],[AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no]) AC_MSG_RESULT([No. Use '--with-rivet=' to set a path to Rivet >= 1.3'.]) with_rivet="no" LOAD_RIVET="" ]) LIBS="$oldLIBS" LDFLAGS="$oldLDFLAGS" CPPFLAGS="$oldCPPFLAGS" fi rivetversion=1 if test "x$with_rivet" = "xsystem"; then echo $( rivet-config --version ) | grep -q '^2\.' && rivetversion=2 echo $( rivet-config --version ) | grep -q '^3\.' && rivetversion=3 + echo $( rivet-config --version ) | grep -q '^4\.' && rivetversion=4 elif test "x$with_rivet" != "xno"; then echo $( "$with_rivet/bin/rivet-config" --version ) | grep -q '^2\.' && rivetversion=2 echo $( "$with_rivet/bin/rivet-config" --version ) | grep -q '^3\.' && rivetversion=3 + echo $( "$with_rivet/bin/rivet-config" --version ) | grep -q '^4\.' && rivetversion=4 fi AC_DEFINE_UNQUOTED([ThePEG_RIVET_VERSION], [$rivetversion], [Rivet major version (1,2,3)]) AM_CONDITIONAL(HAVE_RIVET,[test "x$with_rivet" != "xno"]) AC_SUBST(RIVETINCLUDE) AC_SUBST(RIVETLIBS) AC_SUBST(LOAD_RIVET) ])