25 #include "GaudiKernel/MsgStream.h"
36 #include "CLHEP/Random/RandFlat.h"
37 #include "CLHEP/Geometry/Point3D.h"
42 static CLHEP::HepRandomEngine *p_Engine;
43 static std::string hijing_stream =
"HIJING_INIT";
51 return (
float) CLHEP::RandFlat::shoot(p_Engine);
65 void hijing_(
const char*,
float*,
float*,
long int);
90 std::cout <<
"MetaData: generator = Hijing "
91 << HIJINGVERSION << std::endl;
97 ATH_MSG_INFO(
"===> Vertex rand covers whole beampipe." );
102 else ATH_MSG_INFO(
"===> NOT keeping all decay vertices" );
112 hijing_stream =
"HIJING";
117 const char* frame =
m_frame.c_str();
119 const char* targ =
m_targ.c_str();
122 strlen(frame), strlen(
proj), strlen(targ) );
124 ATH_MSG_INFO(
"\n=================================================\n"
125 <<
" HIJING initialization results: \n"
129 <<
"=================================================\n" );
132 return StatusCode::SUCCESS;
142 const EventContext& ctx = Gaudi::Hive::currentContext();
144 p_Engine->setSeeds(seeds, 0);
150 const char* frame =
m_frame.c_str();
156 if (errorStatus != 0) {
157 ATH_MSG_ERROR(
"Error returned from HIJING, value = " << errorStatus );
158 return StatusCode::FAILURE;
179 event_params = std::make_unique<HijingEventParams>(
np,
nt, n0, n01, n10, n11, natt, jatt,
b, bphi);
181 ATH_MSG_INFO(
"\n=================================================\n"
182 <<
" HIJING event description: \n"
183 <<
" b = " <<
b <<
" fm \n"
184 <<
" # proj participants = " <<
np <<
"\n"
185 <<
" # targ participants = " <<
nt <<
"\n"
186 <<
" # final particles = " << natt <<
"\n"
187 <<
"=================================================\n" );
190 return StatusCode::SUCCESS;
197 return StatusCode::SUCCESS;
232 HepMC::GenHeavyIonPtr ion= std::make_shared<HepMC::GenHeavyIon>();
233 ion->Ncoll_hard=
static_cast<int>(jatt);
234 ion->Npart_proj=
static_cast<int>(
np);
235 ion->Npart_targ=
static_cast<int>(
nt);
236 ion->Ncoll=
static_cast<int>(n0+n10+n01+n11);
237 ion->N_Nwounded_collisions=
static_cast<int>(n01);
238 ion->Nwounded_N_collisions=
static_cast<int>(n10);
239 ion->Nwounded_Nwounded_collisions=
static_cast<int>(n11);
240 ion->spectator_neutrons=-1;
241 ion->spectator_protons=-1;
242 ion->impact_parameter=
b;
243 ion->event_plane_angle=bphi;
244 ion->event_plane_angle=-1;
245 ion->sigma_inel_NN=sigmainel;
246 evt->set_heavy_ion(ion);
250 static_cast<int>(jatt),
251 static_cast<int>(
np),
252 static_cast<int>(
nt),
253 static_cast<int>(n0+n10+n01+n11),
254 static_cast<int>(-1),
255 static_cast<int>(-1),
256 static_cast<int>(n01),
257 static_cast<int>(n10),
258 static_cast<int>(n11),
264 evt->set_heavy_ion(ion);
265 std::cout <<
" heavy ion " <<
evt->heavy_ion() << std::endl;
278 std::vector<int> partOriginVertex_vec(numHijingPart, 0);
279 std::vector<int> partDecayVertex_vec(numHijingPart, -1);
280 std::vector<HepMC::GenParticlePtr> particleHepPartPtr_vec(numHijingPart,
nullptr);
284 std::vector<HepMC::GenVertexPtr> vertexPtrVec;
288 CLHEP::HepLorentzVector newVertex;
289 newVertex = CLHEP::HepLorentzVector(0.,0.,0.,0.);
292 else if(
m_sel) newVertex = CLHEP::HepLorentzVector(
m_x,
m_y,
m_z, 0.);
297 vertexPtrVec.push_back(v1);
300 if (
m_frame ==
"CMS " ) eproj = eproj / 2.;
303 if (
m_proj ==
"PBAR " ) {
305 }
else if (
m_proj ==
"N " ) {
307 }
else if (
m_proj ==
"NBAR " ) {
309 }
else if (
m_proj ==
"PI+ " ) {
311 }
else if (
m_proj ==
"PI- " ) {
313 }
else if (
m_proj ==
"A " ) {
314 proj_id = 3000000 +
m_iap;
317 v1->add_particle_in( part_p );
323 if (
m_targ ==
"PBAR " ) {
325 }
else if (
m_targ ==
"N " ) {
327 }
else if (
m_targ ==
"NBAR " ) {
329 }
else if (
m_targ ==
"PI+ " ) {
331 }
else if (
m_targ ==
"PI- " ) {
333 }
else if (
m_targ ==
"A " ) {
334 targ_id = 3000000 +
m_iat;
337 v1->add_particle_in( part_t );
339 evt->set_beam_particles(part_p,part_t);
350 bool inconsistency =
false;
363 int parentOriginIndex = 0;
364 int parentDecayIndex = -1;
368 if (parentIndex >= 0)
370 parentOriginIndex = partOriginVertex_vec[parentIndex];
371 parentDecayIndex = partDecayVertex_vec[parentIndex];
386 << std::setw(5) <<
i <<
","
403 int particleVertexIndex = 0;
412 if (parentDecayIndex != -1)
416 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[parentDecayIndex]->position().
x(),
417 vertexPtrVec[parentDecayIndex]->position().
y(),
418 vertexPtrVec[parentDecayIndex]->position().
z());
419 double distance = vertex_pos.distance(particleStart.vect());
426 ATH_MSG_WARNING(
" Inconsistency in Hijing particle vertexing, particle # " <<
i
427 <<
" starting point (x,y,z) = ("
428 << particleStart.x() <<
", "
429 << particleStart.y() <<
", "
430 << particleStart.z() <<
") "
431 <<
" a distance " <<
distance <<
" away from parent decay point " );
436 log << MSG::WARNING <<
" Parent decay vertex: (x,y,z) = " << vertexPtrVec[parentDecayIndex]->position().x()
437 <<
", " << vertexPtrVec[parentDecayIndex]->position().y()
438 <<
", " << vertexPtrVec[parentDecayIndex]->position().z()
439 <<
", associated daughter IDs = ";
442 auto vertexPtrVec_particles_out_const_begin=vertexPtrVec[parentDecayIndex]->particles_out().begin();
443 auto vertexPtrVec_particles_out_const_end=vertexPtrVec[parentDecayIndex]->particles_out().end();
445 auto vertexPtrVec_particles_out_const_begin=vertexPtrVec[parentDecayIndex]->particles_out_const_begin();
446 auto vertexPtrVec_particles_out_const_end=vertexPtrVec[parentDecayIndex]->particles_out_const_end();
448 for (
auto iter = vertexPtrVec_particles_out_const_begin;
449 iter != vertexPtrVec_particles_out_const_end;
452 log << (*iter) <<
", ";
456 inconsistency =
true;
461 particleVertexIndex = parentDecayIndex;
468 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[parentOriginIndex]->position().
x(),
469 vertexPtrVec[parentOriginIndex]->position().
y(),
470 vertexPtrVec[parentOriginIndex]->position().
z());
471 double distance = vertex_pos.distance(particleStart.vect());
479 ATH_MSG_WARNING(
"HIJING BUG:: Particle found with displaced vertex but no parent " );
480 ATH_MSG_WARNING(
" Particle parameters: " << std::fixed << std::setprecision(2)
481 << std::setw(5) <<
i <<
","
495 particleVertexIndex = parentOriginIndex;
503 evt->add_vertex(newVertex_p);
504 vertexPtrVec.push_back(newVertex_p);
505 particleVertexIndex = vertexPtrVec.size() - 1;
509 partDecayVertex_vec[parentIndex] = particleVertexIndex;
514 newVertex_p->add_particle_in(particleHepPartPtr_vec[parentIndex]);
519 particleVertexIndex = parentOriginIndex;
528 for (
unsigned int ivert = 0; ivert < vertexPtrVec.size(); ivert++)
531 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[ivert]->position().
x(),
532 vertexPtrVec[ivert]->position().
y(),
533 vertexPtrVec[ivert]->position().
z());
534 double distance = vertex_pos.distance(particleStart.vect());
548 evt->add_vertex(newVertex_p);
549 vertexPtrVec.push_back(newVertex_p);
550 particleVertexIndex = vertexPtrVec.size() - 1;
554 particleVertexIndex = foundVert;
562 int particleStatus = 1;
579 particleHepPartPtr_vec[
i-1] = newParticle_p;
583 vertexPtrVec[particleVertexIndex]->add_particle_out(newParticle_p);
584 partOriginVertex_vec[
i-1] = particleVertexIndex;
596 ATH_MSG_WARNING(
" Hijing.cxx inconsistency: " << std::fixed << std::setprecision(2)
598 << std::setw(5) <<
i <<
","
616 for (
int jparton = 1; jparton <=
m_hijjet2.
njsg(isg); jparton++)
625 double mt = std::sqrt(ptsq +
mass*
mass);
626 double pt = std::sqrt(ptsq);
637 <<
", eta = " << pseud );
651 for (
int iproj = 1; iproj <= iap; iproj++)
653 for (
int jparton = 1; jparton <=
m_hijjet1.
npj(iproj); jparton++)
662 double mt = std::sqrt(ptsq +
mass*
mass);
663 double pt = std::sqrt(ptsq);
674 <<
", eta = " << pseud );
685 for (
int itarg = 1; itarg <= iat; itarg++)
687 for (
int jparton = 1; jparton <=
m_hijjet1.
ntj(itarg); jparton++)
696 double mt = std::sqrt(ptsq +
mass*
mass);
697 double pt = std::sqrt(ptsq);
708 <<
", eta = " << pseud );
723 HepMC::FourVector tmpmom(0.,0.,0.,0.);
724 double ranz = CLHEP::RandFlat::shoot(p_Engine);
728 for(
auto pitr: *
evt){
729 tmpmom= pitr->momentum();
730 tmpmom.setX(-tmpmom.x());
731 tmpmom.setY(-tmpmom.y());
732 tmpmom.setZ(-tmpmom.z());
733 tmpmom.setT(tmpmom.t());
734 pitr->set_momentum(tmpmom);
744 const std::vector <HepMC::GenParticlePtr> allParticles=
evt->particles();
745 for(
auto p : allParticles)
748 if(
p->status() == 2 && !end_v)
evt->remove_particle(
p);
756 if (
p->status() == 2 && !end_v)
delete p->production_vertex()->remove_particle(
p);
760 return StatusCode::SUCCESS;
763 CLHEP::HepLorentzVector
772 double ranz = CLHEP::RandFlat::shoot(engine, -
Zmax,
Zmax);
774 if( std::abs(ranz) <
Start1 ) {
777 }
else if( std::abs(ranz) <
Start2 ) {
780 }
else if( std::abs(ranz) <
Start3 ) {
783 }
else if ( std::abs(ranz) <=
Envelope ){
787 ATH_MSG_ERROR(
"**** Hijing::randomizeVertex() " << ranz <<
" (z) is outside the detector (units of mm). Returning a centered event." );
788 return CLHEP::HepLorentzVector(0.,0.,0.,0.);
791 ATH_MSG_INFO(
"New Coordinates: x=0., y=0., z=" << ranz );
792 return CLHEP::HepLorentzVector(0., 0., ranz, 0);
794 ranx = CLHEP::RandFlat::shoot(engine, -
xmax,
xmax);
795 rany = CLHEP::RandFlat::shoot(engine, -
ymax,
ymax);
797 ATH_MSG_INFO(
"New Coordinates: x=" << ranx <<
", y=" << rany <<
", z=" << ranz );
799 return CLHEP::HepLorentzVector(ranx, rany, ranz, 0);
823 std::string myparam = mystring.
piece<std::string>(1);
824 if (myparam ==
"efrm")
828 else if (myparam ==
"frame")
833 unsigned nbl = 8 -
m_frame.size();
834 for (
unsigned i = 0;
i < nbl; ++
i)
m_frame +=
' ';
837 else if (myparam ==
"proj")
842 unsigned nbl = 8 -
m_proj.size();
843 for (
unsigned i = 0;
i < nbl; ++
i)
m_proj +=
' ';
846 else if (myparam ==
"targ")
851 unsigned nbl = 8 -
m_targ.size();
852 for (
unsigned i = 0;
i < nbl; ++
i)
m_targ +=
' ';
855 else if (myparam ==
"iap")
859 else if (myparam ==
"izp")
863 else if (myparam ==
"iat")
867 else if (myparam ==
"izt")
871 else if (myparam ==
"bmin")
875 else if (myparam ==
"bmax")
879 else if (myparam ==
"nseed")
883 else if (myparam ==
"hipr1")
885 int myelem = mystring.
piece<
int>(2);
888 else if (myparam ==
"ihpr2")
890 int myelem = mystring.
piece<
int>(2);
893 else if (myparam ==
"hint1")
895 int myelem = mystring.
piece<
int>(2);
898 else if (myparam ==
"ihnt2")
900 int myelem = mystring.
piece<
int>(2);
905 ATH_MSG_ERROR(
" ERROR in HIJING INITIALIZATION PARAMETERS " << myparam <<
" is an invalid parameter !" );