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

Last change on this file since 2669 was 2669, checked in by cmv, 20 years ago
  • n/read pour creer et remplir un ntuple a partir d'un choix de colonnes d'un fichier ASCII
  • n/merge pour merger des ntuples dans un ntuple unique
  • savelist pour sauver une liste d'objects dans un fichier ppf

cmv 15/04/2005

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