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

Last change on this file since 1912 was 1912, checked in by cmv, 24 years ago

v/hinteg v/deriv cmv 26/02/2002

File size: 54.1 KB
Line 
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 "nomgadapter.h"
17#include "pistdimgapp.h"
18
19#ifdef SANS_EVOLPLANCK
20#include "cvector.h"
21#include "matrix.h"
22#else
23#include "tmatrix.h"
24#include "tvector.h"
25#endif
26
27/* Reza + cmv 13/10/99 */
28
29uint_4 PAWExecutor::autoc_counter_ = 0;
30
31/* methode */
32PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
33: mApp(app)
34{
35string kw, usage;
36string hgrp = "pawCmd";
37
38kw = "reset";
39usage = "Reset histograms vectors or matrix";
40usage += "\n reset nameobj";
41piac->RegisterCommand(kw,usage,this,hgrp);
42
43kw = "n/plot";
44usage = "Plot NTuple variables a la paw (alias n/pl)";
45usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
46usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]";
47usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]";
48usage += "\n for default use ! , loop=i1[:i2[:di]]";
49usage += "\n Related commands: plot2dw plot3d";
50piac->RegisterCommand(kw,usage,this,hgrp);
51
52kw = "n/proj";
53usage = "Project NTuple in histogram (1D or 2D) a la paw";
54usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
55usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]";
56usage += "\n for default use ! , loop=i1[:i2[:di]]";
57usage += "\n Related commands: projh1d projh2d projprof exptovec";
58piac->RegisterCommand(kw,usage,this,hgrp);
59
60kw = "n/scan";
61usage = "Scan NTuple a la paw";
62usage += "\n n/scan nameobj[.exp1%exp2%exp3] cut loop";
63usage += "\n [-f:filename] [list_of_variables]";
64usage += "\n loop : iev1[:iev2[:diev]] or !";
65usage += "\n cut : cut expression or 1. or !";
66usage += "\n list_of_variables : default is all variables";
67usage += "\n : var1 var2 var3 ... varn";
68usage += "\n : var1 : var2 (from var1 to var2)";
69usage += "\n : : var2 (from first variable to var2)";
70usage += "\n : var1 : (from var1 to last variable)";
71usage += "\n ex: \"v1 : v3 v7 v4 : v6 v2 v9 :\"";
72usage += "\n exp1%exp2%exp3 :";
73usage += "\n if given add exp1,exp2,exp3 to the variable list";
74usage += "\n -f:filename : write into \"filename\", Default is to stdout";
75piac->RegisterCommand(kw,usage,this,hgrp);
76
77kw = "h/integ";
78usage = "Integrate a 1D histogram";
79usage += "\n h/integ nameh1d [norm]";
80usage += "\n norm<=0 means no normalisation (def norm=1)";
81usage += "\n Related commands: h/deriv v/integ v/deriv";
82piac->RegisterCommand(kw,usage,this,hgrp);
83
84kw = "v/integ";
85usage = "Integrate a TVector";
86usage += "\n v/integ namevec [norm]";
87usage += "\n norm<=0 means no normalisation (def norm=0)";
88usage += "\n Related commands: h/integ h/deriv v/deriv";
89piac->RegisterCommand(kw,usage,this,hgrp);
90
91kw = "h/deriv";
92usage = "Derivate a 1D histogram";
93usage += "\n h/deriv nameh1d";
94usage += "\n Related commands: h/integ v/integ v/deriv";
95piac->RegisterCommand(kw,usage,this,hgrp);
96
97kw = "v/deriv";
98usage = "Derivate a TVector";
99usage += "\n v/deriv namevec [deriv_option]";
100usage += "\n deriv_option -1 replace v[i] with v[i]-v[i-1]";
101usage += "\n 0 replace v[i] with (v[i+1]-v[i-1])/2 (default)";
102usage += "\n +1 replace v[i] with v[i+1]-v[i]";
103usage += "\n Related commands: h/integ h/deriv v/integ";
104piac->RegisterCommand(kw,usage,this,hgrp);
105
106kw = "h/rebin";
107usage = "Rebin a 1D histogram or profile";
108usage += "\n h/rebin nameh1d nbin";
109piac->RegisterCommand(kw,usage,this,hgrp);
110
111kw = "h/cadd";
112usage = "Add a constant to an histogram, a vector or a matrix";
113usage += "\n h/cadd namehisto val";
114usage += "\n Related commands: h/cmult h/oper";
115piac->RegisterCommand(kw,usage,this,hgrp);
116
117kw = "h/cmult";
118usage = "Multiply an histogram, a vector or a matrix by a constant";
119usage += "\n h/cmult namehisto val";
120usage += "\n Related commands: h/cadd h/oper";
121piac->RegisterCommand(kw,usage,this,hgrp);
122
123kw = "h/oper";
124usage = "Operation on histograms vectors or matrices";
125usage += "\n h/oper @ h1 h2 hres";
126usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
127usage += "\n For vectors and matrices, operations are elements by elements";
128usage += "\n Related commands: h/cadd h/cmult";
129piac->RegisterCommand(kw,usage,this,hgrp);
130
131kw = "h/plot/2d";
132usage = "Specific plot for 2D histogrammes";
133usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme";
134usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
135usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
136usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
137usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
138usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
139usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
140usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
141usage += "\n n < 0 means Show Info";
142piac->RegisterCommand(kw,usage,this,hgrp);
143
144kw = "h/put_vec";
145usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
146usage += "\n h/put_vec nameh1d namevector [cont,err2]";
147usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
148usage += "\n cont : put into histogramme content";
149usage += "\n err2 : put into histogramme error^2";
150usage += "\n Related commands: h/get_vec";
151piac->RegisterCommand(kw,usage,this,hgrp);
152
153kw = "h/get_vec";
154usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
155usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
156usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
157usage += "\n cont : get histogramme content";
158usage += "\n err2 : get histogramme error^2";
159usage += "\n absc : get histogramme low bin abscissa (1D only)";
160usage += "\n proj :";
161usage += "\n show : show available projections for Histo2D";
162usage += "\n px : get X projection";
163usage += "\n py : get Y projection";
164usage += "\n bx n : get X band number n";
165usage += "\n by n : get Y band number n";
166usage += "\n sx n : get X slice number n";
167usage += "\n sy n : get Y slice number n";
168usage += "\n Related commands: h/put_vec";
169piac->RegisterCommand(kw,usage,this,hgrp);
170
171kw = "h/copy";
172usage = "Copy content of object1 into object2";
173usage += "\n objects are Vector,Matrix,Histo,Histo2D";
174usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
175usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)";
176usage += "\n copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)";
177usage += "\n Warning: elements from i1 to i2 included are copied";
178usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1";
179usage += "\n or obj2Dto with size i2-i1+1,j2-j1+1";
180usage += "\n The adressed content of obj?Dfrom is overwritten";
181usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
182usage += "\n Related commands: copy";
183piac->RegisterCommand(kw,usage,this,hgrp);
184
185kw = "h/set/err";
186usage = "Set Histo,Histo2D errors for range of bins or range of values";
187usage += "\n h/set/err namehisto setvalue i1[:i2] [j1[:j2]]";
188usage += "\n set error to setvalue for bin range i1:i2 j1:j2";
189usage += "\n h/set/err namehisto setvalue v v1:v2";
190usage += "\n set error to setvalue for content values range v1:v2";
191usage += "\n h/set/err namehisto setvalue e e1:e2";
192usage += "\n set error to setvalue for error values range v1:v2";
193usage += "\n Related commands: h/set/cont";
194piac->RegisterCommand(kw,usage,this,hgrp);
195
196kw = "h/set/cont";
197usage = "Set Histo,Histo2D content for range of bins or range of values";
198usage += "\n h/set/cont namehisto setvalue i1[:i2] [j1[:j2]]";
199usage += "\n set content to setvalue for bin range i1:i2 j1:j2";
200usage += "\n h/set/cont namehisto setvalue v v1:v2";
201usage += "\n set content to setvalue for content values range v1:v2";
202usage += "\n h/set/cont namehisto setvalue e e1:e2";
203usage += "\n set content to setvalue for error values range v1:v2";
204usage += "\n Related commands: h/set/err";
205piac->RegisterCommand(kw,usage,this,hgrp);
206
207kw = "h/err";
208usage = "Set Histo,Histo2D error to function of bin content value";
209usage += "\n h/err namehisto expr_func";
210usage += "\n Related commands: h/set/err";
211piac->RegisterCommand(kw,usage,this,hgrp);
212
213}
214
215/* methode */
216PAWExecutor::~PAWExecutor()
217{
218}
219
220/* methode */
221int PAWExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
222{
223if(kw == "reset") {
224 reset(tokens); return(0);
225} else if(kw == "n/plot" || kw == "n/pl") {
226 n_plot(tokens); return(0);
227} else if(kw == "n/proj") {
228 n_proj(tokens); return(0);
229} else if(kw == "n/scan") {
230 n_scan(tokens); return(0);
231} else if(kw == "h/integ") {
232 h_integ(tokens); return(0);
233} else if(kw == "v/integ") {
234 v_integ(tokens); return(0);
235} else if(kw == "h/deriv") {
236 h_deriv(tokens); return(0);
237} else if(kw == "v/deriv") {
238 v_deriv(tokens); return(0);
239} else if(kw == "h/rebin") {
240 h_rebin(tokens); return(0);
241} else if(kw == "h/cadd") {
242 h_cadd(tokens); return(0);
243} else if(kw == "h/cmult") {
244 h_cmult(tokens); return(0);
245} else if(kw == "h/oper") {
246 h_oper(tokens); return(0);
247} else if(kw == "h/plot/2d") {
248 h_plot_2d(tokens); return(0);
249} else if(kw == "h/put_vec") {
250 h_put_vec(tokens); return(0);
251} else if(kw == "h/get_vec") {
252 h_get_vec(tokens); return(0);
253} else if(kw == "h/copy") {
254 h_copy(tokens); return(0);
255} else if(kw == "h/set/err") {
256 string dum = "err";
257 h_set(dum,tokens); return(0);
258} else if(kw == "h/set/cont") {
259 string dum = "cont";
260 h_set(dum,tokens); return(0);
261} else if(kw == "h/err") {
262 h_err(tokens); return(0);
263} else return(1);
264}
265
266/* methode */
267void PAWExecutor::reset(vector<string>& tokens)
268// Reset d'histogrammes, vecteurs et matrices
269{
270if(tokens.size() < 1)
271 {cout<<"Usage: reset nameobj"<<endl; return;}
272NamedObjMgr omg;
273AnyDataObj* mobj = omg.GetObj(tokens[0]);
274if(mobj == NULL)
275 {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
276 return;}
277string ctyp = typeid(*mobj).name();
278
279#ifdef SANS_EVOLPLANCK
280if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
281else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
282#else
283 if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
284// ob->DataBlock().Reset(0.);}
285 else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
286//ob->DataBlock().Reset(0.);}
287#endif
288else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
289else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
290else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
291else {
292 cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
293 return;
294}
295
296return;
297}
298
299/* methode */
300void PAWExecutor::n_plot(vector<string>& tokens)
301// Equivalent n/plot de paw
302// Plot 1D
303// n/plot nameobj.x_exp [cut] [w_exp] [gratt]
304// Plot 2D (plot2dw)
305// n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
306// Plot 3D (plot3d)
307// n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
308{
309if(tokens.size() < 1) {
310 cout
311 <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
312 <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
313 <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
314 <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
315 return;
316}
317string nameobj,expx,expy,expz;
318int_4 nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
319string expcut = "1"; string expwt = "1."; string loop = "";
320string dopt = ""; string nameproj="";
321if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
322
323NamedObjMgr omg;
324Services2NObjMgr* srvo = omg.GetServiceObj();
325
326if(nvar<=0) {
327 cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
328} else if(nvar==1) { // c'est un plot 1D
329 if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
330 if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
331 if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
332 if(tokens.size()>=6) nameproj = tokens[5];
333 if(nameproj.length()<=0 || nameproj=="!") {
334 nameproj = "/autoc/paw_n_plot1D_";
335 AnyDataObj* mobj = omg.GetObj(nameproj);
336 if(mobj!=NULL) {
337 char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
338 nameproj += buff;
339 }
340 }
341 srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
342} else if(nvar==2) { // c'est un plot 2D
343 if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
344 if(tokens.size()>=4) dopt = tokens[3];
345 string err = "";
346 srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
347} else { // c'est un plot 3D
348 if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
349 if(tokens.size()>=4) dopt = tokens[3];
350 srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
351}
352
353return;
354}
355
356/* methode */
357void PAWExecutor::n_proj(vector<string>& tokens)
358// Equivalent n/proj de paw
359// Project NTuple in histogram a la paw
360// Dans un Histo 1D
361// n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
362// Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
363// n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
364{
365if(tokens.size()<2)
366 {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
367 <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
368string nameproj = tokens[0];
369string nameobj,expx,expy,expz;
370int_4 nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
371string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
372if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
373if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
374if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
375if(tokens.size()>=6) dopt = tokens[5];
376
377NamedObjMgr omg;
378Services2NObjMgr* srvo = omg.GetServiceObj();
379
380if(nvar==1) {
381 // c'est une projection dans un histo 1D
382 srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
383} else if(nvar==2) {
384 // c'est une projection dans un histo2D
385 // OU un HProf si nameproj est un HProf un deja defini
386 AnyDataObj* mobj = omg.GetObj(nameproj);
387 if(mobj==NULL)
388 srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
389 else if(dynamic_cast<HProf*>(mobj))
390 srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
391 else
392 srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
393} else {
394 cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<" nvar="<<nvar<<endl;
395}
396
397return;
398}
399
400/* methode */
401void PAWExecutor::n_scan(vector<string>& tokens)
402{
403if(tokens.size()<3)
404 {cerr<<"Usage: n/scan nameobj[.exp1%exp2%exp3] cut loop\n"
405 <<" [-f:filename] [list_of_variables]"<<endl; return;}
406
407// decodage des premiers arguments
408string nameobj,expr[4];
409int_4 nexpr = decodepawstring(tokens[0],nameobj,expr[0],expr[1],expr[2]);
410if(nexpr<4) {for(int_4 i=nexpr;i<4;i++) expr[i]="1.";}
411string expcut = tokens[1]; if(expcut=="!") expcut="1";
412string loop = tokens[2]; if(loop=="!") loop="";
413FILE* fout = NULL;
414uint_4 ldebvar = 3;
415if(tokens.size()>3) {
416 if(tokens[3].find("-f:") == 0) {
417 string filename = tokens[3].substr(3);
418 if(filename.size()>0) {
419 fout = fopen(filename.c_str(),"w");
420 if(fout==NULL)
421 {cerr<<"PAWExecutor::n_scan Error, file "<<filename
422 <<" not opened"<<endl; return;}
423 }
424 ldebvar++;
425 }
426}
427
428// ntuple adaptateur
429NamedObjMgr omg;
430Services2NObjMgr& srvo = *omg.GetServiceObj();
431NObjMgrAdapter* obja = omg.GetObjAdapter(nameobj); // Ne pas deleter
432if(obja == NULL)
433 {cerr<<"PAWExecutor::n_scan Error, ObjAdapter==NULL for "
434 <<nameobj<<endl; return;}
435bool adel = true;
436NTupleInterface* objnt = obja->GetNTupleInterface(adel);
437if(objnt == NULL)
438 {cerr<<"PAWExecutor::n_scan Error, NTupleInterface==NULL for "
439 <<nameobj<<endl; return;}
440
441// function pour le choix
442string vardec = objnt->VarList_C("_zz6qi_");
443PlotExprFunc f = srvo.LinkExprFunc(vardec,expr[0],expr[1],expr[2],expr[3],expcut);
444if(!f)
445 {cerr<<"PAWExecutor::n_scan Error, Creation PlotExprFunc"<<endl;
446 if(adel) delete objnt; if(fout) fclose(fout); return;}
447
448// variables a imprimer
449// "rien" --> de 0 a ncol-1 (toutes les variables)
450// : v1 --> de 0 a v1
451// v1 : --> de v1 a ncol-1
452// v1 : v2 --> de v1 a v2 (si v2 apres v1)
453// v1 et v2 (si v2 avant v1)
454// v1 v2 v3 v4 --> v1 v2 v3 v4 (ordre indifferent)
455// et toute combinaison : "v1 : v3 v7 v4 : v6 v2 v9 :"
456// --> v1 v2 v3 v7 v4 v5 v6 v2 v9 v10...v(ncol-1)
457int_4 ncol = objnt->NbColumns();
458if(ncol<=0)
459 {cerr<<"PAWExecutor::n_scan Error, no columns for NTuple"<<endl;
460 return;}
461vector<int_4> varnum;
462if(ldebvar>=tokens.size()) { // Toutes les variables
463 for(int_4 i=0;i<ncol;i++) varnum.push_back(i);
464} else { // Choix de certaines variables
465 int_4 k,klast,kk; bool frlast=false;
466 if(tokens[ldebvar]==":") {varnum.push_back(0); frlast=true;}
467 else {k = objnt->ColumnIndex(tokens[ldebvar]); varnum.push_back(k);}
468 ldebvar++;
469 if(ldebvar<tokens.size()) for(uint_4 i=ldebvar;i<tokens.size();i++) {
470 if(tokens[i]!=":") { // pas un separateur
471 k = klast = objnt->ColumnIndex(tokens[i]);
472 if(frlast) klast = varnum[varnum.size()-1] + 1;
473 if(klast>k) klast=k;
474 for(kk=klast;kk<=k;kk++) varnum.push_back(kk);
475 frlast=false;
476 } else if(i==tokens.size()-1) { // separateur a la fin
477 k = ncol-1;
478 klast = varnum[varnum.size()-1] + 1;
479 if(klast>k) klast=k;
480 for(kk=klast;kk<=k;kk++) varnum.push_back(kk);
481 } else frlast=true; // separateur pas a la fin
482 }
483}
484
485vector<string> varname;
486if(varnum.size()>0) for(int_4 i=0;i<(int)varnum.size();i++) {
487 if(varnum[i]<0 || varnum[i]>=ncol)
488 {cerr<<"PAWExecutor::n_scan Error, bad variable name at pos "
489 <<i<<endl; if(adel) delete objnt; if(fout) fclose(fout); return;}
490 string dum = objnt->ColumnName(varnum[i]);
491 varname.push_back(dum);
492}
493
494// evenements a utiliser
495int_4 k1=0, k2=objnt->NbLines(), dk=1;
496srvo.DecodeLoopParameters(loop,k1,k2,dk);
497if (k1<0) k1=0;
498if (k2<0) k2=objnt->NbLines();
499if (k2>(int)objnt->NbLines()) k2=objnt->NbLines();
500if (dk<=0) dk=1;
501
502// boucle sur les evenements et print
503try {
504 int_4 i;
505 if(fout) fprintf(fout,"#ev "); else printf("#ev ");
506 for(i=0;i<(int)varname.size();i++)
507 if(fout) fprintf(fout,"%s ",varname[i].c_str());
508 else printf( "%s ",varname[i].c_str());
509 if(nexpr>0) for(i=0;i<nexpr;i++)
510 if(fout) fprintf(fout,"%s ",expr[i].c_str());
511 else printf( "%s ",expr[i].c_str());
512 if(fout) fprintf(fout,"\n"); else printf("\n");
513
514 double xnt[5]={0,0,0,0,0};
515 double* xn;
516 for(int_4 k=k1; k<k2; k += dk) {
517 xn = objnt->GetLineD(k);
518 if(f(xn,xnt,xnt+1,xnt+2,xnt+3) != 0) {
519 if(fout) fprintf(fout,"%d ",k); else printf("%d ",k);
520 for(i=0;i<(int)varnum.size();i++) {
521 if(fout) fprintf(fout,"%g ",*(xn+varnum[i]));
522 else printf( "%g ",*(xn+varnum[i]));
523 }
524 if(nexpr>0) for(i=0;i<nexpr;i++) {
525 if(fout) fprintf(fout,"%g ",*(xnt+i));
526 else printf( "%g ",*(xnt+i));
527 }
528 if(fout) fprintf(fout,"\n"); else printf("\n");
529 }
530 }
531} // fin du try
532#ifdef SANS_EVOLPLANCK
533CATCH(merr) {
534 fflush(stdout); cout<<endl; cerr<<endl;
535 string es = PeidaExc(merr);
536 cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<merr<<es;
537} ENDTRY;
538#else
539catch ( PException exc ) {
540 fflush(stdout); cout<<endl; cerr<<endl;
541 cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<exc.Msg()<<endl;
542}
543#endif
544
545if(adel) delete objnt;
546if(fout) fclose(fout);
547srvo.CloseDLL(); // Fermeture du fichier .so
548return;
549}
550
551/* methode */
552void PAWExecutor::h_integ(vector<string>& tokens)
553// Pour remplacer le contenu d'un histo 1D par son integrale
554{
555if(tokens.size()<1)
556 {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
557NamedObjMgr omg;
558AnyDataObj* mobj = omg.GetObj(tokens[0]);
559if(mobj==NULL)
560 {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
561 return;}
562r_8 norm = 1.;
563if(tokens.size()>=2) norm = atof(tokens[1].c_str());
564// attention: dynamic_cast<Histo*>(HProf)=Vrai!
565Histo* h1 = dynamic_cast<Histo*>(mobj);
566HProf* hp = dynamic_cast<HProf*>(mobj);
567if(hp || !h1)
568 {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
569 return;}
570h1->HInteg(norm);
571}
572
573/* methode */
574void PAWExecutor::v_integ(vector<string>& tokens)
575// Pour remplacer le contenu d'un TVector<r_8> par son integrale
576// normalisee a norm:
577// Si norm <= 0 : pas de normalisation, integration seule
578{
579if(tokens.size()<1)
580 {cout<<"Usage: v/integ namevec [norm]"<<endl; return;}
581NamedObjMgr omg;
582AnyDataObj* mobj = omg.GetObj(tokens[0]);
583if(mobj==NULL)
584 {cout<<"PAWExecutor::v_integ Error: unknow object"<<tokens[0]<<endl;
585 return;}
586r_8 norm=-1.;
587if(tokens.size()>=2) norm = atof(tokens[1].c_str());
588TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
589if(!v)
590 {cout<<"PAWExecutor::v_integ Error: "<<tokens[0]<<" not a TVector"<<endl;
591 return;}
592uint_4 n = v->Size();
593if(n<=0)
594 {cout<<"PAWExecutor::v_integ Error: "<<tokens[0]<<" is an empty vector"<<endl;
595 return;}
596if(n>1) for(uint_4 i=1;i<n;i++) (*v)(i)+=(*v)(i-1);
597if(norm<=0. || (*v)(n-1)==0.) return;
598norm /= (*v)(n-1);
599for(int_4 i=0;i<n;i++) (*v)(i) *= norm;
600}
601
602/* methode */
603void PAWExecutor::h_deriv(vector<string>& tokens)
604// Pour remplacer le contenu d'un histo 1D par sa derivee
605{
606if(tokens.size()<1)
607 {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
608NamedObjMgr omg;
609AnyDataObj* mobj = omg.GetObj(tokens[0]);
610if(mobj==NULL)
611 {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
612 return;}
613// attention: dynamic_cast<Histo*>(HProf)=Vrai!
614Histo* h1 = dynamic_cast<Histo*>(mobj);
615HProf* hp = dynamic_cast<HProf*>(mobj);
616if(hp || !h1)
617 {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
618 return;}
619h1->HDeriv();
620}
621
622/* methode */
623void PAWExecutor::v_deriv(vector<string>& tokens)
624// Pour remplacer le contenu d'un TVector<r_8> par sa derivee
625// deriv_option = -1 replace v[i] with v[i]-v[i-1]
626// = 0 replace v[i] with (v[i+1]-v[i-1])/2 (default)
627// = +1 replace v[i] with v[i+1]-v[i]
628{
629if(tokens.size()<1)
630 {cout<<"Usage: v/deriv namevec [deriv_option(-1,0,+1)]"<<endl; return;}
631NamedObjMgr omg;
632AnyDataObj* mobj = omg.GetObj(tokens[0]);
633if(mobj==NULL)
634 {cout<<"PAWExecutor::v_deriv Error: unknow object"<<tokens[0]<<endl;
635 return;}
636int_4 deriv_option = 0;
637if(tokens.size()>=2) deriv_option = atoi(tokens[1].c_str());
638TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
639if(!v)
640 {cout<<"PAWExecutor::v_deriv Error: "<<tokens[0]<<" not a TVector"<<endl;
641 return;}
642uint_4 n = v->Size();
643if(n<=0)
644 {cout<<"PAWExecutor::v_deriv Error: "<<tokens[0]<<" is an empty vector"<<endl;
645 return;}
646if(n<=1) return;
647TVector<r_8> vsave(*v,false);
648if(deriv_option<0) {
649 for(uint_4 i=1;i<n;i++) (*v)(i) = vsave(i)-vsave(i-1);
650 (*v)(0) = (*v)(1);
651} else if(deriv_option>0) {
652 for(uint_4 i=0;i<n-1;i++) (*v)(i) = vsave(i+1)-vsave(i);
653 (*v)(n-1) = (*v)(n-2);
654} else {
655 for(uint_4 i=1;i<n-1;i++) (*v)(i) = (vsave(i+1)-vsave(i-1))/2.;
656 (*v)(0) = vsave(1)-vsave(0);
657 (*v)(n-1) = vsave(n-1)-vsave(n-2);
658}
659}
660
661/* methode */
662void PAWExecutor::h_rebin(vector<string>& tokens)
663// Pour re-binner un histogramme 1D
664{
665if(tokens.size()<2)
666 {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
667NamedObjMgr omg;
668AnyDataObj* mobj = omg.GetObj(tokens[0]);
669if(mobj==NULL)
670 {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
671 return;}
672int_4 nbin = atoi(tokens[1].c_str());
673Histo* h1 = dynamic_cast<Histo*>(mobj);
674// Ca marche aussi pour les HProf, HRebin a ete passe virtuel
675//HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
676if(!h1)
677 {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
678 return;}
679h1->HRebin(nbin);
680}
681
682/* methode */
683void PAWExecutor::h_cadd(vector<string>& tokens)
684// Additionne une constante a un histogramme
685{
686if(tokens.size()<2)
687 {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
688NamedObjMgr omg;
689AnyDataObj* mobj = omg.GetObj(tokens[0]);
690if(mobj==NULL)
691 {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
692 return;}
693r_8 val = atof(tokens[1].c_str());
694Histo* h1 = dynamic_cast<Histo*>(mobj);
695HProf* hp = dynamic_cast<HProf*>(mobj);
696Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
697Vector* v = dynamic_cast<Vector*>(mobj);
698Matrix* m = dynamic_cast<Matrix*>(mobj);
699if(h1 && !hp) *h1 += val;
700else if(h2) *h2 += val;
701else if(v) *v += val;
702else if(m) *m += val;
703else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
704}
705
706/* methode */
707void PAWExecutor::h_cmult(vector<string>& tokens)
708// Multiplie un histogramme par une constante
709{
710if(tokens.size()<2)
711 {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
712NamedObjMgr omg;
713AnyDataObj* mobj = omg.GetObj(tokens[0]);
714if(mobj==NULL)
715 {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
716 return;}
717r_8 val = atof(tokens[1].c_str());
718Histo* h1 = dynamic_cast<Histo*>(mobj);
719HProf* hp = dynamic_cast<HProf*>(mobj);
720Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
721Vector* v = dynamic_cast<Vector*>(mobj);
722Matrix* m = dynamic_cast<Matrix*>(mobj);
723if(h1 && !hp) *h1 *= val;
724else if(h2) *h2 *= val;
725else if(v) *v += val;
726else if(m) *m += val;
727else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
728}
729
730/* methode */
731void PAWExecutor::h_oper(vector<string>& tokens)
732// Equivalent h/oper/add sub,mul,div de paw
733// Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
734// h/oper @ h1 h2 hres
735// hres = h1 @ h2 with @ = (+,-,*,/)
736// Pour les vecteurs et les matrices, il sagit d'operations elements a elements
737{
738if(tokens.size()<4)
739 {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
740 return;}
741
742// Decode arguments
743const char * oper = tokens[0].c_str();
744if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
745 {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
746 return;}
747string h1name = tokens[1];
748string h2name = tokens[2];
749string h3name = tokens[3];
750
751// Get objects
752NamedObjMgr omg;
753AnyDataObj* mobjh1 = omg.GetObj(h1name);
754AnyDataObj* mobjh2 = omg.GetObj(h2name);
755if( mobjh1==NULL || mobjh2==NULL )
756 {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
757 return;}
758AnyDataObj* mobjh3 = omg.GetObj(h3name);
759
760// Operations on HProf, only + is working
761if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
762 if( oper[0]!='+' )
763 { cout<<"PAWExecutor::h_oper Error: operation "<<oper
764 <<" not implemented for HProf"<<endl; return;}
765 if( dynamic_cast<HProf*>(mobjh2) == NULL )
766 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
767 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
768 return;}
769 HProf* h1 =(HProf*) mobjh1;
770 HProf* h2 =(HProf*) mobjh2;
771 if( h1->NBins() != h2->NBins() )
772 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
773 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
774 HProf* h3 = NULL;
775 if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
776 {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
777 h3 = dynamic_cast<HProf*>(mobjh3);
778 if(h3 == NULL) // ce n'est pas un HProf
779 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
780 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
781 if(h1->NBins() != h3->NBins())
782 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
783 <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
784 *h3 = *h1 + *h2;
785 h3->UpdateHisto();
786
787// Operations on Histo
788} else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
789 if( dynamic_cast<Histo*>(mobjh2) == NULL )
790 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
791 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
792 return;}
793 Histo* h1 =(Histo*) mobjh1;
794 Histo* h2 =(Histo*) mobjh2;
795 if( h1->NBins() != h2->NBins() )
796 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
797 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
798 Histo* h3 = NULL;
799 if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
800 {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
801 h3 = dynamic_cast<Histo*>(mobjh3);
802 if(h3 == NULL) // ce n'est pas un Histo
803 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
804 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
805 if(h1->NBins() != h3->NBins())
806 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
807 <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
808 if( oper[0]=='+') *h3 = *h1 + *h2;
809 else if( oper[0]=='-') *h3 = *h1 - *h2;
810 else if( oper[0]=='*') *h3 = *h1 * *h2;
811 else if( oper[0]=='/') *h3 = *h1 / *h2;
812
813// Operations on Histo2D
814} else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
815 if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
816 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
817 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
818 return;}
819 Histo2D* h1 =(Histo2D*) mobjh1;
820 Histo2D* h2 =(Histo2D*) mobjh2;
821 if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
822 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
823 <<h1->NBinX()<<","<<h1->NBinY()<<" "
824 <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
825 Histo2D* h3 = NULL;
826 if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
827 {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
828 h3 = dynamic_cast<Histo2D*>(mobjh3);
829 if(h3 == NULL) // ce n'est pas un Histo2D
830 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
831 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
832 if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
833 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
834 <<h1->NBinX()<<","<<h1->NBinY()<<" "
835 <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
836 if( oper[0]=='+') *h3 = *h1 + *h2;
837 else if( oper[0]=='-') *h3 = *h1 - *h2;
838 else if( oper[0]=='*') *h3 = *h1 * *h2;
839 else if( oper[0]=='/') *h3 = *h1 / *h2;
840
841// Operations on Vector
842} else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
843 if( dynamic_cast<Vector*>(mobjh2) == NULL )
844 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
845 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
846 return;}
847 Vector* h1 =(Vector*) mobjh1;
848 Vector* h2 =(Vector*) mobjh2;
849 if( h1->NElts() != h2->NElts() )
850 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
851 <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
852 Vector* h3 = NULL;
853 if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
854#ifdef SANS_EVOLPLANCK
855 h3 = new Vector(*h1);
856#else
857 h3 = new Vector(*h1,false);
858#endif
859 *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
860 }
861 h3 = dynamic_cast<Vector*>(mobjh3);
862 if(h3 == NULL) // ce n'est pas un Vector
863 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
864 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
865 if(h1->NElts() != h3->NElts())
866 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
867 <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
868 if( oper[0]=='+') *h3 = *h1 + *h2;
869 else if( oper[0]=='-') *h3 = *h1 - *h2;
870#ifdef SANS_EVOLPLANCK
871 else if(oper[0]=='*' || oper[0]=='/')
872 cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
873 <<" not implemented for Vector in Peida"<<endl;
874#else
875 else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
876 else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
877#endif
878
879// Operations on Matrix
880} else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
881 if( dynamic_cast<Matrix*>(mobjh2) == NULL )
882 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
883 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
884 return;}
885 Matrix* h1 =(Matrix*) mobjh1;
886 Matrix* h2 =(Matrix*) mobjh2;
887 if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
888 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
889 <<h1->NRows()<<","<<h1->NCol()<<" "
890 <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
891 Matrix* h3 = NULL;
892 if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
893#ifdef SANS_EVOLPLANCK
894 h3 = new Matrix(*h1);
895#else
896 h3 = new Matrix(*h1,false);
897#endif
898 *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
899 }
900 h3 = dynamic_cast<Matrix*>(mobjh3);
901 if(h3 == NULL) // ce n'est pas un Matrix
902 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
903 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
904 if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
905 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
906 <<h1->NRows()<<","<<h1->NCol()<<" "
907 <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
908 if( oper[0]=='+') *h3 = *h1 + *h2;
909 else if( oper[0]=='-') *h3 = *h1 - *h2;
910#ifdef SANS_EVOLPLANCK
911 else if(oper[0]=='*' || oper[0]=='/')
912 cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
913 <<" not implemented for Vector in Peida"<<endl;
914#else
915 else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2);}
916 else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);}
917#endif
918
919// Doesn't work for other objects
920} else {
921 cout<<"PAWExecutor::h_oper Error: not implemented for "
922 <<typeid(*mobjh1).name()<<endl;
923 return;
924}
925
926return;
927}
928
929/* methode */
930void PAWExecutor::h_plot_2d(vector<string>& tokens)
931// plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
932{
933if(tokens.size()<1)
934 {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
935string proj = "h"; if(tokens.size()>1) proj = tokens[1];
936NamedObjMgr omg;
937AnyDataObj* mobj = omg.GetObj(tokens[0]);
938if(mobj==NULL)
939 {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
940 return;}
941Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
942if(!h2)
943 {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
944 return;}
945
946Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
947
948string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
949if(proj == "show") {
950 h2->ShowProj();
951 h2->ShowBand(2);
952 h2->ShowSli(2);
953 return;
954} else if(proj == "h") {
955 nametoplot = tokens[0];
956} else if(proj == "px") {
957 if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
958 else {h2->ShowProj(); return;}
959} else if(proj == "py") {
960 if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
961 else {h2->ShowProj(); return;}
962} else {
963 if(tokens.size()<3)
964 {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
965 int_4 n = atoi(tokens[2].c_str());
966 dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
967 if(proj == "bx") {
968 if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
969 else {h2->ShowBand(); return;}
970 } else if(proj == "by") {
971 if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
972 else {h2->ShowBand(); return;}
973 } else if(proj == "sx") {
974 if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
975 else {h2->ShowSli(); return;}
976 } else if(proj == "sy") {
977 if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
978 else {h2->ShowSli(); return;}
979 }
980}
981
982omg.DisplayObj(nametoplot,dopt);
983}
984
985/* methode */
986int_4 PAWExecutor::decodepawstring(string tokens,string& nameobj
987 ,string& xexp,string& yexp,string& zexp)
988// Decodage general de "nameobj.xexp"
989// "nameobj.yexp%xexp"
990// "nameobj.zexp%yexp%xexp"
991// Return: nombre de variables trouvees, -1 si probleme
992{
993nameobj = ""; xexp= ""; yexp= ""; zexp= "";
994
995int_4 lt = (int) tokens.length();
996if(lt<=0) return -1;
997
998// decodage de la chaine de type PAW.
999char *str = new char[lt+2];
1000strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
1001//cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
1002char *c[3] = {NULL,NULL,NULL};
1003int_4 i, np=0; bool namefound = false;
1004for(i=0;i<lt;i++) {
1005 if(!namefound && str[i]=='.') {
1006 str[i]='\0';
1007 namefound=true;
1008 c[np] = str+i+1; np++;
1009 }
1010 if( namefound && str[i]=='%') {
1011 str[i]='\0';
1012 if(np<3) {c[np] = str+i+1; np++;}
1013 }
1014}
1015//cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
1016
1017// Remplissage du nom et des variables
1018nameobj = str;
1019if(np==1) xexp=c[0];
1020if(np==2) {yexp=c[0]; xexp=c[1];}
1021if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
1022//cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
1023delete [] str;
1024
1025// Comptage des variables
1026np = -1;
1027if(nameobj.length()>0)
1028 {np = 0; if(xexp.length()>0)
1029 {np++; if(yexp.length()>0)
1030 {np++; if(zexp.length()>0) np++;}}}
1031//cout<<"pawstring["<<np<<"] name="<<nameobj
1032// <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
1033return np;
1034}
1035
1036/* methode */
1037void PAWExecutor::h_put_vec(vector<string>& tokens)
1038// Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
1039// L'histogramme doit deja exister. Le nombre de bins remplit
1040// depend des tailles respectives des 2 objets.
1041// tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!")
1042// = "err2" : on remplit les erreurs de l'histogramme
1043{
1044if(tokens.size()<2)
1045 {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
1046 return;}
1047string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
1048if(toput=="!") toput = "cont";
1049if(toput!="cont" && toput!="err2")
1050 {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
1051 return;}
1052string hname = tokens[0];
1053string vname = tokens[1];
1054
1055// Get objects
1056NamedObjMgr omg;
1057AnyDataObj* mobjh = omg.GetObj(hname);
1058AnyDataObj* mobjv = omg.GetObj(vname);
1059if( mobjh==NULL || mobjv==NULL )
1060 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
1061 return;}
1062
1063// Fill Histo from Vector
1064if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
1065 Histo* h = dynamic_cast<Histo*>(mobjh);
1066 Vector* v = dynamic_cast<Vector*>(mobjv);
1067 if(toput=="cont") h->PutValue(*v);
1068 else if(toput=="err2") h->PutError2(*v);
1069
1070// Fill Histo2D from Matrix
1071} else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
1072 Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
1073 Matrix* v = dynamic_cast<Matrix*>(mobjv);
1074 if(toput=="cont") h->PutValue(*v);
1075 else if(toput=="err2") h->PutError2(*v);
1076
1077} else {
1078 cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
1079 <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
1080 return;
1081}
1082
1083}
1084
1085/* methode */
1086void PAWExecutor::h_get_vec(vector<string>& tokens)
1087// Pour copier un histo dans un vecteur ou une matrice
1088// Si le vecteur (matrice) n'existe pas, il est cree.
1089// Le vecteur ou la matrice est re-dimensionne correctement.
1090// tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!")
1091// = "err2" : on copie les erreurs de l'histogramme
1092// = "absc" : on copie les erreurs de l'histogramme (1D only)
1093// tokens[3[,4]] = show : show available projections for Histo2D
1094// px : get X projection
1095// py : get Y projection
1096// bx n : get X band number n
1097// by n : get Y band number n
1098// sx n : get X slice number n
1099// sy n : get Y slice number n
1100{
1101if(tokens.size()<2)
1102 {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
1103 return;}
1104string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
1105if(toget=="!") toget = "cont";
1106if(toget!="cont" && toget!="err2" && toget!="absc")
1107 {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
1108 return;}
1109string proj = "h"; if(tokens.size()>3) proj = tokens[3];
1110int_4 nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
1111string hname = tokens[0];
1112string vname = tokens[1];
1113
1114// Get objects
1115NamedObjMgr omg;
1116AnyDataObj* mobjh = omg.GetObj(hname);
1117AnyDataObj* mobjv = omg.GetObj(vname);
1118if( mobjh==NULL)
1119 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
1120 return;}
1121
1122// Copy Histo/Histo2D/Projection to Vector/Matrix
1123Histo* h = dynamic_cast<Histo*>(mobjh);
1124Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
1125if( h != NULL ) { // Histo ou HProf
1126 h->UpdateHisto(); // pour le cas ou c'est un HProf
1127 Vector* v = NULL;
1128 if(mobjv==NULL) // le vecteur n'existe pas
1129 {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
1130 if(typeid(*mobjv) != typeid(Vector))
1131 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
1132 <<typeid(*mobjv).name()<<endl; return;}
1133 v = dynamic_cast<Vector*>(mobjv);
1134 if(toget=="cont") h->GetValue(*v);
1135 else if(toget=="err2") h->GetError2(*v);
1136 else if(toget=="absc") h->GetAbsc(*v);
1137
1138} else if( h2 != NULL) { // Histo2D
1139
1140 if(proj == "h") { // On veut les valeurs de l'histogramme 2D
1141 Matrix* v = NULL;
1142 if(mobjv==NULL) // la matrice n'existe pas
1143 {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
1144 if(typeid(*mobjv) != typeid(Matrix))
1145 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
1146 <<typeid(*mobjv).name()<<endl; return;}
1147 v = dynamic_cast<Matrix*>(mobjv);
1148 if(toget=="cont") h2->GetValue(*v);
1149 else if(toget=="err2") h2->GetError2(*v);
1150 else
1151 {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
1152 return;}
1153
1154 } else { // On veut les valeurs d'une projection de l'histo 2D
1155 h = NULL;
1156 if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
1157 else if(proj == "px") h = h2->HProjX();
1158 else if(proj == "py") h = h2->HProjY();
1159 else if(proj == "bx") h = h2->HBandX(nproj);
1160 else if(proj == "by") h = h2->HBandY(nproj);
1161 else if(proj == "sx") h = h2->HSliX(nproj);
1162 else if(proj == "sy") h = h2->HSliY(nproj);
1163 if(h==NULL)
1164 {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
1165 <<" number "<<nproj<<endl; return;}
1166 Vector* v = NULL;
1167 if(mobjv==NULL) // le vecteur n'existe pas
1168 {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
1169 if(typeid(*mobjv) != typeid(Vector))
1170 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
1171 <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
1172 v = dynamic_cast<Vector*>(mobjv);
1173 if(toget=="cont") h->GetValue(*v);
1174 else if(toget=="err2") h->GetError2(*v);
1175 else if(toget=="absc") h->GetAbsc(*v);
1176 }
1177
1178} else {
1179 cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
1180 <<typeid(*mobjh).name()<<endl;
1181 return;
1182}
1183
1184}
1185
1186/* methode */
1187void PAWExecutor::h_copy(vector<string>& tokens)
1188// Pour copier un object dans un object
1189// objects are Vector,Matrix,Histo,Histo2D
1190// h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
1191// copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
1192// copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
1193// Attention: elements depuis i1 jusqu'a i2 COMPRIS
1194// Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
1195// ou obj2Dto avec une taille i2-i1+1,j2-j1+1
1196// Le contenu de obj?Dfrom adresse est surecrit
1197// Le contenu de obj?Dfrom non adresse reste le meme
1198{
1199int_4 tks = tokens.size();
1200if(tks<2)
1201 {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
1202 return;}
1203
1204NamedObjMgr omg;
1205AnyDataObj* mobjv1 = omg.GetObj(tokens[0]);
1206if( mobjv1==NULL)
1207 {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
1208 return;}
1209AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
1210
1211int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
1212
1213// Cas d'un Vector
1214if(typeid(*mobjv1) == typeid(Vector)) {
1215 Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
1216 i2=nx1-1;
1217 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
1218 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
1219 if(i2<i1)
1220 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
1221 <<nx1<<endl; return;}
1222 Vector* v2 = NULL;
1223 if(mobjv2==NULL)
1224 {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
1225 if(typeid(*mobjv2) != typeid(Vector))
1226 {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
1227 <<typeid(*mobjv2).name()<<endl; return;}
1228 v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
1229 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
1230 if(ic1<0) ic1=0;
1231 if(ic1>=nx2)
1232 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
1233 <<nx2<<endl; return;}
1234 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
1235 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
1236 return;
1237}
1238
1239// Cas d'un Histo
1240if(typeid(*mobjv1) == typeid(Histo)) {
1241 Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
1242 i2=nx1-1;
1243 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
1244 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
1245 if(i2<i1)
1246 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
1247 <<nx1<<endl; return;}
1248 Histo* v2 = NULL;
1249 if(mobjv2==NULL)
1250 {v2 = new Histo(0.,(r_8)(i2-i1+1),i2-i1+1);
1251 omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
1252 if(typeid(*mobjv2) != typeid(Histo))
1253 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
1254 <<typeid(*mobjv2).name()<<endl; return;}
1255 v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
1256 if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
1257 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
1258 if(ic1<0) ic1=0;
1259 if(ic1>=nx2)
1260 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
1261 <<nx2<<endl; return;}
1262 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
1263 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
1264 {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
1265 return;
1266}
1267
1268// Cas d'une Matrix
1269if(typeid(*mobjv1) == typeid(Matrix)) {
1270 Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
1271 i2=nx1-1; j2=ny1-1;
1272 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
1273 if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
1274 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
1275 if(i2<i1 || j2<j1)
1276 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
1277 <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
1278 <<nx1<<" , "<<ny1<<endl; return;}
1279 Matrix* v2 = NULL;
1280 if(mobjv2==NULL)
1281 {v2 = new Matrix(i2-i1+1,j2-j1+1);
1282 omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
1283 if(typeid(*mobjv2) != typeid(Matrix))
1284 {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
1285 <<typeid(*mobjv2).name()<<endl; return;}
1286 v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
1287 if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
1288 if(ic1<0) ic1=0; if(jc1<0) jc1=0;
1289 if(ic1>=nx2 || jc1>=ny2)
1290 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
1291 <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
1292 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
1293 <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
1294 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
1295 for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
1296 return;
1297}
1298
1299// Cas d'un Histo2D
1300if(typeid(*mobjv1) == typeid(Histo2D)) {
1301 Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
1302 i2=nx1-1; j2=ny1-1;
1303 if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
1304 if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
1305 if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
1306 if(i2<i1 || j2<j1)
1307 {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
1308 <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
1309 <<nx1<<" , "<<ny1<<endl; return;}
1310 Histo2D* v2 = NULL;
1311 if(mobjv2==NULL)
1312 {v2 = new Histo2D(0.,(r_8)(i2-i1+1),i2-i1+1,0.,(r_8)(j2-j1+1),j2-j1+1);
1313 omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
1314 if(typeid(*mobjv2) != typeid(Histo2D))
1315 {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
1316 <<typeid(*mobjv2).name()<<endl; return;}
1317 v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
1318 if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
1319 if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
1320 if(ic1<0) ic1=0; if(jc1<0) jc1=0;
1321 if(ic1>=nx2 || jc1>=ny2)
1322 {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
1323 <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
1324 cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
1325 <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
1326 for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
1327 for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
1328 {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
1329 return;
1330}
1331
1332// Cas non prevu
1333cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n"
1334 <<typeid(*mobjv1).name()<<endl;
1335return;
1336}
1337
1338/* methode */
1339void PAWExecutor::h_set(string dum,vector<string>& tokens)
1340// Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee
1341// dum = err : on change les valeurs des erreurs
1342// cont : on change les valeurs du contenu des bins
1343// tokens[0] : nom de l'histogramme
1344// tokens[1] : valeur de remplacement
1345// tokens[2-3] : i1:i2 j1:j2 intervalle des bins qui doivent etre remplace
1346// : v v1:v2 remplacement des bins ayant une valeur dans cet intervalle
1347// : e e1:e2 remplacement des bins ayant une erreur dans cet intervalle
1348{
1349int_4 tks = tokens.size();
1350if(tks<3)
1351 {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2] [j1[:j2]]\n"
1352 <<" v v1:v2\n"
1353 <<" e e1:e2"
1354 <<endl; return;}
1355
1356// Decodage arguments
1357bool replerr = false; if(dum=="err") replerr = true;
1358r_8 setval = atof(tokens[1].c_str());
1359int_4 testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2;
1360int_4 i1=-1, i2=-1, j1=-1, j2=-1;
1361r_8 v1=0., v2=0.;
1362if(testcont==0) {
1363 sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
1364 if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
1365} else {
1366 if(tks<=3)
1367 {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl;
1368 return;}
1369 sscanf(tokens[3].c_str(),"%lf:%lf",&v1,&v2);
1370}
1371
1372if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;}
1373if(testcont!=0 && v2<v1)
1374 {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;}
1375
1376// identification objet
1377NamedObjMgr omg;
1378AnyDataObj* mobj = omg.GetObj(tokens[0]);
1379if( mobj==NULL)
1380 {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl;
1381 return;}
1382
1383// Traitement
1384if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
1385 Histo* h = dynamic_cast<Histo*>(mobj);
1386 if( (replerr || testcont==2) && !(h->HasErrors()) )
1387 {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
1388 if(testcont!=0) {i1=0; i2=h->NBins()-1;}
1389 if(i1<0 || i1>=h->NBins())
1390 {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;}
1391 if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1;
1392 for(int_4 i=i1;i<=i2;i++) {
1393 bool change = true;
1394 if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;}
1395 else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;}
1396 if(!change) continue;
1397 if(replerr) h->Error2(i) = setval; else (*h)(i) = setval;
1398 }
1399
1400} else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
1401 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
1402 if( (replerr || testcont==2) && !(h2->HasErrors()) )
1403 {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
1404 if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;}
1405 if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY())
1406 {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;}
1407 if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1;
1408 if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1;
1409 for(int_4 i=i1;i<=i2;i++) for(int_4 j=j1;j<=j2;j++) {
1410 bool change = true;
1411 if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;}
1412 else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;}
1413 if(!change) continue;
1414 if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval;
1415 }
1416
1417} else {
1418 cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n"
1419 <<typeid(*mobj).name()<<endl;
1420 return;
1421}
1422
1423}
1424
1425/* methode */
1426void PAWExecutor::h_err(vector<string>& tokens)
1427// Mise des erreurs d'un histo 1D ou 2D a une valeur
1428// donnee par une fonction de la valeur du bin
1429// tokens[0] : nom de l'histogramme
1430// tokens[1] : expression de la fonction
1431{
1432if(tokens.size()<2)
1433 {cout<<"Usage: h/err namehisto expr_func"<<endl; return;}
1434
1435// identification objet
1436NamedObjMgr omg;
1437AnyDataObj* mobj = omg.GetObj(tokens[0]);
1438if( mobj==NULL)
1439 {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl;
1440 return;}
1441
1442// Fonction
1443FILE *fip = NULL;
1444string expfunc = ""; {for(int_4 i=1;i<(int)tokens.size();i++) expfunc += tokens[i];}
1445string fname = "func1or2_pia_dl.c";
1446string func = "func1or2_pia_dl_func";
1447if((fip = fopen(fname.c_str(), "w")) == NULL)
1448 {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl;
1449 return;}
1450fprintf(fip,"#include <math.h>\n");
1451fprintf(fip,"double %s(double x) \n{\n",func.c_str());
1452fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
1453fclose(fip);
1454DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func);
1455if(!f)
1456 {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl;
1457 return;}
1458
1459// Traitement
1460if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
1461 Histo* h = dynamic_cast<Histo*>(mobj);
1462 if(!(h->HasErrors())) h->Errors();
1463 for(int_4 i=0;i<h->NBins();i++) {
1464 r_8 x = (*h)(i);
1465 r_8 e = f(x);
1466 h->SetErr2(i,e*e);
1467 }
1468
1469} else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
1470 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
1471 if(!(h2->HasErrors())) h2->Errors();
1472 for(int_4 i=0;i<h2->NBinX();i++) for(int_4 j=0;j<h2->NBinY();j++) {
1473 r_8 x = (*h2)(i,j);
1474 r_8 e = f(x);
1475 h2->Error2(i,j) = e*e;
1476 }
1477
1478} else {
1479 cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n"
1480 <<typeid(*mobj).name()<<endl;
1481 return;
1482}
1483
1484}
Note: See TracBrowser for help on using the repository browser.