Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galplot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Andrew Strong
galplot
Commits
79051632
Commit
79051632
authored
Dec 21, 2019
by
Andrew Strong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
source/*cc
parent
36842732
Changes
133
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
133 changed files
with
77566 additions
and
0 deletions
+77566
-0
source/ArrayModel.cc
source/ArrayModel.cc
+80
-0
source/BaseModel.cc
source/BaseModel.cc
+313
-0
source/CAT.cc
source/CAT.cc
+294
-0
source/Configure.cc
source/Configure.cc
+26
-0
source/Coordinate.cc
source/Coordinate.cc
+22
-0
source/Counts.cc
source/Counts.cc
+252
-0
source/Distribution.cc
source/Distribution.cc
+599
-0
source/EBV_convert.cc
source/EBV_convert.cc
+344
-0
source/EGRET_catalogue.cc
source/EGRET_catalogue.cc
+272
-0
source/EnergyDispersionFermiLAT.cc
source/EnergyDispersionFermiLAT.cc
+1852
-0
source/ErrorLogger.cc
source/ErrorLogger.cc
+58
-0
source/Exposure.cc
source/Exposure.cc
+339
-0
source/FITS.cc
source/FITS.cc
+1096
-0
source/Fermi_Aeff.cc
source/Fermi_Aeff.cc
+462
-0
source/Fermi_systematic_errors.cc
source/Fermi_systematic_errors.cc
+56
-0
source/GCR_data.cc
source/GCR_data.cc
+529
-0
source/GalacticRadiationField.cc
source/GalacticRadiationField.cc
+589
-0
source/Galaxy.cc
source/Galaxy.cc
+191
-0
source/Galdef.cc
source/Galdef.cc
+972
-0
source/Galplot.cc
source/Galplot.cc
+272
-0
source/Galplotdef.cc
source/Galplotdef.cc
+1196
-0
source/HIH2IC.cc
source/HIH2IC.cc
+470
-0
source/IRF.cc
source/IRF.cc
+285
-0
source/Isotropic.cc
source/Isotropic.cc
+181
-0
source/JoinModel.cc
source/JoinModel.cc
+69
-0
source/Particle.cc
source/Particle.cc
+439
-0
source/Psf.cc
source/Psf.cc
+460
-0
source/RMF.cc
source/RMF.cc
+167
-0
source/RadiationField.cc
source/RadiationField.cc
+682
-0
source/Region.cc
source/Region.cc
+154
-0
source/SPIERSP.cc
source/SPIERSP.cc
+290
-0
source/SkymapFitsio.cc
source/SkymapFitsio.cc
+522
-0
source/Skymap_Energy_Dispersion.cc
source/Skymap_Energy_Dispersion.cc
+146
-0
source/SourceModel2.cc
source/SourceModel2.cc
+1207
-0
source/SourcePopulation.cc
source/SourcePopulation.cc
+2537
-0
source/Sources.cc
source/Sources.cc
+1108
-0
source/Sun.cc
source/Sun.cc
+180
-0
source/Utils.cc
source/Utils.cc
+144
-0
source/Variables.cc
source/Variables.cc
+231
-0
source/convolve.cc
source/convolve.cc
+195
-0
source/convolve_EGRET.cc
source/convolve_EGRET.cc
+297
-0
source/convolve_EGRET_HI_H2.cc
source/convolve_EGRET_HI_H2.cc
+303
-0
source/convolve_GLAST.cc
source/convolve_GLAST.cc
+297
-0
source/convolve_GLAST_HI_H2.cc
source/convolve_GLAST_HI_H2.cc
+303
-0
source/create_galaxy.cc
source/create_galaxy.cc
+254
-0
source/create_gcr.cc
source/create_gcr.cc
+132
-0
source/energy_integral.cc
source/energy_integral.cc
+157
-0
source/fit_EGRET.cc
source/fit_EGRET.cc
+741
-0
source/fit_EGRET_Xco.cc
source/fit_EGRET_Xco.cc
+2079
-0
source/galplot.cc
source/galplot.cc
+16
-0
source/gen_GLAST_models.cc
source/gen_GLAST_models.cc
+581
-0
source/gen_isrf_energy_density.cc
source/gen_isrf_energy_density.cc
+128
-0
source/gen_source_population.cc
source/gen_source_population.cc
+495
-0
source/kinematic.cc
source/kinematic.cc
+190
-0
source/modulate.cc
source/modulate.cc
+144
-0
source/nH.cc
source/nH.cc
+429
-0
source/plot_COMPTEL_model_profile.cc
source/plot_COMPTEL_model_profile.cc
+564
-0
source/plot_COMPTEL_profile.cc
source/plot_COMPTEL_profile.cc
+429
-0
source/plot_COMPTEL_spectrum.cc
source/plot_COMPTEL_spectrum.cc
+410
-0
source/plot_Chandra_spectrum.cc
source/plot_Chandra_spectrum.cc
+4518
-0
source/plot_EGRET_profile.cc
source/plot_EGRET_profile.cc
+354
-0
source/plot_EGRET_skymaps.cc
source/plot_EGRET_skymaps.cc
+220
-0
source/plot_EGRET_spectrum.cc
source/plot_EGRET_spectrum.cc
+681
-0
source/plot_GINGA_spectrum.cc
source/plot_GINGA_spectrum.cc
+440
-0
source/plot_GLAST_profile.cc
source/plot_GLAST_profile.cc
+352
-0
source/plot_GLAST_profile_healpix.cc
source/plot_GLAST_profile_healpix.cc
+475
-0
source/plot_GLAST_spectrum.cc
source/plot_GLAST_spectrum.cc
+394
-0
source/plot_GLAST_spectrum_healpix.cc
source/plot_GLAST_spectrum_healpix.cc
+511
-0
source/plot_IBIS_spectrum.cc
source/plot_IBIS_spectrum.cc
+127
-0
source/plot_IBIS_spectrum_krivonos.cc
source/plot_IBIS_spectrum_krivonos.cc
+243
-0
source/plot_OSSE_spectrum.cc
source/plot_OSSE_spectrum.cc
+156
-0
source/plot_RXTE_spectrum.cc
source/plot_RXTE_spectrum.cc
+146
-0
source/plot_SPI_bouchet_profile.cc
source/plot_SPI_bouchet_profile.cc
+685
-0
source/plot_SPI_model_profile.cc
source/plot_SPI_model_profile.cc
+564
-0
source/plot_SPI_spectrum.cc
source/plot_SPI_spectrum.cc
+1120
-0
source/plot_SPI_spectrum_bouchet.cc
source/plot_SPI_spectrum_bouchet.cc
+2056
-0
source/plot_SPI_spectrum_spimodfit.cc
source/plot_SPI_spectrum_spimodfit.cc
+2716
-0
source/plot_SPI_spiskymax_profile.cc
source/plot_SPI_spiskymax_profile.cc
+508
-0
source/plot_convolved_EGRET_profile.cc
source/plot_convolved_EGRET_profile.cc
+891
-0
source/plot_convolved_GLAST_profile.cc
source/plot_convolved_GLAST_profile.cc
+894
-0
source/plot_convolved_GLAST_profile_healpix.cc
source/plot_convolved_GLAST_profile_healpix.cc
+1629
-0
source/plot_gcr_spectra.cc
source/plot_gcr_spectra.cc
+633
-0
source/plot_gcr_spectra_data.cc
source/plot_gcr_spectra_data.cc
+314
-0
source/plot_gcr_spectra_data_legend.cc
source/plot_gcr_spectra_data_legend.cc
+149
-0
source/plot_gcr_spectra_ratios.cc
source/plot_gcr_spectra_ratios.cc
+435
-0
source/plot_gcr_spectra_ratios_data.cc
source/plot_gcr_spectra_ratios_data.cc
+166
-0
source/plot_isotropic_EGRET_spectrum.cc
source/plot_isotropic_EGRET_spectrum.cc
+237
-0
source/plot_isotropic_sreekumar_spectrum.cc
source/plot_isotropic_sreekumar_spectrum.cc
+200
-0
source/plot_luminosity.cc
source/plot_luminosity.cc
+2243
-0
source/plot_luminosity_multiple_galdef.cc
source/plot_luminosity_multiple_galdef.cc
+2262
-0
source/plot_model_ridge.cc
source/plot_model_ridge.cc
+130
-0
source/plot_mw_isrf.cc
source/plot_mw_isrf.cc
+1555
-0
source/plot_source_population_NS.cc
source/plot_source_population_NS.cc
+375
-0
source/plot_source_population_profile.cc
source/plot_source_population_profile.cc
+365
-0
source/plot_spectrum.cc
source/plot_spectrum.cc
+1471
-0
source/plot_spectrum_healpix.cc
source/plot_spectrum_healpix.cc
+719
-0
source/plot_synchrotron_clouds_profile.cc
source/plot_synchrotron_clouds_profile.cc
+2285
-0
source/plot_synchrotron_profile.cc
source/plot_synchrotron_profile.cc
+3057
-0
source/plot_synchrotron_profile_planck.cc
source/plot_synchrotron_profile_planck.cc
+2429
-0
source/plot_synchrotron_skymap.cc
source/plot_synchrotron_skymap.cc
+2621
-0
source/poisson.cc
source/poisson.cc
+72
-0
source/power_law_sampler.cc
source/power_law_sampler.cc
+94
-0
source/read_COMPTEL_data.cc
source/read_COMPTEL_data.cc
+75
-0
source/read_COR.cc
source/read_COR.cc
+201
-0
source/read_EGRET_data.cc
source/read_EGRET_data.cc
+303
-0
source/read_EGRET_psf.cc
source/read_EGRET_psf.cc
+151
-0
source/read_GLAST_data.cc
source/read_GLAST_data.cc
+359
-0
source/read_GLAST_psf.cc
source/read_GLAST_psf.cc
+153
-0
source/read_HIR.cc
source/read_HIR.cc
+286
-0
source/read_IC_emiss.cc
source/read_IC_emiss.cc
+112
-0
source/read_IC_skymap.cc
source/read_IC_skymap.cc
+146
-0
source/read_bremss_H2R_skymap.cc
source/read_bremss_H2R_skymap.cc
+91
-0
source/read_bremss_HIR_skymap.cc
source/read_bremss_HIR_skymap.cc
+91
-0
source/read_bremss_emiss.cc
source/read_bremss_emiss.cc
+224
-0
source/read_bremss_skymap.cc
source/read_bremss_skymap.cc
+127
-0
source/read_gcr.cc
source/read_gcr.cc
+273
-0
source/read_gcr_source_functions.cc
source/read_gcr_source_functions.cc
+202
-0
source/read_isrf.cc
source/read_isrf.cc
+1265
-0
source/read_pi0_decay_H2R_skymap.cc
source/read_pi0_decay_H2R_skymap.cc
+91
-0
source/read_pi0_decay_HIR_skymap.cc
source/read_pi0_decay_HIR_skymap.cc
+91
-0
source/read_pi0_decay_emiss.cc
source/read_pi0_decay_emiss.cc
+108
-0
source/read_pi0_decay_skymap.cc
source/read_pi0_decay_skymap.cc
+115
-0
source/read_solar_skymap.cc
source/read_solar_skymap.cc
+405
-0
source/read_synchrotron_data.cc
source/read_synchrotron_data.cc
+2858
-0
source/read_synchrotron_emiss.cc
source/read_synchrotron_emiss.cc
+108
-0
source/read_synchrotron_skymap.cc
source/read_synchrotron_skymap.cc
+155
-0
source/sabin.cc
source/sabin.cc
+74
-0
source/set_output.cc
source/set_output.cc
+102
-0
source/store_gcr_source_functions.cc
source/store_gcr_source_functions.cc
+234
-0
source/test_Skymap.cc
source/test_Skymap.cc
+104
-0
source/test_gsl_gamma_function.cc
source/test_gsl_gamma_function.cc
+163
-0
source/test_gsl_gauss_sampler.cc
source/test_gsl_gauss_sampler.cc
+57
-0
source/write_convolved_EGRET.cc
source/write_convolved_EGRET.cc
+120
-0
No files found.
source/ArrayModel.cc
0 → 100644
View file @
79051632
#include "Model.h"
ArrayModel
::
ArrayModel
(
const
Exposure
&
exposure
,
const
CountsMap
&
counts
,
const
Psf
&
psf
,
const
Sources
&
sources
,
const
Parameters
&
pars
,
const
Skymap
<
char
>
&
filter
,
unsigned
int
configure
)
:
BaseModel
(
counts
,
exposure
,
psf
,
sources
,
pars
,
filter
,
configure
),
fmodels
(
0
)
{
}
void
ArrayModel
::
setModels
(
const
std
::
vector
<
BaseModel
*>
&
models
)
{
//Check for null pointers in the array
for
(
int
i
=
0
;
i
<
models
.
size
();
++
i
){
if
(
models
[
i
]
==
0
)
{
throw
(
ModelError
(
"Null pointer in array model, aborting"
));
}
}
//Clear up the variables
fvariables
.
clear
();
//Set the model array to the new models
fmodels
=
models
;
//Join the variables
for
(
int
i
=
0
;
i
<
fmodels
.
size
();
++
i
){
fvariables
.
add
(
fmodels
[
i
]
->
getVariables
());
}
}
void
ArrayModel
::
getMap
(
const
Variables
&
vars
,
Skymap
<
double
>
&
map
)
{
for
(
int
i
=
0
;
i
<
fmodels
.
size
();
++
i
){
fmodels
[
i
]
->
getMap
(
vars
,
map
);
}
}
BaseModel
::
gradMap
ArrayModel
::
getComponents
(
const
Variables
&
vars
,
const
std
::
string
&
prefix
){
gradMap
output
;
for
(
int
i
=
0
;
i
<
fmodels
.
size
();
++
i
){
gradMap
tmp
(
fmodels
[
i
]
->
getComponents
(
vars
,
prefix
));
for
(
gradMap
::
iterator
it
=
tmp
.
begin
();
it
!=
tmp
.
end
();
++
it
){
//Check if something exists, if it does, add the new map
//rather than replace it
gradMap
::
iterator
it2
=
output
.
find
((
*
it
).
first
);
if
(
it2
==
output
.
end
())
{
output
[(
*
it
).
first
]
=
(
*
it
).
second
;
}
else
{
output
[(
*
it
).
first
]
+=
(
*
it
).
second
;
}
}
}
return
output
;
}
void
ArrayModel
::
getGrads
(
const
Variables
&
vars
,
const
std
::
string
&
varName
,
Skymap
<
double
>
&
map
)
{
for
(
int
i
=
0
;
i
<
fmodels
.
size
();
++
i
){
fmodels
[
i
]
->
getGrads
(
vars
,
varName
,
map
);
}
}
BaseModel
::
gradMap
ArrayModel
::
getSecDer
(
const
Variables
&
vars
,
const
std
::
string
&
varName1
,
const
std
::
string
&
varName2
)
{
gradMap
output
;
//Loop over the models and add to output
for
(
int
i
=
0
;
i
<
fmodels
.
size
();
++
i
){
gradMap
tmp
(
fmodels
[
i
]
->
getSecDer
(
vars
,
varName1
,
varName2
));
for
(
gradMap
::
iterator
it
=
tmp
.
begin
();
it
!=
tmp
.
end
();
++
it
){
//Check if something exists, if it does, add the new map
//rather than replace it
gradMap
::
iterator
it2
=
output
.
find
((
*
it
).
first
);
if
(
it2
==
output
.
end
())
{
output
[(
*
it
).
first
]
=
(
*
it
).
second
;
}
else
{
output
[(
*
it
).
first
]
+=
(
*
it
).
second
;
}
}
}
return
output
;
}
void
ArrayModel
::
modifySources
(
const
Variables
&
vars
,
Sources
&
sources
)
const
{
for
(
int
i
=
0
;
i
<
fmodels
.
size
();
++
i
)
{
fmodels
[
i
]
->
modifySources
(
vars
,
sources
);
}
}
source/BaseModel.cc
0 → 100644
View file @
79051632
#include "Goodness.h"
#include "Exposure.h"
#include "Counts.h"
#include "Psf.h"
#include "Sources.h"
#include "Parameters.h"
#include "Skymap.h"
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <valarray>
#include "alm.h"
#ifdef HAVE_ALM_MAP_TOOLS_H
#include "alm_map_tools.h"
#endif
#ifdef HAVE_ALM_HEALPIX_TOOLS_H
#include "alm_healpix_tools.h"
#endif
#include "xcomplex.h"
#include "arr.h"
#include "time.h"
#include "Utils.h"
#include <ostream>
BaseModel
::
BaseModel
(
const
CountsMap
&
counts
,
const
Exposure
&
exposure
,
const
Psf
&
psf
,
const
Sources
&
sources
,
const
Parameters
&
pars
,
const
Skymap
<
char
>
&
filter
,
unsigned
int
configure
)
:
fcounts
(
counts
),
fexposure
(
exposure
),
fpsf
(
psf
),
fsources
(
sources
),
fparameters
(
pars
),
ffilter
(
filter
),
fconfigure
(
configure
),
EXPOSURE_CORRECT
(
1
),
CONVOLVE
(
2
)
{
//Sanity check, to see that the energy range of the exposure and psf is
//greater than that of the counts.
if
(
counts
.
getEMin
().
min
()
<
exposure
.
getEnergies
().
min
()){
std
::
cout
<<
"Warning: "
<<
std
::
endl
;
std
::
cout
<<
"Lower energy bound of counts is lower than the lowest energy of exposure, continuing with extrapolation"
<<
std
::
endl
;
std
::
cout
<<
counts
.
getEMin
().
min
()
<<
" < "
<<
exposure
.
getEnergies
().
min
()
<<
std
::
endl
;
}
if
(
counts
.
getEMin
().
min
()
<
psf
.
getEnergies
().
front
()){
std
::
cout
<<
"Warning: "
<<
std
::
endl
;
std
::
cout
<<
"Lower energy bound of counts is lower than the lowest energy of psf, continuing with extrapolation"
<<
std
::
endl
;
std
::
cout
<<
counts
.
getEMin
().
min
()
<<
" < "
<<
psf
.
getEnergies
().
front
()
<<
std
::
endl
;
}
if
(
counts
.
getEMax
().
max
()
>
exposure
.
getEnergies
().
max
()){
std
::
cout
<<
"Warning: "
<<
std
::
endl
;
std
::
cout
<<
"Higher energy bound of counts is higher than the highest energy of exposure, continuing with extrapolation"
<<
std
::
endl
;
std
::
cout
<<
counts
.
getEMax
().
max
()
<<
" > "
<<
exposure
.
getEnergies
().
max
()
<<
std
::
endl
;
}
if
(
counts
.
getEMax
().
max
()
>
psf
.
getEnergies
().
back
()){
std
::
cout
<<
"Warning: "
<<
std
::
endl
;
std
::
cout
<<
"Higher energy bound of counts is higher than the highest energy of psf, continuing with extrapolation"
<<
std
::
endl
;
std
::
cout
<<
counts
.
getEMax
().
max
()
<<
" > "
<<
psf
.
getEnergies
().
back
()
<<
std
::
endl
;
}
}
const
CountsMap
&
BaseModel
::
getCounts
()
const
{
return
fcounts
;
}
const
Skymap
<
char
>
&
BaseModel
::
getFilter
()
const
{
return
ffilter
;
}
std
::
valarray
<
double
>
BaseModel
::
spectraToCounts
(
std
::
valarray
<
double
>
&
intensities
,
const
std
::
valarray
<
double
>
&
energies
,
const
SM
::
Coordinate
&
co
,
bool
psfRebin
,
std
::
valarray
<
double
>
*
eMinArr
,
std
::
valarray
<
double
>
*
eMaxArr
)
const
{
//We use pointers here because of backward compatibility. Passing a
//reference would be more natural.
//If psfRebin is given, make finer energy bins, compatible with psf
if
(
eMinArr
==
0
)
eMinArr
=
new
std
::
valarray
<
double
>
();
if
(
eMaxArr
==
0
)
eMaxArr
=
new
std
::
valarray
<
double
>
();
if
(
psfRebin
){
getPsfEnergyBoundaries
(
*
eMinArr
,
*
eMaxArr
);
}
else
{
fcounts
.
getCountsMap
().
getBoundaries
(
*
eMinArr
,
*
eMaxArr
);
}
if
(
fconfigure
&
EXPOSURE_CORRECT
)
{
return
fexposure
.
spectraToCounts
(
intensities
,
energies
,
*
eMinArr
,
*
eMaxArr
,
co
);
}
else
{
//Do interpolation of intensities
std
::
valarray
<
double
>
output
(
eMinArr
->
size
());
int
il
,
iu
;
for
(
int
i
=
0
;
i
<
eMinArr
->
size
();
++
i
){
Utils
::
findIndexRange
(
energies
,
(
*
eMinArr
)[
i
],
(
*
eMaxArr
)[
i
],
il
,
iu
);
//Calculate the average spectrum over the entire bin
double
flux
=
0
;
for
(
int
j
=
il
;
j
<
iu
;
++
j
)
{
//Handle extrapolation gracefully
double
emin
;
if
(
j
==
0
&&
(
*
eMinArr
)[
i
]
<
energies
[
j
]){
emin
=
(
*
eMinArr
)[
i
];
}
else
{
emin
=
std
::
max
((
*
eMinArr
)[
i
],
energies
[
j
]);
}
double
emax
;
if
(
j
==
energies
.
size
()
-
2
&&
(
*
eMaxArr
)[
i
]
>
energies
[
j
+
1
]){
emax
=
(
*
eMaxArr
)[
i
];
}
else
{
emax
=
std
::
min
((
*
eMaxArr
)[
i
],
energies
[
j
+
1
]);
}
if
(
intensities
[
j
]
>
0
&&
intensities
[
j
+
1
]
>
0
)
{
double
tmpInd
=
log
(
intensities
[
j
+
1
]
/
intensities
[
j
])
/
log
(
energies
[
j
+
1
]
/
energies
[
j
]);
if
(
tmpInd
!=
1
)
{
flux
+=
intensities
[
j
]
*
pow
(
energies
[
j
],
-
tmpInd
)
/
(
tmpInd
+
1
)
*
(
pow
(
emax
,
tmpInd
+
1
)
-
pow
(
emin
,
tmpInd
+
1
));
}
else
{
flux
+=
intensities
[
j
]
*
pow
(
energies
[
j
],
-
tmpInd
)
*
(
log
(
emax
)
-
log
(
emin
));
}
}
}
output
[
i
]
=
flux
/
((
*
eMaxArr
)[
i
]
-
(
*
eMinArr
)[
i
]);
if
(
isnan
(
output
[
i
])
||
isinf
(
output
[
i
])){
std
::
cout
<<
"NANs in spectraToCounts "
<<
intensities
[
iu
]
<<
", "
<<
intensities
[
il
]
<<
", "
<<
energies
[
iu
]
<<
", "
<<
energies
[
il
]
<<
std
::
endl
;
}
}
return
output
;
}
}
std
::
valarray
<
double
>
BaseModel
::
powerLawCounts
(
double
prefactor
,
double
index
,
double
pivot
,
const
SM
::
Coordinate
&
co
,
bool
psfRebin
,
std
::
valarray
<
double
>
*
eMinArr
,
std
::
valarray
<
double
>
*
eMaxArr
)
const
{
//We use pointers here because of backward compatibility. Passing a
//reference would be more natural.
//If psfRebin is given, make finer energy bins, compatible with psf
if
(
eMinArr
==
0
)
eMinArr
=
new
std
::
valarray
<
double
>
();
if
(
eMaxArr
==
0
)
eMaxArr
=
new
std
::
valarray
<
double
>
();
if
(
psfRebin
){
getPsfEnergyBoundaries
(
*
eMinArr
,
*
eMaxArr
);
}
else
{
fcounts
.
getCountsMap
().
getBoundaries
(
*
eMinArr
,
*
eMaxArr
);
}
if
(
fconfigure
&
EXPOSURE_CORRECT
)
{
return
fexposure
.
spectraToCounts
(
index
,
prefactor
,
pivot
,
*
eMinArr
,
*
eMaxArr
,
co
);
}
else
{
std
::
valarray
<
double
>
sp
(
eMinArr
->
size
());
for
(
int
i
=
0
;
i
<
sp
.
size
();
++
i
){
sp
[
i
]
=
prefactor
*
pow
(
0.5
*
((
*
eMinArr
)[
i
]
+
(
*
eMaxArr
)[
i
])
/
pivot
,
index
);
}
return
sp
;
}
}
Skymap
<
double
>
BaseModel
::
convolve
(
const
Skymap
<
double
>
&
skyMap
,
bool
psfRebin
)
const
{
Skymap
<
double
>
outMap
;
if
(
fconfigure
&
CONVOLVE
)
{
outMap
=
fpsf
.
convolve
(
skyMap
);
}
else
{
outMap
=
skyMap
;
}
// Need to re-bin the outMap if psfRebin is true
if
(
psfRebin
){
rebinPsfBoundariesToCounts
(
outMap
);
}
return
outMap
;
}
Skymap
<
double
>
BaseModel
::
fluxToCounts
(
const
Skymap
<
double
>
&
inputFluxMap
,
bool
psfRebin
)
const
{
// If psfRebin is true, rebin the input bins in such a way to split the bins
// in the count map into finer bins so we have very little energy gap for
// the psf correction.
std
::
valarray
<
double
>
eMinArr
,
eMaxArr
;
if
(
psfRebin
)
{
getPsfEnergyBoundaries
(
eMinArr
,
eMaxArr
);
}
else
{
fcounts
.
getCountsMap
().
getBoundaries
(
eMinArr
,
eMaxArr
);
}
if
(
fconfigure
&
EXPOSURE_CORRECT
)
{
//Use the exposure method
return
fexposure
.
mapToCounts
(
inputFluxMap
,
eMinArr
,
eMaxArr
,
fcounts
.
getCountsMap
().
Order
());
}
else
{
//Rebin the map to conform to counts (eMinArr)
Skymap
<
double
>
output
(
fcounts
.
getCountsMap
().
Order
(),
eMinArr
,
eMaxArr
);
Skymap
<
double
>
rebinned
=
inputFluxMap
.
rebin
(
fcounts
.
getCountsMap
().
Order
());
for
(
int
k
=
0
;
k
<
output
.
Npix
();
++
k
)
{
int
il
,
iu
;
for
(
int
i
=
0
;
i
<
eMinArr
.
size
();
++
i
){
Utils
::
findIndexRange
(
inputFluxMap
.
getSpectra
(),
eMinArr
[
i
],
eMaxArr
[
i
],
il
,
iu
);
//Calculate the average spectrum over the entire bin
double
flux
=
0
;
for
(
int
j
=
il
;
j
<
iu
;
++
j
)
{
//Handle extrapolation gracefully
double
emin
;
if
(
j
==
0
&&
eMinArr
[
i
]
<
inputFluxMap
.
getSpectra
()[
j
]){
emin
=
eMinArr
[
i
];
}
else
{
emin
=
std
::
max
(
eMinArr
[
i
],
inputFluxMap
.
getSpectra
()[
j
]);
}
double
emax
;
if
(
j
==
inputFluxMap
.
nSpectra
()
-
2
&&
eMaxArr
[
i
]
>
inputFluxMap
.
getSpectra
()[
j
+
1
]){
emax
=
eMaxArr
[
i
];
}
else
{
emax
=
std
::
min
(
eMaxArr
[
i
],
inputFluxMap
.
getSpectra
()[
j
+
1
]);
}
if
(
rebinned
[
k
][
j
]
>
0
&&
rebinned
[
k
][
j
+
1
]
>
0
)
{
double
tmpInd
=
log
(
rebinned
[
k
][
j
+
1
]
/
rebinned
[
k
][
j
])
/
log
(
inputFluxMap
.
getSpectra
()[
j
+
1
]
/
inputFluxMap
.
getSpectra
()[
j
]);
if
(
tmpInd
!=
1
)
{
flux
+=
rebinned
[
k
][
j
]
*
pow
(
inputFluxMap
.
getSpectra
()[
j
],
-
tmpInd
)
/
(
tmpInd
+
1
)
*
(
pow
(
emax
,
tmpInd
+
1
)
-
pow
(
emin
,
tmpInd
+
1
));
}
else
{
flux
+=
rebinned
[
k
][
j
]
*
pow
(
inputFluxMap
.
getSpectra
()[
j
],
-
tmpInd
)
*
(
log
(
emax
)
-
log
(
emin
));
}
}
}
output
[
k
][
i
]
=
flux
/
(
eMaxArr
[
i
]
-
eMinArr
[
i
]);
if
(
isnan
(
output
[
k
][
i
])
||
isinf
(
output
[
k
][
i
])
)
{
std
::
cout
<<
"NAN in fluxToCounts "
<<
rebinned
[
k
][
iu
]
<<
", "
<<
rebinned
[
k
][
il
]
<<
", "
<<
inputFluxMap
.
getSpectra
()[
iu
]
<<
", "
<<
inputFluxMap
.
getSpectra
()[
il
]
<<
std
::
endl
;
}
}
}
return
output
;
}
}
Variables
&
BaseModel
::
getVariables
(){
return
fvariables
;
}
const
Variables
&
BaseModel
::
getVariables
()
const
{
return
fvariables
;
}
void
BaseModel
::
setVariables
(
const
Variables
&
vars
){
//Get the names of the current variables
std
::
vector
<
std
::
string
>
varNames
=
fvariables
.
getNames
();
for
(
int
i
=
0
;
i
<
varNames
.
size
();
++
i
)
{
fvariables
[
varNames
[
i
]]
=
vars
[
varNames
[
i
]];
fvariables
.
error
(
varNames
[
i
])
=
vars
.
error
(
varNames
[
i
]);
}
}
Sources
BaseModel
::
getSources
(
const
Variables
&
vars
)
const
{
Sources
sources
(
fsources
);
modifySources
(
vars
,
sources
);
return
sources
;
}
void
BaseModel
::
getPsfEnergyBoundaries
(
std
::
valarray
<
double
>
&
eMin
,
std
::
valarray
<
double
>
&
eMax
)
const
{
std
::
vector
<
double
>
eMinVec
,
eMaxVec
;
// First we need to get the energies at which the psf is defined
const
std
::
vector
<
double
>
&
psfE
=
fpsf
.
getEnergies
();
// Then we get the boundaries from the counts map
const
std
::
valarray
<
double
>
&
cMin
=
fcounts
.
getEMin
();
const
std
::
valarray
<
double
>
&
cMax
=
fcounts
.
getEMax
();
// Now we need to loop over the counts energy boundaries and add the
// necessary splits to the energy arrays. We split such that there is
// at least one psf defined in an energy bin, within the limits of the
// counts binning of course.
for
(
size_t
i
=
0
;
i
<
cMin
.
size
();
++
i
){
// Get the indexes of the psf within the energy bin
int
lowIndex
,
highIndex
;
// The routine brackets the energy bin, unless the psf energy range
// does not span the energy bin.
Utils
::
findIndexRange
(
psfE
,
cMin
[
i
],
cMax
[
i
],
lowIndex
,
highIndex
);
// Unless the psf energy range does not extend beyond the minimum
// boundary, skip the first element
int
j
=
1
;
if
(
psfE
[
lowIndex
]
>
cMin
[
i
]
)
j
=
0
;
// Same for the last element
int
k
=
1
;
if
(
psfE
[
highIndex
]
<
cMax
[
i
]
)
k
=
0
;
eMinVec
.
push_back
(
cMin
[
i
]);
for
(
int
l
=
lowIndex
+
j
;
l
<
highIndex
-
k
;
++
l
){
eMaxVec
.
push_back
((
psfE
[
l
]
+
psfE
[
l
+
1
])
/
2.
);
eMinVec
.
push_back
((
psfE
[
l
]
+
psfE
[
l
+
1
])
/
2.
);
}
eMaxVec
.
push_back
(
cMax
[
i
]);
}
eMin
.
resize
(
eMinVec
.
size
());
eMax
.
resize
(
eMaxVec
.
size
());
std
::
copy
(
eMinVec
.
begin
(),
eMinVec
.
end
(),
&
eMin
[
0
]);
std
::
copy
(
eMaxVec
.
begin
(),
eMaxVec
.
end
(),
&
eMax
[
0
]);
}
void
BaseModel
::
rebinPsfBoundariesToCounts
(
Skymap
<
double
>
&
inMap
)
const
{
if
(
fcounts
.
getEMax
().
size
()
<
inMap
.
nSpectra
())
{
Skymap
<
double
>
tmpMap
(
fcounts
.
getCountsMap
().
Order
(),
fcounts
.
getEMin
(),
fcounts
.
getEMax
(),
RING
);
//Get the boundaries of the input map
std
::
valarray
<
double
>
eMinArr
,
eMaxArr
;
inMap
.
getBoundaries
(
eMinArr
,
eMaxArr
);
//std::copy(&eMaxArr[0],&eMaxArr[0]+eMaxArr.size(), std::ostream_iterator<double>(std::cout, ", "));
//Loop over the count map bins and sum up the output map
int
j
=
0
;
for
(
int
i
=
0
;
i
<
fcounts
.
getEMin
().
size
();
++
i
){
if
(
fcounts
.
getEMin
()[
i
]
!=
eMinArr
[
j
])
{
std
::
cerr
<<
"Things might be wrong when rebinning in convolution. Energy boundaries don't match"
<<
std
::
endl
;
std
::
cerr
<<
fcounts
.
getEMin
()[
i
]
<<
" != "
<<
eMinArr
[
j
]
<<
std
::
endl
;
}
int
cnt
=
0
;
while
(
eMaxArr
[
j
]
<=
fcounts
.
getEMax
()[
i
]
&&
j
<
eMaxArr
.
size
())
{
//std::cout<<j<<", ";
for
(
int
k
=
0
;
k
<
inMap
.
Npix
();
++
k
){
tmpMap
[
k
][
i
]
+=
inMap
[
k
][
j
];
}
++
j
;
++
cnt
;
}
if
(
!
(
fconfigure
&
EXPOSURE_CORRECT
)
&&
cnt
!=
0
)
{
for
(
int
k
=
0
;
k
<
inMap
.
Npix
();
++
k
)
{
tmpMap
[
k
][
i
]
/=
float
(
cnt
);
}
}
if
(
fcounts
.
getEMax
()[
i
]
!=
eMaxArr
[
j
-
1
]){
std
::
cerr
<<
"Things might be wrong when rebinning in convolution. Energy boundaries don't match"
<<
std
::
endl
;
std
::
cerr
<<
fcounts
.
getEMax
()[
i
]
<<
" != "
<<
eMaxArr
[
j
-
1
]
<<
std
::
endl
;
}
}
inMap
=
tmpMap
;
}
}
source/CAT.cc
0 → 100644
View file @
79051632
using
namespace
std
;
// for slalib version which uses: if defined (__cplusplus) extern "C"
// but this does not work, use version without this
// #define __cplusplus
#include<iostream>
#include"fitsio.h"
#include"slalib.h"
#include"CAT.h"
//////////////////////////////////////////////////////
///////////////////////////////////////////////////////
int
CAT
::
read
(
char
*
directory
)
{
char
infile
[
500
];
char
err_text
[
100
];
char
comment
[
100
];
fitsfile
*
fptr
;
int
status
;
int
hdunum
,
hdutype
,
total_hdus
,
colnum
;
int
n_columns
,
n_rows
;
double
nulval
=
0.
;
int
anynul
=
0
;
char
nulstr
[
100
];
strcpy
(
nulstr
,
"null"
);
double
dtr
=
acos
(
-
1.0
)
/
180.
;
int
i
,
j
,
k
;
//char catalogue_file[]="gnrl_refr_cat_0020_reformatted.fits";
//char catalogue_file[]="isgriCat_2nd_Tony.fits";
char
catalogue_file
[]
=
"isgri_2nd_cat_revised.fits"
;
cout
<<
"CAT::read ("
<<
directory
<<
")"
<<
endl
;
strcpy
(
infile
,
directory
);
strcat
(
infile
,
catalogue_file
);
cout
<<
" infile "
<<
infile
<<
endl
;
status
=
0
;
// needed
fits_open_file
(
&
fptr
,
infile
,
READONLY
,
&
status
)
;
cout
<<
"FITS read open status= "
<<
status
<<
" "
<<
infile
<<
endl
;
fits_get_errstatus
(
status
,
err_text
);
cout
<<
err_text
<<
endl
;
fits_get_num_hdus
(
fptr
,
&
total_hdus
,
&
status
);
cout
<<
"total number of header units="
<<
total_hdus
<<
endl
;
hdunum
=
1
;
fits_movabs_hdu
(
fptr
,
hdunum
+
1
,
&
hdutype
,
&
status
);
cout
<<
"FITS movabs_hdu hdunum="
<<
hdunum
<<
" status= "
<<
status
<<
" hdutype="
<<
hdutype
<<
endl
;
fits_read_key
(
fptr
,
TLONG
,
"TFIELDS"
,
&
n_columns
,
comment
,
&
status
);
cout
<<
" n_columns ="
<<
n_columns
;
fits_read_key
(
fptr
,
TLONG
,
"NAXIS2"
,
&
n_rows
,
comment
,
&
status
);
cout
<<
" n_rows ="
<<
n_rows
<<
endl
;
n_sources
=
n_rows
;
ra
=
new
double
[
n_rows
];
dec
=
new
double
[
n_rows
];
flux
=
new
double
[
n_rows
];
//AWS20060110
flux_err
=
new
double
[
n_rows
];
//AWS20060110
fits_get_colnum
(
fptr
,
CASEINSEN
,
"RA_OBJ"
,
&
colnum
,
&
status
);
cout
<<
"RA_OBJ column ="
<<
colnum
<<
endl
;
fits_read_col
(
fptr
,
TDOUBLE
,
colnum
,
1
,
1
,
n_rows
,
&
nulval
,
ra
,
&
anynul
,
&
status
);
fits_get_colnum
(
fptr
,
CASEINSEN
,
"DEC_OBJ"
,
&
colnum
,
&
status
);
cout
<<
"DEC_OBJ column ="
<<
colnum
<<
endl
;
fits_read_col
(
fptr
,
TDOUBLE
,
colnum
,
1
,
1
,
n_rows
,
&
nulval
,
dec
,
&
anynul
,
&
status
);
// cout<<"ra :";for (i=0;i<n_rows;i++)cout<<" "<<ra [i];cout<<endl;
//cout<<"dec:";for (i=0;i<n_rows;i++)cout<<" "<<dec[i];cout<<endl;
fits_get_colnum
(
fptr
,
CASEINSEN
,
"NAME"
,
&
colnum
,
&
status
);
cout
<<
"NAME column ="
<<
colnum
<<
endl
;
name
=
new
char
*
[
n_rows
];
for
(
i
=
0
;
i
<
n_rows
;
i
++
)
name
[
i
]
=
new
char
[
100
];
fits_read_col_str
(
fptr
,
colnum
,
1
,
1
,
n_rows
,
nulstr
,
name
,
&
anynul
,
&
status
);
// for (i=0;i<n_rows;i++) cout<< name[i] <<" ra="<<ra[i]<<" dec="<<dec[i]<<endl;
longitude
=
new
double
[
n_rows
];
latitude
=
new
double
[
n_rows
];
for
(
i
=
0
;
i
<
n_rows
;
i
++
)
{
// NB had to compile sla_c since undefined symbol using lib from osa4.2
slaEqgal
(
ra
[
i
]
*
dtr
,
dec
[
i
]
*
dtr
,
&
longitude
[
i
],
&
latitude
[
i
]);
longitude
[
i
]
/=
dtr
;
latitude
[
i
]
/=
dtr
;
}
return
0
;
}
///////////////////////////////////////////////////////
int
CAT
::
read
(
char
*
directory
,
char
*
filename
)
//AWS20060110
{
char
infile
[
500
];
char
err_text
[
100
];
char
comment
[
100
];
fitsfile
*
fptr
;
int
status
;
int
hdunum
,
hdutype
,
total_hdus
,
colnum
;
int
n_columns
,
n_rows
;
double
nulval
=
0.
;
int
anynul
=
0
;
char
nulstr
[
100
];
strcpy
(
nulstr
,
"null"
);
double
dtr
=
acos
(
-
1.0
)
/
180.
;
int
i
,
j
,
k
;
cout
<<
"CAT::read ("
<<
directory
<<
"/"
<<
filename
<<
")"
<<
endl
;
strcpy
(
infile
,
directory
);
strcat
(
infile
,
filename
);
cout
<<
"CAT::read infile= "
<<
infile
<<
endl
;
status
=
0
;
// needed
fits_open_file
(
&
fptr
,
infile
,
READONLY
,
&
status
)
;
cout
<<
"FITS read open status= "
<<
status
<<
" "
<<
infile
<<
endl
;
fits_get_errstatus
(
status
,
err_text
);
cout
<<
err_text
<<
endl
;
fits_get_num_hdus
(
fptr
,
&
total_hdus
,
&
status
);
cout
<<
"total number of header units="
<<
total_hdus
<<
endl
;
hdunum
=
total_hdus
-
1
;
// because spimodfit output has also grouping extension, make it thus more general assuming catalogue is last extension
fits_movabs_hdu
(
fptr
,
hdunum
+
1
,
&
hdutype
,
&
status
);
cout
<<
"FITS movabs_hdu hdunum="
<<
hdunum
<<
" status= "
<<
status
<<
" hdutype="
<<
hdutype
<<
endl
;
fits_read_key
(
fptr
,
TLONG
,
"TFIELDS"
,
&
n_columns
,
comment
,
&
status
);
cout
<<
" n_columns ="
<<
n_columns
;
fits_read_key
(
fptr
,
TLONG
,
"NAXIS2"
,
&
n_rows
,
comment
,
&
status
);
cout
<<
" n_rows ="
<<
n_rows
<<
endl
;
n_sources
=
n_rows
;
ra
=
new
double
[
n_rows
];
dec
=
new
double
[
n_rows
];
flux
=
new
double
[
n_rows
];