Version: SMASH-3.3
smash::RootOutput Class Reference

#include <rootoutput.h>

SMASH output to ROOT file

SMASH supports ROOT output as an option (see http://root.cern.ch). The ROOT framework needs to be installed before building SMASH, otherwise ROOT support will be disabled.

This class produces a file Particles.root, which contains a ROOT TTree. The TTree contains information about particles from all SMASH events comprising a simulation. If Collisions output is requested, this class also produces a file Collisions.root, which contains a ROOT TTRee with information about all collisions.

See ROOT format for more informatioon.

Definition at line 46 of file rootoutput.h.

Inheritance diagram for smash::RootOutput:
smash::OutputInterface

Public Member Functions

 RootOutput (const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par)
 Construct ROOT output. More...
 
 ~RootOutput ()
 Destructor. More...
 
void at_eventstart (const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
 update event number and writes intermediate particles to a tree. More...
 
void at_eventend (const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
 update event number and impact parameter, and writes intermediate particles to a tree. More...
 
void at_intermediate_time (const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventLabel &event_label, const EventInfo &event) override
 Writes intermediate particles to a tree defined by treename, if it is allowed (i.e., particles_only_final_ is No). More...
 
void at_interaction (const Action &action, const double density) override
 Writes collisions to a tree defined by treename. 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 ThermodynamicQuantity)
 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 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

template<typename T >
void particles_to_tree (T &particles)
 Writes particles to a tree defined by treename. More...
 
void collisions_to_tree (const ParticleList &incoming, const ParticleList &outgoing, const double weight, const double partial_weight)
 Writes collisions to a tree defined by treename. More...
 

Private Attributes

const std::filesystem::path filename_
 Filename of output. More...
 
std::filesystem::path filename_unfinished_
 Filename of output as long as simulation is still running. More...
 
std::unique_ptr< TFile > root_out_file_
 Pointer to root output file. More...
 
TTree * particles_tree_
 TTree for particles output. More...
 
TTree * collisions_tree_
 TTree for collision output. More...
 
int output_counter_ = 0
 Number of output in a given event. More...
 
int current_event_ = 0
 Number of current event. More...
 
int current_ensemble_ = 0
 Number of current ensemble. More...
 

Static Private Attributes

static const int max_buffer_size_ = 500000
 Maximal buffer size. More...
 

Buffer for filling TTree

See class documentation for definitions.

int ev_ {}
 Property that is written to ROOT output. More...
 
int ens_ {}
 Property that is written to ROOT output. More...
 
int tcounter_ {}
 Property that is written to ROOT output. More...
 
int npart_ {}
 Property that is written to ROOT output. More...
 
int test_p_ {}
 Property that is written to ROOT output. More...
 
double modus_l_ {}
 Property that is written to ROOT output. More...
 
double current_t_ {}
 Property that is written to ROOT output. More...
 
double impact_b_ {}
 Property that is written to ROOT output. More...
 
bool empty_event_ {}
 Property that is written to ROOT output. More...
 
std::vector< int > id_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< int > pdgcode_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< int > charge_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< double > formation_time_
 Property that is written to ROOT output. More...
 
std::vector< double > time_last_collision_
 Property that is written to ROOT output. More...
 
std::vector< double > p0_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< double > px_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< double > py_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< double > pz_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< double > t_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< double > x_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< double > y_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< double > z_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
double E_kinetic_tot_ {}
 Property that is written to ROOT output. More...
 
double E_fields_tot_ {}
 Property that is written to ROOT output. More...
 
double E_tot_ {}
 Property that is written to ROOT output. More...
 
std::vector< int > coll_per_part_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< double > xsec_factor_ = std::vector<double>(max_buffer_size_, 0.0)
 Property that is written to ROOT output. More...
 
std::vector< int > proc_id_origin_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< int > proc_type_origin_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< int > pdg_mother1_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< int > pdg_mother2_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< int > baryon_number_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
std::vector< int > strangeness_ = std::vector<int>(max_buffer_size_, 0)
 Property that is written to ROOT output. More...
 
int nin_ {}
 Property that is written to ROOT output. More...
 
int nout_ {}
 Property that is written to ROOT output. More...
 
double wgt_ {}
 Property that is written to ROOT output. More...
 
double par_wgt_ {}
 Property that is written to ROOT output. More...
 
bool write_collisions_
 Option to write collisions tree. More...
 
bool write_particles_
 Option to write particles tree. More...
 
bool write_initial_conditions_
 Option to write particles tree for initial conditions. More...
 
OutputOnlyFinal particles_only_final_
 Print only final particles in the event (no intermediate output). More...
 
int autosave_frequency_ = -1
 ROOT file cannot be read if it was not properly closed and finalized. More...
 
const bool part_extended_
 Whether extended particle output is on. More...
 
const bool coll_extended_
 Whether extended collisions output is on. More...
 
const bool ic_extended_
 Whether extended ic output is on. More...
 
void init_trees ()
 Basic initialization routine, creating the TTree objects for particles and collisions. More...
 

Additional Inherited Members

- 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

◆ RootOutput()

smash::RootOutput::RootOutput ( const std::filesystem::path &  path,
const std::string &  name,
const OutputParameters out_par 
)

Construct ROOT output.

Parameters
[in]pathOutput path.
[in]nameName of the ouput.
[in]out_parA structure containing parameters of the output.

Definition at line 266 of file rootoutput.cc.

268  : OutputInterface(name),
269  filename_(path / (name + ".root")),
270  write_collisions_(name == "Collisions" || name == "Dileptons" ||
271  name == "Photons"),
272  write_particles_(name == "Particles"),
273  write_initial_conditions_(name == "SMASH_IC"),
274  particles_only_final_(out_par.part_only_final),
275  part_extended_(out_par.part_extended),
276  coll_extended_(out_par.coll_extended),
277  ic_extended_(out_par.ic_extended) {
279  filename_unfinished_ += ".unfinished";
281  std::make_unique<TFile>(filename_unfinished_.native().c_str(), "NEW");
282  init_trees();
283 }
OutputInterface(std::string name)
Construct output interface.
OutputOnlyFinal particles_only_final_
Print only final particles in the event (no intermediate output).
Definition: rootoutput.h:208
bool write_collisions_
Option to write collisions tree.
Definition: rootoutput.h:199
const std::filesystem::path filename_
Filename of output.
Definition: rootoutput.h:102
bool write_initial_conditions_
Option to write particles tree for initial conditions.
Definition: rootoutput.h:205
const bool part_extended_
Whether extended particle output is on.
Definition: rootoutput.h:225
std::unique_ptr< TFile > root_out_file_
Pointer to root output file.
Definition: rootoutput.h:106
std::filesystem::path filename_unfinished_
Filename of output as long as simulation is still running.
Definition: rootoutput.h:104
const bool coll_extended_
Whether extended collisions output is on.
Definition: rootoutput.h:227
void init_trees()
Basic initialization routine, creating the TTree objects for particles and collisions.
Definition: rootoutput.cc:285
const bool ic_extended_
Whether extended ic output is on.
Definition: rootoutput.h:229
bool write_particles_
Option to write particles tree.
Definition: rootoutput.h:202

◆ ~RootOutput()

smash::RootOutput::~RootOutput ( )

Destructor.

RootOutput destructor.

Writes root objects (here TTrees) to file and closes it.

Definition at line 393 of file rootoutput.cc.

393  {
394  // kOverwrite option prevents from writing extra TKey objects into root file
395  root_out_file_->Write("", TObject::kOverwrite);
396  root_out_file_->Close();
397  std::filesystem::rename(filename_unfinished_, filename_);
398 }

Member Function Documentation

◆ at_eventstart()

void smash::RootOutput::at_eventstart ( const Particles particles,
const EventLabel event_label,
const EventInfo event 
)
overridevirtual

update event number and writes intermediate particles to a tree.

Parameters
[in]particlesParticles to be written to output.
[in]event_labelNumbers of event and ensemble.
[in]eventEvent info, see event_info

Reimplemented from smash::OutputInterface.

Definition at line 400 of file rootoutput.cc.

402  {
403  // save event and ensemble numbers
404  current_event_ = event_label.event_number;
405  current_ensemble_ = event_label.ensemble_number;
406 
407  modus_l_ = event.modus_length;
408  test_p_ = event.test_particles;
409  current_t_ = event.current_time;
410  E_kinetic_tot_ = event.total_kinetic_energy;
411  E_fields_tot_ = event.total_mean_field_energy;
412  E_tot_ = event.total_energy;
413 
415  output_counter_ = 0;
416  // This is to have only one output of positive impact parameter per event
417  impact_b_ = -1.0;
418  empty_event_ = false;
419  particles_to_tree(particles);
420  output_counter_++;
421  }
422 }
double current_t_
Property that is written to ROOT output.
Definition: rootoutput.h:163
int current_event_
Number of current event.
Definition: rootoutput.h:140
double E_kinetic_tot_
Property that is written to ROOT output.
Definition: rootoutput.h:181
int test_p_
Property that is written to ROOT output.
Definition: rootoutput.h:161
double modus_l_
Property that is written to ROOT output.
Definition: rootoutput.h:162
void particles_to_tree(T &particles)
Writes particles to a tree defined by treename.
Definition: rootoutput.cc:500
double impact_b_
Property that is written to ROOT output.
Definition: rootoutput.h:164
int current_ensemble_
Number of current ensemble.
Definition: rootoutput.h:142
bool empty_event_
Property that is written to ROOT output.
Definition: rootoutput.h:165
double E_fields_tot_
Property that is written to ROOT output.
Definition: rootoutput.h:182
int output_counter_
Number of output in a given event.
Definition: rootoutput.h:138
double E_tot_
Property that is written to ROOT output.
Definition: rootoutput.h:183
@ No
Print initial, intermediate and final-state particles.

◆ at_eventend()

void smash::RootOutput::at_eventend ( const Particles particles,
const EventLabel event_label,
const EventInfo event 
)
overridevirtual

update event number and impact parameter, and writes intermediate particles to a tree.

Parameters
[in]particlesParticles to be written to output.
[in]event_labelNumbers of event and ensemble.
[in]eventEvent info, see event_info

Reimplemented from smash::OutputInterface.

Definition at line 443 of file rootoutput.cc.

445  {
446  current_ensemble_ = event_label.ensemble_number;
447  test_p_ = event.test_particles;
448  modus_l_ = event.modus_length;
449  current_t_ = event.current_time;
450  impact_b_ = event.impact_parameter;
451  empty_event_ = event.empty_event;
452 
453  E_kinetic_tot_ = event.total_kinetic_energy;
454  E_fields_tot_ = event.total_mean_field_energy;
455  E_tot_ = event.total_energy;
456 
457  if (write_particles_ &&
458  !(event.empty_event &&
460  particles_to_tree(particles);
461  }
462  /* Calculate the autosave frequency to be used. In case multiple ensembles are
463  * used this has to be at least 1, so set it to 1 if the number of ensembles
464  * is larger than the initial value of the autosave frequency. The evaluation
465  * of the actual frequency to be used has to be done only once, i.e. when the
466  * autosave_frequency_ has still its meaningless initial negative value. */
467  if (autosave_frequency_ < 0) {
468  autosave_frequency_ = 1000 / event.n_ensembles;
469  if (autosave_frequency_ == 0) {
471  }
472  }
473  /* Forced regular dump from operational memory to disk. Very demanding!
474  * If program crashes written data will NOT be lost. */
477  particles_tree_->AutoSave("SaveSelf");
478  }
479  if (write_collisions_) {
480  collisions_tree_->AutoSave("SaveSelf");
481  }
482  }
483 }
TTree * collisions_tree_
TTree for collision output.
Definition: rootoutput.h:120
int autosave_frequency_
ROOT file cannot be read if it was not properly closed and finalized.
Definition: rootoutput.h:222
TTree * particles_tree_
TTree for particles output.
Definition: rootoutput.h:113
@ IfNotEmpty
Print only final-state particles, and those only if the event is not empty.

