예제 #1
0
파일: fit1.py 프로젝트: youmehsid/root
#
# The function "ls()" lists the directory contents of this file
#
fill.ls()

#
# Get object "sqroot" from the file.
#

sqroot = gROOT.FindObject('sqroot')
sqroot.Print()

#
# Now fit histogram h1f with the function sqroot
#
h1f = gROOT.FindObject('h1f')
h1f.SetFillColor(45)
h1f.Fit('sqroot')

# We now annotate the picture by creating a PaveText object
# and displaying the list of commands in this macro
#
fitlabel = TPaveText(0.6, 0.3, 0.9, 0.80, 'NDC')
fitlabel.SetTextAlign(12)
fitlabel.SetFillColor(42)
fitlabel.ReadFile(path.join(gROOT.GetTutorialsDir(), 'pyroot', 'fit1_py.py'))
fitlabel.Draw()
c1.Update()
gBenchmark.Show('fit1')
예제 #2
0
ntbasket.AddText('fLast: pointer to last used byte in Basket')
ntbasket.Draw()
ldot.DrawLine(.4, .3, 0.02, 0.25)
ldot.DrawLine(.5, .25, 0.35, -.07)
ldot.DrawLine(.5, .3, 0.35, 0.25)
ntbranch = TPaveText(0.02, 0.40, 0.18, 0.68)
ntbranch.SetFillColor(branchcolor)
ntbranch.SetTextSize(0.015)
ntbranch.SetTextAlign(12)
ntbranch.AddText('fBasketSize')
ntbranch.AddText('fEventOffsetLen')
ntbranch.AddText('fMaxBaskets')
ntbranch.AddText('fEntries')
ntbranch.AddText('fAddress of Leaf0')
ntbranch.AddText(' ')
ntbranch.AddLine(0, 0, 0, 0)
ntbranch.AddText('fName: Branchname')
ntbranch.AddText('fTitle: leaflist')
ntbranch.Draw()
ldot.DrawLine(.2, .97, .02, .68)
ldot.DrawLine(.35, .97, .18, .68)
ldot.DrawLine(.35, .87, .18, .40)
basketstore = TPavesText(.8, -0.088, 0.952, -0.0035, 7, 'tr')
basketstore.SetFillColor(28)
basketstore.AddText('Baskets')
basketstore.AddText('Stores')
basketstore.Draw()
c1.Update()

gBenchmark.Show('tree')
예제 #3
0
    if TH2D_profileX == 1:
        twoD_profile_pol_save = "root -l -q /Users/leejunho/Desktop/git/python3Env/group_study/fruit_team/ROOT/Project/functions/2Dplots_Saver/TwoD_profileX_pol_fitter.C\(" + "'" + '"' + HistROOT_PATH_2D + '"' + "'" + "\)"
        os.system(twoD_profile_pol_save)
        #        os.system("rm -rf ROOT_2D_profileX_pols")
        os.system("mkdir ROOT_2D_profileX_pols")
        os.system("mv *profileX_pol_2D.pdf ROOT_2D_profileX_pols")

#os.system("mkdir ROOT_files")
#os.system("mv *.root ROOT_files")

if PYTHON_HIST != 1:
    #    os.system("rm -rf ROOT_files")
    os.system("mkdir ROOT_files")
    os.system("mv *.root ROOT_files")
    gBenchmark.Show("All in One")

elif (PYTHON_HIST == 1) & (TH1D_transfer == 1):
    sys.path.append(
        "/Users/leejunho/Desktop/git/python3Env/group_study/fruit_team/ROOT/Project/functions/rootHist_TXT/func"
    )
    from D1H_rootHist_TXT_conversion import D1H_roothist_to_txt
    from D1H_rootHist_TXT_conversion_largeBin import D1H_roothist_to_txt_largeBin
    TXT_FILE_LIST = D1H_roothist_to_txt(HistROOT_PATH, "")
    TXT_FILE_LIST_largeBin = D1H_roothist_to_txt_largeBin(
        HistROOT_PATH_largeBin, "")

    sys.path.append(
        "/Users/leejunho/Desktop/git/python3Env/group_study/project_pre/func")
    from c1_basic_statistic import *
    from c2_basic_histo_plotting_ROOT import Basic_histo
예제 #4
0
from ROOT import gROOT, gBenchmark

c1 = TCanvas("c1","c1",200,10,700,500)
c1.SetGrid()
c1.GetFrame().SetFillColor(21)
c1.GetFrame().SetBorderMode(-1)
c1.GetFrame().SetBorderSize(5)

gBenchmark.Start("fit1")

fill = TFile("py-fillrandom.root","READ")
fill.ls()

sqroot = gROOT.FindObject("sqroot")
sqroot.Print(); print("\n")

hist = gROOT.FindObject("h1f")
hist.Print(); print("\n"); hist.Draw()
hist.SetFillColor(45)
hist.Fit("sqroot")
c1.Update()





fill.Close()
gBenchmark.Show("fit1")


