Version: SMASH-1.7
customnucleus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2019
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include <cmath>
8 #include <fstream>
9 #include <map>
10 #include <string>
11 #include <vector>
12 
13 #include "smash/constants.h"
14 #include "smash/customnucleus.h"
15 #include "smash/particledata.h"
16 #include "smash/particletype.h"
17 #include "smash/pdgcode.h"
19 #include "smash/random.h"
20 
21 namespace smash {
22 
90 std::unique_ptr<std::ifstream> CustomNucleus::filestream_shared_ = nullptr;
91 
92 CustomNucleus::CustomNucleus(Configuration& config, int testparticles,
93  bool same_file) {
94  // Read in file directory from config
95  std::string particle_list_file_directory =
96  config.take({"Custom", "File_Directory"});
97  // Read in file name from config
98  std::string particle_list_file_name = config.take({"Custom", "File_Name"});
99 
100  if (particles_.size() != 0) {
101  throw std::runtime_error(
102  "Your Particle List is already filled before reading in from the "
103  "external file."
104  "Something went wrong. Please check your config.");
105  }
106  /*
107  * Counts number of nucleons in one nucleus as it is specialized
108  * by the user in the config file.
109  * It is needed to read in the proper number of nucleons for one
110  * nucleus and to restart at the listreading for the following
111  * nucleus as one does not want to read configurations twice.
112  */
113  std::map<PdgCode, int> particle_list = config.take({"Particles"});
114  for (const auto& particle : particle_list)
115  number_of_nucleons_ += particle.second * testparticles;
116  /*
117  * "if" statement makes sure the streams to the file are initialized
118  * properly.
119  */
120  const std::string path =
121  file_path(particle_list_file_directory, particle_list_file_name);
122  if (same_file && !filestream_shared_) {
123  filestream_shared_ = make_unique<std::ifstream>(path);
125  } else if (!same_file) {
126  filestream_ = make_unique<std::ifstream>(path);
128  } else {
130  }
131 
134  // Inherited from nucleus class (see nucleus.h)
136 }
137 
138 void CustomNucleus::fill_from_list(const std::vector<Nucleoncustom>& vec) {
139  particles_.clear();
140  index = 0;
141  // checking if particle is proton or neutron
142  for (const auto& it : vec) {
143  PdgCode pdgcode;
144  if (it.isospin == 1) {
145  pdgcode = pdg::p;
146  } else if (it.isospin == 0) {
147  pdgcode = pdg::n;
148  } else {
149  throw std::runtime_error(
150  "Your particles charges are not 1 = proton or 0 = neutron."
151  "Check whether your list is correct or there is an error.");
152  }
153  // setting parameters for the particles in the particlelist in smash
154  const ParticleType& current_type = ParticleType::find(pdgcode);
155  double current_mass = current_type.mass();
156  particles_.emplace_back(current_type);
157  particles_.back().set_4momentum(current_mass, 0.0, 0.0, 0.0);
158  }
159 }
160 
162  /*
163  * As only arrange_nucleons is called at the beginning of every
164  * event it is important to have readfile and fill from list
165  * called again when a new event starts. The constructor is only
166  * called twice to initialize the first target and projectile.
167  * Therefore this if statement is implemented.
168  */
169  if (index >= custom_nucleus_.size()) {
172  }
173  const auto& pos = custom_nucleus_.at(index);
174  index++;
175  ThreeVector nucleon_position(pos.x, pos.y, pos.z);
176  // rotate nucleon about euler angle
177  nucleon_position.rotate(euler_phi_, euler_theta_, euler_psi_);
178 
179  return nucleon_position;
180 }
181 
183  /* Randomly generate Euler angles for rotation everytime a new
184  * custom nucleus is initialiezed. Therefore this is done 2 times per
185  * event.
186  */
188 
189  for (auto i = begin(); i != end(); i++) {
190  // Initialize momentum
191  i->set_4momentum(i->pole_mass(), 0.0, 0.0, 0.0);
192  /* Sampling the Woods-Saxon, get the radial
193  * position and solid angle for the nucleon. */
195  // Set the position of the nucleon.
196  i->set_4position(FourVector(0.0, pos));
197  }
198  // Recenter
199  align_center();
200 }
201 
204  const auto& log = logger<LogArea::Collider>();
205  log.warn() << "Fermi motion activated with a custom nucleus.\n";
206  log.warn() << "Be aware that generating the Fermi momenta\n"
207  << "assumes nucleons distributed according to a\n"
208  << "Woods-Saxon distribution.";
209 }
210 
211 std::string CustomNucleus::file_path(const std::string& file_directory,
212  const std::string& file_name) {
213  if (file_directory.back() == '/') {
214  return file_directory + file_name;
215  } else {
216  return file_directory + '/' + file_name;
217  }
218 }
219 
220 std::vector<Nucleoncustom> CustomNucleus::readfile(std::ifstream& infile,
221  int particle_number) const {
222  int A = particle_number;
223  std::string line;
224  std::vector<Nucleoncustom> custom_nucleus;
225  // read in only A particles for one nucleus
226  for (int i = 0; i < A; ++i) {
227  std::getline(infile, line);
228  // make sure the stream goes back to the beginning when it hits end of file
229  if (infile.eof()) {
230  infile.clear();
231  infile.seekg(0, infile.beg);
232  std::getline(infile, line);
233  }
234  Nucleoncustom nucleon;
235  std::istringstream iss(line);
236  if (!(iss >> nucleon.x >> nucleon.y >> nucleon.z >>
237  nucleon.spinprojection >> nucleon.isospin)) {
238  throw std::runtime_error(
239  "SMASH could not read in a line from your initial nuclei input file."
240  "Check if your file has the following format: x y z spinprojection "
241  "isospin");
242  break;
243  }
244  custom_nucleus.push_back(nucleon);
245  }
246  return custom_nucleus;
247 }
248 
249 } // namespace smash
double euler_psi_
Euler angel psi.
Definition: nucleus.h:269
double x
x-coordinate
Definition: customnucleus.h:24
void generate_fermi_momenta() override
Generates Fermi momenta as it is done in the mother class but in addition prints a warning that the F...
std::vector< Nucleoncustom > readfile(std::ifstream &infile, int particle_number) const
The returned vector contains Data for one nucleus given in the particlelist.
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
double y
y-coordinate
Definition: customnucleus.h:26
bool isospin
to differentiate between protons isospin=1 and neutrons isospin=0
Definition: customnucleus.h:32
std::vector< Nucleoncustom > custom_nucleus_
Vector contianing Data for one nucleus given in the particlelist.
Definition: customnucleus.h:95
Collection of useful constants that are known at compile time.
double euler_phi_
Euler angel phi.
Definition: nucleus.h:265
size_t index
Index needed to read out vector in distribute nucleon.
Definition: customnucleus.h:97
int number_of_nucleons_
Number of Nucleons per Nucleus Set initally to zero to be modified in the constructor.
Definition: customnucleus.h:93
CustomNucleus(Configuration &config, int testparticles, bool same_file)
Constructor that needs configuration parameters from input file and the number of testparticles...
std::unique_ptr< std::ifstream > filestream_
Filestream variable used if projectile and target are read in from different files and they therefore...
Interface to the SMASH configuration files.
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
void arrange_nucleons() override
Sets the positions of the nucleons inside a nucleus.
Contains data for one nucleon that is read in from the list.
Definition: customnucleus.h:22
double mass() const
Definition: particletype.h:144
std::string file_path(const std::string &file_directory, const std::string &file_name)
Generates the name of the stream file.
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
static std::unique_ptr< std::ifstream > filestream_shared_
Filestream variable used if projectile and target are read in from the same file and they use the sam...
Particle type contains the static properties of a particle species.
Definition: particletype.h:97
virtual void generate_fermi_momenta()
Generates momenta according to Fermi motion for the nucleons.
Definition: nucleus.cc:368
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:108
double euler_theta_
Euler angel theta.
Definition: nucleus.h:267
bool spinprojection
spinprojection of the nucleon
Definition: customnucleus.h:30
void random_euler_angles()
Randomly generate Euler angles.
Definition: nucleus.cc:501
void fill_from_list(const std::vector< Nucleoncustom > &vec)
Fills Particlelist from vector containing data for one nucleus.
std::unique_ptr< std::ifstream > * used_filestream_
Pointer to the used filestream pointer.
constexpr int p
Proton.
std::vector< ParticleData > particles_
Particles associated with this nucleus.
Definition: nucleus.h:256
std::vector< ParticleData >::iterator begin()
For iterators over the particle list:
Definition: nucleus.h:273
constexpr int n
Neutron.
virtual void set_parameters_automatic()
Sets the deformation parameters of the Woods-Saxon distribution according to the current mass number...
Definition: nucleus.cc:283
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
void align_center()
Shifts the nucleus so that its center is at (0,0,0)
Definition: nucleus.h:215
ThreeVector distribute_nucleon() override
Returns position of a nucleon as given in the external file.
void rotate(double phi, double theta, double psi)
Rotate vector by the given Euler angles phi, theta, psi.
Definition: threevector.h:276
Definition: action.h:24
double z
z-coordinate
Definition: customnucleus.h:28
std::vector< ParticleData >::iterator end()
For iterators over the particle list:
Definition: nucleus.h:277