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

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

suite adaptation travail reza 2D et adapteur + adaptation aux modifs HistoErr cmv 18/01/2007

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