3 from __future__
import print_function
10 ROOT.gSystem.Load(
"libGenVector.so")
22 treeNameJETMET =
"qcd"
23 treeNameCOMMON =
"physics"
24 writeBranchInformation =
False
27 fileNameJETMET=
"/afs/cern.ch/user/d/delsart/public/COMMON/NTUP_COMMON_ref.root"
28 treeNameJETMET=
"physics"
29 fileNameCOMMON=
"/afs/cern.ch/user/d/delsart/public/COMMON/NTUP_COMMON_new.root"
32 print (
"Too few arguments. Expected the following:")
33 print (
"1. JETMET file (required)")
34 print (
"2. COMMON file (required)")
35 print (
"3. JETMET tree name (optional, default=\"qcd\")")
36 print (
"4. COMMON tree name (optional, default=\"physics\")")
37 print (
"5. Whether or not to write branch information to files (optional, default=False)")
40 fileNameJETMET=sys.argv[1]
41 fileNameCOMMON=sys.argv[2]
43 treeNameJETMET = sys.argv[3]
45 treeNameCOMMON = sys.argv[4]
47 if "True" in sys.argv[5]
or "true" in sys.argv[5]:
48 writeBranchInformation =
True
49 elif "False" in sys.argv[5]
or "false" in sys.argv[5]:
50 writeBranchInformation =
False
52 print (
"Could not interpret the branch information control argument: ",sys.argv[5])
71 fileJETMET = ROOT.TFile(fileNameJETMET,
"READ")
72 fileCOMMON = ROOT.TFile(fileNameCOMMON,
"READ")
74 treeJETMET = fileJETMET.Get(treeNameJETMET)
75 if not isinstance(treeJETMET,ROOT.TTree) :
76 print (
"JETMET file does not contain the specified tree. Is the tree name correct?")
77 print (
"File: ",fileNameJETMET)
78 print (
"Tree: ",treeNameJETMET)
81 treeCOMMON = fileCOMMON.Get(treeNameCOMMON)
82 if not isinstance(treeJETMET,ROOT.TTree):
83 print (
"COMMON file does not contain the specified tree. Is the tree name correct?")
84 print (
"File: ",fileNameCOMMON)
85 print (
"Tree: ",treeNameCOMMON)
94 from JetValidation.D3PDHistoBuildLib
import MultipleHistoBuilderFromD3PD,JetType,JetVar
101 branchesJETMET = treeJETMET.GetSetOfTreeBranchNames()
102 branchesCOMMON = treeCOMMON.GetSetOfTreeBranchNames()
103 branchesBOTH = frozenset.intersection(branchesJETMET,branchesCOMMON)
104 brNotInCOMMON = branchesJETMET-branchesCOMMON
105 brNotInJETMET = branchesCOMMON-branchesJETMET
107 if writeBranchInformation:
108 outFile =
open(
'Branches_JETMET.txt',
'w')
109 outFile.write(
str(
sorted(branchesJETMET)))
112 outFile =
open(
'Branches_COMMON.txt',
'w')
113 outFile.write(
str(
sorted(branchesCOMMON)))
116 outFile =
open(
'Branches_BOTH.txt',
'w')
120 outFile =
open(
'Branches_NotIn_COMMON.txt',
'w')
121 outFile.write(
str(
sorted(brNotInCOMMON)))
124 outFile =
open(
'Branches_NotIn_JETMET.txt',
'w')
125 outFile.write(
str(
sorted(brNotInJETMET)))
129 outFile =
open(
'Twiki_Branches_NotIn_COMMON.txt',
'w')
130 outFile.write(
'| *Branch name* | *Expected* | *Confirmed by* ||\n')
131 for aBranch
in sorted(brNotInCOMMON):
132 outFile.write(
'| !%s | ? | ? ||\n'%(aBranch))
140 if writeBranchInformation:
143 for name
in branchesJETMET:
147 jetTypesJETMET.add(type)
148 jetVarsJETMET.add(
JetVar(name))
152 for name
in branchesCOMMON:
156 jetTypesCOMMON.add(type)
157 jetVarsCOMMON.add(
JetVar(name))
159 jetTypesBoth = set.intersection(jetTypesJETMET,jetTypesCOMMON)
160 jetVarsBoth = set.intersection(jetVarsJETMET,jetVarsCOMMON)
163 branchesNotExisting = []
164 for aType
in jetTypesBoth:
165 for aVar
in jetVarsBoth:
166 toCheck = aType +
"_" + aVar
167 if toCheck
not in branchesBOTH:
168 branchesNotExisting.append(toCheck)
170 outFile =
open(
'Branches_JetTypes_NotExisting.txt',
'w')
171 outFile.write(
str(
sorted(branchesNotExisting)))
179 multiBuilder = MultipleHistoBuilderFromD3PD()
180 multiBuilder.addTrees(treeJETMET,treeCOMMON)
181 multiBuilder.createBuildersFromTrees()
196 for aBranch
in multiBuilder.getBranchIntersection() :
198 if "EventNumber" in aBranch:
199 multiBuilder.addHistos(aBranch)
200 if "jet_AntiKt4" in aBranch
and (
"LC" in aBranch
or "EM" in aBranch) :
201 multiBuilder.addHistosWithLeadingJetSelectors(JetType(aBranch), aBranch)
203 print (
"\nRunning event loop...")
204 multiBuilder.eventLoop()
205 print (
"Done event loop!")
209 twikiLog =
open(
'Twiki_ToleranceResults.log',
'w')
210 twikiLog.write(
'| *Variable* | *Passes tolerance* | *Num failed/total bins* | *Largest difference (%)* ||\n')
211 multiBuilder.writeAllHistoToFile(
"test.pdf",logFile=
"failsTolerance.log",twikiLogFile=twikiLog)