Changeset 3320 in Sophya for trunk/Cosmo/SimLSS/cmvschdist.cc


Ignore:
Timestamp:
Sep 5, 2007, 9:58:05 AM (18 years ago)
Author:
cmv
Message:

intro SchechterMassDist pour accelerer la simulations cmv 05/09/2007

File:
1 edited

Legend:

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

    r3319 r3320  
    66// ex: on a un pixel qui a N galaxies, quelle est la distribution
    77//     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
    913#include <iostream>
    1014#include <stdlib.h>
     
    2832void usage(void)
    2933{
    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
    3540     <<"  -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;
    3744}
    3845
     
    4653
    4754 double xmin=1e8, xmax=1e13;
    48  int npt = 100;
     55 int npt = -100;
    4956 int ngmax = 200, ngmin = 1;
     57 bool useonly1 = false;
    5058 unsigned long long nalea = 10000;
    5159 bool verif = false;
     60 bool readfrppf = false;
     61 string namefrppf = "";
     62 string nametoppf = "";
    5263
    5364 char c;
    54  while((c = getopt(narg,arg,"havm:N:n:r:")) != -1) {
     65 while((c = getopt(narg,arg,"h0avm:N:n:r:R:W:")) != -1) {
    5566   switch (c) {
    5667   case 'm' :
     
    6879   case 'n' :
    6980     sscanf(optarg,"%d",&npt);
    70      if(npt<=0) npt = 100;
     81     if(npt<=0) npt = -100;
    7182     break;
    7283   case 'N' :
     
    7788     verif = true;
    7889     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;
    79100   case 'a' :
    80101     Auto_Ini_Ranf(5);
     
    86107 }
    87108
    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;
    90111 cout<<"npt="<<npt<<",  nalea="<<nalea<<endl;
    91  cout<<"ngmin="<<ngmin<<" ngmax="<<ngmax<<endl;
     112 cout<<"useonly1="<<useonly1<<" ngmin="<<ngmin<<" ngmax="<<ngmax<<endl;
    92113 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;
    93116
    94117
     
    96119 cout<<"> Schechter m*dn/dm nstar="<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
    97120 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();
    113131
    114132 //------- Random
    115133 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;
    144143 if(verif) {
    145    cout<<"> Creating "<<nbhist<<" FunRan and Histos for back-verif"<<endl;
     144   cout<<"> Creating "<<ngmax-ngmin+1<<" Histos for back-verif"<<endl;
    146145   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();
    152147     vthisto.push_back(h);
    153      sprintf(str,"th%d",i);
     148     char str[32]; sprintf(str,"th%d",i);
    154149     vthname.push_back(string(str));
    155150   }
     151   cout<<"   "<<vthisto.size()<<" Histos created"<<endl;
     152   vthisto[20].Show();
    156153
    157154   cout<<"> Checking tirage"<<endl;
     155   int lpmod = nalea/20; if(lpmod<=0) lpmod=1;
    158156   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));
    163162     }
    164163   }
     164   schdmass.PrintStatus();
    165165   PrtTim("End Random loop back-tirage");
    166166 }
    167167
    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;
    170175 string tag = "cmvschdist.ppf";
    171176 POutPersist pos(tag);
     177 {
     178 cout<<"  writing hmdndm tirhmdndm"<<endl;
    172179 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++)
    180200     if(vthisto[i].NEntries()>0) pos.PutObject(vthisto[i],vthname[i]);
     201 }
     202
     203 PrtTim("End of Job");
    181204
    182205 return 0;
     
    191214
    192215set h h$n
     216set t t$n
    193217set th th$n
     218
     219disp tirhmdndm
     220disp $t "same red"
    194221
    195222disp $h
     
    201228n/plot $h.log10(val)%x val>0. ! "connectpoints"
    202229n/plot $th.log10(val)%x val>0. ! "nsta connectpoints same red"
     230
     231n/plot $h.val%pow(10.,x) ! ! "connectpoints"
     232n/plot $th.val%pow(10.,x) ! ! "nsta connectpoints same red"
    203233
    204234c++exec \
Note: See TracChangeset for help on using the changeset viewer.