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