+ // check data
+ if ((dEdx <= 0.) || (timebin <= -1.)) continue;
+
+ // retrive kinematic info for this track segment
+ if(!RecalculateTrackSegmentKine(t, iPlan, mom, length)){
+ // information is not fully reliable especialy for length
+ // estimation. To be used in the future.
+ }
+
+ // this track segment has fulfilled all requierments
+ nPlanePID++;
+
+ // Get the probabilities for the different particle species
+ for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) {
+ p[iSpecies] *= pd->GetProbability(iSpecies, mom, dedx, length, iPlan);
+ //p[iSpecies] *= pd->GetProbabilityT(iSpecies, mom, timebin);
+ }
+ }
+ if(nPlanePID == 0) continue;
+
+ // normalize probabilities
+ Double_t probTotal = 0.;
+ for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) probTotal += p[iSpecies];
+ if(probTotal <= 0.){
+ AliWarning(Form("The total probability (%e) over all species <= 0 in ESD track %d."
+ , probTotal, i));
+ AliWarning("This may be caused by some error in reference data.");
+ AliWarning("Calculation continues but results might be corrupted.");
+ continue;
+ }
+ for(Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) p[iSpecies] /= probTotal;
+
+ // book PID to the track
+ t->SetTRDpid(p);
+ t->SetTRDpidQuality(nPlanePID);
+ }
+
+ return 0;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDpidESD::CheckTrack(AliESDtrack *t)
+{
+ //
+ // Check if track is eligible for PID calculations
+ //
+
+ // Check the ESD track status
+ if (fgCheckTrackStatus) {
+ if (((t->GetStatus() & AliESDtrack::kTRDout ) == 0) &&
+ ((t->GetStatus() & AliESDtrack::kTRDrefit) == 0)) return kFALSE;
+ }
+
+ // Check for ESD kink tracks
+ if (fgCheckKinkStatus && (t->GetKinkIndex(0) != 0)) return kFALSE;
+
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDpidESD::RecalculateTrackSegmentKine(AliESDtrack *esd
+ , Int_t plan
+ , Float_t &mom
+ , Float_t &length)
+{
+ //
+ // Retrive momentum "mom" and track "length" in TRD chamber from plane
+ // "plan" according to information stored in AliESDtrack "t".
+ //
+ // Origin
+ // Alex Bercuci (A.Bercuci@gsi.de)
+ //
+
+ const Float_t kAmHalfWidth = AliTRDgeometry::AmThick() / 2.;
+ const Float_t kDrWidth = AliTRDgeometry::DrThick();
+ const Float_t kTime0 = AliTRDgeometry::GetTime0(plan);
+
+ // set initial length value to chamber height
+ length = 2 * kAmHalfWidth + kDrWidth;
+
+ // retrive track's outer param
+ const AliExternalTrackParam *op = esd->GetOuterParam();
+ if(!op){
+ mom = esd->GetP();
+ return kFALSE;
+ }
+
+ AliExternalTrackParam *param = 0x0;
+ if(!fTrack){
+ fTrack = new AliExternalTrackParam(*op);
+ param = fTrack;
+ } else param = new(fTrack) AliExternalTrackParam(*op);
+
+ // retrive the magnetic field
+ Double_t xyz0[3];
+ op->GetXYZ(xyz0);
+ Float_t field = AliTracker::GetBz(xyz0); // Bz in kG at point xyz0
+ Double_t s, t;
+
+ // propagate to chamber entrance
+ if(!param->PropagateTo(kTime0-kAmHalfWidth-kDrWidth, field)){
+ mom = op->GetP();
+ s = op->GetSnp();
+ t = op->GetTgl();
+ if (s < 1.) length /= TMath::Sqrt((1. - s*s) / (1. + t*t));
+ return kFALSE;
+ }
+ mom = param->GetP();
+ s = param->GetSnp();
+ t = param->GetTgl();
+ if (s < 1.) length /= TMath::Sqrt((1. - s*s) / (1. + t*t));
+
+ // check if track is crossing tracking sector by propagating to chamber exit- maybe is too much :)
+ Double_t alpha = param->GetAlpha();
+ if(!param->PropagateTo(kTime0+kAmHalfWidth, field)) return kFALSE;
+
+ // mark track segments which are crossing SM boundaries along chamber
+ if(TMath::Abs(alpha-param->GetAlpha())>.01) return kFALSE;
+
+ return kTRUE;
+
+}