source: Sophya/trunk/Cosmo/SimLSS/cmvtstagn.cc

Last change on this file was 3808, checked in by cmv, 15 years ago

pb mineurs de print, cmv 26/07/2010

File size: 5.4 KB
Line 
1// Distribution des flux des AGN dans un pixel de taille donne
2#include "sopnamsp.h"
3#include "machdefs.h"
4#include <iostream>
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8#include <math.h>
9#include <unistd.h>
10#include "sophyainit.h"
11#include "timing.h"
12#include "ntuple.h"
13
14#include "geneutils.h"
15#include "agnjackson.h"
16#include "srandgen.h"
17
18void usage(void);
19void usage(void)
20{
21cout<<"cmvtstagn "<<endl
22 <<" -a angsol: taille pixel (en sr si >0 ou arcmin^2 si <0)"<<endl
23 <<" -x nbin,xmin,xmax: def histo des log10(S Jy)/pixel"<<endl
24 <<" si nbin<0 on a de <S>+xmin , <S>-xmax"<<endl
25 <<" -n npix: nombre de tirages de pixel"<<endl;
26}
27
28
29int main(int narg,char *arg[])
30{
31SophyaInit();
32 double angsol = 1.; // sr
33 double lxmin=-3.,lxmax=4.; int nbinlx = -100;
34 int npix = 100;
35
36 // --- Decodage arguments
37 char c;
38 while((c = getopt(narg,arg,"ha:x:n:")) != -1) {
39 switch (c) {
40 case 'a' :
41 sscanf(optarg,"%lf",&angsol);
42 break;
43 case 'x' :
44 sscanf(optarg,"%d,%lf,%lf",&nbinlx,&lxmin,&lxmax);
45 break;
46 case 'n' :
47 sscanf(optarg,"%d",&npix);
48 break;
49 case 'h' :
50 default :
51 usage();
52 return -1;
53 }
54 }
55
56 // --- Class de distribution d'AGN
57 double sr2amin = AngSol(M_PI/180./60./2.,M_PI/180./60./2.);
58 if(angsol<0) angsol *= -sr2amin;
59 cout<<"angsol = "<<angsol<<" sr -> "<<angsol/sr2amin<<" arcmin^2"<<endl;
60 AGNJackson agn;
61 agn.Print();
62
63 cout<<endl;
64 vector<double> xjack, yjack; agn.OrigJack(xjack,yjack);
65 Histo hdndls0 = agn.dNdlS();
66 Histo hdndls(hdndls0); hdndls *= angsol;
67 Histo htirls = agn.TirL10S();
68 double nobjang = agn.NObjAng()*angsol;
69 double fluxang = agn.FluxAng()*angsol;
70 cout<<"Nombre moyen d\'objets dans notre pixel: "<<nobjang<<endl;
71 cout<<"Flux moyen dans notre pixel: "<<fluxang<<" Jy"<<endl;
72
73 // --- Distribution sur angsol
74 // Histo du nombre d'objets / angsol
75 cout<<endl;
76 double mu = nobjang; if(mu<=0.) mu=1.;
77 double xmin = mu-5.*sqrt(mu); if(xmin<0.) xmin=0.; xmin=floor(xmin);
78 double xmax = mu+7.*sqrt(mu); xmax=floor(xmax+1.);
79 long nb = long(xmax-xmin+1.01); while(nb>250) nb /= 2;
80 // Histo du nombre d'objets/pixel
81 Histo hnobj(xmin,xmax,nb); hnobj.ReCenterBin();
82 cout<<"hnobj: "; hnobj.Show();
83 // Histo de check du tirage
84 Histo hlflux(htirls); hlflux.Zero();
85 // Histo du flux/pixel
86 if(nbinlx==0 || nbinlx==1) nbinlx = -100;
87 if(nbinlx<0) {
88 nbinlx = -nbinlx;
89 lxmin = log10(fluxang) + lxmin;
90 lxmax = log10(fluxang) + lxmax;
91 cout<<"Recomputing: lxmin="<<lxmin<<" lxmax="<<lxmax<<" nbin="<<nbinlx<<endl;
92 }
93 Histo hlfang(lxmin,lxmax,nbinlx); hlfang.Zero();
94 cout<<"hlfang: "; hlfang.Show();
95
96 // Tirage aleatoire
97 cout<<endl;
98 if(npix>1) {
99 long l = npix/10; if(l<=0) l=1;
100 cout<<"Making "<<npix<<" trials"<<endl;
101 unsigned long nzero=0, ntir=0;
102 double sumpix=0., sumpix2=0., sumn=0., sumn2=0.;
103 for(long i=0;i<npix;i++) {
104 if(i%l==0) cout<<"...trial: "<<i<<endl;
105 double n = PoissonRand(mu,10.);
106 hnobj.Add(n);
107 sumn += n; sumn2 += n*n;
108 double fsum = 0.; unsigned long nf = 0;
109 for(unsigned long j=0;j<n;j++) {
110 double f = agn.FluxJY();
111 hlflux.Add(log10(f));
112 fsum += f;
113 nf++;
114 }
115 ntir += nf;
116 if(nf==0) {
117 nzero++;
118 } else {
119 sumpix += fsum; sumpix2 += fsum*fsum;
120 hlfang.Add(log10(fsum));
121 }
122 }
123 sumn /= (double)npix;
124 sumn2 = sumn2/(double)npix - sumn*sumn;
125 sumpix /= (double)npix;
126 sumpix2 = sumpix2/(double)npix - sumpix*sumpix;
127 cout<<"Number of try: "<<ntir<<endl;
128 cout<<"Number of pixels with no flux: "<<nzero<<" / "<<npix<<endl;
129 cout<<"Mean object number/pix: "<<sumn<<" (check "<<(double)ntir/(double)npix
130 <<") s^2="<<sumn2<<" s="<<sqrt(fabs(sumn2))<<endl;
131 cout<<"Mean flux/pix: "<<sumpix<<" s^2="<<sumpix2<<" s="<<sqrt(fabs(sumpix2))<<endl;
132 // Info de l'histo des flux
133 cout<<"hlfang: "; hlfang.Show();
134 // normalisation de hlflux
135 hlflux *= hdndls.BinWidth()/hlflux.BinWidth()*hdndls.Sum()/hlflux.Sum();
136 }
137
138 // --- Ecriture sur fichier ppf
139 string tag = "cmvtstagn.ppf";
140 POutPersist pos(tag);
141
142 TVector<r_8> vxjack(xjack), vyjack(yjack);
143 tag = "xjack"; pos.PutObject(vxjack,tag);
144 tag = "yjack"; pos.PutObject(vyjack,tag);
145
146 tag = "dndls0"; pos.PutObject(hdndls0,tag);
147 tag = "dndls"; pos.PutObject(hdndls,tag);
148
149 tag = "tirls"; pos.PutObject(htirls,tag);
150 tag = "hlflux"; pos.PutObject(hlflux,tag);
151
152 tag = "nobj"; pos.PutObject(hnobj,tag);
153 tag = "hlfang"; pos.PutObject(hlfang,tag);
154
155 return 0;
156}
157
158
159/*
160openppf cmvtstagn.ppf
161
162del ntjack
163c++exec const char *vname[2] = {"x","y"}; double xnt[2]; \
164NTuple ntjack(2,vname); \
165for(int i=0;i<xjack.Size();i++) \
166 {xnt[0]=xjack(i); xnt[1]=yjack(i); ntjack.Fill(xnt);} \
167KeepObj(ntjack); cout<<"OK";
168
169# Jackson initial (Jy^1.5/sr)
170n/plot ntjack.y%x ! ! "nsta connectpoints"
171vecplot xjack yjack "same red fcirclemarker7"
172
173# Check de ce qu'on a extrapole
174set yxt "y*pow(10.,-1.5*x)*M_LN10"
175n/plot dndls0.log10(val)%x ! ! "nsta connectpoints"
176n/plot ntjack.log10($yxt)%x ! ! "nsta red fcirclemarker7 same"
177
178# la pdf : histo en 1/log10(Jy)/sr
179disp dndls0 "nsta"
180n/plot ntjack.$yxt%x ! ! "nsta red fcirclemarker7 same"
181
182# la pdf : histo en 1/log10(Jy)/angsol
183disp dndls "nsta"
184
185# la pdf en flux: dn/dlog10(S)*S en microJy/log10(Jy)/sr
186n/plot dndls.val*pow(10.,x)*1e6%x ! ! "nsta connectpoints"
187
188# la fonction de tirage en 1/Jy/(angsol sr)
189disp tirls "nsta"
190
191# Check tirages
192disp dndls "nsta"
193disp hlflux "nsta same red"
194
195# Resultat: nombre d'objets (poisson) par pixel
196disp nobj
197
198# Resultat: distribution du flux par pixel
199disp hlfang
200
201 */
Note: See TracBrowser for help on using the repository browser.