Changeset 523 for BAORadio/AmasNancay/analyse.cc
- Timestamp:
- Sep 22, 2011, 10:32:01 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BAORadio/AmasNancay/analyse.cc
r514 r523 83 83 } 84 84 //----- 85 //JEC 22/9/11 comparison, not case sensitive to sort File liste START 86 bool stringCompare( const string &left, const string &right ){ 87 if( left.size() < right.size() ) 88 return true; 89 return false; 90 for( string::const_iterator lit = left.begin(), rit = right.begin(); lit != left.end() && rit != right.end(); ++lit, ++rit ) 91 if( tolower( *lit ) < tolower( *rit ) ) 92 return true; 93 else if( tolower( *lit ) > tolower( *rit ) ) 94 return false; 95 }//JEC 22/9/11 comparison, not case sensitive to sort File liste END 96 //----- 85 97 list<string> ListOfFileInDir(string dir, string filePettern) throw(string) { 86 98 list<string> theList; … … 89 101 DIR *dip; 90 102 struct dirent *dit; 91 string msg; 92 string fileName; 103 string msg; string fileName; 93 104 string fullFileName; 94 105 size_t found; … … 111 122 throw msg; 112 123 } 124 125 //JEC 22/9/11 START 126 theList.sort(stringCompare); 127 //JEC 22/9/11 END 128 113 129 return theList; 114 130 } … … 290 306 ka+=2; 291 307 } 292 if (strcmp(arg[ka],"-act")==0) {308 else if (strcmp(arg[ka],"-act")==0) { 293 309 action=arg[ka+1]; 294 310 ka+=2; 295 311 } 296 if (strcmp(arg[ka],"-inPath")==0) {312 else if (strcmp(arg[ka],"-inPath")==0) { 297 313 inputPath=arg[ka+1]; 298 314 ka+=2; 299 315 } 300 if (strcmp(arg[ka],"-outPath")==0) {316 else if (strcmp(arg[ka],"-outPath")==0) { 301 317 outputPath=arg[ka+1]; 302 318 ka+=2; … … 346 362 347 363 364 //JEC 21/9/11 Give the input parameters START 365 cout << " action " << action << "\n" 366 << " inputPath = " << inputPath << "\n" 367 << " outputPath = " << outputPath << "\n" 368 << " sourceName = " << sourceName << "\n" 369 << " scaFile = " << scaFile << "\n" 370 << " dateOfRun = " << dateOfRun << "\n" 371 << " spectraDirectory = " << spectraDirectory << "\n" 372 << " freqBAOCalib = " << freqBAOCalib << "\n" 373 << " bandWidthBAOCalib = " << bandWidthBAOCalib << "\n" 374 << " debuglev = " << debuglev << "\n" 375 << " mode = " << mode << "\n" 376 << " numcycle = " << numcycle << "\n" 377 << " calibrationOpt = " << calibrationOpt << endl; 378 //JEC 21/9/11 Give the input parameters END 379 348 380 349 381 try { … … 356 388 } 357 389 390 391 392 358 393 359 394 // … … 671 706 iSpectre != iSpectreEnd ; ++iSpectre, ++id) { 672 707 tag = "specRaw"; 708 709 //JEC 20/9/11 modif tag to take into account Mode and Cycle number START 710 // stringstream sid; 711 // sid << id; 712 // tag += sid.str(); 713 tag += (iSpectre->first).first; 673 714 stringstream sid; 674 sid << id;715 sid << (iSpectre->first).second; 675 716 tag += sid.str(); 717 if(debuglev_>9) { 718 cout << "save tag<" << tag << ">" << endl; 719 } 720 //JEC 20/9/11 modif tag to take into account Mode and Cycle number END 721 676 722 fos << PPFNameTag(tag) << iSpectre->second; 677 723 } … … 687 733 //------------------------------------------ 688 734 //Read BAO calibration files 689 TMatrix<r_4> calibBAOfactors;690 735 sa_size_t nr,nc; //values read 691 bool first = true; 692 693 for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){ 694 string calibFileName = "./" + sourceName_ + "/" 695 + dateOfRun_ + StringToLower(sourceName_) + "-" + mode + "-" + freqBAOCalibration_ + "MHz"; 696 stringstream channel; 697 channel << iCh; 698 calibFileName += "-Ch" + channel.str() + "Cycles.txt"; 699 if(debuglev_>0) cout << "Read file " << calibFileName << endl; 700 ifstream ifs(calibFileName.c_str()); 701 if ( ! ifs.is_open() ) { 702 rc = 999; 703 throw calibFileName + " cannot be opened..."; 704 } 705 TVector<r_4> aCalib; 706 aCalib.ReadASCII(ifs,nr,nc); 707 if(first){ 708 first = false; 709 calibBAOfactors.SetSize(NUMBER_OF_CHANNELS,nr); 710 } 711 calibBAOfactors( Range(iCh), Range::all() ) = aCalib.Transpose(); 712 ifs.close(); 713 }//end of loop on channels 714 736 //JEC 20/9/11 use mean calibration coeff upon all cycles START 737 // bool first = true; 738 // TMatrix<r_4> calibBAOfactors; 739 // for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){ 740 // string calibFileName = inputPath_+ "/" 741 // + sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_) 742 // + "/calib_" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_" 743 // + mode + "_" + freqBAOCalibration_ + "MHz"; 744 // stringstream channel; 745 // channel << iCh; 746 // calibFileName += "-Ch" + channel.str() + "Cycles.txt"; 747 // if(debuglev_>0) cout << "Read file " << calibFileName << endl; 748 // ifstream ifs(calibFileName.c_str()); 749 // if ( ! ifs.is_open() ) { 750 // rc = 999; 751 // throw calibFileName + " cannot be opened..."; 752 // } 753 // TVector<r_4> aCalib; 754 // if(debuglev_>9) cout << "Debug 1" << endl; 755 // aCalib.ReadASCII(ifs,nr,nc); 756 // if(debuglev_>9) cout << "Debug 2" << endl; 757 // if(first){ 758 // first = false; 759 // if(debuglev_>9) cout << "Debug 3" << endl; 760 // calibBAOfactors.SetSize(NUMBER_OF_CHANNELS,nr); 761 // if(debuglev_>9) cout << "Debug 4" << endl; 762 // } 763 // calibBAOfactors( Range(iCh), Range::all() ) = aCalib.Transpose(); 764 // if(debuglev_>9) cout << "Debug 5" << endl; 765 // ifs.close(); 766 // }//end of loop on channels 767 768 769 string calibFileName = inputPath_+ "/" 770 + sourceName_ + "/" + dateOfRun_ + StringToLower(sourceName_) 771 + "/calib_" + dateOfRun_ + "_" + StringToLower(sourceName_) + "_" 772 + mode + "_" + freqBAOCalibration_ + "MHz-All.txt"; 773 774 if(debuglev_>0) cout << "Read file " << calibFileName << endl; 775 ifstream ifs(calibFileName.c_str()); 776 if ( ! ifs.is_open() ) { 777 rc = 999; 778 throw calibFileName + " cannot be opened..."; 779 } 780 TVector<r_4> calibBAOfactors; 781 if(debuglev_>9) cout << "Debug 1" << endl; 782 calibBAOfactors.ReadASCII(ifs,nr,nc); 783 if(debuglev_>9){ 784 cout << "Debug 2: (nr,nc): "<< nr << "," << nc << endl; 785 calibBAOfactors.Print(cout); 786 } 787 788 //JEC 20/9/11 use mean calibration coeff upon all cycles END 715 789 716 790 // 717 791 //spectra corrected by BAO calibration factor 718 //make it different on Channels and Cycles (1/06/2011) 792 //-----make it different on Channels and Cycles (1/06/2011) OBSOLETE 793 //use mean calibration coeff upon all cycles (20/6/11) 719 794 //warning cycles are numbered from 1,...,N 720 795 // … … 724 799 725 800 for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){ 726 specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh,icycle-1); 801 //JEC 20/9/11 use mean calibration coeff upon all cycles START 802 803 // specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh,icycle-1); 804 specmtx( Range(iCh), Range::all() ) /= calibBAOfactors(iCh); 805 //JEC 20/9/11 use mean calibration coeff upon all cycles END 727 806 } 728 807 } … … 739 818 id=0; 740 819 for (iSpectre = spectreCollect.begin();iSpectre != iSpectreEnd ; ++iSpectre, ++id) { 820 741 821 tag = "specBAOCalib"; 822 //JEC 20/9/11 modif tag to take into account Mode and Cycle number START 823 // stringstream sid; 824 // sid << id; 825 // tag += sid.str(); 826 tag += (iSpectre->first).first; 742 827 stringstream sid; 743 sid << id;828 sid << (iSpectre->first).second; 744 829 tag += sid.str(); 745 fos << PPFNameTag(tag) << (*iSpectre).second; 830 if(debuglev_>9) { 831 cout << "save tag<" << tag << ">" << endl; 832 } 833 //JEC 20/9/11 modif tag to take into account Mode and Cycle number END 834 835 fos << PPFNameTag(tag) << iSpectre->second; 746 836 } 747 837 }//end of save fits … … 775 865 for (iSpectre = spectreCollect.begin();iSpectre != iSpectreEnd ; ++iSpectre, ++id) { 776 866 tag = "specBAORTCalib"; 867 //JEC 20/9/11 modif tag to take into account Mode and Cycle number START 868 // stringstream sid; 869 // sid << id; 870 // tag += sid.str(); 871 tag += (iSpectre->first).first; 777 872 stringstream sid; 778 sid << id;873 sid << (iSpectre->first).second; 779 874 tag += sid.str(); 780 fos << PPFNameTag(tag) << (*iSpectre).second; 875 if(debuglev_>9) { 876 cout << "save tag<" << tag << ">" << endl; 877 } 878 //JEC 20/9/11 modif tag to take into account Mode and Cycle number END 879 fos << PPFNameTag(tag) << iSpectre->second; 781 880 } 782 881 }//end of save fits … … 821 920 tag = "specONOFF"; 822 921 stringstream sid; 823 sid << id; 922 //JEC 20/9/11 sid << id; 923 sid << iDiff->first; 824 924 tag += sid.str(); 825 fos << PPFNameTag(tag) << (*iDiff).second; 925 if(debuglev_>9) { 926 cout << "save tag<" << tag << ">" << endl; 927 } 928 fos << PPFNameTag(tag) << iDiff->second; 826 929 } 827 930 //save the mean also … … 869 972 iFileEnd = listOfSpecFiles.end(); 870 973 map<string, r_4> meanpowerCollect; 974 //JEC 21/9/11 add meanpower for each Channels START 975 map<string, r_4> meanPowerPerChanCollect; 976 //JEC 21/9/11 add meanpower for each Channels END 977 871 978 map<string, r_4>::const_iterator iMeanPow, iMeanPowEnd; 872 979 … … 876 983 aSpectrum >> spectre; 877 984 meanpowerCollect[*iFile] = spectre.Sum()/spectre.Size(); 985 //JEC 21/9/11 add meanpower for each Channels START 986 for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh) { 987 TVector<r_4> specChan(NUMBER_OF_FREQ); 988 specChan = spectre.Row(iCh).Transpose(); 989 stringstream tmp; 990 tmp << iCh; 991 string tag = *iFile + "_" + tmp.str(); 992 meanPowerPerChanCollect[tag] = specChan.Sum()/specChan.Size(); 993 } 994 //JEC 21/9/11 add meanpower for each Channels END 878 995 }//end of for files 879 996 pair<string, r_4> minelement = *min_element(meanpowerCollect.begin(),meanpowerCollect.end(),compare); … … 929 1046 { 930 1047 vector<r_4> tmp; 1048 //JEC 21/9/11 add meanpower for each Channels START 1049 vector<r_4> tmpCh0; //for Chan 0 1050 vector<r_4> tmpCh1; //for Chan 1 1051 //JEC 21/9/11 add meanpower for each Channels END 931 1052 for (iFile = listOfSpecFiles.begin(); iFile != iFileEnd; ++iFile) { 1053 if (debuglev_>9) { 1054 cout << "Gain: save mean power of file: " << *iFile << endl; 1055 } 932 1056 tmp.push_back(meanpowerCollect[*iFile]); 1057 //JEC 21/9/11 add meanpower for each Channels START 1058 stringstream tmp0; 1059 tmp0 << (sa_size_t)0; 1060 string tag0 = *iFile + "_" + tmp0.str(); 1061 tmpCh0.push_back(meanPowerPerChanCollect[tag0]); 1062 if (NUMBER_OF_CHANNELS>1){ 1063 stringstream tmp1; 1064 tmp1 << (sa_size_t)1; 1065 string tag1 = *iFile + "_" + tmp1.str(); 1066 tmpCh1.push_back(meanPowerPerChanCollect[tag1]); 1067 } 1068 //JEC 21/9/11 add meanpower for each Channels END 933 1069 } 934 1070 string fileName; … … 937 1073 POutPersist fos(fileName); 938 1074 TVector<r_4> tvtmp(tmp); 939 fos.PutObject(tvtmp,"gainmoni"); 940 } 941 942 1075 fos.PutObject(tvtmp,"gainmoni"); //Attention initialement le tag etait "monitor"... 1076 //JEC 21/9/11 add meanpower for each Channels START 1077 TVector<r_4> tvtmp0(tmpCh0); 1078 fos.PutObject(tvtmp0,"gainmoni0"); 1079 if (NUMBER_OF_CHANNELS>1){ 1080 TVector<r_4> tvtmp1(tmpCh1); 1081 fos.PutObject(tvtmp1,"gainmoni1"); 1082 } 1083 //JEC 21/9/11 add meanpower for each Channels END 1084 } 1085 943 1086 cout << "OK gain finished" <<endl; 944 1087 return rc;
Note: See TracChangeset
for help on using the changeset viewer.