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