ctpwa 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ctpwa-0.3.0/LICENSE +21 -0
- ctpwa-0.3.0/MANIFEST.in +9 -0
- ctpwa-0.3.0/PKG-INFO +18 -0
- ctpwa-0.3.0/README.md +1 -0
- ctpwa-0.3.0/ctpwa.egg-info/PKG-INFO +18 -0
- ctpwa-0.3.0/ctpwa.egg-info/SOURCES.txt +63 -0
- ctpwa-0.3.0/ctpwa.egg-info/dependency_links.txt +1 -0
- ctpwa-0.3.0/ctpwa.egg-info/requires.txt +2 -0
- ctpwa-0.3.0/ctpwa.egg-info/top_level.txt +2 -0
- ctpwa-0.3.0/doc/hessian_formula.md +215 -0
- ctpwa-0.3.0/doc/hessian_status.md +52 -0
- ctpwa-0.3.0/example/config.yml +148 -0
- ctpwa-0.3.0/example/fit.py +633 -0
- ctpwa-0.3.0/example/plot.py +1006 -0
- ctpwa-0.3.0/include/AmpGen.cuh +400 -0
- ctpwa-0.3.0/include/Amplitude.cuh +52 -0
- ctpwa-0.3.0/include/AutoDiff.cuh +538 -0
- ctpwa-0.3.0/include/ComplexType.h +118 -0
- ctpwa-0.3.0/include/ComputeBF.cuh +35 -0
- ctpwa-0.3.0/include/ComputeHessian.cuh +42 -0
- ctpwa-0.3.0/include/ComputeNLL.cuh +40 -0
- ctpwa-0.3.0/include/ComputeResults.cuh +40 -0
- ctpwa-0.3.0/include/Config.cuh +129 -0
- ctpwa-0.3.0/include/DeviceManager.cuh +127 -0
- ctpwa-0.3.0/include/Figure.cuh +98 -0
- ctpwa-0.3.0/include/Info.cuh +82 -0
- ctpwa-0.3.0/include/Parameters.cuh +232 -0
- ctpwa-0.3.0/include/ResModel.cuh +89 -0
- ctpwa-0.3.0/include/Resonance.cuh +84 -0
- ctpwa-0.3.0/pyproject.toml +12 -0
- ctpwa-0.3.0/setup.cfg +4 -0
- ctpwa-0.3.0/setup.py +231 -0
- ctpwa-0.3.0/src/AmpGen.cu +2900 -0
- ctpwa-0.3.0/src/Amplitude.cu +642 -0
- ctpwa-0.3.0/src/Analysis.cu +4509 -0
- ctpwa-0.3.0/src/ComputeBF.cu +185 -0
- ctpwa-0.3.0/src/ComputeHessian.cu +993 -0
- ctpwa-0.3.0/src/ComputeNLL.cu +504 -0
- ctpwa-0.3.0/src/ComputeResults.cu +261 -0
- ctpwa-0.3.0/src/Config.cu +1048 -0
- ctpwa-0.3.0/src/DeviceManager.cu +272 -0
- ctpwa-0.3.0/src/Figure.cu +528 -0
- ctpwa-0.3.0/src/Info.cu +377 -0
- ctpwa-0.3.0/src/Parameters.cu +772 -0
- ctpwa-0.3.0/src/ResModel.cu +204 -0
- ctpwa-0.3.0/src/Resonance.cu +128 -0
- ctpwa-0.3.0/src/main.cu +112 -0
- ctpwa-0.3.0/tests/__init__.py +0 -0
- ctpwa-0.3.0/tests/configs/no_trans.yml +84 -0
- ctpwa-0.3.0/tests/configs/simple.yml +47 -0
- ctpwa-0.3.0/tests/configs/with_trans.yml +86 -0
- ctpwa-0.3.0/tests/conftest.py +120 -0
- ctpwa-0.3.0/tests/data/test_data.dat +3000 -0
- ctpwa-0.3.0/tests/data/test_phsp.dat +30000 -0
- ctpwa-0.3.0/tests/data/test_sideband.dat +300 -0
- ctpwa-0.3.0/tests/fit_benchmark.py +123 -0
- ctpwa-0.3.0/tests/generate_test_data.py +169 -0
- ctpwa-0.3.0/tests/golden/grad_simple.txt +4 -0
- ctpwa-0.3.0/tests/golden/nll_simple.txt +1 -0
- ctpwa-0.3.0/tests/prepare_real_data.py +148 -0
- ctpwa-0.3.0/tests/run_tests.sh +32 -0
- ctpwa-0.3.0/tests/test_endtoend.py +212 -0
- ctpwa-0.3.0/tests/test_numerical.py +239 -0
- ctpwa-0.3.0/tests/test_structure.py +219 -0
- ctpwa-0.3.0/tests/update_golden.py +41 -0
ctpwa-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Benhou Xiang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ctpwa-0.3.0/MANIFEST.in
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# sdist 内容清单:setup.py 自动包含 ext sources (src/main.cu) 和 packages (tests),
|
|
2
|
+
# 但被 main.cu #include 的 .cu 和头文件不会自动包含——必须显式列出,
|
|
3
|
+
# 否则其他机器 pip install 编译失败。
|
|
4
|
+
recursive-include include *.cuh *.h
|
|
5
|
+
recursive-include src *.cu *.cuh *.h
|
|
6
|
+
recursive-include tests *.py *.yml *.txt *.dat *.sh
|
|
7
|
+
recursive-include doc *
|
|
8
|
+
recursive-include example *.py *.yml *.md
|
|
9
|
+
include README.md LICENSE
|
ctpwa-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ctpwa
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: CUDA-Torch Partial Wave Analysis
|
|
5
|
+
Author: Benhou Xiang
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Science/Research
|
|
8
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: C++
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy>=1.20.0
|
|
16
|
+
Requires-Dist: pyyaml>=5.4.0
|
|
17
|
+
|
|
18
|
+
A partial wave analysis packages with theory of covariant tensor and tools of CUDA and Torch.
|
ctpwa-0.3.0/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
A partial wave analysis packages with theory of covariant tensor and tools of CUDA and Torch.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ctpwa
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: CUDA-Torch Partial Wave Analysis
|
|
5
|
+
Author: Benhou Xiang
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Science/Research
|
|
8
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: C++
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy>=1.20.0
|
|
16
|
+
Requires-Dist: pyyaml>=5.4.0
|
|
17
|
+
|
|
18
|
+
A partial wave analysis packages with theory of covariant tensor and tools of CUDA and Torch.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
ctpwa.egg-info/PKG-INFO
|
|
7
|
+
ctpwa.egg-info/SOURCES.txt
|
|
8
|
+
ctpwa.egg-info/dependency_links.txt
|
|
9
|
+
ctpwa.egg-info/requires.txt
|
|
10
|
+
ctpwa.egg-info/top_level.txt
|
|
11
|
+
doc/hessian_formula.md
|
|
12
|
+
doc/hessian_status.md
|
|
13
|
+
example/config.yml
|
|
14
|
+
example/fit.py
|
|
15
|
+
example/plot.py
|
|
16
|
+
include/AmpGen.cuh
|
|
17
|
+
include/Amplitude.cuh
|
|
18
|
+
include/AutoDiff.cuh
|
|
19
|
+
include/ComplexType.h
|
|
20
|
+
include/ComputeBF.cuh
|
|
21
|
+
include/ComputeHessian.cuh
|
|
22
|
+
include/ComputeNLL.cuh
|
|
23
|
+
include/ComputeResults.cuh
|
|
24
|
+
include/Config.cuh
|
|
25
|
+
include/DeviceManager.cuh
|
|
26
|
+
include/Figure.cuh
|
|
27
|
+
include/Info.cuh
|
|
28
|
+
include/Parameters.cuh
|
|
29
|
+
include/ResModel.cuh
|
|
30
|
+
include/Resonance.cuh
|
|
31
|
+
src/AmpGen.cu
|
|
32
|
+
src/Amplitude.cu
|
|
33
|
+
src/Analysis.cu
|
|
34
|
+
src/ComputeBF.cu
|
|
35
|
+
src/ComputeHessian.cu
|
|
36
|
+
src/ComputeNLL.cu
|
|
37
|
+
src/ComputeResults.cu
|
|
38
|
+
src/Config.cu
|
|
39
|
+
src/DeviceManager.cu
|
|
40
|
+
src/Figure.cu
|
|
41
|
+
src/Info.cu
|
|
42
|
+
src/Parameters.cu
|
|
43
|
+
src/ResModel.cu
|
|
44
|
+
src/Resonance.cu
|
|
45
|
+
src/main.cu
|
|
46
|
+
tests/__init__.py
|
|
47
|
+
tests/conftest.py
|
|
48
|
+
tests/fit_benchmark.py
|
|
49
|
+
tests/generate_test_data.py
|
|
50
|
+
tests/prepare_real_data.py
|
|
51
|
+
tests/run_tests.sh
|
|
52
|
+
tests/test_endtoend.py
|
|
53
|
+
tests/test_numerical.py
|
|
54
|
+
tests/test_structure.py
|
|
55
|
+
tests/update_golden.py
|
|
56
|
+
tests/configs/no_trans.yml
|
|
57
|
+
tests/configs/simple.yml
|
|
58
|
+
tests/configs/with_trans.yml
|
|
59
|
+
tests/data/test_data.dat
|
|
60
|
+
tests/data/test_phsp.dat
|
|
61
|
+
tests/data/test_sideband.dat
|
|
62
|
+
tests/golden/grad_simple.txt
|
|
63
|
+
tests/golden/nll_simple.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# Hessian 公式备忘录
|
|
2
|
+
|
|
3
|
+
> 已验证精度:vv, vθ, θv, θθ 四个 block 与 PyTorch autograd 差异 < 1.2×10⁻⁶
|
|
4
|
+
|
|
5
|
+
## 1. NLL 定义
|
|
6
|
+
|
|
7
|
+
$$
|
|
8
|
+
\text{NLL} = -\sum_{\text{data}} \log I_e + w_{\text{bkg}} \sum_{\text{bkg}} \log I_e + A \cdot \log(\text{pf})
|
|
9
|
+
$$
|
|
10
|
+
|
|
11
|
+
其中:
|
|
12
|
+
|
|
13
|
+
- $A = N_{\text{data}} - \int_{\text{bkg}}$ (phsp 项的系数)
|
|
14
|
+
- $\text{pf} = \frac{1}{N_{\text{phsp}}} \sum_{e \in \text{phsp}} I_e$
|
|
15
|
+
- $I_e = \sum_p |S_{e,p}|^2$ (所有极化求和)
|
|
16
|
+
- $S_{e,p} = \sum_a v_a \cdot \text{amp}_{a,e,p}$ (所有 channel 求和)
|
|
17
|
+
- $\text{amp}_{a,e,p} = SL_{a,e,p} \cdot R_{\text{res}(a),e}(\theta) \cdot bf$ (完整振幅)
|
|
18
|
+
|
|
19
|
+
## 2. Per-event 量定义
|
|
20
|
+
|
|
21
|
+
### 2.1 基本量
|
|
22
|
+
|
|
23
|
+
| 符号 | 定义 | 含义 |
|
|
24
|
+
|------|------|------|
|
|
25
|
+
| $S[p]$ | $\sum_a v_a \cdot \text{amp}_a[p]$ | 每个极化的复振幅 |
|
|
26
|
+
| $I$ | $\sum_p (S_{\text{re}}[p]^2 + S_{\text{im}}[p]^2)$ | 每个事件的强度 |
|
|
27
|
+
| $1/I$ | | 逆强度 |
|
|
28
|
+
|
|
29
|
+
### 2.2 一阶导数
|
|
30
|
+
|
|
31
|
+
| 符号 | 公式 | 含义 |
|
|
32
|
+
|------|------|------|
|
|
33
|
+
| $\partial S/\partial v_a^{\text{re}}$ | $\text{amp}_a$ | S 对耦合实部的导数 |
|
|
34
|
+
| $\partial S/\partial v_a^{\text{im}}$ | $i \cdot \text{amp}_a$ | S 对耦合虚部的导数 |
|
|
35
|
+
| $dS_j[p]$ | $\partial S[p]/\partial\theta_j$ | S 对共振态参数的导数 |
|
|
36
|
+
| $\partial I/\partial v_a^{\text{re}}$ | $2 \cdot \text{Re}(\text{conj}(S) \cdot \text{amp}_a)$ | I 对耦合实部的导数 |
|
|
37
|
+
| $\partial I/\partial v_a^{\text{im}}$ | $-2 \cdot \text{Im}(\text{conj}(S) \cdot \text{amp}_a)$ | I 对耦合虚部的导数 |
|
|
38
|
+
| $\partial I/\partial\theta_j$ | $2 \cdot \text{Re}(\text{conj}(S) \cdot dS_j)$ | I 对共振态参数的导数 |
|
|
39
|
+
|
|
40
|
+
### 2.3 二阶导数
|
|
41
|
+
|
|
42
|
+
| 符号 | 公式 | 含义 |
|
|
43
|
+
|------|------|------|
|
|
44
|
+
| $\partial^2 I/\partial v_a^{\text{re}}\partial\theta_j$ | $2 \cdot \text{Re}(\text{conj}(dS_j) \cdot \text{amp}_a + \text{conj}(S) \cdot \partial\text{amp}_a/\partial\theta_j)$ | 混合二阶导数(实部) |
|
|
45
|
+
| $\partial^2 I/\partial v_a^{\text{im}}\partial\theta_j$ | $-2 \cdot \text{Im}(\text{conj}(dS_j) \cdot \text{amp}_a + \text{conj}(S) \cdot \partial\text{amp}_a/\partial\theta_j)$ | 混合二阶导数(虚部) |
|
|
46
|
+
| $\partial\text{amp}_a/\partial\theta_j$ | $SL_a \cdot \partial R_{\text{res}(a)}/\partial\theta_j$ | 振幅对 θ 的导数(同块非零,跨块为零) |
|
|
47
|
+
|
|
48
|
+
### 2.4 Per-event 梯度
|
|
49
|
+
|
|
50
|
+
| 符号 | 公式 | 含义 |
|
|
51
|
+
|------|------|------|
|
|
52
|
+
| $g_j$ | $-\frac{2}{I} \cdot \text{Re}(\text{conj}(S) \cdot dS_j)$ | $\partial(-\log I)/\partial\theta_j$(per-event,无权重) |
|
|
53
|
+
| $g_a^{(v,\text{re})}$ | $-\frac{2}{I} \cdot \text{Re}(\text{conj}(S) \cdot \text{amp}_a)$ | $\partial(-\log I)/\partial v_a^{\text{re}}$ |
|
|
54
|
+
| $g_a^{(v,\text{im})}$ | $+\frac{2}{I} \cdot \text{Im}(\text{conj}(S) \cdot \text{amp}_a)$ | $\partial(-\log I)/\partial v_a^{\text{im}}$ |
|
|
55
|
+
|
|
56
|
+
## 3. Hessian 公式(data + bkg)
|
|
57
|
+
|
|
58
|
+
每事件带权重 $w_e$(data=+1, bkg=-w_b):
|
|
59
|
+
|
|
60
|
+
### 3.1 vv Block(由 PyTorch autograd 计算)
|
|
61
|
+
|
|
62
|
+
$H_{vv} = \partial^2\text{NLL}/\partial v\partial v$,由 `NLLFunction` 的 autograd 自动计算。
|
|
63
|
+
|
|
64
|
+
### 3.2 θθ Block
|
|
65
|
+
|
|
66
|
+
对每个事件 $e$,per-event Hessian:
|
|
67
|
+
|
|
68
|
+
$$
|
|
69
|
+
h_{jk} = g_j \cdot g_k - \frac{2}{I} \cdot \text{Re}(\text{conj}(dS_k) \cdot dS_j) - \frac{2}{I} \cdot \text{Re}(\text{conj}(S) \cdot d^2S_{jk})
|
|
70
|
+
$$
|
|
71
|
+
|
|
72
|
+
三项分别称为 **Term A**(外积)、**Term B**($|dS|^2$ 修正)、**Term C**($d^2S$ 修正,仅同块非零)。
|
|
73
|
+
|
|
74
|
+
总 θθ Hessian:
|
|
75
|
+
|
|
76
|
+
$$
|
|
77
|
+
H_{\theta\theta}[j,k] = \sum_e w_e \cdot h_{jk}^{(e)}
|
|
78
|
+
$$
|
|
79
|
+
|
|
80
|
+
### 3.3 vθ / θv Block(混合 Hessian)
|
|
81
|
+
|
|
82
|
+
对每个振幅 $a$ 和共振态参数 $j$(同块,即 $a$ 和 $\theta_j$ 属于同一 resonance):
|
|
83
|
+
|
|
84
|
+
$$
|
|
85
|
+
\begin{aligned}
|
|
86
|
+
H_{v_a^{\text{re}}, \theta_j} &= -\frac{2w_e}{I} \cdot \Big[\text{Re}(\text{conj}(dS_j) \cdot \text{amp}_a) + \text{Re}(\text{conj}(S) \cdot \partial\text{amp}_a/\partial\theta_j) + g_j \cdot \text{Re}(\text{conj}(S) \cdot \text{amp}_a)\Big] \\
|
|
87
|
+
&= -\frac{2w_e}{I} \cdot \big[\text{Term1}_{\text{re}} + \text{Term2}_{\text{re}} + g_j \cdot \text{Term3}_{\text{re}}\big]
|
|
88
|
+
\end{aligned}
|
|
89
|
+
$$
|
|
90
|
+
|
|
91
|
+
$$
|
|
92
|
+
H_{v_a^{\text{im}}, \theta_j} = +\frac{2w_e}{I} \cdot \big[\text{Term1}_{\text{im}} + \text{Term2}_{\text{im}} + g_j \cdot \text{Term3}_{\text{im}}\big]
|
|
93
|
+
$$
|
|
94
|
+
|
|
95
|
+
对跨块($a$ 和 $\theta_j$ 属于不同 resonance):Term2 = 0(因为 $\partial\text{amp}_a/\partial\theta_j = 0$),只用 Term1 + Term3。
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
**Term1, Term2, Term3 定义:**
|
|
100
|
+
|
|
101
|
+
| 项 | 实部公式 | 虚部公式 |
|
|
102
|
+
|----|---------|---------|
|
|
103
|
+
| Term1 | $\text{Re}(\text{conj}(dS_j) \cdot \text{amp}_a)$ | $\text{Im}(\text{conj}(dS_j) \cdot \text{amp}_a)$ |
|
|
104
|
+
| Term2 | $\text{Re}(\text{conj}(S) \cdot SL_a \cdot \partial R/\partial\theta_j)$ | $\text{Im}(\text{conj}(S) \cdot SL_a \cdot \partial R/\partial\theta_j)$ |
|
|
105
|
+
| Term3 | $\text{Re}(\text{conj}(S) \cdot \text{amp}_a)$ | $\text{Im}(\text{conj}(S) \cdot \text{amp}_a)$ |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 4. Phsp 贡献
|
|
110
|
+
|
|
111
|
+
### 4.1 θθ Block
|
|
112
|
+
|
|
113
|
+
Phsp 项 $L_{\text{phsp}} = A \cdot \log(\text{pf})$,其中 $\text{pf} = \frac{1}{N_{\text{phsp}}} \sum_{e \in \text{phsp}} I_e$。
|
|
114
|
+
|
|
115
|
+
$$
|
|
116
|
+
\frac{\partial^2 L_{\text{phsp}}}{\partial\theta_j\partial\theta_k} = c_1 \cdot \Sigma_{\text{phsp}}[I \cdot (g_j g_k - h_{jk})] + c_2 \cdot (\Sigma I g_j) \cdot (\Sigma I g_k)
|
|
117
|
+
$$
|
|
118
|
+
|
|
119
|
+
其中:
|
|
120
|
+
- $c_1 = \dfrac{A}{\text{pf} \cdot N_{\text{phsp}}}$
|
|
121
|
+
- $c_2 = -\dfrac{A}{\text{pf}^2 \cdot N_{\text{phsp}}^2}$
|
|
122
|
+
|
|
123
|
+
### 4.2 vθ Block
|
|
124
|
+
|
|
125
|
+
Phsp 对混合 Hessian 的贡献:
|
|
126
|
+
|
|
127
|
+
$$
|
|
128
|
+
\frac{\partial^2 L_{\text{phsp}}}{\partial v_a^{\text{re}}\partial\theta_j} = c_{1m} \cdot \Sigma_{\text{phsp}}(\text{Term1}_{\text{re}} + \text{Term2}_{\text{re}}) + c_{2m} \cdot \big(\Sigma_{\text{phsp}} \text{Term3}_{\text{re}}^{(a)}\big) \cdot \big(\Sigma_{\text{phsp}} I \cdot g_j\big)
|
|
129
|
+
$$
|
|
130
|
+
|
|
131
|
+
$$
|
|
132
|
+
\frac{\partial^2 L_{\text{phsp}}}{\partial v_a^{\text{im}}\partial\theta_j} = -\Big[c_{1m} \cdot \Sigma_{\text{phsp}}(\text{Term1}_{\text{im}} + \text{Term2}_{\text{im}}) + c_{2m} \cdot \big(\Sigma_{\text{phsp}} \text{Term3}_{\text{im}}^{(a)}\big) \cdot \big(\Sigma_{\text{phsp}} I \cdot g_j\big)\Big]
|
|
133
|
+
$$
|
|
134
|
+
|
|
135
|
+
其中:
|
|
136
|
+
- $c_{1m} = \dfrac{2A}{\text{pf} \cdot N_{\text{phsp}}}$
|
|
137
|
+
- $c_{2m} = \dfrac{2A}{\text{pf}^2 \cdot N_{\text{phsp}}^2}$
|
|
138
|
+
|
|
139
|
+
> **注意**:$c_{1m}$ 和 $c_{2m}$ 都有因子 2(与 θθ 的 $c_1, c_2$ 不同),这是因为 $\partial I/\partial v = 2 \cdot \text{Term3}$,而 $\partial I/\partial\theta = -I \cdot g$。
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 5. CUDA 实现结构
|
|
144
|
+
|
|
145
|
+
### 5.1 Kernel 流水线
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
Pre-pass: computeSfromAmpsKernel
|
|
149
|
+
→ 计算 S[p], I, 以及 Term3(用于 phsp vθ)
|
|
150
|
+
|
|
151
|
+
Stage 1: hessianStage1Kernel<Npr, Nres> (per-block, per-event)
|
|
152
|
+
→ 输出 per-event g_j, dS_j, ∂F/∂θ_j
|
|
153
|
+
→ 累加同块 θθ Hessian
|
|
154
|
+
→ 累加 phsp: I·g, I·(g⊗g - h)
|
|
155
|
+
|
|
156
|
+
Stage 2: hessianCrossBlockKernel
|
|
157
|
+
→ 跨块 θθ Hessian(仅 Term A + Term B)
|
|
158
|
+
|
|
159
|
+
Stage 3: hessianMixedBlockKernel (per-block)
|
|
160
|
+
→ 同块 vθ Hessian(Term 1 + 2 + 3)
|
|
161
|
+
→ phsp path: 写 Term1+Term2 到 h_sum,Term3 由 pre-pass 计算
|
|
162
|
+
|
|
163
|
+
Stage 4: hessianCrossMixedKernel
|
|
164
|
+
→ 跨块 vθ Hessian(仅 Term 1 + 3,Term2=0)
|
|
165
|
+
→ phsp path: 写 Term1 到 h_sum(Term3 已由 pre-pass 计算,不重复)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 5.2 关键注意点
|
|
169
|
+
|
|
170
|
+
- **Pre-pass 计算完整 S**:Stage 1 不自己算 S,而是从 pre-pass 读入。确保 S 包含所有 channel 的贡献(不仅是本块的)。
|
|
171
|
+
- **Term3(t3)在 pre-pass 统一计算**:Term3 是 per-amplitude 的量,与具体哪个 θ block 无关。在 pre-pass 中一次性计算所有 SL channel 的 Term3,避免 stage 3 和 stage 4 重复累加。
|
|
172
|
+
- **跨块 Term2 = 0**:对于 $a \in \text{block A}, \theta_j \in \text{block B}$,$\partial\text{amp}_a/\partial\theta_j = 0$,因此 Term2 不参与跨块贡献。
|
|
173
|
+
- **Phsp 的 is_phsp 判断**:`default_weight == 0.0 && d_phsp_sum != nullptr` 时走 phsp 路径,写入独立 buffer(非 d_mixed)。
|
|
174
|
+
- **所有 resonance 必须注册到 blocks_**:即使没有 free params,其 SL channels 也需要参与跨块 vθ 计算(stage 4)。
|
|
175
|
+
|
|
176
|
+
### 5.3 符号约定
|
|
177
|
+
|
|
178
|
+
| ctpwa | 数学含义 |
|
|
179
|
+
|-------|---------|
|
|
180
|
+
| `g[j]` | $-\partial(\log I)/\partial\theta_j$(无权重) |
|
|
181
|
+
| `d_dS_re[j][p]` | $\text{Re}(\partial S[p]/\partial\theta_j)$ |
|
|
182
|
+
| `d_dS_im[j][p]` | $\text{Im}(\partial S[p]/\partial\theta_j)$ |
|
|
183
|
+
| `d_dF_re[a][j]` | $\text{Re}(\partial R_{\text{res}(a)}/\partial\theta_j)$ |
|
|
184
|
+
| `d_dF_im[a][j]` | $\text{Im}(\partial R_{\text{res}(a)}/\partial\theta_j)$ |
|
|
185
|
+
| `d_phsp_I` | $\Sigma_{\text{phsp}} I_e$ |
|
|
186
|
+
| `d_phsp_grad[j]` | $\Sigma_{\text{phsp}} I_e \cdot g_j^{(e)}$ |
|
|
187
|
+
| `d_phsp_hessA[j][k]` | $\Sigma_{\text{phsp}} I_e \cdot (g_j g_k - h_{jk})$ |
|
|
188
|
+
| `d_phsp_mixed_sum[a][j]` | $\Sigma_{\text{phsp}}(\text{Term1} + \text{Term2})_{a,j}$ |
|
|
189
|
+
| `d_phsp_mixed_t3[a]` | $\Sigma_{\text{phsp}} \text{Term3}_a$(由 pre-pass 计算) |
|
|
190
|
+
|
|
191
|
+
### 5.4 约束投影
|
|
192
|
+
|
|
193
|
+
在 vv 和 vθ block 计算完成后,需要将 extended parameter space 的结果投影到 free parameter space:
|
|
194
|
+
|
|
195
|
+
对于实部约束:$v_{\text{ext}}[e] = rr \cdot v_{\text{free}}[\text{oid}] + \cdots$
|
|
196
|
+
|
|
197
|
+
$$
|
|
198
|
+
H_{\text{free}}[\text{oid}, :] \mathrel{+}= rr \cdot H_{\text{ext}}[e, :] + ir \cdot H_{\text{ext}}[n_{\text{ext}} + e, :]
|
|
199
|
+
$$
|
|
200
|
+
$$
|
|
201
|
+
H_{\text{free}}[n_{\text{free}} + \text{oid}, :] \mathrel{+}= -ir \cdot H_{\text{ext}}[e, :] + rr \cdot H_{\text{ext}}[n_{\text{ext}} + e, :]
|
|
202
|
+
$$
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 6. 验证结果
|
|
207
|
+
|
|
208
|
+
| Block | 1-res(1 个自由共振态) | 2-res(2 个自由共振态) |
|
|
209
|
+
|-------|------------------------|------------------------|
|
|
210
|
+
| vv | 7.73×10⁻⁷ | 7.73×10⁻⁷ |
|
|
211
|
+
| vθ | 2.89×10⁻⁷ | 3.18×10⁻⁷ |
|
|
212
|
+
| θv | 2.89×10⁻⁷ | 3.18×10⁻⁷ |
|
|
213
|
+
| θθ | 8.95×10⁻⁷ | 1.18×10⁻⁶ |
|
|
214
|
+
|
|
215
|
+
测试条件:1 data event, 3 phsp events, 1 bkg event, 9 polarizations, BWR×2 resonances。
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Hessian 多共振态修复状态报告
|
|
2
|
+
|
|
3
|
+
## 已验证(正确)
|
|
4
|
+
|
|
5
|
+
1. **AutoDiff BWR Hessian** (`Var<double,N,true>`): 与 PyTorch autograd 精确一致 (<1e-15)
|
|
6
|
+
2. **Per-event Hessian 公式**: 在 Python 中与 PyTorch 完全匹配
|
|
7
|
+
```
|
|
8
|
+
g[j] = -2·bf·Re(D^j · Σ conj(w)·T)
|
|
9
|
+
H = g·g^T - 2·I_inv·bf²·Σ|T|²·Re(conj(D_k)·D_j) - 2·bf·Re(Σ conj(w)·T · D²_jk)
|
|
10
|
+
```
|
|
11
|
+
3. **单共振态**: getHessian 与 PyTorch 匹配 (rel < 1e-7)
|
|
12
|
+
4. **θθ 交叉块公式**: H_rs = g_r·g_s^T (只有外积,无 d²S 修正项)
|
|
13
|
+
|
|
14
|
+
## 当前代码状态 (hessian-research 分支)
|
|
15
|
+
|
|
16
|
+
### 已修改
|
|
17
|
+
- `resonanceHessianBlockKernel` Step 5: 替换为 per-event 聚合公式
|
|
18
|
+
- `computeResonanceHessian`: 替换为直接调用 BlockKernel(移除 3-pass)
|
|
19
|
+
- `getHessian`: 添加 computeEffectiveCoupling 调用
|
|
20
|
+
- `d_v[site+sl_idx]`: double-offset 修复(3个kernel)
|
|
21
|
+
|
|
22
|
+
### 未解决
|
|
23
|
+
1. **符号/权重**: data 的 sign 是 +1 还是 -1 需要和 NLL 公式对齐
|
|
24
|
+
2. **bkg 权重**: 每个 bkg event 需要独立的 w_evt 权重传入 kernel
|
|
25
|
+
3. **PHSP 对 θθ 的贡献**: 完全缺失
|
|
26
|
+
4. **vθ 混合块**: 暂填零(单链模型下正确,多链需要实现)
|
|
27
|
+
|
|
28
|
+
## 建议方案
|
|
29
|
+
|
|
30
|
+
### 短期(最小修改让当前代码工作)
|
|
31
|
+
在 `getHessian` 里 per-event 循环调用 `computeResonanceHessian` 时传入正确的 w_evt:
|
|
32
|
+
- data: w_evt = -1
|
|
33
|
+
- bkg: w_evt 从 bkg_weights_ 读取(正权重 → 负贡献)
|
|
34
|
+
- 然后将 kernel 里的 `sign` 参数统一为 +1,外积和修正都用 `w_evt * (...)` 格式
|
|
35
|
+
|
|
36
|
+
### 长期(推荐架构)
|
|
37
|
+
```
|
|
38
|
+
computeResonanceHessian() {
|
|
39
|
+
for each event:
|
|
40
|
+
1. 计算 S = A*v, I = |S|², w = S/I
|
|
41
|
+
2. for each resonance r:
|
|
42
|
+
计算 g_r, H_rr (per-event)
|
|
43
|
+
H_total += w_evt * H_rr
|
|
44
|
+
存储 g_r 到 per-event buffer
|
|
45
|
+
3. for each pair (r,s) where r≠s:
|
|
46
|
+
H_total += w_evt * g_r ⊗ g_s^T
|
|
47
|
+
4. PHSP 贡献: H += n_data * ∂²log(phsp_factor)/∂θ²
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 如果重新开始
|
|
52
|
+
用 Python 先写完整的多共振态 NLL + Hessian,验证公式完全对上后,再逐块翻译成 CUDA kernel。避免在 C++ 里反复编译调试。
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# ============================================================
|
|
2
|
+
# ctpwa config.yml — compact format
|
|
3
|
+
# ============================================================
|
|
4
|
+
# 衰变链支持两种写法:
|
|
5
|
+
# 紧凑格式(推荐):
|
|
6
|
+
# chain_name:
|
|
7
|
+
# mother:
|
|
8
|
+
# - [daughter1, intermediate] # 含中间态
|
|
9
|
+
# - [daughter2, intermediate]
|
|
10
|
+
# intermediate: [d1, d2] # 中间态衰变
|
|
11
|
+
#
|
|
12
|
+
# intermediates: # 中间态共振态配置
|
|
13
|
+
# intermediate:
|
|
14
|
+
# - [J: 1, P: -1]: [res1, res2]
|
|
15
|
+
# 展开格式 (等价):
|
|
16
|
+
# chain_name:
|
|
17
|
+
# decay:
|
|
18
|
+
# - mother: [daughter1, intermediate]
|
|
19
|
+
# - intermediate: [d1, d2]
|
|
20
|
+
# intermediate:
|
|
21
|
+
# - [J: 1, P: -1]: [res1, res2]
|
|
22
|
+
#
|
|
23
|
+
# 约束:
|
|
24
|
+
# trans: 跨链全同约束。[chain_substr_A, chain_substr_B]: ratio
|
|
25
|
+
# identical: 全同粒子组,自动施加 (-1)^{L+S} 选择定则
|
|
26
|
+
# maxL: 全局轨道角动量上限
|
|
27
|
+
# ============================================================
|
|
28
|
+
|
|
29
|
+
Particles:
|
|
30
|
+
Jpsi:
|
|
31
|
+
J: 1; P: -1; mass: 3.0969
|
|
32
|
+
# polarization: [1, -1] # 横极化 (仅 m=±1)
|
|
33
|
+
tex: ['J/\\psi']
|
|
34
|
+
eta:
|
|
35
|
+
J: 0; P: -1; mass: 0.5478
|
|
36
|
+
tex: ['\\eta']
|
|
37
|
+
Kp:
|
|
38
|
+
J: 0; P: -1; mass: 0.4937
|
|
39
|
+
tex: ['K^{+}']
|
|
40
|
+
Km:
|
|
41
|
+
J: 0; P: -1; mass: 0.4937
|
|
42
|
+
tex: ['K^{-}']
|
|
43
|
+
|
|
44
|
+
Data:
|
|
45
|
+
order: [Kp, Km, eta]
|
|
46
|
+
data: [dat, "./data.dat"]
|
|
47
|
+
phsp: [dat, "./phsp.dat"]
|
|
48
|
+
# bkg: [dat, "./bkg.dat"]
|
|
49
|
+
# bkg_weights: [dat, "./bkg_weights.dat"]
|
|
50
|
+
|
|
51
|
+
# 使用root文件 (TBranch名字与order中粒子名字顺序一致)
|
|
52
|
+
# data: [ROOT, "/file.root", TTree, TBranch1, TBranch2, TBranch3, ...]
|
|
53
|
+
# phsp: [ROOT, "/file.root", TTree, TBranch1, TBranch2, TBranch3, ...]
|
|
54
|
+
# bkg: [ROOT, "/file.root", TTree, TBranch1, TBranch2, TBranch3, ...]
|
|
55
|
+
# bkg_weights: [ROOT, "/file.root", TTree, TBranch1(weight)]
|
|
56
|
+
# 也可混合使用
|
|
57
|
+
|
|
58
|
+
# ============================================================
|
|
59
|
+
# 衰变链: J/psi → eta KK / Kp Keta / Km Keta
|
|
60
|
+
# BFS 自动展开所有中间态 J^P 组合 × 共振态组合
|
|
61
|
+
# ============================================================
|
|
62
|
+
DecayChains:
|
|
63
|
+
decay1:
|
|
64
|
+
Jpsi:
|
|
65
|
+
- [eta, R_KK] # [eta, R_KK, {if some requirement, like p_break: true}]
|
|
66
|
+
- [Kp, R_Kpeta]
|
|
67
|
+
- [Km, R_Kmeta]
|
|
68
|
+
R_KK: [Kp, Km]
|
|
69
|
+
R_Kpeta:
|
|
70
|
+
- [Kp, eta] # R_Keta_0
|
|
71
|
+
- [Km, eta] # R_Keta_1
|
|
72
|
+
|
|
73
|
+
intermediates:
|
|
74
|
+
R_KK:
|
|
75
|
+
- [J: 1, P: -1]: [phi1020, omega1420]
|
|
76
|
+
- [J: 3, P: -1]: [omega3_1670]
|
|
77
|
+
R_Keta:
|
|
78
|
+
- [J: 1, P: -1]: [K1_1410]
|
|
79
|
+
- [J: 2, P: +1]: [K2_1430]
|
|
80
|
+
legends:
|
|
81
|
+
- ['R_KK', ' \\to ', 'eta'] # chain 0: R_KK 的第0个共振态
|
|
82
|
+
- ['R_Keta_0', ' \\to ', 'Kp'] # chain 1
|
|
83
|
+
- ['R_Keta_1', ' \\to ', 'Km'] # chain 2
|
|
84
|
+
|
|
85
|
+
Constraints:
|
|
86
|
+
# R_Keta_0 和 R_Keta_1 通过 trans 约束共享参数(互为相反数)
|
|
87
|
+
trans:
|
|
88
|
+
- [R_Keta_0, R_Keta_1]: -1
|
|
89
|
+
# 全局参数
|
|
90
|
+
# maxL: 4
|
|
91
|
+
bf_d: 3.0
|
|
92
|
+
|
|
93
|
+
# ============================================================
|
|
94
|
+
# 共振态配置
|
|
95
|
+
# model: BWR (Breit-Wigner), Flatte, ONE (常数), BWR_Bf (含势垒)
|
|
96
|
+
# free: 自由参数下标,-1 表示全部自由
|
|
97
|
+
# free_range: 自由参数拟合范围
|
|
98
|
+
# ============================================================
|
|
99
|
+
Resonances:
|
|
100
|
+
# ---- R_KK 共振态 ----
|
|
101
|
+
phi1020:
|
|
102
|
+
J: 1; P: -1; model: BWR
|
|
103
|
+
parameters: [1.0195, 0.0045]
|
|
104
|
+
tex: ["\\phi(1020)"]
|
|
105
|
+
|
|
106
|
+
omega1420:
|
|
107
|
+
J: 1; P: -1; model: BWR
|
|
108
|
+
parameters: [1.41, 0.35]
|
|
109
|
+
tex: ["\\omega(1420)"]
|
|
110
|
+
|
|
111
|
+
omega3_1670:
|
|
112
|
+
J: 3; P: -1; model: BWR
|
|
113
|
+
parameters: [1.667, 0.168]
|
|
114
|
+
tex: ["\\omega_{3}(1670)"]
|
|
115
|
+
|
|
116
|
+
# ---- R_Keta 共振态 (Kpi) ----
|
|
117
|
+
K1_1410:
|
|
118
|
+
J: 1; P: -1; model: BWR
|
|
119
|
+
parameters: [1.414, 0.232]
|
|
120
|
+
tex: ["K_{1}(1410)"]
|
|
121
|
+
|
|
122
|
+
K2_1430:
|
|
123
|
+
J: 2; P: +1; model: BWR
|
|
124
|
+
parameters: [1.432, 0.109]
|
|
125
|
+
tex: ["K_{2}^{*}(1430)"]
|
|
126
|
+
|
|
127
|
+
# ============================================================
|
|
128
|
+
# ROOT 输出绘图
|
|
129
|
+
# ============================================================
|
|
130
|
+
Plot:
|
|
131
|
+
mass:
|
|
132
|
+
- input: [Kp, Km]
|
|
133
|
+
bins: 100; range: [1.0, 2.6]
|
|
134
|
+
display: ["M(K^{+}K^{-}) (GeV/c^{2})", "Events/16 MeV/c^{2}"]
|
|
135
|
+
- input: [Kp, eta]
|
|
136
|
+
bins: 100; range: [1.0, 2.6]
|
|
137
|
+
display: ["M(K^{+}\\eta) (GeV/c^{2})", "Events/16 MeV/c^{2}"]
|
|
138
|
+
- input: [Km, eta]
|
|
139
|
+
bins: 100; range: [1.0, 2.6]
|
|
140
|
+
display: ["M(K^{-}\\eta) (GeV/c^{2})", "Events/16 MeV/c^{2}"]
|
|
141
|
+
cosbeta:
|
|
142
|
+
- input: [[Jpsi], [Kp, Km], [Kp]]
|
|
143
|
+
bins: 100; range: [-1.0, 1.0]
|
|
144
|
+
display: ["cos\\beta(K^{+}K^{-})", "Events/0.02"]
|
|
145
|
+
dalitz:
|
|
146
|
+
- input: [[Kp, Km], [Kp, eta]]
|
|
147
|
+
bins: [100, 100]; range: [[1.0, 6.8], [1.0, 6.8]]
|
|
148
|
+
display: ["M^{2}(K^{+}K^{-}) (GeV^{2}/c^{4})", "M^{2}(K^{+}\\eta) (GeV^{2}/c^{4})"]
|