1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <ctype.h>
|
---|
4 | #include <iostream.h>
|
---|
5 | #include <typeinfo>
|
---|
6 |
|
---|
7 | #include "strutil.h"
|
---|
8 | #include "histos.h"
|
---|
9 | #include "histos2.h"
|
---|
10 | #include "hisprof.h"
|
---|
11 | #include "ntuple.h"
|
---|
12 |
|
---|
13 | #include "pawexecut.h"
|
---|
14 | #include "nobjmgr.h"
|
---|
15 | #include "servnobjm.h"
|
---|
16 | #include "pistdimgapp.h"
|
---|
17 |
|
---|
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 |
|
---|
26 | /* Reza + cmv 13/10/99 */
|
---|
27 |
|
---|
28 | uint_4 PAWExecutor::autoc_counter_ = 0;
|
---|
29 |
|
---|
30 | /* methode */
|
---|
31 | PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
|
---|
32 | : mApp(app)
|
---|
33 | {
|
---|
34 | string kw, usage;
|
---|
35 | string hgrp = "pawCmd";
|
---|
36 |
|
---|
37 | kw = "reset";
|
---|
38 | usage = "Reset histograms vectors or matrix";
|
---|
39 | usage += "\n reset nameobj";
|
---|
40 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
41 |
|
---|
42 | kw = "n/plot";
|
---|
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]]";
|
---|
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";
|
---|
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]]";
|
---|
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";
|
---|
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";
|
---|
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 nameh1d nbin";
|
---|
74 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
75 |
|
---|
76 | kw = "h/cadd";
|
---|
77 | usage = "Add a constant to an histogram, a vector or a matrix";
|
---|
78 | usage += "\n h/cadd namehisto val";
|
---|
79 | usage += "\n Related commands: h/cmult h/oper";
|
---|
80 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
81 |
|
---|
82 | kw = "h/cmult";
|
---|
83 | usage = "Multiply an histogram, a vector or a matrix by a constant";
|
---|
84 | usage += "\n h/cmult namehisto val";
|
---|
85 | usage += "\n Related commands: h/cadd h/oper";
|
---|
86 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
87 |
|
---|
88 | kw = "h/oper";
|
---|
89 | usage = "Operation on histograms vectors or matrices";
|
---|
90 | usage += "\n h/oper @ h1 h2 hres";
|
---|
91 | usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
|
---|
92 | usage += "\n For vectors and matrices, operations are elements by elements";
|
---|
93 | usage += "\n Related commands: h/cadd h/cmult";
|
---|
94 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
95 |
|
---|
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);
|
---|
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 |
|
---|
136 | kw = "h/copy";
|
---|
137 | usage = "Copy content of object1 into object2";
|
---|
138 | usage += "\n objects are Vector,Matrix,Histo,Histo2D";
|
---|
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";
|
---|
147 | usage += "\n Related commands: copy";
|
---|
148 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
149 |
|
---|
150 | kw = "h/set/err";
|
---|
151 | usage = "Set Histo,Histo2D errors for range of bins or range of values";
|
---|
152 | usage += "\n h/set/err namehisto setvalue i1[:i2] [j1[:j2]]";
|
---|
153 | usage += "\n set error to setvalue for bin range i1:i2 j1:j2";
|
---|
154 | usage += "\n h/set/err namehisto setvalue v v1:v2";
|
---|
155 | usage += "\n set error to setvalue for content values range v1:v2";
|
---|
156 | usage += "\n h/set/err namehisto setvalue e e1:e2";
|
---|
157 | usage += "\n set error to setvalue for error values range v1:v2";
|
---|
158 | usage += "\n Related commands: h/set/cont";
|
---|
159 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
160 |
|
---|
161 | kw = "h/set/cont";
|
---|
162 | usage = "Set Histo,Histo2D content for range of bins or range of values";
|
---|
163 | usage += "\n h/set/cont namehisto setvalue i1[:i2] [j1[:j2]]";
|
---|
164 | usage += "\n set content to setvalue for bin range i1:i2 j1:j2";
|
---|
165 | usage += "\n h/set/cont namehisto setvalue v v1:v2";
|
---|
166 | usage += "\n set content to setvalue for content values range v1:v2";
|
---|
167 | usage += "\n h/set/cont namehisto setvalue e e1:e2";
|
---|
168 | usage += "\n set content to setvalue for error values range v1:v2";
|
---|
169 | usage += "\n Related commands: h/set/err";
|
---|
170 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
171 |
|
---|
172 | kw = "h/err";
|
---|
173 | usage = "Set Histo,Histo2D error to function of bin content value";
|
---|
174 | usage += "\n h/err namehisto expr_func";
|
---|
175 | usage += "\n Related commands: h/set/err";
|
---|
176 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
177 |
|
---|
178 | }
|
---|
179 |
|
---|
180 | /* methode */
|
---|
181 | PAWExecutor::~PAWExecutor()
|
---|
182 | {
|
---|
183 | }
|
---|
184 |
|
---|
185 | /* methode */
|
---|
186 | int PAWExecutor::Execute(string& kw, vector<string>& tokens)
|
---|
187 | {
|
---|
188 | if(kw == "reset") {
|
---|
189 | reset(tokens); return(0);
|
---|
190 | } else if(kw == "n/plot") {
|
---|
191 | n_plot(tokens); return(0);
|
---|
192 | } else if(kw == "n/proj") {
|
---|
193 | n_proj(tokens); return(0);
|
---|
194 | } else if(kw == "h/integ") {
|
---|
195 | h_integ(tokens); return(0);
|
---|
196 | } else if(kw == "h/deriv") {
|
---|
197 | h_deriv(tokens); return(0);
|
---|
198 | } else if(kw == "h/rebin") {
|
---|
199 | h_rebin(tokens); return(0);
|
---|
200 | } else if(kw == "h/cadd") {
|
---|
201 | h_cadd(tokens); return(0);
|
---|
202 | } else if(kw == "h/cmult") {
|
---|
203 | h_cmult(tokens); return(0);
|
---|
204 | } else if(kw == "h/oper") {
|
---|
205 | h_oper(tokens); return(0);
|
---|
206 | } else if(kw == "h/plot/2d") {
|
---|
207 | h_plot_2d(tokens); return(0);
|
---|
208 | } else if(kw == "h/put_vec") {
|
---|
209 | h_put_vec(tokens); return(0);
|
---|
210 | } else if(kw == "h/get_vec") {
|
---|
211 | h_get_vec(tokens); return(0);
|
---|
212 | } else if(kw == "h/copy") {
|
---|
213 | h_copy(tokens); return(0);
|
---|
214 | } else if(kw == "h/set/err") {
|
---|
215 | string dum = "err";
|
---|
216 | h_set(dum,tokens); return(0);
|
---|
217 | } else if(kw == "h/set/cont") {
|
---|
218 | string dum = "cont";
|
---|
219 | h_set(dum,tokens); return(0);
|
---|
220 | } else if(kw == "h/err") {
|
---|
221 | h_err(tokens); return(0);
|
---|
222 | } else return(1);
|
---|
223 | }
|
---|
224 |
|
---|
225 | /* methode */
|
---|
226 | void PAWExecutor::reset(vector<string>& tokens)
|
---|
227 | // Reset d'histogrammes, vecteurs et matrices
|
---|
228 | {
|
---|
229 | if(tokens.size() < 1)
|
---|
230 | {cout<<"Usage: reset nameobj"<<endl; return;}
|
---|
231 | NamedObjMgr omg;
|
---|
232 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
233 | if(mobj == NULL)
|
---|
234 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
235 | return;}
|
---|
236 | string ctyp = typeid(*mobj).name();
|
---|
237 |
|
---|
238 | #ifdef SANS_EVOLPLANCK
|
---|
239 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
|
---|
240 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
|
---|
241 | #else
|
---|
242 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
|
---|
243 | // ob->DataBlock().Reset(0.);}
|
---|
244 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
|
---|
245 | //ob->DataBlock().Reset(0.);}
|
---|
246 | #endif
|
---|
247 | else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
|
---|
248 | else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
|
---|
249 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
|
---|
250 | else {
|
---|
251 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
|
---|
252 | return;
|
---|
253 | }
|
---|
254 |
|
---|
255 | return;
|
---|
256 | }
|
---|
257 |
|
---|
258 | /* methode */
|
---|
259 | void PAWExecutor::n_plot(vector<string>& tokens)
|
---|
260 | // Equivalent n/plot de paw
|
---|
261 | // Plot 1D
|
---|
262 | // n/plot nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
263 | // Plot 2D (plot2dw)
|
---|
264 | // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
265 | // Plot 3D (plot3d)
|
---|
266 | // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
|
---|
267 | {
|
---|
268 | if(tokens.size() < 1) {
|
---|
269 | cout
|
---|
270 | <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
|
---|
271 | <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
272 | <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
273 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
|
---|
274 | return;
|
---|
275 | }
|
---|
276 | string nameobj,expx,expy,expz;
|
---|
277 | int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
|
---|
278 | string expcut = "1"; string expwt = "1."; string loop = "";
|
---|
279 | string dopt = ""; string nameproj="";
|
---|
280 | if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
281 |
|
---|
282 | NamedObjMgr omg;
|
---|
283 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
284 |
|
---|
285 | if(nvar<=0) {
|
---|
286 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
|
---|
287 | } else if(nvar==1) { // c'est un plot 1D
|
---|
288 | if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
|
---|
289 | if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
|
---|
290 | if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
|
---|
291 | if(tokens.size()>=6) nameproj = tokens[5];
|
---|
292 | if(nameproj.length()<=0 || nameproj=="!") {
|
---|
293 | nameproj = "/autoc/paw_n_plot1D_";
|
---|
294 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
295 | if(mobj!=NULL) {
|
---|
296 | char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
|
---|
297 | nameproj += buff;
|
---|
298 | }
|
---|
299 | }
|
---|
300 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
301 | } else if(nvar==2) { // c'est un plot 2D
|
---|
302 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
303 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
304 | string err = "";
|
---|
305 | srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
|
---|
306 | } else { // c'est un plot 3D
|
---|
307 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
308 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
309 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
|
---|
310 | }
|
---|
311 |
|
---|
312 | return;
|
---|
313 | }
|
---|
314 |
|
---|
315 | /* methode */
|
---|
316 | void PAWExecutor::n_proj(vector<string>& tokens)
|
---|
317 | // Equivalent n/proj de paw
|
---|
318 | // Project NTuple in histogram a la paw
|
---|
319 | // Dans un Histo 1D
|
---|
320 | // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
321 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
|
---|
322 | // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
323 | {
|
---|
324 | if(tokens.size()<2)
|
---|
325 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
|
---|
326 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
|
---|
327 | string nameproj = tokens[0];
|
---|
328 | string nameobj,expx,expy,expz;
|
---|
329 | int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
|
---|
330 | string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
|
---|
331 | if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
|
---|
332 | if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
|
---|
333 | if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
|
---|
334 | if(tokens.size()>=6) dopt = tokens[5];
|
---|
335 |
|
---|
336 | NamedObjMgr omg;
|
---|
337 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
338 |
|
---|
339 | if(nvar==1) {
|
---|
340 | // c'est une projection dans un histo 1D
|
---|
341 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
342 | } else if(nvar==2) {
|
---|
343 | // c'est une projection dans un histo2D
|
---|
344 | // OU un HProf si nameproj est un HProf un deja defini
|
---|
345 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
346 | if(mobj==NULL)
|
---|
347 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
348 | else if(dynamic_cast<HProf*>(mobj))
|
---|
349 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
350 | else
|
---|
351 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
352 | } else {
|
---|
353 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<" nvar="<<nvar<<endl;
|
---|
354 | }
|
---|
355 |
|
---|
356 | return;
|
---|
357 | }
|
---|
358 |
|
---|
359 | /* methode */
|
---|
360 | void PAWExecutor::h_integ(vector<string>& tokens)
|
---|
361 | // Pour remplacer le contenu d'un histo 1D par son integrale
|
---|
362 | {
|
---|
363 | if(tokens.size()<1)
|
---|
364 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
|
---|
365 | NamedObjMgr omg;
|
---|
366 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
367 | if(mobj==NULL)
|
---|
368 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
369 | return;}
|
---|
370 | r_8 norm = 1.;
|
---|
371 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
372 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
373 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
374 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
375 | if(hp || !h1)
|
---|
376 | {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
377 | return;}
|
---|
378 | h1->HInteg(norm);
|
---|
379 | }
|
---|
380 |
|
---|
381 | /* methode */
|
---|
382 | void PAWExecutor::h_deriv(vector<string>& tokens)
|
---|
383 | // Pour remplacer le contenu d'un histo 1D par sa derivee
|
---|
384 | {
|
---|
385 | if(tokens.size()<1)
|
---|
386 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
|
---|
387 | NamedObjMgr omg;
|
---|
388 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
389 | if(mobj==NULL)
|
---|
390 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
391 | return;}
|
---|
392 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
393 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
394 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
395 | if(hp || !h1)
|
---|
396 | {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
397 | return;}
|
---|
398 | h1->HDeriv();
|
---|
399 | }
|
---|
400 |
|
---|
401 | /* methode */
|
---|
402 | void PAWExecutor::h_rebin(vector<string>& tokens)
|
---|
403 | // Pour re-binner un histogramme 1D
|
---|
404 | {
|
---|
405 | if(tokens.size()<2)
|
---|
406 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
|
---|
407 | NamedObjMgr omg;
|
---|
408 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
409 | if(mobj==NULL)
|
---|
410 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
|
---|
411 | return;}
|
---|
412 | int_4 nbin = atoi(tokens[1].c_str());
|
---|
413 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
414 | // Ca marche aussi pour les HProf, HRebin a ete passe virtuel
|
---|
415 | //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
|
---|
416 | if(!h1)
|
---|
417 | {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
418 | return;}
|
---|
419 | h1->HRebin(nbin);
|
---|
420 | }
|
---|
421 |
|
---|
422 | /* methode */
|
---|
423 | void PAWExecutor::h_cadd(vector<string>& tokens)
|
---|
424 | // Additionne une constante a un histogramme
|
---|
425 | {
|
---|
426 | if(tokens.size()<2)
|
---|
427 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
|
---|
428 | NamedObjMgr omg;
|
---|
429 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
430 | if(mobj==NULL)
|
---|
431 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
|
---|
432 | return;}
|
---|
433 | r_8 val = atof(tokens[1].c_str());
|
---|
434 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
435 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
436 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
437 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
438 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
439 | if(h1 && !hp) *h1 += val;
|
---|
440 | else if(h2) *h2 += val;
|
---|
441 | else if(v) *v += val;
|
---|
442 | else if(m) *m += val;
|
---|
443 | else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
444 | }
|
---|
445 |
|
---|
446 | /* methode */
|
---|
447 | void PAWExecutor::h_cmult(vector<string>& tokens)
|
---|
448 | // Multiplie un histogramme par une constante
|
---|
449 | {
|
---|
450 | if(tokens.size()<2)
|
---|
451 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
|
---|
452 | NamedObjMgr omg;
|
---|
453 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
454 | if(mobj==NULL)
|
---|
455 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
|
---|
456 | return;}
|
---|
457 | r_8 val = atof(tokens[1].c_str());
|
---|
458 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
459 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
460 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
461 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
462 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
463 | if(h1 && !hp) *h1 *= val;
|
---|
464 | else if(h2) *h2 *= val;
|
---|
465 | else if(v) *v += val;
|
---|
466 | else if(m) *m += val;
|
---|
467 | else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
468 | }
|
---|
469 |
|
---|
470 | /* methode */
|
---|
471 | void PAWExecutor::h_oper(vector<string>& tokens)
|
---|
472 | // Equivalent h/oper/add sub,mul,div de paw
|
---|
473 | // Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
|
---|
474 | // h/oper @ h1 h2 hres
|
---|
475 | // hres = h1 @ h2 with @ = (+,-,*,/)
|
---|
476 | // Pour les vecteurs et les matrices, il sagit d'operations elements a elements
|
---|
477 | {
|
---|
478 | if(tokens.size()<4)
|
---|
479 | {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
|
---|
480 | return;}
|
---|
481 |
|
---|
482 | // Decode arguments
|
---|
483 | const char * oper = tokens[0].c_str();
|
---|
484 | if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
|
---|
485 | {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
|
---|
486 | return;}
|
---|
487 | string h1name = tokens[1];
|
---|
488 | string h2name = tokens[2];
|
---|
489 | string h3name = tokens[3];
|
---|
490 |
|
---|
491 | // Get objects
|
---|
492 | NamedObjMgr omg;
|
---|
493 | AnyDataObj* mobjh1 = omg.GetObj(h1name);
|
---|
494 | AnyDataObj* mobjh2 = omg.GetObj(h2name);
|
---|
495 | if( mobjh1==NULL || mobjh2==NULL )
|
---|
496 | {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
|
---|
497 | return;}
|
---|
498 | AnyDataObj* mobjh3 = omg.GetObj(h3name);
|
---|
499 |
|
---|
500 | // Operations on HProf, only + is working
|
---|
501 | if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
|
---|
502 | if( oper[0]!='+' )
|
---|
503 | { cout<<"PAWExecutor::h_oper Error: operation "<<oper
|
---|
504 | <<" not implemented for HProf"<<endl; return;}
|
---|
505 | if( dynamic_cast<HProf*>(mobjh2) == NULL )
|
---|
506 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
507 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
508 | return;}
|
---|
509 | HProf* h1 =(HProf*) mobjh1;
|
---|
510 | HProf* h2 =(HProf*) mobjh2;
|
---|
511 | if( h1->NBins() != h2->NBins() )
|
---|
512 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
513 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
514 | HProf* h3 = NULL;
|
---|
515 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
516 | {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
517 | h3 = dynamic_cast<HProf*>(mobjh3);
|
---|
518 | if(h3 == NULL) // ce n'est pas un HProf
|
---|
519 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
520 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
521 | if(h1->NBins() != h3->NBins())
|
---|
522 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
523 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
524 | *h3 = *h1 + *h2;
|
---|
525 | h3->UpdateHisto();
|
---|
526 |
|
---|
527 | // Operations on Histo
|
---|
528 | } else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
|
---|
529 | if( dynamic_cast<Histo*>(mobjh2) == NULL )
|
---|
530 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
531 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
532 | return;}
|
---|
533 | Histo* h1 =(Histo*) mobjh1;
|
---|
534 | Histo* h2 =(Histo*) mobjh2;
|
---|
535 | if( h1->NBins() != h2->NBins() )
|
---|
536 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
537 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
538 | Histo* h3 = NULL;
|
---|
539 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
540 | {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
541 | h3 = dynamic_cast<Histo*>(mobjh3);
|
---|
542 | if(h3 == NULL) // ce n'est pas un Histo
|
---|
543 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
544 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
545 | if(h1->NBins() != h3->NBins())
|
---|
546 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
547 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
548 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
549 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
550 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
551 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
552 |
|
---|
553 | // Operations on Histo2D
|
---|
554 | } else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
|
---|
555 | if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
|
---|
556 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
557 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
558 | return;}
|
---|
559 | Histo2D* h1 =(Histo2D*) mobjh1;
|
---|
560 | Histo2D* h2 =(Histo2D*) mobjh2;
|
---|
561 | if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
|
---|
562 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
563 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
564 | <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
|
---|
565 | Histo2D* h3 = NULL;
|
---|
566 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
567 | {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
568 | h3 = dynamic_cast<Histo2D*>(mobjh3);
|
---|
569 | if(h3 == NULL) // ce n'est pas un Histo2D
|
---|
570 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
571 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
572 | if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
|
---|
573 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
574 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
575 | <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
|
---|
576 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
577 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
578 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
579 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
580 |
|
---|
581 | // Operations on Vector
|
---|
582 | } else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
|
---|
583 | if( dynamic_cast<Vector*>(mobjh2) == NULL )
|
---|
584 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
585 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
586 | return;}
|
---|
587 | Vector* h1 =(Vector*) mobjh1;
|
---|
588 | Vector* h2 =(Vector*) mobjh2;
|
---|
589 | if( h1->NElts() != h2->NElts() )
|
---|
590 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
591 | <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
|
---|
592 | Vector* h3 = NULL;
|
---|
593 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
594 | #ifdef SANS_EVOLPLANCK
|
---|
595 | h3 = new Vector(*h1);
|
---|
596 | #else
|
---|
597 | h3 = new Vector(*h1,false);
|
---|
598 | #endif
|
---|
599 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
600 | }
|
---|
601 | h3 = dynamic_cast<Vector*>(mobjh3);
|
---|
602 | if(h3 == NULL) // ce n'est pas un Vector
|
---|
603 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
604 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
605 | if(h1->NElts() != h3->NElts())
|
---|
606 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
607 | <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
|
---|
608 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
609 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
610 | #ifdef SANS_EVOLPLANCK
|
---|
611 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
612 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
613 | <<" not implemented for Vector in Peida"<<endl;
|
---|
614 | #else
|
---|
615 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
|
---|
616 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
|
---|
617 | #endif
|
---|
618 |
|
---|
619 | // Operations on Matrix
|
---|
620 | } else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
|
---|
621 | if( dynamic_cast<Matrix*>(mobjh2) == NULL )
|
---|
622 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
623 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
624 | return;}
|
---|
625 | Matrix* h1 =(Matrix*) mobjh1;
|
---|
626 | Matrix* h2 =(Matrix*) mobjh2;
|
---|
627 | if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
|
---|
628 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
629 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
630 | <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
|
---|
631 | Matrix* h3 = NULL;
|
---|
632 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
633 | #ifdef SANS_EVOLPLANCK
|
---|
634 | h3 = new Matrix(*h1);
|
---|
635 | #else
|
---|
636 | h3 = new Matrix(*h1,false);
|
---|
637 | #endif
|
---|
638 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
639 | }
|
---|
640 | h3 = dynamic_cast<Matrix*>(mobjh3);
|
---|
641 | if(h3 == NULL) // ce n'est pas un Matrix
|
---|
642 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
643 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
644 | if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
|
---|
645 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
646 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
647 | <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
|
---|
648 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
649 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
650 | #ifdef SANS_EVOLPLANCK
|
---|
651 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
652 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
653 | <<" not implemented for Vector in Peida"<<endl;
|
---|
654 | #else
|
---|
655 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
|
---|
656 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
|
---|
657 | #endif
|
---|
658 |
|
---|
659 | // Doesn't work for other objects
|
---|
660 | } else {
|
---|
661 | cout<<"PAWExecutor::h_oper Error: not implemented for "
|
---|
662 | <<typeid(*mobjh1).name()<<endl;
|
---|
663 | return;
|
---|
664 | }
|
---|
665 |
|
---|
666 | return;
|
---|
667 | }
|
---|
668 |
|
---|
669 | /* methode */
|
---|
670 | void PAWExecutor::h_plot_2d(vector<string>& tokens)
|
---|
671 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
|
---|
672 | {
|
---|
673 | if(tokens.size()<1)
|
---|
674 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
|
---|
675 | string proj = "h"; if(tokens.size()>1) proj = tokens[1];
|
---|
676 | NamedObjMgr omg;
|
---|
677 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
678 | if(mobj==NULL)
|
---|
679 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
|
---|
680 | return;}
|
---|
681 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
682 | if(!h2)
|
---|
683 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
|
---|
684 | return;}
|
---|
685 |
|
---|
686 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
|
---|
687 |
|
---|
688 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
|
---|
689 | if(proj == "show") {
|
---|
690 | h2->ShowProj();
|
---|
691 | h2->ShowBand(2);
|
---|
692 | h2->ShowSli(2);
|
---|
693 | return;
|
---|
694 | } else if(proj == "h") {
|
---|
695 | nametoplot = tokens[0];
|
---|
696 | } else if(proj == "px") {
|
---|
697 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
698 | else {h2->ShowProj(); return;}
|
---|
699 | } else if(proj == "py") {
|
---|
700 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
701 | else {h2->ShowProj(); return;}
|
---|
702 | } else {
|
---|
703 | if(tokens.size()<3)
|
---|
704 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
|
---|
705 | int_4 n = atoi(tokens[2].c_str());
|
---|
706 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
|
---|
707 | if(proj == "bx") {
|
---|
708 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
709 | else {h2->ShowBand(); return;}
|
---|
710 | } else if(proj == "by") {
|
---|
711 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
712 | else {h2->ShowBand(); return;}
|
---|
713 | } else if(proj == "sx") {
|
---|
714 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
715 | else {h2->ShowSli(); return;}
|
---|
716 | } else if(proj == "sy") {
|
---|
717 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
718 | else {h2->ShowSli(); return;}
|
---|
719 | }
|
---|
720 | }
|
---|
721 |
|
---|
722 | omg.DisplayObj(nametoplot,dopt);
|
---|
723 | }
|
---|
724 |
|
---|
725 | /* methode */
|
---|
726 | int PAWExecutor::decodepawstring(string tokens,string& nameobj
|
---|
727 | ,string& xexp,string& yexp,string& zexp)
|
---|
728 | // Decodage general de "nameobj.xexp"
|
---|
729 | // "nameobj.yexp%xexp"
|
---|
730 | // "nameobj.zexp%yexp%xexp"
|
---|
731 | // Return: nombre de variables trouvees, -1 si probleme
|
---|
732 | {
|
---|
733 | nameobj = ""; xexp= ""; yexp= ""; zexp= "";
|
---|
734 |
|
---|
735 | int lt = (int) tokens.length();
|
---|
736 | if(lt<=0) return -1;
|
---|
737 |
|
---|
738 | // decodage de la chaine de type PAW.
|
---|
739 | char *str = new char[lt+2];
|
---|
740 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
|
---|
741 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
|
---|
742 | char *c[3] = {NULL,NULL,NULL};
|
---|
743 | int i, np=0; bool namefound = false;
|
---|
744 | for(i=0;i<lt;i++) {
|
---|
745 | if(!namefound && str[i]=='.') {
|
---|
746 | str[i]='\0';
|
---|
747 | namefound=true;
|
---|
748 | c[np] = str+i+1; np++;
|
---|
749 | }
|
---|
750 | if( namefound && str[i]=='%') {
|
---|
751 | str[i]='\0';
|
---|
752 | if(np<3) {c[np] = str+i+1; np++;}
|
---|
753 | }
|
---|
754 | }
|
---|
755 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
|
---|
756 |
|
---|
757 | // Remplissage du nom et des variables
|
---|
758 | nameobj = str;
|
---|
759 | if(np==1) xexp=c[0];
|
---|
760 | if(np==2) {yexp=c[0]; xexp=c[1];}
|
---|
761 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
|
---|
762 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
|
---|
763 | delete [] str;
|
---|
764 |
|
---|
765 | // Comptage des variables
|
---|
766 | np = -1;
|
---|
767 | if(nameobj.length()>0)
|
---|
768 | {np = 0; if(xexp.length()>0)
|
---|
769 | {np++; if(yexp.length()>0)
|
---|
770 | {np++; if(zexp.length()>0) np++;}}}
|
---|
771 | cout<<"pawstring["<<np<<"] name="<<nameobj
|
---|
772 | <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
|
---|
773 | return np;
|
---|
774 | }
|
---|
775 |
|
---|
776 | /* methode */
|
---|
777 | void PAWExecutor::h_put_vec(vector<string>& tokens)
|
---|
778 | // Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
|
---|
779 | // L'histogramme doit deja exister. Le nombre de bins remplit
|
---|
780 | // depend des tailles respectives des 2 objets.
|
---|
781 | // tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!")
|
---|
782 | // = "err2" : on remplit les erreurs de l'histogramme
|
---|
783 | {
|
---|
784 | if(tokens.size()<2)
|
---|
785 | {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
|
---|
786 | return;}
|
---|
787 | string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
|
---|
788 | if(toput=="!") toput = "cont";
|
---|
789 | if(toput!="cont" && toput!="err2")
|
---|
790 | {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
|
---|
791 | return;}
|
---|
792 | string hname = tokens[0];
|
---|
793 | string vname = tokens[1];
|
---|
794 |
|
---|
795 | // Get objects
|
---|
796 | NamedObjMgr omg;
|
---|
797 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
798 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
799 | if( mobjh==NULL || mobjv==NULL )
|
---|
800 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
|
---|
801 | return;}
|
---|
802 |
|
---|
803 | // Fill Histo from Vector
|
---|
804 | if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
|
---|
805 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
806 | Vector* v = dynamic_cast<Vector*>(mobjv);
|
---|
807 | if(toput=="cont") h->PutValue(*v);
|
---|
808 | else if(toput=="err2") h->PutError2(*v);
|
---|
809 |
|
---|
810 | // Fill Histo2D from Matrix
|
---|
811 | } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
|
---|
812 | Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
|
---|
813 | Matrix* v = dynamic_cast<Matrix*>(mobjv);
|
---|
814 | if(toput=="cont") h->PutValue(*v);
|
---|
815 | else if(toput=="err2") h->PutError2(*v);
|
---|
816 |
|
---|
817 | } else {
|
---|
818 | cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
|
---|
819 | <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
|
---|
820 | return;
|
---|
821 | }
|
---|
822 |
|
---|
823 | }
|
---|
824 |
|
---|
825 | /* methode */
|
---|
826 | void PAWExecutor::h_get_vec(vector<string>& tokens)
|
---|
827 | // Pour copier un histo dans un vecteur ou une matrice
|
---|
828 | // Si le vecteur (matrice) n'existe pas, il est cree.
|
---|
829 | // Le vecteur ou la matrice est re-dimensionne correctement.
|
---|
830 | // tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!")
|
---|
831 | // = "err2" : on copie les erreurs de l'histogramme
|
---|
832 | // = "absc" : on copie les erreurs de l'histogramme (1D only)
|
---|
833 | // tokens[3[,4]] = show : show available projections for Histo2D
|
---|
834 | // px : get X projection
|
---|
835 | // py : get Y projection
|
---|
836 | // bx n : get X band number n
|
---|
837 | // by n : get Y band number n
|
---|
838 | // sx n : get X slice number n
|
---|
839 | // sy n : get Y slice number n
|
---|
840 | {
|
---|
841 | if(tokens.size()<2)
|
---|
842 | {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
|
---|
843 | return;}
|
---|
844 | string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
|
---|
845 | if(toget=="!") toget = "cont";
|
---|
846 | if(toget!="cont" && toget!="err2" && toget!="absc")
|
---|
847 | {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
|
---|
848 | return;}
|
---|
849 | string proj = "h"; if(tokens.size()>3) proj = tokens[3];
|
---|
850 | int_4 nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
|
---|
851 | string hname = tokens[0];
|
---|
852 | string vname = tokens[1];
|
---|
853 |
|
---|
854 | // Get objects
|
---|
855 | NamedObjMgr omg;
|
---|
856 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
857 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
858 | if( mobjh==NULL)
|
---|
859 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
|
---|
860 | return;}
|
---|
861 |
|
---|
862 | // Copy Histo/Histo2D/Projection to Vector/Matrix
|
---|
863 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
864 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
|
---|
865 | if( h != NULL ) { // Histo ou HProf
|
---|
866 | h->UpdateHisto(); // pour le cas ou c'est un HProf
|
---|
867 | Vector* v = NULL;
|
---|
868 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
869 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
870 | if(typeid(*mobjv) != typeid(Vector))
|
---|
871 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
|
---|
872 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
873 | v = dynamic_cast<Vector*>(mobjv);
|
---|
874 | if(toget=="cont") h->GetValue(*v);
|
---|
875 | else if(toget=="err2") h->GetError2(*v);
|
---|
876 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
877 |
|
---|
878 | } else if( h2 != NULL) { // Histo2D
|
---|
879 |
|
---|
880 | if(proj == "h") { // On veut les valeurs de l'histogramme 2D
|
---|
881 | Matrix* v = NULL;
|
---|
882 | if(mobjv==NULL) // la matrice n'existe pas
|
---|
883 | {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
884 | if(typeid(*mobjv) != typeid(Matrix))
|
---|
885 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
|
---|
886 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
887 | v = dynamic_cast<Matrix*>(mobjv);
|
---|
888 | if(toget=="cont") h2->GetValue(*v);
|
---|
889 | else if(toget=="err2") h2->GetError2(*v);
|
---|
890 | else
|
---|
891 | {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
|
---|
892 | return;}
|
---|
893 |
|
---|
894 | } else { // On veut les valeurs d'une projection de l'histo 2D
|
---|
895 | h = NULL;
|
---|
896 | if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
|
---|
897 | else if(proj == "px") h = h2->HProjX();
|
---|
898 | else if(proj == "py") h = h2->HProjY();
|
---|
899 | else if(proj == "bx") h = h2->HBandX(nproj);
|
---|
900 | else if(proj == "by") h = h2->HBandY(nproj);
|
---|
901 | else if(proj == "sx") h = h2->HSliX(nproj);
|
---|
902 | else if(proj == "sy") h = h2->HSliY(nproj);
|
---|
903 | if(h==NULL)
|
---|
904 | {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
|
---|
905 | <<" number "<<nproj<<endl; return;}
|
---|
906 | Vector* v = NULL;
|
---|
907 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
908 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
909 | if(typeid(*mobjv) != typeid(Vector))
|
---|
910 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
|
---|
911 | <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
|
---|
912 | v = dynamic_cast<Vector*>(mobjv);
|
---|
913 | if(toget=="cont") h->GetValue(*v);
|
---|
914 | else if(toget=="err2") h->GetError2(*v);
|
---|
915 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
916 | }
|
---|
917 |
|
---|
918 | } else {
|
---|
919 | cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
|
---|
920 | <<typeid(*mobjh).name()<<endl;
|
---|
921 | return;
|
---|
922 | }
|
---|
923 |
|
---|
924 | }
|
---|
925 |
|
---|
926 | /* methode */
|
---|
927 | void PAWExecutor::h_copy(vector<string>& tokens)
|
---|
928 | // Pour copier un object dans un object
|
---|
929 | // objects are Vector,Matrix,Histo,Histo2D
|
---|
930 | // h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
|
---|
931 | // copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
|
---|
932 | // copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
|
---|
933 | // Attention: elements depuis i1 jusqu'a i2 COMPRIS
|
---|
934 | // Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
|
---|
935 | // ou obj2Dto avec une taille i2-i1+1,j2-j1+1
|
---|
936 | // Le contenu de obj?Dfrom adresse est surecrit
|
---|
937 | // Le contenu de obj?Dfrom non adresse reste le meme
|
---|
938 | {
|
---|
939 | int tks = tokens.size();
|
---|
940 | if(tks<2)
|
---|
941 | {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
|
---|
942 | return;}
|
---|
943 |
|
---|
944 | NamedObjMgr omg;
|
---|
945 | AnyDataObj* mobjv1 = omg.GetObj(tokens[0]);
|
---|
946 | if( mobjv1==NULL)
|
---|
947 | {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
|
---|
948 | return;}
|
---|
949 | AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
|
---|
950 |
|
---|
951 | int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
|
---|
952 |
|
---|
953 | // Cas d'un Vector
|
---|
954 | if(typeid(*mobjv1) == typeid(Vector)) {
|
---|
955 | Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
|
---|
956 | i2=nx1-1;
|
---|
957 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
958 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
959 | if(i2<i1)
|
---|
960 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
|
---|
961 | <<nx1<<endl; return;}
|
---|
962 | Vector* v2 = NULL;
|
---|
963 | if(mobjv2==NULL)
|
---|
964 | {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
965 | if(typeid(*mobjv2) != typeid(Vector))
|
---|
966 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
|
---|
967 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
968 | v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
|
---|
969 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
970 | if(ic1<0) ic1=0;
|
---|
971 | if(ic1>=nx2)
|
---|
972 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
|
---|
973 | <<nx2<<endl; return;}
|
---|
974 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
975 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
|
---|
976 | return;
|
---|
977 | }
|
---|
978 |
|
---|
979 | // Cas d'un Histo
|
---|
980 | if(typeid(*mobjv1) == typeid(Histo)) {
|
---|
981 | Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
|
---|
982 | i2=nx1-1;
|
---|
983 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
984 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
985 | if(i2<i1)
|
---|
986 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
|
---|
987 | <<nx1<<endl; return;}
|
---|
988 | Histo* v2 = NULL;
|
---|
989 | if(mobjv2==NULL)
|
---|
990 | {v2 = new Histo(0.,(r_8)(i2-i1+1),i2-i1+1);
|
---|
991 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
992 | if(typeid(*mobjv2) != typeid(Histo))
|
---|
993 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
|
---|
994 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
995 | v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
|
---|
996 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
997 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
998 | if(ic1<0) ic1=0;
|
---|
999 | if(ic1>=nx2)
|
---|
1000 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
|
---|
1001 | <<nx2<<endl; return;}
|
---|
1002 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
1003 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
1004 | {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
|
---|
1005 | return;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | // Cas d'une Matrix
|
---|
1009 | if(typeid(*mobjv1) == typeid(Matrix)) {
|
---|
1010 | Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
|
---|
1011 | i2=nx1-1; j2=ny1-1;
|
---|
1012 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
1013 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
1014 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
1015 | if(i2<i1 || j2<j1)
|
---|
1016 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
1017 | <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
|
---|
1018 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
1019 | Matrix* v2 = NULL;
|
---|
1020 | if(mobjv2==NULL)
|
---|
1021 | {v2 = new Matrix(i2-i1+1,j2-j1+1);
|
---|
1022 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
1023 | if(typeid(*mobjv2) != typeid(Matrix))
|
---|
1024 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
|
---|
1025 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
1026 | v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
|
---|
1027 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
1028 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
1029 | if(ic1>=nx2 || jc1>=ny2)
|
---|
1030 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
1031 | <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
|
---|
1032 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
1033 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
1034 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
1035 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
|
---|
1036 | return;
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | // Cas d'un Histo2D
|
---|
1040 | if(typeid(*mobjv1) == typeid(Histo2D)) {
|
---|
1041 | Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
|
---|
1042 | i2=nx1-1; j2=ny1-1;
|
---|
1043 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
1044 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
1045 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
1046 | if(i2<i1 || j2<j1)
|
---|
1047 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
1048 | <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
|
---|
1049 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
1050 | Histo2D* v2 = NULL;
|
---|
1051 | if(mobjv2==NULL)
|
---|
1052 | {v2 = new Histo2D(0.,(r_8)(i2-i1+1),i2-i1+1,0.,(r_8)(j2-j1+1),j2-j1+1);
|
---|
1053 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
1054 | if(typeid(*mobjv2) != typeid(Histo2D))
|
---|
1055 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
|
---|
1056 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
1057 | v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
|
---|
1058 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
1059 | if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
1060 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
1061 | if(ic1>=nx2 || jc1>=ny2)
|
---|
1062 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
1063 | <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
|
---|
1064 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
1065 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
1066 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
1067 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
|
---|
1068 | {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
|
---|
1069 | return;
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | // Cas non prevu
|
---|
1073 | cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n"
|
---|
1074 | <<typeid(*mobjv1).name()<<endl;
|
---|
1075 | return;
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | /* methode */
|
---|
1079 | void PAWExecutor::h_set(string dum,vector<string>& tokens)
|
---|
1080 | // Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee
|
---|
1081 | // dum = err : on change les valeurs des erreurs
|
---|
1082 | // cont : on change les valeurs du contenu des bins
|
---|
1083 | // tokens[0] : nom de l'histogramme
|
---|
1084 | // tokens[1] : valeur de remplacement
|
---|
1085 | // tokens[2-3] : i1:i2 j1:j2 intervalle des bins qui doivent etre remplace
|
---|
1086 | // : v v1:v2 remplacement des bins ayant une valeur dans cet intervalle
|
---|
1087 | // : e e1:e2 remplacement des bins ayant une erreur dans cet intervalle
|
---|
1088 | {
|
---|
1089 | int tks = tokens.size();
|
---|
1090 | if(tks<3)
|
---|
1091 | {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2] [j1[:j2]]\n"
|
---|
1092 | <<" v v1:v2\n"
|
---|
1093 | <<" e e1:e2"
|
---|
1094 | <<endl; return;}
|
---|
1095 |
|
---|
1096 | // Decodage arguments
|
---|
1097 | bool replerr = false; if(dum=="err") replerr = true;
|
---|
1098 | r_8 setval = atof(tokens[1].c_str());
|
---|
1099 | int testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2;
|
---|
1100 | int_4 i1=-1, i2=-1, j1=-1, j2=-1;
|
---|
1101 | r_8 v1=0., v2=0.;
|
---|
1102 | if(testcont==0) {
|
---|
1103 | sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
1104 | if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
1105 | } else {
|
---|
1106 | if(tks<=3)
|
---|
1107 | {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl;
|
---|
1108 | return;}
|
---|
1109 | sscanf(tokens[3].c_str(),"%lf:%lf",&v1,&v2);
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;}
|
---|
1113 | if(testcont!=0 && v2<v1)
|
---|
1114 | {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;}
|
---|
1115 |
|
---|
1116 | // identification objet
|
---|
1117 | NamedObjMgr omg;
|
---|
1118 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
1119 | if( mobj==NULL)
|
---|
1120 | {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl;
|
---|
1121 | return;}
|
---|
1122 |
|
---|
1123 | // Traitement
|
---|
1124 | if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
|
---|
1125 | Histo* h = dynamic_cast<Histo*>(mobj);
|
---|
1126 | if( (replerr || testcont==2) && !(h->HasErrors()) )
|
---|
1127 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
|
---|
1128 | if(testcont!=0) {i1=0; i2=h->NBins()-1;}
|
---|
1129 | if(i1<0 || i1>=h->NBins())
|
---|
1130 | {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;}
|
---|
1131 | if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1;
|
---|
1132 | for(int_4 i=i1;i<=i2;i++) {
|
---|
1133 | bool change = true;
|
---|
1134 | if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;}
|
---|
1135 | else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;}
|
---|
1136 | if(!change) continue;
|
---|
1137 | if(replerr) h->Error2(i) = setval; else (*h)(i) = setval;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
|
---|
1141 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
1142 | if( (replerr || testcont==2) && !(h2->HasErrors()) )
|
---|
1143 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
|
---|
1144 | if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;}
|
---|
1145 | if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY())
|
---|
1146 | {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;}
|
---|
1147 | if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1;
|
---|
1148 | if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1;
|
---|
1149 | for(int_4 i=i1;i<=i2;i++) for(int_4 j=j1;j<=j2;j++) {
|
---|
1150 | bool change = true;
|
---|
1151 | if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;}
|
---|
1152 | else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;}
|
---|
1153 | if(!change) continue;
|
---|
1154 | if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | } else {
|
---|
1158 | cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n"
|
---|
1159 | <<typeid(*mobj).name()<<endl;
|
---|
1160 | return;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | /* methode */
|
---|
1166 | void PAWExecutor::h_err(vector<string>& tokens)
|
---|
1167 | // Mise des erreurs d'un histo 1D ou 2D a une valeur
|
---|
1168 | // donnee par une fonction de la valeur du bin
|
---|
1169 | // tokens[0] : nom de l'histogramme
|
---|
1170 | // tokens[1] : expression de la fonction
|
---|
1171 | {
|
---|
1172 | if(tokens.size()<2)
|
---|
1173 | {cout<<"Usage: h/err namehisto expr_func"<<endl; return;}
|
---|
1174 |
|
---|
1175 | // identification objet
|
---|
1176 | NamedObjMgr omg;
|
---|
1177 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
1178 | if( mobj==NULL)
|
---|
1179 | {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl;
|
---|
1180 | return;}
|
---|
1181 |
|
---|
1182 | // Fonction
|
---|
1183 | FILE *fip = NULL;
|
---|
1184 | string expfunc = ""; {for(int i=1;i<(int)tokens.size();i++) expfunc += tokens[i];}
|
---|
1185 | string fname = "func1or2_pia_dl.c";
|
---|
1186 | string func = "func1or2_pia_dl_func";
|
---|
1187 | if((fip = fopen(fname.c_str(), "w")) == NULL)
|
---|
1188 | {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl;
|
---|
1189 | return;}
|
---|
1190 | fprintf(fip,"#include <math.h>\n");
|
---|
1191 | fprintf(fip,"double %s(double x) \n{\n",func.c_str());
|
---|
1192 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
1193 | fclose(fip);
|
---|
1194 | DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func);
|
---|
1195 | if(!f)
|
---|
1196 | {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl;
|
---|
1197 | return;}
|
---|
1198 |
|
---|
1199 | // Traitement
|
---|
1200 | if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
|
---|
1201 | Histo* h = dynamic_cast<Histo*>(mobj);
|
---|
1202 | if(!(h->HasErrors())) h->Errors();
|
---|
1203 | for(int_4 i=0;i<h->NBins();i++) {
|
---|
1204 | r_8 x = (*h)(i);
|
---|
1205 | r_8 e = f(x);
|
---|
1206 | h->SetErr2(i,e*e);
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
|
---|
1210 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
1211 | if(!(h2->HasErrors())) h2->Errors();
|
---|
1212 | for(int_4 i=0;i<h2->NBinX();i++) for(int_4 j=0;j<h2->NBinY();j++) {
|
---|
1213 | r_8 x = (*h2)(i,j);
|
---|
1214 | r_8 e = f(x);
|
---|
1215 | h2->Error2(i,j) = e*e;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | } else {
|
---|
1219 | cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n"
|
---|
1220 | <<typeid(*mobj).name()<<endl;
|
---|
1221 | return;
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | }
|
---|