forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testNanoWeights.py
34 lines (30 loc) · 1.08 KB
/
testNanoWeights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import ROOT
import argparse
def variableAndNumber(varName, tree):
countVar = "n"+varName
if not hasattr(tree, varName):
print("No variable %s found in file" % varName)
else:
count = getattr(tree, countVar)
var = getattr(tree, varName)
print("Found %i entries of %s in file" % (count, varName))
branch = tree.GetBranch(varName)
print(" --> Desciption:%s" % branch.GetTitle())
parser = argparse.ArgumentParser()
parser.add_argument('inputFile', type=str, help='NanoAOD file to process')
args = parser.parse_args()
rtfile = ROOT.TFile(args.inputFile)
tree = rtfile.Get("Events")
tree.GetEntry(0)
types = ["ScaleWeight", "PdfWeight", "MEParamWeight", "UnknownWeight", ]
variables = ["LHE"+t for t in types]
variables.append("GenPartonShowerWeight")
variables.extend(["Gen"+t for t in types])
for varName in variables:
variableAndNumber(varName, tree)
i = 1
altName = varName + "AltSet%i" % i
while hasattr(tree, altName):
variableAndNumber(altName, tree)
i = i+1
altName = varName + "AltSet%i" % i