1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <ctype.h>
|
---|
4 |
|
---|
5 | #include <iostream.h>
|
---|
6 | #include <string>
|
---|
7 | #include <list>
|
---|
8 | #include <map>
|
---|
9 | #if defined(__KCC__)
|
---|
10 | using std::string ;
|
---|
11 | #include <list.h>
|
---|
12 | #include <map.h>
|
---|
13 | #endif
|
---|
14 |
|
---|
15 | #include "strutil.h"
|
---|
16 | #include "datatypes.h"
|
---|
17 | #include "fitsimage.h"
|
---|
18 |
|
---|
19 | #include "nobjmgr.h"
|
---|
20 | #include "servnobjm.h"
|
---|
21 | #include "pistdimgapp.h"
|
---|
22 |
|
---|
23 | #include "pclassids.h"
|
---|
24 | #include "poly.h"
|
---|
25 | #include "dvlist.h"
|
---|
26 | #include "matrix.h"
|
---|
27 | #include "cvector.h"
|
---|
28 | #include "zfidu.h"
|
---|
29 |
|
---|
30 | #include "fft.h"
|
---|
31 | #include "fct1dfit.h"
|
---|
32 | #include "fct2dfit.h"
|
---|
33 |
|
---|
34 | #include "pimgadapter.h"
|
---|
35 | #include "pipodrw.h"
|
---|
36 |
|
---|
37 | #include "pihisto.h"
|
---|
38 | #include "hisprof.h"
|
---|
39 | #include "pihisto2d.h"
|
---|
40 | #include "pintuple.h"
|
---|
41 | #include "pisurfdr.h"
|
---|
42 | #include "pintup3d.h"
|
---|
43 | #include "pigfd1.h"
|
---|
44 | #include "pigfd2.h"
|
---|
45 |
|
---|
46 | // Si le module StarReco++ a ete compile (Pour les StarList, Transfo, etc ...
|
---|
47 | #ifndef SANS_StarReco
|
---|
48 | #include "pistlist.h"
|
---|
49 | #include "transfo.h"
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | //++
|
---|
53 | // Class NamedObjMgr
|
---|
54 | // Lib PI
|
---|
55 | // include nobjmgr.h
|
---|
56 | //
|
---|
57 | // Cette classe fournit les services nécéssaire àla gestion des objets
|
---|
58 | // (l'ensemble des objets PPersist de PEIDA++) au sein du programme
|
---|
59 | // d'analyse interactive *piapp* . Elle constitue en outre l'interface
|
---|
60 | // entre les fonctions utilisateur et l'application graphique.
|
---|
61 | //--
|
---|
62 | //++
|
---|
63 | // Links Voir aussi
|
---|
64 | // PIStdImgApp
|
---|
65 | // Services2NObjMgr
|
---|
66 | // PIACmd
|
---|
67 | //--
|
---|
68 |
|
---|
69 |
|
---|
70 | // ..................................................................
|
---|
71 | // ...... Gestion des objets nommes, variables globales ............
|
---|
72 | struct nobj_item {
|
---|
73 | PPersist* obj;
|
---|
74 | int num;
|
---|
75 | list<int> wrsid;
|
---|
76 | bool operator==(nobj_item const& b) const
|
---|
77 | { return (this->obj == b.obj); }
|
---|
78 | };
|
---|
79 |
|
---|
80 | typedef map<string, nobj_item, less<string> > NObjList;
|
---|
81 |
|
---|
82 | static NObjList* myObjs;
|
---|
83 | static int fgOInit = 0;
|
---|
84 | static int myNObj = 0;
|
---|
85 | static string* lastobj = NULL;
|
---|
86 |
|
---|
87 | static PIStdImgApp* myImgApp=NULL;
|
---|
88 | static Services2NObjMgr* servnobjm=NULL;
|
---|
89 |
|
---|
90 | static string* TmpDir; // Repertoire pour les compilations / link dynamique
|
---|
91 |
|
---|
92 | //++
|
---|
93 | // Titre Constructeurs
|
---|
94 | //--
|
---|
95 | //++
|
---|
96 | // NamedObjMgr()
|
---|
97 | // Constructeur. Les différents instantiation de la classe "NamedObjMgr"
|
---|
98 | // dans une même application créent des objets qui travaillent sur la même
|
---|
99 | // liste d'objets. Les objets de cette classe ne possedent en effet pas
|
---|
100 | // de variables membres.
|
---|
101 | //--
|
---|
102 |
|
---|
103 | /* --Methode-- */
|
---|
104 | NamedObjMgr::NamedObjMgr()
|
---|
105 | {
|
---|
106 | if (fgOInit == 0) {
|
---|
107 | myObjs = new NObjList;
|
---|
108 | lastobj = new string("");
|
---|
109 | char* varenv;
|
---|
110 | TmpDir = new string("");
|
---|
111 | if ( (varenv=getenv("PEIDA_TMP")) != NULL ) (*TmpDir) = varenv;
|
---|
112 | else if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
|
---|
113 | int l = (*TmpDir).length();
|
---|
114 | if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
|
---|
115 | servnobjm = new Services2NObjMgr(NULL, (*TmpDir));
|
---|
116 | }
|
---|
117 | fgOInit++;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | /* --Methode-- */
|
---|
122 | NamedObjMgr::~NamedObjMgr()
|
---|
123 | {
|
---|
124 | fgOInit--;
|
---|
125 | if (fgOInit == 0) delete myObjs;
|
---|
126 | }
|
---|
127 |
|
---|
128 | //++
|
---|
129 | // Titre Méthodes
|
---|
130 | //--
|
---|
131 | //++
|
---|
132 | // void SetImgApp(PIStdImgApp* app)
|
---|
133 | // Spécifie l'objet "PIStdImgApp" associé.
|
---|
134 | // PIStdImgApp* GetImgApp()
|
---|
135 | // Accès à l'objet "PIStdImgApp" associé.
|
---|
136 | //--
|
---|
137 |
|
---|
138 | /* --Methode-- */
|
---|
139 | void NamedObjMgr::SetImgApp(PIStdImgApp* app)
|
---|
140 | {
|
---|
141 | myImgApp = app;
|
---|
142 | servnobjm->SetImgApp(app);
|
---|
143 | }
|
---|
144 |
|
---|
145 | /* --Methode-- */
|
---|
146 | PIStdImgApp* NamedObjMgr::GetImgApp()
|
---|
147 | {
|
---|
148 | return(myImgApp);
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* --Methode-- */
|
---|
152 | Services2NObjMgr* NamedObjMgr::GetServiceObj()
|
---|
153 | {
|
---|
154 | return(servnobjm);
|
---|
155 | }
|
---|
156 |
|
---|
157 | //++
|
---|
158 | // Titre Gestion de la liste des objets
|
---|
159 | //--
|
---|
160 | //++
|
---|
161 | // void AddObj(PPersist* obj, string& nom)
|
---|
162 | // Ajoute l'objet "obj" à la liste, identifié par "nom".
|
---|
163 | // Si un objet de même nom existe, l'ancien objet est renommé en concaténant
|
---|
164 | // un numéro à son nom.
|
---|
165 | // void DelObj(string const& nom, bool fgd=true)
|
---|
166 | // Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
|
---|
167 | // void DelObjects(string const& patt, bool fgd=true)
|
---|
168 | // Supprime l'ensemble des objets dont le nom correspond au patron "patt".
|
---|
169 | // Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
|
---|
170 | // PPersist* GetObj(string const& nom)
|
---|
171 | // Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
|
---|
172 | // pas dans la liste.
|
---|
173 | // void RenameObj(string const& nom, string& nomnew)
|
---|
174 | // Change le nom d'un objet dans la liste.
|
---|
175 | // string LastObjName()
|
---|
176 | // Renvoie le nom du dernier objet ajouté à la liste
|
---|
177 | //--
|
---|
178 |
|
---|
179 |
|
---|
180 | /* --Methode-- */
|
---|
181 | void NamedObjMgr::AddObj(PPersist* obj, string& nom)
|
---|
182 | {
|
---|
183 |
|
---|
184 | if (obj == NULL) return;
|
---|
185 | // on supprime les blancs de debut et de fin
|
---|
186 | size_t p = nom.find_first_not_of(" ");
|
---|
187 | if(p>nom.length()) {
|
---|
188 | nom = "";
|
---|
189 | } else {
|
---|
190 | nom = nom.substr(p);
|
---|
191 | p = nom.find_first_of(" ");
|
---|
192 | if(p>nom.length()) p=nom.length();
|
---|
193 | nom = nom.substr(0, p);
|
---|
194 | }
|
---|
195 |
|
---|
196 | myNObj++;
|
---|
197 | if (nom.length() < 1) nom = servnobjm->PClassIdToShortClassName(obj->ClassId());
|
---|
198 | NObjList::iterator it = myObjs->find(nom);
|
---|
199 | if (it != myObjs->end()) { // l'objet existe deja
|
---|
200 | char strg[16];
|
---|
201 | sprintf(strg, "%d", myNObj);
|
---|
202 | string nomnew = nom + strg;
|
---|
203 | RenameObj(nom, nomnew);
|
---|
204 | }
|
---|
205 |
|
---|
206 | (*lastobj) = nom;
|
---|
207 | nobj_item no;
|
---|
208 | no.obj = obj;
|
---|
209 | no.num = myNObj;
|
---|
210 | (*myObjs)[(*lastobj)] = no;
|
---|
211 | if (myImgApp) {
|
---|
212 | string str = (*lastobj) + " (T= " + servnobjm->PClassIdToClassName(obj->ClassId()) + ")" ;
|
---|
213 | (myImgApp->ObjMgrW())->AddObj(str.c_str(), myNObj+1000);
|
---|
214 | }
|
---|
215 |
|
---|
216 | cout << "NamedObjMgr::AddObj() Object " << (*lastobj) << " ( "
|
---|
217 | << servnobjm->PClassIdToClassName(obj->ClassId()) << " ) added (Total= " << myObjs->size() << ")" << endl;
|
---|
218 | return;
|
---|
219 | }
|
---|
220 |
|
---|
221 | /* --Methode-- */
|
---|
222 | void NamedObjMgr::DelObj(string const& nom, bool fgd)
|
---|
223 | {
|
---|
224 | NObjList::iterator it = myObjs->find(nom);
|
---|
225 | if (it == myObjs->end()) return;
|
---|
226 | list<int>::iterator ii;
|
---|
227 | if (myImgApp) {
|
---|
228 | //DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
|
---|
229 | for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
|
---|
230 | myImgApp->DelWRsId((*ii));
|
---|
231 | (myImgApp->ObjMgrW())->DelObj((*it).second.num+1000);
|
---|
232 | }
|
---|
233 | if (fgd) delete (*it).second.obj;
|
---|
234 | myObjs->erase(it);
|
---|
235 | if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
|
---|
236 | else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
|
---|
237 | return;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /* --Methode-- */
|
---|
241 | void NamedObjMgr::DelObjects(string const& patt, bool fgd)
|
---|
242 | {
|
---|
243 | NObjList::iterator it;
|
---|
244 | list<string> odel;
|
---|
245 | string cn;
|
---|
246 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
247 | cn = (*it).first;
|
---|
248 | if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
|
---|
249 | }
|
---|
250 | list<string>::iterator ii;
|
---|
251 | for(ii=odel.begin(); ii != odel.end(); ii++) DelObj(*ii, fgd);
|
---|
252 | }
|
---|
253 |
|
---|
254 | /* --Methode-- */
|
---|
255 | PPersist* NamedObjMgr::GetObj(string const& nom)
|
---|
256 | {
|
---|
257 | NObjList::iterator it = myObjs->find(nom);
|
---|
258 | if (it == myObjs->end()) return(NULL);
|
---|
259 | return((*it).second.obj);
|
---|
260 | }
|
---|
261 |
|
---|
262 | /* --Methode-- */
|
---|
263 | void NamedObjMgr::RenameObj(string const& nom, string& nomnew)
|
---|
264 | {
|
---|
265 | PPersist* obj = GetObj(nom);
|
---|
266 | if (obj == NULL) return;
|
---|
267 | DelObj(nom, false);
|
---|
268 | AddObj(obj, nomnew);
|
---|
269 | return;
|
---|
270 | }
|
---|
271 |
|
---|
272 | /* --Methode-- */
|
---|
273 | string NamedObjMgr::LastObjName()
|
---|
274 | {
|
---|
275 | return((*lastobj));
|
---|
276 | }
|
---|
277 |
|
---|
278 | //++
|
---|
279 | // Titre Entrées-Sorties (I/O) sur les objets
|
---|
280 | //--
|
---|
281 | //++
|
---|
282 | // void ReadObj(PInPersist& s, int num=-1)
|
---|
283 | // Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
|
---|
284 | // et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
|
---|
285 | // sur le flot "s" sont créés et ajoutés à la liste.
|
---|
286 | // void ReadObj(string const & nomppf, string nobj="")
|
---|
287 | // Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
|
---|
288 | // à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
|
---|
289 | // composé à partir du nom de fichier.
|
---|
290 | //--
|
---|
291 |
|
---|
292 | /* --Methode-- */
|
---|
293 | void NamedObjMgr::ReadObj(string const & flnm, string nobj)
|
---|
294 | {
|
---|
295 | PPersist* obj=NULL;
|
---|
296 | bool ok = true;
|
---|
297 |
|
---|
298 | TRY{
|
---|
299 | PInPersist pis(flnm);
|
---|
300 | obj = PPersistMgr::ReadObject(pis);
|
---|
301 | if (obj == NULL) ok = false;
|
---|
302 | } CATCH(merr)
|
---|
303 | { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
|
---|
304 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
305 |
|
---|
306 | if (!ok) return;
|
---|
307 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
308 | AddObj(obj, nobj);
|
---|
309 | return;
|
---|
310 | }
|
---|
311 |
|
---|
312 | /* --Methode-- */
|
---|
313 | void NamedObjMgr::ReadObj(PInPersist& s, int num)
|
---|
314 | {
|
---|
315 | int i, cid, key, ln;
|
---|
316 | int n0, n1;
|
---|
317 | bool ok = true;
|
---|
318 | PPersist* obj=NULL;
|
---|
319 | string nom;
|
---|
320 |
|
---|
321 | if ( (s.NbTags() < 1) || (num >= s.NbTags()) ) {
|
---|
322 | if (num >= 0) {
|
---|
323 | printf("NamedObjMgr::ReadObj(PInPersist, %d) Error! NbTags = %d \n", num, s.NbTags());
|
---|
324 | return;
|
---|
325 | }
|
---|
326 | TRY {
|
---|
327 | obj = PPersistMgr::ReadObject(s);
|
---|
328 | if (obj == NULL) ok = false;
|
---|
329 | } CATCH(merr) {
|
---|
330 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
331 | ok = false;
|
---|
332 | } ENDTRY;
|
---|
333 | if (!ok) return;
|
---|
334 | nom = "";
|
---|
335 | AddObj(obj, nom);
|
---|
336 | }
|
---|
337 |
|
---|
338 | if (num < 0) { n0 = 0; n1 = s.NbTags(); }
|
---|
339 | else { n0 = num; n1 = num+1; }
|
---|
340 | for(i=n0; i<n1; i++) {
|
---|
341 | key = s.TagKey(i, cid, ln);
|
---|
342 | if (ln <= 0) nom = "";
|
---|
343 | else nom = s.TagName(i);
|
---|
344 | s.GotoTag(i);
|
---|
345 | TRY {
|
---|
346 | obj = PPersistMgr::ReadObject(s);
|
---|
347 | if (obj == NULL) ok = false;
|
---|
348 | } CATCH(merr) {
|
---|
349 | printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
350 | ok = false;
|
---|
351 | } ENDTRY;
|
---|
352 | if (ok) AddObj(obj, nom);
|
---|
353 | }
|
---|
354 |
|
---|
355 | return;
|
---|
356 | }
|
---|
357 | /* --Methode-- */
|
---|
358 | void NamedObjMgr::ReadAll(string const & flnm)
|
---|
359 | {
|
---|
360 | bool ok = true;
|
---|
361 | PPersist* obj=NULL;
|
---|
362 |
|
---|
363 | PInPersist* ppin;
|
---|
364 | TRY{
|
---|
365 | ppin = new PInPersist(flnm);
|
---|
366 | if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
|
---|
367 | else obj = NULL;
|
---|
368 | } CATCH(merr)
|
---|
369 | { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
|
---|
370 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
371 |
|
---|
372 | if (!ok) return;
|
---|
373 | if (obj) {
|
---|
374 | string nom = servnobjm->FileName2Name(flnm);
|
---|
375 | AddObj(obj, nom);
|
---|
376 | }
|
---|
377 | else ReadObj((*ppin), -1);
|
---|
378 | delete ppin;
|
---|
379 | return;
|
---|
380 | }
|
---|
381 |
|
---|
382 | /* --Methode-- */
|
---|
383 | void NamedObjMgr::ReadFits(string const & flnm, string nobj)
|
---|
384 | {
|
---|
385 | bool ok = true;
|
---|
386 | RzImage* obj;
|
---|
387 |
|
---|
388 | TRY{
|
---|
389 | // obj = RzReadFits((char*)flnm.c_str(), ImgOffX, ImgOffY, ImgSizX, ImgSizY, ImgBitSgn);
|
---|
390 | obj = RzReadFits((char*)flnm.c_str());
|
---|
391 | if (obj == NULL) ok = false;
|
---|
392 | } CATCH(merr) {
|
---|
393 | printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
394 | ok = false;
|
---|
395 | } ENDTRY;
|
---|
396 | if (ok) {
|
---|
397 | if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
|
---|
398 | AddObj((PPersist*)obj, nobj);
|
---|
399 | }
|
---|
400 | return;
|
---|
401 | }
|
---|
402 |
|
---|
403 |
|
---|
404 | static int key_for_write = 5000;
|
---|
405 | /* --Methode-- */
|
---|
406 | void NamedObjMgr::SaveObj(string const& nom, POutPersist& s)
|
---|
407 | {
|
---|
408 | PPersist* obj=NULL;
|
---|
409 | obj = GetObj(nom);
|
---|
410 | if (obj == NULL) return;
|
---|
411 | printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
|
---|
412 | nom.c_str(), servnobjm->PClassIdToClassName(obj->ClassId()));
|
---|
413 | string nm = nom; // A cause de const
|
---|
414 | obj->Write(s, key_for_write, nm);
|
---|
415 | key_for_write++;
|
---|
416 | return;
|
---|
417 | }
|
---|
418 |
|
---|
419 | /* --Methode-- */
|
---|
420 | void NamedObjMgr::SaveAll(string const& flnm)
|
---|
421 | {
|
---|
422 | bool ok = true;
|
---|
423 |
|
---|
424 | POutPersist* pout;
|
---|
425 | TRY{
|
---|
426 | pout = new POutPersist(flnm);
|
---|
427 | } CATCH(merr)
|
---|
428 | { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
|
---|
429 | (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
|
---|
430 | if (!ok) return;
|
---|
431 | NObjList::iterator it;
|
---|
432 | for(it = myObjs->begin(); it != myObjs->end(); it++) SaveObj((*it).first, (*pout));
|
---|
433 | delete pout;
|
---|
434 | return;
|
---|
435 | }
|
---|
436 |
|
---|
437 | /* --Methode-- */
|
---|
438 | void NamedObjMgr::SaveFits(string const& nom, string const & flnm)
|
---|
439 | {
|
---|
440 | PPersist* obj=NULL;
|
---|
441 | obj = GetObj(nom);
|
---|
442 | if (obj == NULL) return;
|
---|
443 |
|
---|
444 | int cid = obj->ClassId();
|
---|
445 | if ( (cid < ClassId_Image) && ( cid > ClassId_Image+kr_8) ) {
|
---|
446 | printf("NamedObjMgr::SaveFits(%s, ) Error - Object is NOT an image (type=%s) \n",
|
---|
447 | nom.c_str(), servnobjm->PClassIdToClassName(obj->ClassId()) );
|
---|
448 | return;
|
---|
449 | }
|
---|
450 |
|
---|
451 | RzImage* pim = (RzImage*)obj;
|
---|
452 | TRY {
|
---|
453 | switch (pim->PixelType()) {
|
---|
454 | case kuint_2:
|
---|
455 | {
|
---|
456 | FitsImageU2 imgfits(*pim);
|
---|
457 | imgfits.Save(flnm);
|
---|
458 | }
|
---|
459 | break;
|
---|
460 | case kint_2:
|
---|
461 | {
|
---|
462 | FitsImageI2 imgfits(*pim);
|
---|
463 | imgfits.Save(flnm);
|
---|
464 | }
|
---|
465 | break;
|
---|
466 | case kint_4:
|
---|
467 | {
|
---|
468 | FitsImageI4 imgfits(*pim);
|
---|
469 | imgfits.Save(flnm);
|
---|
470 | }
|
---|
471 | break;
|
---|
472 | case kr_4:
|
---|
473 | {
|
---|
474 | FitsImageR4 imgfits(*pim);
|
---|
475 | imgfits.Save(flnm);
|
---|
476 | }
|
---|
477 | break;
|
---|
478 | default :
|
---|
479 | printf("NamedObjMgr::SaveObj()/Error Type d'image (%d) NON supporte en FITS \n",
|
---|
480 | (int)pim->PixelType());
|
---|
481 | break;
|
---|
482 | }
|
---|
483 | } CATCH(merr) {
|
---|
484 | printf("NamedObjMgr::SaveObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
|
---|
485 | } ENDTRY;
|
---|
486 |
|
---|
487 | return;
|
---|
488 | }
|
---|
489 |
|
---|
490 |
|
---|
491 | /* --Methode-- */
|
---|
492 | void NamedObjMgr::ListObjs()
|
---|
493 | {
|
---|
494 | int k;
|
---|
495 | PPersist* obj=NULL;
|
---|
496 | string ctyp;
|
---|
497 | char strg[256];
|
---|
498 | int cid;
|
---|
499 |
|
---|
500 | cout << "NamedObjMgr::ListObjs() NObjs= " << myObjs->size() << "\n" ;
|
---|
501 | NObjList::iterator it; k = 0;
|
---|
502 | for(it = myObjs->begin(); it != myObjs->end(); it++) {
|
---|
503 | obj = (*it).second.obj;
|
---|
504 |
|
---|
505 | cid = obj->ClassId();
|
---|
506 | ctyp = servnobjm->PClassIdToClassName(cid);
|
---|
507 | sprintf(strg, "%2d/ %16s : %s", k, servnobjm->PClassIdToClassName(obj->ClassId()), ((*it).first).c_str());
|
---|
508 | ctyp = strg;
|
---|
509 | cout << ctyp << "\n" ;
|
---|
510 | k++;
|
---|
511 | }
|
---|
512 | cout << endl;
|
---|
513 | return;
|
---|
514 | }
|
---|
515 |
|
---|
516 | /* --Methode-- */
|
---|
517 | void NamedObjMgr::PrintObj(string const& nom)
|
---|
518 | {
|
---|
519 | PPersist* obj=GetObj(nom);
|
---|
520 | if (obj == NULL) {
|
---|
521 | cout << "NamedObjMgr::PrintObj() Error , Pas d'objet de nom " << nom << endl;
|
---|
522 | return;
|
---|
523 | }
|
---|
524 |
|
---|
525 | int cid = obj->ClassId();
|
---|
526 | string ctyp = servnobjm->PClassIdToClassName(cid);
|
---|
527 |
|
---|
528 | cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp
|
---|
529 | << "Cid= " << cid << ")" << endl;
|
---|
530 |
|
---|
531 | int i4dum;
|
---|
532 | switch (cid) {
|
---|
533 | case ClassId_Poly1 :
|
---|
534 | ((Poly*)obj)->Print(cout);
|
---|
535 | break;
|
---|
536 | case ClassId_Poly2 :
|
---|
537 | ((Poly2*)obj)->Print(cout);
|
---|
538 | break;
|
---|
539 | case ClassId_Matrix :
|
---|
540 | case ClassId_Vector :
|
---|
541 | cout << *((Matrix*)obj);
|
---|
542 | break;
|
---|
543 |
|
---|
544 | case ClassId_DVList :
|
---|
545 | ((DVList*)obj)->Print();
|
---|
546 | break;
|
---|
547 |
|
---|
548 | case ClassId_Histo1D :
|
---|
549 | ((Histo*)obj)->Print(60);
|
---|
550 | break;
|
---|
551 | case ClassId_Histo2D :
|
---|
552 | ((Histo2D*)obj)->Print();
|
---|
553 | break;
|
---|
554 | case ClassId_HProf :
|
---|
555 | ((HProf*)obj)->Print(60);
|
---|
556 | break;
|
---|
557 | case ClassId_NTuple :
|
---|
558 | cout << ((NTuple*)obj)->Info();
|
---|
559 | cout << *((NTuple*)obj);
|
---|
560 | break;
|
---|
561 | case ClassId_GeneralFitData :
|
---|
562 | ((GeneralFitData*)obj)->PrintStatus();
|
---|
563 | i4dum = ((GeneralFitData*)obj)->NData();
|
---|
564 | if(i4dum>0) {
|
---|
565 | ((GeneralFitData*)obj)->PrintData(0);
|
---|
566 | ((GeneralFitData*)obj)->PrintData(i4dum-1);
|
---|
567 | }
|
---|
568 | break;
|
---|
569 |
|
---|
570 | case ClassId_Image :
|
---|
571 | case ClassId_Image + kuint_1 :
|
---|
572 | case ClassId_Image + kint_1 :
|
---|
573 | case ClassId_Image + kuint_2 :
|
---|
574 | case ClassId_Image + kint_2 :
|
---|
575 | case ClassId_Image + kuint_4 :
|
---|
576 | case ClassId_Image + kint_4 :
|
---|
577 | case ClassId_Image + kr_4 :
|
---|
578 | case ClassId_Image + kr_8 :
|
---|
579 | ((RzImage*)obj)->Print();
|
---|
580 | break;
|
---|
581 |
|
---|
582 | case ClassId_ZFidu :
|
---|
583 | ((ZFidu*)obj)->Print();
|
---|
584 | break;
|
---|
585 |
|
---|
586 | #ifndef SANS_StarReco
|
---|
587 | case ClassId_StarList :
|
---|
588 | ((StarList*)obj)->Print(10, 1, 50);
|
---|
589 | break;
|
---|
590 | case ClassId_Transfo :
|
---|
591 | ((Transfo*)obj)->Print(cout);
|
---|
592 | break;
|
---|
593 | case ClassId_PSF :
|
---|
594 | break;
|
---|
595 |
|
---|
596 | case ClassId_Star + BStar_Type :
|
---|
597 | case ClassId_Star + RzStar_Type :
|
---|
598 | case ClassId_Star + PSFStar_Type :
|
---|
599 | case ClassId_Star + MCStar_Type :
|
---|
600 | case ClassId_Star + CircRFixStar_Type :
|
---|
601 | case ClassId_Star + PSFDHStar_Type :
|
---|
602 | case ClassId_Star + PSFSEStar_Type :
|
---|
603 | case ClassId_Star + MCDHStar_Type :
|
---|
604 | ((BStar*)obj)->Print(1);
|
---|
605 | break;
|
---|
606 | #endif
|
---|
607 |
|
---|
608 | // - Ajout objet PPF
|
---|
609 | default:
|
---|
610 | break;
|
---|
611 | }
|
---|
612 | cout << endl;
|
---|
613 | return;
|
---|
614 | }
|
---|
615 |
|
---|
616 | /* --Methode-- */
|
---|
617 | void NamedObjMgr::DisplayObj(string const& nom, string dopt)
|
---|
618 | {
|
---|
619 | PPersist* obj=GetObj(nom);
|
---|
620 | if (obj == NULL) {
|
---|
621 | cout << "NamedObjMgr::DisplayObj() Error , Pas d'objet de nom " << nom << endl;
|
---|
622 | return;
|
---|
623 | }
|
---|
624 | if (!myImgApp) return;
|
---|
625 |
|
---|
626 | int cid = obj->ClassId();
|
---|
627 | string ctyp = servnobjm->PClassIdToClassName(cid);
|
---|
628 |
|
---|
629 | int wrsid = 0;
|
---|
630 | bool fgsr = true;
|
---|
631 | // On veut tracer une ligne pour vecteur et histo1D par defaut
|
---|
632 | if ( (cid == ClassId_Vector) || (cid == ClassId_Histo1D) ) dopt = "thinline," + dopt;
|
---|
633 | else if(cid == ClassId_HProf) dopt = "fcirclemarker5," + dopt;
|
---|
634 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
635 |
|
---|
636 | switch (cid) {
|
---|
637 | case ClassId_Poly1 :
|
---|
638 | case ClassId_Poly2 :
|
---|
639 | case ClassId_DVList :
|
---|
640 | cout << "NamedObjMgr::DisplayObj() Error , Pas de display pour " << ctyp << endl;
|
---|
641 | break;
|
---|
642 |
|
---|
643 | case ClassId_Matrix :
|
---|
644 | {
|
---|
645 | wrsid = myImgApp->DispImage(new POMatrixAdapter((Matrix*)obj, false), nom, opt);
|
---|
646 | break;
|
---|
647 | }
|
---|
648 | case ClassId_Vector :
|
---|
649 | {
|
---|
650 | PIYfXDrawer* dr = new PIYfXDrawer( new POVectorAdapter((Vector*)obj, false), NULL, true);
|
---|
651 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)dr, nom, opt);
|
---|
652 | break;
|
---|
653 | }
|
---|
654 | case ClassId_Histo1D :
|
---|
655 | {
|
---|
656 | PIHisto* pih = new PIHisto(((Histo*)obj), false);
|
---|
657 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pih, nom, opt);
|
---|
658 | break;
|
---|
659 | }
|
---|
660 | case ClassId_Histo2D :
|
---|
661 | {
|
---|
662 | PIHisto2D* pih2 = new PIHisto2D(((Histo2D*)obj), false);
|
---|
663 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pih2, nom, opt, nom, true);
|
---|
664 | break;
|
---|
665 | }
|
---|
666 | case ClassId_HProf :
|
---|
667 | {
|
---|
668 | PIHisto* pihp = new PIHisto(((Histo*)obj), false);
|
---|
669 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pihp, nom, opt);
|
---|
670 | break;
|
---|
671 | }
|
---|
672 | case ClassId_GeneralFitData :
|
---|
673 | {
|
---|
674 | GeneralFitData* gfd = (GeneralFitData*)obj;
|
---|
675 | if(gfd->NVar()==1) {
|
---|
676 | PIGenFitDat* pigfd = new PIGenFitDat(gfd,false);
|
---|
677 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
|
---|
678 | } else if(gfd->NVar()==2) {
|
---|
679 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(gfd,false);
|
---|
680 | wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);
|
---|
681 | } else {
|
---|
682 | cout<<"NamedObjMgr::DisplayObj() Error , Utilisez DisplayGFD pour GeneralFitData "
|
---|
683 | <<ctyp<<"\n de "<<gfd->NVar()<<" variables (!=1,2)"<<endl;
|
---|
684 | }
|
---|
685 | break;
|
---|
686 | }
|
---|
687 |
|
---|
688 | case ClassId_NTuple :
|
---|
689 | cout << "NamedObjMgr::DisplayObj() Error , Utilisez DisplayNt pour NTuple " << ctyp << endl;
|
---|
690 | break;
|
---|
691 |
|
---|
692 | case ClassId_Image :
|
---|
693 | case ClassId_Image + kuint_1 :
|
---|
694 | case ClassId_Image + kint_1 :
|
---|
695 | case ClassId_Image + kr_8 :
|
---|
696 | case ClassId_Image + kuint_4 :
|
---|
697 | wrsid = myImgApp->DispImage(new RzImageAdapter((RzImage*)obj, false), nom, opt);
|
---|
698 | break;
|
---|
699 | case ClassId_Image + kuint_2 :
|
---|
700 | wrsid = myImgApp->DispImage(new ImageAdapter<uint_2>((ImageU2*)obj, false), nom, opt);
|
---|
701 | break;
|
---|
702 | case ClassId_Image + kint_2 :
|
---|
703 | wrsid = myImgApp->DispImage(new ImageAdapter<int_2>((ImageI2*)obj, false), nom, opt);
|
---|
704 | break;
|
---|
705 | case ClassId_Image + kint_4 :
|
---|
706 | wrsid = myImgApp->DispImage(new ImageAdapter<int_4>((ImageI4*)obj, false), nom, opt);
|
---|
707 | break;
|
---|
708 | case ClassId_Image + kr_4 :
|
---|
709 | wrsid = myImgApp->DispImage(new ImageAdapter<r_4>((ImageR4*)obj, false), nom, opt);
|
---|
710 | break;
|
---|
711 |
|
---|
712 | case ClassId_ZFidu :
|
---|
713 | {
|
---|
714 | int nx = ((ZFidu*)obj)->XMax() - ((ZFidu*)obj)->XMin();
|
---|
715 | int ny = ((ZFidu*)obj)->YMax() - ((ZFidu*)obj)->YMin();
|
---|
716 | if (nx > 1024) nx = 1024;
|
---|
717 | if (ny > 1024) ny = 1024;
|
---|
718 | if (nx < 128) nx = 128;
|
---|
719 | if (ny < 128) nx = 128;
|
---|
720 | ImageU2* msk = ((ZFidu*)obj)->MakeBadZoneMask(nx, ny);
|
---|
721 | myImgApp->DispImage(new ImageAdapter<uint_2>((ImageU2*)msk, true), nom, opt);
|
---|
722 | break;
|
---|
723 | }
|
---|
724 |
|
---|
725 | #ifndef SANS_StarReco
|
---|
726 | case ClassId_StarList :
|
---|
727 | {
|
---|
728 | PIStarList* pist = new PIStarList(((StarList*)obj), false);
|
---|
729 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pist, nom, opt);
|
---|
730 | break;
|
---|
731 | }
|
---|
732 |
|
---|
733 | case ClassId_Transfo :
|
---|
734 | case ClassId_PSF :
|
---|
735 | case ClassId_Star + BStar_Type :
|
---|
736 | case ClassId_Star + RzStar_Type :
|
---|
737 | case ClassId_Star + PSFStar_Type :
|
---|
738 | case ClassId_Star + MCStar_Type :
|
---|
739 | case ClassId_Star + CircRFixStar_Type :
|
---|
740 | case ClassId_Star + PSFDHStar_Type :
|
---|
741 | case ClassId_Star + PSFSEStar_Type :
|
---|
742 | case ClassId_Star + MCDHStar_Type :
|
---|
743 | cout << "NamedObjMgr::DisplayObj() Error , Pas de display pour " << ctyp << endl;
|
---|
744 | break;
|
---|
745 | #endif
|
---|
746 |
|
---|
747 | // - Ajout objet PPF
|
---|
748 | default:
|
---|
749 | break;
|
---|
750 | }
|
---|
751 |
|
---|
752 | if(wrsid != 0) {
|
---|
753 | NObjList::iterator it = myObjs->find(nom);
|
---|
754 | if (it == myObjs->end()) return;
|
---|
755 | (*it).second.wrsid.push_back(wrsid);
|
---|
756 | }
|
---|
757 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
758 | return;
|
---|
759 | }
|
---|
760 |
|
---|
761 |
|
---|
762 | /* --Methode-- */
|
---|
763 | void NamedObjMgr::DisplayNT(string const& nom, string& nmx, string& nmy, string& nmz,
|
---|
764 | string& erx, string& ery, string& erz, string dopt)
|
---|
765 | {
|
---|
766 | PPersist* obj=GetObj(nom);
|
---|
767 | if (obj == NULL) {
|
---|
768 | cout << "NamedObjMgr::DisplayNT() Error , Pas d'objet de nom " << nom << endl;
|
---|
769 | return;
|
---|
770 | }
|
---|
771 | if (!myImgApp) return;
|
---|
772 |
|
---|
773 | int cid = obj->ClassId();
|
---|
774 | if (cid != ClassId_NTuple) {
|
---|
775 | string ctyp = servnobjm->PClassIdToClassName(cid);
|
---|
776 | cout << "NamedObjMgr::DisplayNT() Error , Objet n'est pas un NTuple " << ctyp << endl;
|
---|
777 | return;
|
---|
778 | }
|
---|
779 |
|
---|
780 | int wrsid = 0;
|
---|
781 | bool fgsr = true;
|
---|
782 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
783 |
|
---|
784 | if (nmz.length()>0) { // Display 3D
|
---|
785 | PINTuple3D* pin = new PINTuple3D(((NTuple*)obj), false);
|
---|
786 | pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
|
---|
787 | pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
|
---|
788 | string titre = nmz + "%" + nmy + "%" + nmz;
|
---|
789 | wrsid = myImgApp->Disp3DDrawer(pin, nom, opt, titre);
|
---|
790 | }
|
---|
791 | else {
|
---|
792 | PINTuple* pin = new PINTuple(((NTuple*)obj), false);
|
---|
793 | pin->SelectXY(nmx.c_str(), nmy.c_str());
|
---|
794 | pin->SelectErrBar(erx.c_str(), ery.c_str());
|
---|
795 | string titre = nmy + "%" + nmz;
|
---|
796 | wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre);
|
---|
797 | }
|
---|
798 |
|
---|
799 | if(wrsid >= 0) {
|
---|
800 | NObjList::iterator it = myObjs->find(nom);
|
---|
801 | if (it == myObjs->end()) return;
|
---|
802 | (*it).second.wrsid.push_back(wrsid);
|
---|
803 | }
|
---|
804 |
|
---|
805 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
806 | return;
|
---|
807 | }
|
---|
808 |
|
---|
809 | /* --Methode-- cmv 13/10/98 */
|
---|
810 | void NamedObjMgr::DisplayGFD(string const& nom, string& numvarx, string& numvary, string& err, string dopt)
|
---|
811 | // Pour le display 2D ou 3D d'un ``GeneralFitData''.
|
---|
812 | //| nom = nom de l'objet GeneralFitData a representer.
|
---|
813 | //| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
|
---|
814 | //| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
|
---|
815 | //| Pour le display 2D, numvary="" string vide.
|
---|
816 | //| err = qu'elles erreurs faut il representer ?
|
---|
817 | //| - 2D : x y xy (display y=f(x))
|
---|
818 | //| - 3D : x y z xy xz yz xzy (display z=f(x,y))
|
---|
819 | //| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
|
---|
820 | //| les barres d'erreurs sont representees.
|
---|
821 | //| opt = options generales pour le display.
|
---|
822 | {
|
---|
823 | PPersist* obj=GetObj(nom);
|
---|
824 | if(obj == NULL)
|
---|
825 | {cout << "NamedObjMgr::DisplayGFD() Error , Pas d'objet de nom " << nom << endl;
|
---|
826 | return;}
|
---|
827 | if(!myImgApp) return;
|
---|
828 | int cid = obj->ClassId();
|
---|
829 | if(cid != ClassId_GeneralFitData)
|
---|
830 | {string ctyp = servnobjm->PClassIdToClassName(cid);
|
---|
831 | cout<<"NamedObjMgr::DisplayGFD() Error , Objet n'est pas un GeneralFitData "<<ctyp<<endl;
|
---|
832 | return;}
|
---|
833 |
|
---|
834 | // Decodage des options classiques
|
---|
835 | bool fgsr = true;
|
---|
836 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
837 | // Decodage des erreurs a representer
|
---|
838 | bool errx=false, erry=false, errz=false;
|
---|
839 | if(err.length()>0) {
|
---|
840 | for(int i=0;i<err.length();i++)
|
---|
841 | if (err[i]=='x' || err[i]=='X') errx = true;
|
---|
842 | else if(err[i]=='y' || err[i]=='Y') erry = true;
|
---|
843 | else if(err[i]=='z' || err[i]=='Z') errz = true;
|
---|
844 | }
|
---|
845 | // Decodage des numeros de variables en abscisse
|
---|
846 | int numvx=-1, numvy=-1;
|
---|
847 | if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
|
---|
848 | if(numvary.length()>0) numvy = atoi(numvary.c_str());
|
---|
849 |
|
---|
850 | int wrsid = 0;
|
---|
851 | if(numvy>=0) { // Display 3D
|
---|
852 | PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
|
---|
853 | pigfd->SelectXY(numvx,numvy);
|
---|
854 | pigfd->SelectErrBar(errx,erry,errz);
|
---|
855 | wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);
|
---|
856 | } else { // Display 2D
|
---|
857 | PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
|
---|
858 | pigfd->SelectX(numvx);
|
---|
859 | pigfd->SelectErrBar(errx,erry);
|
---|
860 | wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
|
---|
861 | }
|
---|
862 |
|
---|
863 | if(wrsid >= 0) {
|
---|
864 | NObjList::iterator it = myObjs->find(nom);
|
---|
865 | if (it == myObjs->end()) return;
|
---|
866 | (*it).second.wrsid.push_back(wrsid);
|
---|
867 | }
|
---|
868 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
869 | return;
|
---|
870 | }
|
---|
871 |
|
---|
872 | /* --Methode--
|
---|
873 | void NamedObjMgr::DisplayImage(string const& nom, string dopt)
|
---|
874 | {
|
---|
875 | cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
|
---|
876 | }
|
---|
877 | */
|
---|
878 |
|
---|
879 |
|
---|
880 | /* --Methode-- */
|
---|
881 | void NamedObjMgr::DisplaySurf3D(string const& nom, string dopt)
|
---|
882 | {
|
---|
883 | PPersist* obj=GetObj(nom);
|
---|
884 | if (obj == NULL) {
|
---|
885 | cout << "NamedObjMgr::DisplaySurf3D() Error , Pas d'objet de nom " << nom << endl;
|
---|
886 | return;
|
---|
887 | }
|
---|
888 | if (!myImgApp) return;
|
---|
889 |
|
---|
890 | int cid = obj->ClassId();
|
---|
891 |
|
---|
892 |
|
---|
893 | P2DArrayAdapter* arr=NULL;
|
---|
894 | switch (cid) {
|
---|
895 | case ClassId_Matrix :
|
---|
896 | arr = new POMatrixAdapter((Matrix*)obj, false);
|
---|
897 | break;
|
---|
898 | case ClassId_Histo2D :
|
---|
899 | arr = new POH2DAdapter((Histo2D*)obj, false);
|
---|
900 | break;
|
---|
901 | case ClassId_Image :
|
---|
902 | case ClassId_Image + kuint_1 :
|
---|
903 | case ClassId_Image + kint_1 :
|
---|
904 | case ClassId_Image + kr_8 :
|
---|
905 | case ClassId_Image + kuint_4 :
|
---|
906 | arr = new RzImageAdapter((RzImage*)obj, false);
|
---|
907 | break;
|
---|
908 | case ClassId_Image + kuint_2 :
|
---|
909 | arr = new ImageAdapter<uint_2>((ImageU2*)obj, false);
|
---|
910 | break;
|
---|
911 | case ClassId_Image + kint_2 :
|
---|
912 | arr = new ImageAdapter<int_2>((ImageI2*)obj, false);
|
---|
913 | break;
|
---|
914 | case ClassId_Image + kint_4 :
|
---|
915 | arr = new ImageAdapter<int_4>((ImageI4*)obj, false);
|
---|
916 | break;
|
---|
917 | case ClassId_Image + kr_4 :
|
---|
918 | arr = new ImageAdapter<r_4>((ImageR4*)obj, false);
|
---|
919 | break;
|
---|
920 |
|
---|
921 | default :
|
---|
922 | cout << "NamedObjMgr::DisplaySurf3D() Error , Pas de display pour " << servnobjm->PClassIdToClassName(cid) << endl;
|
---|
923 | return;
|
---|
924 | }
|
---|
925 |
|
---|
926 | if (!arr) return;
|
---|
927 | if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
|
---|
928 | cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
|
---|
929 | << "x" << arr->YSize() << ") trop grand (max=250x250)" << endl;
|
---|
930 | delete arr;
|
---|
931 | return;
|
---|
932 | }
|
---|
933 |
|
---|
934 | int wrsid = 0;
|
---|
935 | bool fgsr = true;
|
---|
936 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
937 | if (cid == ClassId_Histo2D) arr->DefineXYCoordinates(0., 0., 1., 1.);
|
---|
938 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
939 | wrsid = myImgApp->Disp3DDrawer(sdr, nom, opt);
|
---|
940 | if(wrsid >= 0) {
|
---|
941 | NObjList::iterator it = myObjs->find(nom);
|
---|
942 | if (it == myObjs->end()) return;
|
---|
943 | (*it).second.wrsid.push_back(wrsid);
|
---|
944 | }
|
---|
945 |
|
---|
946 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
947 | return;
|
---|
948 | }
|
---|
949 |
|
---|
950 |
|
---|
951 | /* --Methode-- */
|
---|
952 | void NamedObjMgr::SetGraphicAttributes(string gratt)
|
---|
953 | {
|
---|
954 | bool fg = false;
|
---|
955 | servnobjm->DecodeDispOption(gratt, fg);
|
---|
956 | }
|
---|
957 | /* --Methode-- */
|
---|
958 | void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
|
---|
959 | {
|
---|
960 | if (!myImgApp) return;
|
---|
961 | if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
|
---|
962 | else myImgApp->SetZone(nzx, nzy);
|
---|
963 | }
|
---|
964 |
|
---|
965 | /* --Methode-- */
|
---|
966 | void NamedObjMgr::DisplayPoints2D(string const& nom, string& expx, string& expy,
|
---|
967 | string& experrx, string& experry,
|
---|
968 | string& expcut, string dopt)
|
---|
969 | {
|
---|
970 | PPersist* obj=GetObj(nom);
|
---|
971 | if (obj == NULL) {
|
---|
972 | cout << "NamedObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl;
|
---|
973 | return;
|
---|
974 | }
|
---|
975 | if (!myImgApp) return;
|
---|
976 |
|
---|
977 | // Creation NTuple
|
---|
978 | char* ntn[4] = {"expx","expy","expex","expey",};
|
---|
979 | NTuple* nt = NULL;
|
---|
980 | bool haserr = false;
|
---|
981 |
|
---|
982 | if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(2, ntn); }
|
---|
983 | else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
|
---|
984 |
|
---|
985 | servnobjm->Nobj_ComputeExpressions(obj, expx, expy, experrx, experry, expcut, nt, NULL, NULL);
|
---|
986 |
|
---|
987 | if (nt->NEntry() < 1) {
|
---|
988 | cout << "NamedObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
|
---|
989 | delete nt;
|
---|
990 | return;
|
---|
991 | }
|
---|
992 |
|
---|
993 | // nt->Show();
|
---|
994 | // nt->Print(0,10);
|
---|
995 | PINTuple* pin = new PINTuple(nt, true);
|
---|
996 | pin->SelectXY(ntn[0], ntn[1]);
|
---|
997 | if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
|
---|
998 |
|
---|
999 | bool fgsr = true;
|
---|
1000 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
1001 | string titre = nom + ":" + expy + "%" + expx;
|
---|
1002 | myImgApp->DispScDrawer( (PIDrawer*)pin, titre, opt);
|
---|
1003 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
1004 | return;
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | /* --Methode-- */
|
---|
1008 | void NamedObjMgr::DisplayPoints3D(string const& nom, string& expx, string& expy, string& expz,
|
---|
1009 | string& expcut, string dopt)
|
---|
1010 | {
|
---|
1011 | PPersist* obj=GetObj(nom);
|
---|
1012 | if (obj == NULL) {
|
---|
1013 | cout << "NamedObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl;
|
---|
1014 | return;
|
---|
1015 | }
|
---|
1016 | if (!myImgApp) return;
|
---|
1017 |
|
---|
1018 | char* ntn[3] = {"expx","expy","expz"};
|
---|
1019 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
1020 |
|
---|
1021 | string expwt = "1.";
|
---|
1022 | servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expz, expwt, expcut, nt, NULL, NULL);
|
---|
1023 |
|
---|
1024 | if (nt->NEntry() < 1) {
|
---|
1025 | cout << "NamedObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
|
---|
1026 | delete nt;
|
---|
1027 | return;
|
---|
1028 | }
|
---|
1029 | nt->Show();
|
---|
1030 | nt->Print(0,10);
|
---|
1031 | PINTuple3D* pin = new PINTuple3D(nt, true);
|
---|
1032 | pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
|
---|
1033 | bool fgsr = true;
|
---|
1034 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
1035 |
|
---|
1036 | // Pour plot a partir de DispScDrawer
|
---|
1037 | // string nomdisp = "_NT3D_";
|
---|
1038 | // myImgApp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
|
---|
1039 | // Pour plot a partir de Disp3DDrawer
|
---|
1040 | string titre = nom + ":" + expy + "%" + expx;
|
---|
1041 | myImgApp->Disp3DDrawer(pin, titre, opt);
|
---|
1042 |
|
---|
1043 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
1044 | return;
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | /* --Methode-- */
|
---|
1048 | void NamedObjMgr::ProjectH1(string const& nom, string& expx, string& expwt, string& expcut, string& nomh1, string dopt)
|
---|
1049 | {
|
---|
1050 | PPersist* obj=GetObj(nom);
|
---|
1051 |
|
---|
1052 | if (obj == NULL) {
|
---|
1053 | cout << "NamedObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl;
|
---|
1054 | return;
|
---|
1055 | }
|
---|
1056 | if (!myImgApp) return;
|
---|
1057 |
|
---|
1058 | Histo* h1 = NULL;
|
---|
1059 | NTuple* nt = NULL;
|
---|
1060 | PPersist* oh = NULL;
|
---|
1061 | if (nomh1.length() > 0) oh=GetObj(nomh1);
|
---|
1062 | else nomh1 = "H1Proj";
|
---|
1063 | if ( (oh != NULL) && (oh->ClassId() == ClassId_Histo1D) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
|
---|
1064 | else {
|
---|
1065 | char* ntn[2]= {"hxval", "hwt"};
|
---|
1066 | nt = new NTuple(2,ntn); // Creation NTuple
|
---|
1067 | }
|
---|
1068 | string expz = "0.";
|
---|
1069 | servnobjm->Nobj_ComputeExpressions(obj, expx, expwt, expz, expwt, expcut, nt, h1, NULL);
|
---|
1070 |
|
---|
1071 | if ((!h1) && (!nt)) return;
|
---|
1072 | if (!h1) {
|
---|
1073 | if (nt->NEntry() < 1) {
|
---|
1074 | cout << "NamedObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
|
---|
1075 | delete nt;
|
---|
1076 | return;
|
---|
1077 | }
|
---|
1078 | float xmin, xmax;
|
---|
1079 | nt->GetMinMax(0, xmin, xmax);
|
---|
1080 | h1 = new Histo(xmin, xmax, 100);
|
---|
1081 | int k;
|
---|
1082 | float* xn;
|
---|
1083 | for(k=0; k<nt->NEntry(); k++) {
|
---|
1084 | xn = nt->GetVec(k);
|
---|
1085 | h1->Add(xn[0], xn[1]);
|
---|
1086 | }
|
---|
1087 | delete nt;
|
---|
1088 | AddObj(h1, nomh1);
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | DisplayObj(nomh1, dopt);
|
---|
1092 | return;
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | /* --Methode-- */
|
---|
1096 | void NamedObjMgr::ProjectH2(string const& nom, string& expx, string& expy, string& expwt, string& expcut,
|
---|
1097 | string& nomh2, string dopt)
|
---|
1098 | {
|
---|
1099 | PPersist* obj=GetObj(nom);
|
---|
1100 |
|
---|
1101 | if (obj == NULL) {
|
---|
1102 | cout << "NamedObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl;
|
---|
1103 | return;
|
---|
1104 | }
|
---|
1105 | if (!myImgApp) return;
|
---|
1106 |
|
---|
1107 | Histo2D* h2 = NULL;
|
---|
1108 | NTuple* nt = NULL;
|
---|
1109 | PPersist* oh = NULL;
|
---|
1110 | if (nomh2.length() > 0) oh=GetObj(nomh2);
|
---|
1111 | else nomh2 = "H2Proj";
|
---|
1112 | if ( (oh != NULL) && (oh->ClassId() == ClassId_Histo2D) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
|
---|
1113 | else {
|
---|
1114 | char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
1115 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
1116 | }
|
---|
1117 | string expz = "0.";
|
---|
1118 | servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expwt, expwt, expcut, nt, NULL, h2);
|
---|
1119 |
|
---|
1120 | if ((!h2) && (!nt)) return;
|
---|
1121 | if (!h2) {
|
---|
1122 | if (nt->NEntry() < 1) {
|
---|
1123 | cout << "NamedObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
|
---|
1124 | delete nt;
|
---|
1125 | return;
|
---|
1126 | }
|
---|
1127 | float xmin, xmax, ymin, ymax;
|
---|
1128 | nt->GetMinMax(0, xmin, xmax);
|
---|
1129 | nt->GetMinMax(0, ymin, ymax);
|
---|
1130 | h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
|
---|
1131 | int k;
|
---|
1132 | float* xn;
|
---|
1133 | for(k=0; k<nt->NEntry(); k++) {
|
---|
1134 | xn = nt->GetVec(k);
|
---|
1135 | h2->Add(xn[0], xn[1], xn[2]);
|
---|
1136 | }
|
---|
1137 | delete nt;
|
---|
1138 | AddObj(h2, nomh2);
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | DisplayObj(nomh2, dopt);
|
---|
1142 | return;
|
---|
1143 |
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | /* --Methode-- cmv 13/10/98 */
|
---|
1147 | void NamedObjMgr::ProjectHProf(string const& nom, string& expx, string& expy, string& expwt, string& expcut,
|
---|
1148 | string& nomprof, string dopt)
|
---|
1149 | // Pour remplir un ``GeneralFitData'' a partir de divers objets:
|
---|
1150 | //| nom = nom de l'objet a projeter dans un HProf.
|
---|
1151 | //| expx = expression X de definition du bin.
|
---|
1152 | //| expy = expression Y a additionner dans le bin.
|
---|
1153 | //| expwt = expression W du poids a additionner.
|
---|
1154 | //| expcut = expression du test de selection.
|
---|
1155 | //| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
|
---|
1156 | //| les limites Xmin,Xmax sont calculees automatiquement.
|
---|
1157 | //| sinon ce sont celles de l'objet preexistant.
|
---|
1158 | //| opt = options generales pour le display.
|
---|
1159 | {
|
---|
1160 | PPersist* obj=GetObj(nom);
|
---|
1161 |
|
---|
1162 | if (obj == NULL) {
|
---|
1163 | cout << "NamedObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl;
|
---|
1164 | return;
|
---|
1165 | }
|
---|
1166 | if (!myImgApp) return;
|
---|
1167 |
|
---|
1168 | HProf* hprof = NULL;
|
---|
1169 | NTuple* nt = NULL;
|
---|
1170 | PPersist* oh = NULL;
|
---|
1171 | if (nomprof.length() > 0) oh=GetObj(nomprof);
|
---|
1172 | else nomprof = "ProfProj";
|
---|
1173 | if( (oh!=NULL) && (oh->ClassId()== ClassId_HProf) ) hprof = (HProf*)oh;
|
---|
1174 | else {
|
---|
1175 | char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
1176 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
1177 | }
|
---|
1178 | string expz = "0.";
|
---|
1179 | servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof);
|
---|
1180 |
|
---|
1181 | if((!hprof) && (!nt)) return;
|
---|
1182 | if(!hprof) {
|
---|
1183 | if (nt->NEntry() < 1) {
|
---|
1184 | cout << "NamedObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
|
---|
1185 | delete nt;
|
---|
1186 | return;
|
---|
1187 | }
|
---|
1188 | float xmin, xmax;
|
---|
1189 | nt->GetMinMax(0, xmin, xmax);
|
---|
1190 | hprof = new HProf(xmin, xmax, 100);
|
---|
1191 | int k;
|
---|
1192 | float* xn;
|
---|
1193 | for(k=0; k<nt->NEntry(); k++) {
|
---|
1194 | xn = nt->GetVec(k);
|
---|
1195 | hprof->Add(xn[0], xn[1], xn[2]);
|
---|
1196 | }
|
---|
1197 | delete nt;
|
---|
1198 | AddObj(hprof, nomprof);
|
---|
1199 | }
|
---|
1200 | hprof->UpdateHisto();
|
---|
1201 |
|
---|
1202 | DisplayObj(nomprof, dopt);
|
---|
1203 | return;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | /* --Methode-- */
|
---|
1207 | void NamedObjMgr::FillVect(string const& nom, string& expx, string& expcut, string& nomvec, string dopt)
|
---|
1208 | {
|
---|
1209 | PPersist* obj=GetObj(nom);
|
---|
1210 |
|
---|
1211 | if (obj == NULL) {
|
---|
1212 | cout << "NamedObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl;
|
---|
1213 | return;
|
---|
1214 | }
|
---|
1215 | if (!myImgApp) return;
|
---|
1216 |
|
---|
1217 | NTuple* nt = NULL;
|
---|
1218 | if (nomvec.length() < 1) nomvec = "VecFill";
|
---|
1219 |
|
---|
1220 | char* ntn[2]= {"vecval", "vecwt"};
|
---|
1221 | nt = new NTuple(1,ntn); // Creation NTuple
|
---|
1222 |
|
---|
1223 | string expwt = "1.";
|
---|
1224 | string expz = "0.";
|
---|
1225 | servnobjm->Nobj_ComputeExpressions(obj, expx, expz, expz, expwt, expcut, nt, NULL, NULL);
|
---|
1226 |
|
---|
1227 | if (!nt) return;
|
---|
1228 | if (nt->NEntry() < 1) {
|
---|
1229 | cout << "NamedObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
|
---|
1230 | delete nt;
|
---|
1231 | return;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | Vector* vec = new Vector(nt->NEntry());
|
---|
1235 | int k;
|
---|
1236 | float* xn;
|
---|
1237 | for(k=0; k<nt->NEntry(); k++) {
|
---|
1238 | xn = nt->GetVec(k);
|
---|
1239 | (*vec)(k) = xn[0];
|
---|
1240 | }
|
---|
1241 | delete nt;
|
---|
1242 | AddObj(vec, nomvec);
|
---|
1243 | DisplayObj(nomvec, dopt);
|
---|
1244 | return;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | /* --Methode-- */
|
---|
1248 | void NamedObjMgr::FillNT(string const& nom, string& expx, string& expy, string& expz, string& expt,
|
---|
1249 | string& expcut, string& nomnt)
|
---|
1250 | {
|
---|
1251 | PPersist* obj=GetObj(nom);
|
---|
1252 |
|
---|
1253 | if (obj == NULL) {
|
---|
1254 | cout << "NamedObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl;
|
---|
1255 | return;
|
---|
1256 | }
|
---|
1257 | if (!myImgApp) return;
|
---|
1258 |
|
---|
1259 | bool fgnnt = false;
|
---|
1260 | NTuple* nt = NULL;
|
---|
1261 | PPersist* oh = NULL;
|
---|
1262 | if (nomnt.length() > 0) oh=GetObj(nomnt);
|
---|
1263 | else nomnt = "NTFill";
|
---|
1264 | if ( (oh != NULL) && (oh->ClassId() == ClassId_NTuple) ) {
|
---|
1265 | nt = (NTuple*)oh;
|
---|
1266 | if (nt->NVar() > 10) {
|
---|
1267 | cout << "NamedObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
|
---|
1268 | nt = NULL;
|
---|
1269 | }
|
---|
1270 | }
|
---|
1271 | if (nt == NULL) {
|
---|
1272 | char* ntn[4]= {"x", "y","z","t"};
|
---|
1273 | nt = new NTuple(4,ntn); // Creation NTuple
|
---|
1274 | fgnnt = true;
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expz, expt, expcut, nt, NULL, NULL);
|
---|
1278 |
|
---|
1279 | if (fgnnt) AddObj(nt, nomnt);
|
---|
1280 | return;
|
---|
1281 |
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | /* --Methode-- cmv 13/10/98 */
|
---|
1285 | void NamedObjMgr::FillGFD(string const& nom, string& expx, string& expy, string& expz,
|
---|
1286 | string& experr, string& expcut, string& nomgfd)
|
---|
1287 | // Pour remplir un ``GeneralFitData'' a partir de divers objets:
|
---|
1288 | //| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
|
---|
1289 | //| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
|
---|
1290 | //| expx = expression X du GeneralFitData (1er abscisse)
|
---|
1291 | //| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
|
---|
1292 | //| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
|
---|
1293 | //| experr = expression de l'erreur sur l'ordonnee Z
|
---|
1294 | //| expcut = expression du test de selection
|
---|
1295 | //| nomgfd = nom du GeneralFitData engendre (optionnel)
|
---|
1296 | {
|
---|
1297 | PPersist* obj=GetObj(nom);
|
---|
1298 | if(obj == NULL)
|
---|
1299 | {cout<<"NamedObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl;
|
---|
1300 | return;}
|
---|
1301 | if(!myImgApp) return;
|
---|
1302 |
|
---|
1303 | // 2D ou 3D?
|
---|
1304 | int nvar = 2;
|
---|
1305 | if(expy.length()<=0) {nvar = 1; expy = "0.";}
|
---|
1306 |
|
---|
1307 | // Que faut-il copier dans GeneralFitData
|
---|
1308 | int ndata=0;
|
---|
1309 | int cid = obj->ClassId();
|
---|
1310 | switch (cid) {
|
---|
1311 | case ClassId_Vector :
|
---|
1312 | ndata=((Vector*)obj)->NElts();
|
---|
1313 | break;
|
---|
1314 | case ClassId_Matrix :
|
---|
1315 | ndata=((Matrix*)obj)->NCol()*((Matrix*)obj)->NRows();
|
---|
1316 | break;
|
---|
1317 | case ClassId_Histo1D :
|
---|
1318 | case ClassId_HProf :
|
---|
1319 | ndata=((Histo*)obj)->NBins();
|
---|
1320 | break;
|
---|
1321 | case ClassId_Histo2D :
|
---|
1322 | ndata=((Histo2D*)obj)->NBinX()*((Histo2D*)obj)->NBinY();
|
---|
1323 | break;
|
---|
1324 | case ClassId_Image :
|
---|
1325 | case ClassId_Image + kuint_1 :
|
---|
1326 | case ClassId_Image + kint_1 :
|
---|
1327 | case ClassId_Image + kr_8 :
|
---|
1328 | case ClassId_Image + kuint_4 :
|
---|
1329 | case ClassId_Image + kuint_2 :
|
---|
1330 | case ClassId_Image + kint_2 :
|
---|
1331 | case ClassId_Image + kint_4 :
|
---|
1332 | case ClassId_Image + kr_4 :
|
---|
1333 | ndata=((RzImage*)obj)->XSize()*((RzImage*)obj)->YSize();
|
---|
1334 | break;
|
---|
1335 | #ifndef SANS_StarReco
|
---|
1336 | case ClassId_StarList :
|
---|
1337 | ndata=((StarList*)obj)->NbStars();
|
---|
1338 | break;
|
---|
1339 | #endif
|
---|
1340 | case ClassId_NTuple :
|
---|
1341 | ndata=((NTuple*)obj)->NEntry();
|
---|
1342 | break;
|
---|
1343 | case ClassId_GeneralFitData :
|
---|
1344 | ndata=((GeneralFitData*)obj)->NData();
|
---|
1345 | break;
|
---|
1346 | default :
|
---|
1347 | cout<<"FillGFD Erreur: N/A to "<<servnobjm->PClassIdToClassName(cid)<<endl;
|
---|
1348 | return;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | // Nom du GeneralFitData cree.
|
---|
1352 | if (nomgfd.length() <= 0) nomgfd = "GFDFill";
|
---|
1353 | // Consistence ndata.
|
---|
1354 | if(ndata<=0)
|
---|
1355 | {cout<<"NamedObjMgr::FillGFD() Warning ndata="<<ndata<<endl;
|
---|
1356 | return;}
|
---|
1357 |
|
---|
1358 | // Creation NTuple Buffer
|
---|
1359 | char* ntn[4]= {"x","y","f","e"};
|
---|
1360 | NTuple*nt = new NTuple(4,ntn);
|
---|
1361 |
|
---|
1362 | // Remplissage NTuple buffer
|
---|
1363 | servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expz, experr, expcut, nt, NULL, NULL);
|
---|
1364 | if(nt->NEntry() < 1)
|
---|
1365 | {cout<<"NamedObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
|
---|
1366 | delete nt; return;}
|
---|
1367 |
|
---|
1368 | //Remplissage de la structure GeneraFitData
|
---|
1369 | GeneralFitData* gfd = new GeneralFitData(nvar,ndata,0);
|
---|
1370 | int k;
|
---|
1371 | float* xn;
|
---|
1372 | for(k=0; k<nt->NEntry(); k++) {
|
---|
1373 | xn = nt->GetVec(k);
|
---|
1374 | gfd->AddData(xn,xn[2],xn[3]);
|
---|
1375 | }
|
---|
1376 |
|
---|
1377 | // Menage et table d'objets
|
---|
1378 | delete nt;
|
---|
1379 | AddObj(gfd, nomgfd);
|
---|
1380 | return;
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 | /* --Methode-- */
|
---|
1384 | void NamedObjMgr::PlotFunc(string& expfunc, float xmin, float xmax, int np, string dopt)
|
---|
1385 | {
|
---|
1386 | FILE *fip;
|
---|
1387 | string fname = (*TmpDir) + "func1_pia_dl.c";
|
---|
1388 | string fnamer = (*TmpDir) + "func1_pia_dl";
|
---|
1389 | string cmd;
|
---|
1390 | int rc;
|
---|
1391 |
|
---|
1392 | if (!myImgApp) return;
|
---|
1393 |
|
---|
1394 | cmd = "rm " + fname;
|
---|
1395 | rc = system(cmd.c_str());
|
---|
1396 | printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
1397 |
|
---|
1398 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
1399 | string sn = fname;
|
---|
1400 | cout << "NamedObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl;
|
---|
1401 | return;
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | // constitution du fichier a compiler
|
---|
1405 | fputs("#include <math.h> \n", fip);
|
---|
1406 | fputs("double func1_pia_dl_func(double x) \n{\n", fip);
|
---|
1407 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
1408 | fclose(fip);
|
---|
1409 |
|
---|
1410 | DlFunctionOfX f = (DlFunctionOfX) servnobjm->LinkFunctionFromFile(fnamer, "func1_pia_dl_func");
|
---|
1411 | if (!f) return;
|
---|
1412 | PlotFunc(f, xmin, xmax, np, dopt);
|
---|
1413 | servnobjm->CloseDLL();
|
---|
1414 | return;
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | /* --Methode-- */
|
---|
1418 | void NamedObjMgr::PlotFunc2D(string& expfunc, float xmin, float xmax, float ymin, float ymax,
|
---|
1419 | int npx, int npy, string dopt)
|
---|
1420 | {
|
---|
1421 | FILE *fip;
|
---|
1422 | string fname = (*TmpDir) + "func2_pia_dl.c";
|
---|
1423 | string fnamer = (*TmpDir) + "func2_pia_dl";
|
---|
1424 | string cmd;
|
---|
1425 | int rc;
|
---|
1426 |
|
---|
1427 | if (!myImgApp) return;
|
---|
1428 |
|
---|
1429 | cmd = "rm " + fname;
|
---|
1430 | rc = system(cmd.c_str());
|
---|
1431 | printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
1432 |
|
---|
1433 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
1434 | string sn = fname;
|
---|
1435 | cout << "NamedObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl;
|
---|
1436 | return;
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | // constitution du fichier a compiler
|
---|
1440 | fputs("#include <math.h> \n", fip);
|
---|
1441 | fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
|
---|
1442 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
1443 | fclose(fip);
|
---|
1444 |
|
---|
1445 | DlFunctionOfXY f = (DlFunctionOfXY) servnobjm->LinkFunctionFromFile(fnamer, "func2_pia_dl_func");
|
---|
1446 | if (!f) return;
|
---|
1447 | PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt);
|
---|
1448 | servnobjm->CloseDLL();
|
---|
1449 | return;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | /* --Methode-- */
|
---|
1453 | void NamedObjMgr::PlotFunc(DlFunctionOfX f, float xmin, float xmax, int np, string dopt)
|
---|
1454 | {
|
---|
1455 | if (!myImgApp) return;
|
---|
1456 |
|
---|
1457 | int k;
|
---|
1458 | if (np < 1) np = 1;
|
---|
1459 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
1460 | Vector* vpy = new Vector(np);
|
---|
1461 |
|
---|
1462 | double xx;
|
---|
1463 | double dx = (xmax-xmin)/np;
|
---|
1464 | TRY {
|
---|
1465 | for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
|
---|
1466 | } CATCH(merr) {
|
---|
1467 | fflush(stdout);
|
---|
1468 | cout << endl;
|
---|
1469 | cerr << endl;
|
---|
1470 | string es = PeidaExc(merr);
|
---|
1471 | cerr << "NamedObjMgr::PlotFunc() Exception :" << merr << es;
|
---|
1472 | delete vpy;
|
---|
1473 | vpy = NULL;
|
---|
1474 | } ENDTRY;
|
---|
1475 |
|
---|
1476 |
|
---|
1477 | if (vpy) {
|
---|
1478 | string nom = "Func";
|
---|
1479 | AddObj(vpy, nom);
|
---|
1480 | P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
|
---|
1481 | vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
|
---|
1482 | PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
|
---|
1483 | bool fgsr = true;
|
---|
1484 | dopt = "thinline," + dopt;
|
---|
1485 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
1486 | int wrsid = myImgApp->DispScDrawer(dr, nom, opt);
|
---|
1487 | if(wrsid >= 0) {
|
---|
1488 | NObjList::iterator it = myObjs->find(nom);
|
---|
1489 | if (it == myObjs->end()) return;
|
---|
1490 | (*it).second.wrsid.push_back(wrsid);
|
---|
1491 | }
|
---|
1492 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | return;
|
---|
1496 | }
|
---|
1497 |
|
---|
1498 | /* --Methode-- */
|
---|
1499 | void NamedObjMgr::PlotFunc2D(DlFunctionOfXY f, float xmin, float xmax, float ymin, float ymax,
|
---|
1500 | int npx, int npy, string dopt)
|
---|
1501 | {
|
---|
1502 | if (!myImgApp) return;
|
---|
1503 |
|
---|
1504 | if (npx < 1) npx = 1;
|
---|
1505 | if (npy < 1) npy = 1;
|
---|
1506 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
1507 | if (ymax <= ymin) ymax = ymin+1.;
|
---|
1508 |
|
---|
1509 | Matrix* mtx = new Matrix(npy, npx);
|
---|
1510 |
|
---|
1511 | int i,j;
|
---|
1512 | double xx, yy;
|
---|
1513 | double dx = (xmax-xmin)/npx;
|
---|
1514 | double dy = (ymax-ymin)/npy;
|
---|
1515 | // printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
|
---|
1516 | TRY {
|
---|
1517 | for(j=0; j<npy; j++) {
|
---|
1518 | yy = ymin+dy*j;
|
---|
1519 | for(i=0; i<npx; i++) {
|
---|
1520 | xx = xmin+dx*i;
|
---|
1521 | (*mtx)(j, i) = f(xx, yy);
|
---|
1522 | }
|
---|
1523 | }
|
---|
1524 | } CATCH(merr) {
|
---|
1525 | fflush(stdout);
|
---|
1526 | cout << endl;
|
---|
1527 | cerr << endl;
|
---|
1528 | string es = PeidaExc(merr);
|
---|
1529 | cerr << "NamedObjMgr::PlotFunc2D() Exception :" << merr << es;
|
---|
1530 | delete mtx; mtx = NULL;
|
---|
1531 | } ENDTRY;
|
---|
1532 |
|
---|
1533 | if (mtx) {
|
---|
1534 | string nom = "Func2";
|
---|
1535 | AddObj(mtx, nom);
|
---|
1536 | DisplaySurf3D(nom, dopt);
|
---|
1537 | }
|
---|
1538 |
|
---|
1539 | return;
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | ///////////////////// Fit 1D et 2D //////////////////////////
|
---|
1543 | /* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */
|
---|
1544 | struct DFOptions {
|
---|
1545 | int okres, okfun;
|
---|
1546 | int polcx,polcy; double xc,yc;
|
---|
1547 | double err_e, err_E;
|
---|
1548 | double stc2;
|
---|
1549 | int lp,lpg;
|
---|
1550 | int i1,i2,j1,j2;
|
---|
1551 | };
|
---|
1552 | typedef struct DFOptions DFOPTIONS;
|
---|
1553 | static void DecodeFitsOptions(string par,string step,string min,string max,string opt
|
---|
1554 | ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O);
|
---|
1555 | void DecodeFitsOptions(string par,string step,string min,string max,string opt
|
---|
1556 | ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O)
|
---|
1557 | //| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D)
|
---|
1558 | {
|
---|
1559 | // set des vecteurs et decodage des string correspondantes
|
---|
1560 | int NParMax = 100;
|
---|
1561 | Par.Realloc(NParMax); Step.Realloc(NParMax);
|
---|
1562 | Min.Realloc(NParMax); Max.Realloc(NParMax);
|
---|
1563 | {
|
---|
1564 | Vector* v; string* s;
|
---|
1565 | {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}}
|
---|
1566 | for(int j=0;j<4;j++) {
|
---|
1567 | if(j==0) {v=&Par; s=∥}
|
---|
1568 | else if(j==1) {v=&Step; s=&step;}
|
---|
1569 | else if(j==2) {v=&Min; s=&min;}
|
---|
1570 | else if(j==3) {v=&Max; s=&max;}
|
---|
1571 | if(s->length()>0) *s += ",";
|
---|
1572 | for(int i=0;i<NParMax;i++) {
|
---|
1573 | if(s->length()<=0) break;
|
---|
1574 | sscanf(s->c_str(),"%lf",&(*v)(i));
|
---|
1575 | size_t p = s->find_first_of(',') + 1;
|
---|
1576 | if(p>=s->length()) *s = ""; else *s = s->substr(p);
|
---|
1577 | }
|
---|
1578 | }
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | // Decodage de options de opt
|
---|
1582 | O.okres = O.okfun = 0;
|
---|
1583 | O.polcx = O.polcy = 0;
|
---|
1584 | O.xc = O.yc = 0.;
|
---|
1585 | O.stc2 = 1.e-3;
|
---|
1586 | O.err_e = O.err_E = -1.;
|
---|
1587 | O.lp = 1; O.lpg = 0;
|
---|
1588 | O.i1 = O.j1 = O.i2 = O.j2 = -1;
|
---|
1589 |
|
---|
1590 | if(opt.length()<=0) return;
|
---|
1591 | opt = "," + opt + ",";
|
---|
1592 |
|
---|
1593 | if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus
|
---|
1594 | if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee
|
---|
1595 | if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
|
---|
1596 | O.polcx = 2; // Le centrage est calcule automatiquement
|
---|
1597 | size_t p = opt.find(",x");
|
---|
1598 | size_t q = opt.find_first_of(',',p+1);
|
---|
1599 | string dum = opt.substr(p,q-p);
|
---|
1600 | if(dum.length()>2) {
|
---|
1601 | sscanf(dum.c_str(),",x%lf",&O.xc);
|
---|
1602 | O.polcx = 1; // Le centrage est fixe par la valeur lue
|
---|
1603 | }
|
---|
1604 | }
|
---|
1605 | if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
|
---|
1606 | O.polcy = 2; // Le centrage est calcule automatiquement
|
---|
1607 | size_t p = opt.find(",y");
|
---|
1608 | size_t q = opt.find_first_of(',',p+1);
|
---|
1609 | string dum = opt.substr(p,q-p);
|
---|
1610 | if(dum.length()>2) {
|
---|
1611 | sscanf(dum.c_str(),",y%lf",&O.yc);
|
---|
1612 | O.polcy = 1; // Le centrage est fixe par la valeur lue
|
---|
1613 | }
|
---|
1614 | }
|
---|
1615 | if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
|
---|
1616 | size_t p = opt.find(",E");
|
---|
1617 | size_t q = opt.find_first_of(',',p+1);
|
---|
1618 | string dum = opt.substr(p,q-p);
|
---|
1619 | if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E);
|
---|
1620 | if(O.err_E<=0.) O.err_E = 1.;
|
---|
1621 | O.err_e=-1.;
|
---|
1622 | }
|
---|
1623 | if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
|
---|
1624 | size_t p = opt.find(",e");
|
---|
1625 | size_t q = opt.find_first_of(',',p+1);
|
---|
1626 | string dum = opt.substr(p,q-p);
|
---|
1627 | if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e);
|
---|
1628 | if(O.err_e<=0.) O.err_e = 1.;
|
---|
1629 | O.err_E=-1.;
|
---|
1630 | }
|
---|
1631 | if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
|
---|
1632 | size_t p = opt.find(",X");
|
---|
1633 | size_t q = opt.find_first_of(',',p+1);
|
---|
1634 | string dum = opt.substr(p,q-p);
|
---|
1635 | if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2);
|
---|
1636 | if(O.stc2<=0.) O.stc2 = 1.e-3;
|
---|
1637 | }
|
---|
1638 | if(strstr(opt.c_str(),",l")) { // niveau de print
|
---|
1639 | size_t p = opt.find(",l");
|
---|
1640 | size_t q = opt.find_first_of(',',p+1);
|
---|
1641 | string dum = opt.substr(p,q-p);
|
---|
1642 | float ab;
|
---|
1643 | if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
|
---|
1644 | if(ab<0) ab = 0.;
|
---|
1645 | O.lp = (int) ab; O.lpg = (int) 10.*(ab-O.lp);
|
---|
1646 | }
|
---|
1647 | if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
|
---|
1648 | size_t p = opt.find(",I");
|
---|
1649 | size_t q = opt.find_first_of(',',p+1);
|
---|
1650 | string dum = opt.substr(p,q-p);
|
---|
1651 | if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2);
|
---|
1652 | }
|
---|
1653 | if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
|
---|
1654 | size_t p = opt.find(",J");
|
---|
1655 | size_t q = opt.find_first_of(',',p+1);
|
---|
1656 | string dum = opt.substr(p,q-p);
|
---|
1657 | if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2);
|
---|
1658 | }
|
---|
1659 | return;
|
---|
1660 | }
|
---|
1661 |
|
---|
1662 | /* --Methode-- cmv 13/10/98 */
|
---|
1663 | void NamedObjMgr:: Fit12D(string const& nom, string& func,
|
---|
1664 | string par,string step,string min,string max,
|
---|
1665 | string opt)
|
---|
1666 | //| --------------- Fit d'objets a 1 et 2 dimensions ---------------
|
---|
1667 | //| nom : nom de l'objet qui peut etre:
|
---|
1668 | //| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D)
|
---|
1669 | //| fit-2D: Matrix,Histo2D,Imagexx ou GeneraFitData(2D)
|
---|
1670 | //| func : pnn = fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
|
---|
1671 | //| : Pnn = fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
|
---|
1672 | //| : gnn = fit gaussienne (hauteur) + polynome de degre nn 1D
|
---|
1673 | //| : g = fit gaussienne (hauteur) 1D
|
---|
1674 | //| : enn = fit exponentielle + polynome de degre nn 1D
|
---|
1675 | //| : e = fit exponentielle 1D
|
---|
1676 | //| : Gnn = fit gaussienne (volume) + polynome de degre nn 1D
|
---|
1677 | //| : G = fit gaussienne (volume) 1D
|
---|
1678 | //| : = fit gaussienne+fond (volume) 2D
|
---|
1679 | //| : Gi = fit gaussienne+fond integree (volume) 2D
|
---|
1680 | //| : d = fit DL de gaussienne+fond (volume) 2D
|
---|
1681 | //| : di = fit DL de gaussienne+fond integree (volume) 2D
|
---|
1682 | //| : D = fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
|
---|
1683 | //| : Di = fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
|
---|
1684 | //| : M = fit Moffat+fond (expos=p6) (volume) 2D
|
---|
1685 | //| : Mi = fit Moffat+fond integree (expos=p6) (volume) 2D
|
---|
1686 | //| par : p1,...,pn valeur d'initialisation des parametres (def=0)
|
---|
1687 | //| step : s1,...,sn valeur des steps de depart (def=1)
|
---|
1688 | //| min : m1,...,mn valeur des minima (def=1)
|
---|
1689 | //| max : M1,...,Mn valeur des maxima (def=-1) (max<=min : pas de limite)
|
---|
1690 | //| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b"
|
---|
1691 | //| f = generation d'un Objet identique contenant la fonction fittee
|
---|
1692 | //| r = generation d'un Objet identique contenant les residus
|
---|
1693 | //| Xaa.b = aa.b valeur du DXi2 d'arret (def=1.e-3)
|
---|
1694 | //| la.b = niveau "a.b" de print: a=niveau de print Fit1/2D
|
---|
1695 | //| b=niveau de debug GeneralFit
|
---|
1696 | //| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2]
|
---|
1697 | //|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2]
|
---|
1698 | //| - L'erreur est celle associee a l'objet si existe, 1 sinon sauf si
|
---|
1699 | //| E = erreur prise comme la racine de la valeur a fitter
|
---|
1700 | //| Eaa.b = erreur prise aa.b*sqrt(val)
|
---|
1701 | //| e = erreur prise egale a 1 pour toutes les valeurs
|
---|
1702 | //| eaa.b = erreur prise egale a aa.b
|
---|
1703 | //| xaa.b = demande de centrage: on fit x-aa.b au lieu de x)
|
---|
1704 | //| x = demande de centrage: on fit x-xc au lieu de x
|
---|
1705 | //| avec xc=abscisse du milieu de l'histogramme
|
---|
1706 | //| Actif pour: exp+poly 1D, poly 1D
|
---|
1707 | //| gauss+poly 1D (mais xc est le centre de la gaussienne)
|
---|
1708 | //|2D yaa.b et y = idem "xaa.b et x" mais pour y
|
---|
1709 | {
|
---|
1710 | PPersist* obj=GetObj(nom);
|
---|
1711 | if (obj == NULL) {
|
---|
1712 | cout<<"NamedObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl;
|
---|
1713 | return;
|
---|
1714 | }
|
---|
1715 | if (!myImgApp) return;
|
---|
1716 | if(func.length()<=0)
|
---|
1717 | {cout<<"NamedObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl;
|
---|
1718 | return;}
|
---|
1719 | int cid = obj->ClassId();
|
---|
1720 | string ctyp = servnobjm->PClassIdToClassName(cid);
|
---|
1721 |
|
---|
1722 | int ndim = 0, nbinx=0, nbiny=0, ndata = 0;
|
---|
1723 | Vector* v = NULL; Histo* h = NULL;
|
---|
1724 | Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL;
|
---|
1725 | GeneralFitData* g = NULL;
|
---|
1726 | switch (cid) {
|
---|
1727 | // 1D
|
---|
1728 | case ClassId_Vector :
|
---|
1729 | ndim = 1;
|
---|
1730 | v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1;
|
---|
1731 | break;
|
---|
1732 | case ClassId_HProf :
|
---|
1733 | case ClassId_Histo1D :
|
---|
1734 | ndim = 1;
|
---|
1735 | h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1;
|
---|
1736 | break;
|
---|
1737 | // 2D
|
---|
1738 | case ClassId_Matrix :
|
---|
1739 | ndim = 2;
|
---|
1740 | m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows();
|
---|
1741 | break;
|
---|
1742 | case ClassId_Histo2D :
|
---|
1743 | ndim = 2;
|
---|
1744 | h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY();
|
---|
1745 | break;
|
---|
1746 | // 1D ou 2D selon
|
---|
1747 | case ClassId_GeneralFitData :
|
---|
1748 | g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1;
|
---|
1749 | if( g->NVar()==1) ndim = 1;
|
---|
1750 | else if(g->NVar()==2) ndim = 2;
|
---|
1751 | else {
|
---|
1752 | cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
|
---|
1753 | <<((GeneralFitData*) obj)->NVar()<<endl; return;}
|
---|
1754 | break;
|
---|
1755 | case ClassId_Image :
|
---|
1756 | case ClassId_Image + kuint_1 :
|
---|
1757 | case ClassId_Image + kuint_2 :
|
---|
1758 | case ClassId_Image + kint_2 :
|
---|
1759 | case ClassId_Image + kint_4 :
|
---|
1760 | case ClassId_Image + kr_4 :
|
---|
1761 | case ClassId_Image + kr_8 :
|
---|
1762 | ndim = 2;
|
---|
1763 | im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize();
|
---|
1764 | break;
|
---|
1765 | default:
|
---|
1766 | cout<<"NamedObjMgr::Fit12D() Error , Objet n'est pas un "
|
---|
1767 | <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
|
---|
1768 | return;
|
---|
1769 | break;
|
---|
1770 | }
|
---|
1771 | ndata = nbinx*nbiny;
|
---|
1772 | if(ndata<=0)
|
---|
1773 | {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;}
|
---|
1774 |
|
---|
1775 | // Decodage des options et des parametres, mise en forme
|
---|
1776 | Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O;
|
---|
1777 | DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O);
|
---|
1778 | O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1;
|
---|
1779 | O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2;
|
---|
1780 | if(ndim>=2) {
|
---|
1781 | O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1;
|
---|
1782 | O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2;
|
---|
1783 | } else O.j2 = O.j1 = 0;
|
---|
1784 | if(O.polcx==2) {
|
---|
1785 | if(v||m) O.xc = (O.i2-O.i1+1)/2.;
|
---|
1786 | else if(h) O.xc = (h->XMin()+h->XMax())/2.;
|
---|
1787 | else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.;
|
---|
1788 | else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;}
|
---|
1789 | else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;}
|
---|
1790 | }
|
---|
1791 | if(O.polcy==2 && ndim>=2) {
|
---|
1792 | if(m) O.yc = (O.j2-O.j1+1)/2.;
|
---|
1793 | if(h2) O.yc = (h2->YMin()+h2->YMax())/2.;
|
---|
1794 | if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;}
|
---|
1795 | if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;}
|
---|
1796 | }
|
---|
1797 | if(O.lp>0)
|
---|
1798 | cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":"
|
---|
1799 | <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl
|
---|
1800 | <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y"
|
---|
1801 | <<" TypE="<<O.err_e<<","<<O.err_E
|
---|
1802 | <<" StpX2="<<O.stc2
|
---|
1803 | <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl;
|
---|
1804 |
|
---|
1805 | ///////////////////////////////////
|
---|
1806 | // Remplissage de GeneralFitData //
|
---|
1807 | ///////////////////////////////////
|
---|
1808 | GeneralFitData mydata(ndim,ndata,0);
|
---|
1809 | {for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) {
|
---|
1810 | double x,y,f,e;
|
---|
1811 |
|
---|
1812 | if(v)
|
---|
1813 | {x= (double) i; f=(*v)(i); e=1.;}
|
---|
1814 | else if(h)
|
---|
1815 | {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;}
|
---|
1816 | else if(m)
|
---|
1817 | {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;}
|
---|
1818 | else if(h2)
|
---|
1819 | {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
|
---|
1820 | f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;}
|
---|
1821 | else if(im)
|
---|
1822 | {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize();
|
---|
1823 | f=im->DValue(i,j); e=1.;}
|
---|
1824 | else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);}
|
---|
1825 | else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);}
|
---|
1826 | else x=y=f=e=0.;
|
---|
1827 |
|
---|
1828 | // Gestion des erreurs a utiliser
|
---|
1829 | if(O.err_e>0.) e=O.err_e;
|
---|
1830 | else if(O.err_E>0.) {e=(y<-1.||y>1.)?O.err_E*sqrt(fabs(y)):O.err_E;}
|
---|
1831 |
|
---|
1832 | // Remplissage de generalfit
|
---|
1833 | if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;}
|
---|
1834 | if(ndim==1) mydata.AddData1(x,f,e);
|
---|
1835 | else if(ndim==2) mydata.AddData2(x,y,f,e);
|
---|
1836 | }}
|
---|
1837 | if(mydata.NData()<=0)
|
---|
1838 | {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl;
|
---|
1839 | return;}
|
---|
1840 | if(O.lpg>1) {
|
---|
1841 | mydata.PrintStatus();
|
---|
1842 | mydata.PrintData(0);
|
---|
1843 | mydata.PrintData(mydata.NData()-1);
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | ////////////////////////////////////////////
|
---|
1847 | // Identification de la fonction a fitter //
|
---|
1848 | ////////////////////////////////////////////
|
---|
1849 | GeneralFunction* myfunc = NULL;
|
---|
1850 | if(func[0]=='p' && ndim==1) {
|
---|
1851 | // Fit de polynome sans passer par les GeneralFit
|
---|
1852 | int degre = 0;
|
---|
1853 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
1854 | cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
|
---|
1855 | Poly p1(0);
|
---|
1856 | double c2rl = mydata.PolFit(0,p1,degre);
|
---|
1857 | cout<<"C2r_lineaire = "<<c2rl<<endl;
|
---|
1858 | if(O.lp>0) cout<<p1<<endl;
|
---|
1859 | return;
|
---|
1860 |
|
---|
1861 | } else if(func[0]=='P' && ndim==1) {
|
---|
1862 | // Fit de polynome
|
---|
1863 | int degre = 0;
|
---|
1864 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
1865 | cout<<"Fit polynome 1D de degre "<<degre<<endl;
|
---|
1866 | Polyn1D* myf = new Polyn1D(degre,O.xc);
|
---|
1867 | myfunc = myf;
|
---|
1868 |
|
---|
1869 | } else if(func[0]=='e' && ndim==1) {
|
---|
1870 | // Fit d'exponentielle
|
---|
1871 | int degre =-1;
|
---|
1872 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
1873 | cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
|
---|
1874 | Exp1DPol* myf;
|
---|
1875 | if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc);
|
---|
1876 | else myf = new Exp1DPol(O.xc);
|
---|
1877 | myfunc = myf;
|
---|
1878 |
|
---|
1879 | } else if(func[0]=='g' && ndim==1) {
|
---|
1880 | // Fit de gaussienne en hauteur
|
---|
1881 | int degre =-1;
|
---|
1882 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
1883 | cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
|
---|
1884 | Gauss1DPol* myf;
|
---|
1885 | if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false));
|
---|
1886 | else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); }
|
---|
1887 | myfunc = myf;
|
---|
1888 |
|
---|
1889 | } else if(func[0]=='G' && ndim==1) {
|
---|
1890 | // Fit de gaussienne en volume
|
---|
1891 | int degre =-1;
|
---|
1892 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
1893 | cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
|
---|
1894 | GaussN1DPol* myf;
|
---|
1895 | if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false));
|
---|
1896 | else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); }
|
---|
1897 | myfunc = myf;
|
---|
1898 |
|
---|
1899 | } else if(func[0]=='p' && ndim==2) {
|
---|
1900 | // Fit de polynome 2D sans passer par les GeneralFit
|
---|
1901 | int degre = 0;
|
---|
1902 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
1903 | cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
|
---|
1904 | Poly2 p2(0);
|
---|
1905 | double c2rl = mydata.PolFit(0,1,p2,degre);
|
---|
1906 | cout<<"C2r_lineaire = "<<c2rl<<endl;
|
---|
1907 | if(O.lp>0) cout<<p2<<endl;
|
---|
1908 | return;
|
---|
1909 |
|
---|
1910 | } else if(func[0]=='P' && ndim==2) {
|
---|
1911 | // Fit de polynome 2D
|
---|
1912 | int degre = 0;
|
---|
1913 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
1914 | cout<<"Fit polynome 2D de degre "<<degre<<endl;
|
---|
1915 | Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc);
|
---|
1916 | myfunc = myf;
|
---|
1917 |
|
---|
1918 | } else if(func[0]=='G' && ndim==2) {
|
---|
1919 | // Fit de gaussienne+fond en volume
|
---|
1920 | int integ = 0;
|
---|
1921 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
1922 | cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
|
---|
1923 | if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;}
|
---|
1924 | else {GauRho2D* myf = new GauRho2D; myfunc = myf;}
|
---|
1925 |
|
---|
1926 | } else if(func[0]=='d' && ndim==2) {
|
---|
1927 | // Fit de DL gaussienne+fond en volume
|
---|
1928 | int integ = 0;
|
---|
1929 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
1930 | cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
|
---|
1931 | if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;}
|
---|
1932 | else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;}
|
---|
1933 |
|
---|
1934 | } else if(func[0]=='D' && ndim==2) {
|
---|
1935 | // Fit de DL gaussienne+fond avec coeff variable p6 en volume
|
---|
1936 | int integ = 0;
|
---|
1937 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
1938 | cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
|
---|
1939 | if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;}
|
---|
1940 | else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;}
|
---|
1941 |
|
---|
1942 | } else if(func[0]=='M' && ndim==2) {
|
---|
1943 | // Fit de Moffat+fond (volume)
|
---|
1944 | int integ = 0;
|
---|
1945 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
1946 | cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
|
---|
1947 | if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;}
|
---|
1948 | else {MofRho2D* myf = new MofRho2D; myfunc = myf;}
|
---|
1949 |
|
---|
1950 | } else {
|
---|
1951 | cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl;
|
---|
1952 | return;
|
---|
1953 | }
|
---|
1954 |
|
---|
1955 | /////////////////////////
|
---|
1956 | // Fit avec generalfit //
|
---|
1957 | /////////////////////////
|
---|
1958 | if(myfunc->NPar()>Par.NElts())
|
---|
1959 | {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl;
|
---|
1960 | if(myfunc) delete myfunc; return;}
|
---|
1961 | GeneralFit myfit(myfunc);
|
---|
1962 | myfit.SetDebug(O.lpg);
|
---|
1963 | myfit.SetData(&mydata);
|
---|
1964 | myfit.SetStopChi2(O.stc2);
|
---|
1965 | {for(int i=0;i<myfunc->NPar();i++) {
|
---|
1966 | char str[10];
|
---|
1967 | sprintf(str,"P%d",i);
|
---|
1968 | myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i));
|
---|
1969 | }}
|
---|
1970 | if(O.lp>1) myfit.PrintFit();
|
---|
1971 | double c2r = (double) myfit.Fit();
|
---|
1972 | if(O.lp>0) myfit.PrintFit();
|
---|
1973 | if(c2r>0.) {
|
---|
1974 | c2r = myfit.GetChi2Red();
|
---|
1975 | cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl;
|
---|
1976 | Vector ParFit(myfunc->NPar());
|
---|
1977 | for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i);
|
---|
1978 | } else {
|
---|
1979 | cout<<"echec Fit, rc = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl;
|
---|
1980 | }
|
---|
1981 |
|
---|
1982 | // Mise a disposition des resultats
|
---|
1983 | if(c2r>=0. && myfunc && (O.okres>0||O.okfun>0)) {
|
---|
1984 | string nomres = nom + "res";
|
---|
1985 | string nomfun = nom + "fun";
|
---|
1986 | if(v) {
|
---|
1987 | if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
|
---|
1988 | if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
|
---|
1989 | } else if(h) {
|
---|
1990 | if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
|
---|
1991 | if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
|
---|
1992 | } else if(m) {
|
---|
1993 | if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
|
---|
1994 | if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
|
---|
1995 | } else if(h2) {
|
---|
1996 | if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
|
---|
1997 | if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
|
---|
1998 | } else if(im) {
|
---|
1999 | if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
|
---|
2000 | if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
|
---|
2001 | } else if(g) {
|
---|
2002 | if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
|
---|
2003 | if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
|
---|
2004 | }
|
---|
2005 | }
|
---|
2006 |
|
---|
2007 | // Nettoyage
|
---|
2008 | if(myfunc) delete myfunc;
|
---|
2009 | return;
|
---|
2010 | }
|
---|
2011 |
|
---|
2012 | /* --Methode-- */
|
---|
2013 | void NamedObjMgr::FFT(string const& nom, string dopt)
|
---|
2014 | {
|
---|
2015 | PPersist* obj=GetObj(nom);
|
---|
2016 | if (obj == NULL) {
|
---|
2017 | cout << "NamedObjMgr::FFT() Error , Pas d'objet de nom " << nom << endl;
|
---|
2018 | return;
|
---|
2019 | }
|
---|
2020 | if (!myImgApp) return;
|
---|
2021 |
|
---|
2022 | int cid = obj->ClassId();
|
---|
2023 | if (cid != ClassId_Vector) {
|
---|
2024 | string ctyp = servnobjm->PClassIdToClassName(cid);
|
---|
2025 | cout << "NamedObjMgr::FFT() Error , Objet n'est pas un vecteur " << ctyp << endl;
|
---|
2026 | return;
|
---|
2027 | }
|
---|
2028 |
|
---|
2029 | FFT1 fft( *((Vector*)obj) );
|
---|
2030 |
|
---|
2031 | if (fft.NData() < 1) return;
|
---|
2032 |
|
---|
2033 | char* ntn[3] = {"refc", "imfc", "pfc"};
|
---|
2034 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
2035 | Vector* vf = new Vector(fft.NData()/2);
|
---|
2036 |
|
---|
2037 | float xnt[3];
|
---|
2038 | double pf;
|
---|
2039 | for(int k=0; k<fft.NData()/2; k++) {
|
---|
2040 | xnt[0] = fft.ReF(k); xnt[1] = fft.ImF(k);
|
---|
2041 | pf = (xnt[0]*xnt[0]+xnt[1]*xnt[1]);
|
---|
2042 | if (pf >= 0.) pf = sqrt(pf);
|
---|
2043 | xnt[2] = pf; (*vf)(k) = pf;
|
---|
2044 | nt->Fill(xnt);
|
---|
2045 | }
|
---|
2046 |
|
---|
2047 | P1DArrayAdapter* vya = new POVectorAdapter(vf, true);
|
---|
2048 | // vya->DefineXCoordinate(xmin, xmax); a determiner
|
---|
2049 | PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
|
---|
2050 | bool fgsr = true;
|
---|
2051 | dopt = "thinline," + dopt;
|
---|
2052 | int opt = servnobjm->DecodeDispOption(dopt, fgsr);
|
---|
2053 | myImgApp->DispScDrawer(dr, nom, opt);
|
---|
2054 | if (fgsr) myImgApp->RestoreGraphicAtt();
|
---|
2055 |
|
---|
2056 | return;
|
---|
2057 | }
|
---|