<p>我给开发者发了邮件,这是回复。你知道吗</p>
<p>使用swig的LCIO的python绑定在很久以前就已经停止了,它们与pyLCIO没有任何关系,因此您发现的文档是不相关的。你知道吗</p>
<p>pyLCIO构建在pyROOT绑定之上,利用LCIO提供的根字典,允许将LCIO对象直接存储在根文件中。这些字典还隐式地为所有类提供python接口。在pyROOT中,c样式数组(或任何其他指向基本类型的指针)必须作为python数组或相应类型的numpy数组传递(例如,请参见<a href="https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#using-pyroot" rel="nofollow noreferrer">https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#using-pyroot</a>中的“19.1.9.2编写树”)。
(另外,您应该使用IMPL.MCParticleImpl实现要手工构造MCParticles,请参见<a href="http://lcio.desy.de/v02-09/doc/doxygen_api/html/classIMPL_1_1MCParticleImpl.html" rel="nofollow noreferrer">http://lcio.desy.de/v02-09/doc/doxygen_api/html/classIMPL_1_1MCParticleImpl.html</a>。IOIMPL版本只从SIO流中添加了一个构造函数,而SIO流是从LCIO文件中读取它所需要的。你知道吗</p>
<p>在这种情况下你应该这样做</p>
<pre><code>from pyLCIO import IMPL
from array import array
particle=IMPL.MCParticleImpl()
p = array('f', [1.0, 2.0, 3.0]) # the type ‘f’ has the length of a C++ float, for a double use ‘d'
particle.setMomentum(p)
</code></pre>
<p>由于我从不喜欢LCIO的设计选择,将物理向量作为c风格的数组传递,因此我扩展了pyLCIO中的所有类接口,以支持根物理向量(TVector3)的使用。所有实际上是物理向量的setter和getter都有另一个版本setXxxVec()或getXxxVec(),它们接受或返回物理向量。如果一个对象有getEnergy和getMomentum,那么它在pyLCIO中也会有getLorentzVec,它返回一个根TLorentzVector对象。有关扩展接口,请参见<a href="https://github.com/iLCSoft/LCIO/blob/master/src/python/pyLCIO/base/DecorateLcioClasses.py" rel="nofollow noreferrer">https://github.com/iLCSoft/LCIO/blob/master/src/python/pyLCIO/base/DecorateLcioClasses.py</a>。所以在你的例子中,你也可以用</p>
<pre><code>from pyLCIO import IMPL
from ROOT import TVector3
particle=IMPL.MCParticleImpl()
p = TVector3(1.0, 2.0, 3.0)
particle.setMomentumVec(p)
</code></pre>
<p>由于您正在尝试创建LCIO文件,您可能会发现这个示例非常有用<a href="https://github.com/iLCSoft/LCIO/blob/master/examples/python/EventBuilder.py" rel="nofollow noreferrer">https://github.com/iLCSoft/LCIO/blob/master/examples/python/EventBuilder.py</a>。事实上,它已经包含了一个如何创建MCParticle对象的示例。关于如何使用pyLCIO,请看一下其他示例。你知道吗</p>