Changeset 552


Ignore:
Timestamp:
Oct 5, 2011, 3:13:36 PM (13 years ago)
Author:
campagne
Message:

improvment (jec)

Location:
BAORadio/AmasNancay/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • BAORadio/AmasNancay/trunk/mergeRawOnOff.cc

    r551 r552  
    5555//--------------------------------------------------------------
    5656//Utility functions
     57
     58  class median_of_empty_list_exception:public std::exception{
     59    virtual const char* what() const throw() {
     60    return "Attempt to take the median of an empty list of numbers.  "
     61      "The median of an empty list is undefined.";
     62  }
     63  };
     64  template<class RandAccessIter>
     65    double median(RandAccessIter begin, RandAccessIter end)
     66    throw(median_of_empty_list_exception){
     67    if(begin == end){ throw median_of_empty_list_exception(); }
     68    std::size_t size = end - begin;
     69    std::size_t middleIdx = size/2;
     70    RandAccessIter target = begin + middleIdx;
     71    std::nth_element(begin, target, end);
     72   
     73    if(size % 2 != 0){ //Odd number of elements
     74      return *target;
     75    }else{            //Even number of elements
     76      double a = *target;
     77      RandAccessIter targetNeighbor= target-1;
     78      std::nth_element(begin, targetNeighbor, end);
     79      return (a+*targetNeighbor)/2.0;
     80    }
     81  }
     82
    5783//--------------------------------------------------------------
    5884char *regexp (const char *string, const char *patrn, int *begin, int *end) {   
     
    291317
    292318      if ((sa_size_t)nSpectra < TOTAL_NUM_CYCLES ) {
    293         //STORE THE spectra
    294         //      tableOfSpectra(Range::all(),Range::all(),Range(nSpectra)).Show();
    295         //      aSpec.Show();
    296319        tableOfSpectra(Range::all(),Range::all(),Range(nSpectra)) = aSpec;
    297 //      aSpec.Show();
    298 //      cout << "deb 1" << endl;
    299 //      tmp = aSpec;
    300 //      cout << "deb 2" << endl;
    301320      } else {
    302321        stringstream tmp;
     
    310329  //Resize
    311330
    312   nSpectra--;//For further selection in Range
    313   if (para.debuglev_>90){
    314     cout << "Cycles < 0," <<  nSpectra << ">" << endl;
    315   }
    316331 
    317 
    318332  TMatrix<r_4> medianOfSpectra(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
    319333  //Compute the median for each freq. and Channel
    320334  for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; iCh++){
    321335    for (sa_size_t freq =0; freq<NUMBER_OF_FREQ; freq++){
    322       TVector<r_4> tmp0(tableOfSpectra(Range(freq),Range(iCh),Range(0,nSpectra)).CompactAllDimensions());
     336      TVector<r_4> tmp0(tableOfSpectra(Range(freq),Range(iCh),Range(0,nSpectra-1)).CompactAllDimensions());
    323337      vector<r_4> tmp;
    324338      tmp0.FillTo(tmp);
    325       nth_element(tmp.begin(),tmp.begin()+tmp.size()/2,tmp.end());
    326       medianOfSpectra(iCh,freq) = *(tmp.begin()+tmp.size()/2);
     339      medianOfSpectra(iCh,freq) = median(tmp.begin(),tmp.end());
    327340    }
    328341  }
     
    338351    tmp << nSpectra;
    339352    string fileName = para.outPath_+"/medianDiffOnOffRaw_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
    340     cout << "Save median based on " <<  (nSpectra+1) << " cycles " << endl;
     353    cout << "Save median based on " <<  nSpectra << " cycles " << endl;
    341354    POutPersist fos(fileName);
    342355
     
    347360    tag = "sigmamedred";
    348361    fos << PPFNameTag(tag) << sigmaRedMtx;
     362    tag = "cycleVsfreq";
     363   
     364    TArray<r_4> tarr(tableOfSpectra(Range::all(),Range::all(),Range(0,nSpectra-1)));
     365    fos << PPFNameTag(tag) << tarr;
    349366  }
    350367}
  • BAORadio/AmasNancay/trunk/plotDiffOnOff.pic

    r550 r552  
    66set ncycles $2
    77set nFreqBin $3
     8set action $4
     9
     10set defatt "font=helvetica,bold,20"
     11
     12
     13
     14if ( ${action} == "mean" ) then
     15
    816openppf meanDiffOnOffRaw_${source}-${ncycles}Cycles.ppf
    917
     
    1321objaoper mean row 0 s0
    1422objaoper mean row 1 s1
    15 graphicatt "xylimits=1250,1500,-0.01,0.01"
     23graphicatt "${defatt} xylimits=1250,1500,-0.01,0.01"
    1624newwin 1 1
    1725plot2d s0 (n/8192)*250+1250 val n>0 "cpts blue nsta notit"
    1826plot2d s1 (n/8192)*250+1250 val n>0 "same cpts red nsta notit"
    19 settitle "<(ON-OFF)[r,c]/Gain[r]>_{r,c} $source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)"
     27settitle "$source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)" ' ' $defatt
     28setaxelabels "Freq. (MHz)" "<(ON-OFF)[r,c]/Gain[r]>_{r,c}" $defatt
     29
    2030
    2131
     
    2737plot2d rs0 (n/${nFreqBin})*250+1250 val n>0 "marker=fcircle,5 blue nsta notit"
    2838plot2d rs1 (n/${nFreqBin})*250+1250 val n>0 "same marker=fcircle,5 red nsta notit"
    29 settitle "<(ON-OFF)[r,c]/Gain[r]>_{r,c} Rebin(${nFreqBin}) $source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)"
     39settitle "$source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)" ' ' $defatt
     40setaxelabels "Freq. (MHz)" "<(ON-OFF)[r,c]/Gain[r]>_{r,c} Rebin(${nFreqBin})" $defatt
     41
    3042
    3143##Reduced Mean
     
    3648plot2d rss0 (n/${nFreqBin})*250+1250 val n>0 "marker=fcircle,5 blue nsta notit"
    3749plot2d rss1 (n/${nFreqBin})*250+1250 val n>0 "same marker=fcircle,5 red nsta notit"
    38 settitle "Sigma[(ON-OFF)[r,c]/Gain[r]] Rebin(${nFreqBin}) $source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)"
     50settitle "$source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)" ' ' $defatt
     51setaxelabels "Freq. (MHz)" "Sigma[(ON-OFF)[r,c]/Gain[r]] Rebin(${nFreqBin})" $defatt
     52
     53else
     54
     55openppf medianDiffOnOffRaw_${source}-${ncycles}Cycles.ppf
    3956
    4057
     58##General Median
     59del s0 s1
     60objaoper median row 0 s0
     61objaoper median row 1 s1
     62graphicatt "xylimits=1250,1500,-0.01,0.01"
     63newwin 1 1
     64plot2d s0 (n/8192)*250+1250 val n>0 "cpts blue nsta notit"
     65plot2d s1 (n/8192)*250+1250 val n>0 "same cpts red nsta notit"
     66settitle "$source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)" ' ' $defatt
     67setaxelabels "Freq. (MHz)" "Median[(ON-OFF)[r,c]/Gain[r]]"  $defatt
     68
     69
     70##Reduced Mean of the median
     71newwin 1 1
     72del rs0 rs1
     73objaoper meanmedred row 0 rs0
     74objaoper meanmedred row 1 rs1
     75graphicatt "xylimits=1250,1500,-0.01,0.01"
     76plot2d rs0 (n/${nFreqBin})*250+1250 val n>0 "marker=fcircle,5 blue nsta notit"
     77plot2d rs1 (n/${nFreqBin})*250+1250 val n>0 "same marker=fcircle,5 red nsta notit"
     78settitle "$source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)" ' ' $defatt
     79setaxelabels "Freq. (MHz)" "Mean Median[(ON-OFF)[r,c]/Gain[r]] Rebin(${nFreqBin})" $defatt
     80
     81
     82##Reduced Sigma of the median
     83newwin 1 1
     84del rss0 rss1
     85objaoper sigmamedred row 0 rss0
     86objaoper sigmamedred row 1 rss1
     87graphicatt "xylimits=1250,1500,0,0.01"
     88plot2d rss0 (n/${nFreqBin})*250+1250 val n>0 "marker=fcircle,5 blue nsta notit"
     89plot2d rss1 (n/${nFreqBin})*250+1250 val n>0 "same marker=fcircle,5 red nsta notit"
     90settitle "$source (${ncycles} cycles) Ch 0 (blue) Ch 1 (red)" ' ' $defatt
     91setaxelabels "Freq. (MHz)" "Sigma Median[(ON-OFF)[r,c]/Gain[r]] Rebin(${nFreqBin})" $defatt
     92 
     93
     94endif
     95
Note: See TracChangeset for help on using the changeset viewer.