@@ -74,10 +74,30 @@ namespace o2
7474 auto part = genMap [mTag ]();
7575 if (part .GetPdgCode () == 23 ) {
7676 auto daughters = decayZ0 (part );
77+ int startIdx = mParticles .size (); // Position where Z0 will be inserted
7778 for (auto & dau : daughters )
7879 {
7980 mParticles .push_back (dau );
8081 }
82+ // Fix daughter/mother indices to reflect actual positions in mParticles
83+ // The decayZ0 uses local indices (relative to subparts), we need to offset them
84+ for (size_t i = 0 ; i < daughters .size (); i ++ ) {
85+ int globalIdx = startIdx + i ;
86+ // Adjust mother indices
87+ int motherIdx = mParticles [globalIdx ].GetFirstMother ();
88+ if (motherIdx >= 0 ) {
89+ mParticles [globalIdx ].SetFirstMother (startIdx + motherIdx );
90+ }
91+ // Adjust daughter indices
92+ int firstDaughter = mParticles [globalIdx ].GetFirstDaughter ();
93+ int lastDaughter = mParticles [globalIdx ].GetLastDaughter ();
94+ if (firstDaughter >= 0 ) {
95+ mParticles [globalIdx ].SetFirstDaughter (startIdx + firstDaughter );
96+ }
97+ if (lastDaughter >= 0 ) {
98+ mParticles [globalIdx ].SetLastDaughter (startIdx + lastDaughter );
99+ }
100+ }
81101 } else {
82102 mParticles .push_back (part );
83103 }
@@ -329,56 +349,16 @@ namespace o2
329349 }
330350 for (int j = 0 ; j < event .size (); ++ j )
331351 {
332- const Pythia8 ::Particle & p = event [j ];
333- if (p .id () == 23 ) // PDG code for Z0
334- {
335- // Push Z0 itself
336- subparts .push_back (TParticle (p .id (), p .status (),
337- -1 , -1 , -1 , -1 ,
338- p .px (), p .py (),
339- p .pz (), p .e (),
340- z0 .Vx (), z0 .Vy (), z0 .Vz (), 0.0 ));
341- subparts .back ().SetStatusCode (o2 ::mcgenstatus ::MCGenStatusEncoding (p .status (), 0 ).fullEncoding );
342- subparts .back ().SetUniqueID (mGenID );
343- subparts .back ().SetBit (ParticleStatus ::kToBeDone , false);
344- // Navigate through intermediate Z0s to find final decay products
345- int iZ0 = j ;
346- while (event [iZ0 ].daughter1 () != 0 &&
347- event [event [iZ0 ].daughter1 ()].id () == 23 )
348- {
349- iZ0 = event [iZ0 ].daughter1 ();
350- }
351- // Recursively collect all final-state descendants
352- std ::function < void (int )> collectAllDescendants = [& ](int idx )
353- {
354- const Pythia8 ::Particle & particle = event [idx ];
355- subparts .push_back (TParticle (particle .id (), particle .status (),
356- -1 , -1 , -1 , -1 ,
357- particle .px (), particle .py (),
358- particle .pz (), particle .e (),
359- p .xProd (), p .yProd (), p .zProd (), p .tProd ()));
360- subparts .back ().SetStatusCode (o2 ::mcgenstatus ::MCGenStatusEncoding (particle .status (), 0 ).fullEncoding );
361- subparts .back ().SetUniqueID (mGenID + 1 );
362- subparts .back ().SetBit (ParticleStatus ::kToBeDone ,
363- o2 ::mcgenstatus ::getHepMCStatusCode (subparts .back ().GetStatusCode ()) == 1 );
364- // Not final-state, recurse through daughters
365- if (!particle .isFinal ())
366- {
367- int d1 = particle .daughter1 ();
368- int d2 = particle .daughter2 ();
369- if (d1 > 0 )
370- {
371- for (int k = d1 ; k <= d2 ; ++ k )
372- {
373- collectAllDescendants (k );
374- }
375- }
376- }
377- };
378- // Start collecting from the final Z0
379- collectAllDescendants (iZ0 );
380- break ; // Found and processed the Z0
381- }
352+ const Pythia8 ::Particle & particle = event [j ];
353+ subparts .push_back (TParticle (particle .id (), particle .status (),
354+ particle .mother1 (), particle .mother2 (), particle .daughter1 (), particle .daughter2 (), // mother set to local index in subparts
355+ particle .px (), particle .py (),
356+ particle .pz (), particle .e (),
357+ particle .xProd (), particle .yProd (), particle .zProd (), particle .tProd ()));
358+ subparts .back ().SetStatusCode (o2 ::mcgenstatus ::MCGenStatusEncoding (particle .statusHepMC (), particle .status ()).fullEncoding );
359+ subparts .back ().SetUniqueID (mGenID + 1 );
360+ subparts .back ().SetBit (ParticleStatus ::kToBeDone ,
361+ particle .id () != 23 && o2 ::mcgenstatus ::getHepMCStatusCode (subparts .back ().GetStatusCode ()) == 1 );
382362 }
383363 return subparts ;
384364 }
@@ -395,4 +375,4 @@ Generator_Performance(const float fraction = 0.03f, const unsigned short int nsi
395375{
396376 auto generator = new o2 ::eventgen ::GenPerf (fraction , nsig , tag );
397377 return generator ;
398- }
378+ }
0 commit comments