]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGCF/Correlations/DPhi/AliAnalysisTaskPhiCorrelations.cxx
fix in processing MC AODs
[u/mrichter/AliRoot.git] / PWGCF / Correlations / DPhi / AliAnalysisTaskPhiCorrelations.cxx
CommitLineData
e0331fd9 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 **************************************************************************/
15
16/* $Id:$ */
17
18#include <TROOT.h>
19#include <TChain.h>
20#include <TFile.h>
21#include <TList.h>
22#include <TMath.h>
23#include <TTree.h>
24#include <TH2F.h>
25#include <TRandom.h>
26
27#include "AliAnalysisTaskPhiCorrelations.h"
28#include "AliAnalyseLeadingTrackUE.h"
29#include "AliUEHistograms.h"
30#include "AliUEHist.h"
31
e0331fd9 32#include "AliAnalysisManager.h"
33#include "AliAODHandler.h"
34#include "AliAODInputHandler.h"
35#include "AliAODMCParticle.h"
e0331fd9 36#include "AliInputEventHandler.h"
37#include "AliLog.h"
38#include "AliMCEventHandler.h"
39#include "AliVParticle.h"
2a910c25 40#include "AliCFContainer.h"
e0331fd9 41
42#include "AliESDEvent.h"
43#include "AliESDInputHandler.h"
44#include "AliMultiplicity.h"
2a910c25 45#include "AliCentrality.h"
46#include "AliStack.h"
7dd4dec4 47#include "AliAODMCHeader.h"
e0331fd9 48
2a910c25 49#include "AliEventPoolManager.h"
e0331fd9 50
51
52////////////////////////////////////////////////////////////////////////
53//
54// Analysis class for azimuthal correlation studies
55// Based on the UE task from Sara Vallero and Jan Fiete
56//
57// This class needs input AODs.
58// The output is a list of analysis-specific containers.
59//
60// The AOD can be either connected to the InputEventHandler
61// for a chain of AOD files
62// or
63// to the OutputEventHandler
64// for a chain of ESD files,
65// in this case the class should be in the train after the jet-finder
66//
67// Authors:
68// Jan Fiete Grosse-Oetringhaus
69//
70////////////////////////////////////////////////////////////////////////
71
72
73ClassImp( AliAnalysisTaskPhiCorrelations )
a1c31636 74ClassImp( AliDPhiBasicParticle )
e0331fd9 75
76//____________________________________________________________________
77AliAnalysisTaskPhiCorrelations:: AliAnalysisTaskPhiCorrelations(const char* name):
78AliAnalysisTask(name,""),
79// general configuration
80fDebug(0),
81fMode(0),
82fReduceMemoryFootprint(kFALSE),
eed401dc 83fFillMixed(kTRUE),
ac647b0f 84fMixingTracks(50000),
c3294f09 85fCompareCentralities(kFALSE),
1bba939a 86fTwoTrackEfficiencyStudy(kFALSE),
44af28f9 87fUseVtxAxis(kFALSE),
e0331fd9 88// pointers to UE classes
89fAnalyseUE(0x0),
90fHistos(0x0),
91fHistosMixed(0),
92fkTrackingEfficiency(0x0),
93// handlers and events
85bfac17 94fAOD(0x0),
95fESD(0x0),
e0331fd9 96fArrayMC(0x0),
97fInputHandler(0x0),
98fMcEvent(0x0),
99fMcHandler(0x0),
2a910c25 100fPoolMgr(0x0),
e0331fd9 101// histogram settings
102fListOfHistos(0x0),
103// event QA
104fnTracksVertex(1), // QA tracks pointing to principal vertex (= 3 default)
85bfac17 105fZVertex(7.),
2a910c25 106fCentralityMethod("V0M"),
e0331fd9 107// track cuts
108fTrackEtaCut(0.8),
109fPtMin(0.5),
110fFilterBit(0xFF),
111fSelectBit(0),
2a910c25 112fUseChargeHadrons(kFALSE),
c05ff6be 113fSelectCharge(0),
d38fa455 114fTriggerRestrictEta(-1),
c05ff6be 115fFillpT(kFALSE)
e0331fd9 116{
117 // Default constructor
118 // Define input and output slots here
119 // Input slot #0 works with a TChain
120 DefineInput(0, TChain::Class());
121 // Output slot #0 writes into a TList container
122 DefineOutput(0, TList::Class());
e0331fd9 123}
124
125AliAnalysisTaskPhiCorrelations::~AliAnalysisTaskPhiCorrelations()
126{
127 // destructor
128
129 if (fListOfHistos && !AliAnalysisManager::GetAnalysisManager()->IsProofMode())
130 delete fListOfHistos;
131}
132
133//____________________________________________________________________
134void AliAnalysisTaskPhiCorrelations::ConnectInputData(Option_t* /*option*/)
135{
136
137 // Connect the input data
138 if (fDebug > 1) AliInfo("ConnectInputData() ");
139
140 // Since AODs can either be connected to the InputEventHandler
141 // or to the OutputEventHandler ( the AOD is created by a previus task in the train )
142 // we need to get the pointer to the AODEvent correctly.
143
144 // Delta AODs are also accepted.
145
146 TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
147
85bfac17 148 if( handler && handler->InheritsFrom("AliAODInputHandler") )
149 { // input AOD
150 fAOD = ((AliAODInputHandler*)handler)->GetEvent();
151 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODInputHandler");
152 }
153 else
154 { //output AOD
155 handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
156 if (handler && handler->InheritsFrom("AliAODHandler") )
157 {
158 fAOD = ((AliAODHandler*)handler)->GetAOD();
159 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODHandler");
160 }
161 else
162 { // no AOD
163 AliWarning("I can't get any AOD Event Handler");
164 }
165 }
166
167 if (handler && handler->InheritsFrom("AliESDInputHandler") )
168 { // input ESD
169 // pointer received per event in ::Exec
170 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliESDInputHandler");
171 }
e0331fd9 172
173 // Initialize common pointers
174 Initialize();
e0331fd9 175}
176
177//____________________________________________________________________
178void AliAnalysisTaskPhiCorrelations::CreateOutputObjects()
179{
180 // Create the output container
181
182 if (fDebug > 1) AliInfo("CreateOutputObjects()");
183
184 // Initialize class with main algorithms, event and track selection.
185 fAnalyseUE = new AliAnalyseLeadingTrackUE();
2a910c25 186 fAnalyseUE->SetParticleSelectionCriteria(fFilterBit, fUseChargeHadrons, fTrackEtaCut, fPtMin);
e0331fd9 187 fAnalyseUE->SetDebug(fDebug);
85bfac17 188 fAnalyseUE->DefineESDCuts(fFilterBit);
e0331fd9 189
190 // Initialize output list of containers
191 if (fListOfHistos != NULL){
192 delete fListOfHistos;
193 fListOfHistos = NULL;
194 }
195 if (!fListOfHistos){
196 fListOfHistos = new TList();
197 fListOfHistos->SetOwner(kTRUE);
198 }
199
200 // Initialize class to handle histograms
44af28f9 201 const char* histType = "4";
202 if (fUseVtxAxis)
203 histType = "5";
204 fHistos = new AliUEHistograms("AliUEHistogramsSame", histType);
205 fHistosMixed = new AliUEHistograms("AliUEHistogramsMixed", histType);
e0331fd9 206
2a910c25 207 fHistos->SetSelectCharge(fSelectCharge);
208 fHistosMixed->SetSelectCharge(fSelectCharge);
209
d38fa455 210 fHistos->SetTriggerRestrictEta(fTriggerRestrictEta);
211 fHistosMixed->SetTriggerRestrictEta(fTriggerRestrictEta);
212
e0331fd9 213 // add histograms to list
214 fListOfHistos->Add(fHistos);
215 fListOfHistos->Add(fHistosMixed);
216
2a910c25 217 fListOfHistos->Add(new TH2F("trackletsVsV0Cent", ";L1 clusters;v0 centrality", 100, -0.5, 9999.5, 101, 0, 101));
218 fListOfHistos->Add(new TH2F("processIDs", ";#Delta#phi;process id", 100, -0.5 * TMath::Pi(), 1.5 * TMath::Pi(), kPNoProcess + 1, -0.5, kPNoProcess + 0.5));
c066889a 219 fListOfHistos->Add(new TH1F("eventStat", ";;events", 4, -0.5, 3.5));
220 fListOfHistos->Add(new TH1F("mixedDist", ";tracks;events", 200, 0, fMixingTracks * 1.5));
e0331fd9 221
1a32ecc0 222 PostData(0,fListOfHistos);
223
e0331fd9 224 // Add task configuration to output list
225 AddSettingsTree();
226
2a910c25 227 // event mixing
ac647b0f 228 Int_t trackDepth = fMixingTracks;
a1c31636 229 Int_t poolsize = 1000; // Maximum number of events, ignored in the present implemented of AliEventPool
c066889a 230
2a910c25 231 Int_t nCentralityBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(1);
232 Double_t* centralityBins = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(1, 0)->GetXbins()->GetArray();
233
7a028750 234 Int_t nZvtxBins = 7+1+7;
235 // bins for second buffer are shifted by 100 cm
236 Double_t vertexBins[] = { -7, -5, -3, -1, 1, 3, 5, 7, 93, 95, 97, 99, 101, 103, 105, 107 };
eb88bdfe 237 Double_t* zvtxbin = vertexBins;
c066889a 238
eb88bdfe 239 if (fHistos->GetUEHist(2)->GetEventHist()->GetNVar() > 2)
240 {
241 nZvtxBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(2);
242 zvtxbin = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(2, 0)->GetXbins()->GetArray();
243 }
85bfac17 244
2a910c25 245 fPoolMgr = new AliEventPoolManager(poolsize, trackDepth, nCentralityBins, centralityBins, nZvtxBins, zvtxbin);
e0331fd9 246}
247
248//____________________________________________________________________
249void AliAnalysisTaskPhiCorrelations::Exec(Option_t */*option*/)
250{
85bfac17 251 // receive ESD pointer if we are not running AOD analysis
252 if (!fAOD)
253 {
254 AliVEventHandler* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
255 if (handler && handler->InheritsFrom("AliESDInputHandler"))
256 fESD = ((AliESDInputHandler*)handler)->GetEvent();
257 }
258
7dd4dec4 259 if (fMode)
260 {
261 // correction mode
262
263 if (fMcHandler)
264 fMcEvent = fMcHandler->MCEvent();
265
266 if (fAOD)
267 {
268 // array of MC particles
269 fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
270 if (!fArrayMC)
271 AliFatal("No array of MC particles found !!!");
272 }
273
274 AnalyseCorrectionMode();
275 }
e0331fd9 276 else AnalyseDataMode();
e0331fd9 277}
278
279/******************** ANALYSIS METHODS *****************************/
280
281//____________________________________________________________________
282void AliAnalysisTaskPhiCorrelations::AddSettingsTree()
283{
284 //Write settings to output list
285 TTree *settingsTree = new TTree("UEAnalysisSettings","Analysis Settings in UE estimation");
c05ff6be 286 settingsTree->Branch("fnTracksVertex", &fnTracksVertex,"nTracksVertex/I");
287 settingsTree->Branch("fZVertex", &fZVertex,"ZVertex/D");
288 //settingsTree->Branch("fCentralityMethod", fCentralityMethod.Data(),"CentralityMethod/C");
e0331fd9 289 settingsTree->Branch("fTrackEtaCut", &fTrackEtaCut, "TrackEtaCut/D");
290 settingsTree->Branch("fPtMin", &fPtMin, "PtMin/D");
c05ff6be 291 settingsTree->Branch("fFilterBit", &fFilterBit,"FilterBit/I");
292 settingsTree->Branch("fSelectBit", &fSelectBit,"EventSelectionBit/I");
e0331fd9 293 settingsTree->Branch("fUseChargeHadrons", &fUseChargeHadrons,"UseChHadrons/O");
c05ff6be 294 settingsTree->Branch("fSelectCharge", &fSelectCharge,"SelectCharge/I");
d38fa455 295 settingsTree->Branch("fTriggerRestrictEta", &fTriggerRestrictEta,"SelectCharge/D");
c05ff6be 296 settingsTree->Branch("fFillpT", &fFillpT,"FillpT/O");
e0331fd9 297 settingsTree->Branch("fkTrackingEfficiency", "TH1D", &fkTrackingEfficiency);
ac647b0f 298 settingsTree->Branch("fMixingTracks", &fMixingTracks,"MixingTracks/I");
e0331fd9 299 settingsTree->Fill();
300 fListOfHistos->Add(settingsTree);
301}
302
303//____________________________________________________________________
304void AliAnalysisTaskPhiCorrelations::AnalyseCorrectionMode()
305{
306 // Run the analysis on MC to get the correction maps
307 //
308
2a910c25 309 if ( fDebug > 3 ) AliInfo( " Processing event in Corrections mode ..." );
310
311 Double_t centrality = 0;
312
313 if (fCentralityMethod.Length() > 0)
314 {
85bfac17 315 AliCentrality *centralityObj = 0;
316 if (fAOD)
317 centralityObj = fAOD->GetHeader()->GetCentralityP();
318 else if (fESD)
319 centralityObj = fESD->GetCentrality();
320
2a910c25 321 if (centralityObj)
322 {
323 centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
a8583211 324 AliInfo(Form("Centrality is %f", centrality));
2a910c25 325 }
326 else
327 {
328 Printf("WARNING: Centrality object is 0");
329 centrality = -1;
330 }
331 }
332
85bfac17 333 // Support for ESD and AOD based analysis
334 AliVEvent* inputEvent = fAOD;
335 if (!inputEvent)
336 inputEvent = fESD;
337
338 TObject* mc = fArrayMC;
339 if (!mc)
340 mc = fMcEvent;
341
2a910c25 342 // count all events
343 fHistos->FillEvent(centrality, -1);
344
345 // Only consider MC events within the vtx-z region used also as cut on the reconstructed vertex
7dd4dec4 346 TObject* vertexSupplier = fMcEvent;
347 if (fAOD) // AOD
348 vertexSupplier = fAOD->FindListObject(AliAODMCHeader::StdBranchName());
349
350 if (!fAnalyseUE->VertexSelection(vertexSupplier, 0, fZVertex))
2a910c25 351 return;
85bfac17 352
7dd4dec4 353 Float_t zVtx = 0;
354 if (fAOD)
355 zVtx = ((AliAODMCHeader*) vertexSupplier)->GetVtxZ();
356 else
357 zVtx = fMcEvent->GetPrimaryVertex()->GetZ();
c05ff6be 358 Float_t weight = 1;
359 if (fFillpT)
360 weight = -1;
2a910c25 361
362 // Get MC primaries
85bfac17 363 TObjArray* tracksMC = fAnalyseUE->GetAcceptedParticles(mc, 0, kTRUE, -1, kTRUE);
2a910c25 364
365 // (MC-true all particles)
366 // STEP 0
c05ff6be 367 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepAll, tracksMC, 0, weight);
2a910c25 368
7a028750 369 // mixed event
8781a433 370 if (fFillMixed)
371 {
372 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx);
373 //pool->PrintInfo();
374 if (pool->IsReady() || pool->NTracksInPool() > fMixingTracks / 10 || pool->GetCurrentNEvents() >= 5)
375 for (Int_t jMix=0; jMix<pool->GetCurrentNEvents(); jMix++)
376 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepAll, tracksMC, pool->GetEvent(jMix), 1.0 / pool->GetCurrentNEvents(), (jMix == 0));
377 pool->UpdatePool(CloneAndReduceTrackList(tracksMC));
378 }
7a028750 379
2a910c25 380 // Trigger selection ************************************************
381 if (fAnalyseUE->TriggerSelection(fInputHandler))
382 {
c32a0ca9 383 // (MC-true all particles)
384 // STEP 1
385 if (!fReduceMemoryFootprint)
c05ff6be 386 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTriggered, tracksMC, 0, weight);
c32a0ca9 387 else
388 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
389
872dc651 390 if (!inputEvent) {
c32a0ca9 391 AliFatal("UNEXPECTED: inputEvent is 0. Trigger selection should have failed");
872dc651 392 return;
393 }
2a910c25 394
395 // Vertex selection *************************************************
85bfac17 396 if (fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex))
2a910c25 397 {
398 // fill here for tracking efficiency
399 // loop over particle species
400
401 for (Int_t particleSpecies = 0; particleSpecies < 4; particleSpecies++)
402 {
85bfac17 403 TObjArray* primMCParticles = fAnalyseUE->GetAcceptedParticles(mc, 0x0, kTRUE, particleSpecies, kTRUE);
404 TObjArray* primRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, particleSpecies, kTRUE);
405 TObjArray* allRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, particleSpecies, kTRUE);
2a910c25 406
407 fHistos->FillTrackingEfficiency(primMCParticles, primRecoTracksMatched, allRecoTracksMatched, particleSpecies, centrality);
408
eed401dc 409// Printf("%d --> %d %d %d", particleSpecies, primMCParticles->GetEntries(), primRecoTracksMatched->GetEntries(), allRecoTracksMatched->GetEntries());
410
411 delete primMCParticles;
2a910c25 412 delete primRecoTracksMatched;
413 delete allRecoTracksMatched;
414 }
415
416 // (MC-true all particles)
417 // STEP 2
85bfac17 418 if (!fReduceMemoryFootprint)
c05ff6be 419 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepVertex, tracksMC, 0, weight);
c32a0ca9 420 else
421 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
2a910c25 422
423 // Get MC primaries that match reconstructed track
85bfac17 424 TObjArray* tracksRecoMatchedPrim = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, -1, kTRUE);
2a910c25 425
426 // (RECO-matched (quantities from MC particle) primary particles)
427 // STEP 4
c05ff6be 428 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTrackedOnlyPrim, tracksRecoMatchedPrim, 0, weight);
2a910c25 429
430 // Get MC primaries + secondaries that match reconstructed track
85bfac17 431 TObjArray* tracksRecoMatchedAll = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, -1, kTRUE);
2a910c25 432
433 // (RECO-matched (quantities from MC particle) all particles)
434 // STEP 5
c05ff6be 435 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTracked, tracksRecoMatchedAll, 0, weight);
2a910c25 436
437 // Get RECO tracks
85bfac17 438 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, -1, kTRUE);
2a910c25 439
440 // (RECO all tracks)
441 // STEP 6
c05ff6be 442 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
2a910c25 443
7a028750 444 // mixed event
8781a433 445 if (fFillMixed)
446 {
447 AliEventPool* pool2 = fPoolMgr->GetEventPool(centrality, zVtx + 100);
448 //pool2->PrintInfo();
449 if (pool2->IsReady() || pool2->NTracksInPool() > fMixingTracks / 10 || pool2->GetCurrentNEvents() >= 5)
450 for (Int_t jMix=0; jMix<pool2->GetCurrentNEvents(); jMix++)
451 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, pool2->GetEvent(jMix), 1.0 / pool2->GetCurrentNEvents(), (jMix == 0));
452 pool2->UpdatePool(CloneAndReduceTrackList(tracks));
453 }
7a028750 454
85bfac17 455 if (0 && !fReduceMemoryFootprint)
2a910c25 456 {
457 // make list of secondaries (matched with MC)
458 TObjArray* tracksRecoMatchedSecondaries = new TObjArray;
459 for (Int_t i=0; i<tracksRecoMatchedAll->GetEntries(); i++)
460 if (((AliAODMCParticle*)tracksRecoMatchedAll->At(i))->IsPhysicalPrimary() == kFALSE)
461 tracksRecoMatchedSecondaries->Add(tracksRecoMatchedAll->At(i));
462
463 // Study: Use only secondaries as trigger particles and plot the correlation vs. all particles; store in step 9
c05ff6be 464 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy2, tracksRecoMatchedSecondaries, tracksRecoMatchedAll, weight);
2a910c25 465
466 // Study: Use only primaries as trigger particles and plot the correlation vs. secondaries; store in step 8
c05ff6be 467 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracksRecoMatchedPrim, tracksRecoMatchedSecondaries, weight);
2a910c25 468
469 // plot delta phi vs process id of secondaries
470 // trigger particles: primaries in 4 < pT < 10
471 // associated particles: secondaries in 1 < pT < 10
472
473 for (Int_t i=0; i<tracksRecoMatchedPrim->GetEntries(); i++)
474 {
475 AliVParticle* triggerParticle = (AliVParticle*) tracksRecoMatchedPrim->At(i);
476
477 if (triggerParticle->Pt() < 4 || triggerParticle->Pt() > 10)
478 continue;
479
480 for (Int_t j=0; j<tracksRecoMatchedSecondaries->GetEntries(); j++)
481 {
482 AliAODMCParticle* particle = (AliAODMCParticle*) tracksRecoMatchedSecondaries->At(j);
483
484 if (particle->Pt() < 1 || particle->Pt() > 10)
485 continue;
486
487 if (particle->Pt() > triggerParticle->Pt())
488 continue;
489
490 Double_t deltaPhi = triggerParticle->Phi() - particle->Phi();
491 if (deltaPhi > 1.5 * TMath::Pi())
492 deltaPhi -= TMath::TwoPi();
493 if (deltaPhi < -0.5 * TMath::Pi())
494 deltaPhi += TMath::TwoPi();
495
496 Int_t processID = fMcEvent->Stack()->Particle(particle->GetLabel())->GetUniqueID();
497
498 ((TH2F*) fListOfHistos->FindObject("processIDs"))->Fill(deltaPhi, processID);
499 }
500 }
501
502 delete tracksRecoMatchedSecondaries;
503 }
504
505 delete tracksRecoMatchedPrim;
506 delete tracksRecoMatchedAll;
507 delete tracks;
508 }
509 }
510
511 delete tracksMC;
e0331fd9 512}
513
514//____________________________________________________________________
515void AliAnalysisTaskPhiCorrelations::AnalyseDataMode()
516{
517
518 // Run the analysis on DATA or MC to get raw distributions
519
e0331fd9 520 if ( fDebug > 3 ) AliInfo( " Processing event in Data mode ..." );
e0331fd9 521
c066889a 522 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(0);
523
2a910c25 524 // skip not selected events here (the AOD is not updated for those)
525 if (!fInputHandler)
526 return;
527
85bfac17 528 if (!(fInputHandler->IsEventSelected() & (AliVEvent::kMB | AliVEvent::kUserDefined)))
2a910c25 529 return;
e0331fd9 530
2a910c25 531 Double_t centrality = 0;
532
c3294f09 533 AliCentrality *centralityObj = 0;
2a910c25 534 if (fCentralityMethod.Length() > 0)
535 {
85bfac17 536 if (fAOD)
537 centralityObj = fAOD->GetHeader()->GetCentralityP();
538 else if (fESD)
539 centralityObj = fESD->GetCentrality();
540
2a910c25 541 if (centralityObj)
542 centrality = centralityObj->GetCentralityPercentile(fCentralityMethod);
543 //centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
544 else
545 centrality = -1;
a6d82f4e 546
547 if (fAOD)
548 {
549 // remove outliers
550 if (centrality == 0)
551 {
552 if (fAOD->GetVZEROData())
553 {
554 Float_t multV0 = 0;
555 for (Int_t i=0; i<64; i++)
556 multV0 += fAOD->GetVZEROData()->GetMultiplicity(i);
557 if (multV0 < 19500)
558 {
559 centrality = -1;
560 AliInfo("Rejecting event due to too small V0 multiplicity");
561 }
562 }
563 }
564 }
565
a8583211 566 AliInfo(Form("Centrality is %f", centrality));
2a910c25 567 }
568
85bfac17 569 // Support for ESD and AOD based analysis
570 AliVEvent* inputEvent = fAOD;
571 if (!inputEvent)
572 inputEvent = fESD;
573
574 fHistos->SetRunNumber(inputEvent->GetRunNumber());
575
2a910c25 576 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
577 fHistos->FillEvent(centrality, AliUEHist::kCFStepAll);
578
e0331fd9 579 // Trigger selection ************************************************
580 if (!fAnalyseUE->TriggerSelection(fInputHandler)) return;
581
582 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
2a910c25 583 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
e0331fd9 584
585 // Vertex selection *************************************************
85bfac17 586 if(!fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex)) return;
e0331fd9 587
588 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
2a910c25 589 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
e0331fd9 590
c3294f09 591 // optimization
592 if (centrality < 0 && !fCompareCentralities)
2a910c25 593 return;
e0331fd9 594
85bfac17 595 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, -1, kTRUE);
2a910c25 596 //Printf("Accepted %d tracks", tracks->GetEntries());
e0331fd9 597
85bfac17 598 const AliVVertex* vertex = inputEvent->GetPrimaryVertex();
2a910c25 599 Double_t zVtx = vertex->GetZ();
600
c05ff6be 601 Float_t weight = 1;
602 if (fFillpT)
603 weight = -1;
604
c3294f09 605 // fill two different centralities (syst study)
606 // the zvtx axis is used to distinguish the results of both centralities: configured centrality in zvtx = 0, SPD in zvtx = 2
607 if (fCompareCentralities)
608 zVtx = 0;
2a910c25 609
c3294f09 610 // Fill containers at STEP 6 (reconstructed)
611 if (centrality >= 0)
c066889a 612 {
c05ff6be 613 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
c066889a 614 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(1);
615 }
c3294f09 616
1bba939a 617 // Two-track effect study
618 if (fTwoTrackEfficiencyStudy)
619 {
6840ec31 620 Float_t bSign = (fESD->GetMagneticField() > 0) ? 1 : -1;
c5c840c5 621 fHistos->TwoTrackEfficiency(tracks, 0, bSign);
1bba939a 622 }
623
c3294f09 624 // fill second time with SPD centrality
625 if (fCompareCentralities && centralityObj)
626 {
627 centrality = centralityObj->GetCentralityPercentile("CL1");
628 if (centrality >= 0)
c05ff6be 629 fHistos->FillCorrelations(centrality, 2, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
c3294f09 630 }
631
eed401dc 632 if (fFillMixed)
e0331fd9 633 {
eed401dc 634 // event mixing
2a910c25 635
eed401dc 636 // 1. First get an event pool corresponding in mult (cent) and
637 // zvertex to the current event. Once initialized, the pool
638 // should contain nMix (reduced) events. This routine does not
639 // pre-scan the chain. The first several events of every chain
640 // will be skipped until the needed pools are filled to the
641 // specified depth. If the pool categories are not too rare, this
642 // should not be a problem. If they are rare, you could lose
643 // statistics.
644
645 // 2. Collect the whole pool's content of tracks into one TObjArray
646 // (bgTracks), which is effectively a single background super-event.
647
648 // 3. The reduced and bgTracks arrays must both be passed into
649 // FillCorrelations(). Also nMix should be passed in, so a weight
650 // of 1./nMix can be applied.
651
652 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx);
653
654 if (!pool)
655 AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centrality, zVtx));
656
657 //pool->SetDebug(1);
2d7827bf 658
659 if (pool->IsReady() || pool->NTracksInPool() > fMixingTracks / 10 || pool->GetCurrentNEvents() >= 5)
eed401dc 660 {
661
662 Int_t nMix = pool->GetCurrentNEvents();
a1c31636 663// cout << "nMix = " << nMix << " tracks in pool = " << pool->NTracksInPool() << endl;
c066889a 664
665 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(2);
666 ((TH1F*) fListOfHistos->FindObject("mixedDist"))->Fill(pool->NTracksInPool());
667 if (pool->IsReady())
668 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(3);
eed401dc 669
670 // Fill mixed-event histos here
c05ff6be 671 for (Int_t jMix=0; jMix<nMix; jMix++)
672 {
eed401dc 673 TObjArray* bgTracks = pool->GetEvent(jMix);
c5c840c5 674
675 if (fTwoTrackEfficiencyStudy)
676 {
677 Float_t bSign = (fESD->GetMagneticField() > 0) ? 1 : -1;
678 fHistos->TwoTrackEfficiency(tracks, bgTracks, bSign);
679 }
680
acc90d78 681 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, bgTracks, 1.0 / nMix, (jMix == 0));
eed401dc 682 }
e0331fd9 683 }
eed401dc 684
a1c31636 685 // create a list of reduced objects (to reduce memory consumption) and give ownership to event pool
7a028750 686 TObjArray* tracksClone = CloneAndReduceTrackList(tracks);
eed401dc 687 pool->UpdatePool(tracksClone);
688 //pool->PrintInfo();
e0331fd9 689 }
2a910c25 690
e0331fd9 691 delete tracks;
e0331fd9 692}
693
7a028750 694TObjArray* AliAnalysisTaskPhiCorrelations::CloneAndReduceTrackList(TObjArray* tracks)
695{
696 // clones a track list by using AliDPhiBasicParticle which uses much less memory (used for event mixing)
697
698 TObjArray* tracksClone = new TObjArray;
699 tracksClone->SetOwner(kTRUE);
700
701 for (Int_t i=0; i<tracks->GetEntries(); i++)
702 {
703 AliVParticle* particle = (AliVParticle*) tracks->At(i);
704 tracksClone->Add(new AliDPhiBasicParticle(particle->Eta(), particle->Phi(), particle->Pt(), particle->Charge()));
705 }
706
707 return tracksClone;
708}
709
e0331fd9 710//____________________________________________________________________
711void AliAnalysisTaskPhiCorrelations::Initialize()
712{
713 // input handler
714 fInputHandler = (AliInputEventHandler*)
715 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
716 // MC handler
717 fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
718}