Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_collider.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file test_collider.cxx
1 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
2 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
3 // MIT License
4 
5 #include "../src/collider.h"
6 
7 #include "catch.hpp"
8 #include "util.h"
9 
10 #include <iostream>
11 
12 #include "../src/nucleus.h"
13 
14 using namespace trento;
15 
16 TEST_CASE( "collider" ) {
17  constexpr auto N = 5;
18 
19  auto var_map = make_var_map({
20  {"number-events", N},
21  {"quiet", false},
22  {"random-seed", static_cast<int64_t>(-1)},
23  {"projectile", std::vector<std::string>{"Pb", "Pb"}},
24  {"b-min", 0.},
25  {"b-max", -1.},
26  {"normalization", 1.},
27  {"reduced-thickness", 0.},
28  {"grid-max", 9.},
29  {"grid-step", 0.3},
30  {"fluctuation", 1.},
31  {"cross-section", 6.4},
32  {"nucleon-width", 0.5},
33  {"nucleon-min-dist", 0.},
34  });
35 
36  std::vector<int> nevent, npart;
37  std::vector<double> impact, mult;
38 
39  // run collider normally and save output
40  {
41  capture_stdout capture;
42 
43  Collider collider{var_map};
44  collider.run_events();
45 
47  while (std::getline(capture.stream, line)) {
48  nevent.push_back(0);
49  impact.push_back(0);
50  npart.push_back(0);
51  mult.push_back(0);
52  std::istringstream(line) >> nevent.back()
53  >> impact.back()
54  >> npart.back()
55  >> mult.back();
56  }
57  }
58 
59  // event numbers should be an integer sequence from zero
60  std::vector<int> sequence(N);
61  std::iota(sequence.begin(), sequence.end(), 0);
62  CHECK( nevent == sequence );
63 
64  // verify impact parameters are within min-bias range
65  auto impact_max = 2*Nucleus::create("Pb")->radius() + 6*.5;
66  CHECK( impact >= std::vector<double>(N, 0.) );
67  CHECK( impact <= std::vector<double>(N, impact_max) );
68 
69  // verify all events have at least 2 participants and at most 416 for PbPb
70  CHECK( npart >= std::vector<int>(N, 2) );
71  CHECK( npart <= std::vector<int>(N, 416) );
72 
73  // nonzero multiplicity
74  CHECK( mult >= std::vector<double>(N, 0.) );
75 }
76 
77 TEST_CASE( "fixed impact parameter" ) {
78  constexpr auto N = 5;
79  constexpr auto bfixed = 4.;
80 
81  auto var_map = make_var_map({
82  {"number-events", N},
83  {"quiet", false},
84  {"random-seed", static_cast<int64_t>(-1)},
85  {"projectile", std::vector<std::string>{"Au", "Au"}},
86  {"b-min", bfixed},
87  {"b-max", bfixed},
88  {"normalization", 1.},
89  {"reduced-thickness", 0.},
90  {"grid-max", 9.},
91  {"grid-step", 0.3},
92  {"fluctuation", 1.},
93  {"cross-section", 6.4},
94  {"nucleon-width", 0.5},
95  {"nucleon-min-dist", 0.2},
96  });
97 
98  std::vector<double> impact;
99 
100  {
101  Collider collider{var_map};
102 
103  capture_stdout capture;
104  collider.run_events();
105 
107  while (std::getline(capture.stream, line)) {
108  double x;
109  std::istringstream(line) >> x >> x;
110  impact.push_back(x);
111  }
112  }
113 
114  // all events have the specified impact parameter
115  CHECK( std::all_of(impact.cbegin(), impact.cend(),
116  [&bfixed](double b) { return b == Approx(bfixed); }) );
117 }
118 
119 TEST_CASE( "random seed" ) {
120  std::vector<std::string> output(5);
121 
122  const auto seed = static_cast<int64_t>(std::random_device{}());
123 
124  // run several collider batches with the same seed
125  std::generate(output.begin(), output.end(),
126  [&seed]() {
127  Collider collider{make_var_map({
128  {"number-events", 3},
129  {"quiet", false},
130  {"random-seed", seed},
131  {"projectile", std::vector<std::string>{"p", "U"}},
132  {"b-min", 0.},
133  {"b-max", -1.},
134  {"normalization", 1.},
135  {"reduced-thickness", 0.},
136  {"grid-max", 9.},
137  {"grid-step", 0.3},
138  {"fluctuation", 1.},
139  {"cross-section", 6.4},
140  {"nucleon-width", 0.5},
141  {"nucleon-min-dist", 0.4},
142  })};
143 
144  capture_stdout capture;
145  collider.run_events();
146 
147  return capture.stream.str();
148  });
149 
150  // all collider batches are identical
151  CHECK( std::all_of(output.cbegin(), output.cend(),
152  [&output](const std::string& s) { return s == output.front(); }) );
153 }