source: Sophya/trunk/Cosmo/SimLSS/cmvconcherr.cc@ 3141

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

chgt HProf->HistoErr + spectre 2D cmv 17/01/2007

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 "histerr.h"
11
12void usage(void);
13void usage(void)
14{
15 cout<<"cmvconchprof -n name_histoerr 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 HistoErr
40 HistoErr *herrconc = NULL;
41 int nherr = 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 HistoErr herr;
47 pis.GetObject(herr,nameh);
48 int n = herr.NBins();
49 cout<<ifile<<" : "<<ppfname[ifile]<<" nbin="<<n<<endl;
50 if(ifile==0) {
51 herrconc = new HistoErr(herr.XMin(),herr.XMax(),herr.NBins());
52 nherr = n;
53 itest = int(herrconc->NBins()/5.+0.5);
54 }
55 if(n!=nherr) {cout<<"BAD NUMBER OF BINS"<<endl; continue;}
56 for(int i=0;i<nherr;i++) herrconc->AddBin(i,herr(i));
57 sum+=herr(itest); sum2+=herr(itest)*herr(itest), nsum++;
58 }
59 herrconc->ToCorrel();
60 if(nsum>0) {sum/=nsum; sum2/=nsum; sum2-=sum*sum;}
61 cout<<"Test bin "<<itest<<" mean="<<sum<<" sigma^2="<<sum2<<" nsum="<<nsum<<endl;
62 cout<<" "<<" mean="<<(*herrconc)(itest)<<" sigma^2="<<herrconc->Error2(itest)<<endl;
63
64 // --- ecriture ascii
65 if(1) {
66 FILE * fdata = fopen("cmvconchprof.data","w");
67 fprintf(fdata,"# k(Mpc^-1) <pkz_reconstruit> variance_pkz\n");
68 for(int i=0;i<herrconc->NBins();i++) {
69 double k = herrconc->BinCenter(i);
70 fprintf(fdata,"%e %e %e\n",k,(*herrconc)(i),herrconc->Error2(i));
71 }
72 fclose(fdata);
73 }
74
75 // --- ecriture ppf
76 string tagobs = "cmvconchprof.ppf";
77 POutPersist posobs(tagobs);
78 tagobs = "herrconc"; posobs.PutObject(*herrconc,tagobs);
79
80 delete herrconc;
81
82 return 0;
83}
84
85/*
86openppf cmvconchprof.ppf
87
88disp herrconc
89
90n/plot herrconc.val%log10(x) x>0 ! "connectpoints"
91n/plot herrconc.err%log10(x) x>0 ! "connectpoints same red"
92
93n/plot herrconc.err/val%log10(x) x>0&&val>0 ! "connectpoints"
94*/
Note: See TracBrowser for help on using the repository browser.