]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliAnalysisTaskEmcalDiJetBase.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliAnalysisTaskEmcalDiJetBase.cxx
1 //
2 // Dijet base 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
32 #include "AliAnalysisTaskEmcalDiJetBase.h"
33
34 ClassImp(AliAnalysisTaskEmcalDiJetBase)
35
36 //________________________________________________________________________
37 AliAnalysisTaskEmcalDiJetBase::AliAnalysisTaskEmcalDiJetBase() : 
38   AliAnalysisTaskEmcalJet("AliAnalysisTaskEmcalDiJetBase", kTRUE),
39   fDebug(kFALSE),
40   fJetCorrelationType(kCorrelateAll),
41   fJetFullChargedMatchingType(kFraction),
42   fTriggerClass(""),
43   fContainerCharged(1),
44   fContainerFull(0),
45   fContainerChargedMC(3),
46   fContainerFullMC(2),
47   fRhoType(0),
48   fRhoChVal(0),
49   fRhoFullVal(0),
50   fDoChargedCharged(kTRUE),
51   fDoFullCharged(kTRUE),
52   fDoFullFull(kFALSE),
53   fPtMinTriggerJet(10.),
54   fDoPtBias(kTRUE),
55   fMinFractionShared(0.5),
56   fMatchingDone(kFALSE),
57   faFullFracIndex(0),
58   faFullFracIndexMC(0),
59   fhNEvents(0),
60   fHistTrialsSelEvents(0)
61 {
62   // Default constructor.
63
64   
65   SetMakeGeneralHistograms(kTRUE);
66
67 }
68
69 //________________________________________________________________________
70 AliAnalysisTaskEmcalDiJetBase::AliAnalysisTaskEmcalDiJetBase(const char *name) : 
71   AliAnalysisTaskEmcalJet(name, kTRUE),
72   fDebug(kFALSE),
73   fJetCorrelationType(kCorrelateAll),
74   fJetFullChargedMatchingType(kFraction),
75   fTriggerClass(""),
76   fContainerCharged(1),
77   fContainerFull(0),
78   fContainerChargedMC(3),
79   fContainerFullMC(2),
80   fRhoType(0),
81   fRhoChVal(0),
82   fRhoFullVal(0),
83   fDoChargedCharged(kTRUE),
84   fDoFullCharged(kTRUE),
85   fDoFullFull(kFALSE),
86   fPtMinTriggerJet(10.),
87   fDoPtBias(kTRUE),
88   fMinFractionShared(0.5),
89   fMatchingDone(kFALSE),
90   faFullFracIndex(0),
91   faFullFracIndexMC(0),
92   fhNEvents(0),
93   fHistTrialsSelEvents(0)
94 {
95   // Standard constructor.
96
97   SetMakeGeneralHistograms(kTRUE);
98
99 }
100
101 //________________________________________________________________________
102 AliAnalysisTaskEmcalDiJetBase::~AliAnalysisTaskEmcalDiJetBase()
103 {
104   // Destructor.
105 }
106
107 //________________________________________________________________________
108 Bool_t AliAnalysisTaskEmcalDiJetBase::SelectEvent() {
109   //
110   // Decide if event should be selected for analysis
111   //
112
113   fhNEvents->Fill(3.5);
114
115   if(!fTriggerClass.IsNull()) {
116     //Check if requested trigger was fired
117     TString firedTrigClass = InputEvent()->GetFiredTriggerClasses();
118
119     if(!firedTrigClass.Contains(fTriggerClass))
120       return kFALSE;
121     else if(fTriggerClass.Contains("J1") && fTriggerClass.Contains("J2")) { //if events with J1&&J2 are requested
122       if(!firedTrigClass.Contains("J1") || !firedTrigClass.Contains("J2") ) //check if both are fired
123         return kFALSE;
124     }
125     else if(fTriggerClass.Contains("J1") && firedTrigClass.Contains("J2")) //if J2 is requested also add triggers which have J1&&J2. Reject if J1 is requested and J2 is fired
126       return kFALSE;
127   }
128   
129   fhNEvents->Fill(1.5);
130
131   fHistTrialsSelEvents->Fill(fPtHardBin, fNTrials);
132   
133   return kTRUE;
134
135 }
136
137 //________________________________________________________________________
138 void AliAnalysisTaskEmcalDiJetBase::UserCreateOutputObjects()
139 {
140   // Create user output.
141
142   AliAnalysisTaskEmcalJet::UserCreateOutputObjects();
143
144   Bool_t oldStatus = TH1::AddDirectoryStatus();
145   TH1::AddDirectory(kFALSE);
146
147   fhNEvents = new TH1F("fhNEvents","fhNEvents;selection;N_{evt}",5,0,5);
148   fOutput->Add(fhNEvents);
149
150   //Pythia info
151   fHistTrialsSelEvents = new TH1F("fHistTrialsSelEvents", "fHistTrialsSelEvents", 12, 0, 12);
152   fHistTrialsSelEvents->GetXaxis()->SetTitle("p_{T} hard bin");
153   fHistTrialsSelEvents->GetYaxis()->SetTitle("trials");
154   fOutput->Add(fHistTrialsSelEvents);
155
156   TH1::AddDirectory(oldStatus);
157
158   PostData(1, fOutput); // Post data for ALL output slots > 0 here.
159 }
160
161 //________________________________________________________________________
162 Bool_t AliAnalysisTaskEmcalDiJetBase::IsSameJet(Int_t ijt, Int_t ija, Int_t type, Bool_t isMC) {
163    //check if two jets are the same one
164
165    Bool_t bSame = kFALSE;
166
167    if(type<2 && ijt==ija)
168      bSame = kTRUE;
169    if(type==2) {
170
171      if(fJetFullChargedMatchingType==kFraction) {
172        if(isMC && faFullFracIndexMC.At(ijt)==ija)
173          bSame = kTRUE;
174        else if(!isMC && faFullFracIndex.At(ijt)==ija)
175          bSame = kTRUE;
176      }
177      else if(fJetFullChargedMatchingType==kGeo) {
178        Int_t contFull = fContainerFull;
179        Int_t contChar = fContainerCharged;
180        if(isMC) {
181          contFull = fContainerFullMC;
182          contChar = fContainerChargedMC;
183        }
184        AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ijt, contFull));
185        AliEmcalJet *chJet   = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, contChar));
186        AliEmcalJet *matchJet = fullJet->ClosestJet();
187        if(chJet==matchJet)
188          bSame = kTRUE;
189      }
190      else if(fJetFullChargedMatchingType==kNoMatching) {
191        return kFALSE;
192      }
193      else{
194        AliWarning(Form("%s: matching type unknown", GetName()));
195      }
196    }
197
198    return bSame;
199  }
200
201
202 //________________________________________________________________________
203 Double_t AliAnalysisTaskEmcalDiJetBase::GetJetPt(const AliEmcalJet *jet, Int_t type) {
204
205   if(!jet) return -99;
206
207   if(type==0)
208     return jet->Pt() - fRhoFullVal * jet->Area();
209   else if(type==1)
210     return jet->Pt() - fRhoChVal * jet->Area();
211   else
212     return jet->Pt();
213   
214 }
215
216 //________________________________________________________________________
217 Double_t AliAnalysisTaskEmcalDiJetBase::GetZ(const AliVParticle *trk, const AliEmcalJet *jet)          const
218 {  
219   // Get Z of constituent trk
220
221   return GetZ(trk->Px(),trk->Py(),trk->Pz(),jet->Px(),jet->Py(),jet->Pz());
222 }
223
224 //________________________________________________________________________
225 Double_t AliAnalysisTaskEmcalDiJetBase::GetZ(Double_t trkPx, Double_t trkPy, Double_t trkPz, Double_t jetPx, Double_t jetPy, Double_t jetPz) const
226 {
227   // 
228   // Get the z of a constituent inside of a jet
229   //
230
231   Double_t pJetSq = jetPx*jetPx+jetPy*jetPy+jetPz*jetPz;
232
233   if(pJetSq>0.)
234     return (trkPx*jetPx+trkPy*jetPy+trkPz*jetPz)/pJetSq;
235   else {
236     AliWarning(Form("%s: strange, pjet*pjet seems to be zero pJetSq: %f",GetName(), pJetSq)); 
237     return 0;
238   }
239 }
240
241 //________________________________________________________________________
242 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaR(const AliEmcalJet* jet1, const AliEmcalJet* jet2) const {
243   //
244   // Helper function to calculate the distance between two jets
245   //
246
247   Double_t dPhi = jet1->Phi() - jet2->Phi();
248   if(dPhi>TMath::Pi())dPhi = dPhi - 2.*TMath::Pi();
249   if(dPhi<(-1.*TMath::Pi()))dPhi = dPhi + 2.*TMath::Pi();
250   Double_t dEta = jet1->Eta() - jet2->Eta();
251   Double_t dR = TMath::Sqrt(dPhi*dPhi+dEta*dEta);
252   return dR;
253 }
254
255 //________________________________________________________________________
256 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(const AliEmcalJet* jet1, const AliEmcalJet* jet2) {
257   //
258   // Calculate azimuthal angle between the axises of the jets
259   //
260
261   return GetDeltaPhi(jet1->Phi(),jet2->Phi());
262
263 }
264
265 //________________________________________________________________________
266 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(Double_t phi1,Double_t phi2) {
267   //
268   // Calculate azimuthal angle between the axises of the jets
269   //
270
271   Double_t dPhi = phi1-phi2;
272
273   if(dPhi <-0.5*TMath::Pi())  dPhi += TMath::TwoPi();
274   if(dPhi > 1.5*TMath::Pi())  dPhi -= TMath::TwoPi();
275
276   return dPhi;
277 }
278
279 //________________________________________________________________________
280 Double_t AliAnalysisTaskEmcalDiJetBase::GetFractionSharedPt(const AliEmcalJet *jetFull, const AliEmcalJet *jetCharged) const
281 {
282   //
283   // Get fraction of shared pT between matched full and charged jet
284   // Uses charged jet pT as baseline: fraction = \Sum_{const,full jet} pT,const,i / pT,jet,ch
285   //
286
287   Double_t fraction = 0.;
288   Double_t jetPtCh = jetCharged->Pt();
289  
290   if(jetPtCh>0) {
291
292     AliDebug(11,Form("%s: nConstituents: %d, ch: %d  chne: %d ne: %d",GetName(),jetFull->GetNumberOfConstituents(),jetCharged->GetNumberOfTracks(),jetFull->GetNumberOfTracks(),jetFull->GetNumberOfClusters()));
293     
294     Double_t sumPt = 0.;
295     AliVParticle *vpf = 0x0;
296     Int_t iFound = 0;
297     for(Int_t icc=0; icc<jetCharged->GetNumberOfTracks(); icc++) {
298       Int_t idx = (Int_t)jetCharged->TrackAt(icc);
299       iFound = 0;
300       for(Int_t icf=0; icf<jetFull->GetNumberOfTracks(); icf++) {
301         if(idx == jetFull->TrackAt(icf) && iFound==0 ) {
302           iFound=1;
303           vpf = static_cast<AliVParticle*>(jetFull->TrackAt(icf, fTracks));
304           if(!vpf) continue;
305           if(vpf->Charge()!=0)
306             sumPt += vpf->Pt();
307           continue;
308         }
309       }
310     }
311     
312     fraction = sumPt/jetPtCh;
313   }
314
315   AliDebug(11,Form("%s: charged shared fraction: %.2f",GetName(),fraction));
316
317   return fraction;
318
319 }
320
321 //________________________________________________________________________
322 void AliAnalysisTaskEmcalDiJetBase::MatchJetsGeo(Int_t cFull, Int_t cCharged,
323                                                  Int_t iDebug, Float_t maxDist, Int_t type) {
324
325   //
326   // Match the full jets to the corresponding charged jets
327   // Translation of AliAnalysisHelperJetTasks::GetClosestJets to AliEmcalJet objects
328   // type: 0 = use acceptance cuts of container  1 = allow 0.1 one more for cCharged(MC) in eta 2 = allow 0.1 more in eta and phi for cCharged(MC)
329
330   const int kMode = 3;
331
332   const Int_t nChJets   = GetNJets(cCharged);
333   const Int_t nFullJets = GetNJets(cFull);
334
335   if(nFullJets==0 || nChJets==0) return;
336
337   TArrayI faChNeMatchIndex;
338   faChNeMatchIndex.Set(nChJets+1);
339   faChNeMatchIndex.Reset(-1);
340
341   TArrayI faChMatchIndex;
342   faChMatchIndex.Set(nFullJets+1);
343   faChMatchIndex.Reset(-1);
344
345   static TArrayS iFlag(nChJets*nFullJets);
346   if(iFlag.GetSize()<(nChJets*nFullJets)){
347     iFlag.Set(nChJets*nFullJets+1);
348   }
349   iFlag.Reset(0);
350
351   AliJetContainer *contCh = GetJetContainer(cCharged);
352
353   // find the closest distance to the full jet
354   for(int ifu = 0;ifu<nFullJets;ifu++){
355
356     AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
357     if(!fullJet) continue;
358
359     Float_t dist = maxDist;
360     
361     for(int ich = 0;ich<nChJets;ich++){
362       AliEmcalJet *chJet = 0x0;
363       if(type==0)
364         chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
365       else {
366         chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
367         if(!chJet) continue;
368         if(type>0) {
369           if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
370             continue;
371           if(type==2) {
372             if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
373               continue;
374           }
375         }
376       }
377       if(!chJet)
378         continue;
379
380       Double_t frac = GetFractionSharedPt(fullJet,chJet);
381       Double_t dR = GetDeltaR(fullJet,chJet);
382       if(dR<dist){
383         faChMatchIndex[ifu]=ich;
384         dist = dR;
385       }
386       if(iDebug>10) Printf("Distance (%d)--(%d) %3.3f frac:%.2f",ifu,ich,dR,frac);
387     }
388     if(faChMatchIndex[ifu]>=0) iFlag[ifu*nChJets+faChMatchIndex[ifu]]+=1;//ich closest to ifu
389     if(iDebug>10) Printf("Full Distance (%d)--(%d) %3.3f flag[%d] = %d",ifu,faChMatchIndex[ifu],dist,ifu*nChJets+faChMatchIndex[ifu],iFlag[ifu*nChJets+faChMatchIndex[ifu]]);
390     
391     // reset...
392     faChMatchIndex[ifu]=-1;
393
394            
395   }//full jet loop
396
397
398   // other way around
399   for(int ich = 0;ich<nChJets;ich++){
400     AliEmcalJet *chJet = 0x0;
401     if(type==0)
402       chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
403     else {
404       chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
405       if(!chJet) continue;;
406       if(type>0) {
407         if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
408           continue;
409         if(type==2) {
410           if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
411             continue;
412         }
413       }
414     }
415     if(!chJet)
416       continue;
417
418     Float_t dist = maxDist;
419     for(int ifu = 0;ifu<nFullJets;ifu++){
420       AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
421       if(!fullJet)
422         continue;
423
424       Double_t dR = GetDeltaR(fullJet,chJet); 
425       if(dR<dist){
426         faChNeMatchIndex[ich]=ifu;
427         dist = dR;
428       }   
429     }
430     if(faChNeMatchIndex[ich]>=0) iFlag[faChNeMatchIndex[ich]*nChJets+ich]+=2;//ifu closest to ich
431     if(iDebug>10) Printf("Other way Distance (%d)--(%d) %3.3f flag[%d] = %d",faChNeMatchIndex[ich],ich,dist,faChNeMatchIndex[ich]*nChJets+ich,iFlag[faChNeMatchIndex[ich]*nChJets+ich]);
432
433     // reset...
434     faChNeMatchIndex[ich]=-1;
435     
436   }
437   
438   
439   // check for "true" correlations
440   for(int ifu = 0;ifu<nFullJets;ifu++){
441     for(int ich = 0;ich<nChJets;ich++){
442       AliDebug(11,Form("%s: Flag[%d][%d] %d ",GetName(),ifu,ich,iFlag[ifu*nChJets+ich]));
443       
444       if(kMode==3){
445         // we have a uniqe correlation
446         if(iFlag[ifu*nChJets+ich]==3){
447
448           AliEmcalJet *chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
449           AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetJetFromArray(ifu, cFull));
450           Double_t dR = GetDeltaR(fullJet,chJet); 
451
452           AliDebug(11,Form("closest jets %d  %d  dR =  %f",ich,ifu,dR));
453
454           chJet->SetClosestJet(fullJet,dR);
455           fullJet->SetClosestJet(chJet,dR);
456
457         }
458       }
459     }
460   }
461
462   fMatchingDone = kTRUE;
463   
464 }
465
466 //________________________________________________________________________
467 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndex() {
468
469   // take each full jet and set the index of the charged jet with the largest shared charged fraction
470
471   const Int_t nJetsCh   = GetNJets(fContainerCharged);
472   const Int_t nJetsFull = GetNJets(fContainerFull);
473   faFullFracIndex.Set(nJetsFull+1);
474   faFullFracIndex.Reset(-1);
475
476   AliJetContainer  *cont = GetJetContainer(fContainerFull); 
477   Float_t radius =  cont->GetJetRadius();
478
479   for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
480     Double_t frac = 0.;
481     Double_t dist = 10.;
482     AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFull));
483     if(!jetFull) {
484       faFullFracIndex.SetAt(-1,ifu);
485       continue;
486     }
487
488     for(Int_t ich = 0; ich<nJetsCh; ich++) {
489       AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerCharged));
490       if(!jetCh)
491         continue;
492       Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
493       dist = GetDeltaR(jetFull,jetCh);
494       if(tmpFrac>frac && dist<radius) {
495         frac = tmpFrac;
496         faFullFracIndex.SetAt(ich,ifu);
497       }
498     }
499
500   }
501
502 }
503
504 //________________________________________________________________________
505 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndexMC() {
506
507   // take each full jet and set the index of the charged jet with the largest shared charged fraction
508
509   const Int_t nJetsCh   = GetNJets(fContainerChargedMC);
510   const Int_t nJetsFull = GetNJets(fContainerFullMC);
511   faFullFracIndexMC.Set(nJetsFull);
512   faFullFracIndexMC.Reset(-1);
513
514   AliJetContainer  *cont = GetJetContainer(fContainerFullMC); 
515   Float_t radius =  cont->GetJetRadius();
516
517   for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
518     Double_t frac = 0.;
519     Double_t dist = 10.;
520     AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFullMC));
521     if(!jetFull) {
522       faFullFracIndexMC.SetAt(-1,ifu);
523       continue;
524     }
525
526     for(Int_t ich = 0; ich<nJetsCh; ich++) {
527       AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerChargedMC));
528       if(!jetCh)
529         continue;
530       Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
531       dist = GetDeltaR(jetFull,jetCh);
532       if(tmpFrac>frac && dist<radius) {
533         frac = tmpFrac;
534         faFullFracIndexMC.SetAt(ich,ifu);
535       }
536     }
537
538   }
539
540 }
541
542 //_______________________________________________________________________
543 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetLeadingJetOppositeHemisphere(Int_t type, Int_t typea, const AliEmcalJet *jetTrig) {
544
545   // Get leading jet in opposite hemisphere from trigger jet
546   // type = correlation type
547   // typea = container of associated jets
548
549   Int_t nJetsAssoc = GetNJets(typea);
550   Double_t ptLead = -999;
551   Int_t    iJetLead = -1;
552   for(Int_t ija=0; ija<nJetsAssoc; ija++) {
553
554     AliEmcalJet *jetAssoc = NULL;
555     if(type==0) {
556       jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
557       if(TMath::Abs(jetAssoc->Eta())>0.5)
558         jetAssoc = NULL;
559     }
560     else
561       jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
562
563     if(!jetAssoc)
564       continue;
565
566     Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
567     Double_t phiMin = 0.5*TMath::Pi();
568     Double_t phiMax = 1.5*TMath::Pi();
569     if(dPhi<phiMin || dPhi>phiMax)
570       continue;
571
572     Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
573
574     if(jetAssocPt>ptLead) {
575       ptLead = jetAssocPt;
576       iJetLead = ija;
577     }
578
579   }
580
581   AliEmcalJet *jetAssocLead = NULL;
582   if(iJetLead>-1)
583     jetAssocLead = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead, typea));
584
585   return jetAssocLead;
586
587 }
588
589 //_______________________________________________________________________
590 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetSecondLeadingJetOppositeHemisphere(Int_t type, Int_t typea, const AliEmcalJet *jetTrig) {
591
592   // Get leading jet in opposite hemisphere from trigger jet
593   // type = correlation type
594   // typea = container of associated jets
595
596   Int_t nJetsAssoc = GetNJets(typea);
597   Double_t ptLead = -999;
598   Int_t    iJetLead = -1;
599   Int_t    iJetLead2 = -1;
600   for(Int_t ija=0; ija<nJetsAssoc; ija++) {
601
602     AliEmcalJet *jetAssoc = NULL;
603     if(type==0) {
604       jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
605       if(TMath::Abs(jetAssoc->Eta())>0.5)
606         jetAssoc = NULL;
607     }
608     else
609       jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
610
611     if(!jetAssoc)
612       continue;
613
614     Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
615     Double_t phiMin = 0.5*TMath::Pi();
616     Double_t phiMax = 1.5*TMath::Pi();
617     if(dPhi<phiMin || dPhi>phiMax)
618       continue;
619
620     Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
621
622     if(jetAssocPt>ptLead) {
623       iJetLead2 = iJetLead;
624       ptLead = jetAssocPt;
625       iJetLead = ija;
626     }
627
628   }
629
630   AliEmcalJet *jetAssocLead2 = NULL;
631   if(iJetLead2>-1)
632     jetAssocLead2 = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead2, typea));
633
634   return jetAssocLead2;
635
636 }
637
638 //________________________________________________________________________
639 Bool_t AliAnalysisTaskEmcalDiJetBase::RetrieveEventObjects() {
640   //
641   // Retrieve objects from event.
642   //
643
644   if (!AliAnalysisTaskEmcalJet::RetrieveEventObjects())
645     return kFALSE;
646
647   if(fRhoType==0) {
648     fRhoFullVal = 0.;
649     fRhoChVal = 0.;
650   }
651   if(fRhoType==1) {
652     fRhoFullVal = GetRhoVal(fContainerFull);
653     fRhoChVal = GetRhoVal(fContainerCharged);
654   }
655
656   return kTRUE;
657 }
658
659 //_______________________________________________________________________
660 void AliAnalysisTaskEmcalDiJetBase::Terminate(Option_t *) 
661 {
662   // Called once at the end of the analysis.
663 }