]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGCF/Correlations/DPhi/AliAnalysisTaskPhiCorrelations.cxx
from Carlos Perez:
[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>
ebda4319 25#include <TH3F.h>
e0331fd9 26#include <TRandom.h>
27
28#include "AliAnalysisTaskPhiCorrelations.h"
29#include "AliAnalyseLeadingTrackUE.h"
30#include "AliUEHistograms.h"
31#include "AliUEHist.h"
32
e0331fd9 33#include "AliAnalysisManager.h"
34#include "AliAODHandler.h"
35#include "AliAODInputHandler.h"
36#include "AliAODMCParticle.h"
e0331fd9 37#include "AliInputEventHandler.h"
38#include "AliLog.h"
39#include "AliMCEventHandler.h"
40#include "AliVParticle.h"
2a910c25 41#include "AliCFContainer.h"
e0331fd9 42
43#include "AliESDEvent.h"
44#include "AliESDInputHandler.h"
45#include "AliMultiplicity.h"
2a910c25 46#include "AliCentrality.h"
47#include "AliStack.h"
7dd4dec4 48#include "AliAODMCHeader.h"
1ccd8a0a 49#include "AliGenCocktailEventHeader.h"
50#include "AliGenEventHeader.h"
e0331fd9 51
2a910c25 52#include "AliEventPoolManager.h"
e0331fd9 53
d728f490 54#include "AliESDZDC.h"
3bbad7c1 55#include "AliESDtrackCuts.h"
d728f490 56
32e49607 57#include "AliHelperPID.h"
6e84bd0a 58#include "AliAnalysisUtils.h"
e0331fd9 59
60////////////////////////////////////////////////////////////////////////
61//
62// Analysis class for azimuthal correlation studies
63// Based on the UE task from Sara Vallero and Jan Fiete
64//
65// This class needs input AODs.
66// The output is a list of analysis-specific containers.
67//
68// The AOD can be either connected to the InputEventHandler
69// for a chain of AOD files
70// or
71// to the OutputEventHandler
72// for a chain of ESD files,
73// in this case the class should be in the train after the jet-finder
74//
75// Authors:
76// Jan Fiete Grosse-Oetringhaus
77//
78////////////////////////////////////////////////////////////////////////
79
80
81ClassImp( AliAnalysisTaskPhiCorrelations )
a1c31636 82ClassImp( AliDPhiBasicParticle )
e0331fd9 83
84//____________________________________________________________________
85AliAnalysisTaskPhiCorrelations:: AliAnalysisTaskPhiCorrelations(const char* name):
86AliAnalysisTask(name,""),
87// general configuration
88fDebug(0),
89fMode(0),
90fReduceMemoryFootprint(kFALSE),
eed401dc 91fFillMixed(kTRUE),
ac647b0f 92fMixingTracks(50000),
1bba939a 93fTwoTrackEfficiencyStudy(kFALSE),
d4b3dbfc 94fTwoTrackEfficiencyCut(0),
44af28f9 95fUseVtxAxis(kFALSE),
9894bedd 96fCourseCentralityBinning(kFALSE),
04af8d15 97fSkipTrigger(kFALSE),
1ccd8a0a 98fInjectedSignals(kFALSE),
e0331fd9 99// pointers to UE classes
32e49607 100fHelperPID(0x0),
6e84bd0a 101fAnalysisUtils(0x0),
e0331fd9 102fAnalyseUE(0x0),
103fHistos(0x0),
104fHistosMixed(0),
418b56c5 105fEfficiencyCorrectionTriggers(0),
106fEfficiencyCorrectionAssociated(0),
e0331fd9 107// handlers and events
85bfac17 108fAOD(0x0),
109fESD(0x0),
e0331fd9 110fArrayMC(0x0),
111fInputHandler(0x0),
112fMcEvent(0x0),
113fMcHandler(0x0),
2a910c25 114fPoolMgr(0x0),
e0331fd9 115// histogram settings
116fListOfHistos(0x0),
117// event QA
118fnTracksVertex(1), // QA tracks pointing to principal vertex (= 3 default)
85bfac17 119fZVertex(7.),
2a910c25 120fCentralityMethod("V0M"),
e0331fd9 121// track cuts
122fTrackEtaCut(0.8),
97dc2b4e 123fTrackEtaCutMin(-1.),
9da2f080 124fOnlyOneEtaSide(0),
e0331fd9 125fPtMin(0.5),
97270ee2 126fDCAXYCut(0),
e0331fd9 127fFilterBit(0xFF),
418b56c5 128fTrackStatus(0),
5cabd2cd 129fSelectBit(AliVEvent::kMB|AliVEvent::kUserDefined),
2a910c25 130fUseChargeHadrons(kFALSE),
5c9b9fa6 131fParticleSpeciesTrigger(-1),
132fParticleSpeciesAssociated(-1),
9e35c487 133fCheckMotherPDG(kTRUE),
c05ff6be 134fSelectCharge(0),
7a77d480 135fTriggerSelectCharge(0),
15b0fdd0 136fAssociatedSelectCharge(0),
d38fa455 137fTriggerRestrictEta(-1),
00b6f3c6 138fEtaOrdering(kFALSE),
b0d56b29 139fCutConversions(kFALSE),
140fCutResonances(kFALSE),
97270ee2 141fRejectResonanceDaughters(-1),
a26093ba 142fFillOnlyStep0(kFALSE),
143fSkipStep6(kFALSE),
5e053cad 144fRejectCentralityOutliers(kFALSE),
ff9f18e4 145fRejectZeroTrackEvents(kFALSE),
f613255f 146fRemoveWeakDecays(kFALSE),
d6a8903f 147fRemoveDuplicates(kFALSE),
51d0a028 148fSkipFastCluster(kFALSE),
8a368fc2 149fWeightPerEvent(kFALSE),
3f3f12d9 150fCustomBinning(),
640b9425 151fPtOrder(kTRUE),
c05ff6be 152fFillpT(kFALSE)
e0331fd9 153{
154 // Default constructor
155 // Define input and output slots here
156 // Input slot #0 works with a TChain
157 DefineInput(0, TChain::Class());
158 // Output slot #0 writes into a TList container
159 DefineOutput(0, TList::Class());
e0331fd9 160}
161
162AliAnalysisTaskPhiCorrelations::~AliAnalysisTaskPhiCorrelations()
163{
164 // destructor
165
166 if (fListOfHistos && !AliAnalysisManager::GetAnalysisManager()->IsProofMode())
167 delete fListOfHistos;
168}
169
170//____________________________________________________________________
171void AliAnalysisTaskPhiCorrelations::ConnectInputData(Option_t* /*option*/)
172{
173
174 // Connect the input data
175 if (fDebug > 1) AliInfo("ConnectInputData() ");
176
177 // Since AODs can either be connected to the InputEventHandler
178 // or to the OutputEventHandler ( the AOD is created by a previus task in the train )
179 // we need to get the pointer to the AODEvent correctly.
180
181 // Delta AODs are also accepted.
182
183 TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
184
85bfac17 185 if( handler && handler->InheritsFrom("AliAODInputHandler") )
186 { // input AOD
187 fAOD = ((AliAODInputHandler*)handler)->GetEvent();
188 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODInputHandler");
189 }
190 else
191 { //output AOD
192 handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
193 if (handler && handler->InheritsFrom("AliAODHandler") )
194 {
195 fAOD = ((AliAODHandler*)handler)->GetAOD();
196 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODHandler");
197 }
198 else
199 { // no AOD
200 AliWarning("I can't get any AOD Event Handler");
201 }
202 }
203
204 if (handler && handler->InheritsFrom("AliESDInputHandler") )
205 { // input ESD
206 // pointer received per event in ::Exec
207 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliESDInputHandler");
208 }
e0331fd9 209
210 // Initialize common pointers
211 Initialize();
e0331fd9 212}
213
214//____________________________________________________________________
215void AliAnalysisTaskPhiCorrelations::CreateOutputObjects()
216{
217 // Create the output container
218
219 if (fDebug > 1) AliInfo("CreateOutputObjects()");
220
221 // Initialize class with main algorithms, event and track selection.
222 fAnalyseUE = new AliAnalyseLeadingTrackUE();
97dc2b4e 223 fAnalyseUE->SetParticleSelectionCriteria(fFilterBit, fUseChargeHadrons, fTrackEtaCut, fTrackEtaCutMin, fPtMin);
97270ee2 224 fAnalyseUE->SetDCAXYCut(fDCAXYCut);
418b56c5 225 fAnalyseUE->SetTrackStatus(fTrackStatus);
9e35c487 226 fAnalyseUE->SetCheckMotherPDG(fCheckMotherPDG);
e0331fd9 227 fAnalyseUE->SetDebug(fDebug);
85bfac17 228 fAnalyseUE->DefineESDCuts(fFilterBit);
5cabd2cd 229 fAnalyseUE->SetEventSelection(fSelectBit);
32e49607 230 fAnalyseUE->SetHelperPID(fHelperPID);
231 if ((fParticleSpeciesTrigger != -1 || fParticleSpeciesAssociated != -1) && !fHelperPID)
232 AliFatal("HelperPID object should be set in the steering macro");
e0331fd9 233
234 // Initialize output list of containers
235 if (fListOfHistos != NULL){
236 delete fListOfHistos;
237 fListOfHistos = NULL;
238 }
239 if (!fListOfHistos){
240 fListOfHistos = new TList();
241 fListOfHistos->SetOwner(kTRUE);
242 }
243
244 // Initialize class to handle histograms
9894bedd 245 TString histType = "4R";
3bbad7c1 246 if (fUseVtxAxis == 1)
b752706a 247 histType = "5R";
3bbad7c1 248 else if (fUseVtxAxis == 2)
249 histType = "6R";
9894bedd 250 if (fCourseCentralityBinning)
251 histType += "C";
3f3f12d9 252 fHistos = new AliUEHistograms("AliUEHistogramsSame", histType, fCustomBinning);
253 fHistosMixed = new AliUEHistograms("AliUEHistogramsMixed", histType, fCustomBinning);
e0331fd9 254
2a910c25 255 fHistos->SetSelectCharge(fSelectCharge);
256 fHistosMixed->SetSelectCharge(fSelectCharge);
257
afe13b94 258 fHistos->SetSelectTriggerCharge(fTriggerSelectCharge);
259 fHistosMixed->SetSelectTriggerCharge(fTriggerSelectCharge);
15b0fdd0 260
261 fHistos->SetSelectAssociatedCharge(fAssociatedSelectCharge);
262 fHistosMixed->SetSelectAssociatedCharge(fAssociatedSelectCharge);
7a77d480 263
d38fa455 264 fHistos->SetTriggerRestrictEta(fTriggerRestrictEta);
265 fHistosMixed->SetTriggerRestrictEta(fTriggerRestrictEta);
266
9da2f080 267 fHistos->SetOnlyOneEtaSide(fOnlyOneEtaSide);
268 fHistosMixed->SetOnlyOneEtaSide(fOnlyOneEtaSide);
269
00b6f3c6 270 fHistos->SetEtaOrdering(fEtaOrdering);
271 fHistosMixed->SetEtaOrdering(fEtaOrdering);
272
b0d56b29 273 fHistos->SetPairCuts(fCutConversions, fCutResonances);
274 fHistosMixed->SetPairCuts(fCutConversions, fCutResonances);
275
97270ee2 276 fHistos->SetRejectResonanceDaughters(fRejectResonanceDaughters);
277 fHistosMixed->SetRejectResonanceDaughters(fRejectResonanceDaughters);
278
defad170 279 fHistos->SetTrackEtaCut(fTrackEtaCut);
280 fHistosMixed->SetTrackEtaCut(fTrackEtaCut);
281
8a368fc2 282 fHistos->SetWeightPerEvent(fWeightPerEvent);
283 fHistosMixed->SetWeightPerEvent(fWeightPerEvent);
418b56c5 284
640b9425 285 fHistos->SetPtOrder(fPtOrder);
286 fHistosMixed->SetPtOrder(fPtOrder);
287
418b56c5 288 if (fEfficiencyCorrectionTriggers)
289 {
290 fHistos->SetEfficiencyCorrectionTriggers(fEfficiencyCorrectionTriggers);
291 fHistosMixed->SetEfficiencyCorrectionTriggers((THnF*) fEfficiencyCorrectionTriggers->Clone());
292 }
293 if (fEfficiencyCorrectionAssociated)
408d1ac9 294 {
418b56c5 295 fHistos->SetEfficiencyCorrectionAssociated(fEfficiencyCorrectionAssociated);
296 fHistosMixed->SetEfficiencyCorrectionAssociated((THnF*) fEfficiencyCorrectionAssociated->Clone());
408d1ac9 297 }
13a404ed 298
e0331fd9 299 // add histograms to list
300 fListOfHistos->Add(fHistos);
301 fListOfHistos->Add(fHistosMixed);
32e49607 302 // add HelperPID to list
303 if (fHelperPID)
304 fListOfHistos->Add(fHelperPID);
e0331fd9 305
2a910c25 306 fListOfHistos->Add(new TH2F("trackletsVsV0Cent", ";L1 clusters;v0 centrality", 100, -0.5, 9999.5, 101, 0, 101));
307 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 308 fListOfHistos->Add(new TH1F("eventStat", ";;events", 4, -0.5, 3.5));
5614e02f 309 fListOfHistos->Add(new TH2F("mixedDist", ";centrality;tracks;events", 101, 0, 101, 200, 0, fMixingTracks * 1.5));
b0d56b29 310 fListOfHistos->Add(new TH1F("pids", ";pdg;tracks", 2001, -1000.5, 1000.5));
f0a25b1d 311 fListOfHistos->Add(new TH2F("referenceMultiplicity", ";centrality;tracks;events", 101, 0, 101, 200, 0, 200));
e0331fd9 312
1a32ecc0 313 PostData(0,fListOfHistos);
314
e0331fd9 315 // Add task configuration to output list
316 AddSettingsTree();
317
2a910c25 318 // event mixing
3f3f12d9 319 Int_t poolsize = 1000; // Maximum number of events, ignored in the present implemention of AliEventPoolManager
c066889a 320
2a910c25 321 Int_t nCentralityBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(1);
322 Double_t* centralityBins = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(1, 0)->GetXbins()->GetArray();
323
5f54dac4 324 const Int_t kNZvtxBins = 10+(1+10)*4;
408d1ac9 325 // bins for further buffers are shifted by 100 cm
5f54dac4 326 Double_t vertexBins[kNZvtxBins+1] = { -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10,
327 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110,
328 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210,
329 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310,
330 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410 };
331
332 Int_t nZvtxBins = kNZvtxBins;
eb88bdfe 333 Double_t* zvtxbin = vertexBins;
c066889a 334
408d1ac9 335 if (fMode == 0 && fHistos->GetUEHist(2)->GetEventHist()->GetNVar() > 2)
eb88bdfe 336 {
337 nZvtxBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(2);
338 zvtxbin = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(2, 0)->GetXbins()->GetArray();
339 }
85bfac17 340
3f3f12d9 341 fPoolMgr = new AliEventPoolManager(poolsize, fMixingTracks, nCentralityBins, centralityBins, nZvtxBins, zvtxbin);
f0df9076 342 fPoolMgr->SetTargetValues(fMixingTracks, 0.1, 5);
e0331fd9 343}
344
345//____________________________________________________________________
346void AliAnalysisTaskPhiCorrelations::Exec(Option_t */*option*/)
347{
416af868 348 // exec (per event)
349 fAnalyseUE->NextEvent();
350
85bfac17 351 // receive ESD pointer if we are not running AOD analysis
352 if (!fAOD)
353 {
354 AliVEventHandler* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
355 if (handler && handler->InheritsFrom("AliESDInputHandler"))
356 fESD = ((AliESDInputHandler*)handler)->GetEvent();
357 }
358
7dd4dec4 359 if (fMode)
360 {
361 // correction mode
362
363 if (fMcHandler)
364 fMcEvent = fMcHandler->MCEvent();
365
366 if (fAOD)
367 {
368 // array of MC particles
369 fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
370 if (!fArrayMC)
371 AliFatal("No array of MC particles found !!!");
372 }
373
374 AnalyseCorrectionMode();
375 }
e0331fd9 376 else AnalyseDataMode();
e0331fd9 377}
378
379/******************** ANALYSIS METHODS *****************************/
380
381//____________________________________________________________________
382void AliAnalysisTaskPhiCorrelations::AddSettingsTree()
383{
384 //Write settings to output list
385 TTree *settingsTree = new TTree("UEAnalysisSettings","Analysis Settings in UE estimation");
c05ff6be 386 settingsTree->Branch("fnTracksVertex", &fnTracksVertex,"nTracksVertex/I");
387 settingsTree->Branch("fZVertex", &fZVertex,"ZVertex/D");
388 //settingsTree->Branch("fCentralityMethod", fCentralityMethod.Data(),"CentralityMethod/C");
e0331fd9 389 settingsTree->Branch("fTrackEtaCut", &fTrackEtaCut, "TrackEtaCut/D");
97dc2b4e 390 settingsTree->Branch("fTrackEtaCutMin", &fTrackEtaCutMin, "TrackEtaCutMin/D");
9da2f080 391 settingsTree->Branch("fOnlyOneEtaSide", &fOnlyOneEtaSide,"OnlyOneEtaSide/I");
e0331fd9 392 settingsTree->Branch("fPtMin", &fPtMin, "PtMin/D");
c05ff6be 393 settingsTree->Branch("fFilterBit", &fFilterBit,"FilterBit/I");
418b56c5 394 settingsTree->Branch("fTrackStatus", &fTrackStatus,"TrackStatus/I");
c05ff6be 395 settingsTree->Branch("fSelectBit", &fSelectBit,"EventSelectionBit/I");
e0331fd9 396 settingsTree->Branch("fUseChargeHadrons", &fUseChargeHadrons,"UseChHadrons/O");
5c9b9fa6 397 settingsTree->Branch("fParticleSpeciesTrigger", &fParticleSpeciesTrigger,"ParticleSpeciesTrigger/I");
398 settingsTree->Branch("fParticleSpeciesAssociated", &fParticleSpeciesAssociated,"ParticleSpeciesAssociated/I");
9e35c487 399 settingsTree->Branch("fCheckMotherPDG", &fCheckMotherPDG,"CheckMotherPDG/I");
c05ff6be 400 settingsTree->Branch("fSelectCharge", &fSelectCharge,"SelectCharge/I");
7a77d480 401 settingsTree->Branch("fTriggerSelectCharge", &fTriggerSelectCharge,"TriggerSelectCharge/I");
15b0fdd0 402 settingsTree->Branch("fAssociatedSelectCharge", &fAssociatedSelectCharge,"fAssociatedSelectCharge/I");
b0d56b29 403 settingsTree->Branch("fTriggerRestrictEta", &fTriggerRestrictEta,"TriggerRestrictEta/D");
00b6f3c6 404 settingsTree->Branch("fEtaOrdering", &fEtaOrdering,"EtaOrdering/O");
b0d56b29 405 settingsTree->Branch("fCutConversions", &fCutConversions,"CutConversions/O");
406 settingsTree->Branch("fCutResonances", &fCutResonances,"CutResonances/O");
97270ee2 407 settingsTree->Branch("fRejectResonanceDaughters", &fRejectResonanceDaughters,"RejectResonanceDaughters/I");
c05ff6be 408 settingsTree->Branch("fFillpT", &fFillpT,"FillpT/O");
ac647b0f 409 settingsTree->Branch("fMixingTracks", &fMixingTracks,"MixingTracks/I");
04af8d15 410 settingsTree->Branch("fSkipTrigger", &fSkipTrigger,"SkipTrigger/O");
1ccd8a0a 411 settingsTree->Branch("fInjectedSignals", &fInjectedSignals,"SkipTrigger/O");
5e053cad 412 settingsTree->Branch("fRejectCentralityOutliers", &fRejectCentralityOutliers,"RejectCentralityOutliers/O");
ff9f18e4 413 settingsTree->Branch("fRejectZeroTrackEvents", &fRejectZeroTrackEvents,"RejectZeroTrackEvents/O");
f613255f 414 settingsTree->Branch("fRemoveWeakDecays", &fRemoveWeakDecays,"RemoveWeakDecays/O");
d6a8903f 415 settingsTree->Branch("fRemoveDuplicates", &fRemoveDuplicates,"RemoveDuplicates/O");
51d0a028 416 settingsTree->Branch("fSkipFastCluster", &fSkipFastCluster,"SkipFastCluster/O");
8a368fc2 417 settingsTree->Branch("fWeightPerEvent", &fWeightPerEvent,"WeightPerEvent/O");
640b9425 418 settingsTree->Branch("fPtOrder", &fPtOrder,"PtOrder/O");
3f3f12d9 419 //fCustomBinning
04af8d15 420
e0331fd9 421 settingsTree->Fill();
422 fListOfHistos->Add(settingsTree);
423}
424
425//____________________________________________________________________
426void AliAnalysisTaskPhiCorrelations::AnalyseCorrectionMode()
427{
428 // Run the analysis on MC to get the correction maps
429 //
430
2a910c25 431 if ( fDebug > 3 ) AliInfo( " Processing event in Corrections mode ..." );
432
433 Double_t centrality = 0;
434
435 if (fCentralityMethod.Length() > 0)
436 {
85bfac17 437 AliCentrality *centralityObj = 0;
438 if (fAOD)
439 centralityObj = fAOD->GetHeader()->GetCentralityP();
440 else if (fESD)
441 centralityObj = fESD->GetCentrality();
442
2a910c25 443 if (centralityObj)
444 {
445 centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
a8583211 446 AliInfo(Form("Centrality is %f", centrality));
2a910c25 447 }
448 else
449 {
450 Printf("WARNING: Centrality object is 0");
451 centrality = -1;
452 }
453 }
454
85bfac17 455 // Support for ESD and AOD based analysis
456 AliVEvent* inputEvent = fAOD;
457 if (!inputEvent)
458 inputEvent = fESD;
d4b3dbfc 459
932155c7 460 Float_t bSign = 0;
461
d4b3dbfc 462 if (inputEvent)
932155c7 463 {
d4b3dbfc 464 fHistos->SetRunNumber(inputEvent->GetRunNumber());
932155c7 465 bSign = (inputEvent->GetMagneticField() > 0) ? 1 : -1;
466 }
467
85bfac17 468 TObject* mc = fArrayMC;
469 if (!mc)
470 mc = fMcEvent;
471
2a910c25 472 // count all events
473 fHistos->FillEvent(centrality, -1);
474
72b62cb8 475 if (centrality < 0)
476 return;
477
2a910c25 478 // Only consider MC events within the vtx-z region used also as cut on the reconstructed vertex
7dd4dec4 479 TObject* vertexSupplier = fMcEvent;
480 if (fAOD) // AOD
481 vertexSupplier = fAOD->FindListObject(AliAODMCHeader::StdBranchName());
482
483 if (!fAnalyseUE->VertexSelection(vertexSupplier, 0, fZVertex))
2a910c25 484 return;
85bfac17 485
7dd4dec4 486 Float_t zVtx = 0;
487 if (fAOD)
488 zVtx = ((AliAODMCHeader*) vertexSupplier)->GetVtxZ();
489 else
490 zVtx = fMcEvent->GetPrimaryVertex()->GetZ();
c05ff6be 491 Float_t weight = 1;
492 if (fFillpT)
493 weight = -1;
1ccd8a0a 494
495 // For productions with injected signals, figure out above which label to skip particles/tracks
496 Int_t skipParticlesAbove = 0;
497 if (fInjectedSignals)
498 {
499 AliGenEventHeader* eventHeader = 0;
500 Int_t headers = 0;
501
502 if (fMcEvent)
503 {
504 // ESD
505 AliHeader* header = (AliHeader*) fMcEvent->Header();
506 if (!header)
507 AliFatal("fInjectedSignals set but no MC header found");
508
509 AliGenCocktailEventHeader* cocktailHeader = dynamic_cast<AliGenCocktailEventHeader*> (header->GenEventHeader());
510 if (!cocktailHeader)
511 {
512 header->Dump();
513 AliFatal("fInjectedSignals set but no MC cocktail header found");
514 }
515
516 headers = cocktailHeader->GetHeaders()->GetEntries();
517 eventHeader = dynamic_cast<AliGenEventHeader*> (cocktailHeader->GetHeaders()->First());
518 }
519 else
520 {
521 // AOD
522 AliAODMCHeader* header = (AliAODMCHeader*) fAOD->GetList()->FindObject(AliAODMCHeader::StdBranchName());
523 if (!header)
524 AliFatal("fInjectedSignals set but no MC header found");
525
526 headers = header->GetNCocktailHeaders();
527 eventHeader = header->GetCocktailHeader(0);
528 }
2a910c25 529
1ccd8a0a 530 if (!eventHeader)
46848f0b 531 {
532 // We avoid AliFatal here, because the AOD productions sometimes have events where the MC header is missing
533 // (due to unreadable Kinematics) and we don't want to loose the whole job because of a few events
534 AliError("First event header not found. Skipping this event.");
535 fHistos->FillEvent(centrality, AliUEHist::kCFStepAnaTopology);
536 return;
537 }
1ccd8a0a 538
539 skipParticlesAbove = eventHeader->NProduced();
540 AliInfo(Form("Injected signals in this event (%d headers). Keeping events of %s. Will skip particles/tracks above %d.", headers, eventHeader->ClassName(), skipParticlesAbove));
541 }
542
2a910c25 543 // Get MC primaries
3f3f12d9 544 // triggers
5c9b9fa6 545 TObjArray* tmpList = fAnalyseUE->GetAcceptedParticles(mc, 0, kTRUE, fParticleSpeciesTrigger, kTRUE);
3f3f12d9 546 CleanUp(tmpList, mc, skipParticlesAbove);
762206c7 547 TObjArray* tracksMC = CloneAndReduceTrackList(tmpList);
548 delete tmpList;
2a910c25 549
3f3f12d9 550 // associated
551 TObjArray* tracksCorrelateMC = tracksMC;
5c9b9fa6 552 if (fParticleSpeciesAssociated != fParticleSpeciesTrigger)
3f3f12d9 553 {
b54ab0b1 554 tmpList = fAnalyseUE->GetAcceptedParticles(mc, 0, kTRUE, fParticleSpeciesAssociated, kTRUE);
555 CleanUp(tmpList, mc, skipParticlesAbove);
556 tracksCorrelateMC = CloneAndReduceTrackList(tmpList);
557 delete tmpList;
3f3f12d9 558 }
559
1ccd8a0a 560 /*
b0d56b29 561 if (fAOD)
562 {
563 for (Int_t i=0; i<fArrayMC->GetEntriesFast(); i++)
564 ((TH1F*) fListOfHistos->FindObject("pids"))->Fill(((AliAODMCParticle*) fArrayMC->At(i))->PdgCode());
565 }
566 else
567 {
568 for (Int_t i=0; i<fMcEvent->GetNumberOfTracks(); i++)
569 ((TH1F*) fListOfHistos->FindObject("pids"))->Fill(fMcEvent->GetTrack(i)->PdgCode());
570 }
1ccd8a0a 571 */
b0d56b29 572
9375b5e2 573 if (fFillOnlyStep0)
574 zVtx = 0;
575
2a910c25 576 // (MC-true all particles)
577 // STEP 0
3f3f12d9 578 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepAll, tracksMC, tracksCorrelateMC, weight);
2a910c25 579
7a028750 580 // mixed event
8781a433 581 if (fFillMixed)
582 {
583 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx);
f0df9076 584 if (pool->IsReady())
8781a433 585 for (Int_t jMix=0; jMix<pool->GetCurrentNEvents(); jMix++)
586 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepAll, tracksMC, pool->GetEvent(jMix), 1.0 / pool->GetCurrentNEvents(), (jMix == 0));
3f3f12d9 587 pool->UpdatePool(CloneAndReduceTrackList(tracksCorrelateMC));
8781a433 588 }
7a028750 589
04af8d15 590// Printf("trigger: %d", ((AliInputEventHandler*)fInputHandler)->IsEventSelected());
591
2a910c25 592 // Trigger selection ************************************************
a26093ba 593 if (!fFillOnlyStep0 && (fSkipTrigger || fAnalyseUE->TriggerSelection(fInputHandler)))
2a910c25 594 {
c32a0ca9 595 // (MC-true all particles)
596 // STEP 1
597 if (!fReduceMemoryFootprint)
3f3f12d9 598 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTriggered, tracksMC, tracksCorrelateMC, weight);
c32a0ca9 599 else
600 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
601
872dc651 602 if (!inputEvent) {
c32a0ca9 603 AliFatal("UNEXPECTED: inputEvent is 0. Trigger selection should have failed");
872dc651 604 return;
605 }
2a910c25 606
607 // Vertex selection *************************************************
85bfac17 608 if (fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex))
2a910c25 609 {
610 // fill here for tracking efficiency
611 // loop over particle species
612
613 for (Int_t particleSpecies = 0; particleSpecies < 4; particleSpecies++)
614 {
85bfac17 615 TObjArray* primMCParticles = fAnalyseUE->GetAcceptedParticles(mc, 0x0, kTRUE, particleSpecies, kTRUE);
59375a30 616 TObjArray* primRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, particleSpecies, kTRUE, kFALSE);
617 TObjArray* allRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, particleSpecies, kTRUE, kFALSE);
618 TObjArray* primRecoTracksMatchedPID = 0;
619 TObjArray* allRecoTracksMatchedPID = 0;
620
621 if (fHelperPID)
622 {
623 primRecoTracksMatchedPID = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, particleSpecies, kTRUE, kTRUE);
624 allRecoTracksMatchedPID = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, particleSpecies, kTRUE, kTRUE);
625 }
1ccd8a0a 626
3f3f12d9 627 CleanUp(primMCParticles, mc, skipParticlesAbove);
628 CleanUp(primRecoTracksMatched, mc, skipParticlesAbove);
629 CleanUp(allRecoTracksMatched, mc, skipParticlesAbove);
59375a30 630 CleanUp(primRecoTracksMatchedPID, mc, skipParticlesAbove);
631 CleanUp(allRecoTracksMatchedPID, mc, skipParticlesAbove);
29cfdb5f 632
633 // select charges
634 if (fTriggerSelectCharge != 0)
635 {
636 SelectCharge(primMCParticles);
637 SelectCharge(primRecoTracksMatched);
638 SelectCharge(allRecoTracksMatched);
59375a30 639 SelectCharge(primRecoTracksMatchedPID);
640 SelectCharge(allRecoTracksMatchedPID);
29cfdb5f 641 }
2a910c25 642
59375a30 643 fHistos->FillTrackingEfficiency(primMCParticles, primRecoTracksMatched, allRecoTracksMatched, primRecoTracksMatchedPID, allRecoTracksMatchedPID, 0, particleSpecies, centrality, zVtx);
2a910c25 644
eed401dc 645// Printf("%d --> %d %d %d", particleSpecies, primMCParticles->GetEntries(), primRecoTracksMatched->GetEntries(), allRecoTracksMatched->GetEntries());
646
647 delete primMCParticles;
2a910c25 648 delete primRecoTracksMatched;
649 delete allRecoTracksMatched;
650 }
3f3f12d9 651
b591fb9c 652 TObjArray* fakeParticles = fAnalyseUE->GetFakeParticles(inputEvent, mc, kFALSE, -1, kTRUE);
3f3f12d9 653 CleanUp((TObjArray*) fakeParticles->At(0), mc, skipParticlesAbove);
654 CleanUp((TObjArray*) fakeParticles->At(1), mc, skipParticlesAbove);
655
59375a30 656 fHistos->FillTrackingEfficiency(0, 0, 0, 0, 0, (TObjArray*) fakeParticles->At(2), 0, centrality, zVtx);
b591fb9c 657 fHistos->FillFakePt(fakeParticles, centrality);
d728f490 658// Printf(">>>>> %d %d %d fakes", ((TObjArray*) fakeParticles->At(0))->GetEntriesFast(), ((TObjArray*) fakeParticles->At(1))->GetEntriesFast(), ((TObjArray*) fakeParticles->At(2))->GetEntriesFast());
b591fb9c 659 delete fakeParticles;
2a910c25 660
661 // (MC-true all particles)
662 // STEP 2
85bfac17 663 if (!fReduceMemoryFootprint)
3f3f12d9 664 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepVertex, tracksMC, tracksCorrelateMC, weight);
c32a0ca9 665 else
666 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
2a910c25 667
668 // Get MC primaries that match reconstructed track
3f3f12d9 669 // triggers
b54ab0b1 670 tmpList = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, fParticleSpeciesTrigger, kTRUE);
671 CleanUp(tmpList, mc, skipParticlesAbove);
672 TObjArray* tracksRecoMatchedPrim = CloneAndReduceTrackList(tmpList);
673 delete tmpList;
674
3f3f12d9 675 // associated
676 TObjArray* tracksCorrelateRecoMatchedPrim = tracksRecoMatchedPrim;
5c9b9fa6 677 if (fParticleSpeciesAssociated != fParticleSpeciesTrigger)
3f3f12d9 678 {
b54ab0b1 679 tmpList = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, fParticleSpeciesAssociated, kTRUE);
680 CleanUp(tmpList, mc, skipParticlesAbove);
681 tracksCorrelateRecoMatchedPrim = CloneAndReduceTrackList(tmpList);
682 delete tmpList;
3f3f12d9 683 }
684
2a910c25 685 // (RECO-matched (quantities from MC particle) primary particles)
686 // STEP 4
3f3f12d9 687 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTrackedOnlyPrim, tracksRecoMatchedPrim, tracksCorrelateRecoMatchedPrim, weight);
408d1ac9 688
689 // mixed event
690 if (fFillMixed)
691 {
692 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx + 200);
f0df9076 693 if (pool->IsReady())
408d1ac9 694 for (Int_t jMix=0; jMix<pool->GetCurrentNEvents(); jMix++)
695 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTrackedOnlyPrim, tracksRecoMatchedPrim, pool->GetEvent(jMix), 1.0 / pool->GetCurrentNEvents(), (jMix == 0));
3f3f12d9 696 pool->UpdatePool(CloneAndReduceTrackList(tracksCorrelateRecoMatchedPrim));
408d1ac9 697 }
2a910c25 698
699 // Get MC primaries + secondaries that match reconstructed track
3f3f12d9 700 // triggers
b54ab0b1 701 tmpList = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, fParticleSpeciesTrigger, kTRUE);
702 CleanUp(tmpList, mc, skipParticlesAbove);
703 TObjArray* tracksRecoMatchedAll = CloneAndReduceTrackList(tmpList);
704 delete tmpList;
705
3f3f12d9 706 // associated
707 TObjArray* tracksCorrelateRecoMatchedAll = tracksRecoMatchedAll;
5c9b9fa6 708 if (fParticleSpeciesAssociated != fParticleSpeciesTrigger)
3f3f12d9 709 {
b54ab0b1 710 tmpList = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, fParticleSpeciesAssociated, kTRUE);
711 CleanUp(tmpList, mc, skipParticlesAbove);
712 tracksCorrelateRecoMatchedAll = CloneAndReduceTrackList(tmpList);
713 delete tmpList;
3f3f12d9 714 }
715
2a910c25 716 // (RECO-matched (quantities from MC particle) all particles)
717 // STEP 5
3f3f12d9 718 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTracked, tracksRecoMatchedAll, tracksCorrelateRecoMatchedAll, weight);
2a910c25 719
408d1ac9 720 // mixed event
721 if (fFillMixed)
722 {
723 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx + 300);
f0df9076 724 if (pool->IsReady())
408d1ac9 725 for (Int_t jMix=0; jMix<pool->GetCurrentNEvents(); jMix++)
726 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTracked, tracksRecoMatchedAll, pool->GetEvent(jMix), 1.0 / pool->GetCurrentNEvents(), (jMix == 0));
3f3f12d9 727 pool->UpdatePool(CloneAndReduceTrackList(tracksCorrelateRecoMatchedAll));
408d1ac9 728 }
729
2a910c25 730 // Get RECO tracks
3f3f12d9 731 // triggers
b54ab0b1 732 tmpList = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, fParticleSpeciesTrigger, kTRUE);
733 CleanUp(tmpList, mc, skipParticlesAbove);
734 TObjArray* tracks = CloneAndReduceTrackList(tmpList);
735 delete tmpList;
736
3f3f12d9 737 // associated
738 TObjArray* tracksCorrelate = tracks;
5c9b9fa6 739 if (fParticleSpeciesAssociated != fParticleSpeciesTrigger)
3f3f12d9 740 {
b54ab0b1 741 tmpList = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, fParticleSpeciesAssociated, kTRUE);
742 CleanUp(tmpList, mc, skipParticlesAbove);
743 tracksCorrelate = CloneAndReduceTrackList(tmpList);
744 delete tmpList;
3f3f12d9 745 }
1ccd8a0a 746
2a910c25 747 // (RECO all tracks)
748 // STEP 6
a26093ba 749 if (!fSkipStep6)
3f3f12d9 750 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, tracksCorrelate, weight);
2a910c25 751
932155c7 752 // two track cut, STEP 8
753 if (fTwoTrackEfficiencyCut > 0)
3f3f12d9 754 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracks, tracksCorrelate, weight, kTRUE, kTRUE, bSign, fTwoTrackEfficiencyCut);
932155c7 755
408d1ac9 756 // apply correction efficiency, STEP 10
418b56c5 757 if (fEfficiencyCorrectionTriggers || fEfficiencyCorrectionAssociated)
408d1ac9 758 {
418b56c5 759 // with or without two track efficiency depending on if fTwoTrackEfficiencyCut is set
408d1ac9 760 Bool_t twoTrackCut = (fTwoTrackEfficiencyCut > 0);
761
3f3f12d9 762 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepCorrected, tracks, tracksCorrelate, weight, kTRUE, twoTrackCut, bSign, fTwoTrackEfficiencyCut, kTRUE);
408d1ac9 763 }
418b56c5 764
7a028750 765 // mixed event
408d1ac9 766 if (fFillMixed)
8781a433 767 {
768 AliEventPool* pool2 = fPoolMgr->GetEventPool(centrality, zVtx + 100);
f0df9076 769 if (pool2->IsReady())
408d1ac9 770 {
932155c7 771 for (Int_t jMix=0; jMix<pool2->GetCurrentNEvents(); jMix++)
772 {
773 // STEP 6
408d1ac9 774 if (!fSkipStep6)
775 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, pool2->GetEvent(jMix), 1.0 / pool2->GetCurrentNEvents(), (jMix == 0));
932155c7 776
777 // two track cut, STEP 8
778 if (fTwoTrackEfficiencyCut > 0)
779 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracks, pool2->GetEvent(jMix), 1.0 / pool2->GetCurrentNEvents(), (jMix == 0), kTRUE, bSign, fTwoTrackEfficiencyCut);
408d1ac9 780
781 // apply correction efficiency, STEP 10
418b56c5 782 if (fEfficiencyCorrectionTriggers || fEfficiencyCorrectionAssociated)
408d1ac9 783 {
784 // with or without two track efficiency depending on if fTwoTrackEfficiencyCut is set
785 Bool_t twoTrackCut = (fTwoTrackEfficiencyCut > 0);
786
787 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepCorrected, tracks, pool2->GetEvent(jMix), 1.0 / pool2->GetCurrentNEvents(), (jMix == 0), twoTrackCut, bSign, fTwoTrackEfficiencyCut, kTRUE);
788 }
932155c7 789 }
408d1ac9 790 }
3f3f12d9 791 pool2->UpdatePool(CloneAndReduceTrackList(tracksCorrelate));
8781a433 792 }
408d1ac9 793
85bfac17 794 if (0 && !fReduceMemoryFootprint)
2a910c25 795 {
796 // make list of secondaries (matched with MC)
797 TObjArray* tracksRecoMatchedSecondaries = new TObjArray;
b0d56b29 798 for (Int_t i=0; i<tracksRecoMatchedAll->GetEntriesFast(); i++)
2a910c25 799 if (((AliAODMCParticle*)tracksRecoMatchedAll->At(i))->IsPhysicalPrimary() == kFALSE)
800 tracksRecoMatchedSecondaries->Add(tracksRecoMatchedAll->At(i));
801
802 // Study: Use only secondaries as trigger particles and plot the correlation vs. all particles; store in step 9
c05ff6be 803 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy2, tracksRecoMatchedSecondaries, tracksRecoMatchedAll, weight);
2a910c25 804
805 // Study: Use only primaries as trigger particles and plot the correlation vs. secondaries; store in step 8
c05ff6be 806 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracksRecoMatchedPrim, tracksRecoMatchedSecondaries, weight);
2a910c25 807
808 // plot delta phi vs process id of secondaries
809 // trigger particles: primaries in 4 < pT < 10
810 // associated particles: secondaries in 1 < pT < 10
811
b0d56b29 812 for (Int_t i=0; i<tracksRecoMatchedPrim->GetEntriesFast(); i++)
2a910c25 813 {
814 AliVParticle* triggerParticle = (AliVParticle*) tracksRecoMatchedPrim->At(i);
815
816 if (triggerParticle->Pt() < 4 || triggerParticle->Pt() > 10)
817 continue;
818
b0d56b29 819 for (Int_t j=0; j<tracksRecoMatchedSecondaries->GetEntriesFast(); j++)
2a910c25 820 {
821 AliAODMCParticle* particle = (AliAODMCParticle*) tracksRecoMatchedSecondaries->At(j);
822
823 if (particle->Pt() < 1 || particle->Pt() > 10)
824 continue;
825
826 if (particle->Pt() > triggerParticle->Pt())
827 continue;
828
829 Double_t deltaPhi = triggerParticle->Phi() - particle->Phi();
830 if (deltaPhi > 1.5 * TMath::Pi())
831 deltaPhi -= TMath::TwoPi();
832 if (deltaPhi < -0.5 * TMath::Pi())
833 deltaPhi += TMath::TwoPi();
834
835 Int_t processID = fMcEvent->Stack()->Particle(particle->GetLabel())->GetUniqueID();
836
837 ((TH2F*) fListOfHistos->FindObject("processIDs"))->Fill(deltaPhi, processID);
838 }
839 }
840
841 delete tracksRecoMatchedSecondaries;
842 }
843
3f3f12d9 844 if (tracksCorrelateRecoMatchedPrim != tracksRecoMatchedPrim)
845 delete tracksCorrelateRecoMatchedPrim;
2a910c25 846 delete tracksRecoMatchedPrim;
3f3f12d9 847
848 if (tracksCorrelateRecoMatchedAll != tracksRecoMatchedAll)
849 delete tracksCorrelateRecoMatchedAll;
2a910c25 850 delete tracksRecoMatchedAll;
3f3f12d9 851
852 if (tracksCorrelate != tracks)
853 delete tracksCorrelate;
2a910c25 854 delete tracks;
855 }
856 }
857
3f3f12d9 858 if (tracksMC != tracksCorrelateMC)
859 delete tracksCorrelateMC;
2a910c25 860 delete tracksMC;
e0331fd9 861}
862
863//____________________________________________________________________
864void AliAnalysisTaskPhiCorrelations::AnalyseDataMode()
865{
866
867 // Run the analysis on DATA or MC to get raw distributions
868
e0331fd9 869 if ( fDebug > 3 ) AliInfo( " Processing event in Data mode ..." );
e0331fd9 870
c066889a 871 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(0);
872
2a910c25 873 if (!fInputHandler)
874 return;
875
5e053cad 876 // skip not selected events here (the AOD is not updated for those)
d728f490 877 if (!fSkipTrigger && !(fInputHandler->IsEventSelected() & fSelectBit))
2a910c25 878 return;
51d0a028 879
880 // skip fast cluster events here if requested
8a368fc2 881 if (fSkipFastCluster && (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly))
51d0a028 882 return;
6e84bd0a 883
72b62cb8 884 // Support for ESD and AOD based analysis
885 AliVEvent* inputEvent = fAOD;
886 if (!inputEvent)
887 inputEvent = fESD;
888
2a910c25 889 Double_t centrality = 0;
890
c3294f09 891 AliCentrality *centralityObj = 0;
2a910c25 892 if (fCentralityMethod.Length() > 0)
893 {
d728f490 894 if (fCentralityMethod == "ZNA_MANUAL")
895 {
9894bedd 896 Bool_t zna = kFALSE;
897 for(Int_t j = 0; j < 4; ++j) {
898 if (fESD->GetZDCData()->GetZDCTDCData(12,j) != 0) {
899 zna = kTRUE;
900 }
901 }
902
903// Printf("%d %f", zna, fZNAtower[0]);
904 if (zna)
905 {
906 // code from Chiara O (23.10.12)
907 const Double_t *fZNAtower = fESD->GetZDCData()->GetZN2TowerEnergy();
72b62cb8 908 Float_t znacut[4] = {681., 563., 413., 191.};
909
9894bedd 910 if(fZNAtower[0]>znacut[0]) centrality = 1;
72b62cb8 911 else if(fZNAtower[0]>znacut[1]) centrality = 21;
912 else if(fZNAtower[0]>znacut[2]) centrality = 41;
913 else if(fZNAtower[0]>znacut[3]) centrality = 61;
914 else centrality = 81;
9894bedd 915 }
916 else
917 centrality = -1;
d728f490 918 }
72b62cb8 919 else if (fCentralityMethod == "TRACKS_MANUAL")
920 {
921 // for pp
922 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, -1, kTRUE);
923 centrality = tracks->GetEntriesFast();
924 if (centrality > 40)
925 centrality = 41;
926// Printf("%d %f", tracks->GetEntriesFast(), centrality);
927 delete tracks;
928 }
2a910c25 929 else
a6d82f4e 930 {
d728f490 931 if (fAOD)
932 centralityObj = fAOD->GetHeader()->GetCentralityP();
933 else if (fESD)
934 centralityObj = fESD->GetCentrality();
935
936 if (centralityObj)
937 centrality = centralityObj->GetCentralityPercentile(fCentralityMethod);
938 //centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
939 else
940 centrality = -1;
941
942 if (fAOD)
a6d82f4e 943 {
d728f490 944 // remove outliers
945 if (centrality == 0)
a6d82f4e 946 {
d728f490 947 if (fAOD->GetVZEROData())
a6d82f4e 948 {
d728f490 949 Float_t multV0 = 0;
950 for (Int_t i=0; i<64; i++)
951 multV0 += fAOD->GetVZEROData()->GetMultiplicity(i);
952 if (multV0 < 19500)
953 {
954 centrality = -1;
955 AliInfo("Rejecting event due to too small V0 multiplicity");
956 }
a6d82f4e 957 }
958 }
959 }
960 }
961
a8583211 962 AliInfo(Form("Centrality is %f", centrality));
2a910c25 963 }
964
04af8d15 965 Float_t bSign = (inputEvent->GetMagneticField() > 0) ? 1 : -1;
966
85bfac17 967 fHistos->SetRunNumber(inputEvent->GetRunNumber());
968
2a910c25 969 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
970 fHistos->FillEvent(centrality, AliUEHist::kCFStepAll);
971
e0331fd9 972 // Trigger selection ************************************************
d728f490 973 if (!fSkipTrigger && !fAnalyseUE->TriggerSelection(fInputHandler)) return;
6e84bd0a 974
e0331fd9 975 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
2a910c25 976 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
e0331fd9 977
6e84bd0a 978 // Pileup selection ************************************************
979 if (fAnalysisUtils && fAnalysisUtils->IsPileUpEvent(inputEvent))
980 {
981 // count the removed events
982 fHistos->FillEvent(centrality, AliUEHist::kCFStepAnaTopology);
983
984 return;
985 }
986
e0331fd9 987 // Vertex selection *************************************************
85bfac17 988 if(!fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex)) return;
e0331fd9 989
990 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
2a910c25 991 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
e0331fd9 992
c3294f09 993 // optimization
1d53fb34 994 if (centrality < 0)
2a910c25 995 return;
e0331fd9 996
5c9b9fa6 997 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, fParticleSpeciesTrigger, kTRUE);
636a6c1d 998 //Printf("Accepted %d tracks", tracks->GetEntries());
5e053cad 999
1000 // check for outlier in centrality vs number of tracks (rough constants extracted from correlation histgram)
1001 Bool_t reject = kFALSE;
1002 if (fRejectCentralityOutliers)
1003 {
1004 if (centrality > 40 && centrality <= 50 && tracks->GetEntriesFast() > 1160)
1005 reject = kTRUE;
1006 if (centrality > 50 && centrality <= 60 && tracks->GetEntriesFast() > 650)
1007 reject = kTRUE;
1008 if (centrality > 60 && centrality <= 70 && tracks->GetEntriesFast() > 370)
1009 reject = kTRUE;
1010 if (centrality > 70 && centrality <= 80 && tracks->GetEntriesFast() > 220)
1011 reject = kTRUE;
1012 if (centrality > 80 && centrality <= 90 && tracks->GetEntriesFast() > 130)
1013 reject = kTRUE;
1014 if (centrality > 90 && tracks->GetEntriesFast() > 75)
1015 reject = kTRUE;
1016 }
1017
1018 if (reject)
1019 {
1020 AliInfo(Form("Rejecting event due to centrality vs tracks correlation: %f %d", centrality, tracks->GetEntriesFast()));
1021 fHistos->FillEvent(centrality, AliUEHist::kCFStepAnaTopology);
ff9f18e4 1022 delete tracks;
1023 return;
1024 }
1025
1026 if (fRejectZeroTrackEvents && tracks->GetEntriesFast() == 0)
1027 {
1028 AliInfo(Form("Rejecting event because it has no tracks: %f %d", centrality, tracks->GetEntriesFast()));
1029 fHistos->FillEvent(centrality, AliUEHist::kCFStepAnaTopology);
5e053cad 1030 delete tracks;
1031 return;
1032 }
3bbad7c1 1033
636a6c1d 1034 // correlate particles with...
1035 TObjArray* tracksCorrelate = 0;
5c9b9fa6 1036 if (fParticleSpeciesAssociated != fParticleSpeciesTrigger)
1037 tracksCorrelate = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, fParticleSpeciesAssociated, kTRUE);
636a6c1d 1038
3bbad7c1 1039 // reference multiplicity
1040 Int_t referenceMultiplicity = -1;
1041 if (fESD)
1042 referenceMultiplicity = AliESDtrackCuts::GetReferenceMultiplicity(fESD);
3f3f12d9 1043 else if (fAOD)
1044 referenceMultiplicity = tracks->GetEntriesFast(); // TODO to be replaced by the estimator once available in the AOD
418b56c5 1045// referenceMultiplicity = fAOD->GetHeader()->GetRefMultiplicityComb05();
5e053cad 1046
3bbad7c1 1047 ((TH2F*) fListOfHistos->FindObject("referenceMultiplicity"))->Fill(centrality, referenceMultiplicity);
5e053cad 1048
85bfac17 1049 const AliVVertex* vertex = inputEvent->GetPrimaryVertex();
2a910c25 1050 Double_t zVtx = vertex->GetZ();
1051
c05ff6be 1052 Float_t weight = 1;
1053 if (fFillpT)
1054 weight = -1;
1055
c3294f09 1056 // Fill containers at STEP 6 (reconstructed)
1057 if (centrality >= 0)
c066889a 1058 {
a26093ba 1059 if (!fSkipStep6)
636a6c1d 1060 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, tracksCorrelate, weight, kTRUE, kFALSE, 0, 0.02, kTRUE);
a26093ba 1061
c066889a 1062 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(1);
04af8d15 1063
d4b3dbfc 1064 if (fTwoTrackEfficiencyCut > 0)
636a6c1d 1065 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracks, tracksCorrelate, weight, kTRUE, kTRUE, bSign, fTwoTrackEfficiencyCut, kTRUE);
c066889a 1066 }
c3294f09 1067
636a6c1d 1068 // create a list of reduced objects. This speeds up processing and reduces memory consumption for the event pool
1069 TObjArray* tracksClone = CloneAndReduceTrackList(tracks);
1070 delete tracks;
1071
eed401dc 1072 if (fFillMixed)
e0331fd9 1073 {
eed401dc 1074 // event mixing
2a910c25 1075
eed401dc 1076 // 1. First get an event pool corresponding in mult (cent) and
1077 // zvertex to the current event. Once initialized, the pool
1078 // should contain nMix (reduced) events. This routine does not
1079 // pre-scan the chain. The first several events of every chain
1080 // will be skipped until the needed pools are filled to the
1081 // specified depth. If the pool categories are not too rare, this
1082 // should not be a problem. If they are rare, you could lose
1083 // statistics.
1084
1085 // 2. Collect the whole pool's content of tracks into one TObjArray
1086 // (bgTracks), which is effectively a single background super-event.
1087
1088 // 3. The reduced and bgTracks arrays must both be passed into
1089 // FillCorrelations(). Also nMix should be passed in, so a weight
1090 // of 1./nMix can be applied.
1091
1092 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx);
1093
1094 if (!pool)
1095 AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centrality, zVtx));
1096
f0df9076 1097// pool->SetDebug(1);
2d7827bf 1098
f0df9076 1099 if (pool->IsReady())
eed401dc 1100 {
1101
1102 Int_t nMix = pool->GetCurrentNEvents();
a1c31636 1103// cout << "nMix = " << nMix << " tracks in pool = " << pool->NTracksInPool() << endl;
c066889a 1104
1105 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(2);
5614e02f 1106 ((TH2F*) fListOfHistos->FindObject("mixedDist"))->Fill(centrality, pool->NTracksInPool());
c066889a 1107 if (pool->IsReady())
1108 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(3);
eed401dc 1109
1110 // Fill mixed-event histos here
c05ff6be 1111 for (Int_t jMix=0; jMix<nMix; jMix++)
1112 {
eed401dc 1113 TObjArray* bgTracks = pool->GetEvent(jMix);
c5c840c5 1114
a26093ba 1115 if (!fSkipStep6)
408d1ac9 1116 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracksClone, bgTracks, 1.0 / nMix, (jMix == 0), kFALSE, 0, 0.02, kTRUE);
c5c840c5 1117
d4b3dbfc 1118 if (fTwoTrackEfficiencyCut > 0)
408d1ac9 1119 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracksClone, bgTracks, 1.0 / nMix, (jMix == 0), kTRUE, bSign, fTwoTrackEfficiencyCut, kTRUE);
eed401dc 1120 }
e0331fd9 1121 }
eed401dc 1122
04af8d15 1123 // ownership is with the pool now
636a6c1d 1124 if (tracksCorrelate)
1125 {
1126 pool->UpdatePool(CloneAndReduceTrackList(tracksCorrelate));
1127 delete tracksClone;
1128 }
1129 else
1130 pool->UpdatePool(tracksClone);
eed401dc 1131 //pool->PrintInfo();
e0331fd9 1132 }
04af8d15 1133 else
636a6c1d 1134 {
04af8d15 1135 delete tracksClone;
636a6c1d 1136 if (tracksCorrelate)
1137 delete tracksCorrelate;
1138 }
e0331fd9 1139}
1140
7a028750 1141TObjArray* AliAnalysisTaskPhiCorrelations::CloneAndReduceTrackList(TObjArray* tracks)
1142{
1143 // clones a track list by using AliDPhiBasicParticle which uses much less memory (used for event mixing)
1144
1145 TObjArray* tracksClone = new TObjArray;
1146 tracksClone->SetOwner(kTRUE);
1147
b0d56b29 1148 for (Int_t i=0; i<tracks->GetEntriesFast(); i++)
7a028750 1149 {
1d53fb34 1150 AliVParticle* particle = (AliVParticle*) tracks->UncheckedAt(i);
1151 AliDPhiBasicParticle* copy = new AliDPhiBasicParticle(particle->Eta(), particle->Phi(), particle->Pt(), particle->Charge());
1152 copy->SetUniqueID(particle->GetUniqueID());
1153 tracksClone->Add(copy);
7a028750 1154 }
1155
1156 return tracksClone;
1157}
1158
e0331fd9 1159//____________________________________________________________________
1160void AliAnalysisTaskPhiCorrelations::Initialize()
1161{
1162 // input handler
1163 fInputHandler = (AliInputEventHandler*)
1164 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
1165 // MC handler
1166 fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
1167}
d6a8903f 1168
1169//____________________________________________________________________
1170void AliAnalysisTaskPhiCorrelations::RemoveDuplicates(TObjArray* tracks)
1171{
1172 // remove particles with the same label
1173
1174 Int_t before = tracks->GetEntriesFast();
1175
1176 for (Int_t i=0; i<before; ++i)
1177 {
1178 AliVParticle* part = (AliVParticle*) tracks->At(i);
1179
1180 for (Int_t j=i+1; j<before; ++j)
1181 {
1182 AliVParticle* part2 = (AliVParticle*) tracks->At(j);
1183
1184 if (part->GetLabel() == part2->GetLabel())
1185 {
1186 Printf("Removing %d with label %d (duplicated in %d)", i, part->GetLabel(), j); part->Dump(); part2->Dump();
1187 TObject* object = tracks->RemoveAt(i);
1188 if (tracks->IsOwner())
1189 delete object;
1190 break;
1191 }
1192 }
1193 }
1194
1195 tracks->Compress();
1196
1197 if (before > tracks->GetEntriesFast())
1198 AliInfo(Form("Reduced from %d to %d", before, tracks->GetEntriesFast()));
1199}
3f3f12d9 1200
1201void AliAnalysisTaskPhiCorrelations::CleanUp(TObjArray* tracks, TObject* mcObj, Int_t maxLabel)
1202{
1203 // calls RemoveInjectedSignals, RemoveWeakDecays and RemoveDuplicates
1204
59375a30 1205 if (!tracks)
1206 return;
1207
3f3f12d9 1208 if (fInjectedSignals)
1209 fAnalyseUE->RemoveInjectedSignals(tracks, mcObj, maxLabel);
1210 if (fRemoveWeakDecays)
1211 fAnalyseUE->RemoveWeakDecays(tracks, mcObj);
1212 if (fRemoveDuplicates)
1213 RemoveDuplicates(tracks);
1214}
29cfdb5f 1215
1216//____________________________________________________________________
1217void AliAnalysisTaskPhiCorrelations::SelectCharge(TObjArray* tracks)
1218{
1219 // remove particles with charge not selected (depending on fTriggerSelectCharge)
1220
59375a30 1221 if (!tracks)
1222 return;
1223
29cfdb5f 1224 Int_t before = tracks->GetEntriesFast();
1225
1226 for (Int_t i=0; i<before; ++i)
1227 {
1228 AliVParticle* part = (AliVParticle*) tracks->At(i);
1229
1230 if (part->Charge() * fTriggerSelectCharge < -1)
1231 {
1232// Printf("Removing %d with charge %d", i, part->Charge());
1233 TObject* object = tracks->RemoveAt(i);
1234 if (tracks->IsOwner())
1235 delete object;
1236 }
1237 }
1238
1239 tracks->Compress();
1240
1241 if (before > tracks->GetEntriesFast())
1242 AliInfo(Form("Reduced from %d to %d", before, tracks->GetEntriesFast()));
1243}