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

Last change on this file since 3135 was 3135, checked in by cmv, 19 years ago

suite du display des HistoErr avec Wrapper cmv 12/01/07

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