Example #1
0
def getReweightingFunction(data="PU_2100_XSecCentral", mc="Spring15"):

    # Data
    fileNameData = "$CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/%s.root" % data

    histoData = getObjFromFile(fileNameData, 'pileup')
    histoData.Scale(1./histoData.Integral())
    logger.info("Loaded 'pileup' from data file %s", fileNameData )

    # MC
    if mc=='Spring15':
        from StopsDilepton.tools.puProfiles import spring15 as mcProfile
        logger.info("Loaded Spring15 MC Profile" )
    elif mc=="Fall15":
        mcProfile = extendHistoTo(getObjFromFile("$CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/MCProfile_Fall15.root", 'MC'), histoData)
    else:
        raise ValueError( "Don't know about MC PU profile %s" %mc )

    mcProfile.Scale(1./mcProfile.Integral())

    # Create reweighting histo
    reweightingHisto = histoData.Clone( '_'.join(['reweightingHisto', data, mc]) )
    reweightingHisto.Divide(mcProfile)

    # Define reweightingFunc
    def reweightingFunc(nvtx):
        return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nvtx))

    return reweightingFunc
Example #2
0
def getReweightingFunction(data="PU_2100_XSecCentral", mc="Spring15"):

    # Data
    fileNameData = "$CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/%s.root" % data

    histoData = getObjFromFile(fileNameData, 'pileup')
    histoData.Scale(1. / histoData.Integral())
    logger.info("Loaded 'pileup' from data file %s", fileNameData)

    # MC
    if mc == 'Spring15':
        from StopsDilepton.tools.puProfiles import spring15 as mcProfile
        logger.info("Loaded Spring15 MC Profile")
    elif mc == "Fall15":
        mcProfile = extendHistoTo(
            getObjFromFile(
                "$CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/MCProfile_Fall15.root",
                'MC'), histoData)
    else:
        raise ValueError("Don't know about MC PU profile %s" % mc)

    mcProfile.Scale(1. / mcProfile.Integral())

    # Create reweighting histo
    reweightingHisto = histoData.Clone('_'.join(['reweightingHisto', data,
                                                 mc]))
    reweightingHisto.Divide(mcProfile)

    # Define reweightingFunc
    def reweightingFunc(nvtx):
        return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nvtx))

    return reweightingFunc
Example #3
0
    def __init__(self):
        self.dataDir = "$CMSSW_BASE/src/StopsDilepton/tools/data/leptonFastSimSFData"
        muFileName = os.path.join(self.dataDir, muSFFile+'.root')
        eleFileName = os.path.join(self.dataDir, eleSFFile+'.root')

        self.mu3D = getObjFromFile(os.path.expandvars(muFileName), "histo3D")
        assert self.mu3D, "Could not load 'histo3D' from %s"%os.path.expandvars(muFileName)
        self.ele3D = getObjFromFile(os.path.expandvars(eleFileName), "histo3D")
        assert self.ele3D, "Could not load 'histo3D' from %s"%os.path.expandvars(eleFileName)
        print "Loaded lepton SF file for muons:     %s"%muFileName
        print "Loaded lepton SF file for electrons: %s"%eleFileName
Example #4
0
    def __init__(self):
        self.dataDir = "$CMSSW_BASE/src/StopsDilepton/tools/data/leptonFastSimSFData"
        muFileName = os.path.join(self.dataDir, muSFFile + '.root')
        eleFileName = os.path.join(self.dataDir, eleSFFile + '.root')

        self.mu3D = getObjFromFile(os.path.expandvars(muFileName), "histo3D")
        assert self.mu3D, "Could not load 'histo3D' from %s" % os.path.expandvars(
            muFileName)
        self.ele3D = getObjFromFile(os.path.expandvars(eleFileName), "histo3D")
        assert self.ele3D, "Could not load 'histo3D' from %s" % os.path.expandvars(
            eleFileName)
        print "Loaded lepton SF file for muons:     %s" % muFileName
        print "Loaded lepton SF file for electrons: %s" % eleFileName
def getReweightingFunction(era="Run2015D_205pb", histoTitle="nVtxReweight"):
  fileName = "$CMSSW_BASE/src/StopsDilepton/tools/python/puReweightingData/"+era+'.root'
  reweightingHisto = getObjFromFile(fileName, histoTitle)
  print "Loaded %s from file %s"%(histoTitle, fileName)
  def reweightingFunc(nvtx):
    return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nvtx))

  return reweightingFunc
