Set a specific storage to keep having the FMD background and energy distribution...
[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//
b056c5e3 23// Contact: andrea.dainese@lnl.infn.it
dc963de9 24// Contributors: E.Bruna, G.E.Bruno, A.Dainese, C.Di Gliglio,
25// F.Prino, R.Romita, X.M.Zhang
6a213b59 26//----------------------------------------------------------------------------
b82f6d67 27#include <TFile.h>
6a213b59 28#include <TDatabasePDG.h>
29#include <TString.h>
dcb444c9 30#include "AliLog.h"
31#include "AliVEvent.h"
32#include "AliVVertex.h"
33#include "AliVTrack.h"
6a213b59 34#include "AliVertexerTracks.h"
a353d2e4 35#include "AliKFVertex.h"
dcb444c9 36#include "AliESDEvent.h"
6a213b59 37#include "AliESDVertex.h"
e18fbfa7 38#include "AliExternalTrackParam.h"
dcfa35b3 39#include "AliNeutralTrackParam.h"
dcb444c9 40#include "AliESDtrack.h"
f8fa4595 41#include "AliESDtrackCuts.h"
b056c5e3 42#include "AliAODEvent.h"
6a213b59 43#include "AliAODRecoDecay.h"
44#include "AliAODRecoDecayHF.h"
45#include "AliAODRecoDecayHF2Prong.h"
46#include "AliAODRecoDecayHF3Prong.h"
47#include "AliAODRecoDecayHF4Prong.h"
2ff20727 48#include "AliAODRecoCascadeHF.h"
f8fa4595 49#include "AliAnalysisFilter.h"
6a213b59 50#include "AliAnalysisVertexingHF.h"
51
52ClassImp(AliAnalysisVertexingHF)
53
54//----------------------------------------------------------------------------
55AliAnalysisVertexingHF::AliAnalysisVertexingHF():
dcb444c9 56fInputAOD(kFALSE),
57fAODMap(0),
b82f6d67 58fBzkG(0.),
59fSecVtxWithKF(kFALSE),
6a213b59 60fRecoPrimVtxSkippingTrks(kFALSE),
61fRmTrksFromPrimVtx(kFALSE),
62fV1(0x0),
b82f6d67 63fD0toKpi(kTRUE),
64fJPSItoEle(kTRUE),
65f3Prong(kTRUE),
66f4Prong(kTRUE),
2ff20727 67fDstar(kTRUE),
dc963de9 68fLikeSign(kFALSE),
2ff20727 69fTrackFilter(0x0),
70fTrackFilterSoftPi(0x0)
6a213b59 71{
72 // Default constructor
73
74 SetD0toKpiCuts();
75 SetBtoJPSICuts();
76 SetDplusCuts();
b82f6d67 77 SetDsCuts();
78 SetLcCuts();
2ff20727 79 SetDstarCuts();
f8fa4595 80
6a213b59 81}
13977a79 82//--------------------------------------------------------------------------
83AliAnalysisVertexingHF::AliAnalysisVertexingHF(const AliAnalysisVertexingHF &source) :
84TNamed(source),
dcb444c9 85fInputAOD(source.fInputAOD),
86fAODMap(source.fAODMap),
b82f6d67 87fBzkG(source.fBzkG),
88fSecVtxWithKF(source.fSecVtxWithKF),
13977a79 89fRecoPrimVtxSkippingTrks(source.fRecoPrimVtxSkippingTrks),
90fRmTrksFromPrimVtx(source.fRmTrksFromPrimVtx),
91fV1(source.fV1),
13977a79 92fD0toKpi(source.fD0toKpi),
93fJPSItoEle(source.fJPSItoEle),
94f3Prong(source.f3Prong),
95f4Prong(source.f4Prong),
2ff20727 96fDstar(source.fDstar),
dc963de9 97fLikeSign(source.fLikeSign),
2ff20727 98fTrackFilter(source.fTrackFilter),
99fTrackFilterSoftPi(source.fTrackFilterSoftPi)
13977a79 100{
101 //
102 // Copy constructor
103 //
104 for(Int_t i=0; i<9; i++) fD0toKpiCuts[i]=source.fD0toKpiCuts[i];
105 for(Int_t i=0; i<9; i++) fBtoJPSICuts[i]=source.fBtoJPSICuts[i];
106 for(Int_t i=0; i<12; i++) fDplusCuts[i]=source.fDplusCuts[i];
2ff20727 107 for(Int_t i=0; i<13; i++) fDsCuts[i]=source.fDsCuts[i];
108 for(Int_t i=0; i<12; i++) fLcCuts[i]=source.fLcCuts[i];
109 for(Int_t i=0; i<5; i++) fDstarCuts[i]=source.fDstarCuts[i];
13977a79 110}
111//--------------------------------------------------------------------------
112AliAnalysisVertexingHF &AliAnalysisVertexingHF::operator=(const AliAnalysisVertexingHF &source)
113{
114 //
115 // assignment operator
116 //
117 if(&source == this) return *this;
dcb444c9 118 fInputAOD = source.fInputAOD;
b82f6d67 119 fBzkG = source.fBzkG;
120 fSecVtxWithKF = source.fSecVtxWithKF;
13977a79 121 fRecoPrimVtxSkippingTrks = source.fRecoPrimVtxSkippingTrks;
122 fRmTrksFromPrimVtx = source.fRmTrksFromPrimVtx;
123 fV1 = source.fV1;
13977a79 124 fD0toKpi = source.fD0toKpi;
125 fJPSItoEle = source.fJPSItoEle;
126 f3Prong = source.f3Prong;
127 f4Prong = source.f4Prong;
2ff20727 128 fDstar = source.fDstar;
dc963de9 129 fLikeSign = source.fLikeSign;
f8fa4595 130 fTrackFilter = source.fTrackFilter;
2ff20727 131 fTrackFilterSoftPi = source.fTrackFilterSoftPi;
13977a79 132
133 for(Int_t i=0; i<9; i++) fD0toKpiCuts[i]=source.fD0toKpiCuts[i];
134 for(Int_t i=0; i<9; i++) fBtoJPSICuts[i]=source.fBtoJPSICuts[i];
135 for(Int_t i=0; i<12; i++) fDplusCuts[i]=source.fDplusCuts[i];
2ff20727 136 for(Int_t i=0; i<13; i++) fDsCuts[i]=source.fDsCuts[i];
137 for(Int_t i=0; i<12; i++) fLcCuts[i]=source.fLcCuts[i];
138 for(Int_t i=0; i<5; i++) fDstarCuts[i]=source.fDstarCuts[i];
13977a79 139
140 return *this;
141}
6a213b59 142//----------------------------------------------------------------------------
143AliAnalysisVertexingHF::~AliAnalysisVertexingHF() {
144 // Destructor
13977a79 145 if(fV1) { delete fV1; fV1=0; }
f8fa4595 146 if(fTrackFilter) { delete fTrackFilter; fTrackFilter=0; }
2ff20727 147 if(fTrackFilterSoftPi) { delete fTrackFilterSoftPi; fTrackFilterSoftPi=0; }
6a213b59 148}
149//----------------------------------------------------------------------------
dcb444c9 150void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
151 TClonesArray *aodVerticesHFTClArr,
152 TClonesArray *aodD0toKpiTClArr,
153 TClonesArray *aodJPSItoEleTClArr,
154 TClonesArray *aodCharm3ProngTClArr,
2ff20727 155 TClonesArray *aodCharm4ProngTClArr,
dc963de9 156 TClonesArray *aodDstarTClArr,
157 TClonesArray *aodLikeSignTClArr)
b056c5e3 158{
159 // Find heavy-flavour vertex candidates
dcb444c9 160 // Input: ESD or AOD
b056c5e3 161 // Output: AOD (additional branches added)
162
dcb444c9 163
164 TString evtype = event->IsA()->GetName();
165 fInputAOD = ((evtype=="AliAODEvent") ? kTRUE : kFALSE);
166
b056c5e3 167 if(!aodVerticesHFTClArr) {
168 printf("ERROR: no aodVerticesHFTClArr");
169 return;
170 }
fa925a06 171 if((fD0toKpi || fDstar) && !aodD0toKpiTClArr) {
b056c5e3 172 printf("ERROR: no aodD0toKpiTClArr");
173 return;
174 }
175 if(fJPSItoEle && !aodJPSItoEleTClArr) {
176 printf("ERROR: no aodJPSItoEleTClArr");
177 return;
178 }
179 if(f3Prong && !aodCharm3ProngTClArr) {
180 printf("ERROR: no aodCharm3ProngTClArr");
181 return;
182 }
183 if(f4Prong && !aodCharm4ProngTClArr) {
184 printf("ERROR: no aodCharm4ProngTClArr");
185 return;
186 }
2ff20727 187 if(fDstar && !aodDstarTClArr) {
188 printf("ERROR: no aodDstarTClArr");
189 return;
190 }
dc963de9 191 if(fLikeSign && !aodLikeSignTClArr) {
192 printf("ERROR: no aodLikeSignTClArr");
193 return;
194 }
b056c5e3 195
196 // delete candidates from previous event and create references
dc963de9 197 Int_t iVerticesHF=0,iD0toKpi=0,iJPSItoEle=0,i3Prong=0,i4Prong=0,iDstar=0,iLikeSign=0;
b056c5e3 198 aodVerticesHFTClArr->Delete();
199 iVerticesHF = aodVerticesHFTClArr->GetEntriesFast();
200 TClonesArray &verticesHFRef = *aodVerticesHFTClArr;
fa925a06 201 if(fD0toKpi || fDstar) {
b056c5e3 202 aodD0toKpiTClArr->Delete();
203 iD0toKpi = aodD0toKpiTClArr->GetEntriesFast();
204 }
205 if(fJPSItoEle) {
206 aodJPSItoEleTClArr->Delete();
207 iJPSItoEle = aodJPSItoEleTClArr->GetEntriesFast();
208 }
209 if(f3Prong) {
210 aodCharm3ProngTClArr->Delete();
211 i3Prong = aodCharm3ProngTClArr->GetEntriesFast();
212 }
213 if(f4Prong) {
214 aodCharm4ProngTClArr->Delete();
215 i4Prong = aodCharm4ProngTClArr->GetEntriesFast();
216 }
2ff20727 217 if(fDstar) {
218 aodDstarTClArr->Delete();
219 iDstar = aodDstarTClArr->GetEntriesFast();
220 }
dc963de9 221 if(fLikeSign) {
222 aodLikeSignTClArr->Delete();
223 iLikeSign = aodLikeSignTClArr->GetEntriesFast();
224 }
2ff20727 225 TClonesArray &aodD0toKpiRef = *aodD0toKpiTClArr;
226 TClonesArray &aodJPSItoEleRef = *aodJPSItoEleTClArr;
227 TClonesArray &aodCharm3ProngRef = *aodCharm3ProngTClArr;
228 TClonesArray &aodCharm4ProngRef = *aodCharm4ProngTClArr;
229 TClonesArray &aodDstarRef = *aodDstarTClArr;
dc963de9 230 TClonesArray &aodLikeSignRef = *aodLikeSignTClArr;
231
b056c5e3 232
2ff20727 233 AliAODRecoDecayHF2Prong *io2Prong = 0;
234 AliAODRecoDecayHF3Prong *io3Prong = 0;
235 AliAODRecoDecayHF4Prong *io4Prong = 0;
236 AliAODRecoCascadeHF *ioCascade = 0;
b056c5e3 237
2ff20727 238 Int_t iTrkP1,iTrkP2,iTrkN1,iTrkN2,iTrkSoftPi,trkEntries;
239 Double_t xdummy,ydummy,dcap1n1,dcap1n2,dcap2n1,dcap1p2,dcan1n2,dcaCasc;
b056c5e3 240 Bool_t okD0=kFALSE,okJPSI=kFALSE,ok3Prong=kFALSE,ok4Prong=kFALSE;
2ff20727 241 Bool_t okDstar=kFALSE,okD0fromDstar=kFALSE;
b056c5e3 242 AliESDtrack *postrack1 = 0;
243 AliESDtrack *postrack2 = 0;
244 AliESDtrack *negtrack1 = 0;
245 AliESDtrack *negtrack2 = 0;
2ff20727 246 AliESDtrack *trackPi = 0;
b056c5e3 247 Double_t dcaMax = fD0toKpiCuts[1];
248 if(dcaMax < fBtoJPSICuts[1]) dcaMax=fBtoJPSICuts[1];
249 if(dcaMax < fDplusCuts[11]) dcaMax=fDplusCuts[11];
dcb444c9 250 AliDebug(2,Form(" dca cut set to %f cm",dcaMax));
b056c5e3 251
b056c5e3 252
dcb444c9 253 // get Bz
254 fBzkG = (Double_t)event->GetMagneticField();
b056c5e3 255
dcb444c9 256 trkEntries = (Int_t)event->GetNumberOfTracks();
257 AliDebug(1,Form(" Number of tracks: %d",trkEntries));
357cd934 258
259 if(trkEntries<2) {
260 AliDebug(1,Form(" Not enough tracks: %d",trkEntries));
261 return;
262 }
b056c5e3 263
357cd934 264 const AliVVertex *primary = event->GetPrimaryVertex();
265 if(!primary) {
266 AliDebug(1," No primary vertex from tracks");
267 return;
268 }
269 TString primTitle = primary->GetTitle();
270 if(!primTitle.Contains("VertexerTracks")) {
271 AliDebug(1," No primary vertex from tracks");
b056c5e3 272 return;
273 }
274
dcb444c9 275 // call function that applies sigle-track selection,
2ff20727 276 // for displaced tracks and soft pions (both charges) for D*,
dcb444c9 277 // and retrieves primary vertex
2ff20727 278 TObjArray seleTrksArray(trkEntries);
279 UChar_t *seleFlags = new UChar_t[trkEntries]; // bit 0: displaced, bit 1: softpi
280 Int_t nSeleTrks=0;
281 SelectTracksAndCopyVertex(event,seleTrksArray,nSeleTrks,seleFlags);
b056c5e3 282
2ff20727 283 AliDebug(1,Form(" Selected tracks: %d",nSeleTrks));
b056c5e3 284
2ff20727 285 TObjArray *twoTrackArray1 = new TObjArray(2);
286 TObjArray *twoTrackArray2 = new TObjArray(2);
287 TObjArray *twoTrackArrayCasc = new TObjArray(2);
288 TObjArray *threeTrackArray = new TObjArray(3);
289 TObjArray *fourTrackArray = new TObjArray(4);
b056c5e3 290
dcb444c9 291 Double_t dispersion;
dc963de9 292 Bool_t isLikeSignPair=kFALSE;
dcb444c9 293
2ff20727 294 AliAODRecoDecayHF *rd = 0;
295 AliAODRecoCascadeHF *rc = 0;
296
b056c5e3 297 // LOOP ON POSITIVE TRACKS
2ff20727 298 for(iTrkP1=0; iTrkP1<nSeleTrks; iTrkP1++) {
dc963de9 299
2ff20727 300 if(iTrkP1%1==0) AliDebug(1,Form(" 1st loop on pos: track number %d of %d",iTrkP1,nSeleTrks));
dc963de9 301
b056c5e3 302 // get track from tracks array
2ff20727 303 postrack1 = (AliESDtrack*)seleTrksArray.UncheckedAt(iTrkP1);
dc963de9 304
305 if(!TESTBIT(seleFlags[iTrkP1],kBitDispl)) continue;
306
307 if(postrack1->Charge()<0 && !fLikeSign) continue;
308
b056c5e3 309 // LOOP ON NEGATIVE TRACKS
2ff20727 310 for(iTrkN1=0; iTrkN1<nSeleTrks; iTrkN1++) {
dc963de9 311
2ff20727 312 if(iTrkN1%1==0) AliDebug(1,Form(" 1st loop on neg: track number %d of %d",iTrkN1,nSeleTrks));
dc963de9 313
314 if(iTrkN1==iTrkP1) continue;
315
b056c5e3 316 // get track from tracks array
2ff20727 317 negtrack1 = (AliESDtrack*)seleTrksArray.UncheckedAt(iTrkN1);
dc963de9 318
319 if(negtrack1->Charge()>0 && !fLikeSign) continue;
320
321 if(!TESTBIT(seleFlags[iTrkN1],kBitDispl)) continue;
322
323 if(postrack1->Charge()==negtrack1->Charge()) { // like-sign
324 isLikeSignPair=kTRUE;
325 if(!fLikeSign) continue;
326 if(iTrkN1<iTrkP1) continue; // this is needed to avoid double-counting of like-sign
327 } else { // unlike-sign
328 isLikeSignPair=kFALSE;
329 if(postrack1->Charge()<0 || negtrack1->Charge()>0) continue; // this is needed to avoid double-counting of unlike-sign
330 }
331
dcb444c9 332 // back to primary vertex
333 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
334 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
dc963de9 335
b056c5e3 336 // DCA between the two tracks
337 dcap1n1 = postrack1->GetDCA(negtrack1,fBzkG,xdummy,ydummy);
338 if(dcap1n1>dcaMax) { negtrack1=0; continue; }
dc963de9 339
b056c5e3 340 // Vertexing
341 twoTrackArray1->AddAt(postrack1,0);
342 twoTrackArray1->AddAt(negtrack1,1);
dcb444c9 343 AliAODVertex *vertexp1n1 = ReconstructSecondaryVertex(twoTrackArray1,dispersion);
b056c5e3 344 if(!vertexp1n1) {
345 twoTrackArray1->Clear();
346 negtrack1=0;
347 continue;
348 }
dc963de9 349
350 // 2 prong candidate
351 if(fD0toKpi || fJPSItoEle || fDstar || fLikeSign) {
352
2ff20727 353 io2Prong = Make2Prong(twoTrackArray1,event,vertexp1n1,dcap1n1,okD0,okJPSI,okD0fromDstar);
dc963de9 354
355 if((fD0toKpi && okD0) || (fJPSItoEle && okJPSI) || (isLikeSignPair && (okD0 || okJPSI))) {
2ff20727 356 // add the vertex and the decay to the AOD
357 AliAODVertex *v2Prong = new(verticesHFRef[iVerticesHF++])AliAODVertex(*vertexp1n1);
358 if(fInputAOD) AddDaughterRefs(v2Prong,event,twoTrackArray1);
dc963de9 359 if(!isLikeSignPair) {
360 if(okD0) {
361 rd = new(aodD0toKpiRef[iD0toKpi++])AliAODRecoDecayHF2Prong(*io2Prong);
362 rd->SetSecondaryVtx(v2Prong);
363 v2Prong->SetParent(rd);
364 }
365 if(okJPSI) {
366 rd = new(aodJPSItoEleRef[iJPSItoEle++])AliAODRecoDecayHF2Prong(*io2Prong);
367 rd->SetSecondaryVtx(v2Prong);
368 if(!okD0) v2Prong->SetParent(rd); // it cannot have two mothers ...
369 }
370 } else { // isLikeSignPair
371 rd = new(aodLikeSignRef[iLikeSign++])AliAODRecoDecayHF2Prong(*io2Prong);
2ff20727 372 rd->SetSecondaryVtx(v2Prong);
373 v2Prong->SetParent(rd);
dcb444c9 374 }
b056c5e3 375 }
dc963de9 376 // D* candidates
377 if(fDstar && okD0fromDstar && !isLikeSignPair) {
378 // write references in io2Prong
379 if(fInputAOD) {
2ff20727 380 AddDaughterRefs(vertexp1n1,event,twoTrackArray1);
dc963de9 381 } else {
382 vertexp1n1->AddDaughter(postrack1);
383 vertexp1n1->AddDaughter(negtrack1);
2ff20727 384 }
dc963de9 385 io2Prong->SetSecondaryVtx(vertexp1n1);
386 //printf("---> %d %d %d %d %d\n",vertexp1n1->GetNDaughters(),iTrkP1,iTrkN1,postrack1->Charge(),negtrack1->Charge());
2ff20727 387 // create a track from the D0
dcfa35b3 388 AliNeutralTrackParam *trackD0 = new AliNeutralTrackParam(io2Prong);
dc963de9 389
2ff20727 390 // LOOP ON TRACKS THAT PASSED THE SOFT PION CUTS
391 for(iTrkSoftPi=0; iTrkSoftPi<nSeleTrks; iTrkSoftPi++) {
dc963de9 392
2ff20727 393 if(iTrkSoftPi==iTrkP1 || iTrkSoftPi==iTrkN1) continue;
dc963de9 394
2ff20727 395 if(!TESTBIT(seleFlags[iTrkSoftPi],kBitSoftPi)) continue;
dc963de9 396
2ff20727 397 if(iTrkSoftPi%1==0) AliDebug(1,Form(" 1st loop on pi_s: track number %d of %d",iTrkSoftPi,nSeleTrks));
dc963de9 398
2ff20727 399 // get track from tracks array
400 trackPi = (AliESDtrack*)seleTrksArray.UncheckedAt(iTrkSoftPi);
401
402 trackPi->PropagateToDCA(fV1,fBzkG,kVeryBig);
403 trackD0->PropagateToDCA(fV1,fBzkG,kVeryBig);
dc963de9 404
2ff20727 405 // DCA between the two tracks
406 dcaCasc = trackPi->GetDCA(trackD0,fBzkG,xdummy,ydummy);
dc963de9 407
2ff20727 408 // Vertexing
409 twoTrackArrayCasc->AddAt(trackPi,0);
410 twoTrackArrayCasc->AddAt(trackD0,1);
dcfa35b3 411 AliAODVertex *vertexCasc = ReconstructSecondaryVertex(twoTrackArrayCasc,dispersion,kFALSE);
2ff20727 412 if(!vertexCasc) {
413 twoTrackArrayCasc->Clear();
414 trackPi=0;
415 continue;
416 }
dc963de9 417
2ff20727 418 ioCascade = MakeCascade(twoTrackArrayCasc,event,vertexCasc,io2Prong,dcaCasc,okDstar);
419 if(okDstar) {
dc963de9 420 // add the D0 to the AOD (if not already done)
2ff20727 421 if(!okD0) {
2ff20727 422 AliAODVertex *v2Prong = new(verticesHFRef[iVerticesHF++])AliAODVertex(*vertexp1n1);
423 if(fInputAOD) AddDaughterRefs(v2Prong,event,twoTrackArray1);
424 rd = new(aodD0toKpiRef[iD0toKpi++])AliAODRecoDecayHF2Prong(*io2Prong);
425 rd->SetSecondaryVtx(v2Prong);
426 v2Prong->SetParent(rd);
427 okD0=kTRUE; // this is done to add it only once
428 }
429 // add the vertex and the cascade to the AOD
430 AliAODVertex *vCasc = new(verticesHFRef[iVerticesHF++])AliAODVertex(*vertexCasc);
dcfa35b3 431 if(fInputAOD) {
432 AddDaughterRefs(vCasc,event,twoTrackArrayCasc); // add the pion
433 } else {
434 vCasc->AddDaughter(rd); // just to fill ref #0
435 }
436 vCasc->AddDaughter(rd); // add the D0 (in ref #1)
2ff20727 437 rc = new(aodDstarRef[iDstar++])AliAODRecoCascadeHF(*ioCascade);
2ff20727 438 rc->SetSecondaryVtx(vCasc);
439 vCasc->SetParent(rc);
440 }
441 twoTrackArrayCasc->Clear();
442 trackPi=0;
443 ioCascade=NULL;
444 delete vertexCasc;
445 } // end loop on soft pi tracks
dc963de9 446
2ff20727 447 if(trackD0) {delete trackD0; trackD0=NULL;}
dc963de9 448
2ff20727 449 }
dc963de9 450
b056c5e3 451 io2Prong=NULL;
2ff20727 452 }
dc963de9 453
b056c5e3 454 twoTrackArray1->Clear();
dc963de9 455 if((!f3Prong && !f4Prong) || isLikeSignPair) {
b056c5e3 456 negtrack1=0;
457 delete vertexp1n1;
458 continue;
459 }
460
461
462 // 2nd LOOP ON POSITIVE TRACKS
2ff20727 463 for(iTrkP2=iTrkP1+1; iTrkP2<nSeleTrks; iTrkP2++) {
dc963de9 464
2ff20727 465 if(iTrkP2==iTrkP1 || iTrkP2==iTrkN1) continue;
dc963de9 466
2ff20727 467 if(iTrkP2%1==0) AliDebug(1,Form(" 2nd loop on pos: track number %d of %d",iTrkP2,nSeleTrks));
dc963de9 468
b056c5e3 469 // get track from tracks array
2ff20727 470 postrack2 = (AliESDtrack*)seleTrksArray.UncheckedAt(iTrkP2);
dc963de9 471
472 if(postrack2->Charge()<0) continue;
473
474 if(!TESTBIT(seleFlags[iTrkP2],kBitDispl)) continue;
475
dcb444c9 476 // back to primary vertex
477 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
478 postrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
479 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
2ff20727 480 //printf("********** %d %d %d\n",postrack1->GetID(),postrack2->GetID(),negtrack1->GetID());
dc963de9 481
b056c5e3 482 dcap2n1 = postrack2->GetDCA(negtrack1,fBzkG,xdummy,ydummy);
483 if(dcap2n1>dcaMax) { postrack2=0; continue; }
484 dcap1p2 = postrack2->GetDCA(postrack1,fBzkG,xdummy,ydummy);
485 if(dcap1p2>dcaMax) { postrack2=0; continue; }
486
487 // Vertexing
488 twoTrackArray2->AddAt(postrack2,0);
489 twoTrackArray2->AddAt(negtrack1,1);
dcb444c9 490 AliAODVertex *vertexp2n1 = ReconstructSecondaryVertex(twoTrackArray2,dispersion);
b056c5e3 491 if(!vertexp2n1) {
492 twoTrackArray2->Clear();
493 postrack2=0;
494 continue;
495 }
dc963de9 496
497 // 3 prong candidates
b056c5e3 498 if(f3Prong) {
dc963de9 499
b056c5e3 500 threeTrackArray->AddAt(postrack1,0);
501 threeTrackArray->AddAt(negtrack1,1);
502 threeTrackArray->AddAt(postrack2,2);
dc963de9 503
dcb444c9 504 AliAODVertex* secVert3PrAOD = ReconstructSecondaryVertex(threeTrackArray,dispersion);
505 io3Prong = Make3Prong(threeTrackArray,event,secVert3PrAOD,dispersion,vertexp1n1,vertexp2n1,dcap1n1,dcap2n1,dcap1p2,ok3Prong);
b056c5e3 506 if(ok3Prong) {
2ff20727 507 AliAODVertex *v3Prong = new(verticesHFRef[iVerticesHF++])AliAODVertex(*secVert3PrAOD);
508 if(fInputAOD) AddDaughterRefs(v3Prong,event,threeTrackArray);
509 rd = new(aodCharm3ProngRef[i3Prong++])AliAODRecoDecayHF3Prong(*io3Prong);
510 rd->SetSecondaryVtx(v3Prong);
511 v3Prong->SetParent(rd);
b056c5e3 512 }
dcb444c9 513 if(io3Prong) io3Prong=NULL;
b056c5e3 514 }
dc963de9 515
516 // 4 prong candidates
b056c5e3 517 if(f4Prong) {
dc963de9 518
b056c5e3 519 // 3rd LOOP ON NEGATIVE TRACKS (for 4 prong)
2ff20727 520 for(iTrkN2=iTrkN1+1; iTrkN2<nSeleTrks; iTrkN2++) {
dc963de9 521
2ff20727 522 if(iTrkN2==iTrkP1 || iTrkN2==iTrkP2 || iTrkN2==iTrkN1) continue;
dc963de9 523
2ff20727 524 if(iTrkN2%1==0) AliDebug(1,Form(" 3rd loop on neg: track number %d of %d",iTrkN2,nSeleTrks));
dc963de9 525
b056c5e3 526 // get track from tracks array
2ff20727 527 negtrack2 = (AliESDtrack*)seleTrksArray.UncheckedAt(iTrkN2);
dc963de9 528
529 if(negtrack2->Charge()>0) continue;
530
531 if(!TESTBIT(seleFlags[iTrkN2],kBitDispl)) continue;
532
dcb444c9 533 // back to primary vertex
534 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
535 postrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
536 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
537 negtrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
b056c5e3 538 dcap1n2 = postrack1->GetDCA(negtrack2,fBzkG,xdummy,ydummy);
539 if(dcap1n2>dcaMax) { negtrack2=0; continue; }
dc963de9 540
b056c5e3 541 // Vertexing
542 fourTrackArray->AddAt(postrack1,0);
543 fourTrackArray->AddAt(negtrack1,1);
544 fourTrackArray->AddAt(postrack2,2);
545 fourTrackArray->AddAt(negtrack2,3);
dc963de9 546
dcb444c9 547 AliAODVertex* secVert4PrAOD = ReconstructSecondaryVertex(fourTrackArray,dispersion);
548 io4Prong = Make4Prong(fourTrackArray,event,secVert4PrAOD,vertexp1n1,vertexp2n1,dcap1n1,dcap1n2,dcap2n1,ok4Prong);
b056c5e3 549 if(ok4Prong) {
2ff20727 550 AliAODVertex *v4Prong = new(verticesHFRef[iVerticesHF++])AliAODVertex(*secVert4PrAOD);
551 if(fInputAOD) AddDaughterRefs(v4Prong,event,fourTrackArray);
552 rd = new(aodCharm4ProngRef[i4Prong++])AliAODRecoDecayHF4Prong(*io4Prong);
553 rd->SetSecondaryVtx(v4Prong);
554 v4Prong->SetParent(rd);
b056c5e3 555 }
dc963de9 556
dcb444c9 557 if(io4Prong) io4Prong=NULL;
b056c5e3 558 fourTrackArray->Clear();
559 negtrack2 = 0;
dc963de9 560
b056c5e3 561 } // end loop on negative tracks
dc963de9 562
b056c5e3 563 }
dc963de9 564
b056c5e3 565 postrack2 = 0;
566 delete vertexp2n1;
dc963de9 567
b056c5e3 568 } // end 2nd loop on positive tracks
dc963de9 569
b056c5e3 570 twoTrackArray2->Clear();
571
dc963de9 572 // 2nd LOOP ON NEGATIVE TRACKS (for 3 prong +--)
2ff20727 573 for(iTrkN2=iTrkN1+1; iTrkN2<nSeleTrks; iTrkN2++) {
dc963de9 574
2ff20727 575 if(iTrkN2==iTrkP1 || iTrkN2==iTrkP2 || iTrkN2==iTrkN1) continue;
dc963de9 576
2ff20727 577 if(iTrkN2%1==0) AliDebug(1,Form(" 2nd loop on neg: track number %d of %d",iTrkN2,nSeleTrks));
dc963de9 578
b056c5e3 579 // get track from tracks array
2ff20727 580 negtrack2 = (AliESDtrack*)seleTrksArray.UncheckedAt(iTrkN2);
dc963de9 581
582 if(negtrack2->Charge()>0) continue;
583
584 if(!TESTBIT(seleFlags[iTrkN2],kBitDispl)) continue;
585
dcb444c9 586 // back to primary vertex
587 postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
588 negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
589 negtrack2->PropagateToDCA(fV1,fBzkG,kVeryBig);
2ff20727 590 //printf("********** %d %d %d\n",postrack1->GetID(),negtrack1->GetID(),negtrack2->GetID());
dc963de9 591
b056c5e3 592 dcap1n2 = postrack1->GetDCA(negtrack2,fBzkG,xdummy,ydummy);
593 if(dcap1n2>dcaMax) { negtrack2=0; continue; }
594 dcan1n2 = negtrack1->GetDCA(negtrack2,fBzkG,xdummy,ydummy);
595 if(dcan1n2>dcaMax) { negtrack2=0; continue; }
596
597 // Vertexing
598 twoTrackArray2->AddAt(postrack1,0);
599 twoTrackArray2->AddAt(negtrack2,1);
dcb444c9 600
601 AliAODVertex *vertexp1n2 = ReconstructSecondaryVertex(twoTrackArray2,dispersion);
b056c5e3 602 if(!vertexp1n2) {
603 twoTrackArray2->Clear();
604 negtrack2=0;
605 continue;
606 }
dc963de9 607
b056c5e3 608 if(f3Prong) {
609 threeTrackArray->AddAt(negtrack1,0);
610 threeTrackArray->AddAt(postrack1,1);
611 threeTrackArray->AddAt(negtrack2,2);
dcb444c9 612 AliAODVertex* secVert3PrAOD = ReconstructSecondaryVertex(threeTrackArray,dispersion);
613 io3Prong = Make3Prong(threeTrackArray,event,secVert3PrAOD,dispersion,vertexp1n1,vertexp1n2,dcap1n1,dcap1n2,dcan1n2,ok3Prong);
b056c5e3 614 if(ok3Prong) {
2ff20727 615 AliAODVertex *v3Prong = new(verticesHFRef[iVerticesHF++])AliAODVertex(*secVert3PrAOD);
616 if(fInputAOD) AddDaughterRefs(v3Prong,event,threeTrackArray);
617 rd = new(aodCharm3ProngRef[i3Prong++])AliAODRecoDecayHF3Prong(*io3Prong);
618 rd->SetSecondaryVtx(v3Prong);
619 v3Prong->SetParent(rd);
b056c5e3 620 }
dcb444c9 621 if(io3Prong) io3Prong=NULL;
b056c5e3 622 }
dc963de9 623
b056c5e3 624 negtrack2 = 0;
625 delete vertexp1n2;
dc963de9 626
b056c5e3 627 } // end 2nd loop on negative tracks
628 twoTrackArray2->Clear();
629
630 negtrack1 = 0;
631 delete vertexp1n1;
632 } // end 1st loop on negative tracks
633
634 postrack1 = 0;
635 } // end 1st loop on positive tracks
636
637
2ff20727 638 AliDebug(1,Form(" Total HF vertices in event = %d;",
639 (Int_t)aodVerticesHFTClArr->GetEntriesFast()));
b056c5e3 640 if(fD0toKpi) {
dcb444c9 641 AliDebug(1,Form(" D0->Kpi in event = %d;",
642 (Int_t)aodD0toKpiTClArr->GetEntriesFast()));
b056c5e3 643 }
644 if(fJPSItoEle) {
dcb444c9 645 AliDebug(1,Form(" JPSI->ee in event = %d;",
646 (Int_t)aodJPSItoEleTClArr->GetEntriesFast()));
b056c5e3 647 }
648 if(f3Prong) {
dcb444c9 649 AliDebug(1,Form(" Charm->3Prong in event = %d;",
650 (Int_t)aodCharm3ProngTClArr->GetEntriesFast()));
b056c5e3 651 }
652 if(f4Prong) {
dcb444c9 653 AliDebug(1,Form(" Charm->4Prong in event = %d;\n",
654 (Int_t)aodCharm4ProngTClArr->GetEntriesFast()));
b056c5e3 655 }
2ff20727 656 if(fDstar) {
657 AliDebug(1,Form(" D*->D0pi in event = %d;\n",
658 (Int_t)aodDstarTClArr->GetEntriesFast()));
659 }
dc963de9 660 if(fLikeSign) {
661 AliDebug(1,Form(" Like-sign pairs in event = %d;\n",
662 (Int_t)aodLikeSignTClArr->GetEntriesFast()));
663 }
b056c5e3 664
665
dcb444c9 666 twoTrackArray1->Delete(); delete twoTrackArray1;
667 twoTrackArray2->Delete(); delete twoTrackArray2;
2ff20727 668 twoTrackArrayCasc->Delete(); delete twoTrackArrayCasc;
b056c5e3 669 threeTrackArray->Clear();
670 threeTrackArray->Delete(); delete threeTrackArray;
dcb444c9 671 fourTrackArray->Delete(); delete fourTrackArray;
2ff20727 672 delete [] seleFlags; seleFlags=NULL;
b056c5e3 673
dcb444c9 674 if(fInputAOD) {
2ff20727 675 seleTrksArray.Delete();
dcb444c9 676 }
b056c5e3 677
678 return;
679}
680//----------------------------------------------------------------------------
dcb444c9 681void AliAnalysisVertexingHF::AddDaughterRefs(AliAODVertex *v,AliVEvent *event,
682 TObjArray *trkArray) const
6a213b59 683{
dcb444c9 684 // Add the AOD tracks as daughters of the vertex (TRef)
6a213b59 685
dcb444c9 686 Int_t nTrks = trkArray->GetEntriesFast();
6a213b59 687
e18fbfa7 688 AliExternalTrackParam *track = 0;
dcb444c9 689 AliAODTrack *aodTrack = 0;
690 Int_t id;
6a213b59 691
dcb444c9 692 for(Int_t i=0; i<nTrks; i++) {
e18fbfa7 693 track = (AliExternalTrackParam*)trkArray->UncheckedAt(i);
694 id = (Int_t)track->GetID();
2ff20727 695 //printf("---> %d\n",id);
e18fbfa7 696 if(id<0) continue; // this track is a AliAODRecoDecay
dcb444c9 697 aodTrack = (AliAODTrack*)event->GetTrack(fAODMap[id]);
698 v->AddDaughter(aodTrack);
6a213b59 699 }
6a213b59 700
701 return;
dcb444c9 702}
6a213b59 703//----------------------------------------------------------------------------
2ff20727 704AliAODRecoCascadeHF* AliAnalysisVertexingHF::MakeCascade(
705 TObjArray *twoTrackArray,AliVEvent *event,
706 AliAODVertex *secVert,
707 AliAODRecoDecayHF2Prong *rd2Prong,
708 Double_t dca,
709 Bool_t &okDstar) const
710{
711 // Make the cascade as a 2Prong decay and check if it passes Dstar
712 // reconstruction cuts
713
714 okDstar = kFALSE;
715
716 Bool_t dummy1,dummy2,dummy3;
717
718 // We use Make2Prong to construct the AliAODRecoCascadeHF
719 // (which inherits from AliAODRecoDecayHF2Prong)
720 AliAODRecoCascadeHF *theCascade =
721 (AliAODRecoCascadeHF*)Make2Prong(twoTrackArray,event,secVert,dca,
722 dummy1,dummy2,dummy3);
723 if(!theCascade) return 0x0;
724
725 // charge
726 AliESDtrack *trackPi = (AliESDtrack*)twoTrackArray->UncheckedAt(0);
727 theCascade->SetCharge(trackPi->Charge());
728
729 //--- selection cuts
730 //
731 AliAODRecoCascadeHF *tmpCascade = new AliAODRecoCascadeHF(*theCascade);
dcfa35b3 732 tmpCascade->GetSecondaryVtx()->AddDaughter(trackPi);
733 tmpCascade->GetSecondaryVtx()->AddDaughter(rd2Prong);
2ff20727 734 AliAODVertex *primVertexAOD=0;
735 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
736 // take event primary vertex
737 primVertexAOD = PrimaryVertex();
738 tmpCascade->SetOwnPrimaryVtx(primVertexAOD);
739 rd2Prong->SetOwnPrimaryVtx(primVertexAOD);
740 }
741 // select D*->D0pi
742 if(fDstar) {
743 Bool_t testD0=kTRUE;
744 okDstar = tmpCascade->SelectDstar(fDstarCuts,fD0fromDstarCuts,testD0);
745 }
dcfa35b3 746 tmpCascade->GetSecondaryVtx()->RemoveDaughters();
2ff20727 747 tmpCascade->UnsetOwnPrimaryVtx();
2ff20727 748 delete tmpCascade; tmpCascade=NULL;
749 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
750 rd2Prong->UnsetOwnPrimaryVtx();
751 delete primVertexAOD; primVertexAOD=NULL;
752 }
753 //---
754
755 return theCascade;
756}
757//-----------------------------------------------------------------------------
6a213b59 758AliAODRecoDecayHF2Prong *AliAnalysisVertexingHF::Make2Prong(
2ff20727 759 TObjArray *twoTrackArray,AliVEvent *event,
dcb444c9 760 AliAODVertex *secVert,Double_t dca,
2ff20727 761 Bool_t &okD0,Bool_t &okJPSI,
762 Bool_t &okD0fromDstar) const
6a213b59 763{
764 // Make 2Prong candidates and check if they pass D0toKpi or BtoJPSI
765 // reconstruction cuts
766 // G.E.Bruno (J/psi), A.Dainese (D0->Kpi)
767
2ff20727 768 okD0=kFALSE; okJPSI=kFALSE; okD0fromDstar=kFALSE;
6a213b59 769
770 Double_t px[2],py[2],pz[2],d0[2],d0err[2];
6a213b59 771
2ff20727 772 AliESDtrack *postrack = (AliESDtrack*)twoTrackArray->UncheckedAt(0);
773 AliESDtrack *negtrack = (AliESDtrack*)twoTrackArray->UncheckedAt(1);
6a213b59 774
775 // propagate tracks to secondary vertex, to compute inv. mass
dcb444c9 776 postrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
777 negtrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
6a213b59 778
779 Double_t momentum[3];
780 postrack->GetPxPyPz(momentum);
781 px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
782 negtrack->GetPxPyPz(momentum);
783 px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
784
785
786 // invariant mass cut (try to improve coding here..)
787 Bool_t okMassCut=kFALSE;
dcb444c9 788 if(!okMassCut && fD0toKpi) if(SelectInvMass(0,2,px,py,pz)) okMassCut=kTRUE;
6a213b59 789 if(!okMassCut && fJPSItoEle) if(SelectInvMass(1,2,px,py,pz)) okMassCut=kTRUE;
2ff20727 790 if(!okMassCut && fDstar) if(SelectInvMass(3,2,px,py,pz)) okMassCut=kTRUE;
6a213b59 791 if(!okMassCut) {
dcb444c9 792 AliDebug(2," candidate didn't pass mass cut");
6a213b59 793 return 0x0;
794 }
795
dcb444c9 796 // primary vertex to be used by this candidate
2ff20727 797 AliAODVertex *primVertexAOD = PrimaryVertex(twoTrackArray,event);
dcb444c9 798 if(!primVertexAOD) return 0x0;
6a213b59 799
dcb444c9 800 Double_t d0z0[2],covd0z0[3];
801 postrack->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
6a213b59 802 d0[0] = d0z0[0];
803 d0err[0] = TMath::Sqrt(covd0z0[0]);
dcb444c9 804 negtrack->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
6a213b59 805 d0[1] = d0z0[0];
806 d0err[1] = TMath::Sqrt(covd0z0[0]);
807
808 // create the object AliAODRecoDecayHF2Prong
dcb444c9 809 AliAODRecoDecayHF2Prong *the2Prong = new AliAODRecoDecayHF2Prong(secVert,px,py,pz,d0,d0err,dca);
6a213b59 810 the2Prong->SetOwnPrimaryVtx(primVertexAOD);
dcb444c9 811 UShort_t id[2]={(UShort_t)postrack->GetID(),(UShort_t)negtrack->GetID()};
812 the2Prong->SetProngIDs(2,id);
6a213b59 813
b056c5e3 814
6a213b59 815 // select D0->Kpi
816 Int_t checkD0,checkD0bar;
2ff20727 817 if(fD0toKpi) okD0 = the2Prong->SelectD0(fD0toKpiCuts,checkD0,checkD0bar);
6a213b59 818 //if(fDebug && fD0toKpi) printf(" %d\n",(Int_t)okD0);
819 // select J/psi from B
820 Int_t checkJPSI;
2ff20727 821 if(fJPSItoEle) okJPSI = the2Prong->SelectBtoJPSI(fBtoJPSICuts,checkJPSI);
6a213b59 822 //if(fDebug && fJPSItoEle) printf(" %d\n",(Int_t)okJPSI);
2ff20727 823 // select D0->Kpi from Dstar
824 if(fDstar) okD0fromDstar = the2Prong->SelectD0(fD0fromDstarCuts,checkD0,checkD0bar);
825 //if(fDebug && fDstar) printf(" %d\n",(Int_t)okD0fromDstar);
6a213b59 826
2ff20727 827 // remove the primary vertex (was used only for selection)
dcb444c9 828 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) the2Prong->UnsetOwnPrimaryVtx();
6a213b59 829
2ff20727 830 // get PID info from ESD
831 Double_t esdpid0[5];
832 postrack->GetESDpid(esdpid0);
833 Double_t esdpid1[5];
834 negtrack->GetESDpid(esdpid1);
835 Double_t esdpid[10];
836 for(Int_t i=0;i<5;i++) {
837 esdpid[i] = esdpid0[i];
838 esdpid[5+i] = esdpid1[i];
6a213b59 839 }
2ff20727 840 the2Prong->SetPID(2,esdpid);
6a213b59 841
6a213b59 842 return the2Prong;
843}
844//----------------------------------------------------------------------------
845AliAODRecoDecayHF3Prong* AliAnalysisVertexingHF::Make3Prong(
dcb444c9 846 TObjArray *threeTrackArray,AliVEvent *event,
847 AliAODVertex *secVert,Double_t dispersion,
848 AliAODVertex *vertexp1n1,AliAODVertex *vertexp2n1,
6a213b59 849 Double_t dcap1n1,Double_t dcap2n1,Double_t dcap1p2,
850 Bool_t &ok3Prong) const
851{
852 // Make 3Prong candidates and check if they pass Dplus or Ds or Lambdac
853 // reconstruction cuts
854 // E.Bruna, F.Prino
855
dcb444c9 856
6a213b59 857 ok3Prong=kFALSE;
dcb444c9 858 if(!secVert) return 0x0;
859
860 Double_t px[3],py[3],pz[3],d0[3],d0err[3];
861 Double_t momentum[3];
6a213b59 862
6a213b59 863
864 AliESDtrack *postrack1 = (AliESDtrack*)threeTrackArray->UncheckedAt(0);
dcb444c9 865 AliESDtrack *negtrack = (AliESDtrack*)threeTrackArray->UncheckedAt(1);
6a213b59 866 AliESDtrack *postrack2 = (AliESDtrack*)threeTrackArray->UncheckedAt(2);
867
dcb444c9 868 postrack1->PropagateToDCA(secVert,fBzkG,kVeryBig);
869 negtrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
870 postrack2->PropagateToDCA(secVert,fBzkG,kVeryBig);
6a213b59 871 postrack1->GetPxPyPz(momentum);
872 px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
873 negtrack->GetPxPyPz(momentum);
874 px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
875 postrack2->GetPxPyPz(momentum);
876 px[2] = momentum[0]; py[2] = momentum[1]; pz[2] = momentum[2];
877
b82f6d67 878 // invariant mass cut for D+, Ds, Lc
6a213b59 879 Bool_t okMassCut=kFALSE;
880 if(!okMassCut && f3Prong) if(SelectInvMass(2,3,px,py,pz)) okMassCut=kTRUE;
881 if(!okMassCut) {
dcb444c9 882 AliDebug(2," candidate didn't pass mass cut");
6a213b59 883 return 0x0;
884 }
885
dcb444c9 886 // primary vertex to be used by this candidate
2ff20727 887 AliAODVertex *primVertexAOD = PrimaryVertex(threeTrackArray,event);
dcb444c9 888 if(!primVertexAOD) return 0x0;
889
890 Double_t d0z0[2],covd0z0[3];
891 postrack1->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
892 d0[0]=d0z0[0];
893 d0err[0] = TMath::Sqrt(covd0z0[0]);
894 negtrack->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
895 d0[1]=d0z0[0];
896 d0err[1] = TMath::Sqrt(covd0z0[0]);
897 postrack2->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
898 d0[2]=d0z0[0];
899 d0err[2] = TMath::Sqrt(covd0z0[0]);
6a213b59 900
6a213b59 901
902 // create the object AliAODRecoDecayHF3Prong
dcb444c9 903 Double_t pos[3]; primVertexAOD->GetXYZ(pos);
6a213b59 904 Double_t dca[3]={dcap1n1,dcap2n1,dcap1p2};
dcb444c9 905 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]));
906 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]));
907 Short_t charge=(Short_t)(postrack1->Charge()*postrack2->Charge()*negtrack->Charge());
908 AliAODRecoDecayHF3Prong *the3Prong = new AliAODRecoDecayHF3Prong(secVert,px,py,pz,d0,d0err,dca,dispersion,dist12,dist23,charge);
6a213b59 909 the3Prong->SetOwnPrimaryVtx(primVertexAOD);
dcb444c9 910 UShort_t id[3]={(UShort_t)postrack1->GetID(),(UShort_t)negtrack->GetID(),(UShort_t)postrack2->GetID()};
911 the3Prong->SetProngIDs(3,id);
6a213b59 912
913
b82f6d67 914 // select D+->Kpipi, Ds->KKpi, Lc->pKpi
915 if(f3Prong) {
916 ok3Prong = kFALSE;
917 Int_t ok1,ok2;
918 if(the3Prong->SelectDplus(fDplusCuts)) ok3Prong = kTRUE;
919 if(the3Prong->SelectDs(fDsCuts,ok1,ok2)) ok3Prong = kTRUE;
920 if(the3Prong->SelectLc(fLcCuts,ok1,ok2)) ok3Prong = kTRUE;
921 }
6a213b59 922 //if(fDebug) printf("ok3Prong: %d\n",(Int_t)ok3Prong);
dcb444c9 923
924 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) the3Prong->UnsetOwnPrimaryVtx();
925
2ff20727 926 // get PID info from ESD
927 Double_t esdpid0[5];
928 postrack1->GetESDpid(esdpid0);
929 Double_t esdpid1[5];
930 negtrack->GetESDpid(esdpid1);
931 Double_t esdpid2[5];
932 postrack2->GetESDpid(esdpid2);
933
934 Double_t esdpid[15];
935 for(Int_t i=0;i<5;i++) {
936 esdpid[i] = esdpid0[i];
937 esdpid[5+i] = esdpid1[i];
938 esdpid[10+i] = esdpid2[i];
6a213b59 939 }
2ff20727 940 the3Prong->SetPID(3,esdpid);
6a213b59 941
6a213b59 942 return the3Prong;
943}
944//----------------------------------------------------------------------------
945AliAODRecoDecayHF4Prong* AliAnalysisVertexingHF::Make4Prong(
dcb444c9 946 TObjArray *fourTrackArray,AliVEvent *event,
947 AliAODVertex *secVert,
948 AliAODVertex *vertexp1n1,AliAODVertex *vertexp2n1,
6a213b59 949 Double_t dcap1n1,Double_t dcap1n2,Double_t dcap2n1,
950 Bool_t &ok4Prong) const
951{
952 // Make 4Prong candidates and check if they pass D0toKpipipi
953 // reconstruction cuts
954 // G.E.Bruno, R.Romita
955
956 ok4Prong=kFALSE;
dcb444c9 957 if(!secVert) return 0x0;
6a213b59 958
959 Double_t px[4],py[4],pz[4],d0[4],d0err[4];//d0z[3];
6a213b59 960
b82f6d67 961 px[0]=dcap1n1*dcap1n2*dcap2n1; // TO BE CHANGED (done just to removed compilation warning about dca... not used)
6a213b59 962
6a213b59 963 AliESDtrack *postrack1 = (AliESDtrack*)fourTrackArray->UncheckedAt(0);
964 AliESDtrack *negtrack1 = (AliESDtrack*)fourTrackArray->UncheckedAt(1);
965 AliESDtrack *postrack2 = (AliESDtrack*)fourTrackArray->UncheckedAt(2);
966 AliESDtrack *negtrack2 = (AliESDtrack*)fourTrackArray->UncheckedAt(3);
967
dcb444c9 968 postrack1->PropagateToDCA(secVert,fBzkG,kVeryBig);
969 negtrack1->PropagateToDCA(secVert,fBzkG,kVeryBig);
970 postrack2->PropagateToDCA(secVert,fBzkG,kVeryBig);
971 negtrack2->PropagateToDCA(secVert,fBzkG,kVeryBig);
6a213b59 972
973 Double_t momentum[3];
974 postrack1->GetPxPyPz(momentum);
975 px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
976 negtrack1->GetPxPyPz(momentum);
977 px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
978 postrack2->GetPxPyPz(momentum);
979 px[2] = momentum[0]; py[2] = momentum[1]; pz[2] = momentum[2];
980 negtrack2->GetPxPyPz(momentum);
981 px[3] = momentum[0]; py[3] = momentum[1]; pz[3] = momentum[2];
982
983 // invariant mass cut for rho or D0 (try to improve coding here..)
984 //Bool_t okMassCut=kFALSE;
985 //if(!okMassCut) if(SelectInvMass(2,3,px,py,pz)) okMassCut=kTRUE;
986 //if(!okMassCut) {
987 // if(fDebug) printf(" candidate didn't pass mass cut\n");
988 // return 0x0;
989 //}
990
dcb444c9 991 // primary vertex to be used by this candidate
2ff20727 992 AliAODVertex *primVertexAOD = PrimaryVertex(fourTrackArray,event);
dcb444c9 993 if(!primVertexAOD) return 0x0;
994
995 /*
996 Double_t d0z0[2],covd0z0[3];
997 postrack1->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
998 negtrack1->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
999 postrack2->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
1000 negtrack2->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
1001 */
6a213b59 1002
1003 // create the object AliAODRecoDecayHF4Prong
dcb444c9 1004 Double_t pos[3]; primVertexAOD->GetXYZ(pos);
6a213b59 1005 Double_t dca[6]={0.,0.,0.,0.,0.,0.}; // modify it
dcb444c9 1006 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]));
1007 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 1008 Double_t dist14=0.; // to be implemented
1009 Double_t dist34=0.; // to be implemented
dcb444c9 1010 Short_t charge=0;
1011 AliAODRecoDecayHF4Prong *the4Prong = new AliAODRecoDecayHF4Prong(secVert,px,py,pz,d0,d0err,dca,dist12,dist23,dist14,dist34,charge);
6a213b59 1012 the4Prong->SetOwnPrimaryVtx(primVertexAOD);
dcb444c9 1013 UShort_t id[4]={(UShort_t)postrack1->GetID(),(UShort_t)negtrack1->GetID(),(UShort_t)postrack2->GetID(),(UShort_t)negtrack2->GetID()};
1014 the4Prong->SetProngIDs(4,id);
6a213b59 1015
1016
1017 // use the following two lines once AliAODRecoDecayHF4Prong::SelectD0 is available
1018 // select D0->Kpipipi
1019 //Int_t checkD0,checkD0bar;
1020 // ok4Prong=the4Prong->SelectD0(fD04pCuts,checkD0,checkD0bar);
1021 ok4Prong=kFALSE; //for the time being ...
1022
dcb444c9 1023 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) the4Prong->UnsetOwnPrimaryVtx();
6a213b59 1024
1025 // get PID info from ESD
1026 Double_t esdpid0[5];
1027 postrack1->GetESDpid(esdpid0);
1028 Double_t esdpid1[5];
1029 negtrack1->GetESDpid(esdpid1);
1030 Double_t esdpid2[5];
1031 postrack2->GetESDpid(esdpid2);
1032 Double_t esdpid3[5];
1033 negtrack2->GetESDpid(esdpid3);
1034
1035 Double_t esdpid[20];
1036 for(Int_t i=0;i<5;i++) {
2ff20727 1037 esdpid[i] = esdpid0[i];
1038 esdpid[5+i] = esdpid1[i];
6a213b59 1039 esdpid[10+i] = esdpid2[i];
1040 esdpid[15+i] = esdpid3[i];
1041 }
1042 the4Prong->SetPID(4,esdpid);
1043
6a213b59 1044 return the4Prong;
1045}
1046//-----------------------------------------------------------------------------
2ff20727 1047AliAODVertex* AliAnalysisVertexingHF::PrimaryVertex(TObjArray *trkArray,
1048 AliVEvent *event) const
6a213b59 1049{
2ff20727 1050 // Returns primary vertex to be used for this candidate
6a213b59 1051
dcb444c9 1052 AliESDVertex *vertexESD = 0;
1053 AliAODVertex *vertexAOD = 0;
1054
dcb444c9 1055
1056 if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
1057 // primary vertex from the input event
1058
1059 vertexESD = new AliESDVertex(*fV1);
1060
1061 } else {
1062 // primary vertex specific to this candidate
1063
2ff20727 1064 Int_t nTrks = trkArray->GetEntriesFast();
dcb444c9 1065 AliVertexerTracks *vertexer = new AliVertexerTracks(event->GetMagneticField());
1066
1067 if(fRecoPrimVtxSkippingTrks) {
1068 // recalculating the vertex
1069
1070 if(strstr(fV1->GetTitle(),"VertexerTracksWithConstraint")) {
1071 Float_t diamondcovxy[3];
1072 event->GetDiamondCovXY(diamondcovxy);
1073 Double_t pos[3]={event->GetDiamondX(),event->GetDiamondY(),0.};
1074 Double_t cov[6]={diamondcovxy[0],diamondcovxy[1],diamondcovxy[2],0.,0.,10.};
1075 AliESDVertex *diamond = new AliESDVertex(pos,cov,1.,1);
1076 vertexer->SetVtxStart(diamond);
1077 delete diamond; diamond=NULL;
1078 if(strstr(fV1->GetTitle(),"VertexerTracksWithConstraintOnlyFitter"))
1079 vertexer->SetOnlyFitter();
1080 }
1081 Int_t skipped[10];
e18fbfa7 1082 Int_t nTrksToSkip=0,id;
1083 AliExternalTrackParam *t = 0;
dcb444c9 1084 for(Int_t i=0; i<nTrks; i++) {
e18fbfa7 1085 t = (AliExternalTrackParam*)trkArray->UncheckedAt(i);
1086 id = (Int_t)t->GetID();
1087 if(id<0) continue;
1088 skipped[nTrksToSkip++] = id;
dcb444c9 1089 }
e18fbfa7 1090 vertexer->SetSkipTracks(nTrksToSkip,skipped);
dcb444c9 1091 vertexESD = (AliESDVertex*)vertexer->FindPrimaryVertex(event);
1092
1093 } else if(fRmTrksFromPrimVtx) {
1094 // removing the prongs tracks
1095
1096 TObjArray rmArray(nTrks);
1097 UShort_t *rmId = new UShort_t[nTrks];
1098 AliESDtrack *esdTrack = 0;
1099 AliESDtrack *t = 0;
1100 for(Int_t i=0; i<nTrks; i++) {
1101 t = (AliESDtrack*)trkArray->UncheckedAt(i);
1102 esdTrack = new AliESDtrack(*t);
1103 rmArray.AddLast(esdTrack);
2ff20727 1104 if(esdTrack->GetID()>=0) {
1105 rmId[i]=(UShort_t)esdTrack->GetID();
1106 } else {
1107 rmId[i]=9999;
1108 }
dcb444c9 1109 }
1110 Float_t diamondxy[2]={event->GetDiamondX(),event->GetDiamondY()};
1111 vertexESD = vertexer->RemoveTracksFromVertex(fV1,&rmArray,rmId,diamondxy);
1112 delete [] rmId; rmId=NULL;
1113 rmArray.Delete();
1114
6a213b59 1115 }
6a213b59 1116
dcb444c9 1117 if(!vertexESD) return vertexAOD;
1118 if(vertexESD->GetNContributors()<=0) {
1119 AliDebug(2,"vertexing failed");
1120 delete vertexESD; vertexESD=NULL;
1121 return vertexAOD;
6a213b59 1122 }
dcb444c9 1123
1124 delete vertexer; vertexer=NULL;
1125
6a213b59 1126 }
1127
dcb444c9 1128 // convert to AliAODVertex
1129 Double_t pos[3],cov[6],chi2perNDF;
1130 vertexESD->GetXYZ(pos); // position
1131 vertexESD->GetCovMatrix(cov); //covariance matrix
1132 chi2perNDF = vertexESD->GetChi2toNDF();
1133 delete vertexESD; vertexESD=NULL;
1134
1135 vertexAOD = new AliAODVertex(pos,cov,chi2perNDF);
6a213b59 1136
dcb444c9 1137 return vertexAOD;
6a213b59 1138}
1139//-----------------------------------------------------------------------------
1140void AliAnalysisVertexingHF::PrintStatus() const {
1141 // Print parameters being used
1142
f8fa4595 1143 //printf("Preselections:\n");
1144 // fTrackFilter->Dump();
4d5c9633 1145 if(fSecVtxWithKF) {
1146 printf("Secondary vertex with Kalman filter package (AliKFParticle)\n");
1147 } else {
1148 printf("Secondary vertex with AliVertexerTracks\n");
1149 }
6a213b59 1150 if(fRecoPrimVtxSkippingTrks) printf("RecoPrimVtxSkippingTrks\n");
1151 if(fRmTrksFromPrimVtx) printf("RmTrksFromPrimVtx\n");
1152 if(fD0toKpi) {
1153 printf("Reconstruct D0->Kpi candidates with cuts:\n");
1154 printf(" |M-MD0| [GeV] < %f\n",fD0toKpiCuts[0]);
1155 printf(" dca [cm] < %f\n",fD0toKpiCuts[1]);
1156 printf(" cosThetaStar < %f\n",fD0toKpiCuts[2]);
1157 printf(" pTK [GeV/c] > %f\n",fD0toKpiCuts[3]);
1158 printf(" pTpi [GeV/c] > %f\n",fD0toKpiCuts[4]);
1159 printf(" |d0K| [cm] < %f\n",fD0toKpiCuts[5]);
1160 printf(" |d0pi| [cm] < %f\n",fD0toKpiCuts[6]);
1161 printf(" d0d0 [cm^2] < %f\n",fD0toKpiCuts[7]);
1162 printf(" cosThetaPoint > %f\n",fD0toKpiCuts[8]);
1163 }
2ff20727 1164 if(fDstar) {
1165 printf(" |M-MD*| [GeV] < %f\n",fDstarCuts[0]);
1166 printf(" |M_Kpipi-M_Kpi-(MD*-MD0)| [GeV] < %f\n",fDstarCuts[1]);
1167 printf(" pTpisoft [GeV/c] > %f\n",fDstarCuts[2]);
1168 printf(" pTpisoft [GeV/c] < %f\n",fDstarCuts[3]);
1169 printf(" Theta(pisoft,D0plane) < %f\n",fDstarCuts[4]);
1170 printf("Reconstruct D*->D0pi candidates with cuts:\n");
1171 printf(" D0 from D* cuts:\n");
1172 printf(" |M-MD0| [GeV] < %f\n",fD0fromDstarCuts[0]);
1173 printf(" dca [cm] < %f\n",fD0fromDstarCuts[1]);
1174 printf(" cosThetaStar < %f\n",fD0fromDstarCuts[2]);
1175 printf(" pTK [GeV/c] > %f\n",fD0fromDstarCuts[3]);
1176 printf(" pTpi [GeV/c] > %f\n",fD0fromDstarCuts[4]);
1177 printf(" |d0K| [cm] < %f\n",fD0fromDstarCuts[5]);
1178 printf(" |d0pi| [cm] < %f\n",fD0fromDstarCuts[6]);
1179 printf(" d0d0 [cm^2] < %f\n",fD0fromDstarCuts[7]);
1180 printf(" cosThetaPoint > %f\n",fD0fromDstarCuts[8]);
1181 }
6a213b59 1182 if(fJPSItoEle) {
1183 printf("Reconstruct J/psi from B candidates with cuts:\n");
1184 printf(" |M-MJPSI| [GeV] < %f\n",fBtoJPSICuts[0]);
1185 printf(" dca [cm] < %f\n",fBtoJPSICuts[1]);
1186 printf(" cosThetaStar < %f\n",fBtoJPSICuts[2]);
1187 printf(" pTP [GeV/c] > %f\n",fBtoJPSICuts[3]);
1188 printf(" pTN [GeV/c] > %f\n",fBtoJPSICuts[4]);
1189 printf(" |d0P| [cm] < %f\n",fBtoJPSICuts[5]);
1190 printf(" |d0N| [cm] < %f\n",fBtoJPSICuts[6]);
1191 printf(" d0d0 [cm^2] < %f\n",fBtoJPSICuts[7]);
1192 printf(" cosThetaPoint > %f\n",fBtoJPSICuts[8]);
1193 }
1194 if(f3Prong) {
1195 printf("Reconstruct 3 prong candidates.\n");
4d5c9633 1196 printf(" D+->Kpipi cuts:\n");
6a213b59 1197 printf(" |M-MD+| [GeV] < %f\n",fDplusCuts[0]);
1198 printf(" pTK [GeV/c] > %f\n",fDplusCuts[1]);
1199 printf(" pTPi [GeV/c] > %f\n",fDplusCuts[2]);
1200 printf(" |d0K| [cm] > %f\n",fDplusCuts[3]);
1201 printf(" |d0Pi| [cm] > %f\n",fDplusCuts[4]);
1202 printf(" dist12 [cm] < %f\n",fDplusCuts[5]);
1203 printf(" sigmavert [cm] < %f\n",fDplusCuts[6]);
1204 printf(" dist prim-sec [cm] > %f\n",fDplusCuts[7]);
1205 printf(" pM=Max{pT1,pT2,pT3} [GeV/c] > %f\n",fDplusCuts[8]);
1206 printf(" cosThetaPoint > %f\n",fDplusCuts[9]);
1207 printf(" Sum d0^2 [cm^2] > %f\n",fDplusCuts[10]);
1208 printf(" dca cut [cm] < %f\n",fDplusCuts[11]);
4d5c9633 1209 printf(" Ds->KKpi cuts:\n");
1210 printf(" |M-MDs| [GeV] < %f\n",fDsCuts[0]);
81679460 1211 printf(" pTK [GeV/c] > %f\n",fDsCuts[1]);
1212 printf(" pTPi [GeV/c] > %f\n",fDsCuts[2]);
1213 printf(" |d0K| [cm] > %f\n",fDsCuts[3]);
1214 printf(" |d0Pi| [cm] > %f\n",fDsCuts[4]);
1215 printf(" dist12 [cm] < %f\n",fDsCuts[5]);
1216 printf(" sigmavert [cm] < %f\n",fDsCuts[6]);
1217 printf(" dist prim-sec [cm] > %f\n",fDsCuts[7]);
1218 printf(" pM=Max{pT1,pT2,pT3} [GeV/c] > %f\n",fDsCuts[8]);
1219 printf(" cosThetaPoint > %f\n",fDsCuts[9]);
1220 printf(" Sum d0^2 [cm^2] > %f\n",fDsCuts[10]);
1221 printf(" dca cut [cm] < %f\n",fDsCuts[11]);
1222 printf(" Inv. Mass phi/K0* [GeV] < %f\n",fDsCuts[12]);
6ea608bf 1223 printf(" Lc->pKpi cuts:\n");
1224 printf(" |M-MLc| [GeV] < %f\n",fLcCuts[0]);
81679460 1225 printf(" pTP [GeV/c] > %f\n",fLcCuts[1]);
1226 printf(" pTPi and pTK [GeV/c] > %f\n",fLcCuts[2]);
1227 printf(" |d0P| [cm] > %f\n",fLcCuts[3]);
1228 printf(" |d0Pi| and |d0K| [cm] > %f\n",fLcCuts[4]);
1229 printf(" dist12 [cm] < %f\n",fLcCuts[5]);
1230 printf(" sigmavert [cm] < %f\n",fLcCuts[6]);
1231 printf(" dist prim-sec [cm] > %f\n",fLcCuts[7]);
1232 printf(" pM=Max{pT1,pT2,pT3} [GeV/c] > %f\n",fLcCuts[8]);
1233 printf(" cosThetaPoint > %f\n",fLcCuts[9]);
1234 printf(" Sum d0^2 [cm^2] > %f\n",fLcCuts[10]);
1235 printf(" dca cut [cm] < %f\n",fLcCuts[11]);
6a213b59 1236 }
1237
1238 return;
1239}
1240//-----------------------------------------------------------------------------
dcb444c9 1241AliAODVertex* AliAnalysisVertexingHF::ReconstructSecondaryVertex(TObjArray *trkArray,
dcfa35b3 1242 Double_t &dispersion,Bool_t useTRefArray) const
dcb444c9 1243{
1244 // Secondary vertex reconstruction with AliVertexerTracks or AliKFParticle
1245
1246 AliESDVertex *vertexESD = 0;
1247 AliAODVertex *vertexAOD = 0;
1248
1249 if(!fSecVtxWithKF) { // AliVertexerTracks
1250
1251 AliVertexerTracks *vertexer = new AliVertexerTracks(fBzkG);
1252 vertexer->SetVtxStart(fV1);
1253 vertexESD = (AliESDVertex*)vertexer->VertexForSelectedESDTracks(trkArray);
1254 delete vertexer; vertexer=NULL;
1255
1256 if(!vertexESD) return vertexAOD;
1257
1258 if(vertexESD->GetNContributors()!=trkArray->GetEntriesFast()) {
1259 AliDebug(2,"vertexing failed");
1260 delete vertexESD; vertexESD=NULL;
1261 return vertexAOD;
1262 }
1263
1264 } else { // Kalman Filter vertexer (AliKFParticle)
1265
1266 AliKFParticle::SetField(fBzkG);
1267
a353d2e4 1268 AliKFVertex vertexKF;
dcb444c9 1269
1270 Int_t nTrks = trkArray->GetEntriesFast();
1271 for(Int_t i=0; i<nTrks; i++) {
1272 AliESDtrack *esdTrack = (AliESDtrack*)trkArray->At(i);
1273 AliKFParticle daughterKF(*esdTrack,211);
1274 vertexKF.AddDaughter(daughterKF);
1275 }
a353d2e4 1276 vertexESD = new AliESDVertex(vertexKF.Parameters(),
1277 vertexKF.CovarianceMatrix(),
1278 vertexKF.GetChi2(),
1279 vertexKF.GetNContributors());
dcb444c9 1280
1281 }
1282
1283 // convert to AliAODVertex
1284 Double_t pos[3],cov[6],chi2perNDF;
1285 vertexESD->GetXYZ(pos); // position
1286 vertexESD->GetCovMatrix(cov); //covariance matrix
1287 chi2perNDF = vertexESD->GetChi2toNDF();
1288 dispersion = vertexESD->GetDispersion();
1289 delete vertexESD; vertexESD=NULL;
1290
dcfa35b3 1291 Int_t nprongs= (useTRefArray ? 0 : trkArray->GetEntriesFast());
1292 vertexAOD = new AliAODVertex(pos,cov,chi2perNDF,0x0,-1,AliAODVertex::kUndef,nprongs);
dcb444c9 1293
1294 return vertexAOD;
1295}
1296//-----------------------------------------------------------------------------
6a213b59 1297Bool_t AliAnalysisVertexingHF::SelectInvMass(Int_t decay,
1298 Int_t nprongs,
1299 Double_t *px,
1300 Double_t *py,
1301 Double_t *pz) const {
1302 // Check invariant mass cut
1303
1304 Short_t dummycharge=0;
1305 Double_t *dummyd0 = new Double_t[nprongs];
b056c5e3 1306 for(Int_t ip=0;ip<nprongs;ip++) dummyd0[ip]=0.;
6a213b59 1307 AliAODRecoDecay *rd = new AliAODRecoDecay(0x0,nprongs,dummycharge,px,py,pz,dummyd0);
1308 delete [] dummyd0;
1309
1310 UInt_t pdg2[2],pdg3[3];
1311 Double_t mPDG,minv;
1312
1313 Bool_t retval=kFALSE;
1314 switch (decay)
1315 {
1316 case 0: // D0->Kpi
1317 pdg2[0]=211; pdg2[1]=321;
1318 mPDG=TDatabasePDG::Instance()->GetParticle(421)->Mass();
1319 minv = rd->InvMass(nprongs,pdg2);
1320 if(TMath::Abs(minv-mPDG)<fD0toKpiCuts[0]) retval=kTRUE;
1321 pdg2[0]=321; pdg2[1]=211;
1322 minv = rd->InvMass(nprongs,pdg2);
1323 if(TMath::Abs(minv-mPDG)<fD0toKpiCuts[0]) retval=kTRUE;
1324 break;
1325 case 1: // JPSI->ee
1326 pdg2[0]=11; pdg2[1]=11;
1327 mPDG=TDatabasePDG::Instance()->GetParticle(443)->Mass();
1328 minv = rd->InvMass(nprongs,pdg2);
1329 if(TMath::Abs(minv-mPDG)<fBtoJPSICuts[0]) retval=kTRUE;
1330 break;
1331 case 2: // D+->Kpipi
1332 pdg3[0]=211; pdg3[1]=321; pdg3[2]=211;
1333 mPDG=TDatabasePDG::Instance()->GetParticle(411)->Mass();
1334 minv = rd->InvMass(nprongs,pdg3);
1335 if(TMath::Abs(minv-mPDG)<fDplusCuts[0]) retval=kTRUE;
b82f6d67 1336 // Ds+->KKpi
1337 pdg3[0]=321; pdg3[1]=321; pdg3[2]=211;
1338 mPDG=TDatabasePDG::Instance()->GetParticle(431)->Mass();
1339 minv = rd->InvMass(nprongs,pdg3);
1340 if(TMath::Abs(minv-mPDG)<fDsCuts[0]) retval=kTRUE;
1341 pdg3[0]=211; pdg3[1]=321; pdg3[2]=321;
1342 minv = rd->InvMass(nprongs,pdg3);
1343 if(TMath::Abs(minv-mPDG)<fDsCuts[0]) retval=kTRUE;
1344 // Lc->pKpi
1345 pdg3[0]=2212; pdg3[1]=321; pdg3[2]=211;
1346 mPDG=TDatabasePDG::Instance()->GetParticle(4122)->Mass();
1347 minv = rd->InvMass(nprongs,pdg3);
1348 if(TMath::Abs(minv-mPDG)<fLcCuts[0]) retval=kTRUE;
1349 pdg3[0]=211; pdg3[1]=321; pdg3[2]=2212;
1350 minv = rd->InvMass(nprongs,pdg3);
1351 if(TMath::Abs(minv-mPDG)<fLcCuts[0]) retval=kTRUE;
6a213b59 1352 break;
2ff20727 1353 case 3: // D*->D0pi
1354 pdg2[0]=421; pdg2[1]=211;
1355 mPDG=TDatabasePDG::Instance()->GetParticle(413)->Mass();
1356 minv = rd->InvMass(nprongs,pdg2);
1357 if(TMath::Abs(minv-mPDG)<fDstarCuts[0]) retval=kTRUE;
1358 break;
6a213b59 1359 default:
2ff20727 1360 printf("SelectInvMass(): wrong decay selection\n");
6a213b59 1361 break;
1362 }
1363
1364 delete rd;
1365
1366 return retval;
1367}
1368//-----------------------------------------------------------------------------
dcb444c9 1369void AliAnalysisVertexingHF::SelectTracksAndCopyVertex(AliVEvent *event,
2ff20727 1370 TObjArray &seleTrksArray,Int_t &nSeleTrks,
1371 UChar_t *seleFlags)
6a213b59 1372{
2ff20727 1373 // Apply single-track preselection.
1374 // Fill a TObjArray with selected tracks (for displaced vertices or
1375 // soft pion from D*). Selection flag stored in seleFlags.
dcb444c9 1376 // Create the AliESDVertex object (convert from AliAODVertex if necessary)
1377 // In case of AOD input, also fill fAODMap for track index<->ID
1378
1379 const AliVVertex *vprimary = event->GetPrimaryVertex();
1380
1381 if(fV1) { delete fV1; fV1=NULL; }
1382 if(fAODMap) { delete [] fAODMap; fAODMap=NULL; }
1383
1384 Int_t nindices=0;
1385 UShort_t *indices = 0;
1386 Double_t pos[3],cov[6];
1387
1388 if(!fInputAOD) { // ESD
1389 fV1 = new AliESDVertex(*((AliESDVertex*)vprimary));
1390 } else { // AOD
1391 vprimary->GetXYZ(pos);
1392 vprimary->GetCovarianceMatrix(cov);
1393 fV1 = new AliESDVertex(pos,cov,100.,100,vprimary->GetName());
1394 indices = new UShort_t[event->GetNumberOfTracks()];
1395 fAODMap = new Int_t[100000];
1396 }
1397
1398
dcb444c9 1399 Int_t entries = (Int_t)event->GetNumberOfTracks();
2ff20727 1400 Bool_t okDisplaced=kFALSE,okSoftPi=kFALSE;
1401 nSeleTrks=0;
6a213b59 1402
dcb444c9 1403 // transfer ITS tracks from event to arrays
6a213b59 1404 for(Int_t i=0; i<entries; i++) {
dcb444c9 1405 AliVTrack *track = (AliVTrack*)event->GetTrack(i);
1406
1407 if(fInputAOD) {
1408 AliAODTrack *aodt = (AliAODTrack*)track;
1409 if(aodt->GetUsedForPrimVtxFit()) {
1410 indices[nindices]=aodt->GetID(); nindices++;
1411 }
1412 fAODMap[(Int_t)aodt->GetID()] = i;
1413 }
6a213b59 1414
dcb444c9 1415 AliESDtrack *esdt = 0;
1416 if(!fInputAOD) {
1417 esdt = (AliESDtrack*)track;
1418 } else {
1419 esdt = new AliESDtrack(track);
1420 }
6a213b59 1421
1422 // single track selection
2ff20727 1423 okDisplaced=kFALSE; okSoftPi=kFALSE;
1424 if(SingleTrkCuts(esdt,okDisplaced,okSoftPi)) {
1425 seleTrksArray.AddLast(esdt);
1426 seleFlags[nSeleTrks]=0;
1427 if(okDisplaced) SETBIT(seleFlags[nSeleTrks],kBitDispl);
1428 if(okSoftPi) SETBIT(seleFlags[nSeleTrks],kBitSoftPi);
1429 nSeleTrks++;
1430 } else {
dcb444c9 1431 if(fInputAOD) delete esdt;
1432 esdt = NULL;
1433 continue;
2ff20727 1434 }
6a213b59 1435
dcb444c9 1436 } // end loop on tracks
1437
1438 // primary vertex from AOD
1439 if(fInputAOD) {
1440 delete fV1; fV1=NULL;
1441 vprimary->GetXYZ(pos);
1442 vprimary->GetCovarianceMatrix(cov);
1443 Double_t chi2toNDF = vprimary->GetChi2perNDF();
1444 Int_t ncontr=nindices;
a6e0ebfe 1445 if(!strcmp(vprimary->GetTitle(),"VertexerTracksWithContraint")) ncontr += 1;
dcb444c9 1446 Double_t chi2=chi2toNDF*(2.*(Double_t)ncontr-3.);
1447 fV1 = new AliESDVertex(pos,cov,chi2,ncontr,vprimary->GetName());
1448 fV1->SetTitle(vprimary->GetTitle());
1449 fV1->SetIndices(nindices,indices);
1450 }
1451 if(indices) { delete [] indices; indices=NULL; }
1452
6a213b59 1453
1454 return;
1455}
1456//-----------------------------------------------------------------------------
1457void AliAnalysisVertexingHF::SetD0toKpiCuts(Double_t cut0,Double_t cut1,
1458 Double_t cut2,Double_t cut3,Double_t cut4,
1459 Double_t cut5,Double_t cut6,
1460 Double_t cut7,Double_t cut8)
1461{
1462 // Set the cuts for D0 selection
1463 fD0toKpiCuts[0] = cut0;
1464 fD0toKpiCuts[1] = cut1;
1465 fD0toKpiCuts[2] = cut2;
1466 fD0toKpiCuts[3] = cut3;
1467 fD0toKpiCuts[4] = cut4;
1468 fD0toKpiCuts[5] = cut5;
1469 fD0toKpiCuts[6] = cut6;
1470 fD0toKpiCuts[7] = cut7;
1471 fD0toKpiCuts[8] = cut8;
1472
1473 return;
1474}
1475//-----------------------------------------------------------------------------
1476void AliAnalysisVertexingHF::SetD0toKpiCuts(const Double_t cuts[9])
1477{
1478 // Set the cuts for D0 selection
1479
1480 for(Int_t i=0; i<9; i++) fD0toKpiCuts[i] = cuts[i];
1481
1482 return;
1483}
1484//-----------------------------------------------------------------------------
2ff20727 1485void AliAnalysisVertexingHF::SetD0fromDstarCuts(Double_t cut0,Double_t cut1,
1486 Double_t cut2,Double_t cut3,Double_t cut4,
1487 Double_t cut5,Double_t cut6,
1488 Double_t cut7,Double_t cut8)
1489{
1490 // Set the cuts for D0 from D* selection
1491 fD0fromDstarCuts[0] = cut0;
1492 fD0fromDstarCuts[1] = cut1;
1493 fD0fromDstarCuts[2] = cut2;
1494 fD0fromDstarCuts[3] = cut3;
1495 fD0fromDstarCuts[4] = cut4;
1496 fD0fromDstarCuts[5] = cut5;
1497 fD0fromDstarCuts[6] = cut6;
1498 fD0fromDstarCuts[7] = cut7;
1499 fD0fromDstarCuts[8] = cut8;
1500
1501 return;
1502}
1503//-----------------------------------------------------------------------------
1504void AliAnalysisVertexingHF::SetD0fromDstarCuts(const Double_t cuts[9])
1505{
1506 // Set the cuts for D0 from D* selection
1507
1508 for(Int_t i=0; i<9; i++) fD0fromDstarCuts[i] = cuts[i];
1509
1510 return;
1511}
1512//-----------------------------------------------------------------------------
1513void AliAnalysisVertexingHF::SetDstarCuts(Double_t cut0,Double_t cut1,
1514 Double_t cut2,Double_t cut3,
1515 Double_t cut4)
1516{
1517 // Set the cuts for D* selection
1518 fDstarCuts[0] = cut0;
1519 fDstarCuts[1] = cut1;
1520 fDstarCuts[2] = cut2;
1521 fDstarCuts[3] = cut3;
1522 fDstarCuts[4] = cut4;
1523
1524 return;
1525}
1526//-----------------------------------------------------------------------------
1527void AliAnalysisVertexingHF::SetDstarCuts(const Double_t cuts[5])
1528{
1529 // Set the cuts for D* selection
1530
1531 for(Int_t i=0; i<5; i++) fDstarCuts[i] = cuts[i];
1532
1533 return;
1534}
1535//-----------------------------------------------------------------------------
6a213b59 1536void AliAnalysisVertexingHF::SetBtoJPSICuts(Double_t cut0,Double_t cut1,
1537 Double_t cut2,Double_t cut3,Double_t cut4,
1538 Double_t cut5,Double_t cut6,
1539 Double_t cut7,Double_t cut8)
1540{
1541 // Set the cuts for J/psi from B selection
1542 fBtoJPSICuts[0] = cut0;
1543 fBtoJPSICuts[1] = cut1;
1544 fBtoJPSICuts[2] = cut2;
1545 fBtoJPSICuts[3] = cut3;
1546 fBtoJPSICuts[4] = cut4;
1547 fBtoJPSICuts[5] = cut5;
1548 fBtoJPSICuts[6] = cut6;
1549 fBtoJPSICuts[7] = cut7;
1550 fBtoJPSICuts[8] = cut8;
1551
1552 return;
1553}
1554//-----------------------------------------------------------------------------
1555void AliAnalysisVertexingHF::SetBtoJPSICuts(const Double_t cuts[9])
1556{
1557 // Set the cuts for J/psi from B selection
1558
1559 for(Int_t i=0; i<9; i++) fBtoJPSICuts[i] = cuts[i];
1560
1561 return;
1562}
1563//-----------------------------------------------------------------------------
1564void AliAnalysisVertexingHF::SetDplusCuts(Double_t cut0,Double_t cut1,
1565 Double_t cut2,Double_t cut3,Double_t cut4,
1566 Double_t cut5,Double_t cut6,
1567 Double_t cut7,Double_t cut8,
1568 Double_t cut9,Double_t cut10,Double_t cut11)
1569{
1570 // Set the cuts for Dplus->Kpipi selection
1571 fDplusCuts[0] = cut0;
1572 fDplusCuts[1] = cut1;
1573 fDplusCuts[2] = cut2;
1574 fDplusCuts[3] = cut3;
1575 fDplusCuts[4] = cut4;
1576 fDplusCuts[5] = cut5;
1577 fDplusCuts[6] = cut6;
1578 fDplusCuts[7] = cut7;
1579 fDplusCuts[8] = cut8;
1580 fDplusCuts[9] = cut9;
1581 fDplusCuts[10] = cut10;
1582 fDplusCuts[11] = cut11;
1583
1584 return;
1585}
1586//-----------------------------------------------------------------------------
1587void AliAnalysisVertexingHF::SetDplusCuts(const Double_t cuts[12])
1588{
b82f6d67 1589 // Set the cuts for Dplus->Kpipi selection
6a213b59 1590
1591 for(Int_t i=0; i<12; i++) fDplusCuts[i] = cuts[i];
1592
1593 return;
1594}
1595//-----------------------------------------------------------------------------
6ea608bf 1596void AliAnalysisVertexingHF::SetDsCuts(Double_t cut0,Double_t cut1,
1597 Double_t cut2,Double_t cut3,Double_t cut4,
1598 Double_t cut5,Double_t cut6,
1599 Double_t cut7,Double_t cut8,
81679460 1600 Double_t cut9,Double_t cut10,
1601 Double_t cut11,Double_t cut12)
b82f6d67 1602{
1603 // Set the cuts for Ds->KKpi selection
1604 fDsCuts[0] = cut0;
6ea608bf 1605 fDsCuts[1] = cut1;
1606 fDsCuts[2] = cut2;
1607 fDsCuts[3] = cut3;
1608 fDsCuts[4] = cut4;
1609 fDsCuts[5] = cut5;
1610 fDsCuts[6] = cut6;
1611 fDsCuts[7] = cut7;
1612 fDsCuts[8] = cut8;
1613 fDsCuts[9] = cut9;
1614 fDsCuts[10] = cut10;
1615 fDsCuts[11] = cut11;
81679460 1616 fDsCuts[12] = cut12;
b82f6d67 1617
1618 return;
1619}
1620//-----------------------------------------------------------------------------
81679460 1621void AliAnalysisVertexingHF::SetDsCuts(const Double_t cuts[13])
b82f6d67 1622{
1623 // Set the cuts for Ds->KKpi selection
1624
81679460 1625 for(Int_t i=0; i<13; i++) fDsCuts[i] = cuts[i];
b82f6d67 1626
1627 return;
1628}
1629//-----------------------------------------------------------------------------
6ea608bf 1630void AliAnalysisVertexingHF::SetLcCuts(Double_t cut0,Double_t cut1,
1631 Double_t cut2,Double_t cut3,Double_t cut4,
1632 Double_t cut5,Double_t cut6,
1633 Double_t cut7,Double_t cut8,
1634 Double_t cut9,Double_t cut10,Double_t cut11)
b82f6d67 1635{
1636 // Set the cuts for Lc->pKpi selection
1637 fLcCuts[0] = cut0;
6ea608bf 1638 fLcCuts[1] = cut1;
1639 fLcCuts[2] = cut2;
1640 fLcCuts[3] = cut3;
1641 fLcCuts[4] = cut4;
1642 fLcCuts[5] = cut5;
1643 fLcCuts[6] = cut6;
1644 fLcCuts[7] = cut7;
1645 fLcCuts[8] = cut8;
1646 fLcCuts[9] = cut9;
1647 fLcCuts[10] = cut10;
1648 fLcCuts[11] = cut11;
b82f6d67 1649
1650 return;
1651}
1652//-----------------------------------------------------------------------------
6ea608bf 1653void AliAnalysisVertexingHF::SetLcCuts(const Double_t cuts[12])
b82f6d67 1654{
1655 // Set the cuts for Lc->pKpi selection
1656
6ea608bf 1657 for(Int_t i=0; i<12; i++) fLcCuts[i] = cuts[i];
b82f6d67 1658
1659 return;
1660}
1661//-----------------------------------------------------------------------------
2ff20727 1662Bool_t AliAnalysisVertexingHF::SingleTrkCuts(AliESDtrack *trk,
1663 Bool_t &okDisplaced,Bool_t &okSoftPi) const
6a213b59 1664{
1665 // Check if track passes some kinematical cuts
6a213b59 1666
f8fa4595 1667 // this is needed to store the impact parameters
1668 trk->RelateToVertex(fV1,fBzkG,kVeryBig);
1669
2ff20727 1670 UInt_t selectInfo;
f8fa4595 1671 //
2ff20727 1672 // Track selection, displaced tracks
1673 selectInfo = 0;
f8fa4595 1674 if(fTrackFilter) {
1675 selectInfo = fTrackFilter->IsSelected(trk);
6a213b59 1676 }
2ff20727 1677 if(selectInfo) okDisplaced=kTRUE;
1678 // Track selection, soft pions
1679 selectInfo = 0;
1680 if(fDstar && fTrackFilterSoftPi) {
1681 selectInfo = fTrackFilterSoftPi->IsSelected(trk);
1682 }
1683 if(selectInfo) okSoftPi=kTRUE;
6a213b59 1684
2ff20727 1685 if(okDisplaced || okSoftPi) return kTRUE;
f8fa4595 1686
2ff20727 1687 return kFALSE;
6a213b59 1688}
1689//-----------------------------------------------------------------------------