-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion: algebra, and constructor #13
Comments
Let me write down three applications that can benefit from this interface (i.e. save code a downstream developer needs to write), they have different goals and thus demand different set of things from this LVBase package, we should think about what trade-off we want to make: 1. Particle genThis is @szabo137 's original application, imagine you have: struct GenParticle
lv::LV
pdgID:Int
isSUSY::Bool
...
end Clearly in this case, demanding 2. Jet clusteringThis is @grasph 's original application in mind, Philippe wants to write a jet clustering algorithm that can take any jets satisfying the interface, which clearly needs 3. AnalysisThis is an example I learned from @pviscone by looking at what scikit-hep has, when people read nanoAOD from CMS and loads up muon/electron etc., it's possible to defined the "behavior" of the collection. And one of the possible behavior involves adding muons and muons, that roughly looks like: struct Muon <: CMSParticle
lv::LV
charge::Int8
end in this case, it's reasonable to defined SummaryOne argument is to say "LV is LV, particle is particle", but I can sympathize with people who scratch their heads and think "it's just LV, why it's so damn complicated". After all we're doing some practical physics, not trying to use these LVs for mathematical proof...
|
thinking a bit more, I'd be in favor of keeping this package minimal: no arithmetic, no transformations, no constraints to constructor. |
I agree with you, therefore I proposed a compromise here. With this, the package stays light weight, yet keeps the possibility for library developer to require arithmetics via the |
About the constructorThe We need to add to the list of functions to implements for compliance with the interface (I will use LVB as shortcut of LorentzVectorBase):
and this method must return a Callable defined as:
with This method will allow the development of packages that provides transformation of Lorentz-vector-like objects e.g. boost and rotation. ❓ Can the dependency of the callable returned by About the arithmeticThe behaviour of a function acting on AbstractLorentzVectors and using the arithmetic defined by the subtypes will depend on their implementation, unless:
An example of definition can be defining the sum p+q (resp. the difference p-q) as the object p with the Lorentz vector of q added (resp. subtracted) to the Lorentz vector of p. In addition to the + and - operations we discussed at the hackatron, we need matrix multiplication to make it useful. This totals to 6 methods: If I define a Particle type and desire to use the boost function of an algorithm package relying on the AbstractLorentzVector interface, the number of methods to implement to use the package will definitely discourage me and I will implement my own boost function. Therefore, I would prefer other developers to not rely on me to implement the arithmetic. I don't have examples of algorithms, when the component accessors defined by our interface, together with the materializer() method, will not be sufficient. I am not convinced by the "compromise". It comes from an attempt to reconcile two orthogonal views: subtyping AbstactLorentzVector to benefit from default overrides of Base operators (the original idea), and subtyping to define an interface. @oliver was advocating that subtyping is absolutely needed. I would need an example where the inheritance-free interface does not work, in order to understand if this package can and should solve the case. It might be that what we actual need is an abstract type for pure Lorentz vectors. I'm also adding @graeme-a-stewart to the discussion. |
I wonder, conceptually, do we to want to implement transformations (boosts, rotations)? - naively, if I have an object that is a Lorentz vector, I know how to boost, and rotate. How often, different applications would need to do something different (additional) when I'd benefit from having this functions inside the LVB package. Some mechanism like @grasph, I do not fully follow, what is a type of
i.e. how to pass the "minimal" Lorentz vector information to For arithmetic, I do not see how we can define it, but I also do not fully follow the proposal. |
In the definition example I gave, only the Lorentz vector properties are summed, and other properties, if any, are copied from the 1st argument, which takes a special place. I would like to make a proposal which is for me more satisfactory.
This will looks like this for abstract type AbtractLorentzVector end
# Note: if we go that way, I would prefer to use the shorter name
# PxPyPzE for the vector and the longer name e.g., PxPyPzECoord
# for the coordinate system.
struct PxPyPzEVec{T} <: AbtractLorentzVector
px::T
py::T
pz::T
energy::T
end
# Constructor from any type compliant with the kinematic interface
PxPyPzEVec(q) = PxPyPzEVec(px(q), py(q), pz(q), energy(q))
const XYZTVec{T} = PxPyPzEVec{T}
px(p::PxPyPzEVec) = p.px
py(p::PxPyPzEVec) = p.py
pz(p::PxPyPzEVec) = p.pz
energy(p::PxPyPzEVec) = p.energy
coordinate_system(PxPyPzEVec) = PxPyPzE
# Similar definitions for PtEtaPhiEVec{T}, PtEtaPhiMVec{T}
# ....
function Base.:+(p::Any, q::AbstractLorentzVector)
px = px(p) + px(q)
py = py(p) + py(q)
pz = pz(p) + pz(q)
energy = energy(p) + energy(q)
materializer(p)(PxPyPzEVec(px, py, pz, energy))
end
# And possibly we define also (not clear to me if we should):
Base.:+(q::AbstractLorentzVector, p::Any) = Base.:+(p::Any, q::AbstractLorentzVector)
Note: I think we need to require in the kinematic interface that all component accessors (px(), py(), pz(), energy() in case of PxPyPzE coordinate) return elements of the same type. In the above code, the ctor of PxPyPzEVec(::Any) assumes this. We could relax the requirements by asking that either they have the same type or |
Items braught up by @grasph
if we want to provide a default algebra implementation, then we need an abstract supertype is order to override the Base package operators. We could make inheritance from a
LorentzVectorBase
abstract type as optional.Constructor from a
LorentzVector
. The constructor will need to take an argument of any type. It's probably ok. TheTable.jl
interface has amaterializer()
method that returns the "constructor". Maybe there is a reason for doing this way?The text was updated successfully, but these errors were encountered: