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." );
104 hijing_stream =
"HIJING";
109 const char* frame =
m_frame.c_str();
111 const char* targ =
m_targ.c_str();
114 strlen(frame), strlen(
proj), strlen(targ) );
116 ATH_MSG_INFO(
"\n=================================================\n"
117 <<
" HIJING initialization results: \n"
121 <<
"=================================================\n" );
142 return StatusCode::SUCCESS;
152 const EventContext& ctx = Gaudi::Hive::currentContext();
154 p_Engine->setSeeds(seeds, 0);
160 const char* frame =
m_frame.c_str();
166 if (errorStatus != 0) {
167 ATH_MSG_ERROR(
"Error returned from HIJING, value = " << errorStatus );
168 return StatusCode::FAILURE;
189 event_params = std::make_unique<HijingEventParams>(
np,
nt, n0, n01, n10, n11, natt, jatt,
b, bphi);
191 ATH_MSG_INFO(
"\n=================================================\n"
192 <<
" HIJING event description: \n"
193 <<
" b = " <<
b <<
" fm \n"
194 <<
" # proj participants = " <<
np <<
"\n"
195 <<
" # targ participants = " <<
nt <<
"\n"
196 <<
" # final particles = " << natt <<
"\n"
197 <<
"=================================================\n" );
200 return StatusCode::SUCCESS;
207 return StatusCode::SUCCESS;
242 HepMC::GenHeavyIonPtr ion= std::make_shared<HepMC::GenHeavyIon>();
243 ion->Ncoll_hard=
static_cast<int>(jatt);
244 ion->Npart_proj=
static_cast<int>(
np);
245 ion->Npart_targ=
static_cast<int>(
nt);
246 ion->Ncoll=
static_cast<int>(n0+n10+n01+n11);
247 ion->N_Nwounded_collisions=
static_cast<int>(n01);
248 ion->Nwounded_N_collisions=
static_cast<int>(n10);
249 ion->Nwounded_Nwounded_collisions=
static_cast<int>(n11);
250 ion->spectator_neutrons=-1;
251 ion->spectator_protons=-1;
252 ion->impact_parameter=
b;
253 ion->event_plane_angle=bphi;
254 ion->event_plane_angle=-1;
255 ion->sigma_inel_NN=sigmainel;
259 static_cast<int>(jatt),
260 static_cast<int>(
np),
261 static_cast<int>(
nt),
262 static_cast<int>(n0+n10+n01+n11),
263 static_cast<int>(-1),
264 static_cast<int>(-1),
265 static_cast<int>(n01),
266 static_cast<int>(n10),
267 static_cast<int>(n11),
273 evt->set_heavy_ion(ion);
274 std::cout <<
" heavy ion " <<
evt->heavy_ion() << std::endl;
287 std::vector<int> partOriginVertex_vec(numHijingPart, 0);
288 std::vector<int> partDecayVertex_vec(numHijingPart, -1);
289 std::vector<HepMC::GenParticlePtr> particleHepPartPtr_vec(numHijingPart,
nullptr);
293 std::vector<HepMC::GenVertexPtr> vertexPtrVec;
297 CLHEP::HepLorentzVector newVertex;
298 newVertex = CLHEP::HepLorentzVector(0.,0.,0.,0.);
301 else if(
m_sel) newVertex = CLHEP::HepLorentzVector(
m_x,
m_y,
m_z, 0.);
306 vertexPtrVec.push_back(v1);
309 if (
m_frame ==
"CMS " ) eproj = eproj / 2.;
312 if (
m_proj ==
"PBAR " ) {
314 }
else if (
m_proj ==
"N " ) {
316 }
else if (
m_proj ==
"NBAR " ) {
318 }
else if (
m_proj ==
"PI+ " ) {
320 }
else if (
m_proj ==
"PI- " ) {
322 }
else if (
m_proj ==
"A " ) {
323 proj_id = 3000000 +
m_iap;
326 v1->add_particle_in( part_p );
332 if (
m_targ ==
"PBAR " ) {
334 }
else if (
m_targ ==
"N " ) {
336 }
else if (
m_targ ==
"NBAR " ) {
338 }
else if (
m_targ ==
"PI+ " ) {
340 }
else if (
m_targ ==
"PI- " ) {
342 }
else if (
m_targ ==
"A " ) {
343 targ_id = 3000000 +
m_iat;
346 v1->add_particle_in( part_t );
348 evt->set_beam_particles(part_p,part_t);
359 bool inconsistency =
false;
372 int parentOriginIndex = 0;
373 int parentDecayIndex = -1;
377 if (parentIndex >= 0)
379 parentOriginIndex = partOriginVertex_vec[parentIndex];
380 parentDecayIndex = partDecayVertex_vec[parentIndex];
395 << std::setw(5) <<
i <<
","
412 int particleVertexIndex = 0;
421 if (parentDecayIndex != -1)
425 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[parentDecayIndex]->position().
x(),
426 vertexPtrVec[parentDecayIndex]->position().
y(),
427 vertexPtrVec[parentDecayIndex]->position().
z());
428 double distance = vertex_pos.distance(particleStart.vect());
435 ATH_MSG_WARNING(
" Inconsistency in Hijing particle vertexing, particle # " <<
i
436 <<
" starting point (x,y,z) = ("
437 << particleStart.x() <<
", "
438 << particleStart.y() <<
", "
439 << particleStart.z() <<
") "
440 <<
" a distance " <<
distance <<
" away from parent decay point " );
445 log << MSG::WARNING <<
" Parent decay vertex: (x,y,z) = " << vertexPtrVec[parentDecayIndex]->position().x()
446 <<
", " << vertexPtrVec[parentDecayIndex]->position().y()
447 <<
", " << vertexPtrVec[parentDecayIndex]->position().z()
448 <<
", associated daughter IDs = ";
451 auto vertexPtrVec_particles_out_const_begin=vertexPtrVec[parentDecayIndex]->particles_out().begin();
452 auto vertexPtrVec_particles_out_const_end=vertexPtrVec[parentDecayIndex]->particles_out().end();
454 auto vertexPtrVec_particles_out_const_begin=vertexPtrVec[parentDecayIndex]->particles_out_const_begin();
455 auto vertexPtrVec_particles_out_const_end=vertexPtrVec[parentDecayIndex]->particles_out_const_end();
457 for (
auto iter = vertexPtrVec_particles_out_const_begin;
458 iter != vertexPtrVec_particles_out_const_end;
461 log << (*iter) <<
", ";
465 inconsistency =
true;
470 particleVertexIndex = parentDecayIndex;
477 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[parentOriginIndex]->position().
x(),
478 vertexPtrVec[parentOriginIndex]->position().
y(),
479 vertexPtrVec[parentOriginIndex]->position().
z());
480 double distance = vertex_pos.distance(particleStart.vect());
488 ATH_MSG_WARNING(
"HIJING BUG:: Particle found with displaced vertex but no parent " );
489 ATH_MSG_WARNING(
" Particle parameters: " << std::fixed << std::setprecision(2)
490 << std::setw(5) <<
i <<
","
504 particleVertexIndex = parentOriginIndex;
512 evt->add_vertex(newVertex_p);
513 vertexPtrVec.push_back(newVertex_p);
514 particleVertexIndex = vertexPtrVec.size() - 1;
518 partDecayVertex_vec[parentIndex] = particleVertexIndex;
523 newVertex_p->add_particle_in(particleHepPartPtr_vec[parentIndex]);
528 particleVertexIndex = parentOriginIndex;
537 for (
unsigned int ivert = 0; ivert < vertexPtrVec.size(); ivert++)
540 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[ivert]->position().
x(),
541 vertexPtrVec[ivert]->position().
y(),
542 vertexPtrVec[ivert]->position().
z());
543 double distance = vertex_pos.distance(particleStart.vect());
557 evt->add_vertex(newVertex_p);
558 vertexPtrVec.push_back(newVertex_p);
559 particleVertexIndex = vertexPtrVec.size() - 1;
563 particleVertexIndex = foundVert;
571 int particleStatus = 1;
588 particleHepPartPtr_vec[
i-1] = newParticle_p;
592 vertexPtrVec[particleVertexIndex]->add_particle_out(newParticle_p);
593 partOriginVertex_vec[
i-1] = particleVertexIndex;
607 ATH_MSG_WARNING(
" Hijing.cxx inconsistency: " << std::fixed << std::setprecision(2)
609 << std::setw(5) <<
i <<
","
634 for (
int jparton = 1; jparton <=
m_hijjet2.
njsg(isg); jparton++)
643 double mt = std::sqrt(ptsq +
mass*
mass);
644 double pt = std::sqrt(ptsq);
655 <<
", eta = " << pseud );
669 for (
int iproj = 1; iproj <= iap; iproj++)
671 for (
int jparton = 1; jparton <=
m_hijjet1.
npj(iproj); jparton++)
680 double mt = std::sqrt(ptsq +
mass*
mass);
681 double pt = std::sqrt(ptsq);
692 <<
", eta = " << pseud );
703 for (
int itarg = 1; itarg <= iat; itarg++)
705 for (
int jparton = 1; jparton <=
m_hijjet1.
ntj(itarg); jparton++)
714 double mt = std::sqrt(ptsq +
mass*
mass);
715 double pt = std::sqrt(ptsq);
726 <<
", eta = " << pseud );
741 HepMC::FourVector tmpmom(0.,0.,0.,0.);
742 double ranz = CLHEP::RandFlat::shoot(p_Engine);
746 for(
auto pitr: *
evt){
747 tmpmom= pitr->momentum();
748 tmpmom.setX(-tmpmom.x());
749 tmpmom.setY(-tmpmom.y());
750 tmpmom.setZ(-tmpmom.z());
751 tmpmom.setT(tmpmom.t());
752 pitr->set_momentum(tmpmom);
762 const std::vector <HepMC::GenParticlePtr> allParticles=
evt->particles();
763 for(
auto p : allParticles)
766 if(
p->status() == 2 && !end_v)
evt->remove_particle(
p);
774 if (
p->status() == 2 && !end_v)
p->production_vertex()->remove_particle(
p);
778 return StatusCode::SUCCESS;
781 CLHEP::HepLorentzVector
790 double ranz = CLHEP::RandFlat::shoot(engine, -
Zmax,
Zmax);
792 if( std::abs(ranz) <
Start1 ) {
795 }
else if( std::abs(ranz) <
Start2 ) {
798 }
else if( std::abs(ranz) <
Start3 ) {
801 }
else if ( std::abs(ranz) <=
Envelope ){
805 ATH_MSG_ERROR(
"**** Hijing::randomizeVertex() " << ranz <<
" (z) is outside the detector (units of mm). Returning a centered event." );
806 return CLHEP::HepLorentzVector(0.,0.,0.,0.);
809 ATH_MSG_INFO(
"New Coordinates: x=0., y=0., z=" << ranz );
810 return CLHEP::HepLorentzVector(0., 0., ranz, 0);
812 ranx = CLHEP::RandFlat::shoot(engine, -
xmax,
xmax);
813 rany = CLHEP::RandFlat::shoot(engine, -
ymax,
ymax);
815 ATH_MSG_INFO(
"New Coordinates: x=" << ranx <<
", y=" << rany <<
", z=" << ranz );
817 return CLHEP::HepLorentzVector(ranx, rany, ranz, 0);
841 std::string myparam = mystring.
piece<std::string>(1);
842 if (myparam ==
"efrm")
846 else if (myparam ==
"frame")
851 unsigned nbl = 8 -
m_frame.size();
852 for (
unsigned i = 0;
i < nbl; ++
i)
m_frame +=
' ';
855 else if (myparam ==
"proj")
860 unsigned nbl = 8 -
m_proj.size();
861 for (
unsigned i = 0;
i < nbl; ++
i)
m_proj +=
' ';
864 else if (myparam ==
"targ")
869 unsigned nbl = 8 -
m_targ.size();
870 for (
unsigned i = 0;
i < nbl; ++
i)
m_targ +=
' ';
873 else if (myparam ==
"iap")
877 else if (myparam ==
"izp")
881 else if (myparam ==
"iat")
885 else if (myparam ==
"izt")
889 else if (myparam ==
"bmin")
893 else if (myparam ==
"bmax")
897 else if (myparam ==
"nseed")
901 else if (myparam ==
"hipr1")
903 int myelem = mystring.
piece<
int>(2);
906 else if (myparam ==
"ihpr2")
908 int myelem = mystring.
piece<
int>(2);
911 else if (myparam ==
"hint1")
913 int myelem = mystring.
piece<
int>(2);
916 else if (myparam ==
"ihnt2")
918 int myelem = mystring.
piece<
int>(2);
923 ATH_MSG_ERROR(
" ERROR in HIJING INITIALIZATION PARAMETERS " << myparam <<
" is an invalid parameter !" );