Changeset 3135 in Sophya
- Timestamp:
- Jan 12, 2007, 7:36:32 PM (19 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/nomherradapter.cc
r3125 r3135 102 102 PIDrawer* NOMAdapter_HistoErr::GetDrawer(string & dopt) 103 103 { 104 /* A_FAIRE_CMV -> + des options pour choisir val / err2 / nb 105 pour les options, il faut rajouter des arguments ou methodes a 106 la classe HistoErrWrapper() et modifier la methode operator()(int_4 i) Error() 107 108 Si besoin, modifier dopt apres... dopt = "fcirclemarker5 " + dopt; 109 */ 104 dopt = "thinline " + dopt; 110 105 HistoErrWrapper* hw = new HistoErrWrapper(mHerr, false); // false: le Wrapper ne delete pas l'objet mHerr 111 106 PIHisto * pih = new PIHisto(hw, true); // true: PIHisto delete l'objet HistoErrWrapper hw -
trunk/SophyaPI/PIext/pawexecut.cc
r3125 r3135 309 309 usage += "\n h/err namehisto expr_func"; 310 310 usage += "\n Related commands: h/set/err"; 311 piac->RegisterCommand(kw,usage,this,hgrp); 312 313 kw = "herr/correl"; 314 usage = "Perform bin mean computation for HistoErr and Histo2DErr"; 315 usage += "\n herr/correl nameherr todo"; 316 usage += "\n todo = +1 : compute mean"; 317 usage += "\n = -1 : cancel computation"; 311 318 piac->RegisterCommand(kw,usage,this,hgrp); 312 319 … … 375 382 } else if(kw == "h/err") { 376 383 h_err(tokens); return(0); 384 } else if(kw == "herr/correl") { 385 herr_correl(tokens); return(0); 377 386 } else return(1); 378 387 } … … 2414 2423 2415 2424 } 2425 2426 /* methode */ 2427 void PAWExecutor::herr_correl(vector<string>& tokens) 2428 // Pour appliquer ToCorrel ou FromCorrel a un HistoErr ou Histo2DErr 2429 { 2430 int_4 tks = tokens.size(); 2431 if(tks<1) 2432 {cout<<"Usage: herr_correl namehisterr [+1,-1]"<<endl; 2433 return;} 2434 2435 NamedObjMgr omg; 2436 AnyDataObj* mobj = omg.GetObj(tokens[0]); 2437 if( mobj==NULL) 2438 {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl; 2439 return;} 2440 2441 int sens = 1; 2442 if(tks>1) sens = atoi(tokens[1].c_str()); 2443 2444 HistoErr *herr = dynamic_cast<HistoErr*>(mobj); 2445 Histo2DErr *herr2 = dynamic_cast<Histo2DErr*>(mobj); 2446 2447 if(sens>=0) { 2448 if(herr) herr->ToCorrel(); 2449 else if(herr2) herr2->ToCorrel(); 2450 } else { 2451 if(herr) herr->FromCorrel(); 2452 else if(herr2) herr2->FromCorrel(); 2453 } 2454 2455 int ncorrel = 0; 2456 if(herr) ncorrel = herr->NCorrel(); 2457 else if(herr2) ncorrel = herr2->NCorrel(); 2458 cout<<tokens[0]<<" : ncorrel = "<<ncorrel<<endl; 2459 2460 } -
trunk/SophyaPI/PIext/pawexecut.h
r3058 r3135 47 47 void h_set(string dum,vector<string>& tokens); 48 48 void h_err(vector<string>& tokens); 49 void herr_correl(vector<string>& tokens); 49 50 int_4 decodepawstring(string tokens,string& nameobj 50 51 ,string& xexp,string& yexp,string& zexp); -
trunk/SophyaPI/PIext/phistwrapper.h
r3132 r3135 31 31 virtual r_8 Value(int_4 i) = 0; 32 32 virtual r_8 Error(int_4 i) = 0; 33 virtual r_8 NbEntries(int_4 i) = 0; 33 34 34 35 inline r_8 operator()(int_4 i) { return ( Value(i)*mScale+mOff ); } -
trunk/SophyaPI/PIext/pihisto.cc
r3132 r3135 41 41 mScale = atof(opts.substr(7).c_str()); 42 42 } 43 else if(opt [k].substr(0,8) == "hoffset=") {43 else if(opts.substr(0,8) == "hoffset=") { 44 44 mOff = atof(opts.substr(8).c_str()); 45 45 } … … 72 72 //-- 73 73 //++ 74 // PIHisto(P1DHistoWrapper* histo , bool ad=false)75 // Constructeur. Si "ad == true", l'objet "histo " est détruit par74 // PIHisto(P1DHistoWrapper* histowp, bool ad=false) 75 // Constructeur. Si "ad == true", l'objet "histowp" est détruit par 76 76 // le destructeur de l'objet "PIHisto" 77 // Note : "histo " doit être créé par new77 // Note : "histowp" doit être créé par new 78 78 // 79 // void SetStats(bool fg=true)80 // Active/ désactive l'indication des statistiques d'histogramme81 79 //-- 82 80 83 81 84 PIHisto::PIHisto(P1DHistoWrapper* histo, bool ad) 85 : PIDrawer(), mHisto(histo) 86 { 87 mAdDO = ad; // Flag pour suppression automatique de mHisto 88 SetStats(); 89 SetError(); 90 SetFilled(); 91 SetStatPosOffset(); 82 PIHisto::PIHisto(P1DHistoWrapper* histowp, bool ad) 83 : PIDrawer(), mHistoWp(histowp) 84 { 85 mAdDO = ad; // Flag pour suppression automatique de mHistoWp 86 stats=true; 87 // todraw = 0 draw scaled and offset value (default) 88 // = 1 draw bin content 89 // = 2 draw bin error (if exist) 90 // = 3 draw number of entries in the bin (if exist) 91 todraw=0; 92 // error = -1 pas de barre d'erreur 93 // 1 barres d'erreurs, 94 // 0 barres d'erreurs automatiques (si markeur demande) 95 error=0; 96 filled=false; 97 spoX=-0.01; spoY=-0.01; 92 98 SetName("HistoDrw"); 93 99 } … … 95 101 PIHisto::~PIHisto() 96 102 { 97 if(mAdDO) delete mHisto ;103 if(mAdDO) delete mHistoWp; 98 104 } 99 105 … … 101 107 PIHisto::UpdateLimits() 102 108 { 103 if (!mHisto ) return;104 double v 1,v2,hmin,hmax;109 if (!mHistoWp) return; 110 double v,hmin,hmax; 105 111 hmin = 9.e39; 106 112 hmax = -9.e39; 107 for (int i=1; i<mHisto->NBins(); i++) { 108 v1 = (*mHisto)(i); //DEL - mHisto->Error(i); 109 v2 = (*mHisto)(i); //DEL + mHisto->Error(i); 110 if(v1<hmin) hmin = v1; 111 if(v2>hmax) hmax = v2; 113 for (int i=1; i<mHistoWp->NBins(); i++) { 114 v = DrawVal(i); 115 if(v<hmin) hmin = v; 116 if(v>hmax) hmax = v; 112 117 } 113 118 // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log 114 v 1= 0.1*(hmax-hmin);115 hmin -= v 1; hmax += v1;119 v = 0.1*(hmax-hmin); 120 hmin -= v; hmax += v; 116 121 117 122 if(hmax<=hmin) hmax = hmin+1.; 118 SetLimits(mHisto ->XMin(), mHisto->XMax(), hmin, hmax);123 SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax); 119 124 } 120 125 … … 124 129 if (axesFlags != kAxesNone) DrawAxes(g); 125 130 126 if (!mHisto ) return;127 if (mHisto ->NBins()<=0) return;131 if (!mHistoWp) return; 132 if (mHistoWp->NBins()<=0) return; 128 133 129 mHisto ->Update();134 mHistoWp->Update(); 130 135 131 136 bool oktrace=false; … … 136 141 bool drawmarker=false; 137 142 if (GetGraphicAtt().GetMarker() != PI_NotDefMarker) drawmarker = true; 138 //RZDEL || (typeid(*mHisto) == typeid(HProf)) ) drawmarker = true;139 143 // Tracer des erreurs ? 140 144 bool drawerr=false; 141 145 if(error==0) { // Gestion automatique des erreurs 142 //RZDEL Tracer les erreurs si HProf143 //RZDEL if( typeid(*mHisto)==typeid(HProf) ) drawerr=true;144 146 // Trace les erreurs si marqueurs demandes 145 147 if(drawmarker) drawerr=true; … … 156 158 if(drawfill) { 157 159 oktrace = true; 158 for(int i=0; i<mHisto ->NBins(); i++) {159 double left = mHisto ->BinLowEdge(i);160 double width = mHisto ->BinWidth();160 for(int i=0; i<mHistoWp->NBins(); i++) { 161 double left = mHistoWp->BinLowEdge(i); 162 double width = mHistoWp->BinWidth(); 161 163 double bottom = 0; 162 double height = (*mHisto)(i);164 double height = DrawVal(i); 163 165 g->DrawFBox(left,bottom,width,height); 164 166 } … … 168 170 if(drawmarker) { 169 171 double x1,y1; oktrace = true; 170 for(int i=0; i<mHisto ->NBins(); i++) {171 x1 = mHisto ->BinCenter(i);172 y1 = (*mHisto)(i);172 for(int i=0; i<mHistoWp->NBins(); i++) { 173 x1 = mHistoWp->BinCenter(i); 174 y1 = DrawVal(i); 173 175 g->DrawMarker(x1,y1); 174 176 } … … 179 181 if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 180 182 double x1,x2,y1,y2; oktrace = true; 181 double bw = mHisto ->BinWidth();182 for(int i=0; i<mHisto ->NBins(); i++) {183 if(mHisto ->Error(i)>0.) {183 double bw = mHistoWp->BinWidth(); 184 for(int i=0; i<mHistoWp->NBins(); i++) { 185 if(mHistoWp->Error(i)>0.) { 184 186 // barres d'erreur verticales 185 x1 = x2 = mHisto ->BinCenter(i);186 y1 = (*mHisto)(i) - mHisto->Error(i);187 y2 = (*mHisto)(i) + mHisto->Error(i);187 x1 = x2 = mHistoWp->BinCenter(i); 188 y1 = DrawVal(i) - mHistoWp->Error(i); 189 y2 = DrawVal(i) + mHistoWp->Error(i); 188 190 g->DrawLine(x1,y1, x1, y2); 189 191 // limites de barres d'erreurs (horizontales) … … 197 199 // Trace de la ligne continue si demandee 198 200 if(drawpline) { 199 PIGrCoord* x1 = new PIGrCoord[2*mHisto ->NBins()+2];200 PIGrCoord* y1 = new PIGrCoord[2*mHisto ->NBins()+2];201 double dx = mHisto ->BinWidth();201 PIGrCoord* x1 = new PIGrCoord[2*mHistoWp->NBins()+2]; 202 PIGrCoord* y1 = new PIGrCoord[2*mHistoWp->NBins()+2]; 203 double dx = mHistoWp->BinWidth(); 202 204 int npt=0; 203 x1[npt] = mHisto ->BinLowEdge(0);205 x1[npt] = mHistoWp->BinLowEdge(0); 204 206 y1[npt] = 0; 205 207 npt++; 206 for(int i=0; i<mHisto ->NBins(); i++) {207 x1[npt] = mHisto ->BinLowEdge(i);208 y1[npt] = (*mHisto)(i);208 for(int i=0; i<mHistoWp->NBins(); i++) { 209 x1[npt] = mHistoWp->BinLowEdge(i); 210 y1[npt] = DrawVal(i); 209 211 npt++; 210 212 x1[npt] = (double)x1[npt-1] + dx; … … 238 240 for( k=0; k<opt.size(); k++ ) { 239 241 string opts = opt[k]; 240 if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);242 if(opts=="sta" || opts=="stat" || opts=="stats") stats=true; 241 243 else if( opts=="nsta" || opts=="nstat" 242 || opts=="nostat" || opts=="nostats") SetStats(false);243 else if(opts=="err") SetError(1);244 else if(opts=="noerr" || opts=="nerr") SetError(-1);245 else if(opts=="autoerr") SetError(0);246 else if(opts=="fill") SetFilled(true);247 else if(opts=="nofill" || opts=="nfill") SetFilled(false);244 || opts=="nostat" || opts=="nostats") stats=false; 245 else if(opts=="err") error=1; 246 else if(opts=="noerr" || opts=="nerr") error=-1; 247 else if(opts=="autoerr") error=0; 248 else if(opts=="fill") filled=true; 249 else if(opts=="nofill" || opts=="nfill") filled=false; 248 250 else if(opts.substr(0,11) == "statposoff=") { 249 251 float xo=0., yo=0.; 250 252 sscanf(opts.substr(11).c_str(),"%g,%g",&xo, &yo); 251 SetStatPosOffset(xo, yo); 252 } 253 spoX=xo; spoY=yo; 254 } 255 else if(opts.substr(0,6) == "draw=v") todraw = 1; 256 else if(opts.substr(0,6) == "draw=e") todraw = 2; 257 else if(opts.substr(0,6) == "draw=n") todraw = 3; 258 else if(opts.substr(0,5) == "draw=" ) todraw = 0; 253 259 else { 254 260 ndec--; … … 264 270 // Decodage des options par le histo-wrapper 265 271 int ndec2 = 0; 266 if ( ( optsz1-ndec1-ndec > 0) && (mHisto ) ) {267 ndec2 = mHisto ->DecodeOptionString(opt, rmdecopt);272 if ( ( optsz1-ndec1-ndec > 0) && (mHistoWp) ) { 273 ndec2 = mHistoWp->DecodeOptionString(opt, rmdecopt); 268 274 } 269 275 return(ndec+ndec1+ndec2); … … 280 286 else if(error==1) opt.push_back("err"); 281 287 if(filled) opt.push_back("fill"); else opt.push_back("nofill"); 288 if(todraw==1) opt.push_back("draw=v"); 289 else if(todraw==2) opt.push_back("draw=e"); 290 else if(todraw==3) opt.push_back("draw=n"); 282 291 283 292 char str[256]; sprintf(str,"statposoff=%g,%g",spoX,spoY); … … 291 300 { 292 301 info += " ---- PIHisto options help info : \n" ; 302 info += " draw=v: draw bin content\n"; 303 info += " =e: draw bin error (if exist)\n"; 304 info += " =n: draw number of entries in the bin (if exist)\n"; 305 info += " default: draw scaled and offset value (default)"; 293 306 info += " sta,stat,stats: activate statistic display\n"; 294 307 info += " nsta,nstat,nostat,nostats: deactivate statistic display\n"; 295 308 info += " err / noerr,nerr : draw, do not draw error bars\n"; 296 info += " autoerr : draw error bars if Marker drawing requested OR Profile histo\n";309 info += " autoerr : draw error bars if Marker drawing requested\n"; 297 310 info += " fill / nofill,nfill : fill, do not fill bars with selected color\n"; 298 311 info += " statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n"; … … 310 323 PIHisto::DrawStats(PIGraphicUC* g) 311 324 { 312 if (!mHisto ) return;325 if (!mHistoWp) return; 313 326 // if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 314 327 g->SelLine(PI_ThinLine); … … 319 332 double cH = (double)g->GetFontHeight(a,d); 320 333 vector<string> lines; 321 int nlig = mHisto ->GetStatInfoAsText(lines);334 int nlig = mHistoWp->GetStatInfoAsText(lines); 322 335 if (nlig < 1) return; 323 336 … … 361 374 } 362 375 363 364 365 376 /* --Methode-- */ 366 double PIHisto::GetDistanceToPoint(double x, double y) 367 { 368 if (!mHisto) return 1.e+9; 377 double 378 PIHisto::GetDistanceToPoint(double x, double y) 379 { 380 if (!mHistoWp) return 1.e+9; 369 381 370 382 double dist = -1.e+18; 371 for(int i=0; i<mHisto ->NBins(); i++) {372 double xp=mHisto ->BinCenter(i);373 double yp= (*mHisto)(i);383 for(int i=0; i<mHistoWp->NBins(); i++) { 384 double xp=mHistoWp->BinCenter(i); 385 double yp=DrawVal(i); 374 386 xp = (xp-x)/(XMax()-XMin())/0.5; 375 387 yp = (yp-y)/(YMax()-YMin())/0.5; … … 379 391 dist=sqrt(fabs(dist)); 380 392 //cout<<dist<<"PIHisto: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax() 381 // <<" NBins="<<mHisto ->NBins()<<endl;393 // <<" NBins="<<mHistoWp->NBins()<<endl; 382 394 //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<endl; 383 395 -
trunk/SophyaPI/PIext/pihisto.h
r3125 r3135 13 13 class PIHisto : public PIDrawer { 14 14 public: 15 PIHisto(P1DHistoWrapper* histo , bool ad=true);15 PIHisto(P1DHistoWrapper* histowp, bool ad=true); 16 16 virtual ~PIHisto(); 17 17 virtual void Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax); 18 18 virtual void UpdateLimits(); 19 inline void SetStats(bool fg=true) {stats=fg;} 20 inline void SetStatPosOffset(float ofx=-0.01, float ofy=-0.01) 21 {spoX=ofx; spoY=ofy; } 22 // fg=-1 pas de barre d'erreur, 1=barres d'erreurs, 23 // 0=barres d'erreurs automatiques: trace si HProf ou markeur demande 24 inline void SetError(short fg=0) {error=fg;} 25 inline void SetFilled(bool fg=false) {filled=fg;} 26 inline P1DHistoWrapper* HistoWrapper() {return(mHisto);} 19 20 inline P1DHistoWrapper* HistoWrapper() {return(mHistoWp);} 21 22 // ce qu'on plot 23 double DrawVal(int_4 i) { 24 if(todraw==1) return mHistoWp->Value(i); 25 if(todraw==2) return mHistoWp->Error(i); 26 if(todraw==3) return mHistoWp->NbEntries(i); 27 return (*mHistoWp)(i); 28 } 27 29 28 30 // Methode de decodage des options … … 36 38 protected: 37 39 virtual void DrawStats(PIGraphicUC* g); 38 P1DHistoWrapper* mHisto ;40 P1DHistoWrapper* mHistoWp; 39 41 bool mAdDO; 40 42 bool stats,filled; 41 short error ;43 short error,todraw; 42 44 float spoX, spoY; // Stat pos offset par rapport a position defaut 43 45 }; -
trunk/SophyaPI/PIext/piinit.cc
r3024 r3135 5 5 #include "servnobjm.h" 6 6 #include "nomhistadapter.h" 7 #include "nomherradapter.h" 7 8 #include "nomgfdadapter.h" 8 9 #include "nomimagadapter.h" … … 50 51 serv->RegisterClass(new Histo, new NOMAdapter_Histo ); 51 52 serv->RegisterClass(new HProf, new NOMAdapter_Histo ); 52 serv->RegisterClass(new HistoErr, new NOMAdapter_Histo );53 53 serv->RegisterClass(new Histo2D, new NOMAdapter_Histo2D ); 54 55 serv->RegisterClass(new HistoErr, new NOMAdapter_HistoErr ); 56 serv->RegisterClass(new Histo2DErr, new NOMAdapter_Histo2DErr ); 57 54 58 serv->RegisterClass(new NTuple, new NOMAdapter_NTuple ); 55 59 -
trunk/SophyaPI/PIext/sohiswrap.h
r3132 r3135 25 25 { 26 26 if (h == NULL) throw NullPtrError("HistoWrapper(Histo* h = NULL)"); 27 mHis = h; mAD = ad; 27 mHis = h; 28 mHpr = dynamic_cast<HProf*>(h); 29 mAD = ad; 28 30 } 29 31 ~HistoWrapper() { if (mAD) delete mHis; } … … 40 42 virtual r_8 Value(int_4 i) { return (*mHis)(i) ; } 41 43 virtual r_8 Error(int_4 i) { return mHis->Error(i) ; } 44 virtual r_8 NbEntries(int_4 i) { if(mHpr) return mHpr->SumW(i); else return 0.; } 42 45 43 46 virtual void Update() { mHis->UpdateHisto(); } … … 59 62 // pointeur sur l'objet histo 60 63 inline Histo* getHisto() { return mHis; } 64 61 65 protected: 62 66 Histo* mHis; 67 HProf* mHpr; 63 68 bool mAD; 64 69 }; … … 87 92 virtual r_8 Value(int_4 i) { return (*mHis)(i) ; } 88 93 virtual r_8 Error(int_4 i) { return mHis->Error(i) ; } 89 90 // CMV $CHECK$ pas besoin ? virtual void Update() { } 94 virtual r_8 NbEntries(int_4 i) { return mHis->NEntBin(i) ; } 91 95 92 96 // ajoute des lignes de texte avec les infos statistiques 93 97 virtual int GetStatInfoAsText(vector<string> & text) 94 98 { 95 // CMV $CHECK$ Y-a-t il qque chose a ecrire ? 96 string s = "HistoErr"; 97 text.push_back(s); 99 char label[64]; string s; 100 101 sprintf(label, "NCor= %d",mHis->NCorrel()); 102 s = label; text.push_back(s); 103 98 104 return 1; 99 105 } … … 101 107 // pointeur sur l'objet histo 102 108 inline HistoErr* getHistoErr() { return mHis; } 109 103 110 protected: 104 111 HistoErr* mHis;
Note:
See TracChangeset
for help on using the changeset viewer.