BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
compare_trees.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <iomanip>
4#include <cstring>
5#include <string>
6#include <vector>
7#include <TFile.h>
8#include <TTree.h>
9#include <TString.h>
10#include <TBranch.h>
11#include <TLeaf.h>
12#include <TH1F.h>
13
14using namespace std;
15int const num_item = 9;
16TString str_name_list[num_item]={"runcalib",
17 "gaincalib",
18 "resolcalib",
19 "wiregcalib",
20 "ggscalib",
21 "ddgcalib",
22 "entracalib",
23 "zdepcalib",
24 "layergcalib"};
25
26int main(int argc, char *argv[]){
27 if(argc<3){
28 cout << "please append two root files' names you want to compare " << endl;
29 return 1;
30 }
31
32
33 TFile f1(argv[1]);
34 TTree *t1(0);
35 TFile f2(argv[2]);
36 TTree *t2(0);
37
38 int m_flag(0);
39 TH1F *h1 = new TH1F("h1","h1",100000,-100000,100000);
40 TH1F *h2 = new TH1F("h2","h2",100000,-100000,100000);
41
42 for(int i=0; i<num_item; i++){
43 m_flag = 0;
44 t1 = (TTree*)f1.Get(str_name_list[i]);
45 t2 = (TTree*)f2.Get(str_name_list[i]);
46 TObjArray *l_b1 = t1->GetListOfBranches();
47 TObjArray *l_b2 = t1->GetListOfBranches();
48 if(l_b1->GetSize() != l_b2->GetSize()){
49 cout << "tree " << str_name_list[i] << " is different" << endl;
50 break;
51 }
52 // cout << "size " << l_b1->GetEntries() << endl;
53 for(int j=0; j<l_b1->GetEntries(); j++){
54 // cout << "j= " << j << " branch name " << l_b1->At(j)->GetName() << endl;
55 t1->Project("h1", l_b1->At(j)->GetName());
56 t2->Project("h2", l_b2->At(j)->GetName());
57 if(h1->GetMean() - h2->GetMean()){
58 cout << "tree " << str_name_list[i] << " is different" << endl;
59 m_flag = 1;
60 break;
61 }
62 }// end of loop branches in trees
63 if(m_flag) continue;
64 else cout << "tree " << str_name_list[i] << " is same" << endl;
65 }// end of loop tree
66
67 return 0;
68}
TFile * f1
TString str_name_list[num_item]
int const num_item
int main()
Definition: test_IFile.cxx:11