Version: SMASH-2.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 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)
 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_eventstart (const std::vector< Particles > &ensembles, int event_number)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type, RectangularLattice< DensityOnLattice > lattice)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type, RectangularLattice< EnergyMomentumTensor > lattice)
 Output launched atevent start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventend (const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type)
 Output launched at event end. More...
 
virtual void at_eventend (const ThermodynamicQuantity tq)
 Output launched at event end. More...
 
virtual void at_eventend (const Particles &particles, const int event_number, const EventInfo &info)
 Output launched at event end. More...
 
virtual void at_eventend (const std::vector< Particles > &ensembles, const int event_number)
 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 at_intermediate_time (const std::vector< Particles > &ensembles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param)
 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_lattice_output (RectangularLattice< DensityOnLattice > &lattice, const double current_time)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &lattice, const double current_time, const std::vector< Particles > &ensembles, const DensityParameters &dens_param)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (const ThermodynamicQuantity tq, RectangularLattice< EnergyMomentumTensor > &lattice, const double current_time)
 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...
 
virtual void fields_output (const std::string name1, const std::string name2, RectangularLattice< std::pair< ThreeVector, ThreeVector >> &lat)
 Write fields in vtk output. 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...
 
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 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]out_parConfiguration parameters of SMASH

Definition at line 146 of file rivetoutput.cc.

148  : HepMcInterface(name, full_event),
149  handler_(),
150  filename_(path / (name + ".yoda")),
151  need_init_(true),
152  rivet_confs_(out_par.subcon_for_rivet) {
153  handler_ = std::make_shared<Rivet::AnalysisHandler>();
154  setup();
155 }
HepMcInterface(const std::string &name, const bool full_event)
Create HepMC particle event in memory.
void setup()
Read configuration of Rivet from SMASH configuration.
Definition: rivetoutput.cc:224
std::shared_ptr< Rivet::AnalysisHandler > handler_
Rivet analysis handler.
Definition: rivetoutput.h:120
bool need_init_
Whether we need initialisation.
Definition: rivetoutput.h:124
bf::path filename_
Output file.
Definition: rivetoutput.h:122
Configuration rivet_confs_
Configutations for rivet.
Definition: rivetoutput.h:126
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 157 of file rivetoutput.cc.

157  {
158  logg[LOutput].debug() << "Writing Rivet results to " << filename_
159  << std::endl;
160  analysis_handler_proxy()->finalize();
161  analysis_handler_proxy()->writeData(filename_.string());
162 }
Proxy analysis_handler_proxy()
Return a proxy that temporarily disables FP exceptions.
Definition: rivetoutput.h:117
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
static constexpr int LOutput
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 164 of file rivetoutput.cc.

166  {
167  HepMcInterface::at_eventend(particles, event_number, event);
168 
169  // Initialize Rivet on first event
170  if (need_init_) {
171  logg[LOutput].debug() << "Initialising Rivet" << std::endl;
172  need_init_ = false;
174  }
175 
176  logg[LOutput].debug() << "Analysing event " << event_number << std::endl;
177  // Let Rivet analyse the event
178  analysis_handler_proxy()->analyze(event_);
179 }
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.
HepMC3::GenEvent event_
The event.
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 181 of file rivetoutput.cc.

181  {
182  analysis_handler_proxy()->addAnalysis(name);
183 }
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 185 of file rivetoutput.cc.

185  {
186  Rivet::addAnalysisLibPath(path);
187  Rivet::addAnalysisDataPath(path);
188 }
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 190 of file rivetoutput.cc.

190  {
191  analysis_handler_proxy()->readData(file);
192 }
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 194 of file rivetoutput.cc.

194  {
195  logg[LOutput].info() << "Ignore beams? " << (ignore ? "yes" : "no")
196  << std::endl;
197  analysis_handler_proxy()->setIgnoreBeams(ignore);
198 }
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 200 of file rivetoutput.cc.

201  {
202  std::string fname(name);
203  if (fname.rfind("Rivet", 0) != 0) {
204  fname = "Rivet." + fname;
205  }
206 
207  auto upcase = [](const std::string& s) {
208  std::string out(s);
209  std::transform(out.begin(), out.end(), out.begin(),
210  [](char c) { return std::toupper(c); });
211  return out;
212  };
213 
214  try {
215  Rivet::Log::setLevel(fname, Rivet::Log::getLevelFromName(upcase(level)));
216  } catch (...) {
217  }
218 }
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 220 of file rivetoutput.cc.

220  {
221  analysis_handler_proxy()->setCrossSection(xs, xserr, true);
222 }
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 224 of file rivetoutput.cc.