◆ at_intermediate_time()

void smash::RootOutput::at_intermediate_time ( const Particles particles,
const std::unique_ptr< Clock > &  clock,
const DensityParameters dens_param,
const EventLabel event_label,
const EventInfo event 
)
overridevirtual

Writes intermediate particles to a tree defined by treename, if it is allowed (i.e., particles_only_final_ is No).

Parameters
[in]particlesParticles to be written to output.
[in]clockUnused, needed since inherited.
[in]dens_paramUnused, needed since inherited.
[in]event_labelNumbers of event and ensemble.
[in]eventEvent info, see event_info

Reimplemented from smash::OutputInterface.

Definition at line 424 of file rootoutput.cc.

428  {
429  current_ensemble_ = event_label.ensemble_number;
430  modus_l_ = event.modus_length;
431  test_p_ = event.test_particles;
432  current_t_ = event.current_time;
433  E_kinetic_tot_ = event.total_kinetic_energy;
434  E_fields_tot_ = event.total_mean_field_energy;
435  E_tot_ = event.total_energy;
436 
438  particles_to_tree(particles);
439  output_counter_++;
440  }
441 }

◆ at_interaction()

void smash::RootOutput::at_interaction ( const Action action,
const double  density 
)
overridevirtual

Writes collisions to a tree defined by treename.

