ATLAS Offline Software
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Rivet_i Class Reference

Interface to the Rivet analysis package. More...

#include <Rivet_i.h>

Inheritance diagram for Rivet_i:
Collaboration diagram for Rivet_i:

Public Member Functions

 Rivet_i (const std::string &name, ISvcLocator *pSvcLocator)
 Standard algorithm constructor. More...
 
virtual StatusCode initialize ATLAS_NOT_THREAD_SAFE () override
 Initialise the Rivet interface and Athena services. More...
 
virtual StatusCode execute () override
 Run the Rivet analyses on one event, which is retrieved from StoreGate. More...
 
virtual StatusCode finalize () override
 Finalise each analysis and commit the plots to an AIDA tree and the THistSvc ROOT tree. More...
 
virtual StatusCode sysInitialize () override
 Override sysInitialize. More...
 
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies. More...
 
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc. More...
 
const ServiceHandle< StoreGateSvc > & evtStore () const
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc. More...
 
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc. More...
 
virtual StatusCode sysStart () override
 Handle START transition. More...
 
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles. More...
 
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles. More...
 
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T > &t)
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, SG::VarHandleKey &hndl, const std::string &doc, const SG::VarHandleKeyType &)
 Declare a new Gaudi property. More...
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, SG::VarHandleBase &hndl, const std::string &doc, const SG::VarHandleType &)
 Declare a new Gaudi property. More...
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, SG::VarHandleKeyArray &hndArr, const std::string &doc, const SG::VarHandleKeyArrayType &)
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, T &property, const std::string &doc, const SG::NotHandleType &)
 Declare a new Gaudi property. More...
 
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, T &property, const std::string &doc="none")
 Declare a new Gaudi property. More...
 
void updateVHKA (Gaudi::Details::PropertyBase &)
 
MsgStream & msg () const
 
MsgStream & msg (const MSG::Level lvl) const
 
bool msgLvl (const MSG::Level lvl) const
 

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution More...
 
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
 
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed. More...
 

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t
 

Private Member Functions

std::unique_ptr< HepMC::GenEvent > checkEvent (const HepMC::GenEvent &event, const EventContext &ctx)
 Book an AIDA::IDataPointSet into the THistSvc as a TH1D at path. More...
 
void MeV2GeV (HepMC::GenEvent &event)
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey> More...
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleKeyArrayType &)
 specialization for handling Gaudi::Property<SG::VarHandleKeyArray> More...
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleType &)
 specialization for handling Gaudi::Property<SG::VarHandleBase> More...
 
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T > &t, const SG::NotHandleType &)
 specialization for handling everything that's not a Gaudi::Property<SG::VarHandleKey> or a <SG::VarHandleKeyArray> More...
 

Private Attributes

std::string m_stream
 A pointer to the THistSvc. More...
 
std::string m_file
 The base file name to write results to. More...
 
std::string m_preload
 
std::string m_anapath
 The analysis plugin search path. More...
 
bool m_ignorebeams
 Whether to avoid the beam consistency checks. More...
 
bool m_needsConversion
 Do we need to convert xAOD::Truth back to HepMC::GenEvemt? More...
 
bool m_patchBeams
 Flag to insert beam protons when they are unavailable in the event. More...
 
ToolHandle< IxAODtoHepMCToolm_xAODtoHepMCTool {this, "HepMCTool", "xAODtoHepMCTool"}
 A tool to convert xAOD::Truth to HepMC::GenEvent. More...
 
bool m_doRootHistos
 Will we convert Rivet's internal histo format into a ROOT histo for streaming with THistSvc? More...
 
std::string m_runname
 The name of the run (prepended to plot paths). More...
 
std::string m_genEventKey
 The GenEvent StoreGate key (default "GEN_EVENT") More...
 
Rivet::AnalysisHandler * m_analysisHandler
 A Rivet analysis handler. More...
 
std::vector< std::string > m_analysisNames
 A list of names of the analyses to run (set from the job properties) More...
 
double m_crossSection
 The cross section for this run of events, set from the job properties. More...
 
double m_crossSection_uncert
 The uncertainity of the cross section for this run of events, set from the job properties. More...
 
bool m_init
 Flag to determine whether Rivet init has already happened (in execute()) More...
 
bool m_skipweights
 Skip variation weights and only run nominal. More...
 
std::string m_matchWeights
 String of weight names (or regex) to select multiweights. More...
 
std::string m_unmatchWeights
 String of weight names (or regex) to veto multiweights. More...
 
std::string m_nominalWeightName
 String to specify non-standard nominal weight. More...
 
double m_weightcap
 Weight cap to set allowed maximum for weights. More...
 
SG::ReadHandleKey< xAOD::EventInfom_evtInfoKey
 
