Class onesource

Nested Relationships

Nested Types

Class Documentation

class onesource

represents an object from a catalogue, and manages its fitting to an SED.

Public Functions

inline onesource()
inline onesource(const int posC, const vector<double> &gridz)

Build a source at a given catalogue position and initialise pdfmap with the physical-parameter grids and a redshift grid derived from gridz

Parameters:
  • posC – position (row index) of the source in the catalogue, stored in pos

  • gridz – redshift grid of the SED library, used to set the range and step of the redshift PDFs (a single-element grid is treated as the STAR-only case)

inline ~onesource()
inline void set_verbosity(const bool v)

Set verbosity.

Parameters:

v – bool specifying whether output should be verbose or not.

inline bool get_verbosity() const

Get verbosity.

Returns:

bool specifying whether output is verbose or not.

void readsource(const string &identifier, const vector<double> vals, const vector<double> err_vals, const long context, const double z_spec, const string additional_input)

Set the observed fluxes and their errors, and the identifying metadata, from a catalogue row

Parameters:
  • identifier – source identifier, stored in spec

  • vals – observed flux (or magnitude, converted upstream) per band, stored in ab

  • err_vals – uncertainty per band, stored in sab

  • context – bitmask of bands to use, stored in cont

  • z_spec – spectroscopic redshift, stored in zs

  • additional_input – free-form string carried through to the output, stored in str_inp

void setPriors(const array<double, 2> magabsB, const array<double, 2> magabsF)

Set the absolute magnitude prior range used by nzprior(), for the galaxy and AGN libraries

Parameters:
  • magabsB – [galaxy,AGN] bright absolute magnitude bound

  • magabsF – [galaxy,AGN] faint absolute magnitude bound

void fltUsed(const long gbcont, const long contforb)

Flag, in busnorma and busul, which bands are used in the main fit and which are treated as upper limits, based on the context and on the validity of ab/sab

Parameters:
  • gbcont – global context overriding the per-source context if >= 0

  • contforb – context of bands forbidden from being upper limits

void fltUsedIR(const long fir_cont, const long fir_scale, vector<flt> allFilters, const double fir_lmin)

Flag, in busfir and bscfir, which bands are used in the FIR fit and for its flux scaling

Parameters:
  • fir_cont – context of bands eligible for the FIR fit

  • fir_scale – context of bands used to scale the FIR fit

  • allFilters – filter set, used to check the rest-frame wavelength against fir_lmin

  • fir_lmin – minimum rest-frame wavelength for a band to be eligible

void convertFlux(const string &catmag, const vector<flt> allFilters)

Convert the input magnitudes/fluxes (ab/sab) to fluxes in the LePHARE internal convention, handling invalid/negative values

Parameters:
  • catmag – magnitude system of the input catalogue (“AB” or “VEGA”)

  • allFilters – filter set, used for the VEGA-to-AB conversion

void rescale_flux_errors(const vector<double> min_err, const vector<double> fac_err)

Rescale the flux errors sab, e.g. to add a systematic floor

Parameters:
  • min_err – minimum relative error per band (or a single value applied to all bands)

  • fac_err – multiplicative factor applied to the error per band (or a single value applied to all bands)

void fit(SEDlight &lightLib, const vector<vector<double>> &flux, const vector<size_t> &valid, const array<int, 2> &bp, const bool restrict)

Fit the source against the given library by chi2 minimisation

Parameters:
  • lightLib – light SED library to fit against

  • flux – predicted flux of each library template, in each band

  • valid – indices, in lightLib, of the templates to consider

  • bp – [min,max] index of the bands used for the fit

  • restrict – if true, treat a negative predicted flux (outside the SED’s rest-frame wavelength coverage) as zero rather than using it as-is

void fitIR(vector<SED*> &fulllib, const vector<vector<double>> &flux, const vector<size_t> &valid, const string fit_frsc, cosmo lcdm)

