Commit 19332fbf authored by Réza Ansari's avatar Réza Ansari
Browse files

Amelioration du programme visi2tmfreq.cc avec calcul / remplissage d'un NTuple...

Amelioration du programme visi2tmfreq.cc avec calcul / remplissage d'un NTuple avec mean/sigma des signaux autocorrelation, introduction de la classe P4AnaParams (p4autils.h .cc, Reza 28/02/2017
parent 0a4d0953
/* ----------------------------------------------------------
Projet BAORadio/PAON4 - (C) LAL/IRFU 2008-2017
Classes et fonctions utilitaires pour les programmes d'analyse PAON4
R. Ansari Fevrier 2017
---------------------------------------------------------- */
#include "p4autils.h"
P4AnaParams::P4AnaParams()
: inpath5_("bao5/"), inpath6_("bao6/"), Imin_(0), Imax_(10), Istep_(1),
fgreorderfreq_(false), gain_gnu_file_("gain.ppf"),
outfile_("p4a.ppf"), Nmean_(10), prtlev_(0),
fgTFM_(false), TFMfreqbin_(), TFMtimebin_(30), fgdtable_(false)
{
}
P4AnaParams::P4AnaParams(P4AnaParams const & a)
: inpath5_(a.inpath5_), inpath6_(a.inpath6_), Imin_(a.Imin_), Imax_(a.Imax_), Istep_(a.Istep_),
fgreorderfreq_(a.fgreorderfreq_), gain_gnu_file_(a.gain_gnu_file_),
outfile_(a.outfile_), Nmean_(a.Nmean_), prtlev_(a.prtlev_),
fgTFM_(a.fgTFM_), TFMfreqbin_(a.TFMfreqbin_), TFMtimebin_(a.TFMtimebin_),
fgdtable_(a.fgdtable_), fbands_(a.fbands_), lastargs_(a.lastargs_)
{
}
P4AnaParams& P4AnaParams::operator = (P4AnaParams const & a)
{
inpath5_=a.inpath5_; inpath6_=a.inpath6_;
Imin_=a.Imin_; Imax_=a.Imax_; Istep_=a.Istep_;
fgreorderfreq_=a.fgreorderfreq_; gain_gnu_file_=a.gain_gnu_file_;
outfile_=a.outfile_; Nmean_=a.Nmean_; prtlev_=a.prtlev_;
fgTFM_=a.fgTFM_; TFMfreqbin_=a.TFMfreqbin_; TFMtimebin_=a.TFMtimebin_;
fgdtable_=a.fgdtable_; fbands_=a.fbands_; lastargs_=a.lastargs_;
return *this;
}
int P4AnaParams::DecodeArgs(int narg, const char* arg[])
{
// decodage arguments optionnel
bool fgoptarg=true;
while (fgoptarg&&(narg>1)) {
string fbo = arg[1];
if (fbo=="-inrange") { // specification numeros de fichiers de visi a traiter
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
sscanf(arg[2],"%d,%d,%d",&Imin_,&Imax_,&Istep_); arg+=2; narg-=2;
}
else if (fbo=="-in5") {
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
inpath5_=arg[2]; arg+=2; narg-=2;
}
else if (fbo=="-in6") {
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
inpath6_=arg[2]; arg+=2; narg-=2;
}
else if (fbo=="-gnu") {
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
gain_gnu_file_=arg[2]; arg+=2; narg-=2;
}
else if (fbo=="-o") {
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
outfile_=arg[2]; arg+=2; narg-=2;
}
else if (fbo=="-nmean") {
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
Nmean_=atoi(arg[2]); arg+=2; narg-=2;
}
else if (fbo=="-tfm") {
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
int ja,jb;
sscanf(arg[2],"%d,%d",&ja,&jb); TFMtimebin_=ja; TFMfreqbin_=jb; fgTFM_=true; arg+=2; narg-=2;
}
else if (fbo=="-freq") {
if (narg<2) { cout << "P4AnaParams::DecodeArgs missing/bad argument, -h for help " << endl; return -1; }
double f0,df;
sscanf(arg[2],"%lg,%lg",&f0,&df); fbands_.push_back(P4FreqBand(f0,df)); fgdtable_=true; arg+=2; narg-=2;
}
else fgoptarg=false;
}
// les arguments qui restent a la fin de la ligne de commande:
for(int k=1; k<narg; k++) lastargs_.push_back(arg[k]);
return 0;
}
int P4AnaParams::UsageOptions()
{
cout<< " P4AnaParams::UsageOptions(): -inrange -in5 -in6 -gnu -o -nmean -tfm -freq -prt \n"
<< " [-inrange Imin,Imax[,Istep] ] [-in5 InputPath_BAO5] [-in6 InputPath_BAO6] \n"
<< " [-o outfilename] [-gnu gain_filename] [-nmean N] [-prt level] \n"
<< " [-tfm timebin,freqbin] [-freq f0,df] \n"
<< " -inrange Imin,Imax[,Istep] define range of visibilite matrices to be processed (Imin<=I<=Imax with step Istep) \n"
<< " -in5/6 InputPath_BAO5/6 : input file path for BAO5 and BAO6 \n"
<< " -o outfilename : specify output file name \n"
<< " -gnu gain_filename: gain g(nu) file name \n"
<< " -nmean N: compute average (and sigma...) using N visibility matrices \n"
<< " -prt level: define print level \n"
<< " -tfm timebin,freqbin : time-frequency maps, averaging timebin=nb of visi matrices, freqbin frequency components \n"
<< " -freq f0,df : definition of a frequency band centered on f0, with total width df (in MHz) \n"
<< " several frequency bands can be specified by mutiple -freq options \n"
<< endl;
return 0;
}
ostream& P4AnaParams::Print(ostream& os) const
{
os<<" In5 path="<<inpath5_<<" In6 path="<<inpath6_<< "Range:"<<Imin_<<"<=I<="<<Imax_<<" (step="<<Istep_<<")"<<endl;
if (fgreorderfreq_) os<<" (frequency reordering for FFT firmware) ";
os<<" Gain, g(nu) file:"<<gain_gnu_file_<<" OutFile="<<outfile_<<endl;
os<<" Nmean="<<Nmean_<<" TFM: TimeBin="<<TFMtimebin_<<" FreqBin="<<TFMfreqbin_<<endl;
for(size_t i=0; i<fbands_.size(); i++) os<<"FreqBand["<<i<<"]: "<<fbands_[i]<<endl;
return os;
}
/* ----------------------------------------------------------
Projet BAORadio/PAON4 - (C) LAL/IRFU 2008-2017
Classes et fonctions utilitaires pour les programmes d'analyse PAON4
R. Ansari Fevrier 2017
---------------------------------------------------------- */
#ifndef P4AUTILS_SEEN
#define P4AUTILS_SEEN
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
//----- sophya includes
#include "machdefs.h"
#include "sopnamsp.h"
#include "pexceptions.h"
//---- Classe definition de bande de frequence, frequence centrale et largeur
class P4FreqBand {
public:
// definition de la bande de frequence, specification frequence centrale f0 et largeur df en MHz
P4FreqBand(double f0=1420., double df=1.)
: f0_(f0), df_(df)
{
double deltanufft=250./4096; // 250 MHz en 4096 frequences
double freqstart=1250.; // Bande de 1250-1500 MHz
sa_size_t jfmin_=(f0_-freqstart-0.5*df_)/deltanufft;
sa_size_t jfmax_=(f0_-freqstart+0.5*df_)/deltanufft;
if ((jfmin_<0)||(jfmin_>4095)||(jfmax_<0)||(jfmax_>4095)) {
cout<<"P4FreqBand(f0="<<f0<<" ,df="<<df<<") ERROR -> Out of range (0...4095) jfmin="<<jfmin_<<" jfmax="<<jfmax_<<endl;
throw ParmError("P4FreqBand(f0,df) Out of range (0...4095) jfmin,jfmax");
}
}
P4FreqBand(P4FreqBand const& a)
: f0_(a.f0_), df_(a.df_), jfmin_(a.jfmin_), jfmax_(a.jfmax_)
{ }
P4FreqBand& operator = (P4FreqBand const& a)
{ f0_=a.f0_; df_=a.df_; jfmin_=a.jfmin_; jfmax_=a.jfmax_; return *this; }
double f0_, df_; // frequence centrale et largeur en MHz , f0_-df_/2 <= f <= f0_+df_/2
sa_size_t jfmin_, jfmax_; // numero de colonne de frequence dans la matrice de visibilite
};
inline ostream& operator << (ostream& os, P4FreqBand const& a)
{ os<<a.f0_<<" +/- "<<a.df_<<" MHz (jf="<<a.jfmin_<<"-"<<a.jfmax_<<")"; return os; }
class P4AnaParams {
public:
P4AnaParams();
P4AnaParams(P4AnaParams const & a);
P4AnaParams& operator = (P4AnaParams const & a);
//
int DecodeArgs(int narg, const char* arg[]);
static int UsageOptions();
ostream& Print(ostream& os) const;
//--- definition des fichiers de visibilite en entree
string inpath5_, inpath6_;
int Imin_,Imax_,Istep_;
bool fgreorderfreq_;
//--- nom de fichier de gain
string gain_gnu_file_;
//--- nom du fichier de sortie
string outfile_;
//--- nombre de matrices de visibilites pour les calculs de moyenne, sigma ...
int Nmean_;
//--- print level
int prtlev_;
//--- definition pour les cartes temps-frequence
bool fgTFM_;
sa_size_t TFMtimebin_;
sa_size_t TFMfreqbin_;
// definition des bandes de frequences pour les DataTables
bool fgdtable_;
vector<P4FreqBand> fbands_;
// les arguments en fin de ligne de commande
vector<string> lastargs_;
};
inline ostream& operator << (ostream& os, P4AnaParams const& a)
{ return a.Print(os); }
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment