]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskEmcalDiJetAna.cxx
Merge branch 'master' into TPCdev
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskEmcalDiJetAna.cxx
1 //
2 // Dijet analysis task.
3 //
4 // Author: M.Verweij
5
6 #include <TClonesArray.h>
7 #include <TH1F.h>
8 #include <TH2F.h>
9 #include <TH3F.h>
10 #include <THnSparse.h>
11 #include <TList.h>
12 #include <TLorentzVector.h>
13 #include <TProfile.h>
14 #include <TChain.h>
15 #include <TSystem.h>
16 #include <TFile.h>
17 #include <TKey.h>
18
19 #include "AliVCluster.h"
20 #include "AliVTrack.h"
21 #include "AliEmcalJet.h"
22 #include "AliRhoParameter.h"
23 #include "AliLog.h"
24 #include "AliEmcalParticle.h"
25 #include "AliMCEvent.h"
26 #include "AliGenPythiaEventHeader.h"
27 #include "AliAODMCHeader.h"
28 #include "AliMCEvent.h"
29 #include "AliAnalysisManager.h"
30 #include "AliJetContainer.h"
31 #include "AliCentrality.h"
32
33 #include "AliAnalysisTaskEmcalDiJetAna.h"
34
35 ClassImp(AliAnalysisTaskEmcalDiJetAna)
36
37 //________________________________________________________________________
38 AliAnalysisTaskEmcalDiJetAna::AliAnalysisTaskEmcalDiJetAna() : 
39   AliAnalysisTaskEmcalDiJetBase("AliAnalysisTaskEmcalDiJetAna"),
40   fDoMatchFullCharged(kTRUE),
41   fNKtBins(30),
42   fNDiJetEtaBins(1),
43   fNAjBins(1),
44   fh2CentRhoCh(0),
45   fh2CentRhoScaled(0),
46   fh3PtEtaPhiJetFull(0),
47   fh3PtEtaPhiJetCharged(0),
48   fhnDiJetVarsFull(0),
49   fhnDiJetVarsCh(0),
50   fhnDiJetVarsFullCharged(0),
51   fhnMatchingFullCharged(0),
52   fh3PtTrigKt1Kt2Ch(0),
53   fh3PtTrigKt1Kt2FuCh(0),
54   fh3PtTrigDPhi1DPhi2Ch(0),
55   fh3PtTrigDPhi1DPhi2FuCh(0)
56 {
57   // Default constructor.
58
59   for(Int_t i=0; i<4; i++) {
60     fh3DiJetKtNEFPtAssoc[i]          = 0;
61     fCentCorrPtAssocCh[i]            = 0;
62     fCentCorrPtAssocFuCh[i]          = 0;
63     fAjPtAssocCentCh[i]              = 0;
64     fAjPtAssocCentFuCh[i]            = 0;
65     fh3PtAssoc1PtAssoc2DPhi23Ch[i]   = 0;
66     fh3PtAssoc1PtAssoc2DPhi23FuCh[i] = 0;
67   }  
68
69   SetMakeGeneralHistograms(kTRUE);
70 }
71
72 //________________________________________________________________________
73 AliAnalysisTaskEmcalDiJetAna::AliAnalysisTaskEmcalDiJetAna(const char *name) : 
74   AliAnalysisTaskEmcalDiJetBase(name),
75   fDoMatchFullCharged(kTRUE),
76   fNKtBins(30),
77   fNDiJetEtaBins(1),
78   fNAjBins(1),
79   fh2CentRhoCh(0),
80   fh2CentRhoScaled(0),
81   fh3PtEtaPhiJetFull(0),
82   fh3PtEtaPhiJetCharged(0),
83   fhnDiJetVarsFull(0),
84   fhnDiJetVarsCh(0),
85   fhnDiJetVarsFullCharged(0),
86   fhnMatchingFullCharged(0),
87   fh3PtTrigKt1Kt2Ch(0),
88   fh3PtTrigKt1Kt2FuCh(0),
89   fh3PtTrigDPhi1DPhi2Ch(0),
90   fh3PtTrigDPhi1DPhi2FuCh(0)
91 {
92   // Standard constructor.
93
94   for(Int_t i=0; i<4; i++) {
95     fh3DiJetKtNEFPtAssoc[i]      = 0;
96     fCentCorrPtAssocCh[i]        = 0;
97     fCentCorrPtAssocFuCh[i]      = 0;
98     fAjPtAssocCentCh[i]          = 0;
99     fAjPtAssocCentFuCh[i]        = 0;
100     fh3PtAssoc1PtAssoc2DPhi23Ch[i]   = 0;
101     fh3PtAssoc1PtAssoc2DPhi23FuCh[i] = 0;
102   }
103
104   SetMakeGeneralHistograms(kTRUE);
105 }
106
107 //________________________________________________________________________
108 AliAnalysisTaskEmcalDiJetAna::~AliAnalysisTaskEmcalDiJetAna()
109 {
110   // Destructor.
111 }
112
113 //________________________________________________________________________
114 Bool_t AliAnalysisTaskEmcalDiJetAna::RetrieveEventObjects() {
115   //
116   // retrieve event objects
117   //
118
119   if (!AliAnalysisTaskEmcalDiJetBase::RetrieveEventObjects())
120     return kFALSE;
121
122   return kTRUE;
123 }
124
125 //________________________________________________________________________
126 void AliAnalysisTaskEmcalDiJetAna::UserCreateOutputObjects()
127 {
128   // Create user output.
129
130   AliAnalysisTaskEmcalDiJetBase::UserCreateOutputObjects();
131
132   Bool_t oldStatus = TH1::AddDirectoryStatus();
133   TH1::AddDirectory(kFALSE);
134
135   const Int_t nBinsCent = 100;
136   Double_t minCent = 0.;
137   Double_t maxCent = 100.;
138
139   const Int_t nBinsRho = 200;
140   Double_t minRho = 0.;
141   Double_t maxRho = 20.;
142   fh2CentRhoCh = new TH2F("fh2CentRhoCh","fh2CentRhoCh;centrality;#rho_{ch}",nBinsCent,minCent,maxCent,nBinsRho,minRho,maxRho);
143   fOutput->Add(fh2CentRhoCh);
144   fh2CentRhoScaled = new TH2F("fh2CentRhoScaled","fh2CentRhoScaled;centrality;s_{EMC}#rho_{ch}",nBinsCent,minCent,maxCent,nBinsRho,minRho,maxRho);
145   fOutput->Add(fh2CentRhoScaled);
146
147   const Int_t nBinsPt = 150;
148   Double_t minPt = -20.;
149   Double_t maxPt = 130.;
150   const Int_t nBinsEta = 40;
151   Double_t minEta = -1.;
152   Double_t maxEta = 1.;
153   const Int_t nBinsPhi = 18*6;
154   Double_t minPhi = 0.;
155   Double_t maxPhi = TMath::TwoPi();
156
157   fh3PtEtaPhiJetFull = new TH3F("fh3PtEtaPhiJetFull","fh3PtEtaPhiJetFull;#it{p}_{T}^{jet};#eta;#varphi",nBinsPt,minPt,maxPt,nBinsEta,minEta,maxEta,nBinsPhi,minPhi,maxPhi);
158   fOutput->Add(fh3PtEtaPhiJetFull);
159
160   fh3PtEtaPhiJetCharged = new TH3F("fh3PtEtaPhiJetCharged","fh3PtEtaPhiJetCharged;#it{p}_{T}^{jet};#eta;#varphi",nBinsPt,minPt,maxPt,nBinsEta,minEta,maxEta,nBinsPhi,minPhi,maxPhi);
161   fOutput->Add(fh3PtEtaPhiJetCharged);
162
163   const Int_t nBinsSparse0 = 7;
164   const Int_t nBinsPtW      = 30;
165   const Int_t nBinsDPhi     = 72;
166   const Int_t nBinsKt       = fNKtBins;
167   const Int_t nBinsDiJetEta = fNDiJetEtaBins;//40;
168   const Int_t nBinsCentr    = fNcentBins;
169   const Int_t nBinsAj       = fNAjBins;//20
170   const Int_t nBins0[nBinsSparse0] = {nBinsPtW,nBinsPtW,nBinsDPhi,nBinsKt,nBinsDiJetEta,nBinsCentr,nBinsAj};
171   //pT1, pT2, deltaPhi, kT
172   const Double_t xmin0[nBinsSparse0]  = {  minPt, minPt, -0.5*TMath::Pi(),   0.,-1.,0.  , 0.};
173   const Double_t xmax0[nBinsSparse0]  = {  maxPt, maxPt,  1.5*TMath::Pi(), 120., 1.,100., 1.};
174   const Double_t centArrayBins[8] = {0.,2.,5.,10.,20.,40.,60.,100.};
175
176   if(fDoChargedCharged) {
177     fhnDiJetVarsCh = new THnSparseF("fhnDiJetVarsCh",
178                                     "fhnDiJetVarsCh;#it{p}_{T,1} (GeV/#it{c});#it{p}_{T,2} (GeV/#it{c});#Delta#varphi;#it{k}_{T} = #it{p}_{T,1}sin(#Delta#varphi) (GeV/#it{c});(#eta_{1}+#eta_{2})/2);centrality;#it{A}_{j}",
179                                     nBinsSparse0,nBins0,xmin0,xmax0);
180     if(fNcentBins==7) fhnDiJetVarsCh->SetBinEdges(5,centArrayBins);
181     fOutput->Add(fhnDiJetVarsCh);
182   }
183
184   if(fDoFullCharged) {
185     fhnDiJetVarsFullCharged = new THnSparseF("fhnDiJetVarsFullCharged",
186                                 "fhnDiJetVarsFullCharged;#it{p}_{T,1} (GeV/#it{c});#it{p}_{T,2} (GeV/#it{c});#Delta#varphi;#it{k}_{T} = #it{p}_{T,1}sin(#Delta#varphi) (GeV/#it{c});(#eta_{1}+#eta_{2})/2);centrality;#it{A}_{j}",
187                                 nBinsSparse0,nBins0,xmin0,xmax0);
188     if(fNcentBins==7) fhnDiJetVarsFullCharged->SetBinEdges(5,centArrayBins);
189     fOutput->Add(fhnDiJetVarsFullCharged);
190   }
191
192   if(fDoFullFull) {
193     fhnDiJetVarsFull = new THnSparseF("fhnDiJetVarsFull",
194                                     "fhnDiJetVarsFull;#it{p}_{T,1} (GeV/#it{c});#it{p}_{T,2} (GeV/#it{c});#Delta#varphi;#it{k}_{T} = #it{p}_{T,1}sin(#Delta#varphi) (GeV/#it{c});(#eta_{1}+#eta_{2})/2);centrality;#it{A}_{j}",
195                                     nBinsSparse0,nBins0,xmin0,xmax0);
196     fOutput->Add(fhnDiJetVarsFull);
197   }
198
199   fh3PtTrigKt1Kt2Ch = new TH3F("fh3PtTrigKt1Kt2Ch","fh3PtTrigKt1Kt2Ch;#it{p}_{T,1} (GeV/#it{c});#it{k}_{T,1};#it{k}_{T,2}",nBinsPt,minPt,maxPt,nBinsKt,0.,120.,nBinsKt,0.,120.);
200   fOutput->Add(fh3PtTrigKt1Kt2Ch);  
201
202   fh3PtTrigKt1Kt2FuCh = new TH3F("fh3PtTrigKt1Kt2FuCh","fh3PtTrigKt1Kt2FuCh;#it{p}_{T,1} (GeV/#it{c});#it{k}_{T,1};#it{k}_{T,2}",nBinsPt,minPt,maxPt,nBinsKt,0.,120.,nBinsKt,0.,120.);
203   fOutput->Add(fh3PtTrigKt1Kt2FuCh); 
204
205   fh3PtTrigDPhi1DPhi2Ch = new TH3F("fh3PtTrigDPhi1DPhi2Ch","fh3PtTrigDPhi1DPhi2Ch;#it{p}_{T,1} (GeV/#it{c});#it{k}_{T,1};#it{k}_{T,2}",nBinsPt,minPt,maxPt,36,-0.5*TMath::Pi(),1.5*TMath::Pi(),36,-0.5*TMath::Pi(),1.5*TMath::Pi());
206   fOutput->Add(fh3PtTrigDPhi1DPhi2Ch);  
207
208   fh3PtTrigDPhi1DPhi2FuCh = new TH3F("fh3PtTrigDPhi1DPhi2FuCh","fh3PtTrigDPhi1DPhi2FuCh;#it{p}_{T,1} (GeV/#it{c});#it{k}_{T,1};#it{k}_{T,2}",nBinsPt,minPt,maxPt,36,-0.5*TMath::Pi(),1.5*TMath::Pi(),36,-0.5*TMath::Pi(),1.5*TMath::Pi());
209   fOutput->Add(fh3PtTrigDPhi1DPhi2FuCh);  
210  
211
212   for(Int_t i=0; i<4; i++) {
213     TString histoName = Form("fh3DiJetKtNEFPtAssoc_TrigBin%d",i);
214     fh3DiJetKtNEFPtAssoc[i] = new TH3F(histoName.Data(),histoName.Data(),nBinsKt,0.,120.,50,0.,1.,nBinsPt,minPt,maxPt);
215     fOutput->Add(fh3DiJetKtNEFPtAssoc[i]);
216
217     histoName = Form("fCentCorrPtAssocCh_TrigBin%d",i);
218     fCentCorrPtAssocCh[i]  = new TH3F(histoName.Data(),histoName.Data(),10,0.,100.,10,0.,100.,nBinsPt,minPt,maxPt);
219     fOutput->Add(fCentCorrPtAssocCh[i]);
220
221     histoName = Form("fCentCorrPtAssocFuCh_TrigBin%d",i);
222     fCentCorrPtAssocFuCh[i]  = new TH3F(histoName.Data(),histoName.Data(),10,0.,100.,10,0.,100.,nBinsPt,minPt,maxPt);
223     fOutput->Add(fCentCorrPtAssocFuCh[i]);
224
225     histoName = Form("fAjPtAssocCentCh_TrigBin%d",i);
226     fAjPtAssocCentCh[i]  = new TH3F(histoName.Data(),histoName.Data(),50,0.,1.,nBinsPt,minPt,maxPt,20,0.,100.);
227     fOutput->Add(fAjPtAssocCentCh[i]);
228
229     histoName = Form("fAjPtAssocCentFuCh_TrigBin%d",i);
230     fAjPtAssocCentFuCh[i]  = new TH3F(histoName.Data(),histoName.Data(),50,0.,1.,nBinsPt,minPt,maxPt,20,0.,100.);
231     fOutput->Add(fAjPtAssocCentFuCh[i]);
232
233     histoName = Form("fh3PtAssoc1PtAssoc2DPhi23Ch_TrigBin%d",i);
234     fh3PtAssoc1PtAssoc2DPhi23Ch[i] = new TH3F(histoName.Data(),histoName.Data(),nBinsPt,minPt,maxPt,nBinsPt,minPt,maxPt,nBinsDPhi,-0.5*TMath::Pi(),1.5*TMath::Pi());
235     fOutput->Add(fh3PtAssoc1PtAssoc2DPhi23Ch[i]);
236
237     histoName = Form("fh3PtAssoc1PtAssoc2DPhi23FuCh_TrigBin%d",i);
238     fh3PtAssoc1PtAssoc2DPhi23FuCh[i] = new TH3F(histoName.Data(),histoName.Data(),nBinsPt,minPt,maxPt,nBinsPt,minPt,maxPt,nBinsDPhi,-0.5*TMath::Pi(),1.5*TMath::Pi());
239     fOutput->Add(fh3PtAssoc1PtAssoc2DPhi23FuCh[i]);
240   }
241
242   const Int_t nBinsSparseMatch = 7;
243   const Int_t nBinsDPhiMatch = 80;
244   const Int_t nBinsDEtaMatch = 80;
245   const Int_t nBinsDR = 20;
246   const Int_t nBinsFraction = 21;
247   const Int_t nBinsType = 3;
248   const Int_t nBinsMatch[nBinsSparseMatch] = {nBinsPt,nBinsPt,nBinsDPhiMatch,nBinsDEtaMatch,nBinsDR,nBinsFraction,nBinsType};
249   //pTfull, pTch, deltaPhi, deltaEta, deltaR, fraction, jet type (leading,subleading,other)
250   const Double_t xminMatch[nBinsSparseMatch]  = { minPt, minPt, -0.5,-0.5, 0. ,0.  ,0};
251   const Double_t xmaxMatch[nBinsSparseMatch]  = { maxPt, maxPt,  0.5, 0.5, 0.5,1.05,3};
252   if(fDoMatchFullCharged) {
253     fhnMatchingFullCharged = new THnSparseF("fhnMatchingFullCharged","fhnMatchingFullCharged;#it{p}_{T,full} (GeV/#it{c});#it{p}_{T,ch} (GeV/#it{c});#Delta#varphi;#Delta#eta;#Delta R;f_{ch};type",
254                                           nBinsSparseMatch,nBinsMatch,xminMatch,xmaxMatch);
255     fOutput->Add(fhnMatchingFullCharged);
256   }
257   
258   // =========== Switch on Sumw2 for all histos ===========
259   for (Int_t i=0; i<fOutput->GetEntries(); ++i) {
260     TH1 *h1 = dynamic_cast<TH1*>(fOutput->At(i));
261     if (h1){
262       h1->Sumw2();
263       continue;
264     }
265     THnSparse *hn = dynamic_cast<THnSparse*>(fOutput->At(i));
266     if(hn) {
267       hn->Sumw2();
268       continue;
269     }
270   }
271
272   TH1::AddDirectory(oldStatus);
273
274   PostData(1, fOutput); // Post data for ALL output slots > 0 here.
275 }
276
277 //________________________________________________________________________
278 Bool_t AliAnalysisTaskEmcalDiJetAna::FillHistograms()
279 {
280   // Fill histograms.
281
282   fh2CentRhoCh->Fill(fCent,fRhoChVal);
283   fh2CentRhoScaled->Fill(fCent,fRhoFullVal);
284
285   Int_t nJetsFull = GetNJets(fContainerFull);
286   for(Int_t ij=0; ij<nJetsFull; ij++) {
287     AliEmcalJet *jet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ij, fContainerFull));
288     if(!jet) continue; //jet not selected
289
290     Double_t jetPt = GetJetPt(jet,0);
291     fh3PtEtaPhiJetFull->Fill(jetPt,jet->Eta(),jet->Phi());
292   }
293
294   Int_t nJetsCh = GetNJets(fContainerCharged);
295   for(Int_t ij=0; ij<nJetsCh; ij++) {
296     AliEmcalJet *jet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ij, fContainerCharged));
297     if(!jet) continue; //jet not selected
298
299       Double_t jetPt = GetJetPt(jet,1);
300       fh3PtEtaPhiJetCharged->Fill(jetPt,jet->Eta(),jet->Phi());
301   }
302
303   return kTRUE;
304 }
305
306 //________________________________________________________________________
307 Bool_t AliAnalysisTaskEmcalDiJetAna::Run()
308 {
309   // Run analysis code here, if needed. It will be executed before FillHistograms().
310
311   //Check if event is selected (vertex & pile-up)
312   if(!SelectEvent())
313     return kFALSE;
314
315   if(fRhoType==0) {
316     fRhoFullVal = 0.;
317     fRhoChVal = 0.;
318   }
319   if(fRhoType==1) {
320     fRhoFullVal = GetRhoVal(fContainerFull);
321     fRhoChVal = GetRhoVal(fContainerCharged);
322   }
323   
324   if(fDoFullFull)
325     CorrelateJets(0);
326
327   // MatchFullAndChargedJets();
328   if(fDoChargedCharged)   CorrelateJets(1);
329
330   if(fDoMatchFullCharged) FillMatchFullChargedHistos(fContainerFull,fContainerCharged);
331
332   if(fDoFullCharged)      {
333     SetChargedFractionIndex();
334     CorrelateJets(2);
335   }
336
337   return kTRUE;  // If return kFALSE FillHistogram() will NOT be executed.
338 }
339
340 //________________________________________________________________________
341 void AliAnalysisTaskEmcalDiJetAna::CorrelateJets(const Int_t type) {
342   //
343   // Correlate jets and fill histos
344   //
345
346   if( fJetCorrelationType==kCorrelateAll )
347     CorrelateAllJets(type);
348   else if( fJetCorrelationType==kCorrelateTwo )
349     CorrelateTwoJets(type);
350   else if( fJetCorrelationType==kCorrelateLS )
351     CorrelateLeadingSubleadingJets(type);
352
353   return;
354
355 }
356
357 //________________________________________________________________________
358 void AliAnalysisTaskEmcalDiJetAna::CorrelateTwoJets(const Int_t type) {
359   //
360   // Correlate jets and fill histos
361   //
362
363   Int_t typet = 0;
364   Int_t typea = 0;
365   if(type==0) { //full-full
366     typet = fContainerFull;
367     typea = fContainerFull;
368   }
369   else if(type==1) { //charged-charged
370     typet = fContainerCharged;
371     typea = fContainerCharged;
372   }
373   else if(type==2) { //full-charged
374     typet = fContainerFull;
375     typea = fContainerCharged;
376   }
377   else {
378     AliWarning(Form("%s: type %d of dijet correlation not defined!",GetName(),type));
379     return;
380   }
381
382   Int_t nJetsTrig  = GetNJets(typet);
383   for(Int_t ijt=0; ijt<nJetsTrig; ijt++) {
384
385     AliEmcalJet *jetTrig = NULL; 
386     if(type==0) {
387       jetTrig = static_cast<AliEmcalJet*>(GetJetFromArray(ijt, typet));
388       if(TMath::Abs(jetTrig->Eta())>0.5)
389         jetTrig = NULL;
390     }
391     else
392       jetTrig = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ijt, typet));
393
394     if(!jetTrig)
395       continue; //jet not selected
396     
397     Double_t jetTrigPt = GetJetPt(jetTrig,typet);
398
399     if(jetTrigPt<fPtMinTriggerJet)
400       continue;
401
402     AliEmcalJet *jetAssoc = GetLeadingAssociatedJet(typea,jetTrig);
403     if(!jetAssoc)
404       continue;
405
406     if(type==0 || type==1) {
407       if(GetJetPt(jetAssoc,typea)>jetTrigPt)
408         continue;
409     }
410
411     FillDiJetHistos(jetTrig,jetAssoc, type);
412
413     //Look for second jet on away side - 3-jet events
414     AliEmcalJet *jetAssoc2 = GetSecondLeadingAssociatedJet(typea,jetTrig);
415     if(jetAssoc2)
416       FillThreeJetHistos(jetTrig,jetAssoc,jetAssoc2,type);
417     
418   }
419 }
420
421 //________________________________________________________________________
422 AliEmcalJet* AliAnalysisTaskEmcalDiJetAna::GetLeadingJet(const Int_t type) {
423
424   //Get associated jet which is the leading jet in the opposite hemisphere
425
426   Int_t cont = 0;
427   if(type==0)  //full-full
428     cont = fContainerFull;
429   else if(type==1)  //charged-charged
430     cont = fContainerCharged;
431   else if(type==2)  //full-charged
432     cont = fContainerFull;
433
434   Int_t nJets = GetNJets(cont);
435   Double_t ptLead = -999;
436   Int_t    iJetLead = -1;
437   for(Int_t ij=0; ij<nJets; ij++) {
438     AliEmcalJet *jet = NULL;
439     if(type==0) {
440       jet = static_cast<AliEmcalJet*>(GetJetFromArray(ij, cont));
441       if(TMath::Abs(jet->Eta())>0.5)
442         jet = NULL;
443     }
444     else
445       jet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ij, cont));
446
447     if(!jet)
448       continue;
449
450     Double_t jetPt = GetJetPt(jet,cont);
451
452     if(jetPt>ptLead) {
453       ptLead = jetPt;
454       iJetLead = ij;
455     }
456   }
457
458   AliEmcalJet *jetLead = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead, cont));
459
460   return jetLead;
461 }
462
463 //________________________________________________________________________
464 AliEmcalJet* AliAnalysisTaskEmcalDiJetAna::GetLeadingAssociatedJet(const Int_t type, AliEmcalJet *jetTrig) {
465
466   //Get associated jet which is the leading jet in the opposite hemisphere
467
468   Int_t typea = 0;
469   if(type==0)  //full-full
470     typea = fContainerFull;
471   else if(type==1)  //charged-charged
472     typea = fContainerCharged;
473   else if(type==2)  //full-charged
474     typea = fContainerCharged;
475
476   AliEmcalJet *jetAssocLead = GetLeadingJetOppositeHemisphere(type, typea, jetTrig);
477   
478   return jetAssocLead;
479 }
480
481 //________________________________________________________________________
482 AliEmcalJet* AliAnalysisTaskEmcalDiJetAna::GetSecondLeadingAssociatedJet(const Int_t type, AliEmcalJet *jetTrig) {
483
484   //Get associated jet which is the leading jet in the opposite hemisphere
485
486   Int_t typea = 0;
487   if(type==0)  //full-full
488     typea = fContainerFull;
489   else if(type==1)  //charged-charged
490     typea = fContainerCharged;
491   else if(type==2)  //full-charged
492     typea = fContainerCharged;
493
494   AliEmcalJet *jetAssocLead2 = GetSecondLeadingJetOppositeHemisphere(type, typea, jetTrig);
495   
496   return jetAssocLead2;
497 }
498
499 //________________________________________________________________________
500 void AliAnalysisTaskEmcalDiJetAna::CorrelateAllJets(const Int_t type) {
501   //
502   // Correlate jets and fill histos
503   //
504
505   Int_t typet = 0;
506   Int_t typea = 0;
507   if(type==0) { //full-full
508     typet = fContainerFull;
509     typea = fContainerFull;
510   }
511   else if(type==1) { //charged-charged
512     typet = fContainerCharged;
513     typea = fContainerCharged;
514   }
515   else if(type==2) { //full-charged
516     typet = fContainerFull;
517     typea = fContainerCharged;
518   }
519   else {
520     AliWarning(Form("%s: type %d of dijet correlation not defined!",GetName(),type));
521     return;
522   }
523
524   Int_t nJetsTrig  = GetNJets(typet);
525   Int_t nJetsAssoc = GetNJets(typea);
526
527   for(Int_t ijt=0; ijt<nJetsTrig; ijt++) {
528     AliEmcalJet *jetTrig = NULL; 
529     if(type==0) {
530       jetTrig = static_cast<AliEmcalJet*>(GetJetFromArray(ijt, typet));
531       if(TMath::Abs(jetTrig->Eta())>0.5)
532         jetTrig = NULL;
533     }
534     else
535       jetTrig = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ijt, typet));
536
537     if(!jetTrig)
538       continue; //jet not selected
539     
540     Double_t jetTrigPt = GetJetPt(jetTrig,typet);
541
542     if(jetTrigPt<fPtMinTriggerJet)
543       continue;
544
545     for(Int_t ija=0; ija<nJetsAssoc; ija++) {
546       if(IsSameJet(ijt,ija,type)) continue;
547
548       AliEmcalJet *jetAssoc = NULL;
549       if(type==0) {
550         jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
551         if(TMath::Abs(jetAssoc->Eta())>0.5)
552           jetAssoc = NULL;
553       }
554       else
555         jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
556
557       if(!jetAssoc)
558         continue;
559         
560       Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
561       
562       if(jetTrigPt>jetAssocPt)
563         FillDiJetHistos(jetTrig,jetAssoc, type);
564       
565     } // associate jet loop
566   }//trigger jet loop
567
568 }
569
570 //________________________________________________________________________
571 void AliAnalysisTaskEmcalDiJetAna::CorrelateLeadingSubleadingJets(const Int_t type) {
572   //
573   // Correlate leading jet in event with leading jet in opposite hemisphere
574   //
575
576   Int_t typet = 0;
577   Int_t typea = 0;
578   if(type==0) { //full-full
579     typet = fContainerFull;
580     typea = fContainerFull;
581   }
582   else if(type==1) { //charged-charged
583     typet = fContainerCharged;
584     typea = fContainerCharged;
585   }
586   else if(type==2) { //full-charged
587     typet = fContainerFull;
588     typea = fContainerCharged;
589   }
590   else {
591     AliWarning(Form("%s: type %d of dijet correlation not defined!",GetName(),type));
592     return;
593   }
594
595   AliEmcalJet *jetTrig = GetLeadingJet(typet);
596   if(!jetTrig)
597     return;
598
599   Double_t jetTrigPt = GetJetPt(jetTrig,typet);
600
601   if(jetTrigPt<fPtMinTriggerJet)
602     return;
603   
604   AliEmcalJet *jetAssoc = GetLeadingAssociatedJet(typea,jetTrig);
605   if(!jetAssoc)
606     return;
607   
608   FillDiJetHistos(jetTrig,jetAssoc, type);
609 }
610
611 //________________________________________________________________________
612 void AliAnalysisTaskEmcalDiJetAna::FillDiJetHistos(const AliEmcalJet *jet1, const AliEmcalJet *jet2, const Int_t mode) {
613   //
614   // Fill histos
615   // mode: full vs full        = 0
616   //       charged vs charged  = 1
617   //       full vs charged     = 2
618   //
619
620   Int_t typet = 0;
621   Int_t typea = 0;
622   if(mode==0) { //full-full
623     typet = fContainerFull;
624     typea = fContainerFull;
625   }
626   else if(mode==1) { //charged-charged
627     typet = fContainerCharged;
628     typea = fContainerCharged;
629   }
630   else if(mode==2) { //full-charged
631     typet = fContainerFull;
632     typea = fContainerCharged;
633   }
634   else {
635     AliWarning(Form("%s: mode %d of dijet correlation not defined!",GetName(),mode));
636     return;
637   }
638
639   Double_t jetTrigPt = GetJetPt(jet1,typet);
640   Double_t jetAssocPt = GetJetPt(jet2,typea);
641
642   Double_t deltaPhi = GetDeltaPhi(jet1->Phi(),jet2->Phi());
643
644   Double_t kT = TMath::Abs(jetTrigPt*TMath::Sin(deltaPhi));
645
646   Double_t dijetEta = (jet1->Eta()+jet2->Eta())/2.;
647
648   Double_t aj = 0.;
649   if((jetTrigPt+jetAssocPt)>0.) aj = (jetTrigPt-jetAssocPt)/(jetTrigPt+jetAssocPt);
650
651   Double_t diJetVars[7] = {jetTrigPt,jetAssocPt,deltaPhi,kT,dijetEta,fCent,aj};
652
653   if(mode==0)
654     fhnDiJetVarsFull->Fill(diJetVars);
655   else if(mode==1)
656     fhnDiJetVarsCh->Fill(diJetVars);
657   else if(mode==2)
658     fhnDiJetVarsFullCharged->Fill(diJetVars);
659
660   Double_t dPhiMin = TMath::Pi() - 1./3.*TMath::Pi();
661   Double_t dPhiMax = TMath::Pi() + 1./3.*TMath::Pi();
662   Int_t trigBin = GetPtTriggerBin(jetTrigPt);
663   if(mode==2) {
664     if(trigBin>-1 && trigBin<4) {
665       if(deltaPhi>dPhiMin && deltaPhi<dPhiMax)
666         fh3DiJetKtNEFPtAssoc[trigBin]->Fill(kT, jet1->NEF(), jetAssocPt);
667     }
668   }
669
670   //Fill centrality correlation histos in case a dijet is present in acceptance
671   Double_t centZNA = -1.;
672   AliCentrality *aliCent = InputEvent()->GetCentrality();
673   if (aliCent) {
674     centZNA = aliCent->GetCentralityPercentile("ZNA");
675     if(trigBin>-1 && trigBin<4) {
676       if(deltaPhi>dPhiMin && deltaPhi<dPhiMax) {
677         if(mode==1) {
678           fCentCorrPtAssocCh[trigBin]->Fill(fCent,centZNA,jetAssocPt);
679           fAjPtAssocCentCh[trigBin]->Fill(aj,jetAssocPt,fCent);
680         }
681         else if(mode==2) {
682           fCentCorrPtAssocFuCh[trigBin]->Fill(fCent,centZNA,jetAssocPt);
683           fAjPtAssocCentFuCh[trigBin]->Fill(aj,jetAssocPt,fCent);
684         }
685       }
686     }
687   }
688
689 }
690
691 //________________________________________________________________________
692 void AliAnalysisTaskEmcalDiJetAna::FillThreeJetHistos(const AliEmcalJet *jet1, const AliEmcalJet *jet2, const AliEmcalJet *jet3, const Int_t mode) {
693   //
694   // Fill histos
695   // mode: full vs full        = 0
696   //       charged vs charged  = 1
697   //       full vs charged     = 2
698   //
699
700   Int_t typet = 0;
701   Int_t typea = 0;
702   if(mode==0) { //full-full
703     typet = fContainerFull;
704     typea = fContainerFull;
705   }
706   else if(mode==1) { //charged-charged
707     typet = fContainerCharged;
708     typea = fContainerCharged;
709   }
710   else if(mode==2) { //full-charged
711     typet = fContainerFull;
712     typea = fContainerCharged;
713   }
714   else {
715     AliWarning(Form("%s: mode %d of dijet correlation not defined!",GetName(),mode));
716     return;
717   }
718
719   Double_t jetTrigPt = GetJetPt(jet1,typet);
720   Double_t jetAssoc2Pt = GetJetPt(jet2,typea);
721   Double_t jetAssoc3Pt = GetJetPt(jet3,typea);
722
723   Double_t deltaPhi12 = GetDeltaPhi(jet1->Phi(),jet2->Phi());
724   Double_t deltaPhi13 = GetDeltaPhi(jet1->Phi(),jet3->Phi());
725   Double_t deltaPhi23 = GetDeltaPhi(jet2->Phi(),jet3->Phi());
726
727   Double_t kT12 = TMath::Abs(jetTrigPt*TMath::Sin(deltaPhi12));
728   Double_t kT13 = TMath::Abs(jetTrigPt*TMath::Sin(deltaPhi13));
729   
730   Double_t dPhiMin = TMath::Pi() - 1./3.*TMath::Pi();
731   Double_t dPhiMax = TMath::Pi() + 1./3.*TMath::Pi();
732
733   Int_t trigBin = GetPtTriggerBin(jetTrigPt);
734
735   if(jetAssoc2Pt>20. && jetAssoc3Pt>20.) {
736     if(mode==1) {
737       fh3PtTrigDPhi1DPhi2Ch->Fill(jetTrigPt,deltaPhi12,deltaPhi13);
738       fh3PtAssoc1PtAssoc2DPhi23Ch[trigBin]->Fill(jetAssoc2Pt,jetAssoc3Pt,deltaPhi23);    
739     }
740     else if(mode==1) {
741       fh3PtTrigDPhi1DPhi2FuCh->Fill(jetTrigPt,deltaPhi12,deltaPhi13);
742       fh3PtAssoc1PtAssoc2DPhi23FuCh[trigBin]->Fill(jetAssoc2Pt,jetAssoc3Pt,deltaPhi23);    
743     }
744
745     if(deltaPhi12>dPhiMin && deltaPhi12<dPhiMax) {
746       if(mode==1)
747         fh3PtTrigKt1Kt2Ch->Fill(jetTrigPt,kT12,kT13);
748       else if(mode==2)
749         fh3PtTrigKt1Kt2FuCh->Fill(jetTrigPt,kT12,kT13);
750     }
751   }
752
753 }
754
755 //________________________________________________________________________
756 Int_t AliAnalysisTaskEmcalDiJetAna::GetPtTriggerBin(Double_t pt) {
757
758   Int_t binTrig = -1;
759   if(pt>=20 && pt<40)
760     binTrig = 0;
761   else if(pt>=40 && pt<60)
762     binTrig = 1;
763   else if(pt>=60 && pt<80)
764     binTrig = 2;
765   else if(pt>=80 && pt<100)
766     binTrig = 3;
767
768   return binTrig;
769 }
770
771 //________________________________________________________________________
772 void AliAnalysisTaskEmcalDiJetAna::FillMatchFullChargedHistos(Int_t cFull,Int_t cCharged) {
773   //
774   // Match full to charged jets and fill histo
775   //
776
777   Int_t match = MatchFullAndChargedJets(cFull,cCharged);
778   if(match==0) {
779     AliDebug(11,Form("%s: matching failed",GetName()));
780     return;
781   }
782   
783   for(int ig = 0;ig < GetNJets(cFull);++ig){
784     AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ig, cFull));
785     if(!jetFull) continue;
786
787     AliEmcalJet *jetCh = jetFull->ClosestJet();
788     if(!jetCh) continue;
789
790     Double_t shFraction = GetFractionSharedPt(jetFull,jetCh);
791     Double_t matchVars[7] = {
792       jetFull->Pt(),
793       jetCh->Pt(),
794       GetDeltaPhi(jetFull->Phi(),jetCh->Phi()),
795       jetFull->Eta()-jetCh->Eta(),
796       GetDeltaR(jetFull,jetCh),
797       shFraction,TMath::Min((Float_t)ig+0.5,2.5)
798     };
799       fhnMatchingFullCharged->Fill(matchVars);
800     
801   }//loop over full jets
802
803 }
804
805
806 //________________________________________________________________________
807 Int_t AliAnalysisTaskEmcalDiJetAna::MatchFullAndChargedJets(Int_t cFull, Int_t cCharged) {
808   //
809   // Match charged jets to full jets
810   //
811
812   if(GetNJets(cFull)<1) {
813     AliDebug(2,Form("%s: no full jets: %d", GetName(),GetNJets(cFull)));
814     return 0;
815   }
816
817   if(GetNJets(cCharged)<1) {
818     AliDebug(2,Form("%s: no charged jets: %d", GetName(),GetNJets(cCharged)));
819     return 0;
820   }
821
822   TClonesArray *cJetsFull = GetJetArray(cFull);
823   TClonesArray *cJetsCharged = GetJetArray(cCharged);
824
825   if(!cJetsFull) {
826     AliDebug(2,Form("%s: no full jet array",GetName()));
827     return 0;
828   }
829
830   if(!cJetsCharged) {
831     AliDebug(2,Form("%s: no charged jet array",GetName()));
832     return 0;
833   }
834
835   if(!fMatchingDone) {
836       MatchJetsGeo(cFull, cCharged, 0);
837       return 1;  
838   } else {
839     AliDebug(11,Form("%s: Matching already done before",GetName()));
840     return 1;
841   }
842
843 }
844
845 //_______________________________________________________________________
846 void AliAnalysisTaskEmcalDiJetAna::Terminate(Option_t *) 
847 {
848   // Called once at the end of the analysis.
849 }
850
851
852