-
Notifications
You must be signed in to change notification settings - Fork 0
TMC #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giacomomagni
wants to merge
4
commits into
add_f_total
Choose a base branch
from
add_tmc
base: add_f_total
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
TMC #15
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import numpy as np | ||
| from scipy import integrate | ||
|
|
||
|
|
||
| class TMC_StructureFunction: | ||
| """Compute TMC structure function.""" | ||
|
|
||
| def __init__(self, target_mass, f2, fl=None): | ||
| self.f2 = f2 | ||
| self.fl = fl | ||
| self.target_mass = target_mass | ||
| self.kind = "F2" if self.fl is None else "FL" | ||
|
|
||
| def __call__(self, x, Q): | ||
| self.x = x | ||
| self.Q = Q | ||
|
|
||
| # compute variables | ||
| self.mu = self.target_mass**2 / self.Q**2 | ||
| self.rho = np.sqrt(1 + 4 * self.x**2 * self.mu) # = r = sqrt(tau) | ||
| self.xi = 2 * self.x / (1 + self.rho) | ||
|
|
||
| # run actual computaion | ||
| if self.fl is None: | ||
| return self.tmc_f2() | ||
| return self.tmc_fl() | ||
|
|
||
| def h2(self): | ||
| # TODO: here you need to use interpolation this is too slow | ||
| return integrate.quad( | ||
| lambda u: self.f2(x=u, Q=self.Q) / u, | ||
| self.xi, | ||
| 1, | ||
| ) | ||
|
|
||
| # def tmc_f2_apfel(self): | ||
| # _factor_shifted = self.x**2 / (self.xi**2 * self.rho**3) | ||
| # _factor_h2 = 6.0 * self.mu * self.x**3 / (self.rho**4) | ||
| # F2out = self.f2(x=self.xi, Q=self.Q) | ||
| # h2out = self.h2() | ||
| # return _factor_shifted * F2out + _factor_h2 * h2out | ||
|
|
||
| # def tmc_fl_apfel(self): | ||
| # _factor_shifted = self.x**2 / (self.xi**2 * self.rho) | ||
| # _factor_h2 = 4.0 * self.mu * self.x**3 / (self.rho**2) | ||
| # FLout = self.fl(x=self.xi, Q=self.Q) | ||
| # h2out = self.h2() | ||
| # return _factor_shifted * FLout + _factor_h2 * h2out | ||
|
|
||
| def tmc_f2(self): | ||
| _factor_shifted = self.x**2 / (self.xi**2 * self.rho**3) | ||
| approx_prefactor = _factor_shifted * ( | ||
| 1 + ((6 * self.mu * self.x * self.xi) / self.rho) * (1 - self.xi) ** 2 | ||
| ) | ||
| F2out = self.f2(x=self.xi, Q=self.Q) | ||
| return approx_prefactor * F2out | ||
|
|
||
| def tmc_fl(self): | ||
| _factor_shifted = self.x**2 / (self.xi**2 * self.rho) | ||
| approx_prefactor_F2 = _factor_shifted * ( | ||
| (4 * self.mu * self.x * self.xi) / self.rho * (1 - self.xi) | ||
| + 8 | ||
| * (self.mu * self.x * self.xi / self.rho) ** 2 | ||
| * (-np.log(self.xi) - 1 + self.xi) | ||
| ) | ||
| FLout = self.fl(x=self.xi, Q=self.Q) | ||
| F2out = self.f2(x=self.xi, Q=self.Q) | ||
| return _factor_shifted * FLout + approx_prefactor_F2 * F2out | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was the first attempt of the exact implementation, I think can be removed