-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reworking of the ObserverTimeEvolution #511
base: master
Are you sure you want to change the base?
Conversation
-> detList still available as option -> custom function option added
…d getTime function
- fixed wrong scaling in constructor - fixed unexpected behavior in getTimes - added more detailed documentation - replaced customGetTime with virtual on getTime since it is only used inside c++
- modified Test for checkDetection - added Test for behavior with arrays instead of getTime function - added clear and empty function
- further fixed a floating point issue in testBreakCondition
After discussing pull request with @JulienDoerner, I added setter and getter functions as well as some older functions that I previously removed to preserve compatibility.
For a more detailed description of the single changes, see the comments. |
@@ -240,52 +240,119 @@ class ObserverParticleIdVeto: public ObserverFeature { | |||
This observer is very useful if the time evolution of the particle density is needed. It detects all candidates in lin-spaced, log-spaced, or user-defined time intervals and limits the nextStep of candidates to prevent overshooting of detection intervals. | |||
*/ | |||
class ObserverTimeEvolution: public ObserverFeature { | |||
private: | |||
protected: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed private to protected, so the variables can be accessed in derived classes
Use this function to create a detList with can then be modified. | ||
When detList is not empty its entries are used instead of a runtime calculation of the times. | ||
*/ | ||
void constructDetListIfEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function enables the user to manually construct detList
src/module/Observer.cpp
Outdated
@@ -246,7 +246,7 @@ std::string ObserverParticleIdVeto::getDescription() const { | |||
ObserverTimeEvolution::ObserverTimeEvolution() {} | |||
|
|||
ObserverTimeEvolution::ObserverTimeEvolution(double min, double dist, double numb) { | |||
this->max = min + numb * dist; | |||
this->max = min + (numb - 1) * dist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes the original bug, where the last time to observe was too large because of this
test/testBreakCondition.cpp
Outdated
times = {1, 1000}; | ||
times.clear(); | ||
for (int i=0; i<4; i++) | ||
times.push_back(pow(1000., i / 3.)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pow(1000, 2/3) does not exactly return 100 which caused a wrong negative in line 345
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can check for EXPECT_NEAR
with some small errorband.
EXPECT_TRUE(c.hasProperty("Detected")); | ||
} | ||
|
||
TEST(ObserverFeature, TimeEvolutionArray) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test checks if detList is created and used correctly when using the modifying functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @JanNiklasB,
the overall changes look good for me and it improves the usability for non-uniform observations.
I left some comments about code style (see below).
And can you please add your changes to the CHANGELOG.md
.
include/crpropa/module/Observer.h
Outdated
@@ -240,8 +240,22 @@ class ObserverParticleIdVeto: public ObserverFeature { | |||
This observer is very useful if the time evolution of the particle density is needed. It detects all candidates in lin-spaced, log-spaced, or user-defined time intervals and limits the nextStep of candidates to prevent overshooting of detection intervals. | |||
*/ | |||
class ObserverTimeEvolution: public ObserverFeature { | |||
private: | |||
protected: | |||
int numb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our coding style all variables should be given with full names. Therefore you should use number
or nObservations
instead. Also add an inline comment what this value us.
include/crpropa/module/Observer.h
Outdated
virtual double getTime(std::size_t index) const; | ||
double getMin() const {return min;} | ||
double getMax() const {return max;} | ||
int getNumb() const {return numb;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use full names for functions
src/module/Observer.cpp
Outdated
} | ||
|
||
void ObserverTimeEvolution::addTimeRange(double min, double max, double numb, bool log) { | ||
for (size_t i = 0; i < numb; i++) { | ||
if (log == true) { | ||
if (log) { | ||
if ( min == 0 ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to prove for min <= 0
?
src/module/Observer.cpp
Outdated
if (!detList.empty()) { | ||
return detList.at(index); | ||
} else if (islog) { | ||
if ( min == 0 ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to prove this in every getTime
call, which is called in every propagation step? I guess a proof only in the setter functions would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, if it is set right in the setter functions the check here would be unnecessary
test/testBreakCondition.cpp
Outdated
@@ -273,37 +277,91 @@ TEST(ObserverFeature, TimeEvolutionLog) { | |||
obs.setFlag("Detected", "Detected"); | |||
// usage of a log scaling for the observer | |||
bool log = true; | |||
obs.add(new ObserverTimeEvolution(5, 5, 2, log)); | |||
obs.add(new ObserverTimeEvolution(5, 10.05, 2, log)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this test really reflect the log-scaling? If it only has two points it would be the same in linear or log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, it should at least test 3 points
test/testBreakCondition.cpp
Outdated
times = {1, 1000}; | ||
times.clear(); | ||
for (int i=0; i<4; i++) | ||
times.push_back(pow(1000., i / 3.)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can check for EXPECT_NEAR
with some small errorband.
- Replaced EXPECT_TRUE with EXPECT_NEAR in TimeEvolutionArray
- all changes to variables now over setter functions - valid range check for min if isLogarithmicScaling = true now in setMinimum
Dear All,
in this pull request, I want to introduce a reworked
ObserverTimeEvolution
.I replaced the
addTimeRange
function which filled thedetList
array with a functionthat takes the required index as an argument and returns the time that should be observed.
For that, I also changed other parts of the
ObserverTimeEvolution
class tocorrectly utilize that new
getTime
function.I also kept the option of using a
detList
by utilizing a new constructor.Furthermore, it is possible to use a user-defined
getTime
function by utilizingthe
setUserDefinedGetTime
function.Additionally, I fixed the issue mentioned in #510.
For that, it was necessary to change some tests, since those handled
the maximum observed time like
max = numb * dist
when it shouldbe handled like
max = min + numb * dist
.