DataObjIDColl m_extendedExtraObjects
 
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default) More...
 
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default) More...
 
std::vector< SG::VarHandleKeyArray * > m_vhka
 
bool m_varHandleArraysDeclared
 

Detailed Description

Interface to the Rivet analysis package.

Author
James Monk jmonk.nosp@m.@cer.nosp@m.n.ch
Andy Buckley andy..nosp@m.buck.nosp@m.ley@c.nosp@m.ern..nosp@m.ch
Christian Gutschow chris.nosp@m..g@c.nosp@m.ern.c.nosp@m.h

Definition at line 31 of file Rivet_i.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< Algorithm > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ Rivet_i()

Rivet_i::Rivet_i ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Standard algorithm constructor.

Convert to inherit from GenBase, now we're developing Rivet 2 interfacing for R19+ only.

Definition at line 35 of file Rivet_i.cxx.

35  :
36  AthAlgorithm(name, pSvcLocator),
38  m_init(false)
39 {
40  // Options
41  declareProperty("McEventKey", m_genEventKey="GEN_EVENT");
42  declareProperty("Analyses", m_analysisNames);
43  declareProperty("CrossSection", m_crossSection=0.0);
44  declareProperty("CrossSectionUncertainty", m_crossSection_uncert=0.0);
45  declareProperty("Stream", m_stream="/Rivet");
46  declareProperty("RunName", m_runname="");
47  declareProperty("HistoFile", m_file="Rivet.yoda.gz");
48  declareProperty("HistoPreload", m_preload="");
49  declareProperty("AnalysisPath", m_anapath="");
50  declareProperty("IgnoreBeamCheck", m_ignorebeams=false);
51  declareProperty("DoRootHistos", m_doRootHistos=false);
52  declareProperty("SkipWeights", m_skipweights=false);
53  declareProperty("MatchWeights", m_matchWeights="");
54  declareProperty("UnmatchWeights", m_unmatchWeights="");
55  declareProperty("NominalWeightName", m_nominalWeightName="");
56  declareProperty("WeightCap", m_weightcap=-1.0);
57  declareProperty("AddMissingBeamParticles",m_patchBeams=false);
58 }

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

virtual StatusCode initialize Rivet_i::ATLAS_NOT_THREAD_SAFE ( )
overridevirtual

Initialise the Rivet interface and Athena services.

Pass a list of analyses to the Rivet AnalysisHandler, which dynamically loads the necessary libraries (including user-written analyses).

◆ checkEvent()

std::unique_ptr< HepMC::GenEvent > Rivet_i::checkEvent ( const HepMC::GenEvent &  event,
const EventContext &  ctx 
)
private

Book an AIDA::IDataPointSet into the THistSvc as a TH1D at path.

Parameters
pathBook an AIDA::IDataPointSet into the THistSvc as a TGraph at path
path

Definition at line 293 of file Rivet_i.cxx.

