Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nucleus.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file nucleus.h
1 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
2 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
3 // TRENTO3D: Three-dimensional extension of TRENTO by Weiyao Ke
4 // MIT License
5 
6 #ifndef NUCLEUS_H
7 #define NUCLEUS_H
8 
9 #include <memory>
10 #include <random>
11 #include <string>
12 #include <vector>
13 
14 #include "fwd_decl.h"
15 #include "nucleon.h"
16 
17 #ifdef TRENTO_HDF5
18 // forward declaration for std::unique_ptr<H5::DataSet> member of ManualNucleus
19 namespace H5 {
20 class DataSet;
21 }
22 #endif
23 
24 namespace trento {
25 
26 // Alias for a smart pointer to a Nucleus.
27 using NucleusPtr = std::unique_ptr<Nucleus>;
28 
35 class Nucleus {
36  public:
62  static NucleusPtr create(const std::string& species, double nucleon_width, double nucleon_dmin = 0);
63 
65  virtual ~Nucleus() = default;
66 
69  virtual double radius() const = 0;
70 
73  void sample_nucleons(double offset);
74 
75  using size_type = std::vector<Nucleon>::size_type;
76  using iterator = std::vector<Nucleon>::iterator;
77  using const_iterator = std::vector<Nucleon>::const_iterator;
78 
79  // size = number of nucleons
80  size_type size() const noexcept
81  { return nucleons_.size(); }
82 
83  // non-const overload
84  iterator begin() noexcept
85  { return nucleons_.begin(); }
86  iterator end() noexcept
87  { return nucleons_.end(); }
88 
89  // const overload
90  const_iterator begin() const noexcept
91  { return nucleons_.begin(); }
92  const_iterator end() const noexcept
93  { return nucleons_.end(); }
94 
95  // forced const
96  const_iterator cbegin() const noexcept
97  { return nucleons_.cbegin(); }
98  const_iterator cend() const noexcept
99  { return nucleons_.cend(); }
100 
101  protected:
104  explicit Nucleus(std::size_t A);
105 
112  void set_nucleon_position(iterator nucleon, double x, double y, double z);
113 
114  private:
119  virtual void sample_nucleons_impl() = 0;
120 
122  std::vector<Nucleon> nucleons_;
123 
127  double offset_;
128 };
129 
130 // Now declare Nucleus subclasses.
131 // Each subclass must do the following:
132 // - Define a public constructor which (at minimum) initializes a Nucleus
133 // with the required number of nucleons.
134 // - Override and implement the pure virtual functions
135 // radius() and sample_nucleons_impl().
136 
138 class Proton : public Nucleus {
139  public:
141  Proton();
142 
144  virtual double radius() const override;
145 
146  private:
148  virtual void sample_nucleons_impl() override;
149 };
150 
161 class Deuteron : public Nucleus {
162  public:
165  Deuteron(double a = 0.457, double b = 2.35);
166 
168  virtual double radius() const override;
169 
170  private:
172  virtual void sample_nucleons_impl() override;
173 
175  const double a_, b_;
176 };
177 
180 class MinDistNucleus : public Nucleus {
181  protected:
184  MinDistNucleus(std::size_t A, double dmin = 0);
185 
191  bool is_too_close(const_iterator nucleon) const;
192 
193  private:
195  const double dminsq_;
196 };
197 
209  public:
215  WoodsSaxonNucleus(std::size_t A, double R, double a, double dmin = 0);
216 
218  virtual double radius() const override;
219 
220  private:
222  virtual void sample_nucleons_impl() override;
223 
225  const double R_, a_;
226 
230  mutable std::piecewise_linear_distribution<double> woods_saxon_dist_;
231 };
232 
245  public:
253  DeformedWoodsSaxonNucleus(std::size_t A, double R, double a,
254  double beta2, double beta4, double dmin = 0);
255 
258  virtual double radius() const override;
259 
260  private:
262  virtual void sample_nucleons_impl() override;
263 
265  double deformed_woods_saxon_dist(double r, double cos_theta) const;
266 
268  const double R_, a_, beta2_, beta4_;
269 
271  const double rmax_;
272 };
273 
274 #ifdef TRENTO_HDF5
275 
277 class ManualNucleus : public Nucleus {
278  public:
288  static std::unique_ptr<ManualNucleus> create(const std::string& path);
289 
292  virtual ~ManualNucleus() override;
293 
296  virtual double radius() const override;
297 
298  private:
304  ManualNucleus(std::unique_ptr<H5::DataSet> dataset,
305  std::size_t nconfigs, std::size_t A, double rmax);
306 
308  virtual void sample_nucleons_impl() override;
309 
311  const std::unique_ptr<H5::DataSet> dataset_;
312 
314  const double rmax_;
315 
317  std::uniform_int_distribution<std::size_t> index_dist_;
318 };
319 
320 #endif // TRENTO_HDF5
321 
322 } // namespace trento
323 
324 #endif // NUCLEUS_H