]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/correlationHF/AliAnalysisTaskDxHFECorrelation.cxx
Update in D-electon correlation code (Hege, Matthias)
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliAnalysisTaskDxHFECorrelation.cxx
CommitLineData
72c0a987 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* Sedat Altinpinar <Sedat.Altinpinar@cern.ch> *
9//* Hege Erdal <hege.erdal@gmail.com> *
10//* *
11//* Permission to use, copy, modify and distribute this software and its *
12//* documentation strictly for non-commercial purposes is hereby granted *
13//* without fee, provided that the above copyright notice appears in all *
14//* copies and that both the copyright notice and this permission notice *
15//* appear in the supporting documentation. The authors make no claims *
16//* about the suitability of this software for any purpose. It is *
17//* provided "as is" without express or implied warranty. *
18//**************************************************************************
19
20/// @file AliAnalysisTaskDxHFECorrelation.cxx
21/// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
22/// @date 2012-03-19
23/// @brief AnalysisTask D0 - HFE correlation
24///
25
26#include "AliAnalysisTaskDxHFECorrelation.h"
27#include "AliDxHFECorrelation.h"
28#include "AliDxHFEParticleSelectionD0.h"
29#include "AliDxHFEParticleSelectionEl.h"
30#include "AliAnalysisManager.h"
31#include "AliLog.h"
32#include "AliESDInputHandler.h"
9535cec9 33#include "AliAnalysisDataSlot.h"
34#include "AliAnalysisDataContainer.h"
35#include "AliAnalysisManager.h"
36#include "AliVertexerTracks.h"
37#include "AliAODHandler.h"
38#include "AliInputEventHandler.h"
39#include "AliAODEvent.h"
40#include "AliAODVertex.h"
41#include "AliAODTrack.h"
42#include "AliAODMCHeader.h"
43#include "AliAODMCParticle.h"
44#include "AliAODRecoDecayHF2Prong.h"
45#include "AliAODRecoCascadeHF.h"
46#include "AliRDHFCutsD0toKpi.h"
47#include "AliPID.h"
48#include "AliPIDResponse.h"
49#include "AliHFEcontainer.h"
50#include "AliHFEpid.h"
51#include "AliHFEpidBase.h"
52#include "AliHFEcuts.h"
53#include "AliHFEtools.h"
54#include "TObject.h"
72c0a987 55#include "TChain.h"
56#include "TSystem.h"
57#include "TFile.h"
58#include <memory>
59
9535cec9 60using namespace std;
61
72c0a987 62/// ROOT macro for the implementation of ROOT specific class methods
63ClassImp(AliAnalysisTaskDxHFECorrelation)
64
65AliAnalysisTaskDxHFECorrelation::AliAnalysisTaskDxHFECorrelation(const char* opt)
66 : AliAnalysisTaskSE("AliAnalysisTaskDxHFECorrelation")
67 , fOutput(0)
68 , fOption(opt)
69 , fCorrelation(NULL)
70 , fD0s(NULL)
71 , fElectrons(NULL)
9535cec9 72 , fCutsD0(NULL)
73 , fCutsHFE(NULL)
74 , fPID(NULL)
75 , fFillOnlyD0D0bar(0)
76 , fUseMC(kFALSE)
72c0a987 77{
78 // constructor
79 //
80 //
72c0a987 81 DefineSlots();
9535cec9 82 fPID = new AliHFEpid("hfePid");
83
72c0a987 84}
85
86int AliAnalysisTaskDxHFECorrelation::DefineSlots()
87{
88 // define the data slots
89 DefineInput(0, TChain::Class());
90 DefineOutput(1, TList::Class());
9535cec9 91 DefineOutput(2,AliRDHFCutsD0toKpi::Class());
72c0a987 92 return 0;
93}
94
95AliAnalysisTaskDxHFECorrelation::~AliAnalysisTaskDxHFECorrelation()
96{
97 // destructor
98 //
99 //
100
101 // histograms are in the output list and deleted when the output
102 // list is deleted by the TSelector dtor
103
104 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
105 delete fOutput;
106 fOutput = 0;
107 }
108 if (fD0s) delete fD0s;
109 fD0s=NULL;
110 if (fElectrons) delete fElectrons;
111 fElectrons=NULL;
112 if (fCorrelation) delete fCorrelation;
113 fCorrelation=NULL;
9535cec9 114 if (fCutsD0) delete fCutsD0;
115 fCutsD0=NULL;
116 if (fCutsHFE) delete fCutsHFE;
117 fCutsHFE=NULL;
118 if(fPID) delete fPID;
119 fPID=NULL;
120
121
72c0a987 122}
123
124void AliAnalysisTaskDxHFECorrelation::UserCreateOutputObjects()
125{
126 // create result objects and add to output list
127
9535cec9 128 //Initialize PID for electron selection
129 if(!fPID->GetNumberOfPIDdetectors()) {
130 fPID->AddDetector("TOF",0);
131 fPID->AddDetector("TPC",1);
132 }
133 fPID->InitializePID();
72c0a987 134
9535cec9 135 fOutput = new TList;
136 fOutput->SetOwner();
137
138 // setting up for D0s
139 TString selectionD0Options;
140 switch (fFillOnlyD0D0bar) {
141 case 1: selectionD0Options+="FillOnlyD0 "; break;
142 case 2: selectionD0Options+="FillOnlyD0bar "; break;
143 default: selectionD0Options+="FillD0D0bar ";
72c0a987 144 }
145
9535cec9 146 fD0s=new AliDxHFEParticleSelectionD0(selectionD0Options);
147 fD0s->SetCuts(fCutsD0);
148 fD0s->InitControlObjects();
72c0a987 149
9535cec9 150 //Electrons
151 fElectrons=new AliDxHFEParticleSelectionEl;
152 fElectrons->SetCuts(fPID, AliDxHFEParticleSelectionEl::kCutPID);
153 fElectrons->SetCuts(fCutsHFE, AliDxHFEParticleSelectionEl::kCutHFE);
154 fElectrons->InitControlObjects();
155
156 //Correlation
157 fCorrelation=new AliDxHFECorrelation;
158 fCorrelation->SetCuts(dynamic_cast<AliRDHFCutsD0toKpi*>(fCutsD0));
159 fCorrelation->Init();
160
161 // Fix for merging:
162 // Retrieving the individual objects created
163 // and storing them instead of fD0s,fElectrons etc..
164 TList *list =(TList*)fD0s->GetControlObjects();
165 TObject *obj=NULL;
166
167 TIter next(list);
168 while((obj = next())){
169 fOutput->Add(obj);
170 }
171
172 list=(TList*)fCorrelation->GetControlObjects();
173 next=TIter(list);
174 while((obj= next())){
175 fOutput->Add(obj);
176 }
177
178 list=(TList*)fElectrons->GetControlObjects();
179 next=TIter(list);
180 while((obj = next()))
181 fOutput->Add(obj);
182
183 if (fCutsD0) {
184 AliRDHFCutsD0toKpi* cuts=dynamic_cast<AliRDHFCutsD0toKpi*>(fCutsD0);
185 if (!cuts) {
186 AliFatal(Form("cut object %s is of incorrect type %s, expecting AliRDHFCutsD0toKpi", fCutsD0->GetName(), fCutsD0->ClassName()));
187 return;
188 }
189 }
190
191 // TODO: why copy? cleanup?
192 AliRDHFCutsD0toKpi* copyfCuts=new AliRDHFCutsD0toKpi(dynamic_cast<AliRDHFCutsD0toKpi&>(*fCutsD0));
193 const char* nameoutput=GetOutputSlot(2)->GetContainer()->GetName();
194 copyfCuts->SetName(nameoutput);
72c0a987 195
196 // all tasks must post data once for all outputs
197 PostData(1, fOutput);
9535cec9 198 PostData(2,copyfCuts);
199
72c0a987 200}
201
202void AliAnalysisTaskDxHFECorrelation::UserExec(Option_t* /*option*/)
203{
204 // process the event
72c0a987 205 TObject* pInput=InputEvent();
206 if (!pInput) {
207 AliError("failed to get input");
208 return;
209 }
210 AliVEvent *pEvent = dynamic_cast<AliVEvent*>(pInput);
9535cec9 211 TClonesArray *inputArray=0;
212
213 if(!pEvent && AODEvent() && IsStandardAOD()) { //Not sure if this is needed.. Keep it for now.
214 // In case there is an AOD handler writing a standard AOD, use the AOD
215 // event in memory rather than the input (ESD) event.
216 pEvent = dynamic_cast<AliAODEvent*> (AODEvent());
217 // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
218 // have to taken from the AOD event hold by the AliAODExtension
219 AliAODHandler* aodHandler = (AliAODHandler*)
220 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
221
222 if(aodHandler->GetExtensions()) {
223 AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
224 AliAODEvent* aodFromExt = ext->GetAOD();
225 inputArray=(TClonesArray*)aodFromExt->GetList()->FindObject("D0toKpi");
226 }
227 } else if(pEvent) {
228 inputArray=(TClonesArray*)pEvent->GetList()->FindObject("D0toKpi");
229 }
230 if(!inputArray || !pEvent) {
231 AliError("Input branch not found!\n");
232 return;
233 }
234 // fix for temporary bug in ESDfilter
235 // the AODs with null vertex pointer didn't pass the PhysSel
236 if(!pEvent->GetPrimaryVertex() || TMath::Abs(pEvent->GetMagneticField())<0.001){
237 AliDebug(2,"Rejected at GetPrimaryvertex");
238 return;
239 }
240
241 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsAll);
242 AliRDHFCuts* cutsd0=dynamic_cast<AliRDHFCuts*>(fCutsD0);
243 if (!cutsd0) return; // Fatal thrown already in initialization
244
245 if(!cutsd0->IsEventSelected(pEvent)) {
246 AliDebug(2,"rejected at IsEventSelected");
247 return;
248 }
249
250 if(!fPID->IsInitialized()){
251 // Initialize PID with the given run number
252 AliWarning("PID not initialised, get from Run no");
253 fPID->InitializePID(pEvent->GetRunNumber());
254 }
255
256 AliPIDResponse *pidResponse = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler())->GetPIDResponse();
257 if(!pidResponse){
258 AliDebug(1, "Using default PID Response");
259 pidResponse = AliHFEtools::GetDefaultPID(kFALSE, fInputEvent->IsA() == AliAODEvent::Class());
260 }
261
262 fPID->SetPIDResponse(pidResponse);
263
264
265 Int_t nInD0toKpi = inputArray->GetEntriesFast();
266
267 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsSel);
268
269 //TODO: pSelectedD0s will now contain both D0 and D0bar. Probably add argument to Select
270 // which determines which ones to return.
271 std::auto_ptr<TObjArray> pSelectedD0s(fD0s->Select(inputArray,pEvent));
272 if(! pSelectedD0s.get()) {
273 return;
274 }
275 Int_t nD0Selected = pSelectedD0s->GetEntriesFast();
276
277 // No need to go further if no D0s are found. Not sure if this is the best way though..
278 // At the moment this means no control histos can be implemented in AliDxHFECorrelation
279 if(nD0Selected==0){
280 //AliInfo("No D0s found in this event");
72c0a987 281 return;
282 }
9535cec9 283 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsD0);
284
72c0a987 285
72c0a987 286 std::auto_ptr<TObjArray> pSelectedElectrons(fElectrons->Select(pEvent));
9535cec9 287
288 // TODO: use the array of selected track for something, right now
289 // only the control histograms of the selection class are filled
290 // note: the pointer is deleted automatically once the scope is left
291 // if the array should be published, the auto pointer must be released
292 // first, however some other cleanup will be necessary in that case
293 // probably a clone with a reduced AliVParticle implementation is
294 // appropriate.
295
296
297 if(! pSelectedElectrons.get()) {
298 return;
299 }
300
301 Int_t nElSelected = pSelectedElectrons->GetEntriesFast();
302
303 // No need to go further if no electrons are found. Not sure if this is the best way though..
304 // At the moment this means no control histos can be implemented in AliDxHFECorrelation
305 if(nElSelected==0){
306 //AliInfo("No electrons found in this event");
307 return;
308 }
309
310 AliDebug(4,Form("Number of D0->Kpi Start: %d , End: %d Electrons Selected: %d\n", nInD0toKpi, nD0Selected, nElSelected));
311
312 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsD0e);
313
314 //This is only called if there are electrons and D0s present.
72c0a987 315 int iResult=fCorrelation->Fill(pSelectedD0s.get(), pSelectedElectrons.get());
9535cec9 316
72c0a987 317 if (iResult<0) {
318 AliError(Form("%s processing failed with error %d", fCorrelation->GetName(), iResult));
319 }
320
321 PostData(1, fOutput);
322}
323
324void AliAnalysisTaskDxHFECorrelation::FinishTaskOutput()
325{
326 // end of the processing
327}
328
329void AliAnalysisTaskDxHFECorrelation::Terminate(Option_t *)
330{
331 // last action on the client
332 fOutput = dynamic_cast<TList*> (GetOutputData(1));
333 if (!fOutput) {
334 AliFatal("failed to get output container");
335 return;
336 }
337
338}