Version: SMASH-2.0.2
smash::RivetOutput Class Reference

#include <rivetoutput.h>

SMASH output to Rivet analyses.

This class passes HepMC events to Rivet for analysis. The event is kept in-memory which significanly speeds up processing (at last a factor 10) as compared to writing the HepMC event to disk or pipe and then decoding in Rivet.

More details of the output format can be found in the User Guide.

Definition at line 36 of file rivetoutput.h.

Inheritance diagram for smash::RivetOutput:
[legend]
Collaboration diagram for smash::RivetOutput:
[legend]

Classes

struct  Proxy
 A proxy object that wraps all Rivet::AnalysisHandler calls in an environment where FP errors are disabled. More...
 

Public Member Functions

 RivetOutput (const bf::path &path, std::string name, const bool full_event, const int total_N, const int proj_N, const OutputParameters &out_par)
 Create Rivet output. More...
 
 ~RivetOutput ()
 Destructor. More...
 
void at_eventend (const Particles &particles, const int32_t event_number, const EventInfo &event) override
 Add the final particles information of an event to the central vertex. More...
 
void add_analysis (const std::string &name)
 Add an analysis or analyses to Rivet. More...
 
void add_path (const std::string &path)
 Add a load path to the Rivet handler. More...
 
void add_preload (const std::string &file)
 Add preload to Rivet handler. More...
 
void set_ignore_beams (bool ignore=true)
 Do not insist on appropriate beams for analyses. More...
 
void set_log_level (const std::string &name, const std::string &level)
 Set log level in Rivet. More...
 
void set_cross_section (double xs, double xserr)
 Set X-section. More...
 
void setup ()
 Read configuration of Rivet from SMASH configuration. More...
 
- Public Member Functions inherited from smash::HepMcInterface
 HepMcInterface (const std::string &name, const bool full_event, const int total_N, const int proj_N)
 Create HepMC particle event in memory. More...
 
void at_eventstart (const Particles &particles, const int event_number, const EventInfo &event) override
 Add the initial particles information of an event to the central vertex. More...
 
void at_interaction (const Action &action, const double density) override
 Writes collisions to event. More...
 
void at_eventend (const Particles &particles, const int32_t event_number, const EventInfo &event) override
 Add the final particles information of an event to the central vertex. More...
 
- Public Member Functions inherited from smash::OutputInterface
 OutputInterface (std::string name)
 Construct output interface. More...
 
virtual ~OutputInterface ()=default
 
virtual void at_eventend (const Particles &particles, const int event_number, const EventInfo &info)=0
 Output launched at event end. More...
 
virtual void at_intermediate_time (const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventInfo &info)
 Output launched after every N'th timestep. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< DensityOnLattice > &lattice)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< EnergyMomentumTensor > &lattice)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_output (const GrandCanThermalizer &gct)
 Output to write energy-momentum tensor and related quantities from the thermalizer class. More...
 
bool is_dilepton_output () const
 Get, whether this is the dilepton output? More...
 
bool is_photon_output () const
 Get, whether this is the photon output? More...
 
bool is_IC_output () const
 Get, whether this is the IC output? More...
 
const char * to_string (const ThermodynamicQuantity tq)
 Convert thermodynamic quantities to strings. More...
 
const char * to_string (const DensityType dens_type)
 Convert density types to strings. More...
 

Private Member Functions

Proxy analysis_handler_proxy ()
 Return a proxy that temporarily disables FP exceptions. More...
 

Private Attributes

std::shared_ptr< Rivet::AnalysisHandler > handler_
 Rivet analysis handler. More...
 
bf::path filename_
 Output file. More...
 
bool need_init_
 Whether we need initialisation. More...
 
Configuration rivet_confs_
 Configutations for rivet. More...
 

Additional Inherited Members

- Public Types inherited from smash::HepMcInterface
using AZ = std::pair< int, int >
 Pair of Atomic weight and number. More...
 
- Protected Types inherited from smash::HepMcInterface
enum  Status { beam = 4, fnal = 1, dcy = 2, off = 100 }
 HepMC status codes. More...
 
using IdMap = std::map< int, HepMC3::GenParticlePtr >
 Type of mapping from SMASH ID to HepMC ID. More...
 
using CollCounter = std::valarray< int >
 Counter of collitions per incoming particle. More...
 
- Protected Member Functions inherited from smash::HepMcInterface
void clear ()
 Clear before an event. More...
 
int get_status (const ProcessType &t) const
 Convert SMASH process type to HepMC status. More...
 
HepMC3::GenParticlePtr make_gen (int pid, int status, const smash::FourVector &mom, double mass=-1)
 Make an HepMC particle. More...
 
