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