Changeset 1479 in Sophya for trunk/ArchTOIPipe/ProcWSophya


Ignore:
Timestamp:
Apr 27, 2001, 2:52:15 AM (24 years ago)
Author:
ansari
Message:

debug deglitcher - Ajout Filtre Fourier (SimpleFourierFilter) - Reza 27/4/2001

Location:
trunk/ArchTOIPipe/ProcWSophya
Files:
2 edited

Legend:

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

    r1478 r1479  
    55#include "pexceptions.h"
    66#include "ctimer.h"
    7 
    8 SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt)
     7#include "fftpserver.h"
     8
     9SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt, int minnpt)
    910{
    1011  SetWSize(wsz);
    11   SetDetectionParam(ns, ns/2., maxnpt);
     12  SetDetectionParam(ns, ns/2., maxnpt, minnpt);
    1213  SetRange(-9.e39, 9.e39);
    1314  RepBadSamples(true, true);
     
    2425}
    2526
    26 void SimpleDeglitcher::SetDetectionParam(double ns, double ns2, int maxnpt, int wszrec)
     27void SimpleDeglitcher::SetDetectionParam(double ns, double ns2, int maxnpt,
     28                                         int minnpt, int wszrec)
    2729{
    2830  nsig = (ns > 0.01) ? ns : 1.;
    2931  nsig2 = (ns2 > 0.01) ? ns2 : nsig/2.;
    3032  maxpoints = ((maxnpt > 0) && (maxnpt <= wsize)) ? maxnpt : 5;
     33  minpoints = ((minnpt > 0) && (minnpt <= maxpoints)) ? minnpt : maxpoints/2;
    3134  wrecsize = ((wszrec > 0) && (wszrec <= wsize)) ? wszrec : 2*maxpoints;
    3235}
     
    4245  os << "\n ------------------------------------------------------ \n"
    4346     << " SimpleDeglitcher::PrintStatus() - WindowSize=" << WSize()
    44      << "  NbSigmas=" << NbSigmas() << " MaxPoints=" << MaxPoints() << endl;
    45   os << "  NbSigmas2=" << NbSigmas2() << "  WRecSize= " << WRecSize()
     47     << " MaxPoints=" << MaxPoints() << " MinPoints=" << MinPoints() << endl;
     48  os << " NbSigmas=" << NbSigmas()
     49     << "  NbSigmas2=" << NbSigmas2() << "  WRecSize= " << WRecSize()
    4650     << "  Range_Min= " << range_min << " Range_Max= " << range_max << endl;
    4751  os << "  RepOutOfRangeSamples: " << _Bool2YesNo(rec_out_range_samples)
     
    117121      getData(0, k+snb, vin(k), vfg(k));
    118122
    119     int nokdebut = 0.;
     123    int nokdebut = 0;
    120124    double s = 0.;   
    121125    double mean = 0.;
     
    236240      if (valcur < mean+curnsig*sigma) {  // inferieur au seuil
    237241        if (fgglitch) { 
    238           if (k-kgl < maxpoints) {   // On vient de detecter un glitch
     242          if ( (k-kgl <= maxpoints) && (k-kgl >= minpoints) ) {   
     243            // On vient de detecter un glitch
    239244            glcount++;
    240245            if (rec_gl_samples) { // On change la valeur des samples
     
    253258            lastput = snb+k-1;
    254259          }  // - Fin de detection de glitch
    255           else {  // Trop long - ce n'est pas un glitch ...
     260          else {  // Trop long ou trop court - ce n'est pas un glitch ...
    256261            for(ii=kgl; ii<k; ii++) {
    257262              putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
     
    267272      else {  // Superieur au seuil
    268273        if (fgglitch) {
    269           if (k-kgl+1 >= maxpoints) {  // serie de points > seuil
     274          if (k-kgl+1 > maxpoints) {  // serie de points > seuil
    270275            for(ii=kgl; ii<=k; ii++)   // -> Donc pas glitch
    271276              putData(0, ii+snb, vin(ii%wsize), vfg(ii%wsize));
     
    600605}
    601606
     607// ----------------------------------------------------------------------
     608//   Classe SimpleFourierFilter : Filtre simple ds le domaine de Fourier
     609// ----------------------------------------------------------------------
     610
     611SimpleFourierFilter::SimpleFourierFilter(Vector const & vc)
     612{
     613  ffcoef = vc;
     614  wsize = (ffcoef.Size()-1)*2;
     615  if (wsize < 16)
     616    throw ParmError("SimpleFourierFilter::SimpleFourierFilter() WSize<16 !");
     617  KeepSpectra(0);
     618}
     619
     620SimpleFourierFilter::~SimpleFourierFilter()
     621{
     622}
     623
     624
     625void SimpleFourierFilter::PrintStatus(ostream & os)
     626{
     627  os << "\n ------------------------------------------------------ \n"
     628     << " SimpleFourierFilter::PrintStatus() - WindowSize="
     629     << WSize() << endl;
     630  TOIProcessor::PrintStatus(os);
     631  os << " Coeff= " << ffcoef << endl;
     632  os << " ProcessedSampleCount=" << ProcessedSampleCount() << endl;
     633  os << " ------------------------------------------------------ " << endl;
     634}
     635
     636void SimpleFourierFilter::init() {
     637  cout << "SimpleFourierFFilter::init" << endl;
     638  declareInput("in");
     639  declareOutput("out");
     640  declareOutput("incopie");
     641  name = "SimpleFourierFilter";
     642  //  upExtra = 1;
     643}
     644
     645
     646void SimpleFourierFilter::run() {
     647  //  TOIManager* mgr = TOIManager::getManager();
     648  int snb = getMinIn();
     649  int sne = getMaxIn();
     650
     651  bool fgout = checkOutputTOIIndex(0);
     652  bool fgincopie = checkOutputTOIIndex(1);
     653
     654  if (!checkInputTOIIndex(0)) {
     655    cerr << " SimpleFourierFilter::run() - Input TOI (in) not connected! "
     656         << endl;
     657    throw ParmError("SimpleFourierFilter::run() Input TOI (in) not connected!");
     658  }
     659  if (!fgout) {
     660    cerr << " SimpleFourierFilter::run() - No Output TOI connected! "
     661         << endl;
     662    throw ParmError("SimpleFourierFilter::run() No output TOI connected!");
     663  }
     664
     665  cout << " SimpleFourierFilter::run() SNRange=" << snb << " - " << sne << endl;
     666 
     667
     668  try {
     669    Timer tm("SimpleFourierFilter::run()");
     670    // Le debut
     671    Vector vin(wsize);
     672    Vector vout(wsize);
     673    TVector<int_8> vfg(wsize);
     674    TVector< complex<r_8> > vfft;
     675    TVector< complex<r_8> > zcoef(ffcoef.Size());
     676    zcoef = ffcoef;
     677
     678
     679    FFTPackServer ffts;
     680    ffts.setNormalize(true);
     681    // Boucle sur les sampleNum
     682
     683    int k,i,klast;
     684    int nks = 0;
     685
     686    klast = snb-1;
     687    // 1er partie, on traite par paquets de wsize
     688    for(k=snb;k<=sne-wsize+1;k+=wsize) {
     689      for(i=0; i<wsize; i++)
     690        getData(0, k+i, vin(i), vfg(i));
     691      ffts.FFTForward(vin, vfft);
     692      if (nks < nb_keep) {
     693        string dbgfile = "ffiltdbg" + (string)MuTyV(nks) + ".ppf";
     694        POutPersist po(dbgfile);
     695        po << vfft;
     696        nks++;
     697      }
     698      vfft.MulElt(zcoef);
     699      ffts.FFTBackward(vfft, vout);
     700      for(i=0; i<wsize; i++)
     701        putData(0,k+i,vout(i),vfg(i));
     702      if (fgincopie)
     703        for(i=0; i<wsize; i++)
     704          putData(1, k+i, vin(i), vfg(i));
     705      klast+=wsize;
     706      totnscount+=wsize;
     707    }
     708   
     709
     710    // 2eme partie, on traite la fin du bloc d'echantillons si necessaire
     711    double inval;
     712    int_8 inflg;
     713    if (klast < sne)
     714      for(k=klast+1; k<=sne; k++) {
     715        getData(0, k, inval, inflg);
     716        putData(0, k, inval, inflg);
     717        if (fgincopie)
     718          putData(1, k, inval, inflg);
     719        totnscount++;
     720      }
     721    cout << " SimpleFourierFilter::run() - End of processing " << endl;
     722  }  // Bloc try
     723
     724  catch (PException & exc) {
     725    cerr << "SimpleFourierFilter: Catched Exception " << (string)typeid(exc).name()
     726         << "\n .... Msg= " << exc.Msg() << endl;
     727  }                                                                             
     728}
    602729
    603730// ---------------------------------------------------------------
     
    659786  out_index = -1;
    660787  int nbconin = 0;
    661   bool fggin = false;
    662788  char buff[64];
    663789  for(int ki=0;ki<nb_input;ki++) {
  • trunk/ArchTOIPipe/ProcWSophya/simtoipr.h

    r1478 r1479  
    1414class SimpleDeglitcher : public TOIProcessor {
    1515public:
    16                 SimpleDeglitcher(int wsz=64, double ns=3, int maxnpt=5);
     16                SimpleDeglitcher(int wsz=64, double ns=3,
     17                                 int maxnpt=5, int minnpt=2);
    1718  virtual       ~SimpleDeglitcher();
    1819
     
    2627
    2728
    28   void          SetDetectionParam(double ns, double ns2, int maxnpt, int wszrec=0);
     29  void          SetDetectionParam(double ns, double ns2, int maxnpt,
     30                                  int minnpt, int wszrec=0);
    2931   
    3032  inline void   RepBadSamples(bool gl_samples, bool out_range_samples, bool use_wrec=true)
     
    4042  inline double NbSigmas2() const { return nsig2; }
    4143  inline int    MaxPoints() const { return maxpoints; }
     44  inline int    MinPoints() const { return minpoints; }
    4245 
    4346  inline int_8  ProcessedSampleCount() const { return totnscount; }
     
    6164  double nsig2;     // Seuil en nb de sigmas, pour les points suivants le 1er
    6265  int maxpoints;    // Nb maxi de points > ns sigmas
     66  int minpoints;    // Nb mini de points > ns sigmas pour avoir un glitch
    6367  double range_min, range_max;  // Range acceptable pour in
    6468
     
    136140
    137141
     142//  Un filtre simple, dans le domaine de Fourier
     143//  InverseFFT ( FFT(Vecteur(in)) * FilterCoefficient )
     144
     145class SimpleFourierFilter : public TOIProcessor {
     146public:
     147                SimpleFourierFilter(Vector const & vc); 
     148                ~SimpleFourierFilter();
     149
     150  inline int    WSize() const { return wsize; }
     151  inline int_8  ProcessedSampleCount() const { return totnscount; }
     152  inline Vector FilterCoefficients() const
     153                { Vector rcv; rcv = ffcoef; return(rcv); }
     154
     155  virtual void  PrintStatus(ostream & os) ; // const plus tard
     156
     157  virtual void  init(); 
     158  virtual void  run();
     159
     160  inline  void  KeepSpectra(int nb=0)
     161                { nb_keep = nb; }
     162protected:
     163  int_8 totnscount;   // Nombre total d'echantillon processe
     164  int wsize;         // Taille de fenetre de travail
     165  Vector ffcoef;     // Coefficients du filtre
     166  int nb_keep;
     167};
     168
     169
    138170//  Classe SimpleFanOut
    139 //  Transforme recopie chaque entree sur M lignes de sortie
     171//  Recopie chaque entree sur M lignes de sortie
    140172
    141173class SimpleFanOut : public TOIProcessor {
     
    159191};
    160192
     193
    161194#endif
Note: See TracChangeset for help on using the changeset viewer.