90152e11d296c812b9f9a1b3904970d8f1c333cb
[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 /////////////////////////////////////////////////////////////
17 //
18 // AliAnalysisTaskSE for the reconstruction of heavy flavor
19 // decays, using the class AliAnalysisVertexingHF.
20 //
21 // Author: A.Dainese, andrea.dainese@lnl.infn.it
22 /////////////////////////////////////////////////////////////
23
24 #include <TROOT.h>
25 #include <TSystem.h>
26 #include <TClonesArray.h>
27
28 #include "AliVEvent.h"
29 #include "AliAODEvent.h"
30 #include "AliESDEvent.h"
31 #include "AliAnalysisVertexingHF.h"
32 #include "AliAnalysisTaskSE.h"
33 #include "AliAnalysisManager.h"
34 #include "AliAnalysisTaskSEVertexingHF.h"
35
36 ClassImp(AliAnalysisTaskSEVertexingHF)
37
38
39 //________________________________________________________________________
40 AliAnalysisTaskSEVertexingHF::AliAnalysisTaskSEVertexingHF():
41 AliAnalysisTaskSE(),
42 fVHF(0),
43 fVerticesHFTClArr(0),
44 fD0toKpiTClArr(0),
45 fJPSItoEleTClArr(0),
46 fCharm3ProngTClArr(0),
47 fCharm4ProngTClArr(0),
48 fDstarTClArr(0),
49 fLikeSign2ProngTClArr(0),
50 fLikeSign3ProngTClArr(0)
51 {
52   // Default constructor
53 }
54
55 //________________________________________________________________________
56 AliAnalysisTaskSEVertexingHF::AliAnalysisTaskSEVertexingHF(const char *name):
57 AliAnalysisTaskSE(name),
58 fVHF(0),
59 fVerticesHFTClArr(0),
60 fD0toKpiTClArr(0),
61 fJPSItoEleTClArr(0),
62 fCharm3ProngTClArr(0),
63 fCharm4ProngTClArr(0),
64 fDstarTClArr(0),
65 fLikeSign2ProngTClArr(0),
66 fLikeSign3ProngTClArr(0)
67 {
68   // Default constructor
69 }
70
71 //________________________________________________________________________
72 AliAnalysisTaskSEVertexingHF::~AliAnalysisTaskSEVertexingHF()
73 {
74   // Destructor
75 }  
76
77 //________________________________________________________________________
78 void AliAnalysisTaskSEVertexingHF::Init()
79 {
80   // Initialization
81   // Instanciates vHF and loads its parameters
82
83   if(fDebug > 1) printf("AnalysisTaskSEVertexingHF::Init() \n");
84
85   if(gROOT->LoadMacro("ConfigVertexingHF.C")) {
86     printf("AnalysisTaskSEVertexingHF::Init() \n Using $ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF.C\n");
87     gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF.C");
88   }
89
90   fVHF = (AliAnalysisVertexingHF*)gROOT->ProcessLine("ConfigVertexingHF()");  
91   fVHF->PrintStatus();
92   AliAnalysisManager::GetAnalysisManager()->RegisterExtraFile("AliAOD.VertexingHF.root");
93
94   return;
95 }
96
97 //________________________________________________________________________
98 void AliAnalysisTaskSEVertexingHF::UserCreateOutputObjects()
99 {
100   // Create the output container
101   //
102   if(fDebug > 1) printf("AnalysisTaskSEVertexingHF::UserCreateOutPutData() \n");
103   // Support both the case when the AOD + deltaAOD are produced in an ESD
104   // analysis or if the deltaAOD is produced on an analysis on AOD's. (A.G. 27/04/09)
105   if(!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) {
106     Fatal("UserCreateOutputObjects", "This task needs an AOD handler");
107     return;
108   }   
109   TString filename = "AliAOD.VertexingHF.root";
110   // When running on standard AOD to produce deltas, IsStandardAOD is never set,
111   // If AODEvent is NULL, new branches have to be added to the new file(s) (A.G. 15/01/10)
112   if(!IsStandardAOD() && AODEvent()) filename = "";
113   if(!fVHF) {
114     printf("AnalysisTaskSEVertexingHF::UserCreateOutPutData() \n ERROR! no fvHF!\n");
115     return;
116   }
117
118   fVerticesHFTClArr = new TClonesArray("AliAODVertex", 0);
119   fVerticesHFTClArr->SetName("VerticesHF");
120   AddAODBranch("TClonesArray", &fVerticesHFTClArr, filename);
121
122   if(fVHF->GetD0toKpi()) {
123     fD0toKpiTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
124     fD0toKpiTClArr->SetName("D0toKpi");
125     AddAODBranch("TClonesArray", &fD0toKpiTClArr, filename);
126   }
127
128   if(fVHF->GetJPSItoEle()) {
129     fJPSItoEleTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
130     fJPSItoEleTClArr->SetName("JPSItoEle");
131     AddAODBranch("TClonesArray", &fJPSItoEleTClArr, filename);
132   }
133
134   if(fVHF->Get3Prong()) {
135     fCharm3ProngTClArr = new TClonesArray("AliAODRecoDecayHF3Prong", 0);
136     fCharm3ProngTClArr->SetName("Charm3Prong");
137     AddAODBranch("TClonesArray", &fCharm3ProngTClArr, filename);
138   }
139
140   if(fVHF->Get4Prong()) {
141     fCharm4ProngTClArr = new TClonesArray("AliAODRecoDecayHF4Prong", 0);
142     fCharm4ProngTClArr->SetName("Charm4Prong");
143     AddAODBranch("TClonesArray", &fCharm4ProngTClArr, filename);
144   }
145
146   if(fVHF->GetDstar()) {
147     fDstarTClArr = new TClonesArray("AliAODRecoCascadeHF", 0);
148     fDstarTClArr->SetName("Dstar");
149     AddAODBranch("TClonesArray", &fDstarTClArr, filename);
150   }
151
152   if(fVHF->GetLikeSign()) {                      
153     fLikeSign2ProngTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
154     fLikeSign2ProngTClArr->SetName("LikeSign2Prong");
155     AddAODBranch("TClonesArray", &fLikeSign2ProngTClArr, filename);
156   }
157
158   if(fVHF->GetLikeSign() && fVHF->Get3Prong()) {                      
159     fLikeSign3ProngTClArr = new TClonesArray("AliAODRecoDecayHF3Prong", 0);
160     fLikeSign3ProngTClArr->SetName("LikeSign3Prong");
161     AddAODBranch("TClonesArray", &fLikeSign3ProngTClArr, filename);
162   }
163
164   return;
165 }
166
167 //________________________________________________________________________
168 void AliAnalysisTaskSEVertexingHF::UserExec(Option_t */*option*/)
169 {
170   // Execute analysis for current event:
171   // heavy flavor vertexing
172   
173   AliVEvent *event = dynamic_cast<AliVEvent*> (InputEvent());
174   // In case there is an AOD handler writing a standard AOD, use the AOD 
175   // event in memory rather than the input (ESD) event. (A.G. 27/04/09)
176   if (AODEvent() && IsStandardAOD()) event = dynamic_cast<AliVEvent*> (AODEvent());
177
178   // heavy flavor vertexing
179   fVHF->FindCandidates(event,
180                        fVerticesHFTClArr,
181                        fD0toKpiTClArr,
182                        fJPSItoEleTClArr,
183                        fCharm3ProngTClArr,
184                        fCharm4ProngTClArr,
185                        fDstarTClArr,
186                        fLikeSign2ProngTClArr,
187                        fLikeSign3ProngTClArr);
188   
189   return;
190 }
191
192 //________________________________________________________________________
193 void AliAnalysisTaskSEVertexingHF::Terminate(Option_t */*option*/)
194 {
195   // Terminate analysis
196   //
197   if(fDebug > 1) printf("AnalysisTaskSEVertexingHF: Terminate() \n");
198 }