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