Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /*******************************************************************************
0002  * Copyright (c) The JETSCAPE Collaboration, 2018
0003  *
0004  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
0005  * 
0006  * For the list of contributors see AUTHORS.
0007  *
0008  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
0009  *
0010  * or via email to bugs.jetscape@gmail.com
0011  *
0012  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
0013  * See COPYING for details.
0014  ******************************************************************************/
0015 
0016 #include <string>
0017 #include <fstream>
0018 #include "NcollListFromFile.h"
0019 
0020 // Register the module with the base class
0021 RegisterJetScapeModule<NcollListFromFile> NcollListFromFile::reg(
0022         "NcollListFromFile");
0023 
0024 NcollListFromFile::NcollListFromFile() {
0025   SetId("NcollListFromFile");
0026   event_id_ = -1;
0027 }
0028 
0029 NcollListFromFile::~NcollListFromFile() {}
0030 
0031 void NcollListFromFile::Exec() {
0032   Clear();
0033   Jetscape::JSINFO << "Read binary collision list from file ...";
0034   try {
0035     std::string initialProfilePath =
0036         GetXMLElementText({"IS", "initial_Ncoll_list"});
0037 
0038     event_id_++;
0039     std::ostringstream path_with_filename;
0040     path_with_filename << initialProfilePath << "/event-" << event_id_
0041                        << "/NcollList.dat";
0042     JSINFO << "External initial profile path is" << path_with_filename.str();
0043 
0044     ReadNbcList(path_with_filename.str());
0045   } catch (std::exception &err) {
0046     Jetscape::JSWARN << err.what();
0047     std::exit(-1);
0048   }
0049 }
0050 
0051 
0052 void NcollListFromFile::Clear() {
0053   Jetscape::JSINFO << "clear initial condition vectors";
0054   binary_collision_x_.clear();
0055   binary_collision_y_.clear();
0056 }
0057 
0058 
0059 void NcollListFromFile::ReadNbcList(std::string filename) {
0060   Jetscape::JSINFO << "Read in binary collision list ...";
0061   std::ifstream infile(filename.c_str());
0062   if (!infile.good()) {
0063     Jetscape::JSWARN << "Can not open " << filename;
0064     exit(1);
0065   }
0066 
0067   double x, y;
0068   infile >> x >> y;
0069   while (!infile.eof()) {
0070     binary_collision_x_.push_back(x);
0071     binary_collision_y_.push_back(y);
0072     infile >> x >> y;
0073   }
0074   infile.close();
0075   ncoll_ = binary_collision_x_.size();
0076   rand_int_ptr_ = (
0077         std::make_shared<std::uniform_int_distribution<int>>(0, ncoll_-1));
0078 }
0079 
0080 
0081 void NcollListFromFile::SampleABinaryCollisionPoint(double &x, double &y) {
0082   int rand_idx = (*rand_int_ptr_)(*GetMt19937Generator());
0083   x = binary_collision_x_[rand_idx];
0084   y = binary_collision_y_[rand_idx];
0085 }