Esempio n. 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())
Esempio n. 2
0
 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