- Int_t np = fStack->GetNprimary();
- Int_t nt = fTreeTR->GetEntries();
- //
- // Loop over tracks and find the secondaries with the help of the kine tree
- Int_t ifills = 0;
- Int_t it = 0;
- Int_t itlast = 0;
-
- for (Int_t ip = np - 1; ip > -1; ip--) {
- TParticle *part = fStack->Particle(ip);
-// printf("Particle %5d %5d %5d %5d %5d %5d \n",
-// ip, part->GetPdgCode(), part->GetFirstMother(), part->GetFirstDaughter(),
-// part->GetLastDaughter(), part->TestBit(kTransportBit));
-
- // Determine range of secondaries produced by this primary during transport
- Int_t dau1 = part->GetFirstDaughter();
- if (dau1 < np) continue; // This particle has no secondaries produced during transport
- Int_t dau2 = -1;
- if (dau1 > -1) {
- Int_t inext = ip - 1;
- while (dau2 < 0) {
- if (inext >= 0) {
- part = fStack->Particle(inext);
- dau2 = part->GetFirstDaughter();
- if (dau2 == -1 || dau2 < np) {
- dau2 = -1;
- } else {
- dau2--;
- }
- } else {
- dau2 = fStack->GetNtrack() - 1;
- }
- inext--;
- } // find upper bound
- } // dau2 < 0
-
-
-// printf("Check (1) %5d %5d %5d %5d %5d \n", ip, np, it, dau1, dau2);
-//
-// Loop over reference hits and find secondary label
-// First the tricky part: find the entry in treeTR than contains the hits or
-// make sure that no hits exist.
-//
- Bool_t hasHits = kFALSE;
- Bool_t isOutside = kFALSE;
-
- it = itlast;
- while (!hasHits && !isOutside && it < nt) {
- fTreeTR->GetEntry(it++);
- for (Int_t ib = 0; ib < 7; ib++) {
- if (!trefs[ib]) continue;
- Int_t nh = trefs[ib]->GetEntries();
- for (Int_t ih = 0; ih < nh; ih++) {
- AliTrackReference* tr = (AliTrackReference*) trefs[ib]->At(ih);
- Int_t label = tr->Label();
- if (label >= dau1 && label <= dau2) {
- hasHits = kTRUE;
- itlast = it - 1;
- break;
- }
- if (label > dau2 || label < ip) {
- isOutside = kTRUE;
- itlast = it - 1;
- break;
- }
- } // hits
- if (hasHits || isOutside) break;
- } // branches
- } // entries
-
- if (!hasHits) {
- // Write empty entries
- for (Int_t id = dau1; (id <= dau2); id++) {
- fTmpTreeTR->Fill();
- ifills++;
- }
- } else {
- // Collect all hits
- fTreeTR->GetEntry(itlast);
- for (Int_t id = dau1; (id <= dau2) && (dau1 > -1); id++) {
- for (Int_t ib = 0; ib < 7; ib++) {
- if (!trefs[ib]) continue;
- Int_t nh = trefs[ib]->GetEntries();
- for (Int_t ih = 0; ih < nh; ih++) {
- AliTrackReference* tr = (AliTrackReference*) trefs[ib]->At(ih);
- Int_t label = tr->Label();
- // Skip primaries
- if (label == ip) continue;
- if (label > dau2 || label < dau1)
- printf("AliMCEventHandler::Track Reference Label out of range !: %5d %5d %5d %5d \n",
- itlast, label, dau1, dau2);
- if (label == id) {
- // secondary found
- tr->SetDetectorId(ib-1);
- Int_t nref = fTrackReferences->GetEntriesFast();
- TClonesArray &lref = *fTrackReferences;
- new(lref[nref]) AliTrackReference(*tr);
- }
- } // hits
- } // branches
- fTmpTreeTR->Fill();
- fTrackReferences->Clear();
- ifills++;
- } // daughters
- } // has hits
- } // tracks
- //
- // Now loop again and write the primaries
- //
- it = nt - 1;
- for (Int_t ip = 0; ip < np; ip++) {
- Int_t labmax = -1;
- while (labmax < ip && it > -1) {
- fTreeTR->GetEntry(it--);
- for (Int_t ib = 0; ib < 7; ib++) {
- if (!trefs[ib]) continue;
- Int_t nh = trefs[ib]->GetEntries();
- //
- // Loop over reference hits and find primary labels
- for (Int_t ih = 0; ih < nh; ih++) {
- AliTrackReference* tr = (AliTrackReference*) trefs[ib]->At(ih);
- Int_t label = tr->Label();
- if (label < np && label > labmax) {
- labmax = label;
- }
-
- if (label == ip) {
- tr->SetDetectorId(ib-1);
- Int_t nref = fTrackReferences->GetEntriesFast();
- TClonesArray &lref = *fTrackReferences;
- new(lref[nref]) AliTrackReference(*tr);
- }
- } // hits
- } // branches
- } // entries
- it++;
- fTmpTreeTR->Fill();
- fTrackReferences->Clear();
- ifills++;
- } // tracks
- // Check
- delete fTreeTR;
- for (Int_t ib = 0; ib < 7; ib++) {
- if (trefs[ib]) delete trefs[ib];
- }