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("J1") && firedTrigClass.Contains("J2")) //assign J1&J2 triggers to J2 category
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);
332 faChNeMatchIndex.Reset(-1);
334 TArrayI faChMatchIndex;
335 faChMatchIndex.Set(nFullJets+1);
336 faChMatchIndex.Reset(-1);
338 static TArrayS iFlag(nChJets*nFullJets);
339 if(iFlag.GetSize()<(nChJets*nFullJets)){
340 iFlag.Set(nChJets*nFullJets+1);
344 AliJetContainer *contCh = GetJetContainer(cCharged);
346 // find the closest distance to the full jet
347 for(int ifu = 0;ifu<nFullJets;ifu++){
349 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
350 if(!fullJet) continue;
352 Float_t dist = maxDist;
354 for(int ich = 0;ich<nChJets;ich++){
355 AliEmcalJet *chJet = 0x0;
357 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
359 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
362 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
365 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
373 Double_t frac = GetFractionSharedPt(fullJet,chJet);
374 Double_t dR = GetDeltaR(fullJet,chJet);
376 faChMatchIndex[ifu]=ich;
379 if(iDebug>10) Printf("Distance (%d)--(%d) %3.3f frac:%.2f",ifu,ich,dR,frac);
381 if(faChMatchIndex[ifu]>=0) iFlag[ifu*nChJets+faChMatchIndex[ifu]]+=1;//ich closest to ifu
382 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]]);
385 faChMatchIndex[ifu]=-1;
392 for(int ich = 0;ich<nChJets;ich++){
393 AliEmcalJet *chJet = 0x0;
395 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
397 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
398 if(!chJet) continue;;
400 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
403 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
411 Float_t dist = maxDist;
412 for(int ifu = 0;ifu<nFullJets;ifu++){
413 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
417 Double_t dR = GetDeltaR(fullJet,chJet);
419 faChNeMatchIndex[ich]=ifu;
423 if(faChNeMatchIndex[ich]>=0) iFlag[faChNeMatchIndex[ich]*nChJets+ich]+=2;//ifu closest to ich
424 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]);
427 faChNeMatchIndex[ich]=-1;
432 // check for "true" correlations
433 for(int ifu = 0;ifu<nFullJets;ifu++){
434 for(int ich = 0;ich<nChJets;ich++){
435 if(iDebug>10) AliInfo(Form("%s: Flag[%d][%d] %d ",GetName(),ifu,ich,iFlag[ifu*nChJets+ich]));
438 // we have a uniqe correlation
439 if(iFlag[ifu*nChJets+ich]==3){
441 AliEmcalJet *chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
442 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetJetFromArray(ifu, cFull));
443 Double_t dR = GetDeltaR(fullJet,chJet);
445 if(iDebug>10) Printf("closest jets %d %d dR = %f",ich,ifu,dR);
447 chJet->SetClosestJet(fullJet,dR);
448 fullJet->SetClosestJet(chJet,dR);
455 fMatchingDone = kTRUE;
459 //________________________________________________________________________
460 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndex() {
462 // take each full jet and set the index of the charged jet with the largest shared charged fraction
464 const Int_t nJetsCh = GetNJets(fContainerCharged);
465 const Int_t nJetsFull = GetNJets(fContainerFull);
466 faFullFracIndex.Set(nJetsFull+1);
467 faFullFracIndex.Reset(-1);
469 AliJetContainer *cont = GetJetContainer(fContainerFull);
470 Float_t radius = cont->GetJetRadius();
472 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
475 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFull));
477 faFullFracIndex.SetAt(-1,ifu);
481 for(Int_t ich = 0; ich<nJetsCh; ich++) {
482 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerCharged));
485 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
486 dist = GetDeltaR(jetFull,jetCh);
487 if(tmpFrac>frac && dist<radius) {
489 faFullFracIndex.SetAt(ich,ifu);
497 //________________________________________________________________________
498 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndexMC() {
500 // take each full jet and set the index of the charged jet with the largest shared charged fraction
502 const Int_t nJetsCh = GetNJets(fContainerChargedMC);
503 const Int_t nJetsFull = GetNJets(fContainerFullMC);
504 faFullFracIndexMC.Set(nJetsFull);
505 faFullFracIndexMC.Reset(-1);
507 AliJetContainer *cont = GetJetContainer(fContainerFullMC);
508 Float_t radius = cont->GetJetRadius();
510 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
513 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFullMC));
515 faFullFracIndexMC.SetAt(-1,ifu);
519 for(Int_t ich = 0; ich<nJetsCh; ich++) {
520 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerChargedMC));
523 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
524 dist = GetDeltaR(jetFull,jetCh);
525 if(tmpFrac>frac && dist<radius) {
527 faFullFracIndexMC.SetAt(ich,ifu);
535 //_______________________________________________________________________
536 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetLeadingJetOppositeHemisphere(const Int_t type, const Int_t typea, const AliEmcalJet *jetTrig) {
538 // Get leading jet in opposite hemisphere from trigger jet
539 // type = correlation type
540 // typea = container of associated jets
542 Int_t nJetsAssoc = GetNJets(typea);
543 Double_t ptLead = -999;
545 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
547 AliEmcalJet *jetAssoc = NULL;
549 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
550 if(TMath::Abs(jetAssoc->Eta())>0.5)
554 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
559 Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
560 Double_t phiMin = 0.5*TMath::Pi();
561 Double_t phiMax = 1.5*TMath::Pi();
562 if(dPhi<phiMin || dPhi>phiMax)
565 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
567 if(jetAssocPt>ptLead) {
574 AliEmcalJet *jetAssocLead = NULL;
576 jetAssocLead = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead, typea));
582 //_______________________________________________________________________
583 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetSecondLeadingJetOppositeHemisphere(const Int_t type, const Int_t typea, const AliEmcalJet *jetTrig) {
585 // Get leading jet in opposite hemisphere from trigger jet
586 // type = correlation type
587 // typea = container of associated jets
589 Int_t nJetsAssoc = GetNJets(typea);
590 Double_t ptLead = -999;
592 Int_t iJetLead2 = -1;
593 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
595 AliEmcalJet *jetAssoc = NULL;
597 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
598 if(TMath::Abs(jetAssoc->Eta())>0.5)
602 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
607 Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
608 Double_t phiMin = 0.5*TMath::Pi();
609 Double_t phiMax = 1.5*TMath::Pi();
610 if(dPhi<phiMin || dPhi>phiMax)
613 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
615 if(jetAssocPt>ptLead) {
616 iJetLead2 = iJetLead;
623 AliEmcalJet *jetAssocLead2 = NULL;
625 jetAssocLead2 = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead2, typea));
627 return jetAssocLead2;
631 //________________________________________________________________________
632 Bool_t AliAnalysisTaskEmcalDiJetBase::RetrieveEventObjects() {
634 // Retrieve objects from event.
637 if (!AliAnalysisTaskEmcalJet::RetrieveEventObjects())
645 fRhoFullVal = GetRhoVal(fContainerFull);
646 fRhoChVal = GetRhoVal(fContainerCharged);
652 //_______________________________________________________________________
653 void AliAnalysisTaskEmcalDiJetBase::Terminate(Option_t *)
655 // Called once at the end of the analysis.