当前位置: 首页>>代码示例>>C++>>正文


C++ TTree::Clone方法代码示例

本文整理汇总了C++中TTree::Clone方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::Clone方法的具体用法?C++ TTree::Clone怎么用?C++ TTree::Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TTree的用法示例。


在下文中一共展示了TTree::Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ChangeDataTreeName

void ChangeDataTreeName(std::string suffix){

  // Define names
  TString filename = "", treename = "", histname = "";
  filename.Form("central_%s.root",suffix.c_str());
  treename.Form("id_%s",suffix.c_str());
  histname.Form("sumOfMcWeights_%s",suffix.c_str());

  TString _pathFile(string(getenv("WORKAREA")) + "/histoAna" + "/SusyAna/histos_110312_13fb_n0111_DD_MMtrial9_SYS_HFT/HFTOutputs_merge/");
  filename = _pathFile+filename;
  cout << "open " << filename << endl;

  // Open file
  TFile* file         = new TFile(filename,"UPDATE");
  if(file->IsOpen()==kFALSE){
    cerr << "Cannot open file " << filename << endl;
    abort();
  }
  file->ls();
  TTree* treeOriginal = (TTree*) file->Get(treename);
  TH1D*  histOriginal = (TH1D*)  file->Get(histname);
  TTree* treeNew      = (TTree*) treeOriginal->Clone();
  TH1D*  histNew      = (TH1D*)  histOriginal->Clone();

  // Set-Write-Delete
  histNew->SetName ("sumOfMcWeights_Data" );
  histNew->SetTitle("sumOfMcWeights_Data" );
  histNew->Write   ("",TObject::kOverwrite);
  treeNew->SetName ("id_Data"             );
  treeNew->SetTitle("id_Data"             );
  treeNew->Write   ("",TObject::kOverwrite);
  file->Delete     (histname+";1"         );
  file->Delete     (treename+";1"         );

  // Close file
  file->Close();
}
开发者ID:ataffard,项目名称:SusyWeakProdAna,代码行数:37,代码来源:ChangeDataTreeName.C

示例2: newData

DataFile::GetData(){
  stringstream convert;
  int nameVal = 0;
  convert.str(filename);
  convert >> nameVal;
  bool success = false;
  //Find file type
  string type = "";
  size_t pos = filename.find_last_of('.');
  if(gType.compare("XS")==0){
    TNtuple newData ("newData","", cols.c_str() );
    newData.ReadFile(name.c_str());
    cout<<"TNtuple created"<<endl;
    dataTuple = (TNtuple*) newData.Clone();
    cout<<name.c_str()<<endl;
    cout<<dataTuple<<endl;
    success = true;
  }
  else{
    if(pos != string::npos){
      if(filename[pos+1] == 'r'){
        if(filename[pos-1] == 'e'){
          type.assign("ginuke");
        }
        else{
          type.assign("gst");
        }
      }
      else{
        type.assign("txt");
      }
    }
    else{
      type.assign("chain");
    }
    if(type[0]!='t'){
      if(type[0]=='g'){
        //Normal .ginuke file, Easy
        file = new TFile(name.c_str());
        if(file->IsOpen()){
          TTree* dummy = file->Get(type.c_str());
          dataTree = (TTree*)dummy->Clone(); 
          delete dummy;
          success=true;
        }
        else{
          cout<<name.c_str()<<" was not found. Skipping [GENIE] tag."<<endl;
          success=false;
        }
      }
      //Chaining together some files
      else{
        TChain chain("ginuke");
        TChain* dummy = &chain;
        //Need to have name separate from directory in order to properly construct this filename.
        string n = dir+"/gntp.*"+filename+"*.ginuke.root";
        cout<<"Making a chain called "<<n<<endl;
        chain.Add(n.c_str());
        cout<<"Chain created."<<endl;
        dataTree = (TTree*)dummy->Clone();
        cout<<"dummy cloned"<<endl;
        success=true;
      }
    }
    else{
      //Grabbing simple data from the text file
      dataTree = new TTree("textData",title.c_str());
      int nCol = this->analyzeTextFile();
      success = true;
      if(gType.compare("Energy")==0){
        if(nCol==3){dataTree->ReadFile(name.c_str(),"E/D:xsec:err1");}
        else if(nCol==2){dataTree->ReadFile(name.c_str(),"E/D:xsec");}
        else{cout<<"Published data file has an unrecognized format."<<endl;
             success=false;}
      }
      if(gType.compare("Momentum")==0){
        if(nCol==3){dataTree->ReadFile(name.c_str(),"ph/D:xsec:err1");}
        else if(nCol==2){dataTree->ReadFile(name.c_str(),"ph/D:xsec");}
        else{cout<<"Published data file has an unrecognized format."<<endl;
             success=false;}
      }
      if(gType.compare("Angle")==0){
        if(nCol==3){dataTree->ReadFile(name.c_str(),"cth/D:xsec:err1");}
        else if(nCol==2){dataTree->ReadFile(name.c_str(),"cth/D:xsec");}
        else{cout<<"Published data file has an unrecognized format."<<endl;
             success=false;}
      }
    }
  }

  return success;
}
开发者ID:JJones99,项目名称:GENIE,代码行数:92,代码来源:rootgINukeVal.C


注:本文中的TTree::Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。