benchmark/code/dataset/preprocess.py
def run(card_file, input_jets_file, out_file):
    """Load and recluster the jet constituents. Create binary trees with the
    clustering history of the jets and output a dictionary for each jet that
    contains the root_id, tree, content (constituents 4-momentum vectors),
    mass, pT, energy, eta and phi values (also charge, muon ID, etc. depending
    on the information contained in the dataset)
    """
    # Read card file and extract command list from file content
    with open(card_file) as f:
        commands = f.readlines()
    commands = [x.strip().split('#')[0].split() for x in commands]
    # Evaluate commands in the extracted list
    ptmin = -9999999.
    ptmax = 9999999.
    maxeta = 9999999.
    matchdeltaR = 9999999.
    mergedeltaR = 9999999.
    N_jets = np.inf
    for command in commands:
        if len(command)>=2:
            if command[0] == 'TRIMMING':
                Trimming = int(command[1])
            if command[0] == 'JETDEF':
                jetdef_tree = str(command[1])
            if command[0] == 'PTMIN':
                ptmin = float(command[1])
            if command[0] == 'PTMAX':
                ptmax = float(command[1])
            if command[0] == 'ETAMAX':
                etamax = float(command[1])
            if command[0] == 'MATCHDELTAR':
                matchdeltaR = float(command[1])
            if command[0] == 'MERGEDELTAR':
                mergedeltaR = float(command[1])
            if command[0] == 'RJET':
                Rjet = float(command[1])
            if command[0] == 'RTRIM':
                Rtrim = float(command[1])
            if command[0] == 'MINPTFRACTION':
                MinPtFraction = float(command[1])
            if command[0] == 'PREPROCESS':
                preprocess_label = command[1]
            if command[0] == 'MERGE':
                jetmergeflag = int(command[1])
            if command[0] == 'NPOINTS':
                npoints = int(command[1])
            if command[0] == 'DRETA':
                DReta = float(command[1])
            if command[0] == 'DRPHI':
                DRphi = float(command[1])
            if command[0] == 'NCOLORS':
                Ncolors = int(command[1])
            if command[0] == 'KAPPA':
                kappa = float(command[1])
    logging.info('Loading files for subjets')
    # Expected subjet array format is:
    # ([
    #    [[pTsubj1],[pTsubj2],...],
    #    [[etasubj1],[etasubj2],...],
    #    [[phisubj1],[phisubj2],...]]
    # ])
    logging.info('Loading subjet file {}'.format(input_jets_file))
    # ???
    counter = 0
    # Loop over the data
    with open(input_jets_file, 'rb') as f:
        jets_file_content = pickle.load(f)
    reclustered_jets = list()
    # Loop over all the events
    for element in jets_file_content:
        event = make_pseudojet(element[0])
        label = element[1]
        # Recluster jet constituents
        out_jet = recluster(event, 0.8, 'kt')
        # Create a dictionary with all the jet tree info (topology,
        # constituents features: eta, phi, pT, E, muon label)
        jets_tree = make_tree_list(out_jet)
        # Keep only the leading jet
        for tree, content, mass, pt in [jets_tree[0]]:
            jet = make_dictionary(tree, content, mass, pt)
            reclustered_jets.append((jet, label))
            counter += 1
    # Save output to file
    logging.info('out_filename={}'.format(out_file))
    with open(out_file, "wb") as f:
        pickle.dump(reclustered_jets, f, protocol=2)
    logging.info('counter={}'.format(counter))
Load and recluster the jet constituents. Create binary trees with the
    clustering history of the jets and output a dictionary for each jet that
    contains the root_id, tree, content (constituents 4-momentum vectors),
    mass, pT, energy, eta and phi values (also charge, muon ID, etc. depending
    on the information contained in the dataset)
    
Load and recluster the jet constituents. Create binary trees with the
clustering history of the jets and output a dictionary for each jet that
contains the root_id, tree, content (constituents 4-momentum vectors),
mass, pT, energy, eta and phi values (also charge, muon ID, etc. depending
on the information contained in the dataset)
Load and recluster the jet constituents . Create binary trees with the clustering history of the jets and output a dictionary for each jet that contains the root_id tree content ( constituents 4 - momentum vectors ) mass pT energy eta and phi values ( also charge muon ID etc . depending on the information contained in the dataset )
def run(card_file, input_jets_file, out_file):
    with open(card_file) as f:
        commands = f.readlines()
    commands = [x.strip().split('#')[0].split() for x in commands]
    ptmin = -9999999.
    ptmax = 9999999.
    maxeta = 9999999.
    matchdeltaR = 9999999.
    mergedeltaR = 9999999.
    N_jets = np.inf
    for command in commands:
        if len(command)>=2:
            if command[0] == 'TRIMMING':
                Trimming = int(command[1])
            if command[0] == 'JETDEF':
                jetdef_tree = str(command[1])
            if command[0] == 'PTMIN':
                ptmin = float(command[1])
            if command[0] == 'PTMAX':
                ptmax = float(command[1])
            if command[0] == 'ETAMAX':
                etamax = float(command[1])
            if command[0] == 'MATCHDELTAR':
                matchdeltaR = float(command[1])
            if command[0] == 'MERGEDELTAR':
                mergedeltaR = float(command[1])
            if command[0] == 'RJET':
                Rjet = float(command[1])
            if command[0] == 'RTRIM':
                Rtrim = float(command[1])
            if command[0] == 'MINPTFRACTION':
                MinPtFraction = float(command[1])
            if command[0] == 'PREPROCESS':
                preprocess_label = command[1]
            if command[0] == 'MERGE':
                jetmergeflag = int(command[1])
            if command[0] == 'NPOINTS':
                npoints = int(command[1])
            if command[0] == 'DRETA':
                DReta = float(command[1])
            if command[0] == 'DRPHI':
                DRphi = float(command[1])
            if command[0] == 'NCOLORS':
                Ncolors = int(command[1])
            if command[0] == 'KAPPA':
                kappa = float(command[1])
    logging.info('Loading files for subjets')
    logging.info('Loading subjet file {}'.format(input_jets_file))
    counter = 0
    with open(input_jets_file, 'rb') as f:
        jets_file_content = pickle.load(f)
    reclustered_jets = list()
    for element in jets_file_content:
        event = make_pseudojet(element[0])
        label = element[1]
        out_jet = recluster(event, 0.8, 'kt')
        jets_tree = make_tree_list(out_jet)
        for tree, content, mass, pt in [jets_tree[0]]:
            jet = make_dictionary(tree, content, mass, pt)
            reclustered_jets.append((jet, label))
            counter += 1
    logging.info('out_filename={}'.format(out_file))
    with open(out_file, "wb") as f:
        pickle.dump(reclustered_jets, f, protocol=2)
    logging.info('counter={}'.format(counter))
