Changeset 602


Ignore:
Timestamp:
Nov 14, 2011, 2:28:01 PM (13 years ago)
Author:
campagne
Message:

rewrite meanRawDiffOnOffCycles (jec)

Location:
BAORadio/AmasNancay/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • BAORadio/AmasNancay/trunk/makefile

    r598 r602  
    77PKGOLIST =
    88
    9 EXELIST = $(EXE)analyse $(EXE)mergeAnaFiles $(EXE)anaTools
     9EXELIST = $(EXE)analyse $(EXE)mergeAnaFiles
    1010
    11 EXEOLIST = $(EXE)analyse.o $(EXE)mergeAnaFiles.o $(EXE)anaTools.o
     11EXEOLIST = $(EXE)analyse.o $(EXE)mergeAnaFiles.o
    1212
    1313
    14 all : analyse mergeAnaFiles anaTools
     14all : analyse mergeAnaFiles
    1515
    1616clean :
  • BAORadio/AmasNancay/trunk/mergeAnaFiles.cc

    r595 r602  
    3838//Usage
    3939//
     40//./Objs/mergeAnaFiles -act meanRawDiffOnOff -inPath /sps/baoradio/AmasNancay/JEC/ -src NGC4383 -ppfFile dataRaw -debug 1000 -mxcycles 10
    4041//./Objs/mergeAnaFiles -act meanCalibBAODiffOnOff -inPath /sps/baoradio/AmasNancay/JEC/ -src Abell85 -ppfFile dataRaw -debug 1 -mxcycles 500
    4142//./Objs/mergeAnaFiles -src Abell85 -act meanCalibBAODiffOnOff -mxcycles 500 -calibfreq 1410 -inPath /sps/baoradio/AmasNancay/JEC/ -ppfFile dataRaw -debug 1 >& mergeAna-500.log
     
    644645      aSpecOn_BAOCalibCycle(Range(1),Range::all()) /= calibBAO_On_Cycle_Ch1[*ic];
    645646     
     647      //Load OFF phase
    646648      ppftag = "specRawOff"+cycle.str();
    647649      TMatrix<r_4> aSpecOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
     
    823825  }//end of save
    824826}
     827//JEC 14/11/11 New meanRawDiffOnOffCycles START
    825828//-------------------------------------------------------
    826 //Compute the mean of Diff ON-OFF Raw spectra and also the mean/sigma of rebinned spectra
     829//Compute the mean of Diff ON-OFF/OFF from Raw spectra
    827830//Used like:
    828831//
     
    837840  list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
    838841  iFileEnd = listOfFiles.end();
    839  
    840   StringMatch match("specONOFFRaw[0-9]+"); //Tag of the PPF objects
    841   TMatrix<r_4> meanOfSpectra(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
    842   uint_4 nSpectra=0;
     842
     843  //mean ON-OFF over the list of cycles
     844  TMatrix<r_4> meanDiffONOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);      //(ON-OFF)/GAIN
     845  TMatrix<r_4> meanDiffONOFFovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //(ON-OFF)/Filtered_OFF
     846
     847  int totalNumberCycles=0; //total number of cycles
     848
    843849  //Loop on files
    844850  for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
    845851    if (para.debuglev_>90){
    846       cout << "load file <" << *iFile << ">" << endl;
    847852    }
    848853    PInPersist fin(*iFile);
    849854    vector<string> vec = fin.GetNameTags();
    850     list<string> listOfSpectra;
    851     //Keep only required PPF objects
    852     std::remove_copy_if(
    853                         vec.begin(), vec.end(), back_inserter(listOfSpectra),
    854                         not1(match)
    855                         );
     855
     856    vector<string> modeList;
     857    modeList.push_back("On");
     858    modeList.push_back("Off");
     859    vector<string>::const_iterator iMode;
     860   
     861    map<string, list<int> > cycleModeCollect;
     862   
     863    for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
     864      list<string> listOfSpectra;
     865      //Keep only required PPF objects
     866      string matchstr = "specRaw"+(*iMode)+"[0-9]+";
     867      std::remove_copy_if(
     868                          vec.begin(), vec.end(), back_inserter(listOfSpectra),
     869                          not1(StringMatch(matchstr))
     870                          );
     871     
     872      listOfSpectra.sort(stringCompare);
     873      iSpecEnd = listOfSpectra.end();
     874     
     875      matchstr = "[0-9]+";
     876      //Loop of spectra matrix
     877      list<int> listOfCycles;
     878      for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd;  ++iSpec){
     879        int b,e;
     880        regexp(iSpec->c_str(),matchstr.c_str(),&b,&e);
     881        if (para.debuglev_>90){
     882          cout << " spactra <" << *iSpec << ">" << endl;
     883          cout << " cycle " << iSpec->substr(b) << endl;
     884        }
     885        listOfCycles.push_back(atoi((iSpec->substr(b)).c_str()));
     886      }//end loop spectra
     887      cycleModeCollect[*iMode] = listOfCycles;
     888    }//end of mode   
     889
     890    //Take the Intersection of the list Of cycles in mode Off and On   
     891    list<int> commonCycles;
     892    set_intersection(cycleModeCollect["On"].begin(),
     893                     cycleModeCollect["On"].end(),
     894                     cycleModeCollect["Off"].begin(),
     895                     cycleModeCollect["Off"].end(),
     896                     back_inserter(commonCycles)
     897                     );
     898   
     899    if (para.debuglev_>90){
     900      cout << "Liste of cycles common to On & Off: <";
     901      for (list<int>::iterator i=commonCycles.begin(); i!=commonCycles.end(); ++i){
     902        cout << *i << " ";
     903      }
     904      cout << ">" << endl;
     905    }
     906
     907    //Loop on cyles
     908    for (list<int>::iterator ic=commonCycles.begin(); ic!=commonCycles.end(); ++ic){
     909     
     910      string ppftag;
     911      //load ON phase
     912      stringstream cycle;
     913      cycle << *ic;
     914      ppftag = "specRawOn"+cycle.str();
     915      TMatrix<r_4> aSpecOn(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
     916      fin.GetObject(aSpecOn,ppftag);
     917
     918      //Load OFF phase
     919      ppftag = "specRawOff"+cycle.str();
     920      TMatrix<r_4> aSpecOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
     921      fin.GetObject(aSpecOff,ppftag);
     922     
     923      //Perform the difference ON-OFF
     924      TMatrix<r_4> diffOnOff_noCalib = aSpecOn - aSpecOff;
     925      meanDiffONOFF_noCalib += diffOnOff_noCalib;
     926     
     927      //JEC 29/10/11 add ON-OFF/OFF
     928      TMatrix<r_4> diffOnOffOvOff_noCalib(diffOnOff_noCalib,false); //do not share data
     929      TMatrix<r_4> aSpecOffFitltered(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
     930      sa_size_t halfWidth = 35; //number of freq. bin for the 1/2 width of the filtering window
     931      medianFiltering(aSpecOff,halfWidth,aSpecOffFitltered);
     932     
     933      diffOnOffOvOff_noCalib.Div(aSpecOffFitltered); //division in place
     934      meanDiffONOFFovOFF_noCalib += diffOnOffOvOff_noCalib;
     935
     936      totalNumberCycles++;
     937
     938      //Quit if enough
     939      if (totalNumberCycles >= para.maxNumberCycles_) break;   
     940    }//end of cycles
     941
     942    if (totalNumberCycles >= para.maxNumberCycles_) break;         
     943
     944  }//end files
     945  cout << "End of jobs: we have treated " << totalNumberCycles << " cycles" << endl;
     946  //Normalisation
     947  if(totalNumberCycles > 0){
     948    meanDiffONOFFovOFF_noCalib  /= (r_4)totalNumberCycles;
     949    meanDiffONOFF_noCalib       /= (r_4)totalNumberCycles;
     950  } 
     951
     952  {//save results
     953    stringstream tmp;
     954    tmp << totalNumberCycles;
     955    string fileName = para.outPath_+"/rawOnOffDiff_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
     956
     957    POutPersist fos(fileName);
     958    cout << "Save output in " << fileName << endl;
     959
     960    string tag = "meanNoCalib";
     961    fos << PPFNameTag(tag) << meanDiffONOFF_noCalib;
     962   
     963    tag = "meanOvOffNoCalib";
     964    fos << PPFNameTag(tag) << meanDiffONOFFovOFF_noCalib;
    856965   
    857     listOfSpectra.sort(stringCompare);
    858     iSpecEnd = listOfSpectra.end();
    859     //Loop of spectra matrix
    860     for (iSpec = listOfSpectra.begin(); iSpec !=iSpecEnd;  ++iSpec){
    861       if (para.debuglev_>90){
    862         cout << " spactra <" << *iSpec << ">" << endl;
    863       }
    864       TMatrix<r_4> aSpec(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
    865       fin.GetObject(aSpec,*iSpec);
    866       //How to see if the GetObject is ok?? Ask Reza
    867       nSpectra++;
    868       meanOfSpectra+=aSpec;
    869     }//eo loop on spectra in a file
    870   }//eo loop on files
    871  
    872   //Normalisation
    873   if(nSpectra>0)meanOfSpectra/=(r_4)(nSpectra);
    874 
    875   //Compute the reduced version of the mean and sigma
    876   TMatrix<r_4> meanRedMtx(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
    877   TMatrix<r_4> sigmaRedMtx(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
    878   reduceSpectra(meanOfSpectra,meanRedMtx,sigmaRedMtx);
    879 
    880   {//Save the result
    881     stringstream tmp;
    882     tmp << nSpectra;
    883     string fileName = para.outPath_+"/meanDiffOnOffRaw_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
    884     cout << "Save mean based on " <<  nSpectra << " cycles " << endl;
    885     POutPersist fos(fileName);
    886 
    887     string tag = "mean";
    888     fos << PPFNameTag(tag) << meanOfSpectra;
    889     tag = "meanred";
    890     fos << PPFNameTag(tag) << meanRedMtx;
    891     tag = "sigmared";
    892     fos << PPFNameTag(tag) << sigmaRedMtx;
    893   }
    894 }
     966  }//end save
     967}
     968//JEC 14/11/11 New meanRawDiffOnOffCycles END
     969//-------------------------------------------------------
     970//JEC 14/11/11 Obsolete START
     971//-------------------------------------------------------
     972//Compute the mean of Diff ON-OFF Raw spectra and also the mean/sigma of rebinned spectra
     973//Used like:
     974//
     975// void meanRawDiffOnOffCycles() throw(string) {
     976//   list<string> listOfFiles;
     977//   string directoryName;
     978//   directoryName = para.inPath_ + "/" + para.sourceName_;
     979
     980//   //Make the listing of the directory
     981//   listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
     982 
     983//   list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
     984//   iFileEnd = listOfFiles.end();
     985 
     986//   StringMatch match("specONOFFRaw[0-9]+"); //Tag of the PPF objects
     987//   TMatrix<r_4> meanOfSpectra(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
     988//   uint_4 nSpectra=0;
     989//   //Loop on files
     990//   for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
     991//     if (para.debuglev_>90){
     992//       cout << "load file <" << *iFile << ">" << endl;
     993//     }
     994//     PInPersist fin(*iFile);
     995//     vector<string> vec = fin.GetNameTags();
     996//     list<string> listOfSpectra;
     997//     //Keep only required PPF objects
     998//     std::remove_copy_if(
     999//                      vec.begin(), vec.end(), back_inserter(listOfSpectra),
     1000//                      not1(match)
     1001//                      );
     1002   
     1003//     listOfSpectra.sort(stringCompare);
     1004//     iSpecEnd = listOfSpectra.end();
     1005//     //Loop of spectra matrix
     1006//     for (iSpec = listOfSpectra.begin(); iSpec !=iSpecEnd;  ++iSpec){
     1007//       if (para.debuglev_>90){
     1008//      cout << " spactra <" << *iSpec << ">" << endl;
     1009//       }
     1010//       TMatrix<r_4> aSpec(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
     1011//       fin.GetObject(aSpec,*iSpec);
     1012//       //How to see if the GetObject is ok?? Ask Reza
     1013//       nSpectra++;
     1014//       meanOfSpectra+=aSpec;
     1015//     }//eo loop on spectra in a file
     1016//   }//eo loop on files
     1017 
     1018//   //Normalisation
     1019//   if(nSpectra>0)meanOfSpectra/=(r_4)(nSpectra);
     1020
     1021//   //Compute the reduced version of the mean and sigma
     1022//   TMatrix<r_4> meanRedMtx(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
     1023//   TMatrix<r_4> sigmaRedMtx(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
     1024//   reduceSpectra(meanOfSpectra,meanRedMtx,sigmaRedMtx);
     1025
     1026//   {//Save the result
     1027//     stringstream tmp;
     1028//     tmp << nSpectra;
     1029//     string fileName = para.outPath_+"/meanDiffOnOffRaw_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
     1030//     cout << "Save mean based on " <<  nSpectra << " cycles " << endl;
     1031//     POutPersist fos(fileName);
     1032
     1033//     string tag = "mean";
     1034//     fos << PPFNameTag(tag) << meanOfSpectra;
     1035//     tag = "meanred";
     1036//     fos << PPFNameTag(tag) << meanRedMtx;
     1037//     tag = "sigmared";
     1038//     fos << PPFNameTag(tag) << sigmaRedMtx;
     1039//   }
     1040// }
     1041//JEC 14/11/11 Obsolete END
    8951042//-------------------------------------------------------
    8961043//Compute the median of Diff ON-OFF Raw spectra and also the mean/sigma of rebinned spectra
Note: See TracChangeset for help on using the changeset viewer.