def main():

    INPUT_FILE_INCLUDING_PATH = "../../../root_generator/tree/root2_tree.root"

    FileNameList = read_file_name(INPUT_FILE_INCLUDING_PATH)
    BranchListAll = get_branch_list_all(FileNameList[2])
    BranchListEachTree = get_branch_list_each_tree(FileNameList[2])

    DicNumpyArray_branch = {}
    for numpyarray in BranchListAll:
        a = numpy.array([0], 'd')
        DicNumpyArray_branch[numpyarray] = a
    DicNumpyArray_branch = collections.OrderedDict(
        sorted(DicNumpyArray_branch.items())
    )  #  !!!the input times are ordered!!!
    print(DicNumpyArray_branch)

    DicNumpyArray_branch_w = {}
    for numpyarray_w in BranchListAll:
        a_w = numpy.array([0], 'd')
        DicNumpyArray_branch_w[numpyarray_w] = a_w
    DicNumpyArray_branch_w = collections.OrderedDict(
        sorted(DicNumpyArray_branch_w.items()))
    print(DicNumpyArray_branch_w)

    WCuts = WhetherAddCut(BranchListEachTree)
    if (WCuts == None):
        print("\n")
        print(
            "*********************************************************************************************"
        )
        print("!!!! Please check input CUT !!!!! ")
        print("     !!!! No Output File !!!!    ")
        print("\n")
        for i in range(len(BranchListEachTree)):
            print("compenets below :")
            print("The Tree name is : ", BranchListEachTree.keys()[i])
            for j in range(len(BranchListEachTree.values()[i])):
                print("        it contains : ",
                      BranchListEachTree.values()[i][j])
            print("\n")
        print("!!!! Please check input CUT !!!!! ")
        print("     !!!! No Output File !!!!    ")
        print(
            "*********************************************************************************************"
        )
    else:
        print("\n")
        print("...Cut added and regenerating tree root file...")
        gBenchmark.Start("Regerating tree root")

        f = TFile(FileNameList[2], "READ")
        dirlist = f.GetListOfKeys()
        ITER = dirlist.MakeIterator()
        key = ITER.Next()
        outfileName = FileNameList[0] + "_cut_tree.root"
        outfile = TFile(outfileName, "RECREATE")
        ijk = 0
        while key:
            tree = key.ReadObj()
            tree_f = TTree(tree.GetName() + "_f", tree.GetName() + "_f")
            ENTRY = tree.GetEntries()
            #print(ENTRY)
            for i in range(len(DicNumpyArray_branch)):
                tree.SetBranchAddress(DicNumpyArray_branch.keys()[i],
                                      DicNumpyArray_branch.values()[i])
                tree_f.Branch(DicNumpyArray_branch_w.keys()[i],
                              DicNumpyArray_branch_w.values()[i],
                              DicNumpyArray_branch_w.keys()[i] + "/D")
            print("for tree", tree.GetName())
            for j in range(ENTRY):
                tree.GetEntry(j)
                if (j % 5000 == 0):
                    print("now looping", j, "th Events, total of ", ENTRY,
                          "events")
                for k in range(len(DicNumpyArray_branch)):
                    DicNumpyArray_branch_w.values(
                    )[k][0] = DicNumpyArray_branch.values()[k][0]
                if (  #FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME
                    (
                        DicNumpyArray_branch.values()[0][0] < 0.5
                    )  # [i][0]  means "i"th branch of the tree, [0] don't change   #FIXME#FIXME#FIXME#FIXME
                        &
                    (
                        DicNumpyArray_branch.values()[1][0] < 0.5
                    )  #FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME
                ):
                    ijk = ijk + 1
                    tree_f.Fill()
                else:
                    continue
            print(" Event left after filtering : ", ijk, "!!!!!!!!!")
            print("\n")
            ijk = 0
            if (tree_f.GetEntries() == 0):
                print("!!!!!!! ", tree_f.GetName(),
                      " is Empty, would not be written !!!!!")
            else:
                tree_f.Write()

            key = ITER.Next()

        print("")
        print("////////////////////////////////////////////////")
        print("outputfile : ")
        print(outfileName)
        print("////////////////////////////////////////////////")
        print("")

        outfile.Close()
        f.Close()
        print(
            "*********************************************************************************************"
        )
        gBenchmark.Show("Regerating tree root")
        print(
            "*********************************************************************************************"
        )
예제 #6
0
pad3.GetFrame().SetFillColor(38)
pad3.GetFrame().SetBorderSize(8)
ntuple.SetMarkerColor(1)
ntuple.Draw('py:px', 'pz>1')
ntuple.SetMarkerColor(2)
ntuple.Draw('py:px', 'pz<1', 'same')
c1.Update()

