Пример #1
0
def do_cs_event_wide(full_event, ptmin=100.):
    max_eta = 3.

    # background estimator
    bge = fj.GridMedianBackgroundEstimator(max_eta, 0.5)
    bge.set_particles(full_event)

    rho = bge.rho()
    rhom = bge.rho_m()

    subtractor = cs.ConstituentSubtractor()
    # enum Distance {
    #     deltaR,
    #     angle
    # }
    subtractor.set_distance_type(0)
    subtractor.set_max_distance(max_distance)
    subtractor.set_alpha(alpha)
    subtractor.set_ghost_area(ghost_area)
    subtractor.set_max_eta(max_eta)
    subtractor.set_background_estimator(bge)
    subtractor.set_scalar_background_density(rho, rhom)

    #sel_max_pt = fj.SelectorPtMax(10)
    #subtractor.set_particle_selector(sel_max_pt)

    subtractor.initialize()

    corrected_event = subtractor.subtract_event(full_event)
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    clust_seq_corr = fj.ClusterSequence(corrected_event, jet_def)
    corrected_jets = clust_seq_corr.inclusive_jets(ptmin)

    return corrected_jets, clust_seq_corr
Пример #2
0
def fj_example_02_area(event):
    # cluster the event
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    area_def = fj.AreaDefinition(fj.active_area, fj.GhostedAreaSpec(5.0))
    cs = fj.ClusterSequenceArea(event, jet_def, area_def)
    jets = fj.SelectorPtMin(5.0)(fj.sorted_by_pt(cs.inclusive_jets()))
    print("jet def:", jet_def)
    print("area def:", area_def)
    print("#-------------------- initial jets --------------------")
    print_jets(jets)
    #----------------------------------------------------------------------
    # estimate the background
    maxrap = 4.0
    grid_spacing = 0.55
    gmbge = fj.GridMedianBackgroundEstimator(maxrap, grid_spacing)
    gmbge.set_particles(event)
    print("#-------------------- background properties --------------------")
    print("rho   = ", gmbge.rho())
    print("sigma = ", gmbge.sigma())
    print()
    #----------------------------------------------------------------------
    # subtract the jets
    subtractor = fj.Subtractor(gmbge)
    subtracted_jets = subtractor(jets)
    print("#-------------------- subtracted jets --------------------")
    print_jets(subtracted_jets)
Пример #3
0
def analyze_file_list(file_inputs=[],
                      output_prefix='rg',
                      tree_name='tree_Particle'):

    anl = []

    bg_rho_range = fj.SelectorAbsRapMax(0.9)
    bg_jet_def = fj.JetDefinition(fj.kt_algorithm, 0.4)
    bg_area_def = fj.AreaDefinition(fj.active_area_explicit_ghosts,
                                    fj.GhostedAreaSpec(0.9))
    bg_estimator = fj.JetMedianBackgroundEstimator(bg_rho_range, bg_jet_def,
                                                   bg_area_def)
    print('[i]', bg_estimator.description())
    an_std = MPJetAnalysis(output_prefix=output_prefix,
                           name='std',
                           bg_estimator=bg_estimator)
    anl.append(an_std)

    g_bg_estimator = fj.GridMedianBackgroundEstimator(0.9, 0.4)
    print('[i]', g_bg_estimator.description())
    an_gbg = MPJetAnalysis(output_prefix=output_prefix,
                           name='bgb',
                           bg_estimator=g_bg_estimator)
    anl.append(an_gbg)

    cs004 = csubtractor.CEventSubtractor(alpha=0,
                                         max_distance=0.4,
                                         max_eta=0.9,
                                         bge_rho_grid_size=0.25,
                                         max_pt_correct=100)
    an_cs_004 = MPJetAnalysis(output_prefix=output_prefix,
                              name='cs004',
                              bg_estimator=cs004.bge_rho,
                              constit_subtractor=cs004)
    anl.append(an_cs_004)

    cs404 = csubtractor.CEventSubtractor(alpha=4,
                                         max_distance=0.4,
                                         max_eta=0.9,
                                         bge_rho_grid_size=0.25,
                                         max_pt_correct=100)
    an_cs_404 = MPJetAnalysis(output_prefix=output_prefix,
                              name='cs404',
                              bg_estimator=cs404.bge_rho,
                              constit_subtractor=cs404)
    anl.append(an_cs_404)

    ad = MPAnalysisDriver(file_list=file_inputs,
                          analyses_list=anl,
                          tree_name=tree_name)
    ad.run()

    print()
    print('    ---')
    print()
    print(ad)
    print('[i] done.')
