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();
117 if(!firedTrigClass.Contains(fTriggerClass))
119 else if(fTriggerClass.Contains("J1") && fTriggerClass.Contains("J2")) { //if events with J1&&J2 are requested
120 if(!firedTrigClass.Contains("J1") || !firedTrigClass.Contains("J2") ) //check if both are fired
123 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
127 fhNEvents->Fill(1.5);
129 fHistTrialsSelEvents->Fill(fPtHardBin, fNTrials);
135 //________________________________________________________________________
136 void AliAnalysisTaskEmcalDiJetBase::UserCreateOutputObjects()
138 // Create user output.
140 AliAnalysisTaskEmcalJet::UserCreateOutputObjects();
142 Bool_t oldStatus = TH1::AddDirectoryStatus();
143 TH1::AddDirectory(kFALSE);
145 fhNEvents = new TH1F("fhNEvents","fhNEvents;selection;N_{evt}",5,0,5);
146 fOutput->Add(fhNEvents);
149 fHistTrialsSelEvents = new TH1F("fHistTrialsSelEvents", "fHistTrialsSelEvents", 12, 0, 12);
150 fHistTrialsSelEvents->GetXaxis()->SetTitle("p_{T} hard bin");
151 fHistTrialsSelEvents->GetYaxis()->SetTitle("trials");
152 fOutput->Add(fHistTrialsSelEvents);
154 TH1::AddDirectory(oldStatus);
156 PostData(1, fOutput); // Post data for ALL output slots > 0 here.
159 //________________________________________________________________________
160 Bool_t AliAnalysisTaskEmcalDiJetBase::IsSameJet(const Int_t ijt, const Int_t ija, const Int_t type, const Bool_t isMC) {
161 //check if two jets are the same one
163 Bool_t bSame = kFALSE;
165 if(type<2 && ijt==ija)
169 if(fJetFullChargedMatchingType==kFraction) {
170 if(isMC && faFullFracIndexMC.At(ijt)==ija)
172 else if(!isMC && faFullFracIndex.At(ijt)==ija)
175 else if(fJetFullChargedMatchingType==kGeo) {
176 Int_t contFull = fContainerFull;
177 Int_t contChar = fContainerCharged;
179 contFull = fContainerFullMC;
180 contChar = fContainerChargedMC;
182 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ijt, contFull));
183 AliEmcalJet *chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, contChar));
184 AliEmcalJet *matchJet = fullJet->ClosestJet();
188 else if(fJetFullChargedMatchingType==kNoMatching) {
192 AliWarning(Form("%s: matching type unknown", GetName()));
200 //________________________________________________________________________
201 Double_t AliAnalysisTaskEmcalDiJetBase::GetJetPt(const AliEmcalJet *jet, const Int_t type) {
206 return jet->Pt() - fRhoFullVal * jet->Area();
208 return jet->Pt() - fRhoChVal * jet->Area();
214 //________________________________________________________________________
215 Double_t AliAnalysisTaskEmcalDiJetBase::GetZ(const AliVParticle *trk, const AliEmcalJet *jet) const
217 // Get Z of constituent trk
219 return GetZ(trk->Px(),trk->Py(),trk->Pz(),jet->Px(),jet->Py(),jet->Pz());
222 //________________________________________________________________________
223 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
226 // Get the z of a constituent inside of a jet
229 Double_t pJetSq = jetPx*jetPx+jetPy*jetPy+jetPz*jetPz;
232 return (trkPx*jetPx+trkPy*jetPy+trkPz*jetPz)/pJetSq;
234 AliWarning(Form("%s: strange, pjet*pjet seems to be zero pJetSq: %f",GetName(), pJetSq));
239 //________________________________________________________________________
240 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaR(const AliEmcalJet* jet1, const AliEmcalJet* jet2) const {
242 // Helper function to calculate the distance between two jets
245 Double_t dPhi = jet1->Phi() - jet2->Phi();
246 if(dPhi>TMath::Pi())dPhi = dPhi - 2.*TMath::Pi();
247 if(dPhi<(-1.*TMath::Pi()))dPhi = dPhi + 2.*TMath::Pi();
248 Double_t dEta = jet1->Eta() - jet2->Eta();
249 Double_t dR = TMath::Sqrt(dPhi*dPhi+dEta*dEta);
253 //________________________________________________________________________
254 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(const AliEmcalJet* jet1, const AliEmcalJet* jet2) {
256 // Calculate azimuthal angle between the axises of the jets
259 return GetDeltaPhi(jet1->Phi(),jet2->Phi());
263 //________________________________________________________________________
264 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(Double_t phi1,Double_t phi2) {
266 // Calculate azimuthal angle between the axises of the jets
269 Double_t dPhi = phi1-phi2;
271 if(dPhi <-0.5*TMath::Pi()) dPhi += TMath::TwoPi();
272 if(dPhi > 1.5*TMath::Pi()) dPhi -= TMath::TwoPi();
277 //________________________________________________________________________
278 Double_t AliAnalysisTaskEmcalDiJetBase::GetFractionSharedPt(const AliEmcalJet *jetFull, const AliEmcalJet *jetCharged) const
281 // Get fraction of shared pT between matched full and charged jet
282 // Uses charged jet pT as baseline: fraction = \Sum_{const,full jet} pT,const,i / pT,jet,ch
285 Double_t fraction = 0.;
286 Double_t jetPtCh = jetCharged->Pt();
290 AliDebug(11,Form("%s: nConstituents: %d, ch: %d chne: %d ne: %d",GetName(),jetFull->GetNumberOfConstituents(),jetCharged->GetNumberOfTracks(),jetFull->GetNumberOfTracks(),jetFull->GetNumberOfClusters()));
293 AliVParticle *vpf = 0x0;
295 for(Int_t icc=0; icc<jetCharged->GetNumberOfTracks(); icc++) {
296 Int_t idx = (Int_t)jetCharged->TrackAt(icc);
298 for(Int_t icf=0; icf<jetFull->GetNumberOfTracks(); icf++) {
299 if(idx == jetFull->TrackAt(icf) && iFound==0 ) {
301 vpf = static_cast<AliVParticle*>(jetFull->TrackAt(icf, fTracks));
310 fraction = sumPt/jetPtCh;
313 AliDebug(11,Form("%s: charged shared fraction: %.2f",GetName(),fraction));
319 //________________________________________________________________________
320 void AliAnalysisTaskEmcalDiJetBase::MatchJetsGeo(Int_t cFull, Int_t cCharged,
321 Int_t iDebug, Float_t maxDist, Int_t type) {
324 // Match the full jets to the corresponding charged jets
325 // Translation of AliAnalysisHelperJetTasks::GetClosestJets to AliEmcalJet objects
326 // 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)
330 const Int_t nChJets = GetNJets(cCharged);
331 const Int_t nFullJets = GetNJets(cFull);
333 if(nFullJets==0 || nChJets==0) return;
335 TArrayI faChNeMatchIndex;
336 faChNeMatchIndex.Set(nChJets+1);
337 faChNeMatchIndex.Reset(-1);
339 TArrayI faChMatchIndex;
340 faChMatchIndex.Set(nFullJets+1);
341 faChMatchIndex.Reset(-1);
343 static TArrayS iFlag(nChJets*nFullJets);
344 if(iFlag.GetSize()<(nChJets*nFullJets)){
345 iFlag.Set(nChJets*nFullJets+1);
349 AliJetContainer *contCh = GetJetContainer(cCharged);
351 // find the closest distance to the full jet
352 for(int ifu = 0;ifu<nFullJets;ifu++){
354 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
355 if(!fullJet) continue;
357 Float_t dist = maxDist;
359 for(int ich = 0;ich<nChJets;ich++){
360 AliEmcalJet *chJet = 0x0;
362 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
364 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
367 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
370 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
378 Double_t frac = GetFractionSharedPt(fullJet,chJet);
379 Double_t dR = GetDeltaR(fullJet,chJet);
381 faChMatchIndex[ifu]=ich;
384 if(iDebug>10) Printf("Distance (%d)--(%d) %3.3f frac:%.2f",ifu,ich,dR,frac);
386 if(faChMatchIndex[ifu]>=0) iFlag[ifu*nChJets+faChMatchIndex[ifu]]+=1;//ich closest to ifu
387 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 faChMatchIndex[ifu]=-1;
397 for(int ich = 0;ich<nChJets;ich++){
398 AliEmcalJet *chJet = 0x0;
400 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
402 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
403 if(!chJet) continue;;
405 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
408 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
416 Float_t dist = maxDist;
417 for(int ifu = 0;ifu<nFullJets;ifu++){
418 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
422 Double_t dR = GetDeltaR(fullJet,chJet);
424 faChNeMatchIndex[ich]=ifu;
428 if(faChNeMatchIndex[ich]>=0) iFlag[faChNeMatchIndex[ich]*nChJets+ich]+=2;//ifu closest to ich
429 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 faChNeMatchIndex[ich]=-1;
437 // check for "true" correlations
438 for(int ifu = 0;ifu<nFullJets;ifu++){
439 for(int ich = 0;ich<nChJets;ich++){
440 AliDebug(11,Form("%s: Flag[%d][%d] %d ",GetName(),ifu,ich,iFlag[ifu*nChJets+ich]));
443 // we have a uniqe correlation
444 if(iFlag[ifu*nChJets+ich]==3){
446 AliEmcalJet *chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
447 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetJetFromArray(ifu, cFull));
448 Double_t dR = GetDeltaR(fullJet,chJet);
450 AliDebug(11,Form("closest jets %d %d dR = %f",ich,ifu,dR));
452 chJet->SetClosestJet(fullJet,dR);
453 fullJet->SetClosestJet(chJet,dR);
460 fMatchingDone = kTRUE;
464 //________________________________________________________________________
465 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndex() {
467 // take each full jet and set the index of the charged jet with the largest shared charged fraction
469 const Int_t nJetsCh = GetNJets(fContainerCharged);
470 const Int_t nJetsFull = GetNJets(fContainerFull);
471 faFullFracIndex.Set(nJetsFull+1);
472 faFullFracIndex.Reset(-1);
474 AliJetContainer *cont = GetJetContainer(fContainerFull);
475 Float_t radius = cont->GetJetRadius();
477 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
480 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFull));
482 faFullFracIndex.SetAt(-1,ifu);
486 for(Int_t ich = 0; ich<nJetsCh; ich++) {
487 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerCharged));
490 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
491 dist = GetDeltaR(jetFull,jetCh);
492 if(tmpFrac>frac && dist<radius) {
494 faFullFracIndex.SetAt(ich,ifu);
502 //________________________________________________________________________
503 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndexMC() {
505 // take each full jet and set the index of the charged jet with the largest shared charged fraction
507 const Int_t nJetsCh = GetNJets(fContainerChargedMC);
508 const Int_t nJetsFull = GetNJets(fContainerFullMC);
509 faFullFracIndexMC.Set(nJetsFull);
510 faFullFracIndexMC.Reset(-1);
512 AliJetContainer *cont = GetJetContainer(fContainerFullMC);
513 Float_t radius = cont->GetJetRadius();
515 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
518 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFullMC));
520 faFullFracIndexMC.SetAt(-1,ifu);
524 for(Int_t ich = 0; ich<nJetsCh; ich++) {
525 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerChargedMC));
528 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
529 dist = GetDeltaR(jetFull,jetCh);
530 if(tmpFrac>frac && dist<radius) {
532 faFullFracIndexMC.SetAt(ich,ifu);
540 //_______________________________________________________________________
541 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetLeadingJetOppositeHemisphere(const Int_t type, const Int_t typea, const AliEmcalJet *jetTrig) {
543 // Get leading jet in opposite hemisphere from trigger jet
544 // type = correlation type
545 // typea = container of associated jets
547 Int_t nJetsAssoc = GetNJets(typea);
548 Double_t ptLead = -999;
550 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
552 AliEmcalJet *jetAssoc = NULL;
554 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
555 if(TMath::Abs(jetAssoc->Eta())>0.5)
559 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
564 Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
565 Double_t phiMin = 0.5*TMath::Pi();
566 Double_t phiMax = 1.5*TMath::Pi();
567 if(dPhi<phiMin || dPhi>phiMax)
570 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
572 if(jetAssocPt>ptLead) {
579 AliEmcalJet *jetAssocLead = NULL;
581 jetAssocLead = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead, typea));
587 //_______________________________________________________________________
588 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetSecondLeadingJetOppositeHemisphere(const Int_t type, const Int_t typea, const AliEmcalJet *jetTrig) {
590 // Get leading jet in opposite hemisphere from trigger jet
591 // type = correlation type
592 // typea = container of associated jets
594 Int_t nJetsAssoc = GetNJets(typea);
595 Double_t ptLead = -999;
597 Int_t iJetLead2 = -1;
598 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
600 AliEmcalJet *jetAssoc = NULL;
602 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
603 if(TMath::Abs(jetAssoc->Eta())>0.5)
607 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
612 Double_t dPhi = GetDeltaPhi(jetTrig,jetAssoc);
613 Double_t phiMin = 0.5*TMath::Pi();
614 Double_t phiMax = 1.5*TMath::Pi();
615 if(dPhi<phiMin || dPhi>phiMax)
618 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
620 if(jetAssocPt>ptLead) {
621 iJetLead2 = iJetLead;
628 AliEmcalJet *jetAssocLead2 = NULL;
630 jetAssocLead2 = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead2, typea));
632 return jetAssocLead2;
636 //________________________________________________________________________
637 Bool_t AliAnalysisTaskEmcalDiJetBase::RetrieveEventObjects() {
639 // Retrieve objects from event.
642 if (!AliAnalysisTaskEmcalJet::RetrieveEventObjects())
650 fRhoFullVal = GetRhoVal(fContainerFull);
651 fRhoChVal = GetRhoVal(fContainerCharged);
657 //_______________________________________________________________________
658 void AliAnalysisTaskEmcalDiJetBase::Terminate(Option_t *)
660 // Called once at the end of the analysis.