Exemplo n.º 1
0
def plotdjr(infile, outfile):

    TH1D.SetDefaultSumw2()

    tree = TChain("Events")
    # tree.Add(infile)
    for filename in fileList:
        tree.Add(filename)

    tree.SetAlias("GenEvent", "GenEventInfoProduct_generator__SIM.obj")
    tree.SetAlias("LHEEvent", "LHEEventProduct_externalLHEProducer__SIM.obj")

    weight = TCut("GenEvent.weight()")
    nbins = 50
    djrmin = -0.5
    djrmax = 3.
    # typeMC sets the kind of sample we are looking at:
    # 0 is for NLO with FXFX merging
    # 1 is for LO with MLM
    # 2 is for LO with MLM (plotting partons after excluding non-matched partons in wbb/vbf type processes)
    typeMC = 2

    pad = [None]*5
    setcanvas(c1, pad)
    gStyle.SetOptStat(0)

    histos = []
    histosAll = []
    xlabels = ["DJR 0.1", "DJR 1.2", "DJR 2.3", "DJR 3.4", "DJR 4.5"]

    for m in range(5):
        hall, h = makeplot("djr%d" % m, pad[m], tree, weight,
                         "log10(GenEvent.DJRValues_[%d])" %m, xlabels[m], nbins, djrmin, djrmax, typeMC)
        histos.append(h)
        histosAll.append(hall)

    c1.Print(outfile)
    c1.SaveAs(outfile.replace("root", "png"))
    c1.SaveAs(outfile.replace("root", "pdf"))
Exemplo n.º 2
0
#!/usr/bin/env python
# vim:set sts=4 sw=4 fdm=indent foldlevel=0 foldnestmax=2 et:

import os, imp, math
from ROOT import TFile
from ROOT import TCanvas, TLegend, TLatex, TAxis
from ROOT import TStyle, kWhite
from ROOT import TH1D, THStack, TRatioPlot
from ROOT import TList, TIter

cfi = imp.load_source("cfi", "drawAll_cfi.py")
TH1D.SetDefaultSumw2(True)
canvas = TCanvas("c1", "")
ctemp = TCanvas("ctemp", "")
latex = TLatex()


def SetTdrStyle():
    tdrStyle = TStyle("tdrStyle", "Style for P-TDR")

    # For the canvas:
    tdrStyle.SetCanvasBorderMode(0)
    tdrStyle.SetCanvasColor(kWhite)
    tdrStyle.SetCanvasDefH(600)  #Height of canvas
    tdrStyle.SetCanvasDefW(600)  #Width of canvas
    tdrStyle.SetCanvasDefX(0)  #POsition on screen
    tdrStyle.SetCanvasDefY(0)

    # For the Pad:
    tdrStyle.SetPadBorderMode(0)
    tdrStyle.SetPadColor(kWhite)
Exemplo n.º 3
0
        ff = suda(t1, t2)
        sum0 += ff
        sum00 += ff**2
    sum0 /= npoints
    sum00 /= npoints
    sigma2 = sum00 - sum0 * sum0
    error = sqrt(sigma2 / npoints)

    sudakov = exp(-sum0)
    sudError = sudakov * error  #Error of the sudakov
    return sudakov


# Book a histogram

TH1D.SetDefaultSumw2()
ntmax = 20
tmin, tmax = 1., 500.
histo1 = TH1D("sudakov", ";q^{2};sudakov", ntmax, tmin, tmax)

# Loop over data points in the histogram

for nt in range(1, ntmax + 1):
    t1 = histo1.GetBinCenter(nt)
    sudakov = Sudakov(t1, tmax)
    sudError = 0
    print " t2 = ", tmax, " t1 = ", t1, " Delta_S = ", sudakov, " +-", sudError
    histo1.SetBinContent(nt, sudakov)
    histo1.SetBinError(nt, sudError)

