Version: SMASH-3.3
rootoutput.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020,2022-2025
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_ROOTOUTPUT_H_
11 #define SRC_INCLUDE_SMASH_ROOTOUTPUT_H_
12 
13 #include <filesystem>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "TFile.h"
19 #include "TTree.h"
20 #include "configuration.h"
21 #include "forwarddeclarations.h"
22 #include "outputinterface.h"
23 #include "outputparameters.h"
24 
25 namespace smash {
26 class Particles;
27 
46 class RootOutput : public OutputInterface {
47  public:
55  RootOutput(const std::filesystem::path &path, const std::string &name,
56  const OutputParameters &out_par);
57 
59  ~RootOutput();
60 
67  void at_eventstart(const Particles &particles, const EventLabel &event_label,
68  const EventInfo &event) override;
76  void at_eventend(const Particles &particles, const EventLabel &event_label,
77  const EventInfo &event) override;
87  void at_intermediate_time(const Particles &particles,
88  const std::unique_ptr<Clock> &clock,
89  const DensityParameters &dens_param,
90  const EventLabel &event_label,
91  const EventInfo &event) override;
98  void at_interaction(const Action &action, const double density) override;
99 
100  private:
102  const std::filesystem::path filename_;
104  std::filesystem::path filename_unfinished_;
106  std::unique_ptr<TFile> root_out_file_;
125  template <typename T>
126  void particles_to_tree(T &particles);
134  void collisions_to_tree(const ParticleList &incoming,
135  const ParticleList &outgoing, const double weight,
136  const double partial_weight);
140  int current_event_ = 0;
143 
150  static const int max_buffer_size_;
151 
157  int ev_{};
158  int ens_{};
159  int tcounter_{};
160  int npart_{};
161  int test_p_{};
162  double modus_l_{};
163  double current_t_{};
164  double impact_b_{};
165  bool empty_event_{};
166  std::vector<int> id_ = std::vector<int>(max_buffer_size_, 0);
167  std::vector<int> pdgcode_ = std::vector<int>(max_buffer_size_, 0);
168  std::vector<int> charge_ = std::vector<int>(max_buffer_size_, 0);
169  std::vector<double> formation_time_ =
170  std::vector<double>(max_buffer_size_, 0.0);
171  std::vector<double> time_last_collision_ =
172  std::vector<double>(max_buffer_size_, 0.0);
173  std::vector<double> p0_ = std::vector<double>(max_buffer_size_, 0.0);
174  std::vector<double> px_ = std::vector<double>(max_buffer_size_, 0.0);
175  std::vector<double> py_ = std::vector<double>(max_buffer_size_, 0.0);
176  std::vector<double> pz_ = std::vector<double>(max_buffer_size_, 0.0);
177  std::vector<double> t_ = std::vector<double>(max_buffer_size_, 0.0);
178  std::vector<double> x_ = std::vector<double>(max_buffer_size_, 0.0);
179  std::vector<double> y_ = std::vector<double>(max_buffer_size_, 0.0);
180  std::vector<double> z_ = std::vector<double>(max_buffer_size_, 0.0);
181  double E_kinetic_tot_{};
182  double E_fields_tot_{};
183  double E_tot_{};
184  std::vector<int> coll_per_part_ = std::vector<int>(max_buffer_size_, 0);
185  std::vector<double> xsec_factor_ = std::vector<double>(max_buffer_size_, 0.0);
186  std::vector<int> proc_id_origin_ = std::vector<int>(max_buffer_size_, 0);
187  std::vector<int> proc_type_origin_ = std::vector<int>(max_buffer_size_, 0);
188  std::vector<int> pdg_mother1_ = std::vector<int>(max_buffer_size_, 0);
189  std::vector<int> pdg_mother2_ = std::vector<int>(max_buffer_size_, 0);
190  std::vector<int> baryon_number_ = std::vector<int>(max_buffer_size_, 0);
191  std::vector<int> strangeness_ = std::vector<int>(max_buffer_size_, 0);
192  int nin_{};
193  int nout_{};
194  double wgt_{};
195  double par_wgt_{};
197 
200 
203 
206 
209 
223 
225  const bool part_extended_;
227  const bool coll_extended_;
229  const bool ic_extended_;
230 
235  void init_trees();
236 };
237 
238 } // namespace smash
239 
240 #endif // SRC_INCLUDE_SMASH_ROOTOUTPUT_H_
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:92
Abstraction of generic output.
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
void at_interaction(const Action &action, const double density) override
Writes collisions to a tree defined by treename.
Definition: rootoutput.cc:485
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
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....
Definition: rootoutput.cc:424
double current_t_
Property that is written to ROOT output.
Definition: rootoutput.h:163
OutputOnlyFinal particles_only_final_
Print only final particles in the event (no intermediate output).
Definition: rootoutput.h:208
int current_event_
Number of current event.
Definition: rootoutput.h:140
TTree * collisions_tree_
TTree for collision output.
Definition: rootoutput.h:120
~RootOutput()
Destructor.
Definition: rootoutput.cc:393
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
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
void at_eventstart(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
update event number and writes intermediate particles to a tree.
Definition: rootoutput.cc:400
int autosave_frequency_
ROOT file cannot be read if it was not properly closed and finalized.
Definition: rootoutput.h:222
std::vector< int > proc_type_origin_
Property that is written to ROOT output.
Definition: rootoutput.h:187
double modus_l_
Property that is written to ROOT output.
Definition: rootoutput.h:162
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 nin_
Property that is written to ROOT output.
Definition: rootoutput.h:192
int ev_
Property that is written to ROOT output.
Definition: rootoutput.h:157
bool write_collisions_
Option to write collisions tree.
Definition: rootoutput.h:199
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
const std::filesystem::path filename_
Filename of output.
Definition: rootoutput.h:102
std::vector< int > strangeness_
Property that is written to ROOT output.
Definition: rootoutput.h:191
bool write_initial_conditions_
Option to write particles tree for initial conditions.
Definition: rootoutput.h:205
double wgt_
Property that is written to ROOT output.
Definition: rootoutput.h:194
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
void particles_to_tree(T &particles)
Writes particles to a tree defined by treename.
Definition: rootoutput.cc:500
const bool part_extended_
Whether extended particle output is on.
Definition: rootoutput.h:225
double impact_b_
Property that is written to ROOT output.
Definition: rootoutput.h:164
RootOutput(const std::filesystem::path &path, const std::string &name, const OutputParameters &out_par)
Construct ROOT output.
Definition: rootoutput.cc:266
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
int current_ensemble_
Number of current ensemble.
Definition: rootoutput.h:142
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.
Definition: rootoutput.cc:443
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
bool empty_event_
Property that is written to ROOT output.
Definition: rootoutput.h:165
static const int max_buffer_size_
Maximal buffer size.
Definition: rootoutput.h:150
std::unique_ptr< TFile > root_out_file_
Pointer to root output file.
Definition: rootoutput.h:106
std::vector< double > xsec_factor_
Property that is written to ROOT output.
Definition: rootoutput.h:185
double E_fields_tot_
Property that is written to ROOT output.
Definition: rootoutput.h:182
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
std::vector< double > time_last_collision_
Property that is written to ROOT output.
Definition: rootoutput.h:171
double par_wgt_
Property that is written to ROOT output.
Definition: rootoutput.h:195
void init_trees()
Basic initialization routine, creating the TTree objects for particles and collisions.
Definition: rootoutput.cc:285
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
TTree * particles_tree_
TTree for particles output.
Definition: rootoutput.h:113
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
int nout_
Property that is written to ROOT output.
Definition: rootoutput.h:193
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
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
OutputOnlyFinal
Whether and when only final state particles should be printed.
Definition: action.h:24
Structure to contain custom data for output.
Structure to contain information about the event and ensemble numbers.
Helper structure for Experiment to hold output options and parameters.