224  {
225  logg[LOutput].debug() << "Setting up from configuration:\n"
226  << rivet_confs_.to_string() << std::endl;
227 
228  // Paths to analyses libraries and data
229  if (rivet_confs_.has_value({"Paths"})) {
230  logg[LOutput].info() << "Processing paths" << std::endl;
231  std::vector<std::string> path = rivet_confs_.take({"Paths"});
232  for (auto p : path)
233  add_path(p);
234  }
235 
236  // Data files to pre-load e.g., for centrality configurations
237  if (rivet_confs_.has_value({"Preloads"})) {
238  logg[LOutput].info() << "Processing preloads" << std::endl;
239  std::vector<std::string> prel = rivet_confs_.take({"Preloads"});
240  for (auto p : prel)
241  add_preload(p);
242  }
243 
244  // Analyses (including options) to add to run
245  if (rivet_confs_.has_value({"Analyses"})) {
246  logg[LOutput].info() << "Processing analyses" << std::endl;
247  std::vector<std::string> anas = rivet_confs_.take({"Analyses"});
248  for (auto p : anas)
249  add_analysis(p);
250  }
251 
252  // Whether Rivet should ignore beams
253  if (rivet_confs_.has_value({"Ignore_Beams"})) {
254  set_ignore_beams(rivet_confs_.take({"Ignore_Beams"}));
255  } else {
256  // we must explicity tell Rivet, through the handler, to ignore beam checks
257  set_ignore_beams(true);
258  }
259 
260  // Cross sections
261  if (rivet_confs_.has_value({"Cross_Section"})) {
262  std::array<double, 2> xs = rivet_confs_.take({"Cross_Section"});
263  set_cross_section(xs[0], xs[1]);
264  }
265 
266  // Logging in Rivet
267  if (rivet_confs_.has_value({"Logging"})) {
268  std::map<std::string, std::string> logs = rivet_confs_.take({"Logging"});
269  for (auto nl : logs)
270  set_log_level(nl.first, nl.second);
271  }
272 
273  // Treatment of event weights in Rivet
274  if (rivet_confs_.has_value({"Weights"})) {
275  auto wconf = rivet_confs_["Weights"];
276 
277  // Do not care about multi weights - bool
278  if (wconf.has_value({"No_Multi"})) {
279  analysis_handler_proxy()->skipMultiWeights(wconf.take({"No_Multi"}));
280  }
281 
282  // Set nominal weight name
283  if (wconf.has_value({"Nominal"})) {
284  analysis_handler_proxy()->setNominalWeightName(wconf.take({"Nominal"}));
285  }
286 
287  // Set cap (maximum) on weights
288  if (wconf.has_value({"Cap"})) {
289  analysis_handler_proxy()->setWeightCap(wconf.take({"Cap"}));
290  }
291 
292  // Whether to smear for NLO calculations
293  if (wconf.has_value({"NLO_Smearing"})) {
294  analysis_handler_proxy()->setNLOSmearing(wconf.take({"NLO_Smearing"}));
295  }
296 
297  // Select which weights to enable
298  if (wconf.has_value({"Select"})) {
299  std::vector<std::string> sel = wconf.take({"Select"});
300  std::stringstream s;
301  int comma = 0;
302  for (auto w : sel)
303  s << (comma++ ? "," : "") << w;
304  analysis_handler_proxy()->selectMultiWeights(s.str());
305  }
306 
307  // Select weights to disable
308  if (wconf.has_value({"Deselect"})) {
309  std::vector<std::string> sel = wconf.take({"Deselect"});
310  std::stringstream s;
311  int comma = 0;
312  for (auto w : sel)
313  s << (comma++ ? "," : "") << w;
314  analysis_handler_proxy()->deselectMultiWeights(s.str());
315  }
316  }
317  logg[LOutput].debug() << "After processing configuration:\n"
318  << rivet_confs_.to_string() << std::endl;
319 }
bool has_value(std::initializer_list< const char * > keys) const
Returns whether there is a non-empty value behind the requested keys.
std::string to_string() const
Returns a YAML string of the current tree.
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
void add_path(const std::string &path)
Add a load path to the Rivet handler.
Definition: rivetoutput.cc:185
void add_analysis(const std::string &name)
Add an analysis or analyses to Rivet.
Definition: rivetoutput.cc:181
void set_cross_section(double xs, double xserr)
Set X-section.
Definition: rivetoutput.cc:220
void add_preload(const std::string &file)
Add preload to Rivet handler.
Definition: rivetoutput.cc:190
void set_log_level(const std::string &name, const std::string &level)
Set log level in Rivet.
Definition: rivetoutput.cc:200
void set_ignore_beams(bool ignore=true)
Do not insist on appropriate beams for analyses.
Definition: rivetoutput.cc:194
constexpr int p
Proton.
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 117 of file rivetoutput.h.

117 { 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 120 of file rivetoutput.h.

◆ filename_

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

Output file.

Definition at line 122 of file rivetoutput.h.

◆ need_init_

bool smash::RivetOutput::need_init_
private

Whether we need initialisation.

Definition at line 124 of file rivetoutput.h.

◆ rivet_confs_

Configuration smash::RivetOutput::rivet_confs_
private

Configutations for rivet.

Definition at line 126 of file rivetoutput.h.


The documentation for this class was generated from the following files: