7 #include <TLorentzVector.h>
26 #include "HepMC/GenEvent.h"
27 #include "HepMC/HeavyIon.h"
28 #include "HepMC/IO_HEPEVT.h"
29 #include "HepMC/PythiaWrapper6_4.h"
30 #include "HepMC/SimpleVector.h"
43 int Hydjet2Hadronizer::convertStatusForComponents(
int sta,
int typ) {
44 if (sta == 1 && typ == 0)
46 if (sta == 1 && typ == 1)
48 if (sta == 2 && typ == 0)
50 if (sta == 2 && typ == 1)
57 int Hydjet2Hadronizer::convertStatus(
int st) {
58 if (!separateHydjetComponents_) {
76 rotate_(pset.getParameter<bool>(
"rotateEventPlane")),
89 fParams.allowEmptyEvent =
false;
161 strcpy(
fParams.partDat, (f1.fullPath()).c_str());
164 strcpy(
fParams.tabDecay, (f2.fullPath()).c_str());
168 if (pset.
exists(
"signalVtx"))
174 LogDebug(
"EventSignalVertex") <<
"Setting event signal vertex "
213 LogInfo(
"Hydjet2Hadronizer|GenSeed") <<
"Seed for random number generation: "
225 LogInfo(
"Hydjet2Hadronizer|RAScaling") <<
"Nuclear radius(RA) = " << ra;
242 HepMC::GenVertex *genvtx =
nullptr;
247 if (
mix.size() < 1) {
248 throw cms::Exception(
"MatchVtx") <<
"Mixing has " <<
mix.size() <<
" sub-events, should have been at least 1"
253 throw cms::Exception(
"MatchVtx") <<
"Input background does not have smeared vertex!" << endl;
258 genvtx = inev->signal_process_vertex();
261 throw cms::Exception(
"MatchVtx") <<
"Input background does not have signal process vertex!" << endl;
263 double aX, aY, aZ, aT;
265 aX = genvtx->position().x();
266 aY = genvtx->position().y();
267 aZ = genvtx->position().z();
268 aT = genvtx->position().t();
273 LogInfo(
"MatchVtx") <<
" setting vertex "
274 <<
" aX " << aX <<
" aY " << aY <<
" aZ " << aZ <<
" aT " << aT << endl;
277 const HepMC::HeavyIon *hi = inev->heavy_ion();
281 phi0_ = hi->event_plane_angle();
285 LogWarning(
"EventEmbedding") <<
"Background event does not have heavy ion record!";
299 LogError(
"Hydjet2EmptyEvent") <<
"##### HYDJET2: No Particles generated, Number of tries =" << ntry;
302 std::ostringstream sstr;
303 sstr <<
"Hydjet2HadronizerProducer: No particles generated after " << ntry <<
" tries.\n";
309 if (
hj2->IsEmpty()) {
332 std::unique_ptr<HepMC::GenEvent>
evt = std::make_unique<HepMC::GenEvent>();
333 std::unique_ptr<edm::HepMCProduct> HepMCEvt = std::make_unique<edm::HepMCProduct>();
338 evt->set_signal_process_id(
pypars.msti[0]);
339 evt->set_event_scale(
pypars.pari[16]);
345 HepMCEvt = std::make_unique<edm::HepMCProduct>(evt.get());
347 evt = std::make_unique<HepMC::GenEvent>(*HepMCEvt->GetEvent());
350 HepMC::HEPEVT_Wrapper::check_hepevt_consistency();
351 LogDebug(
"HEPEVT_info") <<
"Ev numb: " << HepMC::HEPEVT_Wrapper::event_number()
352 <<
" Entries number: " << HepMC::HEPEVT_Wrapper::number_entries() <<
" Max. entries "
353 << HepMC::HEPEVT_Wrapper::max_number_entries() << std::endl;
361 std::vector<int> pdg = _pdg;
362 for (
size_t i = 0;
i < pdg.size();
i++) {
364 std::ostringstream pyCard;
365 pyCard <<
"MDCY(" << pyCode <<
",1)=0";
381 const double pi = 3.14159265358979;
390 LogDebug(
"Hydjet2") <<
" Number of hard events " <<
hj2->GetNjet();
399 vector<HepMC::GenParticle *> particle(
hj2->GetNtot());
400 HepMC::GenVertex *sub_vertices =
nullptr;
402 while (ihy < hj2->GetNtot()) {
403 if ((
hj2->GetiJet().at(ihy)) != isub_l) {
404 sub_vertices =
new HepMC::GenVertex(HepMC::FourVector(0, 0, 0, 0),
hj2->GetiJet().at(ihy));
405 evt->add_vertex(sub_vertices);
406 if (!evt->signal_process_vertex())
407 evt->set_signal_process_vertex(sub_vertices);
408 isub_l =
hj2->GetiJet().at(ihy);
411 if ((
hj2->GetFinal().at(ihy)) == 1)
413 LogDebug(
"Hydjet2_array") << ihy <<
" MULTin ev.:" <<
hj2->GetNtot() <<
" SubEv.#" <<
hj2->GetiJet().at(ihy)
414 <<
" Part #" << ihy + 1 <<
", PDG: " <<
hj2->GetPdg().at(ihy) <<
" (st. "
416 <<
") mother=" <<
hj2->GetMotherIndex().at(ihy) + 1 <<
", childs ("
417 <<
hj2->GetFirstDaughterIndex().at(ihy) + 1 <<
"-"
418 <<
hj2->GetLastDaughterIndex().at(ihy) + 1 <<
"), vtx (" <<
hj2->GetX().at(ihy) <<
","
419 <<
hj2->GetY().at(ihy) <<
"," <<
hj2->GetZ().at(ihy) <<
") " << std::endl;
421 if ((
hj2->GetMotherIndex().at(ihy)) <= 0) {
424 LogError(
"Hydjet2_array") <<
"##### HYDJET2: Vertex not initialized!";
426 sub_vertices->add_particle_out(particle.at(ihy));
427 LogDebug(
"Hydjet2_array") <<
" ---> " << ihy + 1 << std::endl;
430 int mid =
hj2->GetMotherIndex().at(ihy);
432 while (((mid + 1) < ihy) && (
std::abs(
hj2->GetPdg().at(mid)) < 100) &&
433 ((
hj2->GetFirstDaughterIndex().at(mid + 1)) <= ihy)) {
435 LogDebug(
"Hydjet2_array") <<
"======== MID changed to " << mid
436 <<
" ======== PDG(mid) = " <<
hj2->GetPdg().at(mid) << std::endl;
440 mid =
hj2->GetMotherIndex().at(ihy);
441 LogDebug(
"Hydjet2_array") <<
"======== MID changed BACK to " << mid
442 <<
" ======== PDG(mid) = " <<
hj2->GetPdg().at(mid) << std::endl;
446 HepMC::GenVertex *prod_vertex = mother->end_vertex();
450 prod_vertex->add_particle_in(mother);
451 LogDebug(
"Hydjet2_array") <<
" <--- " << mid + 1 << std::endl;
452 evt->add_vertex(prod_vertex);
454 prod_vertex->add_particle_out(particle.at(ihy));
455 LogDebug(
"Hydjet2_array") <<
" ---" << mid + 1 <<
"---> " << ihy + 1 << std::endl;
460 LogDebug(
"Hydjet2_array") <<
" MULTin ev.:" <<
hj2->GetNtot() <<
", last index: " << ihy - 1
461 <<
", stable particles: " << stab << std::endl;
468 double px0 = (
hj2->GetPx()).at(index);
469 double py0 = (
hj2->GetPy()).at(index);
477 (
hj2->GetPz()).at(index),
478 (
hj2->GetE()).at(index)),
479 (
hj2->GetPdg()).at(index),
481 (
hj2->GetType()).at(index)))
484 p->suggest_barcode(barcode);
491 double x0 = (
hj2->GetX()).at(i);
492 double y0 = (
hj2->GetY()).at(i);
495 double z = (
hj2->GetZ()).at(i);
496 double t = (
hj2->GetT()).at(i);
498 HepMC::GenVertex *vertex =
new HepMC::GenVertex(HepMC::FourVector(x, y, z, t),
id);
506 int nproj =
static_cast<int>((
hj2->GetNpart()) / 2);
507 int ntarg =
static_cast<int>((
hj2->GetNpart()) - nproj);
509 HepMC::HeavyIon *hi =
new HepMC::HeavyIon(
nsub_,
524 evt->set_heavy_ion(*hi);
T getUntrackedParameter(std::string const &, T const &) const
bool declareStableParticles(const std::vector< int > &)
bool separateHydjetComponents_
unsigned int maxEventsToPrint_
InitialParamsHydjet_t fParams
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void add_heavy_ion_rec(HepMC::GenEvent *evt)
unsigned int pythiaPylistVerbosity_
Sin< T >::type sin(const T &t)
bool call_pygive(const std::string &line)
HepMC::FourVector * fVertex_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::vector< double > signalVtx_
Log< level::Error, false > LogError
double nuclear_radius() const
edm::EDGetTokenT< CrossingFrame< edm::HepMCProduct > > src_
static const std::string kPythia6
HepMC::GenVertex * build_hyjet2_vertex(int i, int id)
Pythia6Service * pythia6Service_
CLHEP::HepRandomEngine * hjRandomEngine
Interface to the HYDJET++ (Hydjet2) generator (since core v. 2.4.3), produces HepMC events...
bool get_particles(HepMC::GenEvent *evt)
int convertStatusForComponents(int, int)
bool initializeForInternalPartons()
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
std::unique_ptr< HepMC::GenEvent > & event()
const char * classname() const
Log< level::Info, false > LogInfo
~Hydjet2Hadronizer() override
const HepMC::GenEvent * GetEvent() const
T const * product() const
bool isVtxGenApplied() const
T getParameter(std::string const &) const
HepMC::GenParticle * build_hyjet2(int index, int barcode)
void setRandomEngine(CLHEP::HepRandomEngine *v)
Log< level::Warning, false > LogWarning
edm::Event & getEDMEvent() const
bool generatePartonsAndHadronize()