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

Last change on this file since 1067 was 1067, checked in by ercodmgr, 25 years ago

piafitting.cc: GeneralData::GetMinMax -> GeneralData::GetMnMx
autres fichiers: intro de gdfrvec (FillGFDfrVec)

cmv 12/07/00

File size: 27.5 KB
RevLine 
[463]1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4#include <iostream.h>
5#include <typeinfo>
6
[466]7#include "strutil.h"
[463]8#include "histos.h"
9#include "histos2.h"
[466]10#include "hisprof.h"
[463]11#include "ntuple.h"
12
13#include "pawexecut.h"
14#include "nobjmgr.h"
[466]15#include "servnobjm.h"
[463]16#include "pistdimgapp.h"
17
[544]18#ifdef SANS_EVOLPLANCK
19#include "cvector.h"
20#include "matrix.h"
21#else
22#include "tmatrix.h"
23#include "tvector.h"
24#endif
25
[466]26/* Reza + cmv 13/10/99 */
27
[1035]28uint_4 PAWExecutor::autoc_counter_ = 0;
29
[466]30/* methode */
[463]31PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
[466]32: mApp(app)
[463]33{
34string kw, usage;
35string hgrp = "pawCmd";
[466]36
37kw = "reset";
38usage = "Reset histograms vectors or matrix";
39usage += "\n reset nameobj";
[463]40piac->RegisterCommand(kw,usage,this,hgrp);
[466]41
42kw = "n/plot";
[469]43usage = "Plot NTuple variables a la paw";
44usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
45usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]";
46usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]";
47usage += "\n for default use ! , loop=i1[:i2[:di]]";
[466]48usage += "\n Related commands: plot2dw plot3d";
49piac->RegisterCommand(kw,usage,this,hgrp);
50
51kw = "n/proj";
52usage = "Project NTuple in histogram (1D or 2D) a la paw";
[469]53usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
54usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]";
55usage += "\n for default use ! , loop=i1[:i2[:di]]";
[466]56usage += "\n Related commands: projh1d projh2d projprof";
57piac->RegisterCommand(kw,usage,this,hgrp);
58
59kw = "h/integ";
[1057]60usage = "Integrate a 1D histogram";
[466]61usage += "\n h/integ nameh1d [norm]";
[1057]62usage += "\n Related commands: h/deriv";
[466]63piac->RegisterCommand(kw,usage,this,hgrp);
64
65kw = "h/deriv";
[1057]66usage = "Derivate a 1D histogram";
[466]67usage += "\n h/deriv nameh1d";
[1057]68usage += "\n Related commands: h/integ";
[466]69piac->RegisterCommand(kw,usage,this,hgrp);
70
71kw = "h/rebin";
72usage = "Rebin a 1D histogram or profile";
[1057]73usage += "\n h/rebin nameh1d nbin";
[466]74piac->RegisterCommand(kw,usage,this,hgrp);
75
76kw = "h/cadd";
[1054]77usage = "Add a constant to an histogram";
[1057]78usage += "\n h/cadd namehisto val";
[1054]79usage += "\n Related commands: h/cmult h/oper";
[466]80piac->RegisterCommand(kw,usage,this,hgrp);
81
82kw = "h/cmult";
[1054]83usage = "Multiply an histogram by a constant";
[1057]84usage += "\n h/cmult namehisto val";
[1054]85usage += "\n Related commands: h/cadd h/oper";
[466]86piac->RegisterCommand(kw,usage,this,hgrp);
87
[1054]88kw = "h/oper";
89usage = "Operation on histograms";
90usage += "\n h/oper @ h1 h2 hres";
91usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
92usage += "\n Related commands: h/cadd h/cmult";
93piac->RegisterCommand(kw,usage,this,hgrp);
94
[466]95kw = "h/plot/2d";
96usage = "Specific plot for 2D histogrammes";
97usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme";
98usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
99usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
100usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
101usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
102usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
103usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
104usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
105usage += "\n n < 0 means Show Info";
106piac->RegisterCommand(kw,usage,this,hgrp);
[1065]107
108kw = "h/put_vec";
109usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
110usage += "\n h/put_vec nameh1d namevector [cont,err2]";
111usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
112usage += "\n cont : put into histogramme content";
113usage += "\n err2 : put into histogramme error^2";
114usage += "\n Related commands: h/get_vec";
115piac->RegisterCommand(kw,usage,this,hgrp);
116
117kw = "h/get_vec";
118usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
119usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
120usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
121usage += "\n cont : get histogramme content";
122usage += "\n err2 : get histogramme error^2";
123usage += "\n absc : get histogramme low bin abscissa (1D only)";
124usage += "\n proj :";
125usage += "\n show : show available projections for Histo2D";
126usage += "\n px : get X projection";
127usage += "\n py : get Y projection";
128usage += "\n bx n : get X band number n";
129usage += "\n by n : get Y band number n";
130usage += "\n sx n : get X slice number n";
131usage += "\n sy n : get Y slice number n";
132usage += "\n Related commands: h/put_vec";
133piac->RegisterCommand(kw,usage,this,hgrp);
134
[463]135}
136
[466]137/* methode */
[463]138PAWExecutor::~PAWExecutor()
139{
140}
141
[466]142/* methode */
[463]143int PAWExecutor::Execute(string& kw, vector<string>& tokens)
144{
[466]145if(kw == "reset") {
146 reset(tokens); return(0);
147} else if(kw == "n/plot") {
148 n_plot(tokens); return(0);
149} else if(kw == "n/proj") {
150 n_proj(tokens); return(0);
151} else if(kw == "h/integ") {
152 h_integ(tokens); return(0);
153} else if(kw == "h/deriv") {
154 h_deriv(tokens); return(0);
155} else if(kw == "h/rebin") {
156 h_rebin(tokens); return(0);
157} else if(kw == "h/cadd") {
158 h_cadd(tokens); return(0);
159} else if(kw == "h/cmult") {
160 h_cmult(tokens); return(0);
[1054]161} else if(kw == "h/oper") {
162 h_oper(tokens); return(0);
[466]163} else if(kw == "h/plot/2d") {
164 h_plot_2d(tokens); return(0);
[1065]165} else if(kw == "h/put_vec") {
166 h_put_vec(tokens); return(0);
167} else if(kw == "h/get_vec") {
168 h_get_vec(tokens); return(0);
[466]169} else return(1);
170}
171
172/* methode */
173void PAWExecutor::reset(vector<string>& tokens)
174// Reset d'histogrammes, vecteurs et matrices
175{
176if(tokens.size() < 1)
[469]177 {cout<<"Usage: reset nameobj"<<endl; return;}
[466]178NamedObjMgr omg;
179AnyDataObj* mobj = omg.GetObj(tokens[0]);
180if(mobj == NULL)
181 {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
182 return;}
183string ctyp = typeid(*mobj).name();
184
[545]185#ifdef SANS_EVOLPLANCK
[466]186if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
187else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
[545]188#else
[815]189 if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
190// ob->DataBlock().Reset(0.);}
191 else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
192//ob->DataBlock().Reset(0.);}
[545]193#endif
[466]194else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
195else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
196else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
197else {
198 cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
199 return;
200}
201
202return;
203}
204
205/* methode */
206void PAWExecutor::n_plot(vector<string>& tokens)
207// Equivalent n/plot de paw
208// Plot 1D
209// n/plot nameobj.x_exp [cut] [w_exp] [gratt]
210// Plot 2D (plot2dw)
211// n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
212// Plot 3D (plot3d)
213// n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
214{
215if(tokens.size() < 1) {
216 cout
[1035]217 <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
[469]218 <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
219 <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
220 <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
[466]221 return;
222}
223string nameobj,expx,expy,expz;
224int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
[1035]225string expcut = "1"; string expwt = "1."; string loop = "";
226string dopt = ""; string nameproj="";
[469]227if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
[466]228
229NamedObjMgr omg;
230Services2NObjMgr* srvo = omg.GetServiceObj();
231
232if(nvar<=0) {
233 cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
234} else if(nvar==1) { // c'est un plot 1D
[1035]235 if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
236 if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
237 if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
238 if(tokens.size()>=6) nameproj = tokens[5];
239 if(nameproj.length()<=0 || nameproj=="!") {
240 nameproj = "/autoc/paw_n_plot1D_";
241 AnyDataObj* mobj = omg.GetObj(nameproj);
242 if(mobj!=NULL) {
243 char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
244 nameproj += buff;
245 }
246 }
[466]247 srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
248} else if(nvar==2) { // c'est un plot 2D
[469]249 if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
250 if(tokens.size()>=4) dopt = tokens[3];
251 string err = "";
252 srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
[466]253} else { // c'est un plot 3D
[469]254 if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
255 if(tokens.size()>=4) dopt = tokens[3];
[466]256 srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
257}
258
259return;
260}
261
262/* methode */
263void PAWExecutor::n_proj(vector<string>& tokens)
264// Equivalent n/proj de paw
265// Project NTuple in histogram a la paw
266// Dans un Histo 1D
267// n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
268// Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
269// n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
270{
271if(tokens.size()<2)
[469]272 {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
273 <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
[466]274string nameproj = tokens[0];
275string nameobj,expx,expy,expz;
276int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
[469]277string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
278if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
279if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
280if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
281if(tokens.size()>=6) dopt = tokens[5];
[466]282
283NamedObjMgr omg;
284Services2NObjMgr* srvo = omg.GetServiceObj();
285
286if(nvar<=0) {
287 cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<endl;
288} else if(nvar==1) {
289 // c'est une projection dans un histo 1D
290 srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
291} else {
292 // c'est une projection dans un histo2D
293 // OU un HProf si nameproj est HProf un deja defini
294 AnyDataObj* mobj = omg.GetObj(nameproj);
295 if(mobj==NULL)
296 srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
297 else if(dynamic_cast<HProf*>(mobj))
298 srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
299 else
300 srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
301}
302
303return;
304}
305
306/* methode */
307void PAWExecutor::h_integ(vector<string>& tokens)
308// Pour remplacer le contenu d'un histo 1D par son integrale
309{
310if(tokens.size()<1)
311 {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
312NamedObjMgr omg;
313AnyDataObj* mobj = omg.GetObj(tokens[0]);
314if(mobj==NULL)
315 {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
316 return;}
317double norm = 1.;
318if(tokens.size()>=2) norm = atof(tokens[1].c_str());
[1057]319// attention: dynamic_cast<Histo*>(HProf)=Vrai!
[466]320Histo* h1 = dynamic_cast<Histo*>(mobj);
[1057]321HProf* hp = dynamic_cast<HProf*>(mobj);
322if(hp || !h1)
323 {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
324 return;}
325h1->HInteg(norm);
[466]326}
327
328/* methode */
329void PAWExecutor::h_deriv(vector<string>& tokens)
330// Pour remplacer le contenu d'un histo 1D par sa derivee
331{
332if(tokens.size()<1)
333 {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
334NamedObjMgr omg;
335AnyDataObj* mobj = omg.GetObj(tokens[0]);
336if(mobj==NULL)
337 {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
338 return;}
[1057]339// attention: dynamic_cast<Histo*>(HProf)=Vrai!
[466]340Histo* h1 = dynamic_cast<Histo*>(mobj);
[1057]341HProf* hp = dynamic_cast<HProf*>(mobj);
342if(hp || !h1)
343 {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
344 return;}
345h1->HDeriv();
[466]346}
347
348/* methode */
349void PAWExecutor::h_rebin(vector<string>& tokens)
350// Pour re-binner un histogramme 1D
351{
352if(tokens.size()<2)
353 {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
354NamedObjMgr omg;
355AnyDataObj* mobj = omg.GetObj(tokens[0]);
356if(mobj==NULL)
357 {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
358 return;}
359int nbin = atoi(tokens[1].c_str());
360Histo* h1 = dynamic_cast<Histo*>(mobj);
[1059]361// Ca marche aussi pour les HProf, HRebin a ete passe virtuel
362//HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
363if(!h1)
[1057]364 {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo"<<endl;
365 return;}
366h1->HRebin(nbin);
[466]367}
368
369/* methode */
370void PAWExecutor::h_cadd(vector<string>& tokens)
371// Additionne une constante a un histogramme
372{
373if(tokens.size()<2)
374 {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
375NamedObjMgr omg;
376AnyDataObj* mobj = omg.GetObj(tokens[0]);
377if(mobj==NULL)
378 {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
379 return;}
380double val = atof(tokens[1].c_str());
381Histo* h1 = dynamic_cast<Histo*>(mobj);
[1057]382HProf* hp = dynamic_cast<HProf*>(mobj);
[466]383Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
[1057]384if(h1 && !hp) *h1 += val;
385else if(h2) *h2 += val;
386else cout<<"PAWExecutor::h_cadd Error: "<<tokens[0]<<" not an Histo/Histo2D"<<endl;
[466]387}
388
389/* methode */
390void PAWExecutor::h_cmult(vector<string>& tokens)
391// Multiplie un histogramme par une constante
392{
393if(tokens.size()<2)
394 {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
395NamedObjMgr omg;
396AnyDataObj* mobj = omg.GetObj(tokens[0]);
397if(mobj==NULL)
398 {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
399 return;}
400double val = atof(tokens[1].c_str());
401Histo* h1 = dynamic_cast<Histo*>(mobj);
[1057]402HProf* hp = dynamic_cast<HProf*>(mobj);
[466]403Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
[1057]404if(h1 && !hp) *h1 *= val;
405else if(h2) *h2 *= val;
[466]406else cout<<"PAWExecutor::h_cmult Error: "<<tokens[0]
[1057]407 <<" not an Histo/Histo2D"<<endl;
[466]408}
409
410/* methode */
[1054]411void PAWExecutor::h_oper(vector<string>& tokens)
412// Equivalent h/oper/add sub,mul,div de paw
413// Operation entre 2 histogrammes
414// h/oper @ h1 h2 hres
415// hres = h1 @ h2 with @ = (+,-,*,/)
416{
417if(tokens.size()<4)
418 {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/)"<<endl;
419 return;}
420
421// Decode arguments
422const char * oper = tokens[0].c_str();
423if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
424 {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
425 return;}
426string h1name = tokens[1];
427string h2name = tokens[2];
428string h3name = tokens[3];
429
430// Get objects
431NamedObjMgr omg;
432AnyDataObj* mobjh1 = omg.GetObj(h1name);
433AnyDataObj* mobjh2 = omg.GetObj(h2name);
434if( mobjh1==NULL || mobjh2==NULL )
435 {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
436 return;}
437AnyDataObj* mobjh3 = omg.GetObj(h3name);
438
439// Operations on HProf, only + is working
440if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
441 if( oper[0]!='+' )
442 { cout<<"PAWExecutor::h_oper Error: operation "<<oper
443 <<" not implemented for HProf"<<endl; return;}
444 if( dynamic_cast<HProf*>(mobjh2) == NULL )
[1057]445 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
[1054]446 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
447 return;}
448 HProf* h1 =(HProf*) mobjh1;
449 HProf* h2 =(HProf*) mobjh2;
450 if( h1->NBins() != h2->NBins() )
451 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
452 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
453 HProf* h3 = NULL;
454 if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
455 h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name);
456 } else { // l'objet existe
457 h3 = dynamic_cast<HProf*>(mobjh3);
458 if(h3 == NULL) // ce n'est pas un HProf
[1057]459 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
[1054]460 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
461 return;}
462 if(h1->NBins() != h3->NBins())
463 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
464 <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
465 *h3 = *h1 + *h2;
466 h3->UpdateHisto();
467 }
468
469// Operations on Histo
470} else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
471 if( dynamic_cast<Histo*>(mobjh2) == NULL )
[1057]472 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
[1054]473 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
474 return;}
475 Histo* h1 =(Histo*) mobjh1;
476 Histo* h2 =(Histo*) mobjh2;
477 if( h1->NBins() != h2->NBins() )
478 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
479 <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
480 Histo* h3 = NULL;
481 if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
482 h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name);
483 } else { // l'objet existe
484 h3 = dynamic_cast<Histo*>(mobjh3);
485 if(h3 == NULL) // ce n'est pas un Histo
[1057]486 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
[1054]487 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
488 return;}
489 if(h1->NBins() != h3->NBins())
490 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
491 <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
492 if( oper[0]=='+') *h3 = *h1 + *h2;
493 else if( oper[0]=='-') *h3 = *h1 - *h2;
494 else if( oper[0]=='*') *h3 = *h1 * *h2;
495 else if( oper[0]=='/') *h3 = *h1 / *h2;
496 }
497
498// Operations on Histo2D
499} else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
500 if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
[1057]501 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
[1054]502 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
503 return;}
504 Histo2D* h1 =(Histo2D*) mobjh1;
505 Histo2D* h2 =(Histo2D*) mobjh2;
506 if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
507 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
508 <<h1->NBinX()<<","<<h1->NBinY()<<" "
509 <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
510 Histo2D* h3 = NULL;
511 if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
512 h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name);
513 } else { // l'objet existe
514 h3 = dynamic_cast<Histo2D*>(mobjh3);
515 if(h3 == NULL) // ce n'est pas un Histo2D
[1057]516 {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
[1054]517 <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl;
518 return;}
519 if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
520 {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
521 <<h1->NBinX()<<","<<h1->NBinY()<<" "
522 <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
523 if( oper[0]=='+') *h3 = *h1 + *h2;
524 else if( oper[0]=='-') *h3 = *h1 - *h2;
525 else if( oper[0]=='*') *h3 = *h1 * *h2;
526 else if( oper[0]=='/') *h3 = *h1 / *h2;
527 }
528
529// Doesn't work for other objects
530} else {
[1057]531 cout<<"PAWExecutor::h_oper Error: not implemented for "
532 <<typeid(*mobjh1).name()<<endl;
[1054]533 return;
534}
535
536return;
537}
538
539/* methode */
[466]540void PAWExecutor::h_plot_2d(vector<string>& tokens)
541// plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
542{
[1065]543if(tokens.size()<1)
[466]544 {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
[1065]545string proj = "h"; if(tokens.size()>1) proj = tokens[1];
[466]546NamedObjMgr omg;
547AnyDataObj* mobj = omg.GetObj(tokens[0]);
548if(mobj==NULL)
549 {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
550 return;}
551Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
552if(!h2)
553 {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
554 return;}
555
556Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
[1065]557//AnyDataObj* mobjh1 = omg.GetObj(nametoplot);
[466]558
559string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
[1065]560if(proj == "show") {
[466]561 h2->ShowProj();
562 h2->ShowBand(2);
563 h2->ShowSli(2);
564 return;
[1065]565} else if(proj == "h") {
[466]566 nametoplot = tokens[0];
[1065]567} else if(proj == "px") {
[466]568 if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
569 else {h2->ShowProj(); return;}
[1065]570} else if(proj == "py") {
[466]571 if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
572 else {h2->ShowProj(); return;}
573} else {
574 if(tokens.size()<3)
575 {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
576 int n = atoi(tokens[2].c_str());
577 dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
[1065]578 if(proj == "bx") {
[466]579 if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
580 else {h2->ShowBand(); return;}
[1065]581 } else if(proj == "by") {
[466]582 if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
583 else {h2->ShowBand(); return;}
[1065]584 } else if(proj == "sx") {
[466]585 if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
586 else {h2->ShowSli(); return;}
[1065]587 } else if(proj == "sy") {
[466]588 if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
589 else {h2->ShowSli(); return;}
[463]590 }
591}
[466]592
593omg.DisplayObj(nametoplot,dopt);
594}
595
596/* methode */
597int PAWExecutor::decodepawstring(string tokens,string& nameobj
598 ,string& xexp,string& yexp,string& zexp)
599// Decodage general de "nameobj.xexp"
600// "nameobj.yexp%xexp"
601// "nameobj.zexp%yexp%xexp"
602// Return: nombre de variables trouvees, -1 si probleme
603{
604nameobj = ""; xexp= ""; yexp= ""; zexp= "";
605
606int lt = (int) tokens.length();
607if(lt<=0) return -1;
608
609// decodage de la chaine de type PAW.
610char *str = new char[lt+2];
611strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
612//cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
613char *c[3] = {NULL,NULL,NULL};
614int i, np=0; bool namefound = false;
[562]615for(i=0;i<lt;i++) {
[466]616 if(!namefound && str[i]=='.') {
617 str[i]='\0';
618 namefound=true;
619 c[np] = str+i+1; np++;
620 }
621 if( namefound && str[i]=='%') {
622 str[i]='\0';
623 if(np<3) {c[np] = str+i+1; np++;}
624 }
625}
626//cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
627
628// Remplissage du nom et des variables
629nameobj = str;
630if(np==1) xexp=c[0];
631if(np==2) {yexp=c[0]; xexp=c[1];}
632if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
633//cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
634delete [] str;
635
636// Comptage des variables
637np = -1;
638if(nameobj.length()>0)
639 {np = 0; if(xexp.length()>0)
640 {np++; if(yexp.length()>0)
641 {np++; if(zexp.length()>0) np++;}}}
642cout<<"pawstring["<<np<<"] name="<<nameobj
643 <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
644return np;
645}
[1065]646
647/* methode */
648void PAWExecutor::h_put_vec(vector<string>& tokens)
649// Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
650// L'histogramme doit deja exister. Le nombre de bins remplit
651// depend des tailles respectives des 2 objets.
[1067]652// tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!")
[1065]653// = "err2" : on remplit les erreurs de l'histogramme
654{
655if(tokens.size()<2)
656 {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
657 return;}
658string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
[1067]659if(toput=="!") toput = "cont";
[1065]660if(toput!="cont" && toput!="err2")
661 {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
662 return;}
663string hname = tokens[0];
664string vname = tokens[1];
665
666// Get objects
667NamedObjMgr omg;
668AnyDataObj* mobjh = omg.GetObj(hname);
669AnyDataObj* mobjv = omg.GetObj(vname);
670if( mobjh==NULL || mobjv==NULL )
671 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
672 return;}
673
674// Fill histo from vector
675if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
676 Histo* h = dynamic_cast<Histo*>(mobjh);
677 Vector* v = dynamic_cast<Vector*>(mobjv);
678 if(toput=="cont") h->PutValue(*v);
679 else if(toput=="err2") h->PutError2(*v);
680
681} else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
682 Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
683 Matrix* v = dynamic_cast<Matrix*>(mobjv);
684 if(toput=="cont") h->PutValue(*v);
685 else if(toput=="err2") h->PutError2(*v);
686
687} else {
688 cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
689 <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
690 return;
691}
692
693}
694
695/* methode */
696void PAWExecutor::h_get_vec(vector<string>& tokens)
697// Pour copier un histo dans un vecteur ou une matrice
698// Si le vecteur (matrice) n'existe pas, il est cree.
699// Le vecteur ou la matrice est re-dimensionne correctement.
[1067]700// tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!")
[1065]701// = "err2" : on copie les erreurs de l'histogramme
702// = "absc" : on copie les erreurs de l'histogramme (1D only)
703// tokens[3[,4]] = show : show available projections for Histo2D
704// px : get X projection
705// py : get Y projection
706// bx n : get X band number n
707// by n : get Y band number n
708// sx n : get X slice number n
709// sy n : get Y slice number n
710{
711if(tokens.size()<2)
712 {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
713 return;}
714string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
[1067]715if(toget=="!") toget = "cont";
[1065]716if(toget!="cont" && toget!="err2" && toget!="absc")
717 {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
718 return;}
719string proj = "h"; if(tokens.size()>3) proj = tokens[3];
720int nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
721string hname = tokens[0];
722string vname = tokens[1];
723
724// Get objects
725NamedObjMgr omg;
726AnyDataObj* mobjh = omg.GetObj(hname);
727AnyDataObj* mobjv = omg.GetObj(vname);
728if( mobjh==NULL)
729 {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
730 return;}
731
732// Fill histo from vector
733Histo* h = dynamic_cast<Histo*>(mobjh);
734Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
735if( h != NULL ) { // Histo ou HProf
736 HProf* hp = dynamic_cast<HProf*>(mobjh);
737 if(hp!=NULL) if(!(hp->IsOk())) hp->UpdateHisto();
738 Vector* v = NULL;
739 if(mobjv==NULL) // le vecteur n'existe pas
740 {v = new Vector(1); omg.AddObj(v,vname);}
741 AnyDataObj* mobjv = omg.GetObj(vname);
742 if(typeid(*mobjv) != typeid(Vector))
743 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
744 <<typeid(*mobjv).name()<<endl; return;}
745 v = dynamic_cast<Vector*>(mobjv);
746 if(toget=="cont") h->GetValue(*v);
747 else if(toget=="err2") h->GetError2(*v);
748 else if(toget=="absc") h->GetAbsc(*v);
749
750} else if( h2 != NULL) { // Histo2D
751
752 if(proj == "h") { // On veut les valeurs de l'histogramme 2D
753 Matrix* v = NULL;
754 if(mobjv==NULL) // la matrice n'existe pas
755 {v = new Matrix(1,1); omg.AddObj(v,vname);}
756 AnyDataObj* mobjv = omg.GetObj(vname);
757 if(typeid(*mobjv) != typeid(Matrix))
758 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
759 <<typeid(*mobjv).name()<<endl; return;}
760 v = dynamic_cast<Matrix*>(mobjv);
761 if(toget=="cont") h2->GetValue(*v);
762 else if(toget=="err2") h2->GetError2(*v);
763 else
764 {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
765 return;}
766
767 } else { // On veut les valeurs d'une projection de l'histo 2D
768 h = NULL;
769 if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
770 else if(proj == "px") h = h2->HProjX();
771 else if(proj == "py") h = h2->HProjY();
772 else if(proj == "bx") h = h2->HBandX(nproj);
773 else if(proj == "by") h = h2->HBandY(nproj);
774 else if(proj == "sx") h = h2->HSliX(nproj);
775 else if(proj == "sy") h = h2->HSliY(nproj);
776 if(h==NULL)
777 {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
778 <<" number "<<nproj<<endl; return;}
779 Vector* v = NULL;
780 if(mobjv==NULL) // le vecteur n'existe pas
781 {v = new Vector(1); omg.AddObj(v,vname);}
782 AnyDataObj* mobjv = omg.GetObj(vname);
783 if(typeid(*mobjv) != typeid(Vector))
784 {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
785 <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
786 v = dynamic_cast<Vector*>(mobjv);
787 if(toget=="cont") h->GetValue(*v);
788 else if(toget=="err2") h->GetError2(*v);
789 else if(toget=="absc") h->GetAbsc(*v);
790 }
791
792} else {
793 cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
794 <<typeid(*mobjh).name()<<endl;
795 return;
796}
797
798}
Note: See TracBrowser for help on using the repository browser.