diff --git a/src/lib/onesource.cpp b/src/lib/onesource.cpp index 66280ec..5134a4a 100644 --- a/src/lib/onesource.cpp +++ b/src/lib/onesource.cpp @@ -260,17 +260,17 @@ void onesource::adapt_mag(vector a0, vector a1) { /* RETURN THE INDEX OF THE LIBRARY TO BE CONSIDERED (MAINLY ZFIX CASE) */ -vector onesource::validLib(vector &thelib, const bool &zfix, +vector onesource::validLib(const vector &zLib, const bool &zfix, const double &consideredZ) { vector val; // Condition with the redshift set ZFIX YES if (zfix) { - for (size_t i = 0; i < thelib.size(); i++) { - if ((thelib[i])->red == closest_red) val.push_back(i); + for (size_t i = 0; i < zLib.size(); i++) { + if (zLib[i] == closest_red) val.push_back(i); } } else { // If not fixed redshift, use everything - for (size_t i = 0; i < thelib.size(); i++) val.push_back(i); + for (size_t i = 0; i < zLib.size(); i++) val.push_back(i); } return val; diff --git a/src/lib/onesource.h b/src/lib/onesource.h index cabe396..9142eab 100644 --- a/src/lib/onesource.h +++ b/src/lib/onesource.h @@ -186,7 +186,7 @@ class onesource { void convertFlux(const string &catmag, const vector allFilters); void rescale_flux_errors(const vector min_err, const vector fac_err); - vector validLib(vector &fulllib, const bool &zfix, + vector validLib(const vector &zLib, const bool &zfix, const double &consideredZ); void fit(vector &fulllib, const vector> &flux, const vector &valid, const double &funz0, diff --git a/src/lib/photoz_lib.cpp b/src/lib/photoz_lib.cpp index c314c53..9b5f482 100644 --- a/src/lib/photoz_lib.cpp +++ b/src/lib/photoz_lib.cpp @@ -418,6 +418,7 @@ PhotoZ::PhotoZ(keymap &key_analysed) { /* Create a 2D array with the predicted flux. Done to improve the performance in the fit*/ flux.resize(fullLib.size(), vector(imagm, 0.)); + zLib.resize(fullLib.size(), -99.); fluxIR.resize(fullLibIR.size(), vector(imagm, 0.)); // Convert the magnitude library in flux #ifdef _OPENMP @@ -429,6 +430,8 @@ PhotoZ::PhotoZ(keymap &key_analysed) { for (size_t k = 0; k < allFilters.size(); k++) { flux[i][k] = pow(10., -0.4 * (fullLib[i]->mag[k] + 48.6)); } + // create a vector with the redshift of the library + zLib[i] = fullLib[i]->red; } #ifdef _OPENMP #pragma omp parallel for schedule(static) @@ -1020,7 +1023,7 @@ std::tuple, vector> PhotoZ::run_autoadapt( oneObj->closest_red = gridz[indexz(oneObj->zs, gridz)]; // Select the valid index of the library in case of ZFIX=YES to save // computational time - valid = oneObj->validLib(fullLib, zfix, oneObj->zs); + valid = oneObj->validLib(zLib, zfix, oneObj->zs); // Fit the source at the spec-z value oneObj->fit(fullLib, flux, valid, funz0, bp); // Interpolation of the predicted magnitudes, scaling at zs, checking @@ -1598,7 +1601,7 @@ void PhotoZ::run_photoz(vector sources, const vector &a0, oneObj->setPriors(magabsB, magabsF); // Select the valid index of the library in case of ZFIX=YES to save // computational time - valid = oneObj->validLib(fullLib, zfix, oneObj->zs); + valid = oneObj->validLib(zLib, zfix, oneObj->zs); // Core of the program: compute the chi2 oneObj->fit(fullLib, flux, valid, funz0, bp); // Try to remove some bands to improve the chi2, only as long as the chi2 is diff --git a/src/lib/photoz_lib.h b/src/lib/photoz_lib.h index e35709a..9a5a863 100644 --- a/src/lib/photoz_lib.h +++ b/src/lib/photoz_lib.h @@ -33,6 +33,7 @@ class PhotoZ { vector bapp, bappOp, pdz_fabs, emMod; cosmo lcdm; vector valid; + vector zLib; public: vector> flux, fluxIR;