+
+//------------------------------------------------------------------------
+void AliITStrackerMI::FlagFakes(const TObjArray &itsTracks)
+{
+ //
+ // RS: flag those tracks which are suxpected to have fake clusters
+ //
+ const double kThreshPt = 0.5;
+ AliRefArray *refArr[6];
+ //
+ for (int i=0;i<6;i++) {
+ int ncl = fgLayers[i].GetNumberOfClusters();
+ refArr[i] = new AliRefArray(ncl,TMath::Min(ncl,1000));
+ }
+ Int_t nentries = itsTracks.GetEntriesFast();
+ //
+ // fill cluster->track associations
+ for (Int_t itr=0;itr<nentries;itr++){
+ AliITStrackMI* track = (AliITStrackMI*)itsTracks.UncheckedAt(itr);
+ if (!track) continue;
+ AliITStrackMI* trackITS = track->GetWinner();
+ if (!trackITS) continue;
+ for (int il=trackITS->GetNumberOfClusters();il--;) {
+ int idx = trackITS->GetClusterIndex(il);
+ Int_t l=(idx & 0xf0000000) >> 28, c=(idx & 0x0fffffff) >> 00;
+ // if (c>fgLayers[l].GetNumberOfClusters()) continue;
+ refArr[l]->AddReference(c, itr);
+ }
+ }
+ //
+ const UInt_t kMaxRef = 100;
+ UInt_t crefs[kMaxRef];
+ Int_t ncrefs=0;
+ // process tracks with shared clusters
+ for (int itr=0;itr<nentries;itr++){
+ AliITStrackMI* track0 = (AliITStrackMI*)itsTracks.UncheckedAt(itr);
+ AliITStrackMI* trackH0 = track0->GetWinner();
+ if (!trackH0) continue;
+ AliESDtrack* esd0 = track0->GetESDtrack();
+ //
+ for (int il=0;il<trackH0->GetNumberOfClusters();il++) {
+ int idx = trackH0->GetClusterIndex(il);
+ Int_t l=(idx & 0xf0000000) >> 28, c=(idx & 0x0fffffff) >> 00;
+ ncrefs = refArr[l]->GetReferences(c,crefs,kMaxRef);
+ if (ncrefs<2) continue; // there will be always self-reference, for sharing needs at least 2
+ esd0->SetITSSharedFlag(l);
+ for (int ir=ncrefs;ir--;) {
+ if (int(crefs[ir]) <= itr) continue; // ==:selfreference, <: the same pair will be checked with >
+ AliITStrackMI* track1 = (AliITStrackMI*)itsTracks.UncheckedAt(crefs[ir]);
+ AliITStrackMI* trackH1 = track1->GetWinner();
+ AliESDtrack* esd1 = track1->GetESDtrack();
+ esd1->SetITSSharedFlag(l);
+ //
+ double pt0 = trackH0->Pt(), pt1 = trackH1->Pt(), res = 0.;
+ if (pt0>kThreshPt && pt0-pt1>0.2+0.2*(pt0-kThreshPt) ) res = -100;
+ else if (pt1>kThreshPt && pt1-pt0>0.2+0.2*(pt1-kThreshPt) ) res = 100;
+
+ // select the one with smallest chi2's product
+ res += trackH0->GetChi2MIP(0)*trackH0->GetChi2MIP(3);
+ res -= trackH1->GetChi2MIP(0)*trackH1->GetChi2MIP(3);
+ //
+ if (res<0) esd1->SetITSFakeFlag(); // esd0 is winner
+ else esd0->SetITSFakeFlag(); // esd1 is winner
+ }
+ //
+ }
+ //
+ }
+ //
+ for (int i=6;i--;) delete refArr[i];
+}
+
+
+
+//------------------------------------------------------------------------
+void AliITStrackerMI::CookLabel(AliITStrackMI *track,Float_t wrong) const {
+ //--------------------------------------------------------------------
+ //This function "cooks" a track label. If label<0, this track is fake.
+ //--------------------------------------------------------------------
+ const int kMaxLbPerCl = 3;
+ int lbID[36],lbStat[36];
+ Int_t nLab=0, nCl = track->GetNumberOfClusters();
+ //
+ // track->SetLabel(-1);
+ // track->SetFakeRatio(0);
+ //
+ for (Int_t i=0;i<nCl;i++) { // fill all labels
+ Int_t cindex = track->GetClusterIndex(i);
+ // Int_t l=(cindex & 0xf0000000) >> 28;
+ AliITSRecPoint *cl = (AliITSRecPoint*)GetCluster(cindex);
+ //
+ for (int imc=0;imc<kMaxLbPerCl;imc++) { // labels within single cluster
+ int trLb = cl->GetLabel(imc);
+ if (trLb<0) break;
+ // search this mc track in already accounted ones
+ int iLab;
+ for (iLab=0;iLab<nLab;iLab++) if (lbID[iLab]==trLb) break;
+ if (iLab<nLab) lbStat[iLab]++;
+ else {
+ lbID[nLab] = trLb;
+ lbStat[nLab++] = 1;
+ }
+ } // loop over given cluster's labels
+ } // loop over clusters
+ //
+ if (nLab<1) return; // no labels at all
+ //
+ Int_t tpcLabel=-1;
+ if (track->GetESDtrack() && track->GetESDtrack()->IsOn(AliESDtrack::kTPCin)){
+ tpcLabel = TMath::Abs(track->GetESDtrack()->GetTPCLabel());
+ }
+ //
+ // find majority label
+ if (nCl && nLab) {
+ int maxLab=0,tpcLabID=-1;
+ for (int ilb=nLab;ilb--;) {
+ int st = lbStat[ilb];
+ if (lbStat[maxLab]<st) maxLab = ilb;
+ if (lbID[ilb] == tpcLabel) tpcLabID = ilb;
+ }
+ // if there is an equal choice, prefer ITS label consistent with TPC label
+ if (tpcLabel>0 && (tpcLabID!=maxLab) && lbStat[maxLab]==lbStat[tpcLabID]) maxLab=tpcLabID;
+
+ track->SetFakeRatio(1.-float(lbStat[maxLab])/nCl);
+ track->SetLabel( lbStat[maxLab]>=nCl-wrong ? lbID[maxLab] : -lbID[maxLab]);
+ }
+ //
+}
+
+/*