- Timestamp:
- Nov 14, 2007, 7:25:34 PM (18 years ago)
- Location:
- trunk/Cosmo/SimLSS
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cmvfitpk.cc
r3380 r3381 23 23 using namespace ROOT::Minuit2; 24 24 25 #include "Minuit2/FCNBase.h"26 25 namespace ROOT { namespace Minuit2 { 27 26 class MyFCN : public FCNBase { 28 27 public: 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; 31 32 double Up(void) const {return 1.;} 32 33 private: 33 34 HistoErr& herr_; 34 GenericFunc& pk_;35 PkSpectrumZ& pk_; 35 36 }; 36 37 } } // namespace ROOT + Minuit2 … … 59 60 double klim[2]={0.,-1.}; 60 61 string fconc = ""; 62 63 // --- les options de print/plot 64 int nprint = 3, nplot = -1; // -1 = all 61 65 62 66 // --- Reading arguments … … 84 88 double ocdm0 = om0-ob0; 85 89 TransfertEisenstein tf(h100,ocdm0,ob0,T_CMB_Par,nobaryon); 86 GrowthFactor growth(om0,ol0); 90 GrowthFactor growth(om0,ol0); cout<<"...Growth="<<growth(zref)<<endl; 87 91 PkSpectrum0 pk0(pkini,tf); 88 92 PkSpectrumZ pkz(pk0,growth,zref); … … 125 129 126 130 // --- NTuple et ppf 131 const int npar = 7; // Number of parameters in the fit 132 TMatrix<r_8> Cov(npar,npar); Cov = 0.; 127 133 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 }; 130 140 NTuple nt(nvar,vname); 131 141 double xnt[nvar]; … … 134 144 // --- Boucle sur les fichiers a fitter 135 145 // *** 136 int nfile =0;146 int nfile=0, ncov=0; 137 147 for(int ifile=optind;ifile<narg;ifile++) { 138 148 … … 158 168 // --- Initialisation de minuit 159 169 MnUserParameters upar; 160 const int npar = 2;170 upar.Add("B",b_ini,b_ini/100.); 161 171 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"); 163 182 MyFCN fcn(herr,pkz); 164 183 if(nbinok<upar.VariableParameters()) { … … 178 197 179 198 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 } 180 209 181 210 // --- Recuperation des informations et remplissage NTuple 182 211 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);186 212 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]; 192 215 nt.Fill(xnt); 193 216 194 // --- stoquage des histos 195 if(nfile< 10) {217 // --- stoquage des histos de plots 218 if(nfile<nplot || nplot<0) { 196 219 HistoErr herrf(herr); herrf.Zero(); 197 220 HistoErr herrd(herr); herrd.Zero(); 221 fcn.Init(parfit); 198 222 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); 200 224 herrf.SetBin(i,f,herr.Error(i),1.); 201 225 herrd.SetBin(i,herr(i)-f,herr.Error(i),1.); … … 208 232 209 233 // --- Print de debug 210 if(nfile< 3) {234 if(nfile<nprint) { 211 235 cout<<"minimum: "<<min<<endl; 212 236 for(int i=0;i<nvar;i++) cout<<"["<<i<<"] = "<<xnt[i]<<endl; … … 225 249 226 250 // --- 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");} 228 253 229 254 return 0; … … 231 256 232 257 //-------------------------------------------------- 233 MyFCN::MyFCN(HistoErr& herr, GenericFunc& pk)258 MyFCN::MyFCN(HistoErr& herr,PkSpectrumZ& pk) 234 259 : herr_(herr) , pk_(pk) 235 260 { 236 261 } 237 262 238 double MyFCN::operator()(const std::vector<double>& par) const 239 { 263 void 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 272 double 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 279 double MyFCN::operator()(const vector<double>& par) const 280 { 281 Init(par); 240 282 double xi2 = 0.; 241 283 for(int i=0;i<herr_.NBins();i++) { … … 244 286 double x = herr_.BinCenter(i); 245 287 double v = herr_(i); 246 double f = par[0]*pk_(x) + par[1];288 double f = Func(x,par); 247 289 xi2 += (v-f)*(v-f)/e2; 248 290 } … … 252 294 /* 253 295 openppf cmvfitpk.ppf 296 297 print nt 254 298 255 299 set i 0 … … 270 314 n/plot nt.b%a ! ! "crossmarker5" 271 315 316 n/plot nt.oc 317 n/plot nt.ob 318 n/plot nt.oc+ob 319 n/plot nt.ob%oc ! ! "crossmarker5" 320 272 321 n/plot nt.ea 273 322 n/plot nt.eb 274 323 n/plot nt.ea%eb ! ! "crossmarker5" 275 324 325 disp cov "zoomx30" 326 del cor 327 c++exec \ 328 TMatrix<r_8> cor(cov,false); cor = 0.; \ 329 for(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 } } \ 335 KeepObj(cor); \ 336 cout<<"Matrice cor cree "<<endl; 337 338 disp cor "zoomx30" 339 276 340 */ -
trunk/Cosmo/SimLSS/pkspectrum.cc
r3378 r3381 31 31 InitialSpectrum::~InitialSpectrum(void) 32 32 { 33 }34 35 void InitialSpectrum::SetNorm(double a)36 {37 A_ = a;38 }39 40 void InitialSpectrum::SetSlope(double n)41 {42 n_ = n;43 33 } 44 34 … … 177 167 } 178 168 179 bool TransfertEisenstein::SetParTo(double h100,double OmegaCDM0,double OmegaBaryon0 ,double tcmb,bool nobaryon)169 bool TransfertEisenstein::SetParTo(double h100,double OmegaCDM0,double OmegaBaryon0) 180 170 // Changement des valeurs des parametres (suivi de re-init eventuel) 171 // Si h100,Omega...<=0. alors pas de changement, on garde l'ancienne valeur 181 172 { 182 173 bool haschanged = false; … … 185 176 if(OmegaCDM0>0.) {Oc_ = OmegaCDM0; haschanged = true;} 186 177 if(OmegaBaryon0>0.) {Ob_ = OmegaBaryon0; haschanged = true;} 187 if(tcmb>0.) {tcmb_ = tcmb; haschanged = true;}188 if(nobaryon!=nobaryon_) {nobaryon_ = nobaryon; haschanged = true;}189 178 190 179 // et on recalcule les initialisations … … 371 360 // Pour avoir D(z) = 1/(1+z) faire: OmegaMatter0=1 OmegaLambda0=0 372 361 GrowthFactor::GrowthFactor(double OmegaMatter0,double OmegaLambda0) 373 : O0_(OmegaMatter0) , Ol_(OmegaLambda0) , Ok_(1.-OmegaMatter0-OmegaLambda0)362 : O0_(OmegaMatter0) , Ol_(OmegaLambda0) 374 363 { 375 364 if(OmegaMatter0==0.) { … … 377 366 throw ParmError("GrowthFactor::GrowthFactor: Error badOmegaMatter0 value"); 378 367 } 379 norm_ = 1.; // puisque (*this)(0.) a besoin de norm_380 norm_ = (*this)(0.);381 cout<<"GrowthFactor::GrowthFactor : norm="<<norm_<<endl;382 368 } 383 369 384 370 GrowthFactor::GrowthFactor(GrowthFactor& d1) 385 : O0_(d1.O0_) , Ol_(d1.Ol_) , Ok_(d1.Ok_) , norm_(d1.norm_)371 : O0_(d1.O0_) , Ol_(d1.Ol_) 386 372 { 387 373 } … … 396 382 z += 1.; 397 383 double z2 = z*z, z3 = z2*z; 398 double den = Ol_ + Ok_*z2 + O0_*z3; 384 385 // Calcul de la normalisation (pour z=0 -> growth=1.) 386 double D1z0 = pow(O0_,4./7.) - Ol_ + (1.+O0_/2.)*(1.+Ol_/70.); 387 D1z0 = 2.5*O0_ / D1z0; 388 389 // Calcul du growthfactor pour z 390 double Ok = 1. - O0_ - Ol_; 391 double den = Ol_ + Ok*z2 + O0_*z3; 399 392 double o0z = O0_ *z3 / den; 400 393 double olz = Ol_ / den; 401 394 402 // 4./7. = 0.571429 403 double D1z = pow(o0z,0.571429) - olz + (1.+o0z/2.)*(1.+olz/70.); 395 double D1z = pow(o0z,4./7.) - olz + (1.+o0z/2.)*(1.+olz/70.); 404 396 D1z = 2.5*o0z / z / D1z; 405 397 406 return D1z / norm_; 407 } 408 409 bool GrowthFactor::SetParTo(double OmegaMatter0,double OmegaLambda0) 410 { 411 bool haschanged = false; 412 413 if(OmegaMatter0>0.) {O0_ = OmegaMatter0; haschanged = true;} 414 if(fabs(OmegaLambda0+12345.)>1e-6) {Ol_ = OmegaLambda0; haschanged = true;} 415 416 // et on recalcule les initialisations 417 if(haschanged) { 418 Ok_ = 1. - O0_ - Ol_; 419 norm_ = 1.; // puisque (*this)(0.) a besoin de norm_ 420 norm_ = (*this)(0.); 421 } 422 423 return haschanged; 398 return D1z / D1z0; 399 } 400 401 void GrowthFactor::SetParTo(double OmegaMatter0,double OmegaLambda0) 402 { 403 if(OmegaMatter0>0.) O0_ = OmegaMatter0; 404 Ol_ = OmegaLambda0; 405 } 406 407 bool GrowthFactor::SetParTo(double OmegaMatter0) 408 // idem precedent sans changer OmegaLambda0 409 { 410 if(OmegaMatter0<=0.) return false; 411 O0_ = OmegaMatter0; 412 return true; 424 413 } 425 414 … … 453 442 PkSpectrumZ::PkSpectrumZ(PkSpectrum0& pk0,GrowthFactor& d1,double zref) 454 443 : pk0_(pk0) , d1_(d1) , zref_(zref) , scale_(1.) , typspec_(PK) 455 , zold_(-1.) , d1old_(1.)456 444 { 457 445 } … … 459 447 PkSpectrumZ::PkSpectrumZ(PkSpectrumZ& pkz) 460 448 : pk0_(pkz.pk0_) , d1_(pkz.d1_) , zref_(pkz.zref_) , scale_(pkz.scale_) , typspec_(PK) 461 , zold_(pkz.zold_) , d1old_(pkz.d1old_)462 449 { 463 450 } … … 481 468 double PkSpectrumZ::operator() (double k,double z) 482 469 { 483 double d1; 484 if(z == zold_) d1 = d1old_; 485 else {d1 = d1old_ = d1_(z); zold_ = z;} 470 double d1 = d1_(z); 486 471 487 472 double v = pk0_(k) * d1*d1; -
trunk/Cosmo/SimLSS/pkspectrum.h
r3378 r3381 14 14 virtual ~InitialSpectrum(void); 15 15 virtual double operator() (double k) {return A_ * pow(k,n_);} 16 void SetNorm(double a) ;17 void SetSlope(double n) ;16 void SetNorm(double a) {A_ = a;} 17 void SetSlope(double n) {n_ = n;} 18 18 protected: 19 19 double n_, A_; … … 29 29 TransfertEisenstein(TransfertEisenstein& tf); 30 30 virtual ~TransfertEisenstein(void); 31 bool SetParTo(double h100 =-1.,double OmegaCDM0=-1.,double OmegaBaryon0=-1.,double tcmb=-1.,bool nobaryon=false);31 bool SetParTo(double h100,double OmegaCDM0,double OmegaBaryon0); 32 32 virtual double operator() (double k); 33 33 double KPeak(void); … … 77 77 virtual ~GrowthFactor(void); 78 78 virtual double operator() (double z); 79 bool SetParTo(double OmegaMatter0=-1.,double OmegaLambda0=-12345.); 79 void SetParTo(double OmegaMatter0,double OmegaLambda0); 80 bool SetParTo(double OmegaMatter0); 80 81 protected: 81 double O0_,Ol_,Ok_; 82 double norm_; 82 double O0_,Ol_; 83 83 }; 84 84 … … 107 107 virtual double operator() (double k); 108 108 virtual double operator() (double k,double z); 109 inlinevoid SetZ(double z) {zref_ = z;}110 inlinedouble GetZ(void) {return zref_;}109 void SetZ(double z) {zref_ = z;} 110 double GetZ(void) {return zref_;} 111 111 void SetTypSpec(ReturnSpectrum typspec=PK); 112 inline void SetScale(double scale=1.) {scale_=scale; zold_=-1.;}113 inlinedouble GetScale(void) {return scale_;}112 void SetScale(double scale=1.) {scale_=scale;} 113 double GetScale(void) {return scale_;} 114 114 PkSpectrum0& GetPk0(void) {return pk0_;} 115 115 GrowthFactor& GetGrowthFactor(void) {return d1_;} … … 119 119 double zref_, scale_; 120 120 ReturnSpectrum typspec_; 121 mutable double zold_, d1old_;122 121 }; 123 122
Note:
See TracChangeset
for help on using the changeset viewer.