Exemple #1
0
def extract_par_limits(pars, model_name, mass, cl=0.05):

    par_limits = {}

    mystruct = "struct Entry{ float quantileExpected; "
    for m in pars:
        mystruct += "float %s;" % m
        par_limits[m] = [0., 99999., -99999.]
    mystruct += "};"

    ROOT.gROOT.ProcessLine(mystruct)
    from ROOT import Entry
    entry = Entry()

    tin = ROOT.TFile.Open("higgsCombine%s_single.MultiDimFit.mH%s.root" %
                          (model_name, mass))
    limit = tin.Get("limit")
    limit.SetBranchAddress("quantileExpected",
                           ROOT.AddressOf(entry, "quantileExpected"))
    for p in pars:
        limit.SetBranchAddress(p, ROOT.AddressOf(entry, p))

    for i in range(limit.GetEntries()):
        limit.GetEntry(i)
        for p in pars:
            val = getattr(entry, p)
            qt = getattr(entry, "quantileExpected")
            if qt == 1.:
                par_limits[p][0] = val
            elif qt >= cl:
                par_limits[p][1] = min(val, par_limits[p][1])
                par_limits[p][2] = max(val, par_limits[p][2])
    tin.Close()

    return par_limits
Exemple #2
0
def getMass(file):
  try:
   tree = file.Get("limit")
  except:
   return -1
  br = tree.GetBranch("mh")
  c = Entry()
  br.SetAddress(ROOT.AddressOf(c,'mh'))
  tree.GetEntry(0)
  return c.mh
def getOBSERVED(file,entry=0):
  try:
   tree = file.Get("limit")
  except:
   return -1
  br = tree.GetBranch("limit")
  c = Entry()
  br.SetAddress(ROOT.AddressOf(c,'r'))
  tree.GetEntry(entry)
  return c.r
Exemple #4
0
def getENTRY(tree, entry=0):
    br = tree.GetBranch("limit")
    m = tree.GetBranch("mh")
    t = tree.GetBranch("iToy")
    c = Entry()
    br.SetAddress(ROOT.AddressOf(c, 'r'))
    m.SetAddress(ROOT.AddressOf(c, 'mh'))
    t.SetAddress(ROOT.AddressOf(c, 'iToy'))
    tree.GetEntry(entry)
    return c.r, c.mh, c.iToy
Exemple #5
0
def getOBSERVED(file, entry=0):
    try:
        tree = file.Get("limit")
        if ROOT.AddressOf(tree) == 0: return -1, -1
    except:
        return -1, -1
    br = tree.GetBranch("limit")
    m = tree.GetBranch("mh")
    c = Entry()
    br.SetAddress(ROOT.AddressOf(c, 'r'))
    m.SetAddress(ROOT.AddressOf(c, 'mh'))
    tree.GetEntry(entry)
    return c.r, c.mh
def getTreeEntry(fileName,treeName,branchName):

	try: ROOT.gROOT
	except NameError: import ROOT
	ROOT.gROOT.ProcessLine( \
	   "struct Entry{	\
    	    int r;	\
   	   };"
	)
	from ROOT import Entry
	newFile   = ROOT.TFile.Open(fileName)

	tree = newFile.Get(treeName)
	brnch= tree.GetBranch(branchName)
	valueStruct = Entry();
	brnch.SetAddress(ROOT.AddressOf(valueStruct,'r'))
	tree.GetEntry(0)
	newFile.Close()

	return int(valueStruct.r)
Exemple #7
0
def getOBSERVED(file, entry=0, ispval=False):
    try:
        tree = file.Get("limit")
        br = tree.GetBranch("limit")
        m = tree.GetBranch("mh")
        c = Entry()
        br.SetAddress(ROOT.AddressOf(c, 'r'))
        m.SetAddress(ROOT.AddressOf(c, 'mh'))
        tree.GetEntry(entry)
    except:
        return -1, -1

    r = c.r
    if ispval:
        print r,
        if r > 0:
            r = ROOT.RooStats.PValueToSignificance(r)
        else:
            r = 0.
        print r, c.mh
    return r, c.mh
