5 #include <HepMC/GenEvent.h>
6 #include <HepMC/GenParticle.h>
7 #include <HepMC/GenVertex.h>
8 #include <HepMC/PdfInfo.h>
9 #include <HepMC/SimpleVector.h>
10 #include <HepMC/Units.h>
13 #include <eicsmear/erhic/EventMC.h>
14 #include <eicsmear/erhic/ParticleMC.h>
15 #include <eicsmear/erhic/Pid.h>
30 #include <boost/tokenizer.hpp>
45 , _node_name(
"PHHepMCGenEvent")
82 HepMC::GenEvent *evt =
new HepMC::GenEvent();
85 evt->use_units(HepMC::Units::GEV, HepMC::Units::CM);
89 vector<HepMC::GenParticle *> hepmc_particles;
90 vector<unsigned> origin_index;
93 vector<HepMC::GenVertex *> hepmc_vertices;
95 typedef boost::tokenizer<boost::escaped_list_separator<char> >
Tokenizer;
105 cout <<
"ReadSynRadFiles::process_event - reading " <<
nEntries <<
" lines from " <<
filename << endl;
107 for (
int ii = 1; ii <=
nEntries; ii++)
111 cout <<
"ReadSynRadFiles::process_event - "
112 <<
"input file end reached" << endl;
118 vec.assign(tok.begin(), tok.end());
120 if (vec.size() != 14 and vec.size() != 15)
122 cout <<
"ReadSynRadFiles::process_event - "
123 <<
"invalid input :" << line << endl;
131 const double Pos_X_cm = stod(vec[
id++]);
132 const double Pos_Y_cm = stod(vec[
id++]);
133 const double Pos_Z_cm = stod(vec[
id++]);
134 const double Pos_u = stod(vec[
id++]);
135 const double Pos_v = stod(vec[
id++]);
136 const double Dir_X = stod(vec[
id++]);
137 const double Dir_Y = stod(vec[
id++]);
138 const double Dir_Z = stod(vec[
id++]);
139 const double Dir_theta_rad = stod(vec[
id++]);
140 const double Dir_phi_rad = stod(vec[
id++]);
141 const double LowFluxRatio = stod(vec[
id++]);
142 const double Energy_eV = stod(vec[
id++]);
143 const double Flux_photon_s = stod(vec[
id++]);
144 const double Power_W = stod(vec[
id++]);
149 cout <<
"ReadSynRadFiles::process_event - " << line <<
" -> " << endl
158 << Dir_theta_rad <<
", "
159 << Dir_phi_rad <<
", "
160 << LowFluxRatio <<
", "
162 << Flux_photon_s <<
", "
173 static bool once =
true;
177 cout <<
"ReadSynRadFiles::process_event - reverse x z axis direction for input photons" << endl;
182 const double E_GeV = Energy_eV / 1e9;
184 const double px = E_GeV * Dir_X;
185 const double py = E_GeV * Dir_Y;
186 const double pz = E_GeV * Dir_Z;
189 HepMC::GenParticle *hepmcpart =
new HepMC::GenParticle(HepMC::FourVector(px * xz_sign, py, pz * xz_sign, E_GeV), 22);
191 hepmcpart->set_status(1);
194 hepmcpart->setGeneratedMass(0);
197 hepmc_particles.push_back(hepmcpart);
198 origin_index.push_back(ii);
200 HepMC::GenVertex *hepmcvtx =
new HepMC::GenVertex(HepMC::FourVector(Pos_X_cm * xz_sign,
204 hepmc_vertices.push_back(hepmcvtx);
205 hepmcvtx->add_particle_out(hepmcpart);
208 SumFlux += Flux_photon_s;
212 if (hepmc_particles.size() != origin_index.size())
214 cout <<
"ReadSynRadFiles::process_event - Lengths of HepMC particles and Origin index vectors do not match!" << endl;
221 for (
unsigned v = 0;
v < hepmc_vertices.size();
v++)
222 evt->add_vertex(hepmc_vertices.at(
v));
225 auto &weightcontainer = evt->weights();
226 weightcontainer.push_back(SumFlux);
227 weightcontainer.push_back(SumPhoton);
233 cout <<
"ReadSynRadFiles::process_event - Failed to add event to HepMC record!" << endl;