Parameters
[in]actionan Action object containing incoming, outgoing particles and type of interactions.
[in]densityUnused, needed since inherited.

Reimplemented from smash::OutputInterface.

Definition at line 485 of file rootoutput.cc.

486  {
487  if (write_collisions_) {
488  collisions_to_tree(action.incoming_particles(), action.outgoing_particles(),
489  action.get_total_weight(), action.get_partial_weight());
490  }
491 
493  (action.get_type() == ProcessType::Fluidization ||
494  action.get_type() == ProcessType::FluidizationNoRemoval)) {
495  particles_to_tree(action.incoming_particles());
496  }
497 }
void collisions_to_tree(const ParticleList &incoming, const ParticleList &outgoing, const double weight, const double partial_weight)
Writes collisions to a tree defined by treename.
Definition: rootoutput.cc:565
@ FluidizationNoRemoval
See here for a short description.
@ Fluidization
See here for a short description.

◆ particles_to_tree()

template<typename T >
void smash::RootOutput::particles_to_tree ( T &  particles)
private

Writes particles to a tree defined by treename.

Parameters
[in]particlesParticles or ParticleList to be written to output.

Definition at line 500 of file rootoutput.cc.

500  {
501  int i = 0;
502 
506  bool exceeded_buffer_message = true;
507 
508  for (const auto &p : particles) {
509  // Buffer full - flush to tree, else fill with particles
510  if (i >= max_buffer_size_) {
511  if (exceeded_buffer_message) {
512  logg[LOutput].warn()
513  << "\nThe number of particles N = " << particles.size()
514  << " exceeds the maximum buffer size B = " << max_buffer_size_
515  << ".\nceil(N/B) = "
516  << std::ceil(particles.size() /
517  static_cast<double>(max_buffer_size_))
518  << " separate ROOT Tree entries will be created at this output."
519  << "\nMaximum buffer size (max_buffer_size_) can be changed in "
520  << "rootoutput.h\n\n";
521  exceeded_buffer_message = false;
522  }
524  i = 0;
525  particles_tree_->Fill();
526  } else {
527  id_[i] = p.id();
528  pdgcode_[i] = p.pdgcode().get_decimal();
529  charge_[i] = p.type().charge();
530  formation_time_[i] = p.formation_time();
531  time_last_collision_[i] = p.get_history().time_last_collision;
532 
533  p0_[i] = p.momentum().x0();
534  px_[i] = p.momentum().x1();
535  py_[i] = p.momentum().x2();
536  pz_[i] = p.momentum().x3();
537 
538  t_[i] = p.position().x0();
539  x_[i] = p.position().x1();
540  y_[i] = p.position().x2();
541  z_[i] = p.position().x3();
542 
543  if (part_extended_ || ic_extended_) {
544  const auto h = p.get_history();
545  coll_per_part_[i] = h.collisions_per_particle;
546  xsec_factor_[i] = p.xsec_scaling_factor();
547  proc_id_origin_[i] = h.id_process;
548  proc_type_origin_[i] = static_cast<int>(h.process_type);
549  pdg_mother1_[i] = h.p1.get_decimal();
550  pdg_mother2_[i] = h.p2.get_decimal();
551  baryon_number_[i] = p.type().baryon_number();
552  strangeness_[i] = p.type().strangeness();
553  }
554 
555  i++;
556  }
557  }
558  // Flush rest to tree
559  if (i > 0) {
560  npart_ = i;
561  particles_tree_->Fill();
562  }
563 }
std::vector< double > t_
Property that is written to ROOT output.
Definition: rootoutput.h:177
std::vector< double > y_
Property that is written to ROOT output.
Definition: rootoutput.h:179
std::vector< int > proc_type_origin_
Property that is written to ROOT output.
Definition: rootoutput.h:187
std::vector< int > coll_per_part_
Property that is written to ROOT output.
Definition: rootoutput.h:184
int tcounter_
Property that is written to ROOT output.
Definition: rootoutput.h:159
std::vector< int > baryon_number_
Property that is written to ROOT output.
Definition: rootoutput.h:190
int npart_
Property that is written to ROOT output.
Definition: rootoutput.h:160
std::vector< int > pdg_mother1_
Property that is written to ROOT output.
Definition: rootoutput.h:188
int ev_
Property that is written to ROOT output.
Definition: rootoutput.h:157
std::vector< int > charge_
Property that is written to ROOT output.
Definition: rootoutput.h:168
std::vector< double > px_
Property that is written to ROOT output.
Definition: rootoutput.h:174
std::vector< int > strangeness_
Property that is written to ROOT output.
Definition: rootoutput.h:191
std::vector< double > py_
Property that is written to ROOT output.
Definition: rootoutput.h:175
std::vector< int > proc_id_origin_
Property that is written to ROOT output.
Definition: rootoutput.h:186
std::vector< double > z_
Property that is written to ROOT output.
Definition: rootoutput.h:180
std::vector< int > id_
Property that is written to ROOT output.
Definition: rootoutput.h:166
std::vector< double > formation_time_
Property that is written to ROOT output.
Definition: rootoutput.h:169
std::vector< double > x_
Property that is written to ROOT output.
Definition: rootoutput.h:178
std::vector< double > p0_
Property that is written to ROOT output.
Definition: rootoutput.h:173
static const int max_buffer_size_
Maximal buffer size.
Definition: rootoutput.h:150
std::vector< double > xsec_factor_
Property that is written to ROOT output.
Definition: rootoutput.h:185
std::vector< double > time_last_collision_
Property that is written to ROOT output.
Definition: rootoutput.h:171
int ens_
Property that is written to ROOT output.
Definition: rootoutput.h:158
std::vector< double > pz_
Property that is written to ROOT output.
Definition: rootoutput.h:176
std::vector< int > pdgcode_
Property that is written to ROOT output.
Definition: rootoutput.h:167
std::vector< int > pdg_mother2_
Property that is written to ROOT output.
Definition: rootoutput.h:189
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:40
constexpr int p
Proton.
static constexpr int LOutput

