Skip to content
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

Add Ideal instrument #24

Open
RastislavTuranyi opened this issue Jan 30, 2025 · 9 comments
Open

Add Ideal instrument #24

RastislavTuranyi opened this issue Jan 30, 2025 · 9 comments
Labels
enhancement New feature or request

Comments

@RastislavTuranyi
Copy link
Collaborator

Add an ideal instrument that will have models such as:

  • square
  • triangle
@RastislavTuranyi RastislavTuranyi added the enhancement New feature or request label Jan 30, 2025
@oerc0122
Copy link
Contributor

  • Gaussian
  • Lorentzian
  • Ikeda-Carpenter

@RastislavTuranyi
Copy link
Collaborator Author

I have started thinking about this and what I am not clear on is how exactly the model should work. For example, given the Gaussian model, should it

  • accept a single float in __init__, and then get_characteristics will return that float as the sigma for each value of [Q, w], and get_kernel will create an identical kernel?
  • or accept a Callable in __init__ (which will define the relationship between [Q, w] and sigma), and then get_characteristics will call the function for each value of [Q, w], and get_kernel will use the callable to create different kernels?
  • or something else?

@RastislavTuranyi
Copy link
Collaborator Author

Assuming the first case above (constant kernel), the question becomes how to handle the triangular distribution - in scipy, the Gaussian and Lorentzian distributions are centered with the peak at 0:

Image

but the triangular distribution is not (it is instead set up so that the slope starts at 0):

Image

So, should they all be left as-is (and therefore have different centerings), or should the triangular one be re-centered, and if so, should it be centered on its peak or its STD? (these are at different places in non-isosceles triangles)

@ajjackson
Copy link
Collaborator

ajjackson commented Feb 3, 2025

For this purpose I would expect we are generally dealing with isosceles triangles; they represent the convolution of two equal-width boxcars. Do you know of any codes using skewed triangles, @oerc0122 ?

Shifting the mean to zero is a bit more general, and works out to equal the peak in that case.

@oerc0122
Copy link
Contributor

oerc0122 commented Feb 3, 2025

I don't know anything using skewed triangles, no, if you're reducing the approximation as far as a triangle (fundamentally unphysical as undifferentiable at the peak) it doesn't make much sense to have a skew.

@ajjackson
Copy link
Collaborator

Is there a particular Ikeda-Carpenter resolution function you have in mind? As described in the paper, the function is in time and not symmetric about zero, so not a suitable kernel for energy resolution. We probably want a TOF resolution function that is derived from this using some instrument parameter(s)?

@RastislavTuranyi
Copy link
Collaborator Author

How about this @oerc0122 @mducle ?

def ik3(x, width):
    x = x / width
    return (0.0625 * x ** 2 * np.exp(- 0.5 * x)) / width

Found this in the VISION resolution paper (+ our own scaling). Gives this kind of plot:

Image

which seems like the tail is in the wrong direction for the energy domain?

@mducle
Copy link
Member

mducle commented Feb 13, 2025

Regarding the Ikeda-Carpenter function - it's complicated...

As described in the paper, the function is in time and not symmetric about zero, so not a suitable kernel for energy resolution. We probably want a TOF resolution function that is derived from this using some instrument parameter(s)?

Yes, that's right. In addition one of the parameters which enter into the function vs ToF (alpha) is neutron energy (wavelength) dependent - so the Ikeda-Carpenter function is both a function of neutron energy and ToF. What this means for us is that the peak profile (width) will change with energy transfer.

An additional complication is the difference between the direct (e.g. MAPS/MERLIN/LET) and indirect (e.g. TOSCA/VISION/IRIS/OSIRIS) spectrometers. In the direct geometry spectrometers a narrow band of incident neutron energies (velocities) are selected by a mechanical chopper. You can imagine this as a gate which opens at a particular time to let neutrons with a specific velocity pass (if they are all emitted at a particular time t0). However, as neutrons are not all emitted at t0 neutrons which are emitted later have to have a faster velocity to pass through the chopper. This means that the peak shape in a direct geometry instrument is "flipped"/opposite to the normal Ikeda-Carpenter form. That is there is a gradual slope on the negative (neutron energy gain / shorter ToF / faster neutrons) side and a sharp drop off on the positive (neutron energy loss / longer ToF / slower neutrons) side. This "flip" does not occur for an indirect instrument like VISION hence they can use the standard Ikeda-Carpenter form.

Another simplification in the form you quoted seems to be ignoring the energy/wavelength dependence of the width. This dependence is approximately proportional to the neutron velocity so it is proportional to the square-root of the energy transfer... I guess this is a relatively slow function that within a narrow enough energy it can be ignored (particularly if you're looking at higher energies).

Anyway, as far as I know we don't really use the proper Ikeda-Carpenter function for resolution because of the complications above. In TobyFit/Horace the Ikeda-Carpenter formulism is used to derive an energy dependent width which is then used to fix a Gaussian or pseudo-voigt lineshape. There is an alternative option in TobyFit/Horace to use a look-up table calculated from McStas which gives the full lineshape as a function of neutron energy and ToF - I guess this could be calculated from the Ikeda-Carpenter function but we'd have to do some measurements to fix the alpha and beta parameters and we haven't done that for most of our instruments.

@ajjackson
Copy link
Collaborator

Thanks, Duc, very helpful! For this particular feature (an "ideal" instrument for testing and benchmarking) I think we want an energy-independent form anyway; it can be matched to individual peaks. Flipping the direction is also simple enough.

What worries me more is that you mention one of the parameters (alpha) being energy-dependent --- but presumably not the beta and R parameters? So this energy form has three parameters at work while our uniform scaling only gives one adjustment point. That suggests we don't have enough degrees of freedom here to match other data/models. Do you know where we can find an equally flexible energy-domain function?

I'm currently working on a look-up table resolution function for TOSCA based on McStas data. Interestingly the long tails are on the low-energy-transfer side, as you described for direct-geometry? Presumably they arise by a different mechanism.

If similar tables are available for other instruments in TobyFit it would be great to incorporate them into ResINS; how many dimensions (q,ω) do they describe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants