]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/JetTasks/AliAnalysisTaskLeadingTrackUE.cxx
New analysis devoted to shower shape studies
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliAnalysisTaskLeadingTrackUE.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 //#include <TVector3.h>
27
28 #include "AliAnalysisTaskLeadingTrackUE.h"
29 #include "AliAnalyseLeadingTrackUE.h"
30 #include "AliUEHistograms.h"
31 #include "AliUEHist.h"
32
33 #include "AliAnalysisHelperJetTasks.h"
34 #include "AliAnalysisManager.h"
35 #include "AliAODHandler.h"
36 #include "AliAODInputHandler.h"
37 #include "AliAODMCParticle.h"
38 #include "AliGenPythiaEventHeader.h"
39 #include "AliInputEventHandler.h"
40 #include "AliLog.h"
41 #include "AliMCEventHandler.h"
42 #include "AliVParticle.h"
43
44
45 ////////////////////////////////////////////////////////////////////////
46 //
47 // Analysis class for Underlying Event studies w.r.t. leading track
48 //
49 // Look for correlations on the tranverse regions w.r.t
50 // the leading track in the event
51 //
52 // This class needs input AODs.
53 // The output is a list of analysis-specific containers.
54 //
55 // The AOD can be either connected to the InputEventHandler  
56 // for a chain of AOD files 
57 // or 
58 // to the OutputEventHandler
59 // for a chain of ESD files,
60 // in this case the class should be in the train after the jet-finder
61 //
62 //    Authors:
63 //    Arian Abrahantes Quintana 
64 //    Jan Fiete Grosse-Oetringhaus
65 //    Ernesto Lopez Torres
66 //    Sara Vallero
67 // 
68 ////////////////////////////////////////////////////////////////////////
69
70
71 ClassImp( AliAnalysisTaskLeadingTrackUE )
72
73 // Define global pointer
74 AliAnalysisTaskLeadingTrackUE* AliAnalysisTaskLeadingTrackUE::fgTaskLeadingTrackUE=NULL;
75
76 //____________________________________________________________________
77 AliAnalysisTaskLeadingTrackUE:: AliAnalysisTaskLeadingTrackUE(const char* name):
78 AliAnalysisTask(name,""),
79 // general configuration
80 fDebug(0),
81 fMode(0),
82 fReduceMemoryFootprint(kFALSE),
83 // pointers to UE classes
84 fAnalyseUE(0x0),
85 fHistosUE(0x0),
86 fkTrackingEfficiency(0x0),
87 // handlers and events
88 fAOD(0x0),           
89 fArrayMC(0x0),
90 fInputHandler(0x0),
91 fMcEvent(0x0),
92 fMcHandler(0x0),
93 // histogram settings
94 fListOfHistos(0x0), 
95 fBinsPtInHist(30),     
96 fMinJetPtInHist(0.),
97 fMaxJetPtInHist(300.), 
98 // event QA
99 fnTracksVertex(1),  // QA tracks pointing to principal vertex (= 3 default) 
100 fZVertex(10.),
101 // track cuts
102 fTrackEtaCut(0.8),
103 fLeadingTrackEtaCut(0.8),
104 fFilterBit(0xFF),
105 fSelectBit(0),
106 fUseChargeHadrons(kFALSE),
107 //For MC weighting
108 fAvgTrials(1)
109 {
110   // Default constructor
111   // Define input and output slots here
112   // Input slot #0 works with a TChain
113   DefineInput(0, TChain::Class());
114   // Output slot #0 writes into a TList container
115   DefineOutput(0, TList::Class());
116
117 }
118
119 AliAnalysisTaskLeadingTrackUE::~AliAnalysisTaskLeadingTrackUE() 
120
121   // destructor
122   
123   if (fListOfHistos  && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) 
124     delete fListOfHistos;
125 }
126
127 /************** INTERFACE METHODS *****************************/
128
129 //______________________________________________________________
130 Bool_t AliAnalysisTaskLeadingTrackUE::Notify()
131 {
132   
133   // Implemented Notify() to read the cross sections
134   // and number of trials from pyxsec.root.
135   // This will be used when merging different MC samples.
136   // (Copied from AliAnalysisTaskJFSystematics)
137   
138   fAvgTrials = 1;
139   TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
140   Float_t xsection = 0;
141   Float_t trials  = 1;
142   if(tree){
143         TFile *curfile = tree->GetCurrentFile();
144         if (!curfile) {
145                 Error("Notify","No current file");
146                 return kFALSE;
147                 }
148         
149         AliAnalysisHelperJetTasks::PythiaInfoFromFile(curfile->GetName(),xsection,trials); 
150         
151         //TO-DO
152         //fHistosUE->GetXsec()->Fill("<#sigma>",xsection);
153
154         // construct average trials
155         Float_t nEntries = (Float_t)tree->GetTree()->GetEntries();
156         if(trials>=nEntries && nEntries>0.)fAvgTrials = trials/nEntries;
157         }
158   
159   return kTRUE;
160 }
161
162 //____________________________________________________________________
163 void AliAnalysisTaskLeadingTrackUE::ConnectInputData(Option_t* /*option*/)
164 {
165   
166   // Connect the input data  
167   if (fDebug > 1) AliInfo("ConnectInputData() ");
168   
169   // Since AODs can either be connected to the InputEventHandler
170   // or to the OutputEventHandler ( the AOD is created by a previus task in the train )
171   // we need to get the pointer to the AODEvent correctly.
172   
173   // Delta AODs are also accepted.
174   
175   TObject* handler = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
176   
177   if( handler && handler->InheritsFrom("AliAODInputHandler") ) { // input AOD
178         fAOD = ((AliAODInputHandler*)handler)->GetEvent();
179         if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODInputHandler");
180   } else {  //output AOD
181         handler = AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler();
182         if( handler && handler->InheritsFrom("AliAODHandler") ) {
183                 fAOD = ((AliAODHandler*)handler)->GetAOD();
184                 if (fDebug > 1) AliInfo(" ==== Tracks and Jets from AliAODHandler");
185         } else {  // no AOD
186                 AliFatal("I can't get any AOD Event Handler");
187                 return;
188                 }
189         }       
190   
191   // Initialize common pointers
192   Initialize();
193    
194 }
195
196 //____________________________________________________________________
197 void  AliAnalysisTaskLeadingTrackUE::CreateOutputObjects()
198 {
199   // Create the output container
200   
201   if (fDebug > 1) AliInfo("CreateOutputObjects()");
202    
203   // Initialize class with main algorithms, event and track selection. 
204   fAnalyseUE = new AliAnalyseLeadingTrackUE();
205   fAnalyseUE->SetParticleSelectionCriteria(fFilterBit, fUseChargeHadrons, fLeadingTrackEtaCut);
206   fAnalyseUE->SetDebug(fDebug); 
207
208   // Initialize output list of containers
209   if (fListOfHistos != NULL){
210         delete fListOfHistos;
211         fListOfHistos = NULL;
212         }
213   if (!fListOfHistos){
214         fListOfHistos = new TList();
215         fListOfHistos->SetOwner(kTRUE); 
216         }
217
218   // Initialize class to handle histograms 
219   fHistosUE = new AliUEHistograms;
220   
221   // add histograms to list
222   fListOfHistos->Add(fHistosUE);
223   
224   //fListOfHistos->Add(new TH2F("multVsLeadStep5", ";multiplicity;leading pT", 100, -0.5, 99.5, 20, 0, 10));
225   
226   // Add task configuration to output list 
227   AddSettingsTree();
228   
229
230   PostData(0,fListOfHistos);
231 }
232
233 //____________________________________________________________________
234 void  AliAnalysisTaskLeadingTrackUE::Exec(Option_t */*option*/)
235 {
236   // array of MC particles
237   if (fMcHandler){
238         fArrayMC = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
239         if (!fArrayMC)AliFatal("No array of MC particles found !!!");
240         }
241
242   // Get number of trials from MC header
243   Float_t nTrials = 1;
244   if (fMcHandler) {
245         fMcEvent = fMcHandler->MCEvent();
246         if (fMcEvent) {
247                 // TO-DO: extend to PHOJET
248                 AliGenPythiaEventHeader*  pythiaGenHeader = AliAnalysisHelperJetTasks::GetPythiaEventHeader(fMcEvent);
249                 if(pythiaGenHeader){
250                         nTrials = pythiaGenHeader->Trials();
251                         }
252                 }
253         }
254
255   // TO-DO      
256   //fHistosUE->GetTrials()->Fill("#sum{ntrials}",fAvgTrials);
257   
258   // Analyse the event
259   if (fMode) AnalyseCorrectionMode();
260   else AnalyseDataMode();
261
262   PostData(0,fListOfHistos);
263 }
264
265 //____________________________________________________________________
266 void  AliAnalysisTaskLeadingTrackUE::Terminate(Option_t */*option*/)
267 {
268   
269   // Terminate analysis
270   if( fDebug > 1 ) AliInfo("End analysis");
271
272   if (!gROOT->IsBatch()){
273         fListOfHistos = dynamic_cast<TList*> (GetOutputData(0));
274         if (!fListOfHistos){
275                 AliError("Histogram List is not available");
276                 return;
277         }else{
278         // Draw something
279         }
280   } else {
281         AliInfo(" Batch mode, not histograms will be shown...");
282         }
283
284 }
285
286
287 /******************** ANALYSIS METHODS *****************************/
288
289 //____________________________________________________________________
290 void  AliAnalysisTaskLeadingTrackUE::AddSettingsTree()
291 {
292   //Write settings to output list
293   TTree *settingsTree   = new TTree("UEAnalysisSettings","Analysis Settings in UE estimation");
294   settingsTree->Branch("fFilterBit", &fFilterBit,"FilterBit/I");
295   settingsTree->Branch("fSelectBit", &fSelectBit,"EventSelectionBit/I");
296   settingsTree->Branch("fLeadingTrackEtaCut", &fLeadingTrackEtaCut, "LeadingTrackEtaCut/D");
297   settingsTree->Branch("fUseChargeHadrons", &fUseChargeHadrons,"UseChHadrons/O");
298   settingsTree->Fill();
299   fListOfHistos->Add(settingsTree);
300 }  
301
302 //____________________________________________________________________
303 void  AliAnalysisTaskLeadingTrackUE::AnalyseCorrectionMode()
304 {
305   // Run the analysis on MC to get the correction maps
306   //
307   // if fReduceMemoryFootprint step 3,4,5,7,9 are not filled
308
309   PostData(0,fListOfHistos);
310   
311   if ( fDebug > 3 ) AliInfo( " Processing event in Corrections mode ..." );
312   
313   //PROCESS TYPE (ND,SD,DD)
314   AliAnalysisHelperJetTasks::MCProcessType eventId = AliAnalysisHelperJetTasks::kInvalidProcess;
315   if (fMcHandler && fMcEvent) {
316         AliGenEventHeader* genHeader = fMcEvent->GenEventHeader();
317         eventId = AliAnalysisHelperJetTasks::GetPythiaEventProcessType(genHeader,kFALSE);
318         if (eventId<0){
319         eventId = AliAnalysisHelperJetTasks::GetDPMjetEventProcessType(genHeader,kFALSE);
320         }
321         if (eventId<0 && fDebug>1)AliInfo("No Pythia or Phojet Header retrived!"); 
322         } 
323   Int_t fillId=-1;
324   if (eventId == AliAnalysisHelperJetTasks::kND)fillId = 0; 
325   if (eventId == AliAnalysisHelperJetTasks::kSD)fillId = 1; 
326   if (eventId == AliAnalysisHelperJetTasks::kDD)fillId = 2; 
327   
328   // count all events
329   fHistosUE->FillEvent(fillId, -1);
330   
331   // Only consider MC events within the vtx-z region used also as cut on the reconstructed vertex
332   if (!fAnalyseUE->VertexSelection(fMcEvent, 0, fZVertex)) 
333     return;
334   
335   // Get MC-true leading particle (but do not cut out events!)
336   TObjArray *ltMC = (TObjArray*)fAnalyseUE->FindLeadingObjects(fArrayMC);
337   AliVParticle* leadingMC = 0;
338   if (ltMC)
339     leadingMC = (AliVParticle*) ltMC->At(0);
340     
341   // it can happen that there is no MC leading particle in the acceptance required (|eta|<0.8)
342   // and we do not want to base the event slection on MC information
343   
344   // Sort MC-true charged particles
345   // as output you get an array of 3 lists of  particles belonging to different regions:
346   // - at 0: towards
347   // - at 1: away
348   // - at 2: transverse MIN
349   // - at 3: transverse MAX
350   TObjArray *regionSortedParticlesMC = (TObjArray*)fAnalyseUE->SortRegions(leadingMC, fArrayMC, 0x0); 
351   TObjArray *regionsMinMaxMC = (TObjArray*)fAnalyseUE->GetMinMaxRegion((TList*)regionSortedParticlesMC->At(2),(TList*)regionSortedParticlesMC->At(3));
352   // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
353   // (MC-true leading particle and MC-true all particles)
354   // STEP 0
355   fHistosUE->Fill(fillId,AliUEHist::kCFStepAll,leadingMC,(TList*)regionSortedParticlesMC->At(0),(TList*)regionSortedParticlesMC->At(1),(TList*)regionsMinMaxMC->At(0),(TList*)regionsMinMaxMC->At(1));
356   
357   // Trigger selection ************************************************
358   if (fAnalyseUE->TriggerSelection(fInputHandler))
359   {
360     // PILEUP-CUT 
361     Bool_t select = kFALSE;
362     if (fSelectBit) select = AliAnalysisHelperJetTasks::TestSelectInfo(fSelectBit);
363     if (select)
364       fHistosUE->FillEvent(fillId, -2);
365     else
366     {
367     
368             // Count events that pass AliPhysicsSelection
369     
370             // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
371             // (MC-true leading particle and MC-true all particles)
372             // STEP 1
373             fHistosUE->Fill(fillId,AliUEHist::kCFStepTriggered,leadingMC,(TList*)regionSortedParticlesMC->At(0),(TList*)regionSortedParticlesMC->At(1),(TList*)regionsMinMaxMC->At(0),(TList*)regionsMinMaxMC->At(1));
374   
375             // count number of MC tracks above 150 MeV/c
376             Int_t nMCTracks = 0; 
377             if (leadingMC && leadingMC->Pt() > 0.15)
378               nMCTracks++;
379             for (Int_t i=0; i<4; i++)
380               for (Int_t j=0; j<((TList*)regionSortedParticlesMC->At(i))->GetEntries(); j++)
381                 if (((AliVParticle*) ((TList*)regionSortedParticlesMC->At(i))->At(j))->Pt() > 0.15)
382                   nMCTracks++;
383       
384             //((TH2F*)fListOfHistos->FindObject("multVsLeadStep5"))->Fill(nMCTracks, leadingMC->Pt());
385     
386             // Vertex selection *************************************************
387             if (fAnalyseUE->VertexSelection(fAOD, fnTracksVertex, fZVertex))
388             {
389               // Count events that pass Vertex selection
390             
391               // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
392               // (MC-true leading particle and MC-true all particles)
393               // STEP 2
394               fHistosUE->Fill(fillId,AliUEHist::kCFStepVertex,leadingMC,(TList*)regionSortedParticlesMC->At(0),(TList*)regionSortedParticlesMC->At(1),(TList*)regionsMinMaxMC->At(0),(TList*)regionsMinMaxMC->At(1));
395     
396               // fill here for tracking efficiency
397               // loop over particle species
398               for (Int_t particleSpecies = 0; particleSpecies < 4; particleSpecies++)
399               {
400                 TObjArray* primMCParticles = fAnalyseUE->GetAcceptedParticles(fArrayMC, 0x0, kTRUE, particleSpecies);
401                 TObjArray* primRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(fAOD, fArrayMC, kTRUE, particleSpecies);
402                 TObjArray* allRecoTracksMatched = fAnalyseUE->GetAcceptedParticles(fAOD, fArrayMC, kFALSE, particleSpecies);
403               
404                 fHistosUE->FillTrackingEfficiency(primMCParticles, primRecoTracksMatched, allRecoTracksMatched, particleSpecies);
405               
406                 delete primMCParticles;
407                 delete primRecoTracksMatched;
408                 delete allRecoTracksMatched;
409               }
410       
411               // Get Reconstructed leading particle *******************************
412               TObjArray *ltRECO = fAnalyseUE->FindLeadingObjects(fAOD);
413               if (ltRECO)
414               {
415                 // Count events where a reconstructed track was found in |eta|<0.8
416                 // the pT cut will be set when projecting output containers
417                 // for leading particle correlation plots
418                 if (leadingMC) {
419                       fHistosUE->Fill(leadingMC, (AliVParticle*)ltRECO->At(0));
420                       }
421               
422                 // If there is no MC leading track the container is not filled, so the number of entries in the container might be different  
423                 // from the number of events after the selection, since the selection is based on RECO tracks
424                 // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
425                 // (MC-true leading particle and MC-true all particles)
426                 // STEP 3
427                 if (!fReduceMemoryFootprint)
428                   fHistosUE->Fill(fillId,AliUEHist::kCFStepAnaTopology,leadingMC,(TList*)regionSortedParticlesMC->At(0),(TList*)regionSortedParticlesMC->At(1),(TList*)regionsMinMaxMC->At(0),(TList*)regionsMinMaxMC->At(1));
429       
430                 //Sort RECO particles w.r.t. MC-leading and return matched (primary) MC particle 
431                 // (you cannot sort tracks w.r.t. RECO-leading and plot it vs. MC-leading ...)
432                 TObjArray *regionSortedParticlesRECOLTMC = (TObjArray*)fAnalyseUE->SortRegions(leadingMC, fAOD, fArrayMC, kTRUE); 
433                 TObjArray *regionsMinMaxRECOLTMC = (TObjArray*)fAnalyseUE->GetMinMaxRegion((TList*)regionSortedParticlesRECOLTMC->At(2),(TList*)regionSortedParticlesRECOLTMC->At(3));
434                 // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
435                 // (MC leading particle and RECO-matched (quantities from MC particle)  all particles)
436                 // STEP 4
437                 if (!fReduceMemoryFootprint)
438                   fHistosUE->Fill(fillId,AliUEHist::kCFStepTrackedOnlyPrim,leadingMC,(TList*)regionSortedParticlesRECOLTMC->At(0),(TList*)regionSortedParticlesRECOLTMC->At(1),(TList*)regionsMinMaxRECOLTMC->At(0),(TList*)regionsMinMaxRECOLTMC->At(1));
439                 // comparing this step with step 3 (for all-tracks observables) you get the tracking efficiency
440         
441                 //Sort RECO particles w.r.t. MC-leading and return matched (primary+secondary) MC particle 
442                 // (you cannot sort tracks w.r.t. RECO-leading and plot it vs. MC-leading ...)
443                 TObjArray *regionSortedParticlesRECOLTMC2 = (TObjArray*)fAnalyseUE->SortRegions(leadingMC, fAOD, fArrayMC,kFALSE); 
444                 TObjArray *regionsMinMaxRECOLTMC2 = (TObjArray*)fAnalyseUE->GetMinMaxRegion((TList*)regionSortedParticlesRECOLTMC2->At(2),(TList*)regionSortedParticlesRECOLTMC2->At(3));
445         
446                 // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
447                 // (MC leading particle and RECO-matched (quantities from MC particle)  all particles)
448                 // STEP 5
449                 if (!fReduceMemoryFootprint)
450                   fHistosUE->Fill(fillId,AliUEHist::kCFStepTracked,leadingMC,(TList*)regionSortedParticlesRECOLTMC2->At(0),(TList*)regionSortedParticlesRECOLTMC2->At(1),(TList*)regionsMinMaxRECOLTMC2->At(0),(TList*)regionsMinMaxRECOLTMC2->At(1));
451                 // comparing this step with step 3 (for all-tracks observables) you get the tracking efficiency
452           
453                 // SWITCH TO RECONSTRUCTED TRACKS  ************************************
454                 // The next steps correspond to track selections
455                 // Sort RECO particles w.r.t. RECO-leading and return RECO particle  
456                 TObjArray *regionSortedParticlesRECO = (TObjArray*)fAnalyseUE->SortRegions((AliVParticle*)ltRECO->At(0), fAOD,0); 
457                 TObjArray *regionsMinMaxRECO = (TObjArray*)fAnalyseUE->GetMinMaxRegion((TList*)regionSortedParticlesRECO->At(2),(TList*)regionSortedParticlesRECO->At(3));
458                 // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
459                 // (RECO leading particle and RECO  all particles)
460                 // STEP 6
461                 fHistosUE->Fill(fillId,AliUEHist::kCFStepReconstructed,(AliVParticle*)ltRECO->At(0),(TList*)regionSortedParticlesRECO->At(0),(TList*)regionSortedParticlesRECO->At(1),(TList*)regionsMinMaxRECO->At(0),(TList*)regionsMinMaxRECO->At(1));
462         
463                 // STEP 8 for reduced efficiency study
464                 FillReducedEfficiency(fillId, AliUEHist::kCFStepBiasStudy, ltRECO, kFALSE);
465                 if (!fReduceMemoryFootprint)
466                   FillReducedEfficiency(fillId, AliUEHist::kCFStepBiasStudy2, ltRECO, kTRUE);
467         
468                 // count number of reco tracks above 150 MeV/c
469                 Int_t nRecoTracks = 0; 
470                 if (((AliVParticle*) ltRECO->At(0))->Pt() > 0.15)
471                   nRecoTracks++;
472                 for (Int_t i=0; i<4; i++)
473                   for (Int_t j=0; j<((TList*)regionSortedParticlesRECO->At(i))->GetEntries(); j++)
474                     if (((AliVParticle*) ((TList*)regionSortedParticlesRECO->At(i))->At(j))->Pt() > 0.15)
475                       nRecoTracks++;
476                 
477                 if (leadingMC && leadingMC->Pt() > 0.5)
478                   fHistosUE->GetCorrelationMultiplicity()->Fill(nMCTracks, nRecoTracks);
479         
480                 if (leadingMC)
481                 {
482                   // Match reco leading track with true *********************************
483                   Int_t recoLabel = ((AliAODTrack*)ltRECO->At(0))->GetLabel();
484                   Int_t mcLabel   = ((AliAODMCParticle*)leadingMC)->GetLabel();
485                   if (recoLabel != mcLabel) 
486                     return;
487           
488                   // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
489                   // (RECO-MATCHED leading particle and RECO all particles)
490                   // STEP 7
491                   fHistosUE->Fill(fillId,AliUEHist::kCFStepRealLeading,(AliVParticle*)ltRECO->At(0),(TList*)regionSortedParticlesRECO->At(0),(TList*)regionSortedParticlesRECO->At(1),(TList*)regionsMinMaxRECO->At(0),(TList*)regionsMinMaxRECO->At(1));
492                   // comparing this step with step 6 (for leading-track observables) you get the efficiency to reconstruct the leading track
493                   // comparing this step with step 6 (for all-tracks observables) you see how leading-track misidentification affects the final distributions
494                 }
495         
496                 delete regionSortedParticlesRECOLTMC;
497                 delete regionsMinMaxRECOLTMC;
498                 delete regionSortedParticlesRECOLTMC2;
499                 delete regionsMinMaxRECOLTMC2;
500                 delete regionSortedParticlesRECO;
501                 delete regionsMinMaxRECO;
502                 delete ltRECO;
503               } // lt reco
504         } // vertex
505     } // pileup
506   } //phyiscs selection
507   
508   if (ltMC)
509     delete ltMC;
510   delete regionSortedParticlesMC;
511   delete regionsMinMaxMC;
512 }
513
514 //____________________________________________________________________
515 void  AliAnalysisTaskLeadingTrackUE::AnalyseDataMode()
516 {
517
518   // Run the analysis on DATA or MC to get raw distributions
519  
520   PostData(0,fListOfHistos);
521   
522   if ( fDebug > 3 ) AliInfo( " Processing event in Data mode ..." );
523   Int_t eventId = 0;
524
525   // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
526   fHistosUE->FillEvent(eventId, AliUEHist::kCFStepAll);
527
528   // Trigger selection ************************************************
529   if (!fAnalyseUE->TriggerSelection(fInputHandler)) return;
530   // PILEUP-CUT 
531   Bool_t select = kFALSE;
532   if (fSelectBit) select = AliAnalysisHelperJetTasks::TestSelectInfo(fSelectBit);
533   if (select) 
534   {
535     fHistosUE->FillEvent(eventId, -2);
536     return;
537   }
538   // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
539   fHistosUE->FillEvent(eventId, AliUEHist::kCFStepTriggered);
540   
541   // Vertex selection *************************************************
542   if(!fAnalyseUE->VertexSelection(fAOD, fnTracksVertex, fZVertex)) return;
543   // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
544   fHistosUE->FillEvent(eventId, AliUEHist::kCFStepVertex);
545   // comparing this step with previous one you get the vertex selection efficiency from data (?)
546  
547
548   // Get Reconstructed leading particle *******************************
549   TObjArray *ltRECO = fAnalyseUE->FindLeadingObjects(fAOD);
550   if (!ltRECO) return;
551   
552   // fill control distributions
553   fHistosUE->Fill(0, (AliVParticle*)ltRECO->At(0));
554   
555   // Fill the "event-counting-container", it is needed to get the number of events remaining after each event-selection cut
556   fHistosUE->FillEvent(eventId, AliUEHist::kCFStepAnaTopology);
557
558   // Switch to reconstructed tracks ************************************
559   // Sort RECO particles w.r.t. RECO-leading and return RECO particle  
560   TObjArray *regionSortedParticlesRECO = (TObjArray*)fAnalyseUE->SortRegions((AliVParticle*)ltRECO->At(0), fAOD,0); 
561   TObjArray *regionsMinMaxRECO = (TObjArray*)fAnalyseUE->GetMinMaxRegion((TList*)regionSortedParticlesRECO->At(2),(TList*)regionSortedParticlesRECO->At(3));
562   // Fill UE containers (step, leading track, towards particles, away particles, transverse MIN and MAX particles)
563   // (RECO leading particle and RECO  all particles)
564   // STEP 6
565   fHistosUE->Fill(eventId,AliUEHist::kCFStepReconstructed,(AliVParticle*)ltRECO->At(0),(TList*)regionSortedParticlesRECO->At(0),(TList*)regionSortedParticlesRECO->At(1),(TList*)regionsMinMaxRECO->At(0),(TList*)regionsMinMaxRECO->At(1));
566   
567   // STEP 8 and 9 for reduced efficiency study
568   FillReducedEfficiency(eventId, AliUEHist::kCFStepBiasStudy, ltRECO, kFALSE);
569   FillReducedEfficiency(eventId, AliUEHist::kCFStepBiasStudy2, ltRECO, kTRUE);
570   
571   delete ltRECO;
572   delete regionSortedParticlesRECO;
573   delete regionsMinMaxRECO;
574 }
575
576 //____________________________________________________________________
577 void AliAnalysisTaskLeadingTrackUE::FillReducedEfficiency(Int_t eventId, AliUEHist::CFStep step, const TObjArray* ltRECO, Bool_t twoStep)
578 {
579   // remove leading particle using fkTrackingEfficiency and use subleading particle to fill the histograms
580   //
581   // if twoStep is kTRUE, do a two step procedure where in each step only 50% of the loss due to the tracking efficiency is applied 
582   
583   if (!fkTrackingEfficiency)
584     return;
585     
586   TObjArray* particleList = (TObjArray*) ltRECO->Clone();
587   AliVParticle* leading = (AliVParticle*) particleList->At(0);
588   if (!leading)
589     return;
590   
591   // remove particles depending on tracking efficiency
592   Int_t count = (twoStep) ? 2 : 1;
593   
594   for (Int_t i=0; i<count; i++)
595   {
596     Float_t trackingEff = fkTrackingEfficiency->GetBinContent(fkTrackingEfficiency->GetXaxis()->FindBin(leading->Pt()));
597     if (twoStep)
598       trackingEff = 0.5 * (trackingEff + 1);
599       
600     if (gRandom->Uniform() > trackingEff)
601     {
602       //Printf("LOWEFF: Removing leading particle");
603       particleList->RemoveAt(0);
604       particleList->Compress();
605     }
606       
607     if (particleList->GetEntries() == 0)
608     {
609       delete particleList;
610       return;
611     }
612     
613     leading = (AliVParticle*) particleList->At(0);
614   }
615   
616   TObjArray *regionSortedParticlesRECOLowEff = fAnalyseUE->SortRegions(leading, particleList, 0); 
617   TObjArray *regionsMinMaxRECOLowEff = fAnalyseUE->GetMinMaxRegion((TList*)regionSortedParticlesRECOLowEff->At(2), (TList*)regionSortedParticlesRECOLowEff->At(3));
618     
619   fHistosUE->Fill(eventId,step,leading,(TList*)regionSortedParticlesRECOLowEff->At(0), (TList*)regionSortedParticlesRECOLowEff->At(1), (TList*)regionsMinMaxRECOLowEff->At(0), (TList*)regionsMinMaxRECOLowEff->At(1));
620
621   delete regionSortedParticlesRECOLowEff;
622   delete regionsMinMaxRECOLowEff;
623   delete particleList;
624 }
625
626 //____________________________________________________________________
627 void  AliAnalysisTaskLeadingTrackUE::Initialize()
628 {
629   // input handler
630   fInputHandler = (AliInputEventHandler*)
631          ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
632   // MC handler
633   fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
634 }
635
636
637
638
639
640