Ejemplo n.º 1
0
if options.signal is None:
  signalEstimators = []
  isFastSim = False
elif options.signal == "DM":
  signalEstimators = [ MCBasedEstimate(name=s.name,    sample={channel:s for channel in allChannels}, cacheDir=setup.defaultCacheDir() ) for s in signals_TTDM ]
  isFastSim = False
elif options.signal == "T2tt":
  signalEstimators = [ MCBasedEstimate(name=s.name,    sample={channel:s for channel in allChannels}, cacheDir=setup.defaultCacheDir() ) for s in [T2tt_450_0] ]
  isFastSim = True
elif options.signal == "allT2tt":
  signalEstimators = [ MCBasedEstimate(name=s.name,    sample={channel:s for channel in allChannels}, cacheDir=setup.defaultCacheDir() ) for s in signals_T2tt ]
  isFastSim = True
else:
  raise Exception("Unknown signal estimator choice")

signalSetup = setup.sysClone(parameters={'useTriggers':False})

def wrapper(args):
        r,channel,setup = args
        res = estimate.cachedEstimate(r, channel, setup, save=True)
        return (estimate.uniqueKey(r, channel, setup), res )


for isSignal, estimators_ in [ [ True, signalEstimators ], [ False, allEstimators ] ]:
    for estimate in estimators_:
        setup_ = signalSetup if isSignal else setup
        if options.skipIfCachefileExists and estimate.cache.cacheFileLoaded:
            print "Cache file %s was loaded -> Skipping."%estimate.cache.filename
            continue
        jobs=[]
        for channel in ['MuMu' ,'EE', 'EMu']:
Ejemplo n.º 2
0
argParser.add_argument("--regions",        action='store', default='defaultRegions', nargs='?', choices=["defaultRegions","reducedRegionsA","reducedRegionsB","reducedRegionsAB","reducedRegionsNew"], help="which regions setup?")
argParser.add_argument("--signal",         action='store', default='T2tt',           nargs='?', choices=["T2tt","DM"],                                                                                 help="which signal to plot?")
argParser.add_argument("--estimateDY",     action='store', default='DY',             nargs='?', choices=["DY","DY-DD"],                                                                                help="which DY estimate?")
argParser.add_argument("--estimateTTZ",    action='store', default='TTZ',            nargs='?', choices=["TTZ","TTZ-DD","TTZ-DD-Top16009"],                                                            help="which DY estimate?")
args = argParser.parse_args()


if   args.regions == "defaultRegions":    regions = defaultRegions
elif args.regions == "reducedRegionsA":   regions = reducedRegionsA
elif args.regions == "reducedRegionsB":   regions = reducedRegionsB
elif args.regions == "reducedRegionsAB":  regions = reducedRegionsAB
elif args.regions == "reducedRegionsNew": regions = reducedRegionsNew
else: raise Exception("Unknown regions setup")

detailedEstimators = constructEstimatorList(['TTJets','other-detailed', args.estimateDY, args.estimateTTZ])
signalSetup = setup.sysClone(parameters={'useTriggers':False})

for estimator in detailedEstimators:
    estimator.style = styles.fillStyle( getattr( color, estimator.name.split('-')[0] ) )

from StopsDilepton.samples.cmgTuples_FastSimT2tt_mAODv2_25ns_postProcessed    import *
from StopsDilepton.samples.cmgTuples_FullSimTTbarDM_mAODv2_25ns_postProcessed import *
signalEstimators = [ MCBasedEstimate(name=s.name,  sample={channel:s for channel in allChannels}, cacheDir=setup.defaultCacheDir() ) for s in ([T2tt_450_0] if args.signal == "T2TT" else [TTbarDMJets_scalar_Mchi1_Mphi100])]
for estimator in signalEstimators:
    estimator.style = styles.lineStyle( getattr(color, estimator.name ), width=2 )
 
estimators = detailedEstimators + signalEstimators
for e in estimators:
    e.initCache(setup.defaultCacheDir())

