예제 #1
0
    def harvestEm(self,channel='wenu',charge='both'):
        cmb = ch.CombineHarvester()

        # Read all the cards.
        # CH stores metadata about each object (Observation, Process, Systematic),
        # this is extracted from the card names with some regex
        for card in glob.glob(self.bindir+('/%s_mass*.txt' % channel)):
            cmb.QuickParseDatacard(card, """%s_mass(?<MASS>\d+)_$CHANNEL.card.txt""" % channel)

        # Need a unqiue bin name for each plus/minus,pt and eta combination
        # We extracted this part of the datacard name into the channel variable above,
        # so can just copy it and override the specific bin name that was in all the cards
        cmb.ForEachObj(lambda obj: obj.set_bin(obj.channel()))

        # We'll have three copies of the observation, one for each mass point.
        # Filter all but one copy.
        cmb.FilterObs(lambda obj: obj.mass() != '%d' % self.mwcentral)

        # Create workspace to hold the morphing pdfs and the mass
        w = ROOT.RooWorkspace('morph', 'morph')
        mass = w.factory('mw[{mwrange}]'.format(mwrange=self.mwrange))

        # BuildRooMorphing will dump a load of debug plots here
        debug = ROOT.TFile(self.bindir+'/debug.root', 'RECREATE')

        # Run for each bin,process combination (only for signal!)
        for b in cmb.bin_set():
            for p in cmb.cp().bin([b]).signals().process_set():
                morphing.BuildRooMorphing(w, cmb, b, p, mass, verbose=True, file=debug)

        # Just to be safe
        mass.setConstant(True)

        # Now the workspace is copied into the CH instance and the pdfs attached to the processes
        # (this relies on us knowing that BuildRooMorphing will name the pdfs in a particular way)
        cmb.AddWorkspace(w, True)
        cmb.cp().process(['W']).ExtractPdfs(cmb, 'morph', '$BIN_$PROCESS_morph', '')

        # Adjust the rateParams a bit - we currently have three for each bin (one for each mass),
        # but we only want one. Easiest to drop the existing ones completely and create new ones
        cmb.syst_type(['rateParam'], False)
        cmb.cp().process(['W']).AddSyst(cmb, 'norm_$BIN', 'rateParam', ch.SystMap()(1.00))

        # Have to set the range by hand
        for sys in cmb.cp().syst_type(['rateParam']).syst_name_set():
            cmb.GetParameter(sys).set_range(0.5, 1.5)

        # Print the contents of the model
        cmb.PrintAll()

        # Write out the cards, one per bin
        outdir=self.bindir+'/wenu_cards_morphed_{charge}'.format(charge=charge)
        writer = ch.CardWriter('$TAG/$BIN.txt', '$TAG/shapes.root')
        writer.SetVerbosity(1)
        writer.WriteCards(outdir, cmb)
	def create_morphing_signals(self, morphing_variable_name, nominal_value, min_value, max_value):
		self.workspace = ROOT.RooWorkspace("workspace", "workspace")
		self.morphing_variable = ROOT.RooRealVar(morphing_variable_name, morphing_variable_name, nominal_value, min_value, max_value)

		cb_signals = self.cb.cp().signals()
		for category in cb_signals.bin_set():
			cb_signals_category = cb_signals.cp().bin([category])
			for signal_process in cb_signals_category.process_set():
				morphing.BuildRooMorphing(self.workspace, self.cb, category, signal_process, self.morphing_variable, "norm", True, log.isEnabledFor(logging.DEBUG))

		self.cb.AddWorkspace(self.workspace, False)
		self.cb.cp().signals().ExtractPdfs(self.cb, "workspace", "$BIN_$PROCESS_morph", "")

		if log.isEnabledFor(logging.DEBUG):
			self.cb.PrintAll()
예제 #3
0
                             bkg_histogram_name_template,
                             sig_histogram_name_template,
                             bkg_syst_histogram_name_template,
                             sig_syst_histogram_name_template,
                             update_systematics=False)

    # create morphing
    ws = ROOT.RooWorkspace("w", "w")
    mes = ROOT.RooRealVar("mes", "", 1.0, args.shift_ranges[0],
                          args.shift_ranges[1])

    for decayMode in args.decay_modes:
        for pt_index, (pt_range) in enumerate(pt_ranges):
            category = "mt_inclusive_" + decayMode + "_ptbin" + pt_bins[
                pt_index]
            morphing.BuildRooMorphing(ws, datacards.cb, category, "ZTT", mes,
                                      "norm", True, True)

    # For some reason the default arguments are not working in the python wrapper
    # of AddWorkspace and ExtractPdfs. Hence, the last argument in either function
    # is set by hand to their default values
    datacards.cb.AddWorkspace(ws, False)
    datacards.cb.cp().signals().ExtractPdfs(datacards.cb, "w",
                                            "$BIN_$PROCESS_morph", "")

    # add bin-by-bin uncertainties
    if args.add_bbb_uncs:
        datacards.add_bin_by_bin_uncertainties(
            processes=datacards.cb.cp().backgrounds().process_set() +
            datacards.cb.cp().signals().process_set(),
            add_threshold=0.1,
            merge_threshold=0.5,
예제 #4
0
#ch.SetStandardBinNames(cb)

# Create workspace
w = ROOT.RooWorkspace('morph', 'morph')

mT = ROOT.RooRealVar("MT","",172.5*decimalScaling,165*decimalScaling,180*decimalScaling)
mT.setConstant(True)


debug = ROOT.TFile('debug.root', 'RECREATE')

# Create morphing splines
print "BuildRooMorphing"
for b in cb.cp().channel(['mtop']).bin_set():   # rec_ptll, rec_ptpos
    for sig in signals: # tt, tW
        morphing.BuildRooMorphing(w, cb, b, sig, mT,force_template_limit=False,file=debug)
        #morphing.BuildRooMorphing(w, cb, b, sig, mT,force_template_limit=False,file=debug, interp_mode="CSPLINE")

cb.AddWorkspace(w,True)

print "Extracting pdfs"
# Extract morphed templates
cb.cp().signals().ExtractPdfs(cb, 'morph', '$BIN_$PROCESS_morph', '')

print "Done extracting pdfs"
# Set up groups
if len(systematics) > 0:
    cb.SetGroup('all', theorySysts + experimentalSysts + binStats)
    cb.SetGroup('theory', theorySysts)
    cb.SetGroup('exp', experimentalSysts)
    if addBinStats: