Changeset 2177 in Sophya for trunk/SophyaPI/ProgPI/skymapmodule.cc
- Timestamp:
- Aug 11, 2002, 4:53:54 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/ProgPI/skymapmodule.cc
r2175 r2177 13 13 #include "pistdimgapp.h" 14 14 #include "servnobjm.h" 15 #include "tvector.h"16 15 #include "pidrawer.h" 17 16 #include "nomgadapter.h" 18 17 19 #include "skymap.h" 18 #include "tvector.h" 19 #include "ntuple.h" 20 #include "slinparbuff.h" 21 #include "localmap.h" 22 #include "spherehealpix.h" 23 #include "spherethetaphi.h" 20 24 #include "sphericaltransformserver.h" 21 25 … … 43 47 void TypeMap(vector<string>& tokens); 44 48 void Map2Double(vector<string>& tokens); 49 void Map2Float(vector<string>& tokens); 45 50 void Map2Map(vector<string>& tokens); 46 51 void MapMult(vector<string>& tokens); … … 57 62 void MapOper(vector<string>& tokens); 58 63 void MapStat(vector<string>& tokens); 64 void Alm2Cl(vector<string>& tokens); 65 void Cl2llCl(vector<string>& tokens); 66 void ClMean(vector<string>& tokens); 67 void ClMult(vector<string>& tokens); 68 void ClOper(vector<string>& tokens); 69 void ClRebin(vector<string>& tokens); 70 void VarOper(vector<string>& tokens); 59 71 protected: 60 72 void SetTypeMap(vector<string>& tokens); … … 77 89 78 90 kw = "settypemap"; 79 usage = "Set le type de map par default"; 91 usage = "Set le type de map(double) par default"; 92 usage += "\n Usage: settypemap type"; 80 93 usage += "\n type= H for Healpix (default)"; 81 94 usage += "\n T for ThetaPhi"; 82 usage += "\n Usage: settypemap type";83 95 mpiac->RegisterCommand(kw, usage, this, hgrp); 84 96 … … 90 102 kw = "map2double"; 91 103 usage = "Convert a float map to a double map"; 92 usage += "\n Usage: map2double map"; 104 usage += "\n Usage: map2double map(float)"; 105 mpiac->RegisterCommand(kw, usage, this, hgrp); 106 107 kw = "map2float"; 108 usage = "Convert a double map to a float map"; 109 usage += "\n Usage: map2float map(double)"; 93 110 mpiac->RegisterCommand(kw, usage, this, hgrp); 94 111 95 112 kw = "map2map"; 96 usage = "Convert a map into an other map type"; 113 usage = "Convert a map(double) into an other map type"; 114 usage += "\n Usage: map2map map(double) type [nside]"; 97 115 usage += "\n type= H for Healpix"; 98 116 usage += "\n T for ThetaPhi"; 99 117 usage += "\n if nside <=1 use nside from map"; 100 usage += "\n Usage: map2map map type [nside]";101 118 mpiac->RegisterCommand(kw, usage, this, hgrp); 102 119 103 120 kw = "mapmult"; 104 usage = "Multiply a map by a constant";105 usage += "\n Usage: mapmult map cste";121 usage = "Multiply a map(double) by a constant"; 122 usage += "\n Usage: mapmult map(double) cste"; 106 123 mpiac->RegisterCommand(kw, usage, this, hgrp); 107 124 108 125 kw = "mapcover"; 109 usage = "Print the covering of a map ";110 usage += "\n Usage: mapcover map v1,v2 [varname]";126 usage = "Print the covering of a map(double)"; 127 usage += "\n Usage: mapcover map(double) v1,v2 [varname]"; 111 128 usage += "\n v1,v2: good pixels have v1<=val<=v2 (def=0.99,1.01)"; 112 129 usage += "\n (use default (0.99,1.01): \"!\")"; … … 115 132 116 133 kw = "map2cl"; 117 usage = "SkyMap to Cl";134 usage = "SkyMap map(double) to Cl"; 118 135 usage += "\n Usage: map2cl map(double) clvec [lmax] [niter]"; 119 136 usage += "\n lmax: if <=0 or \"!\" use default (3*nside-1)"; … … 122 139 123 140 kw = "cl2map"; 124 usage = "Generate SkyMap from Cl";125 usage += "\n Usage: cl2map clvec map nside [fwhm]";141 usage = "Generate SkyMap map(double) from Cl"; 142 usage += "\n Usage: cl2map clvec map(double) nside [fwhm]"; 126 143 usage += "\n (see command settypemap)"; 127 144 mpiac->RegisterCommand(kw, usage, this, hgrp); 128 145 129 146 kw = "map2alm"; 130 usage = "SkyMap to Alm";147 usage = "SkyMap map(double) to Alm"; 131 148 usage += "\n Usage: map2alm map(double) almmat [lmax] [niter]"; 132 149 usage += "\n lmax: if <=0 or \"!\" use default (3*nside-1)"; … … 135 152 136 153 kw = "alm2map"; 137 usage = "Generate SkyMap from Alm";138 usage += "\n Usage: alm2map almmat map nside";154 usage = "Generate SkyMap map(double) from Alm"; 155 usage += "\n Usage: alm2map almmat map(double) nside"; 139 156 usage += "\n (see command settypemap)"; 140 157 mpiac->RegisterCommand(kw, usage, this, hgrp); 141 158 142 159 kw = "crmapmask"; 143 usage = "Create a map mask (nside) between latitudes lat1,lat2 longitudes lon1,lon2";144 usage += "\n Usage: crmapmask mapmsk nside lat1,lat2 lon1,lon2 [valmsk,valnomsk]";160 usage = "Create a map mask(double) (nside) between latitudes lat1,lat2 longitudes lon1,lon2"; 161 usage += "\n Usage: crmapmask mapmsk(double) nside lat1,lat2 lon1,lon2 [valmsk,valnomsk]"; 145 162 usage += "\n mask pixels between [lat1,lat2] ([-90,90] in degrees)"; 146 163 usage += "\n and [lon1,lon2] ([0,360[ in degrees)"; … … 152 169 153 170 kw = "crmaskfrmap"; 154 usage = "Create a map mask (nside) relative to an other mappixels values";155 usage += "\n Usage: crmaskfrmap mapmsk nside map(double) v1,v2 [valmsk,valnomsk]";171 usage = "Create a map mask(double) (nside) relative to an other map(double) pixels values"; 172 usage += "\n Usage: crmaskfrmap mapmsk(double) nside map(double) v1,v2 [valmsk,valnomsk]"; 156 173 usage += "\n mask if v1<mapmsk(i)<v2"; 157 174 usage += "\n valmsk=value to be written into masked pixels (def=0)"; … … 160 177 161 178 kw = "maskmap"; 162 usage = "Mask a map with a mask map";179 usage = "Mask a map(double) with a mask map(double)"; 163 180 usage += "\n Usage: maskmap map msk"; 164 181 usage += "\n operation is map(i) *= msk(theta,phi)"; … … 166 183 167 184 kw = "maproj"; 168 usage = "Project a map into an other one";169 usage += "\n Usage: maproj map mapproj[nside]";185 usage = "Project a map(double) into an other one"; 186 usage += "\n Usage: maproj map(double) mapproj(double) [nside]"; 170 187 usage += "\n Create mapproj(nside) and project map into mapproj"; 171 188 usage += "\n (use \"maproj map mapproj\" to make a copy)"; … … 173 190 174 191 kw = "map2local"; 175 usage = "Project a map into a local map";176 usage += "\n Usage: map2local map localmapnx,ny angleX,angleY phi0,theta0 [x0,y0] [angle]";192 usage = "Project a map(double) into a local map(double)"; 193 usage += "\n Usage: map2local map(double) localmap(double) nx,ny angleX,angleY phi0,theta0 [x0,y0] [angle]"; 177 194 usage += "\n nx,ny: number of pixels in x(col),y(row) direction"; 178 195 usage += "\n X-axis==phi, Y-axis==theta"; … … 185 202 186 203 kw = "mapop"; 187 usage = "operation on a map ";188 usage += "\n Usage: mapop map op1 map1 [op2 map2] [op2 map3] [...]";204 usage = "operation on a map(double)"; 205 usage += "\n Usage: mapop map(double) op1 map1(double) [op2 map2(double)] [op2 map3(double)] [...]"; 189 206 usage += "\n Do \"map op1= map1\", \"map op2=map2\", ..."; 190 207 usage += "\n where op = +,-,*,/"; … … 192 209 193 210 kw = "mapstat"; 194 usage = "Statistics from a map ";195 usage += "\n Usage: mapstat map [msk] [meanvarname] [sigmavarname]";211 usage = "Statistics from a map(double)"; 212 usage += "\n Usage: mapstat map(double) [msk(double)] [meanvarname] [sigmavarname]"; 196 213 usage += "\n msk = mask sphere used as weight"; 197 214 usage += "\n if msk(i)<=0 do not use that pixel"; … … 203 220 mpiac->RegisterCommand(kw, usage, this, hgrp); 204 221 222 kw = "alm2cl"; 223 usage = "Project alm to cl"; 224 usage += "\n Usage: alm2cl alm cl"; 225 mpiac->RegisterCommand(kw, usage, this, hgrp); 226 227 kw = "cl2llcl"; 228 usage = "Project cl to l*(l+1)*cl"; 229 usage += "\n Usage: cl2llcl cl llcl"; 230 mpiac->RegisterCommand(kw, usage, this, hgrp); 231 232 kw = "clmean"; 233 usage = "Compute mean for a cl vector"; 234 usage += "\n Usage: clmean cl imin,imax [meanvarname]"; 235 usage += "\n imin,imax = compute between these indices"; 236 usage += "\n meanvarname = variable name to store mean"; 237 mpiac->RegisterCommand(kw, usage, this, hgrp); 238 239 kw = "clmult"; 240 usage = "Multiply a cl by a constant"; 241 usage += "\n Usage: clmult cl val"; 242 mpiac->RegisterCommand(kw, usage, this, hgrp); 243 244 kw = "clop"; 245 usage = "operation on a cl"; 246 usage += "\n Usage: clop cl(double) op1 cl1(double) [op2 cl2(double)] [op2 cl3(double)] [...]"; 247 usage += "\n Do \"cl op1= cl1\", \"cl op2=cl2\", ..."; 248 usage += "\n where op = +,-,*,/"; 249 mpiac->RegisterCommand(kw, usage, this, hgrp); 250 251 kw = "clrebin"; 252 usage = "rebin a cl into an ntuple"; 253 usage += "\n Usage: clrebin cl ntuple nbin,bin0"; 254 usage += "\n nbin: rebin by nbin"; 255 usage += "\n bin0: begin rebinning at bin bin0 (def=0)"; 256 mpiac->RegisterCommand(kw, usage, this, hgrp); 257 258 kw = "varop"; 259 usage = "operation on variables"; 260 usage += "\n Usage: varop var1 op var2 [resultvarname]"; 261 usage += "\n Do result = var1 op var2"; 262 usage += "\n where op = +,-,*,/,^(pow),exp,sqrt,log,log10"; 263 usage += "\n resultvarname = variable name to store the result"; 264 mpiac->RegisterCommand(kw, usage, this, hgrp); 265 205 266 DefTypMap = HealPix; 206 267 } … … 229 290 } 230 291 Map2Double(tokens); 292 } else if(kw == "map2float") { 293 if(tokens.size()<1) { 294 cout<<"Usage: map2float map"<<endl; 295 return(0); 296 } 297 Map2Float(tokens); 231 298 } else if(kw == "map2map") { 232 299 if(tokens.size()<2) { … … 313 380 } 314 381 MapStat(tokens); 382 } else if(kw == "alm2cl") { 383 if(tokens.size()<2) { 384 cout<<"Usage: alm2cl alm cl"<<endl; 385 return(0); 386 } 387 Alm2Cl(tokens); 388 } else if(kw == "cl2llcl") { 389 if(tokens.size()<2) { 390 cout<<"Usage: cl2llcl cl llcl"<<endl; 391 return(0); 392 } 393 Cl2llCl(tokens); 394 } else if(kw == "clmean") { 395 if(tokens.size()<1) { 396 cout<<"Usage: clmean cl imin,imax [meanvarname]"<<endl; 397 return(0); 398 } 399 ClMean(tokens); 400 } else if(kw == "clmult") { 401 if(tokens.size()<1) { 402 cout<<"Usage: clmult cl val"<<endl; 403 return(0); 404 } 405 ClMult(tokens); 406 } else if(kw == "clop") { 407 if(tokens.size()<3) { 408 cout<<"Usage: clop cl op1 cl1 [op2 cl2] [op2 cl3] [...]"<<endl; 409 return(0); 410 } 411 ClOper(tokens); 412 } else if(kw == "clrebin") { 413 if(tokens.size()<2) { 414 cout<<"Usage: clrebin cl ntuple nbin,bin0"<<endl; 415 return(0); 416 } 417 ClRebin(tokens); 418 } else if(kw == "varop") { 419 if(tokens.size()<2) { 420 cout<<"Usage: varop var1 op var2 [resultvarname]"<<endl; 421 return(0); 422 } 423 VarOper(tokens); 315 424 } 316 425 … … 372 481 373 482 omg.AddObj(map8,tokens[0]); 483 } 484 485 /* --Methode-- */ 486 void skymapmoduleExecutor::Map2Float(vector<string>& tokens) 487 { 488 NamedObjMgr omg; 489 AnyDataObj* obj=omg.GetObj(tokens[0]); 490 if(obj==NULL) { 491 cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl; 492 return; 493 } 494 SphericalMap<r_8>* map = dynamic_cast<SphericalMap<r_8>*>(obj); 495 if(map==NULL) { 496 cout<<"Error: "<<tokens[0]<<" is not a SphericalMap<r_8>"<<endl; 497 return; 498 } 499 uint_2 t = typemap(obj); 500 int_4 nside = map->SizeIndex(); 501 502 SphericalMap<r_4>* map4 = NULL; 503 if(t&HealPix) map4 = new SphereHEALPix<r_4>(nside); 504 else if(t&ThetaPhi) map4 = new SphereThetaPhi<r_4>(nside); 505 else return; 506 507 cout<<"Map2Float: converting to float "<<tokens[0]<<" nside="<<nside<<endl; 508 for(int_4 i=0;i<map4->NbPixels();i++) (*map4)(i) = (r_4) (*map)(i); 509 510 omg.AddObj(map4,tokens[0]); 374 511 } 375 512 … … 508 645 if(lmax<=0) lmax = 3*nside-1; 509 646 510 cout<<"Map2Cl: "<<tokens[0]<<" -> "<<tokens[1]511 <<" lmax="<<lmax<<" niter="<<niter<<endl;512 513 647 SphericalMap<r_8>* tmpmap = NULL; 514 648 if(t&HealPix) tmpmap = new SphereHEALPix<r_8>(*((SphereHEALPix<r_8>*)map),false); … … 516 650 else return; 517 651 652 cout<<"Map2Cl: "<<tokens[0]<<"(nside="<<nside 653 <<") lmax="<<lmax<<" niter="<<niter<<" -> "<<tokens[1]; 654 518 655 TVector<r_8> cltmp = ylmserver.DecomposeToCl(*tmpmap,lmax,0.,niter); 656 cout<<"("<<cltmp.Size()<<")"<<endl; 519 657 delete tmpmap; 520 658 … … 553 691 SphericalTransformServer<r_8> ylmserver; 554 692 cout<<"Cl2Map: Generate map "<<tokens[1]<<" with nside="<<nside 555 <<" from cl "<<tokens[0]<<" with fwhm="<<fwhm<<endl; 693 <<" from cl "<<tokens[0]<<"("<<cl->Size()<<")" 694 <<" with fwhm="<<fwhm<<endl; 556 695 ylmserver.GenerateFromCl(*map,nside,*cl,fwhm); 557 696 … … 587 726 if(lmax<=0) lmax = 3*nside-1; 588 727 589 cout<<"Map2Alm: "<<tokens[0]<<" -> "<<tokens[1]590 <<" lmax="<<lmax<<" niter="<<niter<<endl;591 592 728 SphericalMap<r_8>* tmpmap = NULL; 593 729 if(t&HealPix) tmpmap = new SphereHEALPix<r_8>(*((SphereHEALPix<r_8>*)map),false); … … 595 731 else return; 596 732 733 cout<<"Map2Alm: "<<tokens[0]<<"(nside="<<nside 734 <<") lmax="<<lmax<<" niter="<<niter<<" -> "<<tokens[1]; 735 597 736 Alm<r_8> almtmp; 598 737 ylmserver.DecomposeToAlm(*tmpmap,almtmp,lmax,0.,niter); 738 cout<<"("<<almtmp.rowNumber()<<")"<<endl; 599 739 delete tmpmap; 600 740 … … 639 779 SphericalTransformServer<r_8> ylmserver; 640 780 cout<<"Alm2Map: Generate map "<<tokens[1]<<" with nside="<<nside 641 <<" from alm "<<tokens[0]<< endl;781 <<" from alm "<<tokens[0]<<"("<<alm.rowNumber()<<")"<<endl; 642 782 ylmserver.GenerateFromAlm(*map,nside,alm); 643 783 … … 931 1071 cout<<"MapOper: "<<tokens[0]; 932 1072 for(unsigned short iop=1;iop<tokens.size()-1;iop+=2) { 933 char op = tokens[iop][0];934 if(op!= '+' && op!='-' && op!='*' && op!='/') continue;1073 string op = tokens[iop]; 1074 if(op!="+" && op!="-" && op!="*" && op!="/") continue; 935 1075 AnyDataObj* obj1=omg.GetObj(tokens[iop+1]); 936 1076 if(obj1==NULL) … … 946 1086 int_4 ip = map1->PixIndexSph(theta,phi); 947 1087 if(ip<0 || ip>=map1->NbPixels()) continue; 948 if(op=='+') (*map)(i) += (*map1)(ip); 949 else if(op=='-') (*map)(i) -= (*map1)(ip); 950 else if(op=='*') (*map)(i) *= (*map1)(ip); 951 else if(op=='/') 952 {if((*map1)(ip)!=0.) (*map)(i) /= (*map1)(ip); 953 else (*map)(i) = 0.;} 1088 if(op=="+") (*map)(i) += (*map1)(ip); 1089 else if(op=="-") (*map)(i) -= (*map1)(ip); 1090 else if(op=="*") (*map)(i) *= (*map1)(ip); 1091 else if(op=="/") 1092 {if((*map1)(ip)!=0.) (*map)(i)/=(*map1)(ip); else (*map)(i)=0.;} 954 1093 } 955 1094 } … … 1035 1174 } 1036 1175 1176 /* --Methode-- */ 1177 void skymapmoduleExecutor::Alm2Cl(vector<string>& tokens) 1178 { 1179 NamedObjMgr omg; 1180 1181 AnyDataObj* obj=omg.GetObj(tokens[0]); 1182 if(obj==NULL) { 1183 cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl; 1184 return; 1185 } 1186 TMatrix< complex<r_8> >* almmat = dynamic_cast<TMatrix< complex<r_8> >*>(obj); 1187 if(almmat==NULL) { 1188 cout<<"Error: "<<tokens[0]<<" is not a TMatrix< complex<r_8> >"<<endl; 1189 return; 1190 } 1191 1192 int lmax = almmat->NRows()-1; 1193 Alm<r_8> alm(lmax); 1194 alm = (complex<r_8>)0.; 1195 for(int i=0;i<lmax+1;i++) for(int j=0;j<=i;j++) alm(i,j)=(*almmat)(i,j); 1196 1197 TVector<r_8> cl(almmat->NRows()); 1198 cl = 0.; 1199 1200 cout<<"Alm2Cl: project alm "<<tokens[0]<<"("<<alm.rowNumber() 1201 <<") to cl "<<tokens[1]<<"("<<cl.Size()<<")"<<endl; 1202 1203 for(int_4 l=0;l<alm.rowNumber();l++) { 1204 cl(l) = alm(l,0).real()*alm(l,0).real()+alm(l,0).imag()*alm(l,0).imag(); 1205 if(l>0) for(int_4 m=1;m<=l;m++) 1206 cl(l) += 2.*(alm(l,m).real()*alm(l,m).real()+alm(l,m).imag()*alm(l,m).imag()); 1207 cl(l) /= 2.*l+1; 1208 } 1209 1210 omg.AddObj(cl,tokens[1]); 1211 } 1212 1213 /* --Methode-- */ 1214 void skymapmoduleExecutor::Cl2llCl(vector<string>& tokens) 1215 { 1216 NamedObjMgr omg; 1217 1218 AnyDataObj* obj=omg.GetObj(tokens[0]); 1219 if(obj==NULL) { 1220 cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl; 1221 return; 1222 } 1223 TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj); 1224 if(cl==NULL) { 1225 cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl; 1226 return; 1227 } 1228 1229 TVector<r_8> llcl(*cl,false); 1230 1231 cout<<"Cl2llCl: project "<<tokens[0]<<"("<<cl->Size() 1232 <<") to l*(l+1)*cl "<<tokens[1]<<"("<<llcl.Size()<<")"<<endl; 1233 1234 for(int_4 l=0;l<llcl.Size();l++) llcl(l) *= (double)l*(l+1.); 1235 1236 omg.AddObj(llcl,tokens[1]); 1237 } 1238 1239 /* --Methode-- */ 1240 void skymapmoduleExecutor::ClMean(vector<string>& tokens) 1241 { 1242 NamedObjMgr omg; 1243 1244 AnyDataObj* obj=omg.GetObj(tokens[0]); 1245 if(obj==NULL) { 1246 cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl; 1247 return; 1248 } 1249 TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj); 1250 if(cl==NULL) { 1251 cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl; 1252 return; 1253 } 1254 1255 int lmin=0, lmax=-1; 1256 if(tokens.size()>1) if(tokens[1][0]!='!') 1257 sscanf(tokens[1].c_str(),"%d,%d",&lmin,&lmax); 1258 if(lmin<0) lmin=0; if(lmax>=cl->Size()) lmax=cl->Size()-1; 1259 if(lmin>lmax) {lmin=0; lmax=cl->Size()-1;} 1260 1261 cout<<"ClMean: compute mean "<<tokens[0]<<"("<<cl->Size() 1262 <<") between ["<<lmin<<","<<lmax<<"]"; 1263 1264 double mean = 0.; 1265 for(int_4 l=lmin;l<=lmax;l++) mean += (*cl)(l); 1266 mean /= lmax-lmin+1; 1267 1268 cout<<" mean="<<mean; 1269 1270 if(tokens.size()>2) { 1271 if(omg.HasVar(tokens[2])) omg.DeleteVar(tokens[2]); 1272 char str[128]; sprintf(str,"%.8f",mean); 1273 omg.SetVar(tokens[2],(string)str); 1274 cout<<" stored into $"<<tokens[2]; 1275 } 1276 cout<<endl; 1277 1278 } 1279 1280 /* --Methode-- */ 1281 void skymapmoduleExecutor::ClMult(vector<string>& tokens) 1282 { 1283 NamedObjMgr omg; 1284 1285 AnyDataObj* obj=omg.GetObj(tokens[0]); 1286 if(obj==NULL) { 1287 cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl; 1288 return; 1289 } 1290 TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj); 1291 if(cl==NULL) { 1292 cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl; 1293 return; 1294 } 1295 1296 double val = 1.; 1297 if(tokens.size()>1) val=atof(tokens[1].c_str()); 1298 1299 cout<<"ClMult: multiply "<<tokens[0]<<"("<<cl->Size()<<") by "<<val<<endl; 1300 1301 *cl *= val; 1302 1303 } 1304 1305 /* --Methode-- */ 1306 void skymapmoduleExecutor::ClOper(vector<string>& tokens) 1307 { 1308 NamedObjMgr omg; 1309 1310 AnyDataObj* obj=omg.GetObj(tokens[0]); 1311 if(obj==NULL) { 1312 cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl; 1313 return; 1314 } 1315 TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj); 1316 if(cl==NULL) { 1317 cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl; 1318 return; 1319 } 1320 1321 cout<<"ClOper: "<<tokens[0]<<"("<<cl->Size()<<")"; 1322 for(unsigned short iop=1;iop<tokens.size()-1;iop+=2) { 1323 string op = tokens[iop]; 1324 if(op!="+" && op!="-" && op!="*" && op!="/") continue; 1325 AnyDataObj* obj1=omg.GetObj(tokens[iop+1]); 1326 if(obj1==NULL) 1327 {cout<<"Error: Pas d'objet de nom "<<tokens[iop+1]<<endl; 1328 continue;} 1329 TVector<r_8>* cl1 = dynamic_cast<TVector<r_8>*>(obj1); 1330 if(cl1==NULL) 1331 {cout<<"Error: "<<tokens[iop+1]<<" is not a TVector<r_8>"<<endl; 1332 continue;} 1333 cout<<" "<<op<<"= "<<tokens[iop+1]<<"("<<cl1->Size()<<")"; 1334 int_4 n=cl->Size(); if(n>cl1->Size()) n=cl1->Size(); 1335 for(int_4 i=0;i<n;i++) { 1336 if(op=="+") (*cl)(i) += (*cl1)(i); 1337 else if(op=="-") (*cl)(i) -= (*cl1)(i); 1338 else if(op=="*") (*cl)(i) *= (*cl1)(i); 1339 else if(op=="/") 1340 {if((*cl1)(i)!=0.) (*cl)(i)/=(*cl1)(i); else (*cl)(i)=0.;} 1341 } 1342 } 1343 cout<<endl; 1344 } 1345 /* --Methode-- */ 1346 void skymapmoduleExecutor::ClRebin(vector<string>& tokens) 1347 { 1348 NamedObjMgr omg; 1349 1350 AnyDataObj* obj=omg.GetObj(tokens[0]); 1351 if(obj==NULL) { 1352 cout<<"Error: Pas d'objet de nom "<<tokens[0]<<endl; 1353 return; 1354 } 1355 TVector<r_8>* cl = dynamic_cast<TVector<r_8>*>(obj); 1356 if(cl==NULL) { 1357 cout<<"Error: "<<tokens[0]<<" is not a TVector<r_8>"<<endl; 1358 return; 1359 } 1360 int_4 nn = cl->Size(); 1361 if(nn<=0) return; 1362 1363 int_4 nrebin=1, ibin0=0; 1364 if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d,%d",&nrebin,&ibin0); 1365 if(ibin0<0 || ibin0>=nn) ibin0=0; 1366 1367 cout<<"ClRebin: rebin "<<tokens[0]<<"("<<nn<<") by nbin="<<nrebin 1368 <<" begin at "<<ibin0<<" -> "<<tokens[1]<<endl; 1369 1370 const int ndim = 8; 1371 char *nament[ndim] = 1372 {"l","n","clmean","cllin","clpar","sclmean","scllin","sclpar"}; 1373 NTuple clbin(ndim,nament); 1374 r_4 xnt[ndim]; 1375 1376 SLinParBuff slp(nrebin+2); 1377 1378 for(int_4 i=ibin0;i<nn;i+=nrebin) { 1379 r_8 ll=0.; 1380 slp.Reset(); 1381 for(int_4 j=0;j<ndim;j++) xnt[j]=0.; 1382 for(int_4 j=i;j<nn;j++) { 1383 ll += (r_8) j; 1384 slp.Push((r_8)j,(*cl)(j)); 1385 if((int_4)slp.NPoints()>=nrebin) break; 1386 } 1387 if(slp.NPoints()<=0) continue; 1388 xnt[0] = ll / (r_8) slp.NPoints(); 1389 xnt[1] = slp.NPoints(); 1390 r_8 s,a0,a1,a2; 1391 s = slp.Compute(a0); 1392 if(s>0.) {xnt[2]=a0; xnt[5]=s;} 1393 s = slp.Compute(a0,a1); 1394 if(s>0.) {xnt[3]=a0+a1*ll; xnt[6]=s;} 1395 s = slp.Compute(a0,a1,a2); 1396 if(s>0.) {xnt[4]=a0+a1*ll+a2*ll*ll; xnt[7]=s;} 1397 clbin.Fill(xnt); 1398 } 1399 1400 omg.AddObj(clbin,tokens[1]); 1401 } 1402 1403 /* --Methode-- */ 1404 void skymapmoduleExecutor::VarOper(vector<string>& tokens) 1405 { 1406 NamedObjMgr omg; 1407 1408 double var1=0., var2=0.; string op = "?"; 1409 if(tokens.size()>0) var1 = atof(tokens[0].c_str()); 1410 if(tokens.size()>1) op = tokens[1]; 1411 if(tokens.size()>2) if(tokens[2][0]!='!') var2 = atof(tokens[2].c_str()); 1412 1413 double result = 0.; 1414 try { 1415 if(op=="+") result = var1 + var2; 1416 else if(op=="-") result = var1 - var2; 1417 else if(op=="*") result = var1 * var2; 1418 else if(op=="/" && var2!=0.) result = var1 / var2; else if(op=="^" && var2>0.) result = pow(var1,var2); 1419 else if(op=="pow" && var2>0.) result = pow(var1,var2); 1420 else if(op=="exp") result = exp(var1); 1421 else if(op=="sqrt" && var1>0.) result = sqrt(var1); 1422 else if(op=="log" && var1>0.) result = log(var1); 1423 else if(op=="log10" && var1>0.) result = log10(var1); 1424 } catch ( ... ) { 1425 cout<<"An operation exception occurs"<<endl; 1426 return; 1427 } 1428 1429 cout<<"VarOper: "<<var1<<" "<<op<<" "<<var2<<" = "<<result; 1430 1431 if(tokens.size()>3) { 1432 if(omg.HasVar(tokens[3])) omg.DeleteVar(tokens[3]); 1433 char str[128]; sprintf(str,"%.8f",result); 1434 omg.SetVar(tokens[3],(string)str); 1435 cout<<" stored into $"<<tokens[3]; 1436 } 1437 cout<<endl; 1438 1439 } 1440 1037 1441 //////////////////////////////////////////////////////////// 1038 1442
Note:
See TracChangeset
for help on using the changeset viewer.