Changeset 3193 in Sophya for trunk/Cosmo/SimLSS/cmvconcherr.cc
- Timestamp:
- Mar 21, 2007, 7:18:25 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cmvconcherr.cc
r3184 r3193 13 13 14 14 int ObjectType(string nameh,string nameppf); 15 int ConcatHistoErr(string nameh,vector<string> ppfname,int wrtyp );15 int ConcatHistoErr(string nameh,vector<string> ppfname,int wrtyp,bool do_cov); 16 16 int ConcatHisto2DErr(string nameh,vector<string> ppfname,int wrtyp); 17 17 void usage(void); … … 21 21 <<"cmvconcherr -w wtyp -n name_histoerr file1.ppf file2.ppf ..."<<endl 22 22 <<" name_histoerr: object name"<<endl 23 <<" wtyp: bit0 write ASCII, bit1 write PPF, bit2 write FITS (all=7)"<<endl; 23 <<" wtyp: bit0 write ASCII, bit1 write PPF, bit2 write FITS (all=7)"<<endl 24 <<" -C : compute covariance for 1D spectrum"<<endl; 24 25 } 25 26 … … 32 33 vector<string> ppfname; 33 34 int Write_Type = 3; 35 bool Do_Cov = false; 34 36 35 37 // --- Decodage arguments 36 38 char c; 37 while((c = getopt(narg,arg,"h n:w:")) != -1) {39 while((c = getopt(narg,arg,"hCn:w:")) != -1) { 38 40 switch (c) { 39 41 case 'n' : … … 43 45 sscanf(optarg,"%d",&Write_Type); 44 46 break; 47 case 'C' : 48 Do_Cov = true; 49 break; 45 50 case 'h' : 46 51 default : … … 59 64 // --- lecture et moyenne des HistoErr ou Histo2DErr 60 65 int nread=0; 61 if(obtyp==1) nread = ConcatHistoErr(nameh,ppfname,Write_Type );66 if(obtyp==1) nread = ConcatHistoErr(nameh,ppfname,Write_Type,Do_Cov); 62 67 else if(obtyp==2) nread = ConcatHisto2DErr(nameh,ppfname,Write_Type); 63 68 else { … … 95 100 96 101 //--------------------------------------------------------------- 97 int ConcatHistoErr(string nameh,vector<string> ppfname,int wrtyp )102 int ConcatHistoErr(string nameh,vector<string> ppfname,int wrtyp,bool do_cov) 98 103 { 99 104 if(ppfname.size()<=0) return 0; 100 105 101 106 HistoErr *herrconc = NULL; 107 TVector<r_8> Tsum; TMatrix<r_8> Tsum2; 102 108 int nherr=0, nread=0, itest=0; 103 109 double sum=0., sum2=0., nsum=0; … … 111 117 nherr = herr.NBins(); 112 118 itest = int(herrconc->NBins()/5.+0.5); 119 if(do_cov) {Tsum.ReSize(nherr); Tsum=0.; Tsum2.ReSize(nherr,nherr); Tsum2=0.;} 113 120 } else if(nherr!=herr.NBins()) { 114 121 cout<<"BAD NUMBER OF BINS"<<endl; … … 120 127 for(int i=0;i<nherr;i++) herrconc->AddBin(i,herr(i)); 121 128 sum+=herr(itest); sum2+=herr(itest)*herr(itest); nsum++; 129 130 if(do_cov) { 131 for(int i=0;i<nherr;i++) { 132 Tsum(i) += herr(i); 133 for(int j=0;j<nherr;j++) Tsum2(i,j) += herr(i)*herr(j); 134 } 135 } 136 122 137 } 123 138 herrconc->ToVariance(); … … 127 142 <<" sigma^2="<<herrconc->Error2(itest)<<endl; 128 143 144 // --- Covariance 145 if(do_cov && nread>1) { 146 Tsum /= nread; 147 Tsum2 /= nread; 148 for(int i=0;i<nherr;i++) 149 for(int j=0;j<nherr;j++) Tsum2(i,j) -= Tsum(i)*Tsum(j); 150 } 151 129 152 // --- ecriture 130 153 if(wrtyp&1) { // ecriture ASCII … … 132 155 herrconc->WriteASCII(asname); 133 156 } 134 if(wrtyp&2 ) { // ecriture PPF157 if(wrtyp&2 || do_cov) { // ecriture PPF 135 158 string tagobs = "cmvconcherr.ppf"; 136 159 POutPersist posobs(tagobs); 137 160 tagobs = "herrconc"; posobs.PutObject(*herrconc,tagobs); 161 if(do_cov) { 162 tagobs = "mean"; posobs.PutObject(Tsum,tagobs); 163 tagobs = "cov"; posobs.PutObject(Tsum2,tagobs); 164 } 138 165 } 139 166 if(wrtyp&4) { // ecriture FITS … … 220 247 n/plot herrconc.sqrt(err2)/val%log10(x) x>0&&err2>0&&val>0 ! "connectpoints" 221 248 249 disp mean 250 imag cov 251 252 del cor 253 c++exec \ 254 TMatrix<r_8> cor(cov,false); cor = 0.; \ 255 for(int i=0;i<cor.NRows();i++) { \ 256 for(int j=0;j<cor.NCols();j++) { \ 257 double v = cov(i,i)*cov(j,j); \ 258 if(v<=0.) continue; \ 259 cor(i,j) = cov(i,j)/sqrt(v); \ 260 } } \ 261 KeepObj(cor); \ 262 cout<<"Matrice cor cree "<<endl; 263 264 imag cor 265 222 266 #### Histo2DErr 2D 223 267 openppf cmvconcherr2.ppf
Note:
See TracChangeset
for help on using the changeset viewer.