| [463] | 1 | #include <stdio.h> | 
|---|
|  | 2 | #include <stdlib.h> | 
|---|
|  | 3 | #include <ctype.h> | 
|---|
|  | 4 | #include <iostream.h> | 
|---|
|  | 5 | #include <typeinfo> | 
|---|
|  | 6 |  | 
|---|
| [466] | 7 | #include "strutil.h" | 
|---|
| [463] | 8 | #include "histos.h" | 
|---|
|  | 9 | #include "histos2.h" | 
|---|
| [466] | 10 | #include "hisprof.h" | 
|---|
| [463] | 11 | #include "ntuple.h" | 
|---|
|  | 12 |  | 
|---|
|  | 13 | #include "pawexecut.h" | 
|---|
|  | 14 | #include "nobjmgr.h" | 
|---|
| [466] | 15 | #include "servnobjm.h" | 
|---|
| [1247] | 16 | #include "nomgadapter.h" | 
|---|
| [463] | 17 | #include "pistdimgapp.h" | 
|---|
|  | 18 |  | 
|---|
| [544] | 19 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 20 | #include "cvector.h" | 
|---|
|  | 21 | #include "matrix.h" | 
|---|
|  | 22 | #else | 
|---|
|  | 23 | #include "tmatrix.h" | 
|---|
|  | 24 | #include "tvector.h" | 
|---|
|  | 25 | #endif | 
|---|
|  | 26 |  | 
|---|
| [466] | 27 | /* Reza + cmv  13/10/99 */ | 
|---|
|  | 28 |  | 
|---|
| [1035] | 29 | uint_4 PAWExecutor::autoc_counter_ = 0; | 
|---|
|  | 30 |  | 
|---|
| [466] | 31 | /* methode */ | 
|---|
| [463] | 32 | PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app) | 
|---|
| [466] | 33 | : mApp(app) | 
|---|
| [463] | 34 | { | 
|---|
|  | 35 | string kw, usage; | 
|---|
|  | 36 | string hgrp = "pawCmd"; | 
|---|
| [466] | 37 |  | 
|---|
|  | 38 | kw = "reset"; | 
|---|
|  | 39 | usage = "Reset histograms vectors or matrix"; | 
|---|
|  | 40 | usage += "\n reset nameobj"; | 
|---|
| [463] | 41 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
| [466] | 42 |  | 
|---|
|  | 43 | kw = "n/plot"; | 
|---|
| [1656] | 44 | usage = "Plot NTuple variables a la paw (alias n/pl)"; | 
|---|
| [469] | 45 | usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]"; | 
|---|
|  | 46 | usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"; | 
|---|
|  | 47 | usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"; | 
|---|
|  | 48 | usage += "\n        for default use ! , loop=i1[:i2[:di]]"; | 
|---|
| [466] | 49 | usage += "\n  Related commands: plot2dw plot3d"; | 
|---|
|  | 50 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 51 |  | 
|---|
|  | 52 | kw = "n/proj"; | 
|---|
|  | 53 | usage = "Project NTuple in histogram (1D or 2D) a la paw"; | 
|---|
| [469] | 54 | usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]"; | 
|---|
|  | 55 | usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]"; | 
|---|
|  | 56 | usage += "\n        for default use ! , loop=i1[:i2[:di]]"; | 
|---|
| [1486] | 57 | usage += "\n  Related commands: projh1d projh2d projprof exptovec"; | 
|---|
| [466] | 58 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 59 |  | 
|---|
| [1247] | 60 | kw = "n/scan"; | 
|---|
|  | 61 | usage = "Scan NTuple a la paw"; | 
|---|
|  | 62 | usage += "\n n/scan nameobj[.exp1%exp2%exp3] cut loop"; | 
|---|
|  | 63 | usage += "\n               [-f:filename] [list_of_variables]"; | 
|---|
|  | 64 | usage += "\n  loop : iev1[:iev2[:diev]] or !"; | 
|---|
|  | 65 | usage += "\n  cut  : cut expression or 1. or !"; | 
|---|
|  | 66 | usage += "\n  list_of_variables : default is all variables"; | 
|---|
|  | 67 | usage += "\n                    : var1 var2 var3 ... varn"; | 
|---|
|  | 68 | usage += "\n                    : var1 : var2   (from var1 to var2)"; | 
|---|
|  | 69 | usage += "\n                    :  : var2   (from first variable to var2)"; | 
|---|
|  | 70 | usage += "\n                    : var1 :    (from var1 to last variable)"; | 
|---|
|  | 71 | usage += "\n                  ex: \"v1 : v3 v7 v4 : v6 v2 v9 :\""; | 
|---|
|  | 72 | usage += "\n exp1%exp2%exp3 :"; | 
|---|
|  | 73 | usage += "\n           if given add exp1,exp2,exp3 to the variable list"; | 
|---|
|  | 74 | usage += "\n -f:filename : write into \"filename\", Default is to stdout"; | 
|---|
|  | 75 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 76 |  | 
|---|
| [466] | 77 | kw = "h/integ"; | 
|---|
| [1057] | 78 | usage = "Integrate a 1D histogram"; | 
|---|
| [466] | 79 | usage += "\n h/integ nameh1d [norm]"; | 
|---|
| [1057] | 80 | usage += "\n  Related commands: h/deriv"; | 
|---|
| [466] | 81 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | kw = "h/deriv"; | 
|---|
| [1057] | 84 | usage = "Derivate a 1D histogram"; | 
|---|
| [466] | 85 | usage += "\n h/deriv nameh1d"; | 
|---|
| [1057] | 86 | usage += "\n  Related commands: h/integ"; | 
|---|
| [466] | 87 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 88 |  | 
|---|
|  | 89 | kw = "h/rebin"; | 
|---|
|  | 90 | usage = "Rebin a 1D histogram or profile"; | 
|---|
| [1057] | 91 | usage += "\n h/rebin nameh1d nbin"; | 
|---|
| [466] | 92 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 93 |  | 
|---|
|  | 94 | kw = "h/cadd"; | 
|---|
| [1073] | 95 | usage = "Add a constant to an histogram, a vector or a matrix"; | 
|---|
| [1057] | 96 | usage += "\n h/cadd namehisto val"; | 
|---|
| [1054] | 97 | usage += "\n  Related commands: h/cmult h/oper"; | 
|---|
| [466] | 98 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 99 |  | 
|---|
|  | 100 | kw = "h/cmult"; | 
|---|
| [1073] | 101 | usage = "Multiply an histogram, a vector or a matrix by a constant"; | 
|---|
| [1057] | 102 | usage += "\n h/cmult namehisto val"; | 
|---|
| [1054] | 103 | usage += "\n  Related commands: h/cadd h/oper"; | 
|---|
| [466] | 104 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 105 |  | 
|---|
| [1054] | 106 | kw = "h/oper"; | 
|---|
| [1073] | 107 | usage = "Operation on histograms vectors or matrices"; | 
|---|
| [1054] | 108 | usage += "\n h/oper @ h1 h2 hres"; | 
|---|
|  | 109 | usage += "\n        hres = h1 @ h2   with @ = (+,-,*,/)"; | 
|---|
| [1073] | 110 | usage += "\n For vectors and matrices, operations are elements by elements"; | 
|---|
| [1054] | 111 | usage += "\n  Related commands: h/cadd h/cmult"; | 
|---|
|  | 112 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 113 |  | 
|---|
| [466] | 114 | kw = "h/plot/2d"; | 
|---|
|  | 115 | usage = "Specific plot for 2D histogrammes"; | 
|---|
|  | 116 | usage += "\n h/plot/2d nameh2d show        : infos on 2D histogramme"; | 
|---|
|  | 117 | usage += "\n h/plot/2d nameh2d h    [dopt] : plot 2D histogramme"; | 
|---|
|  | 118 | usage += "\n h/plot/2d nameh2d px   [dopt] : plot X projection"; | 
|---|
|  | 119 | usage += "\n h/plot/2d nameh2d py   [dopt] : plot Y projection"; | 
|---|
|  | 120 | usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n"; | 
|---|
|  | 121 | usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n"; | 
|---|
|  | 122 | usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n"; | 
|---|
|  | 123 | usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n"; | 
|---|
|  | 124 | usage += "\n                      n < 0 means Show Info"; | 
|---|
|  | 125 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
| [1065] | 126 |  | 
|---|
|  | 127 | kw = "h/put_vec"; | 
|---|
|  | 128 | usage = "Put content of vector (matrix) into content of histogram 1D or 2D"; | 
|---|
|  | 129 | usage += "\n h/put_vec nameh1d namevector [cont,err2]"; | 
|---|
|  | 130 | usage += "\n h/put_vec nameh2d namematrix [cont,err2]"; | 
|---|
|  | 131 | usage += "\n     cont : put into histogramme content"; | 
|---|
|  | 132 | usage += "\n     err2 : put into histogramme error^2"; | 
|---|
|  | 133 | usage += "\n  Related commands: h/get_vec"; | 
|---|
|  | 134 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 135 |  | 
|---|
|  | 136 | kw = "h/get_vec"; | 
|---|
|  | 137 | usage = "Get content of histogram 1D profile or 2D into vector (matrix)"; | 
|---|
|  | 138 | usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]"; | 
|---|
|  | 139 | usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]"; | 
|---|
|  | 140 | usage += "\n   cont : get histogramme content"; | 
|---|
|  | 141 | usage += "\n   err2 : get histogramme error^2"; | 
|---|
|  | 142 | usage += "\n   absc : get histogramme low bin abscissa (1D only)"; | 
|---|
|  | 143 | usage += "\n     proj :"; | 
|---|
|  | 144 | usage += "\n            show  : show available projections for Histo2D"; | 
|---|
|  | 145 | usage += "\n            px    : get X projection"; | 
|---|
|  | 146 | usage += "\n            py    : get Y projection"; | 
|---|
|  | 147 | usage += "\n            bx n  : get X band number n"; | 
|---|
|  | 148 | usage += "\n            by n  : get Y band number n"; | 
|---|
|  | 149 | usage += "\n            sx n  : get X slice number n"; | 
|---|
|  | 150 | usage += "\n            sy n  : get Y slice number n"; | 
|---|
|  | 151 | usage += "\n  Related commands: h/put_vec"; | 
|---|
|  | 152 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 153 |  | 
|---|
| [1070] | 154 | kw = "h/copy"; | 
|---|
| [1073] | 155 | usage = "Copy content of object1 into object2"; | 
|---|
| [1070] | 156 | usage += "\n objects are Vector,Matrix,Histo,Histo2D"; | 
|---|
| [1071] | 157 | usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"; | 
|---|
|  | 158 | usage += "\n   copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)"; | 
|---|
|  | 159 | usage += "\n   copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)"; | 
|---|
|  | 160 | usage += "\n Warning: elements from i1 to i2 included are copied"; | 
|---|
|  | 161 | usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1"; | 
|---|
|  | 162 | usage += "\n    or obj2Dto with size i2-i1+1,j2-j1+1"; | 
|---|
|  | 163 | usage += "\n The adressed content of obj?Dfrom is overwritten"; | 
|---|
|  | 164 | usage += "\n The non-adressed content of obj?Dfrom is left unchanged"; | 
|---|
| [1070] | 165 | usage += "\n  Related commands: copy"; | 
|---|
|  | 166 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 167 |  | 
|---|
| [1079] | 168 | kw = "h/set/err"; | 
|---|
|  | 169 | usage = "Set Histo,Histo2D errors for range of bins or range of values"; | 
|---|
|  | 170 | usage += "\n h/set/err namehisto setvalue i1[:i2]  [j1[:j2]]"; | 
|---|
|  | 171 | usage += "\n     set error to setvalue for bin range i1:i2  j1:j2"; | 
|---|
|  | 172 | usage += "\n h/set/err namehisto setvalue v v1:v2"; | 
|---|
|  | 173 | usage += "\n     set error to setvalue for content values range v1:v2"; | 
|---|
|  | 174 | usage += "\n h/set/err namehisto setvalue e e1:e2"; | 
|---|
|  | 175 | usage += "\n     set error to setvalue for error values range v1:v2"; | 
|---|
|  | 176 | usage += "\n  Related commands: h/set/cont"; | 
|---|
|  | 177 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 178 |  | 
|---|
|  | 179 | kw = "h/set/cont"; | 
|---|
|  | 180 | usage = "Set Histo,Histo2D content for range of bins or range of values"; | 
|---|
|  | 181 | usage += "\n h/set/cont namehisto setvalue i1[:i2]  [j1[:j2]]"; | 
|---|
|  | 182 | usage += "\n     set content to setvalue for bin range i1:i2  j1:j2"; | 
|---|
|  | 183 | usage += "\n h/set/cont namehisto setvalue v v1:v2"; | 
|---|
|  | 184 | usage += "\n     set content to setvalue for content values range v1:v2"; | 
|---|
|  | 185 | usage += "\n h/set/cont namehisto setvalue e e1:e2"; | 
|---|
|  | 186 | usage += "\n     set content to setvalue for error values range v1:v2"; | 
|---|
|  | 187 | usage += "\n  Related commands: h/set/err"; | 
|---|
|  | 188 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 189 |  | 
|---|
|  | 190 | kw = "h/err"; | 
|---|
|  | 191 | usage = "Set Histo,Histo2D error to function of bin content value"; | 
|---|
|  | 192 | usage += "\n h/err namehisto expr_func"; | 
|---|
|  | 193 | usage += "\n  Related commands: h/set/err"; | 
|---|
|  | 194 | piac->RegisterCommand(kw,usage,this,hgrp); | 
|---|
|  | 195 |  | 
|---|
| [463] | 196 | } | 
|---|
|  | 197 |  | 
|---|
| [466] | 198 | /* methode */ | 
|---|
| [463] | 199 | PAWExecutor::~PAWExecutor() | 
|---|
|  | 200 | { | 
|---|
|  | 201 | } | 
|---|
|  | 202 |  | 
|---|
| [466] | 203 | /* methode */ | 
|---|
| [1268] | 204 | int PAWExecutor::Execute(string& kw, vector<string>& tokens, string& toks) | 
|---|
| [463] | 205 | { | 
|---|
| [466] | 206 | if(kw == "reset") { | 
|---|
|  | 207 | reset(tokens); return(0); | 
|---|
| [1656] | 208 | } else if(kw == "n/plot" || kw == "n/pl") { | 
|---|
| [466] | 209 | n_plot(tokens); return(0); | 
|---|
|  | 210 | } else if(kw == "n/proj") { | 
|---|
|  | 211 | n_proj(tokens); return(0); | 
|---|
| [1247] | 212 | } else if(kw == "n/scan") { | 
|---|
|  | 213 | n_scan(tokens); return(0); | 
|---|
| [466] | 214 | } else if(kw == "h/integ") { | 
|---|
|  | 215 | h_integ(tokens); return(0); | 
|---|
|  | 216 | } else if(kw == "h/deriv") { | 
|---|
|  | 217 | h_deriv(tokens); return(0); | 
|---|
|  | 218 | } else if(kw == "h/rebin") { | 
|---|
|  | 219 | h_rebin(tokens); return(0); | 
|---|
|  | 220 | } else if(kw == "h/cadd") { | 
|---|
|  | 221 | h_cadd(tokens); return(0); | 
|---|
|  | 222 | } else if(kw == "h/cmult") { | 
|---|
|  | 223 | h_cmult(tokens); return(0); | 
|---|
| [1054] | 224 | } else if(kw == "h/oper") { | 
|---|
|  | 225 | h_oper(tokens); return(0); | 
|---|
| [466] | 226 | } else if(kw == "h/plot/2d") { | 
|---|
|  | 227 | h_plot_2d(tokens); return(0); | 
|---|
| [1065] | 228 | } else if(kw == "h/put_vec") { | 
|---|
|  | 229 | h_put_vec(tokens); return(0); | 
|---|
|  | 230 | } else if(kw == "h/get_vec") { | 
|---|
|  | 231 | h_get_vec(tokens); return(0); | 
|---|
| [1070] | 232 | } else if(kw == "h/copy") { | 
|---|
|  | 233 | h_copy(tokens); return(0); | 
|---|
| [1079] | 234 | } else if(kw == "h/set/err") { | 
|---|
|  | 235 | string dum = "err"; | 
|---|
|  | 236 | h_set(dum,tokens); return(0); | 
|---|
|  | 237 | } else if(kw == "h/set/cont") { | 
|---|
|  | 238 | string dum = "cont"; | 
|---|
|  | 239 | h_set(dum,tokens); return(0); | 
|---|
|  | 240 | } else if(kw == "h/err") { | 
|---|
|  | 241 | h_err(tokens); return(0); | 
|---|
| [466] | 242 | } else return(1); | 
|---|
|  | 243 | } | 
|---|
|  | 244 |  | 
|---|
|  | 245 | /* methode */ | 
|---|
|  | 246 | void PAWExecutor::reset(vector<string>& tokens) | 
|---|
|  | 247 | // Reset d'histogrammes, vecteurs et matrices | 
|---|
|  | 248 | { | 
|---|
|  | 249 | if(tokens.size() < 1) | 
|---|
| [469] | 250 | {cout<<"Usage: reset nameobj"<<endl; return;} | 
|---|
| [466] | 251 | NamedObjMgr omg; | 
|---|
|  | 252 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 253 | if(mobj == NULL) | 
|---|
|  | 254 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl; | 
|---|
|  | 255 | return;} | 
|---|
|  | 256 | string ctyp = typeid(*mobj).name(); | 
|---|
|  | 257 |  | 
|---|
| [545] | 258 | #ifdef SANS_EVOLPLANCK | 
|---|
| [466] | 259 | if(typeid(*mobj)==typeid(Vector))       {Vector*  ob=(Vector*) mobj; ob->Zero();} | 
|---|
|  | 260 | else if(typeid(*mobj)==typeid(Matrix))  {Matrix*  ob=(Matrix*) mobj; ob->Zero();} | 
|---|
| [545] | 261 | #else | 
|---|
| [815] | 262 | if(typeid(*mobj)==typeid(Vector))       {Vector*  ob=(Vector*) mobj; (*ob) = 0.; } | 
|---|
|  | 263 | // ob->DataBlock().Reset(0.);} | 
|---|
|  | 264 | else if(typeid(*mobj)==typeid(Matrix))   {Matrix*  ob=(Matrix*) mobj; (*ob) = 0.; } | 
|---|
|  | 265 | //ob->DataBlock().Reset(0.);} | 
|---|
| [545] | 266 | #endif | 
|---|
| [466] | 267 | else if(typeid(*mobj)==typeid(Histo))   {Histo*   ob=(Histo*)  mobj; ob->Zero();} | 
|---|
|  | 268 | else if(typeid(*mobj)==typeid(HProf))   {HProf*   ob=(HProf*)  mobj; ob->Zero();} | 
|---|
|  | 269 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();} | 
|---|
|  | 270 | else { | 
|---|
|  | 271 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl; | 
|---|
|  | 272 | return; | 
|---|
|  | 273 | } | 
|---|
|  | 274 |  | 
|---|
|  | 275 | return; | 
|---|
|  | 276 | } | 
|---|
|  | 277 |  | 
|---|
|  | 278 | /* methode */ | 
|---|
|  | 279 | void PAWExecutor::n_plot(vector<string>& tokens) | 
|---|
|  | 280 | // Equivalent n/plot de paw | 
|---|
|  | 281 | // Plot 1D | 
|---|
|  | 282 | //   n/plot nameobj.x_exp [cut] [w_exp] [gratt] | 
|---|
|  | 283 | // Plot 2D (plot2dw) | 
|---|
|  | 284 | //   n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt] | 
|---|
|  | 285 | // Plot 3D (plot3d) | 
|---|
|  | 286 | //   n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt] | 
|---|
|  | 287 | { | 
|---|
|  | 288 | if(tokens.size() < 1) { | 
|---|
|  | 289 | cout | 
|---|
| [1035] | 290 | <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl | 
|---|
| [469] | 291 | <<"       n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl | 
|---|
|  | 292 | <<"       n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl | 
|---|
|  | 293 | <<"              for default use ! , loop=i1[:i2[:di]]"<<endl; | 
|---|
| [466] | 294 | return; | 
|---|
|  | 295 | } | 
|---|
|  | 296 | string nameobj,expx,expy,expz; | 
|---|
| [1247] | 297 | int_4 nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz); | 
|---|
| [1035] | 298 | string expcut = "1"; string expwt = "1."; string loop = ""; | 
|---|
|  | 299 | string dopt = ""; string nameproj=""; | 
|---|
| [469] | 300 | if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1"; | 
|---|
| [466] | 301 |  | 
|---|
|  | 302 | NamedObjMgr omg; | 
|---|
|  | 303 | Services2NObjMgr* srvo = omg.GetServiceObj(); | 
|---|
|  | 304 |  | 
|---|
|  | 305 | if(nvar<=0) { | 
|---|
|  | 306 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl; | 
|---|
|  | 307 | } else if(nvar==1) { // c'est un plot 1D | 
|---|
| [1035] | 308 | if(tokens.size()>=3) expwt    = tokens[2]; if(expwt=="!") expwt="1."; | 
|---|
|  | 309 | if(tokens.size()>=4) loop     = tokens[3]; if(loop=="!") loop=""; | 
|---|
|  | 310 | if(tokens.size()>=5) dopt     = tokens[4]; if(dopt=="!") dopt=""; | 
|---|
|  | 311 | if(tokens.size()>=6) nameproj = tokens[5]; | 
|---|
|  | 312 | if(nameproj.length()<=0 || nameproj=="!") { | 
|---|
|  | 313 | nameproj = "/autoc/paw_n_plot1D_"; | 
|---|
|  | 314 | AnyDataObj* mobj = omg.GetObj(nameproj); | 
|---|
|  | 315 | if(mobj!=NULL) { | 
|---|
|  | 316 | char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_); | 
|---|
|  | 317 | nameproj += buff; | 
|---|
|  | 318 | } | 
|---|
|  | 319 | } | 
|---|
| [466] | 320 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop); | 
|---|
|  | 321 | } else if(nvar==2) { // c'est un plot 2D | 
|---|
| [469] | 322 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop=""; | 
|---|
|  | 323 | if(tokens.size()>=4) dopt = tokens[3]; | 
|---|
|  | 324 | string err = ""; | 
|---|
|  | 325 | srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop); | 
|---|
| [466] | 326 | } else {             // c'est un plot 3D | 
|---|
| [469] | 327 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop=""; | 
|---|
|  | 328 | if(tokens.size()>=4) dopt = tokens[3]; | 
|---|
| [466] | 329 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop); | 
|---|
|  | 330 | } | 
|---|
|  | 331 |  | 
|---|
|  | 332 | return; | 
|---|
|  | 333 | } | 
|---|
|  | 334 |  | 
|---|
|  | 335 | /* methode */ | 
|---|
|  | 336 | void PAWExecutor::n_proj(vector<string>& tokens) | 
|---|
|  | 337 | // Equivalent n/proj de paw | 
|---|
|  | 338 | // Project NTuple in histogram a la paw | 
|---|
|  | 339 | // Dans un Histo 1D | 
|---|
|  | 340 | //   n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt] | 
|---|
|  | 341 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree). | 
|---|
|  | 342 | //   n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt] | 
|---|
|  | 343 | { | 
|---|
|  | 344 | if(tokens.size()<2) | 
|---|
| [469] | 345 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl | 
|---|
|  | 346 | <<"              for default use ! , loop=i1[:i2[:di]]"<<endl; return;} | 
|---|
| [466] | 347 | string nameproj = tokens[0]; | 
|---|
|  | 348 | string nameobj,expx,expy,expz; | 
|---|
| [1247] | 349 | int_4 nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz); | 
|---|
| [469] | 350 | string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = ""; | 
|---|
|  | 351 | if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1"; | 
|---|
|  | 352 | if(tokens.size()>=4) expwt  = tokens[3]; if(expwt=="!") expwt="1."; | 
|---|
|  | 353 | if(tokens.size()>=5) loop   = tokens[4]; if(loop=="!") loop=""; | 
|---|
|  | 354 | if(tokens.size()>=6) dopt   = tokens[5]; | 
|---|
| [466] | 355 |  | 
|---|
|  | 356 | NamedObjMgr omg; | 
|---|
|  | 357 | Services2NObjMgr* srvo = omg.GetServiceObj(); | 
|---|
|  | 358 |  | 
|---|
| [1076] | 359 | if(nvar==1) { | 
|---|
| [466] | 360 | // c'est une projection dans un histo 1D | 
|---|
|  | 361 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop); | 
|---|
| [1076] | 362 | } else if(nvar==2) { | 
|---|
| [466] | 363 | // c'est une projection dans un histo2D | 
|---|
| [1076] | 364 | // OU un HProf si nameproj est un HProf un deja defini | 
|---|
| [466] | 365 | AnyDataObj* mobj = omg.GetObj(nameproj); | 
|---|
|  | 366 | if(mobj==NULL) | 
|---|
|  | 367 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop); | 
|---|
|  | 368 | else if(dynamic_cast<HProf*>(mobj)) | 
|---|
|  | 369 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop); | 
|---|
|  | 370 | else | 
|---|
|  | 371 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop); | 
|---|
| [1076] | 372 | } else { | 
|---|
|  | 373 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<" nvar="<<nvar<<endl; | 
|---|
| [466] | 374 | } | 
|---|
|  | 375 |  | 
|---|
|  | 376 | return; | 
|---|
|  | 377 | } | 
|---|
|  | 378 |  | 
|---|
|  | 379 | /* methode */ | 
|---|
| [1247] | 380 | void PAWExecutor::n_scan(vector<string>& tokens) | 
|---|
|  | 381 | { | 
|---|
|  | 382 | if(tokens.size()<3) | 
|---|
|  | 383 | {cerr<<"Usage: n/scan nameobj[.exp1%exp2%exp3] cut loop\n" | 
|---|
|  | 384 | <<"       [-f:filename] [list_of_variables]"<<endl; return;} | 
|---|
|  | 385 |  | 
|---|
|  | 386 | // decodage des premiers arguments | 
|---|
|  | 387 | string nameobj,expr[4]; | 
|---|
|  | 388 | int_4 nexpr = decodepawstring(tokens[0],nameobj,expr[0],expr[1],expr[2]); | 
|---|
|  | 389 | if(nexpr<4) {for(int_4 i=nexpr;i<4;i++) expr[i]="1.";} | 
|---|
|  | 390 | string expcut = tokens[1]; if(expcut=="!") expcut="1"; | 
|---|
|  | 391 | string loop   = tokens[2]; if(loop=="!") loop=""; | 
|---|
|  | 392 | FILE* fout = NULL; | 
|---|
|  | 393 | uint_4 ldebvar = 3; | 
|---|
|  | 394 | if(tokens.size()>3) { | 
|---|
|  | 395 | if(tokens[3].find("-f:") == 0) { | 
|---|
|  | 396 | string filename = tokens[3].substr(3); | 
|---|
|  | 397 | if(filename.size()>0) { | 
|---|
|  | 398 | fout = fopen(filename.c_str(),"w"); | 
|---|
|  | 399 | if(fout==NULL) | 
|---|
|  | 400 | {cerr<<"PAWExecutor::n_scan Error, file "<<filename | 
|---|
|  | 401 | <<" not opened"<<endl; return;} | 
|---|
|  | 402 | } | 
|---|
|  | 403 | ldebvar++; | 
|---|
|  | 404 | } | 
|---|
|  | 405 | } | 
|---|
|  | 406 |  | 
|---|
|  | 407 | // ntuple adaptateur | 
|---|
|  | 408 | NamedObjMgr omg; | 
|---|
|  | 409 | Services2NObjMgr& srvo = *omg.GetServiceObj(); | 
|---|
|  | 410 | NObjMgrAdapter* obja = omg.GetObjAdapter(nameobj); // Ne pas deleter | 
|---|
|  | 411 | if(obja == NULL) | 
|---|
|  | 412 | {cerr<<"PAWExecutor::n_scan Error, ObjAdapter==NULL for " | 
|---|
|  | 413 | <<nameobj<<endl; return;} | 
|---|
|  | 414 | bool adel = true; | 
|---|
|  | 415 | NTupleInterface* objnt = obja->GetNTupleInterface(adel); | 
|---|
|  | 416 | if(objnt == NULL) | 
|---|
|  | 417 | {cerr<<"PAWExecutor::n_scan Error, NTupleInterface==NULL for " | 
|---|
|  | 418 | <<nameobj<<endl; return;} | 
|---|
|  | 419 |  | 
|---|
|  | 420 | // function pour le choix | 
|---|
|  | 421 | string  vardec = objnt->VarList_C("_zz6qi_"); | 
|---|
|  | 422 | PlotExprFunc f = srvo.LinkExprFunc(vardec,expr[0],expr[1],expr[2],expr[3],expcut); | 
|---|
|  | 423 | if(!f) | 
|---|
|  | 424 | {cerr<<"PAWExecutor::n_scan Error, Creation PlotExprFunc"<<endl; | 
|---|
|  | 425 | if(adel) delete objnt; if(fout) fclose(fout); return;} | 
|---|
|  | 426 |  | 
|---|
|  | 427 | // variables a imprimer | 
|---|
|  | 428 | // "rien"          --> de 0 a ncol-1 (toutes les variables) | 
|---|
|  | 429 | // : v1            --> de 0 a v1 | 
|---|
|  | 430 | // v1 :            --> de v1 a ncol-1 | 
|---|
|  | 431 | // v1 : v2         --> de v1 a v2 (si v2 apres v1) | 
|---|
|  | 432 | //                     v1 et v2   (si v2 avant v1) | 
|---|
|  | 433 | // v1 v2 v3 v4     --> v1 v2 v3 v4 (ordre indifferent) | 
|---|
|  | 434 | // et toute combinaison : "v1 : v3 v7 v4 : v6 v2 v9 :" | 
|---|
|  | 435 | //        --> v1 v2 v3  v7  v4 v5 v6  v2  v9 v10...v(ncol-1) | 
|---|
|  | 436 | int_4 ncol = objnt->NbColumns(); | 
|---|
|  | 437 | if(ncol<=0) | 
|---|
|  | 438 | {cerr<<"PAWExecutor::n_scan Error, no columns for NTuple"<<endl; | 
|---|
|  | 439 | return;} | 
|---|
|  | 440 | vector<int_4> varnum; | 
|---|
|  | 441 | if(ldebvar>=tokens.size()) {   // Toutes les variables | 
|---|
|  | 442 | for(int_4 i=0;i<ncol;i++) varnum.push_back(i); | 
|---|
|  | 443 | } else {   // Choix de certaines variables | 
|---|
|  | 444 | int_4 k,klast,kk; bool frlast=false; | 
|---|
|  | 445 | if(tokens[ldebvar]==":") {varnum.push_back(0); frlast=true;} | 
|---|
|  | 446 | else {k = objnt->ColumnIndex(tokens[ldebvar]); varnum.push_back(k);} | 
|---|
|  | 447 | ldebvar++; | 
|---|
|  | 448 | if(ldebvar<tokens.size()) for(uint_4 i=ldebvar;i<tokens.size();i++) { | 
|---|
|  | 449 | if(tokens[i]!=":") {  // pas un separateur | 
|---|
|  | 450 | k = klast = objnt->ColumnIndex(tokens[i]); | 
|---|
|  | 451 | if(frlast) klast = varnum[varnum.size()-1] + 1; | 
|---|
|  | 452 | if(klast>k) klast=k; | 
|---|
|  | 453 | for(kk=klast;kk<=k;kk++) varnum.push_back(kk); | 
|---|
|  | 454 | frlast=false; | 
|---|
|  | 455 | } else if(i==tokens.size()-1) {  // separateur a la fin | 
|---|
|  | 456 | k = ncol-1; | 
|---|
|  | 457 | klast = varnum[varnum.size()-1] + 1; | 
|---|
|  | 458 | if(klast>k) klast=k; | 
|---|
|  | 459 | for(kk=klast;kk<=k;kk++) varnum.push_back(kk); | 
|---|
|  | 460 | } else frlast=true;  // separateur pas a la fin | 
|---|
|  | 461 | } | 
|---|
|  | 462 | } | 
|---|
|  | 463 |  | 
|---|
|  | 464 | vector<string> varname; | 
|---|
|  | 465 | if(varnum.size()>0) for(int_4 i=0;i<(int)varnum.size();i++) { | 
|---|
|  | 466 | if(varnum[i]<0 || varnum[i]>=ncol) | 
|---|
|  | 467 | {cerr<<"PAWExecutor::n_scan Error, bad variable name at pos " | 
|---|
|  | 468 | <<i<<endl; if(adel) delete objnt; if(fout) fclose(fout); return;} | 
|---|
|  | 469 | string dum = objnt->ColumnName(varnum[i]); | 
|---|
|  | 470 | varname.push_back(dum); | 
|---|
|  | 471 | } | 
|---|
|  | 472 |  | 
|---|
|  | 473 | // evenements a utiliser | 
|---|
|  | 474 | int_4 k1=0, k2=objnt->NbLines(), dk=1; | 
|---|
|  | 475 | srvo.DecodeLoopParameters(loop,k1,k2,dk); | 
|---|
|  | 476 | if (k1<0) k1=0; | 
|---|
|  | 477 | if (k2<0) k2=objnt->NbLines(); | 
|---|
|  | 478 | if (k2>(int)objnt->NbLines()) k2=objnt->NbLines(); | 
|---|
|  | 479 | if (dk<=0) dk=1; | 
|---|
|  | 480 |  | 
|---|
|  | 481 | // boucle sur les evenements et print | 
|---|
|  | 482 | try  { | 
|---|
|  | 483 | int_4 i; | 
|---|
|  | 484 | if(fout) fprintf(fout,"#ev "); else printf("#ev "); | 
|---|
|  | 485 | for(i=0;i<(int)varname.size();i++) | 
|---|
|  | 486 | if(fout) fprintf(fout,"%s ",varname[i].c_str()); | 
|---|
|  | 487 | else      printf(     "%s ",varname[i].c_str()); | 
|---|
|  | 488 | if(nexpr>0) for(i=0;i<nexpr;i++) | 
|---|
|  | 489 | if(fout) fprintf(fout,"%s ",expr[i].c_str()); | 
|---|
|  | 490 | else      printf(     "%s ",expr[i].c_str()); | 
|---|
|  | 491 | if(fout) fprintf(fout,"\n"); else printf("\n"); | 
|---|
|  | 492 |  | 
|---|
|  | 493 | double xnt[5]={0,0,0,0,0}; | 
|---|
|  | 494 | double* xn; | 
|---|
|  | 495 | for(int_4 k=k1; k<k2; k += dk)    { | 
|---|
|  | 496 | xn = objnt->GetLineD(k); | 
|---|
|  | 497 | if(f(xn,xnt,xnt+1,xnt+2,xnt+3) != 0) { | 
|---|
|  | 498 | if(fout) fprintf(fout,"%d ",k); else printf("%d ",k); | 
|---|
|  | 499 | for(i=0;i<(int)varnum.size();i++) { | 
|---|
|  | 500 | if(fout) fprintf(fout,"%g ",*(xn+varnum[i])); | 
|---|
|  | 501 | else      printf(     "%g ",*(xn+varnum[i])); | 
|---|
|  | 502 | } | 
|---|
|  | 503 | if(nexpr>0) for(i=0;i<nexpr;i++) { | 
|---|
|  | 504 | if(fout) fprintf(fout,"%g ",*(xnt+i)); | 
|---|
|  | 505 | else      printf(     "%g ",*(xnt+i)); | 
|---|
|  | 506 | } | 
|---|
|  | 507 | if(fout) fprintf(fout,"\n"); else printf("\n"); | 
|---|
|  | 508 | } | 
|---|
|  | 509 | } | 
|---|
|  | 510 | }   // fin du try | 
|---|
|  | 511 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 512 | CATCH(merr) { | 
|---|
|  | 513 | fflush(stdout); cout<<endl; cerr<<endl; | 
|---|
|  | 514 | string es = PeidaExc(merr); | 
|---|
|  | 515 | cerr<<"Services2NObjMgr::ComputeExpressions()  Exception :"<<merr<<es; | 
|---|
|  | 516 | } ENDTRY; | 
|---|
|  | 517 | #else | 
|---|
|  | 518 | catch ( PException exc ) { | 
|---|
|  | 519 | fflush(stdout); cout<<endl; cerr<<endl; | 
|---|
|  | 520 | cerr<<"Services2NObjMgr::ComputeExpressions()  Exception :"<<exc.Msg()<<endl; | 
|---|
|  | 521 | } | 
|---|
|  | 522 | #endif | 
|---|
|  | 523 |  | 
|---|
|  | 524 | if(adel) delete objnt; | 
|---|
|  | 525 | if(fout) fclose(fout); | 
|---|
|  | 526 | srvo.CloseDLL(); // Fermeture du fichier .so | 
|---|
|  | 527 | return; | 
|---|
|  | 528 | } | 
|---|
|  | 529 |  | 
|---|
|  | 530 | /* methode */ | 
|---|
| [466] | 531 | void PAWExecutor::h_integ(vector<string>& tokens) | 
|---|
|  | 532 | // Pour remplacer le contenu d'un histo 1D par son integrale | 
|---|
|  | 533 | { | 
|---|
|  | 534 | if(tokens.size()<1) | 
|---|
|  | 535 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;} | 
|---|
|  | 536 | NamedObjMgr omg; | 
|---|
|  | 537 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 538 | if(mobj==NULL) | 
|---|
|  | 539 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl; | 
|---|
|  | 540 | return;} | 
|---|
| [1091] | 541 | r_8 norm = 1.; | 
|---|
| [466] | 542 | if(tokens.size()>=2) norm = atof(tokens[1].c_str()); | 
|---|
| [1057] | 543 | // attention: dynamic_cast<Histo*>(HProf)=Vrai! | 
|---|
| [466] | 544 | Histo* h1 = dynamic_cast<Histo*>(mobj); | 
|---|
| [1057] | 545 | HProf* hp = dynamic_cast<HProf*>(mobj); | 
|---|
|  | 546 | if(hp || !h1) | 
|---|
|  | 547 | {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl; | 
|---|
|  | 548 | return;} | 
|---|
|  | 549 | h1->HInteg(norm); | 
|---|
| [466] | 550 | } | 
|---|
|  | 551 |  | 
|---|
|  | 552 | /* methode */ | 
|---|
|  | 553 | void PAWExecutor::h_deriv(vector<string>& tokens) | 
|---|
|  | 554 | // Pour remplacer le contenu d'un histo 1D par sa derivee | 
|---|
|  | 555 | { | 
|---|
|  | 556 | if(tokens.size()<1) | 
|---|
|  | 557 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;} | 
|---|
|  | 558 | NamedObjMgr omg; | 
|---|
|  | 559 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 560 | if(mobj==NULL) | 
|---|
|  | 561 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl; | 
|---|
|  | 562 | return;} | 
|---|
| [1057] | 563 | // attention: dynamic_cast<Histo*>(HProf)=Vrai! | 
|---|
| [466] | 564 | Histo* h1 = dynamic_cast<Histo*>(mobj); | 
|---|
| [1057] | 565 | HProf* hp = dynamic_cast<HProf*>(mobj); | 
|---|
|  | 566 | if(hp || !h1) | 
|---|
|  | 567 | {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl; | 
|---|
|  | 568 | return;} | 
|---|
|  | 569 | h1->HDeriv(); | 
|---|
| [466] | 570 | } | 
|---|
|  | 571 |  | 
|---|
|  | 572 | /* methode */ | 
|---|
|  | 573 | void PAWExecutor::h_rebin(vector<string>& tokens) | 
|---|
|  | 574 | // Pour re-binner un histogramme 1D | 
|---|
|  | 575 | { | 
|---|
|  | 576 | if(tokens.size()<2) | 
|---|
|  | 577 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;} | 
|---|
|  | 578 | NamedObjMgr omg; | 
|---|
|  | 579 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 580 | if(mobj==NULL) | 
|---|
|  | 581 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl; | 
|---|
|  | 582 | return;} | 
|---|
| [1091] | 583 | int_4 nbin = atoi(tokens[1].c_str()); | 
|---|
| [466] | 584 | Histo* h1 = dynamic_cast<Histo*>(mobj); | 
|---|
| [1059] | 585 | // Ca marche aussi pour les HProf, HRebin a ete passe virtuel | 
|---|
|  | 586 | //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1) | 
|---|
|  | 587 | if(!h1) | 
|---|
| [1073] | 588 | {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl; | 
|---|
| [1057] | 589 | return;} | 
|---|
|  | 590 | h1->HRebin(nbin); | 
|---|
| [466] | 591 | } | 
|---|
|  | 592 |  | 
|---|
|  | 593 | /* methode */ | 
|---|
|  | 594 | void PAWExecutor::h_cadd(vector<string>& tokens) | 
|---|
|  | 595 | // Additionne une constante a un histogramme | 
|---|
|  | 596 | { | 
|---|
|  | 597 | if(tokens.size()<2) | 
|---|
|  | 598 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;} | 
|---|
|  | 599 | NamedObjMgr omg; | 
|---|
|  | 600 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 601 | if(mobj==NULL) | 
|---|
|  | 602 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl; | 
|---|
|  | 603 | return;} | 
|---|
| [1091] | 604 | r_8 val = atof(tokens[1].c_str()); | 
|---|
| [466] | 605 | Histo*   h1 = dynamic_cast<Histo*>(mobj); | 
|---|
| [1057] | 606 | HProf*   hp = dynamic_cast<HProf*>(mobj); | 
|---|
| [466] | 607 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); | 
|---|
| [1073] | 608 | Vector*  v  = dynamic_cast<Vector*>(mobj); | 
|---|
|  | 609 | Matrix*  m  = dynamic_cast<Matrix*>(mobj); | 
|---|
| [1057] | 610 | if(h1 && !hp) *h1 += val; | 
|---|
|  | 611 | else if(h2)   *h2 += val; | 
|---|
| [1073] | 612 | else if(v)    *v  += val; | 
|---|
|  | 613 | else if(m)    *m  += val; | 
|---|
|  | 614 | else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl; | 
|---|
| [466] | 615 | } | 
|---|
|  | 616 |  | 
|---|
|  | 617 | /* methode */ | 
|---|
|  | 618 | void PAWExecutor::h_cmult(vector<string>& tokens) | 
|---|
|  | 619 | // Multiplie un histogramme par une constante | 
|---|
|  | 620 | { | 
|---|
|  | 621 | if(tokens.size()<2) | 
|---|
|  | 622 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;} | 
|---|
|  | 623 | NamedObjMgr omg; | 
|---|
|  | 624 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 625 | if(mobj==NULL) | 
|---|
|  | 626 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl; | 
|---|
|  | 627 | return;} | 
|---|
| [1091] | 628 | r_8 val = atof(tokens[1].c_str()); | 
|---|
| [466] | 629 | Histo*   h1 = dynamic_cast<Histo*>(mobj); | 
|---|
| [1057] | 630 | HProf*   hp = dynamic_cast<HProf*>(mobj); | 
|---|
| [466] | 631 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); | 
|---|
| [1073] | 632 | Vector*  v  = dynamic_cast<Vector*>(mobj); | 
|---|
|  | 633 | Matrix*  m  = dynamic_cast<Matrix*>(mobj); | 
|---|
| [1057] | 634 | if(h1 && !hp) *h1 *= val; | 
|---|
|  | 635 | else if(h2)   *h2 *= val; | 
|---|
| [1073] | 636 | else if(v)    *v  += val; | 
|---|
|  | 637 | else if(m)    *m  += val; | 
|---|
|  | 638 | else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl; | 
|---|
| [466] | 639 | } | 
|---|
|  | 640 |  | 
|---|
|  | 641 | /* methode */ | 
|---|
| [1054] | 642 | void PAWExecutor::h_oper(vector<string>& tokens) | 
|---|
|  | 643 | // Equivalent h/oper/add sub,mul,div de paw | 
|---|
| [1073] | 644 | // Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices | 
|---|
| [1054] | 645 | // h/oper @ h1 h2 hres | 
|---|
|  | 646 | // hres = h1 @ h2    with @ = (+,-,*,/) | 
|---|
| [1073] | 647 | // Pour les vecteurs et les matrices, il sagit d'operations elements a elements | 
|---|
| [1054] | 648 | { | 
|---|
|  | 649 | if(tokens.size()<4) | 
|---|
| [1073] | 650 | {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl; | 
|---|
| [1054] | 651 | return;} | 
|---|
|  | 652 |  | 
|---|
|  | 653 | // Decode arguments | 
|---|
|  | 654 | const char * oper = tokens[0].c_str(); | 
|---|
|  | 655 | if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' ) | 
|---|
|  | 656 | {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl; | 
|---|
|  | 657 | return;} | 
|---|
|  | 658 | string h1name = tokens[1]; | 
|---|
|  | 659 | string h2name = tokens[2]; | 
|---|
|  | 660 | string h3name = tokens[3]; | 
|---|
|  | 661 |  | 
|---|
|  | 662 | // Get objects | 
|---|
|  | 663 | NamedObjMgr omg; | 
|---|
|  | 664 | AnyDataObj* mobjh1 = omg.GetObj(h1name); | 
|---|
|  | 665 | AnyDataObj* mobjh2 = omg.GetObj(h2name); | 
|---|
|  | 666 | if( mobjh1==NULL || mobjh2==NULL ) | 
|---|
|  | 667 | {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl; | 
|---|
|  | 668 | return;} | 
|---|
|  | 669 | AnyDataObj* mobjh3 = omg.GetObj(h3name); | 
|---|
|  | 670 |  | 
|---|
|  | 671 | // Operations on HProf, only + is working | 
|---|
|  | 672 | if( dynamic_cast<HProf*>(mobjh1) != NULL ) { | 
|---|
|  | 673 | if( oper[0]!='+' ) | 
|---|
|  | 674 | { cout<<"PAWExecutor::h_oper Error: operation "<<oper | 
|---|
|  | 675 | <<" not implemented for HProf"<<endl; return;} | 
|---|
|  | 676 | if( dynamic_cast<HProf*>(mobjh2) == NULL ) | 
|---|
| [1057] | 677 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" | 
|---|
| [1054] | 678 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl; | 
|---|
|  | 679 | return;} | 
|---|
|  | 680 | HProf* h1 =(HProf*) mobjh1; | 
|---|
|  | 681 | HProf* h2 =(HProf*) mobjh2; | 
|---|
|  | 682 | if( h1->NBins() != h2->NBins() ) | 
|---|
|  | 683 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " | 
|---|
|  | 684 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;} | 
|---|
|  | 685 | HProf* h3 = NULL; | 
|---|
| [1073] | 686 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree | 
|---|
|  | 687 | {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);} | 
|---|
|  | 688 | h3 = dynamic_cast<HProf*>(mobjh3); | 
|---|
|  | 689 | if(h3 == NULL)  // ce n'est pas un HProf | 
|---|
|  | 690 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" | 
|---|
|  | 691 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;} | 
|---|
|  | 692 | if(h1->NBins() != h3->NBins()) | 
|---|
|  | 693 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " | 
|---|
|  | 694 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;} | 
|---|
|  | 695 | *h3 = *h1 + *h2; | 
|---|
|  | 696 | h3->UpdateHisto(); | 
|---|
| [1054] | 697 |  | 
|---|
|  | 698 | // Operations on Histo | 
|---|
|  | 699 | } else if( dynamic_cast<Histo*>(mobjh1) != NULL ) { | 
|---|
|  | 700 | if( dynamic_cast<Histo*>(mobjh2) == NULL ) | 
|---|
| [1057] | 701 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" | 
|---|
| [1054] | 702 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl; | 
|---|
|  | 703 | return;} | 
|---|
|  | 704 | Histo* h1 =(Histo*) mobjh1; | 
|---|
|  | 705 | Histo* h2 =(Histo*) mobjh2; | 
|---|
|  | 706 | if( h1->NBins() != h2->NBins() ) | 
|---|
|  | 707 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " | 
|---|
|  | 708 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;} | 
|---|
|  | 709 | Histo* h3 = NULL; | 
|---|
| [1073] | 710 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree | 
|---|
|  | 711 | {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);} | 
|---|
|  | 712 | h3 = dynamic_cast<Histo*>(mobjh3); | 
|---|
|  | 713 | if(h3 == NULL)  // ce n'est pas un Histo | 
|---|
|  | 714 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" | 
|---|
|  | 715 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;} | 
|---|
|  | 716 | if(h1->NBins() != h3->NBins()) | 
|---|
|  | 717 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " | 
|---|
|  | 718 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;} | 
|---|
|  | 719 | if( oper[0]=='+')      *h3 = *h1 + *h2; | 
|---|
|  | 720 | else if( oper[0]=='-') *h3 = *h1 - *h2; | 
|---|
|  | 721 | else if( oper[0]=='*') *h3 = *h1 * *h2; | 
|---|
|  | 722 | else if( oper[0]=='/') *h3 = *h1 / *h2; | 
|---|
| [1054] | 723 |  | 
|---|
|  | 724 | // Operations on Histo2D | 
|---|
|  | 725 | } else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) { | 
|---|
|  | 726 | if( dynamic_cast<Histo2D*>(mobjh2) == NULL ) | 
|---|
| [1057] | 727 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" | 
|---|
| [1054] | 728 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl; | 
|---|
|  | 729 | return;} | 
|---|
|  | 730 | Histo2D* h1 =(Histo2D*) mobjh1; | 
|---|
|  | 731 | Histo2D* h2 =(Histo2D*) mobjh2; | 
|---|
|  | 732 | if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() ) | 
|---|
|  | 733 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " | 
|---|
|  | 734 | <<h1->NBinX()<<","<<h1->NBinY()<<"   " | 
|---|
|  | 735 | <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;} | 
|---|
|  | 736 | Histo2D* h3 = NULL; | 
|---|
| [1073] | 737 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree | 
|---|
|  | 738 | {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);} | 
|---|
|  | 739 | h3 = dynamic_cast<Histo2D*>(mobjh3); | 
|---|
|  | 740 | if(h3 == NULL)  // ce n'est pas un Histo2D | 
|---|
|  | 741 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" | 
|---|
|  | 742 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;} | 
|---|
|  | 743 | if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() ) | 
|---|
|  | 744 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " | 
|---|
|  | 745 | <<h1->NBinX()<<","<<h1->NBinY()<<"   " | 
|---|
|  | 746 | <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;} | 
|---|
|  | 747 | if( oper[0]=='+')      *h3 = *h1 + *h2; | 
|---|
|  | 748 | else if( oper[0]=='-') *h3 = *h1 - *h2; | 
|---|
|  | 749 | else if( oper[0]=='*') *h3 = *h1 * *h2; | 
|---|
|  | 750 | else if( oper[0]=='/') *h3 = *h1 / *h2; | 
|---|
|  | 751 |  | 
|---|
|  | 752 | // Operations on Vector | 
|---|
|  | 753 | } else if( dynamic_cast<Vector*>(mobjh1) != NULL ) { | 
|---|
|  | 754 | if( dynamic_cast<Vector*>(mobjh2) == NULL ) | 
|---|
|  | 755 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" | 
|---|
|  | 756 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl; | 
|---|
|  | 757 | return;} | 
|---|
|  | 758 | Vector* h1 =(Vector*) mobjh1; | 
|---|
|  | 759 | Vector* h2 =(Vector*) mobjh2; | 
|---|
|  | 760 | if( h1->NElts() != h2->NElts() ) | 
|---|
|  | 761 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " | 
|---|
|  | 762 | <<h1->NElts()<<" "<<h2->NElts()<<endl; return;} | 
|---|
|  | 763 | Vector* h3 = NULL; | 
|---|
| [1054] | 764 | if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree | 
|---|
| [1073] | 765 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 766 | h3 = new Vector(*h1); | 
|---|
|  | 767 | #else | 
|---|
|  | 768 | h3 = new Vector(*h1,false); | 
|---|
|  | 769 | #endif | 
|---|
|  | 770 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name); | 
|---|
| [1054] | 771 | } | 
|---|
| [1073] | 772 | h3 = dynamic_cast<Vector*>(mobjh3); | 
|---|
|  | 773 | if(h3 == NULL)  // ce n'est pas un Vector | 
|---|
|  | 774 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" | 
|---|
|  | 775 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;} | 
|---|
|  | 776 | if(h1->NElts() != h3->NElts()) | 
|---|
|  | 777 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " | 
|---|
|  | 778 | <<h1->NElts()<<" "<<h3->NElts()<<endl; return;} | 
|---|
|  | 779 | if( oper[0]=='+')      *h3 = *h1 + *h2; | 
|---|
|  | 780 | else if( oper[0]=='-') *h3 = *h1 - *h2; | 
|---|
|  | 781 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 782 | else if(oper[0]=='*' || oper[0]=='/') | 
|---|
|  | 783 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0] | 
|---|
|  | 784 | <<" not implemented for Vector in Peida"<<endl; | 
|---|
|  | 785 | #else | 
|---|
|  | 786 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);} | 
|---|
|  | 787 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);} | 
|---|
|  | 788 | #endif | 
|---|
| [1054] | 789 |  | 
|---|
| [1073] | 790 | // Operations on Matrix | 
|---|
|  | 791 | } else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) { | 
|---|
|  | 792 | if( dynamic_cast<Matrix*>(mobjh2) == NULL ) | 
|---|
|  | 793 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" | 
|---|
|  | 794 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl; | 
|---|
|  | 795 | return;} | 
|---|
|  | 796 | Matrix* h1 =(Matrix*) mobjh1; | 
|---|
|  | 797 | Matrix* h2 =(Matrix*) mobjh2; | 
|---|
|  | 798 | if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() ) | 
|---|
|  | 799 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " | 
|---|
|  | 800 | <<h1->NRows()<<","<<h1->NCol()<<"   " | 
|---|
|  | 801 | <<h2->NRows()<<","<<h2->NCol()<<endl; return;} | 
|---|
|  | 802 | Matrix* h3 = NULL; | 
|---|
|  | 803 | if( mobjh3 == NULL ) {  // l'objet n'existe pas, on le cree | 
|---|
|  | 804 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 805 | h3 = new Matrix(*h1); | 
|---|
|  | 806 | #else | 
|---|
|  | 807 | h3 = new Matrix(*h1,false); | 
|---|
|  | 808 | #endif | 
|---|
|  | 809 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name); | 
|---|
|  | 810 | } | 
|---|
|  | 811 | h3 = dynamic_cast<Matrix*>(mobjh3); | 
|---|
|  | 812 | if(h3 == NULL)  // ce n'est pas un Matrix | 
|---|
|  | 813 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" | 
|---|
|  | 814 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;} | 
|---|
|  | 815 | if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() ) | 
|---|
|  | 816 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " | 
|---|
|  | 817 | <<h1->NRows()<<","<<h1->NCol()<<"   " | 
|---|
|  | 818 | <<h3->NRows()<<","<<h3->NCol()<<endl; return;} | 
|---|
|  | 819 | if( oper[0]=='+')      *h3 = *h1 + *h2; | 
|---|
|  | 820 | else if( oper[0]=='-') *h3 = *h1 - *h2; | 
|---|
|  | 821 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 822 | else if(oper[0]=='*' || oper[0]=='/') | 
|---|
|  | 823 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0] | 
|---|
|  | 824 | <<" not implemented for Vector in Peida"<<endl; | 
|---|
|  | 825 | #else | 
|---|
|  | 826 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);} | 
|---|
|  | 827 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);} | 
|---|
|  | 828 | #endif | 
|---|
|  | 829 |  | 
|---|
| [1054] | 830 | // Doesn't work for other objects | 
|---|
|  | 831 | } else { | 
|---|
| [1057] | 832 | cout<<"PAWExecutor::h_oper Error: not implemented for " | 
|---|
|  | 833 | <<typeid(*mobjh1).name()<<endl; | 
|---|
| [1054] | 834 | return; | 
|---|
|  | 835 | } | 
|---|
|  | 836 |  | 
|---|
|  | 837 | return; | 
|---|
|  | 838 | } | 
|---|
|  | 839 |  | 
|---|
|  | 840 | /* methode */ | 
|---|
| [466] | 841 | void PAWExecutor::h_plot_2d(vector<string>& tokens) | 
|---|
|  | 842 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y | 
|---|
|  | 843 | { | 
|---|
| [1065] | 844 | if(tokens.size()<1) | 
|---|
| [466] | 845 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;} | 
|---|
| [1065] | 846 | string proj = "h"; if(tokens.size()>1) proj = tokens[1]; | 
|---|
| [466] | 847 | NamedObjMgr omg; | 
|---|
|  | 848 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 849 | if(mobj==NULL) | 
|---|
|  | 850 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl; | 
|---|
|  | 851 | return;} | 
|---|
|  | 852 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); | 
|---|
|  | 853 | if(!h2) | 
|---|
|  | 854 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl; | 
|---|
|  | 855 | return;} | 
|---|
|  | 856 |  | 
|---|
|  | 857 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1"; | 
|---|
|  | 858 |  | 
|---|
|  | 859 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2]; | 
|---|
| [1065] | 860 | if(proj == "show") { | 
|---|
| [466] | 861 | h2->ShowProj(); | 
|---|
|  | 862 | h2->ShowBand(2); | 
|---|
|  | 863 | h2->ShowSli(2); | 
|---|
|  | 864 | return; | 
|---|
| [1065] | 865 | } else if(proj == "h") { | 
|---|
| [466] | 866 | nametoplot = tokens[0]; | 
|---|
| [1065] | 867 | } else if(proj == "px") { | 
|---|
| [466] | 868 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} | 
|---|
|  | 869 | else {h2->ShowProj(); return;} | 
|---|
| [1065] | 870 | } else if(proj == "py") { | 
|---|
| [466] | 871 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} | 
|---|
|  | 872 | else {h2->ShowProj(); return;} | 
|---|
|  | 873 | } else { | 
|---|
|  | 874 | if(tokens.size()<3) | 
|---|
|  | 875 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;} | 
|---|
| [1091] | 876 | int_4 n = atoi(tokens[2].c_str()); | 
|---|
| [466] | 877 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3]; | 
|---|
| [1065] | 878 | if(proj == "bx") { | 
|---|
| [466] | 879 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} | 
|---|
|  | 880 | else {h2->ShowBand(); return;} | 
|---|
| [1065] | 881 | } else if(proj == "by") { | 
|---|
| [466] | 882 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} | 
|---|
|  | 883 | else {h2->ShowBand(); return;} | 
|---|
| [1065] | 884 | } else if(proj == "sx") { | 
|---|
| [466] | 885 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} | 
|---|
|  | 886 | else {h2->ShowSli(); return;} | 
|---|
| [1065] | 887 | } else if(proj == "sy") { | 
|---|
| [466] | 888 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} | 
|---|
|  | 889 | else {h2->ShowSli(); return;} | 
|---|
| [463] | 890 | } | 
|---|
|  | 891 | } | 
|---|
| [466] | 892 |  | 
|---|
|  | 893 | omg.DisplayObj(nametoplot,dopt); | 
|---|
|  | 894 | } | 
|---|
|  | 895 |  | 
|---|
|  | 896 | /* methode */ | 
|---|
| [1247] | 897 | int_4 PAWExecutor::decodepawstring(string tokens,string& nameobj | 
|---|
| [466] | 898 | ,string& xexp,string& yexp,string& zexp) | 
|---|
|  | 899 | // Decodage general de "nameobj.xexp" | 
|---|
|  | 900 | //                     "nameobj.yexp%xexp" | 
|---|
|  | 901 | //                     "nameobj.zexp%yexp%xexp" | 
|---|
|  | 902 | // Return: nombre de variables trouvees, -1 si probleme | 
|---|
|  | 903 | { | 
|---|
|  | 904 | nameobj = ""; xexp= ""; yexp= ""; zexp= ""; | 
|---|
|  | 905 |  | 
|---|
| [1247] | 906 | int_4 lt = (int) tokens.length(); | 
|---|
| [466] | 907 | if(lt<=0) return -1; | 
|---|
|  | 908 |  | 
|---|
|  | 909 | // decodage de la chaine de type PAW. | 
|---|
|  | 910 | char *str = new char[lt+2]; | 
|---|
|  | 911 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str); | 
|---|
|  | 912 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl; | 
|---|
|  | 913 | char *c[3] = {NULL,NULL,NULL}; | 
|---|
| [1247] | 914 | int_4 i, np=0; bool namefound = false; | 
|---|
| [562] | 915 | for(i=0;i<lt;i++) { | 
|---|
| [466] | 916 | if(!namefound && str[i]=='.') { | 
|---|
|  | 917 | str[i]='\0'; | 
|---|
|  | 918 | namefound=true; | 
|---|
|  | 919 | c[np] = str+i+1; np++; | 
|---|
|  | 920 | } | 
|---|
|  | 921 | if( namefound && str[i]=='%') { | 
|---|
|  | 922 | str[i]='\0'; | 
|---|
|  | 923 | if(np<3) {c[np] = str+i+1; np++;} | 
|---|
|  | 924 | } | 
|---|
|  | 925 | } | 
|---|
|  | 926 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl; | 
|---|
|  | 927 |  | 
|---|
|  | 928 | // Remplissage du nom et des variables | 
|---|
|  | 929 | nameobj = str; | 
|---|
|  | 930 | if(np==1)  xexp=c[0]; | 
|---|
|  | 931 | if(np==2) {yexp=c[0]; xexp=c[1];} | 
|---|
|  | 932 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];} | 
|---|
|  | 933 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl; | 
|---|
|  | 934 | delete [] str; | 
|---|
|  | 935 |  | 
|---|
|  | 936 | // Comptage des variables | 
|---|
|  | 937 | np = -1; | 
|---|
|  | 938 | if(nameobj.length()>0) | 
|---|
|  | 939 | {np = 0; if(xexp.length()>0) | 
|---|
|  | 940 | {np++; if(yexp.length()>0) | 
|---|
|  | 941 | {np++; if(zexp.length()>0) np++;}}} | 
|---|
| [1247] | 942 | //cout<<"pawstring["<<np<<"] name="<<nameobj | 
|---|
|  | 943 | //    <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl; | 
|---|
| [466] | 944 | return np; | 
|---|
|  | 945 | } | 
|---|
| [1065] | 946 |  | 
|---|
|  | 947 | /* methode */ | 
|---|
|  | 948 | void PAWExecutor::h_put_vec(vector<string>& tokens) | 
|---|
|  | 949 | // Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice | 
|---|
|  | 950 | // L'histogramme doit deja exister. Le nombre de bins remplit | 
|---|
|  | 951 | // depend des tailles respectives des 2 objets. | 
|---|
| [1067] | 952 | // tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!") | 
|---|
| [1065] | 953 | //           = "err2" : on remplit les erreurs de l'histogramme | 
|---|
|  | 954 | { | 
|---|
|  | 955 | if(tokens.size()<2) | 
|---|
|  | 956 | {cout<<"Usage: h/put_vec  namehisto namevector"<<endl; | 
|---|
|  | 957 | return;} | 
|---|
|  | 958 | string toput = "cont"; if(tokens.size()>2) toput = tokens[2]; | 
|---|
| [1067] | 959 | if(toput=="!") toput = "cont"; | 
|---|
| [1065] | 960 | if(toput!="cont" && toput!="err2") | 
|---|
|  | 961 | {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl; | 
|---|
|  | 962 | return;} | 
|---|
|  | 963 | string hname = tokens[0]; | 
|---|
|  | 964 | string vname = tokens[1]; | 
|---|
|  | 965 |  | 
|---|
|  | 966 | // Get objects | 
|---|
|  | 967 | NamedObjMgr omg; | 
|---|
|  | 968 | AnyDataObj* mobjh = omg.GetObj(hname); | 
|---|
|  | 969 | AnyDataObj* mobjv = omg.GetObj(vname); | 
|---|
|  | 970 | if( mobjh==NULL || mobjv==NULL ) | 
|---|
|  | 971 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl; | 
|---|
|  | 972 | return;} | 
|---|
|  | 973 |  | 
|---|
| [1076] | 974 | // Fill Histo from Vector | 
|---|
| [1065] | 975 | if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) { | 
|---|
|  | 976 | Histo*  h = dynamic_cast<Histo*>(mobjh); | 
|---|
|  | 977 | Vector* v = dynamic_cast<Vector*>(mobjv); | 
|---|
|  | 978 | if(toput=="cont")      h->PutValue(*v); | 
|---|
|  | 979 | else if(toput=="err2") h->PutError2(*v); | 
|---|
|  | 980 |  | 
|---|
| [1076] | 981 | // Fill Histo2D from Matrix | 
|---|
| [1065] | 982 | } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) { | 
|---|
|  | 983 | Histo2D* h = dynamic_cast<Histo2D*>(mobjh); | 
|---|
|  | 984 | Matrix*  v = dynamic_cast<Matrix*>(mobjv); | 
|---|
|  | 985 | if(toput=="cont")      h->PutValue(*v); | 
|---|
|  | 986 | else if(toput=="err2") h->PutError2(*v); | 
|---|
|  | 987 |  | 
|---|
|  | 988 | } else { | 
|---|
|  | 989 | cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n" | 
|---|
|  | 990 | <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl; | 
|---|
|  | 991 | return; | 
|---|
|  | 992 | } | 
|---|
|  | 993 |  | 
|---|
|  | 994 | } | 
|---|
|  | 995 |  | 
|---|
|  | 996 | /* methode */ | 
|---|
|  | 997 | void PAWExecutor::h_get_vec(vector<string>& tokens) | 
|---|
|  | 998 | // Pour copier un histo dans un vecteur ou une matrice | 
|---|
|  | 999 | // Si le vecteur (matrice) n'existe pas, il est cree. | 
|---|
|  | 1000 | // Le vecteur ou la matrice est re-dimensionne correctement. | 
|---|
| [1067] | 1001 | // tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!") | 
|---|
| [1065] | 1002 | //           = "err2" : on copie les erreurs de l'histogramme | 
|---|
|  | 1003 | //           = "absc" : on copie les erreurs de l'histogramme (1D only) | 
|---|
|  | 1004 | // tokens[3[,4]] = show : show available projections for Histo2D | 
|---|
|  | 1005 | //                 px   : get X projection | 
|---|
|  | 1006 | //                 py   : get Y projection | 
|---|
|  | 1007 | //                 bx n : get X band number n | 
|---|
|  | 1008 | //                 by n : get Y band number n | 
|---|
|  | 1009 | //                 sx n : get X slice number n | 
|---|
|  | 1010 | //                 sy n : get Y slice number n | 
|---|
|  | 1011 | { | 
|---|
|  | 1012 | if(tokens.size()<2) | 
|---|
|  | 1013 | {cout<<"Usage: h/get_vec namehisto namevector"<<endl; | 
|---|
|  | 1014 | return;} | 
|---|
|  | 1015 | string toget = "cont"; if(tokens.size()>2) toget = tokens[2]; | 
|---|
| [1067] | 1016 | if(toget=="!") toget = "cont"; | 
|---|
| [1065] | 1017 | if(toget!="cont" && toget!="err2" && toget!="absc") | 
|---|
|  | 1018 | {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl; | 
|---|
|  | 1019 | return;} | 
|---|
|  | 1020 | string proj = "h";  if(tokens.size()>3) proj = tokens[3]; | 
|---|
| [1091] | 1021 | int_4 nproj = -1;   if(tokens.size()>4) nproj = atoi(tokens[4].c_str()); | 
|---|
| [1065] | 1022 | string hname = tokens[0]; | 
|---|
|  | 1023 | string vname = tokens[1]; | 
|---|
|  | 1024 |  | 
|---|
|  | 1025 | // Get objects | 
|---|
|  | 1026 | NamedObjMgr omg; | 
|---|
|  | 1027 | AnyDataObj* mobjh = omg.GetObj(hname); | 
|---|
|  | 1028 | AnyDataObj* mobjv = omg.GetObj(vname); | 
|---|
|  | 1029 | if( mobjh==NULL) | 
|---|
|  | 1030 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl; | 
|---|
|  | 1031 | return;} | 
|---|
|  | 1032 |  | 
|---|
| [1076] | 1033 | // Copy Histo/Histo2D/Projection to Vector/Matrix | 
|---|
| [1065] | 1034 | Histo*   h  = dynamic_cast<Histo*>(mobjh); | 
|---|
|  | 1035 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh); | 
|---|
|  | 1036 | if( h != NULL ) {  // Histo ou HProf | 
|---|
| [1090] | 1037 | h->UpdateHisto();  // pour le cas ou c'est un HProf | 
|---|
| [1065] | 1038 | Vector* v = NULL; | 
|---|
|  | 1039 | if(mobjv==NULL)   // le vecteur n'existe pas | 
|---|
| [1073] | 1040 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);} | 
|---|
| [1065] | 1041 | if(typeid(*mobjv) != typeid(Vector)) | 
|---|
|  | 1042 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n" | 
|---|
|  | 1043 | <<typeid(*mobjv).name()<<endl; return;} | 
|---|
|  | 1044 | v = dynamic_cast<Vector*>(mobjv); | 
|---|
|  | 1045 | if(toget=="cont")      h->GetValue(*v); | 
|---|
|  | 1046 | else if(toget=="err2") h->GetError2(*v); | 
|---|
|  | 1047 | else if(toget=="absc") h->GetAbsc(*v); | 
|---|
|  | 1048 |  | 
|---|
|  | 1049 | } else if( h2 != NULL) {  // Histo2D | 
|---|
|  | 1050 |  | 
|---|
|  | 1051 | if(proj == "h") {   // On veut les valeurs de l'histogramme 2D | 
|---|
|  | 1052 | Matrix*  v = NULL; | 
|---|
|  | 1053 | if(mobjv==NULL)   // la matrice n'existe pas | 
|---|
| [1073] | 1054 | {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);} | 
|---|
| [1065] | 1055 | if(typeid(*mobjv) != typeid(Matrix)) | 
|---|
|  | 1056 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n" | 
|---|
|  | 1057 | <<typeid(*mobjv).name()<<endl; return;} | 
|---|
|  | 1058 | v = dynamic_cast<Matrix*>(mobjv); | 
|---|
|  | 1059 | if(toget=="cont")      h2->GetValue(*v); | 
|---|
|  | 1060 | else if(toget=="err2") h2->GetError2(*v); | 
|---|
|  | 1061 | else | 
|---|
|  | 1062 | {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl; | 
|---|
|  | 1063 | return;} | 
|---|
|  | 1064 |  | 
|---|
|  | 1065 | } else {   // On veut les valeurs d'une projection de l'histo 2D | 
|---|
|  | 1066 | h = NULL; | 
|---|
|  | 1067 | if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);} | 
|---|
|  | 1068 | else if(proj == "px") h = h2->HProjX(); | 
|---|
|  | 1069 | else if(proj == "py") h = h2->HProjY(); | 
|---|
|  | 1070 | else if(proj == "bx") h = h2->HBandX(nproj); | 
|---|
|  | 1071 | else if(proj == "by") h = h2->HBandY(nproj); | 
|---|
|  | 1072 | else if(proj == "sx") h = h2->HSliX(nproj); | 
|---|
|  | 1073 | else if(proj == "sy") h = h2->HSliY(nproj); | 
|---|
|  | 1074 | if(h==NULL) | 
|---|
|  | 1075 | {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj | 
|---|
|  | 1076 | <<" number "<<nproj<<endl; return;} | 
|---|
|  | 1077 | Vector* v = NULL; | 
|---|
|  | 1078 | if(mobjv==NULL)   // le vecteur n'existe pas | 
|---|
| [1073] | 1079 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);} | 
|---|
| [1065] | 1080 | if(typeid(*mobjv) != typeid(Vector)) | 
|---|
|  | 1081 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj | 
|---|
|  | 1082 | <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;} | 
|---|
|  | 1083 | v = dynamic_cast<Vector*>(mobjv); | 
|---|
|  | 1084 | if(toget=="cont")      h->GetValue(*v); | 
|---|
|  | 1085 | else if(toget=="err2") h->GetError2(*v); | 
|---|
|  | 1086 | else if(toget=="absc") h->GetAbsc(*v); | 
|---|
|  | 1087 | } | 
|---|
|  | 1088 |  | 
|---|
|  | 1089 | } else { | 
|---|
|  | 1090 | cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n" | 
|---|
|  | 1091 | <<typeid(*mobjh).name()<<endl; | 
|---|
|  | 1092 | return; | 
|---|
|  | 1093 | } | 
|---|
|  | 1094 |  | 
|---|
|  | 1095 | } | 
|---|
| [1070] | 1096 |  | 
|---|
|  | 1097 | /* methode */ | 
|---|
|  | 1098 | void PAWExecutor::h_copy(vector<string>& tokens) | 
|---|
|  | 1099 | // Pour copier un object dans un object | 
|---|
|  | 1100 | // objects are Vector,Matrix,Histo,Histo2D | 
|---|
| [1071] | 1101 | //   h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]] | 
|---|
|  | 1102 | //   copy obj1Dfrom(i1->i2) into obj1Dto(ic1->) | 
|---|
|  | 1103 | //   copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->) | 
|---|
| [1070] | 1104 | // Attention: elements depuis i1 jusqu'a i2 COMPRIS | 
|---|
| [1071] | 1105 | // Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1 | 
|---|
|  | 1106 | //    ou obj2Dto avec une taille i2-i1+1,j2-j1+1 | 
|---|
|  | 1107 | // Le contenu de obj?Dfrom adresse est surecrit | 
|---|
|  | 1108 | // Le contenu de obj?Dfrom non adresse reste le meme | 
|---|
| [1070] | 1109 | { | 
|---|
| [1247] | 1110 | int_4 tks = tokens.size(); | 
|---|
| [1071] | 1111 | if(tks<2) | 
|---|
|  | 1112 | {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl; | 
|---|
| [1070] | 1113 | return;} | 
|---|
|  | 1114 |  | 
|---|
|  | 1115 | NamedObjMgr omg; | 
|---|
|  | 1116 | AnyDataObj* mobjv1 = omg.GetObj(tokens[0]); | 
|---|
|  | 1117 | if( mobjv1==NULL) | 
|---|
|  | 1118 | {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl; | 
|---|
|  | 1119 | return;} | 
|---|
| [1071] | 1120 | AnyDataObj* mobjv2 = omg.GetObj(tokens[1]); | 
|---|
| [1070] | 1121 |  | 
|---|
| [1071] | 1122 | int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2; | 
|---|
|  | 1123 |  | 
|---|
| [1070] | 1124 | // Cas d'un Vector | 
|---|
|  | 1125 | if(typeid(*mobjv1) == typeid(Vector)) { | 
|---|
| [1071] | 1126 | Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts(); | 
|---|
|  | 1127 | i2=nx1-1; | 
|---|
|  | 1128 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); | 
|---|
|  | 1129 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; | 
|---|
| [1070] | 1130 | if(i2<i1) | 
|---|
|  | 1131 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts=" | 
|---|
| [1071] | 1132 | <<nx1<<endl; return;} | 
|---|
| [1070] | 1133 | Vector* v2 = NULL; | 
|---|
|  | 1134 | if(mobjv2==NULL) | 
|---|
| [1073] | 1135 | {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);} | 
|---|
| [1070] | 1136 | if(typeid(*mobjv2) != typeid(Vector)) | 
|---|
|  | 1137 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector " | 
|---|
|  | 1138 | <<typeid(*mobjv2).name()<<endl; return;} | 
|---|
| [1071] | 1139 | v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts(); | 
|---|
|  | 1140 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1); | 
|---|
|  | 1141 | if(ic1<0) ic1=0; | 
|---|
|  | 1142 | if(ic1>=nx2) | 
|---|
|  | 1143 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts=" | 
|---|
|  | 1144 | <<nx2<<endl; return;} | 
|---|
|  | 1145 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl; | 
|---|
|  | 1146 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i); | 
|---|
| [1070] | 1147 | return; | 
|---|
|  | 1148 | } | 
|---|
|  | 1149 |  | 
|---|
|  | 1150 | // Cas d'un Histo | 
|---|
|  | 1151 | if(typeid(*mobjv1) == typeid(Histo)) { | 
|---|
| [1071] | 1152 | Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins(); | 
|---|
|  | 1153 | i2=nx1-1; | 
|---|
|  | 1154 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); | 
|---|
|  | 1155 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; | 
|---|
| [1070] | 1156 | if(i2<i1) | 
|---|
|  | 1157 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins=" | 
|---|
| [1071] | 1158 | <<nx1<<endl; return;} | 
|---|
| [1070] | 1159 | Histo* v2 = NULL; | 
|---|
|  | 1160 | if(mobjv2==NULL) | 
|---|
| [1091] | 1161 | {v2 = new Histo(0.,(r_8)(i2-i1+1),i2-i1+1); | 
|---|
| [1073] | 1162 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);} | 
|---|
| [1070] | 1163 | if(typeid(*mobjv2) != typeid(Histo)) | 
|---|
|  | 1164 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo " | 
|---|
|  | 1165 | <<typeid(*mobjv2).name()<<endl; return;} | 
|---|
| [1071] | 1166 | v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins(); | 
|---|
|  | 1167 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors(); | 
|---|
|  | 1168 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1); | 
|---|
|  | 1169 | if(ic1<0) ic1=0; | 
|---|
|  | 1170 | if(ic1>=nx2) | 
|---|
|  | 1171 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins=" | 
|---|
|  | 1172 | <<nx2<<endl; return;} | 
|---|
|  | 1173 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl; | 
|---|
|  | 1174 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) | 
|---|
|  | 1175 | {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);} | 
|---|
| [1070] | 1176 | return; | 
|---|
|  | 1177 | } | 
|---|
|  | 1178 |  | 
|---|
|  | 1179 | // Cas d'une Matrix | 
|---|
|  | 1180 | if(typeid(*mobjv1) == typeid(Matrix)) { | 
|---|
| [1071] | 1181 | Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol(); | 
|---|
|  | 1182 | i2=nx1-1; j2=ny1-1; | 
|---|
|  | 1183 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); | 
|---|
|  | 1184 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); | 
|---|
|  | 1185 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1; | 
|---|
| [1070] | 1186 | if(i2<i1 || j2<j1) | 
|---|
|  | 1187 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2 | 
|---|
|  | 1188 | <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol=" | 
|---|
| [1071] | 1189 | <<nx1<<" , "<<ny1<<endl; return;} | 
|---|
| [1070] | 1190 | Matrix* v2 = NULL; | 
|---|
|  | 1191 | if(mobjv2==NULL) | 
|---|
| [1073] | 1192 | {v2 = new Matrix(i2-i1+1,j2-j1+1); | 
|---|
|  | 1193 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);} | 
|---|
| [1070] | 1194 | if(typeid(*mobjv2) != typeid(Matrix)) | 
|---|
|  | 1195 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix " | 
|---|
|  | 1196 | <<typeid(*mobjv2).name()<<endl; return;} | 
|---|
| [1071] | 1197 | v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol(); | 
|---|
|  | 1198 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1); | 
|---|
|  | 1199 | if(ic1<0) ic1=0; if(jc1<0) jc1=0; | 
|---|
|  | 1200 | if(ic1>=nx2 || jc1>=ny2) | 
|---|
|  | 1201 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1 | 
|---|
|  | 1202 | <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;} | 
|---|
|  | 1203 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2 | 
|---|
|  | 1204 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl; | 
|---|
|  | 1205 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) | 
|---|
|  | 1206 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j); | 
|---|
| [1070] | 1207 | return; | 
|---|
|  | 1208 | } | 
|---|
|  | 1209 |  | 
|---|
|  | 1210 | // Cas d'un Histo2D | 
|---|
|  | 1211 | if(typeid(*mobjv1) == typeid(Histo2D)) { | 
|---|
| [1071] | 1212 | Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY(); | 
|---|
|  | 1213 | i2=nx1-1; j2=ny1-1; | 
|---|
|  | 1214 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); | 
|---|
|  | 1215 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); | 
|---|
|  | 1216 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1; | 
|---|
| [1070] | 1217 | if(i2<i1 || j2<j1) | 
|---|
|  | 1218 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2 | 
|---|
|  | 1219 | <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY=" | 
|---|
| [1071] | 1220 | <<nx1<<" , "<<ny1<<endl; return;} | 
|---|
| [1070] | 1221 | Histo2D* v2 = NULL; | 
|---|
|  | 1222 | if(mobjv2==NULL) | 
|---|
| [1091] | 1223 | {v2 = new Histo2D(0.,(r_8)(i2-i1+1),i2-i1+1,0.,(r_8)(j2-j1+1),j2-j1+1); | 
|---|
| [1073] | 1224 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);} | 
|---|
| [1070] | 1225 | if(typeid(*mobjv2) != typeid(Histo2D)) | 
|---|
|  | 1226 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D" | 
|---|
|  | 1227 | <<typeid(*mobjv2).name()<<endl; return;} | 
|---|
| [1071] | 1228 | v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY(); | 
|---|
|  | 1229 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors(); | 
|---|
|  | 1230 | if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1); | 
|---|
|  | 1231 | if(ic1<0) ic1=0; if(jc1<0) jc1=0; | 
|---|
|  | 1232 | if(ic1>=nx2 || jc1>=ny2) | 
|---|
|  | 1233 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1 | 
|---|
|  | 1234 | <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;} | 
|---|
|  | 1235 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2 | 
|---|
|  | 1236 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl; | 
|---|
|  | 1237 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) | 
|---|
|  | 1238 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) | 
|---|
|  | 1239 | {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);} | 
|---|
| [1070] | 1240 | return; | 
|---|
|  | 1241 | } | 
|---|
|  | 1242 |  | 
|---|
|  | 1243 | // Cas non prevu | 
|---|
|  | 1244 | cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n" | 
|---|
|  | 1245 | <<typeid(*mobjv1).name()<<endl; | 
|---|
|  | 1246 | return; | 
|---|
|  | 1247 | } | 
|---|
| [1079] | 1248 |  | 
|---|
|  | 1249 | /* methode */ | 
|---|
|  | 1250 | void PAWExecutor::h_set(string dum,vector<string>& tokens) | 
|---|
|  | 1251 | // Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee | 
|---|
|  | 1252 | // dum = err  : on change les valeurs des erreurs | 
|---|
|  | 1253 | //       cont : on change les valeurs du contenu des bins | 
|---|
|  | 1254 | // tokens[0] : nom de l'histogramme | 
|---|
|  | 1255 | // tokens[1] : valeur de remplacement | 
|---|
|  | 1256 | // tokens[2-3] : i1:i2 j1:j2  intervalle des bins qui doivent etre remplace | 
|---|
|  | 1257 | //             : v v1:v2  remplacement des bins ayant une valeur dans cet intervalle | 
|---|
|  | 1258 | //             : e e1:e2  remplacement des bins ayant une erreur dans cet intervalle | 
|---|
|  | 1259 | { | 
|---|
| [1247] | 1260 | int_4 tks = tokens.size(); | 
|---|
| [1079] | 1261 | if(tks<3) | 
|---|
|  | 1262 | {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2]  [j1[:j2]]\n" | 
|---|
|  | 1263 | <<"                                           v v1:v2\n" | 
|---|
|  | 1264 | <<"                                           e e1:e2" | 
|---|
|  | 1265 | <<endl; return;} | 
|---|
|  | 1266 |  | 
|---|
|  | 1267 | // Decodage arguments | 
|---|
|  | 1268 | bool replerr = false; if(dum=="err") replerr = true; | 
|---|
| [1091] | 1269 | r_8 setval = atof(tokens[1].c_str()); | 
|---|
| [1247] | 1270 | int_4 testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2; | 
|---|
| [1079] | 1271 | int_4 i1=-1, i2=-1, j1=-1, j2=-1; | 
|---|
| [1091] | 1272 | r_8 v1=0., v2=0.; | 
|---|
| [1079] | 1273 | if(testcont==0) { | 
|---|
|  | 1274 | sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); | 
|---|
|  | 1275 | if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); | 
|---|
|  | 1276 | } else { | 
|---|
|  | 1277 | if(tks<=3) | 
|---|
|  | 1278 | {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl; | 
|---|
|  | 1279 | return;} | 
|---|
| [1091] | 1280 | sscanf(tokens[3].c_str(),"%lf:%lf",&v1,&v2); | 
|---|
| [1079] | 1281 | } | 
|---|
|  | 1282 |  | 
|---|
|  | 1283 | if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;} | 
|---|
|  | 1284 | if(testcont!=0 && v2<v1) | 
|---|
|  | 1285 | {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;} | 
|---|
|  | 1286 |  | 
|---|
|  | 1287 | // identification objet | 
|---|
|  | 1288 | NamedObjMgr omg; | 
|---|
|  | 1289 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 1290 | if( mobj==NULL) | 
|---|
|  | 1291 | {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl; | 
|---|
|  | 1292 | return;} | 
|---|
|  | 1293 |  | 
|---|
|  | 1294 | // Traitement | 
|---|
|  | 1295 | if(typeid(*mobj) == typeid(Histo)) {  // Histo 1D | 
|---|
|  | 1296 | Histo* h  = dynamic_cast<Histo*>(mobj); | 
|---|
|  | 1297 | if( (replerr || testcont==2) && !(h->HasErrors()) ) | 
|---|
|  | 1298 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;} | 
|---|
|  | 1299 | if(testcont!=0) {i1=0; i2=h->NBins()-1;} | 
|---|
|  | 1300 | if(i1<0 || i1>=h->NBins()) | 
|---|
|  | 1301 | {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;} | 
|---|
|  | 1302 | if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1; | 
|---|
| [1091] | 1303 | for(int_4 i=i1;i<=i2;i++) { | 
|---|
| [1079] | 1304 | bool change = true; | 
|---|
|  | 1305 | if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;} | 
|---|
|  | 1306 | else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;} | 
|---|
|  | 1307 | if(!change) continue; | 
|---|
|  | 1308 | if(replerr) h->Error2(i) = setval; else (*h)(i) = setval; | 
|---|
|  | 1309 | } | 
|---|
|  | 1310 |  | 
|---|
|  | 1311 | } else if(typeid(*mobj) == typeid(Histo2D)) {  // Histo 2D | 
|---|
|  | 1312 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); | 
|---|
|  | 1313 | if( (replerr || testcont==2) && !(h2->HasErrors()) ) | 
|---|
|  | 1314 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;} | 
|---|
|  | 1315 | if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;} | 
|---|
|  | 1316 | if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY()) | 
|---|
|  | 1317 | {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;} | 
|---|
|  | 1318 | if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1; | 
|---|
|  | 1319 | if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1; | 
|---|
| [1091] | 1320 | for(int_4 i=i1;i<=i2;i++) for(int_4 j=j1;j<=j2;j++) { | 
|---|
| [1079] | 1321 | bool change = true; | 
|---|
|  | 1322 | if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;} | 
|---|
|  | 1323 | else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;} | 
|---|
|  | 1324 | if(!change) continue; | 
|---|
|  | 1325 | if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval; | 
|---|
|  | 1326 | } | 
|---|
|  | 1327 |  | 
|---|
|  | 1328 | } else { | 
|---|
|  | 1329 | cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n" | 
|---|
|  | 1330 | <<typeid(*mobj).name()<<endl; | 
|---|
|  | 1331 | return; | 
|---|
|  | 1332 | } | 
|---|
|  | 1333 |  | 
|---|
|  | 1334 | } | 
|---|
|  | 1335 |  | 
|---|
|  | 1336 | /* methode */ | 
|---|
|  | 1337 | void PAWExecutor::h_err(vector<string>& tokens) | 
|---|
|  | 1338 | // Mise des erreurs d'un histo 1D ou 2D a une valeur | 
|---|
|  | 1339 | // donnee par une fonction de la valeur du bin | 
|---|
|  | 1340 | // tokens[0] : nom de l'histogramme | 
|---|
|  | 1341 | // tokens[1] : expression de la fonction | 
|---|
|  | 1342 | { | 
|---|
|  | 1343 | if(tokens.size()<2) | 
|---|
|  | 1344 | {cout<<"Usage: h/err namehisto expr_func"<<endl; return;} | 
|---|
|  | 1345 |  | 
|---|
|  | 1346 | // identification objet | 
|---|
|  | 1347 | NamedObjMgr omg; | 
|---|
|  | 1348 | AnyDataObj* mobj = omg.GetObj(tokens[0]); | 
|---|
|  | 1349 | if( mobj==NULL) | 
|---|
|  | 1350 | {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl; | 
|---|
|  | 1351 | return;} | 
|---|
|  | 1352 |  | 
|---|
|  | 1353 | // Fonction | 
|---|
|  | 1354 | FILE *fip = NULL; | 
|---|
| [1247] | 1355 | string expfunc = ""; {for(int_4 i=1;i<(int)tokens.size();i++) expfunc += tokens[i];} | 
|---|
| [1079] | 1356 | string fname = "func1or2_pia_dl.c"; | 
|---|
|  | 1357 | string func = "func1or2_pia_dl_func"; | 
|---|
|  | 1358 | if((fip = fopen(fname.c_str(), "w")) == NULL) | 
|---|
|  | 1359 | {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl; | 
|---|
|  | 1360 | return;} | 
|---|
|  | 1361 | fprintf(fip,"#include <math.h>\n"); | 
|---|
|  | 1362 | fprintf(fip,"double %s(double x) \n{\n",func.c_str()); | 
|---|
|  | 1363 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str()); | 
|---|
|  | 1364 | fclose(fip); | 
|---|
|  | 1365 | DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func); | 
|---|
|  | 1366 | if(!f) | 
|---|
|  | 1367 | {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl; | 
|---|
|  | 1368 | return;} | 
|---|
|  | 1369 |  | 
|---|
|  | 1370 | // Traitement | 
|---|
|  | 1371 | if(typeid(*mobj) == typeid(Histo)) {  // Histo 1D | 
|---|
|  | 1372 | Histo* h  = dynamic_cast<Histo*>(mobj); | 
|---|
|  | 1373 | if(!(h->HasErrors())) h->Errors(); | 
|---|
| [1091] | 1374 | for(int_4 i=0;i<h->NBins();i++) { | 
|---|
|  | 1375 | r_8 x = (*h)(i); | 
|---|
|  | 1376 | r_8 e = f(x); | 
|---|
| [1079] | 1377 | h->SetErr2(i,e*e); | 
|---|
|  | 1378 | } | 
|---|
|  | 1379 |  | 
|---|
|  | 1380 | } else if(typeid(*mobj) == typeid(Histo2D)) {  // Histo 2D | 
|---|
|  | 1381 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); | 
|---|
|  | 1382 | if(!(h2->HasErrors())) h2->Errors(); | 
|---|
| [1091] | 1383 | for(int_4 i=0;i<h2->NBinX();i++) for(int_4 j=0;j<h2->NBinY();j++) { | 
|---|
|  | 1384 | r_8 x = (*h2)(i,j); | 
|---|
|  | 1385 | r_8 e = f(x); | 
|---|
| [1079] | 1386 | h2->Error2(i,j) = e*e; | 
|---|
|  | 1387 | } | 
|---|
|  | 1388 |  | 
|---|
|  | 1389 | } else { | 
|---|
|  | 1390 | cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n" | 
|---|
|  | 1391 | <<typeid(*mobj).name()<<endl; | 
|---|
|  | 1392 | return; | 
|---|
|  | 1393 | } | 
|---|
|  | 1394 |  | 
|---|
|  | 1395 | } | 
|---|