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 ////////////////////////////////////////////////////////////////////////////
35 #include "AliESDEvent.h"
36 #include "AliESDtrack.h"
37 #include "AliTracker.h"
40 #include "AliTRDpidESD.h"
41 #include "AliTRDgeometry.h"
42 #include "AliTRDcalibDB.h"
43 #include "AliTRDtrack.h"
44 #include "Cal/AliTRDCalPID.h"
46 ClassImp(AliTRDpidESD)
48 Bool_t AliTRDpidESD::fgCheckTrackStatus = kTRUE;
49 Bool_t AliTRDpidESD::fgCheckKinkStatus = kFALSE;
50 Int_t AliTRDpidESD::fgMinPlane = 0;
52 //_____________________________________________________________________________
53 AliTRDpidESD::AliTRDpidESD()
58 // Default constructor
63 //_____________________________________________________________________________
64 AliTRDpidESD::AliTRDpidESD(const AliTRDpidESD &p)
69 // AliTRDpidESD copy constructor
72 ((AliTRDpidESD &) p).Copy(*this);
76 //_____________________________________________________________________________
77 AliTRDpidESD::~AliTRDpidESD()
83 if(fTrack) delete fTrack;
87 //_____________________________________________________________________________
88 AliTRDpidESD &AliTRDpidESD::operator=(const AliTRDpidESD &p)
91 // Assignment operator
94 if (this != &p) ((AliTRDpidESD &) p).Copy(*this);
99 //_____________________________________________________________________________
100 void AliTRDpidESD::Copy(TObject &p) const
106 ((AliTRDpidESD &) p).fgCheckTrackStatus = fgCheckTrackStatus;
107 ((AliTRDpidESD &) p).fgCheckKinkStatus = fgCheckKinkStatus;
108 ((AliTRDpidESD &) p).fgMinPlane = fgMinPlane;
109 ((AliTRDpidESD &) p).fTrack = 0x0;
113 //_____________________________________________________________________________
114 Int_t AliTRDpidESD::MakePID(AliESDEvent *event)
117 // This function calculates the PID probabilities based on TRD signals
119 // The method produces probabilities based on the charge
120 // and the position of the maximum time bin in each layer.
121 // The dE/dx information can be used as global charge or 2 to 3
122 // slices. Check AliTRDCalPID and AliTRDCalPIDRefMaker for the actual
126 // Alex Bercuci (A.Bercuci@gsi.de) 2nd May 2007
129 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
131 AliErrorGeneral("AliTRDpidESD::MakePID()"
132 ,"No access to calibration data");
136 // Retrieve the CDB container class with the probability distributions
137 const AliTRDCalPID *pd = calibration->GetPIDObject(1);
139 AliErrorGeneral("AliTRDpidESD::MakePID()"
140 ,"No access to AliTRDCalPID");
144 // Loop through all ESD tracks
146 AliESDtrack *t = 0x0;
147 Float_t dedx[AliTRDtrack::kNslice], dEdx;
151 for (Int_t i=0; i<event->GetNumberOfTracks(); i++) {
152 t = event->GetTrack(i);
155 if(!CheckTrack(t)) continue;
158 // Skip tracks which have no TRD signal at all
159 if (t->GetTRDsignal() == 0.) continue;
161 // Loop over detector layers
165 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++)
166 p[iSpecies] = 1./AliPID::kSPECIES;
168 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
169 // read data for track segment
170 for(int iSlice=0; iSlice<AliTRDtrack::kNslice; iSlice++)
171 dedx[iSlice] = t->GetTRDslice(iLayer, iSlice);
172 dEdx = t->GetTRDslice(iLayer, -1);
173 timebin = t->GetTRDTimBin(iLayer);
176 if ((dEdx <= 0.) || (timebin <= -1.)) continue;
178 // retrive kinematic info for this track segment
179 if(!RecalculateTrackSegmentKine(t, iLayer, mom, length)){
180 // information is not fully reliable especialy for length
181 // estimation. To be used in the future.
184 // this track segment has fulfilled all requierments
187 // Get the probabilities for the different particle species
188 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) {
189 p[iSpecies] *= pd->GetProbability(iSpecies, mom, dedx, length, iLayer);
190 //p[iSpecies] *= pd->GetProbabilityT(iSpecies, mom, timebin);
193 if(nPlanePID == 0) continue;
195 // normalize probabilities
196 Double_t probTotal = 0.;
197 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) probTotal += p[iSpecies];
199 AliWarning(Form("The total probability (%e) over all species <= 0 in ESD track %d."
201 AliWarning("This may be caused by some error in reference data.");
202 AliWarning("Calculation continues but results might be corrupted.");
205 for(Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) p[iSpecies] /= probTotal;
207 // book PID to the track
209 t->SetTRDpidQuality(nPlanePID);
216 //_____________________________________________________________________________
217 Bool_t AliTRDpidESD::CheckTrack(AliESDtrack *t)
220 // Check if track is eligible for PID calculations
223 // Check the ESD track status
224 if (fgCheckTrackStatus) {
225 if (((t->GetStatus() & AliESDtrack::kTRDout ) == 0) &&
226 ((t->GetStatus() & AliESDtrack::kTRDrefit) == 0)) return kFALSE;
229 // Check for ESD kink tracks
230 if (fgCheckKinkStatus && (t->GetKinkIndex(0) != 0)) return kFALSE;
236 //_____________________________________________________________________________
237 Bool_t AliTRDpidESD::RecalculateTrackSegmentKine(AliESDtrack *esd
243 // Retrive momentum "mom" and track "length" in TRD chamber from plane
244 // "plan" according to information stored in AliESDtrack "t".
247 // Alex Bercuci (A.Bercuci@gsi.de)
250 const Float_t kAmHalfWidth = AliTRDgeometry::AmThick() / 2.;
251 const Float_t kDrWidth = AliTRDgeometry::DrThick();
252 const Float_t kTime0 = AliTRDgeometry::GetTime0(layer);
254 // set initial length value to chamber height
255 length = 2 * kAmHalfWidth + kDrWidth;
257 // retrive track's outer param
258 const AliExternalTrackParam *op = esd->GetOuterParam();
264 AliExternalTrackParam *param = 0x0;
266 fTrack = new AliExternalTrackParam(*op);
268 } else param = new(fTrack) AliExternalTrackParam(*op);
270 // retrive the magnetic field
273 Float_t field = AliTracker::GetBz(xyz0); // Bz in kG at point xyz0
276 // propagate to chamber entrance
277 if(!param->PropagateTo(kTime0-kAmHalfWidth-kDrWidth, field)){
281 if (s < 1.) length /= TMath::Sqrt((1. - s*s) / (1. + t*t));
287 if (s < 1.) length /= TMath::Sqrt((1. - s*s) / (1. + t*t));
289 // check if track is crossing tracking sector by propagating to chamber exit- maybe is too much :)
290 Double_t alpha = param->GetAlpha();
291 if(!param->PropagateTo(kTime0+kAmHalfWidth, field)) return kFALSE;
293 // mark track segments which are crossing SM boundaries along chamber
294 if(TMath::Abs(alpha-param->GetAlpha())>.01) return kFALSE;