<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_event_list(tree, selection=None, fraction=None, start_fraction=None):
 """ Set the event list for a tree or chain. Parameters tree : `ROOT.TTree` Input tree/chain. selection : str Cut string defining the event list. fraction : float Fraction of the total file to include in the event list starting from the *end* of the file. """

    import ROOT

    elist = rand_str()

    if selection is None:
        cuts = ''
    else:
        cuts = selection

    if fraction is None or fraction >= 1.0:
        n = tree.Draw(">>%s" % elist, cuts, "goff")
        tree.SetEventList(ROOT.gDirectory.Get(elist))
    elif start_fraction is None:
        nentries = int(tree.GetEntries())
        first_entry = min(int((1.0 - fraction) * nentries), nentries)
        n = tree.Draw(">>%s" % elist, cuts, "goff", nentries, first_entry)
        tree.SetEventList(ROOT.gDirectory.Get(elist))
    else:
        nentries = int(tree.GetEntries())
        first_entry = min(int(start_fraction * nentries), nentries)
        n = first_entry + int(nentries * fraction)
        n = tree.Draw(">>%s" % elist, cuts, "goff",
                      n - first_entry, first_entry)
        tree.SetEventList(ROOT.gDirectory.Get(elist))

    return n