]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/correlationHF/AliAnalysisTaskDxHFEParticleSelection.cxx
DxHFE update (Hege)
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliAnalysisTaskDxHFEParticleSelection.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 AliAnalysisTaskDxHFEParticleSelection.cxx
21/// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
22/// @date 2012-03-19
23/// @brief AnalysisTask electron selection for D0 - HFE correlation
24///
25
26#include "AliAnalysisTaskDxHFEParticleSelection.h"
27#include "AliDxHFEParticleSelection.h"
93fcaf9f 28#include "AliDxHFEParticleSelectionD0.h"
d731501a 29#include "AliDxHFEParticleSelectionMCD0.h"
2229ac91 30#include "AliDxHFEParticleSelectionEl.h"
31#include "AliDxHFEParticleSelectionMCEl.h"
72c0a987 32#include "AliAnalysisManager.h"
9535cec9 33#include "AliAnalysisCuts.h"
72c0a987 34#include "AliLog.h"
9535cec9 35#include "TH1F.h"
72c0a987 36#include "AliESDInputHandler.h"
9535cec9 37#include "AliAODHandler.h"
38#include "AliAODRecoDecayHF2Prong.h"
39#include "AliRDHFCutsD0toKpi.h"
2229ac91 40#include "AliHFEtools.h"
72c0a987 41#include "TChain.h"
42#include "TSystem.h"
2229ac91 43#include "TObjArray.h"
72c0a987 44#include "TFile.h"
2229ac91 45#include "TList.h"
9535cec9 46#include "TObjArray.h"
93fcaf9f 47#include <memory>
72c0a987 48
9535cec9 49using namespace std;
50
72c0a987 51/// ROOT macro for the implementation of ROOT specific class methods
52ClassImp(AliAnalysisTaskDxHFEParticleSelection)
53
54AliAnalysisTaskDxHFEParticleSelection::AliAnalysisTaskDxHFEParticleSelection(const char* opt)
55 : AliAnalysisTaskSE("AliAnalysisTaskDxHFEParticleSelection")
56 , fOutput(0)
57 , fOption(opt)
2229ac91 58 , fCutList(NULL)
59 , fCutsD0(NULL)
72c0a987 60 , fSelector(NULL)
9535cec9 61 , fUseMC(kFALSE)
d731501a 62 , fFillOnlyD0D0bar(0)
2229ac91 63 , fSelectedTracks(NULL)
64 , fParticleType(kD0)
65 , fSystem(0)
72c0a987 66{
67 // constructor
68 //
69 //
70
71 DefineSlots();
72}
73
74int AliAnalysisTaskDxHFEParticleSelection::DefineSlots()
75{
76 // define the data slots
77 DefineInput(0, TChain::Class());
78 DefineOutput(1, TList::Class());
2229ac91 79 DefineOutput(2, TList::Class());
72c0a987 80 return 0;
81}
82
83AliAnalysisTaskDxHFEParticleSelection::~AliAnalysisTaskDxHFEParticleSelection()
84{
85 // destructor
86 //
87 //
88
89 // histograms are in the output list and deleted when the output
90 // list is deleted by the TSelector dtor
91
92 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
93 delete fOutput;
94 fOutput = 0;
95 }
96
97 if (fSelector) {
98 fSelector->Clear();
99 delete fSelector;
100 fSelector=NULL;
101 }
2229ac91 102 if(fSelectedTracks){
103 delete fSelectedTracks;
104 fSelectedTracks=NULL;
9535cec9 105 }
2229ac91 106 // external object, do not delete
107 fCutsD0=NULL;
108
72c0a987 109}
110
111void AliAnalysisTaskDxHFEParticleSelection::UserCreateOutputObjects()
112{
113 // create result objects and add to output list
114
2229ac91 115 Int_t iResult=0;
116
72c0a987 117 fOutput = new TList;
118 fOutput->SetOwner();
93fcaf9f 119
2229ac91 120 ParseArguments(fOption.Data());
121
122 // REVIEW: this has only effect if the list is deleted, it should
123 // be done where the list is created, in any case, all objects of the
124 // list are presumably external objects, they should not be deleted in
125 // this class
126 fCutList->SetOwner(); // NOt sure if needed
127
128
d731501a 129 // setting up for D0s
2229ac91 130 if(fParticleType==kD0){
131
132 TString selectionD0Options;
133 switch (fFillOnlyD0D0bar) {
134 case 1: selectionD0Options+="FillOnlyD0 "; break;
135 case 2: selectionD0Options+="FillOnlyD0bar "; break;
136 default: selectionD0Options+="FillD0D0bar ";
137 }
138
139 if(fUseMC) fSelector=new AliDxHFEParticleSelectionMCD0(selectionD0Options);
140 else fSelector=new AliDxHFEParticleSelectionD0(selectionD0Options);
141 fSelector->SetCuts(fCutList,AliDxHFEParticleSelectionD0::kCutList);
142
143 TObject *obj=NULL;
144 TIter iter(fCutList);
145 while((obj = iter())){
146 fCutsD0=dynamic_cast<AliRDHFCuts*>(obj);
147 if (!fCutsD0) {
148 AliError(Form("Cut object is not of required type AliRDHFCuts but %s", obj->ClassName()));
149 }
150 }
151 }
152
153
154 // Setting up for electrons
155 if(fParticleType==kElectron){
156 if(fUseMC) fSelector=new AliDxHFEParticleSelectionMCEl;
157 else fSelector=new AliDxHFEParticleSelectionEl;
158 fSelector->SetCuts(fCutList, AliDxHFEParticleSelectionEl::kCutList);
159
160 // If running on electrons, for now use RDHFCuts for event selection.
161 // Set up default cut object:
162 AliRDHFCutsD0toKpi* cuts=new AliRDHFCutsD0toKpi();
163 cuts->SetStandardCutsPP2010();
164 fCutsD0=cuts;
165 }
166
167 iResult=fSelector->Init();
168 if (iResult<0) {
169 AliFatal(Form("initialization of worker class instance fElectrons failed with error %d", iResult));
9535cec9 170 }
9535cec9 171
9535cec9 172
173 // Retrieving the list containing histos and THnSparse
174 // and storing them instead of fSelector
175 // Fix to be able to merge
176 TList *list =(TList*)fSelector->GetControlObjects();
177 TObject *obj=NULL;
178
179 TIter next(list);
180 while((obj = next())){
181 fOutput->Add(obj);
182 }
183
72c0a987 184 // all tasks must post data once for all outputs
185 PostData(1, fOutput);
2229ac91 186 PostData(2, fCutList);
72c0a987 187}
188
189void AliAnalysisTaskDxHFEParticleSelection::UserExec(Option_t* /*option*/)
190{
191 // process the event
192
193 // TODO: implement correct input, this is likely not to be the
194 // ESD
195 TObject* pInput=InputEvent();
196 if (!pInput) {
197 AliError("failed to get input");
198 return;
199 }
9535cec9 200
201 // check if input is an ESD
72c0a987 202 AliVEvent *pEvent = dynamic_cast<AliVEvent*>(pInput);
9535cec9 203 TClonesArray *inputArray=0;
204
205 if(!pEvent && AODEvent() && IsStandardAOD()) { //Not sure if this is needed.. Keep it for now.
206 // In case there is an AOD handler writing a standard AOD, use the AOD
207 // event in memory rather than the input (ESD) event.
208 pEvent = AODEvent();
209 // in this case the braches in the deltaAOD (AliAOD.VertexingHF.root)
210 // have to taken from the AOD event hold by the AliAODExtension
211 AliAODHandler* aodHandler = (AliAODHandler*)
212 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
213
214 if(aodHandler->GetExtensions()) {
215 AliAODExtension *ext = (AliAODExtension*)aodHandler->GetExtensions()->FindObject("AliAOD.VertexingHF.root");
216 AliAODEvent* aodFromExt = ext->GetAOD();
217 inputArray=(TClonesArray*)aodFromExt->GetList()->FindObject("D0toKpi");
218 }
219 } else if(pEvent) {
220 inputArray=(TClonesArray*)pEvent->GetList()->FindObject("D0toKpi");
221 }
222 if(!inputArray || !pEvent) {
223 AliError("Input branch not found!\n");
224 return;
225 }
226 // fix for temporary bug in ESDfilter
227 // the AODs with null vertex pointer didn't pass the PhysSel
228 if(!pEvent->GetPrimaryVertex() || TMath::Abs(pEvent->GetMagneticField())<0.001){
229 AliDebug(2,"Rejected at GetPrimaryvertex");
230 return;
231 }
232
233 fSelector->HistogramEventProperties(AliDxHFEParticleSelection::kEventsAll);
9535cec9 234
2229ac91 235 //At the moment: Use AliRDHFCuts for event selection
236 AliRDHFCuts* cutsd0=dynamic_cast<AliRDHFCuts*>(fCutsD0);
237 if (!cutsd0) return; // Fatal thrown already in initialization
238
239 if(!cutsd0->IsEventSelected(pEvent)) {
9535cec9 240 AliDebug(2,"rejected at IsEventSelected");
72c0a987 241 return;
242 }
243
9535cec9 244 fSelector->HistogramEventProperties(AliDxHFEParticleSelection::kEventsSel);
9535cec9 245
2229ac91 246 if(fParticleType==kElectron){
247 // Gets the PID response from the analysis manager
248 AliPIDResponse *pidResponse = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler())->GetPIDResponse();
249 if(!pidResponse){
250 // TODO: consider issuing fatal instead of debug in case pidresponse not available
251 AliDebug(1, "Using default PID Response");
252 pidResponse = AliHFEtools::GetDefaultPID(kFALSE, fInputEvent->IsA() == AliAODEvent::Class());
253 }
254
255 // Fetching the PID objects from the list, checks if the objects are AliHFEpids
256 // If so, checks if they are initialized and also sets the pidresponse
257 TObject *obj=NULL;
258 TIter next(fCutList);
259 while((obj = next())){
260 if(strcmp(obj->ClassName(),"AliHFEpid")==0){
261 AliHFEpid* pidObj=(AliHFEpid*)obj;
262 if(!pidObj->IsInitialized()){
263 AliWarning("PID not initialised, get from Run no");
264 pidObj->InitializePID(pEvent->GetRunNumber());
265 }
266 pidObj->SetPIDResponse(pidResponse);
267 }
268 }
9535cec9 269
2229ac91 270 // Also sends the pidresponse to the particle selection class for electron
271 fSelector->SetPIDResponse(pidResponse);
9535cec9 272
93fcaf9f 273 }
274
2229ac91 275 if (fSelectedTracks) delete fSelectedTracks;
276
277 if(fParticleType==kElectron)
278 fSelectedTracks=fSelector->Select(pEvent);
279 else
280 fSelectedTracks=fSelector->Select(inputArray,pEvent);
281
282 Int_t nSelected = fSelectedTracks->GetEntriesFast();
283 if(nSelected>0)
284 fSelector->HistogramEventProperties(AliDxHFEParticleSelection::kEventsWithParticle);
285
72c0a987 286 PostData(1, fOutput);
287}
288
2229ac91 289int AliAnalysisTaskDxHFEParticleSelection::ParseArguments(const char* arguments)
290{
291 // parse arguments and set internal flags
292 TString strArguments(arguments);
293 auto_ptr<TObjArray> tokens(strArguments.Tokenize(" "));
294 if (!tokens.get()) return 0;
295
296 TIter next(tokens.get());
297 TObject* token;
298 while ((token=next())) {
299 TString argument=token->GetName();
300
301 if (argument.BeginsWith("mc")) {
302 fUseMC=true;
303 continue;
304 }
305 if (argument.BeginsWith("system=")) {
306 argument.ReplaceAll("system=", "");
307 if (argument.CompareTo("pp")==0)fSystem=0;
308 else if (argument.CompareTo("Pb-Pb")==0) fSystem=1;
309 else {
310 AliWarning(Form("can not set collision system, unknown parameter '%s'", argument.Data()));
311 // TODO: check what makes sense
312 fSystem=0;
313 }
314 continue;
315 }
316 if (argument.BeginsWith("fillD0scheme=")){
317 argument.ReplaceAll("fillD0scheme=", "");
318 if (argument.CompareTo("both")==0){ fFillOnlyD0D0bar=0; AliInfo("Filling both D0 and D0bar ");}
319 else if (argument.CompareTo("D0")==0){ fFillOnlyD0D0bar=1; AliInfo("Filling only D0 ");}
320 else if (argument.CompareTo("D0bar")==0){ fFillOnlyD0D0bar=2; AliInfo("Filling only D0bar"); }
321 else {
322 AliWarning(Form("can not set D0 filling scheme, unknown parameter '%s'", argument.Data()));
323 fFillOnlyD0D0bar=0;
324 }
325 continue;
326 }
327 if (argument.BeginsWith("particle=")){
328 argument.ReplaceAll("particle=","");
329 if (argument.CompareTo("D0")==0){ fParticleType=kD0; AliInfo("Running over D0s ");}
330 else if (argument.CompareTo("electron")==0){ fParticleType=kElectron; AliInfo("Running over Electrons ");}
331 else{
332 AliWarning(Form("can not set particle, unknown parameter '%s'. Particle set to D0", argument.Data()));
333 fParticleType=kD0;
334 }
335 continue;
336
337 }
338 AliWarning(Form("unknown argument '%s'", argument.Data()));
339
340 }
341
342 return 0;
343}
344
72c0a987 345void AliAnalysisTaskDxHFEParticleSelection::FinishTaskOutput()
346{
347 // end of the processing
348}
349
350void AliAnalysisTaskDxHFEParticleSelection::Terminate(Option_t *)
351{
352 // last action on the client
353 fOutput = dynamic_cast<TList*> (GetOutputData(1));
354 if (!fOutput) {
355 AliFatal("failed to get output container");
356 return;
357 }
358
359}