Changeset 3135 in Sophya


Ignore:
Timestamp:
Jan 12, 2007, 7:36:32 PM (19 years ago)
Author:
cmv
Message:

suite du display des HistoErr avec Wrapper cmv 12/01/07

Location:
trunk/SophyaPI/PIext
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/nomherradapter.cc

    r3125 r3135  
    102102PIDrawer* NOMAdapter_HistoErr::GetDrawer(string & dopt)
    103103{
    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   */
     104dopt = "thinline " + dopt;
    110105HistoErrWrapper* hw = new HistoErrWrapper(mHerr, false); // false: le Wrapper ne delete pas l'objet mHerr
    111106PIHisto * pih = new PIHisto(hw, true); // true: PIHisto delete l'objet HistoErrWrapper hw
  • trunk/SophyaPI/PIext/pawexecut.cc

    r3125 r3135  
    309309usage += "\n h/err namehisto expr_func";
    310310usage += "\n  Related commands: h/set/err"; 
     311piac->RegisterCommand(kw,usage,this,hgrp);
     312
     313kw = "herr/correl";
     314usage = "Perform bin mean computation for HistoErr and Histo2DErr";
     315usage += "\n herr/correl nameherr todo";
     316usage += "\n    todo = +1 : compute mean";
     317usage += "\n         = -1 : cancel computation";
    311318piac->RegisterCommand(kw,usage,this,hgrp);
    312319
     
    375382} else if(kw == "h/err") {
    376383  h_err(tokens); return(0);
     384} else if(kw == "herr/correl") {
     385  herr_correl(tokens); return(0);
    377386} else return(1);
    378387}
     
    24142423
    24152424}
     2425
     2426/* methode */
     2427void 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  
    4747  void  h_set(string dum,vector<string>& tokens);
    4848  void  h_err(vector<string>& tokens);
     49  void  herr_correl(vector<string>& tokens);
    4950  int_4 decodepawstring(string tokens,string& nameobj
    5051                       ,string& xexp,string& yexp,string& zexp);
  • trunk/SophyaPI/PIext/phistwrapper.h

    r3132 r3135  
    3131  virtual r_8 Value(int_4 i) = 0;
    3232  virtual r_8 Error(int_4 i) = 0;
     33  virtual r_8 NbEntries(int_4 i) = 0;
    3334
    3435  inline  r_8 operator()(int_4 i) { return ( Value(i)*mScale+mOff ); }
  • trunk/SophyaPI/PIext/pihisto.cc

    r3132 r3135  
    4141      mScale = atof(opts.substr(7).c_str());
    4242    }
    43     else if(opt[k].substr(0,8) == "hoffset=") {
     43    else if(opts.substr(0,8) == "hoffset=") {
    4444      mOff = atof(opts.substr(8).c_str());
    4545    }
     
    7272//--
    7373//++
    74 // PIHisto(P1DHistoWrapper* histo, bool ad=false)
    75 //      Constructeur. Si "ad == true", l'objet "histo" est détruit par
     74// PIHisto(P1DHistoWrapper* histowp, bool ad=false)
     75//      Constructeur. Si "ad == true", l'objet "histowp" est détruit par
    7676//      le destructeur de l'objet "PIHisto"
    77 //      Note : "histo" doit être créé par new
     77//      Note : "histowp" doit être créé par new
    7878//
    79 // void  SetStats(bool fg=true)
    80 //      Active/ désactive l'indication des statistiques d'histogramme
    8179//--
    8280
    8381
    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();
     82PIHisto::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;
    9298  SetName("HistoDrw");
    9399}
     
    95101PIHisto::~PIHisto()
    96102{
    97   if(mAdDO) delete mHisto;
     103  if(mAdDO) delete mHistoWp;
    98104}
    99105
     
    101107PIHisto::UpdateLimits()
    102108{
    103   if (!mHisto)  return;
    104   double v1,v2,hmin,hmax;
     109  if (!mHistoWp)  return;
     110  double v,hmin,hmax;
    105111  hmin = 9.e39;
    106112  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;
    112117  }
    113118  // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log
    114   v1 = 0.1*(hmax-hmin);
    115   hmin -= v1;   hmax += v1;
     119  v = 0.1*(hmax-hmin);
     120  hmin -= v;   hmax += v;
    116121
    117122  if(hmax<=hmin) hmax = hmin+1.;
    118   SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax);
     123  SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax);
    119124}
    120125
     
    124129  if (axesFlags != kAxesNone) DrawAxes(g);
    125130
    126   if (!mHisto)  return;
    127   if (mHisto->NBins()<=0) return;
     131  if (!mHistoWp)  return;
     132  if (mHistoWp->NBins()<=0) return;
    128133 
    129   mHisto->Update();
     134  mHistoWp->Update();
    130135
    131136  bool oktrace=false;
     
    136141  bool drawmarker=false;
    137142  if (GetGraphicAtt().GetMarker() != PI_NotDefMarker) drawmarker = true;
    138 //RZDEL   ||  (typeid(*mHisto) == typeid(HProf)) ) drawmarker = true;
    139143  // Tracer des erreurs ?
    140144  bool drawerr=false;
    141145  if(error==0) {  // Gestion automatique des erreurs
    142     //RZDEL  Tracer les erreurs si HProf
    143 //RZDEL    if( typeid(*mHisto)==typeid(HProf) ) drawerr=true;
    144146    // Trace les erreurs si marqueurs demandes
    145147    if(drawmarker) drawerr=true;
     
    156158  if(drawfill) {
    157159    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();
    161163      double bottom = 0;
    162       double height = (*mHisto)(i);
     164      double height = DrawVal(i);
    163165      g->DrawFBox(left,bottom,width,height);
    164166    }
     
    168170  if(drawmarker) {
    169171    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);
    173175      g->DrawMarker(x1,y1);
    174176    }
     
    179181    if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
    180182    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.) {
    184186        // 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);
    188190        g->DrawLine(x1,y1, x1, y2);
    189191        // limites de barres d'erreurs (horizontales)
     
    197199  // Trace de la ligne continue si demandee
    198200  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();
    202204    int npt=0;
    203     x1[npt] = mHisto->BinLowEdge(0);
     205    x1[npt] = mHistoWp->BinLowEdge(0);
    204206    y1[npt] = 0;
    205207    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);
    209211      npt++;
    210212      x1[npt] = (double)x1[npt-1] + dx;
     
    238240  for( k=0; k<opt.size(); k++ ) {
    239241    string opts = opt[k];
    240     if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
     242    if(opts=="sta" || opts=="stat" || opts=="stats") stats=true;
    241243    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;
    248250    else if(opts.substr(0,11) == "statposoff=") {
    249251      float xo=0., yo=0.;
    250252      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;
    253259    else {
    254260      ndec--;
     
    264270  // Decodage des options par le histo-wrapper
    265271  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);
    268274  }
    269275  return(ndec+ndec1+ndec2);
     
    280286     else if(error==1) opt.push_back("err");
    281287 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");
    282291
    283292 char str[256]; sprintf(str,"statposoff=%g,%g",spoX,spoY);
     
    291300{
    292301info += " ---- PIHisto options help info : \n" ;
     302info += "  draw=v: draw bin content\n";
     303info += "      =e: draw bin error (if exist)\n";
     304info += "      =n: draw number of entries in the bin (if exist)\n";
     305info += "      default: draw scaled and offset value (default)";
    293306info += "  sta,stat,stats:            activate   statistic display\n";
    294307info += "  nsta,nstat,nostat,nostats: deactivate statistic display\n";
    295308info += "  err / noerr,nerr : draw, do not draw error bars\n";
    296 info += "  autoerr : draw error bars if Marker drawing requested OR Profile histo\n";
     309info += "  autoerr : draw error bars if Marker drawing requested\n";
    297310info += "  fill / nofill,nfill : fill, do not fill bars with selected color\n";
    298311info += "  statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
     
    310323PIHisto::DrawStats(PIGraphicUC* g)
    311324{
    312   if (!mHisto) return;
     325  if (!mHistoWp) return;
    313326  //  if (mLAtt == PI_NotDefLineAtt)  g->SelLine(PI_ThinLine);
    314327  g->SelLine(PI_ThinLine);
     
    319332  double cH = (double)g->GetFontHeight(a,d);
    320333  vector<string> lines;
    321   int nlig = mHisto->GetStatInfoAsText(lines);
     334  int nlig = mHistoWp->GetStatInfoAsText(lines);
    322335  if (nlig < 1) return;
    323336
     
    361374}
    362375
    363 
    364 
    365376/* --Methode-- */
    366 double PIHisto::GetDistanceToPoint(double x, double y)
    367 {
    368  if (!mHisto) return 1.e+9;
     377double
     378PIHisto::GetDistanceToPoint(double x, double y)
     379{
     380 if (!mHistoWp) return 1.e+9;
    369381
    370382 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);
    374386   xp = (xp-x)/(XMax()-XMin())/0.5;
    375387   yp = (yp-y)/(YMax()-YMin())/0.5;
     
    379391 dist=sqrt(fabs(dist));
    380392 //cout<<dist<<"PIHisto: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax()
    381  //    <<" NBins="<<mHisto->NBins()<<endl;
     393 //    <<" NBins="<<mHistoWp->NBins()<<endl;
    382394 //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<endl;
    383395
  • trunk/SophyaPI/PIext/pihisto.h

    r3125 r3135  
    1313class PIHisto : public PIDrawer {
    1414public:
    15                      PIHisto(P1DHistoWrapper* histo, bool ad=true);
     15                     PIHisto(P1DHistoWrapper* histowp, bool ad=true);
    1616  virtual           ~PIHisto();
    1717  virtual void       Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
    1818  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  }
    2729
    2830//   Methode de decodage des options
     
    3638protected:
    3739  virtual void       DrawStats(PIGraphicUC* g);
    38   P1DHistoWrapper*   mHisto;
     40  P1DHistoWrapper*   mHistoWp;
    3941  bool mAdDO;
    4042  bool stats,filled;
    41   short error;
     43  short error,todraw;
    4244  float spoX, spoY; // Stat pos offset par rapport a position defaut
    4345};
  • trunk/SophyaPI/PIext/piinit.cc

    r3024 r3135  
    55#include "servnobjm.h"
    66#include "nomhistadapter.h"
     7#include "nomherradapter.h"
    78#include "nomgfdadapter.h"
    89#include "nomimagadapter.h"
     
    5051  serv->RegisterClass(new Histo, new NOMAdapter_Histo );
    5152  serv->RegisterClass(new HProf, new NOMAdapter_Histo );
    52   serv->RegisterClass(new HistoErr, new NOMAdapter_Histo );
    5353  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
    5458  serv->RegisterClass(new NTuple, new NOMAdapter_NTuple );
    5559
  • trunk/SophyaPI/PIext/sohiswrap.h

    r3132 r3135  
    2525  {
    2626    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;
    2830  }
    2931  ~HistoWrapper() { if (mAD) delete mHis; }
     
    4042  virtual r_8 Value(int_4 i) { return (*mHis)(i) ; }
    4143  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.; }
    4245
    4346  virtual void Update() { mHis->UpdateHisto(); }
     
    5962  // pointeur sur l'objet histo
    6063  inline Histo* getHisto() { return mHis; }
     64
    6165protected:
    6266  Histo* mHis;
     67  HProf* mHpr;
    6368  bool mAD;
    6469};
     
    8792  virtual r_8 Value(int_4 i) { return (*mHis)(i) ; }
    8893  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) ; }
    9195
    9296  // ajoute des lignes de texte avec les infos statistiques
    9397  virtual int GetStatInfoAsText(vector<string> & text)
    9498  {
    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
    98104    return 1;
    99105  }
     
    101107  // pointeur sur l'objet histo
    102108  inline HistoErr* getHistoErr() { return mHis; }
     109
    103110protected:
    104111  HistoErr* mHis;
Note: See TracChangeset for help on using the changeset viewer.