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