Exemple #8
0
def Get_rootfile(filename):
    if ".txt" in filename or ".root" in filename:
        raise "Exception filename should have no extension"
    txt = open(filename + ".txt")

    if txt == None:
        raise "Exceptions file", filename, "does not exist"
    fROOT = ROOT.TFile(filename + ".root", "RECREATE", filename + ".root", 9)
    fROOT.cd()

    ped = Entry()
    event = Entry()

    pedTree = ROOT.TTree("ped", "pedestal taken from the file " + filename)
    pedTree.Branch(
        "Ped", ROOT.AddressOf(ped, "x"),
        "ch0/S:ch1/S:ch2/S:ch3/S:ch4/S:ch5/S:ch6/S:ch7/S:ch8/S:ch9/S:ch10/S:ch11/S"
    )

    dataTree = ROOT.TTree("data", "data taken from file " + filename)
    dataTree.Branch(
        "Events", ROOT.AddressOf(event, "x"),
        "ch0/S:ch1/S:ch2/S:ch3/S:ch4/S:ch5/S:ch6/S:ch7/S:ch8/S:ch9/S:ch10/S:ch11/S"
    )

    pedSection = True
    dataSection = False
    for line in txt:
        if "data" in line:
            pedSection = False
            dataSection = True
            continue
        parts = line.split()
        for i in range(0, 12):
            ped.x[i] = int(parts[i])
            event.x[i] = int(parts[i])
        if dataSection:
            dataTree.Fill()
        if pedSection:
            pedTree.Fill()
    dataTree.Print()
    pedTree.Print()
    txt.close()
    fROOT.Write()
    fROOT.Close()
    print "here"
