1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
27 #include "AliAnalysisTaskPhiCorrelations.h"
28 #include "AliAnalyseLeadingTrackUE.h"
29 #include "AliUEHistograms.h"
30 #include "AliUEHist.h"
32 #include "AliAnalysisManager.h"
33 #include "AliAODHandler.h"
34 #include "AliAODInputHandler.h"
35 #include "AliAODMCParticle.h"
36 #include "AliInputEventHandler.h"
38 #include "AliMCEventHandler.h"
39 #include "AliVParticle.h"
40 #include "AliCFContainer.h"
42 #include "AliESDEvent.h"
43 #include "AliESDInputHandler.h"
44 #include "AliMultiplicity.h"
45 #include "AliCentrality.h"
48 #include "AliEventPoolManager.h"
51 ////////////////////////////////////////////////////////////////////////
53 // Analysis class for azimuthal correlation studies
54 // Based on the UE task from Sara Vallero and Jan Fiete
56 // This class needs input AODs.
57 // The output is a list of analysis-specific containers.
59 // The AOD can be either connected to the InputEventHandler
60 // for a chain of AOD files
62 // to the OutputEventHandler
63 // for a chain of ESD files,
64 // in this case the class should be in the train after the jet-finder
67 // Jan Fiete Grosse-Oetringhaus
69 ////////////////////////////////////////////////////////////////////////
72 ClassImp( AliAnalysisTaskPhiCorrelations )
73 ClassImp( AliDPhiBasicParticle )
75 //____________________________________________________________________
76 AliAnalysisTaskPhiCorrelations:: AliAnalysisTaskPhiCorrelations(const char* name):
77 AliAnalysisTask(name,""),
78 // general configuration
81 fReduceMemoryFootprint(kFALSE),
84 fCompareCentralities(kFALSE),
85 fTwoTrackEfficiencyStudy(kFALSE),
87 // pointers to UE classes
91 fkTrackingEfficiency(0x0),
92 // handlers and events
100 // histogram settings
103 fnTracksVertex(1), // QA tracks pointing to principal vertex (= 3 default)
105 fCentralityMethod("V0M"),
111 fUseChargeHadrons(kFALSE),
113 fTriggerRestrictEta(-1),
116 // Default constructor
117 // Define input and output slots here
118 // Input slot #0 works with a TChain
119 DefineInput(0, TChain::Class());
120 // Output slot #0 writes into a TList container
121 DefineOutput(0, TList::Class());
124 AliAnalysisTaskPhiCorrelations::~AliAnalysisTaskPhiCorrelations()
128 if (fListOfHistos && !AliAnalysisManager::GetAnalysisManager()->IsProofMode())
129 delete fListOfHistos;
132 //____________________________________________________________________
133 void AliAnalysisTaskPhiCorrelations::ConnectInputData(Option_t* /*option*/)
136 // Connect the input data
137 if (fDebug > 1) AliInfo("ConnectInputData() ");
139 // Since AODs can either be connected to the InputEventHandler
140 // or to the OutputEventHandler ( the AOD is created by a previus task in the train )
141 // we need to get the pointer to the AODEvent correctly.
143 // Delta AODs are also accepted.
145 TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
147 if( handler && handler->InheritsFrom("AliAODInputHandler") )
149 fAOD = ((AliAODInputHandler*)handler)->GetEvent();
150 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODInputHandler");
154 handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
155 if (handler && handler->InheritsFrom("AliAODHandler") )
157 fAOD = ((AliAODHandler*)handler)->GetAOD();
158 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODHandler");
162 AliWarning("I can't get any AOD Event Handler");
166 if (handler && handler->InheritsFrom("AliESDInputHandler") )
168 // pointer received per event in ::Exec
169 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliESDInputHandler");
172 // Initialize common pointers
176 //____________________________________________________________________
177 void AliAnalysisTaskPhiCorrelations::CreateOutputObjects()
179 // Create the output container
181 if (fDebug > 1) AliInfo("CreateOutputObjects()");
183 // Initialize class with main algorithms, event and track selection.
184 fAnalyseUE = new AliAnalyseLeadingTrackUE();
185 fAnalyseUE->SetParticleSelectionCriteria(fFilterBit, fUseChargeHadrons, fTrackEtaCut, fPtMin);
186 fAnalyseUE->SetDebug(fDebug);
187 fAnalyseUE->DefineESDCuts(fFilterBit);
189 // Initialize output list of containers
190 if (fListOfHistos != NULL){
191 delete fListOfHistos;
192 fListOfHistos = NULL;
195 fListOfHistos = new TList();
196 fListOfHistos->SetOwner(kTRUE);
199 // Initialize class to handle histograms
200 const char* histType = "4";
203 fHistos = new AliUEHistograms("AliUEHistogramsSame", histType);
204 fHistosMixed = new AliUEHistograms("AliUEHistogramsMixed", histType);
206 fHistos->SetSelectCharge(fSelectCharge);
207 fHistosMixed->SetSelectCharge(fSelectCharge);
209 fHistos->SetTriggerRestrictEta(fTriggerRestrictEta);
210 fHistosMixed->SetTriggerRestrictEta(fTriggerRestrictEta);
212 // add histograms to list
213 fListOfHistos->Add(fHistos);
214 fListOfHistos->Add(fHistosMixed);
216 fListOfHistos->Add(new TH2F("trackletsVsV0Cent", ";L1 clusters;v0 centrality", 100, -0.5, 9999.5, 101, 0, 101));
217 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));
218 fListOfHistos->Add(new TH1F("eventStat", ";;events", 4, -0.5, 3.5));
219 fListOfHistos->Add(new TH1F("mixedDist", ";tracks;events", 200, 0, fMixingTracks * 1.5));
221 PostData(0,fListOfHistos);
223 // Add task configuration to output list
227 Int_t trackDepth = fMixingTracks;
228 Int_t poolsize = 1000; // Maximum number of events, ignored in the present implemented of AliEventPool
230 Int_t nCentralityBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(1);
231 Double_t* centralityBins = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(1, 0)->GetXbins()->GetArray();
234 Double_t vertexBins[] = { -7, -5, -3, -1, 1, 3, 5, 7 };
235 Double_t* zvtxbin = vertexBins;
237 if (fHistos->GetUEHist(2)->GetEventHist()->GetNVar() > 2)
239 nZvtxBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(2);
240 zvtxbin = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(2, 0)->GetXbins()->GetArray();
243 fPoolMgr = new AliEventPoolManager(poolsize, trackDepth, nCentralityBins, centralityBins, nZvtxBins, zvtxbin);
246 //____________________________________________________________________
247 void AliAnalysisTaskPhiCorrelations::Exec(Option_t */*option*/)
249 // array of MC particles
253 fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
255 AliFatal("No array of MC particles found !!!");
257 fMcEvent = fMcHandler->MCEvent();
260 // receive ESD pointer if we are not running AOD analysis
263 AliVEventHandler* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
264 if (handler && handler->InheritsFrom("AliESDInputHandler"))
265 fESD = ((AliESDInputHandler*)handler)->GetEvent();
269 if (fMode) AnalyseCorrectionMode();
270 else AnalyseDataMode();
273 /******************** ANALYSIS METHODS *****************************/
275 //____________________________________________________________________
276 void AliAnalysisTaskPhiCorrelations::AddSettingsTree()
278 //Write settings to output list
279 TTree *settingsTree = new TTree("UEAnalysisSettings","Analysis Settings in UE estimation");
280 settingsTree->Branch("fnTracksVertex", &fnTracksVertex,"nTracksVertex/I");
281 settingsTree->Branch("fZVertex", &fZVertex,"ZVertex/D");
282 //settingsTree->Branch("fCentralityMethod", fCentralityMethod.Data(),"CentralityMethod/C");
283 settingsTree->Branch("fTrackEtaCut", &fTrackEtaCut, "TrackEtaCut/D");
284 settingsTree->Branch("fPtMin", &fPtMin, "PtMin/D");
285 settingsTree->Branch("fFilterBit", &fFilterBit,"FilterBit/I");
286 settingsTree->Branch("fSelectBit", &fSelectBit,"EventSelectionBit/I");
287 settingsTree->Branch("fUseChargeHadrons", &fUseChargeHadrons,"UseChHadrons/O");
288 settingsTree->Branch("fSelectCharge", &fSelectCharge,"SelectCharge/I");
289 settingsTree->Branch("fTriggerRestrictEta", &fTriggerRestrictEta,"SelectCharge/D");
290 settingsTree->Branch("fFillpT", &fFillpT,"FillpT/O");
291 settingsTree->Branch("fkTrackingEfficiency", "TH1D", &fkTrackingEfficiency);
292 settingsTree->Branch("fMixingTracks", &fMixingTracks,"MixingTracks/I");
293 settingsTree->Fill();
294 fListOfHistos->Add(settingsTree);
297 //____________________________________________________________________
298 void AliAnalysisTaskPhiCorrelations::AnalyseCorrectionMode()
300 // Run the analysis on MC to get the correction maps
303 if ( fDebug > 3 ) AliInfo( " Processing event in Corrections mode ..." );
305 Double_t centrality = 0;
307 if (fCentralityMethod.Length() > 0)
309 AliCentrality *centralityObj = 0;
311 centralityObj = fAOD->GetHeader()->GetCentralityP();
313 centralityObj = fESD->GetCentrality();
317 centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
318 AliInfo(Form("Centrality is %f", centrality));
322 Printf("WARNING: Centrality object is 0");
327 // Support for ESD and AOD based analysis
328 AliVEvent* inputEvent = fAOD;
332 TObject* mc = fArrayMC;
337 fHistos->FillEvent(centrality, -1);
339 // Only consider MC events within the vtx-z region used also as cut on the reconstructed vertex
340 if (!fAnalyseUE->VertexSelection(fMcEvent, 0, fZVertex))
343 Float_t zVtx = fMcEvent->GetPrimaryVertex()->GetZ();
349 TObjArray* tracksMC = fAnalyseUE->GetAcceptedParticles(mc, 0, kTRUE, -1, kTRUE);
351 // (MC-true all particles)
353 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepAll, tracksMC, 0, weight);
355 // Trigger selection ************************************************
356 if (fAnalyseUE->TriggerSelection(fInputHandler))
358 // (MC-true all particles)
360 if (!fReduceMemoryFootprint)
361 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTriggered, tracksMC, 0, weight);
363 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
366 AliFatal("UNEXPECTED: inputEvent is 0. Trigger selection should have failed");
370 // Vertex selection *************************************************
371 if (fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex))
373 // fill here for tracking efficiency
374 // loop over particle species
376 for (Int_t particleSpecies = 0; particleSpecies < 4; particleSpecies++)
378 TObjArray* primMCParticles = fAnalyseUE->GetAcceptedParticles(mc, 0x0, kTRUE, particleSpecies, kTRUE);
379 TObjArray* primRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, particleSpecies, kTRUE);
380 TObjArray* allRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, particleSpecies, kTRUE);
382 fHistos->FillTrackingEfficiency(primMCParticles, primRecoTracksMatched, allRecoTracksMatched, particleSpecies, centrality);
384 // Printf("%d --> %d %d %d", particleSpecies, primMCParticles->GetEntries(), primRecoTracksMatched->GetEntries(), allRecoTracksMatched->GetEntries());
386 delete primMCParticles;
387 delete primRecoTracksMatched;
388 delete allRecoTracksMatched;
391 // (MC-true all particles)
393 if (!fReduceMemoryFootprint)
394 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepVertex, tracksMC, 0, weight);
396 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
398 // Get MC primaries that match reconstructed track
399 TObjArray* tracksRecoMatchedPrim = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, -1, kTRUE);
401 // (RECO-matched (quantities from MC particle) primary particles)
403 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTrackedOnlyPrim, tracksRecoMatchedPrim, 0, weight);
405 // Get MC primaries + secondaries that match reconstructed track
406 TObjArray* tracksRecoMatchedAll = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, -1, kTRUE);
408 // (RECO-matched (quantities from MC particle) all particles)
410 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTracked, tracksRecoMatchedAll, 0, weight);
413 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, -1, kTRUE);
417 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
419 if (0 && !fReduceMemoryFootprint)
421 // make list of secondaries (matched with MC)
422 TObjArray* tracksRecoMatchedSecondaries = new TObjArray;
423 for (Int_t i=0; i<tracksRecoMatchedAll->GetEntries(); i++)
424 if (((AliAODMCParticle*)tracksRecoMatchedAll->At(i))->IsPhysicalPrimary() == kFALSE)
425 tracksRecoMatchedSecondaries->Add(tracksRecoMatchedAll->At(i));
427 // Study: Use only secondaries as trigger particles and plot the correlation vs. all particles; store in step 9
428 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy2, tracksRecoMatchedSecondaries, tracksRecoMatchedAll, weight);
430 // Study: Use only primaries as trigger particles and plot the correlation vs. secondaries; store in step 8
431 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracksRecoMatchedPrim, tracksRecoMatchedSecondaries, weight);
433 // plot delta phi vs process id of secondaries
434 // trigger particles: primaries in 4 < pT < 10
435 // associated particles: secondaries in 1 < pT < 10
437 for (Int_t i=0; i<tracksRecoMatchedPrim->GetEntries(); i++)
439 AliVParticle* triggerParticle = (AliVParticle*) tracksRecoMatchedPrim->At(i);
441 if (triggerParticle->Pt() < 4 || triggerParticle->Pt() > 10)
444 for (Int_t j=0; j<tracksRecoMatchedSecondaries->GetEntries(); j++)
446 AliAODMCParticle* particle = (AliAODMCParticle*) tracksRecoMatchedSecondaries->At(j);
448 if (particle->Pt() < 1 || particle->Pt() > 10)
451 if (particle->Pt() > triggerParticle->Pt())
454 Double_t deltaPhi = triggerParticle->Phi() - particle->Phi();
455 if (deltaPhi > 1.5 * TMath::Pi())
456 deltaPhi -= TMath::TwoPi();
457 if (deltaPhi < -0.5 * TMath::Pi())
458 deltaPhi += TMath::TwoPi();
460 Int_t processID = fMcEvent->Stack()->Particle(particle->GetLabel())->GetUniqueID();
462 ((TH2F*) fListOfHistos->FindObject("processIDs"))->Fill(deltaPhi, processID);
466 delete tracksRecoMatchedSecondaries;
469 delete tracksRecoMatchedPrim;
470 delete tracksRecoMatchedAll;
478 //____________________________________________________________________
479 void AliAnalysisTaskPhiCorrelations::AnalyseDataMode()
482 // Run the analysis on DATA or MC to get raw distributions
484 if ( fDebug > 3 ) AliInfo( " Processing event in Data mode ..." );
486 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(0);
488 // skip not selected events here (the AOD is not updated for those)
492 if (!(fInputHandler->IsEventSelected() & (AliVEvent::kMB | AliVEvent::kUserDefined)))
495 Double_t centrality = 0;
497 AliCentrality *centralityObj = 0;
498 if (fCentralityMethod.Length() > 0)
501 centralityObj = fAOD->GetHeader()->GetCentralityP();
503 centralityObj = fESD->GetCentrality();
506 centrality = centralityObj->GetCentralityPercentile(fCentralityMethod);
507 //centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
516 if (fAOD->GetVZEROData())
519 for (Int_t i=0; i<64; i++)
520 multV0 += fAOD->GetVZEROData()->GetMultiplicity(i);
524 AliInfo("Rejecting event due to too small V0 multiplicity");
530 AliInfo(Form("Centrality is %f", centrality));
533 // Support for ESD and AOD based analysis
534 AliVEvent* inputEvent = fAOD;
538 fHistos->SetRunNumber(inputEvent->GetRunNumber());
540 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
541 fHistos->FillEvent(centrality, AliUEHist::kCFStepAll);
543 // Trigger selection ************************************************
544 if (!fAnalyseUE->TriggerSelection(fInputHandler)) return;
546 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
547 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
549 // Vertex selection *************************************************
550 if(!fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex)) return;
552 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
553 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
556 if (centrality < 0 && !fCompareCentralities)
559 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, -1, kTRUE);
560 //Printf("Accepted %d tracks", tracks->GetEntries());
562 const AliVVertex* vertex = inputEvent->GetPrimaryVertex();
563 Double_t zVtx = vertex->GetZ();
569 // fill two different centralities (syst study)
570 // the zvtx axis is used to distinguish the results of both centralities: configured centrality in zvtx = 0, SPD in zvtx = 2
571 if (fCompareCentralities)
574 // Fill containers at STEP 6 (reconstructed)
577 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
578 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(1);
581 // Two-track effect study
582 if (fTwoTrackEfficiencyStudy)
584 Float_t bSign = (fESD->GetMagneticField() > 0) ? 1 : -1;
585 fHistos->TwoTrackEfficiency(tracks, 0, bSign);
588 // fill second time with SPD centrality
589 if (fCompareCentralities && centralityObj)
591 centrality = centralityObj->GetCentralityPercentile("CL1");
593 fHistos->FillCorrelations(centrality, 2, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
600 // 1. First get an event pool corresponding in mult (cent) and
601 // zvertex to the current event. Once initialized, the pool
602 // should contain nMix (reduced) events. This routine does not
603 // pre-scan the chain. The first several events of every chain
604 // will be skipped until the needed pools are filled to the
605 // specified depth. If the pool categories are not too rare, this
606 // should not be a problem. If they are rare, you could lose
609 // 2. Collect the whole pool's content of tracks into one TObjArray
610 // (bgTracks), which is effectively a single background super-event.
612 // 3. The reduced and bgTracks arrays must both be passed into
613 // FillCorrelations(). Also nMix should be passed in, so a weight
614 // of 1./nMix can be applied.
616 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx);
619 AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centrality, zVtx));
623 if (pool->IsReady() || pool->NTracksInPool() > fMixingTracks / 10 || pool->GetCurrentNEvents() >= 5)
626 Int_t nMix = pool->GetCurrentNEvents();
627 // cout << "nMix = " << nMix << " tracks in pool = " << pool->NTracksInPool() << endl;
629 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(2);
630 ((TH1F*) fListOfHistos->FindObject("mixedDist"))->Fill(pool->NTracksInPool());
632 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(3);
634 // Fill mixed-event histos here
635 for (Int_t jMix=0; jMix<nMix; jMix++)
637 TObjArray* bgTracks = pool->GetEvent(jMix);
639 if (fTwoTrackEfficiencyStudy)
641 Float_t bSign = (fESD->GetMagneticField() > 0) ? 1 : -1;
642 fHistos->TwoTrackEfficiency(tracks, bgTracks, bSign);
645 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, bgTracks, 1.0 / nMix, (jMix == 0));
649 // create a list of reduced objects (to reduce memory consumption) and give ownership to event pool
650 TObjArray* tracksClone = new TObjArray;
651 tracksClone->SetOwner(kTRUE);
653 for (Int_t i=0; i<tracks->GetEntries(); i++)
655 AliVParticle* particle = (AliVParticle*) tracks->At(i);
656 tracksClone->Add(new AliDPhiBasicParticle(particle->Eta(), particle->Phi(), particle->Pt(), particle->Charge()));
659 pool->UpdatePool(tracksClone);
666 //____________________________________________________________________
667 void AliAnalysisTaskPhiCorrelations::Initialize()
670 fInputHandler = (AliInputEventHandler*)
671 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
673 fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());