]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/JetTasks/AliAnalysisTaskPhiCorrelations.cxx
Rewritten spectrum2 task, old running is optional, various minor updates to AddTask...
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliAnalysisTaskPhiCorrelations.cxx
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>
25 #include <TRandom.h>
26
27 #include "AliAnalysisTaskPhiCorrelations.h"
28 #include "AliAnalyseLeadingTrackUE.h"
29 #include "AliUEHistograms.h"
30 #include "AliUEHist.h"
31
32 #include "AliAnalysisHelperJetTasks.h"
33 #include "AliAnalysisManager.h"
34 #include "AliAODHandler.h"
35 #include "AliAODInputHandler.h"
36 #include "AliAODMCParticle.h"
37 #include "AliGenPythiaEventHeader.h"
38 #include "AliInputEventHandler.h"
39 #include "AliLog.h"
40 #include "AliMCEventHandler.h"
41 #include "AliVParticle.h"
42
43 #include "AliESDEvent.h"
44 #include "AliESDInputHandler.h"
45 #include "AliMultiplicity.h"
46
47 #include "EventMixing/AliMixEventInputHandler.h"
48
49
50 ////////////////////////////////////////////////////////////////////////
51 //
52 // Analysis class for azimuthal correlation studies
53 // Based on the UE task from Sara Vallero and Jan Fiete
54 //
55 // This class needs input AODs.
56 // The output is a list of analysis-specific containers.
57 //
58 // The AOD can be either connected to the InputEventHandler  
59 // for a chain of AOD files 
60 // or 
61 // to the OutputEventHandler
62 // for a chain of ESD files,
63 // in this case the class should be in the train after the jet-finder
64 //
65 //    Authors:
66 //    Jan Fiete Grosse-Oetringhaus
67 // 
68 ////////////////////////////////////////////////////////////////////////
69
70
71 ClassImp( AliAnalysisTaskPhiCorrelations )
72
73 //____________________________________________________________________
74 AliAnalysisTaskPhiCorrelations:: AliAnalysisTaskPhiCorrelations(const char* name):
75 AliAnalysisTask(name,""),
76 // general configuration
77 fDebug(0),
78 fMode(0),
79 fReduceMemoryFootprint(kFALSE),
80 // pointers to UE classes
81 fAnalyseUE(0x0),
82 fHistos(0x0),
83 fHistosMixed(0),
84 fkTrackingEfficiency(0x0),
85 // handlers and events
86 fAOD(0x0),           
87 fArrayMC(0x0),
88 fInputHandler(0x0),
89 fMcEvent(0x0),
90 fMcHandler(0x0),
91 // histogram settings
92 fListOfHistos(0x0), 
93 // event QA
94 fnTracksVertex(1),  // QA tracks pointing to principal vertex (= 3 default) 
95 fZVertex(10.),
96 // track cuts
97 fTrackEtaCut(0.8),
98 fPtMin(0.5),
99 fFilterBit(0xFF),
100 fSelectBit(0),
101 fUseChargeHadrons(kFALSE)
102 {
103   // Default constructor
104   // Define input and output slots here
105   // Input slot #0 works with a TChain
106   DefineInput(0, TChain::Class());
107   // Output slot #0 writes into a TList container
108   DefineOutput(0, TList::Class());
109
110 }
111
112 AliAnalysisTaskPhiCorrelations::~AliAnalysisTaskPhiCorrelations() 
113
114   // destructor
115   
116   if (fListOfHistos  && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) 
117     delete fListOfHistos;
118 }
119
120 //____________________________________________________________________
121 void AliAnalysisTaskPhiCorrelations::ConnectInputData(Option_t* /*option*/)
122 {
123   
124   // Connect the input data  
125   if (fDebug > 1) AliInfo("ConnectInputData() ");
126   
127   // Since AODs can either be connected to the InputEventHandler
128   // or to the OutputEventHandler ( the AOD is created by a previus task in the train )
129   // we need to get the pointer to the AODEvent correctly.
130   
131   // Delta AODs are also accepted.
132   
133   TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
134   
135   if( handler && handler->InheritsFrom("AliAODInputHandler") ) { // input AOD
136         fAOD = ((AliAODInputHandler*)handler)->GetEvent();
137         if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODInputHandler");
138   } else {  //output AOD
139         handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
140         if( handler && handler->InheritsFrom("AliAODHandler") ) {
141                 fAOD = ((AliAODHandler*)handler)->GetAOD();
142                 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODHandler");
143         } else {  // no AOD
144                 AliFatal("I can't get any AOD Event Handler");
145                 return;
146                 }
147         }       
148   
149   // Initialize common pointers
150   Initialize();
151    
152 }
153
154 //____________________________________________________________________
155 void  AliAnalysisTaskPhiCorrelations::CreateOutputObjects()
156 {
157   // Create the output container
158   
159   if (fDebug > 1) AliInfo("CreateOutputObjects()");
160    
161   // Initialize class with main algorithms, event and track selection. 
162   fAnalyseUE = new AliAnalyseLeadingTrackUE();
163   fAnalyseUE->SetParticleSelectionCriteria(fFilterBit, fUseChargeHadrons, fTrackEtaCut, 1.0);
164   fAnalyseUE->SetDebug(fDebug); 
165   fAnalyseUE->DefineESDCuts(0);
166
167   // Initialize output list of containers
168   if (fListOfHistos != NULL){
169         delete fListOfHistos;
170         fListOfHistos = NULL;
171         }
172   if (!fListOfHistos){
173         fListOfHistos = new TList();
174         fListOfHistos->SetOwner(kTRUE); 
175         }
176
177   // Initialize class to handle histograms 
178   fHistos = new AliUEHistograms("AliUEHistogramsSame", "4");
179   fHistosMixed = new AliUEHistograms("AliUEHistogramsMixed", "4");
180   
181   // add histograms to list
182   fListOfHistos->Add(fHistos);
183   fListOfHistos->Add(fHistosMixed);
184   
185   //fListOfHistos->Add(new TH2F("multVsLeadStep5", ";multiplicity;leading pT", 100, -0.5, 99.5, 20, 0, 10));
186   
187   // Add task configuration to output list 
188   AddSettingsTree();
189
190   PostData(0,fListOfHistos);
191 }
192
193 //____________________________________________________________________
194 void  AliAnalysisTaskPhiCorrelations::Exec(Option_t */*option*/)
195 {
196   // array of MC particles
197   if (fMcHandler){
198         fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
199         if (!fArrayMC)AliFatal("No array of MC particles found !!!");
200         }
201
202   // Analyse the event
203   if (fMode) AnalyseCorrectionMode();
204   else AnalyseDataMode();
205
206   PostData(0,fListOfHistos);
207 }
208
209 /******************** ANALYSIS METHODS *****************************/
210
211 //____________________________________________________________________
212 void  AliAnalysisTaskPhiCorrelations::AddSettingsTree()
213 {
214   //Write settings to output list
215   TTree *settingsTree   = new TTree("UEAnalysisSettings","Analysis Settings in UE estimation");
216   settingsTree->Branch("fFilterBit", &fFilterBit,"FilterBit/I");
217   settingsTree->Branch("fSelectBit", &fSelectBit,"EventSelectionBit/I");
218   settingsTree->Branch("fTrackEtaCut", &fTrackEtaCut, "TrackEtaCut/D");
219   settingsTree->Branch("fPtMin", &fPtMin, "PtMin/D");
220   settingsTree->Branch("fUseChargeHadrons", &fUseChargeHadrons,"UseChHadrons/O");
221   settingsTree->Branch("fkTrackingEfficiency", "TH1D", &fkTrackingEfficiency);
222   settingsTree->Fill();
223   fListOfHistos->Add(settingsTree);
224 }  
225
226 //____________________________________________________________________
227 void  AliAnalysisTaskPhiCorrelations::AnalyseCorrectionMode()
228 {
229   // Run the analysis on MC to get the correction maps
230   //
231  
232 }
233
234 //____________________________________________________________________
235 void  AliAnalysisTaskPhiCorrelations::AnalyseDataMode()
236 {
237
238   // Run the analysis on DATA or MC to get raw distributions
239  
240   PostData(0,fListOfHistos);
241   
242   if ( fDebug > 3 ) AliInfo( " Processing event in Data mode ..." );
243   Int_t eventId = 0;
244
245   // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
246   fHistos->FillEvent(eventId, AliUEHist::kCFStepAll);
247
248   // Trigger selection ************************************************
249   if (!fAnalyseUE->TriggerSelection(fInputHandler)) return;
250   
251   // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
252   fHistos->FillEvent(eventId, AliUEHist::kCFStepTriggered);
253   
254   // Vertex selection *************************************************
255   if(!fAnalyseUE->VertexSelection(fAOD, fnTracksVertex, fZVertex)) return;
256   
257   // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
258   fHistos->FillEvent(eventId, AliUEHist::kCFStepVertex);
259  
260   // TODO HACK centrality should be retrieved from AOD, this needs the ESD
261   AliESDInputHandler* handler = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
262   AliESDEvent* esd = handler->GetEvent();
263   Int_t centrality = esd->GetMultiplicity()->GetNumberOfITSClusters(1);
264
265   TObjArray* tracks = fAnalyseUE->GetAcceptedParticles(fAOD, 0, kTRUE, -1, kTRUE);
266   
267   // reduce to pt and eta range
268   /*
269   TObjArray* reduced = new TObjArray;
270   for (Int_t i=0; i<tracks->GetEntries(); i++)
271   {
272     AliVParticle* particle = (AliVParticle*) tracks->At(i);
273     if (TMath::Abs(particle->Eta()) < fTrackEtaCut && particle->Pt() > fPtMin)
274       reduced->Add(particle);
275   }
276   */
277   
278   // Fill containers at STEP 6 (reconstructed)
279   fHistos->FillCorrelations(eventId, centrality, AliUEHist::kCFStepReconstructed, tracks);
280     
281   AliInfo("**Main Event");
282   AliInfo(Form("  Tracklets %d", fAOD->GetTracklets()->GetNumberOfTracklets()));
283   AliInfo(Form("  Vz %f", fAOD->GetPrimaryVertex()->GetZ()));  
284
285   AliMixEventInputHandler* mixEH = (AliMixEventInputHandler*) fInputHandler->MixingHandler();
286   if (mixEH)
287   {
288     mixEH->GetEntry();
289     AliInfo(Form("num mixed %d", mixEH->MixedEventNumber()));
290           
291     if (mixEH->MixedEventNumber() > 0) 
292     {
293       // TODO in principle need to apply same quality cuts as above
294       // or somewhere before on the level of the pool (would be more efficient)
295       for (Int_t i = 0; i < mixEH->BufferSize(); i++) 
296       {
297         AliESDEvent *eventMix = (AliESDEvent*) mixEH->InputEventHandler(i)->GetEvent();
298         if (!eventMix) {
299           AliError(Form("Could not retrieve event %d", i));
300         }
301         else 
302         {
303           AliInfo(Form("**Mixed Event %d", i));
304           AliInfo(Form("  Tracklets %d", eventMix->GetMultiplicity()->GetNumberOfTracklets()));
305           AliInfo(Form("  Vz %f", eventMix->GetPrimaryVertex()->GetZ()));
306           
307           TObjArray* tracksMixed = fAnalyseUE->GetAcceptedParticles(eventMix, 0, kTRUE, -1, kTRUE);
308           
309           fHistosMixed->FillCorrelations(eventId, centrality, AliUEHist::kCFStepReconstructed, tracks, tracksMixed);
310           
311           tracksMixed->SetOwner(); // contains tpc only tracks, that is why we have to delete the content as well
312           delete tracksMixed;
313           
314         }
315       }
316     }
317   }
318   
319   delete tracks;
320   //delete reduced;
321 }
322
323 //____________________________________________________________________
324 void  AliAnalysisTaskPhiCorrelations::Initialize()
325 {
326   // input handler
327   fInputHandler = (AliInputEventHandler*)
328          ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
329   // MC handler
330   fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
331 }
332
333
334
335
336
337