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