3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* Sedat Altinpinar <Sedat.Altinpinar@cern.ch> *
9 //* Hege Erdal <hege.erdal@gmail.com> *
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 //**************************************************************************
20 /// @file AliAnalysisTaskDxHFECorrelation.cxx
21 /// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
23 /// @brief AnalysisTask D0 - HFE correlation
26 #include "AliAnalysisTaskDxHFECorrelation.h"
27 #include "AliDxHFECorrelation.h"
28 #include "AliDxHFEParticleSelectionD0.h"
29 #include "AliDxHFEParticleSelectionMCD0.h"
30 #include "AliDxHFEParticleSelectionEl.h"
31 #include "AliDxHFEParticleSelectionMCEl.h"
32 #include "AliDxHFEParticleSelection.h"
33 #include "AliAnalysisManager.h"
35 #include "AliESDInputHandler.h"
36 #include "AliAnalysisDataSlot.h"
37 #include "AliAnalysisDataContainer.h"
38 #include "AliAnalysisManager.h"
39 #include "AliVertexerTracks.h"
40 #include "AliAODHandler.h"
41 #include "AliInputEventHandler.h"
42 #include "AliAODEvent.h"
43 #include "AliAODVertex.h"
44 #include "AliAODTrack.h"
45 #include "AliAODMCHeader.h"
46 #include "AliAODMCParticle.h"
47 #include "AliAODRecoDecayHF2Prong.h"
48 #include "AliAODRecoCascadeHF.h"
49 #include "AliRDHFCutsD0toKpi.h"
51 #include "AliPIDResponse.h"
52 #include "AliHFEcontainer.h"
53 #include "AliHFEpid.h"
54 #include "AliHFEpidBase.h"
55 #include "AliHFEcuts.h"
56 #include "AliHFEtools.h"
65 /// ROOT macro for the implementation of ROOT specific class methods
66 ClassImp(AliAnalysisTaskDxHFECorrelation)
68 AliAnalysisTaskDxHFECorrelation::AliAnalysisTaskDxHFECorrelation(const char* opt)
69 : AliAnalysisTaskSE("AliAnalysisTaskDxHFECorrelation")
85 fPID = new AliHFEpid("hfePid");
89 int AliAnalysisTaskDxHFECorrelation::DefineSlots()
91 // define the data slots
92 DefineInput(0, TChain::Class());
93 DefineOutput(1, TList::Class());
94 DefineOutput(2,AliRDHFCutsD0toKpi::Class());
98 AliAnalysisTaskDxHFECorrelation::~AliAnalysisTaskDxHFECorrelation()
104 // histograms are in the output list and deleted when the output
105 // list is deleted by the TSelector dtor
107 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
111 if (fD0s) delete fD0s;
113 if (fElectrons) delete fElectrons;
115 if (fCorrelation) delete fCorrelation;
117 // external object, do not delete
119 // external object, do not delete
121 if(fPID) delete fPID;
127 void AliAnalysisTaskDxHFECorrelation::UserCreateOutputObjects()
129 // create result objects and add to output list
131 //Initialize PID for electron selection
132 if(!fPID->GetNumberOfPIDdetectors()) {
133 fPID->AddDetector("TOF",0);
134 fPID->AddDetector("TPC",1);
136 fPID->InitializePID();
141 // setting up for D0s
142 TString selectionD0Options;
143 switch (fFillOnlyD0D0bar) {
144 case 1: selectionD0Options+="FillOnlyD0 "; break;
145 case 2: selectionD0Options+="FillOnlyD0bar "; break;
146 default: selectionD0Options+="FillD0D0bar ";
149 if(fUseMC) fD0s=new AliDxHFEParticleSelectionMCD0(selectionD0Options);
150 else fD0s=new AliDxHFEParticleSelectionD0(selectionD0Options);
151 fD0s->SetCuts(fCutsD0);
155 if(fUseMC) fElectrons=new AliDxHFEParticleSelectionMCEl;
156 else fElectrons=new AliDxHFEParticleSelectionEl;
157 fElectrons->SetCuts(fPID, AliDxHFEParticleSelectionEl::kCutPID);
158 fElectrons->SetCuts(fCutsHFE, AliDxHFEParticleSelectionEl::kCutHFE);
162 fCorrelation=new AliDxHFECorrelation;
163 fCorrelation->SetCuts(dynamic_cast<AliRDHFCutsD0toKpi*>(fCutsD0));
164 // TODO: check if we can get rid of the mc flag in the correlation analysis class
165 fCorrelation->SetUseMC(fUseMC);
166 fCorrelation->Init();
169 // Retrieving the individual objects created
170 // and storing them instead of fD0s, fElectrons etc..
171 TList *list =(TList*)fD0s->GetControlObjects();
175 while((obj = next())){
179 list=(TList*)fCorrelation->GetControlObjects();
181 while((obj= next())){
185 list=(TList*)fElectrons->GetControlObjects();
187 while((obj = next()))
190 PostData(1, fOutput);
192 AliRDHFCutsD0toKpi* cuts=dynamic_cast<AliRDHFCutsD0toKpi*>(fCutsD0);
194 AliFatal(Form("cut object %s is of incorrect type %s, expecting AliRDHFCutsD0toKpi", fCutsD0->GetName(), fCutsD0->ClassName()));
197 // TODO: why copy? cleanup?
198 AliRDHFCutsD0toKpi* copyfCuts=new AliRDHFCutsD0toKpi(*cuts);
199 const char* nameoutput=GetOutputSlot(2)->GetContainer()->GetName();
200 copyfCuts->SetName(nameoutput);
202 PostData(2,copyfCuts);
206 void AliAnalysisTaskDxHFECorrelation::UserExec(Option_t* /*option*/)
209 TObject* pInput=InputEvent();
211 AliError("failed to get input");
214 AliVEvent *pEvent = dynamic_cast<AliVEvent*>(pInput);
215 TClonesArray *inputArray=0;
217 if(!pEvent && AODEvent() && IsStandardAOD()) { //Not sure if this is needed.. Keep it for now.
218 // In case there is an AOD handler writing a standard AOD, use the AOD
219 // event in memory rather than the input (ESD) event.
220 pEvent = dynamic_cast<AliAODEvent*> (AODEvent());
221 // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
222 // have to taken from the AOD event hold by the AliAODExtension
223 AliAODHandler* aodHandler = (AliAODHandler*)
224 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
226 if(aodHandler->GetExtensions()) {
227 AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
228 AliAODEvent* aodFromExt = ext->GetAOD();
229 inputArray=(TClonesArray*)aodFromExt->GetList()->FindObject("D0toKpi");
232 inputArray=(TClonesArray*)pEvent->GetList()->FindObject("D0toKpi");
234 if(!inputArray || !pEvent) {
235 AliError("Input branch not found!\n");
238 // fix for temporary bug in ESDfilter
239 // the AODs with null vertex pointer didn't pass the PhysSel
240 if(!pEvent->GetPrimaryVertex() || TMath::Abs(pEvent->GetMagneticField())<0.001){
241 AliDebug(2,"Rejected at GetPrimaryvertex");
245 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsAll);
246 AliRDHFCuts* cutsd0=dynamic_cast<AliRDHFCuts*>(fCutsD0);
247 if (!cutsd0) return; // Fatal thrown already in initialization
249 if(!cutsd0->IsEventSelected(pEvent)) {
250 AliDebug(2,"rejected at IsEventSelected");
254 if(!fPID->IsInitialized()){
255 // Initialize PID with the given run number
256 AliWarning("PID not initialised, get from Run no");
257 fPID->InitializePID(pEvent->GetRunNumber());
260 AliPIDResponse *pidResponse = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler())->GetPIDResponse();
262 AliDebug(1, "Using default PID Response");
263 pidResponse = AliHFEtools::GetDefaultPID(kFALSE, fInputEvent->IsA() == AliAODEvent::Class());
266 fPID->SetPIDResponse(pidResponse);
269 Int_t nInD0toKpi = inputArray->GetEntriesFast();
271 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsSel);
273 //TODO: pSelectedD0s will now contain both D0 and D0bar. Probably add argument to Select
274 // which determines which ones to return.
275 std::auto_ptr<TObjArray> pSelectedD0s(fD0s->Select(inputArray,pEvent));
276 if(! pSelectedD0s.get()) {
279 Int_t nD0Selected = pSelectedD0s->GetEntriesFast();
281 // No need to go further if no D0s are found. Not sure if this is the best way though..
282 // At the moment this means no control histos can be implemented in AliDxHFECorrelation
284 //AliInfo("No D0s found in this event");
287 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsD0);
290 std::auto_ptr<TObjArray> pSelectedElectrons(fElectrons->Select(pEvent));
292 // TODO: use the array of selected track for something, right now
293 // only the control histograms of the selection class are filled
294 // note: the pointer is deleted automatically once the scope is left
295 // if the array should be published, the auto pointer must be released
296 // first, however some other cleanup will be necessary in that case
297 // probably a clone with a reduced AliVParticle implementation is
301 if(! pSelectedElectrons.get()) {
305 Int_t nElSelected = pSelectedElectrons->GetEntriesFast();
307 // No need to go further if no electrons are found. Not sure if this is the best way though..
308 // At the moment this means no control histos can be implemented in AliDxHFECorrelation
310 //AliInfo("No electrons found in this event");
314 AliDebug(4,Form("Number of D0->Kpi Start: %d , End: %d Electrons Selected: %d\n", nInD0toKpi, nD0Selected, nElSelected));
316 fCorrelation->HistogramEventProperties(AliDxHFECorrelation::kEventsD0e);
318 //This is only called if there are electrons and D0s present.
319 int iResult=fCorrelation->Fill(pSelectedD0s.get(), pSelectedElectrons.get());
322 AliError(Form("%s processing failed with error %d", fCorrelation->GetName(), iResult));
325 PostData(1, fOutput);
328 void AliAnalysisTaskDxHFECorrelation::FinishTaskOutput()
330 // end of the processing
333 void AliAnalysisTaskDxHFECorrelation::Terminate(Option_t *)
335 // last action on the client
336 fOutput = dynamic_cast<TList*> (GetOutputData(1));
338 AliFatal("failed to get output container");