Changeset 3999 in Sophya for trunk/AddOn


Ignore:
Timestamp:
Jun 14, 2011, 10:21:16 PM (14 years ago)
Author:
ansari
Message:

amelioration prog calcul correlation ADC-CRT, Reza 14/06/2011

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/AddOn/TAcq/corrcrtadc.cc

    r3998 r3999  
    44
    55/* ----------------------------------------------------------
    6    Projet BAORadio - (C) LAL/IRFU  2008-2010
     6   Projet BAORadio - (C) LAL/IRFU  2008-2011
    77
    88   Programme de lecture des fichiers DUMP ADC du CRT (Pittsburgh)
    99   pour calcul de spectres / correlations
    1010   R. Ansari, C. Magneville   -  LAL/Irfu - Juin 2011
    11    V : Mai 2009
    1211   ---------------------------------------------------------- */
    1312
     
    3332#include "fftpserver.h"
    3433#include "utilarr.h"
     34#include "histats.h"
    3535
    3636// include sophya mesure ressource CPU/memoire ...
     
    4343int Usage(bool fgshort=true);
    4444int DecodeProc(int narg, char* arg[]);
    45 int ProcessADCFiles(string& inoutpath, string& outname, int imin, int imax, int istep,  int jf1, int jf2, int nfreq);
     45int ProcessADCFiles(string& inoutpath, vector<int>& adcids, string& outname, int imin, int imax, int istep,  int jf1, int jf2, int nfreq);
    4646int ComputeCorrel(TMatrix< complex<r_4> >& cfour,  TMatrix< complex<r_8> >& correl, TMatrix< complex<r_8> >& autocorrel);
     47int ADCFiles2Histo(string& inoutpath, vector<int>& adcids, string& outname, int imin, int imax, int istep);
     48
    4749//------------------------------------------------------------------------------------------------------------
    4850
     
    5052int Usage(bool fgshort)
    5153{
    52   cout << " --- corrcrtadc.cc : Read CRT-ADC dump files to produce time-frequency\n"
    53        << "     correlation matrices " << endl;
    54   cout << " Usage: corrcrtadc InOutPath OutFile Imin,Imax,step [NumFreq1,NumFreq2,NBinFreq] \n" << endl;
     54  cout << " --- corrcrtadc.cc : Read CRT-ADC dump files and process to produce correlation matrices \n"
     55       << " Usage: corrcrtadc -corr/-hval InOutPath OutFile [AdcIds [Imin,Imax,step\n" << endl;
    5556  if (fgshort) {
    5657    cout << " corrcrtadc -h for detailed instructions" << endl;
    5758    return 1;
    5859  }
    59   cout << " InOutPath : Input/Output directory name \n"
     60  cout << " -corr/-hval : Compute correlations or Fill histograms for ADC sample values \n"
     61       << " InOutPath : Input/Output directory name \n"
     62       << " ADCIds : ADC Id's to be processed (1,2,3,4)  \n"
    6063       << " OutFile : Output PPF file  name \n"
    6164       << " Imin,Imax,IStep: Input ADC dump files sequence number \n"
    62        << "    FileNames=InOutPath/adcdumpNJFII.fits Imin<=II<=Imax II+=IStep , J=0,1,2 \n"
    63        << " NumFreq1,NumFreq2,NBinFreq: Freq Zone and number of frequency bins for ntuple" << endl;
     65       << "    FileNames=InOutPath/adcdumpNJFII.fits Imin<=II<=Imax II+=IStep , J=ADCIds \n" << endl;
     66  //       << " NumFreq1,NumFreq2,NBinFreq: Freq Zone and number of frequency bins for ntuple" << endl;
    6467  return 1;
    6568}
     
    101104}
    102105
     106
    103107//--------------------------------------------------------------------
    104108//       Traitement fichiers produits par vismfib  (V Nov09)
     
    107111{
    108112  // Decodage des arguments et traitement
    109   string inoutpath = arg[0]; 
    110   string outname = arg[1];
     113  string popt = arg[0];
     114  bool fillhis=false;
     115  if (popt=="-hval")  fillhis=true;
     116  string inoutpath = arg[1]; 
     117  string outname = arg[2];
     118  int aids[4]={0,1,-1,1};
     119  if (narg>3) sscanf(arg[3],"%d,%d,%d,%d",aids,aids+1,aids+2,aids+3);
     120  vector<int> adcids;
     121  for(int ii=0;ii<4;ii++)
     122    if((aids[ii]>0)&&(aids[ii]<16))  adcids.push_back(aids[ii]);
    111123  int imin=0;
    112124  int imax=0;
    113125  int istep=1;
    114   sscanf(arg[2],"%d,%d,%d",&imin,&imax,&istep);
     126  if (narg>4) sscanf(arg[4],"%d,%d,%d",&imin,&imax,&istep);
    115127  int jf1=0;
    116128  int jf2=0;
    117129  int nfreq=0;
    118   if (narg>3)
    119     sscanf(arg[3],"%d,%d,%d",&jf1,&jf2,&nfreq);
    120 
    121   cout << " ----- corrcrtadc/DecodeProc - Start - InOutPath= " << inoutpath << " OutFileName=" << outname << endl;
     130  if (narg>5)
     131    sscanf(arg[5],"%d,%d,%d",&jf1,&jf2,&nfreq);
     132
     133  cout << " ----- corrcrtadc/DecodeProc - Start " << ((fillhis)? " Fill ADC-val histogram" : " Compute Correlation") << endl;
     134  cout <<  " InOutPath= " << inoutpath << " ADCIds: " ;
     135  for(size_t ii=0; ii<adcids.size(); ii++) cout << adcids[ii] << " , ";
     136  cout << " (NbADC=" << adcids.size() << ") OutFileName=" << outname << endl;
    122137  cout << " IMin,Max,Step="    << imin << "," << imax << "," << istep
    123138       << "Frequency num range JF=" << jf1 << "," << jf2 << "," << nfreq << "  ------- " << endl;
    124   int rc=ProcessADCFiles(inoutpath, outname, imin, imax, istep, jf1, jf2, nfreq);
     139  int rc=0;
     140  if (fillhis) rc = ADCFiles2Histo(inoutpath, adcids, outname, imin, imax, istep);
     141  else rc=ProcessADCFiles(inoutpath, adcids, outname, imin, imax, istep, jf1, jf2, nfreq);
     142 
    125143  return rc;
    126144}
    127145
    128 // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
    129 /* --Fonction-- */
    130 int ProcessADCFiles(string& inoutpath, string& outname, int imin, int imax, int istep, int jf1, int jf2, int nfreq)
    131 {
    132   Timer tm("ProcessADCFiles"); 
    133 
    134   // Taille des fichiers 4 voies = 1024*1024*128 ===> 32 x 1024 x 1024 samples / voie
    135   // On lit par paquet de 4096 = 4 x 1024 / voie --> ADCRDBLKSZ=16x1024=16384
     146// Taille des fichiers 4 voies = 1024*1024*128 ===> 32 x 1024 x 1024 samples / voie
     147// On lit par paquet de 4096 = 4 x 1024 / voie --> ADCRDBLKSZ=16x1024=16384
    136148#define ADCFLEN 4096
    137149#define ADCRDBLKSZ 16384
    138150#define ADCNREAD 8192
    139 #define NBADC 2
    140 #define NFREQUSED 2000
     151
     152static int PRTMODULO = 250;
     153
     154// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
     155/* --Fonction-- */
     156int ProcessADCFiles(string& inoutpath, vector<int>& adcids, string& outname, int imin, int imax, int istep, int jf1, int jf2, int nfreq)
     157{
     158  Timer tm("ProcessADCFiles"); 
     159
     160#define NFREQUSED 2040
     161#define NFREQUSESTART 5
     162#define NFREBIN 4
     163
     164  sa_size_t NFREQREBIN = NFREQUSED/NFREBIN;
     165  sa_size_t NBADC = adcids.size();
    141166
    142167  sa_size_t  NCHAN = 4*NBADC;
     
    145170  TMatrix< complex<r_8> > correl(NCORREL,NFREQUSED);
    146171  TMatrix< complex<r_8> > autocorrel(NCHAN,NFREQUSED);
    147 
    148   FILE* fip[NBADC]={NULL,NULL};
     172  double nsumcor=0.;
     173
     174  vector<FILE*> fip;
     175  vector<int> adcchans;
     176  for(size_t ka=0; ka<NBADC; ka++)  {
     177    fip.push_back(NULL);
     178    adcchans.push_back(adcids[ka]*4+ka);
     179  }
     180
    149181  FFTPackServer ffts(false);
    150182 
     
    155187
    156188  signed char rdbuff[ADCRDBLKSZ];
    157   int prtmodulo=50;
    158189  for(int ifile=imin; ifile<=imax; ifile+=istep) {
    159190    for(int ka=0; ka<NBADC; ka++) {
    160       sprintf(fname, "%s/adcdumpN%dF%d.bd",inoutpath.c_str(),ka,ifile);
     191      sprintf(fname, "%s/adcdumpN%dF%d.bd",inoutpath.c_str(),adcids[ka],ifile);
    161192      fip[ka]=fopen(fname,"rb");
    162       if (fip[ka]==NULL) cout << "ProcessADCFiles/ERROR opening file " << fname << endl;
    163       else  cout << "ProcessADCFiles/Info - file " << fname << " opened ..." << endl;
     193      if (fip[ka]==NULL)
     194        cout << "ProcessADCFiles/ERROR opening file " << fname << " AdcId=" << adcids[ka] << " I=" << ifile << endl;
     195      else 
     196        cout << "ProcessADCFiles/Info - file " << fname << " opened ... " << " AdcId=" << adcids[ka] << " I=" << ifile << endl;
    164197    }
    165198
     
    171204          for(sa_size_t ls=0; ls<ADCFLEN; ls++) sigadc(ls)=(float)rdbuff[ls*4+jac];
    172205          ffts.FFTForward(sigadc, foursig);
    173           //      cfour.Row(irc)=foursig(Range(400,1679)).Transpose();  irc++;
    174           cfour.Row(irc)=foursig(Range(10,2009)).Transpose();  irc++;
    175 
     206          cfour.Row(irc)=foursig(Range(NFREQUSESTART,NFREQUSESTART+NFREQUSED-1)).Transpose();  irc++;
    176207        }
    177208      }
    178209      ComputeCorrel(cfour, correl, autocorrel);
    179       if (m%prtmodulo==0)  cout << " ProcessADCFiles/Info Done read+FFT+correl m=" << m << " / Max=" << ADCNREAD << endl;
     210      nsumcor++;
     211      if (m%PRTMODULO==0)  cout << " ProcessADCFiles/Info Done read+FFT+correl m=" << m << " / Max=" << ADCNREAD << endl;
    180212    }
    181213    for(int ka=0; ka<NBADC; ka++)  fclose(fip[ka]);
    182214  }
    183215
     216
     217  correl /= nsumcor;
     218  autocorrel /= nsumcor;
     219
     220  TMatrix< complex<r_8> > correbin(NCORREL,NFREQREBIN);
     221  sa_size_t icc=0;
     222  for(sa_size_t i=0; i<correbin.NCols(); i++) {
     223    for(sa_size_t j=0; j<NFREBIN; j++) {
     224      correbin.Column(i) += correl.Column(icc);
     225      icc++;
     226    }
     227  }
    184228
    185229  sprintf(fname, "%s/%s",inoutpath.c_str(),outname.c_str());
     
    188232  po << PPFNameTag("correlmtx") << correl;
    189233  po << PPFNameTag("acorrmtx") << autocorrel;
     234  po << PPFNameTag("rebincormtx") << correbin;
    190235
    191236  cout << "ProcessADCFiles:  finished FFT + correlation computing " << endl;
     237
     238  cout << " --------------- Channel/Correlation number association --------------- " << endl;
     239  cout << " CorreNumber- axb  (MtxRow) :  (Ca, Cb)  -- ADCChan(c,d) " << endl;
     240  cout << " ----------------------------------------------------------------------- " << endl;
     241  sa_size_t jcr=0;
     242  for(sa_size_t j1=0; j1<cfour.NRows(); j1++) {
     243    for(sa_size_t j2=j1; j2<cfour.NRows(); j2++) {
     244      cout <<  jcr << " : (" << j1 << "," << j2 << ") -> ADCChans (" << adcchans[j1] << "," << adcchans[j2] << ")" << endl;
     245      jcr++;
     246    }
     247  }
     248  cout << " ----------------------------------------------------------------------- " << endl;
     249
    192250  return 0;
    193251}
     
    208266}
    209267
     268/* --Fonction-- */
     269int ADCFiles2Histo(string& inoutpath, vector<int>& adcids, string& outname, int imin, int imax, int istep)
     270{
     271  Timer tm("ADCFiles2Histo"); 
     272
     273  sa_size_t NBADC = adcids.size();
     274
     275  sa_size_t  NCHAN = 4*NBADC;
     276  vector<Histo *> vhist;
     277  for(int ka=0; ka<NCHAN; ka++)
     278    vhist.push_back(new Histo(-128.5,128.5,257) );
     279
     280  vector<FILE*> fip;
     281  for(size_t ka=0; ka<NBADC; ka++)  fip.push_back(NULL);
     282   
     283  char fname[512];
     284
     285  signed char rdbuff[ADCRDBLKSZ];
     286  for(int ifile=imin; ifile<=imax; ifile+=istep) {
     287    for(int ka=0; ka<NBADC; ka++) {
     288      sprintf(fname, "%s/adcdumpN%dF%d.bd",inoutpath.c_str(),adcids[ka],ifile);
     289      fip[ka]=fopen(fname,"rb");
     290      if (fip[ka]==NULL)
     291        cout << "ADCFiles2Histo/ERROR opening file " << fname << " AdcId=" << adcids[ka] << " I=" << ifile << endl;
     292      else 
     293        cout << "ADCFiles2Histo/Info - file " << fname << " opened ... " << " AdcId=" << adcids[ka] << " I=" << ifile << endl;
     294    }
     295
     296    for(int m=0; m<ADCNREAD; m++) {
     297      sa_size_t irc=0;
     298      for(int ka=0; ka<NBADC; ka++) {
     299        fread(rdbuff,1,ADCRDBLKSZ,fip[ka]);
     300        for(int jac=0; jac<4; jac++) {
     301          for(sa_size_t ls=0; ls<ADCFLEN; ls++) vhist[irc]->Add((r_8)rdbuff[ls*4+jac]);
     302          irc++;
     303        }
     304      }
     305      if (m%PRTMODULO==0)  cout << " ADCFiles2Histo/Info Done FillHist m=" << m << " / Max=" << ADCNREAD << endl;
     306    }
     307    for(int ka=0; ka<NBADC; ka++)  fclose(fip[ka]);
     308  }
     309
     310  sprintf(fname, "%s/%s",inoutpath.c_str(),outname.c_str());
     311  cout << "ADCFiles2Histo: Opening file " << fname << " for writing ADC value histograms " << endl; 
     312  POutPersist po(fname);
     313  char nametag[64];
     314  for(size_t ka=0; ka<NCHAN; ka++) {
     315    sprintf(nametag,"adcvalC%d",ka);
     316    po << PPFNameTag("nametag") << *(vhist[ka]);
     317  }
     318  for(size_t ka=0; ka<NCHAN; ka++) delete vhist[ka];
     319
     320  cout << "ADCFiles2Histo:  finished ADC value histogram fill " << endl;
     321  return 0;
     322}
Note: See TracChangeset for help on using the changeset viewer.