### DaughtersDict Charge Conjugate Example Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/decay.md Demonstrates how to get the charge-conjugate final state using DaughtersDict. It shows handling of EvtGen names and PDG names. ```python >>> dd = DaughtersDict({'K+': 2, 'pi0': 1}) >>> dd.charge_conjugate() >>> >>> dd = DaughtersDict({'K_S0': 1, 'pi0': 1}) >>> dd.charge_conjugate() >>> >>> dd = DaughtersDict({'K(S)0': 1, 'pi+': 1}) # PDG names! >>> # 'K(S)0' unrecognised in charge conjugation unless specified that these are PDG names >>> dd.charge_conjugate() >>> dd.charge_conjugate(pdg_name=True) ``` -------------------------------- ### Install DecayLanguage from PyPI Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/getting_started/installation.md Use pip to install the DecayLanguage package. This command also installs all required Python dependencies. ```bash pip install decaylanguage ``` -------------------------------- ### C++ GooFit Intro Code Example Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/AmpGen2GooFit_D2K3p.ipynb An example of the generated C++ intro code for GooFit, defining particle masses, constants, and decay parameters for a D0 -> K- pi+ pi+ pi- decay. ```cpp // Event type: D0 -> K- (0) pi+ (1) pi+ (2) pi- (3) std::vector> line_factor_list; std::vector> spin_factor_list; std::vector amplitudes_list; constexpr fptype PI_P { 0.13957018 }; constexpr fptype PI_M { 0.13957018 }; constexpr fptype D_0 { 1.86484 }; constexpr fptype K_M { 0.493677 }; Variable K892_0_M { "K892_0_M" , 0.896 }; Variable K892_0_W { "K892_0_W" , 0.0503 }; Variable rho1450_0_M { "rho1450_0_M" , 1.465 }; Variable rho1450_0_W { "rho1450_0_W" , 0.4 }; Variable PiPi0_0_M { "PiPi0_0_M" , 9.99 }; Variable PiPi0_0_W { "PiPi0_0_W" , 9900000 }; Variable PiPi1_0_M { "PiPi1_0_M" , 9.99 }; Variable PiPi1_0_W { "PiPi1_0_W" , 9900000 }; Variable PiPi2_0_M { "PiPi2_0_M" , 9.99 }; Variable PiPi2_0_W { "PiPi2_0_W" , 9900000 }; Variable PiPi3_0_M { "PiPi3_0_M" , 9.99 }; Variable PiPi3_0_W { "PiPi3_0_W" , 9900000 }; Variable K11400_m_M { "K11400_m_M" , 1.403 }; Variable K11400_m_W { "K11400_m_W" , 0.174 }; Variable KPi0_0_M { "KPi0_0_M" , 9.99 }; Variable KPi0_0_W { "KPi0_0_W" , 9900000 }; Variable omega782_0_M { "omega782_0_M" , 0.78265 }; Variable omega782_0_W { "omega782_0_W" , 0.00849 }; Variable KPi2_0_M { "KPi2_0_M" , 9.99 }; Variable KPi2_0_W { "KPi2_0_W" , 9900000 }; Variable KPi1_0_M { "KPi1_0_M" , 9.99 }; Variable KPi1_0_W { "KPi1_0_W" , 9900000 }; Variable K1460_m_M { "K1460_m_M" , 1.46 }; Variable K1460_m_W { "K1460_m_W" , 0.26 }; Variable K11270_m_M { "K11270_m_M" , 1.272 }; Variable K11270_m_W { "K11270_m_W" , 0.09 }; Variable rho770_0_M { "rho770_0_M" , 0.77549 }; Variable rho770_0_W { "rho770_0_W" , 0.1494 }; Variable a11260_p_M { "a11260_p_M" , 1.23 }; Variable a11260_p_W { "a11260_p_W" , 0.42 }; Variable K2_m_M { "K2_m_M" , 1.4256 }; Variable K2_m_W { "K2_m_W" , 0.0985 }; DK3P_DI.meson_radius = 5; DK3P_DI.particle_masses = {D_0, K_M, PI_P, PI_P, PI_M}; ``` -------------------------------- ### Accessing DecayLanguage Data Files Source: https://github.com/scikit-hep/decaylanguage/blob/main/src/decaylanguage/data/README.rst Demonstrates how to reliably access data files within the DecayLanguage package, regardless of installation method. Use joinpath to get the file path and open() to read its content. ```python import decaylanguage.data with decaylanguage.data.joinpath("DECAY_LHCB.DEC").open() as f: content = f.read() print(content) ``` -------------------------------- ### C++ GooFit Parameters Example Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/AmpGen2GooFit_D2K3p.ipynb An example of the generated C++ GooFit parameters, defining variables for interference terms (IS_pX_...) and masses. These parameters are crucial for the amplitude model. ```cpp Variable D0_radius {"D0_radius", 0.0037559 }; Variable IS_p1_4pi {"IS_p1_4pi", 0 }; Variable IS_p1_EtaEta {"IS_p1_EtaEta", -0.39899 }; Variable IS_p1_EtapEta {"IS_p1_EtapEta", -0.34639 }; Variable IS_p1_KK {"IS_p1_KK", -0.55377 }; Variable IS_p1_mass {"IS_p1_mass", 0.651 }; Variable IS_p1_pipi {"IS_p1_pipi", 0.22889 }; Variable IS_p2_4pi {"IS_p2_4pi", 0 }; Variable IS_p2_EtaEta {"IS_p2_EtaEta", 0.39065 }; Variable IS_p2_EtapEta {"IS_p2_EtapEta", 0.31503 }; Variable IS_p2_KK {"IS_p2_KK", 0.55095 }; Variable IS_p2_mass {"IS_p2_mass", 1.2036 }; Variable IS_p2_pipi {"IS_p2_pipi", 0.94128 }; Variable IS_p3_4pi {"IS_p3_4pi", 0.55639 }; Variable IS_p3_EtaEta {"IS_p3_EtaEta", 0.1834 }; Variable IS_p3_EtapEta {"IS_p3_EtapEta", 0.18681 }; Variable IS_p3_KK {"IS_p3_KK", 0.23888 }; Variable IS_p3_mass {"IS_p3_mass", 1.55817 }; Variable IS_p3_pipi {"IS_p3_pipi", 0.36856 }; Variable IS_p4_4pi {"IS_p4_4pi", 0.85679 }; Variable IS_p4_EtaEta {"IS_p4_EtaEta", 0.19906 }; Variable IS_p4_EtapEta {"IS_p4_EtapEta", -0.00984 }; Variable IS_p4_KK {"IS_p4_KK", 0.40907 }; Variable IS_p4_mass {"IS_p4_mass", 1.21 }; ``` -------------------------------- ### Install DecayLanguage with Modeling Submodule Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/index.md Install DecayLanguage along with its optional modeling submodule dependencies (NumPy, pandas, plumbum) using pip. ```bash pip install "decaylanguage[modeling]" ``` -------------------------------- ### AmpGen Model Definition Example Source: https://github.com/scikit-hep/decaylanguage/blob/main/src/decaylanguage/modeling/AmpGenReader.ipynb This is an example of an AmpGen model definition file. It specifies decay chains and particle properties. ```text /* Autogenerated file by AmpGen2GooFit Generated on 2018-08-08 09:45:23.927978 Momentum transfer definitions: DtoS1S2_S1toP1P2_S2toP3P4 : SF_4Body.ONE D0{KPi00[FOCUS.I32]{K-,pi+},PiPi00[kMatrix.pole.1]{pi+,pi-}} D0{KPi00[FOCUS.I32]{K-,pi+},PiPi00[kMatrix.prod.0]{pi+,pi-}} D0{KPi00[FOCUS.KEta]{K-,pi+},PiPi00[kMatrix.pole.1]{pi+,pi-}} D0{KPi00[FOCUS.KEta]{K-,pi+},PiPi00[kMatrix.prod.0]{pi+,pi-}} D0{KPi00[FOCUS.Kpi]{K-,pi+},PiPi00[kMatrix.pole.1]{pi+,pi-}} D0{KPi00[FOCUS.Kpi]{K-,pi+},PiPi00[kMatrix.prod.0]{pi+,pi-}} DtoV1V2_V1toP1P2_V2toP3P4_D : SF_4Body.DtoV1V2_V1toP1P2_V2toP3P4_D SF_4Body.FF_12_34_L2 D0[D]{K(892)~0{K-,pi+},rho(770)0{pi+,pi-}} D0[D]{rho(1450)0{pi+,pi-},K(892)~0{K-,pi+}} DtoV1S2_V1toP1P2_S2toP3P4 : SF_4Body.DtoVS_VtoP1P2_StoP3P4 SF_4Body.FF_12_34_L1 D0{K(892)~0{K-,pi+},PiPi10[kMatrix.pole.1]{pi+,pi-}} D0{K(892)~0{K-,pi+},PiPi10[kMatrix.prod.0]{pi+,pi-}} D0{rho(770)0{pi+,pi-},KPi10[FOCUS.I32]{K-,pi+}} D0{rho(770)0{pi+,pi-},KPi10[FOCUS.Kpi]{K-,pi+}} DtoA1P1_A1toV2P2_V2toP3P4 : SF_4Body.DtoAP1_AtoVP2Dwave_VtoP3P4 SF_4Body.FF_123_4_L1 D0{K(1)(1270)~-[GSpline.EFF]{K(892)~0{K-,pi+},pi-},pi+} D0{K(1)(1270)~-[GSpline.EFF]{omega(782)0{pi+,pi-},K-},pi+} D0{K(1)(1270)~-[GSpline.EFF]{rho(1450)0{pi+,pi-},K-},pi+} D0{K(1)(1270)~-[GSpline.EFF]{rho(770)0{pi+,pi-},K-},pi+} D0{K(1)(1400)~-{K(892)~0{K-,pi+},pi-},pi+} D0{a(1)(1260)+[GSpline.EFF]{rho(770)0{pi+,pi-},pi+},K-} DtoV1V2_V1toP1P2_V2toP3P4_P : SF_4Body.DtoV1V2_V1toP1P2_V2toP3P4_P SF_4Body.FF_12_34_L1 D0[P]{K(892)~0{K-,pi+},rho(770)0{pi+,pi-}} D0[P]{rho(1450)0{pi+,pi-},K(892)~0{K-,pi+}} DtoT1P1_T1toV2P2_V2toP3P4 : SF_4Body.DtoTP1_TtoVP2_VtoP3P4 SF_4Body.FF_123_4_L2 D0{K(2)~-{K(892)~0{K-,pi+},pi-},pi+} Momentum transfer definitions: DtoV1V2_V1toP1P2_V2toP3P4 : SF_4Body.DtoV1V2_V1toP1P2_V2toP3P4_S D0{K(892)~0{K-,pi+},rho(770)0{pi+,pi-}} D0{rho(1450)0{pi+,pi-},K(892)~0{K-,pi+}} Dtos1P1_s1toV2P2_V2toP3P4 : SF_4Body.DtoPP1_PtoVP2_VtoP3P4 D0{K(1460)~-[GSpline.EFF]{K(892)~0{K-,pi+},pi-},pi+} Dtos1P1_s1toS2P2_S2toP3P4 : SF_4Body.DtoPP1_PtoSP2_StoP3P4 D0{K(1460)~-[GSpline.EFF]{PiPi30[kMatrix.pole.0]{pi+,pi-},K-},pi+} D0{K(1460)~-[GSpline.EFF]{PiPi30[kMatrix.pole.1]{pi+,pi-},K-},pi+} D0{K(1460)~-[GSpline.EFF]{PiPi30[kMatrix.prod.1]{pi+,pi-},K-},pi+} DtoA1P1_A1toV2P2Dwave_V2toP3P4 : SF_4Body.DtoAP1_AtoVP2Dwave_VtoP3P4 SF_4Body.FF_123_4_L1 D0{K(1)(1270)~-[D;GSpline.EFF]{K(892)~0{K-,pi+},pi-},pi+} D0{a(1)(1260)+[D;GSpline.EFF]{rho(770)0{pi+,pi-},pi+},K-} DtoA1P1_A1toS2P2_S2toP3P4 : SF_4Body.DtoAP1_AtoSP2_StoP3P4 SF_4Body.FF_123_4_L1 D0{K(1)(1270)~-[GSpline.EFF]{KPi20[FOCUS.Kpi]{K-,pi+},pi-},pi+} D0{a(1)(1260)+[GSpline.EFF]{PiPi20[kMatrix.pole.0]{pi+,pi-},pi+},K-} D0{a(1)(1260)+[GSpline.EFF]{PiPi20[kMatrix.pole.1]{pi+,pi-},pi+},K-} D0{a(1)(1260)+[GSpline.EFF]{PiPi20[kMatrix.prod.0]{pi+,pi-},pi+},K-} Scalar: PiPi00 PiPi10 PiPi20 PiPi30 KPi00 KPi10 KPi20 PseudoScalar: pi+ pi- K- D0 K(1460)~- Vector: rho(770)0 omega(782)0 K(892)~0 rho(1450)0 Axial: K(1)(1270)~- a(1)(1260)+ K(1)(1400)~- Tensor: K(2)~- PseudoTensor: Unknown: ``` -------------------------------- ### Get Pythia Definitions Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Returns a dictionary of Pythia 8 commands categorized by their application (generic, alias, or both). Commands are defined in the input file using specific syntax. ```default {"PythiaAliasParam": {':': 'LABEL1', ':': VALUE2, ...}, "PythiaBothParam": {':': 'LABEL3', ':': VALUE4, ...}, "PythiaGenericParam": {':': 'LABEL5', ':': VALUE6, ...}}. ``` -------------------------------- ### Convert to GooFit Format Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/index.md Provides an example of how to convert decay chain data to the GooFit format using the command-line interface. This is useful for integrating with external analysis tools. ```bash python -m decaylanguage -G goofit myinput.opts ``` -------------------------------- ### Get Known Decay Models Source: https://github.com/scikit-hep/decaylanguage/blob/main/README.md Import and inspect the list of known decay models supported by the decaylanguage package. ```python from decaylanguage.dec import known_decay_models ``` -------------------------------- ### Print Decay Chain as String and ASCII Tree Source: https://github.com/scikit-hep/decaylanguage/blob/main/README.md Illustrates how to get a one-line string representation and an ASCII tree visualization of a DecayChain object. ```python print(dc.to_string()) ``` ```python dc.print_as_tree() ``` -------------------------------- ### Render Decay Chain Graph with Graphviz Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/decay.md Illustrates how to render the decay chain graph to a file (e.g., PDF) using the `graphviz` library when not in a notebook environment. This requires the `graphviz` package to be installed. ```python >>> dcv.graph.render(filename=”test”, format=”pdf”, view=True, cleanup=True) # doctest: +SKIP ``` -------------------------------- ### Generate and display decay tree PNG Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/ExampleDecFileParsingWithLark.ipynb Uses Lark's `pydot__tree_to_png` to generate a PNG image of the first decay tree found and displays it. Requires `pydot` to be installed. ```Python from IPython.display import Image from lark.tree import pydot__tree_to_png # requires pydot pydot__tree_to_png( list_of_decay_trees(parsed_dec_file)[0], filename="decay.png", rankdir="LR" ) Image(filename="decay.png") ``` -------------------------------- ### Get Lineshape Settings Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Returns a dictionary of all lineshape settings, keyed by particle names or aliases. Sub-dictionaries may contain varying keys for lineshape, Blatt-Weisskopf, and mass range settings. ```default { PARTICLE1: {'lineshape': 'NAME1', # E.g. "LSFLAT" or "LSNONRELBW" 'BlattWeisskopf': VALUE1, 'ChangeMassMin': VALUE12, 'ChangeMassMax': VALUE13}, PARTICLE2: {'lineshape': 'NAME2', 'BlattWeisskopf': VALUE2, 'ChangeMassMin': VALUE22, 'ChangeMassMax': VALUE23, 'IncludeBirthFactor': TRUE_OR_FALSE, 'IncludeDecayFactor': TRUE_OR_FALSE}, ... } ``` -------------------------------- ### Define Lineshapes for kMatrix (prod.0) Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/AmpGen2GooFit_D2K3p.ipynb This snippet defines lineshape functions, specifically using kMatrix with different parameters (prod.0) compared to the previous example, for constructing decay amplitudes. ```cpp line_factor_list.push_back(std::vector{ new Lineshapes::GSpline("a(1)(1260)+", a11260_p_M, a11260_p_W, 1, M_24, FF::BL2, 1.5, a11260p_SplineArr, Lineshapes::spline_t(0.18412,1.9,40)), new Lineshapes::kMatrix("PiPi20", 0, false, sA0, sA, s0_prod, s0_scatt, f_scatt, IS_poles, PiPi2_0_M, PiPi2_0_W, 0, M_24, FF::BL2, 1.5), new Lineshapes::GSpline("a(1)(1260)+", a11260_p_M, a11260_p_W, 1, M_34, FF::BL2, 1.5, a11260p_SplineArr, Lineshapes::spline_t(0.18412,1.9,40)), new Lineshapes::kMatrix("PiPi20", 0, false, sA0, sA, s0_prod, s0_scatt, f_scatt, IS_poles, PiPi2_0_M, PiPi2_0_W, 0, M_34, FF::BL2, 1.5) }); ``` -------------------------------- ### Initialize and Display DecayChainViewer Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/decay.md Demonstrates initializing the `DecayChainViewer` class with a parsed decay chain. This viewer is used for visualizing decay chains, particularly within notebook environments. ```python >>> dfp = DecFileParser('my-Dst-decay-file.dec') >>> dfp.parse() >>> chain = dfp.build_decay_chains('D*+') >>> dcv = DecayChainViewer(chain) >>> # display the SVG figure in a notebook >>> dcv ``` -------------------------------- ### Create and Inspect a Class-Based Decay Chain Source: https://github.com/scikit-hep/decaylanguage/blob/main/README.md Demonstrates how to create a DecayChain object using DecayMode and DecayChain classes. Shows how to inspect the created chain. ```python from decaylanguage import DaughtersDict, DecayMode, DecayChain dm1 = DecayMode(0.0124, 'K_S0 pi0', model='PHSP') dm2 = DecayMode(0.692, 'pi+ pi-') dm3 = DecayMode(0.98823, 'gamma gamma') dc = DecayChain('D0', {'D0':dm1, 'K_S0':dm2, 'pi0':dm3}) print(dc) ``` -------------------------------- ### Instantiate and Parse DecFileParser Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Instantiate the DecFileParser with decay file names and then parse the file content. Ensure the 'my-decay-file.dec' exists in the specified path. ```python >>> dfp = DecFileParser('my-decay-file.dec') >>> dfp.parse() ``` -------------------------------- ### Get Global Photos Flag Status Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Determines if the PHOTOS package is enabled globally for all decays. Returns PhotosEnum.yes or PhotosEnum.no. ```python from decaylanguage.enums import PhotosEnum # Example usage (assuming parsed_file is available): # global_photos_status = get_global_photos_flag(parsed_file) # print(global_photos_status) ``` -------------------------------- ### Parse and Build Decay Chains Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Demonstrates parsing a .dec file and building decay chains for a specified particle. It shows how to retrieve decay information including branching fractions, final states, and decay models. ```python >>> parser = DecFileParser('a-Dplus-decay-file.dec') >>> parser.parse() >>> parser.build_decay_chains('D+') {'D+': [{'bf': 1.0, 'fs': ['K-', 'pi+', 'pi+', {'pi0': [{'bf': 0.988228297, 'fs': ['gamma', 'gamma'], 'model': 'PHSP', 'model_params': ''}, {'bf': 0.011738247, 'fs': ['e+', 'e-', 'gamma'], 'model': 'PI0_DALITZ', 'model_params': ''}, {'bf': 3.3392e-05, 'fs': ['e+', 'e+', 'e-', 'e-'], 'model': 'PHSP', 'model_params': ''}, {'bf': 6.5e-08, 'fs': ['e+', 'e-'], 'model': 'PHSP', 'model_params': ''}]}], 'model': 'PHSP', 'model_params': ''}]} >>> p.build_decay_chains('D+', stable_particles=['pi0']) {'D+': [{'bf': 1.0, 'fs': ['K-', 'pi+', 'pi+', 'pi0'], 'model': 'PHSP', 'model_params': ''}]} ``` -------------------------------- ### Get Decay Model Parameters Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieves the parameters associated with a decay model. This is essential for using models like LbAmpGen. ```default Decay MyB_s0 1.000 K+ K- SSD_CP 20.e12 0.1 1.0 0.04 9.6 -0.8 8.4 -0.6; Enddecay ``` ```default Decay MyD0 1.00 K- pi- pi+ pi+ LbAmpGen DtoKpipipi_v1 ; Enddecay ``` -------------------------------- ### Create and Print Decay Chain Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/decay.md Demonstrates how to create a DecayChain instance with multiple nested decay modes and print its one-line string representation. ```python dm1 = DecayMode(0.6770, "D0 pi+") # D*+ dm2 = DecayMode(0.0124, "K_S0 pi0") # D0 dm3 = DecayMode(0.692, "pi+ pi-") # K_S0 dm4 = DecayMode(0.98823, "gamma gamma") # pi0 dc = DecayChain("D*+", {"D*+":dm1, "D0":dm2, "K_S0":dm3, "pi0":dm4}) print(dc.to_string()) ``` -------------------------------- ### Get JetSet Definitions Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieves a dictionary of all JETSET definitions from the input parsed file. Definitions are structured by module and parameter. ```default {'MODULE1': {PARAMETER1: VALUE1, PARAMETER2: VALUE2, ...}, 'MODULE2': {...}, ...}. ``` -------------------------------- ### Get Define Statements Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieve a dictionary of all 'Define' statements from the parsed file. The dictionary maps the defined name to its corresponding value. ```python >>> dfp.dict_definitions() ``` -------------------------------- ### Get CopyDecay Statements Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieve a dictionary of all 'CopyDecay' statements from the parsed file. The dictionary maps the decay name to the decay it copies. ```python >>> dfp.dict_decays2copy() ``` -------------------------------- ### Create and Inspect a Decay Chain Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/index.md Demonstrates how to create a DecayChain object from DecayMode objects and inspect its properties. Requires importing DecayMode and DecayChain. ```python >>> from decaylanguage import DaughtersDict, DecayMode, DecayChain >>> >>> dm1 = DecayMode(0.0124, 'K_S0 pi0', model='PHSP') >>> dm2 = DecayMode(0.692, 'pi+ pi-') >>> dm3 = DecayMode(0.98823, 'gamma gamma') >>> dc = DecayChain('D0', {'D0':dm1, 'K_S0':dm2, 'pi0':dm3}) >>> dc K_S0 pi0 (2 sub-decays), BF=0.0124> ``` -------------------------------- ### Visualize Decay Chains for D*+ Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/DecayLanguageDemo.ipynb Initializes a DecayChainViewer with the built decay chains for 'D*+'. This visualizes the decay tree for this particle. ```python d = parser.build_decay_chains("D*+") DecayChainViewer(d) ``` -------------------------------- ### Get Charge Conjugate Decay Mode Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/decay.md Returns the charge-conjugate decay mode. Can optionally use PDG names for input particles. ```python >>> dm = DecayMode(1.0, 'K+ K+ pi-') >>> dm.charge_conjugate() >>> >>> dm = DecayMode(1.0, 'K_S0 pi+') >>> dm.charge_conjugate() >>> >>> dm = DecayMode(1.0, 'K(S)0 pi+') # PDG names! >>> dm.charge_conjugate(pdg_name=True) ``` -------------------------------- ### Run All Project Checks with Nox Source: https://github.com/scikit-hep/decaylanguage/blob/main/CONTRIBUTING.rst Execute all project checks, including tests, documentation builds, and spell checks, using the nox tool. ```bash nox ``` -------------------------------- ### Amplitude Definition Example Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/DecayLanguageDemo.ipynb Defines a particle decay amplitude with specific resonances and parameters. This is typically used in advanced decay modeling scenarios. ```C++ amplitudes_list.push_back(new Amplitude{ "D0[P]{rho(1450)0{pi+,pi-},K*(892)~0{K-,pi+}}", mkvar("D0[P]{rho(1450)0{pi+,pi-},K*(892)~0{K-,pi+}}_r", true, -0.0817223, 0.00506033), mkvar("D0[P]{rho(1450)0{pi+,pi-},K*(892)~0{K-,pi+}}_i", true, 0.637565, 0.648409), line_factor_list.back(), spin_factor_list.back(), 2}); DK3P_DI.amplitudes_B.push_back(amplitudes_list.back()); ``` -------------------------------- ### Get Charge Conjugate Statements Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieve a dictionary of all 'ChargeConj' statements. The dictionary maps a particle name to its charge conjugate particle name. ```python >>> dfp.dict_charge_conjugates() ``` -------------------------------- ### Clone DecayLanguage Repository Source: https://github.com/scikit-hep/decaylanguage/blob/main/CONTRIBUTING.rst Clone your fork of the DecayLanguage repository locally to begin development. ```bash git clone git@github.com:your_name_here/decaylanguage.git ``` -------------------------------- ### Visualize Decay Chains Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/DecayLanguageDemo.ipynb Initializes a DecayChainViewer with the built decay chains for 'D+'. This allows for interactive visualization of the decay tree. ```python DecayChainViewer(d) ``` -------------------------------- ### Get Alias Statements Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieve a dictionary of all 'Alias' statements from the parsed file. The dictionary maps an alias name to the particle name it represents. ```python >>> dfp.dict_aliases() ``` -------------------------------- ### Get Grammar Information Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Obtain the filename of the internal Lark grammar and the parser options. Similar to `grammar()`, this loads the default grammar if necessary. ```python >>> dfp.grammar_info() ``` -------------------------------- ### dict_pythia_definitions() Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Returns a dictionary of all Pythia 8 commands (GenericParam, AliasParam, BothParam) found in the parsed file. The dictionary is structured by command type. ```APIDOC ## dict_pythia_definitions() ### Description Return a dictionary of all Pythia 8 commands ‘PythiaGenericParam’ and/or ‘PythiaAliasParam’ and/or ‘PythiaBothParam’, with keys corresponding to the 3 types specifying whether the command is for generic decays, alias decays, or both. ### Return type dict[str, dict[str, str | float]] ``` -------------------------------- ### dict_lineshape_settings() Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Returns a dictionary containing all lineshape settings for particles or aliases. The dictionary includes keys like 'lineshape', 'BlattWeisskopf', 'ChangeMassMin', 'ChangeMassMax', and 'IncludeBirthFactor'/'IncludeDecayFactor' where applicable. ```APIDOC ## dict_lineshape_settings() ### Description Return a dictionary of all lineshape settings, with keys corresponding to particle names or aliases. ### Return type dict[str, dict[str, str | float]] ``` -------------------------------- ### Get Lineshape Parameter Definitions List Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Extracts all SetLineshapePW definitions from a parsed decay file. Each definition includes the mother and daughter particles, and a value. ```default [(['MOTHER1', 'DAUGHTER1-1', 'DAUGHTER1-2'], VALUE1), (['MOTHER2', 'DAUGHTER2-1', 'DAUGHTER2-2'], VALUE2), ... ] ``` -------------------------------- ### Get Final State Particles from Decay Mode Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Extracts the list of final-state particles from a decay line tree. This is useful for analyzing the decay products. ```default Decay MyB_s0 1.000 K+ K- SSD_CP 20.e12 0.1 1.0 0.04 9.6 -0.8 8.4 -0.6; Enddecay ``` -------------------------------- ### Run a Subset of Tests with Nox Source: https://github.com/scikit-hep/decaylanguage/blob/main/CONTRIBUTING.rst Execute a subset of tests by specifying a marker expression using the -k flag with nox. ```bash nox -s tests-3.9 -- -k test_myfeature ``` -------------------------------- ### Discover Spin Configurations Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/AmpGen2GooFit_D2K3p.ipynb Prints all discovered spin configurations for a 4-body decay. Useful for understanding the possible spin states in the amplitude model. ```python colors.bold.print("All discovered spin configurations:") for e in SF_4Body: print(e.name) ``` -------------------------------- ### Get Lineshape PW Definitions Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieves a list of all SetLineshapePW definitions from the parsed file. Each entry includes the mother particle, daughter particles, and a value. ```default [ (['MOTHER1', 'DAUGHTER1-1', 'DAUGHTER1-2'], VALUE1), (['MOTHER2', 'DAUGHTER2-1', 'DAUGHTER2-2'], VALUE2), ... ] ``` -------------------------------- ### Import ampgen2goofit utility Source: https://github.com/scikit-hep/decaylanguage/blob/main/src/decaylanguage/modeling/AmpGenReader.ipynb Import the necessary function from the decaylanguage library. This function is used to perform the conversion. ```python from __future__ import annotations from decaylanguage.modeling.ampgen2goofit import ampgen2goofit ``` -------------------------------- ### Get Model Alias Statements Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieve a dictionary of all 'ModelAlias' statements. The dictionary maps an alias name to a list containing the model name and its options. ```python >>> dfp.dict_model_aliases() ``` -------------------------------- ### Get Dictionary of Aliases Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/DecayLanguageDemo.ipynb Retrieves a dictionary of aliases defined within the parsed DecFile. This can be useful for understanding shorthand notations used in the decay file. ```python parser.dict_aliases() ``` -------------------------------- ### Get Lineshape Settings Dictionary Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Retrieves all lineshape settings from a parsed decay file. Keys are particle names or aliases, with nested dictionaries for lineshape parameters. ```default {PARTICLE1: {'lineshape': 'NAME1', # E.g. "LSFLAT" or "LSNONRELBW" 'BlattWeisskopf': VALUE11, 'ChangeMassMin': VALUE12, 'ChangeMassMax': VALUE13}, PARTICLE2: {'lineshape': 'NAME2', 'BlattWeisskopf': VALUE21, 'ChangeMassMin': VALUE22, 'ChangeMassMax': VALUE23, 'IncludeBirthFactor': TRUE_OR_FALSE, 'IncludeDecayFactor': TRUE_OR_FALSE}, ... } ``` -------------------------------- ### Generate GooFit Intro Code Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/AmpGen2GooFit_D2K3p.ipynb Generates the introductory C++ code for GooFit, including event type, particle masses, and decay channel definitions. This code is essential for setting up the GooFit amplitude analysis environment. ```python print(GooFitChain.make_intro(all_states)) ``` -------------------------------- ### Build Decay Chains for a Particle Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/DecayLanguageDemo.ipynb Builds a hierarchical representation of decay chains starting from a specified particle ('D+'). This is useful for visualizing complex decay processes. ```python d = parser.build_decay_chains("D+") d ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/scikit-hep/decaylanguage/blob/main/CONTRIBUTING.rst Stage all changes, commit them with a descriptive message, and push the branch to GitHub. ```bash git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Initialize DecFileParser with Large File Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/DecayLanguageDemo.ipynb Initializes the DecFileParser with a large DecFile, such as the LHCb main file. This sets up the parser to read a substantial amount of decay data. ```python from decaylanguage import data parser = DecFileParser(data.basepath / "DECAY_LHCB.DEC") parser ``` -------------------------------- ### Expand Decay Modes Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/index.md Get the fully expanded list of decay descriptors for a particle, resolving all sub-decays down to final states. Aliases are reverted to original EvtGen names. ```python dfp.expand_decay_modes('D*+') ``` -------------------------------- ### Apply Charge Conjugate Replacement to Decay Tree Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/api/dec.md Demonstrates how to use the ChargeConjugateReplacement visitor to transform a decay tree, replacing particles with their charge conjugates. ```python >>> from lark import Tree, Token >>> ... >>> t = Tree('decay', [Tree('particle', [Token('LABEL', 'D0')]), Tree('decayline', [Tree ('value', [Token('SIGNED_NUMBER', '1.0')]), Tree('particle', [Token('LABEL', 'K-')]), Tree('particle', [Token('LABEL', 'pi+')]), Tree('model', [Token('MODEL_NAME', 'PHSP')])])]) >>> ChargeConjugateReplacement().visit(t) Tree('decay', [Tree('particle', [Token('LABEL', 'anti-D0')]), Tree('decayline', [Tree('value', [Token('SIGNED_NUMBER', '1.0')]), Tree('particle', [Token('LABEL', 'K+')]), Tree('particle', [Token('LABEL', 'pi-')]), Tree('model', [Token('MODEL_NAME', 'PHSP')])])]) ``` -------------------------------- ### List Known Spin Configurations Source: https://github.com/scikit-hep/decaylanguage/blob/main/notebooks/AmpGen2GooFit_D2K3p.ipynb Prints all known spin configurations for a specific decay channel. This helps in identifying the available amplitude model components. ```python colors.bold.print("All known spin configurations:") for e in SF_4Body: print(e.name) ``` -------------------------------- ### Convert AmpGen to GooFit and Save to File (Command-line) Source: https://github.com/scikit-hep/decaylanguage/blob/main/docs/examples/amplitude_models.md This command converts an AmpGen model file to GooFit format and redirects the output to a file named 'output.cu'. ```bash python -m decaylanguage.goofit models/DtoKpipipi_v2.txt > output.cu ```