[165] | 1 | #include <stdio.h>
|
---|
| 2 | #include <stdlib.h>
|
---|
| 3 | #include <ctype.h>
|
---|
| 4 |
|
---|
[295] | 5 | #include <typeinfo>
|
---|
[165] | 6 | #include <iostream.h>
|
---|
| 7 | #include <string>
|
---|
| 8 | #include <list>
|
---|
| 9 | #include <map>
|
---|
| 10 | #if defined(__KCC__)
|
---|
| 11 | using std::string ;
|
---|
| 12 | #include <list.h>
|
---|
| 13 | #include <map.h>
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
| 16 | #include "strutil.h"
|
---|
| 17 |
|
---|
| 18 | #include "nobjmgr.h"
|
---|
| 19 | #include "servnobjm.h"
|
---|
[330] | 20 | #include "nomgadapter.h"
|
---|
[165] | 21 | #include "pistdimgapp.h"
|
---|
| 22 |
|
---|
[333] | 23 | #include "fct1dfit.h"
|
---|
| 24 | #include "fct2dfit.h"
|
---|
| 25 |
|
---|
| 26 | #include "matrix.h"
|
---|
| 27 | #include "cvector.h"
|
---|
| 28 | #include "ntuple.h"
|
---|
| 29 | #include "cimage.h"
|
---|
| 30 |
|
---|
[165] | 31 | #include "histos.h"
|
---|
| 32 | #include "histos2.h"
|
---|
| 33 | #include "ntuple.h"
|
---|
| 34 | #include "hisprof.h"
|
---|
| 35 |
|
---|
[326] | 36 | #include "piscdrawwdg.h"
|
---|
| 37 | #include "pisurfdr.h"
|
---|
[333] | 38 |
|
---|
| 39 | #include "pintuple.h"
|
---|
| 40 | #include "pintup3d.h"
|
---|
| 41 |
|
---|
[326] | 42 | #include "pipodrw.h"
|
---|
[165] | 43 |
|
---|
| 44 |
|
---|
[326] | 45 |
|
---|
[165] | 46 | /* --Methode-- */
|
---|
[333] | 47 | Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir)
|
---|
[165] | 48 | {
|
---|
| 49 | TmpDir = tmpdir;
|
---|
[171] | 50 | PDynLinkMgr::SetTmpDir(tmpdir);
|
---|
[333] | 51 | mImgapp = NULL;
|
---|
| 52 | mOmg = omg;
|
---|
[171] | 53 | dynlink = NULL;
|
---|
[165] | 54 | InitGrAttNames();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /* --Methode-- */
|
---|
| 58 | Services2NObjMgr::~Services2NObjMgr()
|
---|
| 59 | {
|
---|
| 60 | CloseDLL();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /* --Methode-- */
|
---|
[295] | 64 | void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
|
---|
[165] | 65 | {
|
---|
[295] | 66 | ObjAdaptList::iterator it;
|
---|
| 67 | for(it = objadaplist.begin(); it != objadaplist.end(); it++)
|
---|
| 68 | if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
|
---|
[165] | 69 |
|
---|
[295] | 70 | dataobj_adapter oba;
|
---|
| 71 | oba.obj = o;
|
---|
| 72 | oba.obja = oa;
|
---|
| 73 | objadaplist.push_back(oba);
|
---|
| 74 | }
|
---|
[165] | 75 |
|
---|
[295] | 76 | /* --Methode-- */
|
---|
| 77 | NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
|
---|
| 78 | {
|
---|
| 79 | ObjAdaptList::iterator it;
|
---|
| 80 | for(it = objadaplist.begin(); it != objadaplist.end(); it++)
|
---|
| 81 | if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
|
---|
| 82 | return(new NObjMgrAdapter(o));
|
---|
| 83 | }
|
---|
[165] | 84 |
|
---|
[295] | 85 | /* --Methode-- */
|
---|
[333] | 86 | void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
|
---|
[295] | 87 | {
|
---|
[165] | 88 | FILE *fip;
|
---|
[326] | 89 | string fname = TmpDir + "func1_pia_dl.c";
|
---|
| 90 | string cmd;
|
---|
| 91 | int rc;
|
---|
| 92 |
|
---|
| 93 | if (!mImgapp) return;
|
---|
| 94 |
|
---|
| 95 | cmd = "rm -f " + fname;
|
---|
| 96 | rc = system(cmd.c_str());
|
---|
| 97 | // printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
| 98 |
|
---|
| 99 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
| 100 | string sn = fname;
|
---|
[333] | 101 | cout << "Services2NObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl;
|
---|
[326] | 102 | return;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | // constitution du fichier a compiler
|
---|
| 106 | fputs("#include <math.h> \n", fip);
|
---|
| 107 | fputs("double func1_pia_dl_func(double x) \n{\n", fip);
|
---|
| 108 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
| 109 | fclose(fip);
|
---|
| 110 |
|
---|
| 111 | string func = "func1_pia_dl_func";
|
---|
| 112 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
|
---|
| 113 | if (!f) return;
|
---|
[333] | 114 | PlotFunc(f, nom, xmin, xmax, np, dopt);
|
---|
[326] | 115 | CloseDLL();
|
---|
| 116 | return;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /* --Methode-- */
|
---|
[333] | 120 | void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
|
---|
| 121 | double ymin, double ymax, int npx, int npy, string dopt)
|
---|
[326] | 122 | {
|
---|
| 123 | FILE *fip;
|
---|
| 124 | string fname = TmpDir + "func2_pia_dl.c";
|
---|
| 125 | string cmd;
|
---|
| 126 | int rc;
|
---|
| 127 |
|
---|
| 128 | if (!mImgapp) return;
|
---|
| 129 |
|
---|
| 130 | cmd = "rm " + fname;
|
---|
| 131 | rc = system(cmd.c_str());
|
---|
| 132 | // printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
| 133 |
|
---|
| 134 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
| 135 | string sn = fname;
|
---|
[333] | 136 | cout << "Services2NObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl;
|
---|
[326] | 137 | return;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | // constitution du fichier a compiler
|
---|
| 141 | fputs("#include <math.h> \n", fip);
|
---|
| 142 | fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
|
---|
| 143 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
| 144 | fclose(fip);
|
---|
| 145 |
|
---|
| 146 | string func = "func2_pia_dl_func";
|
---|
| 147 | DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
|
---|
| 148 | if (!f) return;
|
---|
[333] | 149 | PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
|
---|
[326] | 150 | CloseDLL();
|
---|
| 151 | return;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | /* --Methode-- */
|
---|
[333] | 155 | void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
|
---|
| 156 | double xmin, double xmax, int np, string dopt)
|
---|
[326] | 157 | {
|
---|
| 158 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
|
---|
| 159 | if (!f) return;
|
---|
[333] | 160 | PlotFunc(f, nom, xmin, xmax, np, dopt);
|
---|
[326] | 161 | CloseDLL();
|
---|
| 162 | return;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /* --Methode-- */
|
---|
[333] | 166 | void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
|
---|
| 167 | double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
|
---|
[326] | 168 | {
|
---|
| 169 | DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
|
---|
| 170 | if (!f) return;
|
---|
[333] | 171 | PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
|
---|
[326] | 172 | CloseDLL();
|
---|
| 173 | return;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | /* --Methode-- */
|
---|
[333] | 177 | void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
|
---|
[326] | 178 | {
|
---|
| 179 | if (!mImgapp) return;
|
---|
| 180 |
|
---|
| 181 | int k;
|
---|
| 182 | if (np < 1) np = 1;
|
---|
| 183 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
| 184 | Vector* vpy = new Vector(np);
|
---|
| 185 |
|
---|
| 186 | double xx;
|
---|
| 187 | double dx = (xmax-xmin)/np;
|
---|
| 188 | TRY {
|
---|
| 189 | for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
|
---|
| 190 | } CATCH(merr) {
|
---|
| 191 | fflush(stdout);
|
---|
| 192 | cout << endl;
|
---|
| 193 | cerr << endl;
|
---|
| 194 | string es = PeidaExc(merr);
|
---|
| 195 | cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;
|
---|
| 196 | delete vpy;
|
---|
| 197 | vpy = NULL;
|
---|
| 198 | } ENDTRY;
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | if (vpy) {
|
---|
[344] | 202 | string titre;
|
---|
| 203 | if (nom.length() < 1) {
|
---|
| 204 | titre = "Function f(x)";
|
---|
| 205 | nom = "/tmp/func";
|
---|
| 206 | }
|
---|
| 207 | else titre = nom;
|
---|
| 208 |
|
---|
| 209 | P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
|
---|
[326] | 210 | vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
|
---|
| 211 | PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
|
---|
| 212 | bool fgsr = true;
|
---|
| 213 | dopt = "thinline," + dopt;
|
---|
| 214 | int opt = DecodeDispOption(dopt, fgsr);
|
---|
[333] | 215 | int rsid = mImgapp->DispScDrawer(dr, titre, opt);
|
---|
[326] | 216 | if (fgsr) mImgapp->RestoreGraphicAtt();
|
---|
[333] | 217 | if (nom.length() > 0) {
|
---|
| 218 | mOmg->AddObj(vpy, nom);
|
---|
| 219 | mOmg->AddWRsId(nom, rsid);
|
---|
| 220 | }
|
---|
[326] | 221 | }
|
---|
| 222 |
|
---|
| 223 | return;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | /* --Methode-- */
|
---|
[333] | 227 | void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
|
---|
[326] | 228 | int npx, int npy, string dopt)
|
---|
| 229 | {
|
---|
| 230 | if (!mImgapp) return;
|
---|
| 231 |
|
---|
| 232 | if (npx < 3) npx = 3;
|
---|
| 233 | if (npy < 3) npy = 3;
|
---|
| 234 | if (npx > 250) npx = 250;
|
---|
| 235 | if (npy > 250) npy = 250;
|
---|
| 236 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
| 237 | if (ymax <= ymin) ymax = ymin+1.;
|
---|
| 238 |
|
---|
| 239 | Matrix* mtx = new Matrix(npy, npx);
|
---|
| 240 |
|
---|
| 241 | int i,j;
|
---|
| 242 | double xx, yy;
|
---|
| 243 | double dx = (xmax-xmin)/npx;
|
---|
| 244 | double dy = (ymax-ymin)/npy;
|
---|
| 245 | // printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
|
---|
| 246 | TRY {
|
---|
| 247 | for(j=0; j<npy; j++) {
|
---|
| 248 | yy = ymin+dy*j;
|
---|
| 249 | for(i=0; i<npx; i++) {
|
---|
| 250 | xx = xmin+dx*i;
|
---|
| 251 | (*mtx)(j, i) = f(xx, yy);
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 | } CATCH(merr) {
|
---|
| 255 | fflush(stdout);
|
---|
| 256 | cout << endl;
|
---|
| 257 | cerr << endl;
|
---|
| 258 | string es = PeidaExc(merr);
|
---|
| 259 | cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;
|
---|
| 260 | delete mtx; mtx = NULL;
|
---|
| 261 | } ENDTRY;
|
---|
| 262 |
|
---|
| 263 | if (mtx) {
|
---|
[344] | 264 | string titre;
|
---|
| 265 | if (nom.length() < 1) {
|
---|
| 266 | titre = "Function f(x,y)";
|
---|
| 267 | nom = "/tmp/func2d";
|
---|
| 268 | }
|
---|
| 269 | else titre = nom;
|
---|
[326] | 270 | bool fgsr = true;
|
---|
| 271 | int opt = DecodeDispOption(dopt, fgsr);
|
---|
[344] | 272 | P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
|
---|
[326] | 273 | arr->DefineXYCoordinates(xmin, ymin, dx, dy);
|
---|
| 274 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
[333] | 275 | int rsid = mImgapp->Disp3DDrawer(sdr, titre, opt);
|
---|
[326] | 276 | if (fgsr) mImgapp->RestoreGraphicAtt();
|
---|
[333] | 277 | if (nom.length() > 0) {
|
---|
| 278 | mOmg->AddObj(mtx, nom);
|
---|
| 279 | mOmg->AddWRsId(nom, rsid);
|
---|
| 280 | }
|
---|
[326] | 281 | }
|
---|
| 282 |
|
---|
| 283 | return;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | /* --Methode-- */
|
---|
[333] | 287 | void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
|
---|
| 288 | string& experrx, string& experry,
|
---|
| 289 | string& expcut, string dopt)
|
---|
| 290 | {
|
---|
| 291 | NObjMgrAdapter* obja=NULL;
|
---|
| 292 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 293 | if (obja == NULL) {
|
---|
| 294 | cout << "Services2NObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 295 | return;
|
---|
| 296 | }
|
---|
| 297 | if (!mImgapp) return;
|
---|
| 298 |
|
---|
| 299 | // Creation NTuple
|
---|
| 300 | char* ntn[4] = {"expx","expy","expex","expey",};
|
---|
| 301 | NTuple* nt = NULL;
|
---|
| 302 | bool haserr = false;
|
---|
| 303 |
|
---|
| 304 | if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
|
---|
| 305 | else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
|
---|
| 306 |
|
---|
| 307 | ComputeExpressions(obja, expx, expy, experrx, experry, expcut, nt, NULL, NULL);
|
---|
| 308 |
|
---|
| 309 | if (nt->NEntry() < 1) {
|
---|
| 310 | cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
|
---|
| 311 | delete nt;
|
---|
| 312 | return;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | // nt->Show();
|
---|
| 316 | // nt->Print(0,10);
|
---|
| 317 | PINTuple* pin = new PINTuple(nt, true);
|
---|
| 318 | pin->SelectXY(ntn[0], ntn[1]);
|
---|
| 319 | if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
|
---|
| 320 |
|
---|
| 321 | bool fgsr = true;
|
---|
| 322 | dopt = "defline," + dopt;
|
---|
| 323 | int opt = DecodeDispOption(dopt, fgsr);
|
---|
| 324 | string titre = nom + ":" + expy + "%" + expx;
|
---|
| 325 | mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
|
---|
| 326 | if (fgsr) mImgapp->RestoreGraphicAtt();
|
---|
| 327 | return;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | /* --Methode-- */
|
---|
| 331 | void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
|
---|
| 332 | string& expz, string& expcut, string dopt)
|
---|
| 333 | {
|
---|
| 334 | NObjMgrAdapter* obja=NULL;
|
---|
| 335 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 336 | if (obja == NULL) {
|
---|
| 337 | cout << "Services2NObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 338 | return;
|
---|
| 339 | }
|
---|
| 340 | if (!mImgapp) return;
|
---|
| 341 |
|
---|
| 342 | char* ntn[3] = {"expx","expy","expz"};
|
---|
| 343 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
| 344 |
|
---|
| 345 | string expwt = "1.";
|
---|
| 346 | ComputeExpressions(obja, expx, expy, expz, expwt, expcut, nt, NULL, NULL);
|
---|
| 347 |
|
---|
| 348 | if (nt->NEntry() < 1) {
|
---|
| 349 | cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
|
---|
| 350 | delete nt;
|
---|
| 351 | return;
|
---|
| 352 | }
|
---|
| 353 | nt->Show();
|
---|
| 354 | nt->Print(0,10);
|
---|
| 355 | PINTuple3D* pin = new PINTuple3D(nt, true);
|
---|
| 356 | pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
|
---|
| 357 | bool fgsr = true;
|
---|
| 358 | dopt = "defline," + dopt;
|
---|
| 359 | int opt = DecodeDispOption(dopt, fgsr);
|
---|
| 360 |
|
---|
| 361 | // Pour plot a partir de DispScDrawer
|
---|
| 362 | // string nomdisp = "_NT3D_";
|
---|
| 363 | // mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
|
---|
| 364 | // Pour plot a partir de Disp3DDrawer
|
---|
| 365 | string titre = nom + ":" + expy + "%" + expx;
|
---|
| 366 | mImgapp->Disp3DDrawer(pin, titre, opt);
|
---|
| 367 |
|
---|
| 368 | if (fgsr) mImgapp->RestoreGraphicAtt();
|
---|
| 369 | return;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | /* --Methode-- */
|
---|
| 373 | void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
|
---|
| 374 | string& expwt, string& expcut, string dopt)
|
---|
| 375 | {
|
---|
| 376 | NObjMgrAdapter* obja=NULL;
|
---|
| 377 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 378 | if (obja == NULL) {
|
---|
| 379 | cout << "Services2NObjMgr::DisplayPoints2DW() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 380 | return;
|
---|
| 381 | }
|
---|
| 382 | if (!mImgapp) return;
|
---|
| 383 |
|
---|
| 384 | char* ntn[3] = {"expx","expy","expw"};
|
---|
| 385 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
| 386 |
|
---|
| 387 | string exp = "1.";
|
---|
| 388 | ComputeExpressions(obja, expx, expy, expwt, exp, expcut, nt, NULL, NULL);
|
---|
| 389 |
|
---|
| 390 | if (nt->NEntry() < 1) {
|
---|
| 391 | cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
|
---|
| 392 | delete nt;
|
---|
| 393 | return;
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 | PINTuple* pin = new PINTuple(nt, true);
|
---|
| 397 | pin->SelectXY(ntn[0], ntn[1]);
|
---|
| 398 | pin->SelectWt(ntn[2]);
|
---|
| 399 |
|
---|
| 400 | bool fgsr = true;
|
---|
| 401 | int opt = DecodeDispOption(dopt, fgsr);
|
---|
| 402 | string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
|
---|
| 403 | mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
|
---|
| 404 | if (fgsr) mImgapp->RestoreGraphicAtt();
|
---|
| 405 | return;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | /* --Methode-- */
|
---|
| 409 | void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
|
---|
| 410 | string& expcut, string& nomh1, string dopt)
|
---|
| 411 | {
|
---|
| 412 | NObjMgrAdapter* obja=NULL;
|
---|
| 413 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 414 | if (obja == NULL) {
|
---|
| 415 | cout << "Services2NObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 416 | return;
|
---|
| 417 | }
|
---|
| 418 | if (!mImgapp) return;
|
---|
| 419 |
|
---|
| 420 | Histo* h1 = NULL;
|
---|
| 421 | NTuple* nt = NULL;
|
---|
| 422 | AnyDataObj* oh = NULL;
|
---|
| 423 | if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1);
|
---|
| 424 | else nomh1 = "/tmp/projh1d";
|
---|
| 425 | if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
|
---|
| 426 | else {
|
---|
| 427 | char* ntn[2]= {"hxval", "hwt"};
|
---|
| 428 | nt = new NTuple(2,ntn); // Creation NTuple
|
---|
| 429 | }
|
---|
| 430 | string expz = "0.";
|
---|
| 431 | ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, nt, h1, NULL);
|
---|
| 432 |
|
---|
| 433 | if ((!h1) && (!nt)) return;
|
---|
| 434 | if (!h1) {
|
---|
| 435 | if (nt->NEntry() < 1) {
|
---|
| 436 | cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
|
---|
| 437 | delete nt;
|
---|
| 438 | return;
|
---|
| 439 | }
|
---|
| 440 | double xmin, xmax;
|
---|
| 441 | nt->GetMinMax(0, xmin, xmax);
|
---|
| 442 | h1 = new Histo(xmin, xmax, 100);
|
---|
| 443 | int k;
|
---|
| 444 | float* xn;
|
---|
| 445 | for(k=0; k<nt->NEntry(); k++) {
|
---|
| 446 | xn = nt->GetVec(k);
|
---|
| 447 | h1->Add(xn[0], xn[1]);
|
---|
| 448 | }
|
---|
| 449 | delete nt;
|
---|
| 450 | mOmg->AddObj(h1, nomh1);
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 | mOmg->DisplayObj(nomh1, dopt);
|
---|
| 454 | return;
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | /* --Methode-- */
|
---|
| 458 | void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
|
---|
| 459 | string& expcut, string& nomh2, string dopt)
|
---|
| 460 | {
|
---|
| 461 | NObjMgrAdapter* obja=NULL;
|
---|
| 462 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 463 | if (obja == NULL) {
|
---|
| 464 | cout << "Services2NObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 465 | return;
|
---|
| 466 | }
|
---|
| 467 | if (!mImgapp) return;
|
---|
| 468 |
|
---|
| 469 | Histo2D* h2 = NULL;
|
---|
| 470 | NTuple* nt = NULL;
|
---|
| 471 | AnyDataObj* oh = NULL;
|
---|
| 472 | if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2);
|
---|
| 473 | else nomh2 = "/tmp/projh2d";
|
---|
| 474 | if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
|
---|
| 475 | else {
|
---|
| 476 | char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
| 477 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
| 478 | }
|
---|
| 479 | string expz = "0.";
|
---|
| 480 | ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, h2);
|
---|
| 481 |
|
---|
| 482 | if ((!h2) && (!nt)) return;
|
---|
| 483 | if (!h2) {
|
---|
| 484 | if (nt->NEntry() < 1) {
|
---|
| 485 | cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
|
---|
| 486 | delete nt;
|
---|
| 487 | return;
|
---|
| 488 | }
|
---|
| 489 | double xmin, xmax, ymin, ymax;
|
---|
| 490 | nt->GetMinMax(0, xmin, xmax);
|
---|
| 491 | nt->GetMinMax(0, ymin, ymax);
|
---|
| 492 | h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
|
---|
| 493 | int k;
|
---|
| 494 | float* xn;
|
---|
| 495 | for(k=0; k<nt->NEntry(); k++) {
|
---|
| 496 | xn = nt->GetVec(k);
|
---|
| 497 | h2->Add(xn[0], xn[1], xn[2]);
|
---|
| 498 | }
|
---|
| 499 | delete nt;
|
---|
| 500 | mOmg->AddObj(h2, nomh2);
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | mOmg->DisplayObj(nomh2, dopt);
|
---|
| 504 | return;
|
---|
| 505 |
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 | /* --Methode-- cmv 13/10/98 */
|
---|
| 509 | void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
|
---|
| 510 | string& expcut, string& nomprof, string dopt)
|
---|
| 511 | // Pour remplir un ``GeneralFitData'' a partir de divers objets:
|
---|
| 512 | //| nom = nom de l'objet a projeter dans un HProf.
|
---|
| 513 | //| expx = expression X de definition du bin.
|
---|
| 514 | //| expy = expression Y a additionner dans le bin.
|
---|
| 515 | //| expwt = expression W du poids a additionner.
|
---|
| 516 | //| expcut = expression du test de selection.
|
---|
| 517 | //| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
|
---|
| 518 | //| les limites Xmin,Xmax sont calculees automatiquement.
|
---|
| 519 | //| sinon ce sont celles de l'objet preexistant.
|
---|
| 520 | //| opt = options generales pour le display.
|
---|
| 521 | {
|
---|
| 522 | NObjMgrAdapter* obja=NULL;
|
---|
| 523 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 524 | if (obja == NULL) {
|
---|
| 525 | cout << "Services2NObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 526 | return;
|
---|
| 527 | }
|
---|
| 528 | if (!mImgapp) return;
|
---|
| 529 |
|
---|
| 530 | HProf* hprof = NULL;
|
---|
| 531 | NTuple* nt = NULL;
|
---|
| 532 | AnyDataObj* oh = NULL;
|
---|
| 533 | if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof);
|
---|
| 534 | else nomprof = "/tmp/projprof";
|
---|
| 535 | if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
|
---|
| 536 | else {
|
---|
| 537 | char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
| 538 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
| 539 | }
|
---|
| 540 | string expz = "0.";
|
---|
| 541 | ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof);
|
---|
| 542 |
|
---|
| 543 | if((!hprof) && (!nt)) return;
|
---|
| 544 | if(!hprof) {
|
---|
| 545 | if (nt->NEntry() < 1) {
|
---|
| 546 | cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
|
---|
| 547 | delete nt;
|
---|
| 548 | return;
|
---|
| 549 | }
|
---|
| 550 | double xmin, xmax;
|
---|
| 551 | nt->GetMinMax(0, xmin, xmax);
|
---|
| 552 | hprof = new HProf(xmin, xmax, 100);
|
---|
| 553 | int k;
|
---|
| 554 | float* xn;
|
---|
| 555 | for(k=0; k<nt->NEntry(); k++) {
|
---|
| 556 | xn = nt->GetVec(k);
|
---|
| 557 | hprof->Add(xn[0], xn[1], xn[2]);
|
---|
| 558 | }
|
---|
| 559 | delete nt;
|
---|
| 560 | mOmg->AddObj(hprof, nomprof);
|
---|
| 561 | }
|
---|
| 562 | hprof->UpdateHisto();
|
---|
| 563 |
|
---|
| 564 | mOmg->DisplayObj(nomprof, dopt);
|
---|
| 565 | return;
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | /* --Methode-- */
|
---|
| 569 | void Services2NObjMgr::FillVect(string& nom, string& expx, string& expcut,
|
---|
| 570 | string& nomvec, string dopt)
|
---|
| 571 | {
|
---|
| 572 | NObjMgrAdapter* obja=NULL;
|
---|
| 573 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 574 | if (obja == NULL) {
|
---|
| 575 | cout << "Services2NObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 576 | return;
|
---|
| 577 | }
|
---|
| 578 | if (!mImgapp) return;
|
---|
| 579 |
|
---|
| 580 | NTuple* nt = NULL;
|
---|
| 581 | if (nomvec.length() < 1) nomvec = "/tmp/fillvec";
|
---|
| 582 |
|
---|
| 583 | char* ntn[2]= {"vecval", "vecwt"};
|
---|
| 584 | nt = new NTuple(1,ntn); // Creation NTuple
|
---|
| 585 |
|
---|
| 586 | string expwt = "1.";
|
---|
| 587 | string expz = "0.";
|
---|
| 588 | ComputeExpressions(obja, expx, expz, expz, expwt, expcut, nt, NULL, NULL);
|
---|
| 589 |
|
---|
| 590 | if (!nt) return;
|
---|
| 591 | if (nt->NEntry() < 1) {
|
---|
| 592 | cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
|
---|
| 593 | delete nt;
|
---|
| 594 | return;
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | Vector* vec = new Vector(nt->NEntry());
|
---|
| 598 | int k;
|
---|
| 599 | float* xn;
|
---|
| 600 | for(k=0; k<nt->NEntry(); k++) {
|
---|
| 601 | xn = nt->GetVec(k);
|
---|
| 602 | (*vec)(k) = xn[0];
|
---|
| 603 | }
|
---|
| 604 | delete nt;
|
---|
| 605 | mOmg->AddObj(vec, nomvec);
|
---|
| 606 | mOmg->DisplayObj(nomvec, dopt);
|
---|
| 607 | return;
|
---|
| 608 | }
|
---|
| 609 |
|
---|
| 610 | /* --Methode-- */
|
---|
| 611 | void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
|
---|
| 612 | string& expt, string& expcut, string& nomnt)
|
---|
| 613 | {
|
---|
| 614 | NObjMgrAdapter* obja=NULL;
|
---|
| 615 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 616 | if (obja == NULL) {
|
---|
| 617 | cout << "Services2NObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl;
|
---|
| 618 | return;
|
---|
| 619 | }
|
---|
| 620 | if (!mImgapp) return;
|
---|
| 621 |
|
---|
| 622 | bool fgnnt = false;
|
---|
| 623 | NTuple* nt = NULL;
|
---|
| 624 | AnyDataObj* oh = NULL;
|
---|
| 625 | if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
|
---|
| 626 | else nomnt = "/tmp/fillnt";
|
---|
| 627 | if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
|
---|
| 628 | nt = (NTuple*)oh;
|
---|
| 629 | if (nt->NVar() > 10) {
|
---|
| 630 | cout << "Services2NObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
|
---|
| 631 | nt = NULL;
|
---|
| 632 | }
|
---|
| 633 | }
|
---|
| 634 | if (nt == NULL) {
|
---|
| 635 | char* ntn[4]= {"x", "y","z","t"};
|
---|
| 636 | nt = new NTuple(4,ntn); // Creation NTuple
|
---|
| 637 | fgnnt = true;
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | ComputeExpressions(obja, expx, expy, expz, expt, expcut, nt, NULL, NULL);
|
---|
| 641 |
|
---|
| 642 | if (fgnnt) mOmg->AddObj(nt, nomnt);
|
---|
| 643 | return;
|
---|
| 644 |
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | /* --Methode-- */
|
---|
| 648 | void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
|
---|
[344] | 649 | string const & funcname, string & nomnt,
|
---|
| 650 | int nl1, int nl2)
|
---|
[333] | 651 | {
|
---|
| 652 | if (!mImgapp) return;
|
---|
| 653 |
|
---|
| 654 | NObjMgrAdapter* obja=NULL;
|
---|
| 655 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 656 | if (obja == NULL) {
|
---|
| 657 | cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
|
---|
| 658 | return;
|
---|
| 659 | }
|
---|
[344] | 660 | bool adel = true;
|
---|
| 661 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
[333] | 662 | if (objnt == NULL) {
|
---|
| 663 | cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No NTupleInterface !" <<endl;
|
---|
| 664 | return;
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 | NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
|
---|
| 668 | if (!f) {
|
---|
| 669 | cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
|
---|
[344] | 670 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
[333] | 671 | return;
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | bool fgnnt = false;
|
---|
| 675 | NTuple* nt = NULL;
|
---|
| 676 | if (nomnt.length() > 0) {
|
---|
| 677 | AnyDataObj* oh = NULL;
|
---|
| 678 | oh=mOmg->GetObj(nomnt);
|
---|
| 679 | if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
|
---|
| 680 | nt = (NTuple*)oh;
|
---|
| 681 | if (nt->NVar() > 10) {
|
---|
| 682 | cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
|
---|
| 683 | nt = NULL;
|
---|
| 684 | }
|
---|
| 685 | }
|
---|
| 686 | if (nt == NULL) {
|
---|
| 687 | char* ntn[4]= {"x", "y","z","t"};
|
---|
| 688 | nt = new NTuple(4,ntn); // Creation NTuple
|
---|
| 689 | fgnnt = true;
|
---|
| 690 | }
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 | double xnt[10];
|
---|
| 694 | float fxnt[10];
|
---|
| 695 |
|
---|
| 696 | int i,k;
|
---|
| 697 | for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
|
---|
| 698 |
|
---|
| 699 |
|
---|
| 700 | // $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
|
---|
| 701 | // redirige - On redirige la sortie sur le terminal
|
---|
| 702 | bool red = mImgapp->HasRedirectedStdOutErr();
|
---|
| 703 | mImgapp->RedirectStdOutErr(false);
|
---|
| 704 |
|
---|
| 705 | TRY {
|
---|
| 706 | double* xn;
|
---|
[344] | 707 | if (nl1 < 0) nl1 = 0;
|
---|
| 708 | if (nl2 < 0) nl2 = objnt->NbLines();
|
---|
| 709 | if (nl2 > objnt->NbLines()) nl2 = objnt->NbLines();
|
---|
| 710 | int kmax = nl2;
|
---|
| 711 | for(k=nl1; k<kmax; k++) {
|
---|
[333] | 712 | xn = objnt->GetLineD(k);
|
---|
| 713 | if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
|
---|
| 714 | if (nt) {
|
---|
| 715 | for(i=0; i<4; i++) fxnt[i] = xnt[i];
|
---|
| 716 | nt->Fill(fxnt);
|
---|
| 717 | }
|
---|
| 718 | }
|
---|
| 719 | }
|
---|
| 720 | }
|
---|
| 721 | CATCH(merr) {
|
---|
| 722 | fflush(stdout);
|
---|
| 723 | cout << endl;
|
---|
| 724 | cerr << endl;
|
---|
| 725 | string es = PeidaExc(merr);
|
---|
| 726 | cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
|
---|
| 727 | } ENDTRY;
|
---|
[344] | 728 |
|
---|
| 729 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
[333] | 730 | CloseDLL();
|
---|
| 731 |
|
---|
| 732 | // $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
|
---|
| 733 | mImgapp->RedirectStdOutErr(red);
|
---|
| 734 |
|
---|
| 735 | if (fgnnt) mOmg->AddObj(nt, nomnt);
|
---|
| 736 | return;
|
---|
| 737 | }
|
---|
| 738 |
|
---|
| 739 | /* --Methode-- */
|
---|
| 740 | void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
|
---|
| 741 | string const & funcname)
|
---|
| 742 | {
|
---|
| 743 | NObjMgrAdapter* obja=NULL;
|
---|
| 744 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 745 | if (obja == NULL) {
|
---|
| 746 | cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
|
---|
| 747 | return;
|
---|
| 748 | }
|
---|
[344] | 749 | bool adel = true;
|
---|
| 750 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
[333] | 751 | if (objnt == NULL) {
|
---|
| 752 | cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
|
---|
| 753 | << "...) No NTupleInterface !" <<endl;
|
---|
| 754 | return;
|
---|
| 755 | }
|
---|
| 756 | string vardec = objnt->VarList_C("_xnti_");
|
---|
| 757 |
|
---|
| 758 | FILE *fip;
|
---|
| 759 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
| 760 | cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
|
---|
[344] | 761 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
[333] | 762 | return;
|
---|
| 763 | }
|
---|
[344] | 764 |
|
---|
[333] | 765 | // constitution du fichier des decalarations des variables de l'interface NTuple
|
---|
| 766 | fputs("#include <stdlib.h> \n", fip);
|
---|
| 767 | fputs("#include <stdio.h> \n", fip);
|
---|
| 768 | fputs("#include <math.h> \n\n", fip);
|
---|
[344] | 769 |
|
---|
| 770 | fputs("/* ------ Some random number generators --------- */ \n", fip);
|
---|
| 771 | fputs("#define frand01() ( (float) drand48() ) \n", fip);
|
---|
| 772 | fputs("#define drand01() drand48() \n", fip);
|
---|
| 773 | fputs("#define rand01() drand48() \n", fip);
|
---|
| 774 | fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
|
---|
| 775 | fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
| 776 | fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
| 777 | fputs("double NorRand(void) \n", fip);
|
---|
| 778 | fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
|
---|
| 779 | fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
|
---|
[345] | 780 | fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
|
---|
[344] | 781 | fputs(" return(x); \n } \n", fip);
|
---|
| 782 | fputs("#define GauRand() NorRand() \n", fip);
|
---|
| 783 | fputs("#define gaurand() NorRand() \n\n", fip);
|
---|
| 784 |
|
---|
[333] | 785 | fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
|
---|
| 786 | fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
|
---|
| 787 | fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
|
---|
| 788 | funcname.c_str());
|
---|
| 789 | fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
|
---|
| 790 | fprintf(fip, "{ \n %s \n", vardec.c_str());
|
---|
| 791 | fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
|
---|
| 792 | fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
|
---|
| 793 | fputs(" } \n /* Cut expression satisfied */ \n", fip);
|
---|
| 794 | fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
|
---|
| 795 | fputs(" return(1); \n} \n", fip);
|
---|
| 796 |
|
---|
| 797 | fclose(fip);
|
---|
[344] | 798 |
|
---|
| 799 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
[333] | 800 | return;
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 |
|
---|
| 804 | /* --Methode-- cmv 13/10/98 */
|
---|
| 805 | void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
|
---|
| 806 | string& experr, string& expcut, string& nomgfd)
|
---|
| 807 | // Pour remplir un ``GeneralFitData'' a partir de divers objets:
|
---|
| 808 | //| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
|
---|
| 809 | //| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
|
---|
| 810 | //| expx = expression X du GeneralFitData (1er abscisse)
|
---|
| 811 | //| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
|
---|
| 812 | //| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
|
---|
| 813 | //| experr = expression de l'erreur sur l'ordonnee Z
|
---|
| 814 | //| expcut = expression du test de selection
|
---|
| 815 | //| nomgfd = nom du GeneralFitData engendre (optionnel)
|
---|
| 816 | {
|
---|
| 817 | NObjMgrAdapter* obja=NULL;
|
---|
| 818 | obja = mOmg->GetObjAdapter(nom);
|
---|
| 819 | if (obja == NULL) {
|
---|
| 820 | cout << "Services2NObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl;
|
---|
| 821 | return;
|
---|
| 822 | }
|
---|
| 823 | if(!mImgapp) return;
|
---|
| 824 |
|
---|
| 825 | // 2D ou 3D?
|
---|
| 826 | int nvar = 2;
|
---|
| 827 | if(expy.length()<=0) {nvar = 1; expy = "0.";}
|
---|
| 828 |
|
---|
| 829 | // Creation NTuple Buffer
|
---|
| 830 | char* ntn[4]= {"x","y","f","e"};
|
---|
| 831 | NTuple*nt = new NTuple(4,ntn);
|
---|
| 832 |
|
---|
| 833 | // Remplissage NTuple buffer
|
---|
| 834 | ComputeExpressions(obja, expx, expy, expz, experr, expcut, nt, NULL, NULL);
|
---|
| 835 | if(nt->NEntry() < 1)
|
---|
| 836 | {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
|
---|
| 837 | delete nt; return;}
|
---|
| 838 |
|
---|
| 839 | //Remplissage de la structure GeneraFitData
|
---|
| 840 | if (nt->NEntry() <= 0) {
|
---|
| 841 | cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
|
---|
| 842 | delete nt;
|
---|
| 843 | return;
|
---|
| 844 | }
|
---|
| 845 |
|
---|
| 846 | GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
|
---|
| 847 | int k;
|
---|
| 848 | float* xn;
|
---|
| 849 | for(k=0; k<nt->NEntry(); k++) {
|
---|
| 850 | xn = nt->GetVec(k);
|
---|
| 851 | gfd->AddData(xn,xn[2],xn[3]);
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | // Menage et table d'objets
|
---|
| 855 | delete nt;
|
---|
| 856 | mOmg->AddObj(gfd, nomgfd);
|
---|
| 857 | return;
|
---|
| 858 | }
|
---|
| 859 |
|
---|
| 860 |
|
---|
| 861 | ///////////////////// Fit 1D et 2D //////////////////////////
|
---|
| 862 | /* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */
|
---|
| 863 | struct DFOptions {
|
---|
| 864 | int okres, okfun;
|
---|
| 865 | int polcx,polcy; double xc,yc;
|
---|
| 866 | double err_e, err_E;
|
---|
| 867 | double stc2;
|
---|
[341] | 868 | int nstep;
|
---|
[333] | 869 | int lp,lpg;
|
---|
| 870 | int i1,i2,j1,j2;
|
---|
| 871 | };
|
---|
| 872 | typedef struct DFOptions DFOPTIONS;
|
---|
| 873 | static void DecodeFitsOptions(string par,string step,string min,string max,string opt
|
---|
| 874 | ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O);
|
---|
| 875 | void DecodeFitsOptions(string par,string step,string min,string max,string opt
|
---|
| 876 | ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O)
|
---|
| 877 | //| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D)
|
---|
| 878 | {
|
---|
| 879 | // set des vecteurs et decodage des string correspondantes
|
---|
| 880 | int NParMax = 100;
|
---|
| 881 | Par.Realloc(NParMax); Step.Realloc(NParMax);
|
---|
| 882 | Min.Realloc(NParMax); Max.Realloc(NParMax);
|
---|
| 883 | {
|
---|
| 884 | Vector* v=NULL; string* s=NULL;
|
---|
| 885 | {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}}
|
---|
| 886 | for(int j=0;j<4;j++) {
|
---|
| 887 | if(j==0) {v=&Par; s=∥}
|
---|
| 888 | else if(j==1) {v=&Step; s=&step;}
|
---|
| 889 | else if(j==2) {v=&Min; s=&min;}
|
---|
| 890 | else if(j==3) {v=&Max; s=&max;}
|
---|
| 891 | if(s->length()>0) *s += ",";
|
---|
| 892 | for(int i=0;i<NParMax;i++) {
|
---|
| 893 | if(s->length()<=0) break;
|
---|
| 894 | sscanf(s->c_str(),"%lf",&(*v)(i));
|
---|
| 895 | size_t p = s->find_first_of(',') + 1;
|
---|
| 896 | if(p>=s->length()) *s = ""; else *s = s->substr(p);
|
---|
| 897 | }
|
---|
| 898 | }
|
---|
| 899 | }
|
---|
| 900 |
|
---|
| 901 | // Decodage de options de opt
|
---|
| 902 | O.okres = O.okfun = 0;
|
---|
| 903 | O.polcx = O.polcy = 0;
|
---|
| 904 | O.xc = O.yc = 0.;
|
---|
| 905 | O.stc2 = 1.e-3;
|
---|
[341] | 906 | O.nstep = 100;
|
---|
[333] | 907 | O.err_e = O.err_E = -1.;
|
---|
| 908 | O.lp = 1; O.lpg = 0;
|
---|
| 909 | O.i1 = O.j1 = O.i2 = O.j2 = -1;
|
---|
| 910 |
|
---|
| 911 | if(opt.length()<=0) return;
|
---|
| 912 | opt = "," + opt + ",";
|
---|
| 913 |
|
---|
| 914 | if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus
|
---|
| 915 | if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee
|
---|
| 916 | if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
|
---|
| 917 | O.polcx = 2; // Le centrage est calcule automatiquement
|
---|
| 918 | size_t p = opt.find(",x");
|
---|
| 919 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 920 | string dum = opt.substr(p,q-p);
|
---|
| 921 | if(dum.length()>2) {
|
---|
| 922 | sscanf(dum.c_str(),",x%lf",&O.xc);
|
---|
| 923 | O.polcx = 1; // Le centrage est fixe par la valeur lue
|
---|
| 924 | }
|
---|
| 925 | }
|
---|
| 926 | if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
|
---|
| 927 | O.polcy = 2; // Le centrage est calcule automatiquement
|
---|
| 928 | size_t p = opt.find(",y");
|
---|
| 929 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 930 | string dum = opt.substr(p,q-p);
|
---|
| 931 | if(dum.length()>2) {
|
---|
| 932 | sscanf(dum.c_str(),",y%lf",&O.yc);
|
---|
| 933 | O.polcy = 1; // Le centrage est fixe par la valeur lue
|
---|
| 934 | }
|
---|
| 935 | }
|
---|
| 936 | if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
|
---|
| 937 | size_t p = opt.find(",E");
|
---|
| 938 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 939 | string dum = opt.substr(p,q-p);
|
---|
| 940 | if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E);
|
---|
| 941 | if(O.err_E<=0.) O.err_E = 1.;
|
---|
| 942 | O.err_e=-1.;
|
---|
| 943 | }
|
---|
| 944 | if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
|
---|
| 945 | size_t p = opt.find(",e");
|
---|
| 946 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 947 | string dum = opt.substr(p,q-p);
|
---|
| 948 | if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e);
|
---|
| 949 | if(O.err_e<=0.) O.err_e = 1.;
|
---|
| 950 | O.err_E=-1.;
|
---|
| 951 | }
|
---|
| 952 | if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
|
---|
| 953 | size_t p = opt.find(",X");
|
---|
| 954 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 955 | string dum = opt.substr(p,q-p);
|
---|
| 956 | if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2);
|
---|
| 957 | if(O.stc2<=0.) O.stc2 = 1.e-3;
|
---|
| 958 | }
|
---|
[341] | 959 | if(strstr(opt.c_str(),",N")) { // Nombre maximum d'iterations
|
---|
| 960 | size_t p = opt.find(",N");
|
---|
| 961 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 962 | string dum = opt.substr(p,q-p);
|
---|
| 963 | if(dum.length()>2) sscanf(dum.c_str(),",N%d",&O.nstep);
|
---|
| 964 | if(O.nstep<2) O.nstep = 100;
|
---|
| 965 | }
|
---|
[333] | 966 | if(strstr(opt.c_str(),",l")) { // niveau de print
|
---|
| 967 | size_t p = opt.find(",l");
|
---|
| 968 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 969 | string dum = opt.substr(p,q-p);
|
---|
| 970 | float ab;
|
---|
| 971 | if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
|
---|
| 972 | if(ab<0) ab = 0.;
|
---|
[341] | 973 | O.lp = (int) ab; O.lpg = int(10.*(ab-(float)O.lp+0.01));
|
---|
[333] | 974 | }
|
---|
| 975 | if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
|
---|
| 976 | size_t p = opt.find(",I");
|
---|
| 977 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 978 | string dum = opt.substr(p,q-p);
|
---|
| 979 | if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2);
|
---|
| 980 | }
|
---|
| 981 | if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
|
---|
| 982 | size_t p = opt.find(",J");
|
---|
| 983 | size_t q = opt.find_first_of(',',p+1);
|
---|
| 984 | string dum = opt.substr(p,q-p);
|
---|
| 985 | if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2);
|
---|
| 986 | }
|
---|
| 987 | return;
|
---|
| 988 | }
|
---|
| 989 |
|
---|
| 990 | /* --Methode-- cmv 13/10/98 */
|
---|
| 991 | void Services2NObjMgr::Fit12D(string& nom, string& func,
|
---|
| 992 | string par,string step,string min,string max,
|
---|
| 993 | string opt)
|
---|
| 994 | //| --------------- Fit d'objets a 1 et 2 dimensions ---------------
|
---|
| 995 | //| nom : nom de l'objet qui peut etre:
|
---|
| 996 | //| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D)
|
---|
[341] | 997 | //| fit-2D: Matrix,Histo2D,Image<T> ou GeneraFitData(2D)
|
---|
| 998 | //| func : pnn : fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
|
---|
| 999 | //| : Pnn : fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
|
---|
| 1000 | //| : gnn : fit gaussienne (hauteur) + polynome de degre nn 1D
|
---|
| 1001 | //| : g : fit gaussienne (hauteur) 1D
|
---|
| 1002 | //| : enn : fit exponentielle + polynome de degre nn 1D
|
---|
| 1003 | //| : e : fit exponentielle 1D
|
---|
| 1004 | //| : Gnn : fit gaussienne (volume) + polynome de degre nn 1D
|
---|
| 1005 | //| : G : fit gaussienne (volume) 1D
|
---|
| 1006 | //| : : fit gaussienne+fond (volume) 2D
|
---|
| 1007 | //| : Gi : fit gaussienne+fond integree (volume) 2D
|
---|
| 1008 | //| : d : fit DL de gaussienne+fond (volume) 2D
|
---|
| 1009 | //| : di : fit DL de gaussienne+fond integree (volume) 2D
|
---|
| 1010 | //| : D : fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
|
---|
| 1011 | //| : Di : fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
|
---|
| 1012 | //| : M : fit Moffat+fond (expos=p6) (volume) 2D
|
---|
| 1013 | //| : Mi : fit Moffat+fond integree (expos=p6) (volume) 2D
|
---|
| 1014 | //| par : p1,...,pn : valeur d'initialisation des parametres (def=0)
|
---|
| 1015 | //| step : s1,...,sn : valeur des steps de depart (def=1)
|
---|
| 1016 | //| min : m1,...,mn : valeur des minima (def=1)
|
---|
| 1017 | //| max : M1,...,Mn : valeur des maxima (def=-1) (max<=min : pas de limite)
|
---|
[333] | 1018 | //| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b"
|
---|
[341] | 1019 | //| f : generation d'un Objet identique contenant la fonction fittee
|
---|
| 1020 | //| r : generation d'un Objet identique contenant les residus
|
---|
| 1021 | //| Xaa.b : aa.b valeur du DXi2 d'arret (def=1.e-3)
|
---|
| 1022 | //| Naa : aa nombre maximum d'iterations (def=100)
|
---|
| 1023 | //| la.b : niveau "a.b" de print: a=niveau de print Fit1/2D
|
---|
| 1024 | //| b=niveau de debug GeneralFit
|
---|
| 1025 | //| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2]
|
---|
| 1026 | //|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2]
|
---|
| 1027 | //| - L'erreur est celle associee a l'objet (si elle existe),
|
---|
| 1028 | //| elle est mise a 1 sinon, sauf si E... ou e... est precise:
|
---|
| 1029 | //| Eaa.b : si |val|>=1 erreur = aa.b*sqrt(|val|)
|
---|
| 1030 | //| si |val|<1 erreur = aa.b
|
---|
| 1031 | //| si aa.b <=0 alors aa.b=1.0
|
---|
| 1032 | //| E seul est equivalent a E1.0
|
---|
| 1033 | //| eaa.b : erreur = aa.b
|
---|
| 1034 | //| si aa.b <=0 alors aa.b=1.0
|
---|
| 1035 | //| e seul est equivalent a e1.0
|
---|
| 1036 | //| xaa.b : demande de centrage: on fit x-aa.b au lieu de x)
|
---|
| 1037 | //| x : demande de centrage: on fit x-xc au lieu de x
|
---|
| 1038 | //| avec xc=abscisse du milieu de l'histogramme
|
---|
| 1039 | //| Actif pour exp+poly 1D, poly 1D
|
---|
| 1040 | //| pour gauss+poly 1D, xc est le centre de la gaussienne.
|
---|
| 1041 | //|2D yaa.b et y : idem "xaa.b et x" mais pour y
|
---|
[333] | 1042 | {
|
---|
| 1043 | AnyDataObj* obj=mOmg->GetObj(nom);
|
---|
| 1044 | if (obj == NULL) {
|
---|
| 1045 | cout<<"Services2NObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl;
|
---|
| 1046 | return;
|
---|
| 1047 | }
|
---|
| 1048 | if (!mImgapp) return;
|
---|
| 1049 | if(func.length()<=0)
|
---|
| 1050 | {cout<<"Services2NObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl;
|
---|
| 1051 | return;}
|
---|
| 1052 | string ctyp = typeid(*obj).name();
|
---|
| 1053 |
|
---|
| 1054 | int ndim = 0, nbinx=0, nbiny=0, ndata = 0;
|
---|
| 1055 | Vector* v = NULL; Histo* h = NULL;
|
---|
| 1056 | Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL;
|
---|
| 1057 | GeneralFitData* g = NULL;
|
---|
| 1058 |
|
---|
| 1059 | // 1D
|
---|
| 1060 | if (typeid(*obj) == typeid(Vector)) {
|
---|
| 1061 | ndim = 1;
|
---|
| 1062 | v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1;
|
---|
| 1063 | }
|
---|
| 1064 | else if ( (typeid(*obj) == typeid(HProf)) || (typeid(*obj) == typeid(Histo)) ) {
|
---|
| 1065 | ndim = 1;
|
---|
| 1066 | h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1;
|
---|
| 1067 | }
|
---|
| 1068 | else if (typeid(*obj) == typeid(Matrix)) {
|
---|
| 1069 | ndim = 2;
|
---|
| 1070 | m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows();
|
---|
| 1071 | }
|
---|
| 1072 | else if (typeid(*obj) == typeid(Histo2D)) {
|
---|
| 1073 | ndim = 2;
|
---|
| 1074 | h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY();
|
---|
| 1075 | }
|
---|
| 1076 | else if (typeid(*obj) == typeid(GeneralFitData)) {
|
---|
| 1077 | g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1;
|
---|
| 1078 | if( g->NVar()==1) ndim = 1;
|
---|
| 1079 | else if(g->NVar()==2) ndim = 2;
|
---|
| 1080 | else {
|
---|
| 1081 | cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
|
---|
| 1082 | <<((GeneralFitData*) obj)->NVar()<<endl; return; }
|
---|
| 1083 | }
|
---|
| 1084 | else if (dynamic_cast<RzImage*>(obj)) {
|
---|
| 1085 | ndim = 2;
|
---|
| 1086 | im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize();
|
---|
| 1087 | }
|
---|
| 1088 | else {
|
---|
| 1089 | cout<<"Services2NObjMgr::Fit12D() Error , Objet n'est pas un "
|
---|
| 1090 | <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
|
---|
| 1091 | return;
|
---|
| 1092 | }
|
---|
| 1093 |
|
---|
| 1094 | ndata = nbinx*nbiny;
|
---|
| 1095 | if(ndata<=0)
|
---|
| 1096 | {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;}
|
---|
| 1097 |
|
---|
| 1098 | // Decodage des options et des parametres, mise en forme
|
---|
| 1099 | Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O;
|
---|
| 1100 | DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O);
|
---|
| 1101 | O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1;
|
---|
| 1102 | O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2;
|
---|
| 1103 | if(ndim>=2) {
|
---|
| 1104 | O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1;
|
---|
| 1105 | O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2;
|
---|
| 1106 | } else O.j2 = O.j1 = 0;
|
---|
| 1107 | if(O.polcx==2) {
|
---|
| 1108 | if(v||m) O.xc = (O.i2-O.i1+1)/2.;
|
---|
| 1109 | else if(h) O.xc = (h->XMin()+h->XMax())/2.;
|
---|
| 1110 | else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.;
|
---|
| 1111 | else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;}
|
---|
| 1112 | else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;}
|
---|
| 1113 | }
|
---|
| 1114 | if(O.polcy==2 && ndim>=2) {
|
---|
| 1115 | if(m) O.yc = (O.j2-O.j1+1)/2.;
|
---|
| 1116 | if(h2) O.yc = (h2->YMin()+h2->YMax())/2.;
|
---|
| 1117 | if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;}
|
---|
| 1118 | if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;}
|
---|
| 1119 | }
|
---|
| 1120 | if(O.lp>0)
|
---|
| 1121 | cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":"
|
---|
| 1122 | <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl
|
---|
| 1123 | <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y"
|
---|
| 1124 | <<" TypE="<<O.err_e<<","<<O.err_E
|
---|
[341] | 1125 | <<" StpX2="<<O.stc2<<" Nstep="<<O.nstep
|
---|
[333] | 1126 | <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl;
|
---|
| 1127 |
|
---|
| 1128 | ///////////////////////////////////
|
---|
| 1129 | // Remplissage de GeneralFitData //
|
---|
| 1130 | ///////////////////////////////////
|
---|
| 1131 | GeneralFitData mydata(ndim,ndata,0);
|
---|
| 1132 | {for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) {
|
---|
| 1133 | double x,y,f,e;
|
---|
| 1134 |
|
---|
| 1135 | if(v)
|
---|
| 1136 | {x= (double) i; f=(*v)(i); e=1.;}
|
---|
| 1137 | else if(h)
|
---|
| 1138 | {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;}
|
---|
| 1139 | else if(m)
|
---|
| 1140 | {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;}
|
---|
| 1141 | else if(h2)
|
---|
| 1142 | {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
|
---|
| 1143 | f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;}
|
---|
| 1144 | else if(im)
|
---|
| 1145 | {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize();
|
---|
| 1146 | f=im->DValue(i,j); e=1.;}
|
---|
| 1147 | else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);}
|
---|
| 1148 | else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);}
|
---|
| 1149 | else x=y=f=e=0.;
|
---|
| 1150 |
|
---|
| 1151 | // Gestion des erreurs a utiliser
|
---|
| 1152 | if(O.err_e>0.) e=O.err_e;
|
---|
[341] | 1153 | else if(O.err_E>0.) {e=(f<-1.||f>1.)?O.err_E*sqrt(fabs(f)):O.err_E;}
|
---|
[333] | 1154 |
|
---|
| 1155 | // Remplissage de generalfit
|
---|
| 1156 | if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;}
|
---|
| 1157 | if(ndim==1) mydata.AddData1(x,f,e);
|
---|
| 1158 | else if(ndim==2) mydata.AddData2(x,y,f,e);
|
---|
| 1159 | }}
|
---|
| 1160 | if(mydata.NData()<=0)
|
---|
| 1161 | {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl;
|
---|
| 1162 | return;}
|
---|
| 1163 | if(O.lpg>1) {
|
---|
| 1164 | mydata.PrintStatus();
|
---|
| 1165 | mydata.PrintData(0);
|
---|
| 1166 | mydata.PrintData(mydata.NData()-1);
|
---|
| 1167 | }
|
---|
| 1168 |
|
---|
| 1169 | ////////////////////////////////////////////
|
---|
| 1170 | // Identification de la fonction a fitter //
|
---|
| 1171 | ////////////////////////////////////////////
|
---|
| 1172 | GeneralFunction* myfunc = NULL;
|
---|
| 1173 | if(func[0]=='p' && ndim==1) {
|
---|
| 1174 | // Fit de polynome sans passer par les GeneralFit
|
---|
| 1175 | int degre = 0;
|
---|
| 1176 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
| 1177 | cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
|
---|
| 1178 | Poly p1(0);
|
---|
| 1179 | double c2rl = mydata.PolFit(0,p1,degre);
|
---|
| 1180 | cout<<"C2r_lineaire = "<<c2rl<<endl;
|
---|
| 1181 | if(O.lp>0) cout<<p1<<endl;
|
---|
| 1182 | return;
|
---|
| 1183 |
|
---|
| 1184 | } else if(func[0]=='P' && ndim==1) {
|
---|
| 1185 | // Fit de polynome
|
---|
| 1186 | int degre = 0;
|
---|
| 1187 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
| 1188 | cout<<"Fit polynome 1D de degre "<<degre<<endl;
|
---|
| 1189 | Polyn1D* myf = new Polyn1D(degre,O.xc);
|
---|
| 1190 | myfunc = myf;
|
---|
| 1191 |
|
---|
| 1192 | } else if(func[0]=='e' && ndim==1) {
|
---|
| 1193 | // Fit d'exponentielle
|
---|
| 1194 | int degre =-1;
|
---|
| 1195 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
| 1196 | cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
|
---|
| 1197 | Exp1DPol* myf;
|
---|
| 1198 | if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc);
|
---|
| 1199 | else myf = new Exp1DPol(O.xc);
|
---|
| 1200 | myfunc = myf;
|
---|
| 1201 |
|
---|
| 1202 | } else if(func[0]=='g' && ndim==1) {
|
---|
| 1203 | // Fit de gaussienne en hauteur
|
---|
| 1204 | int degre =-1;
|
---|
| 1205 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
| 1206 | cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
|
---|
| 1207 | Gauss1DPol* myf;
|
---|
| 1208 | if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false));
|
---|
| 1209 | else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); }
|
---|
| 1210 | myfunc = myf;
|
---|
| 1211 |
|
---|
| 1212 | } else if(func[0]=='G' && ndim==1) {
|
---|
| 1213 | // Fit de gaussienne en volume
|
---|
| 1214 | int degre =-1;
|
---|
| 1215 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
| 1216 | cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
|
---|
| 1217 | GaussN1DPol* myf;
|
---|
| 1218 | if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false));
|
---|
| 1219 | else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); }
|
---|
| 1220 | myfunc = myf;
|
---|
| 1221 |
|
---|
| 1222 | } else if(func[0]=='p' && ndim==2) {
|
---|
| 1223 | // Fit de polynome 2D sans passer par les GeneralFit
|
---|
| 1224 | int degre = 0;
|
---|
| 1225 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
| 1226 | cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
|
---|
| 1227 | Poly2 p2(0);
|
---|
| 1228 | double c2rl = mydata.PolFit(0,1,p2,degre);
|
---|
| 1229 | cout<<"C2r_lineaire = "<<c2rl<<endl;
|
---|
| 1230 | if(O.lp>0) cout<<p2<<endl;
|
---|
| 1231 | return;
|
---|
| 1232 |
|
---|
| 1233 | } else if(func[0]=='P' && ndim==2) {
|
---|
| 1234 | // Fit de polynome 2D
|
---|
| 1235 | int degre = 0;
|
---|
| 1236 | if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
| 1237 | cout<<"Fit polynome 2D de degre "<<degre<<endl;
|
---|
| 1238 | Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc);
|
---|
| 1239 | myfunc = myf;
|
---|
| 1240 |
|
---|
| 1241 | } else if(func[0]=='G' && ndim==2) {
|
---|
| 1242 | // Fit de gaussienne+fond en volume
|
---|
| 1243 | int integ = 0;
|
---|
| 1244 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
| 1245 | cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
|
---|
| 1246 | if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;}
|
---|
| 1247 | else {GauRho2D* myf = new GauRho2D; myfunc = myf;}
|
---|
| 1248 |
|
---|
| 1249 | } else if(func[0]=='d' && ndim==2) {
|
---|
| 1250 | // Fit de DL gaussienne+fond en volume
|
---|
| 1251 | int integ = 0;
|
---|
| 1252 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
| 1253 | cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
|
---|
| 1254 | if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;}
|
---|
| 1255 | else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;}
|
---|
| 1256 |
|
---|
| 1257 | } else if(func[0]=='D' && ndim==2) {
|
---|
| 1258 | // Fit de DL gaussienne+fond avec coeff variable p6 en volume
|
---|
| 1259 | int integ = 0;
|
---|
| 1260 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
| 1261 | cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
|
---|
| 1262 | if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;}
|
---|
| 1263 | else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;}
|
---|
| 1264 |
|
---|
| 1265 | } else if(func[0]=='M' && ndim==2) {
|
---|
| 1266 | // Fit de Moffat+fond (volume)
|
---|
| 1267 | int integ = 0;
|
---|
| 1268 | if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
| 1269 | cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
|
---|
| 1270 | if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;}
|
---|
| 1271 | else {MofRho2D* myf = new MofRho2D; myfunc = myf;}
|
---|
| 1272 |
|
---|
| 1273 | } else {
|
---|
| 1274 | cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl;
|
---|
| 1275 | return;
|
---|
| 1276 | }
|
---|
| 1277 |
|
---|
| 1278 | /////////////////////////
|
---|
| 1279 | // Fit avec generalfit //
|
---|
| 1280 | /////////////////////////
|
---|
| 1281 | if(myfunc->NPar()>Par.NElts())
|
---|
| 1282 | {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl;
|
---|
| 1283 | if(myfunc) delete myfunc; return;}
|
---|
| 1284 | GeneralFit myfit(myfunc);
|
---|
| 1285 | myfit.SetDebug(O.lpg);
|
---|
| 1286 | myfit.SetData(&mydata);
|
---|
| 1287 | myfit.SetStopChi2(O.stc2);
|
---|
[341] | 1288 | myfit.SetMaxStep(O.nstep);
|
---|
[333] | 1289 | {for(int i=0;i<myfunc->NPar();i++) {
|
---|
| 1290 | char str[10];
|
---|
| 1291 | sprintf(str,"P%d",i);
|
---|
| 1292 | myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i));
|
---|
| 1293 | }}
|
---|
| 1294 | if(O.lp>1) myfit.PrintFit();
|
---|
[341] | 1295 | double c2r = -1.;
|
---|
| 1296 | int rcfit = (double) myfit.Fit();
|
---|
[333] | 1297 | if(O.lp>0) myfit.PrintFit();
|
---|
[341] | 1298 | if(rcfit>0) {
|
---|
[333] | 1299 | c2r = myfit.GetChi2Red();
|
---|
[341] | 1300 | cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<" rc="<<rcfit<<endl;
|
---|
[333] | 1301 | Vector ParFit(myfunc->NPar());
|
---|
| 1302 | for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i);
|
---|
| 1303 | } else {
|
---|
[341] | 1304 | cout<<"echec Fit, rc = "<<rcfit<<" nstep="<<myfit.GetNStep()<<endl;
|
---|
| 1305 | myfit.PrintFitErr(rcfit);
|
---|
[333] | 1306 | }
|
---|
| 1307 |
|
---|
| 1308 | // Mise a disposition des resultats
|
---|
[341] | 1309 | if(rcfit>=0 && myfunc && (O.okres>0||O.okfun>0)) {
|
---|
[333] | 1310 | string nomres = nom + "res";
|
---|
| 1311 | string nomfun = nom + "fun";
|
---|
| 1312 | if(v) {
|
---|
| 1313 | if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
|
---|
| 1314 | if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
|
---|
| 1315 | } else if(h) {
|
---|
| 1316 | if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
|
---|
| 1317 | if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
|
---|
| 1318 | } else if(m) {
|
---|
| 1319 | if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
|
---|
| 1320 | if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
|
---|
| 1321 | } else if(h2) {
|
---|
| 1322 | if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
|
---|
| 1323 | if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
|
---|
| 1324 | } else if(im) {
|
---|
| 1325 | if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
|
---|
| 1326 | if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
|
---|
| 1327 | } else if(g) {
|
---|
| 1328 | if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
|
---|
| 1329 | if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
|
---|
| 1330 | }
|
---|
| 1331 | }
|
---|
| 1332 |
|
---|
| 1333 | // Nettoyage
|
---|
| 1334 | if(myfunc) delete myfunc;
|
---|
| 1335 | return;
|
---|
| 1336 | }
|
---|
| 1337 |
|
---|
| 1338 |
|
---|
| 1339 | /* --Methode-- */
|
---|
| 1340 | void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
|
---|
| 1341 | string& expy, string& expz, string& expt, string& expcut,
|
---|
| 1342 | NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
|
---|
| 1343 | {
|
---|
| 1344 | if (obja == NULL) return;
|
---|
[344] | 1345 | bool adel = true;
|
---|
| 1346 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
[333] | 1347 | if (objnt == NULL) return;
|
---|
| 1348 | string vardec = objnt->VarList_C("_zz6qi_");
|
---|
| 1349 |
|
---|
| 1350 | PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
|
---|
| 1351 | if (!f) {
|
---|
| 1352 | cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
|
---|
[344] | 1353 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
[333] | 1354 | return;
|
---|
| 1355 | }
|
---|
| 1356 |
|
---|
| 1357 | double xnt[10];
|
---|
| 1358 | float fxnt[10];
|
---|
| 1359 |
|
---|
| 1360 | int i,k;
|
---|
| 1361 | for(i=0; i<10; i++) xnt[i] = 0.;
|
---|
| 1362 |
|
---|
| 1363 | TRY {
|
---|
| 1364 | double* xn;
|
---|
| 1365 | for(k=0; k<objnt->NbLines(); k++) {
|
---|
| 1366 | xn = objnt->GetLineD(k);
|
---|
| 1367 | if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
|
---|
| 1368 | if (nt) {
|
---|
| 1369 | for(i=0; i<4; i++) fxnt[i] = xnt[i];
|
---|
| 1370 | nt->Fill(fxnt);
|
---|
| 1371 | }
|
---|
| 1372 | if (h1) h1->Add(xnt[0], xnt[3]);
|
---|
| 1373 | if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
|
---|
| 1374 | if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
|
---|
| 1375 | }
|
---|
| 1376 | }
|
---|
| 1377 | }
|
---|
| 1378 | CATCH(merr) {
|
---|
| 1379 | fflush(stdout);
|
---|
| 1380 | cout << endl;
|
---|
| 1381 | cerr << endl;
|
---|
| 1382 | string es = PeidaExc(merr);
|
---|
| 1383 | cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
|
---|
| 1384 | } ENDTRY;
|
---|
| 1385 |
|
---|
| 1386 |
|
---|
[344] | 1387 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
[333] | 1388 | // Fermeture du fichier .so
|
---|
| 1389 | CloseDLL();
|
---|
| 1390 | return;
|
---|
| 1391 | }
|
---|
| 1392 |
|
---|
| 1393 |
|
---|
| 1394 | /* --Methode-- */
|
---|
| 1395 | PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
|
---|
| 1396 | string& expz, string& expt, string& cut)
|
---|
| 1397 | {
|
---|
| 1398 | FILE *fip;
|
---|
| 1399 | string fname = TmpDir + "expf_pia_dl.c";
|
---|
| 1400 | string cmd;
|
---|
| 1401 | int rc;
|
---|
| 1402 |
|
---|
| 1403 | cmd = "rm -f " + fname;
|
---|
| 1404 | rc = system(cmd.c_str());
|
---|
| 1405 | //DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
| 1406 |
|
---|
| 1407 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
| 1408 | string sn = fname;
|
---|
| 1409 | cout << "Services2NObjMgr/LinkExprFunc_Erreur: Pb. Ouverture " << sn << endl;
|
---|
| 1410 | return(NULL);
|
---|
| 1411 | }
|
---|
| 1412 |
|
---|
| 1413 | // constitution du fichier a compiler
|
---|
| 1414 | fputs("#include <stdlib.h> \n", fip);
|
---|
| 1415 | fputs("#include <math.h> \n", fip);
|
---|
[344] | 1416 |
|
---|
| 1417 | fputs("/* ------ Some random number generators --------- */ \n", fip);
|
---|
| 1418 | fputs("#define frand01() ( (float) drand48() ) \n", fip);
|
---|
| 1419 | fputs("#define drand01() drand48() \n", fip);
|
---|
| 1420 | fputs("#define rand01() drand48() \n", fip);
|
---|
| 1421 | fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
|
---|
| 1422 | fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
| 1423 | fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
| 1424 | fputs("double NorRand(void) \n", fip);
|
---|
| 1425 | fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
|
---|
| 1426 | fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
|
---|
[345] | 1427 | fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
|
---|
[344] | 1428 | fputs(" return(x); \n } \n", fip);
|
---|
| 1429 | fputs("#define GauRand() NorRand() \n", fip);
|
---|
| 1430 | fputs("#define gaurand() NorRand() \n\n", fip);
|
---|
| 1431 |
|
---|
[333] | 1432 | fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
|
---|
| 1433 | fprintf(fip,"%s \n", vardec.c_str());
|
---|
| 1434 | fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
|
---|
| 1435 | fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
|
---|
| 1436 | fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
|
---|
| 1437 | fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
|
---|
| 1438 | fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
|
---|
| 1439 | fputs("return(1); \n} \n", fip);
|
---|
| 1440 | fclose(fip);
|
---|
| 1441 | string func = "expf_pia_dl_func";
|
---|
| 1442 | return((PlotExprFunc)LinkFunctionFromFile(fname, func));
|
---|
| 1443 | }
|
---|
| 1444 |
|
---|
| 1445 |
|
---|
| 1446 | /* --Methode-- */
|
---|
| 1447 | DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
|
---|
| 1448 | {
|
---|
| 1449 | // Le link dynamique
|
---|
| 1450 | CloseDLL();
|
---|
| 1451 | dynlink = PDynLinkMgr::BuildFromCFile(fname);
|
---|
| 1452 | if (dynlink == NULL) {
|
---|
| 1453 | cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
|
---|
| 1454 | return(NULL);
|
---|
| 1455 | }
|
---|
| 1456 |
|
---|
| 1457 | DlFunction retfunc = dynlink->GetFunction(funcname);
|
---|
| 1458 | if (retfunc == NULL) {
|
---|
| 1459 | string sn = funcname;
|
---|
| 1460 | cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
|
---|
| 1461 | CloseDLL();
|
---|
| 1462 | return(NULL);
|
---|
| 1463 | }
|
---|
| 1464 | else return(retfunc);
|
---|
| 1465 | }
|
---|
| 1466 |
|
---|
| 1467 | /* --Methode-- */
|
---|
| 1468 | void Services2NObjMgr::CloseDLL()
|
---|
| 1469 | {
|
---|
| 1470 | if (dynlink) delete dynlink; dynlink = NULL;
|
---|
| 1471 | }
|
---|
| 1472 |
|
---|
| 1473 |
|
---|
| 1474 | /* --Methode-- */
|
---|
[165] | 1475 | string Services2NObjMgr::FileName2Name(string const & fn)
|
---|
| 1476 | {
|
---|
| 1477 |
|
---|
| 1478 | char fsep[2] = {FILESEP, '\0'};
|
---|
| 1479 | char tsep[2] = {'.', '\0'};
|
---|
| 1480 | size_t p = fn.find_last_of(fsep);
|
---|
[194] | 1481 | size_t l = fn.length();
|
---|
| 1482 | if (p >= l) p = 0;
|
---|
| 1483 | else p++;
|
---|
| 1484 | size_t q = fn.find_first_of(tsep,p);
|
---|
| 1485 | if (q < p) q = l;
|
---|
[165] | 1486 | return(fn.substr(p,q-p));
|
---|
| 1487 | }
|
---|
| 1488 |
|
---|
| 1489 |
|
---|
| 1490 | typedef vector<string> GraTok;
|
---|
| 1491 |
|
---|
| 1492 | /* --Methode-- */
|
---|
| 1493 | int Services2NObjMgr::DecodeDispOption(string& gratt, bool& fgsrgr)
|
---|
| 1494 | {
|
---|
| 1495 | int ropt = Disp_Next;
|
---|
| 1496 | if (!mImgapp) return(ropt);
|
---|
| 1497 |
|
---|
| 1498 | for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
|
---|
| 1499 |
|
---|
| 1500 | if (fgsrgr) mImgapp->SaveGraphicAtt();
|
---|
| 1501 |
|
---|
[326] | 1502 | if ( (gratt == "def") || (gratt == "default") ) { // Remise aux valeurs par defaut = non defini
|
---|
[165] | 1503 | mImgapp->SetColAtt();
|
---|
| 1504 | mImgapp->SetLineAtt();
|
---|
| 1505 | mImgapp->SetFontAtt();
|
---|
| 1506 | mImgapp->SetMarkerAtt();
|
---|
| 1507 | mImgapp->SetColMapId();
|
---|
| 1508 | mImgapp->SetZoomAtt();
|
---|
[331] | 1509 | mImgapp->SetAxesAtt();
|
---|
| 1510 | mImgapp->SetXYLimits();
|
---|
| 1511 | mImgapp->UseXYLimits();
|
---|
[165] | 1512 | return(ropt);
|
---|
| 1513 | }
|
---|
| 1514 |
|
---|
| 1515 | // On separe en mots separes par des virgules
|
---|
| 1516 | gratt = ","+gratt;
|
---|
| 1517 | size_t p = 0;
|
---|
| 1518 | size_t q = 0;
|
---|
| 1519 | size_t l = gratt.length();
|
---|
| 1520 | string token;
|
---|
| 1521 |
|
---|
| 1522 | GraTok grt;
|
---|
| 1523 |
|
---|
| 1524 | while (q < l) {
|
---|
| 1525 | p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
|
---|
| 1526 | if (p>=l) break;
|
---|
| 1527 | q = gratt.find_first_of(" ,",p); // la fin du token;
|
---|
| 1528 | token = gratt.substr(p,q-p);
|
---|
| 1529 | grt.push_back(token);
|
---|
| 1530 | }
|
---|
| 1531 |
|
---|
| 1532 |
|
---|
| 1533 | static GrAttNames::iterator it;
|
---|
| 1534 |
|
---|
| 1535 | int k;
|
---|
| 1536 | bool fgcont = true;
|
---|
| 1537 | fgsrgr = false;
|
---|
| 1538 |
|
---|
| 1539 | for(k=0; k<grt.size(); k++) {
|
---|
| 1540 | // cout << "--DBG--SetGraphicAttributes() " << grt[k] << endl;
|
---|
| 1541 |
|
---|
| 1542 | // Decodage option affichage (win, next, etc
|
---|
| 1543 | fgcont = true;
|
---|
| 1544 | if ( (grt[k] == "win") || (grt[k] == "w") ) ropt = Disp_Win;
|
---|
| 1545 | else if ( (grt[k] == "same") || (grt[k] == "s") ) ropt = Disp_Same;
|
---|
| 1546 | else if ( (grt[k] == "stack") || (grt[k] == "st") ) ropt = Disp_Stack;
|
---|
| 1547 | else fgcont = false;
|
---|
| 1548 | if (fgcont) continue;
|
---|
[331] | 1549 |
|
---|
| 1550 | // Utilisation limites X-Y
|
---|
| 1551 | if ( grt[k] == "xylimits" ) { mImgapp->UseXYLimits(true); fgsrgr = true; continue; }
|
---|
[165] | 1552 | // Si c'est une couleur
|
---|
| 1553 | it = GrAcolors.find(grt[k]);
|
---|
| 1554 | if (it != GrAcolors.end()) { mImgapp->SetColAtt((PIColors)((*it).second.a1)); fgsrgr = true; continue; }
|
---|
| 1555 | // Si c'est un attribut de lignes
|
---|
| 1556 | it = GrAlines.find(grt[k]);
|
---|
| 1557 | if (it != GrAlines.end()) { mImgapp->SetLineAtt((PILineAtt)((*it).second.a1)); fgsrgr = true; continue; }
|
---|
| 1558 | // Si c'est un attribut de fontes
|
---|
| 1559 | it = GrAfonts.find(grt[k]);
|
---|
| 1560 | if (it != GrAfonts.end()) { mImgapp->SetFontAtt((PIFontSize)((*it).second.a2), (PIFontAtt)((*it).second.a1) );
|
---|
| 1561 | fgsrgr = true; continue; }
|
---|
| 1562 | // Si c'est un attribut de markers
|
---|
| 1563 | it = GrAmarkers.find(grt[k]);
|
---|
| 1564 | if (it != GrAmarkers.end()) { mImgapp->SetMarkerAtt((*it).second.a2, (PIMarker)((*it).second.a1) );
|
---|
| 1565 | fgsrgr = true; continue; }
|
---|
| 1566 | // Si c'est un colormap
|
---|
| 1567 | it = GrAcmap.find(grt[k]);
|
---|
| 1568 | if (it != GrAcmap.end()) { mImgapp->SetColMapId( (CMapId)((*it).second.a1) ); fgsrgr = true; continue; }
|
---|
| 1569 | // Si c'est un facteur de zoom
|
---|
| 1570 | it = GrAzoom.find(grt[k]);
|
---|
| 1571 | if (it != GrAzoom.end()) { mImgapp->SetZoomAtt( (*it).second.a1 ); fgsrgr = true; continue; }
|
---|
[203] | 1572 | // Si c'est un attribut d'axe
|
---|
| 1573 | it = GrAaxes.find(grt[k]);
|
---|
| 1574 | if (it != GrAaxes.end()) { mImgapp->SetAxesAtt( (*it).second.a1 ); fgsrgr = true; continue; }
|
---|
[165] | 1575 |
|
---|
| 1576 | }
|
---|
| 1577 |
|
---|
| 1578 | return(ropt);
|
---|
| 1579 | }
|
---|
| 1580 |
|
---|
| 1581 |
|
---|
| 1582 |
|
---|
| 1583 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
---|
| 1584 | // Initialisation des chaines de caracteres designant les attributs graphiques
|
---|
| 1585 |
|
---|
| 1586 | /* --Methode-- */
|
---|
| 1587 | void Services2NObjMgr::InitGrAttNames()
|
---|
| 1588 | {
|
---|
| 1589 | gratt_item gi;
|
---|
| 1590 | // Les couleurs
|
---|
| 1591 | gi.a2 = 0;
|
---|
| 1592 | gi.a1 = PI_NotDefColor;
|
---|
| 1593 | GrAcolors["defcol"] = gi;
|
---|
| 1594 | gi.a1 = PI_Black;
|
---|
| 1595 | GrAcolors["black"] = gi;
|
---|
| 1596 | gi.a1 = PI_White;
|
---|
| 1597 | GrAcolors["white"] = gi;
|
---|
| 1598 | gi.a1 = PI_Grey;
|
---|
| 1599 | GrAcolors["grey"] = gi;
|
---|
| 1600 | gi.a1 = PI_Red;
|
---|
| 1601 | GrAcolors["red"] = gi;
|
---|
| 1602 | gi.a1 = PI_Blue;
|
---|
| 1603 | GrAcolors["blue"] = gi;
|
---|
| 1604 | gi.a1 = PI_Green;
|
---|
| 1605 | GrAcolors["green"] = gi;
|
---|
| 1606 | gi.a1 = PI_Yellow;
|
---|
| 1607 | GrAcolors["yellow"] = gi;
|
---|
| 1608 | gi.a1 = PI_Magenta;
|
---|
| 1609 | GrAcolors["magenta"] = gi;
|
---|
| 1610 |
|
---|
| 1611 | gi.a1 = PI_Cyan;
|
---|
| 1612 | GrAcolors["cyan"] = gi;
|
---|
| 1613 | gi.a1 = PI_Turquoise;
|
---|
| 1614 | GrAcolors["turquoise"] = gi;
|
---|
| 1615 | gi.a1 = PI_NavyBlue;
|
---|
| 1616 | GrAcolors["navyblue"] = gi;
|
---|
| 1617 | gi.a1 = PI_Orange;
|
---|
| 1618 | GrAcolors["orange"] = gi;
|
---|
| 1619 | gi.a1 = PI_SiennaRed;
|
---|
| 1620 | GrAcolors["siennared"] = gi;
|
---|
| 1621 | gi.a1 = PI_Purple;
|
---|
| 1622 | GrAcolors["purple"] = gi;
|
---|
| 1623 | gi.a1 = PI_LimeGreen;
|
---|
| 1624 | GrAcolors["limegreen"] = gi;
|
---|
| 1625 | gi.a1 = PI_Gold;
|
---|
| 1626 | GrAcolors["gold"] = gi;
|
---|
| 1627 |
|
---|
| 1628 | // Les attributs de lignes
|
---|
| 1629 | gi.a2 = 0;
|
---|
| 1630 | gi.a1 = PI_NotDefLineAtt;
|
---|
| 1631 | GrAlines["defline"] = gi;
|
---|
| 1632 | gi.a1 = PI_NormalLine;
|
---|
| 1633 | GrAlines["normalline"] = gi;
|
---|
| 1634 | gi.a1 = PI_ThinLine;
|
---|
| 1635 | GrAlines["thinline"] = gi;
|
---|
| 1636 | gi.a1 = PI_ThickLine;
|
---|
| 1637 | GrAlines["thickline"] = gi;
|
---|
| 1638 | gi.a1 = PI_DashedLine;
|
---|
| 1639 | GrAlines["dashedline"] = gi;
|
---|
| 1640 | gi.a1 = PI_ThinDashedLine;
|
---|
| 1641 | GrAlines["thindashedline"] = gi;
|
---|
| 1642 | gi.a1 = PI_ThickDashedLine;
|
---|
| 1643 | GrAlines["thickdashedline"] = gi;
|
---|
[192] | 1644 | gi.a1 = PI_DottedLine;
|
---|
| 1645 | GrAlines["dottedline"] = gi;
|
---|
| 1646 | gi.a1 = PI_ThinDottedLine;
|
---|
| 1647 | GrAlines["thindottedline"] = gi;
|
---|
| 1648 | gi.a1 = PI_ThickDottedLine;
|
---|
| 1649 | GrAlines["thickdottedline"] = gi;
|
---|
[165] | 1650 |
|
---|
[293] | 1651 | // Les fontes
|
---|
[165] | 1652 | gi.a2 = PI_NotDefFontSize;
|
---|
| 1653 | gi.a1 = PI_NotDefFontAtt;
|
---|
| 1654 | GrAlines["deffont"] = gi;
|
---|
| 1655 |
|
---|
| 1656 | gi.a2 = PI_NormalSizeFont;
|
---|
| 1657 | gi.a1 = PI_RomanFont;
|
---|
| 1658 | GrAlines["normalfont"] = gi;
|
---|
| 1659 | gi.a1 = PI_BoldFont;
|
---|
| 1660 | GrAlines["boldfont"] = gi;
|
---|
| 1661 | gi.a1 = PI_ItalicFont;
|
---|
| 1662 | GrAlines["italicfont"] = gi;
|
---|
| 1663 | gi.a2 = PI_SmallSizeFont;
|
---|
| 1664 | gi.a1 = PI_RomanFont;
|
---|
| 1665 | GrAlines["smallfont"] = gi;
|
---|
| 1666 | gi.a1 = PI_BoldFont;
|
---|
| 1667 | GrAlines["smallboldfont"] = gi;
|
---|
| 1668 | gi.a1 = PI_ItalicFont;
|
---|
| 1669 | GrAlines["smallitalicfont"] = gi;
|
---|
| 1670 | gi.a2 = PI_BigSizeFont;
|
---|
| 1671 | gi.a1 = PI_RomanFont;
|
---|
| 1672 | GrAlines["bigfont"] = gi;
|
---|
| 1673 | gi.a1 = PI_BoldFont;
|
---|
| 1674 | GrAlines["bigboldfont"] = gi;
|
---|
| 1675 | gi.a1 = PI_ItalicFont;
|
---|
| 1676 | GrAlines["bigitalicfont"] = gi;
|
---|
[192] | 1677 | gi.a2 = PI_HugeSizeFont;
|
---|
| 1678 | gi.a1 = PI_RomanFont;
|
---|
| 1679 | GrAlines["hugefont"] = gi;
|
---|
| 1680 | gi.a1 = PI_BoldFont;
|
---|
| 1681 | GrAlines["hugeboldfont"] = gi;
|
---|
| 1682 | gi.a1 = PI_ItalicFont;
|
---|
| 1683 | GrAlines["hugeitalicfont"] = gi;
|
---|
[165] | 1684 |
|
---|
| 1685 |
|
---|
| 1686 | // Les markers
|
---|
[176] | 1687 | const char* mrkn[11] = { "dotmarker", "plusmarker", "crossmarker",
|
---|
| 1688 | "circlemarker", "fcirclemarker", "boxmarker", "fboxmarker",
|
---|
| 1689 | "trianglemarker", "ftrianglemarker", "starmarker", "fstarmarker"};
|
---|
[165] | 1690 | PIMarker mrk[11] = { PI_DotMarker, PI_PlusMarker, PI_CrossMarker,
|
---|
| 1691 | PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,
|
---|
| 1692 | PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker};
|
---|
| 1693 |
|
---|
| 1694 | gi.a2 = 0;
|
---|
| 1695 | gi.a1 = PI_NotDefMarker;
|
---|
| 1696 | GrAmarkers["defmarker"] = gi;
|
---|
| 1697 |
|
---|
| 1698 | for(int j=0; j<11; j++) {
|
---|
| 1699 | string smrk;
|
---|
| 1700 | char buff[16];
|
---|
| 1701 | for(int m=1; m<10; m+=2) {
|
---|
| 1702 | sprintf(buff,"%d",m);
|
---|
| 1703 | smrk = (string)mrkn[j] + (string)buff;
|
---|
| 1704 | gi.a1 = mrk[j]; gi.a2 = m;
|
---|
| 1705 | GrAmarkers[smrk] = gi;
|
---|
| 1706 | }
|
---|
| 1707 | }
|
---|
| 1708 |
|
---|
| 1709 | // Les tables de couleurs
|
---|
| 1710 | gi.a2 = 0;
|
---|
| 1711 | gi.a1 = CMAP_OTHER;
|
---|
| 1712 | GrAcmap["defcmap"] = gi;
|
---|
| 1713 | gi.a1 = CMAP_GREY32;
|
---|
| 1714 | GrAcmap["grey32"] = gi;
|
---|
| 1715 | gi.a1 = CMAP_GREYINV32;
|
---|
| 1716 | GrAcmap["greyinv32"] = gi;
|
---|
| 1717 | gi.a1 = CMAP_COLRJ32;
|
---|
| 1718 | GrAcmap["colrj32"] = gi;
|
---|
| 1719 | gi.a1 = CMAP_COLBR32;
|
---|
| 1720 | GrAcmap["colbr32"] = gi;
|
---|
| 1721 | gi.a1 = CMAP_GREY128;
|
---|
| 1722 | GrAcmap["grey128"] = gi;
|
---|
| 1723 | gi.a1 = CMAP_GREYINV128;
|
---|
| 1724 | GrAcmap["greyinv128"] = gi;
|
---|
| 1725 | gi.a1 = CMAP_COLRJ128;
|
---|
| 1726 | GrAcmap["colrj128"] = gi;
|
---|
| 1727 | gi.a1 = CMAP_COLBR128;
|
---|
| 1728 | GrAcmap["colbr128"] = gi;
|
---|
| 1729 |
|
---|
[203] | 1730 | // La valeur de zoom
|
---|
[165] | 1731 | gi.a2 = 0;
|
---|
| 1732 | gi.a1 = 0;
|
---|
| 1733 | GrAzoom["defzoom"] = gi;
|
---|
| 1734 | gi.a1 = 1;
|
---|
| 1735 | GrAzoom["zoomx1"] = gi;
|
---|
| 1736 | gi.a1 = 2;
|
---|
| 1737 | GrAzoom["zoomx2"] = gi;
|
---|
| 1738 | gi.a1 = 3;
|
---|
| 1739 | GrAzoom["zoomx3"] = gi;
|
---|
| 1740 | gi.a1 = 4;
|
---|
| 1741 | GrAzoom["zoomx4"] = gi;
|
---|
| 1742 | gi.a1 = 5;
|
---|
| 1743 | GrAzoom["zoomx5"] = gi;
|
---|
| 1744 | gi.a1 = -2;
|
---|
| 1745 | GrAzoom["zoom/2"] = gi;
|
---|
| 1746 | gi.a1 = -3;
|
---|
| 1747 | GrAzoom["zoom/3"] = gi;
|
---|
| 1748 | gi.a1 = -4;
|
---|
| 1749 | GrAzoom["zoom/4"] = gi;
|
---|
| 1750 | gi.a1 = -5;
|
---|
| 1751 | GrAzoom["zoom/5"] = gi;
|
---|
[203] | 1752 |
|
---|
| 1753 | // Attributs d'axes
|
---|
| 1754 | gi.a2 = 0;
|
---|
| 1755 | gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels);
|
---|
| 1756 | GrAaxes["stdaxes"] = gi;
|
---|
| 1757 | GrAaxes["defaxes"] = gi;
|
---|
| 1758 | GrAaxes["boxaxes"] = gi;
|
---|
| 1759 | gi.a1 = (int)kAxesDflt;
|
---|
| 1760 | GrAaxes["simpleaxes"] = gi;
|
---|
| 1761 | gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels | kGridOn);
|
---|
| 1762 | GrAaxes["boxaxesgrid"] = gi;
|
---|
| 1763 |
|
---|
| 1764 | gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks);
|
---|
| 1765 | GrAaxes["fineaxes"] = gi;
|
---|
| 1766 | gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks | kGridOn);
|
---|
| 1767 | GrAaxes["grid"] = gi;
|
---|
| 1768 | GrAaxes["fineaxesgrid"] = gi;
|
---|
| 1769 |
|
---|
[165] | 1770 | }
|
---|
[333] | 1771 |
|
---|
| 1772 |
|
---|
| 1773 | // SANS_EVOLPLANCK Attention !
|
---|
| 1774 | #include "pclassids.h"
|
---|
| 1775 |
|
---|
| 1776 | /* --Methode-- */
|
---|
| 1777 | char* Services2NObjMgr::PClassIdToClassName(int cid)
|
---|
| 1778 | {
|
---|
| 1779 | switch (cid) {
|
---|
| 1780 | case ClassId_Poly1 :
|
---|
| 1781 | return("Poly1");
|
---|
| 1782 | case ClassId_Poly2 :
|
---|
| 1783 | return("Poly2");
|
---|
| 1784 | case ClassId_Matrix :
|
---|
| 1785 | return("Matrix");
|
---|
| 1786 | case ClassId_Vector :
|
---|
| 1787 | return("Vector");
|
---|
| 1788 |
|
---|
| 1789 | case ClassId_DVList :
|
---|
| 1790 | return("DVList");
|
---|
| 1791 |
|
---|
| 1792 | case ClassId_Histo1D :
|
---|
| 1793 | return("Histo1D");
|
---|
| 1794 | case ClassId_Histo2D :
|
---|
| 1795 | return("Histo2D");
|
---|
| 1796 | case ClassId_HProf :
|
---|
| 1797 | return("HProf");
|
---|
| 1798 | case ClassId_NTuple :
|
---|
| 1799 | return("NTuple");
|
---|
| 1800 | case ClassId_GeneralFitData :
|
---|
| 1801 | return("GeneralFitData");
|
---|
| 1802 |
|
---|
| 1803 | case ClassId_Image :
|
---|
| 1804 | return("RzImage");
|
---|
| 1805 | case ClassId_Image + kuint_1 :
|
---|
| 1806 | return("ImageU1");
|
---|
| 1807 | case ClassId_Image + kint_1 :
|
---|
| 1808 | return("ImageI1");
|
---|
| 1809 | case ClassId_Image + kuint_2 :
|
---|
| 1810 | return("ImageU2");
|
---|
| 1811 | case ClassId_Image + kint_2 :
|
---|
| 1812 | return("ImageI2");
|
---|
| 1813 | case ClassId_Image + kuint_4 :
|
---|
| 1814 | return("ImageU4");
|
---|
| 1815 | case ClassId_Image + kint_4 :
|
---|
| 1816 | return("ImageI4");
|
---|
| 1817 | case ClassId_Image + kr_4 :
|
---|
| 1818 | return("ImageR4");
|
---|
| 1819 | case ClassId_Image + kr_8 :
|
---|
| 1820 | return("ImageR8");
|
---|
| 1821 |
|
---|
| 1822 | case ClassId_ZFidu :
|
---|
| 1823 | return("ZFidu");
|
---|
| 1824 |
|
---|
| 1825 | case ClassId_StarList :
|
---|
| 1826 | return("StarList");
|
---|
| 1827 | case ClassId_Transfo :
|
---|
| 1828 | return("Transfo");
|
---|
| 1829 | case ClassId_PSF :
|
---|
| 1830 | return("PSF");
|
---|
| 1831 |
|
---|
| 1832 |
|
---|
| 1833 | // - Ajout objet PPF
|
---|
| 1834 | default:
|
---|
| 1835 | return("AnyDataObj");
|
---|
| 1836 | }
|
---|
| 1837 | }
|
---|
| 1838 |
|
---|