コード例 #1
0
    def gen_card(self, file_name, **kwargs):
        doDataDriven = kwargs.pop("doDataDriven", True)

        # get the plotter
        nl = 3
        sigMap = getSigMap(nl)
        intLumiMap = getIntLumiMap()
        mergeDict = getMergeDict(self.period)
        channelBackground = getChannelBackgrounds(self.period)
        channels, leptons = getChannels(nl)
        saves = "%s_%s_%iTeV" % (self.analysis, self.region, self.period)

        plotter = Plotter(
            self.region,
            ntupleDir=self.ntuple_dir,
            saveDir=saves,
            period=self.period,
            rootName="plots_limits_wz",
            mergeDict=mergeDict,
            scaleFactor=self.scalefactor,
            datadriven=True,
        )
        plotter.initializeBackgroundSamples(
            [sigMap[self.period][x] for x in channelBackground[self.region + "datadriven"]]
        )
        plotter.initializeDataSamples([sigMap[self.period]["data"]])
        plotter.setIntLumi(intLumiMap[self.period])

        # set expected and observed yields
        sources = (
            [
                x
                for x in channelBackground[self.region + "datadriven"]
                if x not in ["TT", "T", "DY", "Z", "Zfiltered", "WW"]
            ]
            + ["datadriven"]
            if doDataDriven
            else channelBackground[self.region]
        )
        for bg in sources:
            self.log.info("Processing {0}".format(bg))
            val, err = plotter.getNumEntries(self.selection, sigMap[self.period][bg], doError=True)
            statname = "stat_{0}_{1}".format(bg, file_name.split(".")[0])
            staterrs = {bg: err / val + 1.0 if val else 1.0}
            if self.doStat:
                self.add_systematics(statname, "lnN", **staterrs)
            if bg in ["WZ"]:
                self.datacard.add_sig(bg, val)
            else:
                self.datacard.add_bkg(bg, val)
        self.log.info("Processing observed")
        self.datacard.set_observed(plotter.getDataEntries(self.selection))

        # write out the datacard
        self.log.info("Saving card to file")

        with open("%s/%s" % (self.out_dir, file_name), "w") as outfile:
            outfile.write(self.datacard.dump())
コード例 #2
0
ファイル: Limits.py プロジェクト: senka/InitialStateAnalysis
 def getPlotter(self,analysis,region,runPeriod,mass,runTau,plotName,doFakes):
     nl = 3 if analysis=='Hpp3l' or analysis=='WZ' else 4
     ntuples = getNtupleDirectory(analysis,region,runPeriod)
     saves = '%s_%s_%iTeV' % (analysis,region,runPeriod)
     sigMap = getSigMap(nl,mass)
     intLumiMap = getIntLumiMap()
     mergeDict = getMergeDict(runPeriod)
     regionBackground = getChannelBackgrounds(runPeriod)
     channels, leptons = getChannels(nl,runTau=runTau)
 
     plotter = Plotter(region,ntupleDir=ntuples,saveDir=saves,period=runPeriod,rootName=plotName,mergeDict=mergeDict,scaleFactor=self.scalefactor)
     if not doFakes: plotter.initializeBackgroundSamples([sigMap[runPeriod][x] for x in regionBackground[analysis]])
     if runPeriod==8: plotter.initializeDataSamples([sigMap[runPeriod]['data']])
     plotter.setIntLumi(intLumiMap[runPeriod])
 
     return plotter
コード例 #3
0
def calculateLeptonSystematic(mass,chanCuts,chanScales,**kwargs):
    do4l = kwargs.pop('do4l',False)
    analysis = 'Hpp3l'
    region = 'Hpp3l'
    runPeriod = 8
    nl = 3
    ntuples = getNtupleDirectory(analysis,region,runPeriod)
    saves = '%s_%s_%sTeV' % (analysis,region,runPeriod)
    sigMap = getSigMap(4,mass) if do4l else getSigMap(nl,mass)
    intLumiMap = getIntLumiMap()
    mergeDict = getMergeDict(runPeriod)
    regionBackground = {
        'Hpp3l' : ['T','TT', 'TTV','W','Z','VVV','WW','ZZ','WZ'],
        'Hpp4l' : ['TT','Z','DB']
    }
    channels, leptons = getChannels(nl)

    plotter = Plotter(analysis,ntupleDir=ntuples,saveDir=saves,period=runPeriod,rootName='systematics',mergeDict=mergeDict)
    plotter.initializeBackgroundSamples([sigMap[runPeriod][x] for x in regionBackground[analysis]])
    plotter.initializeSignalSamples([sigMap[runPeriod]['Sig']])
    plotter.initializeDataSamples([sigMap[runPeriod]['data']])
    plotter.setIntLumi(intLumiMap[runPeriod])

    fullCut = 'finalstate.mass>100 && finalstate.sT>1.1*%f+60. && fabs(z1.mass-%f)>80. && h1.dPhi<%f/600.+1.95' %(mass,ZMASS,mass)
    finalSRCut = 'h1.mass>0.9*%f && h1.mass<1.1*%f' %(mass,mass)

    totBG = 0
    totBG_scaled = 0
    for c,s in zip(chanCuts,chanScales):
        chanBG = s*plotter.getNumEntries('%s && %s && %s' %(c,fullCut,finalSRCut),plotter.signal[0],scaleup=False)
        chanBG_scaled = s*plotter.getNumEntries('%s && %s && %s' %(c,fullCut,finalSRCut),plotter.signal[0],scaleup=True)
        totBG += chanBG
        totBG_scaled += chanBG_scaled
    sigSelSys = (totBG_scaled-totBG)/totBG

    return sigSelSys+1