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