Пример #1
0
def get_effs_per_track_and_p_station(tracks, data, event_ids, stations='12'):

    tracks_eff_before = pandas.DataFrame(columns=['Eff', 'Momentum'])

    for event_id in event_ids:

        if stations == '12':

            labels = tracks[event_id]['labels12']

            event = data[data.EventID == event_id]
            event = event[(event.StatNb == 1) + (event.StatNb == 2)]

        elif stations == '34':

            labels = tracks[event_id]['labels34']

            event = data[data.EventID == event_id]
            event = event[(event.StatNb == 3) + (event.StatNb == 4)]

        true_labels = event.Label.values

        trm = TracksReconstractionMetrics(0.2)
        trm.fit(labels, event)

        eff = trm.efficiencies_

        for num, lab in enumerate(numpy.unique(labels[labels != -1])):

            valid_labs = true_labels[labels == lab]
            unique, counts = numpy.unique(valid_labs[valid_labs != -1],
                                          return_counts=True)

            if len(unique) == 0:
                continue

            true_lab = unique[counts == counts.max()][0]

            track = event[true_labels == true_lab]
            p_one = numpy.sqrt(track.Px.values**2 + track.Py.values**2 +
                               track.Pz.values**2).mean()

            eff_one = eff[num]

            tracks_eff_before.loc[len(tracks_eff_before)] = [eff_one, p_one]

    return tracks_eff_before
def get_effs_per_track_and_p_station(tracks, data, event_ids, stations='12'):

    tracks_eff_before = pandas.DataFrame(columns=['Eff', 'Momentum'])

    for event_id in event_ids:

        if stations == '12':

            labels = tracks[event_id]['labels12']

            event = data[data.EventID == event_id]
            event = event[(event.StatNb == 1) + (event.StatNb == 2)]

        elif stations == '34':

            labels = tracks[event_id]['labels34']

            event = data[data.EventID == event_id]
            event = event[(event.StatNb == 3) + (event.StatNb == 4)]

        true_labels = event.Label.values

        trm = TracksReconstractionMetrics(0.2)
        trm.fit(labels, event)

        eff = trm.efficiencies_


        for num, lab in enumerate(numpy.unique(labels[labels != -1])):

            valid_labs = true_labels[labels == lab]
            unique, counts = numpy.unique(valid_labs[valid_labs!=-1], return_counts=True)

            if len(unique) == 0:
                continue

            true_lab = unique[counts == counts.max()][0]

            track = event[true_labels == true_lab]
            p_one = numpy.sqrt(track.Px.values**2+track.Py.values**2+track.Pz.values**2).mean()

            eff_one = eff[num]

            tracks_eff_before.loc[len(tracks_eff_before)] = [eff_one, p_one]

    return tracks_eff_before
def get_eff_value(params):

    event_id, data, tracks, clf = params

    # Get an event
    event = data[data.EventID == event_id]
    event12 = event[(event.StatNb == 1) + (event.StatNb == 2)]
    event34 = event[(event.StatNb == 3) + (event.StatNb == 4)]

    labels12 = tracks[event_id]['labels12']
    tracks_params12 = tracks[event_id]['params12']
    labels34 = tracks[event_id]['labels34']
    tracks_params34 = tracks[event_id]['params34']

    # Quality metrics of the reconstruction
    trm12 = TracksReconstractionMetrics(0.2, n_tracks=2)
    trm12.fit(labels12, event12)

    # Quality metrics of the reconstruction
    trm34 = TracksReconstractionMetrics(0.2, n_tracks=2)
    trm34.fit(labels34, event34)

    # Combination of the tracks before and after the magnet
    if clf == None:
        comb = Combinator()
    else:
        comb = SuperCombinator(classifier=clf)
    comb.combine(tracks_params12, tracks_params34)

    # Quality of the combination
    cq = CombinatorQuality()
    cq.fit(labels12, labels34, comb.tracks_combinations_, comb.charges_,
           comb.inv_momentums_, event12, event34)

    # Overall quality
    line = numpy.array([
        1, (trm12.recognition_efficiency_y_ == 1) * 1,
        (trm12.recognition_efficiency_stereo_ >= 1.) * 1,
        (trm12.recognition_efficiency_ == 1) * 1,
        (trm34.recognition_efficiency_y_ == 1) * 1,
        (trm34.recognition_efficiency_stereo_ >= 1.) * 1,
        (trm34.recognition_efficiency_ == 1) * 1, (cq.n_combined_ >= 2) * 1,
        (cq.reco_eff_ == 1) * 1
    ]).cumprod()

    return line[-1]
def get_eff_value(params):

    event_id, data, tracks, clf = params

    # Get an event
    event = data[data.EventID == event_id]
    event12 = event[(event.StatNb == 1) + (event.StatNb == 2)]
    event34 = event[(event.StatNb == 3) + (event.StatNb == 4)]


    labels12 = tracks[event_id]['labels12']
    tracks_params12 = tracks[event_id]['params12']
    labels34 = tracks[event_id]['labels34']
    tracks_params34 = tracks[event_id]['params34']


    # Quality metrics of the reconstruction
    trm12 = TracksReconstractionMetrics(0.2, n_tracks=2)
    trm12.fit(labels12, event12)


    # Quality metrics of the reconstruction
    trm34 = TracksReconstractionMetrics(0.2, n_tracks=2)
    trm34.fit(labels34, event34)


    # Combination of the tracks before and after the magnet
    if clf == None:
        comb = Combinator()
    else:
        comb = SuperCombinator(classifier=clf)
    comb.combine(tracks_params12, tracks_params34)


    # Quality of the combination
    cq = CombinatorQuality()
    cq.fit(labels12, labels34, comb.tracks_combinations_, comb.charges_, comb.inv_momentums_, event12, event34)


    # Overall quality
    line = numpy.array([1,
                         (trm12.recognition_efficiency_y_ == 1)*1,
                         (trm12.recognition_efficiency_stereo_ >= 1.)*1,
                         (trm12.recognition_efficiency_ == 1)*1,
                         (trm34.recognition_efficiency_y_ == 1)*1,
                         (trm34.recognition_efficiency_stereo_ >= 1.)*1,
                         (trm34.recognition_efficiency_ == 1)*1,
                         (cq.n_combined_ >= 2)*1,
                         (cq.reco_eff_ == 1)*1]).cumprod()

    return line[-1]