◆ collisions_to_tree()

void smash::RootOutput::collisions_to_tree ( const ParticleList &  incoming,
const ParticleList &  outgoing,
const double  weight,
const double  partial_weight 
)
private

Writes collisions to a tree defined by treename.

Parameters
[in]incomingIncoming particles to be written to output.
[in]outgoingOutgoing particles to be written to output.
[in]weightTotal weight of the collision.
[in]partial_weightPartial weight of the collision

Definition at line 565 of file rootoutput.cc.

568  {
571  nin_ = incoming.size();
572  nout_ = outgoing.size();
573  npart_ = nin_ + nout_;
574  wgt_ = weight;
575  par_wgt_ = partial_weight;
576 
577  int i = 0;
578 
579  /* It is assumed that nin + nout < max_buffer_size_
580  * This is true for any possible reaction for current buffer size
581  * But if one wants initial/final particles written to collisions
582  * then implementation should be updated. */
583 
584  for (const ParticleList &plist : {incoming, outgoing}) {
585  for (const auto &p : plist) {
586  id_[i] = p.id();
587  pdgcode_[i] = p.pdgcode().get_decimal();
588  charge_[i] = p.type().charge();
589  formation_time_[i] = p.formation_time();
590  time_last_collision_[i] = p.get_history().time_last_collision;
591 
592  p0_[i] = p.momentum().x0();
593  px_[i] = p.momentum().x1();
594  py_[i] = p.momentum().x2();
595  pz_[i] = p.momentum().x3();
596 
597  t_[i] = p.position().x0();
598  x_[i] = p.position().x1();
599  y_[i] = p.position().x2();
600  z_[i] = p.position().x3();
601 
602  if (coll_extended_) {
603  const auto h = p.get_history();
604  coll_per_part_[i] = h.collisions_per_particle;
605  xsec_factor_[i] = p.xsec_scaling_factor();
606  proc_id_origin_[i] = h.id_process;
607  proc_type_origin_[i] = static_cast<int>(h.process_type);
608  pdg_mother1_[i] = h.p1.get_decimal();
609  pdg_mother2_[i] = h.p2.get_decimal();
610  baryon_number_[i] = p.type().baryon_number();
611  strangeness_[i] = p.type().strangeness();
612  }
613 
614  i++;
615  }
616  }
617 
618  collisions_tree_->Fill();
619 }
int nin_
Property that is written to ROOT output.
Definition: rootoutput.h:192
double wgt_
Property that is written to ROOT output.
Definition: rootoutput.h:194
double par_wgt_
Property that is written to ROOT output.
Definition: rootoutput.h:195
int nout_
Property that is written to ROOT output.
Definition: rootoutput.h:193

