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