ATLAS Offline Software
Loading...
Searching...
No Matches
Rivet_i.cxx File Reference
#include "Rivet_i.h"
#include "LogLevels.h"
#include "AtlasHepMC/GenEvent.h"
#include "TruthUtils/HepMCHelpers.h"
#include "GeneratorObjects/McEventCollection.h"
#include "AthenaKernel/errorcheck.h"
#include "PathResolver/PathResolver.h"
#include "GaudiKernel/IAppMgrUI.h"
#include "GaudiKernel/Bootstrap.h"
#include "GaudiKernel/ITHistSvc.h"
#include "Rivet/Rivet.hh"
#include "Rivet/Analysis.hh"
#include "Rivet/Config/RivetConfig.hh"
#include "Rivet/Tools/RivetYODA.hh"
#include <cstdlib>
#include <cstdio>
#include <memory>
#include <regex>

Go to the source code of this file.

Functions

std::string getenv_str (const std::string &key)
StatusCode Rivet_i::initialize ATLAS_NOT_THREAD_SAFE ()
 Install fatal handler with default options.
bool cmpGenParticleByEDesc (HepMC::ConstGenParticlePtr a, HepMC::ConstGenParticlePtr b)
 Helper function to sort GenParticles by descending energy.
std::vector< std::string > split (const std::string &input, const std::string &regex)

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

StatusCode Rivet_i::initialize ATLAS_NOT_THREAD_SAFE ( void )
inline

Install fatal handler with default options.

This is meant to be easy to call from python via ctypes.

Definition at line 67 of file Rivet_i.cxx.

67 {
68 // ^ use of setenv
69 ATH_MSG_INFO("Using Rivet version " << Rivet::version());
70
71 ATH_CHECK(m_evtInfoKey.initialize());
72
73 // Get tool for xAOD::Truth to HepMC::GenEvent conversion
74 ATH_CHECK(m_xAODtoHepMCTool.retrieve());
75
76
77 // Set RIVET_ANALYSIS_PATH based on alg setup
78
79 // First set (overwrite, if necessary) the RIVET_ANALYSIS_PATH variable
80 std::string env_rap(getenv_str("RIVET_ANALYSIS_PATH"));
81 if (!m_anapath.empty()) {
82 ATH_MSG_INFO("Setting Rivet plugin analyses loader env path: " << m_anapath);
83 if (!env_rap.empty()) ATH_MSG_INFO("Overwriting environment's RIVET_ANALYSIS_PATH = " << env_rap << "!");
84 setenv("RIVET_ANALYSIS_PATH", m_anapath.c_str(), 1);
85 }
86
87 // Get the final form of RIVET_ANALYSIS_PATH and talk about it
88 env_rap = getenv_str("RIVET_ANALYSIS_PATH");
89 if (!env_rap.empty()) ATH_MSG_DEBUG("Loading Rivet plugin analyses from env path: " << env_rap);
90
91 // Set up analysis handler
92 #if RIVET_VERSION_CODE >= 40100
93 m_analysisHandler = new Rivet::AnalysisHandler();
94 #else
95 m_analysisHandler = new Rivet::AnalysisHandler(m_runname);
96 #endif
97 assert(m_analysisHandler);
98
99 #if RIVET_VERSION_CODE >= 40000
100 m_analysisHandler->setCheckBeams(!m_ignorebeams); //< Whether to do beam ID/energy consistency checks
101 m_analysisHandler->matchWeightNames(m_matchWeights); //< Only run on a subset of the multi-weights
102 m_analysisHandler->unmatchWeightNames(m_unmatchWeights); //< Veto a subset of the multi-weights
103 #else
104 m_analysisHandler->setIgnoreBeams(m_ignorebeams); //< Whether to do beam ID/energy consistency checks
105 m_analysisHandler->selectMultiWeights(m_matchWeights); //< Only run on a subset of the multi-weights
106 m_analysisHandler->deselectMultiWeights(m_unmatchWeights); //< Veto a subset of the multi-weights
107 #endif
108 m_analysisHandler->skipMultiWeights(m_skipweights); //< Only run on the nominal weight
109 m_analysisHandler->setNominalWeightName(m_nominalWeightName);
110 if (m_weightcap>0) m_analysisHandler->setWeightCap(m_weightcap);
111
112 // Set Rivet native log level to match Athena
113 Rivet::Log::setLevel("Rivet", rivetLevel(msg().level()));
114
115 // Get all available analysis names
116 if (msgLvl(MSG::VERBOSE)) {
117 std::vector<std::string> analysisNames = Rivet::AnalysisLoader::analysisNames();
118 ATH_MSG_VERBOSE("List of available Rivet analyses:");
119 for (const std::string& a : analysisNames) ATH_MSG_VERBOSE(" " + a);
120 }
121
122 // Add analyses
123 for (const std::string& a : m_analysisNames) {
124 ATH_MSG_INFO("Loading Rivet analysis " << a);
125 m_analysisHandler->addAnalysis(a);
126 Rivet::Log::setLevel("Rivet.Analysis."+a, rivetLevel(msg().level()));
127 }
128
129 // Initialise Rivet
130 // m_analysisHandler->init();
131
132 //load a pre-existing yoda file to initialize histograms
133 if (m_preload!= "") {
134 m_analysisHandler->readData(m_preload);
135 }
136
137 return StatusCode::SUCCESS;
138}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t a
Rivet::Log::Level rivetLevel(MSG::Level gaudiLevel)
Definition LogLevels.h:21
std::string getenv_str(const std::string &key)
Definition Rivet_i.cxx:61
MsgStream & msg
Definition testRead.cxx:32

◆ cmpGenParticleByEDesc()

bool cmpGenParticleByEDesc ( HepMC::ConstGenParticlePtr a,
HepMC::ConstGenParticlePtr b )

Helper function to sort GenParticles by descending energy.

Todo
Move into GeneratorUtils (with many friends)

Definition at line 249 of file Rivet_i.cxx.

249 {
250 return a->momentum().e() > b->momentum().e();
251}

◆ getenv_str()

std::string getenv_str ( const std::string & key)

Definition at line 61 of file Rivet_i.cxx.

61 {
62 char const* val = getenv(key.c_str());
63 return val == NULL ? std::string() : std::string(val);
64}
STL class.
std::string getenv(const std::string &variableName)
get an environment variable
STL namespace.

◆ split()

std::vector< std::string > split ( const std::string & input,
const std::string & regex )
inline

Definition at line 253 of file Rivet_i.cxx.

253 {
254 // passing -1 as the submatch index parameter performs splitting
255 std::regex re(regex);
256 std::sregex_token_iterator
257 first{input.begin(), input.end(), re, -1},
258 last;
259 return {first, last};
260}
const boost::regex re(r_e)
bool first
Definition DeMoScan.py:534