Пример #4
0
    def __init__(self, **kwargs):
        # set the default values
        self.configure_from_args(max_eta=4, bge_rho_grid_size=0.2)

        super(CSubtractorJetByJet, self).__init__(**kwargs)

        # background estimator
        self.bge_rho = fj.GridMedianBackgroundEstimator(
            self.max_eta, self.bge_rho_grid_size)
        self.subtractor = fjcontrib.ConstituentSubtractor(self.bge_rho)
Пример #5
0
def do_cs_iterative(full_event, ptmin=100.):
    max_eta = 3.

    bge = fj.GridMedianBackgroundEstimator(3., 0.5)
    bge.set_particles(full_event)

    rho = bge.rho()
    rhom = bge.rho_m()

    subtractor = ics.IterativeConstituentSubtractor()
    subtractor.set_distance_type(0)

    max_distances_vec = ics.DoubleVec()
    max_distances_vec.push_back(max_distances[0])
    max_distances_vec.push_back(max_distances[1])

    alphas_vec = ics.DoubleVec()
    alphas_vec.push_back(alphas[0])
    alphas_vec.push_back(alphas[1])

    subtractor.set_parameters(max_distances_vec, alphas_vec)
    subtractor.set_ghost_removal(True)
    subtractor.set_ghost_area(ghost_area)
    subtractor.set_max_eta(max_eta)
    subtractor.set_background_estimator(bge)
    subtractor.set_scalar_background_density(rho, rhom)

    #sel_max_pt = fj.SelectorPtMax(10)
    #subtractor.set_particle_selector(sel_max_pt)

    subtractor.initialize()

    # clustering
    corrected_event = subtractor.subtract_event(full_event)
    jet_def = fj.JetDefinition(fj.antikt_algorithm, 0.4)
    clust_seq_corr = fj.ClusterSequence(corrected_event, jet_def)
    corrected_jets = clust_seq_corr.inclusive_jets(ptmin)

    return corrected_jets, clust_seq_corr
Пример #6
0
def main(args):
    fname = args.fname
    file = uproot.open(fname)
    all_ttrees = dict(
        file.allitems(
            filterclass=lambda cls: issubclass(cls, uproot.tree.TTreeMethods)))
    tracks = all_ttrees[b'PWGHF_TreeCreator/tree_Particle;1']
    pds_trks = tracks.pandas.df()  # entrystop=10)
    events = all_ttrees[b'PWGHF_TreeCreator/tree_event_char;1']
    pds_evs = events.pandas.df()

    # print the banner first
    fj.ClusterSequence.print_banner()

    # signal jet definition
    maxrap = 0.9
    jet_R0 = args.jetR
    jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
    jet_selector = fj.SelectorPtMin(0.0) & fj.SelectorAbsEtaMax(1)
    jet_area_def = fj.AreaDefinition(fj.active_area,
                                     fj.GhostedAreaSpec(maxrap))
    print(jet_def)

    # background estimation
    grid_spacing = maxrap / 10.
    gmbge = fj.GridMedianBackgroundEstimator(maxrap, grid_spacing)

    print()

    output_columns = ['evid', 'pt', 'eta', 'phi', 'area', 'ptsub']
    e_jets = pd.DataFrame(columns=output_columns)

    for i, e in pds_evs.iterrows():
        iev_id = int(e['ev_id'])
        run_number = int(e['run_number'])
        _ts = pds_trks.loc[pds_trks['ev_id'] == iev_id].loc[
            pds_trks['run_number'] == run_number]
        _tpsj = fjext.vectorize_pt_eta_phi(_ts['ParticlePt'].values,
                                           _ts['ParticleEta'].values,
                                           _ts['ParticlePhi'].values)
        # print('maximum particle rapidity:', max([psj.rap() for psj in _tpsj]))
        _cs = fj.ClusterSequenceArea(_tpsj, jet_def, jet_area_def)
        _jets = jet_selector(fj.sorted_by_pt(_cs.inclusive_jets()))
        gmbge.set_particles(_tpsj)
        # print("rho   = ", gmbge.rho(), "sigma = ", gmbge.sigma())
        _jets_df = pd.DataFrame([[
            iev_id,
            j.perp(),
            j.eta(),
            j.phi(),
            j.area(),
            j.perp() - gmbge.rho() * j.area()
        ] for j in _jets],
                                columns=output_columns)
        e_jets = e_jets.append(_jets_df, ignore_index=True)
        # print('event', i, 'number of parts', len(_tpsj), 'number of jets', len(_jets))
        # print(_jets_df.describe())
        if args.fjsubtract:
            fj_example_02_area(_tpsj)

    # print(e_jets.describe())
    joblib.dump(e_jets, args.output)
