示例#1
0
def getTree(myTree, oldTree, listOfBranches, additionalBranches=[]):

    rando = random.randint(1, 999999)
    # first structure
    stringMyStruct1 = "struct MyStruct1{"
    for branch in listOfBranches:
        if oldTree.GetBranchStatus(branch.GetName()):
            stringMyStruct1 += "float %s;" % (branch.GetName())
    for branchName in additionalBranches:
        stringMyStruct1 += "float %s;" % (branchName)
    stringMyStruct1 += "};"
    tempMacro = open("tempMacro_%d.C" % rando, "w")
    tempMacro.write(stringMyStruct1 + "};}")
    tempMacro.close()
    rt.gROOT.ProcessLine(stringMyStruct1)
    from ROOT import MyStruct1

    # fills the bins list and associate the bins to the corresponding variables in the structure
    s1 = MyStruct1()
    for branch in listOfBranches:
        if oldTree.GetBranchStatus(branch.GetName()):
            #print(branch.GetName(), branch.GetClassName())
            myTree.Branch(branch.GetName(), rt.AddressOf(s1, branch.GetName()),
                          '%s/F' % branch.GetName())
    for branchName in additionalBranches:
        myTree.Branch(branchName, rt.AddressOf(s1, branchName),
                      '%s/F' % branchName)

    os.system("rm tempMacro_%d.C" % rando)
    return s1
示例#2
0
def getTree(myTree, paramNames, nBins, box, z):

    rando = random.randint(1, 999999)
    # first structure
    stringMyStruct1 = "void tempMacro_%d(){struct MyStruct1{" % (rando)

    stringMyStruct1 = stringMyStruct1 + "int toy_num; int migrad_sf; int migrad_ff; int hesse_sf; int hesse_ff; int covQual_sf; int covQual_ff;"

    for paramName in paramNames:
        stringMyStruct1 = stringMyStruct1 + 'float %s_ff; float %s_ff_error; float %s_sf; float %s_sf_error;' % (
            paramName, paramName, paramName, paramName)
    for iBinX in range(0, nBins):
        stringMyStruct1 = stringMyStruct1 + "float b%i_sf;" % (iBinX)
    for iBinX in range(0, nBins):
        stringMyStruct1 = stringMyStruct1 + "float b%i_ff;" % (iBinX)
    for iBinX in range(0, nBins):
        stringMyStruct1 = stringMyStruct1 + "float b%i_toy;" % (iBinX)
    tempMacro = open("tempMacro_%d.C" % rando, "w")
    tempMacro.write(stringMyStruct1 + "};}")
    tempMacro.close()
    rt.gROOT.Macro("tempMacro_%d.C" % rando)
    #rt.gROOT.ProcessLine(".x tempMacro_%d.C"%rando)
    #rt.gROOT.ProcessLine(stringMyStruct1+"};")
    from ROOT import MyStruct1

    # fills the bins list and associate the bins to the corresponding variables in the structure
    s1 = MyStruct1()
    myTree.Branch("toy_num", rt.AddressOf(s1, "toy_num"), 'toy_num/I')
    myTree.Branch("migrad_sf", rt.AddressOf(s1, "migrad_sf"), 'migrad_sf/I')
    myTree.Branch("migrad_ff", rt.AddressOf(s1, "migrad_ff"), 'migrad_ff/I')
    myTree.Branch("hesse_sf", rt.AddressOf(s1, "hesse_sf"), 'hesse_sf/I')
    myTree.Branch("hesse_ff", rt.AddressOf(s1, "hesse_ff"), 'hesse_ff/I')
    myTree.Branch("covQual_sf", rt.AddressOf(s1, "covQual_sf"), 'covQual_sf/I')
    myTree.Branch("covQual_ff", rt.AddressOf(s1, "covQual_ff"), 'covQual_ff/I')

    for paramName in paramNames:
        myTree.Branch('%s_ff' % paramName,
                      rt.AddressOf(s1,
                                   '%s_ff' % paramName), '%s_ff/F' % paramName)
        myTree.Branch('%s_ff_error' % paramName,
                      rt.AddressOf(s1, '%s_ff_error' % paramName),
                      '%s_ff_error/F' % paramName)
        myTree.Branch('%s_sf' % paramName,
                      rt.AddressOf(s1,
                                   '%s_sf' % paramName), '%s_sf/F' % paramName)
        myTree.Branch('%s_sf_error' % paramName,
                      rt.AddressOf(s1, '%s_sf_error' % paramName),
                      '%s_sf_error/F' % paramName)

    for ix in range(0, nBins):
        myTree.Branch("b%i_sf" % (ix), rt.AddressOf(s1, "b%i_sf" % (ix)),
                      'b%i_sf/F' % ix)
        myTree.Branch("b%i_ff" % (ix), rt.AddressOf(s1, "b%i_ff" % (ix)),
                      'b%i_ff/F' % ix)
        myTree.Branch("b%i_toy" % (ix), rt.AddressOf(s1, "b%i_toy" % (ix)),
                      'b%i_toy/F' % ix)

    os.system("rm tempMacro_%d.C" % rando)
    return s1
