diff --git a/PWGDQ/Tasks/dqEnergyCorrelator_direct.cxx b/PWGDQ/Tasks/dqEnergyCorrelator_direct.cxx index b7b64010f6a..537b9712278 100644 --- a/PWGDQ/Tasks/dqEnergyCorrelator_direct.cxx +++ b/PWGDQ/Tasks/dqEnergyCorrelator_direct.cxx @@ -475,6 +475,23 @@ struct AnalysisEnergyCorrelator { LOG(fatal) << "Problem getting histograms from the TList object with efficiencies!"; } } + + float GetSafeInterpolationWeight(TH2* hEff, float x, float y) + { + if (!hEff) + return 1.0; + float minX = hEff->GetXaxis()->GetBinCenter(1); + float maxX = hEff->GetXaxis()->GetBinCenter(hEff->GetXaxis()->GetNbins()); + + float minY = hEff->GetYaxis()->GetBinCenter(1); + float maxY = hEff->GetYaxis()->GetBinCenter(hEff->GetYaxis()->GetNbins()); + + float safeX = std::max(minX, std::min(x, maxX)); + float safeY = std::max(minY, std::min(y, maxY)); + + return hEff->Interpolate(safeX, safeY); + } + template void runDileptonHadron(TTrack1 const& track1, TTrack2 const& track2, int iEleCut, THadron const& hadron, TEvent const& event, aod::McParticles const& /*mcParticles*/) @@ -503,16 +520,18 @@ struct AnalysisEnergyCorrelator { float Effweight_rec = 1.0f; float Accweight_gen = 1.0f; if (fConfigDileptonHadronOptions.fConfigApplyEfficiency) { + float dilepton_pt = VarManager::fgValues[VarManager::kPt]; float dilepton_eta = VarManager::fgValues[VarManager::kEta]; float dilepton_phi = VarManager::fgValues[VarManager::kPhi]; + float dilepton_rap = VarManager::fgValues[VarManager::kRap]; float hadron_eta = hadron.eta(); float hadron_phi = hadron.phi(); float deltaphi = RecoDecay::constrainAngle(dilepton_phi - hadron_phi, -0.5 * o2::constants::math::PI); - Effweight_rec = hAcceptance_rec->Interpolate(dilepton_eta - hadron_eta, deltaphi); - Accweight_gen = hAcceptance_gen->Interpolate(dilepton_eta - hadron_eta, deltaphi); - float Effdilepton = hEfficiency_dilepton->Interpolate(VarManager::fgValues[VarManager::kPt], dilepton_eta); - float Masswindow = hMasswindow->Interpolate(VarManager::fgValues[VarManager::kPt]); - float Effhadron = hEfficiency_hadron->Interpolate(hadron.pt(), hadron.eta()); + float Effweight_rec = GetSafeInterpolationWeight(hAcceptance_rec, dilepton_eta - hadron_eta, deltaphi); + float Accweight_gen = GetSafeInterpolationWeight(hAcceptance_gen, dilepton_eta - hadron_eta, deltaphi); + float Effdilepton = GetSafeInterpolationWeight(hEfficiency_dilepton, dilepton_rap, dilepton_pt); + float Effhadron = GetSafeInterpolationWeight(hEfficiency_hadron, hadron.pt(), hadron_eta); + float Masswindow = hMasswindow->Interpolate(dilepton_pt); Accweight_gen = Accweight_gen * Effdilepton * Effhadron; if (fConfigDileptonHadronOptions.fConfigApplyEfficiencyME) { 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 diff --git a/PWGDQ/Tasks/tableReader_withAssoc.cxx b/PWGDQ/Tasks/tableReader_withAssoc.cxx index 34dd7fc7314..625fbd77440 100644 --- a/PWGDQ/Tasks/tableReader_withAssoc.cxx +++ b/PWGDQ/Tasks/tableReader_withAssoc.cxx @@ -3770,6 +3770,22 @@ struct AnalysisDileptonTrack { } } + float GetSafeInterpolationWeight(TH2* hEff, float x, float y) + { + if (!hEff) + return 1.0; + float minX = hEff->GetXaxis()->GetBinCenter(1); + float maxX = hEff->GetXaxis()->GetBinCenter(hEff->GetXaxis()->GetNbins()); + + float minY = hEff->GetYaxis()->GetBinCenter(1); + float maxY = hEff->GetYaxis()->GetBinCenter(hEff->GetYaxis()->GetNbins()); + + float safeX = std::max(minX, std::min(x, maxX)); + float safeY = std::max(minY, std::min(y, maxY)); + + return hEff->Interpolate(safeX, safeY); + } + // Template function to run pair - hadron combinations template void runDileptonHadron(TEvent const& event, TTrackAssocs const& assocs, TTracks const& tracks, TDileptons const& dileptons) @@ -3853,10 +3869,10 @@ struct AnalysisDileptonTrack { float hadron_eta = track.eta(); float hadron_phi = track.phi(); float deltaphi = RecoDecay::constrainAngle(dilepton_phi - hadron_phi, -0.5 * o2::constants::math::PI); - Effweight_rec = hAcceptance_rec->Interpolate(dilepton_eta - hadron_eta, deltaphi); - float Effdilepton = hEfficiency_dilepton->Interpolate(dilepton.pt(), dilepton_eta); + Effweight_rec = GetSafeInterpolationWeight(hAcceptance_rec, dilepton_eta - hadron_eta, deltaphi); + float Effdilepton = GetSafeInterpolationWeight(hEfficiency_dilepton, dilepton.rap(), dilepton.pt()); + float Effhadron = GetSafeInterpolationWeight(hEfficiency_hadron, track.eta(), track.pt()); float Masswindow = hMasswindow->Interpolate(dilepton.pt()); - float Effhadron = hEfficiency_hadron->Interpolate(track.pt(), hadron_eta); Effweight_rec = Effweight_rec * Effdilepton * Effhadron * Masswindow; } std::vector fTransRange = fConfigTransRange; @@ -4087,10 +4103,10 @@ struct AnalysisDileptonTrack { float hadron_eta = track.eta(); float hadron_phi = track.phi(); float deltaphi = RecoDecay::constrainAngle(dilepton_phi - hadron_phi, -0.5 * o2::constants::math::PI); - Effweight_rec = hAcceptance_rec->Interpolate(dilepton_eta - hadron_eta, deltaphi); - float Effdilepton = hEfficiency_dilepton->Interpolate(dilepton.pt(), dilepton_eta); + Effweight_rec = GetSafeInterpolationWeight(hAcceptance_rec, dilepton_eta - hadron_eta, deltaphi); + float Effdilepton = GetSafeInterpolationWeight(hEfficiency_dilepton, dilepton.rap(), dilepton.pt()); + float Effhadron = GetSafeInterpolationWeight(hEfficiency_hadron, track.eta(), track.pt()); float Masswindow = hMasswindow->Interpolate(dilepton.pt()); - float Effhadron = hEfficiency_hadron->Interpolate(track.pt(), hadron_eta); if (fConfigApplyEfficiencyME) { 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 } else {