- Timestamp:
- May 4, 2011, 7:13:16 PM (14 years ago)
- Location:
- trunk/Cosmo/SimLSS
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cmvgsm2cube.cc
r3790 r3983 11 11 #include "skymap.h" 12 12 13 // set fname = ( `cat gsm820948.list | awk '{print $3}' | sed 's/data/ppf/'` ) 14 // cmvgsm2cube -o gsm820948_cube.ppf -p 360,0.1666667,160. -t 360,0.1666667,30. $fname 13 // set rname = gsm820948 14 // set fname = ( `cat ${rname}.list | awk '{print $3}' | sed 's/data/ppf/'` ) 15 // cmvgsm2cube -o ${rname}_cube.ppf -p 360,0.1666667,160. -t 360,0.1666667,30. $fname 15 16 16 17 void usage(void) … … 19 20 <<"cmvgsm2cube [options] liste_des_spheres_healpix"<<endl 20 21 <<" -o outname.ppf : ppf cube output file name (def=cmvgsm2cube.ppf)"<<endl 21 <<" -p nphi,dphi,phi0 : phi0 -> phi0 +nphi*dphi (degres)"<<endl22 <<" -t ntheta,dtheta,theta0 : theta0 -> theta0 +ntheta*dtheta (degres)"<<endl22 <<" -p nphi,dphi,phi0 : phi0 -> phi0 + nphi*dphi (degres)"<<endl 23 <<" -t ntheta,dtheta,theta0 : theta0 -> theta0 + ntheta*dtheta (degres)"<<endl 23 24 <<endl; 24 25 } … … 66 67 cout<<"Number of spheres "<<sphname.size()<<endl; 67 68 68 TArray<r_4> Cube(sphname.size(),nphi,ntheta); 69 Cube = 0.; 69 TVector<r_4> Theta(ntheta); 70 int nthgood = 0; 71 float thmin = 1.e30, thmax = -1.e30; 72 for(int it=0;it<ntheta;it++) { 73 Theta(it) = -9999.; 74 double t = theta0 + it*dtheta; t *= M_PI/180.; 75 if(t<0. || t>M_PI) continue; // [0,Pi] 76 Theta(it) = t; 77 nthgood += 1; 78 if(t<thmin) thmin = t; 79 if(t>thmax) thmax = t; 80 } 81 cout<<"Theta: ngood="<<nthgood<<" ["<<thmin*180/M_PI<<","<<thmax*180/M_PI 82 <<"] middle="<<0.5*(thmin+thmax)*180/M_PI<<endl; 83 84 TVector<r_4> Phi(nphi); 85 float phmin = 1.e30, phmax = -1.e30; 86 for(int ip=0;ip<nphi;ip++) { 87 double p = phi0 + ip*dphi; p *= M_PI/180.; 88 while(p<0.) p += 2.*M_PI; 89 while(p>=2.*M_PI) p -= 2.*M_PI; 90 Phi(ip) = p; 91 if(p<phmin) phmin = p; 92 if(p>phmax) phmax = p; 93 } 94 cout<<"Phi: ["<<phmin*180/M_PI<<","<<phmax*180/M_PI 95 <<"] middle="<<0.5*(phmin+phmax)*180/M_PI<<endl; 96 97 98 TVector<r_4> Freq(sphname.size()); Freq = -1.; 99 TArray<r_4> Cube(sphname.size(),nphi,ntheta); Cube = 0.; 70 100 for(unsigned int is=0;is<sphname.size();is++) { 71 72 101 cout<<"... "<<sphname[is]<<endl; 73 102 PInPersist pis(sphname[is]); 74 103 SphereHEALPix<r_4> sph; 75 104 pis>>PPFNameTag("sph")>>sph; 76 77 for(int it=0;it<ntheta;it++) { 78 double t = theta0 + it*dtheta; t *= M_PI/180.; 79 if(t<0. || t>M_PI) continue; 80 for(int ip=0;ip<nphi;ip++) { 81 double p = phi0 + ip*dphi; p *= M_PI/180.; 82 while(p<0.) p += 2.*M_PI; 83 while(p>=2.*M_PI) p -= 2.*M_PI; 84 int_4 ksph = sph.PixIndexSph(t,p); 85 Cube(is,ip,it) = sph(ksph); 105 Freq(is) = (r_4)sph.Info()["FMHz"]; 106 for(int it=0;it<Theta.Size();it++) { 107 double t = Theta(it); 108 if(t<0.) continue; 109 for(int ip=0;ip<Phi.Size();ip++) { 110 double p = Phi(ip); 111 int_4 ksph = sph.PixIndexSph(t,p); 112 Cube(is,ip,it) = sph(ksph); 113 } 86 114 } 87 }88 89 115 } 90 116 91 117 POutPersist pos(ppfrn); 92 118 pos<<PPFNameTag("cube")<<Cube; 119 pos<<PPFNameTag("theta")<<Theta; 120 pos<<PPFNameTag("phi")<<Phi; 121 pos<<PPFNameTag("freq")<<Freq; 93 122 94 123 return 0; … … 100 129 print cube 101 130 131 n/plot phi.val*180./M_PI%n ! ! "cpts" 132 n/plot theta.val*180./M_PI%n ! ! "cpts" 133 disp freq 134 102 135 objaoper cube sliceyz 0 103 136 objaoper cube sliceyz 128 -
trunk/Cosmo/SimLSS/cmvgsmcfit.cc
r3790 r3983 24 24 class MyFCN : public FCNBase { 25 25 public: 26 MyFCN( double nu0,double dnu,TVector<r_8>& V,TVector<r_8>& EV);26 MyFCN(TVector<r_4>& FreqMHz,TVector<r_4>& V,TVector<r_4>& EV); 27 27 void InitFit(MnUserParameters& upar); 28 double Func( int ix,const vector<double>& par) const;28 double Func(double fr,const vector<double>& par) const; 29 29 double operator()(const vector<double>& par) const; 30 30 double Up(void) const {return 1.;} 31 void SetNu0(double nu0Mhz) {_nu0 = nu0Mhz;} 31 32 //protected: 33 double _nu0; 32 34 mutable int _ndata; 33 double _nu0, _dnu;34 TVector<r_ 8> _V;35 TVector<r_ 8> _EV;35 TVector<r_4> _F; 36 TVector<r_4> _V; 37 TVector<r_4> _EV; 36 38 }; 37 39 } } // namespace ROOT + Minuit2 … … 40 42 int main(int narg,char *arg[]) 41 43 { 42 double nu0 = 820.0, dnu = 0.5; // MHz44 int nslicemax = -1; 43 45 if(narg<=1) { 44 cout<<"cmvgsmcfit cubefile.ppf "<<endl;46 cout<<"cmvgsmcfit cubefile.ppf [nslicemax]"<<endl; 45 47 return -1; 46 48 } 49 50 if(narg>2) nslicemax = atoi(arg[2]); 51 cout<<"Fitting "<<arg[1]<<" , nslicemax="<<nslicemax<<endl; 52 53 int rc = 0; 54 try { 47 55 48 56 POutPersist pos("cmvgsmcfit.ppf"); … … 50 58 TArray<r_4> Cube; 51 59 pis>>PPFNameTag("cube")>>Cube; 52 TVector<r_8> V(Cube.SizeX()), EV(Cube.SizeX()); 53 54 const int nvar = 6; 55 const char *vname[nvar] = {"x2r","ok","ph","th","A","N"}; 60 TVector<r_4> Freq; 61 pis>>PPFNameTag("freq")>>Freq; 62 63 const int nvar = 8; 64 const char *vname[nvar] = {"x2r","ok","ph","th","v0","vn","A","N"}; 56 65 NTuple nt(nvar,vname); 57 66 double xnt[nvar]; for(int i=0;i<nvar;i++) xnt[i] = 0.; … … 59 68 int nfit = 0; 60 69 for(int j=0;j<Cube.SizeY();j++) { 61 cout<<"... "<<j<<endl;70 cout<<"...j = "<<j<<endl; 62 71 for(int k=0;k<Cube.SizeZ();k++) { 72 73 TVector<r_4> V(Cube.SizeX()), EV(Cube.SizeX()); 63 74 for(int i=0;i<Cube.SizeX();i++) { 64 75 V(i) = Cube(i,j,k); … … 66 77 } 67 78 68 MyFCN myfcn(nu0,dnu,V,EV); 79 MyFCN myfcn(Freq,V,EV); 80 myfcn.SetNu0(Freq(0)); 69 81 MnUserParameters upar; 70 82 myfcn.InitFit(upar); … … 89 101 xnt[0] = xi2r; xnt[1] = (okfit)? 1.: 0.; 90 102 xnt[2] = j; xnt[3] = k; 91 for(unsigned int i=0;i<par.size();i++) xnt[4+i] = par[i]; 103 xnt[4] = V(0); xnt[5] = V(V.Size()-1); 104 for(unsigned int i=0;i<par.size();i++) xnt[6+i] = par[i]; 92 105 nt.Fill(xnt); 93 106 //vector<double> err = ustate.Errors(); 94 for(int i=0;i<Cube.SizeX();i++) Cube(i,j,k) -= myfcn.Func( i,par);107 for(int i=0;i<Cube.SizeX();i++) Cube(i,j,k) -= myfcn.Func(Freq(i),par); 95 108 96 109 if(nfit<10) { 97 110 TVector<r_8> F(Cube.SizeX()), R(Cube.SizeX()); 98 111 for(int i=0;i<Cube.SizeX();i++) { 99 F(i) = myfcn.Func( i,par);112 F(i) = myfcn.Func(Freq(i),par); 100 113 R(i) = V(i) - F(i); 101 114 } … … 108 121 pos<<PPFNameTag(str)<<R; 109 122 } 123 110 124 nfit++; 111 if(nfit>10) break; 125 112 126 } 127 if(nslicemax>0 && j>=nslicemax) break; 113 128 } 114 129 130 cout<<"nfit = "<<nfit<<endl; 115 131 pos<<PPFNameTag("nt")<<nt; 116 132 pos<<PPFNameTag("cublis")<<Cube; 117 133 134 //----------------------------------------------------------------- 135 } catch (PException& exc) { 136 cerr<<"cmvgsmcfit.cc catched PException"<<exc.Msg()<<endl; 137 rc = 77; 138 } catch (std::exception& sex) { 139 cerr << "cmvgsmcfit.cc std::exception :" 140 << (string)typeid(sex).name() << "\n msg= " << sex.what() << endl; 141 rc = 78; 142 } catch (...) { 143 cerr << "cmvgsmcfit.cc catched unknown (...) exception " << endl; 144 rc = 79; 145 } 146 147 return rc; 118 148 } 119 149 120 150 //-------------------------------------------------- 121 MyFCN::MyFCN(double nu0, double dnu,TVector<r_8>& V,TVector<r_8>& EV) 122 : _V(V,false), _EV(EV,false) 123 { 151 MyFCN::MyFCN(TVector<r_4>& FreqMHz,TVector<r_4>& V,TVector<r_4>& EV) 152 : _F(FreqMHz,false), _V(V,false), _EV(EV,false) 153 { 154 if(_F.Size()==0 || _F.Size()!=_V.Size() || _F.Size()!=_EV.Size()) 155 throw SzMismatchError("MyFCN::MyFCN_Error: incompatible F / V / EV sizes"); 156 _nu0 = _F(0); 124 157 _ndata =_V.Size(); 125 _nu0 = nu0;126 _dnu = dnu;127 158 } 128 159 129 160 void MyFCN::InitFit(MnUserParameters& upar) 130 161 { 131 int n = _ V.Size()-1;162 int n = _F.Size() - 1; 132 163 double a = _V(0); 133 double ni = log(_V(n)/a) / log( 1.+n*_dnu/_nu0);164 double ni = log(_V(n)/a) / log(_F(n)/_nu0); 134 165 135 166 upar.Add("A",a,a/50.); … … 137 168 } 138 169 139 double MyFCN::Func(int ix,const vector<double>& par) const 140 // f = A*(nu/nu0)^N avec nu = nu0 + i*dnu 141 { 142 double x = (_nu0 + ix*_dnu)/_nu0; 143 double f = par[0]*pow(x,par[1]); 170 double MyFCN::Func(double fr,const vector<double>& par) const 171 // v = A*(nu/nu0)^N 172 { 173 double f = par[0]*pow(fr/_nu0,par[1]); 144 174 return f; 145 175 } … … 153 183 if(e2<=0.) continue; 154 184 double v = _V(i); 155 double f = Func( i,par);185 double f = Func(_F(i),par); 156 186 xi2 += (v-f)*(v-f)/e2; 157 187 _ndata++; … … 166 196 set j 0 167 197 set k 0 198 zone 1 2 168 199 n/plot v_${j}_${k}.val%n ! ! "nsta cpts" 169 200 n/plot f_${j}_${k}.val%n ! ! "nsta cpts same red" 170 201 n/plot r_${j}_${k}.val%n ! ! "nsta cpts" 171 202 172 n/plot nt.ok%_nl ! ! "cpts" 173 n/plot nt.x2r%_nl ! ! "cpts" 174 175 n/plot nt.A%_nl ! ! "cpts" 176 n/plot nt.N%_nl ! ! "cpts" 203 zone 1 2 204 n/plot nt.ok%_nl ! ! "crossmarker3" 205 n/plot nt.x2r%_nl ! ! "crossmarker3" 206 207 zone 1 2 208 n/plot nt.v0%_nl ! ! "crossmarker3" 209 n/plot nt.vn%_nl ! ! "plusmarker3 same red" 210 n/plot nt.log10(v0/vn)%v0 ! ! "crossmarker3" 211 212 213 zone 214 n/plot nt.A%_nl ! ! "crossmarker3" 215 n/plot nt.N%_nl ! ! "crossmarker3" 216 217 n/plot nt.A%v0 ! ! "crossmarker3" 218 n/plot nt.(A-v0)/v0%_nl ! ! "crossmarker3" 219 n/plot nt.N%A ! ! "crossmarker3" 177 220 178 221 set n 0
Note:
See TracChangeset
for help on using the changeset viewer.