Fix
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAnalysisTaskSEVertexingHF.cxx
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
18 /////////////////////////////////////////////////////////////
19 //
20 // AliAnalysisTaskSE for the reconstruction of heavy flavor
21 // decays, using the class AliAnalysisVertexingHF.
22 //
23 // Author: A.Dainese, andrea.dainese@lnl.infn.it
24 /////////////////////////////////////////////////////////////
25
26 #include <TROOT.h>
27 #include <TSystem.h>
28 #include <TClonesArray.h>
29 #include <TList.h>
30 #include <TString.h>
31
32 #include "AliVEvent.h"
33 #include "AliAODEvent.h"
34 #include "AliAODHandler.h"
35 #include "AliESDEvent.h"
36 #include "AliAnalysisVertexingHF.h"
37 #include "AliAnalysisTaskSE.h"
38 #include "AliAnalysisManager.h"
39 #include "AliAnalysisTaskSEVertexingHF.h"
40
41 #include "AliESDUtils.h"
42 #include "AliAODHFUtil.h"
43
44
45 ClassImp(AliAnalysisTaskSEVertexingHF)
46
47
48 //________________________________________________________________________
49 AliAnalysisTaskSEVertexingHF::AliAnalysisTaskSEVertexingHF():
50 AliAnalysisTaskSE(),
51 fVHF(0),
52 fListOfCuts(0),
53 fDeltaAODFileName("AliAOD.VertexingHF.root"),
54 fVerticesHFTClArr(0),
55 fD0toKpiTClArr(0),
56 fJPSItoEleTClArr(0),
57 fCharm3ProngTClArr(0),
58 fCharm4ProngTClArr(0),
59 fDstarTClArr(0),
60 fCascadesTClArr(0),
61 fLikeSign2ProngTClArr(0),
62 fLikeSign3ProngTClArr(0),
63 fHFUtilInfo(0)
64 {
65   // Default constructor
66 }
67
68 //________________________________________________________________________
69 AliAnalysisTaskSEVertexingHF::AliAnalysisTaskSEVertexingHF(const char *name):
70 AliAnalysisTaskSE(name),
71 fVHF(0),
72 fListOfCuts(0),
73 fDeltaAODFileName("AliAOD.VertexingHF.root"),
74 fVerticesHFTClArr(0),
75 fD0toKpiTClArr(0),
76 fJPSItoEleTClArr(0),
77 fCharm3ProngTClArr(0),
78 fCharm4ProngTClArr(0),
79 fDstarTClArr(0),
80 fCascadesTClArr(0),
81 fLikeSign2ProngTClArr(0),
82 fLikeSign3ProngTClArr(0),
83 fHFUtilInfo(0)
84 {
85   // Standard constructor
86
87   DefineOutput(1,TList::Class()); // analysis cuts
88 }
89
90 //________________________________________________________________________
91 AliAnalysisTaskSEVertexingHF::~AliAnalysisTaskSEVertexingHF()
92 {
93   // Destructor
94
95   if(fListOfCuts) {
96     delete fListOfCuts;
97     fListOfCuts=NULL;
98   }
99
100 }  
101
102 //________________________________________________________________________
103 void AliAnalysisTaskSEVertexingHF::Init()
104 {
105   // Initialization
106   // Instanciates vHF and loads its parameters
107
108   if(fDebug > 1) printf("AnalysisTaskSEVertexingHF::Init() \n");
109
110   if(gROOT->LoadMacro("ConfigVertexingHF.C")) {
111     printf("AnalysisTaskSEVertexingHF::Init() \n Using $ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF.C\n");
112     gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF.C");
113   }
114
115   fVHF = (AliAnalysisVertexingHF*)gROOT->ProcessLine("ConfigVertexingHF()");  
116   fVHF->PrintStatus();
117
118
119   // write the objects AliRDHFCuts to a list to store in the output
120
121   fListOfCuts = fVHF->FillListOfCuts();
122
123   PostData(1,fListOfCuts);
124
125   AliAnalysisManager::GetAnalysisManager()->RegisterExtraFile(fDeltaAODFileName.Data());
126
127   return;
128 }
129
130 //________________________________________________________________________
131 void AliAnalysisTaskSEVertexingHF::UserCreateOutputObjects()
132 {
133   // Create the output container
134   //
135   if(fDebug > 1) printf("AnalysisTaskSEVertexingHF::UserCreateOutPutData() \n");
136   // Support both the case when the AOD + deltaAOD are produced in an ESD
137   // analysis or if the deltaAOD is produced on an analysis on AOD's. (A.G. 27/04/09)
138   if(!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) {
139     Fatal("UserCreateOutputObjects", "This task needs an AOD handler");
140     return;
141   }   
142   TString filename = fDeltaAODFileName;
143   // When running on standard AOD to produce deltas, IsStandardAOD is never set,
144   // If AODEvent is NULL, new branches have to be added to the new file(s) (A.G. 15/01/10)
145   if(!IsStandardAOD() && AODEvent()) filename = "";
146   if(!fVHF) {
147     printf("AnalysisTaskSEVertexingHF::UserCreateOutPutData() \n ERROR! no fvHF!\n");
148     return;
149   }
150
151   fVerticesHFTClArr = new TClonesArray("AliAODVertex", 0);
152   fVerticesHFTClArr->SetName("VerticesHF");
153   AddAODBranch("TClonesArray", &fVerticesHFTClArr, filename);
154
155   if(fVHF->GetD0toKpi()) {
156     fD0toKpiTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
157     fD0toKpiTClArr->SetName("D0toKpi");
158     AddAODBranch("TClonesArray", &fD0toKpiTClArr, filename);
159   }
160
161   if(fVHF->GetJPSItoEle()) {
162     fJPSItoEleTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
163     fJPSItoEleTClArr->SetName("JPSItoEle");
164     AddAODBranch("TClonesArray", &fJPSItoEleTClArr, filename);
165   }
166
167   if(fVHF->Get3Prong()) {
168     fCharm3ProngTClArr = new TClonesArray("AliAODRecoDecayHF3Prong", 0);
169     fCharm3ProngTClArr->SetName("Charm3Prong");
170     AddAODBranch("TClonesArray", &fCharm3ProngTClArr, filename);
171   }
172
173   if(fVHF->Get4Prong()) {
174     fCharm4ProngTClArr = new TClonesArray("AliAODRecoDecayHF4Prong", 0);
175     fCharm4ProngTClArr->SetName("Charm4Prong");
176     AddAODBranch("TClonesArray", &fCharm4ProngTClArr, filename);
177   }
178
179   if(fVHF->GetDstar()) {
180     fDstarTClArr = new TClonesArray("AliAODRecoCascadeHF", 0);
181     fDstarTClArr->SetName("Dstar");
182     AddAODBranch("TClonesArray", &fDstarTClArr, filename);
183   }
184
185   if(fVHF->GetCascades()){
186     fCascadesTClArr = new TClonesArray("AliAODRecoCascadeHF", 0);
187     fCascadesTClArr->SetName("CascadesHF");
188     AddAODBranch("TClonesArray", &fCascadesTClArr, filename);
189   }
190
191   if(fVHF->GetLikeSign()) {                      
192     fLikeSign2ProngTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
193     fLikeSign2ProngTClArr->SetName("LikeSign2Prong");
194     AddAODBranch("TClonesArray", &fLikeSign2ProngTClArr, filename);
195   }
196
197   if(fVHF->GetLikeSign() && fVHF->Get3Prong()) {                      
198     fLikeSign3ProngTClArr = new TClonesArray("AliAODRecoDecayHF3Prong", 0);
199     fLikeSign3ProngTClArr->SetName("LikeSign3Prong");
200     AddAODBranch("TClonesArray", &fLikeSign3ProngTClArr, filename);
201   }
202
203   //---Way to pass information temporarily not available in AOD---
204   // no if() {
205     fHFUtilInfo = new AliAODHFUtil("fHFUtilInfoC");
206     fHFUtilInfo->SetName("fHFUtilInfo");
207     AddAODBranch( "AliAODHFUtil", &fHFUtilInfo, filename);
208   // }
209   //--------------------------------------------------------------  
210
211   return;
212 }
213
214 //________________________________________________________________________
215 void AliAnalysisTaskSEVertexingHF::UserExec(Option_t */*option*/)
216 {
217   // Execute analysis for current event:
218   // heavy flavor vertexing
219   
220   AliVEvent *event = dynamic_cast<AliVEvent*> (InputEvent());
221   // In case there is an AOD handler writing a standard AOD, use the AOD 
222   // event in memory rather than the input (ESD) event. (A.G. 27/04/09)
223   if (AODEvent() && IsStandardAOD()) event = dynamic_cast<AliVEvent*> (AODEvent());
224
225   if (dynamic_cast<AliAODEvent*>(event)) {
226      AliAODHandler *aodhandler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
227      if (aodhandler) aodhandler->SetFillExtension(kTRUE);
228   }   
229
230   // heavy flavor vertexing
231   fVHF->FindCandidates(event,
232                        fVerticesHFTClArr,
233                        fD0toKpiTClArr,
234                        fJPSItoEleTClArr,
235                        fCharm3ProngTClArr,
236                        fCharm4ProngTClArr,
237                        fDstarTClArr,
238                        fCascadesTClArr,
239                        fLikeSign2ProngTClArr,
240                        fLikeSign3ProngTClArr);
241   
242   //---Way to pass information temporarily not available in AOD---
243   AliESDEvent *eventE = dynamic_cast<AliESDEvent*> (InputEvent());
244   if(eventE) {
245     Float_t *vChCorr = new Float_t[64];
246     Float_t dummy;
247     AliESDUtils::GetCorrV0(eventE,dummy,NULL,vChCorr);
248     fHFUtilInfo->SetVZERO( vChCorr );
249     delete [] vChCorr;
250   }
251   //--------------------------------------------------------------
252
253   return;
254 }
255
256 //________________________________________________________________________
257 void AliAnalysisTaskSEVertexingHF::Terminate(Option_t */*option*/)
258 {
259   // Terminate analysis
260   //
261   if(fDebug > 1) printf("AnalysisTaskSEVertexingHF: Terminate() \n");
262 }