Skip to content

Commit 21bac9e

Browse files
YazhenLinCape
andauthored
[PWGDQ] Change some code for the energy correlator study (#15937)
Co-authored-by: Cape <cape@lindeMacBook-Pro.local>
1 parent 5679939 commit 21bac9e

2 files changed

Lines changed: 46 additions & 11 deletions

File tree

PWGDQ/Tasks/dqEnergyCorrelator_direct.cxx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,23 @@ struct AnalysisEnergyCorrelator {
475475
LOG(fatal) << "Problem getting histograms from the TList object with efficiencies!";
476476
}
477477
}
478+
479+
float GetSafeInterpolationWeight(TH2* hEff, float x, float y)
480+
{
481+
if (!hEff)
482+
return 1.0;
483+
float minX = hEff->GetXaxis()->GetBinCenter(1);
484+
float maxX = hEff->GetXaxis()->GetBinCenter(hEff->GetXaxis()->GetNbins());
485+
486+
float minY = hEff->GetYaxis()->GetBinCenter(1);
487+
float maxY = hEff->GetYaxis()->GetBinCenter(hEff->GetYaxis()->GetNbins());
488+
489+
float safeX = std::max(minX, std::min(x, maxX));
490+
float safeY = std::max(minY, std::min(y, maxY));
491+
492+
return hEff->Interpolate(safeX, safeY);
493+
}
494+
478495
template <bool MixedEvent, uint32_t TTrackFillMap, typename TTrack1, typename TTrack2, typename THadron, typename TEvent>
479496
void runDileptonHadron(TTrack1 const& track1, TTrack2 const& track2, int iEleCut,
480497
THadron const& hadron, TEvent const& event, aod::McParticles const& /*mcParticles*/)
@@ -503,16 +520,18 @@ struct AnalysisEnergyCorrelator {
503520
float Effweight_rec = 1.0f;
504521
float Accweight_gen = 1.0f;
505522
if (fConfigDileptonHadronOptions.fConfigApplyEfficiency) {
523+
float dilepton_pt = VarManager::fgValues[VarManager::kPt];
506524
float dilepton_eta = VarManager::fgValues[VarManager::kEta];
507525
float dilepton_phi = VarManager::fgValues[VarManager::kPhi];
526+
float dilepton_rap = VarManager::fgValues[VarManager::kRap];
508527
float hadron_eta = hadron.eta();
509528
float hadron_phi = hadron.phi();
510529
float deltaphi = RecoDecay::constrainAngle(dilepton_phi - hadron_phi, -0.5 * o2::constants::math::PI);
511-
Effweight_rec = hAcceptance_rec->Interpolate(dilepton_eta - hadron_eta, deltaphi);
512-
Accweight_gen = hAcceptance_gen->Interpolate(dilepton_eta - hadron_eta, deltaphi);
513-
float Effdilepton = hEfficiency_dilepton->Interpolate(VarManager::fgValues[VarManager::kPt], dilepton_eta);
514-
float Masswindow = hMasswindow->Interpolate(VarManager::fgValues[VarManager::kPt]);
515-
float Effhadron = hEfficiency_hadron->Interpolate(hadron.pt(), hadron.eta());
530+
float Effweight_rec = GetSafeInterpolationWeight(hAcceptance_rec, dilepton_eta - hadron_eta, deltaphi);
531+
float Accweight_gen = GetSafeInterpolationWeight(hAcceptance_gen, dilepton_eta - hadron_eta, deltaphi);
532+
float Effdilepton = GetSafeInterpolationWeight(hEfficiency_dilepton, dilepton_rap, dilepton_pt);
533+
float Effhadron = GetSafeInterpolationWeight(hEfficiency_hadron, hadron.pt(), hadron_eta);
534+
float Masswindow = hMasswindow->Interpolate(dilepton_pt);
516535
Accweight_gen = Accweight_gen * Effdilepton * Effhadron;
517536
if (fConfigDileptonHadronOptions.fConfigApplyEfficiencyME) {
518537
Effweight_rec = Effdilepton * Effhadron * Masswindow; // for the moment, apply the efficiency correction also for the mixed event pairs, but this can be changed in case we want to apply it only for the same event pairs

PWGDQ/Tasks/tableReader_withAssoc.cxx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,6 +3770,22 @@ struct AnalysisDileptonTrack {
37703770
}
37713771
}
37723772

3773+
float GetSafeInterpolationWeight(TH2* hEff, float x, float y)
3774+
{
3775+
if (!hEff)
3776+
return 1.0;
3777+
float minX = hEff->GetXaxis()->GetBinCenter(1);
3778+
float maxX = hEff->GetXaxis()->GetBinCenter(hEff->GetXaxis()->GetNbins());
3779+
3780+
float minY = hEff->GetYaxis()->GetBinCenter(1);
3781+
float maxY = hEff->GetYaxis()->GetBinCenter(hEff->GetYaxis()->GetNbins());
3782+
3783+
float safeX = std::max(minX, std::min(x, maxX));
3784+
float safeY = std::max(minY, std::min(y, maxY));
3785+
3786+
return hEff->Interpolate(safeX, safeY);
3787+
}
3788+
37733789
// Template function to run pair - hadron combinations
37743790
template <int TCandidateType, uint32_t TEventFillMap, uint32_t TTrackFillMap, typename TEvent, typename TTracks, typename TTrackAssocs, typename TDileptons>
37753791
void runDileptonHadron(TEvent const& event, TTrackAssocs const& assocs, TTracks const& tracks, TDileptons const& dileptons)
@@ -3853,10 +3869,10 @@ struct AnalysisDileptonTrack {
38533869
float hadron_eta = track.eta();
38543870
float hadron_phi = track.phi();
38553871
float deltaphi = RecoDecay::constrainAngle(dilepton_phi - hadron_phi, -0.5 * o2::constants::math::PI);
3856-
Effweight_rec = hAcceptance_rec->Interpolate(dilepton_eta - hadron_eta, deltaphi);
3857-
float Effdilepton = hEfficiency_dilepton->Interpolate(dilepton.pt(), dilepton_eta);
3872+
Effweight_rec = GetSafeInterpolationWeight(hAcceptance_rec, dilepton_eta - hadron_eta, deltaphi);
3873+
float Effdilepton = GetSafeInterpolationWeight(hEfficiency_dilepton, dilepton.rap(), dilepton.pt());
3874+
float Effhadron = GetSafeInterpolationWeight(hEfficiency_hadron, track.eta(), track.pt());
38583875
float Masswindow = hMasswindow->Interpolate(dilepton.pt());
3859-
float Effhadron = hEfficiency_hadron->Interpolate(track.pt(), hadron_eta);
38603876
Effweight_rec = Effweight_rec * Effdilepton * Effhadron * Masswindow;
38613877
}
38623878
std::vector<float> fTransRange = fConfigTransRange;
@@ -4087,10 +4103,10 @@ struct AnalysisDileptonTrack {
40874103
float hadron_eta = track.eta();
40884104
float hadron_phi = track.phi();
40894105
float deltaphi = RecoDecay::constrainAngle(dilepton_phi - hadron_phi, -0.5 * o2::constants::math::PI);
4090-
Effweight_rec = hAcceptance_rec->Interpolate(dilepton_eta - hadron_eta, deltaphi);
4091-
float Effdilepton = hEfficiency_dilepton->Interpolate(dilepton.pt(), dilepton_eta);
4106+
Effweight_rec = GetSafeInterpolationWeight(hAcceptance_rec, dilepton_eta - hadron_eta, deltaphi);
4107+
float Effdilepton = GetSafeInterpolationWeight(hEfficiency_dilepton, dilepton.rap(), dilepton.pt());
4108+
float Effhadron = GetSafeInterpolationWeight(hEfficiency_hadron, track.eta(), track.pt());
40924109
float Masswindow = hMasswindow->Interpolate(dilepton.pt());
4093-
float Effhadron = hEfficiency_hadron->Interpolate(track.pt(), hadron_eta);
40944110
if (fConfigApplyEfficiencyME) {
40954111
Effweight_rec = Effdilepton * Effhadron * Masswindow; // for the moment, apply the efficiency correction also for the mixed event pairs, but this can be changed in case we want to apply it only for the same event pairs
40964112
} else {

0 commit comments

Comments
 (0)