293  {
294  auto modEvent = std::make_unique<HepMC::GenEvent>(event);
295 
296  if (!m_needsConversion) {
297  // overwrite the HEPMC dummy event number with the proper ATLAS event number
299  modEvent->set_event_number(static_cast<int>(evtInfo->eventNumber()));
300  }
301 
302  // weight-name cleaning
303 #ifdef HEPMC3
304  std::shared_ptr<HepMC3::GenRunInfo> modRunInfo;
305  if (event.run_info()) {
306  modRunInfo = std::make_shared<HepMC3::GenRunInfo>(*(event.run_info().get()));
307  if (event.run_info()->weight_names().empty() && event.weights().size() == 1) {
308  modRunInfo->set_weight_names({"Default"});
309  }
310  }
311  else {
312  ATH_MSG_DEBUG("No run info, event weights size is " << event.weights().size() );
313  modRunInfo = std::make_shared<HepMC3::GenRunInfo>();
314  std::vector<std::string> w_names;
315  for (size_t i = 0; i < event.weights().size(); i++) { w_names.push_back(std::string("badweight") + std::to_string(i)); }
316  modRunInfo->set_weight_names(w_names);
317  }
318  modEvent->set_run_info(modRunInfo);
319  std::vector<std::string> w_names = modEvent->weight_names();
320  if (w_names.size()) {
321  std::vector<std::pair<std::string,std::string> > w_subs = {
322  {" nominal ",""},
323  {" set = ","_"},
324  {" = ","_"},
325  {"=",""},
326  {",",""},
327  {".",""},
328  {":",""},
329  {" ","_"},
330  {"#","num"},
331  {"\n","_"},
332  {"/","over"}
333  };
334  for (std::string& wname : w_names) {
335  for (const auto& sub : w_subs) {
336  size_t start_pos = wname.find(sub.first);
337  while (start_pos != std::string::npos) {
338  wname.replace(start_pos, sub.first.length(), sub.second);
339  start_pos = wname.find(sub.first);
340  }
341  }
342  }
343  modEvent->run_info()->set_weight_names(w_names);
344  }
345 #else
346  const HepMC::WeightContainer& old_wc = event.weights();
347  std::vector<std::string> old_wnames = old_wc.weight_names();
348  if (old_wnames.size()) {
349  HepMC::WeightContainer& new_wc = modEvent->weights();
350  new_wc.clear();
351  std::vector<std::pair<std::string,std::string> > w_subs = {
352  {" nominal ",""},
353  {" set = ","_"},
354  {" = ","_"},
355  {"=",""},
356  {",",""},
357  {".",""},
358  {":",""},
359  {" ","_"},
360  {"#","num"},
361  {"\n","_"},
362  {"/","over"}
363  };
364  std::map<std::string, double> new_name_to_value;
365  std::map<std::string, std::string> old_name_to_new_name;
366  for (const std::string& old_name : old_wnames) {
367  std::string wname = std::string(old_name);
368  double value = old_wc[old_name];
369  for (const auto& sub : w_subs) {
370  size_t start_pos = wname.find(sub.first);
371  while (start_pos != std::string::npos) {
372  wname.replace(start_pos, sub.first.length(), sub.second);
373  start_pos = wname.find(sub.first);
374  }
375  }
376  new_name_to_value[wname] = value;
377  old_name_to_new_name[old_name] = wname;
378  }
379  auto itEnd = old_name_to_new_name.end();
380  for (const std::string& old_name : old_wnames) {
381  if (old_name_to_new_name.find(old_name) == itEnd) continue;
382  const std::string& new_name = old_name_to_new_name[old_name];
383  new_wc[ new_name ] = new_name_to_value[new_name];
384  }
385  // end of weight-name cleaning
386  }
387 #endif
388 
389 #ifdef HEPMC3
390  modEvent->set_units(HepMC3::Units::GEV, HepMC3::Units::MM);
391  if (modEvent->particles().size() == 1) modEvent->set_beam_particles(modEvent->particles().front(), modEvent->particles().front());
392  if (m_patchBeams) {
393  // workaround in case beam particles were missing in xAOD::Truth
394  // first work out centre-of-mass energy
395  double etotal = 0;
396  for (const auto& p : modEvent->particles()) {
397  if (!MC::isStable(p)) continue;
398  etotal += p->momentum().e();
399  }
400  const double ebeam = 0.5*etotal;
401  // create dummy beam particles
402  HepMC::GenParticlePtr b1 = std::make_shared<HepMC::GenParticle>(HepMC::FourVector(0,0,ebeam,ebeam),2212,4);
403  HepMC::GenParticlePtr b2 = std::make_shared<HepMC::GenParticle>(HepMC::FourVector(0,0,-1*ebeam,ebeam),2212,4);
404  // remove particles incorrectly labelled as beam particles
405  std::vector<HepMC::GenParticlePtr> notBeams;
406  for (const HepMC::GenParticlePtr& p : modEvent->beams()) {
407  if (!MC::isBeam(p)) notBeams.push_back(p);
408  }
409  //AV: the loop is over shared pointers! Should be const auto&
410  for (const auto& bp : notBeams) bp->production_vertex()->remove_particle_out(bp);
411  // add dummy beam particles
412  modEvent->set_beam_particles(b1, b2);
413  }
414  if (modEvent->beams().front()->momentum().e() > 50000.0) {
415  MeV2GeV(*modEvent);
416  }
417 #else
418  modEvent->use_units(HepMC::Units::GEV, HepMC::Units::MM);
419  if (modEvent->particles_size() == 1) modEvent->set_beam_particles(*modEvent->particles_begin(), *modEvent->particles_begin());
420  if (modEvent->beam_particles().first->momentum().e() > 50000.0) {
421  MeV2GeV(*modEvent);
422  }
423 #endif
424 
425  return modEvent;
426 }

◆ declareGaudiProperty() [1/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T > &  hndl,
const SG::VarHandleKeyArrayType  
)
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKeyArray>

Definition at line 170 of file AthCommonDataStore.h.

172  {
173  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
174  hndl.value(),
175  hndl.documentation());
176 
177  }

◆ declareGaudiProperty() [2/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T > &  hndl,
const SG::VarHandleKeyType  
)
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158  {
159  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
160  hndl.value(),
161  hndl.documentation());
162 
163  }

◆ declareGaudiProperty() [3/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T > &  hndl,
const SG::VarHandleType  
)
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleBase>

Definition at line 184 of file AthCommonDataStore.h.

186  {
187  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
188  hndl.value(),
189  hndl.documentation());
190  }

