CRPropa / CRPropa3

CRPropa is a public astrophysical simulation framework for propagating extraterrestrial ultra-high energy particles. https://crpropa.github.io/CRPropa3/
https://crpropa.desy.de
GNU General Public License v3.0
65 stars 66 forks source link

NormalizeLens() changes results depending on number of times it is applied to a lens #404

Closed angelinapartenheimer closed 1 year ago

angelinapartenheimer commented 1 year ago

Hello,

I am using a magnetic lens on my cosmic ray data, and I want to normalize the lens using normalizeLens(). The problem I ran into is this: for every time I run normalizeLens() on my lens, the lens scales the maximum energy bin of my data down by an extra order of magnitude. As a result, using my lens with normalizeLens() applied once gives a different result than using that same lens with normalizeLens() applied to it twice. Based on my understanding of the source code, this should not happen. The energy scaling by the lens should change after normalizeLens() is applied the first time, but it should not change if normalizeLens() is applied subsequently after that. Is this a bug, or an expected behavior from the normalizing function?

Thank you, Angelina Partenheimer

TobiasWinchen commented 1 year ago

Dear Angelina,

this is certainly not what a user expects, but I don't think this indicates a bug in the code - the lens parts cache their initial maximum value See here, which is reused in the second normalization instead of the new 'true' maximum. You likely noticed that the second 'normalization' executes much faster?

However, it would probably be best to add a warning, respectively a check, so that a normalization can only be applied once.

angelinapartenheimer commented 1 year ago

Dear Tobias,

Thank you so much, this does explain what I had been observing. I must have misunderstood the source code; I did not realize that the old maximum was being used to normalize the lens if normalization was applied twice. I do agree that a warning to only apply normalizeLens() once would be useful.

Best, Angelina