Пример #7
0
    def __init__(self, **kwargs):
        # constants
        # self.max_eta=4  # specify the maximal pseudorapidity for the input particles. It is used for the subtraction. Particles with eta>|max_eta| are removed and not used during the subtraction (they are not returned). The same parameter should be used for the GridMedianBackgroundEstimator as it is demonstrated in this example. If JetMedianBackgroundEstimator is used, then lower parameter should be used  (to avoid including particles outside this range).
        # self.max_eta_jet=3  # the maximal pseudorapidity for selected jets. Not used for the subtraction - just for the final output jets in this example.
        # self.bge_rho_grid_size = 0.2
        # self.max_distance = 0.3
        # self.alpha = 1
        # self.ghost_area = 0.01
        # self.distance_type = fjcontrib.ConstituentSubtractor.deltaR
        # self.CBS=1.0  # choose the scale for scaling the background charged particles
        # self.CSS=1.0  # choose the scale for scaling the signal charged particles
        # self.max_pt_correct = 5.

        # set the default values
        self.configure_from_args(
            max_eta=4,
            bge_rho_grid_size=0.2,
            max_distance=0.3,
            alpha=1,
            ghost_area=0.01,
            distance_type=fjcontrib.ConstituentSubtractor.deltaR,
            CBS=1.0,
            CSS=1.0,
            max_pt_correct=5.)

        super(CEventSubtractor, self).__init__(**kwargs)

        # background estimator
        self.bge_rho = fj.GridMedianBackgroundEstimator(
            self.max_eta, self.bge_rho_grid_size
        )  # Maximal pseudo-rapidity cut max_eta is used inside ConstituentSubtraction, but in GridMedianBackgroundEstimator, the range is specified by maximal rapidity cut. Therefore, it is important to apply the same pseudo-rapidity cut also for particles used for background estimation (specified by function "set_particles") and also derive the rho dependence on rapidity using this max pseudo-rapidity cut to get the correct rescaling function!

        self.subtractor = fjcontrib.ConstituentSubtractor(
        )  # no need to provide background estimator in this case
        self.subtractor.set_distance_type(
            self.distance_type
        )  # free parameter for the type of distance between particle i and ghost k. There  are two options: "deltaR" or "angle" which are defined as deltaR=sqrt((y_i-y_k)^2+(phi_i-phi_k)^2) or Euclidean angle between the momenta
        self.subtractor.set_max_distance(
            self.max_distance
        )  # free parameter for the maximal allowed distance between particle i and ghost k
        self.subtractor.set_alpha(
            self.alpha
        )  # free parameter for the distance measure (the exponent of particle pt). The larger the parameter alpha, the more are favoured the lower pt particles in the subtraction process
        self.subtractor.set_ghost_area(
            self.ghost_area
        )  # free parameter for the density of ghosts. The smaller, the better - but also the computation is slower.
        # self.subtractor.set_do_mass_subtraction()  # use this line if also the mass term sqrt(pT^2+m^2)-pT should be corrected or not. It is necessary to specify it like this because the function set_common_bge_for_rho_and_rhom cannot be used in this case.
        self.subtractor.set_remove_particles_with_zero_pt_and_mass(
            True
        )  # set to false if you want to have also the zero pt and mtMinuspt particles in the output. Set to true, if not. The choice has no effect on the performance. By deafult, these particles are removed - this is the recommended way since then the output contains much less particles, and therefore the next step (e.g. clustering) is faster. In this example, it is set to false to make sure that this test is successful on all systems (mac, linux).
        # self.subtractor.set_grid_size_background_estimator(self.bge_rho_grid_size)  # set the grid size (not area) for the background estimation with GridMedianBackgroundEstimation which is used within CS correction using charged info

        self.subtractor.set_max_eta(
            self.max_eta)  # parameter for the maximal eta cut
        self.subtractor.set_background_estimator(
            self.bge_rho)  # specify the background estimator to estimate rho.

        self.sel_max_pt = fj.SelectorPtMax(self.max_pt_correct)
        self.subtractor.set_particle_selector(self.sel_max_pt)
        # only particles with pt<X will be corrected - the other particles will be copied without any changes.

        # subtractor.set_use_nearby_hard(0.2,2);  // In this example, if there is a hard proxy within deltaR distance of 0.2, then the CS distance is multiplied by factor of 2, i.e. such particle is less favoured in the subtraction procedure. If you uncomment this line, then also uncomment line 106.

        self.subtractor.initialize()
