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

Last change on this file since 2605 was 2605, checked in by cmv, 21 years ago

intro PARTIELLE de HistoErr cmv 3/9/04

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