| Summary: | underflow in G4EMDataSet::FindLowerBound(G4double x, G4DataVector* values) in G4EMDataSet.cc | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | Patrick van Beek <pvanbeek> |
| Component: | processes/electromagnetic/lowenergy | Assignee: | Sebastien Incerti <incerti> |
| Status: | RESOLVED LATER | ||
| Severity: | normal | ||
| Priority: | P4 | ||
| Version: | 10.3 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
Dear Peter, Thank you very much for your bug report. Would you please have a way to reproduce this issue with one of our extended/electromagnetic examples, eg. using a dedicated macro file (with same particle, energy, material...) ? Or send us a printout of data for which the issue occurs (like particle, energy, material ...) Or would you have the possibility to send us your application ? We would like to make sure that the issue is not originating from the database itself. Thanks a lot, Sebastien & Vladimir No further details. |
Hey together, I'm using the newest version of Geant4 (10.3 with newest patch). I experienced some random crashes of my simulation in the last time (it occurred very rarely, about in ever billionth event or so). So I began debugging. Using gdb, I found that the crash always occurred in G4EMDataSet::FindLowerBound(G4double x, G4DataVector* values). Since the crash was caused by a segmentation fault, the only problem I could think of was accessing the array incorrectly. So I decided to change the line if (x < (*values)[midBin]) upperBound = midBin - 1; //should be line 502 to (since the G4DataVector is an std::vector): if (x < values.at(midBin)) upperBound = midBin - 1; and recompiled Geant4 to see if I get an exception. And yes it was an outOfRange exception. The value of midBin was the result of an underflow, as I checked. In my humble opinion, this problem occurs exactly when (x < values[0]) holds, because the logic in this function does not work for this case! I used only the Livermore Physics list. I'm not sure if it is assumed, that values[0] is always 0 and this is just not true for Livermore lists, or if this also could happen with other lists. To fix the problem I changed the function to be: size_t G4EMDataSet::FindLowerBound(G4double x, G4DataVector* values) const { auto it = std::lower_bound(values->begin(),values->end(),x); int index = std::distance(values->begin(),it); return index; } I know this is not elegant. But Using the standard library is safer than using own logic. I did not experience any noticeable performance impact. Greets, Patrick