Пример #8
0
def main(args):
    fname = args.fname
    file = uproot.open(fname)
    all_ttrees = dict(
        file.allitems(
            filterclass=lambda cls: issubclass(cls, uproot.tree.TTreeMethods)))
    tracks = all_ttrees[b'PWGHF_TreeCreator/tree_Particle;1']
    pds_trks = tracks.pandas.df()  # entrystop=10)
    events = all_ttrees[b'PWGHF_TreeCreator/tree_event_char;1']
    pds_evs = events.pandas.df()

    # print the banner first
    fj.ClusterSequence.print_banner()

    # signal jet definition
    maxrap = 0.9
    jet_R0 = args.jetR
    jet_def = fj.JetDefinition(fj.antikt_algorithm, jet_R0)
    jet_selector = fj.SelectorPtMin(0.0) & fj.SelectorPtMax(
        1000.0) & fj.SelectorAbsEtaMax(1)
    jet_area_def = fj.AreaDefinition(fj.active_area,
                                     fj.GhostedAreaSpec(maxrap))
    print(jet_def)

    # background estimation
    grid_spacing = maxrap / 10.
    gmbge = fj.GridMedianBackgroundEstimator(maxrap, grid_spacing)

    print()

    output_columns = ['evid', 'pt', 'eta', 'phi', 'area', 'ptsub']
    e_jets = pd.DataFrame(columns=output_columns)

    for i, e in pds_evs.iterrows():
        iev_id = int(e['ev_id'])
        _ts = pds_trks.loc[pds_trks['ev_id'] == iev_id]

        start = time.time()
        _tpsj = fj_parts_from_tracks_numpy(_ts)
        end = time.time()
        dt_swig = end - start

        start = time.time()
        _tpsj_for = fj_parts_from_tracks(_ts)
        end = time.time()
        dt_for = end - start

        # print ('len {} =?= {}'.format(len(_tpsj_for), len(_tpsj)))
        print(
            '[i] timing (ntracks={}): dt_for: {} dt_swig: {} ratio: {}'.format(
                len(_tpsj), dt_for, dt_swig, dt_for / dt_swig))

        # print('maximum particle rapidity:', max([psj.rap() for psj in _tpsj]))
        _cs = fj.ClusterSequenceArea(_tpsj, jet_def, jet_area_def)
        _jets = jet_selector(fj.sorted_by_pt(_cs.inclusive_jets()))
        gmbge.set_particles(_tpsj)
        # print("rho   = ", gmbge.rho())
        # print("sigma = ", gmbge.sigma())

        # _jets = jet_selector(jet_def(_tpsj))
        # _jets_a = [[iev_id, j.perp(), j.eta(), j.phi()] for j in _jets]
        # _jets_a = pd.DataFrame(np.array([[iev_id, j.perp(), j.eta(), j.phi()] for j in _jets]), columns=['evid', 'pt', 'eta', 'phi'])
        _jets_a = pd.DataFrame([[
            iev_id,
            j.perp(),
            j.eta(),
            j.phi(),
            j.area(),
            j.perp() - gmbge.rho() * j.area()
        ] for j in _jets],
                               columns=output_columns)
        # , columns=['evid, pt, eta, phi']
        e_jets = e_jets.append(_jets_a, ignore_index=True)
        # print('event', i, 'number of parts', len(_tpsj), 'number of jets', len(_jets))
        # print(_jets_a.describe())
        if args.fjsubtract:
            fj_example_02_area(_tpsj)

    # print(e_jets.describe())
    joblib.dump(e_jets, args.output)