Bug fix for GetLatestEvent()
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAnalysisVertexingHF.cxx
CommitLineData
6a213b59 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16//----------------------------------------------------------------------------
17// Implementation of the heavy-flavour vertexing analysis class
dcb444c9 18// Candidates are stored in the AOD as objects deriving from AliAODRecoDecay.
19// To be used as a task of AliAnalysisManager by means of the interface
20// class AliAnalysisTaskSEVertexingHF.
21// An example of usage in the macro AliAnalysisTaskSEVertexingHFTest.C.
6a213b59 22//
23// Origin: E.Bruna, G.E.Bruno, A.Dainese, F.Prino, R.Romita
b056c5e3 24// Contact: andrea.dainese@lnl.infn.it
6a213b59 25//----------------------------------------------------------------------------
b82f6d67 26#include <TFile.h>
6a213b59 27#include <TDatabasePDG.h>
28#include <TString.h>
dcb444c9 29#include "AliLog.h"
30#include "AliVEvent.h"
31#include "AliVVertex.h"
32#include "AliVTrack.h"
6a213b59 33#include "AliVertexerTracks.h"
b82f6d67 34#include "AliKFParticle.h"
dcb444c9 35#include "AliESDEvent.h"
6a213b59 36#include "AliESDVertex.h"
dcb444c9 37#include "AliESDtrack.h"
b056c5e3 38#include "AliAODEvent.h"
6a213b59 39#include "AliAODRecoDecay.h"
40#include "AliAODRecoDecayHF.h"
41#include "AliAODRecoDecayHF2Prong.h"
42#include "AliAODRecoDecayHF3Prong.h"
43#include "AliAODRecoDecayHF4Prong.h"
44#include "AliAnalysisVertexingHF.h"
45
46ClassImp(AliAnalysisVertexingHF)
47
48//----------------------------------------------------------------------------
49AliAnalysisVertexingHF::AliAnalysisVertexingHF():
dcb444c9 50fInputAOD(kFALSE),
51fAODMap(0),
b82f6d67 52fBzkG(0.),
53fSecVtxWithKF(kFALSE),
6a213b59 54fRecoPrimVtxSkippingTrks(kFALSE),
55fRmTrksFromPrimVtx(kFALSE),
56fV1(0x0),
b82f6d67 57fD0toKpi(kTRUE),
58fJPSItoEle(kTRUE),
59f3Prong(kTRUE),
60f4Prong(kTRUE),
61fITSrefit(kFALSE),
62fBothSPD(kTRUE),
63fMinITSCls(5),
64fMinPtCut(0.),
65fMind0rphiCut(0.)
6a213b59 66{
67 // Default constructor
68
69 SetD0toKpiCuts();
70 SetBtoJPSICuts();
71 SetDplusCuts();
b82f6d67 72 SetDsCuts();
73 SetLcCuts();
6a213b59 74}
13977a79 75//--------------------------------------------------------------------------
76AliAnalysisVertexingHF::AliAnalysisVertexingHF(const AliAnalysisVertexingHF &source) :
77TNamed(source),
dcb444c9 78fInputAOD(source.fInputAOD),
79fAODMap(source.fAODMap),
b82f6d67 80fBzkG(source.fBzkG),
81fSecVtxWithKF(source.fSecVtxWithKF),
13977a79 82fRecoPrimVtxSkippingTrks(source.fRecoPrimVtxSkippingTrks),
83fRmTrksFromPrimVtx(source.fRmTrksFromPrimVtx),
84fV1(source.fV1),
13977a79 85fD0toKpi(source.fD0toKpi),
86fJPSItoEle(source.fJPSItoEle),
87f3Prong(source.f3Prong),
88f4Prong(source.f4Prong),
89fITSrefit(source.fITSrefit),
90fBothSPD(source.fBothSPD),
91fMinITSCls(source.fMinITSCls),
92fMinPtCut(source.fMinPtCut),
93fMind0rphiCut(source.fMind0rphiCut)
94{
95 //
96 // Copy constructor
97 //
98 for(Int_t i=0; i<9; i++) fD0toKpiCuts[i]=source.fD0toKpiCuts[i];
99 for(Int_t i=0; i<9; i++) fBtoJPSICuts[i]=source.fBtoJPSICuts[i];
100 for(Int_t i=0; i<12; i++) fDplusCuts[i]=source.fDplusCuts[i];
81679460 101 for(Int_t i=0; i<13; i++) fDsCuts[i]=source.fDsCuts[i];
6ea608bf 102 for(Int_t i=0; i<12; i++) fLcCuts[i]=source.fLcCuts[i];
13977a79 103}
104//--------------------------------------------------------------------------
105AliAnalysisVertexingHF &AliAnalysisVertexingHF::operator=(const AliAnalysisVertexingHF &source)
106{
107 //
108 // assignment operator
109 //
110 if(&source == this) return *this;
dcb444c9 111 fInputAOD = source.fInputAOD;
b82f6d67 112 fBzkG = source.fBzkG;
113 fSecVtxWithKF = source.fSecVtxWithKF;
13977a79 114 fRecoPrimVtxSkippingTrks = source.fRecoPrimVtxSkippingTrks;
115 fRmTrksFromPrimVtx = source.fRmTrksFromPrimVtx;
116 fV1 = source.fV1;
13977a79 117 fD0toKpi = source.fD0toKpi;
118 fJPSItoEle = source.fJPSItoEle;
119 f3Prong = source.f3Prong;
120 f4Prong = source.f4Prong;
121 fITSrefit = source.fITSrefit;
122 fBothSPD = source.fBothSPD;
123 fMinITSCls = source.fMinITSCls;
124 fMinPtCut = source.fMinPtCut;
125 fMind0rphiCut = source.fMind0rphiCut;
126
127 for(Int_t i=0; i<9; i++) fD0toKpiCuts[i]=source.fD0toKpiCuts[i];
128 for(Int_t i=0; i<9; i++) fBtoJPSICuts[i]=source.fBtoJPSICuts[i];
129 for(Int_t i=0; i<12; i++) fDplusCuts[i]=source.fDplusCuts[i];
81679460 130 for(Int_t i=0; i<13; i++) fDsCuts[i]=source.fDsCuts[i];
6ea608bf 131 for(Int_t i=0; i<12; i++) fLcCuts[i]=source.fLcCuts[i];
13977a79 132
133 return *this;
134}
6a213b59 135//----------------------------------------------------------------------------
136AliAnalysisVertexingHF::~AliAnalysisVertexingHF() {
137 // Destructor
13977a79 138 if(fV1) { delete fV1; fV1=0; }
6a213b59 139}
140//----------------------------------------------------------------------------
dcb444c9 141void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
142 TClonesArray *aodVerticesHFTClArr,
143 TClonesArray *aodD0toKpiTClArr,
144 TClonesArray *aodJPSItoEleTClArr,
145 TClonesArray *aodCharm3ProngTClArr,
146 TClonesArray *aodCharm4ProngTClArr)
b056c5e3 147{
148 // Find heavy-flavour vertex candidates
dcb444c9 149 // Input: ESD or AOD
b056c5e3 150 // Output: AOD (additional branches added)
151
dcb444c9 152
153 TString evtype = event->IsA()->GetName();
154 fInputAOD = ((evtype=="AliAODEvent") ? kTRUE : kFALSE);
155
b056c5e3 156 if(!aodVerticesHFTClArr) {
157 printf("ERROR: no aodVerticesHFTClArr");
158 return;
159 }
160 if(fD0toKpi && !aodD0toKpiTClArr) {
161 printf("ERROR: no aodD0toKpiTClArr");
162 return;
163 }
164 if(fJPSItoEle && !aodJPSItoEleTClArr) {
165 printf("ERROR: no aodJPSItoEleTClArr");
166 return;
167 }
168 if(f3Prong && !aodCharm3ProngTClArr) {
169 printf("ERROR: no aodCharm3ProngTClArr");
170 return;
171 }
172 if(f4Prong && !aodCharm4ProngTClArr) {
173 printf("ERROR: no aodCharm4ProngTClArr");
174 return;
175 }
176
177 // delete candidates from previous event and create references
178 Int_t iVerticesHF=0,iD0toKpi=0,iJPSItoEle=0,i3Prong=0,i4Prong=0;
179 aodVerticesHFTClArr->Delete();
180 iVerticesHF = aodVerticesHFTClArr->GetEntriesFast();
181 TClonesArray &verticesHFRef = *aodVerticesHFTClArr;
182 if(fD0toKpi) {
183 aodD0toKpiTClArr->Delete();
184 iD0toKpi = aodD0toKpiTClArr->GetEntriesFast();
185 }
186 if(fJPSItoEle) {
187 aodJPSItoEleTClArr->Delete();
188 iJPSItoEle = aodJPSItoEleTClArr->GetEntriesFast();
189 }
190 if(f3Prong) {
191 aodCharm3ProngTClArr->Delete();
192 i3Prong = aodCharm3ProngTClArr->GetEntriesFast();
193 }
194 if(f4Prong) {
195 aodCharm4ProngTClArr->Delete();
196 i4Prong = aodCharm4ProngTClArr->GetEntriesFast();
197 }
198 TClonesArray &aodD0toKpiRef = *aodD0toKpiTClArr;
199 TClonesArray &aodJPSItoEleRef = *aodJPSItoEleTClArr;
200 TClonesArray &aodCharm3ProngRef = *aodCharm3ProngTClArr;
201 TClonesArray &aodCharm4ProngRef = *aodCharm4ProngTClArr;
202
203
204 AliAODRecoDecayHF2Prong *io2Prong = 0;
205 AliAODRecoDecayHF3Prong *io3Prong = 0;
206 AliAODRecoDecayHF4Prong *io4Prong = 0;
207
208 Int_t iTrkP1,iTrkP2,iTrkN1,iTrkN2,trkEntries;
209 Int_t nTrksP=0,nTrksN=0;
210 Double_t xdummy,ydummy,dcap1n1,dcap1n2,dcap2n1,dcap1p2,dcan1n2;
211 Bool_t okD0=kFALSE,okJPSI=kFALSE,ok3Prong=kFALSE,ok4Prong=kFALSE;
212 AliESDtrack *postrack1 = 0;
213 AliESDtrack *postrack2 = 0;
214 AliESDtrack *negtrack1 = 0;
215 AliESDtrack *negtrack2 = 0;
216 Double_t dcaMax = fD0toKpiCuts[1];
217 if(dcaMax < fBtoJPSICuts[1]) dcaMax=fBtoJPSICuts[1];
218 if(dcaMax < fDplusCuts[11]) dcaMax=fDplusCuts[11];
dcb444c9 219 AliDebug(2,Form(" dca cut set to %f cm",dcaMax));
b056c5e3 220
b056c5e3 221
dcb444c9 222 // get Bz
223 fBzkG = (Double_t)event->GetMagneticField();
b056c5e3 224
dcb444c9 225 trkEntries = (Int_t)event->GetNumberOfTracks();
226 AliDebug(1,Form(" Number of tracks: %d",trkEntries));
357cd934 227
228 if(trkEntries<2) {
229 AliDebug(1,Form(" Not enough tracks: %d",trkEntries));
230 return;
231 }
b056c5e3 232
357cd934 233 const AliVVertex *primary = event->GetPrimaryVertex();
234 if(!primary) {
235 AliDebug(1," No primary vertex from tracks");
236 return;
237 }
238 TString primTitle = primary->GetTitle();
239 if(!primTitle.Contains("VertexerTracks")) {
240 AliDebug(1," No primary vertex from tracks");
b056c5e3 241 return;
242 }
243
dcb444c9 244 // call function that applies sigle-track selection,
245 // separates positives and negatives,
246 // and retrieves primary vertex
b056c5e3 247 TObjArray trksP(trkEntries/2);
248 TObjArray trksN(trkEntries/2);
dcb444c9 249 SelectTracksAndCopyVertex(event,trksP,nTrksP,trksN,nTrksN);
b056c5e3 250
dcb444c9 251 AliDebug(1,Form(" Pos. tracks: %d Neg. tracks: %d",nTrksP,nTrksN));
b056c5e3 252
253 TObjArray *twoTrackArray1 = new TObjArray(2);
254 TObjArray *twoTrackArray2 = new TObjArray(2);
255 TObjArray *threeTrackArray = new TObjArray(3);
256 TObjArray *fourTrackArray = new TObjArray(4);
257
dcb444c9 258 Double_t dispersion;
259
b056c5e3 260 // LOOP ON POSITIVE TRACKS
261 for(iTrkP1=0; iTrkP1<nTrksP; iTrkP1++) {
dcb444c9 262 if(iTrkP1%1==0) AliDebug(1,Form(" Processing positive track number %d of %d",iTrkP1,nTrksP));
b056c5e3 263 // get track from tracks array
264 postrack1 = (AliESDtrack*)trksP.UncheckedAt(iTrkP1);
265
266 // LOOP ON NEGATIVE TRACKS
267 for(iTrkN1=0; iTrkN1<nTrksN; iTrkN1++) {
dcb444c9 268 if(iTrkN1%1==0) AliDebug(1,Form(" Processing negative track number %d of %d",iTrkN1,nTrksN));
b056c5e3 269 // get track from tracks array
270 negtrack1 = (AliESDtrack*)trksN.UncheckedAt(iTrkN1);
dcb444c9 271 // back to primary vertex
272 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
273 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
b056c5e3 274 // DCA between the two tracks
275 dcap1n1 = postrack1->GetDCA(negtrack1,fBzkG,xdummy,ydummy);
276 if(dcap1n1>dcaMax) { negtrack1=0; continue; }
277 // Vertexing
278 twoTrackArray1->AddAt(postrack1,0);
279 twoTrackArray1->AddAt(negtrack1,1);
dcb444c9 280 AliAODVertex *vertexp1n1 = ReconstructSecondaryVertex(twoTrackArray1,dispersion);
b056c5e3 281 if(!vertexp1n1) {
282 twoTrackArray1->Clear();
283 negtrack1=0;
284 continue;
285 }
286 if(fD0toKpi || fJPSItoEle) {
dcb444c9 287 io2Prong = Make2Prong(twoTrackArray1,event,vertexp1n1,dcap1n1,okD0,okJPSI);
b056c5e3 288 if(okD0 || okJPSI) {
dcb444c9 289 AliAODVertex *v = new(verticesHFRef[iVerticesHF++])AliAODVertex(*vertexp1n1);
290 if(fInputAOD) AddDaughterRefs(v,event,twoTrackArray1);
291 if(okD0) {
292 AliAODRecoDecayHF2Prong *rd = new(aodD0toKpiRef[iD0toKpi++])AliAODRecoDecayHF2Prong(*io2Prong);
293 rd->SetSecondaryVtx(v);
294 v->SetParent(rd);
295 }
296 if(okJPSI) {
297 AliAODRecoDecayHF2Prong *rd = new(aodJPSItoEleRef[iJPSItoEle++])AliAODRecoDecayHF2Prong(*io2Prong);
298 rd->SetSecondaryVtx(v);
299 if(!okD0) v->SetParent(rd); // do something better here...
b056c5e3 300 }
301 }
b056c5e3 302 io2Prong=NULL;
303 }
304
305 twoTrackArray1->Clear();
306 if(!f3Prong && !f4Prong) {
307 negtrack1=0;
308 delete vertexp1n1;
309 continue;
310 }
311
312
313 // 2nd LOOP ON POSITIVE TRACKS
314 for(iTrkP2=iTrkP1+1; iTrkP2<nTrksP; iTrkP2++) {
315 // get track from tracks array
316 postrack2 = (AliESDtrack*)trksP.UncheckedAt(iTrkP2);
dcb444c9 317 // back to primary vertex
318 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
319 postrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
320 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
b056c5e3 321 dcap2n1 = postrack2->GetDCA(negtrack1,fBzkG,xdummy,ydummy);
322 if(dcap2n1>dcaMax) { postrack2=0; continue; }
323 dcap1p2 = postrack2->GetDCA(postrack1,fBzkG,xdummy,ydummy);
324 if(dcap1p2>dcaMax) { postrack2=0; continue; }
325
326 // Vertexing
327 twoTrackArray2->AddAt(postrack2,0);
328 twoTrackArray2->AddAt(negtrack1,1);
dcb444c9 329 AliAODVertex *vertexp2n1 = ReconstructSecondaryVertex(twoTrackArray2,dispersion);
b056c5e3 330 if(!vertexp2n1) {
331 twoTrackArray2->Clear();
332 postrack2=0;
333 continue;
334 }
335 if(f3Prong) {
336 threeTrackArray->AddAt(postrack1,0);
337 threeTrackArray->AddAt(negtrack1,1);
338 threeTrackArray->AddAt(postrack2,2);
dcb444c9 339 AliAODVertex* secVert3PrAOD = ReconstructSecondaryVertex(threeTrackArray,dispersion);
340 io3Prong = Make3Prong(threeTrackArray,event,secVert3PrAOD,dispersion,vertexp1n1,vertexp2n1,dcap1n1,dcap2n1,dcap1p2,ok3Prong);
b056c5e3 341 if(ok3Prong) {
dcb444c9 342 AliAODVertex *v = new(verticesHFRef[iVerticesHF++])AliAODVertex(*secVert3PrAOD);
343 if(fInputAOD) AddDaughterRefs(v,event,threeTrackArray);
344 AliAODRecoDecayHF3Prong *rd = new(aodCharm3ProngRef[i3Prong++])AliAODRecoDecayHF3Prong(*io3Prong);
345 rd->SetSecondaryVtx(v);
346 v->SetParent(rd);
b056c5e3 347 }
dcb444c9 348 if(io3Prong) io3Prong=NULL;
b056c5e3 349 }
350 if(f4Prong) {
351 // 3rd LOOP ON NEGATIVE TRACKS (for 4 prong)
352 for(iTrkN2=iTrkN1+1; iTrkN2<nTrksN; iTrkN2++) {
353 // get track from tracks array
354 negtrack2 = (AliESDtrack*)trksN.UncheckedAt(iTrkN2);
dcb444c9 355 // back to primary vertex
356 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
357 postrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
358 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
359 negtrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
b056c5e3 360 dcap1n2 = postrack1->GetDCA(negtrack2,fBzkG,xdummy,ydummy);
361 if(dcap1n2>dcaMax) { negtrack2=0; continue; }
362 // Vertexing
363 fourTrackArray->AddAt(postrack1,0);
364 fourTrackArray->AddAt(negtrack1,1);
365 fourTrackArray->AddAt(postrack2,2);
366 fourTrackArray->AddAt(negtrack2,3);
dcb444c9 367 AliAODVertex* secVert4PrAOD = ReconstructSecondaryVertex(fourTrackArray,dispersion);
368 io4Prong = Make4Prong(fourTrackArray,event,secVert4PrAOD,vertexp1n1,vertexp2n1,dcap1n1,dcap1n2,dcap2n1,ok4Prong);
b056c5e3 369 if(ok4Prong) {
dcb444c9 370 AliAODVertex *v = new(verticesHFRef[iVerticesHF++])AliAODVertex(*secVert4PrAOD);
371 if(fInputAOD) AddDaughterRefs(v,event,fourTrackArray);
372 AliAODRecoDecayHF4Prong *rd = new(aodCharm4ProngRef[i4Prong++])AliAODRecoDecayHF4Prong(*io4Prong);
373 rd->SetSecondaryVtx(v);
374 v->SetParent(rd);
b056c5e3 375 }
dcb444c9 376 if(io4Prong) io4Prong=NULL;
b056c5e3 377 fourTrackArray->Clear();
378 negtrack2 = 0;
379 } // end loop on negative tracks
380 }
381 postrack2 = 0;
382 delete vertexp2n1;
383 } // end 2nd loop on positive tracks
384 twoTrackArray2->Clear();
385
386 // 2nd LOOP ON NEGATIVE TRACKS
387 for(iTrkN2=iTrkN1+1; iTrkN2<nTrksN; iTrkN2++) {
388 // get track from tracks array
389 negtrack2 = (AliESDtrack*)trksN.UncheckedAt(iTrkN2);
dcb444c9 390 // back to primary vertex
391 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
392 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
393 negtrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
b056c5e3 394 dcap1n2 = postrack1->GetDCA(negtrack2,fBzkG,xdummy,ydummy);
395 if(dcap1n2>dcaMax) { negtrack2=0; continue; }
396 dcan1n2 = negtrack1->GetDCA(negtrack2,fBzkG,xdummy,ydummy);
397 if(dcan1n2>dcaMax) { negtrack2=0; continue; }
398
399 // Vertexing
400 twoTrackArray2->AddAt(postrack1,0);
401 twoTrackArray2->AddAt(negtrack2,1);
dcb444c9 402
403 AliAODVertex *vertexp1n2 = ReconstructSecondaryVertex(twoTrackArray2,dispersion);
b056c5e3 404 if(!vertexp1n2) {
405 twoTrackArray2->Clear();
406 negtrack2=0;
407 continue;
408 }
409 if(f3Prong) {
410 threeTrackArray->AddAt(negtrack1,0);
411 threeTrackArray->AddAt(postrack1,1);
412 threeTrackArray->AddAt(negtrack2,2);
dcb444c9 413 AliAODVertex* secVert3PrAOD = ReconstructSecondaryVertex(threeTrackArray,dispersion);
414 io3Prong = Make3Prong(threeTrackArray,event,secVert3PrAOD,dispersion,vertexp1n1,vertexp1n2,dcap1n1,dcap1n2,dcan1n2,ok3Prong);
b056c5e3 415 if(ok3Prong) {
dcb444c9 416 AliAODVertex *v = new(verticesHFRef[iVerticesHF++])AliAODVertex(*secVert3PrAOD);
417 if(fInputAOD) AddDaughterRefs(v,event,threeTrackArray);
418 AliAODRecoDecayHF3Prong *rd = new(aodCharm3ProngRef[i3Prong++])AliAODRecoDecayHF3Prong(*io3Prong);
419 rd->SetSecondaryVtx(v);
420 v->SetParent(rd);
b056c5e3 421 }
dcb444c9 422 if(io3Prong) io3Prong=NULL;
b056c5e3 423 }
424 negtrack2 = 0;
425 delete vertexp1n2;
426 } // end 2nd loop on negative tracks
427 twoTrackArray2->Clear();
428
429 negtrack1 = 0;
430 delete vertexp1n1;
431 } // end 1st loop on negative tracks
432
433 postrack1 = 0;
434 } // end 1st loop on positive tracks
435
436
437 if(fD0toKpi) {
dcb444c9 438 AliDebug(1,Form(" D0->Kpi in event = %d;",
439 (Int_t)aodD0toKpiTClArr->GetEntriesFast()));
b056c5e3 440 }
441 if(fJPSItoEle) {
dcb444c9 442 AliDebug(1,Form(" JPSI->ee in event = %d;",
443 (Int_t)aodJPSItoEleTClArr->GetEntriesFast()));
b056c5e3 444 }
445 if(f3Prong) {
dcb444c9 446 AliDebug(1,Form(" Charm->3Prong in event = %d;",
447 (Int_t)aodCharm3ProngTClArr->GetEntriesFast()));
b056c5e3 448 }
449 if(f4Prong) {
dcb444c9 450 AliDebug(1,Form(" Charm->4Prong in event = %d;\n",
451 (Int_t)aodCharm4ProngTClArr->GetEntriesFast()));
b056c5e3 452 }
453
454
dcb444c9 455 twoTrackArray1->Delete(); delete twoTrackArray1;
456 twoTrackArray2->Delete(); delete twoTrackArray2;
b056c5e3 457 threeTrackArray->Clear();
458 threeTrackArray->Delete(); delete threeTrackArray;
dcb444c9 459 fourTrackArray->Delete(); delete fourTrackArray;
b056c5e3 460
dcb444c9 461 if(fInputAOD) {
462 trksP.Delete();
463 trksN.Delete();
464 }
b056c5e3 465
466 return;
467}
468//----------------------------------------------------------------------------
dcb444c9 469void AliAnalysisVertexingHF::AddDaughterRefs(AliAODVertex *v,AliVEvent *event,
470 TObjArray *trkArray) const
6a213b59 471{
dcb444c9 472 // Add the AOD tracks as daughters of the vertex (TRef)
6a213b59 473
dcb444c9 474 Int_t nTrks = trkArray->GetEntriesFast();
6a213b59 475
dcb444c9 476 AliESDtrack *esdTrack = 0;
477 AliAODTrack *aodTrack = 0;
478 Int_t id;
6a213b59 479
dcb444c9 480 for(Int_t i=0; i<nTrks; i++) {
481 esdTrack = (AliESDtrack*)trkArray->UncheckedAt(i);
482 id = (Int_t)esdTrack->GetID();
483 aodTrack = (AliAODTrack*)event->GetTrack(fAODMap[id]);
484 v->AddDaughter(aodTrack);
6a213b59 485 }
6a213b59 486
487 return;
dcb444c9 488}
6a213b59 489//----------------------------------------------------------------------------
490AliAODRecoDecayHF2Prong *AliAnalysisVertexingHF::Make2Prong(
dcb444c9 491 TObjArray *twoTrackArray1,AliVEvent *event,
492 AliAODVertex *secVert,Double_t dca,
6a213b59 493 Bool_t &okD0,Bool_t &okJPSI) const
494{
495 // Make 2Prong candidates and check if they pass D0toKpi or BtoJPSI
496 // reconstruction cuts
497 // G.E.Bruno (J/psi), A.Dainese (D0->Kpi)
498
499 okD0=kFALSE; okJPSI=kFALSE;
500
501 Double_t px[2],py[2],pz[2],d0[2],d0err[2];
6a213b59 502
503 AliESDtrack *postrack = (AliESDtrack*)twoTrackArray1->UncheckedAt(0);
504 AliESDtrack *negtrack = (AliESDtrack*)twoTrackArray1->UncheckedAt(1);
505
506 // propagate tracks to secondary vertex, to compute inv. mass
dcb444c9 507 postrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
508 negtrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
6a213b59 509
510 Double_t momentum[3];
511 postrack->GetPxPyPz(momentum);
512 px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
513 negtrack->GetPxPyPz(momentum);
514 px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
515
516
517 // invariant mass cut (try to improve coding here..)
518 Bool_t okMassCut=kFALSE;
dcb444c9 519 if(!okMassCut && fD0toKpi) if(SelectInvMass(0,2,px,py,pz)) okMassCut=kTRUE;
6a213b59 520 if(!okMassCut && fJPSItoEle) if(SelectInvMass(1,2,px,py,pz)) okMassCut=kTRUE;
521 if(!okMassCut) {
dcb444c9 522 AliDebug(2," candidate didn't pass mass cut");
6a213b59 523 return 0x0;
524 }
525
dcb444c9 526 // primary vertex to be used by this candidate
527 AliAODVertex *primVertexAOD = OwnPrimaryVertex(twoTrackArray1,event);
528 if(!primVertexAOD) return 0x0;
6a213b59 529
dcb444c9 530 Double_t d0z0[2],covd0z0[3];
531 postrack->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
6a213b59 532 d0[0] = d0z0[0];
533 d0err[0] = TMath::Sqrt(covd0z0[0]);
dcb444c9 534 negtrack->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
6a213b59 535 d0[1] = d0z0[0];
536 d0err[1] = TMath::Sqrt(covd0z0[0]);
537
538 // create the object AliAODRecoDecayHF2Prong
dcb444c9 539 AliAODRecoDecayHF2Prong *the2Prong = new AliAODRecoDecayHF2Prong(secVert,px,py,pz,d0,d0err,dca);
6a213b59 540 the2Prong->SetOwnPrimaryVtx(primVertexAOD);
dcb444c9 541 UShort_t id[2]={(UShort_t)postrack->GetID(),(UShort_t)negtrack->GetID()};
542 the2Prong->SetProngIDs(2,id);
6a213b59 543
b056c5e3 544
6a213b59 545 // select D0->Kpi
546 Int_t checkD0,checkD0bar;
547 if(fD0toKpi) okD0 = the2Prong->SelectD0(fD0toKpiCuts,checkD0,checkD0bar);
548 //if(fDebug && fD0toKpi) printf(" %d\n",(Int_t)okD0);
549 // select J/psi from B
550 Int_t checkJPSI;
551 if(fJPSItoEle) okJPSI = the2Prong->SelectBtoJPSI(fBtoJPSICuts,checkJPSI);
552 //if(fDebug && fJPSItoEle) printf(" %d\n",(Int_t)okJPSI);
553
dcb444c9 554 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) the2Prong->UnsetOwnPrimaryVtx();
6a213b59 555
556 if(okD0 || okJPSI) {
557 // get PID info from ESD
558 Double_t esdpid0[5];
559 postrack->GetESDpid(esdpid0);
560 Double_t esdpid1[5];
561 negtrack->GetESDpid(esdpid1);
562 Double_t esdpid[10];
563 for(Int_t i=0;i<5;i++) {
564 esdpid[i] = esdpid0[i];
565 esdpid[5+i] = esdpid1[i];
566 }
567 the2Prong->SetPID(2,esdpid);
568 }
569
6a213b59 570 return the2Prong;
571}
572//----------------------------------------------------------------------------
573AliAODRecoDecayHF3Prong* AliAnalysisVertexingHF::Make3Prong(
dcb444c9 574 TObjArray *threeTrackArray,AliVEvent *event,
575 AliAODVertex *secVert,Double_t dispersion,
576 AliAODVertex *vertexp1n1,AliAODVertex *vertexp2n1,
6a213b59 577 Double_t dcap1n1,Double_t dcap2n1,Double_t dcap1p2,
578 Bool_t &ok3Prong) const
579{
580 // Make 3Prong candidates and check if they pass Dplus or Ds or Lambdac
581 // reconstruction cuts
582 // E.Bruna, F.Prino
583
dcb444c9 584
6a213b59 585 ok3Prong=kFALSE;
dcb444c9 586 if(!secVert) return 0x0;
587
588 Double_t px[3],py[3],pz[3],d0[3],d0err[3];
589 Double_t momentum[3];
6a213b59 590
6a213b59 591
592 AliESDtrack *postrack1 = (AliESDtrack*)threeTrackArray->UncheckedAt(0);
dcb444c9 593 AliESDtrack *negtrack = (AliESDtrack*)threeTrackArray->UncheckedAt(1);
6a213b59 594 AliESDtrack *postrack2 = (AliESDtrack*)threeTrackArray->UncheckedAt(2);
595
dcb444c9 596 postrack1->PropagateToDCA(secVert,fBzkG,kVeryBig);
597 negtrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
598 postrack2->PropagateToDCA(secVert,fBzkG,kVeryBig);
6a213b59 599 postrack1->GetPxPyPz(momentum);
600 px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
601 negtrack->GetPxPyPz(momentum);
602 px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
603 postrack2->GetPxPyPz(momentum);
604 px[2] = momentum[0]; py[2] = momentum[1]; pz[2] = momentum[2];
605
b82f6d67 606 // invariant mass cut for D+, Ds, Lc
6a213b59 607 Bool_t okMassCut=kFALSE;
608 if(!okMassCut && f3Prong) if(SelectInvMass(2,3,px,py,pz)) okMassCut=kTRUE;
609 if(!okMassCut) {
dcb444c9 610 AliDebug(2," candidate didn't pass mass cut");
6a213b59 611 return 0x0;
612 }
613
dcb444c9 614 // primary vertex to be used by this candidate
615 AliAODVertex *primVertexAOD = OwnPrimaryVertex(threeTrackArray,event);
616 if(!primVertexAOD) return 0x0;
617
618 Double_t d0z0[2],covd0z0[3];
619 postrack1->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
620 d0[0]=d0z0[0];
621 d0err[0] = TMath::Sqrt(covd0z0[0]);
622 negtrack->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
623 d0[1]=d0z0[0];
624 d0err[1] = TMath::Sqrt(covd0z0[0]);
625 postrack2->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
626 d0[2]=d0z0[0];
627 d0err[2] = TMath::Sqrt(covd0z0[0]);
6a213b59 628
6a213b59 629
630 // create the object AliAODRecoDecayHF3Prong
dcb444c9 631 Double_t pos[3]; primVertexAOD->GetXYZ(pos);
6a213b59 632 Double_t dca[3]={dcap1n1,dcap2n1,dcap1p2};
dcb444c9 633 Double_t dist12=TMath::Sqrt((vertexp1n1->GetX()-pos[0])*(vertexp1n1->GetX()-pos[0])+(vertexp1n1->GetY()-pos[1])*(vertexp1n1->GetY()-pos[1])+(vertexp1n1->GetZ()-pos[2])*(vertexp1n1->GetZ()-pos[2]));
634 Double_t dist23=TMath::Sqrt((vertexp2n1->GetX()-pos[0])*(vertexp2n1->GetX()-pos[0])+(vertexp2n1->GetY()-pos[1])*(vertexp2n1->GetY()-pos[1])+(vertexp2n1->GetZ()-pos[2])*(vertexp2n1->GetZ()-pos[2]));
635 Short_t charge=(Short_t)(postrack1->Charge()*postrack2->Charge()*negtrack->Charge());
636 AliAODRecoDecayHF3Prong *the3Prong = new AliAODRecoDecayHF3Prong(secVert,px,py,pz,d0,d0err,dca,dispersion,dist12,dist23,charge);
6a213b59 637 the3Prong->SetOwnPrimaryVtx(primVertexAOD);
dcb444c9 638 UShort_t id[3]={(UShort_t)postrack1->GetID(),(UShort_t)negtrack->GetID(),(UShort_t)postrack2->GetID()};
639 the3Prong->SetProngIDs(3,id);
6a213b59 640
641
b82f6d67 642 // select D+->Kpipi, Ds->KKpi, Lc->pKpi
643 if(f3Prong) {
644 ok3Prong = kFALSE;
645 Int_t ok1,ok2;
646 if(the3Prong->SelectDplus(fDplusCuts)) ok3Prong = kTRUE;
647 if(the3Prong->SelectDs(fDsCuts,ok1,ok2)) ok3Prong = kTRUE;
648 if(the3Prong->SelectLc(fLcCuts,ok1,ok2)) ok3Prong = kTRUE;
649 }
6a213b59 650 //if(fDebug) printf("ok3Prong: %d\n",(Int_t)ok3Prong);
dcb444c9 651
652 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) the3Prong->UnsetOwnPrimaryVtx();
653
6a213b59 654 if(ok3Prong) {
655 // get PID info from ESD
656 Double_t esdpid0[5];
657 postrack1->GetESDpid(esdpid0);
658 Double_t esdpid1[5];
659 negtrack->GetESDpid(esdpid1);
660 Double_t esdpid2[5];
661 postrack2->GetESDpid(esdpid2);
662
6a213b59 663 Double_t esdpid[15];
664 for(Int_t i=0;i<5;i++) {
665 esdpid[i] = esdpid0[i];
666 esdpid[5+i] = esdpid1[i];
667 esdpid[10+i] = esdpid2[i];
668 }
669 the3Prong->SetPID(3,esdpid);
670 }
671
6a213b59 672 return the3Prong;
673}
674//----------------------------------------------------------------------------
675AliAODRecoDecayHF4Prong* AliAnalysisVertexingHF::Make4Prong(
dcb444c9 676 TObjArray *fourTrackArray,AliVEvent *event,
677 AliAODVertex *secVert,
678 AliAODVertex *vertexp1n1,AliAODVertex *vertexp2n1,
6a213b59 679 Double_t dcap1n1,Double_t dcap1n2,Double_t dcap2n1,
680 Bool_t &ok4Prong) const
681{
682 // Make 4Prong candidates and check if they pass D0toKpipipi
683 // reconstruction cuts
684 // G.E.Bruno, R.Romita
685
686 ok4Prong=kFALSE;
dcb444c9 687 if(!secVert) return 0x0;
6a213b59 688
689 Double_t px[4],py[4],pz[4],d0[4],d0err[4];//d0z[3];
6a213b59 690
b82f6d67 691 px[0]=dcap1n1*dcap1n2*dcap2n1; // TO BE CHANGED (done just to removed compilation warning about dca... not used)
6a213b59 692
6a213b59 693 AliESDtrack *postrack1 = (AliESDtrack*)fourTrackArray->UncheckedAt(0);
694 AliESDtrack *negtrack1 = (AliESDtrack*)fourTrackArray->UncheckedAt(1);
695 AliESDtrack *postrack2 = (AliESDtrack*)fourTrackArray->UncheckedAt(2);
696 AliESDtrack *negtrack2 = (AliESDtrack*)fourTrackArray->UncheckedAt(3);
697
dcb444c9 698 postrack1->PropagateToDCA(secVert,fBzkG,kVeryBig);
699 negtrack1->PropagateToDCA(secVert,fBzkG,kVeryBig);
700 postrack2->PropagateToDCA(secVert,fBzkG,kVeryBig);
701 negtrack2->PropagateToDCA(secVert,fBzkG,kVeryBig);
6a213b59 702
703 Double_t momentum[3];
704 postrack1->GetPxPyPz(momentum);
705 px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
706 negtrack1->GetPxPyPz(momentum);
707 px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
708 postrack2->GetPxPyPz(momentum);
709 px[2] = momentum[0]; py[2] = momentum[1]; pz[2] = momentum[2];
710 negtrack2->GetPxPyPz(momentum);
711 px[3] = momentum[0]; py[3] = momentum[1]; pz[3] = momentum[2];
712
713 // invariant mass cut for rho or D0 (try to improve coding here..)
714 //Bool_t okMassCut=kFALSE;
715 //if(!okMassCut) if(SelectInvMass(2,3,px,py,pz)) okMassCut=kTRUE;
716 //if(!okMassCut) {
717 // if(fDebug) printf(" candidate didn't pass mass cut\n");
718 // return 0x0;
719 //}
720
dcb444c9 721 // primary vertex to be used by this candidate
722 AliAODVertex *primVertexAOD = OwnPrimaryVertex(fourTrackArray,event);
723 if(!primVertexAOD) return 0x0;
724
725 /*
726 Double_t d0z0[2],covd0z0[3];
727 postrack1->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
728 negtrack1->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
729 postrack2->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
730 negtrack2->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
731 */
6a213b59 732
733 // create the object AliAODRecoDecayHF4Prong
dcb444c9 734 Double_t pos[3]; primVertexAOD->GetXYZ(pos);
6a213b59 735 Double_t dca[6]={0.,0.,0.,0.,0.,0.}; // modify it
dcb444c9 736 Double_t dist12=TMath::Sqrt((vertexp1n1->GetX()-pos[0])*(vertexp1n1->GetX()-pos[0])+(vertexp1n1->GetY()-pos[1])*(vertexp1n1->GetY()-pos[1])+(vertexp1n1->GetZ()-pos[2])*(vertexp1n1->GetZ()-pos[2]));
737 Double_t dist23=TMath::Sqrt((vertexp2n1->GetX()-pos[0])*(vertexp2n1->GetX()-pos[0])+(vertexp2n1->GetY()-pos[1])*(vertexp2n1->GetY()-pos[1])+(vertexp2n1->GetZ()-pos[2])*(vertexp2n1->GetZ()-pos[2]));
6a213b59 738 Double_t dist14=0.; // to be implemented
739 Double_t dist34=0.; // to be implemented
dcb444c9 740 Short_t charge=0;
741 AliAODRecoDecayHF4Prong *the4Prong = new AliAODRecoDecayHF4Prong(secVert,px,py,pz,d0,d0err,dca,dist12,dist23,dist14,dist34,charge);
6a213b59 742 the4Prong->SetOwnPrimaryVtx(primVertexAOD);
dcb444c9 743 UShort_t id[4]={(UShort_t)postrack1->GetID(),(UShort_t)negtrack1->GetID(),(UShort_t)postrack2->GetID(),(UShort_t)negtrack2->GetID()};
744 the4Prong->SetProngIDs(4,id);
6a213b59 745
746
747 // use the following two lines once AliAODRecoDecayHF4Prong::SelectD0 is available
748 // select D0->Kpipipi
749 //Int_t checkD0,checkD0bar;
750 // ok4Prong=the4Prong->SelectD0(fD04pCuts,checkD0,checkD0bar);
751 ok4Prong=kFALSE; //for the time being ...
752
dcb444c9 753 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) the4Prong->UnsetOwnPrimaryVtx();
6a213b59 754
755 // get PID info from ESD
756 Double_t esdpid0[5];
757 postrack1->GetESDpid(esdpid0);
758 Double_t esdpid1[5];
759 negtrack1->GetESDpid(esdpid1);
760 Double_t esdpid2[5];
761 postrack2->GetESDpid(esdpid2);
762 Double_t esdpid3[5];
763 negtrack2->GetESDpid(esdpid3);
764
765 Double_t esdpid[20];
766 for(Int_t i=0;i<5;i++) {
767 esdpid[i] = esdpid0[i];
768 esdpid[5+i] = esdpid1[i];
769 esdpid[10+i] = esdpid2[i];
770 esdpid[15+i] = esdpid3[i];
771 }
772 the4Prong->SetPID(4,esdpid);
773
6a213b59 774 return the4Prong;
775}
776//-----------------------------------------------------------------------------
dcb444c9 777AliAODVertex* AliAnalysisVertexingHF::OwnPrimaryVertex(TObjArray *trkArray,
778 AliVEvent *event) const
6a213b59 779{
780 // Returns primary vertex specific to this candidate
781
dcb444c9 782 AliESDVertex *vertexESD = 0;
783 AliAODVertex *vertexAOD = 0;
784
785 Int_t nTrks = trkArray->GetEntriesFast();
786
787 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
788 // primary vertex from the input event
789
790 vertexESD = new AliESDVertex(*fV1);
791
792 } else {
793 // primary vertex specific to this candidate
794
795 AliVertexerTracks *vertexer = new AliVertexerTracks(event->GetMagneticField());
796
797 if(fRecoPrimVtxSkippingTrks) {
798 // recalculating the vertex
799
800 if(strstr(fV1->GetTitle(),"VertexerTracksWithConstraint")) {
801 Float_t diamondcovxy[3];
802 event->GetDiamondCovXY(diamondcovxy);
803 Double_t pos[3]={event->GetDiamondX(),event->GetDiamondY(),0.};
804 Double_t cov[6]={diamondcovxy[0],diamondcovxy[1],diamondcovxy[2],0.,0.,10.};
805 AliESDVertex *diamond = new AliESDVertex(pos,cov,1.,1);
806 vertexer->SetVtxStart(diamond);
807 delete diamond; diamond=NULL;
808 if(strstr(fV1->GetTitle(),"VertexerTracksWithConstraintOnlyFitter"))
809 vertexer->SetOnlyFitter();
810 }
811 Int_t skipped[10];
812 AliESDtrack *t = 0;
813 for(Int_t i=0; i<nTrks; i++) {
814 t = (AliESDtrack*)trkArray->UncheckedAt(i);
815 skipped[i] = (Int_t)t->GetID();
816 }
817 vertexer->SetSkipTracks(nTrks,skipped);
818 vertexESD = (AliESDVertex*)vertexer->FindPrimaryVertex(event);
819
820 } else if(fRmTrksFromPrimVtx) {
821 // removing the prongs tracks
822
823 TObjArray rmArray(nTrks);
824 UShort_t *rmId = new UShort_t[nTrks];
825 AliESDtrack *esdTrack = 0;
826 AliESDtrack *t = 0;
827 for(Int_t i=0; i<nTrks; i++) {
828 t = (AliESDtrack*)trkArray->UncheckedAt(i);
829 esdTrack = new AliESDtrack(*t);
830 rmArray.AddLast(esdTrack);
831 rmId[i]=(UShort_t)esdTrack->GetID();
832 }
833 Float_t diamondxy[2]={event->GetDiamondX(),event->GetDiamondY()};
834 vertexESD = vertexer->RemoveTracksFromVertex(fV1,&rmArray,rmId,diamondxy);
835 delete [] rmId; rmId=NULL;
836 rmArray.Delete();
837
6a213b59 838 }
6a213b59 839
dcb444c9 840 if(!vertexESD) return vertexAOD;
841 if(vertexESD->GetNContributors()<=0) {
842 AliDebug(2,"vertexing failed");
843 delete vertexESD; vertexESD=NULL;
844 return vertexAOD;
6a213b59 845 }
dcb444c9 846
847 delete vertexer; vertexer=NULL;
848
6a213b59 849 }
850
dcb444c9 851 // convert to AliAODVertex
852 Double_t pos[3],cov[6],chi2perNDF;
853 vertexESD->GetXYZ(pos); // position
854 vertexESD->GetCovMatrix(cov); //covariance matrix
855 chi2perNDF = vertexESD->GetChi2toNDF();
856 delete vertexESD; vertexESD=NULL;
857
858 vertexAOD = new AliAODVertex(pos,cov,chi2perNDF);
6a213b59 859
dcb444c9 860 return vertexAOD;
6a213b59 861}
862//-----------------------------------------------------------------------------
863void AliAnalysisVertexingHF::PrintStatus() const {
864 // Print parameters being used
865
866 printf("Preselections:\n");
867 printf(" fITSrefit = %d\n",(Int_t)fITSrefit);
868 printf(" fBothSPD = %d\n",(Int_t)fBothSPD);
869 printf(" fMinITSCls = %d\n",fMinITSCls);
870 printf(" fMinPtCut = %f GeV/c\n",fMinPtCut);
871 printf(" fMind0rphiCut = %f cm\n",fMind0rphiCut);
4d5c9633 872 if(fSecVtxWithKF) {
873 printf("Secondary vertex with Kalman filter package (AliKFParticle)\n");
874 } else {
875 printf("Secondary vertex with AliVertexerTracks\n");
876 }
6a213b59 877 if(fRecoPrimVtxSkippingTrks) printf("RecoPrimVtxSkippingTrks\n");
878 if(fRmTrksFromPrimVtx) printf("RmTrksFromPrimVtx\n");
879 if(fD0toKpi) {
880 printf("Reconstruct D0->Kpi candidates with cuts:\n");
881 printf(" |M-MD0| [GeV] < %f\n",fD0toKpiCuts[0]);
882 printf(" dca [cm] < %f\n",fD0toKpiCuts[1]);
883 printf(" cosThetaStar < %f\n",fD0toKpiCuts[2]);
884 printf(" pTK [GeV/c] > %f\n",fD0toKpiCuts[3]);
885 printf(" pTpi [GeV/c] > %f\n",fD0toKpiCuts[4]);
886 printf(" |d0K| [cm] < %f\n",fD0toKpiCuts[5]);
887 printf(" |d0pi| [cm] < %f\n",fD0toKpiCuts[6]);
888 printf(" d0d0 [cm^2] < %f\n",fD0toKpiCuts[7]);
889 printf(" cosThetaPoint > %f\n",fD0toKpiCuts[8]);
890 }
891 if(fJPSItoEle) {
892 printf("Reconstruct J/psi from B candidates with cuts:\n");
893 printf(" |M-MJPSI| [GeV] < %f\n",fBtoJPSICuts[0]);
894 printf(" dca [cm] < %f\n",fBtoJPSICuts[1]);
895 printf(" cosThetaStar < %f\n",fBtoJPSICuts[2]);
896 printf(" pTP [GeV/c] > %f\n",fBtoJPSICuts[3]);
897 printf(" pTN [GeV/c] > %f\n",fBtoJPSICuts[4]);
898 printf(" |d0P| [cm] < %f\n",fBtoJPSICuts[5]);
899 printf(" |d0N| [cm] < %f\n",fBtoJPSICuts[6]);
900 printf(" d0d0 [cm^2] < %f\n",fBtoJPSICuts[7]);
901 printf(" cosThetaPoint > %f\n",fBtoJPSICuts[8]);
902 }
903 if(f3Prong) {
904 printf("Reconstruct 3 prong candidates.\n");
4d5c9633 905 printf(" D+->Kpipi cuts:\n");
6a213b59 906 printf(" |M-MD+| [GeV] < %f\n",fDplusCuts[0]);
907 printf(" pTK [GeV/c] > %f\n",fDplusCuts[1]);
908 printf(" pTPi [GeV/c] > %f\n",fDplusCuts[2]);
909 printf(" |d0K| [cm] > %f\n",fDplusCuts[3]);
910 printf(" |d0Pi| [cm] > %f\n",fDplusCuts[4]);
911 printf(" dist12 [cm] < %f\n",fDplusCuts[5]);
912 printf(" sigmavert [cm] < %f\n",fDplusCuts[6]);
913 printf(" dist prim-sec [cm] > %f\n",fDplusCuts[7]);
914 printf(" pM=Max{pT1,pT2,pT3} [GeV/c] > %f\n",fDplusCuts[8]);
915 printf(" cosThetaPoint > %f\n",fDplusCuts[9]);
916 printf(" Sum d0^2 [cm^2] > %f\n",fDplusCuts[10]);
917 printf(" dca cut [cm] < %f\n",fDplusCuts[11]);
4d5c9633 918 printf(" Ds->KKpi cuts:\n");
919 printf(" |M-MDs| [GeV] < %f\n",fDsCuts[0]);
81679460 920 printf(" pTK [GeV/c] > %f\n",fDsCuts[1]);
921 printf(" pTPi [GeV/c] > %f\n",fDsCuts[2]);
922 printf(" |d0K| [cm] > %f\n",fDsCuts[3]);
923 printf(" |d0Pi| [cm] > %f\n",fDsCuts[4]);
924 printf(" dist12 [cm] < %f\n",fDsCuts[5]);
925 printf(" sigmavert [cm] < %f\n",fDsCuts[6]);
926 printf(" dist prim-sec [cm] > %f\n",fDsCuts[7]);
927 printf(" pM=Max{pT1,pT2,pT3} [GeV/c] > %f\n",fDsCuts[8]);
928 printf(" cosThetaPoint > %f\n",fDsCuts[9]);
929 printf(" Sum d0^2 [cm^2] > %f\n",fDsCuts[10]);
930 printf(" dca cut [cm] < %f\n",fDsCuts[11]);
931 printf(" Inv. Mass phi/K0* [GeV] < %f\n",fDsCuts[12]);
6ea608bf 932 printf(" Lc->pKpi cuts:\n");
933 printf(" |M-MLc| [GeV] < %f\n",fLcCuts[0]);
81679460 934 printf(" pTP [GeV/c] > %f\n",fLcCuts[1]);
935 printf(" pTPi and pTK [GeV/c] > %f\n",fLcCuts[2]);
936 printf(" |d0P| [cm] > %f\n",fLcCuts[3]);
937 printf(" |d0Pi| and |d0K| [cm] > %f\n",fLcCuts[4]);
938 printf(" dist12 [cm] < %f\n",fLcCuts[5]);
939 printf(" sigmavert [cm] < %f\n",fLcCuts[6]);
940 printf(" dist prim-sec [cm] > %f\n",fLcCuts[7]);
941 printf(" pM=Max{pT1,pT2,pT3} [GeV/c] > %f\n",fLcCuts[8]);
942 printf(" cosThetaPoint > %f\n",fLcCuts[9]);
943 printf(" Sum d0^2 [cm^2] > %f\n",fLcCuts[10]);
944 printf(" dca cut [cm] < %f\n",fLcCuts[11]);
6ea608bf 945 printf(" Ds->KKpi cuts:\n");
6a213b59 946 }
947
948 return;
949}
950//-----------------------------------------------------------------------------
dcb444c9 951AliAODVertex* AliAnalysisVertexingHF::ReconstructSecondaryVertex(TObjArray *trkArray,
952 Double_t &dispersion) const
953{
954 // Secondary vertex reconstruction with AliVertexerTracks or AliKFParticle
955
956 AliESDVertex *vertexESD = 0;
957 AliAODVertex *vertexAOD = 0;
958
959 if(!fSecVtxWithKF) { // AliVertexerTracks
960
961 AliVertexerTracks *vertexer = new AliVertexerTracks(fBzkG);
962 vertexer->SetVtxStart(fV1);
963 vertexESD = (AliESDVertex*)vertexer->VertexForSelectedESDTracks(trkArray);
964 delete vertexer; vertexer=NULL;
965
966 if(!vertexESD) return vertexAOD;
967
968 if(vertexESD->GetNContributors()!=trkArray->GetEntriesFast()) {
969 AliDebug(2,"vertexing failed");
970 delete vertexESD; vertexESD=NULL;
971 return vertexAOD;
972 }
973
974 } else { // Kalman Filter vertexer (AliKFParticle)
975
976 AliKFParticle::SetField(fBzkG);
977
978 AliKFParticle vertexKF;
979
980 Int_t nTrks = trkArray->GetEntriesFast();
981 for(Int_t i=0; i<nTrks; i++) {
982 AliESDtrack *esdTrack = (AliESDtrack*)trkArray->At(i);
983 AliKFParticle daughterKF(*esdTrack,211);
984 vertexKF.AddDaughter(daughterKF);
985 }
986 vertexESD = new AliESDVertex();
987 vertexKF.CopyToESDVertex(*vertexESD);
988
989 }
990
991 // convert to AliAODVertex
992 Double_t pos[3],cov[6],chi2perNDF;
993 vertexESD->GetXYZ(pos); // position
994 vertexESD->GetCovMatrix(cov); //covariance matrix
995 chi2perNDF = vertexESD->GetChi2toNDF();
996 dispersion = vertexESD->GetDispersion();
997 delete vertexESD; vertexESD=NULL;
998
999 vertexAOD = new AliAODVertex(pos,cov,chi2perNDF);
1000 vertexAOD->SetType(AliAODVertex::kUndef); // to be changed
1001
1002 return vertexAOD;
1003}
1004//-----------------------------------------------------------------------------
6a213b59 1005Bool_t AliAnalysisVertexingHF::SelectInvMass(Int_t decay,
1006 Int_t nprongs,
1007 Double_t *px,
1008 Double_t *py,
1009 Double_t *pz) const {
1010 // Check invariant mass cut
1011
1012 Short_t dummycharge=0;
1013 Double_t *dummyd0 = new Double_t[nprongs];
b056c5e3 1014 for(Int_t ip=0;ip<nprongs;ip++) dummyd0[ip]=0.;
6a213b59 1015 AliAODRecoDecay *rd = new AliAODRecoDecay(0x0,nprongs,dummycharge,px,py,pz,dummyd0);
1016 delete [] dummyd0;
1017
1018 UInt_t pdg2[2],pdg3[3];
1019 Double_t mPDG,minv;
1020
1021 Bool_t retval=kFALSE;
1022 switch (decay)
1023 {
1024 case 0: // D0->Kpi
1025 pdg2[0]=211; pdg2[1]=321;
1026 mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
1027 minv = rd->InvMass(nprongs,pdg2);
1028 if(TMath::Abs(minv-mPDG)<fD0toKpiCuts[0]) retval=kTRUE;
1029 pdg2[0]=321; pdg2[1]=211;
1030 minv = rd->InvMass(nprongs,pdg2);
1031 if(TMath::Abs(minv-mPDG)<fD0toKpiCuts[0]) retval=kTRUE;
1032 break;
1033 case 1: // JPSI->ee
1034 pdg2[0]=11; pdg2[1]=11;
1035 mPDG=TDatabasePDG::Instance()->GetParticle(443)->Mass();
1036 minv = rd->InvMass(nprongs,pdg2);
1037 if(TMath::Abs(minv-mPDG)<fBtoJPSICuts[0]) retval=kTRUE;
1038 break;
1039 case 2: // D+->Kpipi
1040 pdg3[0]=211; pdg3[1]=321; pdg3[2]=211;
1041 mPDG=TDatabasePDG::Instance()->GetParticle(411)->Mass();
1042 minv = rd->InvMass(nprongs,pdg3);
1043 if(TMath::Abs(minv-mPDG)<fDplusCuts[0]) retval=kTRUE;
b82f6d67 1044 // Ds+->KKpi
1045 pdg3[0]=321; pdg3[1]=321; pdg3[2]=211;
1046 mPDG=TDatabasePDG::Instance()->GetParticle(431)->Mass();
1047 minv = rd->InvMass(nprongs,pdg3);
1048 if(TMath::Abs(minv-mPDG)<fDsCuts[0]) retval=kTRUE;
1049 pdg3[0]=211; pdg3[1]=321; pdg3[2]=321;
1050 minv = rd->InvMass(nprongs,pdg3);
1051 if(TMath::Abs(minv-mPDG)<fDsCuts[0]) retval=kTRUE;
1052 // Lc->pKpi
1053 pdg3[0]=2212; pdg3[1]=321; pdg3[2]=211;
1054 mPDG=TDatabasePDG::Instance()->GetParticle(4122)->Mass();
1055 minv = rd->InvMass(nprongs,pdg3);
1056 if(TMath::Abs(minv-mPDG)<fLcCuts[0]) retval=kTRUE;
1057 pdg3[0]=211; pdg3[1]=321; pdg3[2]=2212;
1058 minv = rd->InvMass(nprongs,pdg3);
1059 if(TMath::Abs(minv-mPDG)<fLcCuts[0]) retval=kTRUE;
6a213b59 1060 break;
1061 default:
1062 break;
1063 }
1064
1065 delete rd;
1066
1067 return retval;
1068}
1069//-----------------------------------------------------------------------------
dcb444c9 1070void AliAnalysisVertexingHF::SelectTracksAndCopyVertex(AliVEvent *event,
6a213b59 1071 TObjArray &trksP,Int_t &nTrksP,
dcb444c9 1072 TObjArray &trksN,Int_t &nTrksN)
6a213b59 1073{
1074 // Fill two TObjArrays with positive and negative tracks and
dcb444c9 1075 // apply single-track preselection.
1076 // Create the AliESDVertex object (convert from AliAODVertex if necessary)
1077 // In case of AOD input, also fill fAODMap for track index<->ID
1078
1079 const AliVVertex *vprimary = event->GetPrimaryVertex();
1080
1081 if(fV1) { delete fV1; fV1=NULL; }
1082 if(fAODMap) { delete [] fAODMap; fAODMap=NULL; }
1083
1084 Int_t nindices=0;
1085 UShort_t *indices = 0;
1086 Double_t pos[3],cov[6];
1087
1088 if(!fInputAOD) { // ESD
1089 fV1 = new AliESDVertex(*((AliESDVertex*)vprimary));
1090 } else { // AOD
1091 vprimary->GetXYZ(pos);
1092 vprimary->GetCovarianceMatrix(cov);
1093 fV1 = new AliESDVertex(pos,cov,100.,100,vprimary->GetName());
1094 indices = new UShort_t[event->GetNumberOfTracks()];
1095 fAODMap = new Int_t[100000];
1096 }
1097
1098
6a213b59 1099 nTrksP=0,nTrksN=0;
1100
dcb444c9 1101 Int_t entries = (Int_t)event->GetNumberOfTracks();
6a213b59 1102
dcb444c9 1103 // transfer ITS tracks from event to arrays
6a213b59 1104 for(Int_t i=0; i<entries; i++) {
1105
dcb444c9 1106 AliVTrack *track = (AliVTrack*)event->GetTrack(i);
1107
1108 if(fInputAOD) {
1109 AliAODTrack *aodt = (AliAODTrack*)track;
1110 if(aodt->GetUsedForPrimVtxFit()) {
1111 indices[nindices]=aodt->GetID(); nindices++;
1112 }
1113 fAODMap[(Int_t)aodt->GetID()] = i;
1114 }
6a213b59 1115
1116 // require refit in ITS
dcb444c9 1117 UInt_t status = track->GetStatus();
6a213b59 1118 if(fITSrefit && !(status&AliESDtrack::kITSrefit)) {
dcb444c9 1119 AliDebug(2,Form("track %d is not kITSrefit",i));
6a213b59 1120 continue;
1121 }
1122
dcb444c9 1123 Int_t ncls0=0;
1124 for(Int_t l=0;l<6;l++) if(TESTBIT(track->GetITSClusterMap(),l)) ncls0++;
1125
6a213b59 1126 // require minimum # of ITS points
dcb444c9 1127 if(ncls0<fMinITSCls) {
1128 AliDebug(2,Form("track %d has %d ITS cls",i,ncls0));
6a213b59 1129 continue;
1130 }
1131 // require points on the 2 pixel layers
1132 if(fBothSPD)
dcb444c9 1133 if(!TESTBIT(track->GetITSClusterMap(),0) ||
1134 !TESTBIT(track->GetITSClusterMap(),1)) continue;
1135
1136 AliESDtrack *esdt = 0;
1137 if(!fInputAOD) {
1138 esdt = (AliESDtrack*)track;
1139 } else {
1140 esdt = new AliESDtrack(track);
1141 }
6a213b59 1142
1143 // single track selection
dcb444c9 1144 if(!SingleTrkCuts(*esdt)) {
1145 if(fInputAOD) delete esdt;
1146 esdt = NULL;
1147 continue;
1148 }
6a213b59 1149
dcb444c9 1150 if(track->Charge()<0) { // negative track
1151 trksN.AddLast(esdt);
6a213b59 1152 nTrksN++;
1153 } else { // positive track
dcb444c9 1154 trksP.AddLast(esdt);
6a213b59 1155 nTrksP++;
1156 }
1157
dcb444c9 1158 } // end loop on tracks
1159
1160 // primary vertex from AOD
1161 if(fInputAOD) {
1162 delete fV1; fV1=NULL;
1163 vprimary->GetXYZ(pos);
1164 vprimary->GetCovarianceMatrix(cov);
1165 Double_t chi2toNDF = vprimary->GetChi2perNDF();
1166 Int_t ncontr=nindices;
a6e0ebfe 1167 if(!strcmp(vprimary->GetTitle(),"VertexerTracksWithContraint")) ncontr += 1;
dcb444c9 1168 Double_t chi2=chi2toNDF*(2.*(Double_t)ncontr-3.);
1169 fV1 = new AliESDVertex(pos,cov,chi2,ncontr,vprimary->GetName());
1170 fV1->SetTitle(vprimary->GetTitle());
1171 fV1->SetIndices(nindices,indices);
1172 }
1173 if(indices) { delete [] indices; indices=NULL; }
1174
6a213b59 1175
1176 return;
1177}
1178//-----------------------------------------------------------------------------
1179void AliAnalysisVertexingHF::SetD0toKpiCuts(Double_t cut0,Double_t cut1,
1180 Double_t cut2,Double_t cut3,Double_t cut4,
1181 Double_t cut5,Double_t cut6,
1182 Double_t cut7,Double_t cut8)
1183{
1184 // Set the cuts for D0 selection
1185 fD0toKpiCuts[0] = cut0;
1186 fD0toKpiCuts[1] = cut1;
1187 fD0toKpiCuts[2] = cut2;
1188 fD0toKpiCuts[3] = cut3;
1189 fD0toKpiCuts[4] = cut4;
1190 fD0toKpiCuts[5] = cut5;
1191 fD0toKpiCuts[6] = cut6;
1192 fD0toKpiCuts[7] = cut7;
1193 fD0toKpiCuts[8] = cut8;
1194
1195 return;
1196}
1197//-----------------------------------------------------------------------------
1198void AliAnalysisVertexingHF::SetD0toKpiCuts(const Double_t cuts[9])
1199{
1200 // Set the cuts for D0 selection
1201
1202 for(Int_t i=0; i<9; i++) fD0toKpiCuts[i] = cuts[i];
1203
1204 return;
1205}
1206//-----------------------------------------------------------------------------
1207void AliAnalysisVertexingHF::SetBtoJPSICuts(Double_t cut0,Double_t cut1,
1208 Double_t cut2,Double_t cut3,Double_t cut4,
1209 Double_t cut5,Double_t cut6,
1210 Double_t cut7,Double_t cut8)
1211{
1212 // Set the cuts for J/psi from B selection
1213 fBtoJPSICuts[0] = cut0;
1214 fBtoJPSICuts[1] = cut1;
1215 fBtoJPSICuts[2] = cut2;
1216 fBtoJPSICuts[3] = cut3;
1217 fBtoJPSICuts[4] = cut4;
1218 fBtoJPSICuts[5] = cut5;
1219 fBtoJPSICuts[6] = cut6;
1220 fBtoJPSICuts[7] = cut7;
1221 fBtoJPSICuts[8] = cut8;
1222
1223 return;
1224}
1225//-----------------------------------------------------------------------------
1226void AliAnalysisVertexingHF::SetBtoJPSICuts(const Double_t cuts[9])
1227{
1228 // Set the cuts for J/psi from B selection
1229
1230 for(Int_t i=0; i<9; i++) fBtoJPSICuts[i] = cuts[i];
1231
1232 return;
1233}
1234//-----------------------------------------------------------------------------
1235void AliAnalysisVertexingHF::SetDplusCuts(Double_t cut0,Double_t cut1,
1236 Double_t cut2,Double_t cut3,Double_t cut4,
1237 Double_t cut5,Double_t cut6,
1238 Double_t cut7,Double_t cut8,
1239 Double_t cut9,Double_t cut10,Double_t cut11)
1240{
1241 // Set the cuts for Dplus->Kpipi selection
1242 fDplusCuts[0] = cut0;
1243 fDplusCuts[1] = cut1;
1244 fDplusCuts[2] = cut2;
1245 fDplusCuts[3] = cut3;
1246 fDplusCuts[4] = cut4;
1247 fDplusCuts[5] = cut5;
1248 fDplusCuts[6] = cut6;
1249 fDplusCuts[7] = cut7;
1250 fDplusCuts[8] = cut8;
1251 fDplusCuts[9] = cut9;
1252 fDplusCuts[10] = cut10;
1253 fDplusCuts[11] = cut11;
1254
1255 return;
1256}
1257//-----------------------------------------------------------------------------
1258void AliAnalysisVertexingHF::SetDplusCuts(const Double_t cuts[12])
1259{
b82f6d67 1260 // Set the cuts for Dplus->Kpipi selection
6a213b59 1261
1262 for(Int_t i=0; i<12; i++) fDplusCuts[i] = cuts[i];
1263
1264 return;
1265}
1266//-----------------------------------------------------------------------------
6ea608bf 1267void AliAnalysisVertexingHF::SetDsCuts(Double_t cut0,Double_t cut1,
1268 Double_t cut2,Double_t cut3,Double_t cut4,
1269 Double_t cut5,Double_t cut6,
1270 Double_t cut7,Double_t cut8,
81679460 1271 Double_t cut9,Double_t cut10,
1272 Double_t cut11,Double_t cut12)
b82f6d67 1273{
1274 // Set the cuts for Ds->KKpi selection
1275 fDsCuts[0] = cut0;
6ea608bf 1276 fDsCuts[1] = cut1;
1277 fDsCuts[2] = cut2;
1278 fDsCuts[3] = cut3;
1279 fDsCuts[4] = cut4;
1280 fDsCuts[5] = cut5;
1281 fDsCuts[6] = cut6;
1282 fDsCuts[7] = cut7;
1283 fDsCuts[8] = cut8;
1284 fDsCuts[9] = cut9;
1285 fDsCuts[10] = cut10;
1286 fDsCuts[11] = cut11;
81679460 1287 fDsCuts[12] = cut12;
b82f6d67 1288
1289 return;
1290}
1291//-----------------------------------------------------------------------------
81679460 1292void AliAnalysisVertexingHF::SetDsCuts(const Double_t cuts[13])
b82f6d67 1293{
1294 // Set the cuts for Ds->KKpi selection
1295
81679460 1296 for(Int_t i=0; i<13; i++) fDsCuts[i] = cuts[i];
b82f6d67 1297
1298 return;
1299}
1300//-----------------------------------------------------------------------------
6ea608bf 1301void AliAnalysisVertexingHF::SetLcCuts(Double_t cut0,Double_t cut1,
1302 Double_t cut2,Double_t cut3,Double_t cut4,
1303 Double_t cut5,Double_t cut6,
1304 Double_t cut7,Double_t cut8,
1305 Double_t cut9,Double_t cut10,Double_t cut11)
b82f6d67 1306{
1307 // Set the cuts for Lc->pKpi selection
1308 fLcCuts[0] = cut0;
6ea608bf 1309 fLcCuts[1] = cut1;
1310 fLcCuts[2] = cut2;
1311 fLcCuts[3] = cut3;
1312 fLcCuts[4] = cut4;
1313 fLcCuts[5] = cut5;
1314 fLcCuts[6] = cut6;
1315 fLcCuts[7] = cut7;
1316 fLcCuts[8] = cut8;
1317 fLcCuts[9] = cut9;
1318 fLcCuts[10] = cut10;
1319 fLcCuts[11] = cut11;
b82f6d67 1320
1321 return;
1322}
1323//-----------------------------------------------------------------------------
6ea608bf 1324void AliAnalysisVertexingHF::SetLcCuts(const Double_t cuts[12])
b82f6d67 1325{
1326 // Set the cuts for Lc->pKpi selection
1327
6ea608bf 1328 for(Int_t i=0; i<12; i++) fLcCuts[i] = cuts[i];
b82f6d67 1329
1330 return;
1331}
1332//-----------------------------------------------------------------------------
1333Bool_t AliAnalysisVertexingHF::SingleTrkCuts(AliESDtrack& trk) const
6a213b59 1334{
1335 // Check if track passes some kinematical cuts
6a213b59 1336
dcb444c9 1337 if(trk.Pt() < fMinPtCut) {
b056c5e3 1338 //printf("pt %f\n",1./trk.GetParameter()[4]);
6a213b59 1339 return kFALSE;
1340 }
dcb444c9 1341 Double_t d0z0[2],covd0z0[3];
1342 trk.PropagateToDCA(fV1,fBzkG,kVeryBig,d0z0,covd0z0);
6a213b59 1343 if(TMath::Abs(d0z0[0]) < fMind0rphiCut) {
dcb444c9 1344 //printf("d0rphi %f\n",TMath::Abs(d0z0[0]));
6a213b59 1345 return kFALSE;
1346 }
1347
1348 return kTRUE;
1349}
1350//-----------------------------------------------------------------------------