Fit the source against a far-infrared library, in the bands flagged by fltUsedIR()

Parameters:
  • fulllib – FIR SED library to fit against

  • flux – predicted flux of each library template, in each band

  • valid – indices, in fulllib, of the templates to consider

  • fit_frsc – FIR flux-scaling method

  • lcdm – cosmology used to rescale distances

double nzprior(const double luv, const double lnir, const double reds, const array<int, 2> bp)

Compute the N(z) prior weight applied to the chi2 during the fit, following Ilbert et al. (2006)

Parameters:
  • luv – rest-frame UV luminosity of the template

  • lnir – rest-frame NIR luminosity of the template

  • reds – redshift of the template

  • bp – [min,max] index of the bands used to define the apparent magnitude the prior is conditioned on

Returns:

the prior weight, to be combined with the chi2

NzPriorSetup nzprior_setup(const array<int, 2> bp) const

Compute the source-dependent part of the N(z) prior, see nzprior()

void rm_discrepant(SEDlight &lightLib, const vector<vector<double>> &flux, const vector<size_t> &valid, const array<int, 2> bp, double thresholdChi2, const bool restrict)

Iteratively remove the band contributing most to the chi2 of the best-fit solution, and re-fit, as long as this improves the chi2 by more than thresholdChi2

Parameters:
  • lightLib – light SED library to fit against

  • flux – predicted flux of each library template, in each band

  • valid – indices, in lightLib, of the templates to consider

  • bp – [min,max] index of the bands used for the fit

  • thresholdChi2 – minimum chi2 improvement required to discard a band

  • restrict – forwarded to fit(), see there

vector<vector<double>> redden_flux(const vector<vector<double>> &flux, const vector<vector<double>> &reddening) const

Apply a per-template, per-band reddening correction to a predicted flux array

Parameters:
  • flux – predicted flux of each library template, in each band

  • reddening – per-template, per-band reddening correction to apply

Returns:

the reddened flux array

void redden_flux_into(const vector<vector<double>> &flux, const vector<vector<double>> &reddening, vector<vector<double>> &out) const

Same as above, but writes into out (resized if needed) so that its storage is reused from one object to the next.

void write_out(ofstream &stout, const vector<string> &outkeywords)

Write output in the lephare ascii format

Parameters:
  • stout – stream object pointing to the output file

  • outkeywords – list of keywords to be output

void write_pdz_header(vector<string> pdztype, unordered_map<string, ofstream> &stpdz)

Write the header of the PDF output file(s)

