/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Mdc/DedxCalibAlg/DedxCalibAlg-00-01-15/share/shell/genRawScript/compare_trees.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <iomanip>
00004 #include <cstring>
00005 #include <string>
00006 #include <vector>
00007 #include <TFile.h>
00008 #include <TTree.h>
00009 #include <TString.h>
00010 #include <TBranch.h>
00011 #include <TLeaf.h>
00012 #include <TH1F.h>
00013 
00014 using namespace std;
00015 int const num_item = 9;
00016 TString str_name_list[num_item]={"runcalib",
00017                                  "gaincalib",
00018                                  "resolcalib",
00019                                  "wiregcalib",
00020                                  "ggscalib",
00021                                  "ddgcalib",
00022                                  "entracalib",
00023                                  "zdepcalib",
00024                                  "layergcalib"};
00025 
00026 int main(int argc, char *argv[]){
00027   if(argc<3){
00028     cout << "please append two root files' names you want to compare " << endl;
00029     return 1;
00030   }
00031 
00032 
00033   TFile f1(argv[1]);
00034   TTree *t1(0);
00035   TFile f2(argv[2]);
00036   TTree *t2(0);
00037 
00038   int m_flag(0);
00039   TH1F *h1 = new TH1F("h1","h1",100000,-100000,100000);
00040   TH1F *h2 = new TH1F("h2","h2",100000,-100000,100000);
00041 
00042   for(int i=0; i<num_item; i++){
00043     m_flag = 0;
00044     t1 = (TTree*)f1.Get(str_name_list[i]);
00045     t2 = (TTree*)f2.Get(str_name_list[i]);
00046     TObjArray *l_b1 = t1->GetListOfBranches();
00047     TObjArray *l_b2 = t1->GetListOfBranches();
00048     if(l_b1->GetSize() != l_b2->GetSize()){
00049       cout << "tree " << str_name_list[i] << " is different" << endl;
00050       break;
00051     }
00052     //    cout << "size " << l_b1->GetEntries() << endl;
00053     for(int j=0; j<l_b1->GetEntries(); j++){
00054       // cout << "j= " << j << "  branch name " << l_b1->At(j)->GetName() << endl;
00055       t1->Project("h1", l_b1->At(j)->GetName());
00056       t2->Project("h2", l_b2->At(j)->GetName());
00057       if(h1->GetMean() - h2->GetMean()){
00058         cout << "tree " << str_name_list[i] << " is different" << endl;
00059         m_flag = 1;
00060         break;
00061       } 
00062     }// end of loop branches in trees
00063     if(m_flag) continue;
00064     else cout << "tree " << str_name_list[i] << " is same" << endl;
00065   }// end of loop tree
00066 
00067   return 0;
00068 }

Generated on Tue Nov 29 23:12:45 2016 for BOSS_7.0.2 by  doxygen 1.4.7