Macro to create std AOD + MC
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAnalysisTaskSESelectHF.cxx
CommitLineData
0de9de87 1/**************************************************************************
2 * Copyright(c) 1998-2008, 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//
18// AliAnalysisTaskSE for the selection of heavy flavor
19// decay candidates and creation a stand-alone AOD.
20//
21// Author: A.Dainese, andrea.dainese@lnl.infn.it
22/////////////////////////////////////////////////////////////
23
24#include <TClonesArray.h>
25
26#include "AliAODEvent.h"
27#include "AliAODVertex.h"
28#include "AliAODTrack.h"
29#include "AliAODRecoDecayHF2Prong.h"
30#include "AliAnalysisTaskSE.h"
31#include "AliAnalysisTaskSESelectHF.h"
32
33ClassImp(AliAnalysisTaskSESelectHF)
34
35
36//________________________________________________________________________
37AliAnalysisTaskSESelectHF::AliAnalysisTaskSESelectHF():
38AliAnalysisTaskSE(),
39fVerticesHFTClArr(0),
40fD0toKpiTClArr(0)
41{
42 // Default constructor
43 SetD0toKpiCuts();
44}
45
46//________________________________________________________________________
47AliAnalysisTaskSESelectHF::AliAnalysisTaskSESelectHF(const char *name):
48AliAnalysisTaskSE(name),
49fVerticesHFTClArr(0),
50fD0toKpiTClArr(0)
51{
52 // Default constructor
53 SetD0toKpiCuts();
54}
55
56//________________________________________________________________________
57AliAnalysisTaskSESelectHF::~AliAnalysisTaskSESelectHF()
58{
59 // Destructor
60}
61
62//________________________________________________________________________
63void AliAnalysisTaskSESelectHF::Init()
64{
65 // Initialization
66
67 if(fDebug > 1) printf("AnalysisTaskSESelectHF::Init() \n");
68
69 return;
70}
71
72//________________________________________________________________________
73void AliAnalysisTaskSESelectHF::UserCreateOutputObjects()
74{
75 // Create the output container
76 //
77 if(fDebug > 1) printf("AnalysisTaskSESelectHF::UserCreateOutputObjects() \n");
78
79 fVerticesHFTClArr = new TClonesArray("AliAODVertex", 0);
80 fVerticesHFTClArr->SetName("VerticesHF");
080ac6fd 81 AddAODBranch("TClonesArray", &fVerticesHFTClArr);
0de9de87 82
83 fD0toKpiTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
84 fD0toKpiTClArr->SetName("D0toKpi");
080ac6fd 85 AddAODBranch("TClonesArray", &fD0toKpiTClArr);
0de9de87 86
87 return;
88}
89
90//________________________________________________________________________
91void AliAnalysisTaskSESelectHF::UserExec(Option_t */*option*/)
92{
93 // Execute analysis for current event:
94 // heavy flavor candidates selection and histograms
95
96 AliAODEvent *aodIn = dynamic_cast<AliAODEvent*> (InputEvent());
97
98 // load D0->Kpi candidates
99 TClonesArray *inputArrayD0toKpi =
100 (TClonesArray*)aodIn->GetList()->FindObject("D0toKpi");
0bd2832b 101 if(!inputArrayD0toKpi) {
102 printf("AliAnalysisTaskSESelectHF::UserExec: D0toKpi branch not found!\n");
103 return;
104 }
0de9de87 105
106 //print event info
0bd2832b 107 //aodIn->GetHeader()->Print();
0de9de87 108
109 // primary vertex
110 AliAODVertex *vtx1 = (AliAODVertex*)aodIn->GetPrimaryVertex();
0bd2832b 111 //vtx1->Print();
0de9de87 112
113 // make trkIDtoEntry register (temporary)
114 Int_t trkIDtoEntry[100000];
115 for(Int_t it=0;it<aodIn->GetNumberOfTracks();it++) {
116 AliAODTrack *track = aodIn->GetTrack(it);
117 trkIDtoEntry[track->GetID()]=it;
118 }
119
120 Int_t iOutVerticesHF=0,iOutD0toKpi=0;
121 fVerticesHFTClArr->Delete();
122 iOutVerticesHF = fVerticesHFTClArr->GetEntriesFast();
123 TClonesArray &verticesHFRef = *fVerticesHFTClArr;
124 fD0toKpiTClArr->Delete();
125 iOutD0toKpi = fD0toKpiTClArr->GetEntriesFast();
126 TClonesArray &aodD0toKpiRef = *fD0toKpiTClArr;
127
128
129 // loop over D0->Kpi candidates
130 Int_t nInD0toKpi = inputArrayD0toKpi->GetEntriesFast();
131 printf("Number of D0->Kpi: %d\n",nInD0toKpi);
132
133 for (Int_t iD0toKpi = 0; iD0toKpi < nInD0toKpi; iD0toKpi++) {
134 AliAODRecoDecayHF2Prong *dIn = (AliAODRecoDecayHF2Prong*)inputArrayD0toKpi->UncheckedAt(iD0toKpi);
135 Bool_t unsetvtx=kFALSE;
136 if(!dIn->GetOwnPrimaryVtx()) {
137 dIn->SetOwnPrimaryVtx(vtx1); // needed to compute all variables
138 unsetvtx=kTRUE;
139 }
140 Int_t okD0=0,okD0bar=0;
141 if(dIn->SelectD0(fD0toKpiCuts,okD0,okD0bar)) {
142 // get daughter AOD tracks
143 AliAODTrack *trk0=aodIn->GetTrack(trkIDtoEntry[dIn->GetProngID(0)]);
144 AliAODTrack *trk1=aodIn->GetTrack(trkIDtoEntry[dIn->GetProngID(1)]);
145 // this will be replaced by
146 //AliAODTrack *trk0 = (AliAODTrack*)(dIn->GetSecondaryVtx()->GetDaughter(0));
147 printf("pt of positive track: %f\n",trk0->Pt());
148 printf("pt of negative track: %f\n",trk1->Pt());
0bd2832b 149 // HERE ONE COULD RECALCULATE THE VERTEX USING THE KF PACKAGE
0de9de87 150
151 // clone candidate for output AOD
152 AliAODVertex *v = new(verticesHFRef[iOutVerticesHF++])
153 AliAODVertex(*(dIn->GetSecondaryVtx()));
154 Double_t px[2]={dIn->PxProng(0),dIn->PxProng(1)};
155 Double_t py[2]={dIn->PyProng(0),dIn->PyProng(1)};
156 Double_t pz[2]={dIn->PzProng(0),dIn->PzProng(1)};
157 Double_t d0[2]={dIn->Getd0Prong(0),dIn->Getd0Prong(1)};
158 Double_t d0err[2]={dIn->Getd0errProng(0),dIn->Getd0errProng(1)};
159 AliAODRecoDecayHF2Prong *dOut=new(aodD0toKpiRef[iOutD0toKpi++])
160 AliAODRecoDecayHF2Prong(v,px,py,pz,d0,d0err,dIn->GetDCA());
0bd2832b 161 dOut->SetOwnPrimaryVtx((AliAODVertex*)((dIn->GetOwnPrimaryVtx())->Clone()));
b0ebe389 162 v->SetParent(dOut);
0de9de87 163 }
164 if(unsetvtx) dIn->UnsetOwnPrimaryVtx();
165 } // end loop on D0->Kpi
166
0bd2832b 167 printf("Number of selected D0->Kpi: %d\n",iOutD0toKpi);
168
0de9de87 169
170 return;
171}
172
173//________________________________________________________________________
174void AliAnalysisTaskSESelectHF::Terminate(Option_t */*option*/)
175{
176 // Terminate analysis
177 //
178 if(fDebug > 1) printf("AnalysisTaskSESelectHF: Terminate() \n");
179}
180
181//________________________________________________________________________
182void AliAnalysisTaskSESelectHF::SetD0toKpiCuts(Double_t cut0,Double_t cut1,
183 Double_t cut2,Double_t cut3,Double_t cut4,
184 Double_t cut5,Double_t cut6,
185 Double_t cut7,Double_t cut8)
186{
187 // Set the cuts for D0 selection
188 // cuts[0] = inv. mass half width [GeV]
189 // cuts[1] = dca [cm]
190 // cuts[2] = cosThetaStar
191 // cuts[3] = pTK [GeV/c]
192 // cuts[4] = pTPi [GeV/c]
193 // cuts[5] = d0K [cm] upper limit!
194 // cuts[6] = d0Pi [cm] upper limit!
195 // cuts[7] = d0d0 [cm^2]
196 // cuts[8] = cosThetaPoint
197
198 fD0toKpiCuts[0] = cut0;
199 fD0toKpiCuts[1] = cut1;
200 fD0toKpiCuts[2] = cut2;
201 fD0toKpiCuts[3] = cut3;
202 fD0toKpiCuts[4] = cut4;
203 fD0toKpiCuts[5] = cut5;
204 fD0toKpiCuts[6] = cut6;
205 fD0toKpiCuts[7] = cut7;
206 fD0toKpiCuts[8] = cut8;
207
208 return;
209}
210
211//________________________________________________________________________
212void AliAnalysisTaskSESelectHF::SetD0toKpiCuts(const Double_t cuts[9])
213{
214 // Set the cuts for D0 selection
215 // cuts[0] = inv. mass half width [GeV]
216 // cuts[1] = dca [cm]
217 // cuts[2] = cosThetaStar
218 // cuts[3] = pTK [GeV/c]
219 // cuts[4] = pTPi [GeV/c]
220 // cuts[5] = d0K [cm] upper limit!
221 // cuts[6] = d0Pi [cm] upper limit!
222 // cuts[7] = d0d0 [cm^2]
223 // cuts[8] = cosThetaPoint
224
225 for(Int_t i=0; i<9; i++) fD0toKpiCuts[i] = cuts[i];
226
227 return;
228}