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

Last change on this file since 2708 was 2708, checked in by cmv, 20 years ago
  • intro de v/sort
  • acceleration lecture fichiers ASCII n/read

cmv 28/04/05

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