def Loop(t,
         PtCuts=[0, 100, 200, 2000],
         EtaCuts=[0, 1.5],
         nBins=30,
         mass=91,
         mw=30,
         maxentries=-1,
         Extra=""):
    if DEBUG > 0:
        print "PtCuts"
        print PtCuts
        print "EtaCuts"
        print EtaCuts
    entry = Entry()
    photonIsoFPRRandomConePhoton = ROOT.std.vector(float)()
    photonPt = ROOT.std.vector(float)()
    photonEta = ROOT.std.vector(float)()
    photonPhi = ROOT.std.vector(float)()
    photonE = ROOT.std.vector(float)()
    photonid_sieie = ROOT.std.vector(float)()
    photonid_r9 = ROOT.std.vector(float)()
    photonid_hadronicOverEm = ROOT.std.vector(float)()
    photonhcalTowerSumEtConeDR03 = ROOT.std.vector(float)()
    photontrkSumPtHollowConeDR03 = ROOT.std.vector(float)()
    photonIsoFPRPhoton = ROOT.std.vector(float)()
    photonPfIsoCharged02ForCicVtx0 = ROOT.std.vector(float)()
    photonPassConversionVeto = ROOT.std.vector(float)()
    TriMatchF4Path_photon = ROOT.std.vector(int)()

    t.SetBranchAddress("isRealData", ROOT.AddressOf(entry, 'isRealData'))
    t.GetEntry(0)
    #update isRealData
    t.SetBranchAddress("photonIsoFPRRandomConePhoton",
                       ROOT.AddressOf(photonIsoFPRRandomConePhoton))
    t.SetBranchAddress("photonPt", ROOT.AddressOf(photonPt))
    t.SetBranchAddress("photonEta", ROOT.AddressOf(photonEta))
    t.SetBranchAddress("photonPhi", ROOT.AddressOf(photonPhi))
    t.SetBranchAddress("photonE", ROOT.AddressOf(photonE))
    t.SetBranchAddress("photonhcalTowerSumEtConeDR03",
                       ROOT.AddressOf(photonhcalTowerSumEtConeDR03))
    t.SetBranchAddress("photontrkSumPtHollowConeDR03",
                       ROOT.AddressOf(photontrkSumPtHollowConeDR03))
    t.SetBranchAddress("photonPfIsoCharged02ForCicVtx0",
                       ROOT.AddressOf(photonPfIsoCharged02ForCicVtx0))
    t.SetBranchAddress("photonIsoFPRPhoton",
                       ROOT.AddressOf(photonIsoFPRPhoton))
    t.SetBranchAddress("rho", ROOT.AddressOf(entry, 'rho'))
    t.SetBranchAddress("nVtx", ROOT.AddressOf(entry, 'nVtx'))
    t.SetBranchAddress("photonid_sieie", ROOT.AddressOf(photonid_sieie))
    t.SetBranchAddress("photonid_r9", ROOT.AddressOf(photonid_r9))
    t.SetBranchAddress("photonid_hadronicOverEm",
                       ROOT.AddressOf(photonid_hadronicOverEm))
    t.SetBranchAddress("photonPassConversionVeto",
                       ROOT.AddressOf(photonPassConversionVeto))
    t.SetBranchAddress("TriMatchF4Path_photon",
                       ROOT.AddressOf(TriMatchF4Path_photon))
    #electrons
    lepPt = ROOT.std.vector(float)()
    lepEta = ROOT.std.vector(float)()
    lepPhi = ROOT.std.vector(float)()
    lepE = ROOT.std.vector(float)()
    t.SetBranchAddress("lepPt", ROOT.AddressOf(lepPt))
    t.SetBranchAddress("lepEta", ROOT.AddressOf(lepEta))
    t.SetBranchAddress("lepPhi", ROOT.AddressOf(lepPhi))
    t.SetBranchAddress("lepE", ROOT.AddressOf(lepE))
    if not entry.isRealData:
        t.SetBranchAddress("PUWeight", ROOT.AddressOf(entry, 'PUWeight'))

    H = {}

    #H=ROOT.std.map(ROOT.std.pair(string,ROOT.TH2D))()
    if maxentries < 0:
        ment = t.GetEntries()
    else:
        print "Max Entries Set to " + str(maxentries)
        ment = maxentries
    for iEntry in range(0, ment):
        t.GetEntry(iEntry)
        if lepPt.size() <= 0:
            continue
            #No Electron

        electron = ROOT.TLorentzVector()
        electron.SetPtEtaPhiE(lepPt[0], lepEta[0], lepPhi[0], lepE[0])

        #G PreSelection
        #ETA
        #G
        GammaIdx = -1
        gamma = ROOT.TLorentzVector()
        for iGamma in range(0, photonPt.size()):
            gamma.SetPtEtaPhiE(photonPt[iGamma], photonEta[iGamma],
                               photonPhi[iGamma], photonE[iGamma])
            if math.fabs(gamma.Eta()) >= 1.4: continue
            ##
            if photonid_sieie[iGamma] > 0.014: continue
            if photonid_r9[iGamma] >= 0.9:
                if photonid_hadronicOverEm[iGamma] > 0.082: continue
                if photonhcalTowerSumEtConeDR03[
                        iGamma] > 50 + 0.005 * photonPt[iGamma]:
                    continue
                if photontrkSumPtHollowConeDR03[
                        iGamma] > 50 + 0.002 * photonPt[iGamma]:
                    continue
            else:
                if photonid_hadronicOverEm[iGamma] > 0.075: continue
                if photonhcalTowerSumEtConeDR03[
                        iGamma] > 4 + 0.005 * photonPt[iGamma]:
                    continue
                if photontrkSumPtHollowConeDR03[
                        iGamma] > 4 + 0.002 * photonPt[iGamma]:
                    continue

            if photonPfIsoCharged02ForCicVtx0[iGamma] > 4: continue
            if photonIsoFPRPhoton[iGamma] > 10: continue
            trigger = TriMatchF4Path_photon[iGamma]
            ## Select the right trigger
            if entry.isRealData and len(PtTriggers) > 0:
                ####
                j = -1
                for i in range(0, len(PtTriggers)):
                    if gamma.Pt() >= PtTriggers[i][0] and gamma.Pt(
                    ) < PtTriggers[i][1]:
                        j = 1
                if j < 0:
                    continue
                    #no trigger
                if TriggerMenus[j] == "HLT_Photon20_CaloIdVL_v*" and not (
                        trigger & 1):
                    continue
                elif TriggerMenus[
                        j] == "HLT_Photon20_CaloIdVL_IsoL_v*" and not (trigger
                                                                       & 2):
                    continue
                elif TriggerMenus[j] == "HLT_Photon30_v*" and not (trigger
                                                                   & 4):
                    continue
                elif TriggerMenus[j] == "HLT_Photon30_CaloIdVL_v*" and not (
                        trigger & 8):
                    continue
                elif TriggerMenus[
                        j] == "HLT_Photon30_CaloIdVL_IsoL_v*" and not (trigger
                                                                       & 16):
                    continue
                elif TriggerMenus[j] == "HLT_Photon50_CaloIdVL_v*" and not (
                        trigger & 32):
                    continue
                elif TriggerMenus[
                        j] == "HLT_Photon50_CaloIdVL_IsoL_v*" and not (trigger
                                                                       & 64):
                    continue
                elif TriggerMenus[j] == "HLT_Photon75_CaloIdVL_v*" and not (
                        trigger & 128):
                    continue
                elif TriggerMenus[
                        j] == "HLT_Photon75_CaloIdVL_IsoL_v*" and not (trigger
                                                                       & 256):
                    continue
                elif TriggerMenus[j] == "HLT_Photon90_CaloIdVL_v*" and not (
                        trigger & 512):
                    continue
                elif TriggerMenus[
                        j] == "HLT_Photon90_CaloIdVL_IsoL_v*" and not (trigger
                                                                       & 1024):
                    continue
                elif TriggerMenus[j] == "HLT_Photon135_v*" and not (trigger
                                                                    & 2048):
                    continue
                elif TriggerMenus[j] == "HLT_Photon150_v*" and not (trigger
                                                                    & 4096):
                    continue
            GammaIdx = iGamma
            break
        if GammaIdx < 0:
            isEG = True
            #NO GAMMA
        else:
            isEG = False

        # ELECTRON - GAMMA
        if isEG:
            eg = electron + gamma
            if DEBUG > 1: print "EG Mass=" + str(eg.M())
            if eg.M() < mass - mw or eg.M() > mass + mw: continue
            if DEBUG > 1: print "Mass Pass"
            p = -1
            e = -1
            for pp in range(0, len(PtCuts) - 1):
                if gamma.Pt() >= PtCuts[pp] and gamma.Pt() < PtCuts[pp + 1]:
                    p = pp
                    break
            for ee in range(0, len(EtaCuts) - 1):
                if math.fabs(gamma.Eta()) >= EtaCuts[ee] and math.fabs(
                        gamma.Eta()) < EtaCuts[ee + 1]:
                    e = ee
                    break
            if DEBUG > 1: print "Pt=" + str(gamma.Pt()) + " bin = " + str(p)
            if p < 0: continue
            if DEBUG > 1: print "Eta=" + str(gamma.Eta()) + " bin = " + str(e)
            if DEBUG > 1: print "PT Pass"
            if e < 0: continue
            if DEBUG > 1: print "Eta Pass"
            Name = Extra + "Mass_EG_" + "Pt_" + str(PtCuts[p]) + "_" + str(
                PtCuts[p + 1]) + "_Eta_" + str(EtaCuts[e]) + "_" + str(
                    EtaCuts[e + 1])
            try:
                H[Name].Integral()
            except KeyError, TypeError:
                if DEBUG > 0: print "Creating histo with Name " + Name
                H[Name] = ROOT.TH1F(Name, Name, nBins, mass - mw, mass + mw)

            if entry.isRealData:
                weight = 1
            else:
                weight = PUWeight
            H[Name].Fill(eg.M(), weight)
