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