◆ init_trees()

void smash::RootOutput::init_trees ( )
private

Basic initialization routine, creating the TTree objects for particles and collisions.

Definition at line 285 of file rootoutput.cc.

285  {
287  particles_tree_ = new TTree("particles", "particles");
288 
289  particles_tree_->Branch("ev", &ev_, "ev/I");
290  particles_tree_->Branch("ens", &ens_, "ens/I");
291  particles_tree_->Branch("tcounter", &tcounter_, "tcounter/I");
292  particles_tree_->Branch("npart", &npart_, "npart/I");
293  particles_tree_->Branch("test_p", &test_p_, "test_p/I");
294  particles_tree_->Branch("modus_l", &modus_l_, "modus_l/D");
295  particles_tree_->Branch("current_t", &current_t_, "current_t/D");
296  particles_tree_->Branch("impact_b", &impact_b_, "impact_b/D");
297  particles_tree_->Branch("empty_event", &empty_event_, "empty_event/O");
298 
299  particles_tree_->Branch("id", &id_[0], "id[npart]/I");
300  particles_tree_->Branch("pdgcode", &pdgcode_[0], "pdgcode[npart]/I");
301  particles_tree_->Branch("charge", &charge_[0], "charge[npart]/I");
302  particles_tree_->Branch("formation_time", &formation_time_[0],
303  "formation_time[npart]/D");
304  particles_tree_->Branch("time_last_collision", &time_last_collision_[0],
305  "time_last_collision[npart]/D");
306 
307  particles_tree_->Branch("p0", &p0_[0], "p0[npart]/D");
308  particles_tree_->Branch("px", &px_[0], "px[npart]/D");
309  particles_tree_->Branch("py", &py_[0], "py[npart]/D");
310  particles_tree_->Branch("pz", &pz_[0], "pz[npart]/D");
311 
312  particles_tree_->Branch("t", &t_[0], "t[npart]/D");
313  particles_tree_->Branch("x", &x_[0], "x[npart]/D");
314  particles_tree_->Branch("y", &y_[0], "y[npart]/D");
315  particles_tree_->Branch("z", &z_[0], "z[npart]/D");
316 
317  particles_tree_->Branch("E_kinetic_tot", &E_kinetic_tot_,
318  "E_kinetic_tot/D");
319  particles_tree_->Branch("E_fields_tot", &E_fields_tot_, "E_fields_tot/D");
320  particles_tree_->Branch("E_tot", &E_tot_, "E_tot/D");
321 
322  if (part_extended_ || ic_extended_) {
323  particles_tree_->Branch("ncoll", &coll_per_part_[0], "ncoll[npart]/I");
324  particles_tree_->Branch("xsecfac", &xsec_factor_[0], "xsecfac[npart]/D");
325  particles_tree_->Branch("proc_id_origin", &proc_id_origin_[0],
326  "proc_id_origin[npart]/I");
327  particles_tree_->Branch("proc_type_origin", &proc_type_origin_[0],
328  "proc_type_origin[npart]/I");
329  particles_tree_->Branch("pdg_mother1", &pdg_mother1_[0],
330  "pdg_mother1[npart]/I");
331  particles_tree_->Branch("pdg_mother2", &pdg_mother2_[0],
332  "pdg_mother2[npart]/I");
333  particles_tree_->Branch("baryon_number", &baryon_number_[0],
334  "baryon_number[npart]/I");
335  particles_tree_->Branch("strangeness", &strangeness_[0],
336  "strangeness[npart]/I");
337  }
338  }
339 
340  if (write_collisions_) {
341  collisions_tree_ = new TTree("collisions", "collisions");
342 
343  collisions_tree_->Branch("ev", &ev_, "ev/I");
344  collisions_tree_->Branch("ens", &ens_, "ens/I");
345 
346  collisions_tree_->Branch("nin", &nin_, "nin/I");
347  collisions_tree_->Branch("nout", &nout_, "nout/I");
348  collisions_tree_->Branch("npart", &npart_, "npart/I");
349  collisions_tree_->Branch("weight", &wgt_, "weight/D");
350  collisions_tree_->Branch("partial_weight", &par_wgt_, "partial_weight/D");
351 
352  collisions_tree_->Branch("id", &id_[0], "id[npart]/I");
353  collisions_tree_->Branch("pdgcode", &pdgcode_[0], "pdgcode[npart]/I");
354  collisions_tree_->Branch("charge", &charge_[0], "charge[npart]/I");
355  collisions_tree_->Branch("formation_time", &formation_time_[0],
356  "formation_time[npart]/D");
357  collisions_tree_->Branch("time_last_collision", &time_last_collision_[0],
358  "time_last_collision[npart]/D");
359 
360  collisions_tree_->Branch("p0", &p0_[0], "p0[npart]/D");
361  collisions_tree_->Branch("px", &px_[0], "px[npart]/D");
362  collisions_tree_->Branch("py", &py_[0], "py[npart]/D");
363  collisions_tree_->Branch("pz", &pz_[0], "pz[npart]/D");
364 
365  collisions_tree_->Branch("t", &t_[0], "t[npart]/D");
366  collisions_tree_->Branch("x", &x_[0], "x[npart]/D");
367  collisions_tree_->Branch("y", &y_[0], "y[npart]/D");
368  collisions_tree_->Branch("z", &z_[0], "z[npart]/D");
369 
370  if (coll_extended_) {
371  collisions_tree_->Branch("ncoll", &coll_per_part_[0], "ncoll[npart]/I");
372  collisions_tree_->Branch("xsecfac", &xsec_factor_[0], "xsecfac[npart]/D");
373  collisions_tree_->Branch("proc_id_origin", &proc_id_origin_[0],
374  "proc_id_origin[npart]/I");
375  collisions_tree_->Branch("proc_type_origin", &proc_type_origin_[0],
376  "proc_type_origin[npart]/I");
377  collisions_tree_->Branch("pdg_mother1", &pdg_mother1_[0],
378  "pdg_mother1[npart]/I");
379  collisions_tree_->Branch("pdg_mother2", &pdg_mother2_[0],
380  "pdg_mother2[npart]/I");
381  collisions_tree_->Branch("baryon_number", &baryon_number_[0],
382  "baryon_number[npart]/I");
383  collisions_tree_->Branch("strangeness", &strangeness_[0],
384  "strangeness[npart]/I");
385  }
386  }
387 }

