Skip to content

Commit 7d88e0a

Browse files
authored
PWGEM: avoid Errors from GetRandom() for empty histograms (AliceO2Group#2491)
* avoid Errors from GetRandom() for empty histograms * clang format
1 parent 8297e46 commit 7d88e0a

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

PWGEM/Dilepton/Tasks/lmeeLFCocktail.cxx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,11 @@ struct lmeelfcocktail {
880880
ptbin = 1;
881881
if (ptbin > fArrResoPt->GetLast())
882882
ptbin = fArrResoPt->GetLast();
883-
Double_t smearing = reinterpret_cast<TH1D*>(fArrResoPt->At(ptbin))->GetRandom() * pt;
883+
Double_t smearing = 0.;
884+
TH1D* thisHist = reinterpret_cast<TH1D*>(fArrResoPt->At(ptbin));
885+
if (thisHist->GetEntries() > 0) {
886+
smearing = thisHist->GetRandom() * pt;
887+
}
884888
Double_t sPt = pt - smearing;
885889

886890
// smear eta
@@ -889,7 +893,11 @@ struct lmeelfcocktail {
889893
ptbin = 1;
890894
if (ptbin > fArrResoEta->GetLast())
891895
ptbin = fArrResoEta->GetLast();
892-
smearing = reinterpret_cast<TH1D*>(fArrResoEta->At(ptbin))->GetRandom();
896+
smearing = 0.;
897+
thisHist = reinterpret_cast<TH1D*>(fArrResoEta->At(ptbin));
898+
if (thisHist->GetEntries() > 0) {
899+
smearing = thisHist->GetRandom();
900+
}
893901
Double_t sEta = eta - smearing;
894902

895903
// smear phi
@@ -898,10 +906,14 @@ struct lmeelfcocktail {
898906
ptbin = 1;
899907
if (ptbin > fArrResoPhi_Pos->GetLast())
900908
ptbin = fArrResoPhi_Pos->GetLast();
909+
smearing = 0.;
901910
if (ch > 0) {
902-
smearing = reinterpret_cast<TH1D*>(fArrResoPhi_Pos->At(ptbin))->GetRandom();
911+
thisHist = reinterpret_cast<TH1D*>(fArrResoPhi_Pos->At(ptbin));
903912
} else if (ch < 0) {
904-
smearing = reinterpret_cast<TH1D*>(fArrResoPhi_Neg->At(ptbin))->GetRandom();
913+
thisHist = reinterpret_cast<TH1D*>(fArrResoPhi_Neg->At(ptbin));
914+
}
915+
if (thisHist->GetEntries() > 0) {
916+
smearing = thisHist->GetRandom();
905917
}
906918
Double_t sPhi = phi - smearing;
907919

0 commit comments

Comments
 (0)