Esempio n. 1
0
def make_new_cluster(eventWise):
    """
    

    Parameters
    ----------
    eventWise :
        

    Returns
    -------

    """
    cluster_name, cluster_function, chosen_parameters = pick_class_params()
    # now we have parameters, apply them
    jet_name = InputTools.list_complete("Name this cluster (empty for autoname); ", [''])
    if jet_name  == '':
        found = [name.split('_', 1)[0] for name in eventWise.hyperparameters
                 if name.startswith(cluster_name)]
        i = 0
        jet_name = cluster_name + "Jet" + str(i)
        while jet_name in found:
            i += 1
            jet_name = cluster_name + "Jet" + str(i)
        print(f"Naming this {jet_name}")
    FormJets.cluster_multiapply(eventWise, cluster_function, chosen_parameters, batch_length=BATCH_LENGTH, jet_name=jet_name)
    return jet_name
Esempio n. 2
0
    def _cluster(self, dR=0.8):
        self.dR = dR
        self.__jet_name = "MyJet"

        # calculate higher level (HL) data
        Components.add_all(self.__data_obj, inc_mass=True)

        # filter using the HL data
        filt_fin_pcl = FormJets.filter_ends  # pcls at end of shower
        filt_observe = FormJets.filter_pt_eta  # observable pt & eta range
        FormJets.create_jetInputs(  # apply the filters to edit data inplace
            self.__data_obj, [filt_fin_pcl, filt_observe],
            batch_length=np.inf)

        # jet cluster events with anti-kt
        FormJets.cluster_multiapply(self.__data_obj,
                                    cluster_algorithm=FormJets.Traditional,
                                    dict_jet_params={
                                        'DeltaR': dR,
                                        'ExpofPTMultiplier': -1
                                    },
                                    jet_name=self.__jet_name,
                                    batch_length=np.inf)

        self.clustered = True
Esempio n. 3
0
def check_problem():
    """ """
    eventWise = get_data_file()
    BATCH_LENGTH = InputTools.get_literal("How long should the batch be (-1 for all events)? ", int)
    if BATCH_LENGTH == -1:
        BATCH_LENGTH = np.inf
    eventWise = define_inputs(eventWise)
    params = {'DeltaR': 0.4, 'ExponentMultiplier': 0.1, 'NumEigenvectors': 2, 'Laplacien': 'symmetric', "AffinityType": 'linear', "WithLaplacienScaling": False, "CutoffDistance":  5.2, "Invarient": 'normed'}
    jet_name = "ProblemJet"
    params["jet_name"] = jet_name
    FormJets.cluster_multiapply(eventWise, FormJets.Spectral, params, batch_length=BATCH_LENGTH)
Esempio n. 4
0
def cluster_multiapply_with_ghosts(eventWise, cluster_algorithm,
                                   dict_jet_params={}, jet_name=None,
                                   batch_length=100, silent=False,
                                   variable=0.1, on_grid=True):
    """
    Apply a clustering algorithm to many events, 
    also incluse ghost particles to get jet areas.

    Parameters
    ----------
    eventWise : EventWise
        data file with inputs, results are also written here
    cluster_algorithm: callable
        function or class that will create the jets
    dict_jet_params : dict
        dictionary of input parameters for clustering settings
        (Default value = {})
    jet_name : string
        Prefix name for the jet in eventWise
        (Default value = None)
    batch_length : int
        numebr of events to process
        (Default value = 100)
    silent : bool
        should print statments indicating progrss be suppressed?
        useful for running in parallel
        (Default value = False)
    variable : float
        if on_grid is True; the spacing of the grid
        else; the number of particles
        (Default value = 0.1)
    on_grid : bool
        should the ghosts be on a grid?
        if this is False they will be randomly distributed
        (Default value = True)

    Returns
    -------
    : bool
        All events in the eventWise have been clustered

    """
    particle_labels, cluster_algorithm = \
        clustering_with_ghosts(cluster_algorithm, variable, on_grid)
    clustered = FormJets.cluster_multiapply(eventWise=eventWise,
                                            cluster_algorithm=cluster_algorithm,
                                            dict_jet_params=dict_jet_params,
                                            jet_name=jet_name,
                                            batch_length=batch_length,
                                            silent=silent)
    if not silent:
        print("Clustering finished, removing ghosts")
    remove_particles_from_jets(eventWise, particle_labels, silent=silent)
    return clustered
Esempio n. 5
0
def single_check(eventWise,
                 jet_class,
                 jet_name,
                 jet_params={},
                 num_particles=10,
                 compare_tree=None):
    if compare_tree is None:
        # make a guess baes on the jet name
        if "SKM" in jet_name or "KMeans" in jet_name:
            compare_tree = False
        elif "Indicator" or "SI" in jet_name:
            compare_tree = False
        else:
            compare_tree = True
    print("Clustering without ghosts")
    jet_name_no = "NoGhost" + jet_name
    FormJets.cluster_multiapply(eventWise,
                                jet_class,
                                dict_jet_params=jet_params,
                                jet_name=jet_name_no,
                                batch_length=np.inf,
                                silent=False)
    print("Clustering with ghosts")
    GhostParticles.cluster_multiapply_with_ghosts(eventWise,
                                                  jet_class,
                                                  dict_jet_params=jet_params,
                                                  jet_name=jet_name,
                                                  batch_length=np.inf,
                                                  silent=False,
                                                  variable=num_particles,
                                                  on_grid=False)
    print("Comparing")
    if compare_tree:
        changed = check_tree_changes(eventWise, jet_name)
    else:
        changed = check_leaf_changes(eventWise, jet_name)
    if np.any(changed):
        print("Not IR safe")
    else:
        print("IR safe")
    eventWise.append(**{jet_name + "_GhostChanges": changed})
