source: Sophya/trunk/SophyaPI/PIext/nobjmgr.cc@ 293

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

Adaptation aux "normes DPC", introduction des classes CmdExecutor, ...
Fenetre d'aide en lignes, gestion de modules, ... Reza 11/05/99

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