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