scikit-hep / decaylanguage

Package to parse decay files, describe and convert particle decays between digital representations.
https://decaylanguage.readthedocs.io
BSD 3-Clause "New" or "Revised" License
42 stars 15 forks source link

restore AmpGen2GooFit conversion #298

Closed FlorianReiss closed 1 year ago

FlorianReiss commented 1 year ago

Hello, I would like to use the functionality to convert AmpGen options files to GooFit code.

However, I'm running into issues. For example, trying to do

python3 -m decaylanguage -G goofit  models/DtoKpipipi_v2.txt 

results in

/* Autogenerated file by AmpGen2GooFit
Generated on  2023-01-31 17:28:16.726714

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/freiss/.local/lib/python3.10/site-packages/decaylanguage/__main__.py", line 29, in <module>
    main()
  File "/home/freiss/.local/lib/python3.10/site-packages/decaylanguage/__main__.py", line 25, in main
    DecayLanguageDecay.run()
  File "/home/freiss/.local/lib/python3.10/site-packages/plumbum/cli/application.py", line 634, in run
    retcode = inst.main(*tailargs)
  File "/home/freiss/.local/lib/python3.10/site-packages/decaylanguage/__main__.py", line 21, in main
    ampgen2goofit(filename)
  File "/home/freiss/.local/lib/python3.10/site-packages/decaylanguage/modeling/ampgen2goofit.py", line 40, in ampgen2goofit
    printer(colors.bold | seen_factor, ":", *my_lines[0].spinfactors)
  File "/home/freiss/.local/lib/python3.10/site-packages/decaylanguage/modeling/goofit.py", line 167, in spinfactors
    raise LineFailure(
decaylanguage.utils.errors.LineFailure: D0{K(1)(1270)-[GSpline.EFF]{KPi20[FOCUS.Kpi]{K-,pi+},pi-},pi+}: Spinfactors not currently included!: DtoA1P1_A1toN2P2_N2toP3P4

Trying to understand this, I believe this is caused by some particles in the decay chain having NonDefined or Unknown SpinType. From the particle package:

@property
    def spin_type(self) -> SpinType:
        """
        Access the SpinType enum.
        Note that this is relevant for bosons only. SpinType.NonDefined is returned otherwise.
        """
        # Non-valid or non-standard PDG IDs
        if self.pdgid.j_spin is None:
            return SpinType.NonDefined

        # Fermions - 2J+1 is always an even number
        if self.pdgid.j_spin % 2 == 0:
            return SpinType.NonDefined

        J = int(self.J)
        if J in {0, 1, 2}:
            if self.P == Parity.p:
                return (SpinType.Scalar, SpinType.Axial, SpinType.Tensor)[J]
            if self.P == Parity.m:
                spin_types = (
                    SpinType.PseudoScalar,
                    SpinType.Vector,
                    SpinType.PseudoTensor,
                )
                return spin_types[J]

        return SpinType.Unknown

One place where I noticed this, are the pipi and Kpi S-waves, which are described as quasi-particles in MintDalitzSpecialParticles.csv. In this case, the KPi20 quasi-particle is given the PDGID 998112. In my understanding, the last digit corresponds to 2*j+1, so its spin is 1/2, which I don't think is intended and results in an undefined SpinType.NonDefined. I believe this could be fixed by changing the last digits of the quasi-particles to 1 to represent spin 0. This requires changing another digit to have unique PDGIDs for all of them and I'm not sure which can be safely changed.

Another problematic particle seems to be the K(1460), which seems to have an undefined parity Parity.u and then results in SpinType.Unkown. Here I'm not sure what causes this and how to fix it.

Any help would be greatly appreciated!

eduardo-rodrigues commented 1 year ago

Hello @FlorianReiss . First things first, thank you for the interest in the 2 packages.

The AmpGen/Goofit part of this package is the only one I'm not really familiar with, but let me try and give you a few pointers that may complement what @henryiii may tell you about the submodule.

Though the PDG lists the K(1460) as an established particle, see https://pdglive.lbl.gov/ParticleGroup.action?init=0&node=MXXX020 and https://pdglive.lbl.gov/Particle.action?init=0&node=M021&home=MXXX020, the PDG data table we use to provide particle data information does not contain it yet. That's something that the PDG may be able to explain; I do not know. We do list the particle in our "database", but understandably do not provide unmeasured properties (provided by the PDG data). This is what you see from

>>> p = Particle.from_pdgid(100321)
>>> p
<Particle: name="K(1460)+", pdgid=100321, mass=None>

>>> print(p.describe())
Name: K(1460)+       ID: 100321       Latex: $K(1460)^{+}$
Mass  = None
Width = None
Q (charge)        = +       J (total angular) = 0.0      P (space parity) = None
C (charge parity) = None    I (isospin)       = 0.5      G (G-parity)     = None
    Quarks: uS
    Antiparticle name: K(1460)- (antiparticle status: ChargeInv)

I can dwell on more details, if so I'm happy to talk in person / via Zoom if you welcome that. (We extend the list of particles provided by the PDG via https://github.com/scikit-hep/particle/blob/master/src/particle/data/mass_width_2008_ext.fwf, etc. ...)

But you can easily update properties on the fly, if you want. For example,

>>> p.P = Parity.m
>>> print(p.describe())
Name: K(1460)+       ID: 100321       Latex: $K(1460)^{+}$
Mass  = None
Width = None
Q (charge)        = +       J (total angular) = 0.0      P (space parity) = -
C (charge parity) = None    I (isospin)       = 0.5      G (G-parity)     = None
    SpinType: SpinType.PseudoScalar
    Quarks: uS
    Antiparticle name: K(1460)- (antiparticle status: ChargeInv)

You can even define "user particles", see https://github.com/scikit-hep/particle#advanced-how-to-create-user-defined-particles ...

One of these methods should get you sorted as far as the K(1460) is concerned. Can you "play around" and confirm?

As for your other problem. I did not check but indeed you can edit your MintDalitzSpecialParticles.csv file and change the PDG IDs of particles to suit your needs. You can use the functions in particle.functions to check you encoded the PDG ID OK to obtain the expected spin, parity, etc. The method print(p.describe()) is handy for that, for example.

I hope these give you already some points. Let us know your findings and do not hesitate to suggest updates/fixes as per your investigations. They will be very much appreciated.

eduardo-rodrigues commented 1 year ago

BTW, if you define at some point some user particles, you can update/enhance the standard tables as explained in https://github.com/scikit-hep/particle#advanced-loading-custom-tables.

HTH.

FlorianReiss commented 1 year ago

thanks @eduardo-rodrigues for the very detailed pointers! With that I managed to fix the problems in the parser by modifying the MintDalitzSpecialParticles.csv. I've opened a PR to document the changes https://github.com/scikit-hep/decaylanguage/pull/302

While this works for the moment, I would be happy to discuss how to update the particle properties in the particle package.

I still need to make some changes to make the resulting GooFit code compatible with the current version of GooFit out of the box, but with some manual changes I was able to compile it. Thanks again!

eduardo-rodrigues commented 1 year ago

That's great to hear. As I'm about to be off, please ping me next week and we talk some way or another ... Thanks.

eduardo-rodrigues commented 1 year ago

Hi, I see you keep working on the content of https://github.com/scikit-hep/decaylanguage/pull/302. Let us know when happy with things - maybe your updates require updates to tests as well?

In due time we can talk about Particle, as said.

eduardo-rodrigues commented 1 year ago

Closed via https://github.com/scikit-hep/decaylanguage/pull/302.