@@ -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