Changes for task Optimization of V0 finder (2079) + plus fix for the bug number 47412...
[u/mrichter/AliRoot.git] / ITS / AliITSV0Finder.cxx
CommitLineData
cd90f0a2 1/**************************************************************************\r
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *\r
3 * *\r
4 * Author: The ALICE Off-line Project. *\r
5 * Contributors are mentioned in the code where appropriate. *\r
6 * *\r
7 * Permission to use, copy, modify and distribute this software and its *\r
8 * documentation strictly for non-commercial purposes is hereby granted *\r
9 * without fee, provided that the above copyright notice appears in all *\r
10 * copies and that both the copyright notice and this permission notice *\r
11 * appear in the supporting documentation. The authors make no claims *\r
12 * about the suitability of this software for any purpose. It is *\r
13 * provided "as is" without express or implied warranty. *\r
14 **************************************************************************/\r
15/* $Id$ */\r
16\r
17//-------------------------------------------------------------------------\r
18// Implementation of the on-the-fly v0 finder for ITS tracker MI\r
19// Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch \r
20// Extraction from AliITStrackerMI: Andrea Dainese\r
21// Current support and development: \r
22//-------------------------------------------------------------------------\r
23\r
24#include <TMatrixD.h>\r
25#include <TTree.h>\r
26#include <TString.h>\r
27#include <TRandom.h>\r
28#include <TTreeStream.h>\r
29\r
30\r
31#include "AliLog.h"\r
32#include "AliESDVertex.h"\r
33#include "AliESDEvent.h"\r
34#include "AliESDtrack.h"\r
35#include "AliV0.h"\r
36#include "AliHelix.h"\r
37#include "AliITSRecPoint.h"\r
38#include "AliITSReconstructor.h"\r
39#include "AliITStrackerMI.h"\r
40#include "AliITSV0Finder.h"\r
767aaecb 41#include "AliKFParticle.h"\r
61673d36 42#include "AliKFVertex.h"\r
cd90f0a2 43\r
44ClassImp(AliITSV0Finder)\r
45\r
767aaecb 46\r
47AliITSV0Finder::AliITSV0Finder():\r
48fDebugStreamer(0)\r
49 {\r
cd90f0a2 50 //Default constructor\r
767aaecb 51\r
52 fDebugStreamer = new TTreeSRedirector("ITSdebug.root");\r
53} \r
54\r
cd90f0a2 55//------------------------------------------------------------------------\r
56void AliITSV0Finder::UpdateTPCV0(const AliESDEvent *event,\r
57 AliITStrackerMI *tracker)\r
58{\r
59 //\r
60 //try to update, or reject TPC V0s\r
61 //\r
767aaecb 62 const Float_t kMinTgl2= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinTgl2();\r
63\r
cd90f0a2 64 TObjArray *trackHypothesys = tracker->GetTrackHypothesys();\r
65\r
66 Int_t nv0s = event->GetNumberOfV0s();\r
67 Int_t nitstracks = trackHypothesys->GetEntriesFast();\r
68\r
69 for (Int_t i=0;i<nv0s;i++){\r
70 AliESDv0 * vertex = event->GetV0(i);\r
71 Int_t ip = vertex->GetIndex(0);\r
72 Int_t im = vertex->GetIndex(1);\r
73 //\r
74 TObjArray * arrayp = (ip<nitstracks) ? (TObjArray*)trackHypothesys->At(ip):0;\r
75 TObjArray * arraym = (im<nitstracks) ? (TObjArray*)trackHypothesys->At(im):0;\r
76 AliITStrackMI * trackp = (arrayp!=0) ? (AliITStrackMI*)arrayp->At(0):0;\r
77 AliITStrackMI * trackm = (arraym!=0) ? (AliITStrackMI*)arraym->At(0):0;\r
78 //\r
79 //\r
80 if (trackp){\r
81 if (trackp->GetNumberOfClusters()+trackp->GetNDeadZone()>5.5){\r
82 if (trackp->GetConstrain()&&trackp->GetChi2MIP(0)<3) vertex->SetStatus(-100);\r
83 if (!trackp->GetConstrain()&&trackp->GetChi2MIP(0)<2) vertex->SetStatus(-100); \r
84 }\r
85 }\r
86\r
87 if (trackm){\r
88 if (trackm->GetNumberOfClusters()+trackm->GetNDeadZone()>5.5){\r
89 if (trackm->GetConstrain()&&trackm->GetChi2MIP(0)<3) vertex->SetStatus(-100);\r
90 if (!trackm->GetConstrain()&&trackm->GetChi2MIP(0)<2) vertex->SetStatus(-100); \r
91 }\r
92 }\r
93 if (vertex->GetStatus()==-100) continue;\r
94 //\r
95 Double_t xrp[3]; vertex->GetXYZ(xrp[0],xrp[1],xrp[2]); //I.B.\r
96 Int_t clayer = tracker->GetNearestLayer(xrp); //I.B.\r
97 vertex->SetNBefore(clayer); //\r
98 vertex->SetChi2Before(9*clayer); //\r
99 vertex->SetNAfter(6-clayer); //\r
100 vertex->SetChi2After(0); //\r
101 //\r
102 if (clayer >1 ){ // calculate chi2 before vertex\r
103 Float_t chi2p = 0, chi2m=0; \r
104 //\r
105 if (trackp){\r
106 for (Int_t ilayer=0;ilayer<clayer;ilayer++){\r
107 if (trackp->GetClIndex(ilayer)>=0){\r
108 chi2p+=trackp->GetDy(ilayer)*trackp->GetDy(ilayer)/(trackp->GetSigmaY(ilayer)*trackp->GetSigmaY(ilayer))+\r
109 trackp->GetDz(ilayer)*trackp->GetDz(ilayer)/(trackp->GetSigmaZ(ilayer)*trackp->GetSigmaZ(ilayer));\r
110 }\r
111 else{\r
112 chi2p+=9;\r
113 }\r
114 }\r
115 }else{\r
116 chi2p = 9*clayer;\r
117 }\r
118 //\r
119 if (trackm){\r
120 for (Int_t ilayer=0;ilayer<clayer;ilayer++){\r
121 if (trackm->GetClIndex(ilayer)>=0){\r
122 chi2m+=trackm->GetDy(ilayer)*trackm->GetDy(ilayer)/(trackm->GetSigmaY(ilayer)*trackm->GetSigmaY(ilayer))+\r
123 trackm->GetDz(ilayer)*trackm->GetDz(ilayer)/(trackm->GetSigmaZ(ilayer)*trackm->GetSigmaZ(ilayer));\r
124 }\r
125 else{\r
126 chi2m+=9;\r
127 }\r
128 }\r
129 }else{\r
130 chi2m = 9*clayer;\r
131 }\r
132 vertex->SetChi2Before(TMath::Min(chi2p,chi2m));\r
133 if (TMath::Min(chi2p,chi2m)/Float_t(clayer)<4) vertex->SetStatus(-10); // track exist before vertex\r
134 }\r
135 \r
136 if (clayer < 5 ){ // calculate chi2 after vertex\r
137 Float_t chi2p = 0, chi2m=0; \r
138 //\r
767aaecb 139 if (trackp&&TMath::Abs(trackp->GetTgl())<kMinTgl2){\r
cd90f0a2 140 for (Int_t ilayer=clayer;ilayer<6;ilayer++){\r
141 if (trackp->GetClIndex(ilayer)>=0){\r
142 chi2p+=trackp->GetDy(ilayer)*trackp->GetDy(ilayer)/(trackp->GetSigmaY(ilayer)*trackp->GetSigmaY(ilayer))+\r
143 trackp->GetDz(ilayer)*trackp->GetDz(ilayer)/(trackp->GetSigmaZ(ilayer)*trackp->GetSigmaZ(ilayer));\r
144 }\r
145 else{\r
146 chi2p+=9;\r
147 }\r
148 }\r
149 }else{\r
150 chi2p = 0;\r
151 }\r
152 //\r
767aaecb 153 if (trackm&&TMath::Abs(trackm->GetTgl())<kMinTgl2){\r
cd90f0a2 154 for (Int_t ilayer=clayer;ilayer<6;ilayer++){\r
155 if (trackm->GetClIndex(ilayer)>=0){\r
156 chi2m+=trackm->GetDy(ilayer)*trackm->GetDy(ilayer)/(trackm->GetSigmaY(ilayer)*trackm->GetSigmaY(ilayer))+\r
157 trackm->GetDz(ilayer)*trackm->GetDz(ilayer)/(trackm->GetSigmaZ(ilayer)*trackm->GetSigmaZ(ilayer));\r
158 }\r
159 else{\r
160 chi2m+=9;\r
161 }\r
162 }\r
163 }else{\r
164 chi2m = 0;\r
165 }\r
166 vertex->SetChi2After(TMath::Max(chi2p,chi2m));\r
167 if (TMath::Max(chi2m,chi2p)/Float_t(6-clayer)>9) vertex->SetStatus(-20); // track not found in ITS\r
168 }\r
169 }\r
170 //\r
171}\r
172//------------------------------------------------------------------------\r
173void AliITSV0Finder::FindV02(AliESDEvent *event,\r
174 AliITStrackerMI *tracker) \r
175{\r
176 //\r
177 // V0 finder\r
178 //\r
179 // Cuts on DCA - R dependent\r
180 // max distance DCA between 2 tracks cut \r
181 // maxDist = TMath::Min(kMaxDist,kMaxDist0+pvertex->GetRr()*kMaxDist);\r
182 //\r
767aaecb 183 const Float_t kMaxDist0 = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxDist0();\r
184 const Float_t kMaxDist1 = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxDist1();\r
185 const Float_t kMaxDist = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxDist();\r
186 const Float_t kMinPointAngle = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinPointAngle();\r
187 const Float_t kMinPointAngle2 = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinPointAngle2();\r
188 const Float_t kMinR = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinR();\r
189 const Float_t kMaxR = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxR();\r
61673d36 190 const Float_t kMinPABestConst = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinPABestConst();\r
191 const Float_t kMaxRBestConst = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxRBestConst();\r
767aaecb 192 const Float_t kCausality0Cut = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetCausality0Cut();\r
193 const Float_t kLikelihood01Cut = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetLikelihood01Cut();\r
194 const Float_t kLikelihood1Cut = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetLikelihood1Cut();\r
195 const Float_t kCombinedCut = AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetCombinedCut();\r
b47f2a3f 196 const Float_t kMinClFullTrk= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinClFullTrk();\r
767aaecb 197 const Float_t kMinTgl0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinTgl0();\r
61673d36 198 const Float_t kMinRTgl0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinRTgl0();\r
199\r
200 const Float_t kMinNormDistForbTgl0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinNormDistForbTgl0();\r
201 const Float_t kMinClForb0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinClForb0();\r
202 const Float_t kMinNormDistForb1= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinNormDistForb1();\r
203 const Float_t kMinNormDistForb2= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinNormDistForb2();\r
204 const Float_t kMinNormDistForb3= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinNormDistForb3();\r
205 const Float_t kMinNormDistForb4= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinNormDistForb4();\r
206 const Float_t kMinNormDistForb5= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinNormDistForb5();\r
207\r
208 const Float_t kMinRTPCdensity= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinRTPCdensity();\r
209 const Float_t kMaxRTPCdensity0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxRTPCdensity0();\r
210 const Float_t kMaxRTPCdensity10= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxRTPCdensity10();\r
211 const Float_t kMaxRTPCdensity20= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxRTPCdensity20();\r
212 const Float_t kMaxRTPCdensity30= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxRTPCdensity30();\r
213\r
214\r
767aaecb 215 const Float_t kMinTPCdensity= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinTPCdensity();\r
216 const Float_t kMinTgl1= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinTgl1();\r
217\r
218 const Float_t kMinchi2before0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinchi2before0();\r
219 const Float_t kMinchi2before1= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinchi2before1();\r
220 const Float_t kMinchi2after0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinchi2after0();\r
221 const Float_t kMinchi2after1= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMinchi2after1();\r
222 const Float_t kAddchi2SharedCl= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetAddchi2SharedCl();\r
223 const Float_t kAddchi2NegCl0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetAddchi2NegCl0();\r
224 const Float_t kAddchi2NegCl1= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetAddchi2NegCl1();\r
225\r
226 const Float_t kSigp0Par0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetSigp0Par0();\r
227 const Float_t kSigp0Par1= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetSigp0Par1();\r
228 const Float_t kSigp0Par2= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetSigp0Par2();\r
229\r
230 const Float_t kSigpPar0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetSigpPar0();\r
231 const Float_t kSigpPar1= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetSigpPar1();\r
232 const Float_t kSigpPar2= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetSigpPar2();\r
61673d36 233 const Float_t kMaxDcaLh0= AliITSReconstructor::GetRecoParam()->GetESDV0Params()->GetMaxDcaLh0();\r
234\r
cd90f0a2 235\r
236 TObjArray *trackHypothesys = tracker->GetTrackHypothesys();\r
237 TObjArray *bestHypothesys = tracker->GetBestHypothesys();\r
238 TObjArray *originalTracks = tracker->GetOriginal();\r
239 //\r
240 //\r
241 TTreeSRedirector &cstream = *(tracker->GetDebugStreamer());\r
242 Int_t ntracks = event->GetNumberOfTracks(); \r
243 Int_t nitstracks = trackHypothesys->GetEntriesFast();\r
244 originalTracks->Expand(ntracks);\r
245 trackHypothesys->Expand(ntracks);\r
246 bestHypothesys->Expand(ntracks);\r
247 //\r
248 AliHelix * helixes = new AliHelix[ntracks+2];\r
249 TObjArray trackarray(ntracks+2); //array with tracks - with vertex constrain\r
250 TObjArray trackarrayc(ntracks+2); //array of "best tracks" - without vertex constrain\r
251 TObjArray trackarrayl(ntracks+2); //array of "longest tracks" - without vertex constrain\r
61673d36 252 //Change from Bool_t to Int_t for optimization\r
253 // Int_t forbN=0;\r
254 // Int_t * forbidden = new Int_t [ntracks+2];\r
cd90f0a2 255 Bool_t * forbidden = new Bool_t [ntracks+2];\r
256 Int_t *itsmap = new Int_t [ntracks+2];\r
257 Float_t *dist = new Float_t[ntracks+2];\r
258 Float_t *normdist0 = new Float_t[ntracks+2];\r
259 Float_t *normdist1 = new Float_t[ntracks+2];\r
260 Float_t *normdist = new Float_t[ntracks+2];\r
261 Float_t *norm = new Float_t[ntracks+2];\r
262 Float_t *maxr = new Float_t[ntracks+2];\r
263 Float_t *minr = new Float_t[ntracks+2];\r
264 Float_t *minPointAngle= new Float_t[ntracks+2];\r
265 //\r
266 AliV0 *pvertex = new AliV0;\r
267 AliITStrackMI * dummy= new AliITStrackMI;\r
268 dummy->SetLabel(0);\r
269 AliITStrackMI trackat0; //temporary track for DCA calculation\r
270 //\r
271 Float_t primvertex[3]={tracker->GetX(),tracker->GetY(),tracker->GetZ()};\r
272 //\r
273 // make ITS - ESD map\r
274 //\r
275 for (Int_t itrack=0;itrack<ntracks+2;itrack++) {\r
276 itsmap[itrack] = -1;\r
61673d36 277 // forbidden[itrack] = 0;\r
cd90f0a2 278 forbidden[itrack] = kFALSE;\r
279 maxr[itrack] = kMaxR;\r
280 minr[itrack] = kMinR;\r
281 minPointAngle[itrack] = kMinPointAngle;\r
282 }\r
283 for (Int_t itrack=0;itrack<nitstracks;itrack++){\r
284 AliITStrackMI * original = (AliITStrackMI*)(originalTracks->At(itrack));\r
285 Int_t esdindex = original->GetESDtrack()->GetID();\r
286 itsmap[esdindex] = itrack;\r
287 }\r
288 //\r
289 // create ITS tracks from ESD tracks if not done before\r
290 //\r
291 for (Int_t itrack=0;itrack<ntracks;itrack++){\r
292 if (itsmap[itrack]>=0) continue;\r
293 AliITStrackMI * tpctrack = new AliITStrackMI(*(event->GetTrack(itrack)));\r
294 //tpctrack->fD[0] = tpctrack->GetD(GetX(),GetY());\r
295 //tpctrack->fD[1] = tpctrack->GetZat(GetX())-GetZ(); \r
296 tpctrack->GetDZ(tracker->GetX(),tracker->GetY(),tracker->GetZ(),tpctrack->GetDP()); //I.B.\r
297 if (tpctrack->GetD(0)<20 && tpctrack->GetD(1)<20){\r
298 // tracks which can reach inner part of ITS\r
299 // propagate track to outer its volume - with correction for material\r
300 AliITStrackerMI::CorrectForTPCtoITSDeadZoneMaterial(tpctrack); \r
301 }\r
302 itsmap[itrack] = nitstracks;\r
303 originalTracks->AddAt(tpctrack,nitstracks);\r
304 nitstracks++;\r
305 }\r
306 //\r
307 // fill temporary arrays\r
308 //\r
309 for (Int_t itrack=0;itrack<ntracks;itrack++){\r
310 AliESDtrack * esdtrack = event->GetTrack(itrack);\r
311 Int_t itsindex = itsmap[itrack];\r
312 AliITStrackMI *original = (AliITStrackMI*)originalTracks->At(itsmap[itrack]);\r
313 if (!original) continue;\r
314 AliITStrackMI *bestConst = 0;\r
315 AliITStrackMI *bestLong = 0;\r
316 AliITStrackMI *best = 0; \r
317 //\r
318 //\r
319 TObjArray * array = (TObjArray*) trackHypothesys->At(itsindex);\r
320 Int_t hentries = (array==0) ? 0 : array->GetEntriesFast();\r
321 // Get best track with vertex constrain\r
322 for (Int_t ih=0;ih<hentries;ih++){\r
323 AliITStrackMI * trackh = (AliITStrackMI*)array->At(ih);\r
324 if (!trackh->GetConstrain()) continue;\r
325 if (!bestConst) bestConst = trackh;\r
61673d36 326 if (trackh->GetNumberOfClusters()>kMinClFullTrk ){\r
cd90f0a2 327 bestConst = trackh; // full track - with minimal chi2\r
328 break;\r
329 }\r
330 if (trackh->GetNumberOfClusters()+trackh->GetNDeadZone()<=bestConst->GetNumberOfClusters()+bestConst->GetNDeadZone()) continue; \r
331 bestConst = trackh;\r
332 break;\r
333 }\r
334 // Get best long track without vertex constrain and best track without vertex constrain\r
335 for (Int_t ih=0;ih<hentries;ih++){\r
336 AliITStrackMI * trackh = (AliITStrackMI*)array->At(ih);\r
337 if (trackh->GetConstrain()) continue;\r
338 if (!best) best = trackh;\r
339 if (!bestLong) bestLong = trackh;\r
b47f2a3f 340 if (trackh->GetNumberOfClusters()>kMinClFullTrk){\r
cd90f0a2 341 bestLong = trackh; // full track - with minimal chi2\r
342 break;\r
343 }\r
344 if (trackh->GetNumberOfClusters()+trackh->GetNDeadZone()<=bestLong->GetNumberOfClusters()+bestLong->GetNDeadZone()) continue; \r
345 bestLong = trackh; \r
346 }\r
347 if (!best) {\r
348 best = original;\r
349 bestLong = original;\r
350 }\r
351 //I.B. trackat0 = *bestLong;\r
352 new (&trackat0) AliITStrackMI(*bestLong);\r
353 Double_t xx,yy,zz,alpha; \r
354 if (!bestLong->GetGlobalXYZat(bestLong->GetX(),xx,yy,zz)) continue;\r
61673d36 355 \r
356\r
cd90f0a2 357 alpha = TMath::ATan2(yy,xx); \r
358 // if (!trackat0.Propagate(alpha,0)) continue; \r
359 trackat0.Propagate(alpha,0); //PH The check on the return value is temporarily disabled (bug 45751) \r
360 // calculate normalized distances to the vertex \r
361 //\r
362 Float_t ptfac = (1.+100.*TMath::Abs(trackat0.GetC()));\r
363 if ( bestLong->GetNumberOfClusters()>3 ){ \r
364 dist[itsindex] = trackat0.GetY();\r
365 norm[itsindex] = ptfac*TMath::Sqrt(trackat0.GetSigmaY2());\r
366 normdist0[itsindex] = TMath::Abs(trackat0.GetY()/norm[itsindex]);\r
367 normdist1[itsindex] = TMath::Abs((trackat0.GetZ()-primvertex[2])/(ptfac*TMath::Sqrt(trackat0.GetSigmaZ2())));\r
368 normdist[itsindex] = TMath::Sqrt(normdist0[itsindex]*normdist0[itsindex]+normdist1[itsindex]*normdist1[itsindex]);\r
369 if (!bestConst){\r
370 if (bestLong->GetNumberOfClusters()+bestLong->GetNDeadZone()<6) normdist[itsindex]*=2.;\r
371 if (bestLong->GetNumberOfClusters()+bestLong->GetNDeadZone()<5) normdist[itsindex]*=2.;\r
372 if (bestLong->GetNumberOfClusters()+bestLong->GetNDeadZone()<4) normdist[itsindex]*=2.;\r
373 }else{\r
374 if (bestConst->GetNumberOfClusters()+bestConst->GetNDeadZone()<6) normdist[itsindex]*=1.5;\r
375 if (bestConst->GetNumberOfClusters()+bestConst->GetNDeadZone()<5) normdist[itsindex]*=1.5;\r
376 }\r
377 }\r
378 else{ \r
379 if (bestConst&&bestConst->GetNumberOfClusters()+bestConst->GetNDeadZone()>4.5){\r
380 dist[itsindex] = bestConst->GetD(0);\r
381 norm[itsindex] = bestConst->GetDnorm(0);\r
382 normdist0[itsindex] = TMath::Abs(bestConst->GetD(0)/norm[itsindex]);\r
383 normdist1[itsindex] = TMath::Abs(bestConst->GetD(0)/norm[itsindex]);\r
384 normdist[itsindex] = TMath::Sqrt(normdist0[itsindex]*normdist0[itsindex]+normdist1[itsindex]*normdist1[itsindex]);\r
385 }else{\r
386 dist[itsindex] = trackat0.GetY();\r
387 norm[itsindex] = ptfac*TMath::Sqrt(trackat0.GetSigmaY2());\r
388 normdist0[itsindex] = TMath::Abs(trackat0.GetY()/norm[itsindex]);\r
389 normdist1[itsindex] = TMath::Abs((trackat0.GetZ()-primvertex[2])/(ptfac*TMath::Sqrt(trackat0.GetSigmaZ2())));\r
390 normdist[itsindex] = TMath::Sqrt(normdist0[itsindex]*normdist0[itsindex]+normdist1[itsindex]*normdist1[itsindex]);\r
767aaecb 391 if (TMath::Abs(trackat0.GetTgl())>kMinTgl0){\r
61673d36 392 if (normdist[itsindex]<kMinNormDistForbTgl0){\r
393 // forbN=1;\r
394 // forbidden[itsindex]+=1<<forbN;\r
395 forbidden[itsindex]=kTRUE;\r
396 }\r
397 if (normdist[itsindex]>kMinNormDistForbTgl0) {\r
398 minr[itsindex] = TMath::Max(kMinRTgl0,minr[itsindex]);\r
cd90f0a2 399 }\r
400 }\r
401 }\r
402 }\r
61673d36 403\r
404\r
cd90f0a2 405 //\r
406 //-----------------------------------------------------------\r
407 //Forbid primary track candidates - \r
408 //\r
409 //treetr->SetAlias("forbidden0","Tr0.fN<4&&Tr1.fN+Tr1.fNDeadZone>4.5");\r
410 //treetr->SetAlias("forbidden1","ND<3&&Tr1.fN+Tr1.fNDeadZone>5.5");\r
411 //treetr->SetAlias("forbidden2","ND<2&&Tr1.fClIndex[0]>0&&Tr1.fClIndex[0]>0");\r
412 //treetr->SetAlias("forbidden3","ND<1&&Tr1.fClIndex[0]>0");\r
413 //treetr->SetAlias("forbidden4","ND<4&&Tr1.fNormChi2[0]<2");\r
414 //treetr->SetAlias("forbidden5","ND<5&&Tr1.fNormChi2[0]<1");\r
415 //-----------------------------------------------------------\r
416 if (bestConst){\r
61673d36 417 if (bestLong->GetNumberOfClusters()<4 && bestConst->GetNumberOfClusters()+bestConst->GetNDeadZone()>kMinClForb0){\r
418 // forbN=2;\r
419 // forbidden[itsindex]+=1<<forbN;\r
420 forbidden[itsindex]=kTRUE;\r
421 }\r
422 if (normdist[itsindex]<kMinNormDistForb1 && bestConst->GetNumberOfClusters()+bestConst->GetNDeadZone()>5.5){\r
423 // forbN=3;\r
424 // forbidden[itsindex]+=1<<forbN;\r
425 forbidden[itsindex]=kTRUE;\r
426 }\r
427 if (normdist[itsindex]<kMinNormDistForb2 && bestConst->GetClIndex(0)>=0 && bestConst->GetClIndex(1)>=0 ){\r
428 // forbN=4;\r
429 // forbidden[itsindex]+=1<<forbN;\r
430 forbidden[itsindex]=kTRUE;\r
431 }\r
432 if (normdist[itsindex]<kMinNormDistForb3 && bestConst->GetClIndex(0)>=0){\r
433 // forbN=5;\r
434 // forbidden[itsindex]+=1<<forbN;\r
435 forbidden[itsindex]=kTRUE;\r
436 }\r
437 if (normdist[itsindex]<kMinNormDistForb4 && bestConst->GetNormChi2(0)<2){\r
438 // forbN=6;\r
439 // forbidden[itsindex]+=1<<forbN;\r
440 forbidden[itsindex]=kTRUE;\r
441 }\r
442 if (normdist[itsindex]<kMinNormDistForb5 && bestConst->GetNormChi2(0)<1){\r
443 // forbN=7;\r
444 // forbidden[itsindex]+=1<<forbN;\r
445 forbidden[itsindex]=kTRUE;\r
446 }\r
cd90f0a2 447 if (bestConst->GetNormChi2(0)<2.5) {\r
61673d36 448 minPointAngle[itsindex]= kMinPABestConst;\r
449 maxr[itsindex] = kMaxRBestConst;\r
cd90f0a2 450 }\r
451 }\r
452 //\r
453 //forbid daughter kink candidates\r
454 //\r
455 if (esdtrack->GetKinkIndex(0)>0) forbidden[itsindex] = kTRUE;\r
456 Bool_t isElectron = kTRUE;\r
457 Bool_t isProton = kTRUE;\r
458 Double_t pid[5];\r
459 esdtrack->GetESDpid(pid);\r
460 for (Int_t i=1;i<5;i++){\r
461 if (pid[0]<pid[i]) isElectron= kFALSE;\r
462 if (pid[4]<pid[i]) isProton= kFALSE;\r
463 }\r
464 if (isElectron){\r
465 forbidden[itsindex]=kFALSE; \r
466 normdist[itsindex]*=-1;\r
467 }\r
468 if (isProton){\r
469 if (normdist[itsindex]>2) forbidden[itsindex]=kFALSE; \r
470 normdist[itsindex]*=-1;\r
471 }\r
472\r
473 //\r
474 // Causality cuts in TPC volume\r
475 //\r
61673d36 476 if (esdtrack->GetTPCdensity(0,10) >kMinTPCdensity) maxr[itsindex] = TMath::Min(Float_t(kMaxRTPCdensity0),maxr[itsindex]);\r
477 if (esdtrack->GetTPCdensity(10,30)>kMinTPCdensity) maxr[itsindex] = TMath::Min(Float_t(kMaxRTPCdensity10),maxr[itsindex]);\r
478 if (esdtrack->GetTPCdensity(20,40)>kMinTPCdensity) maxr[itsindex] = TMath::Min(Float_t(kMaxRTPCdensity20),maxr[itsindex]);\r
479 if (esdtrack->GetTPCdensity(30,50)>kMinTPCdensity) maxr[itsindex] = TMath::Min(Float_t(kMaxRTPCdensity30),maxr[itsindex]);\r
cd90f0a2 480 //\r
61673d36 481 if (esdtrack->GetTPCdensity(0,60)<0.4&&bestLong->GetNumberOfClusters()<3) minr[itsindex]=kMinRTPCdensity; \r
cd90f0a2 482 //\r
483 //\r
61673d36 484\r
767aaecb 485 if (AliITSReconstructor::GetRecoParam()->GetESDV0Params()->StreamLevel()>0){\r
cd90f0a2 486 cstream<<"Track"<<\r
487 "Tr0.="<<best<<\r
488 "Tr1.="<<((bestConst)? bestConst:dummy)<<\r
489 "Tr2.="<<bestLong<<\r
490 "Tr3.="<<&trackat0<<\r
491 "Esd.="<<esdtrack<<\r
492 "Dist="<<dist[itsindex]<<\r
493 "ND0="<<normdist0[itsindex]<<\r
494 "ND1="<<normdist1[itsindex]<<\r
495 "ND="<<normdist[itsindex]<<\r
496 "Pz="<<primvertex[2]<<\r
497 "Forbid="<<forbidden[itsindex]<<\r
498 "\n";\r
499 //\r
500 }\r
501 trackarray.AddAt(best,itsindex);\r
502 trackarrayc.AddAt(bestConst,itsindex);\r
503 trackarrayl.AddAt(bestLong,itsindex);\r
504 new (&helixes[itsindex]) AliHelix(*best);\r
505 }\r
506 //\r
507 //\r
508 //\r
509 // first iterration of V0 finder\r
510 //\r
61673d36 511 // AM Comment out for optimization\r
512 // Int_t rejectBase=0;\r
513 // Int_t cutN=0;\r
767aaecb 514\r
cd90f0a2 515 for (Int_t iesd0=0;iesd0<ntracks;iesd0++){\r
516 Int_t itrack0 = itsmap[iesd0];\r
61673d36 517 //-AM comment for optimization and store the forbidden value in the debug streamer\r
cd90f0a2 518 if (forbidden[itrack0]) continue;\r
519 AliITStrackMI * btrack0 = (AliITStrackMI*)trackarray.At(itrack0);\r
520 if (!btrack0) continue; \r
cd90f0a2 521 AliITStrackMI *trackc0 = (AliITStrackMI*)trackarrayc.At(itrack0);\r
522 //\r
523 for (Int_t iesd1=iesd0+1;iesd1<ntracks;iesd1++){\r
524 Int_t itrack1 = itsmap[iesd1];\r
61673d36 525 //-AM comment for optimization and store the forbidden value in the debug streamer\r
cd90f0a2 526 if (forbidden[itrack1]) continue;\r
527\r
528 AliITStrackMI * btrack1 = (AliITStrackMI*)trackarray.At(itrack1); \r
529 if (!btrack1) continue;\r
61673d36 530\r
531 if ( (btrack0->GetSign()==btrack1->GetSign()) && !AliITSReconstructor::GetRecoParam()->GetStoreLikeSignV0s()) continue;\r
532\r
cd90f0a2 533 Bool_t isGold = kFALSE;\r
534 if (TMath::Abs(TMath::Abs(btrack0->GetLabel())-TMath::Abs(btrack1->GetLabel()))==1){\r
535 isGold = kTRUE;\r
536 }\r
61673d36 537 // rejectBase=0;\r
cd90f0a2 538 AliITStrackMI *trackc1 = (AliITStrackMI*)trackarrayc.At(itrack1);\r
539 AliHelix &h1 = helixes[itrack0];\r
540 AliHelix &h2 = helixes[itrack1];\r
541 //\r
542 // find linear distance\r
543 Double_t rmin =0;\r
544 //\r
545 //\r
546 //\r
547 Double_t phase[2][2],radius[2];\r
548 Int_t points = h1.GetRPHIintersections(h2, phase, radius);\r
61673d36 549 if (points==0) {\r
550 // cutN=1;\r
551 // rejectBase+=1<<cutN;\r
552 continue;\r
553 }\r
cd90f0a2 554 Double_t delta[2]={1000000,1000000}; \r
555 rmin = radius[0];\r
556 h1.ParabolicDCA(h2,phase[0][0],phase[0][1],radius[0],delta[0]);\r
557 if (points==2){ \r
558 if (radius[1]<rmin) rmin = radius[1];\r
559 h1.ParabolicDCA(h2,phase[1][0],phase[1][1],radius[1],delta[1]);\r
560 }\r
561 rmin = TMath::Sqrt(rmin);\r
562 Double_t distance = 0;\r
563 Double_t radiusC = 0;\r
564 Int_t iphase = 0;\r
565 if (points==1 || delta[0]<delta[1]){\r
566 distance = TMath::Sqrt(delta[0]);\r
567 radiusC = TMath::Sqrt(radius[0]);\r
568 }else{\r
569 distance = TMath::Sqrt(delta[1]);\r
570 radiusC = TMath::Sqrt(radius[1]);\r
571 iphase=1;\r
572 }\r
61673d36 573 if (radiusC<TMath::Max(minr[itrack0],minr[itrack1])){\r
574 // cutN=2;\r
575 //rejectBase+=1<<cutN;\r
576 continue;\r
577 }\r
578 if (radiusC>TMath::Min(maxr[itrack0],maxr[itrack1])){\r
579 // cutN=3;\r
580 // rejectBase+=1<<cutN;\r
581 continue;\r
582 } \r
cd90f0a2 583 Float_t maxDist = TMath::Min(kMaxDist,Float_t(kMaxDist0+radiusC*kMaxDist1)); \r
61673d36 584 if (distance>maxDist){\r
585 // cutN=4;\r
586 // rejectBase+=1<<cutN;\r
587 continue;\r
588 }\r
cd90f0a2 589 Float_t pointAngle = h1.GetPointAngle(h2,phase[iphase],primvertex);\r
61673d36 590 if (pointAngle<TMath::Max(minPointAngle[itrack0],minPointAngle[itrack1])) {\r
591 // cutN=5;\r
592 // rejectBase+=1<<cutN;\r
593 continue;\r
594 }\r
cd90f0a2 595 //\r
596 //\r
597 // Double_t distance = TestV0(h1,h2,pvertex,rmin);\r
598 //\r
599 // if (distance>maxDist) continue;\r
600 // if (pvertex->GetRr()<kMinR) continue;\r
601 // if (pvertex->GetRr()>kMaxR) continue;\r
602 AliITStrackMI * track0=btrack0;\r
603 AliITStrackMI * track1=btrack1;\r
604 // if (pvertex->GetRr()<3.5){ \r
605 if (radiusC<3.5){ \r
606 //use longest tracks inside the pipe\r
607 track0 = (AliITStrackMI*)trackarrayl.At(itrack0);\r
608 track1 = (AliITStrackMI*)trackarrayl.At(itrack1);\r
609 } \r
610 //\r
611 //\r
767aaecb 612 \r
613\r
614 \r
cd90f0a2 615 pvertex->SetParamN(*track0);\r
616 pvertex->SetParamP(*track1);\r
617 pvertex->Update(primvertex);\r
618 pvertex->SetClusters(track0->ClIndex(),track1->ClIndex()); // register clusters\r
619\r
61673d36 620 // Define gamma, K0, lambda and lambda_bar from the decay particles and calculate the chi2 \r
621 AliKFVertex vertexKF;\r
622\r
623 vertexKF.X() = tracker->GetX();\r
624 vertexKF.Y() = tracker->GetY();\r
625 vertexKF.Z() = tracker->GetZ();\r
626 vertexKF.Covariance(0,0) = tracker->GetSigmaX()*tracker->GetSigmaX();\r
627 vertexKF.Covariance(1,2) = tracker->GetSigmaY()*tracker->GetSigmaY();\r
628 vertexKF.Covariance(2,2) = tracker->GetSigmaZ()*tracker->GetSigmaZ();\r
629 \r
630 AliKFParticle elecKF( *(pvertex->GetParamN()) ,11);\r
631 AliKFParticle posiKF( *(pvertex->GetParamP()) ,-11);\r
632 AliKFParticle pipKF( *(pvertex->GetParamN()) , 211);\r
633 AliKFParticle pinKF( *(pvertex->GetParamP()) ,-211);\r
634 AliKFParticle protKF( *(pvertex->GetParamP()) ,2212);\r
635 AliKFParticle aproKF ( *(pvertex->GetParamN()) ,-2212);\r
636\r
637\r
638 // Gamma\r
639 AliKFParticle gamKF(elecKF,posiKF);\r
640 gamKF.SetProductionVertex(vertexKF);\r
641\r
642 Float_t gamKFchi2 = 1000;\r
643 if ( gamKF.GetNDF()!=0 ){\r
644 gamKFchi2 = gamKF.GetChi2()/gamKF.GetNDF();\r
645 }\r
646\r
647 Float_t massG=0.;\r
648 Float_t sigmaMG=0.001;\r
649 gamKF.SetMassConstraint(massG,sigmaMG);\r
650\r
651 Float_t gamKFchi2C = 1000;\r
652 if ( gamKF.GetNDF()!=0 ){\r
653 gamKFchi2C = gamKF.GetChi2()/gamKF.GetNDF();\r
654 }\r
655\r
656 //K0 short\r
657 AliKFParticle k0KF(pipKF,pinKF);\r
658 k0KF.SetProductionVertex(vertexKF);\r
659\r
660 Float_t k0KFchi2 = 1000;\r
661 if ( k0KF.GetNDF()!=0 ){\r
662 k0KFchi2 = k0KF.GetChi2()/k0KF.GetNDF();\r
663 }\r
664\r
665 //Lambda\r
666 AliKFParticle lambdaKF(protKF,pinKF);\r
667 lambdaKF.SetProductionVertex(vertexKF);\r
668\r
669 Float_t lambdaKFchi2 = 1000;\r
670 if ( lambdaKF.GetNDF()!=0 ){\r
671 lambdaKFchi2 = lambdaKF.GetChi2()/lambdaKF.GetNDF();\r
672 }\r
673\r
674 //Lambda_bar\r
675 AliKFParticle alambKF(aproKF,pipKF);\r
676 alambKF.SetProductionVertex(vertexKF);\r
677\r
678 Float_t alambKFchi2 = 1000;\r
679 if ( alambKF.GetNDF()!=0 ){\r
680 alambKFchi2 = alambKF.GetChi2()/alambKF.GetNDF();\r
681 }\r
767aaecb 682\r
767aaecb 683\r
684\r
61673d36 685\r
686\r
687 if (pvertex->GetRr()<kMinR){\r
688 // cutN=6;\r
689 // rejectBase+=1<<cutN;\r
690 continue;\r
691 }\r
692 if (pvertex->GetRr()>kMaxR){\r
693 // cutN=7;\r
694 // rejectBase+=1<<cutN;\r
695 continue;\r
696 }\r
697 if (pvertex->GetV0CosineOfPointingAngle()<kMinPointAngle){\r
698 // cutN=8;\r
699 // rejectBase+=1<<cutN;\r
700 continue;\r
701 }\r
cd90f0a2 702//Bo: if (pvertex->GetDist2()>maxDist) continue;\r
61673d36 703\r
704 if (pvertex->GetDcaV0Daughters()>maxDist){\r
705 // cutN=9;\r
706 // rejectBase+=1<<cutN;\r
707 continue;\r
708 }\r
cd90f0a2 709//Bo: pvertex->SetLab(0,track0->GetLabel());\r
710//Bo: pvertex->SetLab(1,track1->GetLabel());\r
711 pvertex->SetIndex(0,track0->GetESDtrack()->GetID());\r
712 pvertex->SetIndex(1,track1->GetESDtrack()->GetID());\r
713 // \r
714 AliITStrackMI * htrackc0 = trackc0 ? trackc0:dummy; \r
715 AliITStrackMI * htrackc1 = trackc1 ? trackc1:dummy;\r
716\r
717 //\r
718 //\r
719 TObjArray * array0b = (TObjArray*)bestHypothesys->At(itrack0);\r
767aaecb 720 if (!array0b&&pvertex->GetRr()<40 && TMath::Abs(track0->GetTgl())<kMinTgl1) {\r
cd90f0a2 721 tracker->SetCurrentEsdTrack(itrack0);\r
722 tracker->FollowProlongationTree((AliITStrackMI*)originalTracks->At(itrack0),itrack0, kFALSE);\r
723 }\r
724 TObjArray * array1b = (TObjArray*)bestHypothesys->At(itrack1);\r
767aaecb 725 if (!array1b&&pvertex->GetRr()<40 && TMath::Abs(track1->GetTgl())<kMinTgl1) { \r
cd90f0a2 726 tracker->SetCurrentEsdTrack(itrack1);\r
727 tracker->FollowProlongationTree((AliITStrackMI*)originalTracks->At(itrack1),itrack1, kFALSE);\r
728 }\r
729 //\r
730 AliITStrackMI * track0b = (AliITStrackMI*)originalTracks->At(itrack0);\r
731 AliITStrackMI * track1b = (AliITStrackMI*)originalTracks->At(itrack1);\r
732 AliITStrackMI * track0l = (AliITStrackMI*)originalTracks->At(itrack0);\r
733 AliITStrackMI * track1l = (AliITStrackMI*)originalTracks->At(itrack1);\r
734 \r
767aaecb 735 Float_t minchi2before0=kMinchi2before0;\r
736 Float_t minchi2before1=kMinchi2before1;\r
737 Float_t minchi2after0 =kMinchi2after0;\r
738 Float_t minchi2after1 =kMinchi2after1;\r
cd90f0a2 739 Double_t xrp[3]; pvertex->GetXYZ(xrp[0],xrp[1],xrp[2]); //I.B.\r
740 Int_t maxLayer = tracker->GetNearestLayer(xrp); //I.B.\r
741 \r
742 if (array0b) for (Int_t i=0;i<5;i++){\r
743 // best track after vertex\r
744 AliITStrackMI * btrack = (AliITStrackMI*)array0b->At(i);\r
745 if (!btrack) continue;\r
746 if (btrack->GetNumberOfClusters()>track0l->GetNumberOfClusters()) track0l = btrack; \r
747 // if (btrack->fX<pvertex->GetRr()-2.-0.5/(0.1+pvertex->GetAnglep()[2])) {\r
748 if (btrack->GetX()<pvertex->GetRr()-2.) {\r
749 if ( (maxLayer>i+2|| (i==0)) && btrack->GetNumberOfClusters()==(6-i)&&i<3){\r
750 Float_t sumchi2= 0;\r
751 Float_t sumn = 0;\r
752 if (maxLayer<3){ // take prim vertex as additional measurement\r
753 if (normdist[itrack0]>0 && htrackc0){\r
754 sumchi2 += TMath::Min((3.-maxLayer)*normdist[itrack0]*normdist[itrack0],16.);\r
755 }else{\r
756 sumchi2 += TMath::Min((3.-maxLayer)*(3*normdist[itrack0]*normdist[itrack0]+3.),16.);\r
757 }\r
758 sumn += 3-maxLayer;\r
759 }\r
760 for (Int_t ilayer=i;ilayer<maxLayer;ilayer++){\r
761 sumn+=1.; \r
762 if (btrack->GetClIndex(ilayer)<0){\r
767aaecb 763 sumchi2+=kAddchi2NegCl0;\r
cd90f0a2 764 continue;\r
765 }else{\r
766 Int_t c=( btrack->GetClIndex(ilayer) & 0x0fffffff);\r
767 for (Int_t itrack=0;itrack<4;itrack++){\r
768 AliITStrackerMI::AliITSlayer &layer=tracker->GetLayer(ilayer);\r
769 if (layer.GetClusterTracks(itrack,c)>=0 && layer.GetClusterTracks(itrack,c)!=itrack0){\r
767aaecb 770 sumchi2+=kAddchi2SharedCl; //shared cluster\r
cd90f0a2 771 break;\r
772 }\r
773 }\r
774 sumchi2+=btrack->GetDy(ilayer)*btrack->GetDy(ilayer)/(btrack->GetSigmaY(ilayer)*btrack->GetSigmaY(ilayer));\r
775 sumchi2+=btrack->GetDz(ilayer)*btrack->GetDz(ilayer)/(btrack->GetSigmaZ(ilayer)*btrack->GetSigmaZ(ilayer)); \r
776 }\r
777 }\r
778 sumchi2/=sumn;\r
779 if (sumchi2<minchi2before0) minchi2before0=sumchi2; \r
780 }\r
781 continue; //safety space - Geo manager will give exact layer\r
782 }\r
783 track0b = btrack;\r
784 minchi2after0 = btrack->GetNormChi2(i);\r
785 break;\r
786 }\r
787 if (array1b) for (Int_t i=0;i<5;i++){\r
788 // best track after vertex\r
789 AliITStrackMI * btrack = (AliITStrackMI*)array1b->At(i);\r
790 if (!btrack) continue;\r
791 if (btrack->GetNumberOfClusters()>track1l->GetNumberOfClusters()) track1l = btrack; \r
792 // if (btrack->fX<pvertex->GetRr()-2-0.5/(0.1+pvertex->GetAnglep()[2])){\r
793 if (btrack->GetX()<pvertex->GetRr()-2){\r
794 if ((maxLayer>i+2 || (i==0))&&btrack->GetNumberOfClusters()==(6-i)&&(i<3)){\r
795 Float_t sumchi2= 0;\r
796 Float_t sumn = 0;\r
797 if (maxLayer<3){ // take prim vertex as additional measurement\r
798 if (normdist[itrack1]>0 && htrackc1){\r
799 sumchi2 += TMath::Min((3.-maxLayer)*normdist[itrack1]*normdist[itrack1],16.);\r
800 }else{\r
801 sumchi2 += TMath::Min((3.-maxLayer)*(3*normdist[itrack1]*normdist[itrack1]+3.),16.);\r
802 }\r
803 sumn += 3-maxLayer;\r
804 }\r
805 for (Int_t ilayer=i;ilayer<maxLayer;ilayer++){\r
806 sumn+=1.;\r
807 if (btrack->GetClIndex(ilayer)<0){\r
767aaecb 808 sumchi2+=kAddchi2NegCl1;\r
cd90f0a2 809 continue;\r
810 }else{\r
811 Int_t c=( btrack->GetClIndex(ilayer) & 0x0fffffff);\r
812 for (Int_t itrack=0;itrack<4;itrack++){\r
813 AliITStrackerMI::AliITSlayer &layer=tracker->GetLayer(ilayer);\r
814 if (layer.GetClusterTracks(itrack,c)>=0 && layer.GetClusterTracks(itrack,c)!=itrack1){\r
767aaecb 815 sumchi2+=kAddchi2SharedCl; //shared cluster\r
cd90f0a2 816 break;\r
817 }\r
818 }\r
819 sumchi2+=btrack->GetDy(ilayer)*btrack->GetDy(ilayer)/(btrack->GetSigmaY(ilayer)*btrack->GetSigmaY(ilayer));\r
820 sumchi2+=btrack->GetDz(ilayer)*btrack->GetDz(ilayer)/(btrack->GetSigmaZ(ilayer)*btrack->GetSigmaZ(ilayer)); \r
821 }\r
822 }\r
823 sumchi2/=sumn;\r
824 if (sumchi2<minchi2before1) minchi2before1=sumchi2; \r
825 }\r
826 continue; //safety space - Geo manager will give exact layer \r
827 }\r
828 track1b = btrack;\r
829 minchi2after1 = btrack->GetNormChi2(i);\r
830 break;\r
831 }\r
832 //\r
833 // position resolution - used for DCA cut\r
834 Float_t sigmad = track0b->GetSigmaY2()+track0b->GetSigmaZ2()+track1b->GetSigmaY2()+track1b->GetSigmaZ2()+\r
835 (track0b->GetX()-pvertex->GetRr())*(track0b->GetX()-pvertex->GetRr())*(track0b->GetSigmaSnp2()+track0b->GetSigmaTgl2())+\r
836 (track1b->GetX()-pvertex->GetRr())*(track1b->GetX()-pvertex->GetRr())*(track1b->GetSigmaSnp2()+track1b->GetSigmaTgl2());\r
837 sigmad =TMath::Sqrt(sigmad)+0.04;\r
838 if (pvertex->GetRr()>50){\r
839 Double_t cov0[15],cov1[15];\r
840 track0b->GetESDtrack()->GetInnerExternalCovariance(cov0);\r
841 track1b->GetESDtrack()->GetInnerExternalCovariance(cov1);\r
842 sigmad = cov0[0]+cov0[2]+cov1[0]+cov1[2]+\r
843 (80.-pvertex->GetRr())*(80.-pvertex->GetRr())*(cov0[5]+cov0[9])+\r
844 (80.-pvertex->GetRr())*(80.-pvertex->GetRr())*(cov1[5]+cov1[9]);\r
845 sigmad =TMath::Sqrt(sigmad)+0.05;\r
846 }\r
847 // \r
848 AliV0 vertex2;\r
849 vertex2.SetParamN(*track0b);\r
850 vertex2.SetParamP(*track1b);\r
851 vertex2.Update(primvertex);\r
852 //Bo: if (vertex2.GetDist2()<=pvertex->GetDist2()&&(vertex2.GetV0CosineOfPointingAngle()>=pvertex->GetV0CosineOfPointingAngle())){\r
853 if (vertex2.GetDcaV0Daughters()<=pvertex->GetDcaV0Daughters()&&(vertex2.GetV0CosineOfPointingAngle()>=pvertex->GetV0CosineOfPointingAngle())){\r
854 pvertex->SetParamN(*track0b);\r
855 pvertex->SetParamP(*track1b);\r
856 pvertex->Update(primvertex);\r
857 pvertex->SetClusters(track0b->ClIndex(),track1b->ClIndex()); // register clusters\r
858 pvertex->SetIndex(0,track0->GetESDtrack()->GetID());\r
859 pvertex->SetIndex(1,track1->GetESDtrack()->GetID());\r
860 }\r
861 pvertex->SetDistSigma(sigmad);\r
862 //Bo: pvertex->SetDistNorm(pvertex->GetDist2()/sigmad); \r
863 pvertex->SetNormDCAPrim(normdist[itrack0],normdist[itrack1]);\r
864 //\r
865 // define likelihhod and causalities\r
866 //\r
867 Float_t pa0=1, pa1=1, pb0=0.26, pb1=0.26; \r
868 if (maxLayer<1){\r
869 Float_t fnorm0 = normdist[itrack0];\r
870 if (fnorm0<0) fnorm0*=-3;\r
871 Float_t fnorm1 = normdist[itrack1];\r
872 if (fnorm1<0) fnorm1*=-3;\r
873 if ((pvertex->GetAnglep()[2]>0.1) || ( (pvertex->GetRr()<10.5)&& pvertex->GetAnglep()[2]>0.05 ) || (pvertex->GetRr()<3)){\r
874 pb0 = TMath::Exp(-TMath::Min(fnorm0,Float_t(16.))/12.);\r
875 pb1 = TMath::Exp(-TMath::Min(fnorm1,Float_t(16.))/12.);\r
876 }\r
877 pvertex->SetChi2Before(normdist[itrack0]);\r
878 pvertex->SetChi2After(normdist[itrack1]); \r
879 pvertex->SetNAfter(0);\r
880 pvertex->SetNBefore(0);\r
881 }else{\r
882 pvertex->SetChi2Before(minchi2before0);\r
883 pvertex->SetChi2After(minchi2before1);\r
884 if (pvertex->GetAnglep()[2]>0.1 || ( pvertex->GetRr()<10.5 && pvertex->GetAnglep()[2]>0.05) || pvertex->GetRr()<3){\r
885 pb0 = TMath::Exp(-TMath::Min(minchi2before0,Float_t(16))/12.);\r
886 pb1 = TMath::Exp(-TMath::Min(minchi2before1,Float_t(16))/12.);\r
887 }\r
888 pvertex->SetNAfter(maxLayer);\r
889 pvertex->SetNBefore(maxLayer); \r
890 }\r
891 if (pvertex->GetRr()<90){\r
892 pa0 *= TMath::Min(track0->GetESDtrack()->GetTPCdensity(0,60),Double_t(1.));\r
893 pa1 *= TMath::Min(track1->GetESDtrack()->GetTPCdensity(0,60),Double_t(1.));\r
894 }\r
895 if (pvertex->GetRr()<20){\r
896 pa0 *= (0.2+TMath::Exp(-TMath::Min(minchi2after0,Float_t(16))/8.))/1.2;\r
897 pa1 *= (0.2+TMath::Exp(-TMath::Min(minchi2after1,Float_t(16))/8.))/1.2;\r
898 }\r
899 //\r
900 pvertex->SetCausality(pb0,pb1,pa0,pa1);\r
901 //\r
902 // Likelihood calculations - apply cuts\r
903 // \r
61673d36 904 \r
905 // AM - Comment out for optimization and store the v0OK value\r
906 // Int_t v0OK = 0;\r
907 // Int_t cutOKN=0;\r
cd90f0a2 908 Bool_t v0OK = kTRUE;\r
61673d36 909\r
910\r
cd90f0a2 911 Float_t p12 = pvertex->GetParamP()->GetParameter()[4]*pvertex->GetParamP()->GetParameter()[4];\r
912 p12 += pvertex->GetParamN()->GetParameter()[4]*pvertex->GetParamN()->GetParameter()[4];\r
913 p12 = TMath::Sqrt(p12); // "mean" momenta\r
767aaecb 914\r
915 Float_t sigmap0 = kSigp0Par0+kSigp0Par1/(kSigp0Par2+pvertex->GetRr()); \r
916 Float_t sigmap = kSigpPar0*sigmap0*(kSigpPar1+kSigpPar2*p12); // "resolution: of point angle - as a function of radius and momenta\r
917\r
cd90f0a2 918\r
919 Float_t causalityA = (1.0-pvertex->GetCausalityP()[0])*(1.0-pvertex->GetCausalityP()[1]);\r
920 Float_t causalityB = TMath::Sqrt(TMath::Min(pvertex->GetCausalityP()[2],Double_t(0.7))*\r
921 TMath::Min(pvertex->GetCausalityP()[3],Double_t(0.7)));\r
922 //\r
923 //Bo: Float_t likelihood0 = (TMath::Exp(-pvertex->GetDistNorm())+0.1) *(pvertex->GetDist2()<0.5)*(pvertex->GetDistNorm()<5);\r
924 Float_t lDistNorm = pvertex->GetDcaV0Daughters()/pvertex->GetDistSigma();\r
61673d36 925 Float_t likelihood0 = (TMath::Exp(-lDistNorm)+0.1) *(pvertex->GetDcaV0Daughters()<kMaxDcaLh0)*(lDistNorm<5);\r
cd90f0a2 926\r
927 Float_t likelihood1 = TMath::Exp(-(1.0001-pvertex->GetV0CosineOfPointingAngle())/sigmap)+\r
928 0.4*TMath::Exp(-(1.0001-pvertex->GetV0CosineOfPointingAngle())/(4.*sigmap))+\r
929 0.4*TMath::Exp(-(1.0001-pvertex->GetV0CosineOfPointingAngle())/(8.*sigmap))+\r
930 0.1*TMath::Exp(-(1.0001-pvertex->GetV0CosineOfPointingAngle())/0.01);\r
931 //\r
61673d36 932 if (causalityA<kCausality0Cut){\r
933 // cutOKN=1;\r
934 // v0OK += 1<<cutOKN;\r
935 v0OK = kFALSE;\r
936 }\r
937 if (TMath::Sqrt(likelihood0*likelihood1)<kLikelihood01Cut){\r
938 // cutOKN=2;\r
939 // v0OK += 1<<cutOKN;\r
940 v0OK = kFALSE;\r
941 }\r
942 if (likelihood1<kLikelihood1Cut){\r
943 // cutOKN=3;\r
944 // v0OK += 1<<cutOKN;\r
945 v0OK = kFALSE;\r
946 }\r
947 if (TMath::Power(likelihood0*likelihood1*causalityB,0.33)<kCombinedCut){\r
948 // cutOKN=4;\r
949 // v0OK += 1<<cutOKN;\r
950 v0OK = kFALSE;\r
951 }\r
cd90f0a2 952 //\r
953 //\r
767aaecb 954 if (AliITSReconstructor::GetRecoParam()->GetESDV0Params()->StreamLevel()>0){ \r
cd90f0a2 955 Bool_t gold = TMath::Abs(TMath::Abs(track0->GetLabel())-TMath::Abs(track1->GetLabel()))==1;\r
956 cstream<<"It0"<<\r
957 "Tr0.="<<track0<< //best without constrain\r
958 "Tr1.="<<track1<< //best without constrain \r
61673d36 959 "posiKF.="<<&posiKF<< //KF from track0\r
960 "elecKF.="<<&elecKF<< //KF from track1\r
cd90f0a2 961 "Tr0B.="<<track0b<< //best without constrain after vertex\r
962 "Tr1B.="<<track1b<< //best without constrain after vertex \r
963 "Tr0C.="<<htrackc0<< //best with constrain if exist\r
964 "Tr1C.="<<htrackc1<< //best with constrain if exist\r
965 "Tr0L.="<<track0l<< //longest best \r
966 "Tr1L.="<<track1l<< //longest best\r
967 "Esd0.="<<track0->GetESDtrack()<< // esd track0 params\r
968 "Esd1.="<<track1->GetESDtrack()<< // esd track1 params\r
969 "V0.="<<pvertex<< //vertex properties\r
970 "V0b.="<<&vertex2<< //vertex properties at "best" track\r
61673d36 971 "gamKF.="<<&gamKF<< //KF from pvertex\r
972 "k0KF.="<<&k0KF<< //KF from pvertex\r
973 "lambdaKF.="<<&lambdaKF<< //KF from pvertex\r
974 "alambKF.="<<&lambdaKF<< //KF from pvertex\r
975 "gamKFchi2="<<gamKFchi2<< //Normalized chi2 from KF assuming gamma momther\r
976 "gamKFchi2C="<<gamKFchi2C<< //Normalized chi2 from KF assuming gamma mother+mass constraint\r
977 "k0KFchi2="<<k0KFchi2<< //Normalized chi2 from KF assuming K0 mother\r
978 "lambdaKFchi2="<<lambdaKFchi2<< //Normalized chi2 from KF assuming Lambda mother\r
979 "alambKFchi2="<<alambKFchi2<< //Normalized chi2 from KF assuming lambda_bar mother\r
cd90f0a2 980 "ND0="<<normdist[itrack0]<< //normalize distance for track0\r
981 "ND1="<<normdist[itrack1]<< //normalize distance for track1\r
982 "Gold="<<gold<< //\r
61673d36 983 // "RejectBase="<<rejectBase<< //rejection in First itteration\r
cd90f0a2 984 "OK="<<v0OK<<\r
985 "rmin="<<rmin<<\r
986 "sigmad="<<sigmad<<\r
61673d36 987 "Forbid0="<<forbidden[itrack0]<<\r
988 "Forbid1="<<forbidden[itrack1]<<\r
cd90f0a2 989 "\n";\r
990 } \r
61673d36 991 // if (rejectBase>0) continue;\r
992 //if (forbidden[itrack0]>0 ||forbidden[itrack1]>0) continue; \r
cd90f0a2 993 //\r
994 pvertex->SetStatus(0);\r
995 // if (rejectBase) {\r
996 // pvertex->SetStatus(-100);\r
997 //}\r
998 if (pvertex->GetV0CosineOfPointingAngle()>kMinPointAngle2) {\r
999 //Bo: pvertex->SetESDindexes(track0->GetESDtrack()->GetID(),track1->GetESDtrack()->GetID());\r
1000 pvertex->SetIndex(0,track0->GetESDtrack()->GetID());//Bo: consistency 0 for neg\r
1001 pvertex->SetIndex(1,track1->GetESDtrack()->GetID());//Bo: consistency 1 for pos\r
61673d36 1002 // if (v0OK==0){\r
cd90f0a2 1003 if (v0OK){\r
1004 // AliV0vertex vertexjuri(*track0,*track1);\r
1005 // vertexjuri.SetESDindexes(track0->fESDtrack->GetID(),track1->fESDtrack->GetID());\r
1006 // event->AddV0(&vertexjuri);\r
1007 pvertex->SetStatus(100);\r
1008 }\r
1009 pvertex->SetOnFlyStatus(kTRUE);\r
1010 pvertex->ChangeMassHypothesis(kK0Short);\r
1011 event->AddV0(pvertex);\r
1012 }\r
1013 }\r
1014 }\r
1015 //\r
1016 //\r
1017 // delete temporary arrays\r
1018 // \r
1019 delete[] forbidden;\r
1020 delete[] minPointAngle;\r
1021 delete[] maxr;\r
1022 delete[] minr;\r
1023 delete[] norm;\r
1024 delete[] normdist;\r
1025 delete[] normdist1;\r
1026 delete[] normdist0;\r
1027 delete[] dist;\r
1028 delete[] itsmap;\r
1029 delete[] helixes;\r
1030 delete pvertex;\r
1031}\r
1032//------------------------------------------------------------------------\r
1033void AliITSV0Finder::RefitV02(const AliESDEvent *event,\r
1034 AliITStrackerMI *tracker) \r
1035{\r
1036 //\r
1037 //try to refit V0s in the third path of the reconstruction\r
1038 //\r
1039 TTreeSRedirector &cstream = *(tracker->GetDebugStreamer());\r
1040 //\r
1041 Int_t nv0s = event->GetNumberOfV0s();\r
1042 Float_t primvertex[3]={tracker->GetX(),tracker->GetY(),tracker->GetZ()};\r
1043 AliV0 v0temp;\r
1044 for (Int_t iv0 = 0; iv0<nv0s;iv0++){\r
1045 AliV0 * v0mi = (AliV0*)event->GetV0(iv0);\r
1046 if (!v0mi) continue;\r
1047 Int_t itrack0 = v0mi->GetIndex(0);\r
1048 Int_t itrack1 = v0mi->GetIndex(1);\r
1049 AliESDtrack *esd0 = event->GetTrack(itrack0);\r
1050 AliESDtrack *esd1 = event->GetTrack(itrack1);\r
1051 if (!esd0||!esd1) continue;\r
1052 AliITStrackMI tpc0(*esd0); \r
1053 AliITStrackMI tpc1(*esd1);\r
1054 Double_t x,y,z; v0mi->GetXYZ(x,y,z); //I.B. \r
1055 Double_t alpha =TMath::ATan2(y,x); //I.B.\r
1056 if (v0mi->GetRr()>85){\r
1057 if (tpc0.Propagate(alpha,v0mi->GetRr())&&tpc1.Propagate(alpha,v0mi->GetRr())){\r
1058 v0temp.SetParamN(tpc0);\r
1059 v0temp.SetParamP(tpc1);\r
1060 v0temp.Update(primvertex);\r
767aaecb 1061 if (AliITSReconstructor::GetRecoParam()->GetESDV0Params()->StreamLevel()>0) cstream<<"Refit"<<\r
cd90f0a2 1062 "V0.="<<v0mi<<\r
1063 "V0refit.="<<&v0temp<<\r
1064 "Tr0.="<<&tpc0<<\r
1065 "Tr1.="<<&tpc1<<\r
1066 "\n";\r
1067 //Bo: if (v0temp.GetDist2()<v0mi->GetDist2() || v0temp.GetV0CosineOfPointingAngle()>v0mi->GetV0CosineOfPointingAngle()){\r
1068 if (v0temp.GetDcaV0Daughters()<v0mi->GetDcaV0Daughters() || v0temp.GetV0CosineOfPointingAngle()>v0mi->GetV0CosineOfPointingAngle()){\r
1069 v0mi->SetParamN(tpc0);\r
1070 v0mi->SetParamP(tpc1);\r
1071 v0mi->Update(primvertex);\r
1072 }\r
1073 }\r
1074 continue;\r
1075 }\r
1076 if (v0mi->GetRr()>35){\r
1077 AliITStrackerMI::CorrectForTPCtoITSDeadZoneMaterial(&tpc0);\r
1078 AliITStrackerMI::CorrectForTPCtoITSDeadZoneMaterial(&tpc1);\r
1079 if (tpc0.Propagate(alpha,v0mi->GetRr())&&tpc1.Propagate(alpha,v0mi->GetRr())){\r
1080 v0temp.SetParamN(tpc0);\r
1081 v0temp.SetParamP(tpc1);\r
1082 v0temp.Update(primvertex);\r
767aaecb 1083 if (AliITSReconstructor::GetRecoParam()->GetESDV0Params()->StreamLevel()>0) cstream<<"Refit"<<\r
cd90f0a2 1084 "V0.="<<v0mi<<\r
1085 "V0refit.="<<&v0temp<<\r
1086 "Tr0.="<<&tpc0<<\r
1087 "Tr1.="<<&tpc1<<\r
1088 "\n";\r
1089 //Bo: if (v0temp.GetDist2()<v0mi->GetDist2() || v0temp.GetV0CosineOfPointingAngle()>v0mi->GetV0CosineOfPointingAngle()){\r
1090 if (v0temp.GetDcaV0Daughters()<v0mi->GetDcaV0Daughters() || v0temp.GetV0CosineOfPointingAngle()>v0mi->GetV0CosineOfPointingAngle()){\r
1091 v0mi->SetParamN(tpc0);\r
1092 v0mi->SetParamP(tpc1);\r
1093 v0mi->Update(primvertex);\r
1094 } \r
1095 }\r
1096 continue;\r
1097 }\r
1098 AliITStrackerMI::CorrectForTPCtoITSDeadZoneMaterial(&tpc0);\r
1099 AliITStrackerMI::CorrectForTPCtoITSDeadZoneMaterial(&tpc1); \r
1100 // if (tpc0.Propagate(alpha,v0mi->GetRr())&&tpc1.Propagate(alpha,v0mi->GetRr())){\r
1101 if (tracker->RefitAt(v0mi->GetRr(),&tpc0, v0mi->GetClusters(0)) && \r
1102 tracker->RefitAt(v0mi->GetRr(),&tpc1, v0mi->GetClusters(1))){\r
1103 v0temp.SetParamN(tpc0);\r
1104 v0temp.SetParamP(tpc1);\r
1105 v0temp.Update(primvertex);\r
767aaecb 1106 if (AliITSReconstructor::GetRecoParam()->GetESDV0Params()->StreamLevel()>0) cstream<<"Refit"<<\r
cd90f0a2 1107 "V0.="<<v0mi<<\r
1108 "V0refit.="<<&v0temp<<\r
1109 "Tr0.="<<&tpc0<<\r
1110 "Tr1.="<<&tpc1<<\r
1111 "\n";\r
1112 //Bo: if (v0temp.GetDist2()<v0mi->GetDist2() || v0temp.GetV0CosineOfPointingAngle()>v0mi->GetV0CosineOfPointingAngle()){\r
1113 if (v0temp.GetDcaV0Daughters()<v0mi->GetDcaV0Daughters() || v0temp.GetV0CosineOfPointingAngle()>v0mi->GetV0CosineOfPointingAngle()){\r
1114 v0mi->SetParamN(tpc0);\r
1115 v0mi->SetParamP(tpc1);\r
1116 v0mi->Update(primvertex);\r
1117 } \r
1118 } \r
1119 }\r
1120}\r
1121//------------------------------------------------------------------------\r
767aaecb 1122\r
1123\r
1124AliITSV0Finder::~AliITSV0Finder()\r
1125{\r
1126 //\r
1127 //destructor\r
1128 //\r
1129 if (fDebugStreamer) {\r
1130 //fDebugStreamer->Close();\r
1131 delete fDebugStreamer;\r
1132 }\r
1133\r
1134}\r