Skip to content

Commit 3b47e46

Browse files
committed
Fixed (finally) handling of redshift as in FAST
1 parent 675cdae commit 3b47e46

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

src/fast++-fitter.cpp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ fitter_t::fitter_t(const options_t& opt, const input_state_t& inp, const gridder
6363
uint_t iup = 1 + 2*ic + 1;
6464

6565
for (uint_t is : range(input.id)) {
66-
if (idz.safe[is] != npos) {
67-
// Range is limited to z_spec
68-
idzl.safe[is] = idz.safe[is];
69-
idzu.safe[is] = idz.safe[is];
70-
} else if (is_finite(input.zphot.safe(is,ilow)) && is_finite(input.zphot.safe(is,iup))) {
66+
if (is_finite(input.zphot.safe(is,ilow)) && is_finite(input.zphot.safe(is,iup))) {
7167
// Get range from zlow and zup
7268
idzl.safe[is] = min_id(abs(output.z - input.zphot.safe(is,ilow)));
7369
idzu.safe[is] = min_id(abs(output.z - input.zphot.safe(is,iup)));
@@ -84,6 +80,14 @@ fitter_t::fitter_t(const options_t& opt, const input_state_t& inp, const gridder
8480
}
8581
}
8682

83+
for (uint_t is : range(input.id)) {
84+
if (idz.safe[is] != npos) {
85+
// Range is limited to z_spec
86+
idzl.safe[is] = idz.safe[is];
87+
idzu.safe[is] = idz.safe[is];
88+
}
89+
}
90+
8791
// Pre-generate random fluctuations
8892
if (opts.n_sim > 0) {
8993
auto seed = make_seed(42);
@@ -261,7 +265,8 @@ struct fitter_workspace {
261265
mc_sfr = reinterpret_cast<float*>(pool + off); off += nsim*sizeof(float);
262266
}
263267

264-
chi2 = mass = sfr = vec1f(ngal);
268+
chi2 = replicate(finf, ngal);
269+
mass = sfr = replicate(fnan, ngal);
265270
}
266271

267272
fitter_workspace(const fitter_workspace&) = delete;
@@ -281,12 +286,20 @@ void fitter_t::fit_galaxies(const model_t& model, uint_t i0, uint_t i1) {
281286
uint_t is = i + i0;
282287

283288
// Apply constraints on redshift
284-
if ((!opts.best_at_zphot || idzp.safe[is] == npos || model.iz != idzp.safe[is]) &&
285-
(idz.safe[is] == npos || model.iz != idz.safe[is]) &&
286-
(model.iz < idzl.safe[is] || model.iz > idzu.safe[is])) {
287-
wsp.chi2.safe[i] = finf;
288-
wsp.mass.safe[i] = fnan;
289-
wsp.sfr.safe[i] = fnan;
289+
bool dofit = (idzl.safe[is] <= model.iz && model.iz <= idzu.safe[is]);
290+
bool keepfit = true;
291+
if (opts.best_at_zphot && idzp.safe[is] != npos) {
292+
if (idzp.safe[is] == model.iz) {
293+
dofit = true;
294+
keepfit = true;
295+
} else {
296+
dofit = opts.n_sim != 0;
297+
keepfit = false;
298+
}
299+
}
300+
301+
if (!dofit) {
302+
// Skip this model
290303
continue;
291304
}
292305

@@ -323,15 +336,16 @@ void fitter_t::fit_galaxies(const model_t& model, uint_t i0, uint_t i1) {
323336
tchi2 += sqr(wsp.wflux[il] - scale*wsp.wmodel[il]);
324337
}
325338

326-
wsp.chi2.safe[i] = tchi2;
327-
wsp.mass.safe[i] = scale*model.mass;
328-
wsp.sfr.safe[i] = scale*model.sfr;
339+
if (keepfit) {
340+
wsp.chi2.safe[i] = tchi2;
341+
wsp.mass.safe[i] = scale*model.mass;
342+
wsp.sfr.safe[i] = scale*model.sfr;
343+
}
329344

330345
if (!opts.best_from_sim && opts.parallel == parallel_choice::none) {
331346
// Compare to best
332347
// WARNING: read/modify shared resource
333-
if (output.best_chi2.safe[is] > wsp.chi2.safe[i] &&
334-
(!opts.best_at_zphot || idzp.safe[is] == npos || model.iz == idzp.safe[is])) {
348+
if (output.best_chi2.safe[is] > wsp.chi2.safe[i]) {
335349
output.best_chi2.safe[is] = wsp.chi2.safe[i];
336350
output.best_mass.safe(is,0) = wsp.mass.safe[i];
337351
output.best_sfr.safe(is,0) = wsp.sfr.safe[i];
@@ -413,8 +427,7 @@ void fitter_t::fit_galaxies(const model_t& model, uint_t i0, uint_t i1) {
413427

414428
for (uint_t i : range(i1-i0)) {
415429
uint_t is = i + i0;
416-
if (output.best_chi2.safe[is] > wsp.chi2[i] &&
417-
(!opts.best_at_zphot || idzp.safe[is] == npos || model.iz == idzp.safe[is])) {
430+
if (output.best_chi2.safe[is] > wsp.chi2[i]) {
418431
output.best_chi2.safe[is] = wsp.chi2[i];
419432
output.best_mass.safe(is,0) = wsp.mass[i];
420433
output.best_sfr.safe(is,0) = wsp.sfr[i];

0 commit comments

Comments
 (0)