Skip to content
Snippets Groups Projects

Check for TRUEID vs BKGCAT on $B^+\to J/\psi(\to e^+e^-)K^+$ candidates from Run 3

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Angel Campoverde

    Description

    This snippet tests both approaches to truth matching and uses MC from here. The script below produces

    image

    which shows that TRUEID mostly rejects signal at some point. BKGCAT seems to behave as expected.

    Edited
    truth_matching_check_run3.py 2.56 KiB
    from dataclasses import dataclass
    import matplotlib.pyplot as plt
    
    from ROOT import RDataFrame
    # ---------------
    @dataclass
    class Data:
        file_path = 'root://eoslhcb.cern.ch//eos/lhcb/grid/prod/lhcb/anaprod/lhcb/MC/expected-2024.Q1.2/TUPLE.ROOT/00231483/0000/00231483_00000003_1.tuple.root'
        line_name = 'Hlt2RD_BuToKpEE'
        #mass      = 'B_M'
        mass      = 'B_DTF_noPV_Jpsi_mass_const_M'
    
        min_mass  = 5000
        max_mass  = 5600
        nbins     = 100
    # ---------------
    def _test_bkgcat(rdf : RDataFrame) -> None:
        cut = '(B_BKGCAT == 0) || (B_BKGCAT == 10) || (B_BKGCAT == 50)'
        rdf = _filter_rdf(rdf, cut, 'bkg_cat')
        rep = rdf.Report()
    
        rep.Print()
    # ---------------
    def _add_plot(rdf : RDataFrame, label : str) -> None:
        arr_mass = rdf.AsNumpy([Data.mass])[Data.mass]
    
        plt.figure('mass_trueid')
        plt.hist(
                arr_mass,
                label   =label,
                bins    = Data.nbins,
                range   =(Data.min_mass, Data.max_mass),
                histtype='step')
    # ---------------
    def _save_mass_plot() -> None:
        plt.figure('mass_trueid')
        plt.title('Mass distribution for failed events after a given cut')
        plt.legend()
        plt.xlabel(Data.mass)
        plt.savefig('mass.png')
        plt.close('mass_trueid')
    # ---------------
    def _filter_rdf(rdf : RDataFrame, cut : str, label : str) -> RDataFrame:
        rdf_pas = rdf.Filter(            cut, label)
        rdf_fail= rdf.Filter(f'({cut}) == 0', label)
    
        _add_plot(rdf_fail, label)
    
        return rdf_pas
    # ---------------
    def _test_trueid(rdf : RDataFrame) -> None:
        cut_bi = 'TMath::Abs(B_TRUEID) == 521'
        cut_ji = 'TMath::Abs(Jpsi_TRUEID) == 443'
        cut_jm = 'TMath::Abs(Jpsi_MC_MOTHER_ID) == 521'
        cut_kp = 'TMath::Abs(K_MC_MOTHER_ID) == 521'
        cut_ki = 'TMath::Abs(K_TRUEID) == 321'
        cut_em = 'TMath::Abs(L1_MC_MOTHER_ID) == 443 && TMath::Abs(L2_MC_MOTHER_ID) == 443'
        cut_ei = 'TMath::Abs(L1_TRUEID) == 11 && TMath::Abs(L2_TRUEID) == 11'
    
        rdf    = _filter_rdf(rdf, cut_bi,            'B ID')
        rdf    = _filter_rdf(rdf, cut_ji,         'Jpsi ID')
        rdf    = _filter_rdf(rdf, cut_jm,     'Jpsi Mother')
        rdf    = _filter_rdf(rdf, cut_ki,         'Kaon ID')
        rdf    = _filter_rdf(rdf, cut_kp,    'Kplus Mother')
        rdf    = _filter_rdf(rdf, cut_em, 'Electron Mother')
        rdf    = _filter_rdf(rdf, cut_ei,     'Electron ID')
    
        rep    = rdf.Report()
        rep.Print()
    # ---------------
    def main():
        rdf = RDataFrame(f'{Data.line_name}/DecayTree', Data.file_path)
    
        _test_trueid(rdf)
        _test_bkgcat(rdf)
    
        _save_mass_plot()
    # ---------------
    if __name__ == '__main__':
        main()
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment