33 #include <THnSparse.h> 36 #include "AliAnalysisManager.h" 50 namespace EMCALJetTasks{
52 AliEmcalJetTaggerTaskFast::AliEmcalJetTaggerTaskFast() :
54 fJetTaggingType(kTag),
55 fJetTaggingMethod(kGeo),
59 fMinFractionShared(0),
62 fTypeAcc(kLimitBaseTagEtaPhi),
65 fh3PtJet1VsDeltaEtaDeltaPhi(
nullptr),
68 fh2PtJet1VsLeadPtAllSel(
nullptr),
69 fh2PtJet1VsLeadPtTagged(
nullptr),
75 #ifdef JETTAGGERFAST_TEST
78 , fContainerErrorRateBase(
nullptr)
79 , fContainerErrorRateTag(
nullptr)
126 #ifdef JETTAGGERFAST_TEST
129 , fContainerErrorRateBase(
nullptr)
130 , fContainerErrorRateTag(
nullptr)
159 Bool_t oldStatus = TH1::AddDirectoryStatus();
160 TH1::AddDirectory(kFALSE);
162 const Int_t nBinsPt = 40;
163 const Int_t nBinsDPhi = 72;
164 const Int_t nBinsDEta = 100;
165 const Int_t nBinsDR = 50;
166 const Int_t nBinsFraction = 101;
176 const Double_t minFraction = -0.005;
183 histName = TString::Format(
"fh3PtJet1VsDeltaEtaDeltaPhi_%d",i);
184 histTitle = TString::Format(
"%s;#it{p}_{T,jet1};#it{#Delta#eta};#it{#Delta#varphi}",histName.Data());
185 fh3PtJet1VsDeltaEtaDeltaPhi[i] =
new TH3F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsDEta,minDEta,maxDEta,nBinsDPhi,minDPhi,maxDPhi);
186 fOutput->Add(fh3PtJet1VsDeltaEtaDeltaPhi[i]);
188 histName = TString::Format(
"fh2PtJet1VsDeltaR_%d",i);
189 histTitle = TString::Format(
"%s;#it{p}_{T,jet1};#it{#Delta R}",histName.Data());
190 fh2PtJet1VsDeltaR[i] =
new TH2F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsDR,minDR,maxDR);
191 fOutput->Add(fh2PtJet1VsDeltaR[i]);
193 histName = TString::Format(
"fh2PtJet2VsFraction_%d",i);
194 histTitle = TString::Format(
"%s;#it{p}_{T,jet2};#it{f}_{shared}",histName.Data());
195 fh2PtJet2VsFraction[i] =
new TH2F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsFraction,minFraction,maxFraction);
196 fOutput->Add(fh2PtJet2VsFraction[i]);
198 histName = TString::Format(
"fh2PtJet1VsLeadPtAllSel_%d",i);
199 histTitle = TString::Format(
"%s;#it{p}_{T,jet1};#it{p}_{T,lead trk}",histName.Data());
201 fOutput->Add(fh2PtJet1VsLeadPtAllSel[i]);
203 histName = TString::Format(
"fh2PtJet1VsLeadPtTagged_%d",i);
204 histTitle = TString::Format(
"%s;#it{p}_{T,jet1};#it{p}_{T,lead trk}",histName.Data());
206 fOutput->Add(fh2PtJet1VsLeadPtTagged[i]);
208 histName = TString::Format(
"fh2PtJet1VsPtJet2_%d",i);
209 histTitle = TString::Format(
"%s;#it{p}_{T,jet1};#it{p}_{T,jet2}",histName.Data());
210 fh2PtJet1VsPtJet2[i] =
new TH2F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,nBinsPt,minPt,maxPt);
211 fOutput->Add(fh2PtJet1VsPtJet2[i]);
213 histName = TString::Format(
"fh2PtJet2VsRelPt_%d",i);
214 histTitle = TString::Format(
"%s;#it{p}_{T,jet2};(#it{p}_{T,jet2}-#it{p}_{T,jet1})/#it{p}_{T,jet1}",histName.Data());
215 fh2PtJet2VsRelPt[i] =
new TH2F(histName.Data(),histTitle.Data(),nBinsPt,minPt,maxPt,241,-2.41,2.41);
216 fOutput->Add(fh2PtJet2VsRelPt[i]);
219 fh3PtJetDEtaDPhiConst =
new TH3F(
"fh3PtJetDEtaDPhiConst",
"fh3PtJetDEtaDPhiConst;pT;#Delta #eta;#Delta #varphi",nBinsPt,minPt,maxPt,nBinsDEta,-1.,1.,nBinsDPhi,-1.,1.);
222 fh3PtJetAreaDRConst =
new TH3F(
"fh3PtJetAreaDRConst",
"fh3PtJetAreaDRConst;pT;A;#Delta R",nBinsPt,minPt,maxPt,50,0.,1.,50,0.,1.);
225 fNAccJets =
new TH1F(
"fNAccJets",
"fNAccJets;N/ev",11,-0.5, 9.5);
228 #ifdef JETTAGGERFAST_TEST 229 fIndexErrorRateBase =
new TH1F(
"indexErrorsBase",
"Index errors nearest neighbor base jets", 1, 0.5, 1.5);
230 fIndexErrorRateTag =
new TH1F(
"indexErrorsTag",
"Index errors nearest neighbors tag jets", 1, 0.5, 1.5);
231 fContainerErrorRateBase =
new TH1F(
"containerErrorsBase",
"Matching errors container - kdtree base jets", 1, 0.5, 1.5);
232 fContainerErrorRateTag =
new TH1F(
"containerErrorsTag",
"Matching errors container - kdtree tag jets", 1, 0.5, 1.5);
233 fOutput->Add(fIndexErrorRateBase);
234 fOutput->Add(fIndexErrorRateTag);
235 fOutput->Add(fContainerErrorRateBase);
236 fOutput->Add(fContainerErrorRateTag);
242 TH1 *h1 =
dynamic_cast<TH1*
>(it);
247 THnSparse *hn =
dynamic_cast<THnSparse*
>(it);
252 TH1::AddDirectory(oldStatus);
263 if(!cont1 || !cont2) AliError(
"Missing jet container");
267 Bool_t isZeroTwoPi1 = kFALSE;
269 if(phiMin1 > -1.e-6 && phiMin1 < 1.e-6) isZeroTwoPi1 = kTRUE;
270 Bool_t isZeroTwoPi2 = kFALSE;
271 if(phiMin2 > -1.e-6 && phiMin2 < 1.e-6) isZeroTwoPi2 = kTRUE;
312 if(!jetCont)
return kFALSE;
313 jetCont->ResetCurrentID();
322 AliVParticle *vp =
static_cast<AliVParticle*
>(jet1->
Track(icc));
326 if(dPhi<TMath::Pi()) dPhi+=TMath::TwoPi();
327 if(dPhi>TMath::Pi()) dPhi-=TMath::TwoPi();
330 Double_t dR = TMath::Sqrt(dPhi*dPhi+dEta*dEta);
359 dPhi -= TMath::TwoPi();
360 if(dPhi<(-1.*TMath::Pi()))
361 dPhi += TMath::TwoPi();
371 for(
auto j : c.
all()){
377 j->SetTaggedJet(
nullptr);
386 if(!(kNacceptedBase && kNacceptedTag))
return false;
389 TArrayD etaBase(kNacceptedBase), phiBase(kNacceptedBase),
390 etaTag(kNacceptedTag), phiTag(kNacceptedTag);
391 std::vector<AliEmcalJet *> jetsBase(kNacceptedBase), jetsTag(kNacceptedTag);
393 int countBase(0), countTag(0);
394 for(
auto jb : contBase.
accepted()) {
395 etaBase[countBase] = jb->Eta();
396 phiBase[countBase] = jb->Phi();
397 jetsBase[countBase] = jb;
401 etaTag[countTag] = jt->Eta();
402 phiTag[countTag] = jt->Phi();
403 jetsTag[countTag] = jt;
406 TKDTreeID treeBase(etaBase.GetSize(), 2, 1), treeTag(etaTag.GetSize(), 2, 1);
407 treeBase.SetData(0, etaBase.GetArray());
408 treeBase.SetData(1, phiBase.GetArray());
410 treeTag.SetData(0, etaTag.GetArray());
411 treeTag.SetData(1, phiTag.GetArray());
414 TArrayI faMatchIndexTag(kNacceptedBase), faMatchIndexBase(kNacceptedTag);
415 faMatchIndexBase.Reset(-1);
416 faMatchIndexTag.Reset(-1);
421 Double_t point[2] = {j->Eta(), j->Phi()};
423 treeTag.FindNearestNeighbors(point, 1, &index, &distance);
425 if(index >= 0 && distance < maxDist){
426 AliDebugStream(1) <<
"Found closest tag jet for " << countBase <<
" with match index " << index <<
" and distance " << distance << std::endl;
427 faMatchIndexTag[countBase]=index;
429 AliDebugStream(1) <<
"Not found closest tag jet for " << countBase <<
", distance to closest " << distance << std::endl;
432 #ifdef JETTAGGERFAST_TEST 435 distanceTest = TMath::Sqrt(TMath::Power(etaTag[index] - j->Eta(), 2) + TMath::Power(phiTag[index] - j->Phi(), 2));
436 if(TMath::Abs(distanceTest - distance) > DBL_EPSILON){
437 AliDebugStream(1) <<
"Mismatch in distance from tag jet with index from tree: " << distanceTest <<
", distance from tree " << distance << std::endl;
438 fIndexErrorRateBase->Fill(1);
449 Double_t point[2] = {j->Eta(), j->Phi()};
451 treeBase.FindNearestNeighbors(point, 1, &index, &distance);
452 if(index >= 0 && distance < maxDist){
453 AliDebugStream(1) <<
"Found closest base jet for " << countBase <<
" with match index " << index <<
" and distance " << distance << std::endl;
454 faMatchIndexBase[countTag]=index;
456 AliDebugStream(1) <<
"Not found closest tag jet for " << countBase <<
", distance to closest " << distance << std::endl;
459 #ifdef JETTAGGERFAST_TEST 462 distanceTest = TMath::Sqrt(TMath::Power(etaBase[index] - j->Eta(), 2) + TMath::Power(phiBase[index] - j->Phi(), 2));
463 if(TMath::Abs(distanceTest - distance) > DBL_EPSILON){
464 AliDebugStream(1) <<
"Mismatch in distance from base jet with index from tree: " << distanceTest <<
", distance from tree " << distance << std::endl;
465 fIndexErrorRateTag->Fill(1);
476 AliDebugStream(1) <<
"Starting true jet loop: nbase(" << kNacceptedBase <<
"), ntag(" << kNacceptedTag <<
")\n";
477 for(
int ibase = 0; ibase < kNacceptedBase; ibase++) {
478 AliDebugStream(2) <<
"base jet " << ibase <<
": match index in tag jet container " << faMatchIndexTag[ibase] <<
"\n";
479 if(faMatchIndexTag[ibase] > -1){
480 AliDebugStream(2) <<
"tag jet " << faMatchIndexTag[ibase] <<
": matched base jet " << faMatchIndexBase[faMatchIndexTag[ibase]] <<
"\n";
482 if(faMatchIndexTag[ibase] > -1 && faMatchIndexBase[faMatchIndexTag[ibase]] == ibase) {
483 AliDebugStream(2) <<
"found a true match \n";
485 *jetTag = jetsTag[faMatchIndexTag[ibase]];
486 if(jetBase && jetTag) {
487 #ifdef JETTAGGERFAST_TEST 488 if(TMath::Abs(etaBase[ibase] - jetBase->
Eta()) > DBL_EPSILON || TMath::Abs(phiBase[ibase] - jetBase->
Phi()) > DBL_EPSILON){
489 AliErrorStream() <<
"Selected incorrect base jet for tagging : eta test(" << jetBase->
Eta() <<
")/true(" << etaBase[ibase]
490 <<
"), phi test(" << jetBase->
Phi() <<
")/true(" << phiBase[ibase] <<
")\n";
491 fContainerErrorRateBase->Fill(1);
493 if(TMath::Abs(etaTag[faMatchIndexTag[ibase]] - jetTag->Eta()) > DBL_EPSILON || TMath::Abs(phiTag[faMatchIndexTag[ibase]] - jetTag->Phi()) > DBL_EPSILON){
494 AliErrorStream() <<
"Selected incorrect tag jet for tagging : eta test(" << jetTag->Eta() <<
")/true(" << etaTag[faMatchIndexTag[ibase]]
495 <<
"), phi test(" << jetTag->Phi() <<
")/true(" << phiTag[faMatchIndexTag[ibase]] <<
")\n";
496 fContainerErrorRateTag->Fill(1);
506 jetTag->SetTaggedJet(jetBase);
507 jetTag->SetTagStatus(1);
511 jetTag->SetClosestJet(jetBase,dR);
526 if(dPhi <-0.5*TMath::Pi()) dPhi += TMath::TwoPi();
527 if(dPhi > 1.5*TMath::Pi()) dPhi -= TMath::TwoPi();
533 const char * njetsTag,
535 const char * nrhoBase,
536 const char * nrhoTag,
537 const char * ntracks,
538 const char * nclusters,
540 const char * CentEst,
542 const char * trigClass){
546 std::cerr <<
"E-AddEmcalJetTaggerTaskFast: No analysis manager found.\n";
551 if (!mgr->GetInputEventHandler())
553 std::cerr <<
"E-AddEmcalJetTaggerTaskFast: This task requires an input event handler\n";
557 TString wagonName = Form(
"JetTagger_%s_%s_TC%s",njetsBase,njetsTag,trigClass);
587 for(
Int_t i=0; i<2; i++) {
591 task->SelectCollisionCandidates(pSel);
597 mgr->ConnectInput (task, 0, mgr->GetCommonInputContainer() );
601 TString outputfile = Form(
"%s",AliAnalysisManager::GetCommonFileName());
602 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(contName.Data(), TList::Class(),AliAnalysisManager::kOutputContainer,outputfile);
603 mgr->ConnectOutput(task,1,coutput1);
void SetTagStatus(Int_t i)
void SetPercAreaCut(Float_t p, Int_t c=0)
Double_t GetRhoVal() const
JetTaggingType fJetTaggingType
jet matching type
AliEmcalJet * GetTaggedJet() const
Double_t GetJetEtaMin() const
void SetTaggedJet(AliEmcalJet *j)
Adding 0.1 in eta and phi limits for tag jets.
AliEmcalJet * ClosestJet() const
AliJetContainer * GetJetContainer(Int_t i=0) const
Int_t GetTagStatus() const
TH2 ** fh2PtJet1VsPtJet2
! pT of base jet vs tagged jet
Double_t GetJetPhiMax() const
AliEmcalJetTaggerTaskFast()
Default constructor.
void SetUseAliAnaUtils(Bool_t b, Bool_t bRejPilup=kTRUE)
TH3 ** fh3PtJet1VsDeltaEtaDeltaPhi
! jet 1 vs deta vs dphi
TH1 * fNAccJets
! number of jets per event
Adding 0.1 in eta and phi limits for both base and tag jets.
Double_t GetJetEtaMax() const
AliVParticle * Track(Int_t idx) const
Double_t fMaxDist
distance allowed for two jets to match
void SetJetContainerTag(Int_t c)
AliJetContainer * AddJetContainer(const char *n, TString defaultCutType, Float_t jetRadius=0.4)
Int_t fCentBin
!event centrality bin
Adding 0.1 in eta limit for tag jets.
Double_t GetDeltaPhi(const AliEmcalJet *jet1, const AliEmcalJet *jet2)
Calculate azimuthal angle between the axes of the jets.
AliClusterContainer * AddClusterContainer(const char *n)
Create new cluster container and attach it to the task.
Container for particles within the EMCAL framework.
UShort_t GetNumberOfTracks() const
AliParticleContainer * GetParticleContainer(Int_t i=0) const
Get particle container attached to this task.
void SetRhoName(const char *n)
Bool_t fInit
true when the containers are initialized
Double_t GetJetPhiMin() const
Bool_t FillHistograms()
Filling QA histograms monitoring the quality of the matching.
Int_t fContainerTag
jets used for tagging
static AliEmcalJetTaggerTaskFast * AddTaskJetTaggerFast(const char *njetsBase, const char *njetsTag, const Double_t R, const char *nrhoBase, const char *nrhoTag, const char *ntracks, const char *nclusters, const char *type, const char *CentEst, Int_t pSel, const char *trigClass)
Factory creating new jet matching task.
void SetJetPhiLimits(Float_t min, Float_t max)
TH3 * fh3PtJetDEtaDPhiConst
! jet vs delta eta vs delta phi of constituents
void UserCreateOutputObjects()
AliParticleContainer * AddParticleContainer(const char *n)
Create new particle container and attach it to the task.
Bool_t Run()
Run matching.
Int_t fNcentBins
how many centrality bins
Double_t MaxTrackPt() const
void Init()
Initializing the matching task by defining the accepted range on both jet containers.
Bool_t fMatchingDone
flag to indicate if matching is done or not
AliEmcalJet * GetNextAcceptJet()
Double_t DeltaR(const AliVParticle *part) const
virtual void SetNCentBins(Int_t n)
void ConnectParticleContainer(AliParticleContainer *c)
TH2 ** fh2PtJet1VsLeadPtAllSel
! all jets after std selection
Double_t GetRhoVal(Int_t i=0) const
Bool_t fUseSumw2
activate sumw2 for output histograms
TH2 ** fh2PtJet2VsRelPt
! pT of tagged jet vs pt base jet / pt tagged jet
AliEmcalList * fOutput
!output list
TH2 ** fh2PtJet1VsLeadPtTagged
! tagged jets
void SetClosestJet(AliEmcalJet *j, Double_t d)
void ResetTagging(const AliJetContainer &cont) const
Reset tagging for all jets in jet container.
Int_t fContainerBase
jets to be tagged
JetTaggingMethod fJetTaggingMethod
jet matching method
TH3 * fh3PtJetAreaDRConst
! jet vs Area vs delta R of constituents
void SetMakeGeneralHistograms(Bool_t g)
TH2 ** fh2PtJet2VsFraction
! jet 1 vs shared fraction
Base task in the EMCAL jet framework.
Represent a jet reconstructed using the EMCal jet framework.
Double_t GetFractionSharedPt(const AliEmcalJet *jet, AliParticleContainer *cont2=0x0) const
AcceptanceType fTypeAcc
acceptance cut for the jet containers, see method MatchJetsGeo in .cxx for possibilities ...
void UserCreateOutputObjects()
Main initialization function on the worker.
const AliJetIterableContainer accepted() const
Double_t fMinFractionShared
only fill histos for jets if shared fraction larger than X
void SetCentralityEstimator(const char *c)
Int_t fSpecPartContTag
particle container optionally used in AliJetContainer::GetFractionSharedPt(). Set only if needed...
void ConnectClusterContainer(AliClusterContainer *c)
void SetMaxTrackPt(Float_t b)
void SetJetEtaLimits(Float_t min, Float_t max)
Container structure for EMCAL clusters.
No Additional limit compared to jet containers.
Container for jet within the EMCAL jet framework.
Bool_t MatchJetsGeo(AliJetContainer &contBase, AliJetContainer &contTag, Float_t maxDist=0.3) const
Match the full jets to the corresponding charged jets.
void SetJetContainerBase(Int_t c)
Fast jet tagger for geometric matching of jets.
TH2 ** fh2PtJet1VsDeltaR
! jet 1 vs dR
const AliJetIterableContainer all() const