HepMC3::GenParticlePtr make_register (const ParticleData &p, int status=Status::fnal)
 Find particle in mapping or generate it. More...
 
HepMC3::GenParticlePtr find_or_make (const ParticleData &p, int status=Status::fnal, bool force_new=false)
 Find particle in mapping or generate it. More...
 
int ion_pdg (const AZ &az) const
 Encode ion PDG. More...
 
- Protected Attributes inherited from smash::HepMcInterface
HepMC3::GenEvent event_
 The event. More...
 
HepMC3::GenHeavyIonPtr ion_
 The heavy-ion structure. More...
 
HepMC3::GenCrossSectionPtr xs_
 Dummy cross-section. More...
 
HepMC3::GenVertexPtr ip_
 The interaction point. More...
 
IdMap map_
 Mapping from ID to particle. More...
 
CollCounter coll_
 Collision counter. More...
 
int ncoll_
 counter of binary collisions (e.g., where both incoming particles are from the beams. More...
 
int ncoll_hard_
 counter of hard binary collisions (e.g., where both incoming particles are from the beams. More...
 
const int total_N_
 Total number of nucleons in projectile and target, needed for converting nuclei to single particles. More...
 
const int proj_N_
 Total number of nucleons in projectile, needed for converting nuclei to single particles. More...
 
bool full_event_
 Whether the full event or only final-state particles are in the output. More...
 
- Protected Attributes inherited from smash::OutputInterface
const bool is_dilepton_output_
 Is this the dilepton output? More...
 
const bool is_photon_output_
 Is this the photon output? More...
 
const bool is_IC_output_
 Is this the IC output? More...
 

Constructor & Destructor Documentation

◆ RivetOutput()

smash::RivetOutput::RivetOutput ( const bf::path &  path,
std::string  name,
const bool  full_event,
const int  total_N,
const int  proj_N,
const OutputParameters out_par 
)

Create Rivet output.

Parameters
[in]pathOutput path.
[in]nameName of the output.
[in]full_eventWhether the full event or only final-state particles are printed in the output
[in]total_NTotal number of particles in both nuclei.
[in]proj_NNumber of particles in projectile.
[in]out_parConfiguration parameters of SMASH

Definition at line 146 of file rivetoutput.cc.

149  : HepMcInterface(name, full_event, total_N, proj_N),
150  handler_(),
151  filename_(path / (name + ".yoda")),
152  need_init_(true),
153  rivet_confs_(out_par.subcon_for_rivet) {
154  handler_ = std::make_shared<Rivet::AnalysisHandler>();
155  setup();
156 }
Here is the call graph for this function:

◆ ~RivetOutput()

smash::RivetOutput::~RivetOutput ( )

Destructor.

Finalises the analzyses and writes out results to file

Definition at line 158 of file rivetoutput.cc.

158  {
159  logg[LOutput].debug() << "Writing Rivet results to " << filename_
160  << std::endl;
161  analysis_handler_proxy()->finalize();
162  analysis_handler_proxy()->writeData(filename_.string());
163 }
Here is the call graph for this function:

Member Function Documentation

◆ at_eventend()

void smash::RivetOutput::at_eventend ( const Particles particles,
const int32_t  event_number,
const EventInfo event 
)
override

Add the final particles information of an event to the central vertex.

Store impact paramter and write event.

Parameters
[in]particlesCurrent list of particles.
[in]event_numberNumber of event.
[in]eventEvent info, see event_info

Definition at line 165 of file rivetoutput.cc.

167  {
168  HepMcInterface::at_eventend(particles, event_number, event);
169 
170  // Initialize Rivet on first event
171  if (need_init_) {
172  logg[LOutput].debug() << "Initialising Rivet" << std::endl;
173  need_init_ = false;
175  }
176 
177  logg[LOutput].debug() << "Analysing event " << event_number << std::endl;
178  // Let Rivet analyse the event
179  analysis_handler_proxy()->analyze(event_);
180 }
Here is the call graph for this function:

◆ add_analysis()

void smash::RivetOutput::add_analysis ( const std::string &  name)

Add an analysis or analyses to Rivet.

Parameters
[in]nameName of analysis

Definition at line 182 of file rivetoutput.cc.

182  {
183  analysis_handler_proxy()->addAnalysis(name);
184 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_path()

void smash::RivetOutput::add_path ( const std::string &  path)

Add a load path to the Rivet handler.

Definition at line 186 of file rivetoutput.cc.

186  {
187  Rivet::addAnalysisLibPath(path);
188  Rivet::addAnalysisDataPath(path);
189 }
Here is the caller graph for this function:

◆ add_preload()

void smash::RivetOutput::add_preload ( const std::string &  file)

Add preload to Rivet handler.

Definition at line 191 of file rivetoutput.cc.

191  {
192  analysis_handler_proxy()->readData(file);
193 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_ignore_beams()

void smash::RivetOutput::set_ignore_beams ( bool  ignore = true)

Do not insist on appropriate beams for analyses.

Definition at line 195 of file rivetoutput.cc.

195  {
196  logg[LOutput].info() << "Ignore beams? " << (ignore ? "yes" : "no")
197  << std::endl;
198  analysis_handler_proxy()->setIgnoreBeams(ignore);
199 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_log_level()

void smash::RivetOutput::set_log_level ( const std::string &  name,
const std::string &  level 
)

Set log level in Rivet.

Definition at line 201 of file rivetoutput.cc.

202  {
203  std::string fname(name);
204  if (fname.rfind("Rivet", 0) != 0) {
205  fname = "Rivet." + fname;
206  }
207 
208  auto upcase = [](const std::string& s) {
209  std::string out(s);
210  std::transform(out.begin(), out.end(), out.begin(),
211  [](char c) { return std::toupper(c); });
212  return out;
213  };
214 
215  try {
216  Rivet::Log::setLevel(fname, Rivet::Log::getLevelFromName(upcase(level)));
217  } catch (...) {
218  }
219 }
Here is the caller graph for this function:

◆ set_cross_section()

void smash::RivetOutput::set_cross_section ( double  xs,
double  xserr 
)

Set X-section.

Parameters
[in]xsCross-section value in pb
[in]xserrUncertainty on cross-section in pb

Definition at line 221 of file rivetoutput.cc.

221  {
222  analysis_handler_proxy()->setCrossSection(xs, xserr, true);
223 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup()

void smash::RivetOutput::setup ( )

Read configuration of Rivet from SMASH configuration.

Definition at line 225 of file rivetoutput.cc.

225  {
226  logg[LOutput].debug() << "Setting up from configuration:\n"
227  << rivet_confs_.to_string() << std::endl;
228 
229  // Paths to analyses libraries and data
230  if (rivet_confs_.has_value({"Paths"})) {
231  logg[LOutput].info() << "Processing paths" << std::endl;
232  std::vector<std::string> path = rivet_confs_.take({"Paths"});
233  for (auto p : path)
234  add_path(p);
235  }
236 
237  // Data files to pre-load e.g., for centrality configurations
238  if (rivet_confs_.has_value({"Preloads"})) {
239  logg[LOutput].info() << "Processing preloads" << std::endl;
240  std::vector<std::string> prel = rivet_confs_.take({"Preloads"});
241  for (auto p : prel)
242  add_preload(p);
243  }
244 
245  // Analyses (including options) to add to run
246  if (rivet_confs_.has_value({"Analyses"})) {
247  logg[LOutput].info() << "Processing analyses" << std::endl;
248  std::vector<std::string> anas = rivet_confs_.take({"Analyses"});
249  for (auto p : anas)
250  add_analysis(p);
251  }
252 
253  // Whether Rivet should ignore beams
254  if (rivet_confs_.has_value({"Ignore_Beams"})) {
255  set_ignore_beams(rivet_confs_.take({"Ignore_Beams"}));
256  } else {
257  // we must explicity tell Rivet, through the handler, to ignore beam checks
258  set_ignore_beams(true);
259  }
260 
261  // Cross sections
262  if (rivet_confs_.has_value({"Cross_Section"})) {
263  std::array<double, 2> xs = rivet_confs_.take({"Cross_Section"});
264  set_cross_section(xs[0], xs[1]);
265  }
266 
267  // Logging in Rivet
268  if (rivet_confs_.has_value({"Logging"})) {
269  std::map<std::string, std::string> logs = rivet_confs_.take({"Logging"});
270  for (auto nl : logs)
271  set_log_level(nl.first, nl.second);
272  }
273 
274  // Treatment of event weights in Rivet
275  if (rivet_confs_.has_value({"Weights"})) {
276  auto wconf = rivet_confs_["Weights"];
277 
278  // Do not care about multi weights - bool
279  if (wconf.has_value({"No_Multi"})) {
280  analysis_handler_proxy()->skipMultiWeights(wconf.take({"No_Multi"}));
281  }
282 
283  // Set nominal weight name
284  if (wconf.has_value({"Nominal"})) {
285  analysis_handler_proxy()->setNominalWeightName(wconf.take({"Nominal"}));
286  }
287 
288  // Set cap (maximum) on weights
289  if (wconf.has_value({"Cap"})) {
290  analysis_handler_proxy()->setWeightCap(wconf.take({"Cap"}));
291  }
292 
293  // Whether to smear for NLO calculations
294  if (wconf.has_value({"NLO_Smearing"})) {
295  analysis_handler_proxy()->setNLOSmearing(wconf.take({"NLO_Smearing"}));
296  }
297 
298  // Select which weights to enable
299  if (wconf.has_value({"Select"})) {
300  std::vector<std::string> sel = wconf.take({"Select"});
301  std::stringstream s;
302  int comma = 0;
303  for (auto w : sel)
304  s << (comma++ ? "," : "") << w;
305  analysis_handler_proxy()->selectMultiWeights(s.str());
306  }
307 
308  // Select weights to disable
309  if (wconf.has_value({"Deselect"})) {
310  std::vector<std::string> sel = wconf.take({"Deselect"});
311  std::stringstream s;
312  int comma = 0;
313  for (auto w : sel)
314  s << (comma++ ? "," : "") << w;
315  analysis_handler_proxy()->deselectMultiWeights(s.str());
316  }
317  }
318  logg[LOutput].debug() << "After processing configuration:\n"
319  << rivet_confs_.to_string() << std::endl;
320 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ analysis_handler_proxy()

Proxy smash::RivetOutput::analysis_handler_proxy ( )
inlineprivate

Return a proxy that temporarily disables FP exceptions.

Definition at line 120 of file rivetoutput.h.

120 { return Proxy(handler_); }
Here is the caller graph for this function:

Member Data Documentation

◆ handler_

std::shared_ptr<Rivet::AnalysisHandler> smash::RivetOutput::handler_
private

Rivet analysis handler.

Definition at line 123 of file rivetoutput.h.

◆ filename_

bf::path smash::RivetOutput::filename_
private

Output file.

Definition at line 125 of file rivetoutput.h.

◆ need_init_

bool smash::RivetOutput::need_init_
private

Whether we need initialisation.

Definition at line 127 of file rivetoutput.h.

◆ rivet_confs_

Configuration smash::RivetOutput::rivet_confs_
private

Configutations for rivet.

Definition at line 129 of file rivetoutput.h.


The documentation for this class was generated from the following files:
smash::RivetOutput::analysis_handler_proxy
Proxy analysis_handler_proxy()
Return a proxy that temporarily disables FP exceptions.
Definition: rivetoutput.h:120
smash::RivetOutput::setup
void setup()
Read configuration of Rivet from SMASH configuration.
Definition: rivetoutput.cc:225
smash::LOutput
static constexpr int LOutput
Definition: outputinterface.h:24
smash::HepMcInterface::event_
HepMC3::GenEvent event_
The event.
Definition: hepmcinterface.h:188
smash::Configuration::to_string
std::string to_string() const
Returns a YAML string of the current tree.
Definition: configuration.cc:192
smash::Configuration::has_value
bool has_value(std::initializer_list< const char * > keys) const
Returns whether there is a non-empty value behind the requested keys.
Definition: configuration.cc:181
smash::RivetOutput::add_path
void add_path(const std::string &path)
Add a load path to the Rivet handler.
Definition: rivetoutput.cc:186
smash::logg
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
smash::HepMcInterface::HepMcInterface
HepMcInterface(const std::string &name, const bool full_event, const int total_N, const int proj_N)
Create HepMC particle event in memory.
Definition: hepmcinterface.cc:18
smash::RivetOutput::need_init_
bool need_init_
Whether we need initialisation.
Definition: rivetoutput.h:127
smash::HepMcInterface::at_eventend
void at_eventend(const Particles &particles, const int32_t event_number, const EventInfo &event) override
Add the final particles information of an event to the central vertex.
Definition: hepmcinterface.cc:142
smash::RivetOutput::set_log_level
void set_log_level(const std::string &name, const std::string &level)
Set log level in Rivet.
Definition: rivetoutput.cc:201
smash::RivetOutput::add_analysis
void add_analysis(const std::string &name)
Add an analysis or analyses to Rivet.
Definition: rivetoutput.cc:182
smash::RivetOutput::filename_
bf::path filename_
Output file.
Definition: rivetoutput.h:125
smash::RivetOutput::rivet_confs_
Configuration rivet_confs_
Configutations for rivet.
Definition: rivetoutput.h:129
smash::Configuration::take
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
Definition: configuration.cc:140
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::RivetOutput::add_preload
void add_preload(const std::string &file)
Add preload to Rivet handler.
Definition: rivetoutput.cc:191
smash::RivetOutput::set_cross_section
void set_cross_section(double xs, double xserr)
Set X-section.
Definition: rivetoutput.cc:221
smash::RivetOutput::handler_
std::shared_ptr< Rivet::AnalysisHandler > handler_
Rivet analysis handler.
Definition: rivetoutput.h:123
smash::RivetOutput::set_ignore_beams
void set_ignore_beams(bool ignore=true)
Do not insist on appropriate beams for analyses.
Definition: rivetoutput.cc:195