]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/JetTasks/AliAnalysisTaskPhiCorrelations.cxx
update to trigger correlation study
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliAnalysisTaskPhiCorrelations.cxx
CommitLineData
2a910c25 1
e0331fd9 2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/* $Id:$ */
18
19#include <TROOT.h>
20#include <TChain.h>
21#include <TFile.h>
22#include <TList.h>
23#include <TMath.h>
24#include <TTree.h>
25#include <TH2F.h>
26#include <TRandom.h>
2a910c25 27#include <TMCProcess.h>
e0331fd9 28
29#include "AliAnalysisTaskPhiCorrelations.h"
30#include "AliAnalyseLeadingTrackUE.h"
31#include "AliUEHistograms.h"
32#include "AliUEHist.h"
33
34#include "AliAnalysisHelperJetTasks.h"
35#include "AliAnalysisManager.h"
36#include "AliAODHandler.h"
37#include "AliAODInputHandler.h"
38#include "AliAODMCParticle.h"
39#include "AliGenPythiaEventHeader.h"
40#include "AliInputEventHandler.h"
41#include "AliLog.h"
42#include "AliMCEventHandler.h"
43#include "AliVParticle.h"
2a910c25 44#include "AliCFContainer.h"
e0331fd9 45
46#include "AliESDEvent.h"
47#include "AliESDInputHandler.h"
48#include "AliMultiplicity.h"
2a910c25 49#include "AliCentrality.h"
50#include "AliStack.h"
e0331fd9 51
2a910c25 52#include "AliEventPoolManager.h"
e0331fd9 53
54
55////////////////////////////////////////////////////////////////////////
56//
57// Analysis class for azimuthal correlation studies
58// Based on the UE task from Sara Vallero and Jan Fiete
59//
60// This class needs input AODs.
61// The output is a list of analysis-specific containers.
62//
63// The AOD can be either connected to the InputEventHandler
64// for a chain of AOD files
65// or
66// to the OutputEventHandler
67// for a chain of ESD files,
68// in this case the class should be in the train after the jet-finder
69//
70// Authors:
71// Jan Fiete Grosse-Oetringhaus
72//
73////////////////////////////////////////////////////////////////////////
74
75
76ClassImp( AliAnalysisTaskPhiCorrelations )
77
78//____________________________________________________________________
79AliAnalysisTaskPhiCorrelations:: AliAnalysisTaskPhiCorrelations(const char* name):
80AliAnalysisTask(name,""),
81// general configuration
82fDebug(0),
83fMode(0),
84fReduceMemoryFootprint(kFALSE),
85// pointers to UE classes
86fAnalyseUE(0x0),
87fHistos(0x0),
88fHistosMixed(0),
89fkTrackingEfficiency(0x0),
90// handlers and events
91fAOD(0x0),
92fArrayMC(0x0),
93fInputHandler(0x0),
94fMcEvent(0x0),
95fMcHandler(0x0),
2a910c25 96fPoolMgr(0x0),
e0331fd9 97// histogram settings
98fListOfHistos(0x0),
99// event QA
100fnTracksVertex(1), // QA tracks pointing to principal vertex (= 3 default)
101fZVertex(10.),
2a910c25 102fCentralityMethod("V0M"),
e0331fd9 103// track cuts
104fTrackEtaCut(0.8),
105fPtMin(0.5),
106fFilterBit(0xFF),
107fSelectBit(0),
2a910c25 108fUseChargeHadrons(kFALSE),
109fSelectCharge(0)
e0331fd9 110{
111 // Default constructor
112 // Define input and output slots here
113 // Input slot #0 works with a TChain
114 DefineInput(0, TChain::Class());
115 // Output slot #0 writes into a TList container
116 DefineOutput(0, TList::Class());
117
118}
119
120AliAnalysisTaskPhiCorrelations::~AliAnalysisTaskPhiCorrelations()
121{
122 // destructor
123
124 if (fListOfHistos && !AliAnalysisManager::GetAnalysisManager()->IsProofMode())
125 delete fListOfHistos;
126}
127
128//____________________________________________________________________
129void AliAnalysisTaskPhiCorrelations::ConnectInputData(Option_t* /*option*/)
130{
131
132 // Connect the input data
133 if (fDebug > 1) AliInfo("ConnectInputData() ");
134
135 // Since AODs can either be connected to the InputEventHandler
136 // or to the OutputEventHandler ( the AOD is created by a previus task in the train )
137 // we need to get the pointer to the AODEvent correctly.
138
139 // Delta AODs are also accepted.
140
141 TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
142
143 if( handler && handler->InheritsFrom("AliAODInputHandler") ) { // input AOD
144 fAOD = ((AliAODInputHandler*)handler)->GetEvent();
145 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODInputHandler");
146 } else { //output AOD
147 handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
148 if( handler && handler->InheritsFrom("AliAODHandler") ) {
149 fAOD = ((AliAODHandler*)handler)->GetAOD();
150 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODHandler");
151 } else { // no AOD
2a910c25 152 AliWarning("I can't get any AOD Event Handler");
e0331fd9 153 }
154 }
155
156 // Initialize common pointers
157 Initialize();
158
159}
160
161//____________________________________________________________________
162void AliAnalysisTaskPhiCorrelations::CreateOutputObjects()
163{
164 // Create the output container
165
166 if (fDebug > 1) AliInfo("CreateOutputObjects()");
167
168 // Initialize class with main algorithms, event and track selection.
169 fAnalyseUE = new AliAnalyseLeadingTrackUE();
2a910c25 170 fAnalyseUE->SetParticleSelectionCriteria(fFilterBit, fUseChargeHadrons, fTrackEtaCut, fPtMin);
e0331fd9 171 fAnalyseUE->SetDebug(fDebug);
172 fAnalyseUE->DefineESDCuts(0);
173
174 // Initialize output list of containers
175 if (fListOfHistos != NULL){
176 delete fListOfHistos;
177 fListOfHistos = NULL;
178 }
179 if (!fListOfHistos){
180 fListOfHistos = new TList();
181 fListOfHistos->SetOwner(kTRUE);
182 }
183
184 // Initialize class to handle histograms
185 fHistos = new AliUEHistograms("AliUEHistogramsSame", "4");
186 fHistosMixed = new AliUEHistograms("AliUEHistogramsMixed", "4");
187
2a910c25 188 fHistos->SetSelectCharge(fSelectCharge);
189 fHistosMixed->SetSelectCharge(fSelectCharge);
190
e0331fd9 191 // add histograms to list
192 fListOfHistos->Add(fHistos);
193 fListOfHistos->Add(fHistosMixed);
194
2a910c25 195 fListOfHistos->Add(new TH2F("trackletsVsV0Cent", ";L1 clusters;v0 centrality", 100, -0.5, 9999.5, 101, 0, 101));
196 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));
e0331fd9 197
198 // Add task configuration to output list
199 AddSettingsTree();
200
2a910c25 201 // event mixing
202 // Int_t trackDepth = 100; // Require e.g. 20 5-track events, or 2 50-track events
203 Int_t trackDepth = 1000; // Require e.g. 20 5-track events, or 2 50-track events
204 Int_t poolsize = 100; // Maximum number of events
205
206 Int_t nCentralityBins = fHistos->GetUEHist(2)->GetEventHist()->GetNBins(1);
207 Double_t* centralityBins = (Double_t*) fHistos->GetUEHist(2)->GetEventHist()->GetAxis(1, 0)->GetXbins()->GetArray();
208
209 Int_t nZvtxBins = 5;
210 Double_t zMin = -10.0;
211 Double_t zMax = 10.0;
212 Double_t zVtxBinWidth = (zMax - zMin) / nZvtxBins;
213 Double_t* zvtxbin = new Double_t[nZvtxBins+1];
214 for (int iz=0; iz<nZvtxBins+1; iz++)
215 zvtxbin[iz] = zMin + iz*zVtxBinWidth;
216
217 fPoolMgr = new AliEventPoolManager(poolsize, trackDepth, nCentralityBins, centralityBins, nZvtxBins, zvtxbin);
e0331fd9 218}
219
220//____________________________________________________________________
221void AliAnalysisTaskPhiCorrelations::Exec(Option_t */*option*/)
222{
223 // array of MC particles
224 if (fMcHandler){
2a910c25 225 fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
226 if (!fArrayMC)
227 AliFatal("No array of MC particles found !!!");
228 fMcEvent = fMcHandler->MCEvent();
229 }
e0331fd9 230
231 // Analyse the event
232 if (fMode) AnalyseCorrectionMode();
233 else AnalyseDataMode();
234
235 PostData(0,fListOfHistos);
236}
237
238/******************** ANALYSIS METHODS *****************************/
239
240//____________________________________________________________________
241void AliAnalysisTaskPhiCorrelations::AddSettingsTree()
242{
243 //Write settings to output list
244 TTree *settingsTree = new TTree("UEAnalysisSettings","Analysis Settings in UE estimation");
245 settingsTree->Branch("fFilterBit", &fFilterBit,"FilterBit/I");
246 settingsTree->Branch("fSelectBit", &fSelectBit,"EventSelectionBit/I");
247 settingsTree->Branch("fTrackEtaCut", &fTrackEtaCut, "TrackEtaCut/D");
248 settingsTree->Branch("fPtMin", &fPtMin, "PtMin/D");
249 settingsTree->Branch("fUseChargeHadrons", &fUseChargeHadrons,"UseChHadrons/O");
250 settingsTree->Branch("fkTrackingEfficiency", "TH1D", &fkTrackingEfficiency);
251 settingsTree->Fill();
252 fListOfHistos->Add(settingsTree);
253}
254
255//____________________________________________________________________
256void AliAnalysisTaskPhiCorrelations::AnalyseCorrectionMode()
257{
258 // Run the analysis on MC to get the correction maps
259 //
260
2a910c25 261 if ( fDebug > 3 ) AliInfo( " Processing event in Corrections mode ..." );
262
263 Double_t centrality = 0;
264
265 if (fCentralityMethod.Length() > 0)
266 {
267 AliCentrality *centralityObj = fAOD->GetHeader()->GetCentralityP();
268 if (centralityObj)
269 {
270 centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
271 Printf("Centrality is %f", centrality);
272 }
273 else
274 {
275 Printf("WARNING: Centrality object is 0");
276 centrality = -1;
277 }
278 }
279
280 // count all events
281 fHistos->FillEvent(centrality, -1);
282
283 // Only consider MC events within the vtx-z region used also as cut on the reconstructed vertex
284 if (!fAnalyseUE->VertexSelection(fMcEvent, 0, fZVertex))
285 return;
286
287 // Get MC primaries
288 TObjArray* tracksMC = fAnalyseUE->GetAcceptedParticles(fArrayMC, 0, kTRUE, -1, kTRUE);
289
290 // (MC-true all particles)
291 // STEP 0
292 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepAll, tracksMC);
293
294 // Trigger selection ************************************************
295 if (fAnalyseUE->TriggerSelection(fInputHandler))
296 {
297 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
298
299 // Vertex selection *************************************************
300 if (fAnalyseUE->VertexSelection(fAOD, fnTracksVertex, fZVertex))
301 {
302 // fill here for tracking efficiency
303 // loop over particle species
304
305 for (Int_t particleSpecies = 0; particleSpecies < 4; particleSpecies++)
306 {
307 TObjArray* primMCParticles = fAnalyseUE->GetAcceptedParticles(fArrayMC, 0x0, kTRUE, particleSpecies, kTRUE);
308 TObjArray* primRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(fAOD, fArrayMC, kTRUE, particleSpecies, kTRUE);
309 TObjArray* allRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(fAOD, fArrayMC, kFALSE, particleSpecies, kTRUE);
310
311 fHistos->FillTrackingEfficiency(primMCParticles, primRecoTracksMatched, allRecoTracksMatched, particleSpecies, centrality);
312
313 delete primMCParticles;
314 delete primRecoTracksMatched;
315 delete allRecoTracksMatched;
316 }
317
318 // (MC-true all particles)
319 // STEP 2
320 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepVertex, tracksMC);
321
322 // Get MC primaries that match reconstructed track
323 TObjArray* tracksRecoMatchedPrim = fAnalyseUE->GetAcceptedParticles(fAOD, fArrayMC, kTRUE, -1, kTRUE);
324
325 // (RECO-matched (quantities from MC particle) primary particles)
326 // STEP 4
327 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepTrackedOnlyPrim, tracksRecoMatchedPrim);
328
329 // Get MC primaries + secondaries that match reconstructed track
330 TObjArray* tracksRecoMatchedAll = fAnalyseUE->GetAcceptedParticles(fAOD, fArrayMC, kFALSE, -1, kTRUE);
331
332 // (RECO-matched (quantities from MC particle) all particles)
333 // STEP 5
334 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepTracked, tracksRecoMatchedAll);
335
336 // Get RECO tracks
337 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(fAOD, 0, kTRUE, -1, kTRUE);
338
339 // (RECO all tracks)
340 // STEP 6
341 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepReconstructed, tracks);
342
343 if (1)
344 {
345 // make list of secondaries (matched with MC)
346 TObjArray* tracksRecoMatchedSecondaries = new TObjArray;
347 for (Int_t i=0; i<tracksRecoMatchedAll->GetEntries(); i++)
348 if (((AliAODMCParticle*)tracksRecoMatchedAll->At(i))->IsPhysicalPrimary() == kFALSE)
349 tracksRecoMatchedSecondaries->Add(tracksRecoMatchedAll->At(i));
350
351 // Study: Use only secondaries as trigger particles and plot the correlation vs. all particles; store in step 9
352 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepBiasStudy2, tracksRecoMatchedSecondaries, tracksRecoMatchedAll);
353
354 // Study: Use only primaries as trigger particles and plot the correlation vs. secondaries; store in step 8
355 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepBiasStudy, tracksRecoMatchedPrim, tracksRecoMatchedSecondaries);
356
357 // plot delta phi vs process id of secondaries
358 // trigger particles: primaries in 4 < pT < 10
359 // associated particles: secondaries in 1 < pT < 10
360
361 for (Int_t i=0; i<tracksRecoMatchedPrim->GetEntries(); i++)
362 {
363 AliVParticle* triggerParticle = (AliVParticle*) tracksRecoMatchedPrim->At(i);
364
365 if (triggerParticle->Pt() < 4 || triggerParticle->Pt() > 10)
366 continue;
367
368 for (Int_t j=0; j<tracksRecoMatchedSecondaries->GetEntries(); j++)
369 {
370 AliAODMCParticle* particle = (AliAODMCParticle*) tracksRecoMatchedSecondaries->At(j);
371
372 if (particle->Pt() < 1 || particle->Pt() > 10)
373 continue;
374
375 if (particle->Pt() > triggerParticle->Pt())
376 continue;
377
378 Double_t deltaPhi = triggerParticle->Phi() - particle->Phi();
379 if (deltaPhi > 1.5 * TMath::Pi())
380 deltaPhi -= TMath::TwoPi();
381 if (deltaPhi < -0.5 * TMath::Pi())
382 deltaPhi += TMath::TwoPi();
383
384 Int_t processID = fMcEvent->Stack()->Particle(particle->GetLabel())->GetUniqueID();
385
386 ((TH2F*) fListOfHistos->FindObject("processIDs"))->Fill(deltaPhi, processID);
387 }
388 }
389
390 delete tracksRecoMatchedSecondaries;
391 }
392
393 delete tracksRecoMatchedPrim;
394 delete tracksRecoMatchedAll;
395 delete tracks;
396 }
397 }
398
399 delete tracksMC;
e0331fd9 400}
401
402//____________________________________________________________________
403void AliAnalysisTaskPhiCorrelations::AnalyseDataMode()
404{
405
406 // Run the analysis on DATA or MC to get raw distributions
407
e0331fd9 408 if ( fDebug > 3 ) AliInfo( " Processing event in Data mode ..." );
e0331fd9 409
2a910c25 410 // skip not selected events here (the AOD is not updated for those)
411 if (!fInputHandler)
412 return;
413
414 if (!(fInputHandler->IsEventSelected()&AliVEvent::kMB))
415 return;
e0331fd9 416
2a910c25 417 Double_t centrality = 0;
418
419 if (fCentralityMethod.Length() > 0)
420 {
421 //AliCentrality *centralityObj = esd->GetCentrality();
422 AliCentrality *centralityObj = fAOD->GetHeader()->GetCentralityP();
423 if (centralityObj)
424 centrality = centralityObj->GetCentralityPercentile(fCentralityMethod);
425 //centrality = centralityObj->GetCentralityPercentileUnchecked(fCentralityMethod);
426 else
427 centrality = -1;
428 Printf("Centrality is %f", centrality);
429 }
430
431 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
432 fHistos->FillEvent(centrality, AliUEHist::kCFStepAll);
433
e0331fd9 434 // Trigger selection ************************************************
435 if (!fAnalyseUE->TriggerSelection(fInputHandler)) return;
436
437 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
2a910c25 438 fHistos->FillEvent(centrality, AliUEHist::kCFStepTriggered);
e0331fd9 439
440 // Vertex selection *************************************************
441 if(!fAnalyseUE->VertexSelection(fAOD, fnTracksVertex, fZVertex)) return;
442
443 // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
2a910c25 444 fHistos->FillEvent(centrality, AliUEHist::kCFStepVertex);
e0331fd9 445
2a910c25 446 if (centrality < 0)
447 return;
e0331fd9 448
449 TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(fAOD, 0, kTRUE, -1, kTRUE);
2a910c25 450 //Printf("Accepted %d tracks", tracks->GetEntries());
e0331fd9 451
2a910c25 452 // event mixing
e0331fd9 453
2a910c25 454 // 1. First get an event pool corresponding in mult (cent) and
455 // zvertex to the current event. Once initialized, the pool
456 // should contain nMix (reduced) events. This routine does not
457 // pre-scan the chain. The first several events of every chain
458 // will be skipped until the needed pools are filled to the
459 // specified depth. If the pool categories are not too rare, this
460 // should not be a problem. If they are rare, you could lose
461 // statistics.
462
463 // 2. Collect the whole pool's content of tracks into one TObjArray
464 // (bgTracks), which is effectively a single background super-event.
465
466 // 3. The reduced and bgTracks arrays must both be passed into
467 // FillCorrelations(). Also nMix should be passed in, so a weight
468 // of 1./nMix can be applied.
469
470 AliAODVertex* vertex = fAOD->GetPrimaryVertex();
471 Double_t zVtx = vertex->GetZ();
472
473 AliEventPool* pool = fPoolMgr->GetEventPool(centrality, zVtx);
474
475 if (!pool)
476 AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centrality, zVtx));
477
478 //pool->SetDebug(1);
e0331fd9 479
2a910c25 480 // Fill containers at STEP 6 (reconstructed)
481 fHistos->FillCorrelations(centrality, AliUEHist::kCFStepReconstructed, tracks);
482
483 if (pool->IsReady())
e0331fd9 484 {
2a910c25 485
486 Int_t nMix = pool->GetCurrentNEvents();
487 //cout << "nMix = " << nMix << endl;
488
489 // Fill mixed-event histos here
490 for (Int_t jMix=0; jMix<nMix; jMix++) {
491 TObjArray* bgTracks = pool->GetEvent(jMix);
492 fHistosMixed->FillCorrelations(centrality, AliUEHist::kCFStepReconstructed, tracks, bgTracks, 1.0 / nMix, (jMix == 0));
e0331fd9 493 }
494 }
495
2a910c25 496 // clone and give ownership to event pool
497 TObjArray* tracksClone = (TObjArray*) tracks->Clone();
498 tracksClone->SetOwner(kTRUE);
499
500 pool->UpdatePool(tracksClone);
501 //pool->PrintInfo();
502
e0331fd9 503 delete tracks;
e0331fd9 504}
505
506//____________________________________________________________________
507void AliAnalysisTaskPhiCorrelations::Initialize()
508{
509 // input handler
510 fInputHandler = (AliInputEventHandler*)
511 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
512 // MC handler
513 fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
514}