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

Last change on this file since 2809 was 2809, checked in by cmv, 20 years ago

n/merge/col merging ntuples by columns cmv 14/06/2005

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