Changeset 3319 in Sophya for trunk/Cosmo/SimLSS/cmvschdist.cc
- Timestamp:
- Sep 3, 2007, 12:49:21 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cmvschdist.cc
r3284 r3319 2 2 #include "sopnamsp.h" 3 3 #include "machdefs.h" 4 // Pour faire les histogrammes des distributions de masses 5 // pour ntirages: 6 // ex: on a un pixel qui a N galaxies, quelle est la distribution 7 // statistique de masse dans un tel pixel ? 8 // > cmvschdist -a -v -m 1e+7,1e+14 -n 140 -r 200 -N 100000 4 9 #include <iostream> 5 10 #include <stdlib.h> … … 28 33 <<" ngmax,ngmin : distribution pour tirage de ngmin a ngmax galaxies"<<endl 29 34 <<" nalea : nombre de tirages aleatoires"<<endl 35 <<" -v : back verification of random trials"<<endl 30 36 <<" -a : init auto de l\'aleatoire"<<endl; 31 37 } … … 43 49 int ngmax = 200, ngmin = 1; 44 50 unsigned long long nalea = 10000; 51 bool verif = false; 45 52 46 53 char c; 47 while((c = getopt(narg,arg,"ha m:N:n:r:")) != -1) {54 while((c = getopt(narg,arg,"havm:N:n:r:")) != -1) { 48 55 switch (c) { 49 56 case 'm' : … … 67 74 if(nalea<=0) nalea=10000; 68 75 break; 76 case 'v' : 77 verif = true; 78 break; 69 79 case 'a' : 70 80 Auto_Ini_Ranf(5); … … 80 90 cout<<"npt="<<npt<<", nalea="<<nalea<<endl; 81 91 cout<<"ngmin="<<ngmin<<" ngmax="<<ngmax<<endl; 92 cout<<"verif="<<verif<<endl; 82 93 83 94 … … 85 96 cout<<"> Schechter m*dn/dm nstar="<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl; 86 97 Schechter sch(nstar,mstar,alpha); 87 sch.SetOutValue(1); 98 sch.SetOutValue(1); // on veut m*dN/dm 88 99 Histo hmdndm(lnx1,lnx2,npt); hmdndm.ReCenterBin(); 89 100 FuncToHisto(sch,hmdndm,true); … … 93 104 int nbhist = ngmax-ngmin+1; 94 105 cout<<"> Creating "<<nbhist<<" histos"<<endl; 95 vector<Histo *> vhisto; 96 vector<string> vhname; 106 vector<Histo> vhisto; vector<string> vhname; 97 107 for(int i=ngmin;i<=ngmax;i++) { 98 Histo * h = new Histo(hmdndm); h->Zero();108 Histo h(hmdndm); h.Zero(); 99 109 vhisto.push_back(h); 100 110 char str[32]; sprintf(str,"h%d",i); … … 106 116 cout<<"> Random: "<<nalea<<" trials"<<endl; 107 117 int lpmod = nalea/25; if(lpmod<=0) lpmod=1; 118 double bigsum = 0.; long nbigsum=0; 108 119 for(unsigned long long ia=0;ia<nalea;ia++) { 109 120 if(ia%lpmod==0) cout<<"... "<<ia<<endl; 110 121 double sum = 0.; 111 122 for(int i=1;i<=ngmax;i++) { 112 //sum += tirhmdndm.Random(); 113 sum += tirhmdndm.RandomInterp(); 123 //double l10m = tirhmdndm.Random(); 124 double l10m = tirhmdndm.RandomInterp(); 125 double m = pow(10.,l10m); 126 sum += m; 127 bigsum += m; nbigsum++; 114 128 int ipo = i-ngmin; 115 129 if(ipo<0) continue; 116 vhisto[ipo]->Add(sum/(double)i); 130 double v = log10(sum/(double)i); 131 vhisto[ipo].Add(v); 117 132 } 118 133 if(ia%lpmod==0) PrtTim(" "); 119 134 } 120 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; 144 if(verif) { 145 cout<<"> Creating "<<nbhist<<" FunRan and Histos for back-verif"<<endl; 146 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(); 152 vthisto.push_back(h); 153 sprintf(str,"th%d",i); 154 vthname.push_back(string(str)); 155 } 156 157 cout<<"> Checking tirage"<<endl; 158 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); 163 } 164 } 165 PrtTim("End Random loop back-tirage"); 166 } 121 167 122 168 //------- Ecriture ppf … … 127 173 Histo hdum2(tirhmdndm); 128 174 tag = "tirhmdndm"; pos.PutObject(hdum2,tag); 129 for(unsigned int i=0;i<vhisto.size();i++) 130 if(vhisto[i]->NEntries()>0) pos.PutObject(*vhisto[i],vhname[i]); 131 132 //------- des-allocation 133 for(unsigned int i=0;i<vhisto.size();i++) delete vhisto[i]; 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 if(vthisto[i].NEntries()>0) pos.PutObject(vthisto[i],vthname[i]); 134 181 135 182 return 0; … … 140 187 openppf cmvschdist.ppf 141 188 142 set h h100 189 set n 70 190 echo ${h70.vmax} 191 192 set h h$n 193 set th th$n 194 143 195 disp $h 196 disp $th "same red" 197 144 198 n/plot $h.val%x ! ! "connectpoints" 199 n/plot $th.val%x ! ! "nsta connectpoints same red" 200 145 201 n/plot $h.log10(val)%x val>0. ! "connectpoints" 146 147 echo ${h100.vmax} 202 n/plot $th.log10(val)%x val>0. ! "nsta connectpoints same red" 148 203 149 204 c++exec \ … … 159 214 } 160 215 216 # Compare evolution 217 disp h200 218 disp h100 "same red" 219 disp h50 "same blue" 220 disp h10 "same green" 221 disp h1 "same yellow" 161 222 */
Note:
See TracChangeset
for help on using the changeset viewer.