def main(): parser = argparse.ArgumentParser( description= 'Data writer for Zprime -> ll analysis interpretation in combine') parser.add_argument("-b", "--binned", action="store_true", default=False, help="use binned dataset") parser.add_argument("--expected", action="store_true", default=False, help="write datacards for expected limit mass binning") parser.add_argument("-i", "--inject", action="store_true", default=False, help="inject signal") parser.add_argument("-c", "--chan", dest="chan", default="", help="name of the channel to use") parser.add_argument("-o", "--options", dest="config", default="", help="name of config file") parser.add_argument("-m", "--mass", dest="mass", default=-1, type=int, help="mass point") parser.add_argument("-t", "--tag", dest="tag", default="", help="tag") parser.add_argument("-s", "--signif", action="store_true", default=False, help="write card for significances") parser.add_argument("--DM", action="store_true", default=False, help="write cards for DM interpretation") args = parser.parse_args() tag = args.tag if not args.tag == "": tag = "_" + args.tag import glob from ROOT import gROOT for f in glob.glob("userfuncs/*.cxx"): gROOT.ProcessLine(".L " + f + "+") configName = "scanConfiguration_%s" % args.config config = __import__(configName) moduleName = "channelConfig_%s" % args.chan module = __import__(moduleName) from createInputs import createWS, createHistograms, createSignalDataset from tools import getCardDir cardDir = getCardDir(args, config) if "toy" in tag: injectedFile = "input/%s%s.txt" % (args.chan, tag) if not os.path.isfile(injectedFile): print "dataset file %s does not yet exist. Will generate a dataset to use" % injectedFile name = "input/%s" % (args.chan) createSignalDataset(config.signalInjection["mass"], name, args.chan, config.signalInjection["width"], 0, config.signalInjection["CB"], tag=tag) elif args.inject: if config.signalInjection["CB"]: injectedFile = "input/%s_%d_%.3f_%d_CB.txt" % ( args.chan, config.signalInjection["mass"], config.signalInjection["width"], config.signalInjection["nEvents"]) else: injectedFile = "input/%s_%d_%.3f_%d.txt" % ( args.chan, config.signalInjection["mass"], config.signalInjection["width"], config.signalInjection["nEvents"]) if not os.path.isfile(injectedFile): print "dataset file %s does not yet exist. Will generate a dataset to use" % injectedFile name = "input/%s" % (args.chan) createSignalDataset(config.signalInjection["mass"], name, args.chan, config.signalInjection["width"], config.signalInjection["nEvents"], config.signalInjection["CB"]) if not os.path.exists(cardDir): os.makedirs(cardDir) if args.mass > 0: masses = [[5, args.mass, args.mass]] else: masses = config.masses if args.expected: masses = config.massesExp nMasses = 0 for massRange in masses: mass = massRange[1] while mass <= massRange[2]: nMasses += 1 mass += massRange[0] i = 1 for massRange in masses: mass = massRange[1] while mass <= massRange[2]: if args.binned: name = "%s/%s_%d_binned" % (cardDir, args.chan, mass) if args.inject or "toy" in tag: bkgYields = [ createHistograms(mass, 100, name, args.chan, config.width, config.correlate, config.binWidth, dataFile=injectedFile, CB=config.CB) ] else: bkgYields = [ createHistograms(mass, 100, name, args.chan, config.width, config.correlate, config.binWidth, CB=config.CB) ] else: name = "%s/%s_%d" % (cardDir, args.chan, mass) if args.inject or "toy" in tag: bkgYields = [ createWS(mass, 100, name, args.chan, config.width, config.correlate, dataFile=injectedFile, CB=config.CB) ] else: bkgYields = [ createWS(mass, 100, name, args.chan, config.width, config.correlate, CB=config.CB) ] if args.DM: signalScale = module.provideSignalScaling(mass, DM=True) else: signalScale = module.provideSignalScaling(mass) * 1e-7 nBkg = 1 # only one source of background supported at the moment channelDict = {} channelDict["date"] = time.strftime("%d/%m/%Y") channelDict["time"] = time.strftime("%H:%M:%S") #channelDict["hash"] = get_git_revision_hash() channelDict["bin"] = args.chan channelDict["nBkgs"] = nBkg if nBkg == 1: channelDict["bkgShapes"] = getBackgroundShapes( args.binned, "%s.root" % name, args.chan, 0) else: channelDict["bkgShapes"] = "" for i in range(1, nBkg + 1): channelDict["bkgShapes"] += getBackgroundShapes( args.binned, "%s.root" % nam, eargs.chan, i) if i < nBkg: channelDict["bkgShapes"] += "\n" scale = False if "massScale" in config.systematics: scale = True channelDict["sigShape"] = getSignalShape(args.binned, "%s.root" % name, args.chan, scale) channelDict["data"] = getDataset(args.binned, "%s.root" % name, args.chan) channelDict["channels"] = getChannelBlock(nBkg, bkgYields, signalScale, args.chan) uncertBlock = "" uncerts = module.provideUncertainties(mass) for uncert in config.systematics: uncertBlock += getUncert(uncert, uncerts[uncert], nBkg, mass, args.chan, config.correlate, args.binned, bkgYields, args.signif) channelDict["systs"] = uncertBlock writeCard(cardTemplate % channelDict, name) printProgress(i, nMasses, prefix='Progress:', suffix='Complete', barLength=50) i += 1 mass += massRange[0]
maxVal, '%s ;m [GeV]; scale' % channel) scaleGraph.Draw('LPsame') c.Print('validation/%s_scale.pdf' % channel) from tools import getMassRange mass = 4500 massLow, massHigh = getMassRange( mass, 100, 0.006 + channelConfig.getResolution(mass)['res'], channelConfig.dataFile, 150) ws = createWS(mass, 100, args.config, channel, 0.1, False, dataFile="", CB=True, write=False, useShapeUncert=True) #massRanges[0][1] = 200 #massRanges[-1][2] = 400 frame = ws.var('mass_%s' % channel).frame( ROOT.RooFit.Title(''), ROOT.RooFit.Range(massLow, massHigh)) ws.data("data_%s" % channel).plotOn( frame, ROOT.RooFit.Range(massLow, massHigh)) ws.pdf('bkgpdf_%s' % channel).plotOn( frame, ROOT.RooFit.Range(massLow, massHigh), ROOT.RooFit.LineWidth(2))