21 #pragma GCC diagnostic push
22 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
23 #include <HepMC/GenEvent.h>
24 #pragma GCC diagnostic pop
25 #include <HepMC/GenParticle.h>
26 #include <HepMC/GenVertex.h>
27 #include <HepMC/IteratorRange.h>
28 #include <HepMC/SimpleVector.h>
29 #include <HepMC/Units.h>
31 #include <CLHEP/Vector/LorentzRotation.h>
33 #include <gsl/gsl_const.h>
34 #include <gsl/gsl_randist.h>
35 #include <gsl/gsl_rng.h>
61 bool operator()(
const HepMC::GenParticle *
p)
63 if (!p->end_vertex() && p->status() == 1)
return 1;
94 PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode,
"PHG4INEVENT");
110 cout <<
Name() <<
" override random seed: " << phseed << endl;
119 PHHepMCGenEventMap *genevtmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
123 static bool once =
true;
129 cout <<
"HepMCNodeReader::process_event - No PHHepMCGenEventMap node. Do not perform HepMC->Geant4 input" << endl;
135 PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode,
"PHG4INEVENT");
138 cout <<
PHWHERE <<
"no PHG4INEVENT node" << endl;
156 if (worldshape ==
"G4Tubs")
158 ishape = ShapeG4Tubs;
160 else if (worldshape ==
"G4Box")
166 cout <<
PHWHERE <<
" unknown world shape " << worldshape << endl;
182 cout <<
"HepMCNodeReader::process_event - this event is already simulated. Move on: ";
191 cout << __PRETTY_FUNCTION__ <<
" : L" << __LINE__ <<
" Found PHHepMCGenEvent:" << endl;
197 HepMC::GenEvent *evt = genevt->
getEvent();
200 cout <<
PHWHERE <<
" no evt pointer under HEPMC Node found:";
207 cout << __PRETTY_FUNCTION__ <<
" : L" << __LINE__ <<
" Found HepMC::GenEvent:" << endl;
237 std::list<HepMC::GenParticle *> finalstateparticles;
238 std::list<HepMC::GenParticle *>::const_iterator fiter;
241 const double mom_factor = HepMC::Units::conversion_factor(evt->momentum_unit(), HepMC::Units::GEV);
242 const double length_factor = HepMC::Units::conversion_factor(evt->length_unit(), HepMC::Units::CM);
243 const double time_factor = HepMC::Units::conversion_factor(evt->length_unit(), HepMC::Units::CM) / GSL_CONST_CGS_SPEED_OF_LIGHT * 1e9;
245 for (HepMC::GenEvent::vertex_iterator
v = evt->vertices_begin();
246 v != evt->vertices_end();
251 cout << __PRETTY_FUNCTION__ <<
" : L" << __LINE__ <<
" Found vertex:" << endl;
255 finalstateparticles.clear();
256 for (HepMC::GenVertex::particle_iterator
p =
257 (*v)->particles_begin(HepMC::children);
258 p != (*v)->particles_end(HepMC::children); ++
p)
262 cout << __PRETTY_FUNCTION__ <<
" : L" << __LINE__ <<
" Found particle:" << endl;
264 cout <<
"end vertex " << (*p)->end_vertex() << endl;
270 cout << __PRETTY_FUNCTION__ <<
" " << __LINE__ << endl;
271 cout <<
"\tparticle passed " << endl;
273 finalstateparticles.push_back(*
p);
279 cout << __PRETTY_FUNCTION__ <<
" " << __LINE__ << endl;
280 cout <<
"\tparticle failed " << endl;
285 if (!finalstateparticles.empty())
287 CLHEP::HepLorentzVector lv_vertex((*v)->position().x(),
288 (*v)->position().y(),
289 (*v)->position().z(),
290 (*v)->position().t());
293 lv_vertex.setX(collisionVertex.x());
294 lv_vertex.setY(collisionVertex.y());
295 lv_vertex.setZ(collisionVertex.z());
296 lv_vertex.setT(collisionVertex.t());
299 std::cout << __PRETTY_FUNCTION__ <<
" " << __LINE__
301 std::cout <<
"\t vertex reset to collision vertex: "
302 << lv_vertex << std::endl;
307 lv_vertex = lortentz_rotation(lv_vertex);
309 double xpos = lv_vertex.x() * length_factor + xshift;
310 double ypos = lv_vertex.y() * length_factor + yshift;
311 double zpos = lv_vertex.z() * length_factor + zshift;
312 double time = lv_vertex.t() * time_factor + tshift;
316 cout << __PRETTY_FUNCTION__ <<
" " << __LINE__ << endl;
317 cout <<
"Vertex : " << endl;
319 cout <<
"id: " << (*v)->barcode() << endl;
320 cout <<
"x: " << xpos << endl;
321 cout <<
"y: " << ypos << endl;
322 cout <<
"z: " << zpos << endl;
323 cout <<
"t: " << time << endl;
324 cout <<
"Particles" << endl;
327 if (ishape == ShapeG4Tubs)
329 if (sqrt(xpos * xpos + ypos * ypos) > worldsizey / 2 ||
330 fabs(zpos) > worldsizez / 2)
332 cout <<
"vertex x/y/z " << xpos <<
"/" << ypos <<
"/" << zpos
333 <<
" id: " << (*v)->barcode()
334 <<
" outside world volume radius/z (+-) " << worldsizex / 2
335 <<
"/" << worldsizez / 2 <<
", dropping it and its particles"
340 else if (ishape == ShapeG4Box)
342 if (fabs(xpos) > worldsizex / 2 || fabs(ypos) > worldsizey / 2 ||
343 fabs(zpos) > worldsizez / 2)
345 cout <<
"Vertex x/y/z " << xpos <<
"/" << ypos <<
"/" << zpos
346 <<
" outside world volume x/y/z (+-) " << worldsizex / 2 <<
"/"
347 << worldsizey / 2 <<
"/" << worldsizez / 2
348 <<
", dropping it and its particles" << endl;
354 cout <<
PHWHERE <<
" shape " << ishape <<
" not implemented. exiting"
360 vtxindex = ineve->
AddVtx(xpos, ypos, zpos, time);
361 for (fiter = finalstateparticles.begin();
362 fiter != finalstateparticles.end();
367 cout << __PRETTY_FUNCTION__ <<
" " << __LINE__ << endl;
371 CLHEP::HepLorentzVector lv_momentum((*fiter)->momentum().px(),
372 (*fiter)->momentum().py(),
373 (*fiter)->momentum().pz(),
374 (*fiter)->momentum().e());
377 lv_momentum = lortentz_rotation(lv_momentum);
380 particle->
set_pid((*fiter)->pdg_id());
381 particle->
set_px(lv_momentum.x() * mom_factor);
382 particle->
set_py(lv_momentum.y() * mom_factor);
383 particle->
set_pz(lv_momentum.z() * mom_factor);
403 if (width == 0)
return 0;
409 if (width == 0)
return 0;
416 cout <<
"HepMCNodeReader::VertexPosition - WARNING - this function is depreciated. "
417 <<
"HepMCNodeReader::VertexPosition() move all HEPMC subevents to a new vertex location. "
418 <<
"This also leads to a different vertex is used for HepMC subevent in Geant4 than that recorded in the HepMCEvent Node."
419 <<
"Recommendation: the vertex shifts are better controlled for individually HEPMC subevents in Fun4AllHepMCInputManagers and event generators."
431 cout <<
"HepMCNodeReader::SmearVertex - WARNING - this function is depreciated. "
432 <<
"HepMCNodeReader::SmearVertex() smear each HEPMC subevents to a new vertex location. "
433 <<
"This also leads to a different vertex is used for HepMC subevent in Geant4 than that recorded in the HepMCEvent Node."
434 <<
"Recommendation: the vertex smears are better controlled for individually HEPMC subevents in Fun4AllHepMCInputManagers and event generators."
445 cout <<
"HepMCNodeReader::Embed - WARNING - this function is depreciated. "
446 <<
"Embedding IDs are controlled for individually HEPMC subevents in Fun4AllHepMCInputManagers and event generators."