Skip to content

Commit 91273b4

Browse files
authored
Merge pull request #124 from fact-project/better_reweighting
Add power law with exponential cutoff
2 parents 97adc5d + 88191f1 commit 91273b4

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

fact/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.23.0
1+
0.23.0

fact/analysis/statistics.py

+49-16
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,45 @@ def power_law(
7474
return flux_normalization * (energy / e_ref)**(spectral_index)
7575

7676

77+
def power_law_exponential_cutoff(
78+
energy: u.TeV,
79+
flux_normalization: (FLUX_UNIT, POINT_SOURCE_FLUX_UNIT),
80+
spectral_index,
81+
e_cutoff: u.TeV,
82+
e_ref: u.TeV=1 * u.TeV,
83+
):
84+
r'''
85+
A power law with an additional exponential cutoff
86+
87+
.. math::
88+
\phi = \phi_0 \cdot (E / E_{\mathrm{ref}})^{\gamma} \cdot e^{- E / E_{\mathrm{cutoff}}}
89+
90+
Parameters
91+
----------
92+
energy: Quantity[energy]
93+
energy points to evaluate
94+
flux_normalization: Quantity[m**-2 s**-2 TeV**-1]
95+
Flux normalization
96+
spectral_index: float
97+
Spectral index
98+
e_ref: Quantity[energy]
99+
The reference energy
100+
'''
101+
tau = np.exp(energy / e_cutoff)
102+
return power_law(energy, flux_normalization, spectral_index, e_ref) * tau
103+
104+
77105
@u.quantity_input
78-
def curved_power_law(
106+
def log_parabola(
79107
energy: u.TeV,
80108
flux_normalization: (FLUX_UNIT, POINT_SOURCE_FLUX_UNIT),
81109
a,
82110
b,
83-
e_ref: u.TeV=1 * u.TeV,
111+
e_ref: u.TeV = 1 * u.TeV,
84112
):
85113
r'''
86-
Curved power law
114+
Log-Parabola power law, power law with an additional energy dependent term
115+
in the exponent.
87116
88117
.. math::
89118
\phi = \phi_0 \cdot E ^ {a + b \cdot \log_{10}(E)}
@@ -95,13 +124,13 @@ def curved_power_law(
95124
flux_normalization: float
96125
Flux normalization
97126
a: float
98-
Parameter `a` of the curved power law
127+
Parameter `a` of the curved power law
99128
b: float
100-
Parameter `b` of the curved power law
129+
Parameter `b` of the curved power law
101130
e_ref: Quantity[energy]
102131
The reference energy
103132
'''
104-
exp = a + b * np.log10((energy / e_ref))
133+
exp = a + b * np.log10(energy / e_ref)
105134
return flux_normalization * (energy / e_ref) ** exp
106135

107136

@@ -146,37 +175,41 @@ def li_ma_significance(n_on, n_off, alpha=0.2):
146175

147176

148177
@u.quantity_input
149-
def calc_weight_simple_to_curved(
178+
def calc_weight_power_to_logparabola(
150179
energy: u.TeV,
151-
spectral_index,
152-
a,
153-
b,
180+
simulated_index,
181+
target_a,
182+
target_b,
154183
e_ref: u.TeV = 1 * u.TeV,
155184
):
156185
'''
157186
Reweight simulated events from a simulated power law with
158187
spectral index `spectral_index` to a curved power law with parameters `a` and `b`
159188
189+
phi(E) = phi_0 (E / E_ref)^(a + b * log10(E / E_ref))
190+
160191
Parameters
161192
----------
162193
energy: float or array-like
163194
Energy of the events
164-
spectral_index: float
195+
simulated_index: float
165196
Spectral index of the simulated power law
166-
a: float
197+
target_a: float
167198
Parameter `a` of the target curved power law
168-
b: float
199+
target_b: float
169200
Parameter `b` of the target curved power law
170201
'''
171-
return (energy / e_ref) ** (spectral_index + a + b * np.log10(energy / e_ref))
202+
return (energy / e_ref) ** (
203+
target_a + target_b * np.log10(energy / e_ref) - simulated_index
204+
)
172205

173206

174207
@u.quantity_input
175208
def calc_weight_change_index(
176209
energy: u.TeV,
177210
simulated_index,
178211
target_index,
179-
e_ref: u.TeV=1 * u.TeV,
212+
e_ref: u.TeV = 1 * u.TeV,
180213
):
181214
'''
182215
Reweight simulated events from one power law index to another
@@ -204,7 +237,7 @@ def calc_gamma_obstime(
204237
e_ref: u.TeV = 1 * u.TeV,
205238
) -> u.s:
206239
r'''
207-
Calculate the equivalent observation time for a number of simulation enents
240+
Calculate the equivalent observation time for a number of simulation events
208241
209242
The number of events produced by sampling from a power law with
210243
spectral index γ is given by

0 commit comments

Comments
 (0)