示例#1
0
def get_visible_children(eventWise):
    visibles = set(eventWise.JetInputs_SourceIdx)
    showers = FormShower.get_showers(eventWise)
    results = [sorted(visibles.intersection(s.particle_idxs)) for s in showers]
    roots = [s.root_idxs[0] for s in showers]
    results = ak.from_iter(results)
    assert len(visibles) == len(set(
        ak.flatten(results))), f"Event {eventWise.selected_event}"
    return results, roots
示例#2
0
 def check(children, parents, mcpid, exclude_pids, expected):
     with TempTestDir("tst") as dir_name:
         eventWise = Components.EventWise(
             os.path.join(dir_name, "tmp.parquet"))
         eventWise.append(Children=[ak.from_iter(children)],
                          Parents=[ak.from_iter(parents)],
                          MCPID=[ak.from_iter(mcpid)])
         eventWise.selected_event = 0
         showers = FormShower.get_showers(eventWise, exclude_pids)
         err_msg = f"Showers with parentage {parents}, expected {expected}, found {[set(s.particle_idxs) for s in showers]}"
         assert len(showers) == len(expected), err_msg
         for shower in showers:
             assert set(shower.particle_idxs) in expected, err_msg
示例#3
0
def main():
    """Launch file, makes and saves a dot graph"""
    repeat = True
    eventWise_path = InputTools.get_file_name("Name the eventWise; ", '.awkd')
    eventWise = Components.EventWise.from_file(eventWise_path)
    while repeat:
        from jet_tools import FormShower
        eventWise.selected_event = int(input("Event number: "))
        showers = FormShower.get_showers(eventWise)
        jet_name = "HomeJet"
        chosen_showers = []
        for i, shower in enumerate(showers):
            shower_roots = [shower.labels[i] for i in shower.root_local_idxs]
            if 'b' not in shower_roots and 'bbar' not in shower_roots:
                continue
            chosen_showers.append(shower)
            print(f"Shower roots {shower.root_idxs}")
            max_children = max([len(d) for d in shower.children])
            end_ids = shower.ends
            print(
                f"Drawing shower {i}, has {max_children} max children. Daughters to particles ratio = {max_children/len(shower.children)}"
            )
            # pick the jet with largest overlap
            largest_overlap = 0
            picked_jet = 0
            for i in range(len(eventWise.HomeJet_Parent)):
                is_external = getattr(eventWise, jet_name + "_Child1")[i] < 0
                input_idx = getattr(eventWise,
                                    jet_name + "_Label")[i][is_external]
                jet_particles = eventWise.JetInputs_SourceIdx[input_idx]
                matches_here = sum([p in end_ids for p in jet_particles])
                if matches_here > largest_overlap:
                    largest_overlap = matches_here
                    picked_jet = i
            print(
                f"A jet contains {largest_overlap} out of {len(end_ids)} end products"
            )
            graph = DotGraph(shower=shower,
                             eventWise=eventWise,
                             jet_name=jet_name,
                             jet_num=picked_jet,
                             use_TracksTowers=True)
            base_name = f"event{eventWise.selected_event}_plot"
            dotName = base_name + str(i) + ".dot"
            legendName = base_name + str(i) + "_ledg.dot"
            with open(dotName, 'w') as dotFile:
                dotFile.write(str(graph))
            with open(legendName, 'w') as dotFile:
                dotFile.write(graph.legend)
        #amalgam_shower = chosen_showers[0]
        #if len(chosen_showers)>1:
        #    for shower in chosen_showers[1:]:
        #        amalgam_shower.amalgamate(shower)
        #print("Drawing the amalgam of all b showers")
        #graph = DotGraph(shower=amalgam_shower, observables=obs)
        #dotName = f"event{eventWise.selected_event}_mixing_plot.dot"
        #legendName ="mixing_ledg.dot"
        #with open(dotName, 'w') as dotFile:
        #    dotFile.write(str(graph))
        #with open(legendName, 'w') as dotFile:
        #    dotFile.write(graph.legend)
        repeat = InputTools.yesNo_question("Again? ")