source: Sophya/trunk/SophyaPI/PIext/servnobjm.cc@ 349

Last change on this file since 349 was 349, checked in by ercodmgr, 26 years ago

A/ ajout des blocs foreach et ameliorations gestion des variables ($x)
pour l'interpreteur piacmd.
B/ Ajout PIStdImgApp::AddText et corrections diverses

Reza 05/08/99

File size: 54.5 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
5#include <typeinfo>
6#include <iostream.h>
7#include <string>
8#include <list>
9#include <map>
10#if defined(__KCC__)
11using std::string ;
12#include <list.h>
13#include <map.h>
14#endif
15
16#include "strutil.h"
17
18#include "nobjmgr.h"
19#include "servnobjm.h"
20#include "nomgadapter.h"
21#include "pistdimgapp.h"
22
23#include "fct1dfit.h"
24#include "fct2dfit.h"
25
26#include "matrix.h"
27#include "cvector.h"
28#include "ntuple.h"
29#include "cimage.h"
30
31#include "histos.h"
32#include "histos2.h"
33#include "ntuple.h"
34#include "hisprof.h"
35
36#include "piscdrawwdg.h"
37#include "pisurfdr.h"
38
39#include "pintuple.h"
40#include "pintup3d.h"
41
42#include "pipodrw.h"
43
44
45
46/* --Methode-- */
47Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir)
48{
49TmpDir = tmpdir;
50PDynLinkMgr::SetTmpDir(tmpdir);
51mImgapp = NULL;
52mOmg = omg;
53dynlink = NULL;
54InitGrAttNames();
55}
56
57/* --Methode-- */
58Services2NObjMgr::~Services2NObjMgr()
59{
60CloseDLL();
61}
62
63/* --Methode-- */
64void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
65{
66ObjAdaptList::iterator it;
67for(it = objadaplist.begin(); it != objadaplist.end(); it++)
68 if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
69
70dataobj_adapter oba;
71oba.obj = o;
72oba.obja = oa;
73objadaplist.push_back(oba);
74}
75
76/* --Methode-- */
77NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
78{
79ObjAdaptList::iterator it;
80for(it = objadaplist.begin(); it != objadaplist.end(); it++)
81 if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
82return(new NObjMgrAdapter(o));
83}
84
85/* --Methode-- */
86void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
87{
88FILE *fip;
89string fname = TmpDir + "func1_pia_dl.c";
90string cmd;
91int rc;
92
93if (!mImgapp) return;
94
95cmd = "rm -f " + fname;
96rc = system(cmd.c_str());
97// printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
98
99if ((fip = fopen(fname.c_str(), "w")) == NULL) {
100 string sn = fname;
101 cout << "Services2NObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl;
102 return;
103 }
104
105// constitution du fichier a compiler
106fputs("#include <math.h> \n", fip);
107fputs("double func1_pia_dl_func(double x) \n{\n", fip);
108fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
109fclose(fip);
110
111string func = "func1_pia_dl_func";
112DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
113if (!f) return;
114PlotFunc(f, nom, xmin, xmax, np, dopt);
115CloseDLL();
116return;
117}
118
119/* --Methode-- */
120void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
121 double ymin, double ymax, int npx, int npy, string dopt)
122{
123FILE *fip;
124string fname = TmpDir + "func2_pia_dl.c";
125string cmd;
126int rc;
127
128if (!mImgapp) return;
129
130cmd = "rm " + fname;
131rc = system(cmd.c_str());
132// printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
133
134if ((fip = fopen(fname.c_str(), "w")) == NULL) {
135 string sn = fname;
136 cout << "Services2NObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl;
137 return;
138 }
139
140// constitution du fichier a compiler
141fputs("#include <math.h> \n", fip);
142fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
143fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
144fclose(fip);
145
146string func = "func2_pia_dl_func";
147DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
148if (!f) return;
149PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
150CloseDLL();
151return;
152}
153
154/* --Methode-- */
155void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
156 double xmin, double xmax, int np, string dopt)
157{
158DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
159if (!f) return;
160PlotFunc(f, nom, xmin, xmax, np, dopt);
161CloseDLL();
162return;
163}
164
165/* --Methode-- */
166void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
167 double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
168{
169DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
170if (!f) return;
171PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
172CloseDLL();
173return;
174}
175
176/* --Methode-- */
177void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
178{
179if (!mImgapp) return;
180
181int k;
182if (np < 1) np = 1;
183if (xmax <= xmin) xmax = xmin+1.;
184Vector* vpy = new Vector(np);
185
186double xx;
187double dx = (xmax-xmin)/np;
188TRY {
189 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
190} CATCH(merr) {
191 fflush(stdout);
192 cout << endl;
193 cerr << endl;
194 string es = PeidaExc(merr);
195 cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;
196 delete vpy;
197 vpy = NULL;
198 } ENDTRY;
199
200
201if (vpy) {
202 string titre;
203 if (nom.length() < 1) {
204 titre = "Function f(x)";
205 nom = "/tmp/func";
206 }
207 else titre = nom;
208
209 P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
210 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
211 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
212 bool fgsr = true;
213 dopt = "thinline," + dopt;
214 int opt = DecodeDispOption(dopt, fgsr);
215 int rsid = mImgapp->DispScDrawer(dr, titre, opt);
216 if (fgsr) mImgapp->RestoreGraphicAtt();
217 if (nom.length() > 0) {
218 mOmg->AddObj(vpy, nom);
219 mOmg->AddWRsId(nom, rsid);
220 }
221 }
222
223return;
224}
225
226/* --Methode-- */
227void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
228 int npx, int npy, string dopt)
229{
230if (!mImgapp) return;
231
232if (npx < 3) npx = 3;
233if (npy < 3) npy = 3;
234if (npx > 250) npx = 250;
235if (npy > 250) npy = 250;
236if (xmax <= xmin) xmax = xmin+1.;
237if (ymax <= ymin) ymax = ymin+1.;
238
239Matrix* mtx = new Matrix(npy, npx);
240
241int i,j;
242double xx, yy;
243double dx = (xmax-xmin)/npx;
244double dy = (ymax-ymin)/npy;
245// printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
246TRY {
247 for(j=0; j<npy; j++) {
248 yy = ymin+dy*j;
249 for(i=0; i<npx; i++) {
250 xx = xmin+dx*i;
251 (*mtx)(j, i) = f(xx, yy);
252 }
253 }
254} CATCH(merr) {
255 fflush(stdout);
256 cout << endl;
257 cerr << endl;
258 string es = PeidaExc(merr);
259 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;
260 delete mtx; mtx = NULL;
261 } ENDTRY;
262
263if (mtx) {
264 string titre;
265 if (nom.length() < 1) {
266 titre = "Function f(x,y)";
267 nom = "/tmp/func2d";
268 }
269 else titre = nom;
270 bool fgsr = true;
271 int opt = DecodeDispOption(dopt, fgsr);
272 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
273 arr->DefineXYCoordinates(xmin, ymin, dx, dy);
274 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
275 int rsid = mImgapp->Disp3DDrawer(sdr, titre, opt);
276 if (fgsr) mImgapp->RestoreGraphicAtt();
277 if (nom.length() > 0) {
278 mOmg->AddObj(mtx, nom);
279 mOmg->AddWRsId(nom, rsid);
280 }
281 }
282
283return;
284}
285
286/* --Methode-- */
287void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
288 string& experrx, string& experry,
289 string& expcut, string dopt)
290{
291NObjMgrAdapter* obja=NULL;
292obja = mOmg->GetObjAdapter(nom);
293if (obja == NULL) {
294 cout << "Services2NObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl;
295 return;
296 }
297if (!mImgapp) return;
298
299// Creation NTuple
300char* ntn[4] = {"expx","expy","expex","expey",};
301NTuple* nt = NULL;
302bool haserr = false;
303
304if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
305else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
306
307ComputeExpressions(obja, expx, expy, experrx, experry, expcut, nt, NULL, NULL);
308
309if (nt->NEntry() < 1) {
310 cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
311 delete nt;
312 return;
313 }
314
315// nt->Show();
316// nt->Print(0,10);
317PINTuple* pin = new PINTuple(nt, true);
318pin->SelectXY(ntn[0], ntn[1]);
319if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
320
321bool fgsr = true;
322dopt = "defline," + dopt;
323int opt = DecodeDispOption(dopt, fgsr);
324string titre = nom + ":" + expy + "%" + expx;
325mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
326if (fgsr) mImgapp->RestoreGraphicAtt();
327return;
328}
329
330/* --Methode-- */
331void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
332 string& expz, string& expcut, string dopt)
333{
334NObjMgrAdapter* obja=NULL;
335obja = mOmg->GetObjAdapter(nom);
336if (obja == NULL) {
337 cout << "Services2NObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl;
338 return;
339 }
340if (!mImgapp) return;
341
342char* ntn[3] = {"expx","expy","expz"};
343NTuple* nt = new NTuple(3,ntn); // Creation NTuple
344
345string expwt = "1.";
346ComputeExpressions(obja, expx, expy, expz, expwt, expcut, nt, NULL, NULL);
347
348if (nt->NEntry() < 1) {
349 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
350 delete nt;
351 return;
352 }
353nt->Show();
354nt->Print(0,10);
355PINTuple3D* pin = new PINTuple3D(nt, true);
356pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
357bool fgsr = true;
358dopt = "defline," + dopt;
359int opt = DecodeDispOption(dopt, fgsr);
360
361// Pour plot a partir de DispScDrawer
362// string nomdisp = "_NT3D_";
363// mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
364// Pour plot a partir de Disp3DDrawer
365string titre = nom + ":" + expy + "%" + expx;
366mImgapp->Disp3DDrawer(pin, titre, opt);
367
368if (fgsr) mImgapp->RestoreGraphicAtt();
369return;
370}
371
372/* --Methode-- */
373void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
374 string& expwt, string& expcut, string dopt)
375{
376NObjMgrAdapter* obja=NULL;
377obja = mOmg->GetObjAdapter(nom);
378if (obja == NULL) {
379 cout << "Services2NObjMgr::DisplayPoints2DW() Error , Pas d'objet de nom " << nom << endl;
380 return;
381 }
382if (!mImgapp) return;
383
384char* ntn[3] = {"expx","expy","expw"};
385NTuple* nt = new NTuple(3,ntn); // Creation NTuple
386
387string exp = "1.";
388ComputeExpressions(obja, expx, expy, expwt, exp, expcut, nt, NULL, NULL);
389
390if (nt->NEntry() < 1) {
391 cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
392 delete nt;
393 return;
394 }
395
396PINTuple* pin = new PINTuple(nt, true);
397pin->SelectXY(ntn[0], ntn[1]);
398pin->SelectWt(ntn[2]);
399
400bool fgsr = true;
401int opt = DecodeDispOption(dopt, fgsr);
402string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
403mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
404if (fgsr) mImgapp->RestoreGraphicAtt();
405return;
406}
407
408/* --Methode-- */
409void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
410 string& expcut, string& nomh1, string dopt)
411{
412NObjMgrAdapter* obja=NULL;
413obja = mOmg->GetObjAdapter(nom);
414if (obja == NULL) {
415 cout << "Services2NObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl;
416 return;
417 }
418if (!mImgapp) return;
419
420Histo* h1 = NULL;
421NTuple* nt = NULL;
422AnyDataObj* oh = NULL;
423if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1);
424else nomh1 = "/tmp/projh1d";
425if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
426else {
427 char* ntn[2]= {"hxval", "hwt"};
428 nt = new NTuple(2,ntn); // Creation NTuple
429 }
430string expz = "0.";
431ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, nt, h1, NULL);
432
433if ((!h1) && (!nt)) return;
434if (!h1) {
435 if (nt->NEntry() < 1) {
436 cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
437 delete nt;
438 return;
439 }
440 double xmin, xmax;
441 nt->GetMinMax(0, xmin, xmax);
442 h1 = new Histo(xmin, xmax, 100);
443 int k;
444 float* xn;
445 for(k=0; k<nt->NEntry(); k++) {
446 xn = nt->GetVec(k);
447 h1->Add(xn[0], xn[1]);
448 }
449 delete nt;
450 mOmg->AddObj(h1, nomh1);
451 }
452
453mOmg->DisplayObj(nomh1, dopt);
454return;
455}
456
457/* --Methode-- */
458void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
459 string& expcut, string& nomh2, string dopt)
460{
461NObjMgrAdapter* obja=NULL;
462obja = mOmg->GetObjAdapter(nom);
463if (obja == NULL) {
464 cout << "Services2NObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl;
465 return;
466 }
467if (!mImgapp) return;
468
469Histo2D* h2 = NULL;
470NTuple* nt = NULL;
471AnyDataObj* oh = NULL;
472if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2);
473else nomh2 = "/tmp/projh2d";
474if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
475else {
476 char* ntn[3]= {"hxval", "hyval", "hwt"};
477 nt = new NTuple(3,ntn); // Creation NTuple
478 }
479string expz = "0.";
480ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, h2);
481
482if ((!h2) && (!nt)) return;
483if (!h2) {
484 if (nt->NEntry() < 1) {
485 cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
486 delete nt;
487 return;
488 }
489 double xmin, xmax, ymin, ymax;
490 nt->GetMinMax(0, xmin, xmax);
491 nt->GetMinMax(0, ymin, ymax);
492 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
493 int k;
494 float* xn;
495 for(k=0; k<nt->NEntry(); k++) {
496 xn = nt->GetVec(k);
497 h2->Add(xn[0], xn[1], xn[2]);
498 }
499 delete nt;
500 mOmg->AddObj(h2, nomh2);
501 }
502
503mOmg->DisplayObj(nomh2, dopt);
504return;
505
506}
507
508/* --Methode-- cmv 13/10/98 */
509void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
510 string& expcut, string& nomprof, string dopt)
511// Pour remplir un ``GeneralFitData'' a partir de divers objets:
512//| nom = nom de l'objet a projeter dans un HProf.
513//| expx = expression X de definition du bin.
514//| expy = expression Y a additionner dans le bin.
515//| expwt = expression W du poids a additionner.
516//| expcut = expression du test de selection.
517//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
518//| les limites Xmin,Xmax sont calculees automatiquement.
519//| sinon ce sont celles de l'objet preexistant.
520//| opt = options generales pour le display.
521{
522NObjMgrAdapter* obja=NULL;
523obja = mOmg->GetObjAdapter(nom);
524if (obja == NULL) {
525 cout << "Services2NObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl;
526 return;
527 }
528if (!mImgapp) return;
529
530HProf* hprof = NULL;
531NTuple* nt = NULL;
532AnyDataObj* oh = NULL;
533if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof);
534else nomprof = "/tmp/projprof";
535if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
536else {
537 char* ntn[3]= {"hxval", "hyval", "hwt"};
538 nt = new NTuple(3,ntn); // Creation NTuple
539}
540string expz = "0.";
541ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof);
542
543if((!hprof) && (!nt)) return;
544if(!hprof) {
545 if (nt->NEntry() < 1) {
546 cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
547 delete nt;
548 return;
549 }
550 double xmin, xmax;
551 nt->GetMinMax(0, xmin, xmax);
552 hprof = new HProf(xmin, xmax, 100);
553 int k;
554 float* xn;
555 for(k=0; k<nt->NEntry(); k++) {
556 xn = nt->GetVec(k);
557 hprof->Add(xn[0], xn[1], xn[2]);
558 }
559 delete nt;
560 mOmg->AddObj(hprof, nomprof);
561 }
562hprof->UpdateHisto();
563
564mOmg->DisplayObj(nomprof, dopt);
565return;
566}
567
568/* --Methode-- */
569void Services2NObjMgr::FillVect(string& nom, string& expx, string& expcut,
570 string& nomvec, string dopt)
571{
572NObjMgrAdapter* obja=NULL;
573obja = mOmg->GetObjAdapter(nom);
574if (obja == NULL) {
575 cout << "Services2NObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl;
576 return;
577 }
578if (!mImgapp) return;
579
580NTuple* nt = NULL;
581if (nomvec.length() < 1) nomvec = "/tmp/fillvec";
582
583char* ntn[2]= {"vecval", "vecwt"};
584nt = new NTuple(1,ntn); // Creation NTuple
585
586string expwt = "1.";
587string expz = "0.";
588ComputeExpressions(obja, expx, expz, expz, expwt, expcut, nt, NULL, NULL);
589
590if (!nt) return;
591if (nt->NEntry() < 1) {
592 cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
593 delete nt;
594 return;
595 }
596
597Vector* vec = new Vector(nt->NEntry());
598int k;
599float* xn;
600for(k=0; k<nt->NEntry(); k++) {
601 xn = nt->GetVec(k);
602 (*vec)(k) = xn[0];
603 }
604delete nt;
605mOmg->AddObj(vec, nomvec);
606mOmg->DisplayObj(nomvec, dopt);
607return;
608}
609
610/* --Methode-- */
611void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
612 string& expt, string& expcut, string& nomnt)
613{
614NObjMgrAdapter* obja=NULL;
615obja = mOmg->GetObjAdapter(nom);
616if (obja == NULL) {
617 cout << "Services2NObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl;
618 return;
619 }
620if (!mImgapp) return;
621
622bool fgnnt = false;
623NTuple* nt = NULL;
624AnyDataObj* oh = NULL;
625if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
626else nomnt = "/tmp/fillnt";
627if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
628 nt = (NTuple*)oh;
629 if (nt->NVar() > 10) {
630 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
631 nt = NULL;
632 }
633 }
634if (nt == NULL) {
635 char* ntn[4]= {"x", "y","z","t"};
636 nt = new NTuple(4,ntn); // Creation NTuple
637 fgnnt = true;
638 }
639
640ComputeExpressions(obja, expx, expy, expz, expt, expcut, nt, NULL, NULL);
641
642if (fgnnt) mOmg->AddObj(nt, nomnt);
643return;
644
645}
646
647/* --Methode-- */
648void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
649 string const & funcname, string & nomnt,
650 int nl1, int nl2)
651{
652if (!mImgapp) return;
653
654NObjMgrAdapter* obja=NULL;
655obja = mOmg->GetObjAdapter(nom);
656if (obja == NULL) {
657 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
658 return;
659 }
660bool adel = true;
661NTupleInterface* objnt = obja->GetNTupleInterface(adel);
662if (objnt == NULL) {
663 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No NTupleInterface !" <<endl;
664 return;
665 }
666
667NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
668if (!f) {
669 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
670 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
671 return;
672 }
673
674bool fgnnt = false;
675NTuple* nt = NULL;
676if (nomnt.length() > 0) {
677 AnyDataObj* oh = NULL;
678 oh=mOmg->GetObj(nomnt);
679 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
680 nt = (NTuple*)oh;
681 if (nt->NVar() > 10) {
682 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
683 nt = NULL;
684 }
685 }
686 if (nt == NULL) {
687 char* ntn[4]= {"x", "y","z","t"};
688 nt = new NTuple(4,ntn); // Creation NTuple
689 fgnnt = true;
690 }
691 }
692
693double xnt[10];
694float fxnt[10];
695
696int i,k;
697for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
698
699
700// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
701// redirige - On redirige la sortie sur le terminal
702bool red = mImgapp->HasRedirectedStdOutErr();
703mImgapp->RedirectStdOutErr(false);
704
705TRY {
706 double* xn;
707 if (nl1 < 0) nl1 = 0;
708 if (nl2 < 0) nl2 = objnt->NbLines();
709 if (nl2 > objnt->NbLines()) nl2 = objnt->NbLines();
710 int kmax = nl2;
711 for(k=nl1; k<kmax; k++) {
712 xn = objnt->GetLineD(k);
713 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
714 if (nt) {
715 for(i=0; i<4; i++) fxnt[i] = xnt[i];
716 nt->Fill(fxnt);
717 }
718 }
719 }
720 }
721CATCH(merr) {
722 fflush(stdout);
723 cout << endl;
724 cerr << endl;
725 string es = PeidaExc(merr);
726 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
727 } ENDTRY;
728
729if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
730CloseDLL();
731
732// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
733mImgapp->RedirectStdOutErr(red);
734
735if (fgnnt) mOmg->AddObj(nt, nomnt);
736return;
737}
738
739/* --Methode-- */
740void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
741 string const & funcname)
742{
743NObjMgrAdapter* obja=NULL;
744obja = mOmg->GetObjAdapter(nom);
745if (obja == NULL) {
746 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
747 return;
748 }
749bool adel = true;
750NTupleInterface* objnt = obja->GetNTupleInterface(adel);
751if (objnt == NULL) {
752 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
753 << "...) No NTupleInterface !" <<endl;
754 return;
755 }
756string vardec = objnt->VarList_C("_xnti_");
757
758FILE *fip;
759if ((fip = fopen(fname.c_str(), "w")) == NULL) {
760 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
761 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
762 return;
763 }
764
765// constitution du fichier des decalarations des variables de l'interface NTuple
766fputs("#include <stdlib.h> \n", fip);
767fputs("#include <stdio.h> \n", fip);
768fputs("#include <math.h> \n\n", fip);
769
770fputs("/* ------ Some random number generators --------- */ \n", fip);
771fputs("#define frand01() ( (float) drand48() ) \n", fip);
772fputs("#define drand01() drand48() \n", fip);
773fputs("#define rand01() drand48() \n", fip);
774fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
775fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
776fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
777fputs("double NorRand(void) \n", fip);
778fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
779fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
780fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
781fputs(" return(x); \n } \n", fip);
782fputs("#define GauRand() NorRand() \n", fip);
783fputs("#define gaurand() NorRand() \n\n", fip);
784
785fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
786fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
787fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
788 funcname.c_str());
789fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
790fprintf(fip, "{ \n %s \n", vardec.c_str());
791fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
792fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
793fputs(" } \n /* Cut expression satisfied */ \n", fip);
794fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
795fputs(" return(1); \n} \n", fip);
796
797fclose(fip);
798
799if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
800return;
801}
802
803
804/* --Methode-- cmv 13/10/98 */
805void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
806 string& experr, string& expcut, string& nomgfd)
807// Pour remplir un ``GeneralFitData'' a partir de divers objets:
808//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
809//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
810//| expx = expression X du GeneralFitData (1er abscisse)
811//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
812//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
813//| experr = expression de l'erreur sur l'ordonnee Z
814//| expcut = expression du test de selection
815//| nomgfd = nom du GeneralFitData engendre (optionnel)
816{
817NObjMgrAdapter* obja=NULL;
818obja = mOmg->GetObjAdapter(nom);
819if (obja == NULL) {
820 cout << "Services2NObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl;
821 return;
822 }
823if(!mImgapp) return;
824
825// 2D ou 3D?
826int nvar = 2;
827if(expy.length()<=0) {nvar = 1; expy = "0.";}
828
829// Creation NTuple Buffer
830char* ntn[4]= {"x","y","f","e"};
831NTuple*nt = new NTuple(4,ntn);
832
833// Remplissage NTuple buffer
834ComputeExpressions(obja, expx, expy, expz, experr, expcut, nt, NULL, NULL);
835if(nt->NEntry() < 1)
836 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
837 delete nt; return;}
838
839//Remplissage de la structure GeneraFitData
840if (nt->NEntry() <= 0) {
841 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
842 delete nt;
843 return;
844 }
845
846GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
847int k;
848float* xn;
849for(k=0; k<nt->NEntry(); k++) {
850 xn = nt->GetVec(k);
851 gfd->AddData(xn,xn[2],xn[3]);
852}
853
854// Menage et table d'objets
855delete nt;
856mOmg->AddObj(gfd, nomgfd);
857return;
858}
859
860
861///////////////////// Fit 1D et 2D //////////////////////////
862/* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */
863struct DFOptions {
864 int okres, okfun;
865 int polcx,polcy; double xc,yc;
866 double err_e, err_E;
867 double stc2;
868 int nstep;
869 int lp,lpg;
870 int i1,i2,j1,j2;
871};
872typedef struct DFOptions DFOPTIONS;
873static void DecodeFitsOptions(string par,string step,string min,string max,string opt
874 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O);
875void DecodeFitsOptions(string par,string step,string min,string max,string opt
876 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O)
877//| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D)
878{
879// set des vecteurs et decodage des string correspondantes
880int NParMax = 100;
881Par.Realloc(NParMax); Step.Realloc(NParMax);
882Min.Realloc(NParMax); Max.Realloc(NParMax);
883{
884 Vector* v=NULL; string* s=NULL;
885 {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}}
886 for(int j=0;j<4;j++) {
887 if(j==0) {v=&Par; s=&par;}
888 else if(j==1) {v=&Step; s=&step;}
889 else if(j==2) {v=&Min; s=&min;}
890 else if(j==3) {v=&Max; s=&max;}
891 if(s->length()>0) *s += ",";
892 for(int i=0;i<NParMax;i++) {
893 if(s->length()<=0) break;
894 sscanf(s->c_str(),"%lf",&(*v)(i));
895 size_t p = s->find_first_of(',') + 1;
896 if(p>=s->length()) *s = ""; else *s = s->substr(p);
897 }
898 }
899}
900
901// Decodage de options de opt
902O.okres = O.okfun = 0;
903O.polcx = O.polcy = 0;
904O.xc = O.yc = 0.;
905O.stc2 = 1.e-3;
906O.nstep = 100;
907O.err_e = O.err_E = -1.;
908O.lp = 1; O.lpg = 0;
909O.i1 = O.j1 = O.i2 = O.j2 = -1;
910
911if(opt.length()<=0) return;
912opt = "," + opt + ",";
913
914if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus
915if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee
916if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
917 O.polcx = 2; // Le centrage est calcule automatiquement
918 size_t p = opt.find(",x");
919 size_t q = opt.find_first_of(',',p+1);
920 string dum = opt.substr(p,q-p);
921 if(dum.length()>2) {
922 sscanf(dum.c_str(),",x%lf",&O.xc);
923 O.polcx = 1; // Le centrage est fixe par la valeur lue
924 }
925}
926if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
927 O.polcy = 2; // Le centrage est calcule automatiquement
928 size_t p = opt.find(",y");
929 size_t q = opt.find_first_of(',',p+1);
930 string dum = opt.substr(p,q-p);
931 if(dum.length()>2) {
932 sscanf(dum.c_str(),",y%lf",&O.yc);
933 O.polcy = 1; // Le centrage est fixe par la valeur lue
934 }
935}
936if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
937 size_t p = opt.find(",E");
938 size_t q = opt.find_first_of(',',p+1);
939 string dum = opt.substr(p,q-p);
940 if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E);
941 if(O.err_E<=0.) O.err_E = 1.;
942 O.err_e=-1.;
943}
944if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
945 size_t p = opt.find(",e");
946 size_t q = opt.find_first_of(',',p+1);
947 string dum = opt.substr(p,q-p);
948 if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e);
949 if(O.err_e<=0.) O.err_e = 1.;
950 O.err_E=-1.;
951}
952if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
953 size_t p = opt.find(",X");
954 size_t q = opt.find_first_of(',',p+1);
955 string dum = opt.substr(p,q-p);
956 if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2);
957 if(O.stc2<=0.) O.stc2 = 1.e-3;
958}
959if(strstr(opt.c_str(),",N")) { // Nombre maximum d'iterations
960 size_t p = opt.find(",N");
961 size_t q = opt.find_first_of(',',p+1);
962 string dum = opt.substr(p,q-p);
963 if(dum.length()>2) sscanf(dum.c_str(),",N%d",&O.nstep);
964 if(O.nstep<2) O.nstep = 100;
965}
966if(strstr(opt.c_str(),",l")) { // niveau de print
967 size_t p = opt.find(",l");
968 size_t q = opt.find_first_of(',',p+1);
969 string dum = opt.substr(p,q-p);
970 float ab;
971 if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
972 if(ab<0) ab = 0.;
973 O.lp = (int) ab; O.lpg = int(10.*(ab-(float)O.lp+0.01));
974}
975if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
976 size_t p = opt.find(",I");
977 size_t q = opt.find_first_of(',',p+1);
978 string dum = opt.substr(p,q-p);
979 if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2);
980}
981if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
982 size_t p = opt.find(",J");
983 size_t q = opt.find_first_of(',',p+1);
984 string dum = opt.substr(p,q-p);
985 if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2);
986}
987return;
988}
989
990/* --Methode-- cmv 13/10/98 */
991void Services2NObjMgr::Fit12D(string& nom, string& func,
992 string par,string step,string min,string max,
993 string opt)
994//| --------------- Fit d'objets a 1 et 2 dimensions ---------------
995//| nom : nom de l'objet qui peut etre:
996//| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D)
997//| fit-2D: Matrix,Histo2D,Image<T> ou GeneraFitData(2D)
998//| func : pnn : fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
999//| : Pnn : fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
1000//| : gnn : fit gaussienne (hauteur) + polynome de degre nn 1D
1001//| : g : fit gaussienne (hauteur) 1D
1002//| : enn : fit exponentielle + polynome de degre nn 1D
1003//| : e : fit exponentielle 1D
1004//| : Gnn : fit gaussienne (volume) + polynome de degre nn 1D
1005//| : G : fit gaussienne (volume) 1D
1006//| : : fit gaussienne+fond (volume) 2D
1007//| : Gi : fit gaussienne+fond integree (volume) 2D
1008//| : d : fit DL de gaussienne+fond (volume) 2D
1009//| : di : fit DL de gaussienne+fond integree (volume) 2D
1010//| : D : fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
1011//| : Di : fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
1012//| : M : fit Moffat+fond (expos=p6) (volume) 2D
1013//| : Mi : fit Moffat+fond integree (expos=p6) (volume) 2D
1014//| par : p1,...,pn : valeur d'initialisation des parametres (def=0)
1015//| step : s1,...,sn : valeur des steps de depart (def=1)
1016//| min : m1,...,mn : valeur des minima (def=1)
1017//| max : M1,...,Mn : valeur des maxima (def=-1) (max<=min : pas de limite)
1018//| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b"
1019//| f : generation d'un Objet identique contenant la fonction fittee
1020//| r : generation d'un Objet identique contenant les residus
1021//| Xaa.b : aa.b valeur du DXi2 d'arret (def=1.e-3)
1022//| Naa : aa nombre maximum d'iterations (def=100)
1023//| la.b : niveau "a.b" de print: a=niveau de print Fit1/2D
1024//| b=niveau de debug GeneralFit
1025//| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2]
1026//|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2]
1027//| - L'erreur est celle associee a l'objet (si elle existe),
1028//| elle est mise a 1 sinon, sauf si E... ou e... est precise:
1029//| Eaa.b : si |val|>=1 erreur = aa.b*sqrt(|val|)
1030//| si |val|<1 erreur = aa.b
1031//| si aa.b <=0 alors aa.b=1.0
1032//| E seul est equivalent a E1.0
1033//| eaa.b : erreur = aa.b
1034//| si aa.b <=0 alors aa.b=1.0
1035//| e seul est equivalent a e1.0
1036//| xaa.b : demande de centrage: on fit x-aa.b au lieu de x)
1037//| x : demande de centrage: on fit x-xc au lieu de x
1038//| avec xc=abscisse du milieu de l'histogramme
1039//| Actif pour exp+poly 1D, poly 1D
1040//| pour gauss+poly 1D, xc est le centre de la gaussienne.
1041//|2D yaa.b et y : idem "xaa.b et x" mais pour y
1042{
1043AnyDataObj* obj=mOmg->GetObj(nom);
1044if (obj == NULL) {
1045 cout<<"Services2NObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl;
1046 return;
1047}
1048if (!mImgapp) return;
1049if(func.length()<=0)
1050 {cout<<"Services2NObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl;
1051 return;}
1052string ctyp = typeid(*obj).name();
1053
1054int ndim = 0, nbinx=0, nbiny=0, ndata = 0;
1055Vector* v = NULL; Histo* h = NULL;
1056Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL;
1057GeneralFitData* g = NULL;
1058
1059 // 1D
1060if (typeid(*obj) == typeid(Vector)) {
1061 ndim = 1;
1062 v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1;
1063 }
1064else if ( (typeid(*obj) == typeid(HProf)) || (typeid(*obj) == typeid(Histo)) ) {
1065 ndim = 1;
1066 h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1;
1067 }
1068else if (typeid(*obj) == typeid(Matrix)) {
1069 ndim = 2;
1070 m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows();
1071 }
1072else if (typeid(*obj) == typeid(Histo2D)) {
1073 ndim = 2;
1074 h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY();
1075 }
1076else if (typeid(*obj) == typeid(GeneralFitData)) {
1077 g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1;
1078 if( g->NVar()==1) ndim = 1;
1079 else if(g->NVar()==2) ndim = 2;
1080 else {
1081 cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
1082 <<((GeneralFitData*) obj)->NVar()<<endl; return; }
1083 }
1084else if (dynamic_cast<RzImage*>(obj)) {
1085 ndim = 2;
1086 im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize();
1087 }
1088else {
1089 cout<<"Services2NObjMgr::Fit12D() Error , Objet n'est pas un "
1090 <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
1091 return;
1092 }
1093
1094ndata = nbinx*nbiny;
1095if(ndata<=0)
1096 {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;}
1097
1098// Decodage des options et des parametres, mise en forme
1099Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O;
1100DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O);
1101O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1;
1102O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2;
1103if(ndim>=2) {
1104 O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1;
1105 O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2;
1106} else O.j2 = O.j1 = 0;
1107if(O.polcx==2) {
1108 if(v||m) O.xc = (O.i2-O.i1+1)/2.;
1109 else if(h) O.xc = (h->XMin()+h->XMax())/2.;
1110 else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.;
1111 else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;}
1112 else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;}
1113}
1114if(O.polcy==2 && ndim>=2) {
1115 if(m) O.yc = (O.j2-O.j1+1)/2.;
1116 if(h2) O.yc = (h2->YMin()+h2->YMax())/2.;
1117 if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;}
1118 if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;}
1119}
1120if(O.lp>0)
1121 cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":"
1122 <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl
1123 <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y"
1124 <<" TypE="<<O.err_e<<","<<O.err_E
1125 <<" StpX2="<<O.stc2<<" Nstep="<<O.nstep
1126 <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl;
1127
1128///////////////////////////////////
1129// Remplissage de GeneralFitData //
1130///////////////////////////////////
1131GeneralFitData mydata(ndim,ndata,0);
1132{for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) {
1133 double x,y,f,e;
1134
1135 if(v)
1136 {x= (double) i; f=(*v)(i); e=1.;}
1137 else if(h)
1138 {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;}
1139 else if(m)
1140 {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;}
1141 else if(h2)
1142 {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
1143 f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;}
1144 else if(im)
1145 {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize();
1146 f=im->DValue(i,j); e=1.;}
1147 else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);}
1148 else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);}
1149 else x=y=f=e=0.;
1150
1151 // Gestion des erreurs a utiliser
1152 if(O.err_e>0.) e=O.err_e;
1153 else if(O.err_E>0.) {e=(f<-1.||f>1.)?O.err_E*sqrt(fabs(f)):O.err_E;}
1154
1155 // Remplissage de generalfit
1156 if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;}
1157 if(ndim==1) mydata.AddData1(x,f,e);
1158 else if(ndim==2) mydata.AddData2(x,y,f,e);
1159}}
1160if(mydata.NData()<=0)
1161 {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl;
1162 return;}
1163if(O.lpg>1) {
1164 mydata.PrintStatus();
1165 mydata.PrintData(0);
1166 mydata.PrintData(mydata.NData()-1);
1167}
1168
1169////////////////////////////////////////////
1170// Identification de la fonction a fitter //
1171////////////////////////////////////////////
1172GeneralFunction* myfunc = NULL;
1173if(func[0]=='p' && ndim==1) {
1174 // Fit de polynome sans passer par les GeneralFit
1175 int degre = 0;
1176 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1177 cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
1178 Poly p1(0);
1179 double c2rl = mydata.PolFit(0,p1,degre);
1180 cout<<"C2r_lineaire = "<<c2rl<<endl;
1181 if(O.lp>0) cout<<p1<<endl;
1182 return;
1183
1184} else if(func[0]=='P' && ndim==1) {
1185 // Fit de polynome
1186 int degre = 0;
1187 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1188 cout<<"Fit polynome 1D de degre "<<degre<<endl;
1189 Polyn1D* myf = new Polyn1D(degre,O.xc);
1190 myfunc = myf;
1191
1192} else if(func[0]=='e' && ndim==1) {
1193 // Fit d'exponentielle
1194 int degre =-1;
1195 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1196 cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
1197 Exp1DPol* myf;
1198 if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc);
1199 else myf = new Exp1DPol(O.xc);
1200 myfunc = myf;
1201
1202} else if(func[0]=='g' && ndim==1) {
1203 // Fit de gaussienne en hauteur
1204 int degre =-1;
1205 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1206 cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
1207 Gauss1DPol* myf;
1208 if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false));
1209 else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); }
1210 myfunc = myf;
1211
1212} else if(func[0]=='G' && ndim==1) {
1213 // Fit de gaussienne en volume
1214 int degre =-1;
1215 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1216 cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
1217 GaussN1DPol* myf;
1218 if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false));
1219 else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); }
1220 myfunc = myf;
1221
1222} else if(func[0]=='p' && ndim==2) {
1223 // Fit de polynome 2D sans passer par les GeneralFit
1224 int degre = 0;
1225 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1226 cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
1227 Poly2 p2(0);
1228 double c2rl = mydata.PolFit(0,1,p2,degre);
1229 cout<<"C2r_lineaire = "<<c2rl<<endl;
1230 if(O.lp>0) cout<<p2<<endl;
1231 return;
1232
1233} else if(func[0]=='P' && ndim==2) {
1234 // Fit de polynome 2D
1235 int degre = 0;
1236 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1237 cout<<"Fit polynome 2D de degre "<<degre<<endl;
1238 Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc);
1239 myfunc = myf;
1240
1241} else if(func[0]=='G' && ndim==2) {
1242 // Fit de gaussienne+fond en volume
1243 int integ = 0;
1244 if(func.length()>1) if(func[1]=='i') integ=1;
1245 cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
1246 if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;}
1247 else {GauRho2D* myf = new GauRho2D; myfunc = myf;}
1248
1249} else if(func[0]=='d' && ndim==2) {
1250 // Fit de DL gaussienne+fond en volume
1251 int integ = 0;
1252 if(func.length()>1) if(func[1]=='i') integ=1;
1253 cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
1254 if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;}
1255 else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;}
1256
1257} else if(func[0]=='D' && ndim==2) {
1258 // Fit de DL gaussienne+fond avec coeff variable p6 en volume
1259 int integ = 0;
1260 if(func.length()>1) if(func[1]=='i') integ=1;
1261 cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
1262 if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;}
1263 else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;}
1264
1265} else if(func[0]=='M' && ndim==2) {
1266 // Fit de Moffat+fond (volume)
1267 int integ = 0;
1268 if(func.length()>1) if(func[1]=='i') integ=1;
1269 cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
1270 if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;}
1271 else {MofRho2D* myf = new MofRho2D; myfunc = myf;}
1272
1273} else {
1274 cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl;
1275 return;
1276}
1277
1278/////////////////////////
1279// Fit avec generalfit //
1280/////////////////////////
1281if(myfunc->NPar()>Par.NElts())
1282 {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl;
1283 if(myfunc) delete myfunc; return;}
1284GeneralFit myfit(myfunc);
1285myfit.SetDebug(O.lpg);
1286myfit.SetData(&mydata);
1287myfit.SetStopChi2(O.stc2);
1288myfit.SetMaxStep(O.nstep);
1289{for(int i=0;i<myfunc->NPar();i++) {
1290 char str[10];
1291 sprintf(str,"P%d",i);
1292 myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i));
1293}}
1294if(O.lp>1) myfit.PrintFit();
1295double c2r = -1.;
1296int rcfit = (double) myfit.Fit();
1297if(O.lp>0) myfit.PrintFit();
1298if(rcfit>0) {
1299 c2r = myfit.GetChi2Red();
1300 cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<" rc="<<rcfit<<endl;
1301 Vector ParFit(myfunc->NPar());
1302 for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i);
1303} else {
1304 cout<<"echec Fit, rc = "<<rcfit<<" nstep="<<myfit.GetNStep()<<endl;
1305 myfit.PrintFitErr(rcfit);
1306}
1307
1308// Mise a disposition des resultats
1309if(rcfit>=0 && myfunc && (O.okres>0||O.okfun>0)) {
1310 string nomres = nom + "res";
1311 string nomfun = nom + "fun";
1312 if(v) {
1313 if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1314 if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1315 } else if(h) {
1316 if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1317 if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1318 } else if(m) {
1319 if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1320 if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1321 } else if(h2) {
1322 if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1323 if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1324 } else if(im) {
1325 if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1326 if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1327 } else if(g) {
1328 if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1329 if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1330 }
1331}
1332
1333// Nettoyage
1334if(myfunc) delete myfunc;
1335return;
1336}
1337
1338
1339/* --Methode-- */
1340void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
1341 string& expy, string& expz, string& expt, string& expcut,
1342 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1343{
1344if (obja == NULL) return;
1345bool adel = true;
1346NTupleInterface* objnt = obja->GetNTupleInterface(adel);
1347if (objnt == NULL) return;
1348string vardec = objnt->VarList_C("_zz6qi_");
1349
1350PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1351if (!f) {
1352 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
1353 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1354 return;
1355 }
1356
1357double xnt[10];
1358float fxnt[10];
1359
1360int i,k;
1361for(i=0; i<10; i++) xnt[i] = 0.;
1362
1363TRY {
1364 double* xn;
1365 for(k=0; k<objnt->NbLines(); k++) {
1366 xn = objnt->GetLineD(k);
1367 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1368 if (nt) {
1369 for(i=0; i<4; i++) fxnt[i] = xnt[i];
1370 nt->Fill(fxnt);
1371 }
1372 if (h1) h1->Add(xnt[0], xnt[3]);
1373 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1374 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1375 }
1376 }
1377 }
1378CATCH(merr) {
1379 fflush(stdout);
1380 cout << endl;
1381 cerr << endl;
1382 string es = PeidaExc(merr);
1383 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1384 } ENDTRY;
1385
1386
1387if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1388// Fermeture du fichier .so
1389CloseDLL();
1390return;
1391}
1392
1393
1394/* --Methode-- */
1395PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1396 string& expz, string& expt, string& cut)
1397{
1398FILE *fip;
1399string fname = TmpDir + "expf_pia_dl.c";
1400string cmd;
1401int rc;
1402
1403cmd = "rm -f " + fname;
1404rc = system(cmd.c_str());
1405//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1406
1407if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1408 string sn = fname;
1409 cout << "Services2NObjMgr/LinkExprFunc_Erreur: Pb. Ouverture " << sn << endl;
1410 return(NULL);
1411 }
1412
1413// constitution du fichier a compiler
1414fputs("#include <stdlib.h> \n", fip);
1415fputs("#include <math.h> \n", fip);
1416
1417fputs("/* ------ Some random number generators --------- */ \n", fip);
1418fputs("#define frand01() ( (float) drand48() ) \n", fip);
1419fputs("#define drand01() drand48() \n", fip);
1420fputs("#define rand01() drand48() \n", fip);
1421fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1422fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1423fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1424fputs("double NorRand(void) \n", fip);
1425fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1426fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1427fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1428fputs(" return(x); \n } \n", fip);
1429fputs("#define GauRand() NorRand() \n", fip);
1430fputs("#define gaurand() NorRand() \n\n", fip);
1431
1432fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
1433fprintf(fip,"%s \n", vardec.c_str());
1434fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1435fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1436fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1437fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1438fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1439fputs("return(1); \n} \n", fip);
1440fclose(fip);
1441string func = "expf_pia_dl_func";
1442return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1443}
1444
1445
1446/* --Methode-- */
1447DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1448{
1449// Le link dynamique
1450CloseDLL();
1451dynlink = PDynLinkMgr::BuildFromCFile(fname);
1452if (dynlink == NULL) {
1453 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1454 return(NULL);
1455 }
1456
1457DlFunction retfunc = dynlink->GetFunction(funcname);
1458if (retfunc == NULL) {
1459 string sn = funcname;
1460 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1461 CloseDLL();
1462 return(NULL);
1463 }
1464else return(retfunc);
1465}
1466
1467/* --Methode-- */
1468void Services2NObjMgr::CloseDLL()
1469{
1470if (dynlink) delete dynlink; dynlink = NULL;
1471}
1472
1473
1474/* --Methode-- */
1475string Services2NObjMgr::FileName2Name(string const & fn)
1476{
1477
1478char fsep[2] = {FILESEP, '\0'};
1479char tsep[2] = {'.', '\0'};
1480size_t p = fn.find_last_of(fsep);
1481size_t l = fn.length();
1482if (p >= l) p = 0;
1483else p++;
1484size_t q = fn.find_first_of(tsep,p);
1485if (q < p) q = l;
1486return(fn.substr(p,q-p));
1487}
1488
1489
1490typedef vector<string> GraTok;
1491
1492/* --Methode-- */
1493int Services2NObjMgr::DecodeDispOption(string& gratt, bool& fgsrgr)
1494{
1495int ropt = Disp_Next;
1496if (!mImgapp) return(ropt);
1497
1498for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1499
1500if (fgsrgr) mImgapp->SaveGraphicAtt();
1501
1502if ( (gratt == "def") || (gratt == "default") ) { // Remise aux valeurs par defaut = non defini
1503 mImgapp->SetColAtt();
1504 mImgapp->SetLineAtt();
1505 mImgapp->SetFontAtt();
1506 mImgapp->SetMarkerAtt();
1507 mImgapp->SetColMapId();
1508 mImgapp->SetZoomAtt();
1509 mImgapp->SetAxesAtt();
1510 mImgapp->SetXYLimits();
1511 mImgapp->UseXYLimits();
1512 return(ropt);
1513 }
1514
1515// On separe en mots separes par des virgules
1516gratt = ","+gratt;
1517size_t p = 0;
1518size_t q = 0;
1519size_t l = gratt.length();
1520string token;
1521
1522GraTok grt;
1523
1524while (q < l) {
1525 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
1526 if (p>=l) break;
1527 q = gratt.find_first_of(" ,",p); // la fin du token;
1528 token = gratt.substr(p,q-p);
1529 grt.push_back(token);
1530 }
1531
1532
1533static GrAttNames::iterator it;
1534
1535int k;
1536bool fgcont = true;
1537fgsrgr = false;
1538
1539for(k=0; k<grt.size(); k++) {
1540// cout << "--DBG--SetGraphicAttributes() " << grt[k] << endl;
1541
1542 // Decodage option affichage (win, next, etc
1543 fgcont = true;
1544 if ( (grt[k] == "win") || (grt[k] == "w") ) ropt = Disp_Win;
1545 else if ( (grt[k] == "same") || (grt[k] == "s") ) ropt = Disp_Same;
1546 else if ( (grt[k] == "stack") || (grt[k] == "st") ) ropt = Disp_Stack;
1547 else fgcont = false;
1548 if (fgcont) continue;
1549
1550 // Utilisation limites X-Y
1551 if ( grt[k] == "xylimits" ) { mImgapp->UseXYLimits(true); fgsrgr = true; continue; }
1552 // Si c'est une couleur
1553 it = GrAcolors.find(grt[k]);
1554 if (it != GrAcolors.end()) { mImgapp->SetColAtt((PIColors)((*it).second.a1)); fgsrgr = true; continue; }
1555 // Si c'est un attribut de lignes
1556 it = GrAlines.find(grt[k]);
1557 if (it != GrAlines.end()) { mImgapp->SetLineAtt((PILineAtt)((*it).second.a1)); fgsrgr = true; continue; }
1558 // Si c'est un attribut de fontes
1559 it = GrAfonts.find(grt[k]);
1560 if (it != GrAfonts.end()) { mImgapp->SetFontAtt((PIFontSize)((*it).second.a2), (PIFontAtt)((*it).second.a1) );
1561 fgsrgr = true; continue; }
1562 // Si c'est un attribut de markers
1563 it = GrAmarkers.find(grt[k]);
1564 if (it != GrAmarkers.end()) { mImgapp->SetMarkerAtt((*it).second.a2, (PIMarker)((*it).second.a1) );
1565 fgsrgr = true; continue; }
1566 // Si c'est un colormap
1567 it = GrAcmap.find(grt[k]);
1568 if (it != GrAcmap.end()) { mImgapp->SetColMapId( (CMapId)((*it).second.a1) ); fgsrgr = true; continue; }
1569 // Si c'est un facteur de zoom
1570 it = GrAzoom.find(grt[k]);
1571 if (it != GrAzoom.end()) { mImgapp->SetZoomAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1572 // Si c'est un attribut d'axe
1573 it = GrAaxes.find(grt[k]);
1574 if (it != GrAaxes.end()) { mImgapp->SetAxesAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1575
1576 }
1577
1578return(ropt);
1579}
1580
1581
1582
1583// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1584// Initialisation des chaines de caracteres designant les attributs graphiques
1585
1586/* --Methode-- */
1587void Services2NObjMgr::InitGrAttNames()
1588{
1589gratt_item gi;
1590// Les couleurs
1591gi.a2 = 0;
1592gi.a1 = PI_NotDefColor;
1593GrAcolors["defcol"] = gi;
1594gi.a1 = PI_Black;
1595GrAcolors["black"] = gi;
1596gi.a1 = PI_White;
1597GrAcolors["white"] = gi;
1598gi.a1 = PI_Grey;
1599GrAcolors["grey"] = gi;
1600gi.a1 = PI_Red;
1601GrAcolors["red"] = gi;
1602gi.a1 = PI_Blue;
1603GrAcolors["blue"] = gi;
1604gi.a1 = PI_Green;
1605GrAcolors["green"] = gi;
1606gi.a1 = PI_Yellow;
1607GrAcolors["yellow"] = gi;
1608gi.a1 = PI_Magenta;
1609GrAcolors["magenta"] = gi;
1610
1611gi.a1 = PI_Cyan;
1612GrAcolors["cyan"] = gi;
1613gi.a1 = PI_Turquoise;
1614GrAcolors["turquoise"] = gi;
1615gi.a1 = PI_NavyBlue;
1616GrAcolors["navyblue"] = gi;
1617gi.a1 = PI_Orange;
1618GrAcolors["orange"] = gi;
1619gi.a1 = PI_SiennaRed;
1620GrAcolors["siennared"] = gi;
1621gi.a1 = PI_Purple;
1622GrAcolors["purple"] = gi;
1623gi.a1 = PI_LimeGreen;
1624GrAcolors["limegreen"] = gi;
1625gi.a1 = PI_Gold;
1626GrAcolors["gold"] = gi;
1627
1628// Les attributs de lignes
1629gi.a2 = 0;
1630gi.a1 = PI_NotDefLineAtt;
1631GrAlines["defline"] = gi;
1632gi.a1 = PI_NormalLine;
1633GrAlines["normalline"] = gi;
1634gi.a1 = PI_ThinLine;
1635GrAlines["thinline"] = gi;
1636gi.a1 = PI_ThickLine;
1637GrAlines["thickline"] = gi;
1638gi.a1 = PI_DashedLine;
1639GrAlines["dashedline"] = gi;
1640gi.a1 = PI_ThinDashedLine;
1641GrAlines["thindashedline"] = gi;
1642gi.a1 = PI_ThickDashedLine;
1643GrAlines["thickdashedline"] = gi;
1644gi.a1 = PI_DottedLine;
1645GrAlines["dottedline"] = gi;
1646gi.a1 = PI_ThinDottedLine;
1647GrAlines["thindottedline"] = gi;
1648gi.a1 = PI_ThickDottedLine;
1649GrAlines["thickdottedline"] = gi;
1650
1651// Les fontes
1652gi.a2 = PI_NotDefFontSize;
1653gi.a1 = PI_NotDefFontAtt;
1654GrAfonts["deffont"] = gi;
1655
1656gi.a2 = PI_NormalSizeFont;
1657gi.a1 = PI_RomanFont;
1658GrAfonts["normalfont"] = gi;
1659gi.a1 = PI_BoldFont;
1660GrAfonts["boldfont"] = gi;
1661gi.a1 = PI_ItalicFont;
1662GrAfonts["italicfont"] = gi;
1663gi.a2 = PI_SmallSizeFont;
1664gi.a1 = PI_RomanFont;
1665GrAfonts["smallfont"] = gi;
1666gi.a1 = PI_BoldFont;
1667GrAfonts["smallboldfont"] = gi;
1668gi.a1 = PI_ItalicFont;
1669GrAfonts["smallitalicfont"] = gi;
1670gi.a2 = PI_BigSizeFont;
1671gi.a1 = PI_RomanFont;
1672GrAfonts["bigfont"] = gi;
1673gi.a1 = PI_BoldFont;
1674GrAfonts["bigboldfont"] = gi;
1675gi.a1 = PI_ItalicFont;
1676GrAfonts["bigitalicfont"] = gi;
1677gi.a2 = PI_HugeSizeFont;
1678gi.a1 = PI_RomanFont;
1679GrAfonts["hugefont"] = gi;
1680gi.a1 = PI_BoldFont;
1681GrAfonts["hugeboldfont"] = gi;
1682gi.a1 = PI_ItalicFont;
1683GrAfonts["hugeitalicfont"] = gi;
1684
1685
1686// Les markers
1687const char* mrkn[11] = { "dotmarker", "plusmarker", "crossmarker",
1688 "circlemarker", "fcirclemarker", "boxmarker", "fboxmarker",
1689 "trianglemarker", "ftrianglemarker", "starmarker", "fstarmarker"};
1690PIMarker mrk[11] = { PI_DotMarker, PI_PlusMarker, PI_CrossMarker,
1691 PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,
1692 PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker};
1693
1694gi.a2 = 0;
1695gi.a1 = PI_NotDefMarker;
1696GrAmarkers["defmarker"] = gi;
1697
1698for(int j=0; j<11; j++) {
1699 string smrk;
1700 char buff[16];
1701 for(int m=1; m<10; m+=2) {
1702 sprintf(buff,"%d",m);
1703 smrk = (string)mrkn[j] + (string)buff;
1704 gi.a1 = mrk[j]; gi.a2 = m;
1705 GrAmarkers[smrk] = gi;
1706 }
1707 }
1708
1709// Les tables de couleurs
1710gi.a2 = 0;
1711gi.a1 = CMAP_OTHER;
1712GrAcmap["defcmap"] = gi;
1713gi.a1 = CMAP_GREY32;
1714GrAcmap["grey32"] = gi;
1715gi.a1 = CMAP_GREYINV32;
1716GrAcmap["greyinv32"] = gi;
1717gi.a1 = CMAP_COLRJ32;
1718GrAcmap["colrj32"] = gi;
1719gi.a1 = CMAP_COLBR32;
1720GrAcmap["colbr32"] = gi;
1721gi.a1 = CMAP_GREY128;
1722GrAcmap["grey128"] = gi;
1723gi.a1 = CMAP_GREYINV128;
1724GrAcmap["greyinv128"] = gi;
1725gi.a1 = CMAP_COLRJ128;
1726GrAcmap["colrj128"] = gi;
1727gi.a1 = CMAP_COLBR128;
1728GrAcmap["colbr128"] = gi;
1729
1730// La valeur de zoom
1731gi.a2 = 0;
1732gi.a1 = 0;
1733GrAzoom["defzoom"] = gi;
1734gi.a1 = 1;
1735GrAzoom["zoomx1"] = gi;
1736gi.a1 = 2;
1737GrAzoom["zoomx2"] = gi;
1738gi.a1 = 3;
1739GrAzoom["zoomx3"] = gi;
1740gi.a1 = 4;
1741GrAzoom["zoomx4"] = gi;
1742gi.a1 = 5;
1743GrAzoom["zoomx5"] = gi;
1744gi.a1 = -2;
1745GrAzoom["zoom/2"] = gi;
1746gi.a1 = -3;
1747GrAzoom["zoom/3"] = gi;
1748gi.a1 = -4;
1749GrAzoom["zoom/4"] = gi;
1750gi.a1 = -5;
1751GrAzoom["zoom/5"] = gi;
1752
1753// Attributs d'axes
1754gi.a2 = 0;
1755gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels);
1756GrAaxes["stdaxes"] = gi;
1757GrAaxes["defaxes"] = gi;
1758GrAaxes["boxaxes"] = gi;
1759gi.a1 = (int)kAxesDflt;
1760GrAaxes["simpleaxes"] = gi;
1761gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels | kGridOn);
1762GrAaxes["boxaxesgrid"] = gi;
1763
1764gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks);
1765GrAaxes["fineaxes"] = gi;
1766 gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks | kGridOn);
1767GrAaxes["grid"] = gi;
1768GrAaxes["fineaxesgrid"] = gi;
1769
1770}
1771
1772
1773// SANS_EVOLPLANCK Attention !
1774#include "pclassids.h"
1775
1776/* --Methode-- */
1777char* Services2NObjMgr::PClassIdToClassName(int cid)
1778{
1779switch (cid) {
1780 case ClassId_Poly1 :
1781 return("Poly1");
1782 case ClassId_Poly2 :
1783 return("Poly2");
1784 case ClassId_Matrix :
1785 return("Matrix");
1786 case ClassId_Vector :
1787 return("Vector");
1788
1789 case ClassId_DVList :
1790 return("DVList");
1791
1792 case ClassId_Histo1D :
1793 return("Histo1D");
1794 case ClassId_Histo2D :
1795 return("Histo2D");
1796 case ClassId_HProf :
1797 return("HProf");
1798 case ClassId_NTuple :
1799 return("NTuple");
1800 case ClassId_GeneralFitData :
1801 return("GeneralFitData");
1802
1803 case ClassId_Image :
1804 return("RzImage");
1805 case ClassId_Image + kuint_1 :
1806 return("ImageU1");
1807 case ClassId_Image + kint_1 :
1808 return("ImageI1");
1809 case ClassId_Image + kuint_2 :
1810 return("ImageU2");
1811 case ClassId_Image + kint_2 :
1812 return("ImageI2");
1813 case ClassId_Image + kuint_4 :
1814 return("ImageU4");
1815 case ClassId_Image + kint_4 :
1816 return("ImageI4");
1817 case ClassId_Image + kr_4 :
1818 return("ImageR4");
1819 case ClassId_Image + kr_8 :
1820 return("ImageR8");
1821
1822 case ClassId_ZFidu :
1823 return("ZFidu");
1824
1825 case ClassId_StarList :
1826 return("StarList");
1827 case ClassId_Transfo :
1828 return("Transfo");
1829 case ClassId_PSF :
1830 return("PSF");
1831
1832
1833// - Ajout objet PPF
1834 default:
1835 return("AnyDataObj");
1836 }
1837}
1838
Note: See TracBrowser for help on using the repository browser.