Parameters:
  • pdztype – list of PDF types to write a header for (keys of #maptype)

  • stpdz – map, keyed by PDF type, of the open output streams

void write_pdz(vector<string> pdztype, unordered_map<string, ofstream> &stpdz)

Write this source’s marginalized PDF(s) to the corresponding output stream(s)

Parameters:
  • pdztype – list of PDF types to write (keys of #maptype)

  • stpdz – map, keyed by PDF type, of the open output streams

void convertMag()

Convert the fluxes ab/sab to AB magnitudes mab and errors msab.

void keepOri()

Save a copy of ab, sab and mab, before corrections, into ab_ori/sab_ori/mab_ori

void interp(const bool zfix, const bool zintp, const cosmo &lcdm)

Update the solution of the fit based on execution flags.

zmin and dmmin are updated in place, for the GAL and QSO solutions. Note that zfix and zintp are not supposed to both be set. In case it happens, zintp is discarded here.

Parameters:
  • zfix – bool that sets whether to set solution to a given redshift, typically a true or spectroscopic redshift

  • zintp – bool that sets whether to improve the determination of the minimum on the chi2 curve, by parabolic approximation

  • lcdm – cosmo object to access the distMod and distDet functions

void uncertaintiesMin()

Compute the frequentist (chi2-based) confidence intervals around the GAL and QSO chi2-minimum redshifts, filling zgmin/zqmin

void uncertaintiesBay()

Compute the Bayesian confidence intervals (median and credible intervals) of the redshift and physical parameters from their marginalized PDFs, filling zgmed/zqmed/massmed/etc.

void uncertaintiesBayIR()

Compute the Bayesian confidence intervals of the IR luminosity from its marginalized PDF (pdfmap[4]), filling LIRmed

void secondpeak(SEDlight &lightLib, const double dz_win, const double min_thres)

Detect a secondary peak in the marginalized galaxy redshift PDF and, if found, store its properties in zsec and related members

Parameters:
  • lightLib – light SED library the source was fit against

  • dz_win – minimum redshift separation from the main peak for a secondary peak to be considered

  • min_thres – minimum relative probability for a secondary peak to be considered

void generatePDF(SEDlight &lightLib, const vector<size_t> &va, const bool colAnalysis, const bool zfix)

Build the marginalized PDF of the redshift and of the physical parameters (mass, SFR, age, colors…) by summing the chi2-based probability of every valid template, and fill pdfmap

Parameters:
  • lightLib – light SED library the source was fit against

  • va – indices, in lightLib, of the valid templates

  • colAnalysis – whether to also build the rest-frame color PDFs (pdfmap[6]/[7])

  • zfix – whether the redshift was fixed for this fit

void generatePDF_IR(vector<SED*> &fulllib)

Build the marginalized IR luminosity PDF (pdfmap[4]) from the FIR fit

Parameters:

fulllib – FIR SED library the source was fit against

void mode()

Compute the mode of the marginalized GAL/QSO redshift PDFs and their confidence intervals, filling zgmode/zqmode

void interp_lib(vector<SED*> &fulllib, const vector<vector<double>> &flux)

Interpolate the predicted magnitudes (magm) of the best-fit template at the redshift consiz, between the two adjacent grid points of fulllib

Parameters:
  • fulllib – SED library the source was fit against

  • flux – predicted flux of each library template, in each band

void adapt_mag(const vector<double> &a0)

Apply a per-band zero-point offset to the observed magnitudes/fluxes

Parameters:

a0 – magnitude offset to add, one value per band

void correct_classic_mw(const vector<double> &Alamb_corr, const double mw_global_ebv)

Apply the “classic” Milky Way dust correction to the observed flux and error, using a per-band correction coefficient (galaxy-independent)

Parameters:
  • Alamb_corr – MW dust correction coefficient, one value per band

  • mw_global_ebv – global MW E(B-V) to use for every source if >= 0, overriding mw_ebv; if negative, mw_ebv is used instead

void correct_galametz_mw(const vector<vector<double>> &reddening)

Apply the Galametz et al. Milky Way dust correction to the observed flux and error, using the model-dependent reddening of the best-fit (chi2-minimum) galaxy template. No-op if there is no valid galaxy solution or if mw_ebv is not positive.

Parameters:

reddening – per-template, per-band reddening correction, indexed as indmin

void subtract_stellar_component(const bool substar, vector<flt> allFilters)

Allow for stellar component substraction before fitting an IR template When fitting an IR component after the nominal fit, there is an interval in wavelength where both nominal and IR template would contribute. In order to correctly fit the IR template in this interval, one may want to subtract first the nominal stellar component as obtained from the best fit template. This common interval in lambda (in the rest frame) is bounded by the hardcoded value of 250 um at the high end, and by the value set by the FIR_LMIN keyword (in um, default 7 um) at the low end.

Parameters:
  • substar – : bool value set by the FIR_SUBSTELLAR keyword, defining whether to do this subtraction or not.

  • allFilters – : the list of filters, needed to discard filters which have \(\lambda_{mean}/(1+z) > 250\,\mu m\).

void absmag(const vector<vector<int>> &bestFlt, const vector<vector<double>> &maxkcolor, cosmo lcdm, const vector<double> &gridz)

Compute the absolute magnitude(s) of the source from its best-fit template(s), filling mabs/emabs/absfilt

Parameters:
  • bestFlt – per band-pass, indices of the filters bracketing the rest-frame reference wavelength at the source’s redshift

  • maxkcolor – maximum rest-frame color allowed for the k-correction

  • lcdm – cosmology used to compute the distance modulus

  • gridz – redshift grid of the library

void writeSpec(vector<SED*> &fulllib, vector<SED*> &fulllibIR, cosmo lcdm, const vector<flt> &allFilters, const string outspdir) const

Write the best-fit spectra (and, if available, the FIR spectrum) of this source to per-source output files

Parameters:
  • fulllib – SED library the source was fit against

  • fulllibIR – FIR SED library the source was fit against

  • lcdm – cosmology used to compute the spectra

  • allFilters – filter set, written alongside the spectra

  • outspdir – output directory for the spectra files

void writeFullChi(const SEDlight &lightLib)

Write out in a Id<source id>.chi file the chi2 of all the templates participating to the fit.

Parameters:

lightLib – : the light library of SED objects.

void computePredMag(vector<SED*> &fulllib, cosmo lcdm, const vector<flt> &allFltAdd)

Compute the predicted apparent magnitudes of the best-fit template(s) in an arbitrary set of additional filters, filling magPred

Parameters:
  • fulllib – SED library the source was fit against

  • lcdm – cosmology used to compute the magnitudes

  • allFltAdd – additional filters to predict magnitudes for

void computePredAbsMag(vector<SED*> &fulllib, cosmo lcdm, const vector<flt> &allFltAdd)

Compute the predicted absolute magnitudes of the best-fit template(s) in an arbitrary set of additional filters, filling absmagPred

Parameters:
  • fulllib – SED library the source was fit against

  • lcdm – cosmology used to compute the magnitudes

  • allFltAdd – additional filters to predict magnitudes for

void computeEmFlux(vector<SED*> &fulllib, cosmo lcdm)

Compute the emission-line flux and equivalent width of the best-fit galaxy template rescaled to this source, filling fluxEL_SED and results_emission_lines

Parameters:
  • fulllib – SED library the source was fit against

  • lcdm – cosmology used to rescale the flux

void limits(vector<SED*> &fulllib, vector<double> &limits_zbin, int limits_ref, vector<int> &limits_sel, vector<double> &limits_cut)

Compute the faint-end absolute-magnitude limit reachable for this source given the survey depth, filling limits_zmax/limits_Mfaint

Parameters:
  • fulllib – SED library the source was fit against

  • limits_zbin – redshift bins in which the limit is computed

  • limits_ref – reference filter index

  • limits_sel – selection filter indices

  • limits_cut – flux limit cut per selection filter

pair<vector<double>, vector<double>> best_spec_vec(short sol, vector<SED*> &fulllib, cosmo lcdm, double minl, double maxl) const

Compute the flux-averaged best-fit spectrum (and its uncertainty) of a given solution, between two wavelengths

Parameters:
  • sol – solution to use: 0/1 for the primary/secondary galaxy solution, 2 for the FIR solution, 3 for QSO, 4 for STAR

  • fulllib – SED library the source was fit against

  • lcdm – cosmology used to compute the spectrum

  • minl – lower wavelength bound

  • maxl – upper wavelength bound

Returns:

[flux, flux uncertainty] averaged over the requested range

void compute_best_fit_physical_quantities(vector<SED*> &fulllib)

Compute the physical quantities (mass, SFR, luminosities…) of the best-fit template(s), filling results

Parameters:

fulllib – SED library the source was fit against

Public Members

unordered_map<string, double> results = {{"MASS_BEST", INVALID_PHYS}, {"SFR_BEST", INVALID_PHYS}, {"SSFR_BEST", INVALID_PHYS}, {"LDUST_BEST", INVALID_PHYS}, {"LUM_TIR_BEST", INVALID_PHYS}, {"AGE_BEST", INVALID_PHYS}, {"EBV_BEST", INVALID_PHYS}, {"EXTLAW_BEST", INVALID_PHYS}, {"LUM_NUV_BEST", INVALID_PHYS}, {"LUM_R_BEST", INVALID_PHYS}, {"LUM_K_BEST", INVALID_PHYS},}

Best-fit physical parameters for this source (see phys_par_names for the keys), initialised to #INVALID_PHYS and filled by compute_best_fit_physical_quantities()

unordered_map<string, double> results_emission_lines

Emission line flux (EM_FLUX_<line>) and equivalent width (EM_EW_<line>) for the best-fit galaxy template, filled by computeEmFlux()

long cont

input context: bitmask of bands used, as read from the catalogue (see globals.h CHECK_CONTEXT_BIT)

long new_cont

context rebuilt after masking bands with invalid flux or error, see fltUsed()

vector<double> ab

observed flux, one value per band

vector<double> sab

uncertainty on ab

vector<double> mab

observed AB magnitude, one value per band

vector<double> msab

uncertainty on mab

vector<double> magm

predicted (model) apparent magnitude for the best-fit template, one value per band

vector<double> magm0

predicted magnitude at z=0 for the best-fit template, one value per band

vector<double> absmagPred

predicted absolute magnitude, one value per band

vector<double> magPred

predicted apparent magnitude, one value per band

vector<double> kap

k-correction, one value per band

vector<double> mabs

absolute magnitude, one value per band (see absmag())

vector<double> emabs

uncertainty on mabs, one value per band

vector<double> ab_ori

copy of ab before the MW-dust / zero-point corrections, see keepOri()

vector<double> sab_ori

copy of sab before the corrections applied to ab_ori, see keepOri()

vector<double> mab_ori

copy of mab before the corrections applied to ab_ori, see keepOri()

vector<double> abIR

observed flux used for the FIR fit, i.e. ab minus the stellar predicted flux where applicable (see subtract_stellar_component())

vector<double> sabIR

uncertainty on abIR

vector<int> busnorma

per-band flag: 1 if the band is used in the main fit, 0 otherwise (see fltUsed())

vector<int> busul

per-band flag: 1 if the band is treated as an upper limit, 0 otherwise

vector<int> busfir

per-band flag: 1 if the band is used in the FIR fit, 0 otherwise (see fltUsedIR())

vector<int> bscfir

per-band flag: 1 if the band is used to scale the FIR fit, 0 otherwise

vector<int> absfilt

index of the filter used to compute the absolute magnitude, one value per element of mabs (see absmag())

string spec

identifier of the source (catalogue “spec” column)

string str_inp

additional free-form input string carried through to the output (see readsource())

int pos

position (row index) of the source in the catalogue

int nbused

number of bands used in the main fit

int nbul

number of bands treated as upper limits

int nbusIR

number of bands used to scale the FIR fit

int indminSec

index in the library of the secondary chi2 minimum (see secondpeak())

int indminIR

index in the FIR library of the chi2 minimum

int imasminIR

model number of the FIR fit minimum

double zs

spectroscopic redshift, as read from the catalogue

double consiz

redshift adopted for this source when computing derived/rest-frame quantities (e.g. absolute magnitudes, k-corrections); typically the best-fit or median photo-z depending on the calling context

array<double, 3> zmin

redshift of the chi2 minimum, for GAL/QSO/STAR (indices 0/1/2 respectively)

array<double, 3> chimin

chi2 of the minimum, for GAL/QSO/STAR

array<double, 3> dmmin

template scaling of the minimum, for GAL/QSO/STAR

array<int, 3> indmin

index in the library of the chi2 minimum, for GAL/QSO/STAR

array<int, 3> imasmin

model (template) number of the chi2 minimum, for GAL/QSO/STAR

double zminIR

redshift of the FIR fit chi2 minimum

double chiminIR

chi2 of the FIR fit minimum

double dmminIR

template scaling of the FIR fit minimum

array<double, 4> priorLib

absolute magnitude prior range, as [bright,faint] for the galaxy library followed by [bright,faint] for the AGN library (see setPriors())

vector<double> zgmed

median of the marginalized PDF, and CI bounds

Marginalized redshift PDF summary for galaxy templates: median (resp. chi2-minimum, PDF mode) at index 0, followed by the 68/90/99% credible interval [low,high] bounds at indices 1-6 (see generatePDF())

vector<double> zgmin

chi2-minimum solution, and CI bounds

vector<double> zgmode

mode of the marginalized PDF, and CI bounds

vector<double> zqmed

Same as zgmed/zgmin/zgmode, for the QSO/AGN library.

median of the marginalized PDF, and CI bounds

vector<double> zqmin

chi2-minimum solution, and CI bounds

vector<double> zqmode

mode of the marginalized PDF, and CI bounds

vector<double> massmed

log stellar mass, and CI bounds

Marginalized PDF summary (median, then 68/90/99% credible interval bounds, same layout as zgmed) of, respectively, log stellar mass, log SFR, log sSFR, log age, log dust luminosity, and the first and second rest-frame colors (see generatePDF())

vector<double> SFRmed

log SFR, and CI bounds

vector<double> sSFRmed

log sSFR, and CI bounds

vector<double> agemed

log age, and CI bounds

vector<double> Ldustmed

log dust luminosity, and CI bounds

vector<double> col1med

first rest-frame color, and CI bounds

vector<double> col2med

second rest-frame color, and CI bounds

vector<double> ebvmed

E(B-V), same layout as massmed.

vector<double> Mrefmed

reference absolute magnitude, same layout as massmed

array<double, 7> LIRmed

log IR luminosity marginalized PDF summary (median, then 68/90/99% credible interval bounds), filled by uncertaintiesBayIR()

array<double, 65> fluxEL_SED = {0}

Emission-line flux of the best-fit template rescaled to this source, indexed as in SED::fac_line (see computeEmFlux())

double limits_zmax = 20.

faint-end redshift limit used by limits()

double limits_Mfaint = 0

faint absolute magnitude limit, computed by limits()

unordered_map<int, PDF> pdfmap

Marginalized PDF for each physical/redshift quantity, keyed by the index defined in #maptype (e.g. 0 for stellar mass, 9 for the galaxy redshift); see the onesource(pos, gridz) constructor for the binning

double zsec

redshift of the secondary chi2 minimum

double zsecChi2

chi2 of the secondary minimum

double zsecEbv

E(B-V) of the secondary minimum.

double zsecScale

template scaling of the secondary minimum

double zsecProb

PDF probability of the secondary minimum.

double zsecAge

age of the secondary minimum

int zsecMod

model (template) number of the secondary minimum

int zsecExtlaw

extinction law index of the secondary minimum

double mw_ebv = -99.

Milky Way E(B-V) for this source (galactic coordinates), used by correct_classic_mw()/correct_galametz_mw(); -99. if not set

Public Static Functions

static double nzprior_eval(const NzPriorSetup &setup, const double luv, const double lnir, const double reds)

Evaluate the N(z) prior of one template, given the pre-computed source-dependent part. nzprior() is nzprior_eval(nzprior_setup(bp),…)

struct NzPriorSetup

Part of the N(z) prior that depends on the source only (apparent magnitude and, for each of the 4 template types, the quantities that do not depend on the template redshift). Computed once per fit() call by nzprior_setup() instead of once per template.

Public Members

bool has_mi = false

false if no band is available: prior is 1

double mi = -99.

apparent magnitude used by the prior

double zmax[4] = {}

zot + kt*(mi-20), per type

double pcal[4] = {}

normalisation of P(z|T,m0), per type

double rapp[4] = {}

ft*exp(-ktf*(mi-20)), per type

double rappSum = 1.

sum of rapp over the types