@@ -25,6 +25,12 @@ namespace eventgen
2525
2626GeneratorHybrid::GeneratorHybrid (const std::string& inputgens)
2727{
28+ // This generator has trivial unit conversions
29+ setTimeUnit (1 .);
30+ setPositionUnit (1 .);
31+ setMomentumUnit (1 .);
32+ setEnergyUnit (1 .);
33+
2834 if (!parseJSON (inputgens)) {
2935 LOG (fatal) << " Failed to parse JSON configuration from input generators" ;
3036 exit (1 );
@@ -382,6 +388,27 @@ bool GeneratorHybrid::importParticles()
382388 }
383389 }
384390 }
391+
392+ auto unit_transformer = [](auto & p, auto pos_unit, auto time_unit, auto en_unit, auto mom_unit) {
393+ p.SetMomentum (p.Px () * mom_unit, p.Py () * mom_unit, p.Pz () * mom_unit, p.Energy () * en_unit);
394+ p.SetProductionVertex (p.Vx () * pos_unit, p.Vy () * pos_unit, p.Vz () * pos_unit, p.T () * time_unit);
395+ };
396+
397+ auto index_transformer = [](auto & p, int offset) {
398+ for (int i = 0 ; i < 2 ; ++i) {
399+ if (p.GetMother (i) != -1 ) {
400+ const auto newindex = p.GetMother (i) + offset;
401+ p.SetMother (i, newindex);
402+ }
403+ }
404+ if (p.GetNDaughters () > 0 ) {
405+ for (int i = 0 ; i < 2 ; ++i) {
406+ const auto newindex = p.GetDaughter (i) + offset;
407+ p.SetDaughter (i, newindex);
408+ }
409+ }
410+ };
411+
385412 // Clear particles and event header
386413 mParticles .clear ();
387414 mMCEventHeader .clearInfo ();
@@ -391,23 +418,20 @@ bool GeneratorHybrid::importParticles()
391418 LOG (info) << " Importing particles for task " << subIndex;
392419 auto subParticles = gens[subIndex]->getParticles ();
393420
421+ auto time_unit = gens[subIndex]->getTimeUnit ();
422+ auto pos_unit = gens[subIndex]->getPositionUnit ();
423+ auto mom_unit = gens[subIndex]->getMomentumUnit ();
424+ auto energy_unit = gens[subIndex]->getEnergyUnit ();
425+
394426 // The particles carry mother and daughter indices, which are relative
395427 // to the sub-generator. We need to adjust these indices to reflect that particles
396428 // are now embedded into a cocktail.
397429 auto offset = mParticles .size ();
398430 for (auto & p : subParticles) {
399- for (int i = 0 ; i < 2 ; ++i) {
400- if (p.GetMother (i) != -1 ) {
401- const auto newindex = p.GetMother (i) + offset;
402- p.SetMother (i, newindex);
403- }
404- }
405- if (p.GetNDaughters () > 0 ) {
406- for (int i = 0 ; i < 2 ; ++i) {
407- const auto newindex = p.GetDaughter (i) + offset;
408- p.SetDaughter (i, newindex);
409- }
410- }
431+ // apply the mother-daugher index transformation
432+ index_transformer (p, offset);
433+ // apply unit transformation of sub-generator
434+ unit_transformer (p, pos_unit, time_unit, energy_unit, mom_unit);
411435 }
412436
413437 mParticles .insert (mParticles .end (), subParticles.begin (), subParticles.end ());
@@ -420,6 +444,18 @@ bool GeneratorHybrid::importParticles()
420444 LOG (info) << " Importing particles for task " << genIndex;
421445 // at this moment the mIndex-th generator is ready to be used
422446 mParticles = gens[genIndex]->getParticles ();
447+
448+ auto time_unit = gens[genIndex]->getTimeUnit ();
449+ auto pos_unit = gens[genIndex]->getPositionUnit ();
450+ auto mom_unit = gens[genIndex]->getMomentumUnit ();
451+ auto energy_unit = gens[genIndex]->getEnergyUnit ();
452+
453+ // transform units to units of the hybrid generator
454+ for (auto & p : mParticles ) {
455+ // apply unit transformation
456+ unit_transformer (p, pos_unit, time_unit, energy_unit, mom_unit);
457+ }
458+
423459 // fetch the event Header information from the underlying generator
424460 gens[genIndex]->updateHeader (&mMCEventHeader );
425461 mInputTaskQueue .push (genIndex);
0 commit comments