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