Updates in PbPb cuts (Andrea Rossi)
[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
27de2dfb 16/* $Id$ */
17
0de9de87 18/////////////////////////////////////////////////////////////
19//
20// AliAnalysisTaskSE for the selection of heavy flavor
21// decay candidates and creation a stand-alone AOD.
22//
23// Author: A.Dainese, andrea.dainese@lnl.infn.it
24/////////////////////////////////////////////////////////////
25
26#include <TClonesArray.h>
27
b557eb43 28#include "AliAnalysisManager.h"
29#include "AliAODHandler.h"
0de9de87 30#include "AliAODEvent.h"
31#include "AliAODVertex.h"
32#include "AliAODTrack.h"
33#include "AliAODRecoDecayHF2Prong.h"
12bfc069 34#include "AliAnalysisVertexingHF.h"
0de9de87 35#include "AliAnalysisTaskSE.h"
36#include "AliAnalysisTaskSESelectHF.h"
37
38ClassImp(AliAnalysisTaskSESelectHF)
39
40
41//________________________________________________________________________
42AliAnalysisTaskSESelectHF::AliAnalysisTaskSESelectHF():
43AliAnalysisTaskSE(),
44fVerticesHFTClArr(0),
12bfc069 45fD0toKpiTClArr(0),
46fVHF(0)
0de9de87 47{
48 // Default constructor
0de9de87 49}
50
51//________________________________________________________________________
52AliAnalysisTaskSESelectHF::AliAnalysisTaskSESelectHF(const char *name):
53AliAnalysisTaskSE(name),
54fVerticesHFTClArr(0),
12bfc069 55fD0toKpiTClArr(0),
56fVHF(0)
0de9de87 57{
58 // Default constructor
0de9de87 59}
60
61//________________________________________________________________________
62AliAnalysisTaskSESelectHF::~AliAnalysisTaskSESelectHF()
63{
64 // Destructor
12bfc069 65
66 if (fVHF) {
67 delete fVHF;
68 fVHF = 0;
69 }
70
0de9de87 71}
72
73//________________________________________________________________________
74void AliAnalysisTaskSESelectHF::Init()
75{
76 // Initialization
77
78 if(fDebug > 1) printf("AnalysisTaskSESelectHF::Init() \n");
79
12bfc069 80 gROOT->LoadMacro("ConfigVertexingHF.C");
81
82 fVHF = (AliAnalysisVertexingHF*)gROOT->ProcessLine("ConfigVertexingHF()");
83 fVHF->PrintStatus();
84
0de9de87 85 return;
86}
87
88//________________________________________________________________________
89void AliAnalysisTaskSESelectHF::UserCreateOutputObjects()
90{
91 // Create the output container
92 //
93 if(fDebug > 1) printf("AnalysisTaskSESelectHF::UserCreateOutputObjects() \n");
94
95 fVerticesHFTClArr = new TClonesArray("AliAODVertex", 0);
96 fVerticesHFTClArr->SetName("VerticesHF");
080ac6fd 97 AddAODBranch("TClonesArray", &fVerticesHFTClArr);
0de9de87 98
99 fD0toKpiTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
100 fD0toKpiTClArr->SetName("D0toKpi");
080ac6fd 101 AddAODBranch("TClonesArray", &fD0toKpiTClArr);
0de9de87 102
103 return;
104}
105
106//________________________________________________________________________
107void AliAnalysisTaskSESelectHF::UserExec(Option_t */*option*/)
108{
109 // Execute analysis for current event:
110 // heavy flavor candidates selection and histograms
111
112 AliAODEvent *aodIn = dynamic_cast<AliAODEvent*> (InputEvent());
113
b557eb43 114 TClonesArray *inputArrayD0toKpi = 0;
115
116 if(!aodIn && AODEvent() && IsStandardAOD()) {
117 // In case there is an AOD handler writing a standard AOD, use the AOD
118 // event in memory rather than the input (ESD) event.
119 aodIn = dynamic_cast<AliAODEvent*> (AODEvent());
120 // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
121 // have to taken from the AOD event hold by the AliAODExtension
122 AliAODHandler* aodHandler = (AliAODHandler*)
123 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
124 if(aodHandler->GetExtensions()) {
125 AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
126 AliAODEvent *aodFromExt = ext->GetAOD();
127 // load D0 candidates
128 inputArrayD0toKpi=(TClonesArray*)aodFromExt->GetList()->FindObject("D0toKpi");
129 }
dc222f77 130 } else if(aodIn) {
b557eb43 131 // load D0 candidates
132 inputArrayD0toKpi=(TClonesArray*)aodIn->GetList()->FindObject("D0toKpi");
133 }
8931c313 134
20c2e031 135 if(!inputArrayD0toKpi || !aodIn) {
0bd2832b 136 printf("AliAnalysisTaskSESelectHF::UserExec: D0toKpi branch not found!\n");
137 return;
138 }
0de9de87 139
140 //print event info
0bd2832b 141 //aodIn->GetHeader()->Print();
0de9de87 142
143 // primary vertex
144 AliAODVertex *vtx1 = (AliAODVertex*)aodIn->GetPrimaryVertex();
0bd2832b 145 //vtx1->Print();
0de9de87 146
147 // make trkIDtoEntry register (temporary)
148 Int_t trkIDtoEntry[100000];
149 for(Int_t it=0;it<aodIn->GetNumberOfTracks();it++) {
150 AliAODTrack *track = aodIn->GetTrack(it);
151 trkIDtoEntry[track->GetID()]=it;
152 }
153
154 Int_t iOutVerticesHF=0,iOutD0toKpi=0;
155 fVerticesHFTClArr->Delete();
156 iOutVerticesHF = fVerticesHFTClArr->GetEntriesFast();
157 TClonesArray &verticesHFRef = *fVerticesHFTClArr;
158 fD0toKpiTClArr->Delete();
159 iOutD0toKpi = fD0toKpiTClArr->GetEntriesFast();
160 TClonesArray &aodD0toKpiRef = *fD0toKpiTClArr;
161
162
163 // loop over D0->Kpi candidates
164 Int_t nInD0toKpi = inputArrayD0toKpi->GetEntriesFast();
165 printf("Number of D0->Kpi: %d\n",nInD0toKpi);
166
167 for (Int_t iD0toKpi = 0; iD0toKpi < nInD0toKpi; iD0toKpi++) {
168 AliAODRecoDecayHF2Prong *dIn = (AliAODRecoDecayHF2Prong*)inputArrayD0toKpi->UncheckedAt(iD0toKpi);
169 Bool_t unsetvtx=kFALSE;
170 if(!dIn->GetOwnPrimaryVtx()) {
171 dIn->SetOwnPrimaryVtx(vtx1); // needed to compute all variables
172 unsetvtx=kTRUE;
173 }
20c2e031 174
cb8088a2 175 //Int_t okD0=0,okD0bar=0;
176 //if(dIn->SelectD0(fVHF->GetD0toKpiCuts(),okD0,okD0bar)) {
0de9de87 177 // get daughter AOD tracks
2a57ff58 178 AliAODTrack *trk0 = (AliAODTrack*)dIn->GetDaughter(0);
179 AliAODTrack *trk1 = (AliAODTrack*)dIn->GetDaughter(1);
180 if(!trk0 || !trk1) {
181 trk0=aodIn->GetTrack(trkIDtoEntry[dIn->GetProngID(0)]);
182 trk1=aodIn->GetTrack(trkIDtoEntry[dIn->GetProngID(1)]);
183 }
0de9de87 184 printf("pt of positive track: %f\n",trk0->Pt());
185 printf("pt of negative track: %f\n",trk1->Pt());
0bd2832b 186 // HERE ONE COULD RECALCULATE THE VERTEX USING THE KF PACKAGE
0de9de87 187
188 // clone candidate for output AOD
189 AliAODVertex *v = new(verticesHFRef[iOutVerticesHF++])
190 AliAODVertex(*(dIn->GetSecondaryVtx()));
0de9de87 191 AliAODRecoDecayHF2Prong *dOut=new(aodD0toKpiRef[iOutD0toKpi++])
2a57ff58 192 AliAODRecoDecayHF2Prong(*dIn);
193 dOut->SetSecondaryVtx(v);
0bd2832b 194 dOut->SetOwnPrimaryVtx((AliAODVertex*)((dIn->GetOwnPrimaryVtx())->Clone()));
b0ebe389 195 v->SetParent(dOut);
20c2e031 196
197
0de9de87 198 if(unsetvtx) dIn->UnsetOwnPrimaryVtx();
199 } // end loop on D0->Kpi
200
0bd2832b 201 printf("Number of selected D0->Kpi: %d\n",iOutD0toKpi);
202
0de9de87 203
204 return;
205}
206
207//________________________________________________________________________
208void AliAnalysisTaskSESelectHF::Terminate(Option_t */*option*/)
209{
210 // Terminate analysis
211 //
212 if(fDebug > 1) printf("AnalysisTaskSESelectHF: Terminate() \n");
213}
214