source: Sophya/trunk/SophyaPI/PIext/pawexecut.cc@ 2689

Last change on this file since 2689 was 2689, checked in by ansari, 20 years ago

Suite adaptation a modif interface_ntuple (remplacement int par sa_size_t (oublie ds implementation specifique pour classes template)) et suppression warning de compil pour format printf/sprintf ds pawexecut.cc , pintuple.cc - Reza 26/4/2005

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