Skip to content
2 changes: 1 addition & 1 deletion __analysis__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def sampleSpecs(self, tag = "") :
def sampleSpecDict(looper) :
looper.setupSteps(minimal = True)
sampleSpec = next( s for s in confSamples if s.weightedName == looper.name )
return {"name":looper.name, "outputFileName":looper.steps[0].outputFileName,
return {"name":looper.name, "outputFileName":looper.steps[0].outputFileName, "nInDivide": sampleSpec.nInDivide,
"color":sampleSpec.color, "markerStyle":sampleSpec.markerStyle, "nCheck":self.sampleDict[sampleSpec.name].nCheck }
return [ sampleSpecDict(looper) for looper in self.listsOfLoopers[tag] ]
############
Expand Down
8 changes: 6 additions & 2 deletions __organizer__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ def __init__(self,samples,dirs = None,keys = [], prefixesNoScale=[]) :
[ hist.Scale( 1.0 / sample['nJobs'] ) for hist,sample in zip(self[key],samples) if hist ]
elif any([key.startswith(prefix) for prefix in prefixesNoScale]):
continue
else: [ hist.Scale(sample["xs"]/sample['nEventsIn']) for hist,sample in zip(self[key],samples)
if hist and sample['nEventsIn'] and "xs" in sample ]
else:
for hist, sample in zip(self[key], samples):
if hist and "xs" in sample:
hist.Scale(sample["xs"])
if sample['nEventsIn'] and sample["nInDivide"]:
hist.Scale(1.0 / sample['nEventsIn'])

def __str__(self) : return "%s: %s"%self.nameTitle

Expand Down
29 changes: 14 additions & 15 deletions __plotter__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ def combineBinContentAndError(histo, binToContainCombo, binToBeKilled) :
histo.SetBinError(binToContainCombo, math.sqrt(xflowError**2+currentError**2))


def mcLumi(nEvents=None, w=None, xs=None):
"""see docs/mcLumi.txt"""
if not w*xs:
return 0.0
return nEvents**2/(w*xs)


def sampleName(sample):
if len(sample.get("sources", [])) == 1:
return sample["sources"][0]["name"]
Expand All @@ -38,24 +31,30 @@ def sampleInfo(samples, trim=""):
out = []
for sample in samples:
if "xs" in sample:
xs = sample["xs"]
lumi = mcLumi(nEvents=sample["nEventsIn"],
w=sample["weightIn"],
xs=sample["xs"])
xsIn = sample["xs"]
xsEff = sample["xs"] * sample["weightIn"]
if sample["nInDivide"] and sample["nEventsIn"]:
xsEff /= sample["nEventsIn"]

# see docs/mcLumi.txt
lumi = sample["nEventsIn"] / xsEff if xsEff else 0.0
elif "lumi" in sample:
xs = None
xsIn = None
xsEff = None
lumi = sample["lumi"]
else:
assert False, sample

name = sampleName(sample)
if trim:
name = name.replace(trim, "")

out.append((name,
"%d" % sample['nEventsIn'],
"%g" % sample['nEventsIn'], # %g handles 'float epsilon less than nearest int' better than %d
"%3.2e" % sample['weightIn'],
"%3.2e" % (lumi/1.0e3),
"%3.2e" % (xs*1.0e3) if xs is not None else "",
"%3.2e" % (xsIn*1.0e3) if xsIn is not None else "",
"%3.2e" % (xsEff*1.0e3) if xsEff is not None else "",
))
return out

Expand Down Expand Up @@ -508,7 +507,7 @@ def printSampleList(self, x, rows=[], header="", sigma=None):
text.SetTextSize(0.38*text.GetTextSize())
defSize = text.GetTextSize()

rows = [("name", "nEventsIn", "weightIn", "lumi(/fb)", "xs(fb)")] + rows
rows = [("name", "nEventsIn", "weightIn", "lumi(/fb)", "xsIn(fb)", "xsEff(fb)")] + rows
realRows = filter(lambda x: len(x[1]), rows)
if len(realRows) == 1:
return
Expand Down
16 changes: 12 additions & 4 deletions samples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ def printNumberEvents(sampleHolder, treeName='tree'):
def test(sampleHolder) :
return [(name,len(eval(ss.filesCommand))) for name,ss in sorted(sampleHolder.items())]

def specify(names = [], overrideLumi = None, xsPostWeights = None, effectiveLumi = None, nFilesMax = None, nEventsMax = None, weights = [], color = 1, markerStyle = 1 , weightedName = None) :
def specify(names=[], overrideLumi=None, xsPostWeights=None, effectiveLumi=None, nFilesMax=None, nEventsMax=None, weights=[], nInDivide=True, color=1, markerStyle=1 , weightedName=None):
assert not (overrideLumi and type(names)==list)
if type(names) != list : names = [names]
if type(weights) != list : weights = [weights]
samplespec = collections.namedtuple("samplespec", "name weightedName overrideLumi xsPostWeights effectiveLumi nFilesMax nEventsMax weights color markerStyle")

if not nInDivide: # typically, all events are required for correct normalization
for s in ["nFilesMax", "nEventsMax", "effectiveLumi"]:
x = eval(s)
if x is not None:
print "WARNING: nInDivide=False, but %s=%s (%s)" % (s, x, str(names))

samplespec = collections.namedtuple("samplespec", "name weightedName overrideLumi xsPostWeights effectiveLumi nFilesMax nEventsMax weights nInDivide color markerStyle")
weightNames = [w if type(w)==str else w.name for w in weights]
return [samplespec(name,'.'.join([name]+weightNames),overrideLumi,xsPostWeights,effectiveLumi,nFilesMax,nEventsMax,weights,color,markerStyle) for name in names]
return [samplespec(name, '.'.join([name]+weightNames), overrideLumi, xsPostWeights, effectiveLumi, nFilesMax, nEventsMax, weights, nInDivide, color, markerStyle) for name in names]

class SampleHolder(dict) :
sample = collections.namedtuple("sample", "filesCommand xs lumi ptHatMin nCheck")
def __init__(self) : self.inclusiveGroups = []
Expand All @@ -35,6 +42,7 @@ def update(self, other) :
for group in other.inclusiveGroups : self.addInclusiveGroup(group)

def add(self, name, filesCommand = None, xs = None, lumi = None, ptHatMin = None, nCheck = None) :
assert "/" not in name, "name '%s' contains at least one /" % name
assert name not in self, "%s already specified" % name
assert lumi or xs, "Underspecified sample: %s"%name
assert not (lumi and (xs or ptHatMin)), "Overspecified sample: %s"%name
Expand Down
2 changes: 2 additions & 0 deletions sites/uw_cmsTemplate.condor
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ transfer_output_files = OUTFLAG
Should_Transfer_Files = YES
WhenToTransferOutput = ON_EXIT

Requirements = HAS_CMS_HDFS

Output = JOBFLAG_$(Cluster)_$(Process).stdout
Error = JOBFLAG_$(Cluster)_$(Process).stderr
Log = JOBFLAG_$(Cluster)_$(Process).log
Expand Down
7 changes: 3 additions & 4 deletions steps/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ class skimmer(analysisStep):
created.
"""

def __init__(self, mainChain=True, otherChains=True, extraVars=[], haddOutput=False):
def __init__(self, mainChain=True, otherChains=True, extraVars=[], haddOutput=False, suffix="skim"):
assert mainChain or extraVars
self.outputTree = None
self.moreName = "(see below)"
for var in ["mainChain", "otherChains", "extraVars"]:
for var in ["mainChain", "otherChains", "extraVars", "haddOutput", "suffix"]:
setattr(self, var, eval(var))
self.addresses = None
self.haddOutput = haddOutput

def requiresNoSetBranchAddress(self):
return True # check
Expand Down Expand Up @@ -141,7 +140,7 @@ def endFunc(self, chains):
self.outputFile.Close()

def outputSuffix(self):
return "_skim.root"
return "_%s.root" % self.suffix

def modifiedFileName(self, s):
l = s.split("/")
Expand Down