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

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

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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