#
# Display a 3-D scatter plot of 3 columns. Superimpose a different selection.
pad4.cd()
ntuple.Draw('pz:py:px', '(pz<10 && pz>6)+(pz<4 && pz>3)')
ntuple.SetMarkerColor(4)
ntuple.Draw('pz:py:px', 'pz<6 && pz>4', 'same')
ntuple.SetMarkerColor(5)
ntuple.Draw('pz:py:px', 'pz<4 && pz>3', 'same')
l4 = TPaveText(-0.9, 0.5, 0.9, 0.95)
l4.SetFillColor(42)
l4.SetTextAlign(12)
l4.AddText('You can interactively rotate this view in 2 ways:')
l4.AddText('  - With the RotateCube in clicking in this pad')
l4.AddText('  - Selecting View with x3d in the View menu')
l4.Draw()

#
# done
c1.cd()
c1.Update()
gStyle.SetStatColor(19)
gBenchmark.Show('ntuple1')
예제 #7
0
def CONVERT_WORKING(filename, outputpath = "" ,D1_NBins=100):


    FileNameList = read_file_name(filename)
    print(FileNameList)
    BranchListAll = get_branch_list_all(FileNameList[2])
    BranchListEachTree = get_branch_list_each_tree(FileNameList[2])
    histo_xrange = set_histo_xrange(FileNameList[2], BranchListAll,BranchListEachTree)

#    print(BranchListEachTree)
  
 
    IJK = 0     # number of all element included in all tree.
    for i in range(len(BranchListEachTree.keys())):
        Tlist = (BranchListEachTree.keys())
        for j in range(len(BranchListEachTree[list(Tlist)[i]])):
            IJK = IJK +1 
#    print(IJK)

    NBins = []                      ### here you can enter the bin numbers of each!!!!!
    for ii in range(IJK):
        NBins.append(D1_NBins)

#    print("NBins =", NBins)
#    NBins = [,,,,,]      #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME 
#    NBins = [40,40,40,40,40]  #!!!!!for soomin

    f = TFile(FileNameList[2],"READ")
    dirlist = f.GetListOfKeys()
    ITER = dirlist.MakeIterator()
    key = ITER.Next()
    DichistList = {}
    while key:
        histList = []
        NamehistList = []
        tree = key.ReadObj()
        branchlist = tree.GetListOfBranches()
        if(branchlist.IsEmpty()):
            continue
        ITER_b = branchlist.MakeIterator()
        key_b = ITER_b.Next()
        while key_b:
            Namehist = FileNameList[0] + "_"+ tree.GetName() + "_" + key_b.GetName()
            ijk = 0
            for j in range(len(histo_xrange[tree.GetName()])):
#                if key_b.GetName() in histo_xrange[tree.GetName()].keys()[j]:    ##### This is initally problem causing line... Keep this line
                if key_b.GetName() == list(histo_xrange[tree.GetName()].keys())[j]:    #### problem causing ### FIXME 
                     hist = TH1D(Namehist, Namehist, NBins[ijk], list(histo_xrange[tree.GetName()].values())[j][0], list(histo_xrange[tree.GetName()].values())[j][1])
                     histList.append(hist)
                     ijk = ijk + 1
                else:
                    continue

            key_b = ITER_b.Next()
        DichistList[tree.GetName()] = histList
        key = ITER.Next()

    dicHistList =  Fill_histograms(FileNameList[2], BranchListAll, DichistList, BranchListEachTree)

    if(outputpath == ''):
        Name_Output_File = FileNameList[3] + "/" + FileNameList[0] + "_hist.root"
        Name_Output_File = Name_Output_File.replace("//","/")
    elif(outputpath[0] == "/"):
        Name_Output_File = outputpath + "/"+ FileNameList[0] + "_hist.root"
        Name_Output_File = Name_Output_File.replace("//","/")
#        print("!@#!@!@#!@ ",Name_Output_File)
    elif(outputpath[0] == "~"):
        Name_Output_File = outputpath.replace("~",os.environ['HOME']) +FileNameList[0]+ "_hist.root"
        Name_Output_File = Name_Output_File.replace("//","/")
#        print("!@#!@!@#!@ ",Name_Output_File)
    else:
        Name_Output_File = os.getcwd() + "/" + outputpath+ FileNameList[0]+"_hist.root"
        Name_Output_File = Name_Output_File.replace("//","/")
#        print("!@#!@!@#!@ ",Name_Output_File)

#    Name_Output_File = FileNameList[0] + "_hist.root"
    outfile = TFile(Name_Output_File,"RECREATE")

    for i in range(len(dicHistList)):
        for j in range(len(list(dicHistList.values())[i])):
            list(dicHistList.values())[i][j].Write()
