2 // Dijet base analysis task.
6 #include <TClonesArray.h>
10 #include <THnSparse.h>
12 #include <TLorentzVector.h>
19 #include "AliVCluster.h"
20 #include "AliVTrack.h"
21 #include "AliEmcalJet.h"
22 #include "AliRhoParameter.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"
32 #include "AliAnalysisTaskEmcalDiJetBase.h"
34 ClassImp(AliAnalysisTaskEmcalDiJetBase)
36 //________________________________________________________________________
37 AliAnalysisTaskEmcalDiJetBase::AliAnalysisTaskEmcalDiJetBase() :
38 AliAnalysisTaskEmcalJet("AliAnalysisTaskEmcalDiJetBase", kTRUE),
40 fJetCorrelationType(kCorrelateAll),
41 fJetFullChargedMatchingType(kFraction),
45 fContainerChargedMC(3),
50 fDoChargedCharged(kTRUE),
51 fDoFullCharged(kTRUE),
53 fPtMinTriggerJet(10.),
54 fMinFractionShared(0.5),
55 fMatchingDone(kFALSE),
59 fHistTrialsSelEvents(0)
61 // Default constructor.
64 SetMakeGeneralHistograms(kTRUE);
68 //________________________________________________________________________
69 AliAnalysisTaskEmcalDiJetBase::AliAnalysisTaskEmcalDiJetBase(const char *name) :
70 AliAnalysisTaskEmcalJet(name, kTRUE),
72 fJetCorrelationType(kCorrelateAll),
73 fJetFullChargedMatchingType(kFraction),
77 fContainerChargedMC(3),
82 fDoChargedCharged(kTRUE),
83 fDoFullCharged(kTRUE),
85 fPtMinTriggerJet(10.),
86 fMinFractionShared(0.5),
87 fMatchingDone(kFALSE),
91 fHistTrialsSelEvents(0)
93 // Standard constructor.
95 SetMakeGeneralHistograms(kTRUE);
99 //________________________________________________________________________
100 AliAnalysisTaskEmcalDiJetBase::~AliAnalysisTaskEmcalDiJetBase()
105 //________________________________________________________________________
106 Bool_t AliAnalysisTaskEmcalDiJetBase::SelectEvent() {
108 // Decide if event should be selected for analysis
111 fhNEvents->Fill(3.5);
113 if(!fTriggerClass.IsNull()) {
114 //Check if requested trigger was fired
115 TString firedTrigClass = InputEvent()->GetFiredTriggerClasses();
116 if(!firedTrigClass.Contains(fTriggerClass))
118 if(fTriggerClass.Contains("J2") && firedTrigClass.Contains("J1")) //only accept J2 triggers which were not fired by J1 as well
122 fhNEvents->Fill(1.5);
124 fHistTrialsSelEvents->Fill(fPtHardBin, fNTrials);
130 //________________________________________________________________________
131 void AliAnalysisTaskEmcalDiJetBase::UserCreateOutputObjects()
133 // Create user output.
135 AliAnalysisTaskEmcalJet::UserCreateOutputObjects();
137 Bool_t oldStatus = TH1::AddDirectoryStatus();
138 TH1::AddDirectory(kFALSE);
140 fhNEvents = new TH1F("fhNEvents","fhNEvents;selection;N_{evt}",5,0,5);
141 fOutput->Add(fhNEvents);
144 fHistTrialsSelEvents = new TH1F("fHistTrialsSelEvents", "fHistTrialsSelEvents", 12, 0, 12);
145 fHistTrialsSelEvents->GetXaxis()->SetTitle("p_{T} hard bin");
146 fHistTrialsSelEvents->GetYaxis()->SetTitle("trials");
147 fOutput->Add(fHistTrialsSelEvents);
149 TH1::AddDirectory(oldStatus);
151 PostData(1, fOutput); // Post data for ALL output slots > 0 here.
154 //________________________________________________________________________
155 Bool_t AliAnalysisTaskEmcalDiJetBase::IsSameJet(const Int_t ijt, const Int_t ija, const Int_t type, const Bool_t isMC) {
156 //check if two jets are the same one
158 Bool_t bSame = kFALSE;
160 if(type<2 && ijt==ija)
164 if(fJetFullChargedMatchingType==kFraction) {
165 if(isMC && faFullFracIndexMC.At(ijt)==ija)
167 else if(!isMC && faFullFracIndex.At(ijt)==ija)
170 else if(fJetFullChargedMatchingType==kGeo) {
171 Int_t contFull = fContainerFull;
172 Int_t contChar = fContainerCharged;
174 contFull = fContainerFullMC;
175 contChar = fContainerChargedMC;
177 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ijt, contFull));
178 AliEmcalJet *chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, contChar));
179 AliEmcalJet *matchJet = fullJet->ClosestJet();
183 else if(fJetFullChargedMatchingType==kNoMatching) {
187 AliWarning(Form("%s: matching type unknown", GetName()));
195 //________________________________________________________________________
196 Double_t AliAnalysisTaskEmcalDiJetBase::GetJetPt(const AliEmcalJet *jet, const Int_t type) {
201 return jet->Pt() - fRhoFullVal * jet->Area();
203 return jet->Pt() - fRhoChVal * jet->Area();
209 //________________________________________________________________________
210 Double_t AliAnalysisTaskEmcalDiJetBase::GetZ(const AliVParticle *trk, const AliEmcalJet *jet) const
212 // Get Z of constituent trk
214 return GetZ(trk->Px(),trk->Py(),trk->Pz(),jet->Px(),jet->Py(),jet->Pz());
217 //________________________________________________________________________
218 Double_t AliAnalysisTaskEmcalDiJetBase::GetZ(const Double_t trkPx, const Double_t trkPy, const Double_t trkPz, const Double_t jetPx, const Double_t jetPy, const Double_t jetPz) const
221 // Get the z of a constituent inside of a jet
224 Double_t pJetSq = jetPx*jetPx+jetPy*jetPy+jetPz*jetPz;
227 return (trkPx*jetPx+trkPy*jetPy+trkPz*jetPz)/pJetSq;
229 AliWarning(Form("%s: strange, pjet*pjet seems to be zero pJetSq: %f",GetName(), pJetSq));
234 //________________________________________________________________________
235 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaR(const AliEmcalJet* jet1, const AliEmcalJet* jet2) const {
237 // Helper function to calculate the distance between two jets
240 Double_t dPhi = jet1->Phi() - jet2->Phi();
241 if(dPhi>TMath::Pi())dPhi = dPhi - 2.*TMath::Pi();
242 if(dPhi<(-1.*TMath::Pi()))dPhi = dPhi + 2.*TMath::Pi();
243 Double_t dEta = jet1->Eta() - jet2->Eta();
244 Double_t dR = TMath::Sqrt(dPhi*dPhi+dEta*dEta);
248 //________________________________________________________________________
249 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(const AliEmcalJet* jet1, const AliEmcalJet* jet2) {
251 // Calculate azimuthal angle between the axises of the jets
254 return GetDeltaPhi(jet1->Phi(),jet2->Phi());
258 //________________________________________________________________________
259 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(Double_t phi1,Double_t phi2) {
261 // Calculate azimuthal angle between the axises of the jets
264 Double_t dPhi = phi1-phi2;
266 if(dPhi <-0.5*TMath::Pi()) dPhi += TMath::TwoPi();
267 if(dPhi > 1.5*TMath::Pi()) dPhi -= TMath::TwoPi();
272 //________________________________________________________________________
273 Double_t AliAnalysisTaskEmcalDiJetBase::GetFractionSharedPt(const AliEmcalJet *jetFull, const AliEmcalJet *jetCharged) const
276 // Get fraction of shared pT between matched full and charged jet
277 // Uses charged jet pT as baseline: fraction = \Sum_{const,full jet} pT,const,i / pT,jet,ch
280 Double_t fraction = 0.;
281 Double_t jetPtCh = jetCharged->Pt();
285 if(fDebug>10) AliInfo(Form("%s: nConstituents: %d, ch: %d chne: %d ne: %d",GetName(),jetFull->GetNumberOfConstituents(),jetCharged->GetNumberOfTracks(),jetFull->GetNumberOfTracks(),jetFull->GetNumberOfClusters()));
288 AliVParticle *vpf = 0x0;
290 for(Int_t icc=0; icc<jetCharged->GetNumberOfTracks(); icc++) {
291 Int_t idx = (Int_t)jetCharged->TrackAt(icc);
293 for(Int_t icf=0; icf<jetFull->GetNumberOfTracks(); icf++) {
294 if(idx == jetFull->TrackAt(icf) && iFound==0 ) {
296 vpf = static_cast<AliVParticle*>(jetFull->TrackAt(icf, fTracks));
305 fraction = sumPt/jetPtCh;
308 if(fDebug>10) AliInfo(Form("%s: charged shared fraction: %.2f",GetName(),fraction));
314 //________________________________________________________________________
315 void AliAnalysisTaskEmcalDiJetBase::MatchJetsGeo(Int_t cFull, Int_t cCharged,
316 Int_t iDebug, Float_t maxDist, Int_t type) {
319 // Match the full jets to the corresponding charged jets
320 // Translation of AliAnalysisHelperJetTasks::GetClosestJets to AliEmcalJet objects
321 // 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)
325 const Int_t nChJets = GetNJets(cCharged);
326 const Int_t nFullJets = GetNJets(cFull);
328 if(nFullJets==0 || nChJets==0) return;
330 TArrayI faChNeMatchIndex;
331 faChNeMatchIndex.Set(nChJets+1);
333 TArrayI faChMatchIndex;
334 faChMatchIndex.Set(nFullJets+1);
336 static TArrayS iFlag(nChJets*nFullJets);
337 if(iFlag.GetSize()<(nChJets*nFullJets)){
338 iFlag.Set(nChJets*nFullJets+1);
342 AliJetContainer *contCh = GetJetContainer(cCharged);
344 // find the closest distance to the full jet
345 for(int ifu = 0;ifu<nFullJets;ifu++){
347 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
348 if(!fullJet) continue;
350 Float_t dist = maxDist;
352 for(int ich = 0;ich<nChJets;ich++){
353 AliEmcalJet *chJet = 0x0;
355 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
357 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
358 if(!chJet) continue;;
360 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
363 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
371 Double_t frac = GetFractionSharedPt(fullJet,chJet);
372 Double_t dR = GetDeltaR(fullJet,chJet);
374 faChMatchIndex[ifu]=ich;
377 if(iDebug>10) Printf("Distance (%d)--(%d) %3.3f frac:%.2f",ifu,ich,dR,frac);
379 if(faChMatchIndex[ifu]>=0) iFlag[ifu*nChJets+faChMatchIndex[ifu]]+=1;//ich closest to ifu
380 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]]);
383 faChMatchIndex[ifu]=-1;
390 for(int ich = 0;ich<nChJets;ich++){
391 AliEmcalJet *chJet = 0x0;
393 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
395 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
396 if(!chJet) continue;;
398 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
401 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
409 Float_t dist = maxDist;
410 for(int ifu = 0;ifu<nFullJets;ifu++){
411 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
415 Double_t dR = GetDeltaR(fullJet,chJet);
417 faChNeMatchIndex[ich]=ifu;
421 if(faChNeMatchIndex[ich]>=0) iFlag[faChNeMatchIndex[ich]*nChJets+ich]+=2;//ifu closest to ich
422 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]);
425 faChNeMatchIndex[ich]=-1;
430 // check for "true" correlations
431 for(int ifu = 0;ifu<nFullJets;ifu++){
432 for(int ich = 0;ich<nChJets;ich++){
433 if(iDebug>10) AliInfo(Form("%s: Flag[%d][%d] %d ",GetName(),ifu,ich,iFlag[ifu*nChJets+ich]));
436 // we have a uniqe correlation
437 if(iFlag[ifu*nChJets+ich]==3){
439 AliEmcalJet *chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
440 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetJetFromArray(ifu, cFull));
441 Double_t dR = GetDeltaR(fullJet,chJet);
443 if(iDebug>10) Printf("closest jets %d %d dR = %f",ich,ifu,dR);
445 chJet->SetClosestJet(fullJet,dR);
446 fullJet->SetClosestJet(chJet,dR);
453 fMatchingDone = kTRUE;
457 //________________________________________________________________________
458 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndex() {
460 // take each full jet and set the index of the charged jet with the largest shared charged fraction
462 const Int_t nJetsCh = GetNJets(fContainerCharged);
463 const Int_t nJetsFull = GetNJets(fContainerFull);
464 faFullFracIndex.Set(nJetsFull+1);
465 faFullFracIndex.Reset(-1);
467 AliJetContainer *cont = GetJetContainer(fContainerFull);
468 Float_t radius = cont->GetJetRadius();
470 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
473 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFull));
475 faFullFracIndex.SetAt(-1,ifu);
479 for(Int_t ich = 0; ich<nJetsCh; ich++) {
480 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerCharged));
483 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
484 dist = GetDeltaR(jetFull,jetCh);
485 if(tmpFrac>frac && dist<radius) {
487 faFullFracIndex.SetAt(ich,ifu);
495 //________________________________________________________________________
496 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndexMC() {
498 // take each full jet and set the index of the charged jet with the largest shared charged fraction
500 const Int_t nJetsCh = GetNJets(fContainerChargedMC);
501 const Int_t nJetsFull = GetNJets(fContainerFullMC);
502 faFullFracIndexMC.Set(nJetsFull);
503 faFullFracIndexMC.Reset(-1);
505 AliJetContainer *cont = GetJetContainer(fContainerFullMC);
506 Float_t radius = cont->GetJetRadius();
508 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
511 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFullMC));
513 faFullFracIndexMC.SetAt(-1,ifu);
517 for(Int_t ich = 0; ich<nJetsCh; ich++) {
518 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerChargedMC));
521 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
522 dist = GetDeltaR(jetFull,jetCh);
523 if(tmpFrac>frac && dist<radius) {
525 faFullFracIndexMC.SetAt(ich,ifu);
533 //_______________________________________________________________________
534 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetLeadingJetOppositeHemisphere(const Int_t type, const Int_t typea, const AliEmcalJet *jetTrig) {
536 // Get leading jet in opposite hemisphere from trigger jet
537 // type = correlation type
538 // typea = container of associated jets
540 Int_t nJetsAssoc = GetNJets(typea);
541 Double_t ptLead = -999;
543 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
545 AliEmcalJet *jetAssoc = NULL;
547 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
548 if(TMath::Abs(jetAssoc->Eta())>0.5)
552 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
557 Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
558 Double_t phiMin = 0.5*TMath::Pi();
559 Double_t phiMax = 1.5*TMath::Pi();
560 if(dPhi<phiMin || dPhi>phiMax)
563 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
565 if(jetAssocPt>ptLead) {
572 AliEmcalJet *jetAssocLead = NULL;
574 jetAssocLead = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead, typea));
580 //_______________________________________________________________________
581 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetSecondLeadingJetOppositeHemisphere(const Int_t type, const Int_t typea, const AliEmcalJet *jetTrig) {
583 // Get leading jet in opposite hemisphere from trigger jet
584 // type = correlation type
585 // typea = container of associated jets
587 Int_t nJetsAssoc = GetNJets(typea);
588 Double_t ptLead = -999;
590 Int_t iJetLead2 = -1;
591 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
593 AliEmcalJet *jetAssoc = NULL;
595 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
596 if(TMath::Abs(jetAssoc->Eta())>0.5)
600 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
605 Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
606 Double_t phiMin = 0.5*TMath::Pi();
607 Double_t phiMax = 1.5*TMath::Pi();
608 if(dPhi<phiMin || dPhi>phiMax)
611 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
613 if(jetAssocPt>ptLead) {
614 iJetLead2 = iJetLead;
621 AliEmcalJet *jetAssocLead2 = NULL;
623 jetAssocLead2 = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead2, typea));
625 return jetAssocLead2;
629 //________________________________________________________________________
630 Bool_t AliAnalysisTaskEmcalDiJetBase::RetrieveEventObjects() {
632 // Retrieve objects from event.
635 if (!AliAnalysisTaskEmcalJet::RetrieveEventObjects())
643 fRhoFullVal = GetRhoVal(fContainerFull);
644 fRhoChVal = GetRhoVal(fContainerCharged);
650 //_______________________________________________________________________
651 void AliAnalysisTaskEmcalDiJetBase::Terminate(Option_t *)
653 // Called once at the end of the analysis.