source: Sophya/trunk/Cosmo/SimLSS/cmvconchprof.cc@ 3120

Last change on this file since 3120 was 3120, checked in by cmv, 19 years ago

Suite de la mise dans la base cvs cmv 21/12/2006

File size: 2.4 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <iostream>
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <math.h>
8#include <unistd.h>
9#include "timing.h"
10#include "hisprof.h"
11
12void usage(void);
13void usage(void)
14{
15 cout<<"cmvconchprof -n namehprof file1.ppf file2.ppf ..."<<endl;
16}
17
18int main(int narg,char *arg[])
19{
20 string nameh = ""; // "hpkgen" "hpkgenf" "hpkrec"
21 vector<string> ppfname;
22
23 // --- Decodage arguments
24 char c;
25 while((c = getopt(narg,arg,"hn:")) != -1) {
26 switch (c) {
27 case 'n' :
28 nameh = optarg;
29 break;
30 case 'h' :
31 default :
32 usage(); return -1;
33 }
34 }
35 if(nameh.size()<=0 || optind>=narg) {usage(); return -1;}
36 for (int i=optind;i<narg;i++) ppfname.push_back(arg[i]);
37 cout<<"nameh = "<<nameh<<" , number of file to be read = "<<ppfname.size()<<endl;
38
39 // --- lecture et moyenne des HProf
40 HProf *hpconc = NULL;
41 int nhp = 0;
42 int itest = 0;
43 double sum=0., sum2=0., nsum=0;
44 for (int ifile=0;ifile<ppfname.size();ifile++) {
45 PInPersist pis(ppfname[ifile].c_str());
46 HProf hp;
47 pis.GetObject(hp,nameh);
48 int n = hp.NBins();
49 cout<<ifile<<" : "<<ppfname[ifile]<<" nbin="<<n<<endl;
50 if(ifile==0) {
51 hpconc = new HProf(hp.XMin(),hp.XMax(),hp.NBins());
52 hpconc->SetErrOpt(true);
53 nhp = n;
54 itest = int(hpconc->NBins()/5.+0.5);
55 }
56 if(n!=nhp) {cout<<"BAD NUMBER OF BINS"<<endl; continue;}
57 for(int i=0;i<nhp;i++) hpconc->AddBin(i,hp(i));
58 sum+=hp(itest); sum2+=hp(itest)*hp(itest), nsum++;
59 }
60 hpconc->UpdateHisto(true);
61 if(nsum>0) {sum/=nsum; sum2/=nsum; sum2-=sum*sum;}
62 cout<<"Test bin "<<itest<<" mean="<<sum<<" sigma^2="<<sum2<<" nsum="<<nsum<<endl;
63 cout<<" "<<" mean="<<(*hpconc)(itest)<<" sigma^2="<<hpconc->Error2(itest)<<endl;
64
65 // --- ecriture ascii
66 if(1) {
67 FILE * fdata = fopen("cmvconchprof.data","w");
68 fprintf(fdata,"# k(Mpc^-1) <pkz_reconstruit> variance_pkz\n");
69 for(int i=0;i<hpconc->NBins();i++) {
70 double k = hpconc->BinCenter(i);
71 fprintf(fdata,"%e %e %e\n",k,(*hpconc)(i),hpconc->Error2(i));
72 }
73 fclose(fdata);
74 }
75
76 // --- ecriture ppf
77 string tagobs = "cmvconchprof.ppf";
78 POutPersist posobs(tagobs);
79 tagobs = "hpconc"; posobs.PutObject(*hpconc,tagobs);
80
81 delete hpconc;
82
83 return 0;
84}
85
86/*
87openppf cmvconchprof.ppf
88
89disp hpconc
90
91n/plot hpconc.val%log10(x) x>0 ! "connectpoints"
92n/plot hpconc.err%log10(x) x>0 ! "connectpoints same red"
93
94n/plot hpconc.err/val%log10(x) x>0&&val>0 ! "connectpoints"
95*/
Note: See TracBrowser for help on using the repository browser.