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