Version: SMASH-3.1
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 significantly 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 37 of file rivetoutput.h.

Inheritance diagram for smash::RivetOutput:
smash::HepMcInterface smash::OutputInterface

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 std::filesystem::path &path, std::string name, const bool full_event, const RivetOutputParameters &rivet_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...
 
- 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 ()=0
 Pure virtual destructor to make class abstract and prevent its instantiation. More...
 
virtual void at_eventstart (const std::vector< Particles > &, int)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int, const ThermodynamicQuantity, const DensityType, RectangularLattice< DensityOnLattice >)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int, const ThermodynamicQuantity, const DensityType, RectangularLattice< EnergyMomentumTensor >)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventend (const int, const ThermodynamicQuantity, const DensityType)
 Output launched at event end. More...
 
virtual void at_eventend (const ThermodynamicQuantity)
 Output launched at event end. More...
 
virtual void at_eventend (const Particles &, const int, const EventInfo &)
 Output launched at event end. More...
 
virtual void at_eventend (const std::vector< Particles > &, const int)
 Output launched at event end. More...
 
virtual void at_intermediate_time (const Particles &, const std::unique_ptr< Clock > &, const DensityParameters &, const EventInfo &)
 Output launched after every N'th time-step. More...
 
virtual void at_intermediate_time (const std::vector< Particles > &, const std::unique_ptr< Clock > &, const DensityParameters &)
 Output launched after every N'th timestep. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity, const DensityType, RectangularLattice< DensityOnLattice > &)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity, const DensityType, RectangularLattice< EnergyMomentumTensor > &)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &, const double)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &, const double, const std::vector< Particles > &, const DensityParameters &)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (const ThermodynamicQuantity, RectangularLattice< EnergyMomentumTensor > &, const double)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_output (const GrandCanThermalizer &)
 Output to write energy-momentum tensor and related quantities from the thermalizer class. More...
 
virtual void fields_output (const std::string, const std::string, RectangularLattice< std::pair< ThreeVector, ThreeVector >> &)
 Write fields in vtk output Fields are a pair of threevectors for example electric and magnetic field. 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

void setup (const RivetOutputParameters &params)
 Setup Rivet using SMASH configuration parameters. More...
 
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...
 
std::filesystem::path filename_
 Output file. More...
 
bool need_init_
 Whether we need initialisation. 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 std::filesystem::path &  path,
std::string  name,
const bool  full_event,
const RivetOutputParameters rivet_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]rivet_parRivet parameters from SMASH configuration

Definition at line 91 of file rivetoutput.cc.

94  : HepMcInterface(name, full_event),
95  handler_(),
96  filename_(path / (name + ".yoda")),
97  need_init_(true) {
98  handler_ = std::make_shared<Rivet::AnalysisHandler>();
99  setup(rivet_par);
100 }
HepMcInterface(const std::string &name, const bool full_event)
Create HepMC particle event in memory.
std::filesystem::path filename_
Output file.
Definition: rivetoutput.h:127
std::shared_ptr< Rivet::AnalysisHandler > handler_
Rivet analysis handler.
Definition: rivetoutput.h:125
bool need_init_
Whether we need initialisation.
Definition: rivetoutput.h:129
void setup(const RivetOutputParameters &params)
Setup Rivet using SMASH configuration parameters.
Definition: rivetoutput.cc:169

◆ ~RivetOutput()

smash::RivetOutput::~RivetOutput ( )

Destructor.

Finalises the analzyses and writes out results to file

Definition at line 102 of file rivetoutput.cc.

102  {
103  logg[LOutput].debug() << "Writing Rivet results to " << filename_
104  << std::endl;
105  analysis_handler_proxy()->finalize();
106  analysis_handler_proxy()->writeData(filename_.string());
107 }
Proxy analysis_handler_proxy()
Return a proxy that temporarily disables FP exceptions.
Definition: rivetoutput.h:122
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

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 parameter and write event.

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

Definition at line 109 of file rivetoutput.cc.

111  {
112  HepMcInterface::at_eventend(particles, event_number, event);
113 
114  // Initialize Rivet on first event
115  if (need_init_) {
116  logg[LOutput].debug() << "Initialising Rivet" << std::endl;
117  need_init_ = false;
119  }
120 
121  logg[LOutput].debug() << "Analysing event " << event_number << std::endl;
122  // Let Rivet analyse the event
123  analysis_handler_proxy()->analyze(event_);
124 }
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.

◆ 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 126 of file rivetoutput.cc.

126  {
127  analysis_handler_proxy()->addAnalysis(name);
128 }

◆ add_path()

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

Add a load path to the Rivet handler.

Definition at line 130 of file rivetoutput.cc.

130  {
131  Rivet::addAnalysisLibPath(path);
132  Rivet::addAnalysisDataPath(path);
133 }

◆ add_preload()

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

Add preload to Rivet handler.

Definition at line 135 of file rivetoutput.cc.

135  {
136  analysis_handler_proxy()->readData(file);
137 }

◆ set_ignore_beams()

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

Do not insist on appropriate beams for analyses.

Definition at line 139 of file rivetoutput.cc.

139  {
140  logg[LOutput].info() << "Ignore beams? " << (ignore ? "yes" : "no")
141  << std::endl;
142  analysis_handler_proxy()->setIgnoreBeams(ignore);
143 }