def Loop(t,
         nBins=100,
         xMin=40,
         xMax=120,
         PtBins=[0, 100, 150, 200, 250, 300, 400, 500, 1000],
         EtaBins=[0, 0.5, 1.0, 1.5],
         maxentries=-1):
    entry = Entry()
    photonIsoFPRRandomConePhoton = ROOT.std.vector(float)()
    photonPt = ROOT.std.vector(float)()
    photonEta = ROOT.std.vector(float)()
    photonid_sieie = ROOT.std.vector(float)()
    photonPassConversionVeto = ROOT.std.vector(float)()

    t.SetBranchAddress("isRealData", ROOT.AddressOf(entry, 'isRealData'))
    t.GetEntry(0)
    #update isRealData
    t.SetBranchAddress("photonIsoFPRRandomConePhoton",
                       ROOT.AddressOf(photonIsoFPRRandomConePhoton))
    t.SetBranchAddress("photonPt", ROOT.AddressOf(photonPt))
    t.SetBranchAddress("photonEta", ROOT.AddressOf(photonEta))
    t.SetBranchAddress("rho", ROOT.AddressOf(entry, 'rho'))
    t.SetBranchAddress("nVtx", ROOT.AddressOf(entry, 'nVtx'))
    t.SetBranchAddress("photonid_sieie", ROOT.AddressOf(photonid_sieie))
    t.SetBranchAddress("photonPassConversionVeto",
                       ROOT.AddressOf(photonPassConversionVeto))

    #H=ROOT.std.map(ROOT.std.pair(string,ROOT.TH2D))()
    H = {}
    for iPt in range(0, len(PtBins) - 1):
        for iEta in range(0, len(EtaBins) - 1):
            name = "rho_vs_nvtx" + UniqName(PtBins, iPt, EtaBins, iEta)
            if (DEBUG > 1): print "Going to create:" + name
            H[name] = ROOT.TH2D(name, name, nBins, xMin, xMax, 1000, 0, 50)
            name = "iso_vs_nvtx" + UniqName(PtBins, iPt, EtaBins, iEta)
            if (DEBUG > 1): print "Going to create:" + name
            H[name] = ROOT.TH2D(name, name, nBins, xMin, xMax, 1000, 0, 50)
    #loop
    if (DEBUG > 1):
        for name in H:
            print "HISTO " + name + " is present in the database"

    if (maxentries < 0):
        maxentries = t.GetEntries()
    else:
        print "Running on partial tree: MaxEntry=" + str(
            maxentries) + "/" + str(t.GetEntries())
    for iEntry in range(0, maxentries):
        #if(iEntry>10000):
        #	print "Exiting, too many entries"
        #	break
        t.GetEntry(iEntry)
        iPt = -1
        iEta = -1
        if (photonPt.size() < 1): continue
        GammaIdx = -1
        for iGamma in range(0, photonPt.size()):
            for i in range(0, len(PtBins) - 1):
                if (photonPt[iGamma] >= PtBins[i]
                        and photonPt[iGamma] <= PtBins[i + 1]):
                    iPt = i
            for i in range(0, len(EtaBins) - 1):
                if (abs(photonEta[iGamma]) >= EtaBins[i]
                        and abs(photonEta[iGamma]) <= EtaBins[i + 1]):
                    iEta = i
            if iPt < 0 or iEta < 0: continue
            if photonid_sieie[iGamma] > 0.011: continue
            if photonPassConversionVeto[iGamma] < 0.001: continue
            GammaIdx = iGamma
            break
        if GammaIdx < 0: continue
        name = "rho_vs_nvtx" + UniqName(PtBins, iPt, EtaBins, iEta)
        if (DEBUG > 1): print "Going to Fill:" + name
        H[name].Fill(entry.nVtx, entry.rho)
        name = "iso_vs_nvtx" + UniqName(PtBins, iPt, EtaBins, iEta)
        if (DEBUG > 1): print "Going to Fill:" + name
        H[name].Fill(entry.nVtx, photonIsoFPRRandomConePhoton[GammaIdx])
    return H