Changeset 3319 in Sophya for trunk/Cosmo/SimLSS


Ignore:
Timestamp:
Sep 3, 2007, 12:49:21 PM (18 years ago)
Author:
cmv
Message:

commit pour memoire avant intro class SchechterMassDist cmv 03/09/2007

File:
1 edited

Legend:

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

    r3284 r3319  
    22#include "sopnamsp.h"
    33#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
    49#include <iostream>
    510#include <stdlib.h>
     
    2833     <<"  ngmax,ngmin : distribution pour tirage de ngmin a ngmax galaxies"<<endl
    2934     <<"  nalea : nombre de tirages aleatoires"<<endl
     35     <<"  -v : back verification of random trials"<<endl
    3036     <<"  -a : init auto de l\'aleatoire"<<endl;
    3137}
     
    4349 int ngmax = 200, ngmin = 1;
    4450 unsigned long long nalea = 10000;
     51 bool verif = false;
    4552
    4653 char c;
    47  while((c = getopt(narg,arg,"ham:N:n:r:")) != -1) {
     54 while((c = getopt(narg,arg,"havm:N:n:r:")) != -1) {
    4855   switch (c) {
    4956   case 'm' :
     
    6774     if(nalea<=0) nalea=10000;
    6875     break;
     76   case 'v' :
     77     verif = true;
     78     break;
    6979   case 'a' :
    7080     Auto_Ini_Ranf(5);
     
    8090 cout<<"npt="<<npt<<",  nalea="<<nalea<<endl;
    8191 cout<<"ngmin="<<ngmin<<" ngmax="<<ngmax<<endl;
     92 cout<<"verif="<<verif<<endl;
    8293
    8394
     
    8596 cout<<"> Schechter m*dn/dm nstar="<<nstar<<" mstar="<<mstar<<" alpha="<<alpha<<endl;
    8697 Schechter sch(nstar,mstar,alpha);
    87  sch.SetOutValue(1);
     98 sch.SetOutValue(1);  // on veut m*dN/dm
    8899 Histo hmdndm(lnx1,lnx2,npt); hmdndm.ReCenterBin();
    89100 FuncToHisto(sch,hmdndm,true);
     
    93104 int nbhist = ngmax-ngmin+1;
    94105 cout<<"> Creating "<<nbhist<<" histos"<<endl;
    95  vector<Histo *> vhisto;
    96  vector<string> vhname;
     106 vector<Histo> vhisto;  vector<string> vhname;
    97107 for(int i=ngmin;i<=ngmax;i++) {
    98    Histo* h = new Histo(hmdndm); h->Zero();
     108   Histo h(hmdndm); h.Zero();
    99109   vhisto.push_back(h);
    100110   char str[32]; sprintf(str,"h%d",i);
     
    106116 cout<<"> Random: "<<nalea<<" trials"<<endl;
    107117 int lpmod = nalea/25; if(lpmod<=0) lpmod=1;
     118 double bigsum = 0.; long nbigsum=0;
    108119 for(unsigned long long ia=0;ia<nalea;ia++) {
    109120   if(ia%lpmod==0) cout<<"... "<<ia<<endl;
    110121   double sum = 0.;
    111122   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++;
    114128     int ipo = i-ngmin;
    115129     if(ipo<0) continue;
    116      vhisto[ipo]->Add(sum/(double)i);
     130     double v = log10(sum/(double)i);
     131     vhisto[ipo].Add(v);
    117132   }
    118133   if(ia%lpmod==0) PrtTim(" ");
    119134 }
    120135 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 }
    121167
    122168 //------- Ecriture ppf
     
    127173 Histo hdum2(tirhmdndm);
    128174 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]);
    134181
    135182 return 0;
     
    140187openppf cmvschdist.ppf
    141188
    142 set h h100
     189set n 70
     190echo ${h70.vmax}
     191
     192set h h$n
     193set th th$n
     194
    143195disp $h
     196disp $th "same red"
     197
    144198n/plot $h.val%x ! ! "connectpoints"
     199n/plot $th.val%x ! ! "nsta connectpoints same red"
     200
    145201n/plot $h.log10(val)%x val>0. ! "connectpoints"
    146 
    147 echo ${h100.vmax}
     202n/plot $th.log10(val)%x val>0. ! "nsta connectpoints same red"
    148203
    149204c++exec \
     
    159214}
    160215
     216# Compare evolution
     217disp h200               
     218disp h100 "same red"
     219disp h50 "same blue"
     220disp h10 "same green"
     221disp h1 "same yellow"
    161222*/
Note: See TracChangeset for help on using the changeset viewer.