Esempio n. 1
0
Fit3D::Fit3D(
    TString input_ntuple_file,
    TString analysis_name,
    TString x_axis_label,
    TString x_axis_unit,
    double min_x_bin_edge,
    double max_x_bin_edge,
    TString y_axis_label,
    TString y_axis_unit,
    double min_y_bin_edge,
    double max_y_bin_edge,
    TString z_axis_label,
    TString z_axis_unit,
    double min_z_bin_edge,
    double max_z_bin_edge)
  : DileptonEvents(input_ntuple_file, analysis_name)
{
  std::cout << "Initiliazing Fit3D class." << std::endl;
  
  output_path_
      = "/home/matt/research/belle/adcab/analysis/DileptonEvents/Fit3D/output/"
      + analysis_name + "/";
  
  boost::filesystem::path output_dir(output_path_);
  
  if (boost::filesystem::exists(output_dir)) {
    cout << "Output path exists. Overwriting directory contents!\n";
  } else {
    cout << "Output path does not exist. Creating new directory.\n";
    boost::filesystem::create_directories(output_dir);
  }
  
  // Remove information about moving files. Really, all RooMsgService streams
  //   should be sent to a debug log.
  RooMsgService::instance().getStream(1).removeTopic(RooFit::ObjectHandling);
  RooMsgService::instance().getStream(1).removeTopic(RooFit::Plotting);
  RooMsgService::instance().getStream(0).removeTopic(RooFit::Minimization);
  RooMsgService::instance().getStream(1).removeTopic(RooFit::Minimization);

  // Define the data set elements and add them to the dataset.
  x_variable_ = new RooRealVar(
      "x_variable", x_axis_label, min_x_bin_edge, max_x_bin_edge, x_axis_unit);
  y_variable_ = new RooRealVar(
      "y_variable", y_axis_label, min_y_bin_edge, max_y_bin_edge, y_axis_unit);
  z_variable_ = new RooRealVar(
      "z_variable", z_axis_label, min_z_bin_edge, max_z_bin_edge, z_axis_unit);
  x_variable_->setBins(20);
  y_variable_->setBins(20);
  z_variable_->setBins(20);
  std::cout << "Adding new columns to dataset." << std::endl;
  RooArgSet analysis_variables(*x_variable_, *y_variable_, *z_variable_);
  data_set_->printArgs(cout);
  std::cout << std::endl;
  recreateDataSet(analysis_variables);
  data_set_->printArgs(cout);
  std::cout << std::endl;
  
  // Construct the histograms.
  TString name;
  name.Clear();
  histograms_.clear();

  for (int i = 0; i < tags_.species_.size(); ++i) {
    HistogramListOverEventSigns event_sign_histograms;
    event_sign_histograms.clear();
    for (int j = 0; j < tags_.signs_.size(); ++j) {
      HistogramListOverComponents component_histograms;
      component_histograms.clear();
      for (int k = 0; k < tags_.components_.size(); ++k) {
        name.Append(tags_.species_[i]);
        name.Append("_");
        name.Append(tags_.signs_[j]);
        name.Append("_");
        name.Append(tags_.components_[k]);
        TH3D component_histogram(name, name, 
            x_variable_->getBins(), min_x_bin_edge, max_x_bin_edge,
            y_variable_->getBins(), min_y_bin_edge, max_y_bin_edge, 
            z_variable_->getBins(), min_z_bin_edge, max_z_bin_edge);
        component_histograms.push_back(component_histogram);
        name.Clear();
      }
      event_sign_histograms.push_back(component_histograms);
    }
    histograms_.push_back(event_sign_histograms);
  }
}
Esempio n. 2
0
//============================================================
// <T>将一行保存至文件。</T>
//
// @param out 文件输出流。
//============================================================
void FCsvLine::Store(TDataOutput& out){
   TString csvCell;
   TString csvLine;
   TInt count = _pCells->Count();
   for(TInt n = 0; n < count; n++){
      csvCell.Clear();
      TString tempCell;
      TStringRefer cell = _pCells->Get(n);
      TInt cellLength = cell.Length();
      // 不允许空的格
      MO_ASSERT( 0 != cellLength);
      // 处理双引号
      TInt start = 0;
      TInt index = cell.IndexOf('"');
      if(ENotFound != index){
         while(ENotFound != index){
            index++;
            tempCell.Append(cell.SubStrC(start, index));
            // 不以引号开头或结尾
            if(index != 1 && index != cellLength){
               tempCell.Append('"');
            }else{
               tempCell.Append('"');
               tempCell.Append('"');
            }
            start = index;
            if(start < cellLength){
               index = cell.IndexOf('"', start);
            }else{
               break;
            }
         }
         // 拷贝余下内容
         if(start < cellLength - 1){
            tempCell.Append(cell.SubStrC(start, cell.Length()));
         }
      }else{
         tempCell = cell;
      }
      // 处理逗号
      TInt tempCellLen = tempCell.Length();
      if(tempCell.Contains(',')){
         // 不以“开头
         if(tempCell[0] != '"'){
            csvCell.Append('"');
         }
         csvCell.Append(tempCell);
         // 不以“结尾
         if(tempCell[tempCellLen  -1] != '"'){
            csvCell.Append('"');
         }
      }else{
         csvCell = tempCell;
      }
      // 处理换行符
      TInt csvCellLen = csvCell.Length();
      TInt lfStart = 0;
      TInt lfIndex = csvCell.IndexOf('\n');
      if(ENotFound != lfIndex){
         while(ENotFound != lfIndex){
            //  拷贝换行符前面的内容
            if(lfStart < lfIndex){
               TString sub = csvCell.SubStrC(lfStart, lfIndex);
               csvLine.Append(sub);
            }
            csvLine.Append('\\');
            csvLine.Append('n');
            // 跳过换行符
            lfIndex++;
            lfStart = lfIndex;
            if(lfStart < csvCellLen){
               lfIndex = csvCell.IndexOf('\n', lfStart);
            }else{
               break;
            }  
         }
         if(lfStart < csvCellLen - 1){
            TString sub = csvCell.SubStrC(lfStart, csvCell.Length());
            csvLine.Append(sub);
         }
      }else{
         csvLine.Append(csvCell);
      }
      // 一格格式化结束
      if((count - 1) == n){
         csvLine.Append('\n');
      }else{
         csvLine.Append(',');
      }  
   }
   out.Write((TCharC*)csvLine, csvLine.Length());
}