ATLAS Offline Software
Functions
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. More...
 
bool cmpGenParticleByEDesc (HepMC::ConstGenParticlePtr a, HepMC::ConstGenParticlePtr b)
 Helper function to sort GenParticles by descending energy. More...
 
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 ( )
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  m_analysisHandler = new Rivet::AnalysisHandler(m_runname);
93  assert(m_analysisHandler);
94 
95  #if RIVET_VERSION_CODE >= 40000
96  m_analysisHandler->setCheckBeams(!m_ignorebeams); //< Whether to do beam ID/energy consistency checks
97  m_analysisHandler->matchWeightNames(m_matchWeights); //< Only run on a subset of the multi-weights
98  m_analysisHandler->unmatchWeightNames(m_unmatchWeights); //< Veto a subset of the multi-weights
99  #else
100  m_analysisHandler->setIgnoreBeams(m_ignorebeams); //< Whether to do beam ID/energy consistency checks
101  m_analysisHandler->selectMultiWeights(m_matchWeights); //< Only run on a subset of the multi-weights
102  m_analysisHandler->deselectMultiWeights(m_unmatchWeights); //< Veto a subset of the multi-weights
103  #endif
104  m_analysisHandler->skipMultiWeights(m_skipweights); //< Only run on the nominal weight
105  m_analysisHandler->setNominalWeightName(m_nominalWeightName);
106  if (m_weightcap>0) m_analysisHandler->setWeightCap(m_weightcap);
107 
108  // Set Rivet native log level to match Athena
109  Rivet::Log::setLevel("Rivet", rivetLevel(msg().level()));
110 
111  // Get all available analysis names
112  if (msgLvl(MSG::VERBOSE)) {
113  std::vector<std::string> analysisNames = Rivet::AnalysisLoader::analysisNames();
114  ATH_MSG_VERBOSE("List of available Rivet analyses:");
115  for (const std::string& a : analysisNames) ATH_MSG_VERBOSE(" " + a);
116  }
117 
118  // Add analyses
119  for (const std::string& a : m_analysisNames) {
120  ATH_MSG_INFO("Loading Rivet analysis " << a);
121  m_analysisHandler->addAnalysis(a);
122  Rivet::Log::setLevel("Rivet.Analysis."+a, rivetLevel(msg().level()));
123  }
124 
125  // Initialise Rivet
126  // m_analysisHandler->init();
127 
128  //load a pre-existing yoda file to initialize histograms
129  if (m_preload!= "") {
130  m_analysisHandler->readData(m_preload);
131  }
132 
133  return StatusCode::SUCCESS;
134 }

◆ 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 245 of file Rivet_i.cxx.

245  {
246  return a->momentum().e() > b->momentum().e();
247 }

◆ 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 }

◆ split()

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

Definition at line 249 of file Rivet_i.cxx.

249  {
250  // passing -1 as the submatch index parameter performs splitting
252  std::sregex_token_iterator
253  first{input.begin(), input.end(), re, -1},
254  last;
255  return {first, last};
256 }
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
rivetLevel
Rivet::Log::Level rivetLevel(MSG::Level gaudiLevel)
Definition: LogLevels.h:21
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
pool::DbPrintLvl::setLevel
void setLevel(MsgLevel l)
Definition: DbPrint.h:32
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
get_generator_info.version
version
Definition: get_generator_info.py:33
a
TList * a
Definition: liststreamerinfos.cxx:10
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
getenv_str
std::string getenv_str(const std::string &key)
Definition: Rivet_i.cxx:61
DeMoScan.first
bool first
Definition: DeMoScan.py:536
re
const boost::regex re(r_e)
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37