Skip to content
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

Source sampling #478

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Bug fixes:
* Fixed sign for exponential decay of magn. field strength with Galactic height in LogarithmicSpiralField
* Fixed r term in source distribution for SNR and Pulsar

### New features:

Expand Down
22 changes: 11 additions & 11 deletions src/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,17 @@ void SourceUniformCylinder::setDescription() {

// ---------------------------------------------------------------------------
SourceSNRDistribution::SourceSNRDistribution() :
rEarth(8.5 * kpc),alpha(2.), beta(3.53), zg(0.3 * kpc) {
rEarth(8.5 * kpc), beta(3.53), zg(0.3 * kpc) {
setAlpha(2.);
setFrMax();
setFzMax(0.3 * kpc);
setRMax(20 * kpc);
setZMax(5 * kpc);
}

SourceSNRDistribution::SourceSNRDistribution(double rEarth, double alpha, double beta, double zg) :
rEarth(rEarth),alpha(alpha), beta(beta), zg(zg) {
rEarth(rEarth), beta(beta), zg(zg) {
setAlpha(alpha);
setFrMax();
setFzMax(zg);
setRMax(20 * kpc);
Expand Down Expand Up @@ -414,7 +416,7 @@ double SourceSNRDistribution::fz(double z) const{
}

double SourceSNRDistribution::getAlpha() const {
return alpha;
return alpha - 1; // -1 to account for the R-term in the volume element dV = R * dR * dphi * dz
}

double SourceSNRDistribution::getBeta() const {
Expand Down Expand Up @@ -458,7 +460,7 @@ double SourceSNRDistribution::getZMax() const {
}

void SourceSNRDistribution::setAlpha(double a) {
alpha = a;
alpha = a + 1.; // add 1 for dV = r * dR * dphi * dz
setRMax(rMax);
setFrMax();
}
Expand Down Expand Up @@ -504,7 +506,7 @@ void SourcePulsarDistribution::prepareParticle(ParticleState& particle) const {
double Rtilde;
while (true) {
Rtilde = random.rand() * rMax;
double fTest = random.rand() * frMax;
double fTest = random.rand() * frMax * 1.1;
double fR = fr(Rtilde);
if (fTest <= fR) {
break;
Expand All @@ -530,10 +532,8 @@ void SourcePulsarDistribution::prepareParticle(ParticleState& particle) const {
}

double SourcePulsarDistribution::fr(double r) const {
double Atilde = (pow(beta, 4.) * exp(-beta)) / (12 * M_PI * pow(rEarth, 2.));
double f = pow(r / rEarth, 2.) * exp(-beta * (r - rEarth) / rEarth);
double fr = Atilde * f;
return fr;
double f = r * pow(r / rEarth, 2.) * exp(-beta * (r - rEarth) / rEarth);
return f;
}

double SourcePulsarDistribution::fz(double z) const{
Expand Down Expand Up @@ -569,8 +569,8 @@ double SourcePulsarDistribution::blurTheta(double thetaTilde, double rTilde) con
}

void SourcePulsarDistribution::setFrMax(double R, double b) {
frMax = pow(b, 2.) / (3 * pow(R, 2.) * M_PI) * exp(-2.);
return;
double r = 3 * R / b;
frMax = fr(r);
}

void SourcePulsarDistribution::setFzMax(double zg) {
Expand Down
2 changes: 1 addition & 1 deletion test/testSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ TEST(SourceSNRDistribution, simpleTest) {
}
R2_mean/=100000.;
Z_mean/=100000.;
EXPECT_NEAR(64.4, R2_mean, 1.);
EXPECT_NEAR(100.306, R2_mean, 1);
EXPECT_NEAR(0., Z_mean, 0.1);
}

Expand Down