[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"
|
---|
[463] | 16 | #include "pistdimgapp.h"
|
---|
| 17 |
|
---|
[544] | 18 | #ifdef SANS_EVOLPLANCK
|
---|
| 19 | #include "cvector.h"
|
---|
| 20 | #include "matrix.h"
|
---|
| 21 | #else
|
---|
| 22 | #include "tmatrix.h"
|
---|
| 23 | #include "tvector.h"
|
---|
| 24 | #endif
|
---|
| 25 |
|
---|
[466] | 26 | /* Reza + cmv 13/10/99 */
|
---|
| 27 |
|
---|
[1035] | 28 | uint_4 PAWExecutor::autoc_counter_ = 0;
|
---|
| 29 |
|
---|
[466] | 30 | /* methode */
|
---|
[463] | 31 | PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
|
---|
[466] | 32 | : mApp(app)
|
---|
[463] | 33 | {
|
---|
| 34 | string kw, usage;
|
---|
| 35 | string hgrp = "pawCmd";
|
---|
[466] | 36 |
|
---|
| 37 | kw = "reset";
|
---|
| 38 | usage = "Reset histograms vectors or matrix";
|
---|
| 39 | usage += "\n reset nameobj";
|
---|
[463] | 40 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[466] | 41 |
|
---|
| 42 | kw = "n/plot";
|
---|
[469] | 43 | usage = "Plot NTuple variables a la paw";
|
---|
| 44 | usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 45 | usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]";
|
---|
| 46 | usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]";
|
---|
| 47 | usage += "\n for default use ! , loop=i1[:i2[:di]]";
|
---|
[466] | 48 | usage += "\n Related commands: plot2dw plot3d";
|
---|
| 49 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 50 |
|
---|
| 51 | kw = "n/proj";
|
---|
| 52 | usage = "Project NTuple in histogram (1D or 2D) a la paw";
|
---|
[469] | 53 | usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 54 | usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 55 | usage += "\n for default use ! , loop=i1[:i2[:di]]";
|
---|
[466] | 56 | usage += "\n Related commands: projh1d projh2d projprof";
|
---|
| 57 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 58 |
|
---|
| 59 | kw = "h/integ";
|
---|
[1057] | 60 | usage = "Integrate a 1D histogram";
|
---|
[466] | 61 | usage += "\n h/integ nameh1d [norm]";
|
---|
[1057] | 62 | usage += "\n Related commands: h/deriv";
|
---|
[466] | 63 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 64 |
|
---|
| 65 | kw = "h/deriv";
|
---|
[1057] | 66 | usage = "Derivate a 1D histogram";
|
---|
[466] | 67 | usage += "\n h/deriv nameh1d";
|
---|
[1057] | 68 | usage += "\n Related commands: h/integ";
|
---|
[466] | 69 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 70 |
|
---|
| 71 | kw = "h/rebin";
|
---|
| 72 | usage = "Rebin a 1D histogram or profile";
|
---|
[1057] | 73 | usage += "\n h/rebin nameh1d nbin";
|
---|
[466] | 74 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 75 |
|
---|
| 76 | kw = "h/cadd";
|
---|
[1073] | 77 | usage = "Add a constant to an histogram, a vector or a matrix";
|
---|
[1057] | 78 | usage += "\n h/cadd namehisto val";
|
---|
[1054] | 79 | usage += "\n Related commands: h/cmult h/oper";
|
---|
[466] | 80 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 81 |
|
---|
| 82 | kw = "h/cmult";
|
---|
[1073] | 83 | usage = "Multiply an histogram, a vector or a matrix by a constant";
|
---|
[1057] | 84 | usage += "\n h/cmult namehisto val";
|
---|
[1054] | 85 | usage += "\n Related commands: h/cadd h/oper";
|
---|
[466] | 86 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 87 |
|
---|
[1054] | 88 | kw = "h/oper";
|
---|
[1073] | 89 | usage = "Operation on histograms vectors or matrices";
|
---|
[1054] | 90 | usage += "\n h/oper @ h1 h2 hres";
|
---|
| 91 | usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
|
---|
[1073] | 92 | usage += "\n For vectors and matrices, operations are elements by elements";
|
---|
[1054] | 93 | usage += "\n Related commands: h/cadd h/cmult";
|
---|
| 94 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 95 |
|
---|
[466] | 96 | kw = "h/plot/2d";
|
---|
| 97 | usage = "Specific plot for 2D histogrammes";
|
---|
| 98 | usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme";
|
---|
| 99 | usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
|
---|
| 100 | usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
|
---|
| 101 | usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
|
---|
| 102 | usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
|
---|
| 103 | usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
|
---|
| 104 | usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
|
---|
| 105 | usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
|
---|
| 106 | usage += "\n n < 0 means Show Info";
|
---|
| 107 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[1065] | 108 |
|
---|
| 109 | kw = "h/put_vec";
|
---|
| 110 | usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
|
---|
| 111 | usage += "\n h/put_vec nameh1d namevector [cont,err2]";
|
---|
| 112 | usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
|
---|
| 113 | usage += "\n cont : put into histogramme content";
|
---|
| 114 | usage += "\n err2 : put into histogramme error^2";
|
---|
| 115 | usage += "\n Related commands: h/get_vec";
|
---|
| 116 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 117 |
|
---|
| 118 | kw = "h/get_vec";
|
---|
| 119 | usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
|
---|
| 120 | usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
|
---|
| 121 | usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
|
---|
| 122 | usage += "\n cont : get histogramme content";
|
---|
| 123 | usage += "\n err2 : get histogramme error^2";
|
---|
| 124 | usage += "\n absc : get histogramme low bin abscissa (1D only)";
|
---|
| 125 | usage += "\n proj :";
|
---|
| 126 | usage += "\n show : show available projections for Histo2D";
|
---|
| 127 | usage += "\n px : get X projection";
|
---|
| 128 | usage += "\n py : get Y projection";
|
---|
| 129 | usage += "\n bx n : get X band number n";
|
---|
| 130 | usage += "\n by n : get Y band number n";
|
---|
| 131 | usage += "\n sx n : get X slice number n";
|
---|
| 132 | usage += "\n sy n : get Y slice number n";
|
---|
| 133 | usage += "\n Related commands: h/put_vec";
|
---|
| 134 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 135 |
|
---|
[1070] | 136 | kw = "h/copy";
|
---|
[1073] | 137 | usage = "Copy content of object1 into object2";
|
---|
[1070] | 138 | usage += "\n objects are Vector,Matrix,Histo,Histo2D";
|
---|
[1071] | 139 | usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
|
---|
| 140 | usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)";
|
---|
| 141 | usage += "\n copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)";
|
---|
| 142 | usage += "\n Warning: elements from i1 to i2 included are copied";
|
---|
| 143 | usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1";
|
---|
| 144 | usage += "\n or obj2Dto with size i2-i1+1,j2-j1+1";
|
---|
| 145 | usage += "\n The adressed content of obj?Dfrom is overwritten";
|
---|
| 146 | usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
|
---|
[1070] | 147 | usage += "\n Related commands: copy";
|
---|
| 148 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 149 |
|
---|
[463] | 150 | }
|
---|
| 151 |
|
---|
[466] | 152 | /* methode */
|
---|
[463] | 153 | PAWExecutor::~PAWExecutor()
|
---|
| 154 | {
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[466] | 157 | /* methode */
|
---|
[463] | 158 | int PAWExecutor::Execute(string& kw, vector<string>& tokens)
|
---|
| 159 | {
|
---|
[466] | 160 | if(kw == "reset") {
|
---|
| 161 | reset(tokens); return(0);
|
---|
| 162 | } else if(kw == "n/plot") {
|
---|
| 163 | n_plot(tokens); return(0);
|
---|
| 164 | } else if(kw == "n/proj") {
|
---|
| 165 | n_proj(tokens); return(0);
|
---|
| 166 | } else if(kw == "h/integ") {
|
---|
| 167 | h_integ(tokens); return(0);
|
---|
| 168 | } else if(kw == "h/deriv") {
|
---|
| 169 | h_deriv(tokens); return(0);
|
---|
| 170 | } else if(kw == "h/rebin") {
|
---|
| 171 | h_rebin(tokens); return(0);
|
---|
| 172 | } else if(kw == "h/cadd") {
|
---|
| 173 | h_cadd(tokens); return(0);
|
---|
| 174 | } else if(kw == "h/cmult") {
|
---|
| 175 | h_cmult(tokens); return(0);
|
---|
[1054] | 176 | } else if(kw == "h/oper") {
|
---|
| 177 | h_oper(tokens); return(0);
|
---|
[466] | 178 | } else if(kw == "h/plot/2d") {
|
---|
| 179 | h_plot_2d(tokens); return(0);
|
---|
[1065] | 180 | } else if(kw == "h/put_vec") {
|
---|
| 181 | h_put_vec(tokens); return(0);
|
---|
| 182 | } else if(kw == "h/get_vec") {
|
---|
| 183 | h_get_vec(tokens); return(0);
|
---|
[1070] | 184 | } else if(kw == "h/copy") {
|
---|
| 185 | h_copy(tokens); return(0);
|
---|
[466] | 186 | } else return(1);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | /* methode */
|
---|
| 190 | void PAWExecutor::reset(vector<string>& tokens)
|
---|
| 191 | // Reset d'histogrammes, vecteurs et matrices
|
---|
| 192 | {
|
---|
| 193 | if(tokens.size() < 1)
|
---|
[469] | 194 | {cout<<"Usage: reset nameobj"<<endl; return;}
|
---|
[466] | 195 | NamedObjMgr omg;
|
---|
| 196 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 197 | if(mobj == NULL)
|
---|
| 198 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
| 199 | return;}
|
---|
| 200 | string ctyp = typeid(*mobj).name();
|
---|
| 201 |
|
---|
[545] | 202 | #ifdef SANS_EVOLPLANCK
|
---|
[466] | 203 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
|
---|
| 204 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
|
---|
[545] | 205 | #else
|
---|
[815] | 206 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
|
---|
| 207 | // ob->DataBlock().Reset(0.);}
|
---|
| 208 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
|
---|
| 209 | //ob->DataBlock().Reset(0.);}
|
---|
[545] | 210 | #endif
|
---|
[466] | 211 | else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
|
---|
| 212 | else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
|
---|
| 213 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
|
---|
| 214 | else {
|
---|
| 215 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
|
---|
| 216 | return;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | return;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | /* methode */
|
---|
| 223 | void PAWExecutor::n_plot(vector<string>& tokens)
|
---|
| 224 | // Equivalent n/plot de paw
|
---|
| 225 | // Plot 1D
|
---|
| 226 | // n/plot nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 227 | // Plot 2D (plot2dw)
|
---|
| 228 | // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 229 | // Plot 3D (plot3d)
|
---|
| 230 | // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
|
---|
| 231 | {
|
---|
| 232 | if(tokens.size() < 1) {
|
---|
| 233 | cout
|
---|
[1035] | 234 | <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
|
---|
[469] | 235 | <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 236 | <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 237 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
|
---|
[466] | 238 | return;
|
---|
| 239 | }
|
---|
| 240 | string nameobj,expx,expy,expz;
|
---|
| 241 | int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
|
---|
[1035] | 242 | string expcut = "1"; string expwt = "1."; string loop = "";
|
---|
| 243 | string dopt = ""; string nameproj="";
|
---|
[469] | 244 | if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
[466] | 245 |
|
---|
| 246 | NamedObjMgr omg;
|
---|
| 247 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 248 |
|
---|
| 249 | if(nvar<=0) {
|
---|
| 250 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
|
---|
| 251 | } else if(nvar==1) { // c'est un plot 1D
|
---|
[1035] | 252 | if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
|
---|
| 253 | if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
|
---|
| 254 | if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
|
---|
| 255 | if(tokens.size()>=6) nameproj = tokens[5];
|
---|
| 256 | if(nameproj.length()<=0 || nameproj=="!") {
|
---|
| 257 | nameproj = "/autoc/paw_n_plot1D_";
|
---|
| 258 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 259 | if(mobj!=NULL) {
|
---|
| 260 | char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
|
---|
| 261 | nameproj += buff;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
[466] | 264 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
| 265 | } else if(nvar==2) { // c'est un plot 2D
|
---|
[469] | 266 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 267 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
| 268 | string err = "";
|
---|
| 269 | srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
|
---|
[466] | 270 | } else { // c'est un plot 3D
|
---|
[469] | 271 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 272 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
[466] | 273 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | return;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | /* methode */
|
---|
| 280 | void PAWExecutor::n_proj(vector<string>& tokens)
|
---|
| 281 | // Equivalent n/proj de paw
|
---|
| 282 | // Project NTuple in histogram a la paw
|
---|
| 283 | // Dans un Histo 1D
|
---|
| 284 | // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 285 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
|
---|
| 286 | // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 287 | {
|
---|
| 288 | if(tokens.size()<2)
|
---|
[469] | 289 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
|
---|
| 290 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
|
---|
[466] | 291 | string nameproj = tokens[0];
|
---|
| 292 | string nameobj,expx,expy,expz;
|
---|
| 293 | int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
|
---|
[469] | 294 | string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
|
---|
| 295 | if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
|
---|
| 296 | if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
|
---|
| 297 | if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
|
---|
| 298 | if(tokens.size()>=6) dopt = tokens[5];
|
---|
[466] | 299 |
|
---|
| 300 | NamedObjMgr omg;
|
---|
| 301 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 302 |
|
---|
[1076] | 303 | if(nvar==1) {
|
---|
[466] | 304 | // c'est une projection dans un histo 1D
|
---|
| 305 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
[1076] | 306 | } else if(nvar==2) {
|
---|
[466] | 307 | // c'est une projection dans un histo2D
|
---|
[1076] | 308 | // OU un HProf si nameproj est un HProf un deja defini
|
---|
[466] | 309 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 310 | if(mobj==NULL)
|
---|
| 311 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 312 | else if(dynamic_cast<HProf*>(mobj))
|
---|
| 313 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 314 | else
|
---|
| 315 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
[1076] | 316 | } else {
|
---|
| 317 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<" nvar="<<nvar<<endl;
|
---|
[466] | 318 | }
|
---|
| 319 |
|
---|
| 320 | return;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | /* methode */
|
---|
| 324 | void PAWExecutor::h_integ(vector<string>& tokens)
|
---|
| 325 | // Pour remplacer le contenu d'un histo 1D par son integrale
|
---|
| 326 | {
|
---|
| 327 | if(tokens.size()<1)
|
---|
| 328 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
|
---|
| 329 | NamedObjMgr omg;
|
---|
| 330 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 331 | if(mobj==NULL)
|
---|
| 332 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
| 333 | return;}
|
---|
| 334 | double norm = 1.;
|
---|
| 335 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
[1057] | 336 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 337 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 338 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 339 | if(hp || !h1)
|
---|
| 340 | {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 341 | return;}
|
---|
| 342 | h1->HInteg(norm);
|
---|
[466] | 343 | }
|
---|
| 344 |
|
---|
| 345 | /* methode */
|
---|
| 346 | void PAWExecutor::h_deriv(vector<string>& tokens)
|
---|
| 347 | // Pour remplacer le contenu d'un histo 1D par sa derivee
|
---|
| 348 | {
|
---|
| 349 | if(tokens.size()<1)
|
---|
| 350 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
|
---|
| 351 | NamedObjMgr omg;
|
---|
| 352 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 353 | if(mobj==NULL)
|
---|
| 354 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
| 355 | return;}
|
---|
[1057] | 356 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 357 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 358 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 359 | if(hp || !h1)
|
---|
| 360 | {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 361 | return;}
|
---|
| 362 | h1->HDeriv();
|
---|
[466] | 363 | }
|
---|
| 364 |
|
---|
| 365 | /* methode */
|
---|
| 366 | void PAWExecutor::h_rebin(vector<string>& tokens)
|
---|
| 367 | // Pour re-binner un histogramme 1D
|
---|
| 368 | {
|
---|
| 369 | if(tokens.size()<2)
|
---|
| 370 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
|
---|
| 371 | NamedObjMgr omg;
|
---|
| 372 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 373 | if(mobj==NULL)
|
---|
| 374 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
|
---|
| 375 | return;}
|
---|
| 376 | int nbin = atoi(tokens[1].c_str());
|
---|
| 377 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1059] | 378 | // Ca marche aussi pour les HProf, HRebin a ete passe virtuel
|
---|
| 379 | //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
|
---|
| 380 | if(!h1)
|
---|
[1073] | 381 | {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
[1057] | 382 | return;}
|
---|
| 383 | h1->HRebin(nbin);
|
---|
[466] | 384 | }
|
---|
| 385 |
|
---|
| 386 | /* methode */
|
---|
| 387 | void PAWExecutor::h_cadd(vector<string>& tokens)
|
---|
| 388 | // Additionne une constante a un histogramme
|
---|
| 389 | {
|
---|
| 390 | if(tokens.size()<2)
|
---|
| 391 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
|
---|
| 392 | NamedObjMgr omg;
|
---|
| 393 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 394 | if(mobj==NULL)
|
---|
| 395 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
|
---|
| 396 | return;}
|
---|
| 397 | double val = atof(tokens[1].c_str());
|
---|
| 398 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 399 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 400 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1073] | 401 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 402 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
[1057] | 403 | if(h1 && !hp) *h1 += val;
|
---|
| 404 | else if(h2) *h2 += val;
|
---|
[1073] | 405 | else if(v) *v += val;
|
---|
| 406 | else if(m) *m += val;
|
---|
| 407 | else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
[466] | 408 | }
|
---|
| 409 |
|
---|
| 410 | /* methode */
|
---|
| 411 | void PAWExecutor::h_cmult(vector<string>& tokens)
|
---|
| 412 | // Multiplie un histogramme par une constante
|
---|
| 413 | {
|
---|
| 414 | if(tokens.size()<2)
|
---|
| 415 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
|
---|
| 416 | NamedObjMgr omg;
|
---|
| 417 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 418 | if(mobj==NULL)
|
---|
| 419 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
|
---|
| 420 | return;}
|
---|
| 421 | double val = atof(tokens[1].c_str());
|
---|
| 422 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 423 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 424 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1073] | 425 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 426 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
[1057] | 427 | if(h1 && !hp) *h1 *= val;
|
---|
| 428 | else if(h2) *h2 *= val;
|
---|
[1073] | 429 | else if(v) *v += val;
|
---|
| 430 | else if(m) *m += val;
|
---|
| 431 | else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
[466] | 432 | }
|
---|
| 433 |
|
---|
| 434 | /* methode */
|
---|
[1054] | 435 | void PAWExecutor::h_oper(vector<string>& tokens)
|
---|
| 436 | // Equivalent h/oper/add sub,mul,div de paw
|
---|
[1073] | 437 | // Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
|
---|
[1054] | 438 | // h/oper @ h1 h2 hres
|
---|
| 439 | // hres = h1 @ h2 with @ = (+,-,*,/)
|
---|
[1073] | 440 | // Pour les vecteurs et les matrices, il sagit d'operations elements a elements
|
---|
[1054] | 441 | {
|
---|
| 442 | if(tokens.size()<4)
|
---|
[1073] | 443 | {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
|
---|
[1054] | 444 | return;}
|
---|
| 445 |
|
---|
| 446 | // Decode arguments
|
---|
| 447 | const char * oper = tokens[0].c_str();
|
---|
| 448 | if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
|
---|
| 449 | {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
|
---|
| 450 | return;}
|
---|
| 451 | string h1name = tokens[1];
|
---|
| 452 | string h2name = tokens[2];
|
---|
| 453 | string h3name = tokens[3];
|
---|
| 454 |
|
---|
| 455 | // Get objects
|
---|
| 456 | NamedObjMgr omg;
|
---|
| 457 | AnyDataObj* mobjh1 = omg.GetObj(h1name);
|
---|
| 458 | AnyDataObj* mobjh2 = omg.GetObj(h2name);
|
---|
| 459 | if( mobjh1==NULL || mobjh2==NULL )
|
---|
| 460 | {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
|
---|
| 461 | return;}
|
---|
| 462 | AnyDataObj* mobjh3 = omg.GetObj(h3name);
|
---|
| 463 |
|
---|
| 464 | // Operations on HProf, only + is working
|
---|
| 465 | if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
|
---|
| 466 | if( oper[0]!='+' )
|
---|
| 467 | { cout<<"PAWExecutor::h_oper Error: operation "<<oper
|
---|
| 468 | <<" not implemented for HProf"<<endl; return;}
|
---|
| 469 | if( dynamic_cast<HProf*>(mobjh2) == NULL )
|
---|
[1057] | 470 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 471 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 472 | return;}
|
---|
| 473 | HProf* h1 =(HProf*) mobjh1;
|
---|
| 474 | HProf* h2 =(HProf*) mobjh2;
|
---|
| 475 | if( h1->NBins() != h2->NBins() )
|
---|
| 476 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 477 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 478 | HProf* h3 = NULL;
|
---|
[1073] | 479 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 480 | {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 481 | h3 = dynamic_cast<HProf*>(mobjh3);
|
---|
| 482 | if(h3 == NULL) // ce n'est pas un HProf
|
---|
| 483 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 484 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 485 | if(h1->NBins() != h3->NBins())
|
---|
| 486 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 487 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 488 | *h3 = *h1 + *h2;
|
---|
| 489 | h3->UpdateHisto();
|
---|
[1054] | 490 |
|
---|
| 491 | // Operations on Histo
|
---|
| 492 | } else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
|
---|
| 493 | if( dynamic_cast<Histo*>(mobjh2) == NULL )
|
---|
[1057] | 494 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 495 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 496 | return;}
|
---|
| 497 | Histo* h1 =(Histo*) mobjh1;
|
---|
| 498 | Histo* h2 =(Histo*) mobjh2;
|
---|
| 499 | if( h1->NBins() != h2->NBins() )
|
---|
| 500 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 501 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 502 | Histo* h3 = NULL;
|
---|
[1073] | 503 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 504 | {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 505 | h3 = dynamic_cast<Histo*>(mobjh3);
|
---|
| 506 | if(h3 == NULL) // ce n'est pas un Histo
|
---|
| 507 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 508 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 509 | if(h1->NBins() != h3->NBins())
|
---|
| 510 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 511 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 512 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 513 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 514 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 515 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
[1054] | 516 |
|
---|
| 517 | // Operations on Histo2D
|
---|
| 518 | } else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
|
---|
| 519 | if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
|
---|
[1057] | 520 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 521 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 522 | return;}
|
---|
| 523 | Histo2D* h1 =(Histo2D*) mobjh1;
|
---|
| 524 | Histo2D* h2 =(Histo2D*) mobjh2;
|
---|
| 525 | if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
|
---|
| 526 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 527 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 528 | <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
|
---|
| 529 | Histo2D* h3 = NULL;
|
---|
[1073] | 530 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 531 | {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 532 | h3 = dynamic_cast<Histo2D*>(mobjh3);
|
---|
| 533 | if(h3 == NULL) // ce n'est pas un Histo2D
|
---|
| 534 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 535 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 536 | if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
|
---|
| 537 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 538 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 539 | <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
|
---|
| 540 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 541 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 542 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 543 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
| 544 |
|
---|
| 545 | // Operations on Vector
|
---|
| 546 | } else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
|
---|
| 547 | if( dynamic_cast<Vector*>(mobjh2) == NULL )
|
---|
| 548 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
| 549 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 550 | return;}
|
---|
| 551 | Vector* h1 =(Vector*) mobjh1;
|
---|
| 552 | Vector* h2 =(Vector*) mobjh2;
|
---|
| 553 | if( h1->NElts() != h2->NElts() )
|
---|
| 554 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 555 | <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
|
---|
| 556 | Vector* h3 = NULL;
|
---|
[1054] | 557 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
[1073] | 558 | #ifdef SANS_EVOLPLANCK
|
---|
| 559 | h3 = new Vector(*h1);
|
---|
| 560 | #else
|
---|
| 561 | h3 = new Vector(*h1,false);
|
---|
| 562 | #endif
|
---|
| 563 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
[1054] | 564 | }
|
---|
[1073] | 565 | h3 = dynamic_cast<Vector*>(mobjh3);
|
---|
| 566 | if(h3 == NULL) // ce n'est pas un Vector
|
---|
| 567 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 568 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 569 | if(h1->NElts() != h3->NElts())
|
---|
| 570 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 571 | <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
|
---|
| 572 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 573 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 574 | #ifdef SANS_EVOLPLANCK
|
---|
| 575 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
| 576 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
| 577 | <<" not implemented for Vector in Peida"<<endl;
|
---|
| 578 | #else
|
---|
| 579 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
|
---|
| 580 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
|
---|
| 581 | #endif
|
---|
[1054] | 582 |
|
---|
[1073] | 583 | // Operations on Matrix
|
---|
| 584 | } else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
|
---|
| 585 | if( dynamic_cast<Matrix*>(mobjh2) == NULL )
|
---|
| 586 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
| 587 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 588 | return;}
|
---|
| 589 | Matrix* h1 =(Matrix*) mobjh1;
|
---|
| 590 | Matrix* h2 =(Matrix*) mobjh2;
|
---|
| 591 | if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
|
---|
| 592 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 593 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
| 594 | <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
|
---|
| 595 | Matrix* h3 = NULL;
|
---|
| 596 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 597 | #ifdef SANS_EVOLPLANCK
|
---|
| 598 | h3 = new Matrix(*h1);
|
---|
| 599 | #else
|
---|
| 600 | h3 = new Matrix(*h1,false);
|
---|
| 601 | #endif
|
---|
| 602 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
| 603 | }
|
---|
| 604 | h3 = dynamic_cast<Matrix*>(mobjh3);
|
---|
| 605 | if(h3 == NULL) // ce n'est pas un Matrix
|
---|
| 606 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 607 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 608 | if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
|
---|
| 609 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 610 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
| 611 | <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
|
---|
| 612 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 613 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 614 | #ifdef SANS_EVOLPLANCK
|
---|
| 615 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
| 616 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
| 617 | <<" not implemented for Vector in Peida"<<endl;
|
---|
| 618 | #else
|
---|
| 619 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
|
---|
| 620 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
|
---|
| 621 | #endif
|
---|
| 622 |
|
---|
[1054] | 623 | // Doesn't work for other objects
|
---|
| 624 | } else {
|
---|
[1057] | 625 | cout<<"PAWExecutor::h_oper Error: not implemented for "
|
---|
| 626 | <<typeid(*mobjh1).name()<<endl;
|
---|
[1054] | 627 | return;
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | return;
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 | /* methode */
|
---|
[466] | 634 | void PAWExecutor::h_plot_2d(vector<string>& tokens)
|
---|
| 635 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
|
---|
| 636 | {
|
---|
[1065] | 637 | if(tokens.size()<1)
|
---|
[466] | 638 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
|
---|
[1065] | 639 | string proj = "h"; if(tokens.size()>1) proj = tokens[1];
|
---|
[466] | 640 | NamedObjMgr omg;
|
---|
| 641 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 642 | if(mobj==NULL)
|
---|
| 643 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
|
---|
| 644 | return;}
|
---|
| 645 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 646 | if(!h2)
|
---|
| 647 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
|
---|
| 648 | return;}
|
---|
| 649 |
|
---|
| 650 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
|
---|
| 651 |
|
---|
| 652 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
|
---|
[1065] | 653 | if(proj == "show") {
|
---|
[466] | 654 | h2->ShowProj();
|
---|
| 655 | h2->ShowBand(2);
|
---|
| 656 | h2->ShowSli(2);
|
---|
| 657 | return;
|
---|
[1065] | 658 | } else if(proj == "h") {
|
---|
[466] | 659 | nametoplot = tokens[0];
|
---|
[1065] | 660 | } else if(proj == "px") {
|
---|
[466] | 661 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 662 | else {h2->ShowProj(); return;}
|
---|
[1065] | 663 | } else if(proj == "py") {
|
---|
[466] | 664 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 665 | else {h2->ShowProj(); return;}
|
---|
| 666 | } else {
|
---|
| 667 | if(tokens.size()<3)
|
---|
| 668 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
|
---|
| 669 | int n = atoi(tokens[2].c_str());
|
---|
| 670 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
|
---|
[1065] | 671 | if(proj == "bx") {
|
---|
[466] | 672 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 673 | else {h2->ShowBand(); return;}
|
---|
[1065] | 674 | } else if(proj == "by") {
|
---|
[466] | 675 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 676 | else {h2->ShowBand(); return;}
|
---|
[1065] | 677 | } else if(proj == "sx") {
|
---|
[466] | 678 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 679 | else {h2->ShowSli(); return;}
|
---|
[1065] | 680 | } else if(proj == "sy") {
|
---|
[466] | 681 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 682 | else {h2->ShowSli(); return;}
|
---|
[463] | 683 | }
|
---|
| 684 | }
|
---|
[466] | 685 |
|
---|
| 686 | omg.DisplayObj(nametoplot,dopt);
|
---|
| 687 | }
|
---|
| 688 |
|
---|
| 689 | /* methode */
|
---|
| 690 | int PAWExecutor::decodepawstring(string tokens,string& nameobj
|
---|
| 691 | ,string& xexp,string& yexp,string& zexp)
|
---|
| 692 | // Decodage general de "nameobj.xexp"
|
---|
| 693 | // "nameobj.yexp%xexp"
|
---|
| 694 | // "nameobj.zexp%yexp%xexp"
|
---|
| 695 | // Return: nombre de variables trouvees, -1 si probleme
|
---|
| 696 | {
|
---|
| 697 | nameobj = ""; xexp= ""; yexp= ""; zexp= "";
|
---|
| 698 |
|
---|
| 699 | int lt = (int) tokens.length();
|
---|
| 700 | if(lt<=0) return -1;
|
---|
| 701 |
|
---|
| 702 | // decodage de la chaine de type PAW.
|
---|
| 703 | char *str = new char[lt+2];
|
---|
| 704 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
|
---|
| 705 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
|
---|
| 706 | char *c[3] = {NULL,NULL,NULL};
|
---|
| 707 | int i, np=0; bool namefound = false;
|
---|
[562] | 708 | for(i=0;i<lt;i++) {
|
---|
[466] | 709 | if(!namefound && str[i]=='.') {
|
---|
| 710 | str[i]='\0';
|
---|
| 711 | namefound=true;
|
---|
| 712 | c[np] = str+i+1; np++;
|
---|
| 713 | }
|
---|
| 714 | if( namefound && str[i]=='%') {
|
---|
| 715 | str[i]='\0';
|
---|
| 716 | if(np<3) {c[np] = str+i+1; np++;}
|
---|
| 717 | }
|
---|
| 718 | }
|
---|
| 719 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
|
---|
| 720 |
|
---|
| 721 | // Remplissage du nom et des variables
|
---|
| 722 | nameobj = str;
|
---|
| 723 | if(np==1) xexp=c[0];
|
---|
| 724 | if(np==2) {yexp=c[0]; xexp=c[1];}
|
---|
| 725 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
|
---|
| 726 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
|
---|
| 727 | delete [] str;
|
---|
| 728 |
|
---|
| 729 | // Comptage des variables
|
---|
| 730 | np = -1;
|
---|
| 731 | if(nameobj.length()>0)
|
---|
| 732 | {np = 0; if(xexp.length()>0)
|
---|
| 733 | {np++; if(yexp.length()>0)
|
---|
| 734 | {np++; if(zexp.length()>0) np++;}}}
|
---|
| 735 | cout<<"pawstring["<<np<<"] name="<<nameobj
|
---|
| 736 | <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
|
---|
| 737 | return np;
|
---|
| 738 | }
|
---|
[1065] | 739 |
|
---|
| 740 | /* methode */
|
---|
| 741 | void PAWExecutor::h_put_vec(vector<string>& tokens)
|
---|
| 742 | // Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
|
---|
| 743 | // L'histogramme doit deja exister. Le nombre de bins remplit
|
---|
| 744 | // depend des tailles respectives des 2 objets.
|
---|
[1067] | 745 | // tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!")
|
---|
[1065] | 746 | // = "err2" : on remplit les erreurs de l'histogramme
|
---|
| 747 | {
|
---|
| 748 | if(tokens.size()<2)
|
---|
| 749 | {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
|
---|
| 750 | return;}
|
---|
| 751 | string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
|
---|
[1067] | 752 | if(toput=="!") toput = "cont";
|
---|
[1065] | 753 | if(toput!="cont" && toput!="err2")
|
---|
| 754 | {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
|
---|
| 755 | return;}
|
---|
| 756 | string hname = tokens[0];
|
---|
| 757 | string vname = tokens[1];
|
---|
| 758 |
|
---|
| 759 | // Get objects
|
---|
| 760 | NamedObjMgr omg;
|
---|
| 761 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 762 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 763 | if( mobjh==NULL || mobjv==NULL )
|
---|
| 764 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
|
---|
| 765 | return;}
|
---|
| 766 |
|
---|
[1076] | 767 | // Fill Histo from Vector
|
---|
[1065] | 768 | if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
|
---|
| 769 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 770 | Vector* v = dynamic_cast<Vector*>(mobjv);
|
---|
| 771 | if(toput=="cont") h->PutValue(*v);
|
---|
| 772 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 773 |
|
---|
[1076] | 774 | // Fill Histo2D from Matrix
|
---|
[1065] | 775 | } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
|
---|
| 776 | Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 777 | Matrix* v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 778 | if(toput=="cont") h->PutValue(*v);
|
---|
| 779 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 780 |
|
---|
| 781 | } else {
|
---|
| 782 | cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
|
---|
| 783 | <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
|
---|
| 784 | return;
|
---|
| 785 | }
|
---|
| 786 |
|
---|
| 787 | }
|
---|
| 788 |
|
---|
| 789 | /* methode */
|
---|
| 790 | void PAWExecutor::h_get_vec(vector<string>& tokens)
|
---|
| 791 | // Pour copier un histo dans un vecteur ou une matrice
|
---|
| 792 | // Si le vecteur (matrice) n'existe pas, il est cree.
|
---|
| 793 | // Le vecteur ou la matrice est re-dimensionne correctement.
|
---|
[1067] | 794 | // tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!")
|
---|
[1065] | 795 | // = "err2" : on copie les erreurs de l'histogramme
|
---|
| 796 | // = "absc" : on copie les erreurs de l'histogramme (1D only)
|
---|
| 797 | // tokens[3[,4]] = show : show available projections for Histo2D
|
---|
| 798 | // px : get X projection
|
---|
| 799 | // py : get Y projection
|
---|
| 800 | // bx n : get X band number n
|
---|
| 801 | // by n : get Y band number n
|
---|
| 802 | // sx n : get X slice number n
|
---|
| 803 | // sy n : get Y slice number n
|
---|
| 804 | {
|
---|
| 805 | if(tokens.size()<2)
|
---|
| 806 | {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
|
---|
| 807 | return;}
|
---|
| 808 | string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
|
---|
[1067] | 809 | if(toget=="!") toget = "cont";
|
---|
[1065] | 810 | if(toget!="cont" && toget!="err2" && toget!="absc")
|
---|
| 811 | {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
|
---|
| 812 | return;}
|
---|
| 813 | string proj = "h"; if(tokens.size()>3) proj = tokens[3];
|
---|
| 814 | int nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
|
---|
| 815 | string hname = tokens[0];
|
---|
| 816 | string vname = tokens[1];
|
---|
| 817 |
|
---|
| 818 | // Get objects
|
---|
| 819 | NamedObjMgr omg;
|
---|
| 820 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 821 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 822 | if( mobjh==NULL)
|
---|
| 823 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
|
---|
| 824 | return;}
|
---|
| 825 |
|
---|
[1076] | 826 | // Copy Histo/Histo2D/Projection to Vector/Matrix
|
---|
[1065] | 827 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 828 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 829 | if( h != NULL ) { // Histo ou HProf
|
---|
| 830 | HProf* hp = dynamic_cast<HProf*>(mobjh);
|
---|
| 831 | if(hp!=NULL) if(!(hp->IsOk())) hp->UpdateHisto();
|
---|
| 832 | Vector* v = NULL;
|
---|
| 833 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
[1073] | 834 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 835 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 836 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
|
---|
| 837 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 838 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 839 | if(toget=="cont") h->GetValue(*v);
|
---|
| 840 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 841 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 842 |
|
---|
| 843 | } else if( h2 != NULL) { // Histo2D
|
---|
| 844 |
|
---|
| 845 | if(proj == "h") { // On veut les valeurs de l'histogramme 2D
|
---|
| 846 | Matrix* v = NULL;
|
---|
| 847 | if(mobjv==NULL) // la matrice n'existe pas
|
---|
[1073] | 848 | {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 849 | if(typeid(*mobjv) != typeid(Matrix))
|
---|
| 850 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
|
---|
| 851 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 852 | v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 853 | if(toget=="cont") h2->GetValue(*v);
|
---|
| 854 | else if(toget=="err2") h2->GetError2(*v);
|
---|
| 855 | else
|
---|
| 856 | {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
|
---|
| 857 | return;}
|
---|
| 858 |
|
---|
| 859 | } else { // On veut les valeurs d'une projection de l'histo 2D
|
---|
| 860 | h = NULL;
|
---|
| 861 | if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
|
---|
| 862 | else if(proj == "px") h = h2->HProjX();
|
---|
| 863 | else if(proj == "py") h = h2->HProjY();
|
---|
| 864 | else if(proj == "bx") h = h2->HBandX(nproj);
|
---|
| 865 | else if(proj == "by") h = h2->HBandY(nproj);
|
---|
| 866 | else if(proj == "sx") h = h2->HSliX(nproj);
|
---|
| 867 | else if(proj == "sy") h = h2->HSliY(nproj);
|
---|
| 868 | if(h==NULL)
|
---|
| 869 | {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
|
---|
| 870 | <<" number "<<nproj<<endl; return;}
|
---|
| 871 | Vector* v = NULL;
|
---|
| 872 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
[1073] | 873 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 874 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 875 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
|
---|
| 876 | <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
|
---|
| 877 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 878 | if(toget=="cont") h->GetValue(*v);
|
---|
| 879 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 880 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 881 | }
|
---|
| 882 |
|
---|
| 883 | } else {
|
---|
| 884 | cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
|
---|
| 885 | <<typeid(*mobjh).name()<<endl;
|
---|
| 886 | return;
|
---|
| 887 | }
|
---|
| 888 |
|
---|
| 889 | }
|
---|
[1070] | 890 |
|
---|
| 891 | /* methode */
|
---|
| 892 | void PAWExecutor::h_copy(vector<string>& tokens)
|
---|
| 893 | // Pour copier un object dans un object
|
---|
| 894 | // objects are Vector,Matrix,Histo,Histo2D
|
---|
[1071] | 895 | // h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
|
---|
| 896 | // copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
|
---|
| 897 | // copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
|
---|
[1070] | 898 | // Attention: elements depuis i1 jusqu'a i2 COMPRIS
|
---|
[1071] | 899 | // Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
|
---|
| 900 | // ou obj2Dto avec une taille i2-i1+1,j2-j1+1
|
---|
| 901 | // Le contenu de obj?Dfrom adresse est surecrit
|
---|
| 902 | // Le contenu de obj?Dfrom non adresse reste le meme
|
---|
[1070] | 903 | {
|
---|
[1071] | 904 | int tks = tokens.size();
|
---|
| 905 | if(tks<2)
|
---|
| 906 | {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
|
---|
[1070] | 907 | return;}
|
---|
| 908 |
|
---|
| 909 | NamedObjMgr omg;
|
---|
| 910 | AnyDataObj* mobjv1 = omg.GetObj(tokens[0]);
|
---|
| 911 | if( mobjv1==NULL)
|
---|
| 912 | {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
|
---|
| 913 | return;}
|
---|
[1071] | 914 | AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
|
---|
[1070] | 915 |
|
---|
[1071] | 916 | int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
|
---|
| 917 |
|
---|
[1070] | 918 | // Cas d'un Vector
|
---|
| 919 | if(typeid(*mobjv1) == typeid(Vector)) {
|
---|
[1071] | 920 | Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
|
---|
| 921 | i2=nx1-1;
|
---|
| 922 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 923 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
[1070] | 924 | if(i2<i1)
|
---|
| 925 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
|
---|
[1071] | 926 | <<nx1<<endl; return;}
|
---|
[1070] | 927 | Vector* v2 = NULL;
|
---|
| 928 | if(mobjv2==NULL)
|
---|
[1073] | 929 | {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 930 | if(typeid(*mobjv2) != typeid(Vector))
|
---|
| 931 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
|
---|
| 932 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 933 | v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
|
---|
| 934 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
| 935 | if(ic1<0) ic1=0;
|
---|
| 936 | if(ic1>=nx2)
|
---|
| 937 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
|
---|
| 938 | <<nx2<<endl; return;}
|
---|
| 939 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
| 940 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
|
---|
[1070] | 941 | return;
|
---|
| 942 | }
|
---|
| 943 |
|
---|
| 944 | // Cas d'un Histo
|
---|
| 945 | if(typeid(*mobjv1) == typeid(Histo)) {
|
---|
[1071] | 946 | Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
|
---|
| 947 | i2=nx1-1;
|
---|
| 948 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 949 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
[1070] | 950 | if(i2<i1)
|
---|
| 951 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
|
---|
[1071] | 952 | <<nx1<<endl; return;}
|
---|
[1070] | 953 | Histo* v2 = NULL;
|
---|
| 954 | if(mobjv2==NULL)
|
---|
[1073] | 955 | {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1);
|
---|
| 956 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 957 | if(typeid(*mobjv2) != typeid(Histo))
|
---|
| 958 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
|
---|
| 959 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 960 | v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
|
---|
| 961 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
| 962 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
| 963 | if(ic1<0) ic1=0;
|
---|
| 964 | if(ic1>=nx2)
|
---|
| 965 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
|
---|
| 966 | <<nx2<<endl; return;}
|
---|
| 967 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
| 968 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 969 | {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
|
---|
[1070] | 970 | return;
|
---|
| 971 | }
|
---|
| 972 |
|
---|
| 973 | // Cas d'une Matrix
|
---|
| 974 | if(typeid(*mobjv1) == typeid(Matrix)) {
|
---|
[1071] | 975 | Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
|
---|
| 976 | i2=nx1-1; j2=ny1-1;
|
---|
| 977 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 978 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 979 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
[1070] | 980 | if(i2<i1 || j2<j1)
|
---|
| 981 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
| 982 | <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
|
---|
[1071] | 983 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
[1070] | 984 | Matrix* v2 = NULL;
|
---|
| 985 | if(mobjv2==NULL)
|
---|
[1073] | 986 | {v2 = new Matrix(i2-i1+1,j2-j1+1);
|
---|
| 987 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 988 | if(typeid(*mobjv2) != typeid(Matrix))
|
---|
| 989 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
|
---|
| 990 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 991 | v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
|
---|
| 992 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
| 993 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
| 994 | if(ic1>=nx2 || jc1>=ny2)
|
---|
| 995 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
| 996 | <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
|
---|
| 997 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
| 998 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
| 999 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 1000 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
|
---|
[1070] | 1001 | return;
|
---|
| 1002 | }
|
---|
| 1003 |
|
---|
| 1004 | // Cas d'un Histo2D
|
---|
| 1005 | if(typeid(*mobjv1) == typeid(Histo2D)) {
|
---|
[1071] | 1006 | Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
|
---|
| 1007 | i2=nx1-1; j2=ny1-1;
|
---|
| 1008 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 1009 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 1010 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
[1070] | 1011 | if(i2<i1 || j2<j1)
|
---|
| 1012 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
| 1013 | <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
|
---|
[1071] | 1014 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
[1070] | 1015 | Histo2D* v2 = NULL;
|
---|
| 1016 | if(mobjv2==NULL)
|
---|
| 1017 | {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1);
|
---|
[1073] | 1018 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 1019 | if(typeid(*mobjv2) != typeid(Histo2D))
|
---|
| 1020 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
|
---|
| 1021 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 1022 | v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
|
---|
| 1023 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
| 1024 | if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
| 1025 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
| 1026 | if(ic1>=nx2 || jc1>=ny2)
|
---|
| 1027 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
| 1028 | <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
|
---|
| 1029 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
| 1030 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
| 1031 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 1032 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
|
---|
| 1033 | {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
|
---|
[1070] | 1034 | return;
|
---|
| 1035 | }
|
---|
| 1036 |
|
---|
| 1037 | // Cas non prevu
|
---|
| 1038 | cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n"
|
---|
| 1039 | <<typeid(*mobjv1).name()<<endl;
|
---|
| 1040 | return;
|
---|
| 1041 | }
|
---|