9 ROOT.gSystem.Load(
"libGenVector.so")
21 treeNameJETMET =
"qcd"
22 treeNameCOMMON =
"physics"
23 writeBranchInformation =
False
26 fileNameJETMET=
"/afs/cern.ch/user/d/delsart/public/COMMON/NTUP_COMMON_ref.root"
27 treeNameJETMET=
"physics"
28 fileNameCOMMON=
"/afs/cern.ch/user/d/delsart/public/COMMON/NTUP_COMMON_new.root"
31 print (
"Too few arguments. Expected the following:")
32 print (
"1. JETMET file (required)")
33 print (
"2. COMMON file (required)")
34 print (
"3. JETMET tree name (optional, default=\"qcd\")")
35 print (
"4. COMMON tree name (optional, default=\"physics\")")
36 print (
"5. Whether or not to write branch information to files (optional, default=False)")
39 fileNameJETMET=sys.argv[1]
40 fileNameCOMMON=sys.argv[2]
42 treeNameJETMET = sys.argv[3]
44 treeNameCOMMON = sys.argv[4]
46 if "True" in sys.argv[5]
or "true" in sys.argv[5]:
47 writeBranchInformation =
True
48 elif "False" in sys.argv[5]
or "false" in sys.argv[5]:
49 writeBranchInformation =
False
51 print (
"Could not interpret the branch information control argument: ",sys.argv[5])
70 fileJETMET = ROOT.TFile(fileNameJETMET,
"READ")
71 fileCOMMON = ROOT.TFile(fileNameCOMMON,
"READ")
73 treeJETMET = fileJETMET.Get(treeNameJETMET)
74 if not isinstance(treeJETMET,ROOT.TTree) :
75 print (
"JETMET file does not contain the specified tree. Is the tree name correct?")
76 print (
"File: ",fileNameJETMET)
77 print (
"Tree: ",treeNameJETMET)
80 treeCOMMON = fileCOMMON.Get(treeNameCOMMON)
81 if not isinstance(treeJETMET,ROOT.TTree):
82 print (
"COMMON file does not contain the specified tree. Is the tree name correct?")
83 print (
"File: ",fileNameCOMMON)
84 print (
"Tree: ",treeNameCOMMON)
93 from JetValidation.D3PDHistoBuildLib
import MultipleHistoBuilderFromD3PD,JetType,JetVar
100 branchesJETMET = treeJETMET.GetSetOfTreeBranchNames()
101 branchesCOMMON = treeCOMMON.GetSetOfTreeBranchNames()
102 branchesBOTH = frozenset.intersection(branchesJETMET,branchesCOMMON)
103 brNotInCOMMON = branchesJETMET-branchesCOMMON
104 brNotInJETMET = branchesCOMMON-branchesJETMET
106 if writeBranchInformation:
107 outFile =
open(
'Branches_JETMET.txt',
'w')
108 outFile.write(
str(
sorted(branchesJETMET)))
111 outFile =
open(
'Branches_COMMON.txt',
'w')
112 outFile.write(
str(
sorted(branchesCOMMON)))
115 outFile =
open(
'Branches_BOTH.txt',
'w')
119 outFile =
open(
'Branches_NotIn_COMMON.txt',
'w')
120 outFile.write(
str(
sorted(brNotInCOMMON)))
123 outFile =
open(
'Branches_NotIn_JETMET.txt',
'w')
124 outFile.write(
str(
sorted(brNotInJETMET)))
128 outFile =
open(
'Twiki_Branches_NotIn_COMMON.txt',
'w')
129 outFile.write(
'| *Branch name* | *Expected* | *Confirmed by* ||\n')
130 for aBranch
in sorted(brNotInCOMMON):
131 outFile.write(
'| !%s | ? | ? ||\n'%(aBranch))
139 if writeBranchInformation:
142 for name
in branchesJETMET:
146 jetTypesJETMET.add(type)
147 jetVarsJETMET.add(
JetVar(name))
151 for name
in branchesCOMMON:
155 jetTypesCOMMON.add(type)
156 jetVarsCOMMON.add(
JetVar(name))
158 jetTypesBoth = set.intersection(jetTypesJETMET,jetTypesCOMMON)
159 jetVarsBoth = set.intersection(jetVarsJETMET,jetVarsCOMMON)
162 branchesNotExisting = []
163 for aType
in jetTypesBoth:
164 for aVar
in jetVarsBoth:
165 toCheck = aType +
"_" + aVar
166 if toCheck
not in branchesBOTH:
167 branchesNotExisting.append(toCheck)
169 outFile =
open(
'Branches_JetTypes_NotExisting.txt',
'w')
170 outFile.write(
str(
sorted(branchesNotExisting)))
178 multiBuilder = MultipleHistoBuilderFromD3PD()
179 multiBuilder.addTrees(treeJETMET,treeCOMMON)
180 multiBuilder.createBuildersFromTrees()
195 for aBranch
in multiBuilder.getBranchIntersection() :
197 if "EventNumber" in aBranch:
198 multiBuilder.addHistos(aBranch)
199 if "jet_AntiKt4" in aBranch
and (
"LC" in aBranch
or "EM" in aBranch) :
200 multiBuilder.addHistosWithLeadingJetSelectors(JetType(aBranch), aBranch)
202 print (
"\nRunning event loop...")
203 multiBuilder.eventLoop()
204 print (
"Done event loop!")
208 twikiLog =
open(
'Twiki_ToleranceResults.log',
'w')
209 twikiLog.write(
'| *Variable* | *Passes tolerance* | *Num failed/total bins* | *Largest difference (%)* ||\n')
210 multiBuilder.writeAllHistoToFile(
"test.pdf",logFile=
"failsTolerance.log",twikiLogFile=twikiLog)