Skip to content

Commit 9f286c6

Browse files
achiefaRoyStegeman
authored andcommitted
Adjusting linear triangular function
1 parent ab92347 commit 9f286c6

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

validphys2/src/validphys/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,12 +1792,15 @@ def produce_power_corr_dict(self, pc_parameters=None, pc_func_type=None):
17921792
# Loop over the parameterization for the power corrections in the runcard
17931793
for par in pc_parameters:
17941794
# Check that the length of shifts is one less than the length of nodes.
1795-
if (len(par['yshift']) != len(par['nodes']) - 1) and pc_func_type != 'cubic':
1795+
if (len(par['yshift']) != len(par['nodes']) - 1) and pc_func_type not in [
1796+
'cubic',
1797+
'linear',
1798+
]:
17961799
raise ValueError(
17971800
f"The length of nodes does not match that of the list in {par['ht']}."
17981801
f"Check the runcard. Got {len(par['yshift'])} != {len(par['nodes'])}"
17991802
)
1800-
elif (len(par['yshift']) != len(par['nodes'])) and pc_func_type == 'cubic':
1803+
elif (len(par['yshift']) != len(par['nodes'])) and pc_func_type in ['cubic', 'linear']:
18011804
raise ValueError(
18021805
f"The length of nodes does not match that of the list in {par['ht']}."
18031806
f"Check the runcard. Got {len(par['yshift'])} != {len(par['nodes'])}"

validphys2/src/validphys/theorycovariance/higher_twist_functions.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,31 @@ def linear_bin_function(
135135
"""
136136
res = np.zeros_like(a)
137137
for shift_pos, shift in enumerate(y_shift):
138-
bin_low = bin_edges[shift_pos]
139-
bin_high = bin_edges[shift_pos + 1]
140-
bin_mid = 0.5 * (bin_low + bin_high)
138+
if shift_pos > 0 and shift_pos < len(y_shift) - 1:
139+
bin_low = bin_edges[shift_pos - 1]
140+
bin_high = bin_edges[shift_pos + 1]
141+
bin_mid = bin_edges[shift_pos]
142+
m1 = shift / (bin_mid - bin_low)
143+
m2 = shift / (bin_high - bin_mid)
144+
elif shift_pos == 0: # Left-most bin
145+
bin_high = bin_edges[shift_pos + 1]
146+
bin_mid = bin_edges[shift_pos]
147+
bin_low = bin_mid
148+
m1 = 0.0
149+
m2 = shift / (bin_high - bin_mid)
150+
else: # Right-most bin
151+
bin_low = bin_edges[shift_pos - 1]
152+
bin_mid = bin_edges[shift_pos]
153+
bin_high = bin_mid
154+
m1 = shift / (bin_mid - bin_low)
155+
m2 = 0.0
141156
cond_low = np.multiply(a >= bin_low, a < bin_mid)
142157
cond_high = np.multiply(
143158
a >= bin_mid, a < bin_high if shift_pos != len(y_shift) - 1 else a <= bin_high
144159
)
145-
m = 2 * shift / (bin_high - bin_low)
146-
res = np.add(res, [m * (val - bin_low) if cond else 0.0 for val, cond in zip(a, cond_low)])
160+
res = np.add(res, [m1 * (val - bin_low) if cond else 0.0 for val, cond in zip(a, cond_low)])
147161
res = np.add(
148-
res, [-m * (val - bin_high) if cond else 0.0 for val, cond in zip(a, cond_high)]
162+
res, [-m2 * (val - bin_high) if cond else 0.0 for val, cond in zip(a, cond_high)]
149163
)
150164
return res
151165

0 commit comments

Comments
 (0)