[mcstas-users] How to use USERVARS in place of PreMonitor_nD

Peter Kjær Willendrup pkwi at dtu.dk
Tue Jun 9 18:28:26 CEST 2026


(Sorry for potential double-posting, debugging McStas mailman setup)

Dear all,


I received the below question on using USERVARS in place of PreMonitor_nD from Andreas Ostermann - along with a report that the mailinglist seems to be down.

Hence this email is both a test of the mailinglist and includes my response to Andreas.



For the USERVARS concept, I admit that the manual(s) are missing some updates on this point. Here is an initial recipe to get this to work:

1. Add a USERVARS block to your instrument - below DECLARE but before INITIALIZE

USERVARS %{
    // Variables added to the neutron, for measuring starting-coords at the source:
    double Xsrc;
    double Ysrc;
%}

2. Add an EXTEND block to the component where you want to measure the “pre” state:

COMPONENT ColdSource = Some_source(...)
AT (0,0,0) RELATIVE origin
EXTEND %{
    // After initialisation in the source comp,  neutron has starting coords. We measure here:
    Xsrc=x;
    Ysrc=y;
%}

3. Let a later Monitor_nD use Xsrc and Ysrc as “uservars”:


COMPONENT CS_area_mon = Monitor_nD(xmin=-0.01, xmax=0.01,
    ymin=-0.01, ymax=0.01, user1="Xsrc", user2="Ysrc", username1="y at source / [m]", username2=“y at source / [m],
    filename="CS_area_pre.psd",
    options= “user1,user2, all bins=50, all limits=[-0.12 0.12], use premonitor")
     AT (0,0,0.0008)   RELATIVE Arm_SAM_pos
     ROTATED (0,0,0) RELATIVE Arm_SAM_pos

Hope this helps?

Best,
Peter


On 8 Jun 2026, at 10.27, Andreas Ostermann <Andreas.Ostermann at frm2.tum.de> wrote:

Dear colleagues,


    In the past, I have often used the "PreMonitor_nD / Monitor_nD" pair
    to investigate the origin of neutrons which reach the sample in a
    upstream positon. For example:



    *******



    COMPONENT PreMon_CS_area_mon = PreMonitor_nD(monitor_comp =
    CS_area_mon)

      AT (0,0,0.0001)    RELATIVE ColdSource

      ROTATED (0,0,0)  RELATIVE ColdSource



    COMPONENT CS_area_mon = Monitor_nD(xmin=-0.01, xmax=0.01,
    ymin=-0.01, ymax=0.01,

                                       filename="CS_area_pre.psd",

                                       options= "x,y, all bins=50, all
    limits=[-0.12 0.12], use premonitor")

      AT (0,0,0.0008)   RELATIVE Arm_SAM_pos

      ROTATED (0,0,0) RELATIVE Arm_SAM_pos



    *******



    In the current versions of McStas, I am supposed to use the
    "uservars" concept to investigate or plot the status of neutrons
    earlier in the instrument. Unfortunately, after reading the manuals,
    it is not entirely clear to me how I can use the "uservars" concept
    to reconstruct the "PreMonitor_nD / Monitor_nD" bundle.



    I would be grateful for any help.



    Best wishes from the MLZ,



    Andreas Ostermann










--
Dr. Andreas Ostermann
Instrument BIODIFF
Technical University of Munich
Forschungs-Neutronenquelle
Heinz Maier-Leibnitz (FRM II)
Lichtenbergstr. 1
85748 Garching
Germany
Tel.: +49 (0)89 289-14702


andreas.ostermann at frm2.tum.de<mailto:andreas.ostermann at frm2.tum.de>
www.mlz-garching.de <https://mlz-garching.de/>
www.frm2.tum.de<https://www.frm2.tum.de/frm2/startseite/>
Follow us on social media: [error] <https://www.instagram.com/frm_ii/> [error] <https://www.facebook.com/FRMII> [error] <https://www.youtube.com/channel/UCupBuiPnpYkDpuJyQrMsvdA> [error] <https://www.linkedin.com/company/frm-ii/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman2.mcstas.org/pipermail/mcstas-users/attachments/20260609/13a0355b/attachment.htm>


More information about the mcstas-users mailing list