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.),
55 fMinFractionShared(0.5),
56 fMatchingDone(kFALSE),
60 fHistTrialsSelEvents(0)
62 // Default constructor.
65 SetMakeGeneralHistograms(kTRUE);
69 //________________________________________________________________________
70 AliAnalysisTaskEmcalDiJetBase::AliAnalysisTaskEmcalDiJetBase(const char *name) :
71 AliAnalysisTaskEmcalJet(name, kTRUE),
73 fJetCorrelationType(kCorrelateAll),
74 fJetFullChargedMatchingType(kFraction),
78 fContainerChargedMC(3),
83 fDoChargedCharged(kTRUE),
84 fDoFullCharged(kTRUE),
86 fPtMinTriggerJet(10.),
88 fMinFractionShared(0.5),
89 fMatchingDone(kFALSE),
93 fHistTrialsSelEvents(0)
95 // Standard constructor.
97 SetMakeGeneralHistograms(kTRUE);
101 //________________________________________________________________________
102 AliAnalysisTaskEmcalDiJetBase::~AliAnalysisTaskEmcalDiJetBase()
107 //________________________________________________________________________
108 Bool_t AliAnalysisTaskEmcalDiJetBase::SelectEvent() {
110 // Decide if event should be selected for analysis
113 fhNEvents->Fill(3.5);
115 if(!fTriggerClass.IsNull()) {
116 //Check if requested trigger was fired
117 TString firedTrigClass = InputEvent()->GetFiredTriggerClasses();
119 if(!firedTrigClass.Contains(fTriggerClass))
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
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
129 fhNEvents->Fill(1.5);
131 fHistTrialsSelEvents->Fill(fPtHardBin, fNTrials);
137 //________________________________________________________________________
138 void AliAnalysisTaskEmcalDiJetBase::UserCreateOutputObjects()
140 // Create user output.
142 AliAnalysisTaskEmcalJet::UserCreateOutputObjects();
144 Bool_t oldStatus = TH1::AddDirectoryStatus();
145 TH1::AddDirectory(kFALSE);
147 fhNEvents = new TH1F("fhNEvents","fhNEvents;selection;N_{evt}",5,0,5);
148 fOutput->Add(fhNEvents);
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);
156 TH1::AddDirectory(oldStatus);
158 PostData(1, fOutput); // Post data for ALL output slots > 0 here.
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
165 Bool_t bSame = kFALSE;
167 if(type<2 && ijt==ija)
171 if(fJetFullChargedMatchingType==kFraction) {
172 if(isMC && faFullFracIndexMC.At(ijt)==ija)
174 else if(!isMC && faFullFracIndex.At(ijt)==ija)
177 else if(fJetFullChargedMatchingType==kGeo) {
178 Int_t contFull = fContainerFull;
179 Int_t contChar = fContainerCharged;
181 contFull = fContainerFullMC;
182 contChar = fContainerChargedMC;
184 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ijt, contFull));
185 AliEmcalJet *chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, contChar));
186 AliEmcalJet *matchJet = fullJet->ClosestJet();
190 else if(fJetFullChargedMatchingType==kNoMatching) {
194 AliWarning(Form("%s: matching type unknown", GetName()));
202 //________________________________________________________________________
203 Double_t AliAnalysisTaskEmcalDiJetBase::GetJetPt(const AliEmcalJet *jet, Int_t type) {
208 return jet->Pt() - fRhoFullVal * jet->Area();
210 return jet->Pt() - fRhoChVal * jet->Area();
216 //________________________________________________________________________
217 Double_t AliAnalysisTaskEmcalDiJetBase::GetZ(const AliVParticle *trk, const AliEmcalJet *jet) const
219 // Get Z of constituent trk
221 return GetZ(trk->Px(),trk->Py(),trk->Pz(),jet->Px(),jet->Py(),jet->Pz());
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
228 // Get the z of a constituent inside of a jet
231 Double_t pJetSq = jetPx*jetPx+jetPy*jetPy+jetPz*jetPz;
234 return (trkPx*jetPx+trkPy*jetPy+trkPz*jetPz)/pJetSq;
236 AliWarning(Form("%s: strange, pjet*pjet seems to be zero pJetSq: %f",GetName(), pJetSq));
241 //________________________________________________________________________
242 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaR(const AliEmcalJet* jet1, const AliEmcalJet* jet2) const {
244 // Helper function to calculate the distance between two jets
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);
255 //________________________________________________________________________
256 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(const AliEmcalJet* jet1, const AliEmcalJet* jet2) {
258 // Calculate azimuthal angle between the axises of the jets
261 return GetDeltaPhi(jet1->Phi(),jet2->Phi());
265 //________________________________________________________________________
266 Double_t AliAnalysisTaskEmcalDiJetBase::GetDeltaPhi(Double_t phi1,Double_t phi2) {
268 // Calculate azimuthal angle between the axises of the jets
271 Double_t dPhi = phi1-phi2;
273 if(dPhi <-0.5*TMath::Pi()) dPhi += TMath::TwoPi();
274 if(dPhi > 1.5*TMath::Pi()) dPhi -= TMath::TwoPi();
279 //________________________________________________________________________
280 Double_t AliAnalysisTaskEmcalDiJetBase::GetFractionSharedPt(const AliEmcalJet *jetFull, const AliEmcalJet *jetCharged) const
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
287 Double_t fraction = 0.;
288 Double_t jetPtCh = jetCharged->Pt();
292 AliDebug(11,Form("%s: nConstituents: %d, ch: %d chne: %d ne: %d",GetName(),jetFull->GetNumberOfConstituents(),jetCharged->GetNumberOfTracks(),jetFull->GetNumberOfTracks(),jetFull->GetNumberOfClusters()));
295 AliVParticle *vpf = 0x0;
297 for(Int_t icc=0; icc<jetCharged->GetNumberOfTracks(); icc++) {
298 Int_t idx = (Int_t)jetCharged->TrackAt(icc);
300 for(Int_t icf=0; icf<jetFull->GetNumberOfTracks(); icf++) {
301 if(idx == jetFull->TrackAt(icf) && iFound==0 ) {
303 vpf = static_cast<AliVParticle*>(jetFull->TrackAt(icf, fTracks));
312 fraction = sumPt/jetPtCh;
315 AliDebug(11,Form("%s: charged shared fraction: %.2f",GetName(),fraction));
321 //________________________________________________________________________
322 void AliAnalysisTaskEmcalDiJetBase::MatchJetsGeo(Int_t cFull, Int_t cCharged,
323 Int_t iDebug, Float_t maxDist, Int_t type) {
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)
332 const Int_t nChJets = GetNJets(cCharged);
333 const Int_t nFullJets = GetNJets(cFull);
335 if(nFullJets==0 || nChJets==0) return;
337 TArrayI faChNeMatchIndex;
338 faChNeMatchIndex.Set(nChJets+1);
339 faChNeMatchIndex.Reset(-1);
341 TArrayI faChMatchIndex;
342 faChMatchIndex.Set(nFullJets+1);
343 faChMatchIndex.Reset(-1);
345 static TArrayS iFlag(nChJets*nFullJets);
346 if(iFlag.GetSize()<(nChJets*nFullJets)){
347 iFlag.Set(nChJets*nFullJets+1);
351 AliJetContainer *contCh = GetJetContainer(cCharged);
353 // find the closest distance to the full jet
354 for(int ifu = 0;ifu<nFullJets;ifu++){
356 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
357 if(!fullJet) continue;
359 Float_t dist = maxDist;
361 for(int ich = 0;ich<nChJets;ich++){
362 AliEmcalJet *chJet = 0x0;
364 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
366 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
369 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
372 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
380 Double_t frac = GetFractionSharedPt(fullJet,chJet);
381 Double_t dR = GetDeltaR(fullJet,chJet);
383 faChMatchIndex[ifu]=ich;
386 if(iDebug>10) Printf("Distance (%d)--(%d) %3.3f frac:%.2f",ifu,ich,dR,frac);
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]]);
392 faChMatchIndex[ifu]=-1;
399 for(int ich = 0;ich<nChJets;ich++){
400 AliEmcalJet *chJet = 0x0;
402 chJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, cCharged));
404 chJet = static_cast<AliEmcalJet*>(GetJetFromArray(ich, cCharged));
405 if(!chJet) continue;;
407 if(chJet->Eta()<(contCh->GetJetEtaMin()-0.1) || chJet->Eta()>(contCh->GetJetEtaMax()+0.1))
410 if(chJet->Phi()<(contCh->GetJetPhiMin()-0.1) || chJet->Phi()>(contCh->GetJetPhiMax()+0.1))
418 Float_t dist = maxDist;
419 for(int ifu = 0;ifu<nFullJets;ifu++){
420 AliEmcalJet *fullJet = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, cFull));
424 Double_t dR = GetDeltaR(fullJet,chJet);
426 faChNeMatchIndex[ich]=ifu;
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]);
434 faChNeMatchIndex[ich]=-1;
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]));
445 // we have a uniqe correlation
446 if(iFlag[ifu*nChJets+ich]==3){
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);
452 AliDebug(11,Form("closest jets %d %d dR = %f",ich,ifu,dR));
454 chJet->SetClosestJet(fullJet,dR);
455 fullJet->SetClosestJet(chJet,dR);
462 fMatchingDone = kTRUE;
466 //________________________________________________________________________
467 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndex() {
469 // take each full jet and set the index of the charged jet with the largest shared charged fraction
471 const Int_t nJetsCh = GetNJets(fContainerCharged);
472 const Int_t nJetsFull = GetNJets(fContainerFull);
473 faFullFracIndex.Set(nJetsFull+1);
474 faFullFracIndex.Reset(-1);
476 AliJetContainer *cont = GetJetContainer(fContainerFull);
477 Float_t radius = cont->GetJetRadius();
479 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
482 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFull));
484 faFullFracIndex.SetAt(-1,ifu);
488 for(Int_t ich = 0; ich<nJetsCh; ich++) {
489 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerCharged));
492 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
493 dist = GetDeltaR(jetFull,jetCh);
494 if(tmpFrac>frac && dist<radius) {
496 faFullFracIndex.SetAt(ich,ifu);
504 //________________________________________________________________________
505 void AliAnalysisTaskEmcalDiJetBase::SetChargedFractionIndexMC() {
507 // take each full jet and set the index of the charged jet with the largest shared charged fraction
509 const Int_t nJetsCh = GetNJets(fContainerChargedMC);
510 const Int_t nJetsFull = GetNJets(fContainerFullMC);
511 faFullFracIndexMC.Set(nJetsFull);
512 faFullFracIndexMC.Reset(-1);
514 AliJetContainer *cont = GetJetContainer(fContainerFullMC);
515 Float_t radius = cont->GetJetRadius();
517 for(Int_t ifu = 0; ifu<nJetsFull; ifu++) {
520 AliEmcalJet *jetFull = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ifu, fContainerFullMC));
522 faFullFracIndexMC.SetAt(-1,ifu);
526 for(Int_t ich = 0; ich<nJetsCh; ich++) {
527 AliEmcalJet *jetCh = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ich, fContainerChargedMC));
530 Double_t tmpFrac = GetFractionSharedPt(jetFull,jetCh);
531 dist = GetDeltaR(jetFull,jetCh);
532 if(tmpFrac>frac && dist<radius) {
534 faFullFracIndexMC.SetAt(ich,ifu);
542 //_______________________________________________________________________
543 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetLeadingJetOppositeHemisphere(Int_t type, Int_t typea, const AliEmcalJet *jetTrig) {
545 // Get leading jet in opposite hemisphere from trigger jet
546 // type = correlation type
547 // typea = container of associated jets
549 Int_t nJetsAssoc = GetNJets(typea);
550 Double_t ptLead = -999;
552 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
554 AliEmcalJet *jetAssoc = NULL;
556 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
557 if(TMath::Abs(jetAssoc->Eta())>0.5)
561 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
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)
572 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
574 if(jetAssocPt>ptLead) {
581 AliEmcalJet *jetAssocLead = NULL;
583 jetAssocLead = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead, typea));
589 //_______________________________________________________________________
590 AliEmcalJet* AliAnalysisTaskEmcalDiJetBase::GetSecondLeadingJetOppositeHemisphere(Int_t type, Int_t typea, const AliEmcalJet *jetTrig) {
592 // Get leading jet in opposite hemisphere from trigger jet
593 // type = correlation type
594 // typea = container of associated jets
596 Int_t nJetsAssoc = GetNJets(typea);
597 Double_t ptLead = -999;
599 Int_t iJetLead2 = -1;
600 for(Int_t ija=0; ija<nJetsAssoc; ija++) {
602 AliEmcalJet *jetAssoc = NULL;
604 jetAssoc = static_cast<AliEmcalJet*>(GetJetFromArray(ija, typea));
605 if(TMath::Abs(jetAssoc->Eta())>0.5)
609 jetAssoc = static_cast<AliEmcalJet*>(GetAcceptJetFromArray(ija, typea));
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)
620 Double_t jetAssocPt = GetJetPt(jetAssoc,typea);
622 if(jetAssocPt>ptLead) {
623 iJetLead2 = iJetLead;
630 AliEmcalJet *jetAssocLead2 = NULL;
632 jetAssocLead2 = static_cast<AliEmcalJet*>(GetJetFromArray(iJetLead2, typea));
634 return jetAssocLead2;
638 //________________________________________________________________________
639 Bool_t AliAnalysisTaskEmcalDiJetBase::RetrieveEventObjects() {
641 // Retrieve objects from event.
644 if (!AliAnalysisTaskEmcalJet::RetrieveEventObjects())
652 fRhoFullVal = GetRhoVal(fContainerFull);
653 fRhoChVal = GetRhoVal(fContainerCharged);
659 //_______________________________________________________________________
660 void AliAnalysisTaskEmcalDiJetBase::Terminate(Option_t *)
662 // Called once at the end of the analysis.