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),
115 // Default constructor
116 // Define input and output slots here
117 // Input slot #0 works with a TChain
118 DefineInput(0, TChain::Class());
119 // Output slot #0 writes into a TList container
120 DefineOutput(0, TList::Class());
123 AliAnalysisTaskPhiCorrelations::~AliAnalysisTaskPhiCorrelations()
127 if (fListOfHistos && !AliAnalysisManager::GetAnalysisManager()->IsProofMode())
128 delete fListOfHistos;
131 //____________________________________________________________________
132 void AliAnalysisTaskPhiCorrelations::ConnectInputData(Option_t* /*option*/)
135 // Connect the input data
136 if (fDebug > 1) AliInfo("ConnectInputData() ");
138 // Since AODs can either be connected to the InputEventHandler
139 // or to the OutputEventHandler ( the AOD is created by a previus task in the train )
140 // we need to get the pointer to the AODEvent correctly.
142 // Delta AODs are also accepted.
144 TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
146 if( handler && handler->InheritsFrom("AliAODInputHandler") )
148 fAOD = ((AliAODInputHandler*)handler)->GetEvent();
149 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODInputHandler");
153 handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
154 if (handler && handler->InheritsFrom("AliAODHandler") )
156 fAOD = ((AliAODHandler*)handler)->GetAOD();
157 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODHandler");
161 AliWarning("I can't get any AOD Event Handler");
165 if (handler && handler->InheritsFrom("AliESDInputHandler") )
167 // pointer received per event in ::Exec
168 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliESDInputHandler");
171 // Initialize common pointers
175 //____________________________________________________________________
176 void AliAnalysisTaskPhiCorrelations::CreateOutputObjects()
178 // Create the output container
180 if (fDebug > 1) AliInfo("CreateOutputObjects()");
182 // Initialize class with main algorithms, event and track selection.
183 fAnalyseUE = new AliAnalyseLeadingTrackUE();
184 fAnalyseUE->SetParticleSelectionCriteria(fFilterBit, fUseChargeHadrons, fTrackEtaCut, fPtMin);
185 fAnalyseUE->SetDebug(fDebug);
186 fAnalyseUE->DefineESDCuts(fFilterBit);
188 // Initialize output list of containers
189 if (fListOfHistos != NULL){
190 delete fListOfHistos;
191 fListOfHistos = NULL;
194 fListOfHistos = new TList();
195 fListOfHistos->SetOwner(kTRUE);
198 // Initialize class to handle histograms
199 const char* histType = "4";
202 fHistos = new AliUEHistograms("AliUEHistogramsSame", histType);
203 fHistosMixed = new AliUEHistograms("AliUEHistogramsMixed", histType);
205 fHistos->SetSelectCharge(fSelectCharge);
206 fHistosMixed->SetSelectCharge(fSelectCharge);
208 // add histograms to list
209 fListOfHistos->Add(fHistos);
210 fListOfHistos->Add(fHistosMixed);
212 fListOfHistos->Add(new TH2F("trackletsVsV0Cent", ";L1 clusters;v0 centrality", 100, -0.5, 9999.5, 101, 0, 101));
213 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));
214 fListOfHistos->Add(new TH1F("eventStat", ";;events", 4, -0.5, 3.5));
215 fListOfHistos->Add(new TH1F("mixedDist", ";tracks;events", 200, 0, fMixingTracks * 1.5));
217 PostData(0,fListOfHistos);
219 // Add task configuration to output list
223 Int_t trackDepth = fMixingTracks;
224 Int_t poolsize = 1000; // Maximum number of events, ignored in the present implemented of AliEventPool
226 Int_t nCentralityBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(1);
227 Double_t* centralityBins = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(1, 0)->GetXbins()->GetArray();
230 Double_t vertexBins[] = { -7, -5, -3, -1, 1, 3, 5, 7 };
231 Double_t* zvtxbin = vertexBins;
233 if (fHistos->GetUEHist(2)->GetEventHist()->GetNVar() > 2)
235 nZvtxBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(2);
236 zvtxbin = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(2, 0)->GetXbins()->GetArray();
239 fPoolMgr = new AliEventPoolManager(poolsize, trackDepth, nCentralityBins, centralityBins, nZvtxBins, zvtxbin);
242 //____________________________________________________________________
243 void AliAnalysisTaskPhiCorrelations::Exec(Option_t */*option*/)
245 // array of MC particles
249 fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
251 AliFatal("No array of MC particles found !!!");
253 fMcEvent = fMcHandler->MCEvent();
256 // receive ESD pointer if we are not running AOD analysis
259 AliVEventHandler* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
260 if (handler && handler->InheritsFrom("AliESDInputHandler"))
261 fESD = ((AliESDInputHandler*)handler)->GetEvent();
265 if (fMode) AnalyseCorrectionMode();
266 else AnalyseDataMode();
269 /******************** ANALYSIS METHODS *****************************/
271 //____________________________________________________________________
272 void AliAnalysisTaskPhiCorrelations::AddSettingsTree()
274 //Write settings to output list
275 TTree *settingsTree = new TTree("UEAnalysisSettings","Analysis Settings in UE estimation");
276 settingsTree->Branch("fnTracksVertex", &fnTracksVertex,"nTracksVertex/I");
277 settingsTree->Branch("fZVertex", &fZVertex,"ZVertex/D");
278 //settingsTree->Branch("fCentralityMethod", fCentralityMethod.Data(),"CentralityMethod/C");
279 settingsTree->Branch("fTrackEtaCut", &fTrackEtaCut, "TrackEtaCut/D");
280 settingsTree->Branch("fPtMin", &fPtMin, "PtMin/D");
281 settingsTree->Branch("fFilterBit", &fFilterBit,"FilterBit/I");
282 settingsTree->Branch("fSelectBit", &fSelectBit,"EventSelectionBit/I");
283 settingsTree->Branch("fUseChargeHadrons", &fUseChargeHadrons,"UseChHadrons/O");
284 settingsTree->Branch("fSelectCharge", &fSelectCharge,"SelectCharge/I");
285 settingsTree->Branch("fFillpT", &fFillpT,"FillpT/O");
286 settingsTree->Branch("fkTrackingEfficiency", "TH1D", &fkTrackingEfficiency);
287 settingsTree->Branch("fMixingTracks", &fMixingTracks,"MixingTracks/I");
288 settingsTree->Fill();
289 fListOfHistos->Add(settingsTree);
292 //____________________________________________________________________
293 void AliAnalysisTaskPhiCorrelations::AnalyseCorrectionMode()
295 // Run the analysis on MC to get the correction maps
298 if ( fDebug > 3 ) AliInfo( " Processing event in Corrections mode ..." );
300 Double_t centrality = 0;
302 if (fCentralityMethod.Length() > 0)
304 AliCentrality *centralityObj = 0;
306 centralityObj = fAOD->GetHeader()->GetCentralityP();
308 centralityObj = fESD->GetCentrality();
312 centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
313 AliInfo(Form("Centrality is %f", centrality));
317 Printf("WARNING: Centrality object is 0");
322 // Support for ESD and AOD based analysis
323 AliVEvent* inputEvent = fAOD;
327 TObject* mc = fArrayMC;
332 fHistos->FillEvent(centrality, -1);
334 // Only consider MC events within the vtx-z region used also as cut on the reconstructed vertex
335 if (!fAnalyseUE->VertexSelection(fMcEvent, 0, fZVertex))
338 Float_t zVtx = fMcEvent->GetPrimaryVertex()->GetZ();
344 TObjArray* tracksMC = fAnalyseUE->GetAcceptedParticles(mc, 0, kTRUE, -1, kTRUE);
346 // (MC-true all particles)
348 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepAll, tracksMC, 0, weight);
350 // Trigger selection ************************************************
351 if (fAnalyseUE->TriggerSelection(fInputHandler))
353 // (MC-true all particles)
355 if (!fReduceMemoryFootprint)
356 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTriggered, tracksMC, 0, weight);
358 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
361 AliFatal("UNEXPECTED: inputEvent is 0. Trigger selection should have failed");
365 // Vertex selection *************************************************
366 if (fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex))
368 // fill here for tracking efficiency
369 // loop over particle species
371 for (Int_t particleSpecies = 0; particleSpecies < 4; particleSpecies++)
373 TObjArray* primMCParticles = fAnalyseUE->GetAcceptedParticles(mc, 0x0, kTRUE, particleSpecies, kTRUE);
374 TObjArray* primRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, particleSpecies, kTRUE);
375 TObjArray* allRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, particleSpecies, kTRUE);
377 fHistos->FillTrackingEfficiency(primMCParticles, primRecoTracksMatched, allRecoTracksMatched, particleSpecies, centrality);
379 // Printf("%d --> %d %d %d", particleSpecies, primMCParticles->GetEntries(), primRecoTracksMatched->GetEntries(), allRecoTracksMatched->GetEntries());
381 delete primMCParticles;
382 delete primRecoTracksMatched;
383 delete allRecoTracksMatched;
386 // (MC-true all particles)
388 if (!fReduceMemoryFootprint)
389 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepVertex, tracksMC, 0, weight);
391 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
393 // Get MC primaries that match reconstructed track
394 TObjArray* tracksRecoMatchedPrim = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kTRUE, -1, kTRUE);
396 // (RECO-matched (quantities from MC particle) primary particles)
398 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTrackedOnlyPrim, tracksRecoMatchedPrim, 0, weight);
400 // Get MC primaries + secondaries that match reconstructed track
401 TObjArray* tracksRecoMatchedAll = fAnalyseUE->GetAcceptedParticles(inputEvent, mc, kFALSE, -1, kTRUE);
403 // (RECO-matched (quantities from MC particle) all particles)
405 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepTracked, tracksRecoMatchedAll, 0, weight);
408 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, -1, kTRUE);
412 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
414 if (0 && !fReduceMemoryFootprint)
416 // make list of secondaries (matched with MC)
417 TObjArray* tracksRecoMatchedSecondaries = new TObjArray;
418 for (Int_t i=0; i<tracksRecoMatchedAll->GetEntries(); i++)
419 if (((AliAODMCParticle*)tracksRecoMatchedAll->At(i))->IsPhysicalPrimary() == kFALSE)
420 tracksRecoMatchedSecondaries->Add(tracksRecoMatchedAll->At(i));
422 // Study: Use only secondaries as trigger particles and plot the correlation vs. all particles; store in step 9
423 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy2, tracksRecoMatchedSecondaries, tracksRecoMatchedAll, weight);
425 // Study: Use only primaries as trigger particles and plot the correlation vs. secondaries; store in step 8
426 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepBiasStudy, tracksRecoMatchedPrim, tracksRecoMatchedSecondaries, weight);
428 // plot delta phi vs process id of secondaries
429 // trigger particles: primaries in 4 < pT < 10
430 // associated particles: secondaries in 1 < pT < 10
432 for (Int_t i=0; i<tracksRecoMatchedPrim->GetEntries(); i++)
434 AliVParticle* triggerParticle = (AliVParticle*) tracksRecoMatchedPrim->At(i);
436 if (triggerParticle->Pt() < 4 || triggerParticle->Pt() > 10)
439 for (Int_t j=0; j<tracksRecoMatchedSecondaries->GetEntries(); j++)
441 AliAODMCParticle* particle = (AliAODMCParticle*) tracksRecoMatchedSecondaries->At(j);
443 if (particle->Pt() < 1 || particle->Pt() > 10)
446 if (particle->Pt() > triggerParticle->Pt())
449 Double_t deltaPhi = triggerParticle->Phi() - particle->Phi();
450 if (deltaPhi > 1.5 * TMath::Pi())
451 deltaPhi -= TMath::TwoPi();
452 if (deltaPhi < -0.5 * TMath::Pi())
453 deltaPhi += TMath::TwoPi();
455 Int_t processID = fMcEvent->Stack()->Particle(particle->GetLabel())->GetUniqueID();
457 ((TH2F*) fListOfHistos->FindObject("processIDs"))->Fill(deltaPhi, processID);
461 delete tracksRecoMatchedSecondaries;
464 delete tracksRecoMatchedPrim;
465 delete tracksRecoMatchedAll;
473 //____________________________________________________________________
474 void AliAnalysisTaskPhiCorrelations::AnalyseDataMode()
477 // Run the analysis on DATA or MC to get raw distributions
479 if ( fDebug > 3 ) AliInfo( " Processing event in Data mode ..." );
481 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(0);
483 // skip not selected events here (the AOD is not updated for those)
487 if (!(fInputHandler->IsEventSelected() & (AliVEvent::kMB | AliVEvent::kUserDefined)))
490 Double_t centrality = 0;
492 AliCentrality *centralityObj = 0;
493 if (fCentralityMethod.Length() > 0)
496 centralityObj = fAOD->GetHeader()->GetCentralityP();
498 centralityObj = fESD->GetCentrality();
501 centrality = centralityObj->GetCentralityPercentile(fCentralityMethod);
502 //centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
511 if (fAOD->GetVZEROData())
514 for (Int_t i=0; i<64; i++)
515 multV0 += fAOD->GetVZEROData()->GetMultiplicity(i);
519 AliInfo("Rejecting event due to too small V0 multiplicity");
525 AliInfo(Form("Centrality is %f", centrality));
528 // Support for ESD and AOD based analysis
529 AliVEvent* inputEvent = fAOD;
533 fHistos->SetRunNumber(inputEvent->GetRunNumber());
535 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
536 fHistos->FillEvent(centrality, AliUEHist::kCFStepAll);
538 // Trigger selection ************************************************
539 if (!fAnalyseUE->TriggerSelection(fInputHandler)) return;
541 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
542 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
544 // Vertex selection *************************************************
545 if(!fAnalyseUE->VertexSelection(inputEvent, fnTracksVertex, fZVertex)) return;
547 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
548 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
551 if (centrality < 0 && !fCompareCentralities)
554 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(inputEvent, 0, kTRUE, -1, kTRUE);
555 //Printf("Accepted %d tracks", tracks->GetEntries());
557 const AliVVertex* vertex = inputEvent->GetPrimaryVertex();
558 Double_t zVtx = vertex->GetZ();
564 // fill two different centralities (syst study)
565 // the zvtx axis is used to distinguish the results of both centralities: configured centrality in zvtx = 0, SPD in zvtx = 2
566 if (fCompareCentralities)
569 // Fill containers at STEP 6 (reconstructed)
572 fHistos->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
573 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(1);
576 // Two-track effect study
577 if (fTwoTrackEfficiencyStudy)
579 Float_t bSign = (fESD->GetMagneticField() > 0) ? 1 : -1;
580 fHistos->TwoTrackEfficiency(tracks, 0, bSign);
583 // fill second time with SPD centrality
584 if (fCompareCentralities && centralityObj)
586 centrality = centralityObj->GetCentralityPercentile("CL1");
588 fHistos->FillCorrelations(centrality, 2, AliUEHist::kCFStepReconstructed, tracks, 0, weight);
595 // 1. First get an event pool corresponding in mult (cent) and
596 // zvertex to the current event. Once initialized, the pool
597 // should contain nMix (reduced) events. This routine does not
598 // pre-scan the chain. The first several events of every chain
599 // will be skipped until the needed pools are filled to the
600 // specified depth. If the pool categories are not too rare, this
601 // should not be a problem. If they are rare, you could lose
604 // 2. Collect the whole pool's content of tracks into one TObjArray
605 // (bgTracks), which is effectively a single background super-event.
607 // 3. The reduced and bgTracks arrays must both be passed into
608 // FillCorrelations(). Also nMix should be passed in, so a weight
609 // of 1./nMix can be applied.
611 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx);
614 AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centrality, zVtx));
618 if (pool->IsReady() || pool->NTracksInPool() > fMixingTracks / 10)
621 Int_t nMix = pool->GetCurrentNEvents();
622 // cout << "nMix = " << nMix << " tracks in pool = " << pool->NTracksInPool() << endl;
624 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(2);
625 ((TH1F*) fListOfHistos->FindObject("mixedDist"))->Fill(pool->NTracksInPool());
627 ((TH1F*) fListOfHistos->FindObject("eventStat"))->Fill(3);
629 // Fill mixed-event histos here
630 for (Int_t jMix=0; jMix<nMix; jMix++)
632 TObjArray* bgTracks = pool->GetEvent(jMix);
634 if (fTwoTrackEfficiencyStudy)
636 Float_t bSign = (fESD->GetMagneticField() > 0) ? 1 : -1;
637 fHistos->TwoTrackEfficiency(tracks, bgTracks, bSign);
640 fHistosMixed->FillCorrelations(centrality, zVtx, AliUEHist::kCFStepReconstructed, tracks, bgTracks, 1.0 / nMix, (jMix == 0));
644 // create a list of reduced objects (to reduce memory consumption) and give ownership to event pool
645 TObjArray* tracksClone = new TObjArray;
646 tracksClone->SetOwner(kTRUE);
648 for (Int_t i=0; i<tracks->GetEntries(); i++)
650 AliVParticle* particle = (AliVParticle*) tracks->At(i);
651 tracksClone->Add(new AliDPhiBasicParticle(particle->Eta(), particle->Phi(), particle->Pt(), particle->Charge()));
654 pool->UpdatePool(tracksClone);
661 //____________________________________________________________________
662 void AliAnalysisTaskPhiCorrelations::Initialize()
665 fInputHandler = (AliInputEventHandler*)
666 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
668 fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());