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