示例#3
0
def getTree(myTree, paramNames, nBins, box, z):

    rando = random.randint(1, 999999)
    # first structure
    stringMyStruct1 = "void tempMacro_%d(){struct MyStruct1{" % (rando)
    stringMyStruct1 += "float toy_num; float nll_%s; float n2llr_%s; float chi2_%s;" % (
        box, box, box)
    for k in range(1, len(z)):
        ibtag = z[k - 1]
        stringMyStruct1 += "float nll_%ibtag_%s; float n2llr_%ibtag_%s; float chi2_%ibtag_%s;" % (
            ibtag, box, ibtag, box, ibtag, box)
    stringMyStruct1 += "int covQual_%s; int migrad_%s; int hesse_%s; int minos_%s;" % (
        box, box, box, box)
    for paramName in paramNames:
        stringMyStruct1 = stringMyStruct1 + "float %s; float %s_error;" % (
            paramName, paramName)
        if paramName == 'r':
            stringMyStruct1 = stringMyStruct1 + "float r_errorlo; float r_errorhi;"
    for iBinX in range(0, nBins):
        stringMyStruct1 = stringMyStruct1 + "float b%i;" % (iBinX)
    tempMacro = open("tempMacro_%d.C" % rando, "w")
    tempMacro.write(stringMyStruct1 + "};}")
    tempMacro.close()
    rt.gROOT.Macro("tempMacro_%d.C" % rando)
    #rt.gROOT.ProcessLine(".x tempMacro_%d.C"%rando)
    #rt.gROOT.ProcessLine(stringMyStruct1+"};")
    from ROOT import MyStruct1

    # fills the bins list and associate the bins to the corresponding variables in the structure
    s1 = MyStruct1()
    myTree.Branch('toy_num', rt.AddressOf(s1, 'toy_num'), 'toy_num/F')
    myTree.Branch('nll_%s' % box, rt.AddressOf(s1, 'nll_%s' % box),
                  'nll_%s/F' % box)
    myTree.Branch('n2llr_%s' % box, rt.AddressOf(s1, 'n2llr_%s' % box),
                  'n2llr_%s/F' % box)
    myTree.Branch('chi2_%s' % box, rt.AddressOf(s1, 'chi2_%s' % box),
                  'chi2_%s/F' % box)
    for k in range(1, len(z)):
        ibtag = z[k - 1]
        myTree.Branch('nll_%ibtag_%s' % (ibtag, box),
                      rt.AddressOf(s1, 'nll_%ibtag_%s' % (ibtag, box)),
                      'nll_%ibtag_%s/F' % (ibtag, box))
        myTree.Branch('n2llr_%ibtag_%s' % (ibtag, box),
                      rt.AddressOf(s1, 'n2llr_%ibtag_%s' % (ibtag, box)),
                      'n2llr_%ibtag_%s/F' % (ibtag, box))
        myTree.Branch('chi2_%ibtag_%s' % (ibtag, box),
                      rt.AddressOf(s1, 'chi2_%ibtag_%s' % (ibtag, box)),
                      'chi2_%ibtag_%s/F' % (ibtag, box))
    myTree.Branch('covQual_%s' % box, rt.AddressOf(s1, 'covQual_%s' % box),
                  'covQual_%s/I' % box)
    myTree.Branch('migrad_%s' % box, rt.AddressOf(s1, 'migrad_%s' % box),
                  'migrad_%s/I' % box)
    myTree.Branch('hesse_%s' % box, rt.AddressOf(s1, 'hesse_%s' % box),
                  'hesse_%s/I' % box)
    myTree.Branch('minos_%s' % box, rt.AddressOf(s1, 'minos_%s' % box),
                  'minos_%s/I' % box)
    for paramName in paramNames:
        myTree.Branch(paramName, rt.AddressOf(s1, paramName),
                      '%s/F' % paramName)
        myTree.Branch('%s_error' % paramName,
                      rt.AddressOf(s1, '%s_error' % paramName),
                      '%s_error/F' % paramName)
        if paramName == 'r':
            myTree.Branch('r_errorlo', rt.AddressOf(s1, 'r_errorlo'),
                          'r_errorlo/F')
            myTree.Branch('r_errorhi', rt.AddressOf(s1, 'r_errorhi'),
                          'r_errorhi/F')
    for ix in range(0, nBins):
        myTree.Branch("b%i" % (ix), rt.AddressOf(s1, "b%i" % (ix)),
                      'b%i/F' % ix)

    os.system("rm tempMacro_%d.C" % rando)
    return s1