Changeset 563


Ignore:
Timestamp:
Oct 10, 2011, 4:31:37 PM (13 years ago)
Author:
campagne
Message:

improve mean ON-OFF with Calib BAO (jec)

Location:
BAORadio/AmasNancay/trunk
Files:
1 added
2 edited

Legend:

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

    r562 r563  
    3636
    3737//-----------------------------------------------
     38//Usage
     39//
     40// ./Objs/mergeAnaFiles -act meanCalibBAODiffOnOff -inPath /sps/baoradio/AmasNancay/JEC/ -src Abell85 -ppfFile dataRaw -debug 1 -mxcycles 500
     41//
     42//
     43//
     44//-----------------------------------------------
    3845const sa_size_t NUMBER_OF_CHANNELS = 2;
    3946const sa_size_t NUMBER_OF_FREQ     = 8192;
    4047const r_4    LOWER_FREQUENCY       = 1250.0; //MHz
    4148const r_4    TOTAL_BANDWIDTH       = 250.0;  //MHz
    42 //-----------------------------------------------
    4349//Input parameters
    4450struct Param {
     
    6874                 sa_size_t chHigh,
    6975                 TVector<r_4>& vec){
     76 
    7077  sa_size_t nr = mtx.NRows();
     78 
    7179  for (sa_size_t ir=0; ir<nr; ir++){
    7280    TVector<r_4> tmp(mtx(Range(ir),Range(chLow,chHigh)),false);
     
    242250//-------------------------------------------------------
    243251//Compute the mean of Diff ON-OFF BAO-calibrated spectra and also the mean/sigma of rebinned spectra
    244 //Used like:
    245252//
    246 // void meanCalibBAODiffOnOffCycles() throw(string) {
    247 
    248 //   list<string> listOfFiles;
    249 //   string directoryName;
    250 //   directoryName = para.inPath_ + "/" + para.sourceName_;
    251 
    252 //   //Make the listing of the directory
    253 //   listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
    254  
    255 //   list<string>::const_iterator iFile, iFileEnd, iSpecOff, iSpecOffEnd, iSpecOn, iSpecOnEnd;
    256 //   iFileEnd = listOfFiles.end();
    257  
    258 
    259 //   //Loop on files
    260 //   uint_4 nRuns=0;
    261 //   TArray<r_4> tableOfSpectra(NUMBER_OF_FREQ,NUMBER_OF_CHANNELS,para.maxNumberCycles_); //para.maxNumberCycles_ should be large enough...
    262 
    263 
    264 //   for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
    265 //     if (para.debuglev_>90){
    266 //       cout << "load file <" << *iFile << ">" << endl;
    267 //     }
    268 
    269 //     vector<string> tokens;
    270 //     split(*File,"_",tokens);
    271 //     string dateOfRun = tokens[1];
    272 //     string srcLower = tokens[2];
    273 //     if (para.debuglev_>90){
    274 //       cout << "date <" << dateOfRun << ">" << endl;
    275 //     }
    276    
    277 //     PInPersist fin(*iFile);
    278 //     vector<string> vec = fin.GetNameTags();
    279 
    280 //     if (para.typeOfCalib_ == "perRun") {
    281 //       ///////////////////
    282 //       //make the calibration of the mean of all Off and On of the run and perform the difference
    283 
    284 //       vector<string> modeList;
    285 //       modeList.push_back("On");
    286 //       modeList.push_back("Off");
    287 //       vector<string>::const_iterator iMode;
    288 //       map<string, TMatrix<r_4> > spectreModeCollect;
    289 
    290 //       for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
    291 //      ///////////////////
    292 //      //
    293 //      //Compute the mean of the mode
    294 //      //
    295 //      list<string> listOfSpectra;
    296 //      //Keep only required PPF objects
    297 //      string matchstr = "specRaw"+(*iMode)+"[0-9]+";
    298 //      std::remove_copy_if(
    299 //                          vec.begin(), vec.end(), back_inserter(listOfSpectra),
    300 //                          not1(StringMatch(matchstr))
    301 //                          );
    302        
    303 //      listOfSpectra.sort(stringCompare);
    304 //      iSpecEnd = listOfSpectra.end();
    305 //      TMatrix<r_4> meanOfSpectra(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
    306 //      uint_4 nSpectra=0;
    307 //      //Loop of spectra matrix
    308 //      for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd;  ++iSpec){
    309 //        if (para.debuglev_>90){
    310 //          cout << " spactra <" << *iSpec << ">" << endl;
    311 //        }
    312 //        TMatrix<r_4> aSpec(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
    313 //        fin.GetObject(aSpec,*iSpec);
    314 //        //How to see if the GetObject is ok?? Ask Reza
    315 //        nSpectra++;
    316 //        meanOfSpectra+=aSpec;
    317 //      }//end loop Off
    318 //      //Mean
    319 //      if(nSpectra>0)meanOfSpectra=(r_4)(nSpectra);
    320 
    321 //      //BAO Calibrator
    322 //      string calibFileName = directoryName + "/"
    323 //        + "calib_" + dateOfRun + "_" + srcLower + "_"+(*iMode)+"_"
    324 //        + para.calibFreq_ +"MHz-All.txt";
    325 //      if(debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
    326 //      ifstream ifs(calibFileName.c_str());
    327 //      if ( ! ifs.is_open() ) {
    328 //        rc = 999;
    329 //        throw calibFileName + " cannot be opened...";
    330 //      }       
    331 //      TVector<r_4> calibBAOfactors;
    332 //      sa_size_t nr,nc; //values read
    333 //      calibBAOfactorsOff.ReadASCII(ifs,nr,nc);
    334 //      if(debuglev_>9){
    335 //        cout << "(nr,nc): "<< nr << "," << nc << endl;
    336 //        calibBAOfactors.Print(cout);
    337 //      }
    338        
    339 //      for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
    340 //        meanOfSpectra(Range(iCh), Range::all()) /=calibBAOfactors(iCh);
    341 //      }
    342 //      //storage
    343 //      spectreModeCollect.insert(pair<string, TMatrix<r_4> >(*iMode,TMatrix<r_4>(meanOfSpectra,false))); //do not share data (cf. SOPHYA)
    344 //       }//end of mode
    345 
    346 //       //Take the difference ON-OFF in current run
    347 //       TMatrix<r_4>diffOnOff = spectreModeCollect["On"]-spectreModeCollect["Off"];
    348 
    349 
    350 //     } else if (para.typeOfCalib_ == "perCycle") {
    351 //       //perform the calibration of the OFF and ON per cycle, then make the mean and take the diff
    352 //     } else {
    353 //       string msg="FATAL (meanCalibBAODiffOnOffCycles); unknown calibration mode "
    354 //      + para.typeOfCalib_ ;
    355 //       throw(msg);
    356 //     } 
    357 
    358 
    359 //     nRuns++;
    360    
    361 //   }//eo loop on spectra in a file
    362 // }
    363253void meanCalibBAODiffOnOffCycles() throw(string) {
    364254
     
    378268  TMatrix<r_4> meanDiffONOFF_perCycleCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);    //set to 0
    379269  char* onffTupleName[7]={"cycle",
    380                           "onoffRaw0","onoffRun0","onoffCycle0",
    381                           "onoffRaw1","onoffRun1","onoffCycle1"};
     270                          "onoffRaw0","onoffRaw1",
     271                          "onoffRun0","onoffRun1",
     272                          "onoffCycle0","onoffCycle1"};
    382273  NTuple onoffevolution(7,onffTupleName);
    383274  r_4 xnt[7];
    384275
    385276  //Lower and Higher freq. bin to perform mean follow up
    386   sa_size_t chLow = freqToChan(para.rcalibFreq_ - (para.rcalibBandFreq_*0.5));
     277  sa_size_t chLow  = freqToChan(para.rcalibFreq_ - (para.rcalibBandFreq_*0.5));
    387278  sa_size_t chHigh = freqToChan(para.rcalibFreq_ + (para.rcalibBandFreq_*0.5));
     279  if (para.debuglev_>90){
     280    cout << "freq. band for follow up [" <<  chLow << ", "<< chHigh << "]" << endl;
     281  }
    388282 
    389283  //Loop on files/run
     
    501395      double mean,sigma;
    502396      MeanSigma(coef,mean,sigma);
    503       cout << "Mean: " << mean << " sigma " << sigma << endl;
    504397      calibBAOfactors_Off_Run_Ch0.Column(1).SetCst(mean);
    505398    }
     
    533426      double mean,sigma;
    534427      MeanSigma(coef,mean,sigma);
    535       cout << "Mean: " << mean << " sigma " << sigma << endl;
     428      //      cout << "Mean: " << mean << " sigma " << sigma << endl;
    536429      calibBAOfactors_Off_Run_Ch1.Column(1).SetCst(mean);
    537430    }
     
    566459      double mean,sigma;
    567460      MeanSigma(coef,mean,sigma);
    568       cout << "Mean: " << mean << " sigma " << sigma << endl;
     461      //      cout << "Mean: " << mean << " sigma " << sigma << endl;
    569462      calibBAOfactors_On_Run_Ch0.Column(1).SetCst(mean);
    570463    }
     
    597490      double mean,sigma;
    598491      MeanSigma(coef,mean,sigma);
    599       cout << "Mean: " << mean << " sigma " << sigma << endl;
     492      //      cout << "Mean: " << mean << " sigma " << sigma << endl;
    600493      calibBAOfactors_On_Run_Ch1.Column(1).SetCst(mean);
    601494    }
     
    623516    nr = calibBAOfactors_Off_Run_Ch0.NRows();
    624517    for (sa_size_t ir=0; ir<nr; ++ir){
     518//       cout << "Calib. Off Run Ch0 cycle ["<< calibBAOfactors_Off_Run_Ch0(ir,0)<<"], val "
     519//         << calibBAOfactors_Off_Run_Ch0(ir,1) << endl;
     520
    625521      calibBAO_Off_Run_Ch0[(int)calibBAOfactors_Off_Run_Ch0(ir,0)]
    626522        = calibBAOfactors_Off_Run_Ch0(ir,1);
     
    631527      calibBAO_Off_Cycle_Ch1[(int)calibBAOfactors_Off_Cycle_Ch1(ir,0)]
    632528        = calibBAOfactors_Off_Cycle_Ch1(ir,1);
    633     }
     529    }//eo loop on coef Off
    634530   
    635531    nr = calibBAOfactors_On_Run_Ch0.NRows();
     
    643539      calibBAO_On_Cycle_Ch1[(int)calibBAOfactors_On_Cycle_Ch1(ir,0)]
    644540        = calibBAOfactors_On_Cycle_Ch1(ir,1);
    645     }
     541    }//eo loop on coef On
    646542     
    647 
    648    
    649 //      for (sa_size_t iCh=0;iCh<NUMBER_OF_CHANNELS;++iCh){
    650 //        meanOfSpectra(Range(iCh), Range::all()) /=calibBAOfactors(iCh);
    651 //      }
    652 
    653543    //Loop on cyles
    654544    for (list<int>::iterator ic=commonCycles.begin(); ic!=commonCycles.end(); ++ic){
    655545
    656       if(para.debuglev_>9){
     546      //Look if the cycle has been calibrated...
     547      bool isCycleCalibrated =
     548        ( calibBAO_On_Run_Ch0.count(*ic)    *
     549          calibBAO_On_Run_Ch1.count(*ic)    *
     550          calibBAO_Off_Run_Ch0.count(*ic)   *
     551          calibBAO_Off_Run_Ch1.count(*ic)   *
     552          calibBAO_On_Cycle_Ch0.count(*ic)  *
     553          calibBAO_On_Cycle_Ch1.count(*ic)  *
     554          calibBAO_Off_Cycle_Ch0.count(*ic) *
     555          calibBAO_Off_Cycle_Ch1.count(*ic) ) != 0 ? true : false;
     556
     557      if(para.debuglev_>9) {
    657558        cout << "Calibration coefficients for cycle "<<*ic << endl;
    658         cout << "Off Run Ch0 " << calibBAO_Off_Run_Ch0[*ic] << " "
    659              << "Ch1 " << calibBAO_Off_Run_Ch1[*ic] << "\n"
    660              << "On Run Ch0 " << calibBAO_On_Run_Ch0[*ic] << " "
    661              << "Ch1 " << calibBAO_On_Run_Ch1[*ic] << "\n"
    662              << "Off Cycle Ch0 " << calibBAO_Off_Cycle_Ch0[*ic] << " "
    663              << "Ch1 " << calibBAO_Off_Cycle_Ch1[*ic] << "\n"
    664              << "On Cycle Ch0 " << calibBAO_On_Cycle_Ch0[*ic] << " "
    665              << "Ch1 " << calibBAO_On_Cycle_Ch1[*ic] << endl;
    666       }
     559        if (isCycleCalibrated) {
     560          cout << "Cycle calibrated " << endl;
     561          cout << "Off Run Ch0 " << calibBAO_Off_Run_Ch0[*ic] << " "
     562               << "Ch1 " << calibBAO_Off_Run_Ch1[*ic] << "\n"
     563               << "On Run Ch0 " << calibBAO_On_Run_Ch0[*ic] << " "
     564               << "Ch1 " << calibBAO_On_Run_Ch1[*ic] << "\n"
     565               << "Off Cycle Ch0 " << calibBAO_Off_Cycle_Ch0[*ic] << " "
     566               << "Ch1 " << calibBAO_Off_Cycle_Ch1[*ic] << "\n"
     567               << "On Cycle Ch0 " << calibBAO_On_Cycle_Ch0[*ic] << " "
     568               << "Ch1 " << calibBAO_On_Cycle_Ch1[*ic] << endl;
     569        } else {
     570          cout << "Cycle NOT calibrated " << endl;
     571        }
     572      }//debug
     573
     574
     575      if ( ! isCycleCalibrated ) continue;
    667576     
    668577      string ppftag;
     
    706615      meanDiffONOFF_perCycleCalib += diffOnOff_perCycleCalib;
    707616
     617      //
     618      totalNumberCycles++;
    708619      //Fill NTuple
    709       xnt[0] = *ic;
     620      xnt[0] = totalNumberCycles;
    710621     
    711622      TVector<r_4> meanInRange_noCalib(NUMBER_OF_CHANNELS);
     
    721632      TVector<r_4> meanInRange_perCycleCalib(NUMBER_OF_CHANNELS);
    722633      meanInRange(diffOnOff_perCycleCalib,chLow,chHigh,meanInRange_perCycleCalib);
    723       xnt[3] = meanInRange_perCycleCalib(0);
    724       xnt[4] = meanInRange_perCycleCalib(1);
     634      xnt[5] = meanInRange_perCycleCalib(0);
     635      xnt[6] = meanInRange_perCycleCalib(1);
    725636     
    726637      onoffevolution.Fill(xnt);
    727638
    728       totalNumberCycles++;
     639      //Quit if enough
    729640      if (totalNumberCycles >= para.maxNumberCycles_) break;   
    730641
     
    735646  cout << "End of jobs: we have treated " << totalNumberCycles << " cycles" << endl;
    736647  //Normalisation
    737   if(totalNumberCycles>0){
     648  if(totalNumberCycles > 0){
    738649    meanDiffONOFF_noCalib       /= (r_4)totalNumberCycles;
    739650    meanDiffONOFF_perRunCalib   /= (r_4)totalNumberCycles;
     
    758669    tmp << totalNumberCycles;
    759670    string fileName = para.outPath_+"/onoffsurvey_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
     671
    760672    POutPersist fos(fileName);
     673    cout << "Save output in " << fileName << endl;
    761674
    762675    string tag = "meanNoCalib";
  • BAORadio/AmasNancay/trunk/plotDiffOnOff.pic

    r556 r563  
    88set action $4
    99
    10 set defatt "font=helvetica,bold,20"
     10set defatt "font=helvetica,bold,20 fixedfontsize"
    1111
    1212
Note: See TracChangeset for help on using the changeset viewer.