[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";
|
---|
| 60 | usage = "Integrate a 1D histogram or profile";
|
---|
| 61 | usage += "\n h/integ nameh1d [norm]";
|
---|
| 62 | usage += "\n Related commands: h/deriv";
|
---|
| 63 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 64 |
|
---|
| 65 | kw = "h/deriv";
|
---|
| 66 | usage = "Derivate a 1D histogram or profile";
|
---|
| 67 | usage += "\n h/deriv nameh1d";
|
---|
| 68 | usage += "\n Related commands: h/integ";
|
---|
| 69 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 70 |
|
---|
| 71 | kw = "h/rebin";
|
---|
| 72 | usage = "Rebin a 1D histogram or profile";
|
---|
| 73 | usage += "\n h/rebin nbin";
|
---|
| 74 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 75 |
|
---|
| 76 | kw = "h/cadd";
|
---|
[1054] | 77 | usage = "Add a constant to an histogram";
|
---|
[466] | 78 | usage += "\n h/cadd val";
|
---|
[1054] | 79 | usage += "\n Related commands: h/cmult h/oper";
|
---|
[466] | 80 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 81 |
|
---|
| 82 | kw = "h/cmult";
|
---|
[1054] | 83 | usage = "Multiply an histogram by a constant";
|
---|
[466] | 84 | usage += "\n h/cmult 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";
|
---|
| 89 | usage = "Operation on histograms";
|
---|
| 90 | usage += "\n h/oper @ h1 h2 hres";
|
---|
| 91 | usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
|
---|
| 92 | usage += "\n Related commands: h/cadd h/cmult";
|
---|
| 93 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 94 |
|
---|
[466] | 95 | kw = "h/plot/2d";
|
---|
| 96 | usage = "Specific plot for 2D histogrammes";
|
---|
| 97 | usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme";
|
---|
| 98 | usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
|
---|
| 99 | usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
|
---|
| 100 | usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
|
---|
| 101 | usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
|
---|
| 102 | usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
|
---|
| 103 | usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
|
---|
| 104 | usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
|
---|
| 105 | usage += "\n n < 0 means Show Info";
|
---|
| 106 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[463] | 107 | }
|
---|
| 108 |
|
---|
[466] | 109 | /* methode */
|
---|
[463] | 110 | PAWExecutor::~PAWExecutor()
|
---|
| 111 | {
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[466] | 114 | /* methode */
|
---|
[463] | 115 | int PAWExecutor::Execute(string& kw, vector<string>& tokens)
|
---|
| 116 | {
|
---|
[466] | 117 | if(kw == "reset") {
|
---|
| 118 | reset(tokens); return(0);
|
---|
| 119 | } else if(kw == "n/plot") {
|
---|
| 120 | n_plot(tokens); return(0);
|
---|
| 121 | } else if(kw == "n/proj") {
|
---|
| 122 | n_proj(tokens); return(0);
|
---|
| 123 | } else if(kw == "h/integ") {
|
---|
| 124 | h_integ(tokens); return(0);
|
---|
| 125 | } else if(kw == "h/deriv") {
|
---|
| 126 | h_deriv(tokens); return(0);
|
---|
| 127 | } else if(kw == "h/rebin") {
|
---|
| 128 | h_rebin(tokens); return(0);
|
---|
| 129 | } else if(kw == "h/cadd") {
|
---|
| 130 | h_cadd(tokens); return(0);
|
---|
| 131 | } else if(kw == "h/cmult") {
|
---|
| 132 | h_cmult(tokens); return(0);
|
---|
[1054] | 133 | } else if(kw == "h/oper") {
|
---|
| 134 | h_oper(tokens); return(0);
|
---|
[466] | 135 | } else if(kw == "h/plot/2d") {
|
---|
| 136 | h_plot_2d(tokens); return(0);
|
---|
| 137 | } else return(1);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /* methode */
|
---|
| 141 | void PAWExecutor::reset(vector<string>& tokens)
|
---|
| 142 | // Reset d'histogrammes, vecteurs et matrices
|
---|
| 143 | {
|
---|
| 144 | if(tokens.size() < 1)
|
---|
[469] | 145 | {cout<<"Usage: reset nameobj"<<endl; return;}
|
---|
[466] | 146 | NamedObjMgr omg;
|
---|
| 147 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 148 | if(mobj == NULL)
|
---|
| 149 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
| 150 | return;}
|
---|
| 151 | string ctyp = typeid(*mobj).name();
|
---|
| 152 |
|
---|
[545] | 153 | #ifdef SANS_EVOLPLANCK
|
---|
[466] | 154 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
|
---|
| 155 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
|
---|
[545] | 156 | #else
|
---|
[815] | 157 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
|
---|
| 158 | // ob->DataBlock().Reset(0.);}
|
---|
| 159 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
|
---|
| 160 | //ob->DataBlock().Reset(0.);}
|
---|
[545] | 161 | #endif
|
---|
[466] | 162 | else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
|
---|
| 163 | else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
|
---|
| 164 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
|
---|
| 165 | else {
|
---|
| 166 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
|
---|
| 167 | return;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | return;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | /* methode */
|
---|
| 174 | void PAWExecutor::n_plot(vector<string>& tokens)
|
---|
| 175 | // Equivalent n/plot de paw
|
---|
| 176 | // Plot 1D
|
---|
| 177 | // n/plot nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 178 | // Plot 2D (plot2dw)
|
---|
| 179 | // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 180 | // Plot 3D (plot3d)
|
---|
| 181 | // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
|
---|
| 182 | {
|
---|
| 183 | if(tokens.size() < 1) {
|
---|
| 184 | cout
|
---|
[1035] | 185 | <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
|
---|
[469] | 186 | <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 187 | <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 188 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
|
---|
[466] | 189 | return;
|
---|
| 190 | }
|
---|
| 191 | string nameobj,expx,expy,expz;
|
---|
| 192 | int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
|
---|
[1035] | 193 | string expcut = "1"; string expwt = "1."; string loop = "";
|
---|
| 194 | string dopt = ""; string nameproj="";
|
---|
[469] | 195 | if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
[466] | 196 |
|
---|
| 197 | NamedObjMgr omg;
|
---|
| 198 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 199 |
|
---|
| 200 | if(nvar<=0) {
|
---|
| 201 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
|
---|
| 202 | } else if(nvar==1) { // c'est un plot 1D
|
---|
[1035] | 203 | if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
|
---|
| 204 | if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
|
---|
| 205 | if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
|
---|
| 206 | if(tokens.size()>=6) nameproj = tokens[5];
|
---|
| 207 | if(nameproj.length()<=0 || nameproj=="!") {
|
---|
| 208 | nameproj = "/autoc/paw_n_plot1D_";
|
---|
| 209 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 210 | if(mobj!=NULL) {
|
---|
| 211 | char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
|
---|
| 212 | nameproj += buff;
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
[466] | 215 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
| 216 | } else if(nvar==2) { // c'est un plot 2D
|
---|
[469] | 217 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 218 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
| 219 | string err = "";
|
---|
| 220 | srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
|
---|
[466] | 221 | } else { // c'est un plot 3D
|
---|
[469] | 222 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 223 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
[466] | 224 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | return;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | /* methode */
|
---|
| 231 | void PAWExecutor::n_proj(vector<string>& tokens)
|
---|
| 232 | // Equivalent n/proj de paw
|
---|
| 233 | // Project NTuple in histogram a la paw
|
---|
| 234 | // Dans un Histo 1D
|
---|
| 235 | // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 236 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
|
---|
| 237 | // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 238 | {
|
---|
| 239 | if(tokens.size()<2)
|
---|
[469] | 240 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
|
---|
| 241 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
|
---|
[466] | 242 | string nameproj = tokens[0];
|
---|
| 243 | string nameobj,expx,expy,expz;
|
---|
| 244 | int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
|
---|
[469] | 245 | string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
|
---|
| 246 | if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
|
---|
| 247 | if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
|
---|
| 248 | if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
|
---|
| 249 | if(tokens.size()>=6) dopt = tokens[5];
|
---|
[466] | 250 |
|
---|
| 251 | NamedObjMgr omg;
|
---|
| 252 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 253 |
|
---|
| 254 | if(nvar<=0) {
|
---|
| 255 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<endl;
|
---|
| 256 | } else if(nvar==1) {
|
---|
| 257 | // c'est une projection dans un histo 1D
|
---|
| 258 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
| 259 | } else {
|
---|
| 260 | // c'est une projection dans un histo2D
|
---|
| 261 | // OU un HProf si nameproj est HProf un deja defini
|
---|
| 262 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 263 | if(mobj==NULL)
|
---|
| 264 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 265 | else if(dynamic_cast<HProf*>(mobj))
|
---|
| 266 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 267 | else
|
---|
| 268 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | return;
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | /* methode */
|
---|
| 275 | void PAWExecutor::h_integ(vector<string>& tokens)
|
---|
| 276 | // Pour remplacer le contenu d'un histo 1D par son integrale
|
---|
| 277 | {
|
---|
| 278 | if(tokens.size()<1)
|
---|
| 279 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
|
---|
| 280 | NamedObjMgr omg;
|
---|
| 281 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 282 | if(mobj==NULL)
|
---|
| 283 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
| 284 | return;}
|
---|
| 285 | double norm = 1.;
|
---|
| 286 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
| 287 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
| 288 | // Le HProf se fait tout seul avec Histo: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
| 289 | //HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 290 | if(h1) h1->HInteg(norm);
|
---|
| 291 | //else if(hp) hp->HInteg(norm);
|
---|
| 292 | else cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | /* methode */
|
---|
| 296 | void PAWExecutor::h_deriv(vector<string>& tokens)
|
---|
| 297 | // Pour remplacer le contenu d'un histo 1D par sa derivee
|
---|
| 298 | {
|
---|
| 299 | if(tokens.size()<1)
|
---|
| 300 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
|
---|
| 301 | NamedObjMgr omg;
|
---|
| 302 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 303 | if(mobj==NULL)
|
---|
| 304 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
| 305 | return;}
|
---|
| 306 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
| 307 | //HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 308 | if(h1) h1->HDeriv();
|
---|
| 309 | //else if(hp) hp->HDeriv();
|
---|
| 310 | else cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | /* methode */
|
---|
| 314 | void PAWExecutor::h_rebin(vector<string>& tokens)
|
---|
| 315 | // Pour re-binner un histogramme 1D
|
---|
| 316 | {
|
---|
| 317 | if(tokens.size()<2)
|
---|
| 318 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
|
---|
| 319 | NamedObjMgr omg;
|
---|
| 320 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 321 | if(mobj==NULL)
|
---|
| 322 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
|
---|
| 323 | return;}
|
---|
| 324 | int nbin = atoi(tokens[1].c_str());
|
---|
| 325 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
| 326 | //HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 327 | if(h1) h1->HRebin(nbin);
|
---|
| 328 | //else if(hp) hp->HRebin(nbin);
|
---|
| 329 | else cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | /* methode */
|
---|
| 333 | void PAWExecutor::h_cadd(vector<string>& tokens)
|
---|
| 334 | // Additionne une constante a un histogramme
|
---|
| 335 | {
|
---|
| 336 | if(tokens.size()<2)
|
---|
| 337 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
|
---|
| 338 | NamedObjMgr omg;
|
---|
| 339 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 340 | if(mobj==NULL)
|
---|
| 341 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
|
---|
| 342 | return;}
|
---|
| 343 | double val = atof(tokens[1].c_str());
|
---|
| 344 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
| 345 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 346 | if(h1) *h1 += val;
|
---|
| 347 | else if(h2) *h2 += val;
|
---|
| 348 | else cout<<"PAWExecutor::h_cadd Error: "<<tokens[0]<<" not an Histo/HProf/Histo2D"<<endl;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /* methode */
|
---|
| 352 | void PAWExecutor::h_cmult(vector<string>& tokens)
|
---|
| 353 | // Multiplie un histogramme par une constante
|
---|
| 354 | {
|
---|
| 355 | if(tokens.size()<2)
|
---|
| 356 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
|
---|
| 357 | NamedObjMgr omg;
|
---|
| 358 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 359 | if(mobj==NULL)
|
---|
| 360 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
|
---|
| 361 | return;}
|
---|
| 362 | double val = atof(tokens[1].c_str());
|
---|
| 363 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
| 364 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 365 | if(h1) *h1 *= val;
|
---|
| 366 | else if(h2) *h2 *= val;
|
---|
| 367 | else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0]
|
---|
| 368 | <<" not an Histo/HProf/Histo2D"<<endl;
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | /* methode */
|
---|
[1054] | 372 | void PAWExecutor::h_oper(vector<string>& tokens)
|
---|
| 373 | // Equivalent h/oper/add sub,mul,div de paw
|
---|
| 374 | // Operation entre 2 histogrammes
|
---|
| 375 | // h/oper @ h1 h2 hres
|
---|
| 376 | // hres = h1 @ h2 with @ = (+,-,*,/)
|
---|
| 377 | {
|
---|
| 378 | cout<<"*** WARNING *** Not Tested, Do Not Use (cmv) !"<<endl;
|
---|
| 379 | cerr<<"*** WARNING *** Not Tested, Do Not Use (cmv) !"<<endl;
|
---|
| 380 | if(tokens.size()<4)
|
---|
| 381 | {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/)"<<endl;
|
---|
| 382 | return;}
|
---|
| 383 |
|
---|
| 384 | // Decode arguments
|
---|
| 385 | const char * oper = tokens[0].c_str();
|
---|
| 386 | if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
|
---|
| 387 | {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
|
---|
| 388 | return;}
|
---|
| 389 | string h1name = tokens[1];
|
---|
| 390 | string h2name = tokens[2];
|
---|
| 391 | string h3name = tokens[3];
|
---|
| 392 |
|
---|
| 393 | // Get objects
|
---|
| 394 | NamedObjMgr omg;
|
---|
| 395 | AnyDataObj* mobjh1 = omg.GetObj(h1name);
|
---|
| 396 | AnyDataObj* mobjh2 = omg.GetObj(h2name);
|
---|
| 397 | if( mobjh1==NULL || mobjh2==NULL )
|
---|
| 398 | {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
|
---|
| 399 | return;}
|
---|
| 400 | AnyDataObj* mobjh3 = omg.GetObj(h3name);
|
---|
| 401 |
|
---|
| 402 | // Operations on HProf, only + is working
|
---|
| 403 | if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
|
---|
| 404 | if( oper[0]!='+' )
|
---|
| 405 | { cout<<"PAWExecutor::h_oper Error: operation "<<oper
|
---|
| 406 | <<" not implemented for HProf"<<endl; return;}
|
---|
| 407 | if( dynamic_cast<HProf*>(mobjh2) == NULL )
|
---|
| 408 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2 "
|
---|
| 409 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 410 | return;}
|
---|
| 411 | HProf* h1 =(HProf*) mobjh1;
|
---|
| 412 | HProf* h2 =(HProf*) mobjh2;
|
---|
| 413 | if( h1->NBins() != h2->NBins() )
|
---|
| 414 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 415 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 416 | HProf* h3 = NULL;
|
---|
| 417 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 418 | h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name);
|
---|
| 419 | } else { // l'objet existe
|
---|
| 420 | h3 = dynamic_cast<HProf*>(mobjh3);
|
---|
| 421 | if(h3 == NULL) // ce n'est pas un HProf
|
---|
| 422 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3 "
|
---|
| 423 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
|
---|
| 424 | return;}
|
---|
| 425 | if(h1->NBins() != h3->NBins())
|
---|
| 426 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 427 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 428 | h3->Zero();
|
---|
| 429 | *h3 = *h1 + *h2;
|
---|
| 430 | h3->UpdateHisto();
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | // Operations on Histo
|
---|
| 434 | } else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
|
---|
| 435 | if( dynamic_cast<Histo*>(mobjh2) == NULL )
|
---|
| 436 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2 "
|
---|
| 437 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 438 | return;}
|
---|
| 439 | Histo* h1 =(Histo*) mobjh1;
|
---|
| 440 | Histo* h2 =(Histo*) mobjh2;
|
---|
| 441 | if( h1->NBins() != h2->NBins() )
|
---|
| 442 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 443 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 444 | Histo* h3 = NULL;
|
---|
| 445 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 446 | h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name);
|
---|
| 447 | } else { // l'objet existe
|
---|
| 448 | h3 = dynamic_cast<Histo*>(mobjh3);
|
---|
| 449 | if(h3 == NULL) // ce n'est pas un Histo
|
---|
| 450 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3 "
|
---|
| 451 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
|
---|
| 452 | return;}
|
---|
| 453 | if(h1->NBins() != h3->NBins())
|
---|
| 454 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 455 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 456 | h3->Zero();
|
---|
| 457 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 458 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 459 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 460 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | // Operations on Histo2D
|
---|
| 464 | } else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
|
---|
| 465 | if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
|
---|
| 466 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2 "
|
---|
| 467 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 468 | return;}
|
---|
| 469 | Histo2D* h1 =(Histo2D*) mobjh1;
|
---|
| 470 | Histo2D* h2 =(Histo2D*) mobjh2;
|
---|
| 471 | if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
|
---|
| 472 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 473 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 474 | <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
|
---|
| 475 | Histo2D* h3 = NULL;
|
---|
| 476 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 477 | h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name);
|
---|
| 478 | } else { // l'objet existe
|
---|
| 479 | h3 = dynamic_cast<Histo2D*>(mobjh3);
|
---|
| 480 | if(h3 == NULL) // ce n'est pas un Histo2D
|
---|
| 481 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3 "
|
---|
| 482 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
|
---|
| 483 | return;}
|
---|
| 484 | if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
|
---|
| 485 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 486 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 487 | <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
|
---|
| 488 | h3->Zero();
|
---|
| 489 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 490 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 491 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 492 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | // Doesn't work for other objects
|
---|
| 496 | } else {
|
---|
| 497 | cout<<"PAWExecutor::h_oper Error: not implemented for "<<typeid(*mobjh1).name()<<endl;
|
---|
| 498 | return;
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | return;
|
---|
| 502 | }
|
---|
| 503 |
|
---|
| 504 | /* methode */
|
---|
[466] | 505 | void PAWExecutor::h_plot_2d(vector<string>& tokens)
|
---|
| 506 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
|
---|
| 507 | {
|
---|
| 508 | if(tokens.size()<2)
|
---|
| 509 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
|
---|
| 510 | NamedObjMgr omg;
|
---|
| 511 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 512 | if(mobj==NULL)
|
---|
| 513 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
|
---|
| 514 | return;}
|
---|
| 515 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 516 | if(!h2)
|
---|
| 517 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
|
---|
| 518 | return;}
|
---|
| 519 |
|
---|
| 520 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
|
---|
| 521 | AnyDataObj* mobjh1 = omg.GetObj(nametoplot);
|
---|
[685] | 522 | // if(mobjh1!=NULL) omg.DelObj(nametoplot); $CHECK$ Reza 12/12/99 - Ne pas faire - autoclean
|
---|
[466] | 523 |
|
---|
| 524 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
|
---|
| 525 | if(tokens[1] == "show") {
|
---|
| 526 | h2->ShowProj();
|
---|
| 527 | h2->ShowBand(2);
|
---|
| 528 | h2->ShowSli(2);
|
---|
| 529 | return;
|
---|
| 530 | } else if(tokens[1] == "h") {
|
---|
| 531 | nametoplot = tokens[0];
|
---|
| 532 | } else if(tokens[1] == "px") {
|
---|
| 533 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 534 | else {h2->ShowProj(); return;}
|
---|
| 535 | } else if(tokens[1] == "py") {
|
---|
| 536 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 537 | else {h2->ShowProj(); return;}
|
---|
| 538 | } else {
|
---|
| 539 | if(tokens.size()<3)
|
---|
| 540 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
|
---|
| 541 | int n = atoi(tokens[2].c_str());
|
---|
| 542 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
|
---|
| 543 | if(tokens[1] == "bx") {
|
---|
| 544 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 545 | else {h2->ShowBand(); return;}
|
---|
| 546 | } else if(tokens[1] == "by") {
|
---|
| 547 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 548 | else {h2->ShowBand(); return;}
|
---|
| 549 | } else if(tokens[1] == "sx") {
|
---|
| 550 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 551 | else {h2->ShowSli(); return;}
|
---|
| 552 | } else if(tokens[1] == "sy") {
|
---|
| 553 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 554 | else {h2->ShowSli(); return;}
|
---|
[463] | 555 | }
|
---|
| 556 | }
|
---|
[466] | 557 |
|
---|
| 558 | omg.DisplayObj(nametoplot,dopt);
|
---|
| 559 | }
|
---|
| 560 |
|
---|
| 561 | /* methode */
|
---|
| 562 | int PAWExecutor::decodepawstring(string tokens,string& nameobj
|
---|
| 563 | ,string& xexp,string& yexp,string& zexp)
|
---|
| 564 | // Decodage general de "nameobj.xexp"
|
---|
| 565 | // "nameobj.yexp%xexp"
|
---|
| 566 | // "nameobj.zexp%yexp%xexp"
|
---|
| 567 | // Return: nombre de variables trouvees, -1 si probleme
|
---|
| 568 | {
|
---|
| 569 | nameobj = ""; xexp= ""; yexp= ""; zexp= "";
|
---|
| 570 |
|
---|
| 571 | int lt = (int) tokens.length();
|
---|
| 572 | if(lt<=0) return -1;
|
---|
| 573 |
|
---|
| 574 | // decodage de la chaine de type PAW.
|
---|
| 575 | char *str = new char[lt+2];
|
---|
| 576 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
|
---|
| 577 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
|
---|
| 578 | char *c[3] = {NULL,NULL,NULL};
|
---|
| 579 | int i, np=0; bool namefound = false;
|
---|
[562] | 580 | for(i=0;i<lt;i++) {
|
---|
[466] | 581 | if(!namefound && str[i]=='.') {
|
---|
| 582 | str[i]='\0';
|
---|
| 583 | namefound=true;
|
---|
| 584 | c[np] = str+i+1; np++;
|
---|
| 585 | }
|
---|
| 586 | if( namefound && str[i]=='%') {
|
---|
| 587 | str[i]='\0';
|
---|
| 588 | if(np<3) {c[np] = str+i+1; np++;}
|
---|
| 589 | }
|
---|
| 590 | }
|
---|
| 591 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
|
---|
| 592 |
|
---|
| 593 | // Remplissage du nom et des variables
|
---|
| 594 | nameobj = str;
|
---|
| 595 | if(np==1) xexp=c[0];
|
---|
| 596 | if(np==2) {yexp=c[0]; xexp=c[1];}
|
---|
| 597 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
|
---|
| 598 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
|
---|
| 599 | delete [] str;
|
---|
| 600 |
|
---|
| 601 | // Comptage des variables
|
---|
| 602 | np = -1;
|
---|
| 603 | if(nameobj.length()>0)
|
---|
| 604 | {np = 0; if(xexp.length()>0)
|
---|
| 605 | {np++; if(yexp.length()>0)
|
---|
| 606 | {np++; if(zexp.length()>0) np++;}}}
|
---|
| 607 | cout<<"pawstring["<<np<<"] name="<<nameobj
|
---|
| 608 | <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
|
---|
| 609 | return np;
|
---|
| 610 | }
|
---|