Changeset 3381 in Sophya for trunk/Cosmo/SimLSS/cmvfitpk.cc


Ignore:
Timestamp:
Nov 14, 2007, 7:25:34 PM (18 years ago)
Author:
cmv
Message:

1-/ pkspectrum: GrowthFactor + PkSpectrum on enleve les memorisations

des calculs precedents, tout est recalcule

2-/ cmvfitpk: mise de Ob+Ol+Oc+h100+ns dans le fit

cmv 14/11/2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/SimLSS/cmvfitpk.cc

    r3380 r3381  
    2323using namespace ROOT::Minuit2;
    2424
    25 #include "Minuit2/FCNBase.h"
    2625namespace ROOT { namespace Minuit2 {
    2726class MyFCN : public FCNBase {
    2827public:
    29   MyFCN(HistoErr& herr,GenericFunc& pk);
    30   double operator()(const std::vector<double>& par) const;
     28  MyFCN(HistoErr& herr,PkSpectrumZ& pk);
     29  void Init(const vector<double>& par) const;
     30  double Func(double x,const vector<double>& par) const;
     31  double operator()(const vector<double>& par) const;
    3132  double Up(void) const {return 1.;}
    3233private:
    3334  HistoErr& herr_;
    34   GenericFunc& pk_;
     35  PkSpectrumZ& pk_;
    3536};
    3637} }  // namespace ROOT + Minuit2
     
    5960 double klim[2]={0.,-1.};
    6061 string fconc = "";
     62
     63 // --- les options de print/plot
     64 int nprint = 3, nplot = -1;  // -1 = all
    6165
    6266 // --- Reading arguments
     
    8488 double ocdm0 = om0-ob0;
    8589 TransfertEisenstein tf(h100,ocdm0,ob0,T_CMB_Par,nobaryon);
    86  GrowthFactor growth(om0,ol0);
     90 GrowthFactor growth(om0,ol0); cout<<"...Growth="<<growth(zref)<<endl;
    8791 PkSpectrum0 pk0(pkini,tf);
    8892 PkSpectrumZ pkz(pk0,growth,zref);
     
    125129
    126130 // --- NTuple et ppf
     131 const int npar = 7;  // Number of parameters in the fit
     132 TMatrix<r_8> Cov(npar,npar); Cov = 0.;
    127133 POutPersist pos("cmvfitpk.ppf");
    128  const int nvar = 6;
    129  char *vname[nvar] = {"xi2","a","b","ea","eb","eab"};
     134 const int nvar = 2*npar+1;
     135 char *vname[nvar] = {
     136       "xi2"
     137       ,"b","a","oc","ob","ol","h","n"
     138       ,"eb","ea","eoc","eob","eol","eh","en"
     139       };
    130140 NTuple nt(nvar,vname);
    131141 double xnt[nvar];
     
    134144 // --- Boucle sur les fichiers a fitter
    135145 // ***
    136  int nfile = 0;
     146 int nfile=0, ncov=0;
    137147 for(int ifile=optind;ifile<narg;ifile++) {
    138148
     
    158168   // --- Initialisation de minuit
    159169    MnUserParameters upar;
    160     const int npar = 2;
     170    upar.Add("B",b_ini,b_ini/100.);
    161171    upar.Add("A",1.,0.01);
    162     upar.Add("B",b_ini,b_ini/100.);
     172    upar.Add("Ocdm",ocdm0,0.001,ocdm0/2.,2.*ocdm0);
     173    //upar.Fix("Ocdm");
     174    upar.Add("Ob",ob0,0.001,ob0/10.,10.*ob0);
     175    //upar.Fix("Ob");
     176    upar.Add("Ol",ol0,0.001,0.1,2.);
     177    upar.Fix("Ol");
     178    upar.Add("h100",h100,0.01,10.,150.);
     179    upar.Fix("h100");
     180    upar.Add("ns",ns,0.001,0.7,1.5);
     181    upar.Fix("ns");
    163182    MyFCN fcn(herr,pkz);
    164183    if(nbinok<upar.VariableParameters()) {
     
    178197
    179198   MnUserParameterState ustate = min.UserState();
     199   double xi2r = ustate.Fval()/(nbinok-ustate.VariableParameters());
     200   vector<double> parfit  = ustate.Parameters().Params();
     201   vector<double> eparfit = ustate.Parameters().Errors();
     202   if(ustate.HasCovariance()) {
     203     MnUserCovariance ucov = ustate.Covariance();
     204     for(unsigned int i=0;i<upar.VariableParameters();i++)
     205       for(unsigned int j=0;j<upar.VariableParameters();j++)
     206         Cov(ustate.ExtOfInt(i),ustate.ExtOfInt(j)) += ucov(i,j);
     207     ncov++;
     208   }
    180209
    181210   // --- Recuperation des informations et remplissage NTuple
    182211   for(int i=0;i<nvar;i++) xnt[i] = 0.;
    183    double xi2r = ustate.Fval()/(nbinok-upar.VariableParameters());
    184    double A = ustate.Value((unsigned int)0);
    185    double B = ustate.Value((unsigned int)1);
    186212   xnt[0] = xi2r;
    187    xnt[1] = A;
    188    xnt[2] = B;
    189    xnt[3] = ustate.Error((unsigned int)0);
    190    xnt[4] = ustate.Error((unsigned int)1);
    191    if(ustate.HasCovariance()) xnt[5] = ustate.Covariance()(0,1);
     213   for(int i=0;i<npar;i++) xnt[1+i] = parfit[i];
     214   for(int i=0;i<npar;i++) xnt[npar+1+i] = eparfit[i];
    192215   nt.Fill(xnt);
    193216
    194    // --- stoquage des histos
    195    if(nfile<10) {
     217   // --- stoquage des histos de plots
     218   if(nfile<nplot || nplot<0) {
    196219     HistoErr herrf(herr); herrf.Zero();
    197220     HistoErr herrd(herr); herrd.Zero();
     221     fcn.Init(parfit);
    198222     for(int i=1;i<herr.NBins();i++) {
    199        double f = A*pkz(herr.BinCenter(i))+B;
     223       double f = fcn.Func(herr.BinCenter(i),parfit);
    200224       herrf.SetBin(i,f,herr.Error(i),1.);
    201225       herrd.SetBin(i,herr(i)-f,herr.Error(i),1.);
     
    208232
    209233   // --- Print de debug
    210    if(nfile<3) {
     234   if(nfile<nprint) {
    211235     cout<<"minimum: "<<min<<endl;
    212236     for(int i=0;i<nvar;i++) cout<<"["<<i<<"] = "<<xnt[i]<<endl;
     
    225249
    226250 // --- Fin du job
    227  if(nfile>1) pos.PutObject(nt,"nt");
     251 if(nfile>0) pos.PutObject(nt,"nt");
     252 if(ncov>0) {Cov /= (double)ncov; pos.PutObject(Cov,"cov");}
    228253
    229254 return 0;
     
    231256
    232257//--------------------------------------------------
    233 MyFCN::MyFCN(HistoErr& herr,GenericFunc& pk)
     258MyFCN::MyFCN(HistoErr& herr,PkSpectrumZ& pk)
    234259  : herr_(herr) , pk_(pk)
    235260{
    236261}
    237262
    238 double MyFCN::operator()(const std::vector<double>& par) const
    239 {
     263void MyFCN::Init(const vector<double>& par) const
     264{
     265 double A=par[1], Ocdm0=par[2], Ob0=par[3], Ol0=par[4], h100=par[5], ns=par[6];
     266 pk_.GetPk0().GetPkIni().SetSlope(ns);
     267 pk_.GetPk0().GetPkIni().SetNorm(A);
     268 pk_.GetPk0().GetTransfert().SetParTo(h100,Ocdm0,Ob0);
     269 pk_.GetGrowthFactor().SetParTo(Ocdm0+Ob0,Ol0);
     270}
     271
     272double MyFCN::Func(double x,const vector<double>& par) const
     273// par: [0]=B,  [1]=A,  [2]=Ocdm0,  [3]=Ob0,  [4]=Ol0, [5]=h100, [6]=npow
     274{
     275 Init(par);
     276 return pk_(x) + par[0];
     277}
     278
     279double MyFCN::operator()(const vector<double>& par) const
     280{
     281 Init(par);
    240282 double xi2 = 0.;
    241283 for(int i=0;i<herr_.NBins();i++) {
     
    244286   double x = herr_.BinCenter(i);
    245287   double v = herr_(i);
    246    double f = par[0]*pk_(x) + par[1];
     288   double f = Func(x,par);
    247289   xi2 += (v-f)*(v-f)/e2;
    248290 }
     
    252294/*
    253295openppf cmvfitpk.ppf
     296
     297print nt
    254298
    255299set i 0
     
    270314n/plot nt.b%a ! ! "crossmarker5"
    271315
     316n/plot nt.oc
     317n/plot nt.ob
     318n/plot nt.oc+ob
     319n/plot nt.ob%oc ! ! "crossmarker5"
     320
    272321n/plot nt.ea
    273322n/plot nt.eb
    274323n/plot nt.ea%eb ! ! "crossmarker5"
    275324
     325disp cov "zoomx30"
     326del cor
     327c++exec \
     328TMatrix<r_8> cor(cov,false); cor = 0.; \
     329for(int i=0;i<cor.NRows();i++) { \
     330  for(int j=0;j<cor.NCols();j++) { \
     331    double v = cov(i,i)*cov(j,j); \
     332    if(v<=0.) continue; \
     333    cor(i,j) = cov(i,j)/sqrt(v); \
     334} } \
     335KeepObj(cor); \
     336cout<<"Matrice cor cree "<<endl;
     337
     338disp cor "zoomx30"
     339
    276340 */
Note: See TracChangeset for help on using the changeset viewer.