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

66  {
67  // ^ use of setenv
68  ATH_MSG_INFO("Using Rivet version " << Rivet::version());
69 
70  ATH_CHECK(m_evtInfoKey.initialize());
71 
72  // Get tool for xAOD::Truth to HepMC::GenEvent conversion
73  ATH_CHECK(m_xAODtoHepMCTool.retrieve());
74 
75 
76  // Set RIVET_ANALYSIS_PATH based on alg setup
77 
78  // First set (overwrite, if necessary) the RIVET_ANALYSIS_PATH variable
79  std::string env_rap(getenv_str("RIVET_ANALYSIS_PATH"));
80  if (m_anapath.size() > 0) {
81  ATH_MSG_INFO("Setting Rivet plugin analyses loader env path: " << m_anapath);
82  if (!env_rap.empty()) ATH_MSG_INFO("Overwriting environment's RIVET_ANALYSIS_PATH = " << env_rap << "!");
83  setenv("RIVET_ANALYSIS_PATH", m_anapath.c_str(), 1);
84  }
85 
86  // Now horrid runtime ATLAS env variable and CMT path mangling to work out the std analysis plugin search paths
87  std::vector<std::string> anapaths;
88  const std::string cmtpath = getenv_str("CMTPATH");
89  if (cmtpath.empty()) {
90  ATH_MSG_WARNING("$CMTPATH variable not set: finding the main analysis plugin directory will be difficult...");
91  } else {
92  std::vector<std::string> cmtpaths;
93  std::stringstream ss(cmtpath);
94  std::string item;
95  while (std::getline(ss, item, ':')) {
96  cmtpaths.push_back(std::move(item));
97  }
98  const std::string cmtconfig = getenv_str("CMTCONFIG");
99  if (cmtconfig.empty()) {
100  ATH_MSG_WARNING("$CMTCONFIG variable not set: finding the main analysis plugin directory will be difficult...");
101  }
102  else {
103  const std::string libpath = "/InstallArea/" + cmtconfig + "/lib";
104  for (const std::string& p : cmtpaths) {
105  const std::string cmtlibpath = p + libpath;
106  if (PathResolver::find_file_from_list("RivetMCAnalyses.so", cmtlibpath).empty()) continue;
107  ATH_MSG_INFO("Appending " + cmtlibpath + " to default Rivet analysis search path");
108  anapaths.push_back(cmtlibpath);
109  break;
110  }
111  }
112  }
113 
114  // Then re-grab RIVET_ANALYSIS_PATH and append all the discovered std plugin paths to it
115  std::string anapathstr = getenv_str("RIVET_ANALYSIS_PATH");
116  for (const std::string& ap : anapaths) {
117  if (anapathstr.size() > 0) anapathstr += ":";
118  anapathstr += ap;
119  }
120  setenv("RIVET_ANALYSIS_PATH", anapathstr.c_str(), 1);
121 
122  // Get the final form of RIVET_ANALYSIS_PATH and talk about it. Phew.
123  env_rap = getenv_str("RIVET_ANALYSIS_PATH");
124  if (!env_rap.empty()) ATH_MSG_DEBUG("Loading Rivet plugin analyses from env path: " << env_rap);
125 
126  // Set up analysis handler
127  m_analysisHandler = new Rivet::AnalysisHandler(m_runname);
128  assert(m_analysisHandler);
129 
130  #if RIVET_VERSION_CODE >= 40000
131  m_analysisHandler->setCheckBeams(!m_ignorebeams); //< Whether to do beam ID/energy consistency checks
132  m_analysisHandler->matchWeightNames(m_matchWeights); //< Only run on a subset of the multi-weights
133  m_analysisHandler->unmatchWeightNames(m_unmatchWeights); //< Veto a subset of the multi-weights
134  #else
135  m_analysisHandler->setIgnoreBeams(m_ignorebeams); //< Whether to do beam ID/energy consistency checks
136  m_analysisHandler->selectMultiWeights(m_matchWeights); //< Only run on a subset of the multi-weights
137  m_analysisHandler->deselectMultiWeights(m_unmatchWeights); //< Veto a subset of the multi-weights
138  #endif
139  m_analysisHandler->skipMultiWeights(m_skipweights); //< Only run on the nominal weight
140  m_analysisHandler->setNominalWeightName(m_nominalWeightName);
141  if (m_weightcap>0) m_analysisHandler->setWeightCap(m_weightcap);
142 
143  // Set Rivet native log level to match Athena
144  Rivet::Log::setLevel("Rivet", rivetLevel(msg().level()));
145 
146  // Get all available analysis names
147  if (msgLvl(MSG::VERBOSE)) {
148  std::vector<std::string> analysisNames = Rivet::AnalysisLoader::analysisNames();
149  ATH_MSG_VERBOSE("List of available Rivet analyses:");
150  for (const std::string& a : analysisNames) ATH_MSG_VERBOSE(" " + a);
151  }
152 
153  // Add analyses
154  for (const std::string& a : m_analysisNames) {
155  ATH_MSG_INFO("Loading Rivet analysis " << a);
156  m_analysisHandler->addAnalysis(a);
157  Rivet::Log::setLevel("Rivet.Analysis."+a, rivetLevel(msg().level()));
158  }
159 
160  // Initialise Rivet
161  // m_analysisHandler->init();
162 
163  //load a pre-existing yoda file to initialize histograms
164  if (m_preload!= "") {
165  m_analysisHandler->readData(m_preload);
166  }
167 
168  return StatusCode::SUCCESS;
169 }

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

280  {
281  return a->momentum().e() > b->momentum().e();
282 }

◆ getenv_str()

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

Definition at line 60 of file Rivet_i.cxx.

60  {
61  char const* val = getenv(key.c_str());
62  return val == NULL ? std::string() : std::string(val);
63 }

◆ split()

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

Definition at line 284 of file Rivet_i.cxx.

284  {
285  // passing -1 as the submatch index parameter performs splitting
287  std::sregex_token_iterator
288  first{input.begin(), input.end(), re, -1},
289  last;
290  return {first, last};
291 }
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
python.AtlRunQueryParser.ap
ap
Definition: AtlRunQueryParser.py:826
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
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
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
getCastorRun.setenv
def setenv()
Definition: getCastorRun.py:9
PathResolver::find_file_from_list
static std::string find_file_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:281
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
item
Definition: ItemListSvc.h:43
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
getenv_str
std::string getenv_str(const std::string &key)
Definition: Rivet_i.cxx:60
DeMoScan.first
bool first
Definition: DeMoScan.py:534
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