def getReweightingFunction(era="Run2015D_205pb", histoTitle="nVtxReweight"):
    fileName = "$CMSSW_BASE/src/StopsDilepton/tools/python/puReweightingData/" + era + '.root'
    reweightingHisto = getObjFromFile(fileName, histoTitle)
    print "Loaded %s from file %s" % (histoTitle, fileName)

    def reweightingFunc(nvtx):
        return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nvtx))

    return reweightingFunc
Example #7
0
def getReweightingFunction(data="PU_2100_XSecCentral", mc="Spring15"):
  fileNameData = "$CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/"+data+'.root'
  histoData = getObjFromFile(fileNameData, 'pileup')
  histoData.Scale(1./histoData.Integral())
  print "[puReweighting] Loaded 'pileup' from data file %s"%(fileNameData)
  if mc=='Spring15':
    from StopsDilepton.tools.spring15MCPUProfile import mcProfile
    mcProfile.Scale(1./mcProfile.Integral()) 
    print "[puReweighting] Loaded mcProfile from $CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/spring15MCProfile.py"
  reweightingHisto = histoData.Clone('_'.join(['reweightingHisto', data, mc])) 
  reweightingHisto.Divide(mcProfile) 
  def reweightingFunc(nvtx):
    return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nvtx))

  return reweightingFunc
Example #8
0
def getReweightingFunction(data="PU_2100_XSecCentral", mc="Spring15"):
    fileNameData = "$CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/" + data + '.root'
    histoData = getObjFromFile(fileNameData, 'pileup')
    histoData.Scale(1. / histoData.Integral())
    print "[puReweighting] Loaded 'pileup' from data file %s" % (fileNameData)
    if mc == 'Spring15':
        from StopsDilepton.tools.spring15MCPUProfile import mcProfile
        mcProfile.Scale(1. / mcProfile.Integral())
        print "[puReweighting] Loaded mcProfile from $CMSSW_BASE/src/StopsDilepton/tools/data/puReweightingData/spring15MCProfile.py"
    reweightingHisto = histoData.Clone('_'.join(['reweightingHisto', data,
                                                 mc]))
    reweightingHisto.Divide(mcProfile)

    def reweightingFunc(nvtx):
        return reweightingHisto.GetBinContent(reweightingHisto.FindBin(nvtx))

    return reweightingFunc
Example #9
0
from StopsDilepton.analysis.run.limitHelpers import getContours, cleanContour

defFile="/afs/hephy.at/data/rschoefbeck01/StopsDilepton/results/test5/isOS-nJets2p-nbtag1p-met80-metSig5-dPhiJet0-dPhiJet-mll20/limits/flavSplit_almostAllReg/T2tt_limitResults.root"

from optparse import OptionParser
parser = OptionParser()
parser.add_option("--file", dest="filename", default=defFile, type="string", action="store", help="Which file?")
(options, args) = parser.parse_args()

#ofilename = '/afs/hephy.at/user/r/rschoefbeck/www/etc/T2tt_flavSplit_almostAllReg_'+limitPosFix+'_'
ifs = options.filename.split('/')
ofilename = os.path.join(plotDir, 'T2tt', ifs[-4], ifs[-2], 'T2tt_limit')
if not os.path.exists(os.path.dirname(ofilename)):
    os.makedirs(os.path.dirname(ofilename))

T2tt_exp        = getObjFromFile(options.filename, "T2tt_exp")
T2tt_exp_up     = getObjFromFile(options.filename, "T2tt_exp_up")
T2tt_exp_down   = getObjFromFile(options.filename, "T2tt_exp_down")

T2tt_obs        = getObjFromFile(options.filename, "T2tt_exp").Clone('T2tt_obs') #FIXME!!! This is just for now...
T2tt_obs_UL     = T2tt_obs.Clone("T2tt_obs_UL")
#theory uncertainty on observed limit
T2tt_obs_up   = T2tt_obs.Clone("T2tt_obs_up")
T2tt_obs_down = T2tt_obs.Clone("T2tt_obs_down")
T2tt_obs_up  .Reset()
T2tt_obs_down.Reset()
from StopsDilepton.tools.xSecSusy import xSecSusy
xSecSusy_ = xSecSusy()
for ix in range(T2tt_obs.GetNbinsX()):
    for iy in range(T2tt_obs.GetNbinsY()):
        mStop = T2tt_obs.GetXaxis().GetBinLowEdge(ix)
                  type="string",
                  action="store",
                  help="Output file")