◆ declareGaudiProperty() [4/4]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T > &  t,
const SG::NotHandleType  
)
inlineprivateinherited

specialization for handling everything that's not a Gaudi::Property<SG::VarHandleKey> or a <SG::VarHandleKeyArray>

Definition at line 199 of file AthCommonDataStore.h.

200  {
201  return PBASE::declareProperty(t);
202  }

◆ declareProperty() [1/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( const std::string &  name,
SG::VarHandleBase hndl,
const std::string &  doc,
const SG::VarHandleType  
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
hndlObject holding the property value.
docDocumentation string for the property.

This is the version for types that derive from SG::VarHandleBase. The property value object is put on the input and output lists as appropriate; then we forward to the base class.

Definition at line 245 of file AthCommonDataStore.h.

249  {
250  this->declare(hndl.vhKey());
251  hndl.vhKey().setOwner(this);
252 
253  return PBASE::declareProperty(name,hndl,doc);
254  }

◆ declareProperty() [2/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( const std::string &  name,
SG::VarHandleKey hndl,
const std::string &  doc,
const SG::VarHandleKeyType  
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
hndlObject holding the property value.
docDocumentation string for the property.

This is the version for types that derive from SG::VarHandleKey. The property value object is put on the input and output lists as appropriate; then we forward to the base class.

Definition at line 221 of file AthCommonDataStore.h.

225  {
226  this->declare(hndl);
227  hndl.setOwner(this);
228 
229  return PBASE::declareProperty(name,hndl,doc);
230  }

◆ declareProperty() [3/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( const std::string &  name,
SG::VarHandleKeyArray hndArr,
const std::string &  doc,
const SG::VarHandleKeyArrayType  
)
inlineinherited

Definition at line 259 of file AthCommonDataStore.h.

263  {
264 
265  // std::ostringstream ost;
266  // ost << Algorithm::name() << " VHKA declareProp: " << name
267  // << " size: " << hndArr.keys().size()
268  // << " mode: " << hndArr.mode()
269  // << " vhka size: " << m_vhka.size()
270  // << "\n";
271  // debug() << ost.str() << endmsg;
272 
273  hndArr.setOwner(this);
274  m_vhka.push_back(&hndArr);
275 
276  Gaudi::Details::PropertyBase* p = PBASE::declareProperty(name, hndArr, doc);
277  if (p != 0) {
278  p->declareUpdateHandler(&AthCommonDataStore<PBASE>::updateVHKA, this);
279  } else {
280  ATH_MSG_ERROR("unable to call declareProperty on VarHandleKeyArray "
281  << name);
282  }
283 
284  return p;
285 
286  }

◆ declareProperty() [4/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( const std::string &  name,
T &  property,
const std::string &  doc,
const SG::NotHandleType  
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
propertyObject holding the property value.
docDocumentation string for the property.

This is the generic version, for types that do not derive from SG::VarHandleKey. It just forwards to the base class version of declareProperty.

Definition at line 333 of file AthCommonDataStore.h.

337  {
338  return PBASE::declareProperty(name, property, doc);
339  }

◆ declareProperty() [5/6]

Gaudi::Details::PropertyBase* AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( const std::string &  name,
T &  property,
const std::string &  doc = "none" 
)
inlineinherited

Declare a new Gaudi property.

Parameters
nameName of the property.
propertyObject holding the property value.
docDocumentation string for the property.

This dispatches to either the generic declareProperty or the one for VarHandle/Key/KeyArray.

Definition at line 352 of file AthCommonDataStore.h.

355  {
356  typedef typename SG::HandleClassifier<T>::type htype;
357  return declareProperty (name, property, doc, htype());
358  }

◆ declareProperty() [6/6]

Gaudi::Details::PropertyBase& AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( Gaudi::Property< T > &  t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145  {
146  typedef typename SG::HandleClassifier<T>::type htype;
148  }

◆ detStore()

const ServiceHandle<StoreGateSvc>& AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

95 { return m_detStore; }

◆ evtStore() [1/2]

ServiceHandle<StoreGateSvc>& AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

85 { return m_evtStore; }

◆ evtStore() [2/2]

const ServiceHandle<StoreGateSvc>& AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore ( ) const
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 90 of file AthCommonDataStore.h.

90 { return m_evtStore; }

◆ execute()

StatusCode Rivet_i::execute ( )
overridevirtual

Run the Rivet analyses on one event, which is retrieved from StoreGate.

Todo:
Replace with new GenBase functionality
Todo:
Actually use back(), for the most recent event, or throw an exception if more than one event found?
Todo:
Replace with new GenBase const_event() functionality

Definition at line 172 of file Rivet_i.cxx.

172  {
173  ATH_MSG_DEBUG("Rivet_i execute");
174 
175  const EventContext& ctx = getContext();
176 
178  ATH_MSG_DEBUG("Rivet_i needs xAOD::Truth to HepMC::GenEvent conversion? " << m_needsConversion);
179 
180  std::unique_ptr<HepMC::GenEvent> checkedEvent;
181  if (m_needsConversion) {
182  const xAOD::TruthEventContainer* truthCollection = nullptr;
183  if (evtStore()->retrieve(truthCollection, "TruthEvents").isFailure()) {
184  ATH_MSG_ERROR("Could not retrieve TruthEvents collection, aborting.");
185  return StatusCode::FAILURE;
186  }
187 
189  ATH_MSG_DEBUG("Attempt xAOD::Truth to HepMC::GenEvent conversion.");
190  std::vector<HepMC::GenEvent>&& hepmc_evts = m_xAODtoHepMCTool->getHepMCEvents(truthCollection, eventInfo.cptr());
191 
192  if (hepmc_evts.empty()) {
193  ATH_MSG_ERROR("Conversion didn't yield HepMC::GenEvent, aborting.");
194  return StatusCode::FAILURE;
195  }
196  checkedEvent = checkEvent(std::move(hepmc_evts[0]), ctx);
197  }
198  else {
199  // Get the event collection
201  const McEventCollection* eventCollection = nullptr;
202  StatusCode sc = evtStore()->retrieve(eventCollection, m_genEventKey);
203  if (sc.isFailure() || eventCollection == 0) {
204  ATH_MSG_ERROR("Unable to retrieve event collection from StoreGate with key " << m_genEventKey);
205  return StatusCode::FAILURE;
206  } else {
207  ATH_MSG_DEBUG("Retrieved event collection from StoreGate with key " << m_genEventKey);
208  }
209 
210  // Get the first event in the event collection
213  const HepMC::GenEvent* event = eventCollection->front();
214  if (event == nullptr) {
215  ATH_MSG_ERROR("Rivet_i received a null HepMC event");
216  return StatusCode::FAILURE;
217  }
218 
219  // Modify the event units etc. if necessary
220  checkedEvent = checkEvent(*event, ctx);
221  }
222 
223  if(!checkedEvent) {
224  ATH_MSG_ERROR("Check on HepMC event failed!");
225  return StatusCode::FAILURE;
226  }
227 
228  // Initialize Rivet (on the first event only)
229  if (!m_init) {
230  m_analysisHandler->init(*checkedEvent);
231  m_init = true;
232  }
233 
234  // Analyse the event
235  m_analysisHandler->analyze(*checkedEvent);
236 
237  return StatusCode::SUCCESS;
238 }

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase &  ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ extraOutputDeps()

const DataObjIDColl & AthAlgorithm::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 50 of file AthAlgorithm.cxx.

51 {
52  // If we didn't find any symlinks to add, just return the collection
53  // from the base class. Otherwise, return the extended collection.
54  if (!m_extendedExtraObjects.empty()) {
56  }
57  return Algorithm::extraOutputDeps();
58 }

◆ finalize()

StatusCode Rivet_i::finalize ( )
overridevirtual

Finalise each analysis and commit the plots to an AIDA tree and the THistSvc ROOT tree.

Definition at line 241 of file Rivet_i.cxx.

241  {
242  ATH_MSG_INFO("Rivet_i finalizing");
243 
244  // Setting cross-section in Rivet
245  // If no user-specified cross-section available,
246  // take whatever is in the GenEvent
248 
249  // Call Rivet finalize
250  m_analysisHandler->finalize();
251 
252 
253 
254  // Write out YODA file (add .yoda suffix if missing)
255  if (m_file.find(".yoda") == std::string::npos) m_file += ".yoda.gz";
256  auto pos = m_file.find(".gz.");
257  if (pos == std::string::npos) {
258  m_analysisHandler->writeData(m_file);
259  }
260  else {//filename is e.g. something.yoda.gz.1
261  //write to output file name without the ".1"
262  m_analysisHandler->writeData(m_file.substr(0, pos)+".gz");
263  // then rename it as the requested output filename
264  if (std::rename((m_file.substr(0, pos)+".gz").c_str(), m_file.c_str()) !=0) {
265  std::string error_msg = "Impossible to rename ";
266  error_msg += m_file.substr(0, pos)+".gz";
267  error_msg += " as ";
268  error_msg += m_file;
269  ATH_MSG_ERROR(error_msg.c_str());
270  return StatusCode::FAILURE;
271  }
272  }
273 
274  return StatusCode::SUCCESS;
275 }

◆ inputHandles()

virtual std::vector<Gaudi::DataHandle*> AthCommonDataStore< AthCommonMsg< Algorithm > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ MeV2GeV()

void Rivet_i::MeV2GeV ( HepMC::GenEvent &  event)
private

Definition at line 428 of file Rivet_i.cxx.

428  {
429 #ifdef HEPMC3
430  for (auto& p: evt.particles()) {
431  p->set_momentum(p->momentum()*0.001);
432 #else
433  for (HepMC::GenParticlePtr p: evt) {
434  const HepMC::FourVector& mom = p->momentum();
435  p->set_momentum(HepMC::FourVector (mom.px()*0.001,
436  mom.py()*0.001,
437  mom.pz()*0.001,
438  mom.e()*0.001));
439 #endif
440  p->set_generated_mass(p->generated_mass()*0.001);
441  }
442 }

◆ msg() [1/2]

MsgStream& AthCommonMsg< Algorithm >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24  {
25  return this->msgStream();
26  }

◆ msg() [2/2]

MsgStream& AthCommonMsg< Algorithm >::msg ( const MSG::Level  lvl) const
inlineinherited

Definition at line 27 of file AthCommonMsg.h.

27  {
28  return this->msgStream(lvl);
29  }

◆ msgLvl()

bool AthCommonMsg< Algorithm >::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30  {
31  return this->msgLevel(lvl);
32  }

◆ outputHandles()

virtual std::vector<Gaudi::DataHandle*> AthCommonDataStore< AthCommonMsg< Algorithm > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ renounce()

std::enable_if_t<std::is_void_v<std::result_of_t<decltype(&T::renounce)(T)> > && !std::is_base_of_v<SG::VarHandleKeyArray, T> && std::is_base_of_v<Gaudi::DataHandle, T>, void> AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce ( T &  h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381  {
382  h.renounce();
383  PBASE::renounce (h);
384  }

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::renounceArray ( SG::VarHandleKeyArray handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364  {
365  handlesArray.renounce();
366  }

◆ sysInitialize()

StatusCode AthAlgorithm::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthCommonDataStore< AthCommonMsg< Algorithm > >.

Reimplemented in AthAnalysisAlgorithm, AthFilterAlgorithm, PyAthena::Alg, and AthHistogramAlgorithm.

Definition at line 66 of file AthAlgorithm.cxx.

66  {
68 
69  if (sc.isFailure()) {
70  return sc;
71  }
72  ServiceHandle<ICondSvc> cs("CondSvc",name());
73  for (auto h : outputHandles()) {
74  if (h->isCondition() && h->mode() == Gaudi::DataHandle::Writer) {
75  // do this inside the loop so we don't create the CondSvc until needed
76  if ( cs.retrieve().isFailure() ) {
77  ATH_MSG_WARNING("no CondSvc found: won't autoreg WriteCondHandles");
78  return StatusCode::SUCCESS;
79  }
80  if (cs->regHandle(this,*h).isFailure()) {
81  sc = StatusCode::FAILURE;
82  ATH_MSG_ERROR("unable to register WriteCondHandle " << h->fullKey()
83  << " with CondSvc");
84  }
85  }
86  }
87  return sc;
88 }

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Algorithm > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::updateVHKA ( Gaudi::Details::PropertyBase &  )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308  {
309  // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310  // << " size: " << m_vhka.size() << endmsg;
311  for (auto &a : m_vhka) {
312  std::vector<SG::VarHandleKey*> keys = a->keys();
313  for (auto k : keys) {
314  k->setOwner(this);
315  }
316  }
317  }

Member Data Documentation

◆ m_analysisHandler

Rivet::AnalysisHandler* Rivet_i::m_analysisHandler
private

A Rivet analysis handler.

Definition at line 113 of file Rivet_i.h.

◆ m_analysisNames

std::vector<std::string> Rivet_i::m_analysisNames
private

A list of names of the analyses to run (set from the job properties)

Definition at line 116 of file Rivet_i.h.

◆ m_anapath

std::string Rivet_i::m_anapath
private

The analysis plugin search path.

This will be used to internally set RIVET_ANALYSIS_PATH, if not already set in the environment.

Definition at line 80 of file Rivet_i.h.

◆ m_crossSection

double Rivet_i::m_crossSection
private

The cross section for this run of events, set from the job properties.

Definition at line 119 of file Rivet_i.h.

◆ m_crossSection_uncert

double Rivet_i::m_crossSection_uncert
private

The uncertainity of the cross section for this run of events, set from the job properties.

Definition at line 122 of file Rivet_i.h.

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_doRootHistos

bool Rivet_i::m_doRootHistos
private

Will we convert Rivet's internal histo format into a ROOT histo for streaming with THistSvc?

The default is yes Currently (03.01.12) there is no conversion for 2D distributions, in which case you want to set this to False

Definition at line 104 of file Rivet_i.h.

◆ m_evtInfoKey

SG::ReadHandleKey<xAOD::EventInfo> Rivet_i::m_evtInfoKey
private
Initial value:
{this
, "EventInfo"
, "EventInfo"
, "ReadHandleKey for xAOD::EventInfo" }

Definition at line 142 of file Rivet_i.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthAlgorithm::m_extendedExtraObjects
privateinherited

Definition at line 79 of file AthAlgorithm.h.

◆ m_file

std::string Rivet_i::m_file
private

The base file name to write results to.

Definition at line 72 of file Rivet_i.h.

◆ m_genEventKey

std::string Rivet_i::m_genEventKey
private

The GenEvent StoreGate key (default "GEN_EVENT")

Definition at line 110 of file Rivet_i.h.

◆ m_ignorebeams

bool Rivet_i::m_ignorebeams
private

Whether to avoid the beam consistency checks.

Default is false: checks will be made to ensure that the supplied events have beams of the sort that the analysis was written to expect.

Definition at line 86 of file Rivet_i.h.

◆ m_init

bool Rivet_i::m_init
private

Flag to determine whether Rivet init has already happened (in execute())

Definition at line 125 of file Rivet_i.h.

◆ m_matchWeights

std::string Rivet_i::m_matchWeights
private

String of weight names (or regex) to select multiweights.

Definition at line 131 of file Rivet_i.h.

◆ m_needsConversion

bool Rivet_i::m_needsConversion
private

Do we need to convert xAOD::Truth back to HepMC::GenEvemt?

Default is false: assume user runs on EVNT files

Definition at line 91 of file Rivet_i.h.

◆ m_nominalWeightName

std::string Rivet_i::m_nominalWeightName
private

String to specify non-standard nominal weight.

Definition at line 137 of file Rivet_i.h.

◆ m_patchBeams

bool Rivet_i::m_patchBeams
private

Flag to insert beam protons when they are unavailable in the event.

Definition at line 94 of file Rivet_i.h.

◆ m_preload

std::string Rivet_i::m_preload
private

Definition at line 75 of file Rivet_i.h.

◆ m_runname

std::string Rivet_i::m_runname
private

The name of the run (prepended to plot paths).

Definition at line 107 of file Rivet_i.h.

◆ m_skipweights

bool Rivet_i::m_skipweights
private

Skip variation weights and only run nominal.

Definition at line 128 of file Rivet_i.h.

◆ m_stream

std::string Rivet_i::m_stream
private

A pointer to the THistSvc.

The stream name for storing the output plots under (default "/Rivet")

Definition at line 69 of file Rivet_i.h.

◆ m_unmatchWeights

std::string Rivet_i::m_unmatchWeights
private

String of weight names (or regex) to veto multiweights.

Definition at line 134 of file Rivet_i.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< Algorithm > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< Algorithm > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.

◆ m_weightcap

double Rivet_i::m_weightcap
private

Weight cap to set allowed maximum for weights.

Definition at line 140 of file Rivet_i.h.

◆ m_xAODtoHepMCTool

ToolHandle<IxAODtoHepMCTool> Rivet_i::m_xAODtoHepMCTool {this, "HepMCTool", "xAODtoHepMCTool"}
private

A tool to convert xAOD::Truth to HepMC::GenEvent.

Definition at line 97 of file Rivet_i.h.


The documentation for this class was generated from the following files:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Rivet_i::m_init
bool m_init
Flag to determine whether Rivet init has already happened (in execute())
Definition: Rivet_i.h:125
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Rivet_i::m_anapath
std::string m_anapath
The analysis plugin search path.
Definition: Rivet_i.h:80
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Rivet_i::m_patchBeams
bool m_patchBeams
Flag to insert beam protons when they are unavailable in the event.
Definition: Rivet_i.h:94
HepMC::GenParticlePtr
GenParticle * GenParticlePtr
Definition: GenParticle.h:37
Rivet_i::m_xAODtoHepMCTool
ToolHandle< IxAODtoHepMCTool > m_xAODtoHepMCTool
A tool to convert xAOD::Truth to HepMC::GenEvent.
Definition: Rivet_i.h:97
AthCommonDataStore< AthCommonMsg< Algorithm > >::m_evtStore
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
Definition: AthCommonDataStore.h:390
Rivet_i::m_genEventKey
std::string m_genEventKey
The GenEvent StoreGate key (default "GEN_EVENT")
Definition: Rivet_i.h:110
AthCommonDataStore< AthCommonMsg< Algorithm > >::m_vhka
std::vector< SG::VarHandleKeyArray * > m_vhka
Definition: AthCommonDataStore.h:398
MM
@ MM
Definition: RegSelEnums.h:38
athena.value
value
Definition: athena.py:122
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
Rivet_i::m_stream
std::string m_stream
A pointer to the THistSvc.
Definition: Rivet_i.h:69
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SG::VarHandleKeyArray::setOwner
virtual void setOwner(IDataHandleHolder *o)=0
Rivet_i::m_doRootHistos
bool m_doRootHistos
Will we convert Rivet's internal histo format into a ROOT histo for streaming with THistSvc?
Definition: Rivet_i.h:104
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
AthCommonDataStore
Definition: AthCommonDataStore.h:52
AthAlgorithm::sysInitialize
virtual StatusCode sysInitialize() override
Override sysInitialize.
Definition: AthAlgorithm.cxx:66
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Rivet_i::m_needsConversion
bool m_needsConversion
Do we need to convert xAOD::Truth back to HepMC::GenEvemt?
Definition: Rivet_i.h:91
Rivet_i::m_nominalWeightName
std::string m_nominalWeightName
String to specify non-standard nominal weight.
Definition: Rivet_i.h:137
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
AthCommonDataStore< AthCommonMsg< Algorithm > >::outputHandles
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override
Return this algorithm's output handles.
lumiFormat.i
int i
Definition: lumiFormat.py:92
Rivet_i::m_unmatchWeights
std::string m_unmatchWeights
String of weight names (or regex) to veto multiweights.
Definition: Rivet_i.h:134
Rivet_i::MeV2GeV
void MeV2GeV(HepMC::GenEvent &event)
Definition: Rivet_i.cxx:428
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Rivet_i::m_crossSection_uncert
double m_crossSection_uncert
The uncertainity of the cross section for this run of events, set from the job properties.
Definition: Rivet_i.h:122
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
GEV
#define GEV
Definition: PrintPhotonSF.cxx:24
Rivet_i::m_analysisNames
std::vector< std::string > m_analysisNames
A list of names of the analyses to run (set from the job properties)
Definition: Rivet_i.h:116
AthCommonDataStore< AthCommonMsg< Algorithm > >::m_detStore
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)
Definition: AthCommonDataStore.h:393
Rivet_i::m_crossSection
double m_crossSection
The cross section for this run of events, set from the job properties.
Definition: Rivet_i.h:119
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::VarHandleKeyArray::renounce
virtual void renounce()=0
SG::HandleClassifier::type
std::conditional< std::is_base_of< SG::VarHandleKeyArray, T >::value, VarHandleKeyArrayType, type2 >::type type
Definition: HandleClassifier.h:54
merge_scale_histograms.doc
string doc
Definition: merge_scale_histograms.py:9
Rivet_i::m_file
std::string m_file
The base file name to write results to.
Definition: Rivet_i.h:72
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Rivet_i::m_ignorebeams
bool m_ignorebeams
Whether to avoid the beam consistency checks.
Definition: Rivet_i.h:86
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Rivet_i::m_skipweights
bool m_skipweights
Skip variation weights and only run nominal.
Definition: Rivet_i.h:128
AthAlgorithm::m_extendedExtraObjects
DataObjIDColl m_extendedExtraObjects
Definition: AthAlgorithm.h:79
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
Rivet_i::m_matchWeights
std::string m_matchWeights
String of weight names (or regex) to select multiweights.
Definition: Rivet_i.h:131
a
TList * a
Definition: liststreamerinfos.cxx:10
h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Rivet_i::checkEvent
std::unique_ptr< HepMC::GenEvent > checkEvent(const HepMC::GenEvent &event, const EventContext &ctx)
Book an AIDA::IDataPointSet into the THistSvc as a TH1D at path.
Definition: Rivet_i.cxx:293
MC::isBeam
bool isBeam(const T &p)
Definition: HepMCHelpers.h:28
Rivet_i::m_preload
std::string m_preload
Definition: Rivet_i.h:75
SG::VarHandleBase::vhKey
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
Definition: StoreGate/src/VarHandleBase.cxx:616
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
AthAlgorithm::AthAlgorithm
AthAlgorithm()
Default constructor:
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
LHEF::Writer
Pythia8::Writer Writer
Definition: Prophecy4fMerger.cxx:12
Rivet_i::m_weightcap
double m_weightcap
Weight cap to set allowed maximum for weights.
Definition: Rivet_i.h:140
Rivet_i::m_analysisHandler
Rivet::AnalysisHandler * m_analysisHandler
A Rivet analysis handler.
Definition: Rivet_i.h:113
AthCommonDataStore::declareGaudiProperty
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>
Definition: AthCommonDataStore.h:156
Rivet_i::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
Definition: Rivet_i.h:142
fitman.k
k
Definition: fitman.py:528
ServiceHandle< ICondSvc >
Rivet_i::m_runname
std::string m_runname
The name of the run (prepended to plot paths).
Definition: Rivet_i.h:107