ATLAS Offline Software
CompareRootFiles.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
2 
3 import sys
4 import re
5 from math import fabs
6 from ROOT import *
7 
8 def GetKeyNames(self,dir=""):
9  self.cd(dir)
10  return [key.GetName() for key in gDirectory.GetListOfKeys()]
11 TFile.GetKeyNames = GetKeyNames
12 
13 
14 if 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 
21 inFile1 = TFile.Open(sys.argv[1],"READ")
22 inFile2 = TFile.Open(sys.argv[2],"READ")
23 outFile = TFile.Open(sys.argv[3],"RECREATE")
24 
25 # First check for different histograms
26 for histName in inFile1.GetKeyNames():
27  if histName not in inFile2.GetKeyNames():
28  print "Histogram in file1 but not file2:",histName
29 for 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
34 for 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 
44 outFile.Close()
45 inFile1.Close()
46 inFile2.Close()
47 
CompareRootFiles.GetKeyNames
def GetKeyNames(self, dir="")
Definition: CompareRootFiles.py:8
calibdata.exit
exit
Definition: calibdata.py:236