Logo coherent WaveBurst  
Library Reference Guide
Logo
TreeCompare.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Francesco Salemi
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 /*#include "ObjComparer.h"
20 #include "TFile.h"
21 #include "TTree.h"
22 #include "TSystem.h"
23 #include <iostream>
24 #include "/work/salemi/git/cWB/library/wat/netevent.hh"
25 */
26 /*void printCDBEntry(const char * fileName) {
27  std::cout << "printing CDB file " << fileName << "\n";
28  TFile *file = TFile::Open(fileName);
29  if (!file) return;
30  TObject *obj = (TObject*)file->Get("AliCDBEntry");
31 
32  ROOTObjComparer cmp;
33  cmp.Print(obj);
34 
35  // for debugging purposes, can dump XML here via ROOT serialization
36  // dump them to XML just to have a text comparison also
37  TString outxml(fileName); outxml+=".xml";
38  TFile *file1xml = TFile::Open(outxml.Data(), "RECREATE");
39  if (file1xml){
40  std::cout << "Writing XML for comparision\n";
41  file1xml->WriteTObject(obj);
42  file1xml->Close();
43  }
44 
45  file->Close();
46 }
47 */
48 
49 void TreeCompare(const char * filename, const char *postfix1, const char *postfix2, TString treename="waveburst", float tollerance = 1e-4) {
50  TString fileName1 = filename;
51  TString fileName2 = fileName1;
52  fileName2.ReplaceAll(postfix1,postfix2);
53  std::cout << "processing cWB file1 " << fileName1.Data() << "\n";
54  std::cout << "processing cWB file2 " << fileName2.Data() << "\n";
55  cout.precision(17);
56  TFile *file1 = TFile::Open(fileName1);
57  if (!file1) return;
58  TTree *obj1 = (TTree*)file1->Get(treename);
59  // netevent EVT1(obj1,2);
60 
61  TFile *file2 = TFile::Open(fileName2);
62  if (!file2) return;
63  TTree *obj2 = (TTree*)file2->Get(treename);
64  // netevent EVT2(obj2,2);
65 /*
66  ROOTObjComparer cmp;
67  cmp.SetVerbose(false);
68  cmp.SetDebug(false);
69  cmp.Diff(obj1, obj2);
70 */
71  // dump events
72  int nEVT1 = obj1->GetEntries();
73  int nEVT2 = obj2->GetEntries();
74 
75  //check if the number of events is matching between the 2 TTrees
76  if(nEVT1 != nEVT2){
77  std::cout << "Unequal number of events in the 2 TTrees!!! nEVT1=" << nEVT1 <<" nEVT2=" << nEVT2 << " Exiting now..." << "\n";
78  exit(1);
79  }
80  //check if the TTrees are empty
81  if(nEVT1 == 0) {std::cout << "Empty ntuple!!!" << endl; exit(0);}
82  int index;
83  //sort the TTrees
84 // if(treename!=liveTime) {obj1->BuildIndex("time[0]","time[1]");}
85  // else {
86  obj1->BuildIndex("start[0]","start[1]"); //}
87 
88  TTreeIndex *I1=(TTreeIndex*)obj1->GetTreeIndex(); // get the tree index
89  Long64_t* index1=I1->GetIndex(); //create an array of entries in sorted order
90  //obj2->BuildIndex("time[0]","time[1]");
91  obj2->BuildIndex("start[0]","start[1]");
92  TTreeIndex *I2=(TTreeIndex*)obj2->GetTreeIndex(); // get the tree index
93  Long64_t* index2=I2->GetIndex(); //create an array of entries in sorted order
94 
95  TObjArray *branchList;
96  branchList = obj1->GetListOfBranches();
97  int nBranch = obj1->GetNbranches();
98  TString varnames[63];
99  TLeaf *var1[63];
100  TLeaf *var2[63];
101  double value_1;
102  double value_2;
103  for (Long64_t jentry=0; jentry<nEVT1;jentry++) {
104  obj1->GetEntry(jentry);
105  obj2->GetEntry(jentry);
106  //obj1->Show(jentry);
107  for(int i=0;i<nBranch;i++){
108  varnames[i] = branchList->At(i)->GetName();
109  var1[i] = obj1->GetBranch(varnames[i])->GetLeaf(varnames[i]);
110  var2[i] = obj2->GetBranch(varnames[i])->GetLeaf(varnames[i]);
111  for(int k=0;k<obj1->GetBranch(varnames[i])->GetLeaf(varnames[i])->GetLen();k++){
112  value_1 = var1[i]->GetValue(k);
113  value_2 = var2[i]->GetValue(k);
114  if (TMath::Abs(value_1-value_2) > tollerance){
115  cout <<jentry <<" " << varnames[i].Data() << "["<<k <<"] " << value_1 << " " << value_2 << " " << TMath::Abs(value_1-value_2) <<endl;
116  }
117  }
118  }
119  }
120  file1->Close();
121  file2->Close();
122 }
123 
TString("c")
void TreeCompare(const char *filename, const char *postfix1, const char *postfix2, TString treename="waveburst", float tollerance=1e-4)
Definition: TreeCompare.C:49
i drho i
int k
double e
wavearray< int > index
exit(0)