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