Changeset 3320 in Sophya for trunk/Cosmo/SimLSS/cmvschdist.cc
- Timestamp:
- Sep 5, 2007, 9:58:05 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cmvschdist.cc
r3319 r3320 6 6 // ex: on a un pixel qui a N galaxies, quelle est la distribution 7 7 // statistique de masse dans un tel pixel ? 8 // > cmvschdist -a -v -m 1e+7,1e+14 -n 140 -r 200 -N 100000 8 // > cmvschdist -a -v -m 1e+8,1e+13 -n -100 -r 200 -N 100000 9 // compare with: 10 // > cmvschdist -a -v -m 1e+8,1e+13 -n -100 -r 200 -N 100000 -0 11 // Fabriquer un fichier 12 // > cmvschdist -a -m 1e+8,1e+13 -n -100 -r 2000 -N 5000000 -W schdist_2000.ppf 9 13 #include <iostream> 10 14 #include <stdlib.h> … … 28 32 void usage(void) 29 33 { 30 cout<<"cmvschdist -m xmin,xmax -a -n nbin -r ngmax,ngmin -N nalea"<<endl 31 <<" xmin,xmax : limites en masse"<<endl 32 <<" nbin : nombre de bins"<<endl 33 <<" ngmax,ngmin : distribution pour tirage de ngmin a ngmax galaxies"<<endl 34 <<" nalea : nombre de tirages aleatoires"<<endl 34 cout<<"cmvschdist -m xmin,xmax -a -0 -n nbin -r ngmax,ngmin -N nalea " 35 <<"-R readfile.ppf -W writefile.ppf"<<endl 36 <<" -m xmin,xmax : limites en masse"<<endl 37 <<" -n nbin : nombre de bins (si <0 alors nb par decade)"<<endl 38 <<" -r ngmax,ngmin : distribution pour tirage de ngmin a ngmax galaxies"<<endl 39 <<" -N nalea : nombre de tirages aleatoires"<<endl 35 40 <<" -v : back verification of random trials"<<endl 36 <<" -a : init auto de l\'aleatoire"<<endl; 41 <<" -0 : only use ngal=1 histogram"<<endl 42 <<" -a : init auto de l\'aleatoire"<<endl 43 <<" -R readfile.ppf : read SchechterMassDist from ppf file"<<endl; 37 44 } 38 45 … … 46 53 47 54 double xmin=1e8, xmax=1e13; 48 int npt = 100;55 int npt = -100; 49 56 int ngmax = 200, ngmin = 1; 57 bool useonly1 = false; 50 58 unsigned long long nalea = 10000; 51 59 bool verif = false; 60 bool readfrppf = false; 61 string namefrppf = ""; 62 string nametoppf = ""; 52 63 53 64 char c; 54 while((c = getopt(narg,arg,"h avm:N:n:r:")) != -1) {65 while((c = getopt(narg,arg,"h0avm:N:n:r:R:W:")) != -1) { 55 66 switch (c) { 56 67 case 'm' : … … 68 79 case 'n' : 69 80 sscanf(optarg,"%d",&npt); 70 if(npt<=0) npt = 100;81 if(npt<=0) npt = -100; 71 82 break; 72 83 case 'N' : … … 77 88 verif = true; 78 89 break; 90 case '0' : 91 useonly1 = true; 92 break; 93 case 'R' : 94 readfrppf = true; 95 namefrppf = optarg; 96 break; 97 case 'W' : 98 nametoppf = optarg; 99 break; 79 100 case 'a' : 80 101 Auto_Ini_Ranf(5); … … 86 107 } 87 108 88 double lnx1=log10(xmin), lnx2=log10(xmax) , dlnx = (lnx2-lnx1)/npt;89 cout<<"xmin="<<xmin<<" ("<<lnx1<<") xmax="<<xmax<<" ("<<lnx2<<") , dlnx="<<dlnx<<endl;109 double lnx1=log10(xmin), lnx2=log10(xmax); 110 cout<<"xmin="<<xmin<<" ("<<lnx1<<") xmax="<<xmax<<" ("<<lnx2<<")"<<endl; 90 111 cout<<"npt="<<npt<<", nalea="<<nalea<<endl; 91 cout<<" ngmin="<<ngmin<<" ngmax="<<ngmax<<endl;112 cout<<"useonly1="<<useonly1<<" ngmin="<<ngmin<<" ngmax="<<ngmax<<endl; 92 113 cout<<"verif="<<verif<<endl; 114 if(readfrppf) cout<<"SchechterMassDist will be read from file "<<namefrppf<<endl; 115 if(nametoppf.size()>0) cout<<"SchechterMassDist will be written to file "<<nametoppf<<endl; 93 116 94 117 … … 96 119 cout<<"> Schechter m*dn/dm nstar="<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl; 97 120 Schechter sch(nstar,mstar,alpha); 98 sch.SetOutValue(1); // on veut m*dN/dm 99 Histo hmdndm(lnx1,lnx2,npt); hmdndm.ReCenterBin(); 100 FuncToHisto(sch,hmdndm,true); 101 FunRan tirhmdndm = FunRan(hmdndm,true); 102 103 //------- Construct histo 104 int nbhist = ngmax-ngmin+1; 105 cout<<"> Creating "<<nbhist<<" histos"<<endl; 106 vector<Histo> vhisto; vector<string> vhname; 107 for(int i=ngmin;i<=ngmax;i++) { 108 Histo h(hmdndm); h.Zero(); 109 vhisto.push_back(h); 110 char str[32]; sprintf(str,"h%d",i); 111 vhname.push_back(string(str)); 112 } 121 122 //------- Construct Mass Distribution 123 cout<<"> Creating Mass Distribution"<<endl; 124 SchechterMassDist schdmass(sch,xmin,xmax,npt); 125 if(readfrppf) { 126 cout<<"> Mass Distribution read from "<<namefrppf<<endl; 127 schdmass.ReadPPF(namefrppf); 128 } 129 Histo hmdndm = schdmass.GetHmDnDm(); 130 FunRan tirhmdndm = schdmass.GetTmDnDm(); 113 131 114 132 //------- Random 115 133 InitTim(); 116 cout<<"> Random: "<<nalea<<" trials"<<endl; 117 int lpmod = nalea/25; if(lpmod<=0) lpmod=1; 118 double bigsum = 0.; long nbigsum=0; 119 for(unsigned long long ia=0;ia<nalea;ia++) { 120 if(ia%lpmod==0) cout<<"... "<<ia<<endl; 121 double sum = 0.; 122 for(int i=1;i<=ngmax;i++) { 123 //double l10m = tirhmdndm.Random(); 124 double l10m = tirhmdndm.RandomInterp(); 125 double m = pow(10.,l10m); 126 sum += m; 127 bigsum += m; nbigsum++; 128 int ipo = i-ngmin; 129 if(ipo<0) continue; 130 double v = log10(sum/(double)i); 131 vhisto[ipo].Add(v); 132 } 133 if(ia%lpmod==0) PrtTim(" "); 134 } 135 PrtTim("End Random loop"); 136 if(nbigsum>0) { 137 bigsum /= (double)nbigsum; 138 cout<<"Mean mass : "<<bigsum<<" ("<<log10(fabs(bigsum))<<")"<<endl; 139 } 140 141 //------- Generation des classes de tirage aleatoire et des histos de verif 142 vector<FunRan> vtir; vector<string> vtname; 143 vector<Histo> vthisto; vector<string> vthname; 134 if(!useonly1 && !readfrppf) { 135 cout<<"> Creating "<<ngmax-ngmin+1<<" histos and filling with "<<nalea<<" trials"<<endl; 136 schdmass.SetNgalLim(ngmax,ngmin,nalea); 137 PrtTim("End of filling histos for trials"); 138 } 139 schdmass.Print(); 140 141 //------- Generation des histos de verif 142 vector<Histo> vthisto; vector<string> vthname; 144 143 if(verif) { 145 cout<<"> Creating "<<n bhist<<" FunRan andHistos for back-verif"<<endl;144 cout<<"> Creating "<<ngmax-ngmin+1<<" Histos for back-verif"<<endl; 146 145 for(int i=ngmin;i<=ngmax;i++) { 147 FunRan t(vhisto[i-ngmin],true); 148 vtir.push_back(t); 149 char str[32]; sprintf(str,"t%d",i); 150 vtname.push_back(string(str)); 151 Histo h(vhisto[i-ngmin]); h.Zero(); 146 Histo h(hmdndm); h.Zero(); 152 147 vthisto.push_back(h); 153 sprintf(str,"th%d",i);148 char str[32]; sprintf(str,"th%d",i); 154 149 vthname.push_back(string(str)); 155 150 } 151 cout<<" "<<vthisto.size()<<" Histos created"<<endl; 152 vthisto[20].Show(); 156 153 157 154 cout<<"> Checking tirage"<<endl; 155 int lpmod = nalea/20; if(lpmod<=0) lpmod=1; 158 156 for(unsigned long long ia=0;ia<nalea;ia++) { 159 for(unsigned int i=0;i<vtir.size();i++) { 160 //double v = vtir[i].Random(); 161 double v = vtir[i].RandomInterp(); 162 vthisto[i].Add(v); 157 if(ia%lpmod==0) cout<<"...filling tirage "<<ia<<endl; 158 for(unsigned int i=0;i<vthisto.size();i++) { 159 int ng = ngmin+i; 160 double v = schdmass.TirMass(ng)/(double)ng; 161 vthisto[i].Add(log10(v)); 163 162 } 164 163 } 164 schdmass.PrintStatus(); 165 165 PrtTim("End Random loop back-tirage"); 166 166 } 167 167 168 //------- Ecriture ppf 169 cout<<"Ecriture"<<endl; 168 //------- Ecritures ppf 169 if(nametoppf.size()>0) { 170 cout<<"Ecriture de l\'objet SchechterMassDist dans "<<nametoppf<<endl; 171 schdmass.WritePPF(nametoppf); 172 } 173 174 cout<<"Ecriture pour verification"<<endl; 170 175 string tag = "cmvschdist.ppf"; 171 176 POutPersist pos(tag); 177 { 178 cout<<" writing hmdndm tirhmdndm"<<endl; 172 179 tag = "hmdndm"; pos.PutObject(hmdndm,tag); 173 Histo hdum2(tirhmdndm); 174 tag = "tirhmdndm"; pos.PutObject(hdum2,tag); 175 if(vhisto.size()>0) 176 for(unsigned int i=0;i<vhisto.size();i++) 177 if(vhisto[i].NEntries()>0) pos.PutObject(vhisto[i],vhname[i]); 178 if(vthisto.size()>0) 179 for(unsigned int i=0;i<vthisto.size();i++) 180 Histo hdum(tirhmdndm); 181 tag = "tirhmdndm"; pos.PutObject(hdum,tag); 182 } 183 if(schdmass.GetNgalLim()>0) { 184 cout<<" writing h t"<<endl; 185 for(int i=0;i<schdmass.GetNgalLim();i++) { 186 int ng = schdmass.NGalFrIndex(i); 187 if(ng<=0) continue; 188 char str[32]; 189 sprintf(str,"h%d",ng); 190 Histo hdum = schdmass.GetHisto(i); 191 tag = str; pos.PutObject(hdum,tag); 192 sprintf(str,"t%d",ng); 193 Histo hdum2(schdmass.GetFunRan(i)); 194 tag = str; pos.PutObject(hdum2,tag); 195 } 196 } 197 if(vthisto.size()>0) { 198 cout<<" writing th"<<endl; 199 for(unsigned int i=0;i<vthisto.size();i++) 180 200 if(vthisto[i].NEntries()>0) pos.PutObject(vthisto[i],vthname[i]); 201 } 202 203 PrtTim("End of Job"); 181 204 182 205 return 0; … … 191 214 192 215 set h h$n 216 set t t$n 193 217 set th th$n 218 219 disp tirhmdndm 220 disp $t "same red" 194 221 195 222 disp $h … … 201 228 n/plot $h.log10(val)%x val>0. ! "connectpoints" 202 229 n/plot $th.log10(val)%x val>0. ! "nsta connectpoints same red" 230 231 n/plot $h.val%pow(10.,x) ! ! "connectpoints" 232 n/plot $th.val%pow(10.,x) ! ! "nsta connectpoints same red" 203 233 204 234 c++exec \
Note:
See TracChangeset
for help on using the changeset viewer.