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

Last change on this file since 2322 was 2322, checked in by cmv, 23 years ago
  • passage xxstream.h en xxstream
  • compile avec gcc_3.2, gcc_2.96 et cxx En 3.2 le seek from ::end semble marcher (voir Eval/COS/pbseekios.cc)

rz+cmv 11/2/2003

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