[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";
|
---|
[1054] | 77 | usage = "Add a constant to an histogram";
|
---|
[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";
|
---|
[1054] | 83 | usage = "Multiply an histogram 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";
|
---|
| 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);
|
---|
[1065] | 107 |
|
---|
| 108 | kw = "h/put_vec";
|
---|
| 109 | usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
|
---|
| 110 | usage += "\n h/put_vec nameh1d namevector [cont,err2]";
|
---|
| 111 | usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
|
---|
| 112 | usage += "\n cont : put into histogramme content";
|
---|
| 113 | usage += "\n err2 : put into histogramme error^2";
|
---|
| 114 | usage += "\n Related commands: h/get_vec";
|
---|
| 115 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 116 |
|
---|
| 117 | kw = "h/get_vec";
|
---|
| 118 | usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
|
---|
| 119 | usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
|
---|
| 120 | usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
|
---|
| 121 | usage += "\n cont : get histogramme content";
|
---|
| 122 | usage += "\n err2 : get histogramme error^2";
|
---|
| 123 | usage += "\n absc : get histogramme low bin abscissa (1D only)";
|
---|
| 124 | usage += "\n proj :";
|
---|
| 125 | usage += "\n show : show available projections for Histo2D";
|
---|
| 126 | usage += "\n px : get X projection";
|
---|
| 127 | usage += "\n py : get Y projection";
|
---|
| 128 | usage += "\n bx n : get X band number n";
|
---|
| 129 | usage += "\n by n : get Y band number n";
|
---|
| 130 | usage += "\n sx n : get X slice number n";
|
---|
| 131 | usage += "\n sy n : get Y slice number n";
|
---|
| 132 | usage += "\n Related commands: h/put_vec";
|
---|
| 133 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 134 |
|
---|
[463] | 135 | }
|
---|
| 136 |
|
---|
[466] | 137 | /* methode */
|
---|
[463] | 138 | PAWExecutor::~PAWExecutor()
|
---|
| 139 | {
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[466] | 142 | /* methode */
|
---|
[463] | 143 | int PAWExecutor::Execute(string& kw, vector<string>& tokens)
|
---|
| 144 | {
|
---|
[466] | 145 | if(kw == "reset") {
|
---|
| 146 | reset(tokens); return(0);
|
---|
| 147 | } else if(kw == "n/plot") {
|
---|
| 148 | n_plot(tokens); return(0);
|
---|
| 149 | } else if(kw == "n/proj") {
|
---|
| 150 | n_proj(tokens); return(0);
|
---|
| 151 | } else if(kw == "h/integ") {
|
---|
| 152 | h_integ(tokens); return(0);
|
---|
| 153 | } else if(kw == "h/deriv") {
|
---|
| 154 | h_deriv(tokens); return(0);
|
---|
| 155 | } else if(kw == "h/rebin") {
|
---|
| 156 | h_rebin(tokens); return(0);
|
---|
| 157 | } else if(kw == "h/cadd") {
|
---|
| 158 | h_cadd(tokens); return(0);
|
---|
| 159 | } else if(kw == "h/cmult") {
|
---|
| 160 | h_cmult(tokens); return(0);
|
---|
[1054] | 161 | } else if(kw == "h/oper") {
|
---|
| 162 | h_oper(tokens); return(0);
|
---|
[466] | 163 | } else if(kw == "h/plot/2d") {
|
---|
| 164 | h_plot_2d(tokens); return(0);
|
---|
[1065] | 165 | } else if(kw == "h/put_vec") {
|
---|
| 166 | h_put_vec(tokens); return(0);
|
---|
| 167 | } else if(kw == "h/get_vec") {
|
---|
| 168 | h_get_vec(tokens); return(0);
|
---|
[466] | 169 | } else return(1);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | /* methode */
|
---|
| 173 | void PAWExecutor::reset(vector<string>& tokens)
|
---|
| 174 | // Reset d'histogrammes, vecteurs et matrices
|
---|
| 175 | {
|
---|
| 176 | if(tokens.size() < 1)
|
---|
[469] | 177 | {cout<<"Usage: reset nameobj"<<endl; return;}
|
---|
[466] | 178 | NamedObjMgr omg;
|
---|
| 179 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 180 | if(mobj == NULL)
|
---|
| 181 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
| 182 | return;}
|
---|
| 183 | string ctyp = typeid(*mobj).name();
|
---|
| 184 |
|
---|
[545] | 185 | #ifdef SANS_EVOLPLANCK
|
---|
[466] | 186 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
|
---|
| 187 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
|
---|
[545] | 188 | #else
|
---|
[815] | 189 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
|
---|
| 190 | // ob->DataBlock().Reset(0.);}
|
---|
| 191 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
|
---|
| 192 | //ob->DataBlock().Reset(0.);}
|
---|
[545] | 193 | #endif
|
---|
[466] | 194 | else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
|
---|
| 195 | else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
|
---|
| 196 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
|
---|
| 197 | else {
|
---|
| 198 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
|
---|
| 199 | return;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | return;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | /* methode */
|
---|
| 206 | void PAWExecutor::n_plot(vector<string>& tokens)
|
---|
| 207 | // Equivalent n/plot de paw
|
---|
| 208 | // Plot 1D
|
---|
| 209 | // n/plot nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 210 | // Plot 2D (plot2dw)
|
---|
| 211 | // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 212 | // Plot 3D (plot3d)
|
---|
| 213 | // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
|
---|
| 214 | {
|
---|
| 215 | if(tokens.size() < 1) {
|
---|
| 216 | cout
|
---|
[1035] | 217 | <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
|
---|
[469] | 218 | <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 219 | <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 220 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
|
---|
[466] | 221 | return;
|
---|
| 222 | }
|
---|
| 223 | string nameobj,expx,expy,expz;
|
---|
| 224 | int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
|
---|
[1035] | 225 | string expcut = "1"; string expwt = "1."; string loop = "";
|
---|
| 226 | string dopt = ""; string nameproj="";
|
---|
[469] | 227 | if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
[466] | 228 |
|
---|
| 229 | NamedObjMgr omg;
|
---|
| 230 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 231 |
|
---|
| 232 | if(nvar<=0) {
|
---|
| 233 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
|
---|
| 234 | } else if(nvar==1) { // c'est un plot 1D
|
---|
[1035] | 235 | if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
|
---|
| 236 | if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
|
---|
| 237 | if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
|
---|
| 238 | if(tokens.size()>=6) nameproj = tokens[5];
|
---|
| 239 | if(nameproj.length()<=0 || nameproj=="!") {
|
---|
| 240 | nameproj = "/autoc/paw_n_plot1D_";
|
---|
| 241 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 242 | if(mobj!=NULL) {
|
---|
| 243 | char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
|
---|
| 244 | nameproj += buff;
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
[466] | 247 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
| 248 | } else if(nvar==2) { // c'est un plot 2D
|
---|
[469] | 249 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 250 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
| 251 | string err = "";
|
---|
| 252 | srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
|
---|
[466] | 253 | } else { // c'est un plot 3D
|
---|
[469] | 254 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 255 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
[466] | 256 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | return;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | /* methode */
|
---|
| 263 | void PAWExecutor::n_proj(vector<string>& tokens)
|
---|
| 264 | // Equivalent n/proj de paw
|
---|
| 265 | // Project NTuple in histogram a la paw
|
---|
| 266 | // Dans un Histo 1D
|
---|
| 267 | // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 268 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
|
---|
| 269 | // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 270 | {
|
---|
| 271 | if(tokens.size()<2)
|
---|
[469] | 272 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
|
---|
| 273 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
|
---|
[466] | 274 | string nameproj = tokens[0];
|
---|
| 275 | string nameobj,expx,expy,expz;
|
---|
| 276 | int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
|
---|
[469] | 277 | string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
|
---|
| 278 | if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
|
---|
| 279 | if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
|
---|
| 280 | if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
|
---|
| 281 | if(tokens.size()>=6) dopt = tokens[5];
|
---|
[466] | 282 |
|
---|
| 283 | NamedObjMgr omg;
|
---|
| 284 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 285 |
|
---|
| 286 | if(nvar<=0) {
|
---|
| 287 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<endl;
|
---|
| 288 | } else if(nvar==1) {
|
---|
| 289 | // c'est une projection dans un histo 1D
|
---|
| 290 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
| 291 | } else {
|
---|
| 292 | // c'est une projection dans un histo2D
|
---|
| 293 | // OU un HProf si nameproj est HProf un deja defini
|
---|
| 294 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 295 | if(mobj==NULL)
|
---|
| 296 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 297 | else if(dynamic_cast<HProf*>(mobj))
|
---|
| 298 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 299 | else
|
---|
| 300 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | return;
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | /* methode */
|
---|
| 307 | void PAWExecutor::h_integ(vector<string>& tokens)
|
---|
| 308 | // Pour remplacer le contenu d'un histo 1D par son integrale
|
---|
| 309 | {
|
---|
| 310 | if(tokens.size()<1)
|
---|
| 311 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
|
---|
| 312 | NamedObjMgr omg;
|
---|
| 313 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 314 | if(mobj==NULL)
|
---|
| 315 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
| 316 | return;}
|
---|
| 317 | double norm = 1.;
|
---|
| 318 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
[1057] | 319 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 320 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 321 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 322 | if(hp || !h1)
|
---|
| 323 | {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 324 | return;}
|
---|
| 325 | h1->HInteg(norm);
|
---|
[466] | 326 | }
|
---|
| 327 |
|
---|
| 328 | /* methode */
|
---|
| 329 | void PAWExecutor::h_deriv(vector<string>& tokens)
|
---|
| 330 | // Pour remplacer le contenu d'un histo 1D par sa derivee
|
---|
| 331 | {
|
---|
| 332 | if(tokens.size()<1)
|
---|
| 333 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
|
---|
| 334 | NamedObjMgr omg;
|
---|
| 335 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 336 | if(mobj==NULL)
|
---|
| 337 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
| 338 | return;}
|
---|
[1057] | 339 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 340 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 341 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 342 | if(hp || !h1)
|
---|
| 343 | {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 344 | return;}
|
---|
| 345 | h1->HDeriv();
|
---|
[466] | 346 | }
|
---|
| 347 |
|
---|
| 348 | /* methode */
|
---|
| 349 | void PAWExecutor::h_rebin(vector<string>& tokens)
|
---|
| 350 | // Pour re-binner un histogramme 1D
|
---|
| 351 | {
|
---|
| 352 | if(tokens.size()<2)
|
---|
| 353 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
|
---|
| 354 | NamedObjMgr omg;
|
---|
| 355 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 356 | if(mobj==NULL)
|
---|
| 357 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
|
---|
| 358 | return;}
|
---|
| 359 | int nbin = atoi(tokens[1].c_str());
|
---|
| 360 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1059] | 361 | // Ca marche aussi pour les HProf, HRebin a ete passe virtuel
|
---|
| 362 | //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
|
---|
| 363 | if(!h1)
|
---|
[1057] | 364 | {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 365 | return;}
|
---|
| 366 | h1->HRebin(nbin);
|
---|
[466] | 367 | }
|
---|
| 368 |
|
---|
| 369 | /* methode */
|
---|
| 370 | void PAWExecutor::h_cadd(vector<string>& tokens)
|
---|
| 371 | // Additionne une constante a un histogramme
|
---|
| 372 | {
|
---|
| 373 | if(tokens.size()<2)
|
---|
| 374 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
|
---|
| 375 | NamedObjMgr omg;
|
---|
| 376 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 377 | if(mobj==NULL)
|
---|
| 378 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
|
---|
| 379 | return;}
|
---|
| 380 | double val = atof(tokens[1].c_str());
|
---|
| 381 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 382 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 383 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1057] | 384 | if(h1 && !hp) *h1 += val;
|
---|
| 385 | else if(h2) *h2 += val;
|
---|
| 386 | else cout<<"PAWExecutor::h_cadd Error: "<<tokens[0]<<" not an Histo/Histo2D"<<endl;
|
---|
[466] | 387 | }
|
---|
| 388 |
|
---|
| 389 | /* methode */
|
---|
| 390 | void PAWExecutor::h_cmult(vector<string>& tokens)
|
---|
| 391 | // Multiplie un histogramme par une constante
|
---|
| 392 | {
|
---|
| 393 | if(tokens.size()<2)
|
---|
| 394 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
|
---|
| 395 | NamedObjMgr omg;
|
---|
| 396 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 397 | if(mobj==NULL)
|
---|
| 398 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
|
---|
| 399 | return;}
|
---|
| 400 | double val = atof(tokens[1].c_str());
|
---|
| 401 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 402 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 403 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1057] | 404 | if(h1 && !hp) *h1 *= val;
|
---|
| 405 | else if(h2) *h2 *= val;
|
---|
[466] | 406 | else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0]
|
---|
[1057] | 407 | <<" not an Histo/Histo2D"<<endl;
|
---|
[466] | 408 | }
|
---|
| 409 |
|
---|
| 410 | /* methode */
|
---|
[1054] | 411 | void PAWExecutor::h_oper(vector<string>& tokens)
|
---|
| 412 | // Equivalent h/oper/add sub,mul,div de paw
|
---|
| 413 | // Operation entre 2 histogrammes
|
---|
| 414 | // h/oper @ h1 h2 hres
|
---|
| 415 | // hres = h1 @ h2 with @ = (+,-,*,/)
|
---|
| 416 | {
|
---|
| 417 | if(tokens.size()<4)
|
---|
| 418 | {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/)"<<endl;
|
---|
| 419 | return;}
|
---|
| 420 |
|
---|
| 421 | // Decode arguments
|
---|
| 422 | const char * oper = tokens[0].c_str();
|
---|
| 423 | if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
|
---|
| 424 | {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
|
---|
| 425 | return;}
|
---|
| 426 | string h1name = tokens[1];
|
---|
| 427 | string h2name = tokens[2];
|
---|
| 428 | string h3name = tokens[3];
|
---|
| 429 |
|
---|
| 430 | // Get objects
|
---|
| 431 | NamedObjMgr omg;
|
---|
| 432 | AnyDataObj* mobjh1 = omg.GetObj(h1name);
|
---|
| 433 | AnyDataObj* mobjh2 = omg.GetObj(h2name);
|
---|
| 434 | if( mobjh1==NULL || mobjh2==NULL )
|
---|
| 435 | {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
|
---|
| 436 | return;}
|
---|
| 437 | AnyDataObj* mobjh3 = omg.GetObj(h3name);
|
---|
| 438 |
|
---|
| 439 | // Operations on HProf, only + is working
|
---|
| 440 | if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
|
---|
| 441 | if( oper[0]!='+' )
|
---|
| 442 | { cout<<"PAWExecutor::h_oper Error: operation "<<oper
|
---|
| 443 | <<" not implemented for HProf"<<endl; return;}
|
---|
| 444 | if( dynamic_cast<HProf*>(mobjh2) == NULL )
|
---|
[1057] | 445 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 446 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 447 | return;}
|
---|
| 448 | HProf* h1 =(HProf*) mobjh1;
|
---|
| 449 | HProf* h2 =(HProf*) mobjh2;
|
---|
| 450 | if( h1->NBins() != h2->NBins() )
|
---|
| 451 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 452 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 453 | HProf* h3 = NULL;
|
---|
| 454 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 455 | h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name);
|
---|
| 456 | } else { // l'objet existe
|
---|
| 457 | h3 = dynamic_cast<HProf*>(mobjh3);
|
---|
| 458 | if(h3 == NULL) // ce n'est pas un HProf
|
---|
[1057] | 459 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
[1054] | 460 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
|
---|
| 461 | return;}
|
---|
| 462 | if(h1->NBins() != h3->NBins())
|
---|
| 463 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 464 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 465 | *h3 = *h1 + *h2;
|
---|
| 466 | h3->UpdateHisto();
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | // Operations on Histo
|
---|
| 470 | } else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
|
---|
| 471 | if( dynamic_cast<Histo*>(mobjh2) == NULL )
|
---|
[1057] | 472 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 473 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 474 | return;}
|
---|
| 475 | Histo* h1 =(Histo*) mobjh1;
|
---|
| 476 | Histo* h2 =(Histo*) mobjh2;
|
---|
| 477 | if( h1->NBins() != h2->NBins() )
|
---|
| 478 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 479 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 480 | Histo* h3 = NULL;
|
---|
| 481 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 482 | h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name);
|
---|
| 483 | } else { // l'objet existe
|
---|
| 484 | h3 = dynamic_cast<Histo*>(mobjh3);
|
---|
| 485 | if(h3 == NULL) // ce n'est pas un Histo
|
---|
[1057] | 486 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
[1054] | 487 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
|
---|
| 488 | return;}
|
---|
| 489 | if(h1->NBins() != h3->NBins())
|
---|
| 490 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 491 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 492 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 493 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 494 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 495 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
| 496 | }
|
---|
| 497 |
|
---|
| 498 | // Operations on Histo2D
|
---|
| 499 | } else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
|
---|
| 500 | if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
|
---|
[1057] | 501 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 502 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 503 | return;}
|
---|
| 504 | Histo2D* h1 =(Histo2D*) mobjh1;
|
---|
| 505 | Histo2D* h2 =(Histo2D*) mobjh2;
|
---|
| 506 | if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
|
---|
| 507 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 508 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 509 | <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
|
---|
| 510 | Histo2D* h3 = NULL;
|
---|
| 511 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 512 | h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name);
|
---|
| 513 | } else { // l'objet existe
|
---|
| 514 | h3 = dynamic_cast<Histo2D*>(mobjh3);
|
---|
| 515 | if(h3 == NULL) // ce n'est pas un Histo2D
|
---|
[1057] | 516 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
[1054] | 517 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
|
---|
| 518 | return;}
|
---|
| 519 | if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
|
---|
| 520 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 521 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 522 | <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
|
---|
| 523 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 524 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 525 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 526 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | // Doesn't work for other objects
|
---|
| 530 | } else {
|
---|
[1057] | 531 | cout<<"PAWExecutor::h_oper Error: not implemented for "
|
---|
| 532 | <<typeid(*mobjh1).name()<<endl;
|
---|
[1054] | 533 | return;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | return;
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | /* methode */
|
---|
[466] | 540 | void PAWExecutor::h_plot_2d(vector<string>& tokens)
|
---|
| 541 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
|
---|
| 542 | {
|
---|
[1065] | 543 | if(tokens.size()<1)
|
---|
[466] | 544 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
|
---|
[1065] | 545 | string proj = "h"; if(tokens.size()>1) proj = tokens[1];
|
---|
[466] | 546 | NamedObjMgr omg;
|
---|
| 547 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 548 | if(mobj==NULL)
|
---|
| 549 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
|
---|
| 550 | return;}
|
---|
| 551 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 552 | if(!h2)
|
---|
| 553 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
|
---|
| 554 | return;}
|
---|
| 555 |
|
---|
| 556 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
|
---|
[1065] | 557 | //AnyDataObj* mobjh1 = omg.GetObj(nametoplot);
|
---|
[466] | 558 |
|
---|
| 559 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
|
---|
[1065] | 560 | if(proj == "show") {
|
---|
[466] | 561 | h2->ShowProj();
|
---|
| 562 | h2->ShowBand(2);
|
---|
| 563 | h2->ShowSli(2);
|
---|
| 564 | return;
|
---|
[1065] | 565 | } else if(proj == "h") {
|
---|
[466] | 566 | nametoplot = tokens[0];
|
---|
[1065] | 567 | } else if(proj == "px") {
|
---|
[466] | 568 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 569 | else {h2->ShowProj(); return;}
|
---|
[1065] | 570 | } else if(proj == "py") {
|
---|
[466] | 571 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 572 | else {h2->ShowProj(); return;}
|
---|
| 573 | } else {
|
---|
| 574 | if(tokens.size()<3)
|
---|
| 575 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
|
---|
| 576 | int n = atoi(tokens[2].c_str());
|
---|
| 577 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
|
---|
[1065] | 578 | if(proj == "bx") {
|
---|
[466] | 579 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 580 | else {h2->ShowBand(); return;}
|
---|
[1065] | 581 | } else if(proj == "by") {
|
---|
[466] | 582 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 583 | else {h2->ShowBand(); return;}
|
---|
[1065] | 584 | } else if(proj == "sx") {
|
---|
[466] | 585 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 586 | else {h2->ShowSli(); return;}
|
---|
[1065] | 587 | } else if(proj == "sy") {
|
---|
[466] | 588 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 589 | else {h2->ShowSli(); return;}
|
---|
[463] | 590 | }
|
---|
| 591 | }
|
---|
[466] | 592 |
|
---|
| 593 | omg.DisplayObj(nametoplot,dopt);
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | /* methode */
|
---|
| 597 | int PAWExecutor::decodepawstring(string tokens,string& nameobj
|
---|
| 598 | ,string& xexp,string& yexp,string& zexp)
|
---|
| 599 | // Decodage general de "nameobj.xexp"
|
---|
| 600 | // "nameobj.yexp%xexp"
|
---|
| 601 | // "nameobj.zexp%yexp%xexp"
|
---|
| 602 | // Return: nombre de variables trouvees, -1 si probleme
|
---|
| 603 | {
|
---|
| 604 | nameobj = ""; xexp= ""; yexp= ""; zexp= "";
|
---|
| 605 |
|
---|
| 606 | int lt = (int) tokens.length();
|
---|
| 607 | if(lt<=0) return -1;
|
---|
| 608 |
|
---|
| 609 | // decodage de la chaine de type PAW.
|
---|
| 610 | char *str = new char[lt+2];
|
---|
| 611 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
|
---|
| 612 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
|
---|
| 613 | char *c[3] = {NULL,NULL,NULL};
|
---|
| 614 | int i, np=0; bool namefound = false;
|
---|
[562] | 615 | for(i=0;i<lt;i++) {
|
---|
[466] | 616 | if(!namefound && str[i]=='.') {
|
---|
| 617 | str[i]='\0';
|
---|
| 618 | namefound=true;
|
---|
| 619 | c[np] = str+i+1; np++;
|
---|
| 620 | }
|
---|
| 621 | if( namefound && str[i]=='%') {
|
---|
| 622 | str[i]='\0';
|
---|
| 623 | if(np<3) {c[np] = str+i+1; np++;}
|
---|
| 624 | }
|
---|
| 625 | }
|
---|
| 626 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
|
---|
| 627 |
|
---|
| 628 | // Remplissage du nom et des variables
|
---|
| 629 | nameobj = str;
|
---|
| 630 | if(np==1) xexp=c[0];
|
---|
| 631 | if(np==2) {yexp=c[0]; xexp=c[1];}
|
---|
| 632 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
|
---|
| 633 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
|
---|
| 634 | delete [] str;
|
---|
| 635 |
|
---|
| 636 | // Comptage des variables
|
---|
| 637 | np = -1;
|
---|
| 638 | if(nameobj.length()>0)
|
---|
| 639 | {np = 0; if(xexp.length()>0)
|
---|
| 640 | {np++; if(yexp.length()>0)
|
---|
| 641 | {np++; if(zexp.length()>0) np++;}}}
|
---|
| 642 | cout<<"pawstring["<<np<<"] name="<<nameobj
|
---|
| 643 | <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
|
---|
| 644 | return np;
|
---|
| 645 | }
|
---|
[1065] | 646 |
|
---|
| 647 | /* methode */
|
---|
| 648 | void PAWExecutor::h_put_vec(vector<string>& tokens)
|
---|
| 649 | // Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
|
---|
| 650 | // L'histogramme doit deja exister. Le nombre de bins remplit
|
---|
| 651 | // depend des tailles respectives des 2 objets.
|
---|
| 652 | // tokens[2] = "cont" : on remplit les valeurs de l'histogramme
|
---|
| 653 | // = "err2" : on remplit les erreurs de l'histogramme
|
---|
| 654 | {
|
---|
| 655 | if(tokens.size()<2)
|
---|
| 656 | {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
|
---|
| 657 | return;}
|
---|
| 658 | string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
|
---|
| 659 | if(toput!="cont" && toput!="err2")
|
---|
| 660 | {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
|
---|
| 661 | return;}
|
---|
| 662 | string hname = tokens[0];
|
---|
| 663 | string vname = tokens[1];
|
---|
| 664 |
|
---|
| 665 | // Get objects
|
---|
| 666 | NamedObjMgr omg;
|
---|
| 667 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 668 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 669 | if( mobjh==NULL || mobjv==NULL )
|
---|
| 670 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
|
---|
| 671 | return;}
|
---|
| 672 |
|
---|
| 673 | // Fill histo from vector
|
---|
| 674 | if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
|
---|
| 675 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 676 | Vector* v = dynamic_cast<Vector*>(mobjv);
|
---|
| 677 | if(toput=="cont") h->PutValue(*v);
|
---|
| 678 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 679 |
|
---|
| 680 | } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
|
---|
| 681 | Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 682 | Matrix* v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 683 | if(toput=="cont") h->PutValue(*v);
|
---|
| 684 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 685 |
|
---|
| 686 | } else {
|
---|
| 687 | cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
|
---|
| 688 | <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
|
---|
| 689 | return;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | }
|
---|
| 693 |
|
---|
| 694 | /* methode */
|
---|
| 695 | void PAWExecutor::h_get_vec(vector<string>& tokens)
|
---|
| 696 | // Pour copier un histo dans un vecteur ou une matrice
|
---|
| 697 | // Si le vecteur (matrice) n'existe pas, il est cree.
|
---|
| 698 | // Le vecteur ou la matrice est re-dimensionne correctement.
|
---|
| 699 | // tokens[2] = "cont" : on copie les valeurs de l'histogramme
|
---|
| 700 | // = "err2" : on copie les erreurs de l'histogramme
|
---|
| 701 | // = "absc" : on copie les erreurs de l'histogramme (1D only)
|
---|
| 702 | // tokens[3[,4]] = show : show available projections for Histo2D
|
---|
| 703 | // px : get X projection
|
---|
| 704 | // py : get Y projection
|
---|
| 705 | // bx n : get X band number n
|
---|
| 706 | // by n : get Y band number n
|
---|
| 707 | // sx n : get X slice number n
|
---|
| 708 | // sy n : get Y slice number n
|
---|
| 709 | {
|
---|
| 710 | if(tokens.size()<2)
|
---|
| 711 | {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
|
---|
| 712 | return;}
|
---|
| 713 | string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
|
---|
| 714 | if(toget!="cont" && toget!="err2" && toget!="absc")
|
---|
| 715 | {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
|
---|
| 716 | return;}
|
---|
| 717 | string proj = "h"; if(tokens.size()>3) proj = tokens[3];
|
---|
| 718 | int nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
|
---|
| 719 | string hname = tokens[0];
|
---|
| 720 | string vname = tokens[1];
|
---|
| 721 |
|
---|
| 722 | // Get objects
|
---|
| 723 | NamedObjMgr omg;
|
---|
| 724 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 725 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 726 | if( mobjh==NULL)
|
---|
| 727 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
|
---|
| 728 | return;}
|
---|
| 729 |
|
---|
| 730 | // Fill histo from vector
|
---|
| 731 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 732 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 733 | if( h != NULL ) { // Histo ou HProf
|
---|
| 734 | HProf* hp = dynamic_cast<HProf*>(mobjh);
|
---|
| 735 | if(hp!=NULL) if(!(hp->IsOk())) hp->UpdateHisto();
|
---|
| 736 | Vector* v = NULL;
|
---|
| 737 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
| 738 | {v = new Vector(1); omg.AddObj(v,vname);}
|
---|
| 739 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 740 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 741 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
|
---|
| 742 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 743 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 744 | if(toget=="cont") h->GetValue(*v);
|
---|
| 745 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 746 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 747 |
|
---|
| 748 | } else if( h2 != NULL) { // Histo2D
|
---|
| 749 |
|
---|
| 750 | if(proj == "h") { // On veut les valeurs de l'histogramme 2D
|
---|
| 751 | Matrix* v = NULL;
|
---|
| 752 | if(mobjv==NULL) // la matrice n'existe pas
|
---|
| 753 | {v = new Matrix(1,1); omg.AddObj(v,vname);}
|
---|
| 754 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 755 | if(typeid(*mobjv) != typeid(Matrix))
|
---|
| 756 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
|
---|
| 757 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 758 | v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 759 | if(toget=="cont") h2->GetValue(*v);
|
---|
| 760 | else if(toget=="err2") h2->GetError2(*v);
|
---|
| 761 | else
|
---|
| 762 | {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
|
---|
| 763 | return;}
|
---|
| 764 |
|
---|
| 765 | } else { // On veut les valeurs d'une projection de l'histo 2D
|
---|
| 766 | h = NULL;
|
---|
| 767 | if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
|
---|
| 768 | else if(proj == "px") h = h2->HProjX();
|
---|
| 769 | else if(proj == "py") h = h2->HProjY();
|
---|
| 770 | else if(proj == "bx") h = h2->HBandX(nproj);
|
---|
| 771 | else if(proj == "by") h = h2->HBandY(nproj);
|
---|
| 772 | else if(proj == "sx") h = h2->HSliX(nproj);
|
---|
| 773 | else if(proj == "sy") h = h2->HSliY(nproj);
|
---|
| 774 | if(h==NULL)
|
---|
| 775 | {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
|
---|
| 776 | <<" number "<<nproj<<endl; return;}
|
---|
| 777 | Vector* v = NULL;
|
---|
| 778 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
| 779 | {v = new Vector(1); omg.AddObj(v,vname);}
|
---|
| 780 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 781 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 782 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
|
---|
| 783 | <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
|
---|
| 784 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 785 | if(toget=="cont") h->GetValue(*v);
|
---|
| 786 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 787 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 788 | }
|
---|
| 789 |
|
---|
| 790 | } else {
|
---|
| 791 | cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
|
---|
| 792 | <<typeid(*mobjh).name()<<endl;
|
---|
| 793 | return;
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | }
|
---|