◆ 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 145 of file rivetoutput.cc.

146  {
147  std::string fname(name);
148  if (fname.rfind("Rivet", 0) != 0) {
149  fname = "Rivet." + fname;
150  }
151 
152  auto upcase = [](const std::string& s) {
153  std::string out(s);
154  std::transform(out.begin(), out.end(), out.begin(),
155  [](char c) { return std::toupper(c); });
156  return out;
157  };
158 
159  try {
160  Rivet::Log::setLevel(fname, Rivet::Log::getLevelFromName(upcase(level)));
161  } catch (...) {
162  }
163 }

◆ 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 165 of file rivetoutput.cc.

165  {
166  analysis_handler_proxy()->setCrossSection(xs, xserr, true);
167 }

◆ setup()

void smash::RivetOutput::setup ( const RivetOutputParameters params)
private

Setup Rivet using SMASH configuration parameters.

Parameters
[in]paramsThe SMASH parameters already extracted from the input configuration

Definition at line 169 of file rivetoutput.cc.

169  {
170  logg[LOutput].debug() << "Setting up Rivet output:\n";
171 
172  // Paths to analyses libraries and data
173  if (params.paths) {
174  logg[LOutput].info() << "Processing paths\n";
175  for (auto p : params.paths.value())
176  add_path(p);
177  }
178 
179  // Data files to pre-load e.g., for centrality configurations
180  if (params.preloads) {
181  logg[LOutput].info() << "Processing preloads\n";
182  for (auto p : params.preloads.value())
183  add_preload(p);
184  }
185 
186  // Analyses (including options) to add to run
187  if (params.analyses) {
188  logg[LOutput].info() << "Processing analyses\n";
189  for (auto p : params.analyses.value())
190  add_analysis(p);
191  }
192 
193  // Whether Rivet should ignore beams
194  set_ignore_beams(params.ignore_beams);
195 
196  // Cross sections
197  if (params.cross_sections) {
198  set_cross_section(params.cross_sections.value()[0],
199  params.cross_sections.value()[1]);
200  }
201 
202  // Logging in Rivet
203  if (params.logs) {
204  for (auto nl : params.logs.value())
205  set_log_level(nl.first, nl.second);
206  }
207 
208  // Treatment of event weights in Rivet
209  if (params.any_weight_parameter_was_given) {
210  // Do not care about multi weights
211  if (params.no_multi_weight) {
212  analysis_handler_proxy()->skipMultiWeights(
213  params.no_multi_weight.value());
214  }
215 
216  // Set nominal weight name
217  if (params.nominal_weight_name) {
218  analysis_handler_proxy()->setNominalWeightName(
219  params.nominal_weight_name.value());
220  }
221 
222  // Set cap (maximum) on weights
223  if (params.cap_on_weights) {
224  analysis_handler_proxy()->setWeightCap(params.cap_on_weights.value());
225  }
226 
227  // Whether to smear for NLO calculations
228  if (params.nlo_smearing) {
229  analysis_handler_proxy()->setNLOSmearing(params.nlo_smearing.value());
230  }
231 
232  // Select which weights to enable
233  if (params.to_be_enabled_weights) {
234  std::stringstream s;
235  int comma = 0;
236  for (auto w : params.to_be_enabled_weights.value())
237  s << (comma++ ? "," : "") << w;
238  analysis_handler_proxy()->selectMultiWeights(s.str());
239  }
240 
241  // Select weights to disable
242  if (params.to_be_disabled_weights) {
243  std::stringstream s;
244  int comma = 0;
245  for (auto w : params.to_be_disabled_weights.value())
246  s << (comma++ ? "," : "") << w;
247  analysis_handler_proxy()->deselectMultiWeights(s.str());
248  }
249  }
250  logg[LOutput].debug() << "Setup of Rivet output done.\n";
251 }
void add_path(const std::string &path)
Add a load path to the Rivet handler.
Definition: rivetoutput.cc:130
void add_analysis(const std::string &name)
Add an analysis or analyses to Rivet.
Definition: rivetoutput.cc:126
void set_cross_section(double xs, double xserr)
Set X-section.
Definition: rivetoutput.cc:165
void add_preload(const std::string &file)
Add preload to Rivet handler.
Definition: rivetoutput.cc:135
void set_log_level(const std::string &name, const std::string &level)
Set log level in Rivet.
Definition: rivetoutput.cc:145
void set_ignore_beams(bool ignore=true)
Do not insist on appropriate beams for analyses.
Definition: rivetoutput.cc:139
constexpr int p
Proton.

◆ analysis_handler_proxy()

Proxy smash::RivetOutput::analysis_handler_proxy ( )
inlineprivate

Return a proxy that temporarily disables FP exceptions.

Definition at line 122 of file rivetoutput.h.

122 { return Proxy(handler_); }

Member Data Documentation

◆ handler_

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

Rivet analysis handler.

Definition at line 125 of file rivetoutput.h.

◆ filename_

std::filesystem::path smash::RivetOutput::filename_
private

Output file.

Definition at line 127 of file rivetoutput.h.

◆ need_init_

bool smash::RivetOutput::need_init_
private

Whether we need initialisation.

Definition at line 129 of file rivetoutput.h.


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