def run ( card_file , input_jets_file , out_file ) : with open ( card_file ) as f : commands = f . readlines ( ) commands = [ x . strip ( ) . split ( '#' ) [ 0 ] . split ( ) for x in commands ] ptmin = - 9999999. ptmax = 9999999. maxeta = 9999999. matchdeltaR = 9999999. mergedeltaR = 9999999. N_jets = np . inf for command in commands : if len ( command ) >= 2 : if command [ 0 ] == 'TRIMMING' : Trimming = int ( command [ 1 ] ) if command [ 0 ] == 'JETDEF' : jetdef_tree = str ( command [ 1 ] ) if command [ 0 ] == 'PTMIN' : ptmin = float ( command [ 1 ] ) if command [ 0 ] == 'PTMAX' : ptmax = float ( command [ 1 ] ) if command [ 0 ] == 'ETAMAX' : etamax = float ( command [ 1 ] ) if command [ 0 ] == 'MATCHDELTAR' : matchdeltaR = float ( command [ 1 ] ) if command [ 0 ] == 'MERGEDELTAR' : mergedeltaR = float ( command [ 1 ] ) if command [ 0 ] == 'RJET' : Rjet = float ( command [ 1 ] ) if command [ 0 ] == 'RTRIM' : Rtrim = float ( command [ 1 ] ) if command [ 0 ] == 'MINPTFRACTION' : MinPtFraction = float ( command [ 1 ] ) if command [ 0 ] == 'PREPROCESS' : preprocess_label = command [ 1 ] if command [ 0 ] == 'MERGE' : jetmergeflag = int ( command [ 1 ] ) if command [ 0 ] == 'NPOINTS' : npoints = int ( command [ 1 ] ) if command [ 0 ] == 'DRETA' : DReta = float ( command [ 1 ] ) if command [ 0 ] == 'DRPHI' : DRphi = float ( command [ 1 ] ) if command [ 0 ] == 'NCOLORS' : Ncolors = int ( command [ 1 ] ) if command [ 0 ] == 'KAPPA' : kappa = float ( command [ 1 ] ) logging . info ( 'Loading files for subjets' ) logging . info ( 'Loading subjet file {}' . format ( input_jets_file ) ) counter = 0 with open ( input_jets_file , 'rb' ) as f : jets_file_content = pickle . load ( f ) reclustered_jets = list ( ) for element in jets_file_content : event = make_pseudojet ( element [ 0 ] ) label = element [ 1 ] out_jet = recluster ( event , 0.8 , 'kt' ) jets_tree = make_tree_list ( out_jet ) for tree , content , mass , pt in [ jets_tree [ 0 ] ] : jet = make_dictionary ( tree , content , mass , pt ) reclustered_jets . append ( ( jet , label ) ) counter += 1 logging . info ( 'out_filename={}' . format ( out_file ) ) with open ( out_file , "wb" ) as f : pickle . dump ( reclustered_jets , f , protocol = 2 ) logging . info ( 'counter={}' . format ( counter ) )
Load and recluster the jet constituents.
Load and recluster the jet constituents .
"""Load and recluster the jet constituents. Create binary trees with the
    clustering history of the jets and output a dictionary for each jet that
    contains the root_id, tree, content (constituents 4-momentum vectors),
    mass, pT, energy, eta and phi values (also charge, muon ID, etc. depending
    on the information contained in the dataset)
    """ # Read card file and extract command list from file content # Evaluate commands in the extracted list # Expected subjet array format is: # ([ #    [[pTsubj1],[pTsubj2],...], #    [[etasubj1],[etasubj2],...], #    [[phisubj1],[phisubj2],...]] # ]) # ??? # Loop over the data # Loop over all the events # Recluster jet constituents # Create a dictionary with all the jet tree info (topology, # constituents features: eta, phi, pT, E, muon label) # Keep only the leading jet # Save output to file
card_file
input_jets_file
out_file