Member Data Documentation

◆ filename_

const std::filesystem::path smash::RootOutput::filename_
private

Filename of output.

Definition at line 102 of file rootoutput.h.

◆ filename_unfinished_

std::filesystem::path smash::RootOutput::filename_unfinished_
private

Filename of output as long as simulation is still running.

Definition at line 104 of file rootoutput.h.

◆ root_out_file_

std::unique_ptr<TFile> smash::RootOutput::root_out_file_
private

Pointer to root output file.

Definition at line 106 of file rootoutput.h.

◆ particles_tree_

TTree* smash::RootOutput::particles_tree_
private

TTree for particles output.

TFile takes ownership of all TTrees. That's why TTree is not a unique pointer.

Definition at line 113 of file rootoutput.h.

◆ collisions_tree_

TTree* smash::RootOutput::collisions_tree_
private

TTree for collision output.

TFile takes ownership of all TTrees. That's why TTree is not a unique pointer.

Definition at line 120 of file rootoutput.h.

◆ output_counter_

int smash::RootOutput::output_counter_ = 0
private

Number of output in a given event.

Definition at line 138 of file rootoutput.h.

◆ current_event_

int smash::RootOutput::current_event_ = 0
private

Number of current event.

Definition at line 140 of file rootoutput.h.

◆ current_ensemble_

