]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/hfe/AliAnalysisTaskHFE.cxx
Update of the HFE package and of the macro to run on the
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliAnalysisTaskHFE.cxx
CommitLineData
809a4336 1/**************************************************************************
2* Copyright(c) 1998-1999, 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**************************************************************************/
50685501 15//
16// The analysis task:
17// Filling an AliCFContainer with the quantities pt, eta and phi
18// for tracks which survivied the particle cuts (MC resp. ESD tracks)
19// Track selection is done using the AliHFE package
20//
21// Author:
22// Raphaelle Bailhache <R.Bailhache@gsi.de>
23// Markus Fasel <M.Fasel@gsi.de>
24// Matus Kalisky <matus.kalisky@cern.ch>
25// MinJung Kweon <minjung@physi.uni-heidelberg.de>
26//
809a4336 27#include <TAxis.h>
28#include <TCanvas.h>
29#include <TChain.h>
259c3296 30#include <TDirectory.h>
6ad05e72 31#include <TFile.h>
32#include <TH1D.h>
809a4336 33#include <TH1F.h>
34#include <TH1I.h>
35#include <TH2F.h>
faee3b18 36#include <TH3D.h>
809a4336 37#include <TIterator.h>
38#include <TList.h>
39#include <TLegend.h>
40#include <TMath.h>
41#include <TObjArray.h>
42#include <TParticle.h>
43#include <TProfile.h>
75d81601 44#include <TString.h>
faee3b18 45#include <TF1.h>
809a4336 46#include <TTree.h>
47
9bcfd1ab 48#include "AliAODInputHandler.h"
49#include "AliAODMCParticle.h"
50#include "AliAODTrack.h"
809a4336 51#include "AliCFContainer.h"
52#include "AliCFManager.h"
53#include "AliESDEvent.h"
54#include "AliESDInputHandler.h"
faee3b18 55#include "AliESDpid.h"
809a4336 56#include "AliESDtrack.h"
809a4336 57#include "AliLog.h"
58#include "AliAnalysisManager.h"
59#include "AliMCEvent.h"
60#include "AliMCEventHandler.h"
61#include "AliMCParticle.h"
62#include "AliPID.h"
259c3296 63#include "AliStack.h"
70da6c5a 64#include "AliVVertex.h"
809a4336 65
66#include "AliHFEpid.h"
9bcfd1ab 67#include "AliHFEcollection.h"
809a4336 68#include "AliHFEcuts.h"
259c3296 69#include "AliHFEmcQA.h"
9bcfd1ab 70#include "AliHFEpairs.h"
d2af20c5 71#include "AliHFEpostAnalysis.h"
9bcfd1ab 72#include "AliHFEsecVtxs.h"
259c3296 73#include "AliHFEsecVtx.h"
9bcfd1ab 74#include "AliHFEelecbackground.h"
70da6c5a 75#include "AliHFEtools.h"
809a4336 76#include "AliAnalysisTaskHFE.h"
77
faee3b18 78ClassImp(AliAnalysisTaskHFE)
79
809a4336 80//____________________________________________________________
81AliAnalysisTaskHFE::AliAnalysisTaskHFE():
d2af20c5 82 AliAnalysisTaskSE("PID efficiency Analysis")
75d81601 83 , fQAlevel(0)
84 , fPIDdetectors("")
0792aa82 85 , fPIDstrategy(0)
9bcfd1ab 86 , fPlugins(0)
faee3b18 87 , fWeighting(kFALSE)
88 , fWeightFactors(NULL)
89 , fWeightFactorsFunction(NULL)
e3fc062d 90 , fBackGroundFactorsFunction(NULL)
9bcfd1ab 91 , fCFM(NULL)
e3fc062d 92 , fV0CF(NULL)
faee3b18 93 , fHadronicBackground(NULL)
9bcfd1ab 94 , fCorrelation(NULL)
95 , fPIDperformance(NULL)
96 , fSignalToBackgroundMC(NULL)
97 , fPID(NULL)
e3fc062d 98 , fPIDtagged(NULL)
99 , fPIDpreselect(NULL)
9bcfd1ab 100 , fCuts(NULL)
e3fc062d 101 , fCutsTagged(NULL)
102 , fCutspreselect(NULL)
9bcfd1ab 103 , fSecVtx(NULL)
104 , fElecBackGround(NULL)
105 , fMCQA(NULL)
106 , fNEvents(NULL)
107 , fNElectronTracksEvent(NULL)
108 , fQA(NULL)
109 , fOutput(NULL)
110 , fHistMCQA(NULL)
111 , fHistSECVTX(NULL)
112 , fHistELECBACKGROUND(NULL)
113// , fQAcoll(0x0)
0792aa82 114{
115 //
50685501 116 // Dummy constructor
0792aa82 117 //
0792aa82 118}
119
120//____________________________________________________________
121AliAnalysisTaskHFE::AliAnalysisTaskHFE(const char * name):
d2af20c5 122 AliAnalysisTaskSE(name)
0792aa82 123 , fQAlevel(0)
124 , fPIDdetectors("")
125 , fPIDstrategy(0)
9bcfd1ab 126 , fPlugins(0)
faee3b18 127 , fWeighting(kFALSE)
128 , fWeightFactors(NULL)
129 , fWeightFactorsFunction(NULL)
e3fc062d 130 , fBackGroundFactorsFunction(NULL)
9bcfd1ab 131 , fCFM(NULL)
e3fc062d 132 , fV0CF(NULL)
faee3b18 133 , fHadronicBackground(NULL)
9bcfd1ab 134 , fCorrelation(NULL)
135 , fPIDperformance(NULL)
136 , fSignalToBackgroundMC(NULL)
137 , fPID(NULL)
e3fc062d 138 , fPIDtagged(NULL)
139 , fPIDpreselect(NULL)
9bcfd1ab 140 , fCuts(NULL)
e3fc062d 141 , fCutsTagged(NULL)
142 , fCutspreselect(NULL)
9bcfd1ab 143 , fSecVtx(NULL)
144 , fElecBackGround(NULL)
145 , fMCQA(NULL)
146 , fNEvents(NULL)
147 , fNElectronTracksEvent(NULL)
148 , fQA(NULL)
149 , fOutput(NULL)
150 , fHistMCQA(NULL)
151 , fHistSECVTX(NULL)
152 , fHistELECBACKGROUND(NULL)
153// , fQAcoll(0x0)
809a4336 154{
dbe3abbe 155 //
156 // Default constructor
9bcfd1ab 157 //
d2af20c5 158 DefineOutput(1, TH1I::Class());
259c3296 159 DefineOutput(2, TList::Class());
d2af20c5 160 DefineOutput(3, TList::Class());
161// DefineOutput(4, TList::Class());
809a4336 162
163 // Initialize cuts
809a4336 164}
165
dbe3abbe 166//____________________________________________________________
167AliAnalysisTaskHFE::AliAnalysisTaskHFE(const AliAnalysisTaskHFE &ref):
d2af20c5 168 AliAnalysisTaskSE(ref)
faee3b18 169 , fQAlevel(0)
170 , fPIDdetectors()
171 , fPIDstrategy(0)
172 , fPlugins(0)
173 , fWeighting(kFALSE)
174 , fWeightFactors(NULL)
175 , fWeightFactorsFunction(NULL)
e3fc062d 176 , fBackGroundFactorsFunction(NULL)
faee3b18 177 , fCFM(NULL)
e3fc062d 178 , fV0CF(NULL)
faee3b18 179 , fHadronicBackground(NULL)
180 , fCorrelation(NULL)
181 , fPIDperformance(NULL)
182 , fSignalToBackgroundMC(NULL)
183 , fPID(NULL)
e3fc062d 184 , fPIDtagged(NULL)
185 , fPIDpreselect(NULL)
faee3b18 186 , fCuts(NULL)
e3fc062d 187 , fCutsTagged(NULL)
188 , fCutspreselect(NULL)
faee3b18 189 , fSecVtx(NULL)
190 , fElecBackGround(NULL)
191 , fMCQA(NULL)
192 , fNEvents(NULL)
193 , fNElectronTracksEvent(NULL)
194 , fQA(NULL)
195 , fOutput(NULL)
196 , fHistMCQA(NULL)
197 , fHistSECVTX(NULL)
198 , fHistELECBACKGROUND(NULL)
9bcfd1ab 199// , fQAcoll(ref.fQAcoll)
dbe3abbe 200{
201 //
202 // Copy Constructor
203 //
faee3b18 204 ref.Copy(*this);
dbe3abbe 205}
206
207//____________________________________________________________
208AliAnalysisTaskHFE &AliAnalysisTaskHFE::operator=(const AliAnalysisTaskHFE &ref){
209 //
210 // Assignment operator
211 //
faee3b18 212 if(this == &ref)
213 ref.Copy(*this);
dbe3abbe 214 return *this;
215}
216
faee3b18 217//____________________________________________________________
218void AliAnalysisTaskHFE::Copy(TObject &o) const {
219 //
220 // Copy into object o
221 //
222 AliAnalysisTaskHFE &target = dynamic_cast<AliAnalysisTaskHFE &>(o);
223 target.fQAlevel = fQAlevel;
224 target.fPIDdetectors = fPIDdetectors;
225 target.fPIDstrategy = fPIDstrategy;
226 target.fPlugins = fPlugins;
227 target.fWeighting = fWeighting;
228 target.fWeightFactors = fWeightFactors;
229 target.fWeightFactorsFunction = fWeightFactorsFunction;
e3fc062d 230 target.fBackGroundFactorsFunction = fBackGroundFactorsFunction;
faee3b18 231 target.fCFM = fCFM;
e3fc062d 232 target.fV0CF = fV0CF;
faee3b18 233 target.fHadronicBackground = fHadronicBackground;
234 target.fCorrelation = fCorrelation;
235 target.fPIDperformance = fPIDperformance;
236 target.fSignalToBackgroundMC = fSignalToBackgroundMC;
237 target.fPID = fPID;
e3fc062d 238 target.fPIDtagged = fPIDtagged;
239 target.fPIDpreselect = fPIDpreselect;
faee3b18 240 target.fCuts = fCuts;
e3fc062d 241 target.fCutspreselect = fCutspreselect;
faee3b18 242 target.fSecVtx = fSecVtx;
243 target.fElecBackGround = fElecBackGround;
244 target.fMCQA = fMCQA;
245 target.fNEvents = fNEvents;
246 target.fNElectronTracksEvent = fNElectronTracksEvent;
247 target.fQA = fQA;
248 target.fOutput = fOutput;
249 target.fHistMCQA = fHistMCQA;
250 target.fHistSECVTX = fHistSECVTX;
251 target.fHistELECBACKGROUND = fHistELECBACKGROUND;
252}
253
809a4336 254//____________________________________________________________
255AliAnalysisTaskHFE::~AliAnalysisTaskHFE(){
dbe3abbe 256 //
257 // Destructor
258 //
faee3b18 259 return;
dbe3abbe 260 if(fPID) delete fPID;
e3fc062d 261 if(fPIDtagged) delete fPIDtagged;
dbe3abbe 262 if(fQA){
259c3296 263 fQA->Clear();
264 delete fQA;
265 }
266 if(fOutput){
267 fOutput->Clear();
268 delete fOutput;
269 }
faee3b18 270 if(fWeightFactors) delete fWeightFactors;
271 if(fWeightFactorsFunction) delete fWeightFactorsFunction;
e3fc062d 272 if(fBackGroundFactorsFunction) delete fBackGroundFactorsFunction;
259c3296 273 if(fHistMCQA){
274 fHistMCQA->Clear();
275 delete fHistMCQA;
276 }
277 if(fHistSECVTX){
278 fHistSECVTX->Clear();
279 delete fHistSECVTX;
280 }
9bcfd1ab 281 if(fHistELECBACKGROUND){
282 fHistELECBACKGROUND->Clear();
283 delete fHistELECBACKGROUND;
284 }
259c3296 285 if(fSecVtx) delete fSecVtx;
9bcfd1ab 286 if(fElecBackGround) delete fElecBackGround;
dbe3abbe 287 if(fMCQA) delete fMCQA;
288 if(fNEvents) delete fNEvents;
78ea5ef4 289 if(fCorrelation){
290 fCorrelation->Clear();
291 delete fCorrelation;
292 }
293 if(fPIDperformance) delete fPIDperformance;
9bcfd1ab 294 if(fSignalToBackgroundMC) delete fSignalToBackgroundMC;
295// if(fQAcoll) delete fQAcoll;
faee3b18 296
809a4336 297}
298
299//____________________________________________________________
d2af20c5 300void AliAnalysisTaskHFE::UserCreateOutputObjects(){
50685501 301 //
302 // Creating output container and output objects
303 // Here we also Initialize the correction framework container and
304 // the objects for
305 // - PID
306 // - MC QA
307 // - SecVtx
308 // QA histograms are created if requested
309 // Called once per worker
310 //
e3fc062d 311 fPID = new AliHFEpid("standardPID"); fPIDtagged = new AliHFEpid("taggedPID");
9bcfd1ab 312 AliDebug(3, "Creating Output Objects");
70da6c5a 313 // Automatic determination of the analysis mode
faee3b18 314 AliVEventHandler *inputHandler = dynamic_cast<AliVEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
70da6c5a 315 if(!TString(inputHandler->IsA()->GetName()).CompareTo("AliAODInputHandler")){
316 SetAODAnalysis();
317 } else {
318 SetESDAnalysis();
319 if(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler())
320 SetHasMCData();
321 }
9bcfd1ab 322 printf("Analysis Mode: %s Analysis\n", IsAODanalysis() ? "AOD" : "ESD");
323 printf("MC Data available %s\n", HasMCData() ? "Yes" : "No");
324
325 // example how to use the AliHFEcollection
326 //fQAcoll = new AliHFEcollection("fQAcoll", "QA");
327 //fQAcoll->CreateTH1F("fNevents", "Number of Events in the Analysis", 2, 0, 2);
328 //fQAcoll->CreateProfile("fNtrdclusters", "Number of TRD clusters as function of momentum; p[GeV/c]", 20, 0, 20);
329
dbe3abbe 330 fNEvents = new TH1I("nEvents", "Number of Events in the Analysis", 2, 0, 2); // Number of Events neccessary for the analysis and not a QA histogram
75d81601 331 fNElectronTracksEvent = new TH1I("nElectronTracksEvent", "Number of Electron Candidates", 100, 0, 100);
dbe3abbe 332 // First Step: TRD alone
333 if(!fQA) fQA = new TList;
334 fQA->AddAt(new TProfile("conr", "Electron PID contamination", 20, 0, 20), 0);
335 fQA->AddAt(new TH1F("alpha_rec", "Alpha from reconstructed tracks with TRD hits", 36, -TMath::Pi(), TMath::Pi()), 1);
336 fQA->AddAt(new TH1F("alpha_sim", "Alpha from simulated electron tracks", 36, -TMath::Pi(), TMath::Pi()), 2);
337 fQA->AddAt(new TH1F("nElectron", "Number of electrons", 100, 0, 100), 3);
338 fQA->AddAt(new TProfile("pidquality", "TRD PID quality as function of momentum", 20, 0, 20), 4);
339 fQA->AddAt(new TProfile("ntrdclusters", "Number of TRD clusters as function of momentum", 20, 0, 20), 5);
340 fQA->AddAt(new TH1F("chi2TRD","#chi2 per TRD cluster", 20, 0, 20), 6);
70da6c5a 341 fQA->AddAt(new TH1I("mccharge", "MC Charge", 200, -100, 100), 7);
faee3b18 342 fQA->AddAt(new TH2F("radius", "Production Vertex", 100, 0.0, 5.0, 100, 0.0, 5.0), 8);
343 fQA->AddAt(new TH1F("secvtxept", "pT of tagged e", 500, 0, 50), 9); // mj: will move to another place soon
344 fQA->AddAt(new TH2F("secvtxeTPCsig", "TPC signal for tagged e",125, 0, 25, 200, 0, 200 ), 10); // mj: will move to another place soon
809a4336 345
259c3296 346 if(!fOutput) fOutput = new TList;
809a4336 347 // Initialize correction Framework and Cuts
348 fCFM = new AliCFManager;
e3fc062d 349 fV0CF = new AliCFManager;
809a4336 350 MakeParticleContainer();
70da6c5a 351 MakeEventContainer();
9bcfd1ab 352 // Temporary fix: Initialize particle cuts with NULL
809a4336 353 for(Int_t istep = 0; istep < fCFM->GetParticleContainer()->GetNStep(); istep++)
9bcfd1ab 354 fCFM->SetParticleCutsList(istep, NULL);
0792aa82 355 if(!fCuts){
356 AliWarning("Cuts not available. Default cuts will be used");
357 fCuts = new AliHFEcuts;
358 fCuts->CreateStandardCuts();
809a4336 359 }
9bcfd1ab 360 if(IsAODanalysis()) fCuts->SetAOD();
e3fc062d 361 // Make clone for V0 tagging step
362 fCutsTagged = new AliHFEcuts(*fCuts);
363 fCutsTagged->SetName("hfeV0Cuts");
364 fCutsTagged->SetTitle("Cuts for tagged Particles");
0792aa82 365 fCuts->Initialize(fCFM);
e3fc062d 366 fCutsTagged->Initialize(fV0CF);
367 if(fCuts->IsQAOn()) fQA->Add(fCuts->GetQAhistograms());
368 if(fCutsTagged->IsQAOn()) fQA->Add(fCutsTagged->GetQAhistograms());
0792aa82 369
259c3296 370 // add output objects to the List
371 fOutput->AddAt(fCFM->GetParticleContainer(), 0);
70da6c5a 372 fOutput->AddAt(fCFM->GetEventContainer(), 1);
373 fOutput->AddAt(fCorrelation, 2);
374 fOutput->AddAt(fPIDperformance, 3);
375 fOutput->AddAt(fSignalToBackgroundMC, 4);
376 fOutput->AddAt(fNElectronTracksEvent, 5);
faee3b18 377 fOutput->AddAt(fHadronicBackground, 6);
e3fc062d 378 fOutput->AddAt(fV0CF, 7);
809a4336 379 // Initialize PID
75d81601 380 if(IsQAOn(kPIDqa)){
381 AliInfo("PID QA switched on");
722347d8 382 //fPID->SetDebugLevel(2);
809a4336 383 fPID->SetQAOn();
259c3296 384 fQA->Add(fPID->GetQAhistograms());
809a4336 385 }
722347d8 386 fPID->SetHasMCData(HasMCData());
0792aa82 387 if(!fPIDdetectors.Length() && ! fPIDstrategy) AddPIDdetector("TPC");
e3fc062d 388 if(fPIDstrategy){
0792aa82 389 fPID->InitializePID(Form("Strategy%d", fPIDstrategy));
e3fc062d 390 fPIDtagged->InitializePID(Form("Strategy%d", fPIDstrategy));
391 }
392 else{
0792aa82 393 fPID->InitializePID(fPIDdetectors.Data()); // Only restrictions to TPC allowed
e3fc062d 394 fPIDtagged->InitializePID(fPIDdetectors.Data()); // Only restrictions to TPC allowed
395 }
259c3296 396
dbe3abbe 397 // mcQA----------------------------------
9bcfd1ab 398 if (HasMCData() && IsQAOn(kMCqa)) {
dbe3abbe 399 AliInfo("MC QA on");
400 if(!fMCQA) fMCQA = new AliHFEmcQA;
259c3296 401 if(!fHistMCQA) fHistMCQA = new TList();
e3fc062d 402 fMCQA->CreatDefaultHistograms(fHistMCQA);
259c3296 403 fQA->Add(fHistMCQA);
dbe3abbe 404 }
259c3296 405
dbe3abbe 406 // secvtx----------------------------------
9bcfd1ab 407 if (GetPlugin(kSecVtx)) {
dbe3abbe 408 AliInfo("Secondary Vertex Analysis on");
e3fc062d 409 if(!fSecVtx) fSecVtx = new AliHFEsecVtx;
9bcfd1ab 410 fSecVtx->SetHasMCData(HasMCData());
dbe3abbe 411
259c3296 412 if(!fHistSECVTX) fHistSECVTX = new TList();
9bcfd1ab 413 fSecVtx->CreateHistograms(fHistSECVTX);
75d81601 414 fOutput->Add(fHistSECVTX);
9bcfd1ab 415 }
416
417 // background----------------------------------
418 if (GetPlugin(kIsElecBackGround)) {
419 AliInfo("Electron BackGround Analysis on");
70da6c5a 420 if(!fElecBackGround){
421 AliWarning("ElecBackGround not available. Default elecbackground will be used");
422 fElecBackGround = new AliHFEelecbackground;
423 }
9bcfd1ab 424 fElecBackGround->SetHasMCData(HasMCData());
425
426 if(!fHistELECBACKGROUND) fHistELECBACKGROUND = new TList();
427 fElecBackGround->CreateHistograms(fHistELECBACKGROUND);
428 fOutput->Add(fHistELECBACKGROUND);
429 }
809a4336 430}
431
432//____________________________________________________________
d2af20c5 433void AliAnalysisTaskHFE::UserExec(Option_t *){
dbe3abbe 434 //
435 // Run the analysis
436 //
9bcfd1ab 437 AliDebug(3, "Starting Single Event Analysis");
d2af20c5 438 if(!fInputEvent){
9bcfd1ab 439 AliError("Reconstructed Event not available");
dbe3abbe 440 return;
441 }
9bcfd1ab 442 if(HasMCData()){
d2af20c5 443 AliDebug(4, Form("MC Event: %p", fMCEvent));
444 if(!fMCEvent){
9bcfd1ab 445 AliError("No MC Event, but MC Data required");
446 return;
447 }
dbe3abbe 448 }
722347d8 449 if(!fCuts){
450 AliError("HFE cuts not available");
451 return;
452 }
809a4336 453
faee3b18 454 if(IsESDanalysis() && HasMCData()){
455 // Protect against missing MC trees
456 AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
457 if(!mcH->InitOk()) return;
458 if(!mcH->TreeK()) return;
459 if(!mcH->TreeTR()) return;
460 }
461
462 // Protect agains missing
9bcfd1ab 463 if(HasMCData()) ProcessMC(); // Run the MC loop + MC QA in case MC Data are available
809a4336 464
9bcfd1ab 465 if(IsAODanalysis()) ProcessAOD();
faee3b18 466 else{
467 AliESDInputHandler *inH = dynamic_cast<AliESDInputHandler *>(fInputHandler);
468 AliESDpid *workingPID = inH->GetESDpid();
469 if(workingPID){
470 AliDebug(1, "Using ESD PID from the input handler");
471 fPID->SetESDpid(workingPID);
e3fc062d 472 fPIDtagged->SetESDpid(workingPID);
473 if(fPIDpreselect) fPIDpreselect->SetESDpid(workingPID);
faee3b18 474 } else {
475 AliDebug(1, "Using default ESD PID");
476 fPID->SetESDpid(AliHFEtools::GetDefaultPID(HasMCData()));
e3fc062d 477 fPIDtagged->SetESDpid(AliHFEtools::GetDefaultPID(HasMCData()));
478 if(fPIDpreselect) fPIDpreselect->SetESDpid(AliHFEtools::GetDefaultPID(HasMCData()));
faee3b18 479 }
480 ProcessESD();
481 }
9bcfd1ab 482 // Done!!!
d2af20c5 483 PostData(1, fNEvents);
484 PostData(2, fOutput);
485 PostData(3, fQA);
486// PostData(4, fQAcoll->GetList());
9bcfd1ab 487}
259c3296 488
9bcfd1ab 489//____________________________________________________________
490void AliAnalysisTaskHFE::Terminate(Option_t *){
491 //
492 // Terminate not implemented at the moment
493 //
494 if(GetPlugin(kPostProcess)){
70da6c5a 495 fOutput = dynamic_cast<TList *>(GetOutputData(2));
9bcfd1ab 496 if(!fOutput){
497 AliError("Results not available");
498 return;
259c3296 499 }
d2af20c5 500 AliHFEpostAnalysis postanalysis;
501 postanalysis.SetResults(fOutput);
502 if(HasMCData())postanalysis.DrawMCSignal2Background();
503 postanalysis.DrawEfficiency();
504 postanalysis.DrawPIDperformance();
70da6c5a 505 postanalysis.DrawCutEfficiency();
506
507 if (GetPlugin(kIsElecBackGround)) {
508 AliHFEelecbackground elecBackGround;
509 TList *oe = 0x0;
510 if(!(oe = (TList*)dynamic_cast<TList *>(fOutput->FindObject("HFEelecbackground")))){
511 return;
512 }
513 elecBackGround.Load(oe);
514 elecBackGround.Plot();
515 elecBackGround.PostProcess();
516 }
9bcfd1ab 517 }
9bcfd1ab 518}
faee3b18 519//_______________________________________________________________
520Bool_t AliAnalysisTaskHFE::IsEventInBinZero() {
521 //
522 //
523 //
524
525 //printf("test in IsEventInBinZero\n");
526 if(!fInputEvent){
527 AliError("Reconstructed Event not available");
528 return kFALSE;
529 }
dbe3abbe 530
faee3b18 531 // check vertex
532 const AliVVertex *vertex = fInputEvent->GetPrimaryVertex();
533 if(!vertex) return kTRUE;
534 //if(vertex) return kTRUE;
535
536 // check tracks
537 if(fInputEvent->GetNumberOfTracks()<=0) return kTRUE;
538 //if(fInputEvent->GetNumberOfTracks()>0) return kTRUE;
539
540
541 return kFALSE;
542
543}
9bcfd1ab 544//____________________________________________________________
545void AliAnalysisTaskHFE::ProcessMC(){
546 //
547 // Runs the MC Loop (filling the container for the MC Cut Steps with the observables pt, eta and phi)
548 // In case MC QA is on also MC QA loop is done
549 //
550 AliDebug(3, "Processing MC Information");
e3fc062d 551 Double_t eventstatus = 1.;
70da6c5a 552 if(!fCFM->CheckEventCuts(AliHFEcuts::kEventStepGenerated, fMCEvent)) return;
e3fc062d 553 fCFM->GetEventContainer()->Fill(&eventstatus,AliHFEcuts::kEventStepGenerated);
9bcfd1ab 554 Int_t nElectrons = 0;
555 if(IsESDanalysis()){
556 if (HasMCData() && IsQAOn(kMCqa)) {
557 AliDebug(2, "Running MC QA");
558
70da6c5a 559 if(fMCEvent->Stack()){
e3fc062d 560 fMCQA->SetMCEvent(fMCEvent);
70da6c5a 561 fMCQA->SetGenEventHeader(fMCEvent->GenEventHeader());
562 fMCQA->Init();
563
564 Int_t nMCTracks = fMCEvent->Stack()->GetNtrack();
565
566 // loop over all tracks for decayed electrons
567 for (Int_t igen = 0; igen < nMCTracks; igen++){
568 TParticle* mcpart = fMCEvent->Stack()->Particle(igen);
569 fMCQA->GetQuarkKine(mcpart, igen, AliHFEmcQA::kCharm);
570 fMCQA->GetQuarkKine(mcpart, igen, AliHFEmcQA::kBeauty);
571 fMCQA->GetHadronKine(mcpart, AliHFEmcQA::kCharm);
572 fMCQA->GetHadronKine(mcpart, AliHFEmcQA::kBeauty);
573 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kCharm, AliHFEmcQA::kElectronPDG, 0); // no accept cut
574 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kBeauty, AliHFEmcQA::kElectronPDG, 0); // no accept cut
faee3b18 575 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kOthers, AliHFEmcQA::kElectronPDG, 0); // no accept cut
70da6c5a 576 if (TMath::Abs(mcpart->Eta()) < 0.9) {
577 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kCharm, AliHFEmcQA::kElectronPDG, 1); // accept |eta|<0.9
578 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kBeauty, AliHFEmcQA::kElectronPDG, 1); // accept |eta|<0.9
faee3b18 579 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kOthers, AliHFEmcQA::kElectronPDG, 1); // accept |eta|<0.9
70da6c5a 580 }
581 if (TMath::Abs(AliHFEtools::GetRapidity(mcpart)) < 0.5) {
582 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kCharm, AliHFEmcQA::kElectronPDG, 2); // accept |y|<0.5
583 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kBeauty, AliHFEmcQA::kElectronPDG, 2); // accept |y|<0.5
faee3b18 584 fMCQA->GetDecayedKine(mcpart, AliHFEmcQA::kOthers, AliHFEmcQA::kElectronPDG, 2); // accept |y|<0.5
9bcfd1ab 585 }
9bcfd1ab 586 }
70da6c5a 587 fMCQA->EndOfEventAna(AliHFEmcQA::kCharm);
588 fMCQA->EndOfEventAna(AliHFEmcQA::kBeauty);
9bcfd1ab 589 }
809a4336 590
9bcfd1ab 591 } // end of MC QA loop
592 // -----------------------------------------------------------------
d2af20c5 593 fCFM->SetMCEventInfo(fMCEvent);
9bcfd1ab 594 // fCFM->CheckEventCuts(AliCFManager::kEvtRecCuts, fESD);
595 } else {
d2af20c5 596 fCFM->SetMCEventInfo(fInputEvent);
9bcfd1ab 597 }
598 // Run MC loop
70da6c5a 599 AliVParticle *mctrack = NULL;
faee3b18 600 AliDebug(3, Form("Number of Tracks: %d", fMCEvent->GetNumberOfTracks()));
70da6c5a 601 for(Int_t imc = 0; imc <fMCEvent->GetNumberOfTracks(); imc++){
602 if(!(mctrack = fMCEvent->GetTrack(imc))) continue;
faee3b18 603 AliDebug(4, "Next Track");
70da6c5a 604 if(ProcessMCtrack(mctrack)) nElectrons++;
dbe3abbe 605 }
dbe3abbe 606
607 // fCFM->CheckEventCuts(AliCFManager::kEvtRecCuts, fESD);
9bcfd1ab 608 (dynamic_cast<TH1F *>(fQA->At(3)))->Fill(nElectrons);
609}
dbe3abbe 610
9bcfd1ab 611//____________________________________________________________
612void AliAnalysisTaskHFE::ProcessESD(){
dbe3abbe 613 //
9bcfd1ab 614 // Run Analysis of reconstructed event in ESD Mode
615 // Loop over Tracks, filter according cut steps defined in AliHFEcuts
dbe3abbe 616 //
9bcfd1ab 617 AliDebug(3, "Processing ESD Event");
e3fc062d 618 Double_t eventstatus = 1.;
619 fCFM->GetEventContainer()->Fill(&eventstatus, AliHFEcuts::kEventStepRecNoCut);
70da6c5a 620 if(!fCFM->CheckEventCuts(AliHFEcuts::kEventStepReconstructed, fInputEvent)) return;
e3fc062d 621 fCFM->GetEventContainer()->Fill(&eventstatus, AliHFEcuts::kEventStepReconstructed);
d2af20c5 622 AliESDEvent *fESD = dynamic_cast<AliESDEvent *>(fInputEvent);
9bcfd1ab 623 if(!fESD){
624 AliError("ESD Event required for ESD Analysis")
625 return;
626 }
627 if (GetPlugin(kIsElecBackGround)) {
628 fElecBackGround->SetEvent(fESD);
629 }
630 if (GetPlugin(kSecVtx)) {
631 fSecVtx->SetEvent(fESD);
632 fSecVtx->GetPrimaryCondition();
633 }
634
635 if(HasMCData()){
636 if (GetPlugin(kSecVtx)) {
faee3b18 637 fSecVtx->SetMCEvent(fMCEvent);
9bcfd1ab 638 }
639 if (GetPlugin(kIsElecBackGround)) {
d2af20c5 640 fElecBackGround->SetMCEvent(fMCEvent);
9bcfd1ab 641 }
642 }
643
e3fc062d 644 Double_t nContrib = fInputEvent->GetPrimaryVertex()->GetNContributors();
faee3b18 645 Double_t container[10];
646 memset(container, 0, sizeof(Double_t) * 10);
9bcfd1ab 647 // container for the output THnSparse
67fe7bd0 648 Double_t dataE[6]; // [pT, eta, Phi, type, 'C' or 'B']
75d81601 649 Int_t nElectronCandidates = 0;
9bcfd1ab 650 AliESDtrack *track = NULL, *htrack = NULL;
651 AliMCParticle *mctrack = NULL;
652 TParticle* mctrack4QA = NULL;
259c3296 653 Int_t pid = 0;
dbe3abbe 654 // For double counted tracks
78ea5ef4 655 LabelContainer cont(fESD->GetNumberOfTracks());
dbe3abbe 656 Bool_t alreadyseen = kFALSE;
657
78ea5ef4 658 Bool_t signal = kTRUE;
659
554e120d 660 fCFM->SetRecEventInfo(fESD);
d2af20c5 661 // Electron background analysis
662 if (GetPlugin(kIsElecBackGround)) {
663
664 AliDebug(2, "Running BackGround Analysis");
665
666 fElecBackGround->Reset();
667
668 } // end of electron background analysis
9bcfd1ab 669 //
670 // Loop ESD
671 //
faee3b18 672 AliDebug(3, Form("Number of Tracks: %d", fESD->GetNumberOfTracks()));
dbe3abbe 673 for(Int_t itrack = 0; itrack < fESD->GetNumberOfTracks(); itrack++){
dbe3abbe 674 track = fESD->GetTrack(itrack);
faee3b18 675
e3fc062d 676 // fill counts of v0-identified particles
677 Int_t v0pid = -1;
678 if(track->TestBit(BIT(14))) v0pid = AliPID::kElectron;
679 else if(track->TestBit(BIT(15))) v0pid = AliPID::kPion;
680 else if(track->TestBit(BIT(16))) v0pid = AliPID::kProton;
681 if(v0pid > -1)
682 FilterTaggedTrack(track, v0pid);
683
faee3b18 684 AliDebug(3, Form("Doing track %d, %p", itrack, track));
e3fc062d 685
686 //////////////////////////////////////
687 // preselect
688 /////////////////////////////////////
689 if(fPIDpreselect && fCutspreselect) {
690 if(!PreSelectTrack(track)) continue;
691 }
692
dbe3abbe 693 container[0] = track->Pt();
694 container[1] = track->Eta();
809a4336 695 container[2] = track->Phi();
70da6c5a 696 container[3] = track->Charge();
faee3b18 697 container[4] = 0;
dbe3abbe 698
78ea5ef4 699 dataE[0] = track->Pt();
700 dataE[1] = track->Eta();
701 dataE[2] = track->Phi();
70da6c5a 702 dataE[3] = track->Charge();
78ea5ef4 703 dataE[4] = -1;
70da6c5a 704 dataE[5] = -1;
78ea5ef4 705
706 signal = kTRUE;
faee3b18 707 Double_t weight = 1.0;
708
70da6c5a 709 // Fill step without any cut
dbe3abbe 710
9bcfd1ab 711 if(HasMCData()){
faee3b18 712 container[4] = container[9] = kOther;
9bcfd1ab 713 // Check if it is electrons near the vertex
d2af20c5 714 if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(track->GetLabel()))))) continue;
faee3b18 715 mctrack4QA = mctrack->Particle();
716
717 container[5] = mctrack->Pt();
718 container[6] = mctrack->Eta();
719 container[7] = mctrack->Phi();
720 container[8] = mctrack->Charge()/3.;
721
722 if(fWeighting) weight = FindWeight(container[5],container[6],container[7]);
9bcfd1ab 723
9bcfd1ab 724 if(!fCFM->CheckParticleCuts(AliHFEcuts::kStepMCGenerated, mctrack)) signal = kFALSE;
faee3b18 725 else AliDebug(3, "Signal Electron");
726
727 Int_t signalTrack = 0;
728 if((signalTrack = IsSignalElectron(track))){
729 AliDebug(3, Form("Signal: Index = %d\n", signalTrack));
730 switch(signalTrack){
731 case 1: container[4] = container[9] = kSignalCharm; break;
732 case 2: container[4] = container[9] = kSignalBeauty; break;
733 default: container[4] = container[9] = kOther; break;
734 };
735 } else if(IsGammaElectron(track)) container[4] = container[9] = kGammaConv;
736 AliDebug(3, Form("Signal Decision(%f/%f)", container[4], container[9]));
e3fc062d 737 }
faee3b18 738 AliDebug(3, Form("Weight? %f", weight));
dbe3abbe 739 if(signal) {
78ea5ef4 740 alreadyseen = cont.Find(TMath::Abs(track->GetLabel()));
741 cont.Append(TMath::Abs(track->GetLabel()));
dbe3abbe 742
faee3b18 743 fCFM->GetParticleContainer()->Fill(&container[5], AliHFEcuts::kStepRecNoCut,weight);
744 fCFM->GetParticleContainer()->Fill(&container[0], AliHFEcuts::kStepRecNoCut + 2*AliHFEcuts::kNcutStepsESDtrack,weight);
dbe3abbe 745 if(alreadyseen) {
faee3b18 746 fCFM->GetParticleContainer()->Fill(&container[5], AliHFEcuts::kStepRecNoCut + AliHFEcuts::kNcutStepsESDtrack,weight);
dbe3abbe 747 }
748 }
749
70da6c5a 750 // RecKine: ITSTPC cuts
faee3b18 751 if(!ProcessCutStep(AliHFEcuts::kStepRecKineITSTPC, track, container, signal, alreadyseen, weight)) continue;
70da6c5a 752
dbe3abbe 753 // Check TRD criterions (outside the correction framework)
754 if(track->GetTRDncls()){
755 (dynamic_cast<TH1F *>(fQA->At(6)))->Fill(track->GetTRDchi2()/track->GetTRDncls());
756 (dynamic_cast<TH1F *>(fQA->At(1)))->Fill(track->GetAlpha()); // Check the acceptance without tight cuts
757 (dynamic_cast<TProfile *>(fQA->At(4)))->Fill(container[0], track->GetTRDpidQuality());
758 (dynamic_cast<TProfile *>(fQA->At(5)))->Fill(container[0], track->GetTRDncls());
9bcfd1ab 759 //fQAcoll->Fill("fNtrdclusters", container[0], track->GetTRDncls());
dbe3abbe 760 }
761
762
763 // RecPrim
faee3b18 764 if(!ProcessCutStep(AliHFEcuts::kStepRecPrim, track, container, signal, alreadyseen,weight)) continue;
dbe3abbe 765
766 // HFEcuts: ITS layers cuts
faee3b18 767 if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsITS, track, container, signal, alreadyseen,weight)) continue;
dbe3abbe 768
78ea5ef4 769 // HFEcuts: Nb of tracklets TRD0
faee3b18 770 if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTRD, track, container, signal, alreadyseen,weight)) continue;
dbe3abbe 771 if(signal) {
78ea5ef4 772 // dimensions 3&4&5 : pt,eta,phi (MC)
722347d8 773 ((THnSparseF *)fCorrelation->At(0))->Fill(container);
dbe3abbe 774 }
775
9bcfd1ab 776 if(HasMCData() && IsQAOn(kMCqa)) {
777 // mc qa for after the reconstruction cuts
778 AliDebug(2, "Running MC QA");
779 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kCharm, AliHFEmcQA::kElectronPDG, 3); // charm
780 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kBeauty, AliHFEmcQA::kElectronPDG, 3); // beauty
faee3b18 781 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kOthers, AliHFEmcQA::kElectronPDG, 3); // beauty
0792aa82 782 }
dbe3abbe 783
faee3b18 784 if(HasMCData()){
785 FillProductionVertex(track);
786 }
787
809a4336 788 // track accepted, do PID
722347d8 789 AliHFEpidObject hfetrack;
790 hfetrack.fAnalysisType = AliHFEpidObject::kESDanalysis;
791 hfetrack.fRecTrack = track;
792 if(HasMCData()) hfetrack.fMCtrack = mctrack;
793 if(!fPID->IsSelected(&hfetrack)) continue;
75d81601 794 nElectronCandidates++;
dbe3abbe 795
faee3b18 796 // Fill Histogram for Hadronic Background
797 if(HasMCData()){
798 if(mctrack && (TMath::Abs(mctrack->Particle()->GetPdgCode()) != 11))
799 fHadronicBackground->Fill(container, 0);
800 }
801
9bcfd1ab 802 if (HasMCData() && IsQAOn(kMCqa)) {
803 // mc qa for after the reconstruction and pid cuts
804 AliDebug(2, "Running MC QA");
805 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kCharm, AliHFEmcQA::kElectronPDG, 4); // charm
806 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kBeauty, AliHFEmcQA::kElectronPDG, 4); // beauty
faee3b18 807 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kOthers, AliHFEmcQA::kElectronPDG, 4); // beauty
0792aa82 808 }
dbe3abbe 809
810 // Fill Containers
dbe3abbe 811 if(signal) {
e3fc062d 812 // Apply weight for background contamination
e3fc062d 813 if(fBackGroundFactorsFunction) {
67fe7bd0 814 Double_t weightBackGround = fBackGroundFactorsFunction->Eval(TMath::Abs(track->P()));
815 if(weightBackGround < 0.0) weightBackGround = 0.0;
816 else if(weightBackGround > 1.0) weightBackGround = 0.0;
817 fHadronicBackground->Fill(container, 1, weight * weightBackGround);
e3fc062d 818 }
819 //
67fe7bd0 820 fCFM->GetParticleContainer()->Fill(container, AliHFEcuts::kStepPID + 2*AliHFEcuts::kNcutStepsESDtrack, weight);
821 fCFM->GetParticleContainer()->Fill(&container[5], AliHFEcuts::kStepPID, weight);
dbe3abbe 822 if(alreadyseen) {
67fe7bd0 823 fCFM->GetParticleContainer()->Fill(&container[5], (AliHFEcuts::kStepPID + (AliHFEcuts::kNcutStepsESDtrack)),weight);
dbe3abbe 824 }
259c3296 825 // dimensions 3&4&5 : pt,eta,phi (MC)
722347d8 826 ((THnSparseF *)fCorrelation->At(1))->Fill(container);
dbe3abbe 827 }
828
faee3b18 829 if(GetPlugin(kSecVtx)) {
9bcfd1ab 830 AliDebug(2, "Running Secondary Vertex Analysis");
faee3b18 831 if(track->Pt()>2.0 && nContrib > 1){
9bcfd1ab 832 fSecVtx->InitHFEpairs();
833 fSecVtx->InitHFEsecvtxs();
259c3296 834 for(Int_t jtrack = 0; jtrack < fESD->GetNumberOfTracks(); jtrack++){
835 htrack = fESD->GetTrack(jtrack);
9bcfd1ab 836 if ( itrack == jtrack ) continue; // since it is for tagging single electron, don't need additional condition
faee3b18 837 if (htrack->Pt()<2.0) continue;
9bcfd1ab 838 if (!fCFM->CheckParticleCuts(AliHFEcuts::kStepRecKineITSTPC, htrack)) continue;
839 if (!fCFM->CheckParticleCuts(AliHFEcuts::kStepRecPrim, htrack)) continue;
840 fSecVtx->PairAnalysis(track, htrack, jtrack); // e-h pairing
259c3296 841 }
faee3b18 842 for(int ip=0; ip<fSecVtx->HFEpairs()->GetEntriesFast(); ip++){
843 //if(HasMCData()){
70da6c5a 844 AliHFEpairs *pair = (AliHFEpairs*) (fSecVtx->HFEpairs()->UncheckedAt(ip));
faee3b18 845 //if(!(pair->GetPairCode()>1. && pair->GetPairCode()<4.)) // apply various cuts
846 // apply various cuts
847 if(pair->GetKFChi2()>5.) // only apply vertex chi2 cut for the moment
848 //if((pair->GetKFChi2()>5.) || !(pair->GetSignedLxy()>0. && pair->GetSignedLxy()<2.))
9bcfd1ab 849 fSecVtx->HFEpairs()->RemoveAt(ip);
faee3b18 850 //}
851 }
9bcfd1ab 852 fSecVtx->HFEpairs()->Compress();
faee3b18 853 if(fSecVtx->HFEpairs()->GetEntriesFast()) fSecVtx->RunSECVTX(track); // secondary vertexing with e,h1,h2,.. tracks
9bcfd1ab 854 for(int ip=0; ip<fSecVtx->HFEsecvtxs()->GetEntriesFast(); ip++){
855 AliHFEsecVtxs *secvtx=0x0;
856 secvtx = (AliHFEsecVtxs*) (fSecVtx->HFEsecvtxs()->UncheckedAt(ip));
faee3b18 857 if(!(secvtx->GetInvmass()>2.0 && secvtx->GetInvmass()<5.2) || !(secvtx->GetSignedLxy2()>0.08 && secvtx->GetSignedLxy2()<1.5) || !(secvtx->GetKFIP2()>-0.1 && secvtx->GetKFIP2()<0.1))
858 fSecVtx->HFEsecvtxs()->RemoveAt(ip);
9bcfd1ab 859 // here you apply cuts, then if it doesn't pass the cut, remove it from the fSecVtx->HFEsecvtxs()
860 }
faee3b18 861 if(fSecVtx->HFEsecvtxs()->GetEntriesFast()) {
862 (dynamic_cast<TH1F *>(fQA->At(9)))->Fill(track->Pt());
863 (dynamic_cast<TH2F *>(fQA->At(10)))->Fill(track->P(),track->GetTPCsignal());
864 if (HasMCData() && IsQAOn(kMCqa)) {
865 // mc qa for after the reconstruction and pid cuts
866 AliDebug(2, "Running MC QA");
867 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kCharm, AliHFEmcQA::kElectronPDG, 5); // charm
868 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kBeauty, AliHFEmcQA::kElectronPDG, 5); // beauty
869 fMCQA->GetDecayedKine(mctrack4QA, AliHFEmcQA::kOthers, AliHFEmcQA::kElectronPDG, 5); // beauty
870 }
871 }
9bcfd1ab 872 fSecVtx->DeleteHFEpairs();
873 fSecVtx->DeleteHFEsecvtxs();
874 }
78ea5ef4 875 }
9bcfd1ab 876
877 if(HasMCData()){
878 // Track selected: distinguish between true and fake
879 AliDebug(1, Form("Candidate Selected, filling THnSparse, PID: %d\n", mctrack->Particle()->GetPdgCode()));
880 if((pid = TMath::Abs(mctrack->Particle()->GetPdgCode())) == 11){
881 Int_t type = IsSignalElectron(track);
882 AliDebug(1, Form("Type: %d\n", type));
883 if(type){
70da6c5a 884 dataE[5] = type; // beauty[1] or charm[2]
885 dataE[4] = 2; // signal electron
9bcfd1ab 886 }
887 else{
70da6c5a 888 dataE[4] = 1; // not a signal electron
889 dataE[5] = 0;
9bcfd1ab 890 }
891 }
892 else {
893 // Fill THnSparse with the information for Fake Electrons
9bcfd1ab 894 dataE[4] = 0;
70da6c5a 895 dataE[5] = 0;
9bcfd1ab 896 }
897 // fill the performance THnSparse, if the mc origin could be defined
70da6c5a 898 if(dataE[4] > -1){
899 AliDebug(1, Form("Entries: [%.3f|%.3f|%.3f|%f|%f|%f]\n", dataE[0],dataE[1],dataE[2],dataE[3],dataE[4],dataE[5]));
9bcfd1ab 900 fPIDperformance->Fill(dataE);
901 }
259c3296 902 }
9bcfd1ab 903 // Electron background analysis
904 if (GetPlugin(kIsElecBackGround)) {
905
906 AliDebug(2, "Running BackGround Analysis");
907
908 for(Int_t jtrack = 0; jtrack < fESD->GetNumberOfTracks(); jtrack++){
909 htrack = fESD->GetTrack(jtrack);
910 if ( itrack == jtrack ) continue;
911 fElecBackGround->PairAnalysis(track, htrack);
912 }
913 } // end of electron background analysis
914
dbe3abbe 915 }
916 fNEvents->Fill(1);
9bcfd1ab 917 //fQAcoll->Fill("fNevents", 1);
75d81601 918 fNElectronTracksEvent->Fill(nElectronCandidates);
809a4336 919}
920
921//____________________________________________________________
9bcfd1ab 922void AliAnalysisTaskHFE::ProcessAOD(){
dbe3abbe 923 //
9bcfd1ab 924 // Run Analysis in AOD Mode
925 // Function is still in development
dbe3abbe 926 //
9bcfd1ab 927 AliDebug(3, "Processing AOD Event");
e3fc062d 928 Double_t eventstatus = 1.;
929 fCFM->GetEventContainer()->Fill(&eventstatus,AliHFEcuts::kEventStepRecNoCut);
70da6c5a 930 if(!fCFM->CheckEventCuts(AliHFEcuts::kEventStepReconstructed, fInputEvent)) return;
e3fc062d 931 fCFM->GetEventContainer()->Fill(&eventstatus,AliHFEcuts::kEventStepReconstructed);
d2af20c5 932 AliAODEvent *fAOD = dynamic_cast<AliAODEvent *>(fInputEvent);
9bcfd1ab 933 if(!fAOD){
934 AliError("AOD Event required for AOD Analysis")
935 return;
936 }
937
938 AliAODTrack *track = NULL;
939 AliAODMCParticle *mctrack = NULL;
faee3b18 940 Double_t container[10]; memset(container, 0, sizeof(Double_t) * 10);
70da6c5a 941 Double_t dataE[6]; // [pT, eta, Phi, Charge, type, 'C' or 'B']
9bcfd1ab 942 Int_t nElectronCandidates = 0;
943 Int_t pid;
944 for(Int_t itrack = 0; itrack < fAOD->GetNumberOfTracks(); itrack++){
945 track = fAOD->GetTrack(itrack);
946 if(!track) continue;
947 if(track->GetFlags() != 1<<4) continue; // Only process AOD tracks where the HFE is set
948
949 container[0] = track->Pt();
950 container[1] = track->Eta();
951 container[2] = track->Phi();
70da6c5a 952 container[3] = track->Charge();
9bcfd1ab 953
954 dataE[0] = track->Pt();
955 dataE[1] = track->Eta();
956 dataE[2] = track->Phi();
70da6c5a 957 dataE[3] = track->Charge();
9bcfd1ab 958 dataE[4] = -1;
70da6c5a 959 dataE[5] = -1;
9bcfd1ab 960
961 if(HasMCData()){
faee3b18 962 Int_t signalTrack = 0;
963 if((signalTrack = IsSignalElectron(track))){
964 switch(signalTrack){
965 case 1: container[4] = container[9] = kSignalCharm; break;
966 case 2: container[4] = container[9] = kSignalBeauty; break;
967 };
968 } else if(IsGammaElectron(track))
969 container[4] = container[9] = kGammaConv;
970 else container[4] = container[9] = kOther;
971
9bcfd1ab 972 Int_t label = TMath::Abs(track->GetLabel());
973 if(label){
d2af20c5 974 mctrack = dynamic_cast<AliAODMCParticle *>(fMCEvent->GetTrack(label));
faee3b18 975 container[5] = mctrack->Pt();
976 container[6] = mctrack->Eta();
977 container[7] = mctrack->Phi();
978 container[8] = mctrack->Charge();
9bcfd1ab 979 }
980 }
981 // track accepted, do PID
982 AliHFEpidObject hfetrack;
983 hfetrack.fAnalysisType = AliHFEpidObject::kAODanalysis;
984 hfetrack.fRecTrack = track;
985 if(HasMCData()) hfetrack.fMCtrack = mctrack;
986 //if(!fPID->IsSelected(&hfetrack)) continue; // we will do PID here as soon as possible
987 // Particle identified - Fill CF Container
e3fc062d 988 // Apply weight for background contamination
989 Double_t weightBackGround = 1.0;
990 if(fBackGroundFactorsFunction) {
991 weightBackGround = weightBackGround - fBackGroundFactorsFunction->Eval(TMath::Abs(track->P()));
992 if(weightBackGround < 0.0) weightBackGround = 1.0;
993 }
994 fCFM->GetParticleContainer()->Fill(container, AliHFEcuts::kStepPID + 2*AliHFEcuts::kNcutStepsESDtrack, weightBackGround);
9bcfd1ab 995 nElectronCandidates++;
996 if(HasMCData()){
997 // Track selected: distinguish between true and fake
998 AliDebug(1, Form("Candidate Selected, filling THnSparse, PID: %d\n", mctrack->GetPdgCode()));
999 if((pid = TMath::Abs(mctrack->GetPdgCode())) == 11){
1000 Int_t type = IsSignalElectron(track);
1001 AliDebug(1, Form("Type: %d\n", type));
1002 if(type){
70da6c5a 1003 dataE[5] = type; // beauty[1] or charm[2]
1004 dataE[4] = 2; // signal electron
9bcfd1ab 1005 }
1006 else{
70da6c5a 1007 dataE[4] = 1; // not a signal electron
1008 dataE[5] = 0;
9bcfd1ab 1009 }
1010 }
1011 else {
1012 // Fill THnSparse with the information for Fake Electrons
9bcfd1ab 1013 dataE[4] = 0;
70da6c5a 1014 dataE[5] = 0;
9bcfd1ab 1015 }
1016 // fill the performance THnSparse, if the mc origin could be defined
70da6c5a 1017 if(dataE[4] > -1){
1018 AliDebug(1, Form("Entries: [%.3f|%.3f|%.3f|%f|%f|%f]\n", dataE[0],dataE[1],dataE[2],dataE[3],dataE[4],dataE[5]));
9bcfd1ab 1019 fPIDperformance->Fill(dataE);
1020 }
6ad05e72 1021 }
6ad05e72 1022 }
9bcfd1ab 1023 fNEvents->Fill(1);
1024 fNElectronTracksEvent->Fill(nElectronCandidates);
6ad05e72 1025}
1026
1027//____________________________________________________________
9bcfd1ab 1028Bool_t AliAnalysisTaskHFE::ProcessMCtrack(AliVParticle *track){
6ad05e72 1029 //
9bcfd1ab 1030 // Filter the Monte Carlo Track
1031 // Additionally Fill a THnSparse for Signal To Background Studies
1032 // Works for AOD and MC analysis Type
6ad05e72 1033 //
faee3b18 1034 Double_t container[5], signalContainer[6];
9bcfd1ab 1035 Double_t vertex[3]; // Production vertex cut to mask gammas which are NOT supposed to have hits in the first ITS layer(s)
1036 if(IsESDanalysis()){
1037 AliMCParticle *mctrack = dynamic_cast<AliMCParticle *>(track);
1038 container[0] = mctrack->Pt();
1039 container[1] = mctrack->Eta();
1040 container[2] = mctrack->Phi();
70da6c5a 1041 container[3] = mctrack->Charge()/3;
9bcfd1ab 1042
1043 signalContainer[0] = mctrack->Pt();
1044 signalContainer[1] = mctrack->Eta();
1045 signalContainer[2] = mctrack->Phi();
70da6c5a 1046 signalContainer[3] = mctrack->Charge()/3;
9bcfd1ab 1047
1048 vertex[0] = mctrack->Particle()->Vx();
1049 vertex[1] = mctrack->Particle()->Vy();
1050 } else {
1051 AliAODMCParticle *aodmctrack = dynamic_cast<AliAODMCParticle *>(track);
1052 container[0] = aodmctrack->Pt();
1053 container[1] = aodmctrack->Eta();
1054 container[2] = aodmctrack->Phi();
70da6c5a 1055 container[3] = aodmctrack->Charge()/3;
9bcfd1ab 1056
1057 signalContainer[0] = aodmctrack->Pt();
1058 signalContainer[1] = aodmctrack->Eta();
1059 signalContainer[2] = aodmctrack->Phi();
70da6c5a 1060 signalContainer[3] = aodmctrack->Charge()/3;
9bcfd1ab 1061
1062 aodmctrack->XvYvZv(vertex);
6ad05e72 1063 }
faee3b18 1064 Int_t signal = 0;
1065 if((signal = IsSignalElectron(track))){
1066 switch(signal){
1067 case 1: container[4] = kSignalCharm; break;
1068 case 2: container[4] = kSignalBeauty; break;
1069 };
1070 }else if(IsGammaElectron(track)) container[4] = kGammaConv;
1071 else container[4] = kOther;
1072
1073 // weight
1074 Double_t weight = 1.0;
1075 if(fWeighting) weight = FindWeight(container[0],container[1],container[2]);
1076
1077 if(!fCFM->CheckParticleCuts(AliHFEcuts::kStepMCGenerated, track)) return kFALSE;
70da6c5a 1078 TH1 *test = dynamic_cast<TH1I*>(fQA->FindObject("mccharge"));
1079 test->Fill(signalContainer[3]);
faee3b18 1080 fCFM->GetParticleContainer()->Fill(container, AliHFEcuts::kStepMCGenerated,weight);
1081 if((signalContainer[4] = static_cast<Double_t >(IsSignalElectron(track))) > 1e-3) fCFM->GetParticleContainer()->Fill(container, AliHFEcuts::kStepMCsignal,weight);
70da6c5a 1082 signalContainer[5] = 0;
9bcfd1ab 1083 // apply cut on the sqrt of the production vertex
1084 Double_t radVertex = TMath::Sqrt(vertex[0]*vertex[0] + vertex[1] * vertex[1]);
1085 if(radVertex < 3.5){
1086 // Within first ITS layer(2) -> Background we cannot reject by ITS cut, let it pass
70da6c5a 1087 signalContainer[5] = 1;
9bcfd1ab 1088 } else if (radVertex < 7.5){
70da6c5a 1089 signalContainer[5] = 2;
9bcfd1ab 1090 }
1091 fSignalToBackgroundMC->Fill(signalContainer);
1092 (dynamic_cast<TH1F *>(fQA->At(2)))->Fill(container[2] - TMath::Pi());
1093 //if(IsESDanalysis()){
1094 if(!fCFM->CheckParticleCuts(AliHFEcuts::kStepMCInAcceptance, track)) return kFALSE;
faee3b18 1095 fCFM->GetParticleContainer()->Fill(container, AliHFEcuts::kStepMCInAcceptance,weight);
9bcfd1ab 1096 //}
1097 return kTRUE;
6ad05e72 1098}
1099
e3fc062d 1100//____________________________________________________________
1101void AliAnalysisTaskHFE::FilterTaggedTrack(AliESDtrack *track, Int_t species){
1102 //
1103 // Filter tracks tagged by V0 PID class
1104 //
1105 Int_t offset = AliHFEcuts::kStepRecKineITSTPC;
1106 Double_t container[5] ={track->Pt(), track->Eta(), track->Phi(), track->Charge(), species};
1107 fV0CF->GetParticleContainer()->Fill(container, 0); // Fill Container without filtering
1108 Bool_t survived = kTRUE;
1109 for(Int_t icut = AliHFEcuts::kStepRecKineITSTPC; icut < AliHFEcuts::kStepPID; icut++){
1110 AliDebug(2, Form("Checking cut %d for species %s", icut, AliPID::ParticleName(species)));
1111 if(!fV0CF->CheckParticleCuts(icut, track)){
1112 survived = kFALSE;
1113 break;
1114 }
1115 AliDebug(2, Form("Cut passed, filling container %d", icut - offset + 1));
1116 fV0CF->GetParticleContainer()->Fill(container, icut - offset + 1);
1117 }
1118 if(survived){
1119 // Apply PID
1120 AliHFEpidObject hfetrack;
1121 hfetrack.fAnalysisType = AliHFEpidObject::kESDanalysis;
1122 hfetrack.fRecTrack = track;
1123 if(fPIDtagged->IsSelected(&hfetrack)) fV0CF->GetParticleContainer()->Fill(container, AliHFEcuts::kStepPID - offset + 1);
1124 }
1125}
1126//____________________________________________________________
1127Bool_t AliAnalysisTaskHFE::PreSelectTrack(AliESDtrack *track) const {
1128 //
1129 // Preselect tracks
1130 //
1131
1132
1133 Bool_t survived = kTRUE;
1134
1135 if(!fCutspreselect->CheckParticleCuts(AliHFEcuts::kStepRecKineITSTPC, track)) {
1136 survived = kFALSE;
1137 //printf("Did not pass AliHFEcuts::kStepRecKineITSTPC\n");
1138 }
1139 //else printf("Pass AliHFEcuts::kStepRecKineITSTPC\n");
1140 if(!fCutspreselect->CheckParticleCuts(AliHFEcuts::kStepRecPrim, track)) {
1141 survived = kFALSE;
1142 //printf("Did not pass AliHFEcuts::kStepRecPrim\n");
1143 }
1144 //else printf("Pass AliHFEcuts::kStepRecPrim\n");
1145 if(!fCutspreselect->CheckParticleCuts(AliHFEcuts::kStepHFEcutsITS, track)) {
1146 survived = kFALSE;
1147 //printf("Did not pass AliHFEcuts::kStepHFEcutsITS\n");
1148 }
1149 //else printf("Pass AliHFEcuts::kStepHFEcutsITS\n");
1150 if(!fCutspreselect->CheckParticleCuts(AliHFEcuts::kStepHFEcutsTRD, track)) {
1151 survived = kFALSE;
1152 //printf("Did not pass AliHFEcuts::kStepHFEcutsTRD\n");
1153 }
1154 //else printf("Pass AliHFEcuts::kStepHFEcutsTRD\n");
1155
1156 if(survived){
1157 // Apply PID
1158 AliHFEpidObject hfetrack;
1159 hfetrack.fAnalysisType = AliHFEpidObject::kESDanalysis;
1160 hfetrack.fRecTrack = track;
1161 if(!fPIDpreselect->IsSelected(&hfetrack)) {
1162 //printf("Did not pass AliHFEcuts::kPID\n");
1163 survived = kFALSE;
1164 }
1165 //else printf("Pass AliHFEcuts::kPID\n");
1166 }
1167
1168 return survived;
1169
1170}
70da6c5a 1171//____________________________________________________________
1172void AliAnalysisTaskHFE::MakeEventContainer(){
1173 //
1174 // Create the event container for the correction framework and link it
1175 //
1176 const Int_t kNvar = 1; // number of variables on the grid: number of tracks per event
e3fc062d 1177 const Double_t kStatBound[2] = {0.5, 1.5};
1178 const Int_t kNBins = 1;
70da6c5a 1179
1180 AliCFContainer *evCont = new AliCFContainer("eventContainer", "Container for events", AliHFEcuts::kNcutStepsEvent, kNvar, &kNBins);
1181
e3fc062d 1182 Double_t *statBins = AliHFEtools::MakeLinearBinning(kNBins, kStatBound[0], kStatBound[1]);
1183 evCont->SetBinLimits(0, statBins);
1184 delete[] statBins;
70da6c5a 1185
1186 fCFM->SetEventContainer(evCont);
1187}
1188
809a4336 1189//____________________________________________________________
1190void AliAnalysisTaskHFE::MakeParticleContainer(){
1191 //
1192 // Create the particle container for the correction framework manager and
1193 // link it
1194 //
faee3b18 1195 const Int_t kNvar = 5;
1196 //number of variables on the grid:pt,eta, phi, charge
e3fc062d 1197 const Double_t kPtbound[2] = {0.1, 20.};
70da6c5a 1198 const Double_t kEtabound[2] = {-0.8, 0.8};
1199 const Double_t kPhibound[2] = {0., 2. * TMath::Pi()};
809a4336 1200
1201 //arrays for the number of bins in each dimension
259c3296 1202 Int_t iBin[kNvar];
e3fc062d 1203 iBin[0] = 44; // bins in pt
70da6c5a 1204 iBin[1] = 8; // bins in eta
809a4336 1205 iBin[2] = 18; // bins in phi
70da6c5a 1206 iBin[3] = 2; // bins in charge
faee3b18 1207 iBin[4] = 4; // creation process of the electron
809a4336 1208
1209 //arrays for lower bounds :
259c3296 1210 Double_t* binEdges[kNvar];
70da6c5a 1211 binEdges[0] = AliHFEtools::MakeLogarithmicBinning(iBin[0], kPtbound[0], kPtbound[1]);
1212 binEdges[1] = AliHFEtools::MakeLinearBinning(iBin[1], kEtabound[0], kEtabound[1]);
1213 binEdges[2] = AliHFEtools::MakeLinearBinning(iBin[2], kPhibound[0], kPhibound[1]);
1214 binEdges[3] = AliHFEtools::MakeLinearBinning(iBin[3], -1.1, 1.1); // Numeric precision
faee3b18 1215 binEdges[4] = AliHFEtools::MakeLinearBinning(iBin[4], 0, iBin[4]); // Numeric precision
1216 //for(Int_t ib = 0; ib <= iBin[4]; ib++) printf("%f\t", binEdges[4][ib]);
1217 //printf("\n");
809a4336 1218
1219 //one "container" for MC
70da6c5a 1220 AliCFContainer* container = new AliCFContainer("trackContainer", "Container for tracks", (AliHFEcuts::kNcutStepsTrack + 2*AliHFEcuts::kNcutStepsESDtrack), kNvar, iBin);
67fe7bd0 1221 fHadronicBackground = new AliCFContainer("hadronicBackground", "Container for hadronic Background", 2, kNvar, iBin);
dbe3abbe 1222
809a4336 1223 //setting the bin limits
faee3b18 1224 for(Int_t ivar = 0; ivar < kNvar; ivar++){
dbe3abbe 1225 container -> SetBinLimits(ivar, binEdges[ivar]);
faee3b18 1226 fHadronicBackground -> SetBinLimits(ivar, binEdges[ivar]);
1227 }
809a4336 1228 fCFM->SetParticleContainer(container);
259c3296 1229
1230 //create correlation matrix for unfolding
1231 Int_t thnDim[2*kNvar];
1232 for (int k=0; k<kNvar; k++) {
1233 //first half : reconstructed
1234 //second half : MC
1235 thnDim[k] = iBin[k];
1236 thnDim[k+kNvar] = iBin[k];
1237 }
1238
78ea5ef4 1239 if(!fCorrelation) fCorrelation = new TList();
1240 fCorrelation->SetName("correlation");
1241
722347d8 1242 THnSparseF *correlation0 = new THnSparseF("correlationstepbeforePID","THnSparse with correlations",2*kNvar,thnDim);
1243 THnSparseF *correlation1 = new THnSparseF("correlationstepafterPID","THnSparse with correlations",2*kNvar,thnDim);
259c3296 1244 for (int k=0; k<kNvar; k++) {
78ea5ef4 1245 correlation0->SetBinEdges(k,binEdges[k]);
1246 correlation0->SetBinEdges(k+kNvar,binEdges[k]);
1247 correlation1->SetBinEdges(k,binEdges[k]);
1248 correlation1->SetBinEdges(k+kNvar,binEdges[k]);
259c3296 1249 }
78ea5ef4 1250 correlation0->Sumw2();
1251 correlation1->Sumw2();
722347d8 1252
78ea5ef4 1253 fCorrelation->AddAt(correlation0,0);
1254 fCorrelation->AddAt(correlation1,1);
78ea5ef4 1255
259c3296 1256 // Add a histogram for Fake electrons
70da6c5a 1257 const Int_t nDim=6;
1258 Int_t nBin[nDim] = {40, 8, 18, 2, 3, 3};
78ea5ef4 1259 Double_t* binEdges2[nDim];
78ea5ef4 1260
1261 //values for bin lower bounds
70da6c5a 1262 for(Int_t ivar = 0; ivar < kNvar; ivar++)
1263 binEdges2[ivar] = binEdges[ivar];
1264 binEdges2[4] = AliHFEtools::MakeLinearBinning(nBin[4], 0, nBin[4]);
1265 binEdges2[5] = AliHFEtools::MakeLinearBinning(nBin[5], 0, nBin[5]);
78ea5ef4 1266
70da6c5a 1267 fPIDperformance = new THnSparseF("PIDperformance", "PID performance; pT [GeV/c]; theta [rad]; phi [rad]; charge; type (0 - not el, 1 - other el, 2 - HF el; flavor (0 - no, 1 - charm, 2 - bottom)", nDim, nBin);
d2af20c5 1268 fPIDperformance->Sumw2();
70da6c5a 1269 fSignalToBackgroundMC = new THnSparseF("SignalToBackgroundMC", "PID performance; pT [GeV/c]; theta [rad]; phi [rad]; charge; flavor (0 - no, 1 - charm, 2 - bottom); ITS Cluster (0 - no, 1 - first (and maybe second), 2 - second)", nDim, nBin);
d2af20c5 1270 fSignalToBackgroundMC->Sumw2();
9bcfd1ab 1271 for(Int_t idim = 0; idim < nDim; idim++){
78ea5ef4 1272 fPIDperformance->SetBinEdges(idim, binEdges2[idim]);
9bcfd1ab 1273 fSignalToBackgroundMC->SetBinEdges(idim, binEdges2[idim]);
1274 }
e3fc062d 1275
1276 // create correction framework container for V0-tagged particles, new bin limits in 4th bin
1277 iBin[4] = 5;
1278 delete binEdges[4];
1279 binEdges[4] = AliHFEtools::MakeLinearBinning(iBin[4], 0, iBin[4]); // Numeric precision
1280 AliCFContainer *tagged = new AliCFContainer("taggedTrackContainer", "Correction Framework Container for tagged tracks", AliHFEcuts::kNcutStepsESDtrack, kNvar, iBin);
1281 for(Int_t ivar = 0; ivar < kNvar; ivar++)
1282 tagged->SetBinLimits(ivar, binEdges[ivar]);
1283 fV0CF->SetParticleContainer(tagged);
1284
70da6c5a 1285 for(Int_t ivar = 0; ivar < kNvar; ivar++)
1286 delete binEdges[ivar];
1287 for(Int_t ivar = kNvar; ivar < nDim; ivar++)
1288 delete binEdges2[ivar];
809a4336 1289}
dbe3abbe 1290
50685501 1291//____________________________________________________________
70da6c5a 1292void AliAnalysisTaskHFE::AddPIDdetector(TString detector){
50685501 1293 //
1294 // Adding PID detector to the task
1295 //
75d81601 1296 if(!fPIDdetectors.Length())
1297 fPIDdetectors = detector;
1298 else
70da6c5a 1299 fPIDdetectors += ":" + detector;
75d81601 1300}
1301
1302//____________________________________________________________
50685501 1303void AliAnalysisTaskHFE::PrintStatus() const {
78ea5ef4 1304 //
1305 // Print Analysis status
1306 //
75d81601 1307 printf("\n\tAnalysis Settings\n\t========================================\n\n");
9bcfd1ab 1308 printf("\tSecondary Vertex finding: %s\n", GetPlugin(kSecVtx) ? "YES" : "NO");
1309 printf("\tPrimary Vertex resolution: %s\n", GetPlugin(kPriVtx) ? "YES" : "NO");
75d81601 1310 printf("\n");
1311 printf("\tParticle Identification Detectors:\n");
1312 TObjArray *detectors = fPIDdetectors.Tokenize(":");
1313 for(Int_t idet = 0; idet < detectors->GetEntries(); idet++)
1314 printf("\t\t%s\n", (dynamic_cast<TObjString *>(detectors->At(idet)))->String().Data());
1315 printf("\n");
1316 printf("\tQA: \n");
1317 printf("\t\tPID: %s\n", IsQAOn(kPIDqa) ? "YES" : "NO");
e3fc062d 1318 printf("\t\tCUTS: %s\n", (fCuts != NULL && fCuts->IsQAOn()) ? "YES" : "NO");
75d81601 1319 printf("\t\tMC: %s\n", IsQAOn(kMCqa) ? "YES" : "NO");
1320 printf("\n");
1321}
78ea5ef4 1322
1323//____________________________________________________________
1324AliAnalysisTaskHFE::LabelContainer::LabelContainer(Int_t capacity):
1325 fContainer(NULL),
1326 fBegin(NULL),
1327 fEnd(NULL),
1328 fLast(NULL),
1329 fCurrent(NULL)
1330{
1331 //
1332 // Default constructor
1333 //
1334 fContainer = new Int_t[capacity];
1335 fBegin = &fContainer[0];
1336 fEnd = &fContainer[capacity - 1];
1337 fLast = fCurrent = fBegin;
1338}
1339
1340//____________________________________________________________
1341Bool_t AliAnalysisTaskHFE::LabelContainer::Append(Int_t label){
1342 //
1343 // Add Label to the container
1344 //
1345 if(fLast > fEnd) return kFALSE;
1346 *fLast++ = label;
1347 return kTRUE;
1348}
1349
1350//____________________________________________________________
50685501 1351Bool_t AliAnalysisTaskHFE::LabelContainer::Find(Int_t label) const {
78ea5ef4 1352 //
1353 // Find track in the list of labels
1354 //
1355 for(Int_t *entry = fBegin; entry <= fLast; entry++)
1356 if(*entry == label) return kTRUE;
1357 return kFALSE;
1358}
1359
1360//____________________________________________________________
1361Int_t AliAnalysisTaskHFE::LabelContainer::Next(){
1362 //
1363 // Mimic iterator
1364 //
1365 if(fCurrent > fLast) return -1;
1366 return *fCurrent++;
1367}
1368
1369//____________________________________________________________
faee3b18 1370Int_t AliAnalysisTaskHFE::IsSignalElectron(const AliVParticle * const track) const{
78ea5ef4 1371 //
1372 // Checks whether the identified electron track is coming from heavy flavour
1373 // returns 0 in case of no signal, 1 in case of charm and 2 in case of Bottom
1374 //
1375 enum{
1376 kNoSignal = 0,
722347d8 1377 kCharm = 1,
1378 kBeauty = 2
78ea5ef4 1379 };
faee3b18 1380
1381 if(!fMCEvent) return kNoSignal;
1382 const AliVParticle *motherParticle = NULL, *mctrack = NULL;
1383 TString objectType = track->IsA()->GetName();
1384 Int_t label = 0;
1385 if(objectType.CompareTo("AliESDtrack") == 0 || objectType.CompareTo("AliAODTrack") == 0){
1386 // Reconstructed track
1387 if((label = TMath::Abs(track->GetLabel())) && label < fMCEvent->GetNumberOfTracks())
1388 mctrack = fMCEvent->GetTrack(label);
1389 } else {
1390 // MCParticle
1391 mctrack = track;
1392 }
1393
1394 if(!mctrack) return kNoSignal;
1395
9bcfd1ab 1396 Int_t pid = 0;
faee3b18 1397 Int_t daughterPDG = 0, motherLabel = 0;
1398 if(TString(mctrack->IsA()->GetName()).CompareTo("AliMCParticle") == 0){
1399 // case MC Particle
1400 daughterPDG = TMath::Abs((dynamic_cast<const AliMCParticle *>(mctrack))->Particle()->GetPdgCode());
1401 motherLabel = (dynamic_cast<const AliMCParticle *>(mctrack))->Particle()->GetFirstMother();
1402 if(motherLabel >= 0 && motherLabel < fMCEvent->GetNumberOfTracks())
1403 motherParticle = fMCEvent->GetTrack(motherLabel);
1404 if(motherParticle)
1405 pid = TMath::Abs((dynamic_cast<const AliMCParticle *>(motherParticle))->Particle()->GetPdgCode());
9bcfd1ab 1406 } else {
faee3b18 1407 // case AODMCParticle
1408 daughterPDG = TMath::Abs((dynamic_cast<const AliAODMCParticle *>(mctrack))->GetPdgCode());
1409 motherLabel = (dynamic_cast<const AliAODMCParticle *>(mctrack))->GetMother();
1410 if(motherLabel >= 0 && motherLabel < fMCEvent->GetNumberOfTracks())
1411 motherParticle = fMCEvent->GetTrack(motherLabel);
1412 if(motherParticle)
1413 pid = TMath::Abs((dynamic_cast<const AliAODMCParticle *>(motherParticle))->GetPdgCode());
722347d8 1414 }
faee3b18 1415 AliDebug(5, Form("Daughter PDG code: %d", daughterPDG));
1416
1417 if(!pid) return kNoSignal;
1418
9bcfd1ab 1419 // From here the two analysis modes go together
faee3b18 1420 AliDebug(5, Form("Mother PDG code: %d", pid));
78ea5ef4 1421
faee3b18 1422 // identify signal according to Pdg Code - barions higher ranked than mesons
78ea5ef4 1423 if(pid / 1000 == 4) return kCharm; // charmed baryon, 4th position in pdg code == 4
78ea5ef4 1424 if(pid / 1000 == 5) return kBeauty; // beauty baryon, 4th position in pdg code == 5
faee3b18 1425 if((pid % 1000) / 100 == 4) return kCharm; // charmed meson, 3rd position in pdg code == 4
1426 if((pid % 1000) / 100 == 5) return kBeauty; // beauty meson, 3rd position in pdg code == 5
78ea5ef4 1427 return kNoSignal;
1428}
722347d8 1429
faee3b18 1430//__________________________________________
1431Bool_t AliAnalysisTaskHFE::IsGammaElectron(const AliVParticle * const track) const {
1432 //
1433 // Check for MC if the electron is coming from Gamma
1434 //
1435 if(!fMCEvent) return kFALSE;
1436 const AliVParticle *motherParticle = NULL, *mctrack = NULL;
1437 TString objectType = track->IsA()->GetName();
1438 if(objectType.CompareTo("AliESDtrack") == 0 || objectType.CompareTo("AliAODTrack") == 0){
1439 // Reconstructed track
1440 if(track->GetLabel())
1441 mctrack = fMCEvent->GetTrack(TMath::Abs(track->GetLabel()));
1442 } else {
1443 // MCParticle
1444 mctrack = track;
1445 }
1446
1447 if(!mctrack) return kFALSE;
1448
1449 Int_t motherPDG = 0;
1450 if(TString(mctrack->IsA()->GetName()).CompareTo("AliMCParticle") == 0){
1451 // case MC Particle
1452 motherParticle = fMCEvent->GetTrack((dynamic_cast<const AliMCParticle *>(mctrack)->Particle()->GetFirstMother()));
1453 if(motherParticle)
1454 motherPDG = TMath::Abs((dynamic_cast<const AliMCParticle *>(motherParticle))->Particle()->GetPdgCode());
1455 } else {
1456 // case AODMCParticle
1457 motherParticle = fMCEvent->GetTrack((dynamic_cast<const AliAODMCParticle *>(mctrack))->GetMother());
1458 if(motherParticle)
1459 motherPDG = TMath::Abs((dynamic_cast<const AliAODMCParticle *>(motherParticle))->GetPdgCode());
1460 }
1461 if(motherPDG!=22) return kFALSE;
1462 else return kTRUE;
1463}
1464//____________________________________________________________
1465Bool_t AliAnalysisTaskHFE::FillProductionVertex(const AliVParticle * const track) const{
1466 //
1467 // Find the production vertex of the associated MC track
1468 //
1469 if(!fMCEvent) return kFALSE;
1470 const AliVParticle *mctrack = NULL;
1471 TString objectType = track->IsA()->GetName();
1472 if(objectType.CompareTo("AliESDtrack") == 0 || objectType.CompareTo("AliAODTrack") == 0){
1473 // Reconstructed track
1474 mctrack = fMCEvent->GetTrack(TMath::Abs(track->GetLabel()));
1475 } else {
1476 // MCParticle
1477 mctrack = track;
1478 }
1479
1480 if(!mctrack) return kFALSE;
1481
1482 Double_t xv = 0.0;
1483 Double_t yv = 0.0;
1484
1485 if(TString(mctrack->IsA()->GetName()).CompareTo("AliMCParticle") == 0){
1486 // case MCParticle
1487 xv = (dynamic_cast<const AliMCParticle *>(mctrack)->Xv());
1488 yv = (dynamic_cast<const AliMCParticle *>(mctrack)->Yv());
1489
1490 } else {
1491 // case AODMCParticle
1492 xv = (dynamic_cast<const AliAODMCParticle *>(mctrack)->Xv());
1493 yv = (dynamic_cast<const AliAODMCParticle *>(mctrack)->Yv());
1494 }
1495
1496 //printf("xv %f, yv %f\n",xv,yv);
1497
1498 TH2F *test = dynamic_cast<TH2F*>(fQA->FindObject("radius"));
1499 if(!test) return kFALSE;
1500 else {
1501 test->Fill(TMath::Abs(xv),TMath::Abs(yv));
1502 }
1503
1504 return kTRUE;
1505
1506}
9bcfd1ab 1507//__________________________________________
1508void AliAnalysisTaskHFE::SwitchOnPlugin(Int_t plug){
1509 //
1510 // Switch on Plugin
1511 // Available:
1512 // - Primary vertex studies
1513 // - Secondary vertex Studies
1514 // - Post Processing
1515 //
1516 switch(plug){
1517 case kPriVtx: SETBIT(fPlugins, plug); break;
1518 case kSecVtx: SETBIT(fPlugins, plug); break;
1519 case kIsElecBackGround: SETBIT(fPlugins, plug); break;
1520 case kPostProcess: SETBIT(fPlugins, plug); break;
1521 default: AliError("Unknown Plugin");
1522 };
1523}
faee3b18 1524//_______________________________________________
1525void AliAnalysisTaskHFE::SetWeightFactors(TH3D * const weightFactors){
1526 //
1527 // Set the histos with the weights for the efficiency maps
1528 //
1529 fWeighting = kTRUE;
1530 fWeightFactors = weightFactors;
1531}
1532//_______________________________________________
1533void AliAnalysisTaskHFE::SetWeightFactorsFunction(TF1 * const weightFactorsFunction){
1534 //
1535 // Set the histos with the weights for the efficiency maps
1536 //
1537 fWeighting = kTRUE;
1538 fWeightFactorsFunction = weightFactorsFunction;
1539 //printf("SetWeightFactors\n");
1540}
1541//_______________________________________________
1542Double_t AliAnalysisTaskHFE::FindWeight(Double_t pt, Double_t eta, Double_t phi) const {
1543 //
1544 // Find the weight corresponding to pt eta and phi in the TH3D
1545 //
1546 Double_t weight = 1.0;
1547 if(fWeightFactors) {
1548
1549 TAxis *ptaxis = fWeightFactors->GetXaxis();
1550 TAxis *etaaxis = fWeightFactors->GetYaxis();
1551 TAxis *phiaxis = fWeightFactors->GetZaxis();
1552
1553 Int_t ptbin = ptaxis->FindBin(pt);
1554 Int_t etabin = etaaxis->FindBin(eta);
1555 Int_t phibin = phiaxis->FindBin(phi);
1556
1557
1558 weight = fWeightFactors->GetBinContent(ptbin,etabin,phibin);
1559 }
1560 else if(fWeightFactorsFunction) {
1561
1562 weight = fWeightFactorsFunction->Eval(pt,eta,phi);
1563 //printf("pt %f and weight %f\n",pt,weight);
1564
1565 }
9bcfd1ab 1566
faee3b18 1567 //printf("pt %f, eta %f, phi %f, weight %f\n",pt,eta,phi,weight);
1568
1569 return weight;
1570
1571}
9bcfd1ab 1572//__________________________________________
faee3b18 1573Bool_t AliAnalysisTaskHFE::ProcessCutStep(Int_t cutStep, AliVParticle *track, Double_t *container, Bool_t signal, Bool_t alreadyseen,Double_t weight){
9bcfd1ab 1574 //
1575 // Check single track cuts for a given cut step
1576 // Fill the particle container
1577 //
1578 if(!fCFM->CheckParticleCuts(cutStep, track)) return kFALSE;
1579 if(signal) {
faee3b18 1580 fCFM->GetParticleContainer()->Fill(container, cutStep + 2*AliHFEcuts::kNcutStepsESDtrack,weight);
1581 fCFM->GetParticleContainer()->Fill(&container[5], cutStep,weight);
9bcfd1ab 1582 if(alreadyseen) {
faee3b18 1583 fCFM->GetParticleContainer()->Fill(&container[5], cutStep + AliHFEcuts::kNcutStepsESDtrack,weight);
9bcfd1ab 1584 }
1585 }
1586 return kTRUE;
1587}
70da6c5a 1588