1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Implementation of the TRD PID class //
22 // Assigns the electron and pion likelihoods to each ESD track. //
23 // The function MakePID(AliESDEvent *event) calculates the probability //
24 // of having dedx and a maximum timbin at a given //
25 // momentum (mom) and particle type k //
26 // from the precalculated distributions. //
29 // Prashant Shukla <shukla@pi0.physi.uni-heidelberg.de> (orig. version) //
30 // Alex Bercuci (a.bercuci@gsi.de) //
32 ////////////////////////////////////////////////////////////////////////////
34 #include "AliESDEvent.h"
35 #include "AliESDtrack.h"
36 #include "AliTracker.h"
38 #include "AliTRDpidESD.h"
39 #include "AliTRDgeometry.h"
40 #include "AliTRDcalibDB.h"
41 #include "Cal/AliTRDCalPID.h"
43 ClassImp(AliTRDpidESD)
45 Bool_t AliTRDpidESD::fgCheckTrackStatus = kTRUE;
46 Bool_t AliTRDpidESD::fgCheckKinkStatus = kFALSE;
47 Int_t AliTRDpidESD::fgMinPlane = 0;
49 //_____________________________________________________________________________
50 AliTRDpidESD::AliTRDpidESD()
55 // Default constructor
60 //_____________________________________________________________________________
61 AliTRDpidESD::AliTRDpidESD(const AliTRDpidESD &p)
66 // AliTRDpidESD copy constructor
69 ((AliTRDpidESD &) p).Copy(*this);
73 //_____________________________________________________________________________
74 AliTRDpidESD::~AliTRDpidESD()
80 if(fTrack) delete fTrack;
84 //_____________________________________________________________________________
85 AliTRDpidESD &AliTRDpidESD::operator=(const AliTRDpidESD &p)
88 // Assignment operator
91 if (this != &p) ((AliTRDpidESD &) p).Copy(*this);
96 //_____________________________________________________________________________
97 void AliTRDpidESD::Copy(TObject &p) const
103 ((AliTRDpidESD &) p).fgCheckTrackStatus = fgCheckTrackStatus;
104 ((AliTRDpidESD &) p).fgCheckKinkStatus = fgCheckKinkStatus;
105 ((AliTRDpidESD &) p).fgMinPlane = fgMinPlane;
106 ((AliTRDpidESD &) p).fTrack = NULL;
110 //_____________________________________________________________________________
111 Int_t AliTRDpidESD::MakePID(AliESDEvent * const event)
114 // This function calculates the PID probabilities based on TRD signals
116 // The method produces probabilities based on the charge
117 // and the position of the maximum time bin in each layer.
118 // The dE/dx information can be used as global charge or 2 to 3
119 // slices. Check AliTRDCalPID and AliTRDCalPIDRefMaker for the actual
123 // Alex Bercuci (A.Bercuci@gsi.de) 2nd May 2007
126 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
128 AliErrorGeneral("AliTRDpidESD::MakePID()"
129 ,"No access to calibration data");
133 // AliTRDrecoParam *rec = AliTRDReconstructor::RecoParam();
135 // AliErrorGeneral("AliTRDpidESD::MakePID()", "No TRD reco param.");
139 // Retrieve the CDB container class with the probability distributions
140 const AliTRDCalPID *pd = calibration->GetPIDObject(AliTRDpidUtil::kLQ);
142 AliErrorGeneral("AliTRDpidESD::MakePID()"
143 ,"No access to AliTRDCalPID");
147 // Loop through all ESD tracks
149 AliESDtrack *t = NULL;
150 Float_t dedx[AliTRDCalPID::kNSlicesLQ], dEdx;
154 for (Int_t i=0; i<event->GetNumberOfTracks(); i++) {
155 t = event->GetTrack(i);
158 if(!CheckTrack(t)) continue;
161 // Skip tracks which have no TRD signal at all
162 if (t->GetTRDsignal()<1.e-5) continue;
164 // Loop over detector layers
168 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++)
169 p[iSpecies] = 1./AliPID::kSPECIES;
171 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
172 // read data for track segment
173 for(int iSlice=0; iSlice<AliTRDCalPID::kNSlicesLQ; iSlice++)
174 dedx[iSlice] = t->GetTRDslice(iLayer, iSlice);
175 dEdx = t->GetTRDslice(iLayer, -1);
176 timebin = t->GetTRDTimBin(iLayer);
179 if ((dEdx <= 0.) || (timebin <= -1.)) continue;
181 // retrive kinematic info for this track segment
182 if(!RecalculateTrackSegmentKine(t, iLayer, mom, length)){
183 // information is not fully reliable especialy for length
184 // estimation. To be used in the future.
187 // this track segment has fulfilled all requierments
190 // Get the probabilities for the different particle species
191 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) {
192 p[iSpecies] *= pd->GetProbability(iSpecies, mom, dedx, length, iLayer);
193 //p[iSpecies] *= pd->GetProbabilityT(iSpecies, mom, timebin);
196 if(nPlanePID == 0) continue;
198 // normalize probabilities
199 Double_t probTotal = 0.;
200 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) probTotal += p[iSpecies];
202 AliWarning(Form("The total probability (%e) over all species <= 0 in ESD track %d."
204 AliWarning("This may be caused by some error in reference data.");
205 AliWarning("Calculation continues but results might be corrupted.");
208 for(Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) p[iSpecies] /= probTotal;
210 // book PID to the track
212 t->SetTRDntracklets(nPlanePID<<3);
219 //_____________________________________________________________________________
220 Bool_t AliTRDpidESD::CheckTrack(AliESDtrack * const t)
223 // Check if track is eligible for PID calculations
226 // Check the ESD track status
227 if (fgCheckTrackStatus) {
228 if (((t->GetStatus() & AliESDtrack::kTRDout ) == 0) &&
229 ((t->GetStatus() & AliESDtrack::kTRDrefit) == 0)) return kFALSE;
232 // Check for ESD kink tracks
233 if (fgCheckKinkStatus && (t->GetKinkIndex(0) != 0)) return kFALSE;
239 //_____________________________________________________________________________
240 Bool_t AliTRDpidESD::RecalculateTrackSegmentKine(AliESDtrack * const esd
246 // Retrive momentum "mom" and track "length" in TRD chamber from plane
247 // "plan" according to information stored in AliESDtrack "t".
250 // Alex Bercuci (A.Bercuci@gsi.de)
253 const Float_t kAmHalfWidth = AliTRDgeometry::AmThick() / 2.;
254 const Float_t kDrWidth = AliTRDgeometry::DrThick();
255 const Float_t kTime0 = AliTRDgeometry::GetTime0(layer);
257 // set initial length value to chamber height
258 length = 2 * kAmHalfWidth + kDrWidth;
260 // retrive track's outer param
261 const AliExternalTrackParam *op = esd->GetOuterParam();
267 AliExternalTrackParam *param = NULL;
269 fTrack = new AliExternalTrackParam(*op);
271 } else param = new(fTrack) AliExternalTrackParam(*op);
273 // retrive the magnetic field
276 Float_t field = AliTracker::GetBz(xyz0); // Bz in kG at point xyz0
279 // propagate to chamber entrance
280 if(!param->PropagateTo(kTime0-kAmHalfWidth-kDrWidth, field)){
284 if (s < 1.) length /= TMath::Sqrt((1.-s)*(1.+s) / (1. + t*t));
290 if (s < 1.) length /= TMath::Sqrt((1.-s)*(1.+s) / (1. + t*t));
292 // check if track is crossing tracking sector by propagating to chamber exit- maybe is too much :)
293 Double_t alpha = param->GetAlpha();
294 if(!param->PropagateTo(kTime0+kAmHalfWidth, field)) return kFALSE;
296 // mark track segments which are crossing SM boundaries along chamber
297 if(TMath::Abs(alpha-param->GetAlpha())>.01) return kFALSE;