def cluster_sequence(file_name,
                     names,
                     classes,
                     params,
                     jet_pt_cut,
                     dijet_mass,
                     pileup_file=None,
                     mean_pileup_per_event=50,
                     z_cuts=[0.2, 0.4]):
    if pileup_file is not None:
        ew = NonwritingEventWise.from_file(file_name)
    else:
        ew = Components.EventWise.from_file(file_name)

    if pileup_file is not None:
        print("Adding pileup")
        ew = remove_excess_data(ew)
        pileup = NonwritingEventWise.from_file(pileup_file)
        ew = AddPileup.add_pileup(ew, pileup, mean_pileup_per_event)
        filter_functions = "remove pileup"
    else:
        filter_functions = "ignore pileup"

    print("Adding jet inputs")
    FormJetInputs.create_jetInputs(ew, filter_functions=filter_functions)

    print("Adding jets")
    for name, cla, param in zip(names, classes, params):
        finished = False
        while not finished:
            finished = FormJets.cluster_multiapply(ew, cla, param, name,
                                                   np.inf)
    n_jets = len(names) * 20
    if z_cuts:
        print("Doing z_cuts")
        ParallelFormJets.batch_masks(ew, z_cuts, n_jets)
        ParallelFormJets.batch_filter(ew, n_jets)

    print("Calculating scores")
    if 'top' in str(dijet_mass):
        ParallelFormJets.batch_semileptonic(ew, n_jets)
        ParallelFormJets.batch_correct_semileptonic_masses(ew, n_jets)
    else:
        CompareClusters.append_scores(ew,
                                      dijet_mass=dijet_mass,
                                      end_time=np.inf)
        ParallelFormJets.batch_correct_masses(ew, jet_pt_cut, n_jets)
    return ew
Esempio n. 7
0
def single_check(eventWise,
                 jet_class,
                 jet_name,
                 jet_params={},
                 num_splits=None):
    print("Clustering with splits")
    cluster_algorithm = clustering_with_collinear(jet_class, num_splits)
    jet_params["MaxMeanDist"] = np.inf
    clustered = FormJets.cluster_multiapply(
        eventWise=eventWise,
        cluster_algorithm=cluster_algorithm,
        dict_jet_params=jet_params,
        jet_name=jet_name,
        batch_length=np.inf,
        silent=False)
    print("Checking joins")
    changed = check_correct_joins(eventWise, jet_name)
    eventWise.append(**{jet_name + "_CollinearChanges": changed})
    if np.any(changed):
        print("Not collinear safe")
    else:
        print("Collinear safe")
Esempio n. 8
0
print()
FormJetInputs.create_jetInputs(hepmc)
jet_names = []
jet_name = "AntiKTp8Jet"
jet_names.append(jet_name)
jet_class = FormJets.Traditional
jet_params = {
    'DeltaR': 0.8,
    'ExpofPTFormat': 'min',
    'ExpofPTMultiplier': 0,
    'PhyDistance': 'angular'
}
print()
print(f"Clustering {jet_name}")
print()
FormJets.cluster_multiapply(hepmc, jet_class, jet_params, jet_name, np.inf)

jet_name = "AntiKTp4Jet"
jet_names.append(jet_name)
jet_class = FormJets.Traditional
jet_params = {
    'DeltaR': 0.4,
    'ExpofPTFormat': 'min',
    'ExpofPTMultiplier': 0,
    'PhyDistance': 'angular'
}
print()
print(f"Clustering {jet_name}")
print()
FormJets.cluster_multiapply(hepmc, jet_class, jet_params, jet_name, np.inf)
Esempio n. 9
0
 print(
     "To use it, specify the clustering hyperparameters as a dict, so for anti-KT;"
 )
 print(" > hyperparameters = {'DeltaR': 0.8, 'ExpofPTInput': -1}")
 hyperparameters = {'DeltaR': 0.8, 'ExpofPTInput': -1}
 print("Then we can run this clustering")
 print(
     "FormJets.cluster_multiapply(eventWise, cluster_algorithm=FormJets.GeneralisedKT,"
 )
 print(
     "                            dict_jet_params=hyperparameters, jet_name='MyJet',"
 )
 print("                            batch_length=np.inf)")
 FormJets.cluster_multiapply(eventWise,
                             cluster_algorithm=FormJets.GeneralisedKT,
                             dict_jet_params=hyperparameters,
                             jet_name="MyJet",
                             batch_length=np.inf)
 print("Now every event has been clustered with anti-KT.")
 print(
     "The results are saved in the eventWise, and can be accessed as properties that"
 )
 print("are named starting with <jet_name>_, so for us MyJet_")
 print(" > eventWise.selected_event = None")
 eventWise.selected_event = None
 print(" > eventWise.MyJet_Parent")
 print(eventWise.MyJet_Parent)
 print("Each event is a list of lists,")
 print("each sublist within an event is the information for 1 jet.")
 print("Something like; dataset{ event{ jet{} jet{}} event{ jet{}}}")
 interactive()