Changeset 1079 in Sophya for trunk


Ignore:
Timestamp:
Jul 23, 2000, 7:35:39 PM (25 years ago)
Author:
ercodmgr
Message:

h/set/err h/set/cont h/err cmv 23/7/00

Location:
trunk/SophyaPI/PIext
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pawexecut.cc

    r1076 r1079  
    146146usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
    147147usage += "\n  Related commands: copy"; 
     148piac->RegisterCommand(kw,usage,this,hgrp);
     149
     150kw = "h/set/err";
     151usage = "Set Histo,Histo2D errors for range of bins or range of values";
     152usage += "\n h/set/err namehisto setvalue i1[:i2]  [j1[:j2]]";
     153usage += "\n     set error to setvalue for bin range i1:i2  j1:j2";
     154usage += "\n h/set/err namehisto setvalue v v1:v2";
     155usage += "\n     set error to setvalue for content values range v1:v2";
     156usage += "\n h/set/err namehisto setvalue e e1:e2";
     157usage += "\n     set error to setvalue for error values range v1:v2";
     158usage += "\n  Related commands: h/set/cont"; 
     159piac->RegisterCommand(kw,usage,this,hgrp);
     160
     161kw = "h/set/cont";
     162usage = "Set Histo,Histo2D content for range of bins or range of values";
     163usage += "\n h/set/cont namehisto setvalue i1[:i2]  [j1[:j2]]";
     164usage += "\n     set content to setvalue for bin range i1:i2  j1:j2";
     165usage += "\n h/set/cont namehisto setvalue v v1:v2";
     166usage += "\n     set content to setvalue for content values range v1:v2";
     167usage += "\n h/set/cont namehisto setvalue e e1:e2";
     168usage += "\n     set content to setvalue for error values range v1:v2";
     169usage += "\n  Related commands: h/set/err"; 
     170piac->RegisterCommand(kw,usage,this,hgrp);
     171
     172kw = "h/err";
     173usage = "Set Histo,Histo2D error to function of bin content value";
     174usage += "\n h/err namehisto expr_func";
     175usage += "\n  Related commands: h/set/err"; 
    148176piac->RegisterCommand(kw,usage,this,hgrp);
    149177
     
    184212} else if(kw == "h/copy") {
    185213  h_copy(tokens); return(0);
     214} else if(kw == "h/set/err") {
     215  string dum = "err";
     216  h_set(dum,tokens); return(0);
     217} else if(kw == "h/set/cont") {
     218  string dum = "cont";
     219  h_set(dum,tokens); return(0);
     220} else if(kw == "h/err") {
     221  h_err(tokens); return(0);
    186222} else return(1);
    187223}
     
    902938// Le contenu de obj?Dfrom non adresse reste le meme
    903939{
    904   int tks = tokens.size();
     940int tks = tokens.size();
    905941if(tks<2)
    906942  {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
     
    10401076return;
    10411077}
     1078
     1079/* methode */
     1080void PAWExecutor::h_set(string dum,vector<string>& tokens)
     1081// Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee
     1082// dum = err  : on change les valeurs des erreurs
     1083//       cont : on change les valeurs du contenu des bins
     1084// tokens[0] : nom de l'histogramme
     1085// tokens[1] : valeur de remplacement
     1086// tokens[2-3] : i1:i2 j1:j2  intervalle des bins qui doivent etre remplace
     1087//             : v v1:v2  remplacement des bins ayant une valeur dans cet intervalle
     1088//             : e e1:e2  remplacement des bins ayant une erreur dans cet intervalle
     1089{
     1090int tks = tokens.size();
     1091if(tks<3)
     1092  {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2]  [j1[:j2]]\n"
     1093       <<"                                           v v1:v2\n"
     1094       <<"                                           e e1:e2"
     1095       <<endl; return;}
     1096
     1097// Decodage arguments
     1098bool replerr = false; if(dum=="err") replerr = true;
     1099float setval = (float) atof(tokens[1].c_str());
     1100int testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2;
     1101int_4 i1=-1, i2=-1, j1=-1, j2=-1;
     1102float v1=0., v2=0.;
     1103if(testcont==0) {
     1104  sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     1105  if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
     1106} else {
     1107  if(tks<=3)
     1108    {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl;
     1109    return;}
     1110  sscanf(tokens[3].c_str(),"%f:%f",&v1,&v2);
     1111}
     1112
     1113if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;}
     1114if(testcont!=0 && v2<v1)
     1115  {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;}
     1116
     1117// identification objet
     1118NamedObjMgr omg;
     1119AnyDataObj* mobj = omg.GetObj(tokens[0]);
     1120if( mobj==NULL)
     1121  {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl;
     1122  return;}
     1123
     1124// Traitement
     1125if(typeid(*mobj) == typeid(Histo)) {  // Histo 1D
     1126  Histo* h  = dynamic_cast<Histo*>(mobj);
     1127  if( (replerr || testcont==2) && !(h->HasErrors()) )
     1128    {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
     1129  if(testcont!=0) {i1=0; i2=h->NBins()-1;}
     1130  if(i1<0 || i1>=h->NBins())
     1131    {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;}
     1132  if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1;
     1133  for(int i=i1;i<=i2;i++) {
     1134    bool change = true;
     1135    if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;}
     1136    else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;}
     1137    if(!change) continue;
     1138    if(replerr) h->Error2(i) = setval; else (*h)(i) = setval;
     1139  }
     1140
     1141} else if(typeid(*mobj) == typeid(Histo2D)) {  // Histo 2D
     1142  Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
     1143  if( (replerr || testcont==2) && !(h2->HasErrors()) )
     1144    {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
     1145  if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;}
     1146  if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY())
     1147    {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;}
     1148  if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1;
     1149  if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1;
     1150  for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
     1151    bool change = true;
     1152    if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;}
     1153    else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;}
     1154    if(!change) continue;
     1155    if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval;
     1156  }
     1157
     1158} else {
     1159  cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n"
     1160    <<typeid(*mobj).name()<<endl;
     1161  return;
     1162}
     1163
     1164}
     1165
     1166/* methode */
     1167void PAWExecutor::h_err(vector<string>& tokens)
     1168// Mise des erreurs d'un histo 1D ou 2D a une valeur
     1169// donnee par une fonction de la valeur du bin
     1170// tokens[0] : nom de l'histogramme
     1171// tokens[1] : expression de la fonction
     1172{
     1173if(tokens.size()<2)
     1174  {cout<<"Usage: h/err namehisto expr_func"<<endl; return;}
     1175
     1176// identification objet
     1177NamedObjMgr omg;
     1178AnyDataObj* mobj = omg.GetObj(tokens[0]);
     1179if( mobj==NULL)
     1180  {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl;
     1181  return;}
     1182
     1183// Fonction
     1184FILE *fip = NULL;
     1185string expfunc = ""; {for(int i=1;i<(int)tokens.size();i++) expfunc += tokens[i];}
     1186string fname = "func1or2_pia_dl.c";
     1187string func = "func1or2_pia_dl_func";
     1188if((fip = fopen(fname.c_str(), "w")) == NULL)
     1189  {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl;
     1190  return;}
     1191fprintf(fip,"#include <math.h>\n");
     1192fprintf(fip,"double %s(double x) \n{\n",func.c_str());
     1193fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
     1194fclose(fip);
     1195DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func);
     1196if(!f)
     1197  {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl;
     1198  return;}
     1199
     1200// Traitement
     1201if(typeid(*mobj) == typeid(Histo)) {  // Histo 1D
     1202  Histo* h  = dynamic_cast<Histo*>(mobj);
     1203  if(!(h->HasErrors())) h->Errors();
     1204  for(int i=0;i<h->NBins();i++) {
     1205    double x = (double) (*h)(i);
     1206    double e = f(x);
     1207    h->SetErr2(i,e*e);
     1208  }
     1209
     1210} else if(typeid(*mobj) == typeid(Histo2D)) {  // Histo 2D
     1211  Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
     1212  if(!(h2->HasErrors())) h2->Errors();
     1213  for(int i=0;i<h2->NBinX();i++) for(int j=0;j<h2->NBinY();j++) {
     1214    double x = (double) (*h2)(i,j);
     1215    double e = f(x);
     1216    h2->Error2(i,j) = e*e;
     1217  }
     1218
     1219} else {
     1220  cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n"
     1221    <<typeid(*mobj).name()<<endl;
     1222  return;
     1223}
     1224
     1225}
  • trunk/SophyaPI/PIext/pawexecut.h

    r1070 r1079  
    3333  void h_get_vec(vector<string>& tokens);
    3434  void h_copy(vector<string>& tokens);
     35  void h_set(string dum,vector<string>& tokens);
     36  void h_err(vector<string>& tokens);
    3537  int  decodepawstring(string tokens,string& nameobj
    3638                      ,string& xexp,string& yexp,string& zexp);
Note: See TracChangeset for help on using the changeset viewer.