Dear Rooters,
I have a problem with looping over tracks in the stack. I just want to select tracks from the stack only one time and add this track to TObjArray selParticles object. If there are more than one track has the same label in the stack, I want to select the one track with the smallest chi^2 value and put it in selParticles and other (with same label tracks) tracks should go to rejParticles. I make following macro for this purpose,
AliStack *stack = mcEvent->Stack();
Int_t ntracks = fESD->GetNumberOfTracks();
TObjArray selParticles;
TObjArray rejParticles;
Int_t i1, i2,i3, lab1, lab2;
Bool_t *accept = new Bool_t[ntracks];
for (i1 = 0; i1 < ntracks; i1++) {
accept[i1] = kTRUE;
AliESDtrack *trk1 = fESD->GetTrack(i1);
lab1 = TMath::Abs(trk1->GetLabel());
for (i2 = i1+1; i2 < ntracks; i2++) {
AliESDtrack *trk2 = fESD->GetTrack(i2);
lab2 = TMath::Abs(trk2->GetLabel());
// check if labels are equal
if (lab1 == lab2) {
if (trk1->GetConstrainedChi2() < trk2->GetConstrainedChi2()) {
accept[i1] = kTRUE;
accept[i2] = kFALSE;
} else {
accept[i1] = kFALSE;
accept[i2] = kTRUE;
}
} // for if
} // for i2
} //for i1
for (i3 = 0; i3 < ntracks; i3++) {
AliESDtrack *trk3 = fESD->GetTrack(i3);
if(accept[i3]==kTRUE)
{
selParticles.Add(trk3);
}
if(accept[i3]==kFALSE)
{
rejParticles.Add(trk3);
}
} //for i3
When I print the results some tracks counted more than one time in selParticles, following values are part of my result,
Stackpart label=1854 chi^2=0.000000
label=1854 chi^2=0.000000
label=1854 chi^2=0.000000
label=1854 chi^2=0.158253
label=1854 chi^2=42.000000
label=1854 chi^2=0.000000
label=1854 chi^2=3.531250
SelPart label=1854 chi^2=0.000000
label=1854 chi^2=0.000000
label=1854 chi^2=0.000000
label=1854 chi^2=0.158253
RejPart lab=1854 chi^2=42.000000
lab=1854 chi^2=3.531250
But the result SelPart should include only one time lab=1854 chi^2=0.000000 track.
I don’t know where I’m wrong. Could you please help me to solve this problem.
Thank you,
Kind regards to All,
Ayben