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

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

pawexecutor: copie dans Histo des projections assiciees a un Histo2D cmv 13/8/2006

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