#            dicHistList.values()[i][j].Print()
    print("")
    print("////////////////////////////////////////////////")
    print("outputfile : ")
    print(Name_Output_File)
    print("////////////////////////////////////////////////")
    print("")
    outfile.Close()

    print("*********************************************************************************************")
    gBenchmark.Show("Filling & Writing Histograms")
    print("*********************************************************************************************")

    print("NBins =", NBins)
    print("\n")
    f.Close()
    return Name_Output_File
    def SplitTree(self):
        FileNameList = read_file_name_root(self._infile)
        BranchListAll = self.get_branch_list_all()
        BranchListEachTree = self.get_branch_list_each_tree()

        DicNumpyArray_branch = {}
        for numpyarray in BranchListAll:
            a = numpy.array([0], 'd')
            DicNumpyArray_branch[numpyarray] = a
        DicNumpyArray_branch = collections.OrderedDict(
            sorted(DicNumpyArray_branch.items()))
        print(DicNumpyArray_branch)

        DicNumpyArray_branch_w = {}
        for numpyarray_w in BranchListAll:
            a_w = numpy.array([0], 'd')
            DicNumpyArray_branch_w[numpyarray_w] = a_w
        DicNumpyArray_branch_w = collections.OrderedDict(
            sorted(DicNumpyArray_branch_w.items()))
        print(DicNumpyArray_branch_w)

        gBenchmark.Start("Regerating tree root")
        f = TFile(FileNameList[2], "READ")
        dirlist = f.GetListOfKeys()
        ITER = dirlist.MakeIterator()
        key = ITER.Next()

        outfileName = os.getcwd(
        ) + "/" + FileNameList[0] + "_cut_TTTL.root"  #FIXME
        print("CREATING... :", outfileName)
        outfile = TFile(outfileName, "RECREATE")

        ijk = 0
        break_flag = 0
        while key:
            if (break_flag == 1): break
            break_flag += 1
            tree = key.ReadObj()
            tree_f = TTree(tree.GetName() + "", tree.GetName() + "")
            ENTRY = tree.GetEntries()
            #print(ENTRY)
            for i in range(len(DicNumpyArray_branch)):
                if (list(DicNumpyArray_branch.keys())[i]
                        in BranchListEachTree[tree.GetName()]):
                    tree.SetBranchAddress(
                        list(DicNumpyArray_branch.keys())[i],
                        list(DicNumpyArray_branch.values())[i])
                    tree_f.Branch(
                        list(DicNumpyArray_branch_w.keys())[i],
                        list(DicNumpyArray_branch_w.values())[i],
                        list(DicNumpyArray_branch_w.keys())[i] + "/D")
                else:
                    continue

            print("for tree", tree.GetName())
            for j in range(ENTRY):
                tree.GetEntry(j)
                if (j % 5000 == 0):
                    print("now looping", j, "th Events, total of ", ENTRY,
                          "events")
                for k in range(len(DicNumpyArray_branch)):
                    if (list(DicNumpyArray_branch.keys())[k]
                            in BranchListEachTree[tree.GetName()]
                        ):  ### FIXED MAYBE not correct....
                        pass
                    else:
                        continue
                    list(DicNumpyArray_branch_w.values())[k][0] = list(
                        DicNumpyArray_branch.values())[k][0]
                if (True
                        #& (list(DicNumpyArray_branch.values())[0][0] == 1)  # LL  #FIXME
                        & (list(DicNumpyArray_branch.values())[0][0] == 0
                           )  # TTTL  #FIXME
                    ):
                    ijk = ijk + 1
                    tree_f.Fill()
                else:
                    continue
            print(" Event left after filtering : ", ijk, "!!!!!!!!!")
            print("\n")
            ijk = 0
            if (tree_f.GetEntries() == 0):
                print("!!!!!!! ", tree_f.GetName(),
                      " is Empty, would not be written !!!!!")
            else:
                tree_f.Write()

            key = ITER.Next()

        print("")
        print("////////////////////////////////////////////////")
        print("outputfile : ")
        print(outfileName)
        print("////////////////////////////////////////////////")
        print("")

        outfile.Close()
        f.Close()
        print(
            "*********************************************************************************************"
        )
        gBenchmark.Show("Regerating tree root")
        print(
            "*********************************************************************************************"
        )

        return outfileName
예제 #9
0
        ccos = cos(2 * pi / numberOfPoints * i) + 1
        esin = sin(2 * pi / (numberOfCircles * d) * j) + 1
        x = j * (csin + esin)
        y = j * ccos
        z = j
        pm3d.SetPoint(i, x, y, z)

# set marker size, color & style
    pm3d.SetMarkerSize(1)
    pm3d.SetMarkerColor(2 + (d == (j & d)))
    pm3d.SetMarkerStyle(3)

    # draw
    pm3d.Draw()

    # save a reference
    polymarkers.append(pm3d)

gBenchmark.Show('tornado')

ct = gBenchmark.GetCpuTime('tornado')
timeStr = 'Execution time: %g sec.' % ct

text = TPaveText(0.1, 0.81, 0.9, 0.97)
text.SetFillColor(42)
text.AddText('PyROOT example: tornado.py')
text.AddText(timeStr)
text.Draw()

