+ //
+ // Howmany secondaries have been produced ?
+ Int_t nNew = fNtrack - fHgwmk - 1;
+
+ if (nNew > 0) {
+ Int_t i, j;
+ TArrayI map1(nNew);
+ //
+ // Copy pointers to temporary array
+ TParticle** tmp = new TParticle*[nNew];
+
+ for (i = 0; i < nNew; i++) {
+ if (fParticleMap.At(fHgwmk + 1 + i)) {
+ tmp[i] = GetParticleMapEntry(fHgwmk + 1 + i);
+ } else {
+ tmp[i] = 0x0;
+ }
+ map1[i] = -99;
+ }
+
+
+ //
+ // Reset LoadPoint
+ //
+ Int_t loadPoint = fHgwmk + 1;
+ //
+ // Re-Push particles into stack
+ // The outer loop is over parents, the inner over children.
+ // -1 refers to the primary particle
+ //
+ for (i = -1; i < nNew-1; i++) {
+ Int_t ipa;
+ TParticle* parP;
+ if (i == -1) {
+ ipa = tmp[0]->GetFirstMother();
+ parP = GetParticleMapEntry(ipa);
+ } else {
+ ipa = (fHgwmk + 1 + i);
+ // Skip deleted particles
+ if (!tmp[i]) continue;
+ // Skip particles without children
+ if (tmp[i]->GetFirstDaughter() == -1) continue;
+ parP = tmp[i];
+ }
+ // Reset daughter information
+
+ Int_t idaumin = parP->GetFirstDaughter() - fHgwmk - 1;
+ Int_t idaumax = parP->GetLastDaughter() - fHgwmk - 1;
+ parP->SetFirstDaughter(-1);
+ parP->SetLastDaughter(-1);
+ for (j = idaumin; j <= idaumax; j++) {
+ // Skip deleted particles
+ if (!tmp[j]) continue;
+ // Skip particles already handled
+ if (map1[j] != -99) continue;
+ Int_t jpa = tmp[j]->GetFirstMother();
+ // Check if daughter of current parent
+ if (jpa == ipa) {
+ fParticleMap[loadPoint] = tmp[j];
+ // Re-establish daughter information
+ parP->SetLastDaughter(loadPoint);
+ if (parP->GetFirstDaughter() == -1) parP->SetFirstDaughter(loadPoint);
+ // Set Mother information
+ if (i != -1) {
+ tmp[j]->SetFirstMother(map1[i]);
+ }
+ // Build the map
+ map1[j] = loadPoint;
+ // Increase load point
+ loadPoint++;
+ }
+ } // children
+ } // parents
+
+ delete[] tmp;
+
+ //
+ // Build map for remapping of hits
+ //
+ fTrackLabelMap.Set(fNtrack);
+ for (i = 0; i < fNtrack; i ++) {
+ if (i <= fHgwmk) {
+ fTrackLabelMap[i] = i;
+ } else{
+ fTrackLabelMap[i] = map1[i - fHgwmk -1];
+ }
+ }
+ } // new particles poduced
+
+ return kTRUE;