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