sky.Update()
def REGENERATE_TREE_WITH_CUT(filename, outputpath=''):

    FileNameList = read_file_name(filename)
    #    print(FileNameList)
    BranchListAll = get_branch_list_all(FileNameList[2])
    BranchListEachTree = get_branch_list_each_tree(FileNameList[2])
    #    print("@#!@#!@#",BranchListEachTree)
    #    print("@#!@#!@#",BranchListAll)

    DicNumpyArray_branch = {}
    for numpyarray in BranchListAll:
        a = numpy.array([0], 'd')
        DicNumpyArray_branch[numpyarray] = a
    DicNumpyArray_branch = collections.OrderedDict(
        sorted(DicNumpyArray_branch.items())
    )  #  !!!the input times are ordered!!!
    #    print(DicNumpyArray_branch)

    DicNumpyArray_branch_w = {}
    for numpyarray_w in BranchListAll:
        a_w = numpy.array([0], 'd')
        DicNumpyArray_branch_w[numpyarray_w] = a_w
    DicNumpyArray_branch_w = collections.OrderedDict(
        sorted(DicNumpyArray_branch_w.items()))
    #    print(DicNumpyArray_branch_w)

    #    print(DicNumpyArray_branch.keys())
    #    print(DicNumpyArray_branch.values())

    WCuts = WhetherAddCut(BranchListEachTree)
    if (WCuts == None):
        print("\n")
        print(
            "*********************************************************************************************"
        )
        print("!!!! Please check input CUT !!!!! ")
        print("     !!!! No Output File !!!!    ")
        print("\n")
        #        for i in range(len(BranchListEachTree)):
        #            print("compenets below :")
        #            print("The Tree name is : ",BranchListEachTree.keys()[i])
        #            for j in range(len(BranchListEachTree.values()[i])):
        #                print("        it contains : ", BranchListEachTree.values()[i][j])
        #            print("\n")
        print("!!!! Please check input CUT !!!!! ")
        print("     !!!! No Output File !!!!    ")
        print(
            "*********************************************************************************************"
        )
    else:
        print("\n")
        print("...Cut added and regenerating tree root file...")
        gBenchmark.Start("Regerating tree root")

        f = TFile(FileNameList[2], "READ")
        dirlist = f.GetListOfKeys()
        ITER = dirlist.MakeIterator()
        key = ITER.Next()

        if (outputpath == ''):
            outfileName = FileNameList[3] + "/" + FileNameList[0] + "_cut.root"
            outfileName = outfileName.replace("//", "/")
#            print("!@#!@!@#!@ ",outfileName)
        elif (outputpath[0] == "/"):
            outfileName = outputpath + "/" + FileNameList[0] + "_cut.root"
            outfileName = outfileName.replace("//", "/")
#            print("!@#!@!@#!@ ",outfileName)
        elif (outputpath[0] == "~"):
            outfileName = outputpath.replace(
                "~", os.environ['HOME']) + "/" + FileNameList[0] + "_cut.root"
            outfileName = outfileName.replace("//", "/")
#            print("!@#!@!@#!@ ",outfileName)
        else:
            outfileName = os.getcwd(
            ) + "/" + outputpath + "/" + FileNameList[0] + "_cut.root"
            outfileName = outfileName.replace("//", "/")
#            print("!@#!@!@#!@ ",outfileName)

        outfile = TFile(outfileName, "RECREATE")

        ijk = 0
        while key:
            tree = key.ReadObj()
            tree_f = TTree(tree.GetName() + "_f", tree.GetName() + "_f")
            ENTRY = tree.GetEntries()
            #print(ENTRY)
            for i in range(len(DicNumpyArray_branch)):
                if (list(DicNumpyArray_branch.keys())[i]
                        in BranchListEachTree[tree.GetName()]):
                    tree.SetBranchAddress(
                        list(DicNumpyArray_branch.keys())[i],
                        list(DicNumpyArray_branch.values())[i])
                    tree_f.Branch(
                        list(DicNumpyArray_branch_w.keys())[i],
                        list(DicNumpyArray_branch_w.values())[i],
                        list(DicNumpyArray_branch_w.keys())[i] + "/D")
                else:
                    continue

            print("for tree", tree.GetName())
            #            tt = 0
            for j in range(ENTRY):
                tree.GetEntry(j)
                if (j % 5000 == 0):
                    print("now looping", j, "th Events, total of ", ENTRY,
                          "events")
                for k in range(len(DicNumpyArray_branch)):
                    if (list(DicNumpyArray_branch.keys())[k]
                            in BranchListEachTree[tree.GetName()]
                        ):  ### FIXED MAYBE not correct....
                        pass
                    else:
                        continue
                    list(DicNumpyArray_branch_w.values())[k][0] = list(
                        DicNumpyArray_branch.values())[k][0]


#                    if(j==0):
#                        print(k,DicNumpyArray_branch_w.keys()[k])
#                        print(DicNumpyArray_branch_w.keys()[k])

#                tt = raw_input("press 'Y' to proceed, 'enter' to quit!")  #FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME

                if (True  #FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME

                        #                   & (DicNumpyArray_branch.values()[0][0] > 0)          # [i][0]  means "i+1"th branch of each tree, [0] don't change   #FIXME#FIXME#FIXME#FIXME
                        #&  (DicNumpyArray_branch.values()[1][0] > 0)        #FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME#FIXME
                    ):
                    ijk = ijk + 1
                    tree_f.Fill()
                else:
                    continue
            print(" Event left after filtering : ", ijk, "!!!!!!!!!")
            print("\n")
            ijk = 0
            if (tree_f.GetEntries() == 0):
                print("!!!!!!! ", tree_f.GetName(),
                      " is Empty, would not be written !!!!!")
            else:
                tree_f.Write()

            key = ITER.Next()

        print("")
        print("////////////////////////////////////////////////")
        print("outputfile : ")
        print(outfileName)
        print("////////////////////////////////////////////////")
        print("")

        outfile.Close()
        f.Close()
        print(
            "*********************************************************************************************"
        )
        gBenchmark.Show("Regerating tree root")
        print(
            "*********************************************************************************************"
        )

        return outfileName
