ATLAS Offline Software
Loading...
Searching...
No Matches
compareNtuple.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4
5import os,sys
6sys.argv += [ '-b' ] # tell ROOT to not use graphics
7from ROOT import TFile,TTree
8from PROCTools.diffTAGTree import diffTTree
9#import re
10
11os.environ['STAGE_SVCCLASS']="atlascerngroupdisk"
12os.environ['STAGE_HOST']="castoratlast3"
13
14ignoreTrees=set(("CollectionMetadata",))
15
16if __name__ == "__main__":
17 if len(sys.argv)<4 or sys.argv[1]=="-h" or sys.argv[1]=="--help":
18 print ("Usage: compareNtuple.py ntuple1 ntuple2")
19 print (" Example: compareTCTs.py /castor/cern.ch/user/m/mlimper/ntuple1.root /castor/cern.ch/user/m/mlimper/ntuple2.root")
20 sys.exit(-1)
21
22 rName = sys.argv[1]
23 vName = sys.argv[2]
24
25 if rName.startswith("/castor"):
26 rFile=TFile.Open("root://castoratlas/"+rName)
27 else:
28 rFile=TFile.Open(rName)
29
30 if vName.startswith("/castor"):
31 vFile=TFile.Open("root://castoratlas/"+vName)
32 else:
33 vFile=TFile.Open(vName)
34
35 if rFile is None:
36 print ("Failed to open reference file",rName)
37
38 if vFile is None:
39 print ("Failed to open validation file",vName)
40
41 rKeys=set()
42 for k in rFile.GetListOfKeys():
43 rKeys.add(k.GetName())
44 vKeys=set()
45 for k in vFile.GetListOfKeys():
46 vKeys.add(k.GetName())
47 #print (rKeys)
48 #print (vKeys)
49 keys=rKeys & vKeys
50 keys -= ignoreTrees
51
52 if len(keys)==0:
53 print ("ERROR no common trees names found in files",rName,vName)
54
55 nGood=0
56 nBad=0
57 for k in keys:
58 rTree=rFile.Get(k)
59 vTree=vFile.Get(k)
60 if not isinstance(rTree,TTree):
61 continue
62 if not isinstance(vTree,TTree):
63 continue
64 print ("Comparing TTree",k)
65 (good,bad)=diffTTree(rTree,vTree)
66 nGood+=good
67 nBad+=bad
68
STL class.