Ejemplo n.º 3
0
def wrapper(s):
    c = cardFileWriter.cardFileWriter()
    c.releaseLocation = combineReleaseLocation

    cardFileName = os.path.join(limitDir, s.name + '.txt')
    if not os.path.exists(cardFileName) or overWrite:
        counter = 0
        c.reset()
        c.addUncertainty('PU', 'lnN')
        c.addUncertainty('topPt', 'lnN')
        c.addUncertainty('JEC', 'lnN')
        c.addUncertainty('JER', 'lnN')
        c.addUncertainty('SFb', 'lnN')
        c.addUncertainty('SFl', 'lnN')
        if fastSim:
            c.addUncertainty('SFFS', 'lnN')
            c.addUncertainty('leptonSF', 'lnN')

        eSignal = MCBasedEstimate(
            name=s.name,
            sample={channel: s
                    for channel in allChannels},
            cacheDir=setup.defaultCacheDir())
        for r in regions[1:]:
            for channel in ['MuMu', 'EE', 'EMu']:  # for channel in ['all']:
                niceName = ' '.join([channel, r.__str__()])
                binname = 'Bin' + str(counter)
                counter += 1
                total_exp_bkg = 0
                c.addBin(binname, [e.name for e in estimators], niceName)
                for e in estimators:
                    expected = e.cachedEstimate(r, channel, setup)
                    total_exp_bkg += expected.val
                    c.specifyExpectation(binname, e.name, expected.val)

                    if expected.val > 0:
                        c.specifyUncertainty(
                            'PU', binname, e.name,
                            1 + e.PUSystematic(r, channel, setup).val)
                        c.specifyUncertainty(
                            'JEC', binname, e.name,
                            1 + e.JECSystematic(r, channel, setup).val)
                        c.specifyUncertainty(
                            'JER', binname, e.name,
                            1 + e.JERSystematic(r, channel, setup).val)
                        c.specifyUncertainty(
                            'topPt', binname, e.name,
                            1 + e.topPtSystematic(r, channel, setup).val)
                        c.specifyUncertainty(
                            'SFb', binname, e.name,
                            1 + e.btaggingSFbSystematic(r, channel, setup).val)
                        c.specifyUncertainty(
                            'SFl', binname, e.name,
                            1 + e.btaggingSFlSystematic(r, channel, setup).val)

                        #MC bkg stat (some condition to neglect the smaller ones?)
                        uname = 'Stat_' + binname + '_' + e.name
                        c.addUncertainty(uname, 'lnN')
                        c.specifyUncertainty('Stat_' + binname + '_' + e.name,
                                             binname, e.name,
                                             1 + expected.sigma / expected.val)

                c.specifyObservation(binname, int(total_exp_bkg))

                #signal
                e = eSignal
                if fastSim:
                    signalSetup = setup.sysClone(
                        sys={'reweight': ['reweightLeptonFastSimSF']},
                        parameters={'useTriggers': False})
                else:
                    signalSetup = setup.sysClone(
                        parameters={'useTriggers': False})
                signal = e.cachedEstimate(r, channel, signalSetup)

                c.specifyExpectation(binname, 'signal', signal.val)

                if signal.val > 0:
                    c.specifyUncertainty(
                        'PU', binname, 'signal',
                        1 + e.PUSystematic(r, channel, signalSetup).val)
                    c.specifyUncertainty(
                        'JEC', binname, 'signal',
                        1 + e.JECSystematic(r, channel, signalSetup).val)
                    c.specifyUncertainty(
                        'JER', binname, 'signal',
                        1 + e.JERSystematic(r, channel, signalSetup).val)
                    c.specifyUncertainty(
                        'SFb', binname, 'signal', 1 +
                        e.btaggingSFbSystematic(r, channel, signalSetup).val)
                    c.specifyUncertainty(
                        'SFl', binname, 'signal', 1 +
                        e.btaggingSFlSystematic(r, channel, signalSetup).val)
                    if fastSim:
                        c.specifyUncertainty(
                            'leptonSF', binname, 'signal', 1 +
                            e.leptonFSSystematic(r, channel, signalSetup).val)
                        c.specifyUncertainty(
                            'SFFS', binname, 'signal',
                            1 + e.btaggingSFFSSystematic(
                                r, channel, signalSetup).val)

                    #signal MC stat added in quadrature with PDF uncertainty: 10% uncorrelated
                    uname = 'Stat_' + binname + '_signal'
                    c.addUncertainty(uname, 'lnN')
                    c.specifyUncertainty(
                        uname, binname, 'signal',
                        1 + sqrt(0.1**2 + signal.sigma / signal.val))

                if signal.val <= 0.01 and total_exp_bkg <= 0.01 or total_exp_bkg <= 0:  # or (total_exp_bkg>300 and signal.val<0.05):
                    if verbose:
                        print "Muting bin %s. Total sig: %f, total bkg: %f" % (
                            binname, signal.val, total_exp_bkg)
                    c.muted[binname] = True
                else:
                    if verbose:
                        print "NOT Muting bin %s. Total sig: %f, total bkg: %f" % (
                            binname, signal.val, total_exp_bkg)

        c.addUncertainty('Lumi', 'lnN')
        c.specifyFlatUncertainty('Lumi', 1.046)
        cardFileName = c.writeToFile(cardFileName)
    else:
        print "File %s found. Reusing." % cardFileName

    if args.signal == "DM": sConfig = s.mChi, s.mPhi, s.type
    elif args.signal == "T2tt": sConfig = s.mStop, s.mNeu

    if useCache and not overWrite and limitCache.contains(s):
        res = limitCache.get(sConfig)
    else:
        res = c.calcLimit(cardFileName)
        limitCache.add(sConfig, res, save=True)

    try:
        if res:
            if args.signal == "DM":
                sString = "mChi %i mPhi %i type %i" % sConfig
            elif args.signal == "T2tt":
                sString = "mStop %i mNeu %i" % sConfig
            print "Result: %i obs %5.3f exp %5.3f -1sigma %5.3f +1sigma %5.3f" % (
                sString, res['-1.000'], res['0.500'], res['0.160'],
                res['0.840'])
    except:
        print "Something wrong with the limit: %r" % res
    return sConfig, res
