[mcstas-users] TOFRes_sample

Kim Lefmann lefmann at nbi.ku.dk
Tue Oct 24 10:34:12 CEST 2023


Dear Ryoichi,


Since I wrote the code, please let me explain the logic.


For a resolution calculation, the absolute intensity is irrelevant, since you only want to know the widths.


The weighing using the fraction l_full/scat_factor is done to correct for the fact that the outer parts of the sample scatter differently from the center part due to different path lengths:


l_full is exactly the path length in the sample of this neutron ray

scat_factor is the path length for a ray that hits the sample center (and is constant for the full simulation).


The latter path length is used as normalization (and to ensure that the units are correct).


best, Kim


________________________________
From: mcstas-users <mcstas-users-bounces at mcstas.org> on behalf of Ryoichi Kajimoto <ryoichi.kajimoto at j-parc.jp>
Sent: Tuesday, October 24, 2023 9:40:56 AM
To: pkwi at dtu.dk
Cc: mcstas-users at mcstas.org
Subject: Re: [mcstas-users] TOFRes_sample

[You don't often get email from ryoichi.kajimoto at j-parc.jp. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Dear Peter,

> Wrt. the scat_factor, since thickness is an optional parameter (default=0, parametrises an optional "inner hollow”) I believe the formula is OK.
Thanks, but there is a line in line 176:
      p *= l_full/scat_factor;      /* Scattering probability */
where l_full is "Length of full path through sample."

It seems to me that p is defined as the ratio of length of full path through sample to total size of sample. However, if scat_factor is as it is, p can be larger than unity.

Best regards,

Ryoichi


Peter Kjær Willendrup wrote on 2023/10/24 16:12:
> Dear Ryochi,
>
> Once I have the edits in place and a running instrument I will send the modified component to this mailinglist thread.
>
> Wrt. the scat_factor, since thickness is an optional parameter (default=0, parametrises an optional "inner hollow”) I believe the formula is OK.
>
> Best
> Peter
>
> On 24 Oct 2023, at 07.20, Ryoichi Kajimoto <ryoichi.kajimoto at j-parc.jp> wrote:
>
> Dear Peter,
>
> Thank you for the prompt response. I hope this issue will be solved soon.
>
> I have another question regarding TOFRes_sample.
>
> On line 169 of TOFRes_sample.comp, there is a code:
>       scat_factor = 2*(radius-thickness);
>
> But is this correct? I think scat_factor should be 2*radius.
>
>
> Best regards,
>
> Ryoichi
>
> Peter Kjær Willendrup wrote on 2023/10/24 3:07:
> Dear Ryoichi Kajimoto,
>
>
> Thank you for reporting this issue, you are completely right in pointing out that needed modifications are missing in the McStas 3.4 version of TOFRes_sample.
> (This has gone unnoticed since a test-instrument for the said component was not defined in our test suite, sorry for this.)
>
> I have defined a GitHub issue at https://github.com/McStasMcXtrace/McCode/issues/1512 and will implement the needed changes as soon as time allows.
>
>
> Best,
> Peter Willendrup
>
> On 23 Oct 2023, at 13.29, Ryoichi Kajimoto <ryoichi.kajimoto at j-parc.jp> wrote:
>
> Hi,
>
> I'm simulating a resolution function of a direct-geometry TOF spectrometer. I use TOFRes_sample() for the sample and Res_monitor() for the monitor.
>
> My code worked with McStas 3.1, but it cannot be compiled with McStas 3.4.
> I would appreciate if you could provide any solution.
>
> Converting the .instr file to .c with mcstas command worked fine without an error, but compiling it with gcc -O3 -lm stops with an error message attached below.
>
> I found that Res_monitor.comp and Res_sample.comp were greatly updated in McStas 3.4 but TOFRes_sample.comp was unchanged. I suspect that TOFRes_sample.comp is not compatible with Res_monitor.comp...
>
> Thank you in advance,
>
> Ryoichi Kajimoto
>
>
> ==================================
>
> SIKIResSim.c: In function ‘Table_Read_Handle’:
> SIKIResSim.c:7518:60: warning: format ‘%i’ expects argument of type ‘int’, but argument 5 has type ‘long int’ [-Wformat=]
> 7518 |       fprintf(stderr,"Warning: Read_Table :%s %s Data has %i invalid lines (*****). Ignored.\n",
>      |                                                           ~^
>      |                                                            |
>      |                                                            int
>      |                                                           %li
> ......
> 7521 |         count_invalid);
>      |         ~~~~~~~~~~~~~
>      |         |
>      |         long int
> SIKIResSim.c: In function ‘_resmonitor_setpos’:
> SIKIResSim.c:13221:6: error: ‘RSsample’ undeclared (first use in this function)
> 13221 |   if(RSsample && strlen(RSsample))
>      |      ^~~~~~~~
> SIKIResSim.c:13221:6: note: each undeclared identifier is reported only once for each function it appears in
> SIKIResSim.c: In function ‘class_Res_monitor_init’:
> SIKIResSim.c:663:33: warning: format not a string literal and no format arguments [-Wformat-security]
> 663 | #define NAME_CURRENT_COMP (_comp->_name)
>      |                           ~~~~~~^~~~~~~~
> SIKIResSim.c:13781:48: note: in expansion of macro ‘NAME_CURRENT_COMP’
> 13781 |   if (!strcmp(filename,"\0")) sprintf(filename,NAME_CURRENT_COMP);
>      |                                                ^~~~~~~~~~~~~~~~~
> SIKIResSim.c:641:10: error: ‘_class_Res_sample_parameters’ undeclared (first use in this function); did you mean ‘_class_TOFRes_sample_parameters’?
> 641 |     &( ((_class_ ## type ##_parameters *) _getvar_parameters(compname))->par )
>      |          ^~~~~~~
> SIKIResSim.c:13835:18: note: in expansion of macro ‘COMP_GETPAR3’
> 13835 |   int *index_ptr=COMP_GETPAR3(Res_sample, res_sample_comp, compindex);
>      |                  ^~~~~~~~~~~~
> SIKIResSim.c:641:41: error: expected expression before ‘)’ token
> 641 |     &( ((_class_ ## type ##_parameters *) _getvar_parameters(compname))->par )
>      |                                         ^
> SIKIResSim.c:13835:18: note: in expansion of macro ‘COMP_GETPAR3’
> 13835 |   int *index_ptr=COMP_GETPAR3(Res_sample, res_sample_comp, compindex);
>      |                  ^~~~~~~~~~~~
>
> ==================================
>
> This is how I use TOFRes_sample() and Res_monitor():
>
> ==================================
>
> SPLIT COMPONENT RSsample = TOFRes_sample(
> thickness = sample_r-0.0001,
> radius = sample_r,
> yheight = sample_h,
> focus_xw = Wdx+0.001,
> focus_yh = Wdy+0.001,
> target_x = sample_det_x,
> target_y = sample_det_y,
> target_z = sample_det_z,
> time_bin = (ts+tsd+toffset)*1e6,
> time_width = Dtsd*1e6
> ) AT (0,0,L1) RELATIVE mod
>
> COMPONENT det_pos = Arm()
> AT (sample_det_x,sample_det_y,sample_det_z) RELATIVE RSsample
> ROTATED (0,atan(sample_det_x/sample_det_z)*RAD2DEG,0) RELATIVE RSsample
>
> COMPONENT resmonitor = Res_monitor(
> res_sample_comp = RSsample,
> options = "cylinder",
> xwidth = Wdx, yheight = Wdy,
> filename = "resmonitor.dat"
> ) AT (0,0,0) RELATIVE det_pos
> _______________________________________________
> mcstas-users mailing list
> mcstas-users at mcstas.org
> https://mailman2.mcstas.org/mailman/listinfo/mcstas-users
>
>
> Peter Kjær Willendrup
> Forskningsingeniør, Specialkonsulent
>
> DTU Physics
> [image001.gif]
>
>
> Technical University of Denmark
>
>
> [image002.gif]
>
>
> Department of Physics
> Fysikvej
> Building 307
> DK-2800 Kongens Lyngby
>
> Main office at
> ESS DMSC
> COBIS, Ole Maaløes vej 3, 2200 København N, Denmark
>
> Direct +45 2125 4612
> Mobil +45 2125 4612
> Fax +45 4593 2399
> pkwi at fysik.dtu.dk<mailto:pkwi at fysik.dtu.dk>
>
>
> Peter Kjær Willendrup
> Forskningsingeniør, Specialkonsulent
>
> DTU Physics
> [image001.gif]
>
>
> Technical University of Denmark
>
>
> [image002.gif]
>
>
> Department of Physics
> Fysikvej
> Building 307
> DK-2800 Kongens Lyngby
>
> Main office at
> ESS DMSC
> COBIS, Ole Maaløes vej 3, 2200 København N, Denmark
>
> Direct +45 2125 4612
> Mobil +45 2125 4612
> Fax +45 4593 2399
> pkwi at fysik.dtu.dk
>
_______________________________________________
mcstas-users mailing list
mcstas-users at mcstas.org
https://mailman2.mcstas.org/mailman/listinfo/mcstas-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman2.mcstas.org/pipermail/mcstas-users/attachments/20231024/2b515621/attachment-0001.html>


More information about the mcstas-users mailing list