Skip to content

Commit

Permalink
Merge pull request #15 from bianchini/Lorenzo_V0
Browse files Browse the repository at this point in the history
Lorenzo v0
emanca authored Mar 8, 2019
2 parents 062f6ae + b66a11c commit 59f590a
Showing 3 changed files with 210 additions and 173 deletions.
4 changes: 2 additions & 2 deletions framework/RDFtreeV2.py
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ def getOutput(self):

# now write all the outputs together

print "writing output files in "+ self.outputDir
print "Writing output files in "+ self.outputDir

if not os.path.exists(self.outputDir):
os.system("mkdir -p " + self.outputDir)
@@ -100,7 +100,7 @@ def getOutput(self):
os.chdir('..')
self.objs = {} # re-initialise object list

print self.entries.GetValue(), " events processed in ", time.time()-self.start, " s"
print self.entries.GetValue(), "events processed in "+"{:0.1f}".format(time.time()-self.start), "s"

def saveGraph(self):

51 changes: 20 additions & 31 deletions wmass/controlPlots/controlPlots.py
Original file line number Diff line number Diff line change
@@ -7,64 +7,53 @@

class controlPlots(module):

def __init__(self, selections, variables, dataType, xsec, file, targetLumi = 1.):
def __init__(self, selections, variables, dataType, xsec, inputFile, targetLumi = 1.):

# TH lists
self.myTH1 = []
self.myTH2 = []
self.myTH3 = []

self.dataType = dataType # mc or data
self.selections = selections # for example, 'W'
# MC or DATA
self.dataType = dataType
self.selections = selections
self.variables = variables

self.xsec = xsec / 0.001 # pb to fb conversion
self.file = file
# pb to fb conversion
self.xsec = xsec / 0.001
self.targetLumi = targetLumi


self.inputFile = inputFile

def run(self,d):


RDF = ROOT.ROOT.RDataFrame
runs = RDF('Runs', self.file)
runs = RDF('Runs', self.inputFile)

if self.dataType == 'mc':
if self.dataType == 'MC':
genEventSumw = runs.Sum("genEventSumw").GetValue()
print (1.*self.xsec)/genEventSumw, 'lumiweight', genEventSumw, 'genEventSumw', self.xsec, 'xsec'
#print 'genEventSumw : '+'{:1.1f}'.format(genEventSumw)+' weighted events'
#print 'xsec : '+'{:1.1f}'.format(self.xsec)+' pb'
#print 'lumiweight : '+'{:1.8f}'.format((1.*self.xsec)/genEventSumw)+' (|Generator_weight| not accounted for)'
#genEventSumw=1

self.d = d.Filter(self.selections[self.dataType]['cut'])

# define mc specific weights

if self.dataType == 'mc':

self.d = self.d.Define('lumiweight', '({L}*{xsec})/({genEventSumw})'.format(L=self.targetLumi, genEventSumw = genEventSumw, xsec = self.xsec))\
.Define('totweight', 'lumiweight*Generator_weight*{}'.format(self.selections[self.dataType]['weight']))

if self.dataType == 'MC':
self.d = self.d.Define('lumiweight', '({L}*{xsec})/({genEventSumw})'.format(L=self.targetLumi, genEventSumw = genEventSumw, xsec = self.xsec)) \
.Define('totweight', 'lumiweight*Generator_weight*{}'.format(self.selections[self.dataType]['weight']))
else:
self.d = self.d.Define('totweight', '1')

# loop over variables

for Collection,dic in self.variables.iteritems():


if not dic['newCollection'] == '':

if 'index' in dic:

# first of all define a new subcollection with all the columns of the original collection

self.d = self.defineSubcollectionFromIndex(Collection, dic['newCollection'], dic['index'], self.d)

if 'index' in dic:
# define a new subcollection with all the columns of the original collection
self.d = self.defineSubcollectionFromIndex(Collection, dic['newCollection'], dic['index'], self.d)
for var,tools in dic['variables'].iteritems():

columns = list(self.d.GetDefinedColumnNames())

h = self.d.Histo1D((var, " ; {}; ".format(tools[0]), tools[1],tools[2], tools[3]), dic['newCollection']+dic['modifiers']+'_'+var, 'totweight')

h = self.d.Histo1D((var, " ; {}; ".format(tools[0]), tools[1],tools[2], tools[3]), dic['newCollection']+dic['modifiers']+'_'+var, 'totweight')
self.myTH1.append(h)

return self.d
Loading

0 comments on commit 59f590a

Please sign in to comment.