Closed shenvitor closed 6 months ago
The previous way to address the problem is possible and not bad.
But now the strategy has changed.
To do the concatenation for each vector in 4-vector one by one, and not do it converted to np.ndarray
then all-in-one and convert back.
"Added" since e.g. p1. px, p1.py, p1.pz, and p1.e is directly a numpy array. Thus no conversion is needed The latest solution for this is something like this
def concatenate_data(
data1: tuple[MomentumNumpy4D, ...],
data2: tuple[MomentumNumpy4D, ...],
) -> tuple[MomentumNumpy4D, ...]:
return tuple(concatenate_vectors((pi1, pj2)) for pi1, pj2 in zip(data1, data2))
def concatenate_vectors(vectors: tuple[MomentumNumpy4D]) -> MomentumNumpy4D:
return vector.array(
{
"px": np.concatenate([p.px for p in vectors]),
"py": np.concatenate([p.py for p in vectors]),
"pz": np.concatenate([p.pz for p in vectors]),
"E": np.concatenate([p.e for p in vectors]),
}
)
Done!
Thus no conversion is needed
Behind the scenes, concatenate_vectors()
is still converting between numpy and the vector
package, so performance-wise this is not a good solution. But for the notebook, this is fine, the implementation in that function can be replaced by a cleaner, more efficient solution later.
Thus no conversion is needed
Behind the scenes,
concatenate_vectors()
is still converting between numpy and thevector
package, so performance-wise this is not a good solution. But for the notebook, this is fine, the implementation in that function can be replaced by a cleaner, more efficient solution later.
Agree. Conversion is still there at the end.
I did not find a way to do Concatenation in 4-momentum objects from
vector
package directlyHere is the temporary solution:
Convert to tuple of numpy
Concatenate via numpy for the tuple of numpy
Convert back to tuple of
vector
objectsJust for the record. Maybe we will be finding a better solution soon(?)