# Plot the Sudakov factor
Exemplo n.º 4
0
    def makeNominals(self, sampleName, sample, inFiles, outFile, variables,
                     columns, definitions, cuts, supercut, nuisances):
        print "===================="
        print "=== makeNominals ==="
        print "===================="
        gROOT.SetBatch()

        # only one sample dilivered for now
        self._inFiles = inFiles
        self._variables = variables
        self._cuts = cuts
        self._definitions = definitions

        #print 'ShapeFactory:sample',self._sample
        #print 'ShapeFactory:inFiles',self._inFiles
        #print 'ShapeFactory:outFile',self._outFile
        #print 'ShapeFactory:variables',self._variables
        #print 'ShapeFactory:cuts',self._cuts
        print 'ShapeFactory:supercut', supercut

        #in case some variables need a compiled function
        for variableName, variable in self._variables.iteritems():
            if variable.has_key('linesToAdd'):
                linesToAdd = variable['linesToAdd']
                for line in linesToAdd:
                    gROOT.ProcessLineSync(line)

        TH1D.SetDefaultSumw2(True)
        self.outFile = TFile(outFile, 'recreate')

        #print 'ShapeFactory',self._treeName
        #chain = TChain(self._treeName)
        #                                                         skipMissingFiles
        inputDir = ''
        trees = self._connectInputs(inFiles, inputDir, False)
        for cutName, cut in self._cuts.iteritems():
            totCut = cut + "&&" + supercut
            print 'cut', cutName, '::', cut
            self.outFile.mkdir(cutName)
            for variableName, variable in variables.iteritems():
                self.outFile.mkdir(cutName + "/" + variableName)
                self.outFile.cd(cutName + "/" + variableName)
                print variableName
                print 'variable[name]', variable['name']
                print 'variable[range]', variable['range'][0], ':', variable[
                    'range'][1], ':', variable['range'][2]

                doFold = 0
                if 'fold' in variable.keys():
                    print "	variable[fold] = ", variable['fold']
                    doFold = variable['fold']

                # create histogram
                if 'weights' in sample.keys():
                    outputsHisto = self._draw(
                        variable['name'], variable['range'], sample['weight'],
                        sample['weights'], totCut, sampleName, trees, columns,
                        doFold, cutName, variableName, sample, True)
                else:
                    outputsHisto = self._draw(variable['name'],
                                              variable['range'],
                                              sample['weight'], [], totCut,
                                              sampleName, trees, columns,
                                              doFold, cutName, variableName,
                                              sample, True)

                outputsHisto.Write()

                # weight based nuisances: kind = weight
                for nuisanceName, nuisance in nuisances.iteritems():
                    if ('cuts' not in nuisance) or (
                        ('cuts' in nuisance) and
                        (cutName in nuisance['cuts'])):
                        if 'kind' in nuisance:
                            if nuisance['kind'] == 'weight':
                                for sampleNuisName, configurationNuis in nuisance[
                                        'samples'].iteritems():
                                    if sampleNuisName == sampleName:
                                        newSampleNameUp = sampleName + '_' + nuisance[
                                            'name'] + 'Up'
                                        newSampleNameDo = sampleName + '_' + nuisance[
                                            'name'] + 'Down'
                                        #                                 the first weight is "up", the second is "down"
                                        newSampleWeightUp = sample[
                                            'weight'] + '* (' + configurationNuis[
                                                0] + ")"
                                        newSampleWeightDo = sample[
                                            'weight'] + '* (' + configurationNuis[
                                                1] + ")"

                                        if 'weights' in sample.keys():
                                            outputsHistoUp = self._draw(
                                                variable['name'],
                                                variable['range'],
                                                newSampleWeightUp,
                                                sample['weights'], totCut,
                                                newSampleNameUp, trees,
                                                columns, doFold, cutName,
                                                variableName, sample, False)
                                            outputsHistoDo = self._draw(
                                                variable['name'],
                                                variable['range'],
                                                newSampleWeightDo,
                                                sample['weights'], totCut,
                                                newSampleNameDo, trees,
                                                columns, doFold, cutName,
                                                variableName, sample, False)
                                        else:
                                            #print 'newSampleWeightUp', newSampleWeightUp
                                            outputsHistoUp = self._draw(
                                                variable['name'],
                                                variable['range'],
                                                newSampleWeightUp, [], totCut,
                                                newSampleNameUp, trees,
                                                columns, doFold, cutName,
                                                variableName, sample, False)
                                            outputsHistoDo = self._draw(
                                                variable['name'],
                                                variable['range'],
                                                newSampleWeightDo, [], totCut,
                                                newSampleNameDo, trees,
                                                columns, doFold, cutName,
                                                variableName, sample, False)

                                        outputsHistoUp.Write()
                                        outputsHistoDo.Write()

                            elif nuisance['kind'] == 'PDF':
                                for sampleNuisName, configurationNuis in nuisance[
                                        'samples'].iteritems():
                                    if sampleNuisName == sampleName:
                                        newSampleName = sampleName + '_' + nuisance[
                                            'name']

                                        if 'weights' in sample.keys():
                                            histoList = self._drawPDF(
                                                nuisance['type'],
                                                configurationNuis[0],
                                                variable['name'],
                                                variable['range'],
                                                sample['weight'],
                                                sample['weights'], totCut,
                                                newSampleName, trees, columns,
                                                doFold, cutName, variableName,
                                                sample, False)
                                        else:
                                            #print 'newSampleWeightUp', newSampleWeightUp
                                            histoList = self._drawPDF(
                                                nuisance['type'],
                                                configurationNuis[0],
                                                variable['name'],
                                                variable['range'],
                                                sample['weight'], [], totCut,
                                                newSampleName, trees, columns,
                                                doFold, cutName, variableName,
                                                sample, False)

                                        print 'length of histoList', len(
                                            histoList)
                                        for ahist in histoList:
                                            #print 'writing ahist'
                                            ahist.Write()
                                        #outputsHistoUp.Write()
                                        #outputsHistoDo.Write()

        self.outFile.Close()
        print 'FINISHED'