예제 #11
0
def CONVERT_WORKING2D(filename, outputpath="", NBins=50, NYBins=50):  ### FIXME

    print(
        "*********************************************************************************************"
    )
    print("            This is 2D histo filling process          ")
    print(
        "*********************************************************************************************"
    )
    FileNameList = read_file_name(filename)
    #    print(FileNameList)
    BranchListAll = get_branch_list_all(FileNameList[2])
    BranchListEachTree = get_branch_list_each_tree(FileNameList[2])
    histo_xrange = set_histo_xrange(FileNameList[2], BranchListAll,
                                    BranchListEachTree)

    indicator = 0
    f = TFile(FileNameList[2], "READ")
    dirlist = f.GetListOfKeys()
    ITER = dirlist.MakeIterator()
    key = ITER.Next()
    DichistList = {}
    while key:
        histList = []
        NamehistList = []
        tree = key.ReadObj()
        branchlist = tree.GetListOfBranches()
        if (branchlist.IsEmpty()):
            continue
        ITER_b = branchlist.MakeIterator()
        key_b = ITER_b.Next()
        while key_b:
            branchlistbb = tree.GetListOfBranches()
            ITER_bb = branchlistbb.MakeIterator()
            key_bb = ITER_bb.Next()
            while key_bb:
                if ((key_b.GetName()) != (key_bb.GetName())):
                    Name2DHist = tree.GetName() + "_X_" + BranchName(
                        key_b.GetName()) + "_Y_" + BranchName(key_bb.GetName())
                    #                    print(Name2DHist)
                    #                    print(type(histo_xrange[tree.GetName()][key_b.GetName()][0]))
                    #                    hist = TH2D(Name2DHist, Name2DHist, 200, histo_xrange[tree.GetName()][key_b.GetName()][0], histo_xrange[tree.GetName()][key_b.GetName()][1], 200, histo_xrange[tree.GetName()][key_bb.GetName()][0], histo_xrange[tree.GetName()][key_bb.GetName()][1])
                    #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME  Set bin number !!!!!

                    #                    hist = TH2D(Name2DHist, Name2DHist, NBins, histo_xrange[tree.GetName()][key_b.GetName()][0], histo_xrange[tree.GetName()][key_b.GetName()][1], NBins, histo_xrange[tree.GetName()][key_bb.GetName()][0], histo_xrange[tree.GetName()][key_bb.GetName()][1])  ##for soomin
                    hist = TH2D(
                        Name2DHist, Name2DHist, NBins,
                        histo_xrange[tree.GetName()][key_b.GetName()][0],
                        histo_xrange[tree.GetName()][key_b.GetName()][1],
                        NYBins,
                        histo_xrange[tree.GetName()][key_bb.GetName()][0],
                        histo_xrange[tree.GetName()][key_bb.GetName()][1])

                    histList.append(hist)
                    indicator = indicator + 1

                key_bb = ITER_bb.Next()
            key_b = ITER_b.Next()
        DichistList[tree.GetName()] = histList
        key = ITER.Next()

#    print(DichistList)
##    print(indicator)

    dicHistList = Fill_histograms(FileNameList[2], BranchListAll, DichistList,
                                  BranchListEachTree)

    if (outputpath == ''):
        Name_Output_File = FileNameList[3] + "/" + FileNameList[
            0] + "_hist2D.root"
        Name_Output_File = Name_Output_File.replace("//", "/")
    elif (outputpath[0] == "/"):
        Name_Output_File = outputpath + "/" + FileNameList[0] + "_hist2D.root"
        Name_Output_File = Name_Output_File.replace("//", "/")
#        print("!@#!@!@#!@ ",Name_Output_File)
    elif (outputpath[0] == "~"):
        Name_Output_File = outputpath.replace(
            "~", os.environ['HOME']) + FileNameList[0] + "_hist2D.root"
        Name_Output_File = Name_Output_File.replace("//", "/")
#        print("!@#!@!@#!@ ",Name_Output_File)
    else:
        Name_Output_File = os.getcwd(
        ) + "/" + outputpath + FileNameList[0] + "_hist2D.root"
        Name_Output_File = Name_Output_File.replace("//", "/")


#        print("!@#!@!@#!@ ",Name_Output_File)

