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 **************************************************************************/
17 // Implementation of a branch replicator
18 // to produce aods with only few branches.
20 // This replicator is in charge of replicating the nuclei primary vertices
21 // tracks identified as nuclei with Z>=2, secondary vertices in form of
22 // AliAODRecoDecayLF2Prong and their daughter tracks.
23 // These informations are stored into a reduced AODs (AliAOD.NuclEx.root)
25 // The vertices are filtered so that only the primary vertices make it
26 // to the output aods.
28 // The secondary vertices are recreated here, as a AliAODRecoDecayLF2Prong
29 // plus cuts that select secondary vericesoutside the primary vertex
31 // Authors: S. Bufalino (stefania.bufalino@cern.ch)
32 // R. Lea (ramona.lea@cern.ch)
33 // Based on AliAODMuonReplicator.cxx
39 class AliAODRecoDecay;
41 #include "AliAODDimuon.h"
42 #include "AliAODEvent.h"
43 #include "AliAODMCHeader.h"
44 #include "AliAODMCParticle.h"
45 #include "AliAODTZERO.h"
46 #include "AliAODTrack.h"
47 #include "AliAODVZERO.h"
48 //#include "AliAnalysisCuts.h"
50 #include "AliExternalTrackParam.h"
53 #include "AliPIDResponse.h"
56 #include "AliESDtrack.h"
57 #include "TObjArray.h"
58 #include "AliAnalysisFilter.h"
59 #include "AliAODRecoDecay.h"
60 #include "AliAODRecoDecayLF.h"
61 #include "AliAODRecoDecayLF2Prong.h"
64 #include <TDatabasePDG.h>
68 #include "AliVEvent.h"
69 #include "AliVVertex.h"
70 #include "AliVTrack.h"
71 #include "AliVertexerTracks.h"
72 #include "AliKFVertex.h"
73 #include "AliESDEvent.h"
74 #include "AliESDVertex.h"
75 #include "AliESDtrackCuts.h"
76 #include "AliAODEvent.h"
77 #include "AliAnalysisFilter.h"
78 //#include "AliAnalysisVertexingLF.h"
79 #include "AliAnalysisManager.h"
80 #include "AliAODNuclExReplicator.h"
83 #include "AliInputEventHandler.h"
88 ClassImp(AliAODNuclExReplicator)
90 //_____________________________________________________________________________
91 AliAODNuclExReplicator::AliAODNuclExReplicator(const char* name, const char* title,
92 // AliAnalysisCuts* trackCut,
93 // AliAnalysisCuts* vertexCut,
95 Int_t nsigmaTrk1, Int_t partType1,
96 Int_t nsigmaTrk2, Int_t partType2
98 :AliAODBranchReplicator(name,title),
107 //fVertexCut(vertexCut),
110 // fTrackCut(trackCut),
111 fSecondaryVerices(0x0),
112 fDaughterTracks(0x0),
119 fReplicateHeader(kTRUE), //replicateHeader //to be fixed
120 fnSigmaTrk1(nsigmaTrk1),
121 fnSigmaTrk2(nsigmaTrk2),
122 fpartType1(partType1),
123 fpartType2(partType2),
124 fSecVtxWithKF(kFALSE),
125 fVertexerTracks(0x0),
134 //_____________________________________________________________________________
135 AliAODNuclExReplicator::~AliAODNuclExReplicator()
139 // delete fVertexCut;
143 //_____________________________________________________________________________
144 void AliAODNuclExReplicator::SelectParticle(Int_t i)
146 // taking the absolute values here, need to take care
147 // of negative daughter and mother
150 if (!IsParticleSelected(TMath::Abs(i)))
152 fParticleSelected.Add(TMath::Abs(i),1);
156 //_____________________________________________________________________________
157 Bool_t AliAODNuclExReplicator::IsParticleSelected(Int_t i)
159 // taking the absolute values here, need to take
160 // care with negative daughter and mother
162 return (fParticleSelected.GetValue(TMath::Abs(i))==1);
166 //_____________________________________________________________________________
167 void AliAODNuclExReplicator::CreateLabelMap(const AliAODEvent& source)
170 // this should be called once all selections are done
175 TClonesArray* mcParticles = static_cast<TClonesArray*>(source.FindListObject(AliAODMCParticle::StdBranchName()));
180 TIter next(mcParticles);
184 if (IsParticleSelected(i))
186 fLabelMap.Add(i,j++);
192 //_____________________________________________________________________________
193 Int_t AliAODNuclExReplicator::GetNewLabel(Int_t i)
195 // Gets the label from the new created Map
196 // Call CreatLabelMap before
197 // otherwise only 0 returned
198 return fLabelMap.GetValue(TMath::Abs(i));
201 //_____________________________________________________________________________
202 // void AliAODNuclExReplicator::FilterMC(const AliAODEvent& source)
204 // // Filter MC information
206 // fMCHeader->Reset();
207 // fMCParticles->Clear("C");
209 // AliAODMCHeader* mcHeader(0x0);
210 // TClonesArray* mcParticles(0x0);
212 // fParticleSelected.Delete();
214 // if ( fMCMode>=2 && !fTracks->GetEntries() ) return;
215 // // for fMCMode==1 we only copy MC information for events where there's at least one muon track
217 // mcHeader = static_cast<AliAODMCHeader*>(source.FindListObject(AliAODMCHeader::StdBranchName()));
221 // *fMCHeader = *mcHeader;
224 // mcParticles = static_cast<TClonesArray*>(source.FindListObject(AliAODMCParticle::StdBranchName()));
226 // if ( mcParticles && fMCMode>=2 )
228 // // loop on (kept) muon tracks to find their ancestors
229 // TIter nextMT(fTracks);
232 // while ( ( mt = static_cast<AliAODTrack*>(nextMT()) ) )
234 // Int_t label = mt->GetLabel();
236 // while ( label >= 0 )
238 // SelectParticle(label);
239 // AliAODMCParticle* mother = static_cast<AliAODMCParticle*>(mcParticles->UncheckedAt(label));
242 // AliError("Got a null mother ! Check that !");
247 // label = mother->GetMother();
252 // CreateLabelMap(source);
254 // // Actual filtering and label remapping (shamelessly taken for the implementation of AliAODHandler::StoreMCParticles)
255 // TIter nextMC(mcParticles);
256 // AliAODMCParticle* p;
260 // while ( ( p = static_cast<AliAODMCParticle*>(nextMC()) ) )
262 // AliAODMCParticle c(*p);
264 // if ( IsParticleSelected(nmc) )
267 // Int_t d0 = p->GetDaughter(0);
268 // Int_t d1 = p->GetDaughter(1);
269 // Int_t m = p->GetMother();
271 // // other than for the track labels, negative values mean
272 // // no daughter/mother so preserve it
276 // // no first daughter -> no second daughter
277 // // nothing to be done
278 // // second condition not needed just for sanity check at the end
279 // c.SetDaughter(0,d0);
280 // c.SetDaughter(1,d1);
281 // } else if(d1 < 0 && d0 >= 0)
283 // // Only one daughter
284 // // second condition not needed just for sanity check at the end
285 // if(IsParticleSelected(d0))
287 // c.SetDaughter(0,GetNewLabel(d0));
290 // c.SetDaughter(0,-1);
292 // c.SetDaughter(1,d1);
294 // else if (d0 > 0 && d1 > 0 )
296 // // we have two or more daughters loop on the stack to see if they are
300 // for (int id = d0; id<=d1;++id)
302 // if (IsParticleSelected(id))
307 // d0tmp = GetNewLabel(id);
308 // d1tmp = d0tmp; // this is to have the same schema as on the stack i.e. with one daugther d0 and d1 are the same
310 // else d1tmp = GetNewLabel(id);
313 // c.SetDaughter(0,d0tmp);
314 // c.SetDaughter(1,d1tmp);
317 // AliError(Form("Unxpected indices %d %d",d0,d1));
325 // if (IsParticleSelected(m))
327 // c.SetMother(GetNewLabel(m));
331 // AliError(Form("PROBLEM Mother not selected %d", m));
335 // new ((*fMCParticles)[nmcout++]) AliAODMCParticle(c);
341 // // now remap the tracks...
343 // TIter nextTrack(fTracks);
346 // while ( ( t = static_cast<AliAODTrack*>(nextTrack()) ) )
348 // t->SetLabel(GetNewLabel(t->GetLabel()));
352 // else if ( mcParticles )
354 // // simple copy of input MC particles to ouput MC particles
355 // TIter nextMC(mcParticles);
356 // AliAODMCParticle* p;
359 // while ( ( p = static_cast<AliAODMCParticle*>(nextMC()) ) )
361 // new ((*fMCParticles)[nmcout++]) AliAODMCParticle(*p);
365 // AliDebug(1,Form("input mc %d output mc %d",
366 // mcParticles ? mcParticles->GetEntries() : 0,
367 // fMCParticles ? fMCParticles->GetEntries() : 0));
372 //_____________________________________________________________________________
373 TList* AliAODNuclExReplicator::GetList() const
375 // return (and build if not already done) our internal list of managed objects
379 if ( fReplicateHeader )
381 fHeader = new AliAODHeader;
385 fSecondaryVerices = new TClonesArray("AliAODRecoDecayLF2Prong",30);
386 fSecondaryVerices->SetName("SecondaryVertices");
388 fVertices = new TClonesArray("AliAODVertex",2);
389 fVertices->SetName("vertices");
391 fNuclei = new TClonesArray("AliAODTrack",30);
392 fNuclei->SetName("Nuclei");
394 fDaughterTracks = new TClonesArray("AliAODTrack",30);
395 fDaughterTracks->SetName("DaughterTracks");
399 fList->SetOwner(kTRUE);
402 fList->Add(fVertices);
404 fList->Add(fSecondaryVerices);
405 fList->Add(fDaughterTracks);
410 fMCHeader = new AliAODMCHeader;
411 fMCParticles = new TClonesArray("AliAODMCParticle",1000);
412 fMCParticles->SetName(AliAODMCParticle::StdBranchName());
413 fList->Add(fMCHeader);
414 fList->Add(fMCParticles);
420 //_____________________________________________________________________________
421 void AliAODNuclExReplicator::ReplicateAndFilter(const AliAODEvent& source)
423 // Replicate (and filter if filters are there) the relevant parts we're interested in AODEvent
425 //-----------------------------------------------
428 AliPIDResponse *fPIDResponse;
429 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
430 AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
431 fPIDResponse = inputHandler->GetPIDResponse();
433 //--------------------------------------------------------
435 // printf("Execute NuclEx Replicator\n");
437 //---------------------------------
439 if (fReplicateHeader)
441 *fHeader = *(source.GetHeader());
444 fVertices->Clear("C");
448 fSecondaryVerices->Clear("C");
450 fDaughterTracks->Clear("C");
452 //----------------------------------
454 // cout<<"Centrality AOD source: "<<source.GetHeader()->GetCentrality()<<endl;
461 Double_t xdummy,ydummy;
463 AliAODRecoDecayLF2Prong *io2Prong = 0;
465 TObjArray *twoTrackArray = new TObjArray(2);
468 // cout<<"Qui"<<endl;
469 //cout<<source.GetMagneticField()<<endl;
471 AliAODVertex *vtx = source.GetPrimaryVertex();
473 // cout<<"Source "<<source<<endl;
474 //cout<<"vtx: "<<vtx<<endl;
476 // A Set of very loose cut for a weak strange decay
485 //----------------------------------------------------------
488 UShort_t *indices = 0;
489 const Int_t entries = source.GetNumberOfTracks();
491 Double_t pos[3],cov[6];
493 vtx->GetCovarianceMatrix(cov);
494 fV1 = new AliESDVertex(pos,cov,100.,100,vtx->GetName());
495 // cout<<"fV1 pricipal loop: "<<fV1<<endl;
497 if(entries<=0) return;
498 indices = new UShort_t[entries];
499 memset(indices,0,sizeof(UShort_t)*entries);
500 fAODMapSize = 100000;
501 fAODMap = new Int_t[fAODMapSize];
502 memset(fAODMap,0,sizeof(Int_t)*fAODMapSize);
503 // cent=((AliAODEvent&)source)->GetCentrality();
505 //-------------------------------------------------------------
507 //AliAODRecoDecayLF *rd = 0;
508 // AliAODRecoDecayLF2Prong*rd = 0;
511 if(vtx->GetNContributors()<1) {
514 vtx =source.GetPrimaryVertexSPD();
516 if(vtx->GetNContributors()<1) {
517 Info("AliAnalysisTaskHelium3Pi","No good vertex, skip event");
518 return; // NO GOOD VERTEX, SKIP EVENT
522 Double_t xPrimaryVertex=0.,yPrimaryVertex=0.;
523 xPrimaryVertex=vtx->GetX();
524 yPrimaryVertex=vtx->GetY();
526 fBzkG=source.GetMagneticField();
527 fVertexerTracks=new AliVertexerTracks(fBzkG);
529 // TF1 *foPion=new TF1("foPion", "[0]*([1]*TMath::Power(TMath::Sqrt(1 + (x/0.13957)*(x/0.13957))/(x/0.13957) , [3]) - 1 - TMath::Power(TMath::Sqrt(1 + (x/0.13957)*(x/0.13957))/(x/0.13957) , [3])*TMath::Log([2] + 1/TMath::Power((x/0.13957), [4])))",0.01,20);
530 // foPion->SetParameters(4.1,8.98482806165147636e+00,1.54000000000000005e-05,2.30445734159456084e+00,2.25624744086878559e+00);
532 Double_t TrackNumber = source.GetNumberOfTracks();
536 TArrayI Track0(TrackNumber); //Pions
539 TArrayI Track1(TrackNumber); //Helium3
542 for(Int_t j=0; j<TrackNumber; j++){
544 // cout<<"Inside loop tracks"<<endl;
546 AliVTrack *track = (AliVTrack*)source.GetTrack(j);
548 AliAODTrack *aodtrack =(AliAODTrack*)track;
550 //-----------------------------------------------------------
552 if(aodtrack->GetTPCNcls() < 70 )continue;
553 if(aodtrack->Chi2perNDF() > 4 )continue;
555 // cout<<"Filter Map: "<<aodtrack->GetFilterMap()<<endl;
556 // if (!aodtrack->TestFilterMask(BIT(4))) continue;
557 // if(aodtrack->TestFilterMask(BIT(4))!=0)
558 // cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!! Filter bit mask: !!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
560 if (!aodtrack->IsOn(AliAODTrack::kTPCrefit)) continue;
561 if (!aodtrack->IsOn(AliAODTrack::kTPCin)) continue;
562 if (aodtrack->IsOn(AliAODTrack::kITSpureSA)) continue;
564 //---------------------------------------------------------------
566 Double_t mom = aodtrack->GetDetPid()->GetTPCmomentum();
568 if(mom<0.150)continue;
570 Double_t nSigmaNegPion = TMath::Abs(fPIDResponse->NumberOfSigmasTPC(aodtrack,(AliPID::EParticleType)fpartType1));
571 // cout<<"%%% nsigma Pi: "<<nSigmaNegPion<<endl;
572 // Double_t nSigmaNegPion = TMath::Abs((aodtrack->GetTPCsignal() - foPion->Eval(mom))/foPion->Eval(mom))/0.07;
574 if ( nSigmaNegPion <= fnSigmaTrk1 /*&& aodtrack->Charge()==-1*/){
578 Double_t nSigmaNuclei = fPIDResponse->NumberOfSigmasTPC(aodtrack,(AliPID::EParticleType)fpartType2); //To be changed
579 //cout<<"%%% nsigma Nuclei: "<<nSigmaNuclei<<endl;
581 if(nSigmaNuclei>-fnSigmaTrk2 && aodtrack->GetTPCsignal()<1000 && mom>0.2){
583 //Double_t triggerDeDx = 4*AliExternalTrackParam::BetheBlochAleph((mom*2)/(0.938*3),1.0288,31.9806,5.04114e-11,2.13096,2.38541);
584 //if(aodtrack->GetTPCsignal() > triggerDeDx && aodtrack->GetTPCsignal()<5000 && mom>0.2 /*&& aodtrack->Charge()==1*/){
587 new((*fNuclei)[nnuclei++]) AliAODTrack(*aodtrack);
588 //cout<<"@@@ n sigma NUCLEI"<<nSigmaNuclei<<endl;
593 // cout<<"Delete AodTrack..."<<endl;
595 // aodtrack->Delete();
597 //Set Track Daughters
601 // cout<<"Track loops..."<<endl;
603 AliAODTrack *postrackAOD = 0;
604 AliAODTrack *negtrackAOD = 0;
606 AliESDtrack *postrack = 0;
607 AliESDtrack *negtrack = 0;
609 // cout <<"nTrack1 "<< nTrack1<<endl;
610 // cout <<"nTrack0 "<< nTrack0<<endl;
612 for (Int_t i=0; i<nTrack1; i++){ //! He Tracks Loop
614 // cout<<"Inside track loop"<<endl;
616 Int_t Track1idx=Track1[i];
618 AliVTrack *trackpos = (AliVTrack*)source.GetTrack(Track1idx);
620 postrackAOD = (AliAODTrack*)trackpos;
621 postrack = new AliESDtrack(trackpos);
623 for (Int_t k=0; k <nTrack0 ; k++) { //! Pion Tracks Loop
625 Int_t Track0idx=Track0[k];
627 AliVTrack *trackneg = (AliVTrack*)source.GetTrack(Track0idx);
628 negtrackAOD =(AliAODTrack*)trackneg;
629 negtrack = new AliESDtrack(trackneg);
631 twoTrackArray->AddAt(negtrack,0);
632 twoTrackArray->AddAt(postrack,1);
634 Double_t dcap1n1 = postrack->GetDCA(negtrack,fBzkG,xdummy,ydummy);
636 Double_t dcap1toPV = TMath::Abs(postrack->GetD(xPrimaryVertex, yPrimaryVertex,fBzkG));
637 Double_t dcan1toPV = TMath::Abs(negtrack->GetD(xPrimaryVertex, yPrimaryVertex,fBzkG));
639 if(dcap1n1>fDCAtracksMin)continue;
640 if((xdummy+ydummy)>fRmax )continue;
641 if((xdummy+ydummy)< fRmin)continue;
643 if ( dcan1toPV < fDNmin)
644 if ( dcap1toPV < fDPmin) continue;
646 // cout<<"dcap1n1: "<<dcap1n1<<endl;
648 AliAODVertex *vertexp1n1 = ReconstructSecondaryVertex(twoTrackArray,dispersion,kTRUE);
652 twoTrackArray->Clear();
658 // cout<<"vertexp1n1: "<<vertexp1n1<<endl;
660 io2Prong = Make2Prong(twoTrackArray,source,vertexp1n1,dcap1n1);
662 //cout<<"Fuori dal loop e' quello che salvo \npr0: "<<io2Prong->GetProngID(0)<<" pr1: "<<io2Prong->GetProngID(1)<<" pr2"<<io2Prong->GetProngID(2)<<endl;
664 if(io2Prong->CosPointingAngle()<fCosMin)continue;
666 // cout<<"if CPA \npr0: "<<io2Prong->GetProngID(0)<<" pr1: "<<io2Prong->GetProngID(1)<<" pr2"<<io2Prong->GetProngID(2)<<endl;
667 // cout<<"pointing angle "<<io2Prong->CosPointingAngle()<<endl;
670 AliAODTrack *trk0 = (AliAODTrack*)io2Prong->GetDaughter(0);
671 AliAODTrack *trk1 = (AliAODTrack*)io2Prong->GetDaughter(1);
673 cout<<"**********************************************"<<endl;
674 cout<<trk0/*->GetID()*/<<" "<<negtrackAOD->GetID()<<endl;
675 cout<<trk1/*->GetID()*/<<" "<<postrackAOD->GetID()<<endl;
676 cout<<"d0 io2Prong: "<<io2Prong->GetProngID(1)<<endl;
677 cout<<"d1 io2Prong: "<<io2Prong->GetProngID(0)<<endl;
678 cout<<"**********************************************"<<endl;
680 // rd = new((*fSecondaryVerices)[nsv++]) AliAODRecoDecayLF2Prong(*io2Prong);
682 new((*fSecondaryVerices)[nsv++]) AliAODRecoDecayLF2Prong(*io2Prong);
684 // cout<<"QUELLO CHE SALVo \npr0: "<<rd->GetProngID(0)<<" pr1: "<<rd->GetProngID(1)<<" pr2"<<rd->GetProngID(2)<<endl;
686 // rd->SetSecondaryVtx(vertexp1n1);
687 // vertexp1n1->SetParent(rd);
688 // AddRefs(vertexp1n1,rd,source,twoTrackArray);
691 new((*fDaughterTracks)[ntracksD++]) AliAODTrack(*negtrackAOD);
692 new((*fDaughterTracks)[ntracksD++]) AliAODTrack(*postrackAOD);
707 //----------------------------------------------------------
709 assert(fVertices!=0x0);
710 fVertices->Clear("C");
711 TIter nextV(source.GetVertices());
715 while ( ( v = static_cast<AliAODVertex*>(nextV()) ) )
717 if ( v->GetType() == AliAODVertex::kPrimary ||
718 v->GetType() == AliAODVertex::kMainSPD ||
719 v->GetType() == AliAODVertex::kPileupSPD ||
720 v->GetType() == AliAODVertex::kPileupTracks||
721 v->GetType() == AliAODVertex::kMainTPC )
723 AliAODVertex* tmp = v->CloneWithoutRefs();
724 AliAODVertex* copiedVertex = new((*fVertices)[nvertices++]) AliAODVertex(*tmp);
726 // to insure the main vertex retains the ncontributors information
727 // (which is otherwise computed dynamically from
728 // references to tracks, which we do not keep in muon aods...)
731 copiedVertex->SetNContributors(v->GetNContributors());
733 // fVertices->Delete();
734 // delete copiedVertex;
739 // printf("....Done NuclEx Replicator...\n");
741 AliDebug(1,Form("input mu tracks=%d tracks=%d vertices=%d nnuclei=%d",
742 input,fSecondaryVerices->GetEntries(),fVertices->GetEntries(),fNuclei->GetEntries()));
744 // Finally, deal with MC information, if needed
746 // if ( fMCMode > 0 )
751 //cout<<"Delete..."<<endl;
754 //cout<<"Delete 1"<< endl;
756 if(io2Prong) {delete io2Prong; io2Prong=NULL;}
757 //cout<<"Delete 2"<< endl;
758 twoTrackArray->Delete(); delete twoTrackArray;
759 //cout<<"Delete 3"<< endl;
760 // vtx->Delete(); delete vtx;
761 //cout<<"Delete 4"<< endl;
762 if(fV1) { delete fV1; fV1=NULL; }
763 //cout<<"Delete 5"<< endl;
764 if(fAODMap) { delete [] fAODMap; fAODMap=NULL; }
766 //cout<<"Delete 6"<< endl;
767 delete fVertexerTracks;
772 //-----------------------------------------------------------------------------
774 AliAODVertex *AliAODNuclExReplicator::ReconstructSecondaryVertex(TObjArray *trkArray,
775 Double_t &dispersion,Bool_t useTRefArray) const
778 // Secondary vertex reconstruction with AliVertexerTracks or AliKFParticle
779 //AliCodeTimerAuto("",0);
781 AliESDVertex *vertexESD = 0;
782 AliAODVertex *vertexAOD = 0;
784 if(!fSecVtxWithKF) { // AliVertexerTracks
786 fVertexerTracks->SetVtxStart(fV1);
787 vertexESD = (AliESDVertex*)fVertexerTracks->VertexForSelectedESDTracks(trkArray);
789 if(!vertexESD) return vertexAOD;
792 Double_t vertRadius2=vertexESD->GetXv()*vertexESD->GetXv()+vertexESD->GetYv()*vertexESD->GetYv();
793 if(vertRadius2>200.){
794 // vertex outside beam pipe, reject candidate to avoid propagation through material
795 delete vertexESD; vertexESD=NULL;
799 } else { // Kalman Filter vertexer (AliKFParticle)
801 AliKFParticle::SetField(fBzkG);
803 AliKFVertex vertexKF;
805 Int_t nTrks = trkArray->GetEntriesFast();
806 for(Int_t i=0; i<nTrks; i++) {
807 AliESDtrack *esdTrack = (AliESDtrack*)trkArray->At(i);
808 AliKFParticle daughterKF(*esdTrack,211);
809 vertexKF.AddDaughter(daughterKF);
811 vertexESD = new AliESDVertex(vertexKF.Parameters(),
812 vertexKF.CovarianceMatrix(),
814 vertexKF.GetNContributors());
817 // convert to AliAODVertex
818 Double_t pos[3],cov[6],chi2perNDF;
819 vertexESD->GetXYZ(pos); // position
820 vertexESD->GetCovMatrix(cov); //covariance matrix
821 chi2perNDF = vertexESD->GetChi2toNDF();
822 dispersion = vertexESD->GetDispersion();
826 Int_t nprongs= (useTRefArray ? 0 : trkArray->GetEntriesFast());
827 vertexAOD = new AliAODVertex(pos,cov,chi2perNDF,0x0,-1,AliAODVertex::kUndef,nprongs);
829 //cout<<"------------------> Reconstruct vertexAOD: "<<vertexAOD<<endl;
836 //-----------------------------------------------------------------------------
838 AliAODRecoDecayLF2Prong* AliAODNuclExReplicator::Make2Prong(TObjArray *twoTrackArray,const AliAODEvent &evento,
839 AliAODVertex *secVert,Double_t dca)
844 //cout<<"Inside make 2 prong"<<endl;
847 charge[0]=1; //it was -1 //Ramona
850 // From AliAnalysisVertexingLF.cxx Method:Make2Prongs
852 fBzkG = evento.GetMagneticField();
854 Double_t px[2],py[2],pz[2],d0[2],d0err[2];
855 // Also this has been changed //Ramona
856 AliESDtrack *negtrack = (AliESDtrack*)twoTrackArray->UncheckedAt(0);
857 AliESDtrack *postrack = (AliESDtrack*)twoTrackArray->UncheckedAt(1);
859 //cout<<"negtrack: "<<negtrack<<" postrack: "<<postrack<<endl;
860 //cout<<"kVeryBig: "<<kVeryBig<<endl;
861 //cout<<"secVert: "<<secVert<<endl;
863 // // propagate tracks to secondary vertex, to compute inv. mass
865 postrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
866 negtrack->PropagateToDCA(secVert,fBzkG,kVeryBig);
868 Double_t momentum[3];
870 negtrack->GetPxPyPz(momentum);
871 px[0] = charge[0]*momentum[0];
872 py[0] = charge[0]*momentum[1];
873 pz[0] = charge[0]*momentum[2];
875 postrack->GetPxPyPz(momentum);
876 px[1] = charge[1]*momentum[0];
877 py[1] = charge[1]*momentum[1];
878 pz[1] = charge[1]*momentum[2];
880 //cout<< px[0] <<" "<< " "<< py[0] << " "<< pz[0]<<endl;
881 // px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
882 //cout<< px[1] <<" "<< " "<< py[1] << " "<< pz[1]<<endl;
883 //px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
886 // primary vertex to be used by this candidate
887 AliAODVertex *primVertexAOD = evento.GetPrimaryVertex();
888 //cout<<"primVertexAOD "<<primVertexAOD<<endl;
889 if(!primVertexAOD) return 0x0;
891 Double_t d0z0[2],covd0z0[3];
900 d0err[0] = TMath::Sqrt(TMath::Abs(covd0z0[0]));
903 d0err[1] = TMath::Sqrt(TMath::Abs(covd0z0[0]));
905 // create the object AliAODRecoDecayLF2Prong
906 // AliAODRecoDecayLF2Prong *the2Prong = new AliAODRecoDecayLF2Prong(secVert,px,py,pz,d0,d0err,dcap1n1);
907 AliAODRecoDecayLF2Prong *the2Prong = new AliAODRecoDecayLF2Prong(secVert,px,py,pz,d0,d0err,dca);
908 the2Prong->SetOwnPrimaryVtx(primVertexAOD);
910 // the2Prong->SetProngIDs(2,{-999,999});
911 // UShort_t id0[2]={99999,999999};
912 // the2Prong->SetProngIDs(2,id0);
914 UShort_t id[2]={(UShort_t)postrack->GetID(),(UShort_t)negtrack->GetID()};
915 the2Prong->SetProngIDs(2,id);
917 // cout<<"\n\n\nMake 2 Prong: id[0]"<<id[0]<<" id[1]: "<<id[1]<<endl;
918 // cout<<"Get: 1 "<<the2Prong->GetProngID(0)<<" 2 "<<the2Prong->GetProngID(1)<<endl;
919 // cout<<"Get: 3 "<<the2Prong->GetProngID(2)<<" 4 "<<the2Prong->GetProngID(3)<<endl<<endl<<endl;
920 //delete primVertexAOD; primVertexAOD=NULL;
922 if(postrack->Charge()!=0 && negtrack->Charge()!=0) {
924 AddDaughterRefs(secVert,(AliAODEvent&)evento,twoTrackArray);
925 // AddDaughterRefs(secVert,(AliAODEvent*)evento,twoTrackArray);
934 //----------------------------------------------------------------------------
935 void AliAODNuclExReplicator::AddDaughterRefs(AliAODVertex *v,
936 const AliAODEvent &event,
937 const TObjArray *trkArray) const
940 // Add the AOD tracks as daughters of the vertex (TRef)
941 // AliCodeTimerAuto("",0);
942 // cout<<"Inside AddDaughterRefs "<<endl;
944 Int_t nDg = v->GetNDaughters();
947 if(nDg) dg = v->GetDaughter(0);
948 if(dg) return; // daughters already added
950 Int_t nTrks = trkArray->GetEntriesFast();
952 AliExternalTrackParam *track = 0;
953 AliAODTrack *aodTrack = 0;
956 for(Int_t i=0; i<nTrks; i++) {
957 track = (AliExternalTrackParam*)trkArray->UncheckedAt(i);
959 id = (Int_t)track->GetID();
960 // printf("---> %d\n",id);
961 if(id<0) continue; // this track is a AliAODRecoDecay
963 aodTrack = (AliAODTrack*)event.GetTrack(fAODMap[id]);
964 v->AddDaughter(aodTrack);
968 //----------------------------------------------------------------------------
970 void AliAODNuclExReplicator::AddRefs(AliAODVertex *v,AliAODRecoDecayLF *rd,
971 const AliAODEvent &event,
972 const TObjArray *trkArray) const
975 // Add the AOD tracks as daughters of the vertex (TRef)
976 // Also add the references to the primary vertex and to the cuts
977 //AliCodeTimerAuto("",0);
979 AddDaughterRefs(v,event,trkArray);
980 rd->SetPrimaryVtxRef((AliAODVertex*)event.GetPrimaryVertex());
984 //---------------------------------------------------------------------------
986 void AliAODNuclExReplicator::Terminate(){