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