(options, args) = parser.parse_args()

ofilename = os.path.join(plotDir, options.outfile)
if not os.path.exists(os.path.dirname(ofilename)):
    os.makedirs(os.path.dirname(ofilename))

files = options.filenames.split(',')
print files
assert len(files) == 2, "Need two files"

T2tt_exp = {}
for i, f in enumerate(files):
    T2tt_exp[i] = getObjFromFile(f, "T2tt_exp")

ROOT.gStyle.SetPadRightMargin(0.15)
niceColorPalette(255)

T2tt_exp[0].Divide(T2tt_exp[1])

c1 = ROOT.TCanvas()
T2tt_exp[0].SetMarkerSize(0.4)
T2tt_exp[0].GetXaxis().SetTitle("m_{#tilde{t}_{1}} (GeV)")
T2tt_exp[0].GetYaxis().SetTitle("m_{#tilde{#chi}_{1}^{0}} (GeV)")

T2tt_exp[0].Draw('text45')
T2tt_exp[0].Draw('COLZ')
c1.Update()
c1.Print(ofilename)
Example #11
0
for ofilename in ofilenames:
    if not os.path.exists(os.path.dirname(ofilename)):
        os.makedirs(os.path.dirname(ofilename))

files = []
legendNames={}
for f in options.filenames.split(','):
    if ":" in f:
        n,f=f.split(":")
        files.append(f)
        legendNames[f]=n

contours = {}
for i, f in enumerate(files):
    T2tt_exp        = getObjFromFile(f, "T2tt_exp")
    T2tt_exp_int = interpolate(T2tt_exp)
    T2tt_exp_smooth = T2tt_exp_int.Clone("T2tt_exp_smooth")
    T2tt_exp_smooth.Smooth()
    T2tt_exp_smooth.SetName("T2tt_exp_smooth")
    contours_exp      = getContours(T2tt_exp_smooth)
    contour_exp      = max(contours_exp     , key=lambda x:x.GetN()).Clone("contour_exp") if contours_exp else None
    if not contour_exp: continue
    cleanContour(contour_exp)
    contours[f]=contour_exp
    contours[f].SetLineColor(ROOT_colors[i])
    contours[f].SetFillColor(0)
    contours[f].SetMarkerStyle(0)
    contours[f].SetMarkerColor(ROOT_colors[i])

Example #12
0
from StopsDilepton.analysis.run.limitHelpers import getContours, cleanContour

defFile= os.path.join(analysis_results, "isOS-nJets2p-nbtag1p-met80-metSig5-dPhiJet0-dPhiJet-mll20/limits/defaultRegions/T2tt_limitResults.root")

from optparse import OptionParser
parser = OptionParser()
parser.add_option("--file", dest="filename", default=defFile, type="string", action="store", help="Which file?")
(options, args) = parser.parse_args()

#ofilename = '/afs/hephy.at/user/r/rschoefbeck/www/etc/T2tt_flavSplit_almostAllReg_'+limitPosFix+'_'
ifs = options.filename.split('/')
ofilename = os.path.join(plot_directory, 'T2tt', ifs[-4], ifs[-2], 'T2tt_limit')
if not os.path.exists(os.path.dirname(ofilename)):
    os.makedirs(os.path.dirname(ofilename))

T2tt_exp        = getObjFromFile(options.filename, "T2tt_exp")
T2tt_exp_up     = getObjFromFile(options.filename, "T2tt_exp_up")
T2tt_exp_down   = getObjFromFile(options.filename, "T2tt_exp_down")
#T2tt_obs        = getObjFromFile(options.filename, "T2tt_exp").Clone("T2tt_obs")
T2tt_obs        = getObjFromFile(options.filename, "T2tt_exp")
T2tt_obs_UL     = T2tt_obs.Clone("T2tt_obs_UL")
#theory uncertainty on observed limit
T2tt_obs_up     = T2tt_obs.Clone("T2tt_obs_up")
T2tt_obs_down   = T2tt_obs.Clone("T2tt_obs_down")
T2tt_obs_up  .Reset()
T2tt_obs_down.Reset()

