Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:07

0001 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
0002 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
0003 // MIT License
0004 
0005 #include "../src/collider.h"
0006 
0007 #include "catch.hpp"
0008 #include "util.h"
0009 
0010 #include <iostream>
0011 
0012 #include "../src/nucleus.h"
0013 
0014 using namespace trento;
0015 
0016 TEST_CASE( "collider" ) {
0017   constexpr auto N = 5;
0018 
0019   auto var_map = make_var_map({
0020     {"number-events", N},
0021     {"quiet", false},
0022     {"random-seed", static_cast<int64_t>(-1)},
0023     {"projectile", std::vector<std::string>{"Pb", "Pb"}},
0024     {"b-min", 0.},
0025     {"b-max", -1.},
0026     {"normalization", 1.},
0027     {"reduced-thickness", 0.},
0028     {"grid-max", 9.},
0029     {"grid-step", 0.3},
0030     {"fluctuation", 1.},
0031     {"cross-section", 6.4},
0032     {"nucleon-width", 0.5},
0033     {"nucleon-min-dist", 0.},
0034   });
0035 
0036   std::vector<int> nevent, npart;
0037   std::vector<double> impact, mult;
0038 
0039   // run collider normally and save output
0040   {
0041     capture_stdout capture;
0042 
0043     Collider collider{var_map};
0044     collider.run_events();
0045 
0046     std::string line;
0047     while (std::getline(capture.stream, line)) {
0048       nevent.push_back(0);
0049       impact.push_back(0);
0050       npart.push_back(0);
0051       mult.push_back(0);
0052       std::istringstream(line) >> nevent.back()
0053                                >> impact.back()
0054                                >> npart.back()
0055                                >> mult.back();
0056     }
0057   }
0058 
0059   // event numbers should be an integer sequence from zero
0060   std::vector<int> sequence(N);
0061   std::iota(sequence.begin(), sequence.end(), 0);
0062   CHECK( nevent == sequence );
0063 
0064   // verify impact parameters are within min-bias range
0065   auto impact_max = 2*Nucleus::create("Pb")->radius() + 6*.5;
0066   CHECK( impact >= std::vector<double>(N, 0.) );
0067   CHECK( impact <= std::vector<double>(N, impact_max) );
0068 
0069   // verify all events have at least 2 participants and at most 416 for PbPb
0070   CHECK( npart >= std::vector<int>(N, 2) );
0071   CHECK( npart <= std::vector<int>(N, 416) );
0072 
0073   // nonzero multiplicity
0074   CHECK( mult >= std::vector<double>(N, 0.) );
0075 }
0076 
0077 TEST_CASE( "fixed impact parameter" ) {
0078   constexpr auto N = 5;
0079   constexpr auto bfixed = 4.;
0080 
0081   auto var_map = make_var_map({
0082     {"number-events", N},
0083     {"quiet", false},
0084     {"random-seed", static_cast<int64_t>(-1)},
0085     {"projectile", std::vector<std::string>{"Au", "Au"}},
0086     {"b-min", bfixed},
0087     {"b-max", bfixed},
0088     {"normalization", 1.},
0089     {"reduced-thickness", 0.},
0090     {"grid-max", 9.},
0091     {"grid-step", 0.3},
0092     {"fluctuation", 1.},
0093     {"cross-section", 6.4},
0094     {"nucleon-width", 0.5},
0095     {"nucleon-min-dist", 0.2},
0096   });
0097 
0098   std::vector<double> impact;
0099 
0100   {
0101     Collider collider{var_map};
0102 
0103     capture_stdout capture;
0104     collider.run_events();
0105 
0106     std::string line;
0107     while (std::getline(capture.stream, line)) {
0108       double x;
0109       std::istringstream(line) >> x >> x;
0110       impact.push_back(x);
0111     }
0112   }
0113 
0114   // all events have the specified impact parameter
0115   CHECK( std::all_of(impact.cbegin(), impact.cend(),
0116     [&bfixed](double b) { return b == Approx(bfixed); }) );
0117 }
0118 
0119 TEST_CASE( "random seed" ) {
0120   std::vector<std::string> output(5);
0121 
0122   const auto seed = static_cast<int64_t>(std::random_device{}());
0123 
0124   // run several collider batches with the same seed
0125   std::generate(output.begin(), output.end(),
0126     [&seed]() {
0127       Collider collider{make_var_map({
0128         {"number-events", 3},
0129         {"quiet", false},
0130         {"random-seed", seed},
0131         {"projectile", std::vector<std::string>{"p", "U"}},
0132         {"b-min", 0.},
0133         {"b-max", -1.},
0134         {"normalization", 1.},
0135         {"reduced-thickness", 0.},
0136         {"grid-max", 9.},
0137         {"grid-step", 0.3},
0138         {"fluctuation", 1.},
0139         {"cross-section", 6.4},
0140         {"nucleon-width", 0.5},
0141         {"nucleon-min-dist", 0.4},
0142       })};
0143 
0144       capture_stdout capture;
0145       collider.run_events();
0146 
0147       return capture.stream.str();
0148     });
0149 
0150   // all collider batches are identical
0151   CHECK( std::all_of(output.cbegin(), output.cend(),
0152     [&output](const std::string& s) { return s == output.front(); }) );
0153 }