ATLAS Offline Software
Loading...
Searching...
No Matches
CompareRootFiles.py
Go to the documentation of this file.
1# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
2
3import sys
4import re
5from math import fabs
6from ROOT import *
7
8def GetKeyNames(self,dir=""):
9 self.cd(dir)
10 return [key.GetName() for key in gDirectory.GetListOfKeys()]
11TFile.GetKeyNames = GetKeyNames
12
13
14if len(sys.argv) < 4:
15 print "Too few arguments. Expected the following:"
16 print " 1. Input root file 1"
17 print " 2. Input root file 2"
18 print " 3. Output plot file (.root)"
19 exit(1)
20
21inFile1 = TFile.Open(sys.argv[1],"READ")
22inFile2 = TFile.Open(sys.argv[2],"READ")
23outFile = TFile.Open(sys.argv[3],"RECREATE")
24
25# First check for different histograms
26for histName in inFile1.GetKeyNames():
27 if histName not in inFile2.GetKeyNames():
28 print "Histogram in file1 but not file2:",histName
29for histName in inFile2.GetKeyNames():
30 if histName not in inFile1.GetKeyNames():
31 print "Histogram in file2 but not file1:",histName
32
33# Now compare the same histograms
34for histName in inFile1.GetKeyNames():
35 if histName in inFile2.GetKeyNames():
36 hist1 = inFile1.Get(histName)
37 hist2 = inFile2.Get(histName)
38 hist1.Add(hist2,-1)
39 if fabs(hist1.GetMaximum()) > 1.e-4 or fabs(hist1.GetMinimum()) > 1.e-4:
40 print "Histogram values differ:",histName
41 outFile.cd()
42 hist1.Write(histName)
43
44outFile.Close()
45inFile1.Close()
46inFile2.Close()
47