Ignore:
Timestamp:
Jun 7, 2002, 4:21:22 PM (23 years ago)
Author:
ansari
Message:

Remplacement de l'objet poly (pb plantage ds lors du Fit) par un vecteur - Reza 7/6/2002

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ArchTOIPipe/ProcWSophya/simoffset.cc

    r2034 r2045  
    1212#include "ctimer.h"
    1313#include "ntuple.h"
     14#include "sopemtx.h"
    1415
    1516#include "flagtoidef.h"
    1617
     18
    1719SimpleOffsetEstimator::SimpleOffsetEstimator(int mwsz, int nptfit, int degpol)
    18   : poly((degpol > 1)?degpol:1)
     20  : poly((degpol > 1)?degpol+1:2)
    1921{
    2022  SetParams(mwsz, nptfit, degpol);
     
    2426  bgalcut = false;
    2527  ns_flgcut = ns_bgalcut = 0;
     28  npb_fitpoly = 0;
    2629  SavePolyNTuple();
    2730}
     
    5154  os << "\n ------------------------------------------------------ \n"
    5255     << " SimpleOffsetEstimator::PrintStatus() - MeanWSize= " << mWSz << " NPtFit="
    53      << nPtFit << " DegPoly=" << degPol << " poly.Degre()=" << poly.Degre() << endl;
     56     << nPtFit << " DegPoly=" << degPol << endl;
    5457  if (bgalcut)
    5558    os << " bGalCut = Yes , bGalMin = " << bmincut << " bGalMax= " << bmaxcut << endl;
     
    5760  TOIProcessor::PrintStatus(os);
    5861  os << " ProcessedSampleCount=" << ProcessedSampleCount()
    59      << " NS_FlgCut= " << ns_flgcut << " NS_BGalCut= " << ns_bgalcut << endl;
     62     << " NS_FlgCut= " << ns_flgcut << " NS_BGalCut= " << ns_bgalcut
     63     << " NPb_FitPoly= " << npb_fitpoly << endl;
    6064  os << " ------------------------------------------------------ " << endl; 
    6165}
     
    118122  NTuple xntp(11, nomsnt);
    119123
     124  char ans[20];
     125
    120126  try {
    121127
     
    168174    int nblk = (sne-snb+1)/wsize;
    169175    for(kb=0; kb<nblk; kb++) {
     176      //      cout << " SimpleOffsetEstimator::run - Loop " << kb << " NbBlkOK= " 
     177      //           << nbblkok << " <CR> to continue / q --> QUIT ... \n" ;
     178      //     gets(ans); if (ans[0] == 'q') break;
    170179      k = kb*wsize+snb;
    171180      //    for(k=snb;k<=sne-wsize+1;k+=wsize) {
     
    236245        fg_last_meansig = true;
    237246      }
    238      
     247
     248           
    239249      if (((nok>3.5) || fg_last_meansig) && (nbblkok >= nPtFit) ) {
    240250        // On force le fit a garder une certaine continuite
     
    248258        X0 = X;
    249259        X0 -= sn0;
    250         Vector polsave(degPol);
    251         for(int jj=0; jj<=poly.Degre(); jj++) polsave(jj) = poly[jj];
    252         try {
    253           poly.Fit(X0,Y,YErr,degPol,errCoef);
    254         }
    255         catch (CaughtSignalExc& excsig) {
    256           cout << " -- simoffset.cc/ catched CaughtSignalExc - Msg= "
    257                << excsig.Msg() << " kb=" << kb << " k=" << k << endl;
    258           cout << " X0= " << X0 << " Y=" << Y << " YErr=" << YErr << endl;
    259           for(int jj=0; jj<=poly.Degre(); jj++) poly[jj] = polsave(jj);
    260         }
     260        FitPoly(X0, Y, YErr);
    261261      }
    262262      else {
    263263        if (nbblkok < 2) {
    264264          sn0 = k+1;
    265           poly[0] = mean;
    266           for(int jj=1; jj<=poly.Degre(); jj++) poly[jj] = 0.;
     265          poly(0) = mean;
     266          for(int jj=1; jj<=degPol; jj++) poly(jj) = 0.;
    267267        }
    268268        else if (nbblkok < nPtFit) {
    269           poly[0] = 0.5*(Y(nbblkok-1)+Y(0));
    270           poly[1] = (Y(nbblkok-1) - Y(0))/(X(nbblkok-1)-X(0));
     269          poly(0) = 0.5*(Y(nbblkok-1)+Y(0));
     270          poly(1) = (Y(nbblkok-1) - Y(0))/(X(nbblkok-1)-X(0));
    271271          sn0 =  0.5*(X(nbblkok-1)+X(0));
    272           for(int jj=2; jj<=poly.Degre(); jj++) poly[jj] = 0.;
     272          for(int jj=2; jj<=degPol; jj++) poly(jj) = 0.;
    273273        }
    274274        sn_last = sn0;
    275275        y_last = poly(sn_last-sn0);
    276276      }
     277     
    277278      if (ntpoly) {    // Remplissage du XNTuple de controle
    278279        float xnt[12];
     
    282283        xnt[3] = mean;
    283284        xnt[4] = sig;
    284         xnt[5] = poly[0];
    285         xnt[6] = poly[1];
    286         xnt[7] = poly[2];
    287         xnt[8] = poly(k-sn0);
     285        xnt[5] = poly(0);
     286        xnt[6] = poly(1);
     287        xnt[7] = poly(2);
     288        xnt[8] = ApplyPoly(k-sn0);
    288289        xnt[9] = nok;
    289290        xnt[10] = nbblkok;
     
    291292      }
    292293
    293       /*
    294       if (nbblkok < 8) {
    295         cout << "------ DBG-X " << nbblkok << "," << nok << " degre=" << poly.Degre() << endl;
    296         cout << "DBG-A X0=" << X0 << endl;
    297         cout << "DBG-A Y=" << Y << endl;
    298         cout << "DBG-A YErr=" << YErr << endl;
    299         cout << "DBG-A poly= " << poly << endl;
    300       }
    301       */
    302      
     294     
    303295      if (fgincopie) putData(2, k, wsize, vin.Data(), vfg.Data());
    304296
    305297      if (kb < nPtFit/2) continue;
    306       Vector vinc;
     298      Vector vinc; 
    307299      TVector<uint_8> vfgc;
    308300      int kbs = kb-nPtFit/2;
     
    332324      // Calcul des valeurs d'offset en sortie
    333325      for(j=0; j<wsize; j++)
    334         voff(j) = poly(k+j-sn0);
     326        voff(j) = ApplyPoly(k+j-sn0);
    335327      sn_last = k+wsize;
    336       y_last = poly(sn_last-sn0);
    337 
     328      y_last = ApplyPoly(sn_last-sn0);
    338329      if (fgoffset) putData(0, k, wsize, voff.Data());
    339330      if (fgout) {
     
    341332        putData(1, k, wsize, vinc.Data(), vfgc.Data());
    342333      }
    343       /*
    344       if (fgmeany) {
    345         vout = mean;
    346         putData(4, k, wsize, vout.Data());
    347       }
    348       if (fgsigy) {
    349         vout = sig;
    350         putData(5, k, wsize, vout.Data());
    351       }
    352 
    353       if (fgmeanx) {
    354         vout = meanx;
    355         putData(6, k, wsize, vout.Data());
    356       }
    357       */
    358334
    359335      klast+=wsize;
    360336      totnscount+=wsize;
    361337      totnbblock++;
    362      
     338      //      cout << " SimpleOffset::run " << totnbblock << " totnscount " << totnscount << endl;
    363339    } // Fin boucle sur les samples, par pas de wsize
    364340
     
    379355
    380356      for(j=0; j<wsize; j++)
    381         voff(j) = poly(k+j-sn0);
     357        voff(j) = ApplyPoly(k+j-sn0);
    382358      if (fgoffset) putData(0, k, wsize, voff.Data());
    383359      if (fgincopie) putData(2, k, wsize, vin.Data(), vfg.Data());
     
    425401  }
    426402}
     403
     404
     405double SimpleOffsetEstimator::ApplyPoly(double x)
     406{
     407  if (degPol == 0) return(poly(0));
     408  else if (degPol == 1)  return(poly(0)+poly(1)*x);
     409  else if (degPol == 2)  return(poly(0)+poly(1)*x+poly(2)*x*x);
     410  else if (degPol == 3)  return(poly(0)+poly(1)*x+poly(2)*x*x+poly(3)*x*x*x);
     411  else {
     412    double ret = poly(0);
     413    double xx = x;
     414    for(int k=1; k<degPol+1; k++)  { ret += xx*poly(k);  xx *= x; }
     415    return(ret);
     416  }
     417}
     418
     419// Fonction pour faire LinFit d'un polynome
     420r_8 rzpoly_f(uint_4 k, r_8 x )
     421{
     422  if (k == 0) return(1.);
     423  else if (k == 1) return(x);
     424  else if (k == 2) return(x*x);
     425  else if (k == 3) return(x*x*x);
     426  else {
     427    r_8 ret = x;
     428    for(int i=1; i<k; i++) ret *= x;
     429    return(ret);
     430  }
     431}
     432
     433void SimpleOffsetEstimator::FitPoly(Vector& X0, Vector& Y, Vector& YErr)
     434{
     435  Vector cpol(degPol+1);
     436  Vector errcoef(degPol+1);
     437  LinFitter<r_8> lfit;
     438  try {
     439    lfit.LinFit(X0, Y, YErr, degPol+1, rzpoly_f, cpol, errcoef);
     440    poly = cpol;
     441  }
     442  catch (PException & exc) {
     443    if (npb_fitpoly < 50)
     444      cout << " -- SimpleOffsetEstimator::FitPoly/ Catched Exception "
     445           << (string)typeid(exc).name() << "\n .... Msg= " << exc.Msg() << endl;
     446    if (npb_fitpoly < 10)
     447      cout << " X0= " << X0 << " Y=" << Y << " YErr=" << YErr << endl;
     448    npb_fitpoly++;
     449  }
     450  return;
     451}
     452
Note: See TracChangeset for help on using the changeset viewer.