def test_string_representation(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') assert "n_decays" not in p.__str__() p.parse() assert "n_decays=5" in p.__str__()
def test_simple_dec(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() assert p.list_decay_mother_names() == ['D*+', 'D*-', 'D0', 'D+', 'pi0'] assert p.list_decay_modes('D0') == [['K-', 'pi+']]
def test_decay_mode_details(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() tree_Dp = p._find_decay_modes('D+')[0] output = (1.0, ['K-', 'pi+', 'pi+', 'pi0'], 'PHSP', '') assert p._decay_mode_details(tree_Dp) == output
def test_duplicate_decay_definitions(): p = DecFileParser(DIR / '../data/duplicate-decays.dec') p.parse() assert p.number_of_decays == 2 assert p.list_decay_mother_names() == ['Sigma(1775)0', 'anti-Sigma(1775)0']
def test_graphs_with_EvtGen_specific_names(): p = DecFileParser(DIR / "../../src/decaylanguage/data/DECAY_LHCB.DEC") p.parse() # Not setting many of the particles as stable would result in a gargantuesque chain, # which would also take a fair amount of time to build! list_stable_particles = [ "Xi_c0", "Xi-", "D0", "Omega_c0", "Sigma_c0", "tau-", "D_s-", "J/psi", "pi0", "Lambda0", "psi(2S)", ] chain = p.build_decay_chains("Xi_b-", stable_particles=list_stable_particles) dcv = DecayChainViewer(chain) assert "(cs)<SUB>0</SUB>" in dcv.to_string() # not 'cs_0' ;-) assert "Ξ<SUB>b</SUB><SUP>-</SUP>" in dcv.to_string() assert "Ξ<SUB>c</SUB><SUP>0</SUP>" in dcv.to_string()
def test_print_decay_modes_options(): p1 = DecFileParser(DIR / "../data/test_example_Dst.dec") p1.parse() p2 = DecFileParser(DIR / "../data/test_Bc2BsPi_Bs2KK.dec") p2.parse() # Temporarily direct prints of several calls below to a string old_stdout = sys.stdout tmp_stdout = io.StringIO() sys.stdout = tmp_stdout p1.print_decay_modes("D*+") out_default = tmp_stdout.getvalue() tmp_stdout = io.StringIO() sys.stdout = tmp_stdout p1.print_decay_modes("D*+", normalize=True) out_normalized = tmp_stdout.getvalue() tmp_stdout = io.StringIO() sys.stdout = tmp_stdout p2.print_decay_modes("B_c+sig", display_photos_keyword=False) no_photos = tmp_stdout.getvalue() tmp_stdout.truncate(0) assert "PHOTOS" not in no_photos # This specific dec file happens to have been defined normalized assert out_default == out_normalized # Do not forget to reset sys.stdout and clean up! sys.stdout = old_stdout del old_stdout, tmp_stdout
def test_constructor_multiple_files(): p = DecFileParser(DIR / '../data/test_Xicc2XicPiPi.dec', DIR / '../data/test_Bc2BsPi_Bs2KK.dec') p.parse() assert len(p._dec_file_names) == 2 assert p.number_of_decays == 7
def test_simple_dec(): p = DecFileParser(DIR / "../data/test_example_Dst.dec") p.parse() assert p.list_decay_mother_names() == ["D*+", "D*-", "D0", "D+", "pi0"] assert p.list_decay_modes("D0") == [["K-", "pi+"]]
def test_BELLE2_decfile(): p = DecFileParser(DIR / '../../decaylanguage/data/DECAY_BELLE2.DEC') p.parse() # Just check the dec file will parse since I do not know # how many decays are in the dec file. assert p.number_of_decays == 356
def test_list_charge_conjugate_decays(): p = DecFileParser(DIR / '../data/test_Bd2DmTauNu_Dm23PiPi0_Tau2MuNu.dec') p.parse() assert p.list_charge_conjugate_decays() == [ 'MyD+', 'MyTau+', 'Mya_1-', 'anti-B0sig' ]
def test_copydecay_statement_parsing(): p = DecFileParser(DIR / "../data/test_CopyDecay_RemoveDecay.dec") p.parse() assert len(p.dict_decays2copy()) == 2 assert p.number_of_decays == 4 # 2 original + 2 copied assert p.list_decay_modes("phi_copy") == p.list_decay_modes("phi")
def test_print_decay_modes(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() with pytest.raises(DecayNotFound): p.print_decay_modes('D*(2010)-') p.print_decay_modes('D*(2010)-', pdg_name=True)
def test_print_decay_modes_basics(): p = DecFileParser(DIR / "../data/test_example_Dst.dec") p.parse() with pytest.raises(DecayNotFound): p.print_decay_modes("D*(2010)-") p.print_decay_modes("D*(2010)-", pdg_name=True)
def test_decay_mode_details(): p = DecFileParser(DIR / "../data/test_example_Dst.dec") p.parse() tree_Dp = p._find_decay_modes("D+")[0] output = (1.0, ["K-", "pi+", "pi+", "pi0"], "PHSP", "") assert p._decay_mode_details(tree_Dp, display_photos_keyword=False) == output
def test_init_non_defaults_basic(): p = DecFileParser(DIR / "../data/test_example_Dst.dec") p.parse() chain = p.build_decay_chains("D*+") dcv = DecayChainViewer(chain, name="TEST", format="pdf") assert dcv.graph.name == "TEST" assert dcv.graph.format == "pdf"
def test_init_non_defaults(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() chain = p.build_decay_chains('D*+') dcv = DecayChainViewer(chain, graph_name='TEST', rankdir='TB') assert dcv.graph.get_name() == 'TEST' assert dcv.graph.get_rankdir() == 'TB'
def test_list_lineshape_definitions(): p = DecFileParser(DIR / '../data/defs-aliases-chargeconj.dec') p.parse() assert p.list_lineshape_definitions() == [ (['D_1+', 'D*+', 'pi0'], 2), (['D_1+', 'D*0', 'pi+'], 2), (['D_1-', 'D*-', 'pi0'], 2), (['D_1-', 'anti-D*0', 'pi-'], 2), (['D_10', 'D*0', 'pi0'], 2), (['D_10', 'D*+', 'pi-'], 2), (['anti-D_10', 'anti-D*0', 'pi0'], 2), (['anti-D_10', 'D*-', 'pi+'], 2) ]
def test_list_decay_modes(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() assert p.list_decay_modes('D*-') == [['anti-D0', 'pi-'], ['D-', 'pi0'], ['D-', 'gamma']] assert p.list_decay_modes('D*(2010)-', pdg_name=True) == [['anti-D0', 'pi-'], ['D-', 'pi0'], ['D-', 'gamma']]
def test_list_charge_conjugate_decays(): p = DecFileParser(DIR / "../data/test_Bd2DmTauNu_Dm23PiPi0_Tau2MuNu.dec") p.parse() assert p.list_charge_conjugate_decays() == [ "MyD+", "MyTau+", "Mya_1-", "anti-B0sig", ]
def test_constructor_multiple_files(): p = DecFileParser(DIR / "../data/test_Xicc2XicPiPi.dec", DIR / "../data/test_Bc2BsPi_Bs2KK.dec") with pytest.warns(UserWarning) as record: p.parse() assert len(record) == 1 assert len(p._dec_file_names) == 2 assert p.number_of_decays == 7
def test_dec_with_new_particle(): """ This decay file is special (at least for now) since the mother particle is not known to the PDG data table. """ p = DecFileParser(DIR / '../data/test_Xicc2XicPiPi.dec') p.parse() assert 'MyantiXic-' in p.list_decay_mother_names() assert 'anti-Xi_cc-sig' not in p.list_decay_mother_names()
def test_pythia_definitions_parsing(): p = DecFileParser(DIR / '../data/defs-aliases-chargeconj.dec') p.parse() assert p.dict_pythia_definitions() == { 'ParticleDecays:mixB': 'off', 'Init:showChangedSettings': 'off', 'Init:showChangedParticleData': 'off', 'Next:numberShowEvent': 0.0 }
def test_pythia_definitions_parsing(): p = DecFileParser(DIR / "../data/defs-aliases-chargeconj.dec") p.parse() assert p.dict_pythia_definitions() == { "ParticleDecays:mixB": "off", "Init:showChangedSettings": "off", "Init:showChangedParticleData": "off", "Next:numberShowEvent": 0.0, }
def test_single_decay(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() chain = p.build_decay_chains('D*+', stable_particles=['D+', 'D0', 'pi0']) dcv = DecayChainViewer(chain) graph_output_as_dot = dcv.to_string() assert 'mother -> dec0 [label="0.677"]' in graph_output_as_dot assert 'mother -> dec1 [label="0.307"]' in graph_output_as_dot assert 'mother -> dec2 [label="0.016"]' in graph_output_as_dot
def test_duplicate_decay_definitions(): p = DecFileParser(DIR / "../data/duplicate-decays.dec") with pytest.warns(UserWarning) as w: p.parse() assert len(w) == 2 assert p.number_of_decays == 2 assert p.list_decay_mother_names() == ["Sigma(1775)0", "anti-Sigma(1775)0"]
def test_creation_charge_conjugate_decays_in_decfile_with_aliases(): """ Decay file contains 5 particle decays defined via a 'Decay' statement and the 5 charge-conjugate decays defined via a 'CDecay' statement. The decay modes for the latter 5 should be created on the fly, hence providing in total 10 sets of particle decays parsed. """ p = DecFileParser(DIR / '../data/test_Bd2DstDst.dec') p.parse() assert p.number_of_decays == 10
def test_single_decay(): p = DecFileParser(DIR / "../data/test_example_Dst.dec") p.parse() chain = p.build_decay_chains("D*+", stable_particles=["D+", "D0", "pi0"]) dcv = DecayChainViewer(chain) graph_output_as_dot = dcv.to_string() assert "mother -> dec0 [label=0.677]" in graph_output_as_dot assert "mother -> dec1 [label=0.307]" in graph_output_as_dot assert "mother -> dec2 [label=0.016]" in graph_output_as_dot
def test_simple_decay_chain(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() chain = p.build_decay_chains('D*+') dcv = DecayChainViewer(chain) graph_output_as_dot = dcv.to_string() assert 'mother -> dec3 [label="0.677"]' in graph_output_as_dot assert 'dec3:p0 -> dec4 [label="1.0"]' in graph_output_as_dot assert 'mother -> dec5 [label="0.307"]' in graph_output_as_dot assert 'dec5:p0 -> dec6 [label="1.0"]' in graph_output_as_dot assert 'dec6:p3 -> dec7 [label="0.988228297"]' in graph_output_as_dot
def test_build_decay_chains(): p = DecFileParser(DIR / '../data/test_example_Dst.dec') p.parse() output = { 'D+': [{ 'bf': 1.0, 'fs': ['K-', 'pi+', 'pi+', 'pi0'], 'model': 'PHSP', 'model_params': '' }] } assert p.build_decay_chains('D+', stable_particles=['pi0']) == output
def test_list_decay_modes_on_the_fly(): """ Unlike in the example above the charge conjugate decay modes are created on the fly from the non-CC. decay. """ p = DecFileParser(DIR / '../data/test_Xicc2XicPiPi.dec') p.parse() # Parsed directly from the dec file assert p.list_decay_modes('MyXic+') == [['p+', 'K-', 'pi+']] # Decay mode created on-the-fly from the above assert p.list_decay_modes('MyantiXic-') == [['anti-p-', 'K+', 'pi-']]