#    Name_Output_File = FileNameList[0] + "_hist2D.root"
    outfile = TFile(Name_Output_File, "RECREATE")

    for i in range(len(dicHistList)):
        for j in range(len(list(dicHistList.values())[i])):
            list(dicHistList.values())[i][j].Write()
    print("")
    print("////////////////////////////////////////////////")
    print("outputfile : ")
    print(Name_Output_File)
    print("////////////////////////////////////////////////")
    print("")
    outfile.Close()

    print(
        "*********************************************************************************************"
    )
    gBenchmark.Show("Filling & Writing 2D Histograms")
    print(
        "*********************************************************************************************"
    )

    return Name_Output_File
예제 #12
0
def CONVERT_WORKING(filename, outputpath=""):

    FileNameList = read_file_name(filename)
    print(FileNameList)
    BranchListAll = get_branch_list_all(FileNameList[2])
    BranchListEachTree = get_branch_list_each_tree(FileNameList[2])
    histo_xrange = set_histo_xrange(FileNameList[2], BranchListAll)

    #    print(BranchListEachTree)

    IJK = 0  # number of all element included in all tree.
    for i in range(len(BranchListEachTree.keys())):
        Tlist = (BranchListEachTree.keys())
        #        print(BranchListEachTree[Tlist[i]])
        for j in range(len(BranchListEachTree[Tlist[i]])):
            IJK = IJK + 1
#    print(IJK)

    NBins = []  ### here you can enter the bin numbers of each!!!!!
    for ii in range(IJK):
        NBins.append(100)

#    print("NBins =", NBins)
#    NBins = [,,,,,]      #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME #FIXME

    f = TFile(FileNameList[2], "READ")
    dirlist = f.GetListOfKeys()
    ITER = dirlist.MakeIterator()
    key = ITER.Next()
    DichistList = {}
    while key:
        histList = []
        NamehistList = []
        tree = key.ReadObj()
        branchlist = tree.GetListOfBranches()
        if (branchlist.IsEmpty()):
            continue
        ITER_b = branchlist.MakeIterator()
        key_b = ITER_b.Next()
        #        print(len(histo_xrange[tree.GetName()]),"!!!!!!!")   # correct histo range
        while key_b:
            #            print("!!!!", tree.GetName())  ## correctly rotating
            Namehist = FileNameList[0] + "_" + tree.GetName(
            ) + "_" + key_b.GetName()
            #            print(FileNameList[0])
            #            print(tree.GetName())
            ijk = 0
            #            print("@#!@#!@#!",len(histo_xrange[tree.GetName()]))    # correct 10
            for j in range(len(histo_xrange[tree.GetName()])):
                if key_b.GetName() in histo_xrange[tree.GetName()].keys()[j]:
                    hist = TH1D(Namehist, Namehist, NBins[ijk],
                                histo_xrange[tree.GetName()].values()[j][0],
                                histo_xrange[tree.GetName()].values()[j][1])
                    histList.append(hist)
                    ijk = ijk + 1
                else:
                    continue

            key_b = ITER_b.Next()
        DichistList[tree.GetName()] = histList
        key = ITER.Next()
#    print("!@#!@", len(histList))   # wrong, 13, which should be 10

#    print (DichistList);   ## wrong,, 13 branch which should be 10
#    print("!!!!!!", len(DichistList), "!!!!!")

    dicHistList = Fill_histograms(FileNameList[2], BranchListAll, DichistList)
    #    print(dicHistList)

    #    print(outputpath)
    if (outputpath == ''):
        Name_Output_File = FileNameList[3] + "/" + FileNameList[
            0] + "_hist.root"
        Name_Output_File = Name_Output_File.replace("//", "/")
#        print("!@#!@!@#!@ ",Name_Output_File)
    elif (outputpath[0] == "/"):
        Name_Output_File = outputpath + "/" + FileNameList[0] + "_hist.root"
        Name_Output_File = Name_Output_File.replace("//", "/")
#        print("!@#!@!@#!@ ",Name_Output_File)
    elif (outputpath[0] == "~"):
        Name_Output_File = outputpath.replace(
            "~", os.environ['HOME']) + FileNameList[0] + "_hist.root"
        Name_Output_File = Name_Output_File.replace("//", "/")
#        print("!@#!@!@#!@ ",Name_Output_File)
    else:
        Name_Output_File = os.getcwd(
        ) + "/" + outputpath + FileNameList[0] + "_hist.root"
        Name_Output_File = Name_Output_File.replace("//", "/")
#        print("!@#!@!@#!@ ",Name_Output_File)

#    Name_Output_File = FileNameList[0] + "_hist.root"
    outfile = TFile(Name_Output_File, "RECREATE")

    for i in range(len(dicHistList)):
        for j in range(len(dicHistList.values()[i])):
            dicHistList.values()[i][j].Write()
    print("")
    print("////////////////////////////////////////////////")
    print("outputfile : ")
    print(Name_Output_File)
    print("////////////////////////////////////////////////")
    print("")
    outfile.Close()

    print(
        "*********************************************************************************************"
    )
    gBenchmark.Show("Filling & Writing Histograms")
    print(
        "*********************************************************************************************"
    )

    print("NBins =", NBins)
    print("\n")

    return Name_Output_File
