1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // Secondary vertexing construction Class
17 // Construct secondary vertex from Beauty hadron with electron and
18 // hadrons, then apply selection criteria
21 // MinJung Kweon <minjung@physi.uni-heidelberg.de>
25 #include <TIterator.h>
26 #include <TParticle.h>
28 #include <AliESDVertex.h>
29 #include <AliESDEvent.h>
30 #include <AliAODEvent.h>
31 #include <AliVTrack.h>
32 #include <AliESDtrack.h>
33 #include <AliAODTrack.h>
34 #include "AliHFEsecVtx.h"
35 #include <AliKFParticle.h>
36 #include <AliKFVertex.h>
38 #include <AliMCEvent.h>
39 #include <AliAODMCParticle.h>
40 #include "AliHFEpairs.h"
41 #include "AliHFEsecVtxs.h"
42 #include "AliHFEtrackFilter.h"
43 #include "AliHFEmcQA.h"
44 #include "AliHFEtools.h"
46 ClassImp(AliHFEsecVtx)
48 //_______________________________________________________________________________________________
49 AliHFEsecVtx::AliHFEsecVtx():
87 // Default constructor
93 //_______________________________________________________________________________________________
94 AliHFEsecVtx::AliHFEsecVtx(const AliHFEsecVtx &p):
101 ,fUseMCPID(p.fUseMCPID)
103 ,fNparents(p.fNparents)
107 ,fNoOfHFEpairs(p.fNoOfHFEpairs)
108 ,fNoOfHFEsecvtxs(p.fNoOfHFEsecvtxs)
109 ,fArethereSecVtx(p.fArethereSecVtx)
118 ,fSignedLxy(p.fSignedLxy)
119 ,fSignedLxy2(p.fSignedLxy2)
121 ,fInvmass(p.fInvmass)
122 ,fInvmassSigma(p.fInvmassSigma)
125 ,fNsectrk2prim(p.fNsectrk2prim)
126 ,fVtxchi2Tightcut(p.fVtxchi2Tightcut)
127 ,fVtxchi2Loosecut(p.fVtxchi2Loosecut)
135 fFilter = new AliHFEtrackFilter(*p.fFilter);
138 //_______________________________________________________________________________________________
140 AliHFEsecVtx::operator=(const AliHFEsecVtx &)
143 // Assignment operator
146 AliInfo("Not yet implemented.");
150 //_______________________________________________________________________________________________
151 AliHFEsecVtx::~AliHFEsecVtx()
157 //cout << "Analysis Done." << endl;
161 //__________________________________________
162 void AliHFEsecVtx::Init()
165 // set pdg code and index
170 fParentSelect[0][0] = 411;
171 fParentSelect[0][1] = 421;
172 fParentSelect[0][2] = 431;
173 fParentSelect[0][3] = 4122;
174 fParentSelect[0][4] = 4132;
175 fParentSelect[0][5] = 4232;
176 fParentSelect[0][6] = 4332;
178 fParentSelect[1][0] = 511;
179 fParentSelect[1][1] = 521;
180 fParentSelect[1][2] = 531;
181 fParentSelect[1][3] = 5122;
182 fParentSelect[1][4] = 5132;
183 fParentSelect[1][5] = 5232;
184 fParentSelect[1][6] = 5332;
186 // momentum ranges to apply pt dependent cuts
195 // momentum dependent DCA cut values (preliminary)
203 fFilter = new AliHFEtrackFilter("SecVtxFilter");
204 fFilter->MakeCutStepRecKineITSTPC();
205 fFilter->MakeCutStepPrimary();
208 void AliHFEsecVtx::Process(AliVTrack *signalTrack){
212 //if(signalTrack->Pt() < 1.0) return;
215 AliESDtrack *track = dynamic_cast<AliESDtrack *>(signalTrack);
218 AliDebug(1, "no esd track pointer, return\n");
222 FillHistos(0,track); // wo any cuts
226 AliESDtrack *htrack = 0x0;
228 fFilter->FilterTracks(fESD1);
229 TObjArray *candidates = fFilter->GetFilteredTracks();
230 TIterator *trackIter = candidates->MakeIterator();
231 while((htrack = dynamic_cast<AliESDtrack *>(trackIter->Next()))){
232 if(track->GetID() == htrack->GetID()) continue; // since it is for tagging single electron, don't need additional condition
233 if (htrack->Pt()<1.0) continue;
234 PairAnalysis(track, htrack, htrack->GetID()); // e-h pairing
237 for(int ip=0; ip<HFEpairs()->GetEntriesFast(); ip++){
239 AliHFEpairs *pair = (AliHFEpairs*) (HFEpairs()->UncheckedAt(ip));
240 //if(!(pair->GetPairCode()>1. && pair->GetPairCode()<4.)) // apply various cuts
241 if(pair->GetKFChi2()>5.) // only apply vertex chi2 cut for the moment
242 HFEpairs()->RemoveAt(ip);
245 HFEpairs()->Compress();
246 if(HFEpairs()->GetEntriesFast()) FillHistos(1,track); // after paired
247 if(HFEpairs()->GetEntriesFast()) RunSECVTX(track); // secondary vertexing with e,h1,h2,.. tracks
248 if(HFEsecvtxs()->GetEntriesFast()) FillHistos(2,track); // after secvtxing
249 for(int ip=0; ip<HFEsecvtxs()->GetEntriesFast(); ip++){
250 AliHFEsecVtxs *secvtx=0x0;
251 secvtx = (AliHFEsecVtxs*) (HFEsecvtxs()->UncheckedAt(ip));
252 // here you apply cuts, then if it doesn't pass the cut, remove it from the HFEsecvtxs()
253 if(!(secvtx->GetInvmass()>2.0 && secvtx->GetInvmass()<5.2) || !(secvtx->GetSignedLxy2()>0.08 && secvtx->GetSignedLxy2()<1.5) || !(secvtx->GetKFIP2()>-0.1 && secvtx->GetKFIP2()<0.1))
254 HFEsecvtxs()->RemoveAt(ip);
257 // fill histos for raw spectra
258 if(HFEsecvtxs()->GetEntriesFast()) FillHistos(3,track); //after secvtx cut
264 //_______________________________________________________________________________________________
265 void AliHFEsecVtx::CreateHistograms(TList * const qaList)
273 fSecVtxList = qaList;
274 fSecVtxList->SetName("SecVtx");
283 fkSourceLabel[kAll]="all";
284 fkSourceLabel[kDirectCharm]="directCharm";
285 fkSourceLabel[kDirectBeauty]="directBeauty";
286 fkSourceLabel[kBeautyCharm]="beauty2charm";
287 fkSourceLabel[kGamma]="gamma";
288 fkSourceLabel[kPi0]="pi0";
289 fkSourceLabel[kElse]="others";
290 fkSourceLabel[kBeautyGamma]="beauty22gamma";
291 fkSourceLabel[kBeautyPi0]="beauty22pi0";
292 fkSourceLabel[kBeautyElse]="beauty22others";
295 TString hnopt="secvtx_";
296 for (Int_t isource = 0; isource < 10; isource++ ){
300 //qaList->AddLast(fSecVtxList);
303 //_______________________________________________________________________________________________
304 void AliHFEsecVtx::GetPrimaryCondition()
307 // get primary characteristics and set
311 AliKFVertex primVtxCopy(*(fESD1->GetPrimaryVertex()));
312 if( primVtxCopy.GetNDF() <1 ) return;
313 fPVx = primVtxCopy.GetX();
314 fPVy = primVtxCopy.GetY();
317 AliKFVertex primVtxCopy(*(fAOD1->GetPrimaryVertex()));
318 if( primVtxCopy.GetNDF() <1 ) return;
319 fPVx = primVtxCopy.GetX();
320 fPVy = primVtxCopy.GetY();
324 //_______________________________________________________________________________________________
325 void AliHFEsecVtx::PairAnalysis(AliVTrack* track1, AliVTrack* track2, Int_t index2)
328 // calculate e-h pair characteristics and tag pair
331 //later consider the below
332 Float_t dca1[2]={-999.,-999.}, dca2[2]={-999.,-999.};
333 Float_t cov1[3]={-999.,-999.,-999.}, cov2[3]={-999.,-999.,-999.};
335 Double_t dca1aod[2]={-999.,-999.}, dca2aod[2]={-999.,-999.};
336 Double_t cov1aod[3]={-999.,-999.,-999.}, cov2aod[3]={-999.,-999.,-999.};
338 if (IsAODanalysis()){
339 const AliAODVertex *primVtx = fAOD1->GetPrimaryVertex();
340 AliESDtrack esdTrk1(track1);
341 AliESDtrack esdTrk2(track2);
342 esdTrk1.PropagateToDCA(primVtx,0.,10000.,dca1aod,cov1aod);
343 esdTrk2.PropagateToDCA(primVtx,0.,10000.,dca2aod,cov2aod);
346 ((AliESDtrack*)track1)->GetImpactParameters(dca1,cov1);
347 ((AliESDtrack*)track2)->GetImpactParameters(dca2,cov2);
350 // apply pt dependent dca cut on hadrons
351 /*for(int ibin=0; ibin<6; ibin++){
352 if((track2->Pt()>fPtRng[ibin] && track2->Pt()<fPtRng[ibin+1]) && TMath::Abs(dca2[0])<fDcaCut[ibin]) return;
355 // get KF particle input pid
356 Int_t pdg1 = GetPDG(track1);
357 Int_t pdg2 = GetPDG(track2);
359 if(pdg1==-1 || pdg2==-1) {
360 //printf("out if considered pid range \n");
364 // create KF particle of pair
365 if(IsAODanalysis()) AliKFParticle::SetField(fAOD1->GetMagneticField());
366 else AliKFParticle::SetField(fESD1->GetMagneticField());
368 AliKFParticle kfTrack[2];
369 kfTrack[0] = AliKFParticle(*track1, pdg1);
370 kfTrack[1] = AliKFParticle(*track2, pdg2);
372 AliKFParticle kfSecondary(kfTrack[0],kfTrack[1]);
374 //secondary vertex point from kf particle
375 Double_t kfx = kfSecondary.GetX();
376 Double_t kfy = kfSecondary.GetY();
377 //Double_t kfz = kfSecondary.GetZ();
379 //momentum at the decay point from kf particle
380 Double_t kfpx = kfSecondary.GetPx();
381 Double_t kfpy = kfSecondary.GetPy();
382 //Double_t kfpz = kfSecondary.GetPz();
385 /* //directly use of ESD vertex
386 const AliESDVertex *pvertex = fESD1->GetPrimaryVertex();
388 pvertex->GetXYZ(xyzVtx);
390 Double_t dx = kfx-xyzVtx[0];
391 Double_t dy = kfy-xyzVtx[1];*/
393 AliKFVertex primVtxCopy(*(fESD1->GetPrimaryVertex()));
394 if( primVtxCopy.GetNDF() <1 ) return;
395 fPVx = primVtxCopy.GetX();
396 fPVy = primVtxCopy.GetY();
398 // printf("esdx= %lf kfx= %lf esdy= %lf kfy= %lf\n",xyzVtx[0],fPVx,xyzVtx[1],fPVy);
400 Double_t dx = kfx-fPVx;
401 Double_t dy = kfy-fPVy;
403 // discriminating variables
404 // invariant mass of the KF particle
405 Double_t invmass = -1;
406 Double_t invmassSigma = -1;
407 kfSecondary.GetMass(invmass,invmassSigma);
409 // chi2 of the KF particle
410 Double_t kfchi2 = -1;
411 if(kfSecondary.GetNDF()>0) kfchi2 = TMath::Sqrt(TMath::Abs(kfSecondary.GetChi2()/kfSecondary.GetNDF()));
413 // opening angle between two particles in XY plane
414 Double_t phi = kfTrack[0].GetAngleXY(kfTrack[1]);
415 Double_t cosphi = TMath::Cos(phi);
417 // DCA from primary to e-h KF particle (impact parameter of KF particle)
418 Double_t vtx[2]={fPVx, fPVy};
419 Double_t kfip = kfSecondary.GetDistanceFromVertexXY(vtx);
421 // projection of kf vertex vector to the kf momentum direction
422 Double_t signedLxy=-999.;
423 if((dx*kfpx+dy*kfpy)>0) signedLxy = TMath::Sqrt(dx*dx+dy*dy);
424 if((dx*kfpx+dy*kfpy)<0) signedLxy = -1*TMath::Sqrt(dx*dx+dy*dy);
425 //[the other way to think about]
426 //Double_t psqr = kfpx*kfpx+kfpy*kfpy;
427 //if(psqr>0) signedLxy=(dx*kfpx+dy*kfpy)/TMath::Sqrt(psqr);
429 //recalculating primary vertex after removing secvtx tracks --------------------------
431 trkid[0] = track1->GetID();
432 trkid[1] = track2->GetID();
434 RecalcPrimvtx(2, trkid, kfTrack);
435 Double_t dx2 = kfx-fPVx2;
436 Double_t dy2 = kfy-fPVy2;
438 // IP of sec particle recalculated based on recalculated primary vertex
439 Double_t vtx2[2]={fPVx2, fPVy2};
440 Double_t kfip2 = kfSecondary.GetDistanceFromVertexXY(vtx2);
441 // signed Lxy recalculated based on recalculated primary vertex
442 Double_t signedLxy2=-999.;
443 if((dx2*kfpx+dy2*kfpy)>0) signedLxy2 = TMath::Sqrt(dx2*dx2+dy2*dy2);
444 if((dx2*kfpx+dy2*kfpy)<0) signedLxy2 = -1*TMath::Sqrt(dx2*dx2+dy2*dy2);
445 //------------------------------------------------------------------------------------
449 if (HasMCData()) paircode = GetPairCode(track1,track2);
452 hfepair.SetTrkLabel(index2);
453 hfepair.SetInvmass(invmass);
454 hfepair.SetKFChi2(kfchi2);
455 hfepair.SetOpenangle(phi);
456 hfepair.SetCosOpenangle(cosphi);
457 hfepair.SetSignedLxy(signedLxy);
458 hfepair.SetSignedLxy2(signedLxy2);
459 hfepair.SetKFIP(kfip);
460 hfepair.SetKFIP2(kfip2);
461 hfepair.SetPairCode(paircode);
462 AddHFEpairToArray(&hfepair);
465 // fill into container for later QA
473 //if(cov1[0]>0) dataE[6]=Double_t(dca1[0]/cov1[0]);
474 //if(cov2[0]>0) dataE[7]=Double_t(dca2[0]/cov2[0]);
475 //dataE[6]=track1->Pt();
476 //dataE[7]=track2->Pt();
477 //dataE[6]=dca1[0]; //mjtmp
478 //dataE[7]=dca2[0]; //mjtmp
479 //dataE[8]=TMath::Abs(dca1[0]);
480 //dataE[9]=TMath::Abs(dca2[0]);
482 fPairQA->Fill(dataE);
486 //_______________________________________________________________________________________________
487 void AliHFEsecVtx::RunSECVTX(AliVTrack *track)
490 // run secondary vertexing algorithm and do tagging
493 //printf("number of considered pairs= %d\n",HFEpairs()->GetEntriesFast());
494 FindSECVTXCandid(track);
497 //_______________________________________________________________________________________________
498 void AliHFEsecVtx::FindSECVTXCandid(AliVTrack *track)
501 // find secondary vertex candidate and store them into container
504 AliVTrack *htrack[20];
505 //Int_t htracklabel[20];
506 //Int_t paircode[20];
507 //Double_t vtxchi2[20];
508 //Double_t dataE[7]={-999.,-999.,-999.,-999.,-1.,0,0};
510 fVtxchi2Tightcut=3.; // tight cut for pair
511 fVtxchi2Loosecut=5.; // loose cut for secvtx
513 if (HFEpairs()->GetEntriesFast()>20){
514 AliDebug(3, "number of paired hadron is over maximum(20)");
518 // get paired track objects
519 AliHFEpairs *pair=0x0;
520 if (IsAODanalysis()){
521 for (int ip=0; ip<HFEpairs()->GetEntriesFast(); ip++){
522 pair = (AliHFEpairs*) (HFEpairs()->UncheckedAt(ip));
523 //htracklabel[ip] = pair->GetTrkLabel();
524 htrack[ip] = fAOD1->GetTrack(pair->GetTrkLabel());
525 //if(pair->GetPairCode()==2 || pair->GetPairCode()==3) paircode[ip]=1;
526 //else paircode[ip]=0;
527 //vtxchi2[ip] = pair->GetKFChi2();
531 for (int ip=0; ip<HFEpairs()->GetEntriesFast(); ip++){
532 pair = (AliHFEpairs*) (HFEpairs()->UncheckedAt(ip));
533 //htracklabel[ip] = pair->GetTrkLabel();
534 htrack[ip] = fESD1->GetTrack(pair->GetTrkLabel());
535 //if(pair->GetPairCode()==2 || pair->GetPairCode()==3) paircode[ip]=1;
536 //else paircode[ip]=0;
537 //vtxchi2[ip] = pair->GetKFChi2();
541 Int_t nPairs = HFEpairs()->GetEntriesFast();
544 // 1 electron candidate + 1 track
546 if (pair->GetKFChi2() < fVtxchi2Tightcut) { // you can also put single track cut -> here you apply very tight cut for the pair
547 Fill2TrkSECVTX(track, pair);
551 //--------------------------------------------------------------
553 // 1 electron candidate + 2 tracks
555 CalcSECVTXProperty(track, htrack[0], htrack[1]); // calculate secondary vertex property
557 if (fKFchi2 < fVtxchi2Loosecut) { // -> here you apply rather loose cut
558 Fill3TrkSECVTX(track, 0, 1);
560 else{ // if doesn't pass the sec vtx chi2 cut
561 for(int jp=0; jp<2; jp++){
562 pair = (AliHFEpairs*) (HFEpairs()->UncheckedAt(jp));
563 if (pair->GetKFChi2() < fVtxchi2Tightcut){
564 Fill2TrkSECVTX(track, pair);
570 //--------------------------------------------------------------
572 // 1 electron candidate + 3 tracks
574 CalcSECVTXProperty(track, htrack[0], htrack[1], htrack[2]); // calculate secondary vertex property
576 if (fKFchi2 < fVtxchi2Loosecut) {
577 Fill4TrkSECVTX(track, 0, 1, 2);
581 for (int i=0; i<nPairs-1; i++){
582 for (int j=i+1; j<nPairs; j++){
583 CalcSECVTXProperty(track, htrack[i], htrack[j]);
584 if (fKFchi2 < fVtxchi2Loosecut) {
586 Fill3TrkSECVTX(track, i, j);
590 if(!fArethereSecVtx){
591 for(int jp=0; jp<nPairs; jp++){
592 pair = (AliHFEpairs*) (HFEpairs()->UncheckedAt(jp));
593 if (pair->GetKFChi2() < fVtxchi2Tightcut){
594 Fill2TrkSECVTX(track, pair);
601 //--------------------------------------------------------------
603 // 1 electron candidate + more than 3 tracks
606 for (int ih1=0; ih1<nPairs-2; ih1++){
607 for (int ih2=ih1+1; ih2<nPairs-1; ih2++){
608 for (int ih3=ih2+1; ih3<nPairs; ih3++){
609 CalcSECVTXProperty(track, htrack[ih1], htrack[ih2], htrack[ih3]); // calculate secondary vertex property
610 if (fKFchi2 < fVtxchi2Loosecut) {
612 Fill4TrkSECVTX(track, ih1, ih2, ih3);
617 if (!fArethereSecVtx){
619 for (int i=0; i<nPairs-1; i++){
620 for (int j=i+1; j<nPairs; j++){
621 CalcSECVTXProperty(track, htrack[i], htrack[j]);
622 if (fKFchi2 < fVtxchi2Loosecut) {
624 Fill3TrkSECVTX(track, i, j);
629 if (!fArethereSecVtx){
630 for(int jp=0; jp<nPairs; jp++){
631 pair = (AliHFEpairs*) (HFEpairs()->UncheckedAt(jp));
632 if (pair->GetKFChi2() < fVtxchi2Tightcut){
633 Fill2TrkSECVTX(track, pair);
639 //--------------------------------------------------------------
643 //_______________________________________________________________________________________________
644 void AliHFEsecVtx::Fill4TrkSECVTX(AliVTrack* track, Int_t ipair, Int_t jpair, Int_t kpair)
647 // fill 3 tracks' secondary vertex properties
650 Double_t dataE[9]={-999.,-999.,-999.,-999.,-1.,0,0,-999.,-999.};
652 Int_t paircode1 = 0, paircode2 = 0, paircode3 = 0;
653 Int_t htracklabel1 = 0, htracklabel2= 0;
656 AliHFEpairs *pair1=0x0;
657 AliHFEpairs *pair2=0x0;
658 AliHFEpairs *pair3=0x0;
659 pair1 = (AliHFEpairs*) (HFEpairs()->UncheckedAt(ipair));
660 pair2 = (AliHFEpairs*) (HFEpairs()->UncheckedAt(jpair));
661 pair3 = (AliHFEpairs*) (HFEpairs()->UncheckedAt(kpair));
663 htracklabel1 = pair1->GetTrkLabel();
664 htracklabel2 = pair2->GetTrkLabel();
666 if (pair1->GetPairCode()==2 || pair1->GetPairCode()==3) paircode1=1;
668 if (pair2->GetPairCode()==2 || pair2->GetPairCode()==3) paircode2=1;
670 if (pair3->GetPairCode()==2 || pair3->GetPairCode()==3) paircode3=1;
674 AliHFEsecVtxs hfesecvtx;
675 hfesecvtx.SetTrkLabel1(htracklabel1); // mj: not much meaningful for the moment
676 hfesecvtx.SetTrkLabel2(htracklabel2); // mj: not much meaningful for the moment
677 if(HasMCData()) hfesecvtx.SetMCCode(GetElectronSource(TMath::Abs(track->GetLabel())));
678 hfesecvtx.SetKFChi2(fKFchi2);
679 hfesecvtx.SetInvmass(fInvmass);
680 hfesecvtx.SetSignedLxy(fSignedLxy);
681 hfesecvtx.SetSignedLxy2(fSignedLxy2);
682 hfesecvtx.SetKFIP(fKFip);
683 hfesecvtx.SetKFIP2(fKFip2);
684 AddHFEsecvtxToArray(&hfesecvtx);
691 if(HasMCData()) dataE[4]=GetElectronSource(TMath::Abs(track->GetLabel()));
692 dataE[5]=4; //# of associated tracks
693 if(paircode1 & paircode2 & paircode3) dataE[6]=1;
694 else if(!paircode1 & !paircode2 & !paircode3) dataE[6]=0;
696 dataE[7]=fSignedLxy2;
697 dataE[8]=track->Pt();
698 fSecvtxQA->Fill(dataE);
701 //_______________________________________________________________________________________________
702 void AliHFEsecVtx::Fill3TrkSECVTX(AliVTrack* track, Int_t ipair, Int_t jpair)
705 // fill 3 tracks' secondary vertex properties
708 Double_t dataE[9]={-999.,-999.,-999.,-999.,-1.,0,0,-999.,-999.};
710 Int_t paircode1 = 0, paircode2 = 0;
711 Int_t htracklabel1 = 0, htracklabel2 = 0;
714 AliHFEpairs *pair1=0x0;
715 AliHFEpairs *pair2=0x0;
716 pair1 = (AliHFEpairs*) (HFEpairs()->UncheckedAt(ipair));
717 pair2 = (AliHFEpairs*) (HFEpairs()->UncheckedAt(jpair));
719 htracklabel1 = pair1->GetTrkLabel();
720 htracklabel2 = pair2->GetTrkLabel();
722 if (pair1->GetPairCode()==2 || pair1->GetPairCode()==3) paircode1=1;
724 if (pair2->GetPairCode()==2 || pair2->GetPairCode()==3) paircode2=1;
728 // fill secondary vertex container
729 AliHFEsecVtxs hfesecvtx;
730 hfesecvtx.SetTrkLabel1(htracklabel1);
731 hfesecvtx.SetTrkLabel2(htracklabel2);
732 if(HasMCData()) hfesecvtx.SetMCCode(GetElectronSource(TMath::Abs(track->GetLabel())));
733 hfesecvtx.SetKFChi2(fKFchi2);
734 hfesecvtx.SetInvmass(fInvmass);
735 hfesecvtx.SetSignedLxy(fSignedLxy);
736 hfesecvtx.SetSignedLxy2(fSignedLxy2);
737 hfesecvtx.SetKFIP(fKFip);
738 hfesecvtx.SetKFIP2(fKFip2);
739 AddHFEsecvtxToArray(&hfesecvtx);
742 // fill debugging THnSparse
747 if(HasMCData()) dataE[4]=GetElectronSource(TMath::Abs(track->GetLabel()));
749 if(paircode1 & paircode2) dataE[6]=1;
750 else if(!paircode1 & !paircode2) dataE[6]=0;
752 dataE[7]=fSignedLxy2;
753 dataE[8]=track->Pt();
754 fSecvtxQA->Fill(dataE);
758 //_______________________________________________________________________________________________
759 void AliHFEsecVtx::Fill2TrkSECVTX(AliVTrack* track, AliHFEpairs *pair)
762 // fill 2 tracks' secondary vertex properties
765 Double_t dataE[9]={-999.,-999.,-999.,-999.,-1.,0,0,-999.,-999.};
768 if (pair->GetPairCode()==2 || pair->GetPairCode()==3) paircode=1;
771 // fill secondary vertex container
772 AliHFEsecVtxs hfesecvtx;
773 hfesecvtx.SetTrkLabel1(pair->GetTrkLabel());
774 hfesecvtx.SetTrkLabel2(-999);
775 if(HasMCData()) hfesecvtx.SetMCCode(GetElectronSource(TMath::Abs(track->GetLabel())));
776 hfesecvtx.SetInvmass(pair->GetInvmass());
777 hfesecvtx.SetKFChi2(pair->GetKFChi2());
778 hfesecvtx.SetSignedLxy(pair->GetSignedLxy());
779 hfesecvtx.SetSignedLxy2(pair->GetSignedLxy2());
780 hfesecvtx.SetKFIP(pair->GetKFIP());
781 hfesecvtx.SetKFIP2(pair->GetKFIP2());
782 AddHFEsecvtxToArray(&hfesecvtx);
785 // fill debugging THnSparse
786 dataE[0]=pair->GetInvmass();
787 dataE[1]=pair->GetKFChi2();
788 dataE[2]=pair->GetSignedLxy();
789 dataE[3]=pair->GetKFIP();
790 if (HasMCData()) dataE[4]=GetElectronSource(TMath::Abs(track->GetLabel()));
791 dataE[5]=2; //# of associated tracks
793 dataE[7]=pair->GetSignedLxy2();
794 dataE[8]=track->Pt();
795 fSecvtxQA->Fill(dataE);
799 //_______________________________________________________________________________________________
800 void AliHFEsecVtx::CalcSECVTXProperty(AliVTrack* track1, AliVTrack* track2, AliVTrack* track3)
803 // calculate secondary vertex properties
806 // get KF particle input pid
807 Int_t pdg1 = GetPDG(track1);
808 Int_t pdg2 = GetPDG(track2);
809 Int_t pdg3 = GetPDG(track3);
811 if(pdg1==-1 || pdg2==-1 || pdg3==-1) {
812 //printf("out if considered pid range \n");
816 // create KF particle of pair
817 if(IsAODanalysis()) AliKFParticle::SetField(fAOD1->GetMagneticField());
818 else AliKFParticle::SetField(fESD1->GetMagneticField());
819 AliKFParticle kfTrack[3];
820 kfTrack[0] = AliKFParticle(*track1, pdg1);
821 kfTrack[1] = AliKFParticle(*track2, pdg2);
822 kfTrack[2] = AliKFParticle(*track3, pdg3);
824 AliKFParticle kfSecondary(kfTrack[0],kfTrack[1],kfTrack[2]);
825 //AliKFParticle kfSecondary(kfTrack1,kfTrack2,kfTrack3);
827 //secondary vertex point from kf particle
828 Double_t kfx = kfSecondary.GetX();
829 Double_t kfy = kfSecondary.GetY();
830 //Double_t kfz = kfSecondary.GetZ();
832 //momentum at the decay point from kf particle
833 Double_t kfpx = kfSecondary.GetPx();
834 Double_t kfpy = kfSecondary.GetPy();
835 //Double_t kfpz = kfSecondary.GetPz();
837 Double_t dx = kfx-fPVx;
838 Double_t dy = kfy-fPVy;
840 // discriminating variables ----------------------------------------------------------
842 if(kfSecondary.GetNDF()>0) fKFchi2 = TMath::Sqrt(TMath::Abs(kfSecondary.GetChi2()/kfSecondary.GetNDF()));
844 // invariant mass of the KF particle
845 kfSecondary.GetMass(fInvmass,fInvmassSigma);
847 // DCA from primary to e-h KF particle (impact parameter of KF particle)
848 Double_t vtx[2]={fPVx, fPVy};
849 fKFip = kfSecondary.GetDistanceFromVertexXY(vtx);
851 if((dx*kfpx+dy*kfpy)>0) fSignedLxy= TMath::Sqrt(dx*dx+dy*dy);
852 if((dx*kfpx+dy*kfpy)<0) fSignedLxy= -1*TMath::Sqrt(dx*dx+dy*dy);
853 //[the other way to think about] - projection of kf vertex vector to the kf momentum direction
854 //Double_t psqr = kfpx*kfpx+kfpy*kfpy;
855 //if(psqr>0) fSignedLxy=(dx*kfpx+dy*kfpy)/TMath::Sqrt(psqr);
858 //recalculating primary vertex after removing secvtx tracks --------------------------
860 trkid[0] = track1->GetID();
861 trkid[1] = track2->GetID();
862 trkid[2] = track3->GetID();
864 RecalcPrimvtx(3, trkid, kfTrack);
865 Double_t dx2 = kfx-fPVx2;
866 Double_t dy2 = kfy-fPVy2;
868 // IP of sec particle recalculated based on recalculated primary vertex
869 Double_t vtx2[2]={fPVx2, fPVy2};
870 fKFip2 = kfSecondary.GetDistanceFromVertexXY(vtx2);
871 // signed Lxy recalculated based on recalculated primary vertex
872 if((dx2*kfpx+dy2*kfpy)>0) fSignedLxy2= TMath::Sqrt(dx2*dx2+dy2*dy2);
873 if((dx2*kfpx+dy2*kfpy)<0) fSignedLxy2= -1*TMath::Sqrt(dx2*dx2+dy2*dy2);
874 //------------------------------------------------------------------------------------
878 //_______________________________________________________________________________________________
879 void AliHFEsecVtx::CalcSECVTXProperty(AliVTrack* track1, AliVTrack* track2, AliVTrack* track3, AliVTrack* track4)
882 // calculate secondary vertex properties
885 // get KF particle input pid
886 Int_t pdg1 = GetPDG(track1);
887 Int_t pdg2 = GetPDG(track2);
888 Int_t pdg3 = GetPDG(track3);
889 Int_t pdg4 = GetPDG(track4);
891 if(pdg1==-1 || pdg2==-1 || pdg3==-1 || pdg4==-1) {
892 //printf("out if considered pid range \n");
896 // create KF particle of pair
897 if(IsAODanalysis()) AliKFParticle::SetField(fAOD1->GetMagneticField());
898 else AliKFParticle::SetField(fESD1->GetMagneticField());
900 AliKFParticle kfTrack[4];
901 kfTrack[0] = AliKFParticle(*track1, pdg1);
902 kfTrack[1] = AliKFParticle(*track2, pdg2);
903 kfTrack[2] = AliKFParticle(*track3, pdg3);
904 kfTrack[3] = AliKFParticle(*track4, pdg4);
906 AliKFParticle kfSecondary(kfTrack[0],kfTrack[1],kfTrack[2],kfTrack[3]);
908 //secondary vertex point from kf particle
909 Double_t kfx = kfSecondary.GetX();
910 Double_t kfy = kfSecondary.GetY();
911 //Double_t kfz = kfSecondary.GetZ();
913 //momentum at the decay point from kf particle
914 Double_t kfpx = kfSecondary.GetPx();
915 Double_t kfpy = kfSecondary.GetPy();
916 //Double_t kfpz = kfSecondary.GetPz();
918 Double_t dx = kfx-fPVx;
919 Double_t dy = kfy-fPVy;
921 // discriminating variables ----------------------------------------------------------
923 if(kfSecondary.GetNDF()>0) fKFchi2 = TMath::Sqrt(TMath::Abs(kfSecondary.GetChi2()/kfSecondary.GetNDF()));
925 // invariant mass of the KF particle
926 kfSecondary.GetMass(fInvmass,fInvmassSigma);
928 // DCA from primary to e-h KF particle (impact parameter of KF particle)
929 Double_t vtx[2]={fPVx, fPVy};
930 fKFip = kfSecondary.GetDistanceFromVertexXY(vtx);
932 if((dx*kfpx+dy*kfpy)>0) fSignedLxy= TMath::Sqrt(dx*dx+dy*dy);
933 if((dx*kfpx+dy*kfpy)<0) fSignedLxy= -1*TMath::Sqrt(dx*dx+dy*dy);
934 //[the other way to think about] - projection of kf vertex vector to the kf momentum direction
935 //Double_t psqr = kfpx*kfpx+kfpy*kfpy;
936 //if(psqr>0) fSignedLxy=(dx*kfpx+dy*kfpy)/TMath::Sqrt(psqr);
938 //recalculating primary vertex after removing secvtx tracks --------------------------
940 trkid[0] = track1->GetID();
941 trkid[1] = track2->GetID();
942 trkid[2] = track3->GetID();
943 trkid[3] = track4->GetID();
945 RecalcPrimvtx(4, trkid, kfTrack);
946 Double_t dx2 = kfx-fPVx2;
947 Double_t dy2 = kfy-fPVy2;
949 // IP of sec particle recalculated based on recalculated primary vertex
950 Double_t vtx2[2]={fPVx2, fPVy2};
951 fKFip2 = kfSecondary.GetDistanceFromVertexXY(vtx2);
952 // signed Lxy recalculated based on recalculated primary vertex
953 if((dx2*kfpx+dy2*kfpy)>0) fSignedLxy2= TMath::Sqrt(dx2*dx2+dy2*dy2);
954 if((dx2*kfpx+dy2*kfpy)<0) fSignedLxy2= -1*TMath::Sqrt(dx2*dx2+dy2*dy2);
955 //------------------------------------------------------------------------------------
959 //_______________________________________________________________________________________________
960 void AliHFEsecVtx::RecalcPrimvtx(Int_t nkftrk, const Int_t * const trkid, const AliKFParticle * const kftrk){
962 // reccalculate primary vertex after removing considering track in the calculation
965 const AliESDVertex *primvtx = fESD1->GetPrimaryVertex();
967 AliKFVertex kfESDprimary;
968 Int_t n = primvtx->GetNIndices();
973 if (n>0 && primvtx->GetStatus()){
974 kfESDprimary = AliKFVertex(*primvtx);
975 UShort_t *priIndex = primvtx->GetIndices();
976 for(Int_t j=0; j<nkftrk; j++){
977 for (Int_t i=0;i<n;i++){
978 Int_t idx = Int_t(priIndex[i]);
979 if (idx == trkid[j]){
980 kfESDprimary -= kftrk[j];
987 fPVx2 = kfESDprimary.GetX();
988 fPVy2 = kfESDprimary.GetY();
992 //_______________________________________________________________________________________________
993 Int_t AliHFEsecVtx::GetMCPID(const AliESDtrack *track)
999 AliMCParticle *mctrack = NULL;
1000 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(track->GetLabel()))))) return 0;
1001 TParticle *mcpart = mctrack->Particle();
1003 if ( !mcpart ) return 0;
1004 Int_t pdgCode = mcpart->GetPdgCode();
1009 //_______________________________________________________________________________________________
1010 Int_t AliHFEsecVtx::GetPairOriginESD(AliESDtrack* trk1, AliESDtrack* trk2)
1013 // return pdg code of the origin(source) of the pair
1016 // ---*---*---*-----ancester A----- track1
1019 // => if they originated from same ancester,
1020 // then return "the absolute value of pdg code of ancester A"
1022 // ---*---*---B hadron-----ancester A----- track1
1025 // => if they originated from same ancester, and this ancester originally comes from B hadrons
1026 // then return -1*"the absolute value of pdg code of ancester A"
1028 // caution : it can also return parton pdg code if it originated from same string or gluon spliting.
1031 if (trk1->GetLabel()<0 || trk2->GetLabel()<0) return 0;
1033 AliMCParticle *mctrack = NULL;
1034 AliMCParticle *mctrack1 = NULL;
1035 AliMCParticle *mctrack2 = NULL;
1036 if(!(mctrack1 = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(trk1->GetLabel()))))) return 0;
1037 if(!(mctrack2 = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(trk2->GetLabel()))))) return 0;
1038 TParticle *part1 = mctrack1->Particle();
1039 TParticle *part2 = mctrack2->Particle();
1041 TParticle* part2cp = part2;
1042 if (!(part1) || !(part2)) return 0;
1046 //if the two tracks' mother's label is same, get the mother info
1047 //in case of charm, check if it originated from beauty
1048 for (Int_t i=0; i<10; i++){ //check up to 10 ancesters
1049 Int_t label1 = part1->GetFirstMother();
1050 if (label1 < 0) return 0;
1052 for (Int_t j=0; j<10; j++){ //check up to 10 ancesters
1053 Int_t label2 = part2->GetFirstMother();
1054 if (label2 < 0) break;
1056 if (label1 == label2){ //check if two tracks are originated from same mother
1057 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(label2))))) return 0;
1058 TParticle* commonmom = mctrack->Particle();
1060 srcpdg = abs(commonmom->GetPdgCode());
1062 //check ancester to see if it is originally from beauty
1063 for (Int_t k=0; k<10; k++){ //check up to 10 ancesters
1064 Int_t ancesterlabel = commonmom->GetFirstMother();
1065 if (ancesterlabel < 0) return srcpdg; // if there is no more commonancester, return commonmom's pdg
1067 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(ancesterlabel))))) return 0;
1068 TParticle* commonancester = mctrack->Particle();
1070 Int_t ancesterpdg = abs(commonancester->GetPdgCode());
1072 for (Int_t l=0; l<fNparents; l++){
1073 if (abs(ancesterpdg)==fParentSelect[1][l]){
1074 srcpdg = -1*srcpdg; //multiply -1 for hadron from bottom
1078 commonmom = commonancester;
1081 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(label2))))) return 0;
1082 part2 = mctrack->Particle(); //if their mother is different, go to earlier generation of 2nd particle
1084 if (!(part2)) break;
1086 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(label1))))) return 0;
1087 part1 = mctrack->Particle(); //if their mother is different, go to earlier generation of 1st particle
1089 if (!(part1)) return 0;
1095 //_______________________________________________________________________________________________
1096 Int_t AliHFEsecVtx::GetPairOriginAOD(AliAODTrack* trk1, AliAODTrack* trk2)
1100 // return pdg code of the origin(source) of the pair
1103 // ---*---*---*-----ancester A----- track1
1106 // => if they originated from same ancester,
1107 // then return "the absolute value of pdg code of ancester A"
1109 // ---*---*---B hadron-----ancester A----- track1
1112 // => if they originated from same ancester, and this ancester originally comes from B hadrons
1113 // then return -1*"the absolute value of pdg code of ancester A"
1115 // caution : it can also return parton pdg code if it originated from same string or gluon spliting.
1118 if (trk1->GetLabel()<0 || trk2->GetLabel()<0) return 0;
1119 AliAODMCParticle *part1 = (AliAODMCParticle*)fMCArray->At(trk1->GetLabel());
1120 AliAODMCParticle *part2 = (AliAODMCParticle*)fMCArray->At(trk2->GetLabel());
1121 AliAODMCParticle *part2cp = part2;
1122 if (!(part1) || !(part2)) return 0;
1126 //if the two tracks' mother's label is same, get the mother info
1127 //in case of charm, check if it originated from beauty
1128 for (Int_t i=0; i<10; i++){ //check up to 10 ancesters
1129 Int_t label1 = part1->GetMother();
1130 if (label1 < 0) return 0;
1132 for (Int_t j=0; j<10; j++){ //check up to 10 ancesters
1133 Int_t label2 = part2->GetMother();
1134 if (label2 < 0) return 0;
1136 if (label1 == label2){ //check if two tracks are originated from same mother
1137 AliAODMCParticle *commonmom = (AliAODMCParticle*)fMCArray->At(label1);
1138 srcpdg = abs(commonmom->GetPdgCode());
1140 //check ancester to see if it is originally from beauty
1141 for (Int_t k=0; k<10; k++){ //check up to 10 ancesters
1142 Int_t ancesterlabel = commonmom->GetMother();
1143 if (ancesterlabel < 0) return srcpdg; // if there is no more commonancester, return commonmom's pdg
1145 AliAODMCParticle *commonancester = (AliAODMCParticle*)fMCArray->At(ancesterlabel);
1146 Int_t ancesterpdg = abs(commonancester->GetPdgCode());
1148 for (Int_t l=0; l<fNparents; l++){
1149 if (abs(ancesterpdg)==fParentSelect[1][l]){
1150 srcpdg = -1*srcpdg; //multiply -1 for charm from bottom
1154 commonmom = commonancester;
1157 part2 = (AliAODMCParticle*)fMCArray->At(label2); //if their mother is different, go to earlier generation of 2nd particle
1158 if (!(part2)) break;
1160 part1 = (AliAODMCParticle*)fMCArray->At(label1); //if their mother is different, go to earlier generation of 2nd particle
1162 if (!(part1)) return 0;
1168 //_______________________________________________________________________________________________
1169 Int_t AliHFEsecVtx::GetPairCode(const AliVTrack* const trk1, const AliVTrack* const trk2)
1172 // return pair code which is predefinded as:
1173 // kDirectCharm, kDirectBeauty, kBeautyCharm, kGamma, kPi0,
1174 // kElse, kBeautyGamma, kBeautyPi0, kBeautyElse
1178 Int_t srccode = kElse;
1180 if(IsAODanalysis()) srcpdg = GetPairOriginAOD((AliAODTrack*)trk1,(AliAODTrack*)trk2);
1181 else srcpdg = GetPairOriginESD((AliESDtrack*)trk1,(AliESDtrack*)trk2);
1183 if (srcpdg < 0) srccode = kBeautyElse;
1184 for (Int_t i=0; i<fNparents; i++){
1185 if (abs(srcpdg)==fParentSelect[0][i]) {
1186 if (srcpdg>0) srccode = kDirectCharm;
1187 if (srcpdg<0) srccode = kBeautyCharm;
1189 if (abs(srcpdg)==fParentSelect[1][i]) {
1190 if (srcpdg>0) srccode = kDirectBeauty;
1191 if (srcpdg<0) return kElse;
1194 if (srcpdg == 22) srccode = kGamma;
1195 if (srcpdg == -22) srccode = kBeautyGamma;
1196 if (srcpdg == 111) srccode = kPi0;
1197 if (srcpdg == -111) srccode = kBeautyPi0;
1202 //_______________________________________________________________________________________________
1203 Int_t AliHFEsecVtx::GetElectronSource(Int_t iTrack)
1206 // return decay electron's origin
1210 AliDebug(1, "Stack label is negative, return\n");
1214 AliMCParticle *mctrack = NULL;
1215 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(iTrack))))) return -1;
1216 TParticle *mcpart = mctrack->Particle();
1219 AliDebug(1, "no mc particle, return\n");
1223 if ( abs(mcpart->GetPdgCode()) != 11 ) return kMisID;
1225 // if ( abs(mcpart->GetPdgCode()) != 11 ) return -1; // check if it is electron !
1227 Int_t iLabel = mcpart->GetFirstMother();
1229 AliDebug(1, "Stack label is negative, return\n");
1234 Bool_t isFinalOpenCharm = kFALSE;
1236 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(iLabel))))) return -1;
1237 TParticle *partMother = mctrack->Particle();
1239 Int_t maPdgcode = partMother->GetPdgCode();
1241 // if the mother is charmed hadron
1242 if ( int(abs(maPdgcode)/100.) == kCharm || int(abs(maPdgcode)/1000.) == kCharm ) {
1244 for (Int_t i=0; i<fNparents; i++){
1245 if (abs(maPdgcode)==fParentSelect[0][i]){
1246 isFinalOpenCharm = kTRUE;
1249 if (!isFinalOpenCharm) return -1;
1251 // iterate until you find B hadron as a mother or become top ancester
1252 for (Int_t i=1; i<100; i++){ // check back to the 100 generation older
1254 Int_t jLabel = partMother->GetFirstMother();
1256 origin = kDirectCharm;
1259 if (jLabel < 0){ // safety protection
1260 AliDebug(1, "Stack label is negative, return\n");
1264 // if there is an ancester
1265 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(jLabel))))) return -1;
1266 TParticle *grandMa = mctrack->Particle();
1268 Int_t grandMaPDG = grandMa->GetPdgCode();
1270 for (Int_t j=0; j<fNparents; j++){
1271 if (abs(grandMaPDG)==fParentSelect[1][j]){
1272 origin = kBeautyCharm;
1277 partMother = grandMa;
1278 } // end of iteration
1280 else if ( int(abs(maPdgcode)/100.) == kBeauty || int(abs(maPdgcode)/1000.) == kBeauty ) {
1281 for (Int_t i=0; i<fNparents; i++){
1282 if (abs(maPdgcode)==fParentSelect[1][i]){
1283 origin = kDirectBeauty;
1289 //============ gamma ================
1290 else if ( abs(maPdgcode) == 22 ) {
1293 // iterate until you find B hadron as a mother or become top ancester
1294 for (Int_t i=1; i<100; i++){ // check back to the 100 generation older
1296 Int_t jLabel = partMother->GetFirstMother();
1301 if (jLabel < 0){ // safety protection
1302 AliDebug(1, "Stack label is negative, return\n");
1306 // if there is an ancester
1307 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(jLabel))))) return -1;
1308 TParticle *grandMa = mctrack->Particle();
1310 Int_t grandMaPDG = grandMa->GetPdgCode();
1312 for (Int_t j=0; j<fNparents; j++){
1313 if (abs(grandMaPDG)==fParentSelect[1][j]){
1314 origin = kBeautyGamma;
1319 partMother = grandMa;
1320 } // end of iteration
1325 //============ pi0 ================
1326 else if ( abs(maPdgcode) == 111 ) {
1329 // iterate until you find B hadron as a mother or become top ancester
1330 for (Int_t i=1; i<100; i++){ // check back to the 100 generation older
1332 Int_t jLabel = partMother->GetFirstMother();
1337 if (jLabel < 0){ // safety protection
1338 AliDebug(1, "Stack label is negative, return\n");
1342 // if there is an ancester
1343 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(jLabel))))) return -1;
1344 TParticle *grandMa = mctrack->Particle();
1346 Int_t grandMaPDG = grandMa->GetPdgCode();
1348 for (Int_t j=0; j<fNparents; j++){
1349 if (abs(grandMaPDG)==fParentSelect[1][j]){
1350 origin = kBeautyPi0;
1355 partMother = grandMa;
1356 } // end of iteration
1363 // iterate until you find B hadron as a mother or become top ancester
1364 for (Int_t i=1; i<100; i++){ // check back to the 100 generation older
1366 Int_t jLabel = partMother->GetFirstMother();
1371 if (jLabel < 0){ // safety protection
1372 AliDebug(1, "Stack label is negative, return\n");
1376 // if there is an ancester
1377 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(jLabel))))) return -1;
1378 TParticle *grandMa = mctrack->Particle();
1380 Int_t grandMaPDG = grandMa->GetPdgCode();
1382 for (Int_t j=0; j<fNparents; j++){
1383 if (abs(grandMaPDG)==fParentSelect[1][j]){
1384 origin = kBeautyElse;
1389 partMother = grandMa;
1390 } // end of iteration
1396 //_______________________________________________________________________________________________
1397 Int_t AliHFEsecVtx::GetPDG(AliVTrack *track)
1400 // get KF particle input pdg for mass hypothesis
1405 if (fUseMCPID && HasMCData()){
1406 pdgCode = GetMCPDG(track);
1411 GetESDPID((AliESDtrack*)track, pid, prob);
1413 case 0: pdgCode = 11; break;
1414 case 1: pdgCode = 13; break;
1415 case 2: pdgCode = 211; break;
1416 case 3: pdgCode = 321; break;
1417 case 4: pdgCode = 2212; break;
1418 default: pdgCode = -1;
1422 Int_t pid = ((AliAODTrack*)track)->GetMostProbablePID();
1424 case 0: pdgCode = 11; break;
1425 case 1: pdgCode = 13; break;
1426 case 2: pdgCode = 211; break;
1427 case 3: pdgCode = 321; break;
1428 case 4: pdgCode = 2212; break;
1429 default: pdgCode = -1;
1436 //_______________________________________________________________________________________________
1437 Int_t AliHFEsecVtx::GetMCPDG(const AliVTrack *track)
1440 // return mc pdg code
1443 Int_t label = TMath::Abs(track->GetLabel());
1445 AliMCParticle *mctrack = NULL;
1447 if (IsAODanalysis()) {
1448 AliAODMCParticle *mcpart = (AliAODMCParticle*)fMCArray->At(label);
1449 if ( !mcpart ) return 0;
1450 pdgCode = mcpart->GetPdgCode();
1453 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(label))))) return 0;
1454 TParticle *mcpart = mctrack->Particle();
1456 if ( !mcpart ) return 0;
1457 pdgCode = mcpart->GetPdgCode();
1463 //______________________________________________________________________________
1464 void AliHFEsecVtx::GetESDPID(AliESDtrack *track, Int_t &recpid, Double_t &recprob)
1467 // calculate likehood for esd pid
1476 Double_t probability[5];
1478 // get probability of the diffenrent particle types
1479 track->GetESDpid(probability);
1481 // find most probable particle in ESD pid
1482 // 0:Electron - 1:Muon - 2:Pion - 3:Kaon - 4:Proton
1483 ipid = TMath::LocMax(5,probability);
1484 max = TMath::MaxElement(5,probability);
1490 //_____________________________________________________________________________
1491 void AliHFEsecVtx::AddHFEpairToArray(const AliHFEpairs* const pair)
1494 // Add a HFE pair to the array
1497 Int_t n = HFEpairs()->GetEntriesFast();
1498 if(n!=fNoOfHFEpairs)AliError(Form("fNoOfHFEpairs != HFEpairs()->GetEntriesFast %i != %i \n", fNoOfHFEpairs, n));
1499 new((*HFEpairs())[n]) AliHFEpairs(*pair);
1502 //_____________________________________________________________________________
1503 TClonesArray *AliHFEsecVtx::HFEpairs()
1506 // Returns the list of HFE pairs
1510 fHFEpairs = new TClonesArray("AliHFEpairs", 200);
1515 //_____________________________________________________________________________
1516 void AliHFEsecVtx::DeleteHFEpairs()
1519 // Delete the list of HFE pairs
1523 fHFEpairs->Delete();
1528 //_____________________________________________________________________________
1529 void AliHFEsecVtx::InitHFEpairs()
1532 // Initialization should be done before make all possible pairs for a given electron candidate
1538 //_____________________________________________________________________________
1539 void AliHFEsecVtx::AddHFEsecvtxToArray(const AliHFEsecVtxs* const secvtx)
1542 // Add a HFE secondary vertex to the array
1545 Int_t n = HFEsecvtxs()->GetEntriesFast();
1546 if(n!=fNoOfHFEsecvtxs)AliError(Form("fNoOfHFEsecvtxs != HFEsecvtxs()->GetEntriesFast %i != %i \n", fNoOfHFEsecvtxs, n));
1547 new((*HFEsecvtxs())[n]) AliHFEsecVtxs(*secvtx);
1550 //_____________________________________________________________________________
1551 TClonesArray *AliHFEsecVtx::HFEsecvtxs()
1554 // Returns the list of HFE secvtx
1558 fHFEsecvtxs = new TClonesArray("AliHFEsecVtxs", 200);
1563 //_____________________________________________________________________________
1564 void AliHFEsecVtx::DeleteHFEsecvtxs()
1567 // Delete the list of HFE pairs
1571 fHFEsecvtxs->Delete();
1572 //delete fHFEsecvtx;
1576 //_____________________________________________________________________________
1577 void AliHFEsecVtx::InitHFEsecvtxs()
1580 // Initialization should be done
1583 fNoOfHFEsecvtxs = 0;
1586 //____________________________________________________________
1587 void AliHFEsecVtx::MakeContainer(){
1593 const Int_t nDimPair=6;
1594 Int_t nBinPair[nDimPair] = {200, 500, 314, 2000, 2000, 13};
1595 //Int_t nBinPair[nDimPair] = {200, 500, 314, 2000, 2000, 13, 60, 60, 2000, 2000};
1596 const Double_t kInvmassmin = 0., kInvmassmax = 20.;
1597 const Double_t kKFChi2min = 0, kKFChi2max= 50;
1598 const Double_t kOpenanglemin = 0, kOpenanglemax = 3.14;
1599 const Double_t kSignedLxymin = -10, kSignedLxymax= 10;
1600 const Double_t kKFIPmin = -10, kKFIPmax= 10;
1601 const Double_t kPairCodemin = -1, kPairCodemax= 12;
1602 //const Double_t kPtmin = 0, kPtmax= 30;
1603 //const Double_t kDCAsigmin = -5, kDCAsigmax= 5;
1605 Double_t* binEdgesPair[nDimPair];
1606 for(Int_t ivar = 0; ivar < nDimPair; ivar++)
1607 binEdgesPair[ivar] = new Double_t[nBinPair[ivar] + 1];
1609 for(Int_t i=0; i<=nBinPair[0]; i++) binEdgesPair[0][i]=(Double_t)kInvmassmin + (kInvmassmax - kInvmassmin)/nBinPair[0]*(Double_t)i;
1610 for(Int_t i=0; i<=nBinPair[1]; i++) binEdgesPair[1][i]=(Double_t)kKFChi2min + (kKFChi2max - kKFChi2min)/nBinPair[1]*(Double_t)i;
1611 for(Int_t i=0; i<=nBinPair[2]; i++) binEdgesPair[2][i]=(Double_t)kOpenanglemin + (kOpenanglemax - kOpenanglemin)/nBinPair[2]*(Double_t)i;
1612 for(Int_t i=0; i<=nBinPair[3]; i++) binEdgesPair[3][i]=(Double_t)kSignedLxymin + (kSignedLxymax - kSignedLxymin)/nBinPair[3]*(Double_t)i;
1613 for(Int_t i=0; i<=nBinPair[4]; i++) binEdgesPair[4][i]=(Double_t)kKFIPmin + (kKFIPmax - kKFIPmin)/nBinPair[4]*(Double_t)i;
1614 for(Int_t i=0; i<=nBinPair[5]; i++) binEdgesPair[5][i]=(Double_t)kPairCodemin + (kPairCodemax - kPairCodemin)/nBinPair[5]*(Double_t)i;
1615 //for(Int_t i=0; i<=nBinPair[6]; i++) binEdgesPair[6][i]=(Double_t)kPtmin + (kPtmax - kPtmin)/nBinPair[6]*(Double_t)i;
1616 //for(Int_t i=0; i<=nBinPair[7]; i++) binEdgesPair[7][i]=binEdgesPair[6][i];
1617 //for(Int_t i=0; i<=nBinPair[6]; i++) binEdgesPair[6][i]=(Double_t)kDCAsigmin + (kDCAsigmax - kDCAsigmin)/nBinPair[6]*(Double_t)i;
1618 //for(Int_t i=0; i<=nBinPair[7]; i++) binEdgesPair[7][i]=binEdgesPair[6][i];
1620 fPairQA = new THnSparseF("pairQA", "QA for Pair; invmass[GeV/c^2]; KF chi2; opening angle; signed Lxy; KF ip; pair code; dca1; dca2", nDimPair, nBinPair);
1621 //fPairQA = new THnSparseF("pairQA", "QA for Pair; invmass[GeV/c^2]; KF chi2; opening angle; signed Lxy; KF ip; pair code; pt1; pt2; dca1; dca2", nDimPair, nBinPair);
1622 for(Int_t idim = 0; idim < nDimPair; idim++){
1623 fPairQA->SetBinEdges(idim, binEdgesPair[idim]);
1626 fSecVtxList->AddAt(fPairQA,0);
1628 const Int_t nDimSecvtx=9;
1629 Double_t* binEdgesSecvtx[nDimSecvtx];
1630 Int_t nBinSecvtx[nDimSecvtx] = {200, 500, 2000, 2000, 13, 10, 4, 2000, 500};
1631 const Double_t kNtrksmin = 0, kNtrksmax= 10;
1632 const Double_t kTrueBmin = 0, kTrueBmax= 4;
1633 const Double_t kPtmin = 0, kPtmax= 50;
1634 for(Int_t ivar = 0; ivar < nDimSecvtx; ivar++)
1635 binEdgesSecvtx[ivar] = new Double_t[nBinSecvtx[ivar] + 1];
1637 for(Int_t i=0; i<=nBinSecvtx[0]; i++) binEdgesSecvtx[0][i]=binEdgesPair[0][i];
1638 for(Int_t i=0; i<=nBinSecvtx[1]; i++) binEdgesSecvtx[1][i]=binEdgesPair[1][i];
1639 for(Int_t i=0; i<=nBinSecvtx[2]; i++) binEdgesSecvtx[2][i]=binEdgesPair[3][i];
1640 for(Int_t i=0; i<=nBinSecvtx[3]; i++) binEdgesSecvtx[3][i]=binEdgesPair[4][i];
1641 for(Int_t i=0; i<=nBinSecvtx[4]; i++) binEdgesSecvtx[4][i]=binEdgesPair[5][i];
1642 for(Int_t i=0; i<=nBinSecvtx[5]; i++) binEdgesSecvtx[5][i]=(Double_t)kNtrksmin + (kNtrksmax - kNtrksmin)/nBinSecvtx[5]*(Double_t)i;
1643 for(Int_t i=0; i<=nBinSecvtx[6]; i++) binEdgesSecvtx[6][i]=(Double_t)kTrueBmin + (kTrueBmax - kTrueBmin)/nBinSecvtx[6]*(Double_t)i;
1644 for(Int_t i=0; i<=nBinSecvtx[7]; i++) binEdgesSecvtx[7][i]=binEdgesPair[3][i];
1645 for(Int_t i=0; i<=nBinSecvtx[8]; i++) binEdgesSecvtx[8][i]=(Double_t)kPtmin + (kPtmax - kPtmin)/nBinSecvtx[8]*(Double_t)i;
1647 fSecvtxQA = new THnSparseF("secvtxQA", "QA for Secvtx; invmass[GeV/c^2]; KF chi2; signed Lxy; KF ip; pair code; n tracks ", nDimSecvtx, nBinSecvtx);
1648 for(Int_t idim = 0; idim < nDimSecvtx; idim++){
1649 fSecvtxQA->SetBinEdges(idim, binEdgesSecvtx[idim]);
1652 fSecVtxList->AddAt(fSecvtxQA,1);
1654 for(Int_t ivar = 0; ivar < nDimPair; ivar++)
1655 delete binEdgesPair[ivar];
1656 for(Int_t ivar = 0; ivar < nDimSecvtx; ivar++)
1657 delete binEdgesSecvtx[ivar];
1660 //____________________________________________________________
1661 void AliHFEsecVtx::MakeHistos(Int_t step){
1667 TString hname=Form("step%d",step);
1670 const Double_t kPtbound[2] = {0.1, 20.};
1672 iBin[0] = 44; // bins in pt
1673 Double_t* binEdges[1];
1674 binEdges[0] = AliHFEtools::MakeLogarithmicBinning(iBin[0], kPtbound[0], kPtbound[1]);
1676 fSecVtxList->AddAt(new TH1F(hname+"taggedElec", "pT of e", iBin[0],binEdges[0]), step);
1677 fSecVtxList->AddAt(new TH1F(hname+"charmElec", "pT of e", iBin[0],binEdges[0]), step+1);
1678 fSecVtxList->AddAt(new TH1F(hname+"beautyElec", "pT of e", iBin[0],binEdges[0]), step+2);
1679 fSecVtxList->AddAt(new TH1F(hname+"conversionElec", "pT of e", iBin[0],binEdges[0]), step+3);
1680 fSecVtxList->AddAt(new TH1F(hname+"ebgElec", "pT of e", iBin[0],binEdges[0]), step+4);
1681 fSecVtxList->AddAt(new TH1F(hname+"hcontaminElec", "pT of e", iBin[0],binEdges[0]), step+5);
1682 fSecVtxList->AddAt(new TH1F(hname+"elseElec", "pT of e", iBin[0],binEdges[0]), step+6);
1685 //____________________________________________________________
1686 void AliHFEsecVtx::FillHistos(Int_t step, const AliESDtrack *track){
1694 AliMCParticle *mctrack = NULL;
1695 TParticle* mcpart = NULL;
1697 (dynamic_cast<TH1F *>(fSecVtxList->At(step)))->Fill(track->Pt()); // electrons tagged
1699 if(HasMCData() && fMCQA){
1700 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(track->GetLabel()))))) return;
1701 mcpart = mctrack->Particle();
1703 Int_t esource=fMCQA->GetElecSource(mcpart);
1705 //if(!(dynamic_cast<TH1F *>(fSecVtxList->At(step+1)))) return;
1706 (dynamic_cast<TH1F *>(fSecVtxList->At(step+1)))->Fill(mcpart->Pt()); //charm
1708 else if(esource==2 || esource==3) {
1709 //if(!(dynamic_cast<TH1F *>(fSecVtxList->At(step+2)))) return;
1710 (dynamic_cast<TH1F *>(fSecVtxList->At(step+2)))->Fill(mcpart->Pt()); //beauty
1712 else if(esource==4) {
1713 //if(!(dynamic_cast<TH1F *>(fSecVtxList->At(step+3)))) return;
1714 (dynamic_cast<TH1F *>(fSecVtxList->At(step+3)))->Fill(mcpart->Pt()); //conversion
1716 else if(esource==7) {
1717 //if(!(dynamic_cast<TH1F *>(fSecVtxList->At(step+5)))) return;
1718 (dynamic_cast<TH1F *>(fSecVtxList->At(step+5)))->Fill(mcpart->Pt()); //contamination
1720 else if(!(esource<0)) {
1721 //if(!(dynamic_cast<TH1F *>(fSecVtxList->At(step+4)))) return;
1722 (dynamic_cast<TH1F *>(fSecVtxList->At(step+4)))->Fill(mcpart->Pt()); //e backgrounds
1725 //if(!(dynamic_cast<TH1F *>(fSecVtxList->At(step+6)))) return;
1726 (dynamic_cast<TH1F *>(fSecVtxList->At(step+6)))->Fill(mcpart->Pt()); //something else?