ustajan / grasshopper

GNU General Public License v3.0
5 stars 4 forks source link

Fixed newline bug when reading input_spectrum.txt, and fan beam bug #15

Closed plalor closed 2 years ago

plalor commented 3 years ago

If input_spectrum.txt contains a newline (most commonly seen at the very end of the file), the current code

    while(!f.eof()) {
      float a,b;
      f>>a>>b;
      e.push_back(a);
      dNde.push_back(b);
    }

will read the newline and append the (a, b) of the previous line to e and dNde. This will create incorrect sampling weights when using discrete energy sampling since a given energy will essentially be given twice the weight.

Screen Shot 2021-07-01 at 12 28 18 PM

A simple fix is to just ignore empty lines as follows:

    float a,b;
    while(f >> a >> b) {
      e.push_back(a);
      dNde.push_back(b);
    }

Producing the correct weights:

Screen Shot 2021-07-01 at 12 28 05 PM

Furthermore, there was a bug from a previous commit which removed the line

vDir = G4ThreeVector(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta));

when using a fan beam.