from StopsDilepton.tools.xSecSusy import xSecSusy
xSecSusy_ = xSecSusy()
for ix in range(T2tt_obs.GetNbinsX()):
    for iy in range(T2tt_obs.GetNbinsY()):
Example #13
0
parser = OptionParser()
parser.add_option("--files", dest="filenames", default="", type="string", action="store", help="Which files?")
parser.add_option("--outfile", dest="outfile", default="", type="string", action="store", help="Output file")
(options, args) = parser.parse_args()

ofilename = os.path.join(plotDir, options.outfile)
if not os.path.exists(os.path.dirname(ofilename)):
    os.makedirs(os.path.dirname(ofilename))

files=options.filenames.split(',')
print files
assert len(files)==2, "Need two files"

T2tt_exp = {}
for i, f in enumerate(files):
    T2tt_exp[i]= getObjFromFile(f, "T2tt_exp")

ROOT.gStyle.SetPadRightMargin(0.15)
niceColorPalette(255)

T2tt_exp[0].Divide(T2tt_exp[1])

c1 = ROOT.TCanvas()
T2tt_exp[0].SetMarkerSize(0.4)
T2tt_exp[0].GetXaxis().SetTitle("m_{#tilde{t}_{1}} (GeV)")
T2tt_exp[0].GetYaxis().SetTitle("m_{#tilde{#chi}_{1}^{0}} (GeV)")

T2tt_exp[0].Draw('text45')
T2tt_exp[0].Draw('COLZ')
c1.Update()
c1.Print(ofilename)
from StopsDilepton.tools.objectSelection import getLeptons, looseMuID, looseEleID, getJets
from StopsDilepton.tools.mt2Calculator import mt2Calculator

mt2Calc = mt2Calculator()
from StopsDilepton.tools.user import *

# preselection = 'met_pt>40&&Sum$((Jet_pt)*(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id))>100&&Sum$(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id&&Jet_btagCSV>0.814)==2&&Sum$(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id)>=2&&Sum$(LepGood_pt>20)>=2'
preselection = "isOS&&abs(dl_mass-91.2)<=15.&&isMuMu==1&&nGoodMuons==2&&nGoodElectrons==0"
dataCut = (
    "(HLT_mumuIso&&Flag_HBHENoiseFilter&&Flag_goodVertices&&Flag_CSCTightHaloFilter&&Flag_eeBadScFilter)&&weight>0"
)
prefix = "doubleMu_onZ_isOS_1500pb"

pileup_data = getObjFromFile(
    os.path.expandvars(
        "$CMSSW_BASE/src/StopsDilepton/tools/python/puReweightingData/officialDataPileuphistogram_DoubleMuon_1500.root"
    ),
    "pileup",
)

# load all the samples
from StopsDilepton.samples.cmgTuples_Spring15_mAODv2_25ns_1l_postProcessed import *

backgrounds = [DY, TTJets_Lep, TTX, diBoson, singleTop, singleTop, WJetsToLNu, QCD_Mu5]
# backgrounds = [TTJets_25ns, DY_25ns, singleTop_25ns, diBoson_25ns, WJetsHTToLNu_25ns]#, QCD]
for b in backgrounds:
    b["isData"] = False

# get the TChains for each sample
for s in backgrounds:
    s["chain"] = getChain(s, histname="")
Example #15
0
del c1

for i in range(len(bins)):
    central.SetBinError(i + 1, 0)
    pdf.SetBinError(i + 1,
                    pdf.GetBinError(i + 1) / central.GetBinContent(i + 1))
    q2.SetBinError(i + 1, q2.GetBinError(i + 1) / central.GetBinContent(i + 1))
    pdf.SetBinContent(i + 1, 1)
    q2.SetBinContent(i + 1, 1)

unc = {}
for k in [
        "center", "jesUp", "jesDown", "jer", "jerUp", "jerDown", "btag_bq",
        "btag_bqUp", "btag_bqDown", "btag_lq", "btag_lqUp", "btag_lqDown"
]:
    unc[k] = getObjFromFile("systematics_updated.root", k)

