- Timestamp:
- Jul 19, 2007, 10:13:51 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cmvconcherr.cc
r3246 r3282 13 13 14 14 int ObjectType(string nameh,string nameppf); 15 int ConcatHistoErr(string nameh,vector<string> ppfname,int wrtyp ,bool do_cov);16 int ConcatHisto2DErr(string nameh,vector<string> ppfname,int wrtyp );15 int ConcatHistoErr(string nameh,vector<string> ppfname,int wrtyp=2,bool do_cov=false); 16 int ConcatHisto2DErr(string nameh,vector<string> ppfname,int wrtyp=2,int ibinkt=-1,int ibinkz=-1); 17 17 void usage(void); 18 18 void usage(void) … … 22 22 <<" name_histoerr: object name"<<endl 23 23 <<" wtyp: bit0 write ASCII, bit1 write PPF, bit2 write FITS (all=7)"<<endl 24 <<" -C : compute covariance for 1D spectrum"<<endl; 24 <<" -C : compute covariance for 1D spectrum"<<endl 25 <<" -Z ibinKt : compute covariance of line Pk(ibinKt,.) along Kz for 2D"<<endl 26 <<" -T ibinKz : compute covariance of line Pk(.,ibinKz) along Kt for 2D"<<endl 27 <<endl; 25 28 } 26 29 … … 32 35 string nameh = ""; 33 36 vector<string> ppfname; 34 int Write_Type = 3;37 int Write_Type = 2; 35 38 bool Do_Cov = false; 39 int ibinKt=-1, ibinKz=-1; 36 40 37 41 // --- Decodage arguments 38 42 char c; 39 while((c = getopt(narg,arg,"hCn:w: ")) != -1) {43 while((c = getopt(narg,arg,"hCn:w:Z:T:")) != -1) { 40 44 switch (c) { 41 45 case 'n' : … … 47 51 case 'C' : 48 52 Do_Cov = true; 53 break; 54 case 'Z' : 55 sscanf(optarg,"%d",&ibinKt); 56 break; 57 case 'T' : 58 sscanf(optarg,"%d",&ibinKz); 49 59 break; 50 60 case 'h' : … … 65 75 int nread=0; 66 76 if(obtyp==1) nread = ConcatHistoErr(nameh,ppfname,Write_Type,Do_Cov); 67 else if(obtyp==2) nread = ConcatHisto2DErr(nameh,ppfname,Write_Type );77 else if(obtyp==2) nread = ConcatHisto2DErr(nameh,ppfname,Write_Type,ibinKt,ibinKz); 68 78 else { 69 79 cout<<"Type of object "<<nameh<<" not decoded"<<endl; … … 108 118 int nherr=0, nread=0, itest=0; 109 119 double sum=0., sum2=0., nsum=0; 110 for ( int ifile=0;ifile<ppfname.size();ifile++) {120 for (unsigned int ifile=0;ifile<ppfname.size();ifile++) { 111 121 PInPersist pis(ppfname[ifile].c_str()); 112 122 HistoErr herr; 113 123 pis.GetObject(herr,nameh); 114 124 cout<<ifile<<" : "<<ppfname[ifile]<<" nbin="<<herr.NBins()<<endl; 125 115 126 if(ifile==0) { 116 127 herrconc = new HistoErr(herr.XMin(),herr.XMax(),herr.NBins()); … … 122 133 continue; 123 134 } 135 124 136 if(herr.NMean()!=1) cout<<"ATTENTION: file="<<ppfname[ifile] 125 137 <<" nmean="<<herr.NMean()<<endl; 126 138 nread++; 127 139 for(int i=0;i<nherr;i++) herrconc->AddBin(i,herr(i)); … … 175 187 176 188 //--------------------------------------------------------------- 177 int ConcatHisto2DErr(string nameh,vector<string> ppfname,int wrtyp )189 int ConcatHisto2DErr(string nameh,vector<string> ppfname,int wrtyp,int ibinkt,int ibinkz) 178 190 { 179 191 if(ppfname.size()<=0) return 0; 180 192 181 193 Histo2DErr *herrconc = NULL; 194 TVector<r_8> Tsum_kz; TMatrix<r_8> Tsum2_kz; 195 TVector<r_8> Tsum_kt; TMatrix<r_8> Tsum2_kt; 182 196 int nherrx=0, nherry=0, nread=0, itestx=0, itesty=0; 183 197 double sum=0., sum2=0., nsum=0; 184 for ( int ifile=0;ifile<ppfname.size();ifile++) {198 for (unsigned int ifile=0;ifile<ppfname.size();ifile++) { 185 199 PInPersist pis(ppfname[ifile].c_str()); 186 200 Histo2DErr herr; … … 188 202 cout<<ifile<<" : "<<ppfname[ifile]<<" nbin=" 189 203 <<herr.NBinX()<<","<<herr.NBinY()<<endl; 204 190 205 if(ifile==0) { 191 206 herrconc = new Histo2DErr(herr.XMin(),herr.XMax(),herr.NBinX() … … 194 209 itestx = int(herrconc->NBinX()/5.+0.5); 195 210 itesty = int(herrconc->NBinY()/5.+0.5); 211 if(ibinkt>=0) { // matrix de covariance pour une ligne Kz 212 if(ibinkt>=nherrx) ibinkt = nherrx-1; 213 Tsum_kz.ReSize(nherry); Tsum_kz=0.; 214 Tsum2_kz.ReSize(nherry,nherry); Tsum2_kz=0.; 215 } 216 if(ibinkz>=0) { // matrix de covariance pour une ligne Kt 217 if(ibinkz>=nherry) ibinkz = nherry-1; 218 Tsum_kt.ReSize(nherrx); Tsum_kt=0.; 219 Tsum2_kt.ReSize(nherrx,nherrx); Tsum2_kt=0.; 220 } 196 221 } else if(nherrx!=herr.NBinX() || nherry!=herr.NBinY()) { 197 222 cout<<"BAD NUMBER OF BINS"<<endl; 198 223 continue; 199 224 } 225 200 226 if(herr.NMean()!=1) cout<<"ATTENTION: file="<<ppfname[ifile] 201 227 <<" nmean="<<herr.NMean()<<endl; 202 228 nread++; 203 229 for(int i=0;i<nherrx;i++) 204 230 for(int j=0;j<nherry;j++) herrconc->AddBin(i,j,herr(i,j)); 205 231 sum+=herr(itestx,itesty); sum2+=herr(itestx,itesty)*herr(itestx,itesty); nsum++; 232 233 if(ibinkt>=0) { 234 for(int i=0;i<Tsum_kz.Size();i++) { 235 Tsum_kz(i) += herr(ibinkt,i); 236 for(int j=0;j<Tsum_kz.Size();j++) Tsum2_kz(i,j) += herr(ibinkt,i)*herr(ibinkt,j); 237 } 238 } 239 240 if(ibinkz>=0) { 241 for(int i=0;i<Tsum_kt.Size();i++) { 242 Tsum_kt(i) += herr(i,ibinkz); 243 for(int j=0;j<Tsum_kt.Size();j++) Tsum2_kt(i,j) += herr(i,ibinkz)*herr(j,ibinkz); 244 } 245 } 246 206 247 } 207 248 herrconc->ToVariance(); … … 212 253 <<" sigma^2="<<herrconc->Error2(itestx,itesty)<<endl; 213 254 255 // --- Covariance 256 if(ibinkt>=0 && nread>1) { 257 Tsum_kz /= nread; 258 Tsum2_kz /= nread; 259 for(int i=0;i<Tsum_kz.Size();i++) 260 for(int j=0;j<Tsum_kz.Size();j++) Tsum2_kz(i,j) -= Tsum_kz(i)*Tsum_kz(j); 261 } 262 if(ibinkz>=0 && nread>1) { 263 Tsum_kt /= nread; 264 Tsum2_kt /= nread; 265 for(int i=0;i<Tsum_kt.Size();i++) 266 for(int j=0;j<Tsum_kt.Size();j++) Tsum2_kt(i,j) -= Tsum_kt(i)*Tsum_kt(j); 267 } 268 214 269 // --- ecriture 215 270 if(wrtyp&1) { // ecriture ASCII … … 221 276 POutPersist posobs(tagobs); 222 277 tagobs = "herrconc2"; posobs.PutObject(*herrconc,tagobs); 278 if(ibinkt>=0) { 279 char str[32]; 280 sprintf(str,"kzm%d",ibinkt); 281 posobs.PutObject(Tsum_kz,str); 282 sprintf(str,"kzc%d",ibinkt); 283 posobs.PutObject(Tsum2_kz,str); 284 } 285 if(ibinkz>=0) { 286 char str[32]; 287 sprintf(str,"ktm%d",ibinkz); 288 posobs.PutObject(Tsum_kt,str); 289 sprintf(str,"ktc%d",ibinkz); 290 posobs.PutObject(Tsum2_kt,str); 291 } 223 292 } 224 293 if(wrtyp&4) { // ecriture FITS … … 233 302 234 303 /* 304 #### 235 305 #### HistoErr 1D 306 #### 236 307 openppf cmvconcherr.ppf 237 308 … … 264 335 imag cor 265 336 337 #### 266 338 #### Histo2DErr 2D 339 #### 267 340 openppf cmvconcherr2.ppf 268 341 … … 271 344 imag herrconc2 "hbinerr" 272 345 imag herrconc2 "hbinent" 346 347 zone 348 349 set mean kzm140 350 set cov kzc140 351 352 set mean ktm32 353 set cov ktc32 354 355 n/plot $mean.val%n ! ! "connectpoints" 356 disp $cov 357 n/plot $cov.val%c r==32 ! "connectpoints" 358 359 set cor ${cov}cor 360 del $cor 361 c++exec \ 362 TMatrix<r_8> $cor($cov,false); $cor = 0.; \ 363 for(int i=0;i<$cor.NRows();i++) { \ 364 for(int j=0;j<$cor.NCols();j++) { \ 365 double v = $cov(i,i)*$cov(j,j); \ 366 if(v<=0.) continue; \ 367 $cor(i,j) = $cov(i,j)/sqrt(v); \ 368 } } \ 369 KeepObj($cor); \ 370 cout<<"Matrice cor cree "<<endl; 371 372 disp $cor 373 n/plot $cor.val%c r==32 ! "connectpoints" 273 374 */
Note:
See TracChangeset
for help on using the changeset viewer.