|
| 1 | +#Loop over all branches in the two output trees and get Mean and RMS. Can be used to compare it to another (previous) output file to see impact of changes |
| 2 | +# Use it like: python compare_output.py <file1.root> -b |
| 3 | +# Use it like: python compare_output.py <file2.root> -b |
| 4 | +# Check diff with: diff <file1.log> <file2.log> |
| 5 | + |
| 6 | +from ROOT import TFile, TTree, TH1 |
| 7 | + |
| 8 | +import sys |
| 9 | + |
| 10 | +def compare_output(): |
| 11 | + fileName = sys.argv[1] |
| 12 | + outfileName = fileName[:-4] + "log" |
| 13 | + output = open(outfileName, "w") |
| 14 | + file = TFile(fileName, 'READ') |
| 15 | + tree = file.Get('btagana/ttree') |
| 16 | + if(tree): |
| 17 | + for branch in tree.GetListOfBranches(): |
| 18 | + branchname = branch.GetName() |
| 19 | + tree.Draw(branchname + '>>hist') |
| 20 | + mean = file.Get('hist').GetMean() |
| 21 | + rms = file.Get('hist').GetRMS() |
| 22 | + output.write('{}: {} {}\n'.format(branchname, mean, rms)) |
| 23 | + |
| 24 | + tree = file.Get('btaganaFatJets/ttree') |
| 25 | + if(tree): |
| 26 | + for branch in tree.GetListOfBranches(): |
| 27 | + branchname = branch.GetName() |
| 28 | + tree.Draw(branchname + '>>hist') |
| 29 | + mean = file.Get('hist').GetMean() |
| 30 | + rms = file.Get('hist').GetRMS() |
| 31 | + output.write('{}: {} {}\n'.format(branchname, mean, rms)) |
| 32 | + |
| 33 | + output.close() |
| 34 | + print('Output written to {}'.format(outfileName)) |
| 35 | + |
| 36 | + |
| 37 | +if __name__ == '__main__': |
| 38 | + compare_output() |
| 39 | + |
0 commit comments