jes = unc['jesUp'].Clone("unc_jes")
unc['jesDown'].Scale(-1)
jes.Add(unc['jesDown'])
jes.Divide(unc['center'])

jer = unc['center'].Clone("unc_jer")
jer.Scale(-1)
jer.Add(unc['jer'])
jer.Divide(unc['center'])

btag_bq = unc['btag_bqUp'].Clone("unc_btag_bq")
unc['btag_bqDown'].Scale(-1)
btag_bq.Add(unc['btag_bqDown'])
btag_bq.Divide(unc['btag_bq'])
Example #16
0
import os
from StopsDilepton.tools.helpers import getChain, getObjFromFile, getObjDict, getEList, getVarValue, getPlotFromChain
from StopsDilepton.tools.objectSelection import getLeptons, looseMuID, looseEleID, getJets
from StopsDilepton.tools.mt2Calculator import mt2Calculator

mt2Calc = mt2Calculator()
from StopsDilepton.tools.localInfo import *

#preselection = 'met_pt>40&&Sum$((Jet_pt)*(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id))>100&&Sum$(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id&&Jet_btagCSV>0.814)==2&&Sum$(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id)>=2&&Sum$(LepGood_pt>20)>=2'
preselection = 'isOS&&abs(dl_mass-91.2)<=15.&&isMuMu==1&&nGoodMuons==2&&nGoodElectrons==0'
dataCut = "(HLT_mumuIso&&Flag_HBHENoiseFilter&&Flag_goodVertices&&Flag_CSCTightHaloFilter&&Flag_eeBadScFilter)&&weight>0"
prefix = "doubleMu_onZ_isOS_1500pb"

pileup_data = getObjFromFile(
    os.path.expandvars(
        "$CMSSW_BASE/src/StopsDilepton/tools/python/puReweightingData/officialDataPileuphistogram_DoubleMuon_1500.root"
    ), "pileup")

#load all the samples
from StopsDilepton.samples.cmgTuples_Spring15_mAODv2_25ns_1l_postProcessed import *

backgrounds = [
    DY, TTJets_Lep, TTX, diBoson, singleTop, singleTop, WJetsToLNu, QCD_Mu5
]
#backgrounds = [TTJets_25ns, DY_25ns, singleTop_25ns, diBoson_25ns, WJetsHTToLNu_25ns]#, QCD]
for b in backgrounds:
    b['isData'] = False

#get the TChains for each sample
for s in backgrounds:
    s['chain'] = getChain(s, histname="")
Example #17
0
l.Draw()
c1.Print("/afs/hephy.at/user/r/rschoefbeck/www/etc/TTZ"+postfix+".png")
c1.Print("/afs/hephy.at/user/r/rschoefbeck/www/etc/TTZ"+postfix+".pdf")
c1.Print("/afs/hephy.at/user/r/rschoefbeck/www/etc/TTZ"+postfix+".root")
del c1

for i in range(len(bins)):
    central.SetBinError(i+1, 0)
    pdf.SetBinError(i+1,pdf.GetBinError(i+1)/central.GetBinContent(i+1))
    q2.SetBinError(i+1,q2.GetBinError(i+1)/central.GetBinContent(i+1))
    pdf.SetBinContent(i+1,1)
    q2.SetBinContent(i+1,1)

unc={}
for k  in ["center", "jesUp", "jesDown", "jer", "jerUp", "jerDown", "btag_bq", "btag_bqUp", "btag_bqDown", "btag_lq", "btag_lqUp", "btag_lqDown"]:
    unc[k] = getObjFromFile("systematics_updated.root", k)

jes = unc['jesUp'].Clone("unc_jes")
unc['jesDown'].Scale(-1)
jes.Add(unc['jesDown'])
jes.Divide(unc['center'])

jer = unc['center'].Clone("unc_jer")
jer.Scale(-1)
jer.Add(unc['jer'])
jer.Divide(unc['center'])

btag_bq = unc['btag_bqUp'].Clone("unc_btag_bq")
unc['btag_bqDown'].Scale(-1)
btag_bq.Add(unc['btag_bqDown'])
btag_bq.Divide(unc['btag_bq'])