Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NcollListFromFile.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file NcollListFromFile.cc
1 /*******************************************************************************
2  * Copyright (c) The JETSCAPE Collaboration, 2018
3  *
4  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
5  *
6  * For the list of contributors see AUTHORS.
7  *
8  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9  *
10  * or via email to bugs.jetscape@gmail.com
11  *
12  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13  * See COPYING for details.
14  ******************************************************************************/
15 
16 #include <string>
17 #include <fstream>
18 #include "NcollListFromFile.h"
19 
20 // Register the module with the base class
22  "NcollListFromFile");
23 
25  SetId("NcollListFromFile");
26  event_id_ = -1;
27 }
28 
30 
32  Clear();
33  Jetscape::JSINFO << "Read binary collision list from file ...";
34  try {
35  std::string initialProfilePath =
36  GetXMLElementText({"IS", "initial_Ncoll_list"});
37 
38  event_id_++;
39  std::ostringstream path_with_filename;
40  path_with_filename << initialProfilePath << "/event-" << event_id_
41  << "/NcollList.dat";
42  JSINFO << "External initial profile path is" << path_with_filename.str();
43 
44  ReadNbcList(path_with_filename.str());
45  } catch (std::exception &err) {
46  Jetscape::JSWARN << err.what();
47  std::exit(-1);
48  }
49 }
50 
51 
53  Jetscape::JSINFO << "clear initial condition vectors";
54  binary_collision_x_.clear();
55  binary_collision_y_.clear();
56 }
57 
58 
60  Jetscape::JSINFO << "Read in binary collision list ...";
61  std::ifstream infile(filename.c_str());
62  if (!infile.good()) {
63  Jetscape::JSWARN << "Can not open " << filename;
64  exit(1);
65  }
66 
67  double x, y;
68  infile >> x >> y;
69  while (!infile.eof()) {
70  binary_collision_x_.push_back(x);
71  binary_collision_y_.push_back(y);
72  infile >> x >> y;
73  }
74  infile.close();
75  ncoll_ = binary_collision_x_.size();
76  rand_int_ptr_ = (
77  std::make_shared<std::uniform_int_distribution<int>>(0, ncoll_-1));
78 }
79 
80 
82  int rand_idx = (*rand_int_ptr_)(*GetMt19937Generator());
83  x = binary_collision_x_[rand_idx];
84  y = binary_collision_y_[rand_idx];
85 }