int smash::RootOutput::current_ensemble_ = 0
private

Number of current ensemble.

Definition at line 142 of file rootoutput.h.

◆ max_buffer_size_

const int smash::RootOutput::max_buffer_size_ = 500000
staticprivate

Maximal buffer size.

When the number of particles N exceeds the buffer size B, data is flushed to the ROOT file every B particles. This creates ceil(N/B) entries in the ROOT Tree at every output.

Definition at line 150 of file rootoutput.h.

◆ ev_

int smash::RootOutput::ev_ {}
private

Property that is written to ROOT output.

Definition at line 157 of file rootoutput.h.

◆ ens_

int smash::RootOutput::ens_ {}
private

Property that is written to ROOT output.

Definition at line 158 of file rootoutput.h.

◆ tcounter_

int smash::RootOutput::tcounter_ {}
private

Property that is written to ROOT output.

Definition at line 159 of file rootoutput.h.

◆ npart_

int smash::RootOutput::npart_ {}
private

Property that is written to ROOT output.

Definition at line 160 of file rootoutput.h.

◆ test_p_

int smash::RootOutput::test_p_ {}
private

Property that is written to ROOT output.

Definition at line 161 of file rootoutput.h.

◆ modus_l_

double smash::RootOutput::modus_l_ {}
private

Property that is written to ROOT output.

Definition at line 162 of file rootoutput.h.

◆ current_t_

double smash::RootOutput::current_t_ {}
private

Property that is written to ROOT output.

Definition at line 163 of file rootoutput.h.

◆ impact_b_

double smash::RootOutput::impact_b_ {}
private

Property that is written to ROOT output.

Definition at line 164 of file rootoutput.h.

◆ empty_event_

bool smash::RootOutput::empty_event_ {}
private

Property that is written to ROOT output.

Definition at line 165 of file rootoutput.h.

◆ id_

std::vector<int> smash::RootOutput::id_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 166 of file rootoutput.h.

◆ pdgcode_

std::vector<int> smash::RootOutput::pdgcode_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 167 of file rootoutput.h.

◆ charge_

std::vector<int> smash::RootOutput::charge_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 168 of file rootoutput.h.

◆ formation_time_

std::vector<double> smash::RootOutput::formation_time_
private
Initial value:
=
std::vector<double>(max_buffer_size_, 0.0)

Property that is written to ROOT output.

Definition at line 169 of file rootoutput.h.

◆ time_last_collision_

std::vector<double> smash::RootOutput::time_last_collision_
private
Initial value:
=
std::vector<double>(max_buffer_size_, 0.0)

Property that is written to ROOT output.

Definition at line 171 of file rootoutput.h.

◆ p0_

std::vector<double> smash::RootOutput::p0_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 173 of file rootoutput.h.

◆ px_

std::vector<double> smash::RootOutput::px_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 174 of file rootoutput.h.

◆ py_

