From 4ea7a05ea9a7352602f1f48a860fd81c36e8bc04 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 20 Feb 2017 12:26:17 +0800 Subject: Rename mass_profile to src; Add install & uninstall to Makefile --- src/fit_nfw_mass.cpp | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 src/fit_nfw_mass.cpp (limited to 'src/fit_nfw_mass.cpp') diff --git a/src/fit_nfw_mass.cpp b/src/fit_nfw_mass.cpp new file mode 100644 index 0000000..fae74ef --- /dev/null +++ b/src/fit_nfw_mass.cpp @@ -0,0 +1,159 @@ +/* + Fitting nfw mass profile model + Author: Junhua Gu + Last modification 20120721 +*/ + +#include "nfw.hpp" +#include +#include +#include +#include "chisq.hpp" +#include +#include +#include +#include +#include + +using namespace opt_utilities; +using namespace std; +const double cm=1; +const double kpc=3.08568e+21*cm; +const double pi=4*atan(1); +static double calc_critical_density(double z, + const double H0=2.3E-18, + const double Omega_m=.27) +{ + const double G=6.673E-8;//cm^3 g^-1 s^2 + const double E=std::sqrt(Omega_m*(1+z)*(1+z)*(1+z)+1-Omega_m); + const double H=H0*E; + return 3*H*H/8/pi/G; +} + + +int main(int argc,char* argv[]) +{ + if(argc<3) + { + cerr<<"Usage:"< [rmin in kpc]"<=4) + { + rmin_kpc=atof(argv[3]); + } + double z=0; + z=atof(argv[2]); + //define the fitter + fitter,double,std::string> fit; + //define the data set + default_data_set ds; + //open the data file + ifstream ifs(argv[1]); + //cout<<"read serr 2"<>r>>re>>m>>me; + if(!ifs.good()) + { + break; + } + if(r d(r,m,me,me,re,re); + ofs_fit_result< >()); + //use chi^2 statistic + fit.set_statistic(chisq,double,std::string>()); + fit.set_model(nfw()); + //fit.set_param_value("rs",4); + //fit.set_param_value("rho0",100); + fit.fit(); + fit.fit(); + vector p=fit.fit(); + //output parameters + ofstream ofs_param("nfw_param.txt"); + for(size_t i=0;i d=ds.get_data(i); + double x=d.get_x(); + double y=d.get_y(); + double ye=d.get_y_lower_err(); + double ym=fit.eval_model(x,p); + ofs_fit_result<