两个root文件中的直方图合在一起

void all2daq(const char *rootfilename1,const char *rootfilename2)
{
  TFile *file1 = new TFile(rootfilename1,"READ");//"RECREATE" "READ"
  if(!file1->IsOpen())
    {
      std::cout<<"Can't open root file"<Get("matrix");
  
  TFile *file2 = new TFile(rootfilename2,"READ");//"RECREATE" "READ"
  if(!file2->IsOpen())
    {
      std::cout<<"Can't open root file"<Get("matrix");
  TFile *file3 = new TFile("all2daq.root","RECREATE");
  TH2I *matrix3= new TH2I("matrix3","",4096,0,4096,4096,0,4096);
  matrix3->Add(matrix1,matrix2,1,1);
  
  file3->cd();
  
  matrix3->Write();
  
  file3->Close();

   file1->Close();
   file2->Close();
}

编译方式:

root
.L all2daq.C
all2daq("rootname1","rootname2")

 

你可能感兴趣的:(两个root文件中的直方图合在一起)