std::vector<double> smash::RootOutput::py_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 175 of file rootoutput.h.

◆ pz_

std::vector<double> smash::RootOutput::pz_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 176 of file rootoutput.h.

◆ t_

std::vector<double> smash::RootOutput::t_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 177 of file rootoutput.h.

◆ x_

std::vector<double> smash::RootOutput::x_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 178 of file rootoutput.h.

◆ y_

std::vector<double> smash::RootOutput::y_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 179 of file rootoutput.h.

◆ z_

std::vector<double> smash::RootOutput::z_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 180 of file rootoutput.h.

◆ E_kinetic_tot_

double smash::RootOutput::E_kinetic_tot_ {}
private

Property that is written to ROOT output.

Definition at line 181 of file rootoutput.h.

◆ E_fields_tot_

double smash::RootOutput::E_fields_tot_ {}
private

Property that is written to ROOT output.

Definition at line 182 of file rootoutput.h.

◆ E_tot_

double smash::RootOutput::E_tot_ {}
private

Property that is written to ROOT output.

Definition at line 183 of file rootoutput.h.

◆ coll_per_part_

std::vector<int> smash::RootOutput::coll_per_part_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 184 of file rootoutput.h.

◆ xsec_factor_

std::vector<double> smash::RootOutput::xsec_factor_ = std::vector<double>(max_buffer_size_, 0.0)
private

Property that is written to ROOT output.

Definition at line 185 of file rootoutput.h.

◆ proc_id_origin_

std::vector<int> smash::RootOutput::proc_id_origin_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 186 of file rootoutput.h.

◆ proc_type_origin_

std::vector<int> smash::RootOutput::proc_type_origin_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 187 of file rootoutput.h.

◆ pdg_mother1_

std::vector<int> smash::RootOutput::pdg_mother1_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 188 of file rootoutput.h.

◆ pdg_mother2_

std::vector<int> smash::RootOutput::pdg_mother2_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 189 of file rootoutput.h.

◆ baryon_number_

std::vector<int> smash::RootOutput::baryon_number_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 190 of file rootoutput.h.

◆ strangeness_

std::vector<int> smash::RootOutput::strangeness_ = std::vector<int>(max_buffer_size_, 0)
private

Property that is written to ROOT output.

Definition at line 191 of file rootoutput.h.

◆ nin_

int smash::RootOutput::nin_ {}
private

Property that is written to ROOT output.

Definition at line 192 of file rootoutput.h.

◆ nout_

int smash::RootOutput::nout_ {}
private

Property that is written to ROOT output.

Definition at line 193 of file rootoutput.h.

◆ wgt_

double smash::RootOutput::wgt_ {}
private

Property that is written to ROOT output.

Definition at line 194 of file rootoutput.h.

◆ par_wgt_

double smash::RootOutput::par_wgt_ {}
private

Property that is written to ROOT output.

Definition at line 195 of file rootoutput.h.

◆ write_collisions_

bool smash::RootOutput::write_collisions_
private

Option to write collisions tree.

Definition at line 199 of file rootoutput.h.

◆ write_particles_

bool smash::RootOutput::write_particles_
private

Option to write particles tree.

Definition at line 202 of file rootoutput.h.

◆ write_initial_conditions_

bool smash::RootOutput::write_initial_conditions_
private

Option to write particles tree for initial conditions.

Definition at line 205 of file rootoutput.h.

◆ particles_only_final_

OutputOnlyFinal smash::RootOutput::particles_only_final_
private

Print only final particles in the event (no intermediate output).

Definition at line 208 of file rootoutput.h.

◆ autosave_frequency_

int smash::RootOutput::autosave_frequency_ = -1
private

ROOT file cannot be read if it was not properly closed and finalized.

It can happen that SMASH simulation crashed and ROOT file was not closed. To save results of simulation in such case, "AutoSave" is applied every N events. If multiple ensembles are used, N is divided by the number of ensembles per event. This makes sense especially in case of a large number of ensembles and, at the same time, it ensures that all ensembles belonging to the same event are saved. The autosave_frequency_ sets this N (at the moment N=1000 is hard-coded). Note that "AutoSave" operation is very time-consuming, so the autosave frequency is always a compromise between safety and speed.

Definition at line 222 of file rootoutput.h.

◆ part_extended_

const bool smash::RootOutput::part_extended_
private

Whether extended particle output is on.

Definition at line 225 of file rootoutput.h.

◆ coll_extended_

const bool smash::RootOutput::coll_extended_
private

Whether extended collisions output is on.

Definition at line 227 of file rootoutput.h.

◆ ic_extended_

const bool smash::RootOutput::ic_extended_
private

Whether extended ic output is on.

Definition at line 229 of file rootoutput.h.


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