Ejemplo n.º 4
0
def wrapper(s):
    c = cardFileWriter.cardFileWriter()
    c.releaseLocation = combineReleaseLocation

    cardFileName = os.path.join(limitDir, s.name + ".txt")
    if not os.path.exists(cardFileName) or overWrite:
        counter = 0
        c.reset()
        c.addUncertainty("PU", "lnN")
        c.addUncertainty("topPt", "lnN")
        c.addUncertainty("JEC", "lnN")
        c.addUncertainty("JER", "lnN")
        c.addUncertainty("SFb", "lnN")
        c.addUncertainty("SFl", "lnN")
        if fastSim:
            c.addUncertainty("SFFS", "lnN")
            c.addUncertainty("leptonSF", "lnN")

        eSignal = MCBasedEstimate(
            name=s.name, sample={channel: s for channel in allChannels}, cacheDir=setup.defaultCacheDir()
        )
        for r in regions[1:]:
            for channel in ["MuMu", "EE", "EMu"]:  # for channel in ['all']:
                niceName = " ".join([channel, r.__str__()])
                binname = "Bin" + str(counter)
                counter += 1
                total_exp_bkg = 0
                c.addBin(binname, [e.name for e in estimators], niceName)
                for e in estimators:
                    expected = e.cachedEstimate(r, channel, setup)
                    total_exp_bkg += expected.val
                    c.specifyExpectation(binname, e.name, expected.val)

                    if expected.val > 0:
                        c.specifyUncertainty("PU", binname, e.name, 1 + e.PUSystematic(r, channel, setup).val)
                        c.specifyUncertainty("JEC", binname, e.name, 1 + e.JECSystematic(r, channel, setup).val)
                        c.specifyUncertainty("JER", binname, e.name, 1 + e.JERSystematic(r, channel, setup).val)
                        c.specifyUncertainty("topPt", binname, e.name, 1 + e.topPtSystematic(r, channel, setup).val)
                        c.specifyUncertainty("SFb", binname, e.name, 1 + e.btaggingSFbSystematic(r, channel, setup).val)
                        c.specifyUncertainty("SFl", binname, e.name, 1 + e.btaggingSFlSystematic(r, channel, setup).val)

                        # MC bkg stat (some condition to neglect the smaller ones?)
                        uname = "Stat_" + binname + "_" + e.name
                        c.addUncertainty(uname, "lnN")
                        c.specifyUncertainty(
                            "Stat_" + binname + "_" + e.name, binname, e.name, 1 + expected.sigma / expected.val
                        )

                c.specifyObservation(binname, int(total_exp_bkg))

                # signal
                e = eSignal
                if fastSim:
                    signalSetup = setup.sysClone(
                        sys={"reweight": ["reweightLeptonFastSimSF"]}, parameters={"useTriggers": False}
                    )
                else:
                    signalSetup = setup.sysClone(parameters={"useTriggers": False})
                signal = e.cachedEstimate(r, channel, signalSetup)

                c.specifyExpectation(binname, "signal", signal.val)

                if signal.val > 0:
                    c.specifyUncertainty("PU", binname, "signal", 1 + e.PUSystematic(r, channel, signalSetup).val)
                    c.specifyUncertainty("JEC", binname, "signal", 1 + e.JECSystematic(r, channel, signalSetup).val)
                    c.specifyUncertainty("JER", binname, "signal", 1 + e.JERSystematic(r, channel, signalSetup).val)
                    c.specifyUncertainty(
                        "SFb", binname, "signal", 1 + e.btaggingSFbSystematic(r, channel, signalSetup).val
                    )
                    c.specifyUncertainty(
                        "SFl", binname, "signal", 1 + e.btaggingSFlSystematic(r, channel, signalSetup).val
                    )
                    if fastSim:
                        c.specifyUncertainty(
                            "leptonSF", binname, "signal", 1 + e.leptonFSSystematic(r, channel, signalSetup).val
                        )
                        c.specifyUncertainty(
                            "SFFS", binname, "signal", 1 + e.btaggingSFFSSystematic(r, channel, signalSetup).val
                        )

                    # signal MC stat added in quadrature with PDF uncertainty: 10% uncorrelated
                    uname = "Stat_" + binname + "_signal"
                    c.addUncertainty(uname, "lnN")
                    c.specifyUncertainty(uname, binname, "signal", 1 + sqrt(0.1 ** 2 + signal.sigma / signal.val))

                if (
                    signal.val <= 0.01 and total_exp_bkg <= 0.01 or total_exp_bkg <= 0
                ):  # or (total_exp_bkg>300 and signal.val<0.05):
                    if verbose:
                        print "Muting bin %s. Total sig: %f, total bkg: %f" % (binname, signal.val, total_exp_bkg)
                    c.muted[binname] = True
                else:
                    if verbose:
                        print "NOT Muting bin %s. Total sig: %f, total bkg: %f" % (binname, signal.val, total_exp_bkg)

        c.addUncertainty("Lumi", "lnN")
        c.specifyFlatUncertainty("Lumi", 1.046)
        cardFileName = c.writeToFile(cardFileName)
    else:
        print "File %s found. Reusing." % cardFileName

    if args.signal == "DM":
        sConfig = s.mChi, s.mPhi, s.type
    elif args.signal == "T2tt":
        sConfig = s.mStop, s.mNeu

    if useCache and not overWrite and limitCache.contains(s):
        res = limitCache.get(sConfig)
    else:
        res = c.calcLimit(cardFileName)
        limitCache.add(sConfig, res, save=True)

    try:
        if res:
            if args.signal == "DM":
                sString = "mChi %i mPhi %i type %i" % sConfig
            elif args.signal == "T2tt":
                sString = "mStop %i mNeu %i" % sConfig
            print "Result: %i obs %5.3f exp %5.3f -1sigma %5.3f +1sigma %5.3f" % (
                sString,
                res["-1.000"],
                res["0.500"],
                res["0.160"],
                res["0.840"],
            )
    except:
        print "Something wrong with the limit: %r" % res
    return sConfig, res