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