From 4b91236fe00e7e20dcc605681e8bfbf87535eca3 Mon Sep 17 00:00:00 2001 From: Diablo Date: Wed, 2 Sep 2026 14:34:52 +0200 Subject: [PATCH 1/6] Outgoing attenuation when truncating the order should be in accordance with the total cross section, not only the absorption cross section --- mcstas-comps/samples/Single_crystal.comp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcstas-comps/samples/Single_crystal.comp b/mcstas-comps/samples/Single_crystal.comp index 964c331c17..3897b6ff75 100644 --- a/mcstas-comps/samples/Single_crystal.comp +++ b/mcstas-comps/samples/Single_crystal.comp @@ -1417,7 +1417,7 @@ TRACE if ((order && !(extra_order) && event_counter >= order) || (order && extra_order && event_counter >= order + extra_order)) { // Exit due to truncated order, weight with relevant cross-sections to distance l_full - p *= exp (-abs_xlen * l_full); + p *= exp (-tot_xlen * l_full); intersect = 0; break; } From c280c4e8f4b89da0305c746a8d4361ecb7e7bbb2 Mon Sep 17 00:00:00 2001 From: Diablo Date: Wed, 2 Sep 2026 14:39:05 +0200 Subject: [PATCH 2/6] my_s is used to attenuate due to the sampling of the position, and therefore it should be the total scattering cross section of the powder, and not only the incoherent xsect, no matter the order --- mcstas-comps/samples/PowderN.comp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mcstas-comps/samples/PowderN.comp b/mcstas-comps/samples/PowderN.comp index 36f6baf586..f3adcf4a6e 100644 --- a/mcstas-comps/samples/PowderN.comp +++ b/mcstas-comps/samples/PowderN.comp @@ -1142,11 +1142,7 @@ TRACE } else { dt = dt * (t3 - t2) + (t2 - t0); /* Possibly also 'backside' part */ } - if (order) { - my_s = line_info.my_s_v2_sum / (v * v) + line_info.my_inc; - } else { - my_s = line_info.my_inc; - } + my_s = line_info.my_s_v2_sum / (v * v) + line_info.my_inc; /* Total attenuation from scattering */ lfree = 0; ntype = rand01 (); From e9e270cbbff718f2b925245a2ad861667a57d9f6 Mon Sep 17 00:00:00 2001 From: Diablo Date: Wed, 2 Sep 2026 14:44:43 +0200 Subject: [PATCH 3/6] Remove unused order parameter --- mcstas-comps/samples/PowderN.comp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mcstas-comps/samples/PowderN.comp b/mcstas-comps/samples/PowderN.comp index f3adcf4a6e..e5fb1e2931 100644 --- a/mcstas-comps/samples/PowderN.comp +++ b/mcstas-comps/samples/PowderN.comp @@ -165,7 +165,6 @@ * density: [g/cm^3] Density of material. rho=density/weight/1e24*N_A. * nb_atoms: [1] Number of sub-unit per unit cell, that is ratio of sigma for chemical formula to sigma per unit cell * target_index: [1] Relative index of component to focus incoherent scattering at, e.g. next is +1 -* order: [1] Flag that determines whether the intensity should (1) not (0) be dampened by weighting multiple scattering * * CALCULATED PARAMETERS: * line_info: [struct] internal structure containing many members/info @@ -206,7 +205,7 @@ SETTING PARAMETERS (string reflections="NULL", string geometry="NULL", radius=0, yheight=0, xwidth=0, zdepth=0, thickness=0, pack=1, Vc=0, sigma_abs=0, sigma_inc=0, delta_d_d=0, p_inc=0.1, p_transmit=0.1, DW=0, nb_atoms=1, d_omega=0, d_phi=0, tth_sign=0, p_interact=0.8, - concentric=0, density=0, weight=0, barns=1, Strain=0, focus_flip=0, int target_index=0, int order=1) + concentric=0, density=0, weight=0, barns=1, Strain=0, focus_flip=0, int target_index=0) DEPENDENCY "@NCRYSTALFLAGS@" From 5aca7d49040ca0e7ba2aca6cf225bf7133eb21c4 Mon Sep 17 00:00:00 2001 From: Diablo Date: Wed, 2 Sep 2026 15:05:44 +0200 Subject: [PATCH 4/6] apply clangformat to PowderN component --- mcstas-comps/samples/PowderN.comp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mcstas-comps/samples/PowderN.comp b/mcstas-comps/samples/PowderN.comp index e5fb1e2931..88aef02b8e 100644 --- a/mcstas-comps/samples/PowderN.comp +++ b/mcstas-comps/samples/PowderN.comp @@ -451,9 +451,7 @@ SHARE struct line_data* list = NULL; list = (struct line_data*)malloc (nhkl * sizeof (struct line_data)); if (!list) { - exit (fprintf (stderr, - "PowderN: %s: Error: Could not allocate line array\n", - info->compname)); + exit (fprintf (stderr, "PowderN: %s: Error: Could not allocate line array\n", info->compname)); } info->sigma_a = ncrystal_info_getxsectabsorption (ncobj); info->sigma_i = ncrystalpowdern_determine_sigma_inc (ncobj); @@ -607,9 +605,7 @@ SHARE /* allocate line_data array */ list = (struct line_data*)malloc (size * sizeof (struct line_data)); if (!list) { - exit (fprintf (stderr, - "PowderN: %s: Error: Could not allocate line array\n", - info->compname)); + exit (fprintf (stderr, "PowderN: %s: Error: Could not allocate line array\n", info->compname)); } for (i = 0; i < size; i++) { From 8ba8710e99ecfbf0782d008f65446825eb234db1 Mon Sep 17 00:00:00 2001 From: Diablo Date: Thu, 3 Sep 2026 13:36:15 +0200 Subject: [PATCH 5/6] Revert attenuation in Single crystal component --- mcstas-comps/samples/Single_crystal.comp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcstas-comps/samples/Single_crystal.comp b/mcstas-comps/samples/Single_crystal.comp index 3897b6ff75..964c331c17 100644 --- a/mcstas-comps/samples/Single_crystal.comp +++ b/mcstas-comps/samples/Single_crystal.comp @@ -1417,7 +1417,7 @@ TRACE if ((order && !(extra_order) && event_counter >= order) || (order && extra_order && event_counter >= order + extra_order)) { // Exit due to truncated order, weight with relevant cross-sections to distance l_full - p *= exp (-tot_xlen * l_full); + p *= exp (-abs_xlen * l_full); intersect = 0; break; } From 37d3cf59f0d73c4ffe4f796bdaf4d2373bbd40d1 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 3 Sep 2026 19:46:39 +0200 Subject: [PATCH 6/6] Revised %Example block based on ~20 mctest runs in the 1e6-1e8 range --- .../Test_Powders/Test_Powders.instr | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/mcstas-comps/examples/Tests_samples/Test_Powders/Test_Powders.instr b/mcstas-comps/examples/Tests_samples/Test_Powders/Test_Powders.instr index 72b0faf5fb..8373889e83 100644 --- a/mcstas-comps/examples/Tests_samples/Test_Powders/Test_Powders.instr +++ b/mcstas-comps/examples/Tests_samples/Test_Powders/Test_Powders.instr @@ -14,38 +14,38 @@ * %Description * A test instrument for Powder output from different sample components. * -* %Example: lambda=2.5 directbeam=0 comp=0 material=Ge SPLITS=1 Detector: Sph_mon_I=3.67e+08 -* %Example: lambda=2.5 directbeam=0 comp=0 material=Ge SPLITS=1 Detector: psd_mon_I=7.35e+05 -* %Example: lambda=2.5 directbeam=0 comp=1 material=Ge SPLITS=1 Detector: Sph_mon_I=4.2e+08 -* %Example: lambda=2.5 directbeam=0 comp=1 material=Ge SPLITS=1 Detector: psd_mon_I=8.3e+05 -* %Example: lambda=2.5 directbeam=0 comp=2 material=Ge SPLITS=1 Detector: Sph_mon_I=4.2e+08 -* %Example: lambda=2.5 directbeam=0 comp=2 material=Ge SPLITS=1 Detector: psd_mon_I=8.3e+05 -* %Example: lambda=2.5 directbeam=0 comp=3 material=Ge SPLITS=1 Detector: Sph_mon_I=4.2e+08 -* %Example: lambda=2.5 directbeam=0 comp=3 material=Ge SPLITS=1 Detector: psd_mon_I=8.3e+05 -* %Example: lambda=2.5 directbeam=0 comp=0 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=9.1e+07 -* %Example: lambda=2.5 directbeam=0 comp=0 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=1.94e+05 -* %Example: lambda=2.5 directbeam=0 comp=1 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=1.1e+08 -* %Example: lambda=2.5 directbeam=0 comp=1 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=2e+05 -* %Example: lambda=2.5 directbeam=0 comp=2 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=1.1e+08 -* %Example: lambda=2.5 directbeam=0 comp=2 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=2e+05 -* %Example: lambda=2.5 directbeam=0 comp=3 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=1.1e+08 -* %Example: lambda=2.5 directbeam=0 comp=3 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=2.19e+05 -* %Example: lambda=2.5 directbeam=0 comp=0 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=2.48e+08 -* %Example: lambda=2.5 directbeam=0 comp=0 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=1.78e+05 -* %Example: lambda=2.5 directbeam=0 comp=1 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=3.1e+08 -* %Example: lambda=2.5 directbeam=0 comp=1 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=2.1e+05 -* %Example: lambda=2.5 directbeam=0 comp=2 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=3.1e+08 -* %Example: lambda=2.5 directbeam=0 comp=2 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=1.9e+05 -* %Example: lambda=2.5 directbeam=0 comp=3 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=3.1e+08 -* %Example: lambda=2.5 directbeam=0 comp=3 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=1.9e+05 -* %Example: lambda=2.5 directbeam=0 comp=0 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.13e+08 -* %Example: lambda=2.5 directbeam=0 comp=0 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=3.2e+05 -* %Example: lambda=2.5 directbeam=0 comp=1 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.5e+08 -* %Example: lambda=2.5 directbeam=0 comp=1 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=3.4e+05 -* %Example: lambda=2.5 directbeam=0 comp=2 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.5e+08 -* %Example: lambda=2.5 directbeam=0 comp=2 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=3.4e+05 -* %Example: lambda=2.5 directbeam=0 comp=3 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.5e+08 -* %Example: lambda=2.5 directbeam=0 comp=3 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=3.4e+05 +* %Example: lambda=2.5 directbeam=0 comp=0 material=Ge SPLITS=1 Detector: Sph_mon_I=3.67298e+08 +* %Example: lambda=2.5 directbeam=0 comp=0 material=Ge SPLITS=1 Detector: psd_mon_I=773137 +* %Example: lambda=2.5 directbeam=0 comp=1 material=Ge SPLITS=1 Detector: Sph_mon_I=3.85947e+08 +* %Example: lambda=2.5 directbeam=0 comp=1 material=Ge SPLITS=1 Detector: psd_mon_I=811340 +* %Example: lambda=2.5 directbeam=0 comp=2 material=Ge SPLITS=1 Detector: Sph_mon_I=3.914e+08 +* %Example: lambda=2.5 directbeam=0 comp=2 material=Ge SPLITS=1 Detector: psd_mon_I=723428 +* %Example: lambda=2.5 directbeam=0 comp=3 material=Ge SPLITS=1 Detector: Sph_mon_I=4.68483e+08 +* %Example: lambda=2.5 directbeam=0 comp=3 material=Ge SPLITS=1 Detector: psd_mon_I=786876 +* %Example: lambda=2.5 directbeam=0 comp=0 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=9.12821e+07 +* %Example: lambda=2.5 directbeam=0 comp=0 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=197078 +* %Example: lambda=2.5 directbeam=0 comp=1 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=1.10426e+08 +* %Example: lambda=2.5 directbeam=0 comp=1 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=230205 +* %Example: lambda=2.5 directbeam=0 comp=2 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=9.9981e+07 +* %Example: lambda=2.5 directbeam=0 comp=2 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=178603 +* %Example: lambda=2.5 directbeam=0 comp=3 material=Al twotheta=76.5 SPLITS=1 Detector: Sph_mon_I=1.20784e+08 +* %Example: lambda=2.5 directbeam=0 comp=3 material=Al twotheta=76.5 SPLITS=1 Detector: psd_mon_I=204570 +* %Example: lambda=2.5 directbeam=0 comp=0 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=2.48616e+08 +* %Example: lambda=2.5 directbeam=0 comp=0 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=171164 +* %Example: lambda=2.5 directbeam=0 comp=1 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=2.93457e+08 +* %Example: lambda=2.5 directbeam=0 comp=1 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=196096 +* %Example: lambda=2.5 directbeam=0 comp=2 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=3.11548e+08 +* %Example: lambda=2.5 directbeam=0 comp=2 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=183894 +* %Example: lambda=2.5 directbeam=0 comp=3 material=LaMnO3 twotheta=80 SPLITS=1 Detector: Sph_mon_I=3.40544e+08 +* %Example: lambda=2.5 directbeam=0 comp=3 material=LaMnO3 twotheta=80 SPLITS=1 Detector: psd_mon_I=192638 +* %Example: lambda=2.5 directbeam=0 comp=0 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.1313e+08 +* %Example: lambda=2.5 directbeam=0 comp=0 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=305947 +* %Example: lambda=2.5 directbeam=0 comp=1 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.35283e+08 +* %Example: lambda=2.5 directbeam=0 comp=1 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=341363 +* %Example: lambda=2.5 directbeam=0 comp=2 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.49715e+08 +* %Example: lambda=2.5 directbeam=0 comp=2 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=375832 +* %Example: lambda=2.5 directbeam=0 comp=3 material=NaCl twotheta=78 SPLITS=1 Detector: Sph_mon_I=2.69224e+08 +* %Example: lambda=2.5 directbeam=0 comp=3 material=NaCl twotheta=78 SPLITS=1 Detector: psd_mon_I=311818 * * %Parameters * comp: [1] 0=PowderN-with-NCMAT, 1=PowderN, 2=Single_crystal, 3=NCrystal