def import_model(self, w, whichs={}, name=""): for part in ['','qcd']: if part not in whichs: whichs[part] = dict((i, '_both') for i in ['wj', 'st', 'ttgg', 'ttqq', 'ttqg', 'ttag']) if self.asymmetry: whichs[part].update({'ttqq': '', 'ttqg': '', 'ttag': ''}) whichs[''].update({'dy': '_symm'}) [roo.factory(w, "SUM::%s_mj( expect_%sqcd_data * %sqcd_data_both, %s )" % (name+lepton, lepton, lepton, ','.join(['expect_%s_%s * %s_%s%s' % (lepton + 'qcd', key, lepton + 'qcd', key, value) for key, value in whichs['qcd'].items()]))) for lepton in self.channels] [roo.factory(w, "SUM::model_%s( expect_%sqcd_data * %sqcd_data_both, %s )" % (name+lepton, lepton, lepton, ','.join(['expect_%s_%s * %s_%s%s' % (lepton + part, key, lepton + part, key, value) for part, which in whichs.items() for key, value in which.items() ]))) for lepton in self.channels] roo.factory(w, "SIMUL::%smodel(channel, %s)" % (name, ', '.join("%s=model_%s" % (lepton, name + lepton) for lepton in self.channels)))
def import_model(self, w, whichs={}, name=""): for part in ['','qcd']: if part not in whichs: whichs[part] = dict((i, '_both') for i in ['wj', 'st']) if part!='qcd': whichs[part]['dy'] = '_symm' whichs[part].update({'tt': ''}) if 'dy' in whichs[part]: whichs[part].update({'dy': '_symm'}) if not self.quiet: print 'name:', name, '|', whichs if whichs['qcd']: [roo.factory(w, "SUM::%s_mj( expect_%sqcd_data * %sqcd_data_both, %s )" % (name+lepton, lepton, lepton, ','.join(['expect_%s_%s * %s_%s%s' % (lepton + 'qcd', key, lepton + 'qcd', key, value) for key, value in whichs['qcd'].items()]))) for lepton in self.channels] [roo.factory(w, "SUM::%smodel_%s( %s )" % (name,lepton, ','.join((['expect_%sqcd_data * %sqcd_data_both' % (lepton, lepton)] if whichs['qcd'] else []) + ['expect_%s_%s * %s_%s%s' % (lepton + part, key, lepton + part, key, value) for part, which in whichs.items() for key, value in which.items() ]))) for lepton in self.channels] roo.factory(w, "SIMUL::%smodel(channel, %s)" % (name, ', '.join("%s=%smodel_%s" % (lepton, name, lepton) for lepton in self.channels)))
def import_model(self, w, whichs={}, name=""): for part in ['', 'qcd']: if part not in whichs: whichs[part] = dict( (i, '_both') for i in ['wj', 'st', 'ttgg', 'ttqq', 'ttqg', 'ttag']) if self.asymmetry: whichs[part].update({'ttqq': '', 'ttqg': '', 'ttag': ''}) whichs[''].update({'dy': '_symm'}) [ roo.factory( w, "SUM::%s_mj( expect_%sqcd_data * %sqcd_data_both, %s )" % (name + lepton, lepton, lepton, ','.join([ 'expect_%s_%s * %s_%s%s' % (lepton + 'qcd', key, lepton + 'qcd', key, value) for key, value in whichs['qcd'].items() ]))) for lepton in self.channels ] [ roo.factory( w, "SUM::model_%s( expect_%sqcd_data * %sqcd_data_both, %s )" % (name + lepton, lepton, lepton, ','.join([ 'expect_%s_%s * %s_%s%s' % (lepton + part, key, lepton + part, key, value) for part, which in whichs.items() for key, value in which.items() ]))) for lepton in self.channels ] roo.factory( w, "SIMUL::%smodel(channel, %s)" % (name, ', '.join("%s=model_%s" % (lepton, name + lepton) for lepton in self.channels)))
def import_alt_model(self, channelDict): w = self.w sample = "ttalt" leptons = ['el', 'mu'] channels = dict((L, channelDict[(L, 'top')]) for L in leptons) #xs xs = channels['el'].samples[sample].xs roo.wimport_const(w, 'xs_%s_hat' % sample, xs) roo.factory(w, "d_xs_%s[0,-0.5,1.5]" % sample) roo.factory( w, "expr::xs_%s('(1+@0)*@1',{d_xs_%s, xs_%s_hat})" % (3 * (sample, ))) # eff [ roo.wimport_const(w, 'eff_%s_%s' % (lepton, sample), channel.samples[sample].eff) for lepton, channel in channels.items() ] [ self.import_shape(w, lepton, sample, data) for lepton, channel in channels.items() for sample, data in channel.samples.items() ] self.import_model(w, whichs={ '': dict((i, '_both') for i in ['dy', 'wj', 'st', 'ttalt']) }, name="alt")
def import_expressions(self, w): [roo.factory(w, "sum::expect_%s_notqcd(%s)" % (L, ','.join(['expect_%s_%s' % (L, s) for s in ['wj', 'st', 'tt']]))) for L in self.channels_qcd] [roo.factory(w, "sum::expect_%(n)s_mj(expect_%(n)sqcd_data,expect_%(n)sqcd_notqcd)" % {'n': L}) for L in self.channels]
def import_shapes(self, w, channels=None): if not channels: channels = self.channels [roo.factory(w, "%s[-1,1]" % obs) for obs in self.observables] roo.factory(w, "channel[%s]" % ','.join("%s=%d" % (s, i) for i, s in enumerate(channels))) for v, X in zip(self.observables, 'XY'): w.var(v).setBins(getattr(self.channels['el'].samples['data'].datas[0], 'GetNbins' + X)()) [self.import_shape(w, lepton, sample, data) for lepton, channel in channels.items() for sample, data in channel.samples.items() if sample != 'data']
def import_qcd(self, w): [roo.factory(w, "factor_%s[1,0,5]" % lepton) for lepton in self.channels_qcd] self.import_efficiencies(w, self.channels_qcd) self.import_shapes(w, self.channels_qcd) arglist = r.RooArgList(*[w.var(o) for o in self.observables]) argset = r.RooArgSet(arglist) for L, channel in self.channels_qcd.items(): hist = channel.samples['data'].datas[0] dhist = '%s_data_sim_both' % L roo.wimport(w, r.RooDataHist(dhist, '', arglist, hist)) roo.wimport(w, r.RooHistPdf('%s_data_both' % L, '', argset, w.data(dhist))) roo.factory(w, "expr::expect_%s_data('@0*%f',{factor_%s})" % (L, hist.Integral(), L))
def import_shape(self, w, lepton, sample, data): name = '_'.join([lepton, sample]) arglist = r.RooArgList(*[w.var(o) for o in self.observables]) argset = r.RooArgSet(arglist) for i, label in enumerate(['both', 'symm'][:None if sample in ['tt', 'dy'] else -1]): nL = (name, label) roo.wimport(w, r.RooDataHist('_sim_'.join(nL), '', arglist, data.datas[i])) roo.wimport(w, r.RooHistPdf('_'.join(nL), '', argset, w.data('_sim_'.join(nL)))) roo.factory(w, "prod::expect_%s(%s)" % (name, ','.join(['lumi_' + lepton, 'xs_' + sample, 'eff_' + name, '-1', 'factor_%s' % lepton][:None if 'qcd' in lepton else -2])))
def import_asymmetry(self, w): alpha_max = 0.99 * min(chan.samples['tt'].alphaMax for chan in self.channels.values() + self.channels_qcd.values()) roo.factory(w, "alpha[1, -%f, %f]"%(alpha_max,alpha_max)) [roo.factory(w, "SUM::%(n)s( alpha * %(n)s_both, %(n)s_symm )" % {'n': L+'_tt'}) for L in (self.channels.keys() + self.channels_qcd.keys())] assert self.gen.samples['tt'].datas[0].GetXaxis().GetTitle() == genNameX assert self.gen.samples['tt'].datas[0].GetYaxis().GetTitle() == genNameY for n, d in self.gen.samples.items(): hists = {'XL':d.datasX[0], 'XT':d.datasY[0]} ac, eac = lib.asymmetry(hists[self.observables[0]]) roo.wimport_const(w, 'Ac_'+n, ac) roo.wimport_const(w, 'err_Ac_'+n, eac)
def __init__(self, template): symm,anti = lib.symmAnti(template) for item in ['template','symm','anti']: setattr(self, item, eval(item)) self.nBinsX = symm.GetNbinsX() w = r.RooWorkspace('Workspace') roo.factory(w, "x[-1,1]") argset = w.argSet("x") arglist = r.RooArgList(argset) roo.wimport(w, r.RooDataHist('dh_template_both','', arglist, template)) roo.wimport(w, r.RooDataHist('dh_template_symm','', arglist, symm)) roo.wimport(w, r.RooHistPdf('pdf_template_both','',argset, w.data('dh_template_both'))) roo.wimport(w, r.RooHistPdf('pdf_template_symm','',argset, w.data('dh_template_symm'))) self.import_asymmetry(w) self.w = w
def import_shapes(self, w, channels=None): if not channels: channels = self.channels [roo.factory(w, "%s[-1,1]" % obs) for obs in self.observables] roo.factory( w, "channel[%s]" % ','.join("%s=%d" % (s, i) for i, s in enumerate(channels))) for v, X in zip(self.observables, 'XYZ'[:None if self.asymmetry else -1]): w.var(v).setBins( getattr( unqueue(self.channels['el'].samples['data'].datas[0], self.asymmetry), 'GetNbins' + X)()) [ self.import_shape(w, lepton, sample, data) for lepton, channel in channels.items() for sample, data in channel.samples.items() if sample != 'data' ]
def import_qcd(self, w): [ roo.factory(w, "factor_%s[1,0,5]" % lepton) for lepton in self.channels_qcd ] self.import_efficiencies(w, self.channels_qcd) self.import_shapes(w, self.channels_qcd) arglist = r.RooArgList(*[w.var(o) for o in self.observables]) argset = r.RooArgSet(arglist) for L, channel in self.channels_qcd.items(): hist = unqueue(channel.samples['data'].datas[0], self.asymmetry) dhist = '%s_data_sim_both' % L roo.wimport(w, r.RooDataHist(dhist, '', arglist, hist)) roo.wimport( w, r.RooHistPdf('%s_data_both' % L, '', argset, w.data(dhist))) roo.factory( w, "expr::expect_%s_data('@0*%f',{factor_%s})" % (L, hist.Integral(), L))
def import_asymmetry(self, w): alpha_max = 0.99 * lib.alphaMax(self.symm, self.anti) roo.factory(w, "alpha[0, -%f, %f]"%(alpha_max,alpha_max)) roo.factory(w, 'SUM::model( alpha * pdf_template_both, pdf_template_symm)') ac, eac = lib.asymmetry(self.template) roo.wimport_const(w, "Ac_template", ac) roo.factory(w, "prod::Ac(Ac_template, alpha)")
def import_expressions(self, w): [ roo.factory( w, "sum::expect_%s_tt(%s)" % (L, ','.join(['expect_%s_tt%s' % (L, f) for f in self.ttcomps]))) for L in self.channels ] [ roo.factory( w, "sum::expect_%s_notqcd(%s)" % (L, ','.join([ 'expect_%s_%s' % (L, s) for s in ['wj', 'st', 'ttgg', 'ttag', 'ttqg', 'ttqq'] ]))) for L in self.channels_qcd ] [ roo.factory( w, "sum::expect_%(n)s_mj(expect_%(n)sqcd_data,expect_%(n)sqcd_notqcd)" % {'n': L}) for L in self.channels ]
def import_alt_model(self, channelDict): w = self.w sample = "ttalt" leptons = ['el', 'mu'] channels = dict((L, channelDict[(L,'top')]) for L in leptons) #xs xs = channels['el'].samples[sample].xs roo.wimport_const(w, 'xs_%s_hat' % sample, xs) roo.factory(w, "d_xs_%s[0,-0.5,1.5]" % sample) roo.factory(w, "expr::xs_%s('(1+@0)*@1',{d_xs_%s, xs_%s_hat})" % (3 * (sample,))) # eff [roo.wimport_const(w, 'eff_%s_%s' % (lepton, sample), channel.samples[sample].eff) for lepton, channel in channels.items() ] [self.import_shape(w, lepton, sample, data) for lepton, channel in channels.items() for sample, data in channel.samples.items()] self.import_model(w, whichs={'':dict((i, '_both') for i in ['dy', 'wj', 'st', 'ttalt'])}, name="alt")
def import_shape(self, w, lepton, sample, data): name = '_'.join([lepton, sample]) arglist = r.RooArgList(*[w.var(o) for o in self.observables]) argset = r.RooArgSet(arglist) for i, label in enumerate([ 'both', 'symm' ][:None if sample in ['ttag', 'ttqg', 'ttqq', 'dy'] else -1]): nL = (name, label) roo.wimport( w, r.RooDataHist('_sim_'.join(nL), '', arglist, unqueue(data.datas[i], self.asymmetry))) roo.wimport( w, r.RooHistPdf('_'.join(nL), '', argset, w.data('_sim_'.join(nL)))) roo.factory( w, "prod::expect_%s(%s)" % (name, ','.join([ 'lumi_' + lepton, 'xs_' + sample, 'eff_' + name, '-1', 'factor_%s' % lepton ][:None if 'qcd' in lepton else -2])))
def import_fractions(self, w): [roo.wimport_const(w, "f_%s_hat" % comp, self.gen.samples['tt' + comp].frac) for comp in self.ttcomps] if self.asymmetry: f_qq_max = 0.3 alphaL_max = 0.99 * min(chan.samples['ttqq'].alphaMax for chan in self.channels.values() + self.channels_qcd.values()) falphaL_max = f_qq_max * alphaL_max roo.factory(w, "falphaL[0.13, -%f, %f]"%(falphaL_max,falphaL_max)) roo.factory(w, "slosh[0.44, 0, 1]") e_dqq = '( @0*%f + (1-@0)*abs(@1)/%f) / @2 -1'%(f_qq_max, alphaL_max) roo.factory(w, "expr::d_qq('%s',{slosh,falphaL,f_qq_hat})"%e_dqq) else: roo.factory(w, "d_qq[-0.999999,1]") roo.factory(w, "R_ag[%f,0.07,1]" % (self.gen.samples['ttag'].frac / self.gen.samples['ttqq'].frac)) roo.factory(w, "expr::f_qq('(1+@0)*@1',{d_qq,f_qq_hat})") roo.factory(w, "prod::f_ag(R_ag,f_qq)") roo.factory(w, "expr::f_qg('(1-@0-@1)/(1+@2*@3*@4/(@5*@6))'," +\ "{f_qq,f_ag,R_ag,f_gg_hat,f_qq_hat,f_ag_hat,f_qg_hat})") roo.factory(w, "expr::f_gg('1-@0-@1-@2',{f_qq,f_ag,f_qg})") if self.fixFractions: w.arg('slosh').setConstant(True) w.arg('R_ag').setConstant(True)
def import_asymmetry(self, w): if not self.asymmetry: return roo.factory(w, "falphaT[0.18, -0.8, 0.8]") roo.factory(w, "expr::alphaT('@0/@1',{falphaT,f_qg})") roo.factory(w, "expr::alphaL('@0/@1',{falphaL,f_qq})") [(roo.factory( w, "SUM::%(n)s( alphaT * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttag'}), roo.factory( w, "SUM::%(n)s( alphaT * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqg'}), roo.factory( w, "SUM::%(n)s( alphaL * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqq'})) for L in self.channels.keys()] [(roo.factory( w, "SUM::%(n)s( 0 * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttag'}), roo.factory( w, "SUM::%(n)s( 0 * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqg'}), roo.factory( w, "SUM::%(n)s( 0 * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqq'})) for L in self.channels_qcd.keys()] assert self.gen.samples['tt'].datas[0].GetXaxis().GetTitle( ) == genNameX assert self.gen.samples['tt'].datas[0].GetYaxis().GetTitle( ) == genNameY for n, d in self.gen.samples.items(): y, ey = lib.asymmetry(d.datasX[0]) p, ep = lib.asymmetry(d.datasY[0]) roo.wimport_const(w, 'Ac_y_' + n, y) roo.wimport_const(w, 'Ac_phi_' + n, p) roo.wimport_const(w, 'err_Ac_y_' + n, ey) roo.wimport_const(w, 'err_Ac_phi_' + n, ep)
def import_xs_lumi(self, w): roo.factory(w, "d_lumi[0,-0.2,0.2]") roo.factory(w, 'lumi_factor[1.0]') w.arg('lumi_factor').setConstant() for L, channel in self.channels.items() + self.channels_qcd.items(): roo.wimport_const(w, 'lumi_%s_hat' % L, channel.lumi) if 'qcd' in L: roo.factory(w, "expr::lumi_%s('(1+@0)*@1', {d_lumi, lumi_%s_hat})" % (L, L)) else: roo.factory(w, "expr::lumi_%s('(1+@0)*@1*@2', {d_lumi, lumi_%s_hat, lumi_factor})" % (L, L)) xs_constraints = dict([(samp[:2], data.xs) for samp, data in self.channels['el'].samples.items() if data.xs > 0]) for sample, xs in xs_constraints.items(): roo.wimport_const(w, 'xs_%s_hat' % sample, xs) roo.factory(w, "d_xs_%s[0,-0.5,1.5]" % sample) roo.factory(w, "expr::xs_%s('(1+@0)*@1',{d_xs_%s, xs_%s_hat})" % (3 * (sample,)))
def import_fractions(self, w): [ roo.wimport_const(w, "f_%s_hat" % comp, self.gen.samples['tt' + comp].frac) for comp in self.ttcomps ] if self.asymmetry: f_qq_max = 0.3 alphaL_max = 0.99 * min(chan.samples['ttqq'].alphaMax for chan in self.channels.values() + self.channels_qcd.values()) falphaL_max = f_qq_max * alphaL_max roo.factory(w, "falphaL[0.13, -%f, %f]" % (falphaL_max, falphaL_max)) roo.factory(w, "slosh[0.44, 0, 1]") e_dqq = '( @0*%f + (1-@0)*abs(@1)/%f) / @2 -1' % (f_qq_max, alphaL_max) roo.factory(w, "expr::d_qq('%s',{slosh,falphaL,f_qq_hat})" % e_dqq) else: roo.factory(w, "d_qq[-0.999999,1]") roo.factory( w, "R_ag[%f,0.07,1]" % (self.gen.samples['ttag'].frac / self.gen.samples['ttqq'].frac)) roo.factory(w, "expr::f_qq('(1+@0)*@1',{d_qq,f_qq_hat})") roo.factory(w, "prod::f_ag(R_ag,f_qq)") roo.factory(w, "expr::f_qg('(1-@0-@1)/(1+@2*@3*@4/(@5*@6))'," +\ "{f_qq,f_ag,R_ag,f_gg_hat,f_qq_hat,f_ag_hat,f_qg_hat})") roo.factory(w, "expr::f_gg('1-@0-@1-@2',{f_qq,f_ag,f_qg})") if self.fixFractions: w.arg('slosh').setConstant(True) w.arg('R_ag').setConstant(True)
def import_xs_lumi(self, w): roo.factory(w, "d_lumi[0,-0.2,0.2]") roo.factory(w, 'lumi_factor[1.0]') w.arg('lumi_factor').setConstant() for L, channel in self.channels.items() + self.channels_qcd.items(): roo.wimport_const(w, 'lumi_%s_hat' % L, channel.lumi) if 'qcd' in L: roo.factory( w, "expr::lumi_%s('(1+@0)*@1', {d_lumi, lumi_%s_hat})" % (L, L)) else: roo.factory( w, "expr::lumi_%s('(1+@0)*@1*@2', {d_lumi, lumi_%s_hat, lumi_factor})" % (L, L)) xs_constraints = dict([ (samp[:2], data.xs) for samp, data in self.channels['el'].samples.items() if data.xs > 0 ]) for sample, xs in xs_constraints.items(): roo.wimport_const(w, 'xs_%s_hat' % sample, xs) roo.factory(w, "d_xs_%s[0,-0.5,1.5]" % sample) roo.factory( w, "expr::xs_%s('(1+@0)*@1',{d_xs_%s, xs_%s_hat})" % (3 * (sample, ))) [ roo.factory(w, "prod::xs_tt%s(f_%s,xs_tt)" % (c, c)) for c in self.ttcomps ]
def import_asymmetry(self, w): if not self.asymmetry: return roo.factory(w, "falphaT[0.18, -0.8, 0.8]") roo.factory(w, "expr::alphaT('@0/@1',{falphaT,f_qg})") roo.factory(w, "expr::alphaL('@0/@1',{falphaL,f_qq})") [(roo.factory(w, "SUM::%(n)s( alphaT * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttag'}), roo.factory(w, "SUM::%(n)s( alphaT * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqg'}), roo.factory(w, "SUM::%(n)s( alphaL * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqq'})) for L in self.channels.keys()] [(roo.factory(w, "SUM::%(n)s( 0 * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttag'}), roo.factory(w, "SUM::%(n)s( 0 * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqg'}), roo.factory(w, "SUM::%(n)s( 0 * %(n)s_both, %(n)s_symm )" % {'n': L + '_ttqq'})) for L in self.channels_qcd.keys()] assert self.gen.samples['tt'].datas[0].GetXaxis().GetTitle() == genNameX assert self.gen.samples['tt'].datas[0].GetYaxis().GetTitle() == genNameY for n, d in self.gen.samples.items(): y,ey = lib.asymmetry(d.datasX[0]) p,ep = lib.asymmetry(d.datasY[0]) roo.wimport_const(w, 'Ac_y_' + n, y) roo.wimport_const(w, 'Ac_phi_' + n, p) roo.wimport_const(w, 'err_Ac_y_' + n, ey) roo.wimport_const(w, 'err_Ac_phi_' + n, ep)