Skip to content

Commit

Permalink
new options for friendtrees (port to 7.0.X of Cristina's PR cms-sw#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetruc committed Jul 20, 2014
1 parent 4d45770 commit 3358e5c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
19 changes: 8 additions & 11 deletions CMGTools/TTHAnalysis/macros/prepareEventVariablesFriendTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ def analyze(self,event):
parser.add_option("-N", "--events", dest="chunkSize", type="int", default=500000, help="Default chunk size when splitting trees");
parser.add_option("-j", "--jobs", dest="jobs", type="int", default=1, help="Use N threads");
parser.add_option("-p", "--pretend", dest="pretend", action="store_true", default=False, help="Don't run anything");
parser.add_option("-t", "--tree-dir", dest="treeDir", type="string", default="sf", help="Directory of the friend tree in the file (default: 'sf')");
parser.add_option("-T", "--tree-dir", dest="treeDir", type="string", default="sf", help="Directory of the friend tree in the file (default: 'sf')");
parser.add_option("-q", "--queue", dest="queue", type="string", default=None, help="Run jobs on lxbatch instead of locally");
parser.add_option("-V", "--vector", dest="vectorTree", action="store_true", default=False, help="Input tree is a vector")
parser.add_option("-t", "--tree", dest="tree", default='ttHLepTreeProducerTTH', help="Pattern for tree name");
parser.add_option("-V", "--vector", dest="vectorTree", action="store_true", default=True, help="Input tree is a vector");
parser.add_option("-F", "--add-friend", dest="friendTrees", action="append", default=[], nargs=2, help="Add a friend tree (treename, filename). Can use {name}, {cname} patterns in the treename")
parser.add_option("--FMC", "--add-friend-mc", dest="friendTreesMC", action="append", default=[], nargs=2, help="Add a friend tree (treename, filename) to MC only. Can use {name}, {cname} patterns in the treename")
parser.add_option("--FD", "--add-friend-data", dest="friendTreesData", action="append", default=[], nargs=2, help="Add a friend tree (treename, filename) to data trees only. Can use {name}, {cname} patterns in the treename")
Expand All @@ -64,17 +65,14 @@ def analyze(self,event):

jobs = []
for D in glob(args[0]+"/*"):
if options.vectorTree:
fname = D+"/ttHLepTreeProducerNew/ttHLepTreeProducerNew_tree.root"
else:
fname = D+"/ttHLepTreeProducerBase/ttHLepTreeProducerBase_tree.root"
fname = D+"/"+options.tree+"/"+options.tree+"_tree.root"
if os.path.exists(fname):
short = os.path.basename(D)
if options.datasets != []:
if short not in options.datasets: continue
data = ("DoubleMu" in short or "MuEG" in short or "DoubleElectron" in short or "SingleMu" in short)
f = ROOT.TFile.Open(fname);
t = f.Get("ttHLepTreeProducerNew" if options.vectorTree else "ttHLepTreeProducerBase")
t = f.Get(options.tree)
entries = t.GetEntries()
f.Close()
chunk = options.chunkSize
Expand All @@ -94,9 +92,9 @@ def analyze(self,event):

if options.queue:
import os, sys
basecmd = "bsub -q {queue} {dir}/lxbatch_runner.sh {dir} {cmssw} python {self} -N {chunkSize} -t '{tdir}' {data} {output}".format(
basecmd = "bsub -q {queue} {dir}/lxbatch_runner.sh {dir} {cmssw} python {self} -N {chunkSize} -T '{tdir}' -t {tree} {data} {output}".format(
queue = options.queue, dir = os.getcwd(), cmssw = os.environ['CMSSW_BASE'],
self=sys.argv[0], chunkSize=options.chunkSize, tdir=options.treeDir, data=args[0], output=args[1]
self=sys.argv[0], chunkSize=options.chunkSize, tdir=options.treeDir, tree=options.tree, data=args[0], output=args[1]
)
if options.vectorTree: basecmd += " --vector "
friendPost = "".join([" -F %s %s " % (fn,ft) for fn,ft in options.friendTrees])
Expand All @@ -115,11 +113,10 @@ def _runIt(myargs):
(name,fin,fout,data,range,chunk) = myargs
timer = ROOT.TStopwatch()
fb = ROOT.TFile(fin)
tb = fb.Get(options.tree)
if options.vectorTree:
tb = fb.Get("ttHLepTreeProducerNew")
tb.vectorTree = True
else:
tb = fb.Get("ttHLepTreeProducerBase")
tb.vectorTree = False
friends = options.friendTrees[:]
friends += (options.friendTreesData if data else options.friendTreesMC)
Expand Down
22 changes: 10 additions & 12 deletions CMGTools/TTHAnalysis/macros/prepareScaleFactorsFriendTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
MODULES = []

from CMGTools.TTHAnalysis.tools.btagSFs_POG import bTagSFEvent3WPErrs as btagSFEvent
MODULES += [ ('btag', btagSFEvent) ]
#MODULES += [ ('btag', btagSFEvent) ]

from CMGTools.TTHAnalysis.tools.lepMVA_SF import AllLepSFs
MODULES += [ ('lep',AllLepSFs()) ]

from CMGTools.TTHAnalysis.tools.lepTrigger_SF import LepTriggerSF_Event
MODULES += [ ('trig2l', LepTriggerSF_Event()) ]
#MODULES += [ ('trig2l', LepTriggerSF_Event()) ]

from CMGTools.TTHAnalysis.tools.metLD_reshape import MetLDReshaper
#MODULES += [ ('metLD', MetLDReshaper()) ]
Expand Down Expand Up @@ -60,7 +60,8 @@ def analyze(self,event):
parser.add_option("-j", "--jobs", dest="jobs", type="int", default=1, help="Use N threads");
parser.add_option("-p", "--pretend", dest="pretend", action="store_true", default=False, help="Don't run anything");
parser.add_option("-q", "--queue", dest="queue", type="string", default=None, help="Run jobs on lxbatch instead of locally");
parser.add_option("-V", "--vector", dest="vectorTree", action="store_true", default=False, help="Input tree is a vector")
parser.add_option("-t", "--tree", dest="tree", default='ttHLepTreeProducerTTH', help="Pattern for tree name");
parser.add_option("-V", "--vector", dest="vectorTree",action="store_true", default=True, help="Input tree is a vector")
(options, args) = parser.parse_args()

if len(args) != 2 or not os.path.isdir(args[0]) or not os.path.isdir(args[1]):
Expand All @@ -72,18 +73,16 @@ def analyze(self,event):

jobs = []
for D in glob(args[0]+"/*"):
if options.vectorTree:
fname = D+"/ttHLepTreeProducerNew/ttHLepTreeProducerNew_tree.root"
else:
fname = D+"/ttHLepTreeProducerBase/ttHLepTreeProducerBase_tree.root"
fname = D+"/"+options.tree+"/"+options.tree+"_tree.root"
if os.path.exists(fname):
short = os.path.basename(D)
if options.datasets != []:
if short not in options.datasets: continue
data = ("DoubleMu" in short or "MuEG" in short or "DoubleElectron" in short or "SingleMu" in short)
if data: continue
f = ROOT.TFile.Open(fname);
t = f.Get("ttHLepTreeProducerNew" if options.vectorTree else "ttHLepTreeProducerBase")
#t = f.Get("ttHLepTreeProducerTTH" if options.vectorTree else "ttHLepTreeProducerBase")
t = f.Get(options.tree)
entries = t.GetEntries()
f.Close()
chunk = options.chunkSize
Expand All @@ -103,9 +102,9 @@ def analyze(self,event):

if options.queue:
import os, sys
basecmd = "bsub -q {queue} {dir}/lxbatch_runner.sh {dir} {cmssw} python {self} -N {chunkSize} {data} {output}".format(
basecmd = "bsub -q {queue} {dir}/lxbatch_runner.sh {dir} {cmssw} python {self} -N {chunkSize} -t {tree} {data} {output}".format(
queue = options.queue, dir = os.getcwd(), cmssw = os.environ['CMSSW_BASE'],
self=sys.argv[0], chunkSize=options.chunkSize, data=args[0], output=args[1]
self=sys.argv[0], chunkSize=options.chunkSize, tree=options.tree, data=args[0], output=args[1]
)
if options.vectorTree: basecmd += " --vector "
# specify what to do
Expand All @@ -121,11 +120,10 @@ def _runIt(myargs):
(name,fin,fout,data,range,chunk) = myargs
timer = ROOT.TStopwatch()
fb = ROOT.TFile(fin)
tb = fb.Get(options.tree)
if options.vectorTree:
tb = fb.Get("ttHLepTreeProducerNew")
tb.vectorTree = True
else:
tb = fb.Get("ttHLepTreeProducerBase")
tb.vectorTree = False
nev = tb.GetEntries()
if options.pretend:
Expand Down

0 comments on commit 3358e5c

Please sign in to comment.