gRandom.SetSeed() rannor, rndm = gRandom.Rannor, gRandom.Rndm
# For speed, bind and cache the Fill member functions,
histos = [ 'hpx', 'hpxpy', 'hprof', 'ntuple' ] for name in histos:
   exec('%sFill = %s.Fill' % (name,name))
# Fill histograms randomly.
px, py = Double(), Double() kUPDATE = 1000 for i in range( 25000 ):
 # Generate random values.
   rannor( px, py )
   pz = px*px + py*py
   random = rndm(1)
 # Fill histograms.
   hpx.Fill( px )
   hpxpy.Fill( px, py )
   hprof.Fill( px, pz )
   ntuple.Fill( px, py, pz, random, i )
 # Update display every kUPDATE events.
   if i and i%kUPDATE == 0:
      if i == kUPDATE:
         hpx.Draw()
      c1.Modified()
      c1.Update()
      if gSystem.ProcessEvents(): # allow user interrupt
         break
# Destroy member functions cache.
for name in histos:
   exec('del %sFill' % name) del histos gBenchmark.Show( 'hsimple' )
# Save all objects in this file.
hpx.SetFillColor( 0 ) hfile.Write() hpx.SetFillColor( 48 ) c1.Modified() c1.Update() c1.Draw()
# Note that the file is automatically closed when application terminates
# or when the file destructor is called.
예제 #14
0
파일: hsimple.py 프로젝트: govoni/learn
    hprofFill(px, pz)
    ntupleFill(px, py, pz, random, i)

    # Update display every kUPDATE events.
    if i and i % kUPDATE == 0:
        if i == kUPDATE:
            hpx.Draw()

        c1.Modified()
        c1.Update()

        if gSystem.ProcessEvents():  # allow user interrupt
            break

# Destroy member functions cache.
for name in histos:
    exec 'del %sFill' % name
del histos

gBenchmark.Show('hsimple')

# Save all objects in this file.
hpx.SetFillColor(0)
hfile.Write()
hpx.SetFillColor(48)
c1.Modified()
c1.Update()

# Note that the file is automatically closed when application terminates
# or when the file destructor is called.
예제 #15
0
    # Update display every kUPDATE events.
    if i and (i % kUPDATE) == 0:
        if i == kUPDATE:
            total.Draw('e1p')
            main.Draw('same')
            s1.Draw('same')
            s2.Draw('same')
            c1.Update()
            slider = TSlider('slider', 'test', 4.2, 0, 4.6, total.GetMaximum(),
                             38)
            slider.SetFillColor(46)

        if slider:
            slider.SetRange(0, float(i) / 10000.)

        c1.Modified()
        c1.Update()

# Destroy member functions cache.
for name in histos:
    exec 'del %sFill' % name
del histos

# Done, finalized and trigger an update.
slider.SetRange(0, 1)
total.Draw('sameaxis')  # to redraw axis hidden by the fill area
c1.Modified()
c1.Update()

gBenchmark.Show('hsum')
예제 #16
0
sqroot.SetLineColor( 4 )
sqroot.SetLineWidth( 6 )
sqroot.Draw()
lfunction = TPaveLabel( 5, 39, 9.8, 46, 'The sqroot function' )
lfunction.SetFillColor( 41 )
lfunction.Draw()
c1.Update()

#
# Create a one dimensional histogram (one float per bin)
# and fill it following the distribution in function sqroot.
#
pad2.cd();
pad2.GetFrame().SetFillColor( 42 )
pad2.GetFrame().SetBorderMode( -1 )
pad2.GetFrame().SetBorderSize( 5 )
h1f = TH1F( 'h1f', 'Test random numbers', 200, 0, 10 )
h1f.SetFillColor( 45 )
h1f.FillRandom( 'sqroot', 10000 )
h1f.Draw()
c1.Update()
#
# Open a ROOT file and save the formula, function and histogram
#
myfile = TFile( 'py-fillrandom.root', 'RECREATE' )
form1.Write()
sqroot.Write()
h1f.Write()
myfile.Close()
gBenchmark.Show( 'fillrandom' )
예제 #17
0
gBenchmark.Start("fillrandom")

form1 = TFormula("form1", "abs(sin(x)/x)")
sqroot = TF1("sqroot", "x*gaus(0) + [3]*form1", 0, 10)
sqroot.SetParameters(10, 4, 1, 20)
#pad1.SetGridx()
pad2.SetGridy()
pad1.SetGrid()
c1.Update()
pad1.cd()
sqroot.Draw()
pad1.Modified()
pad1.Update()

pad2.cd()
pad2.GetFrame().SetFillColor(42)
pad2.GetFrame().SetBorderMode(-1)
pad2.GetFrame().SetBorderSize(5)
h1f = TH1F("h1f", "h1f", 200, 0, 10)
h1f.FillRandom("sqroot", 10000)
h1f.Draw()
pad2.Update()

myfile = TFile("py-fillrandom.root", "recreate")
form1.Write()
sqroot.Write()
h1f.Write()
myfile.Close()

gBenchmark.Show("fillrandom")