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