UCN

From DaqWiki
Jump to navigation Jump to search

The Ultracold Neutron group, now the TRIUMF Ultracold Advanced Neutron (TUCAN) collaboration was created to measure the neutron electric dipole moment (nEDM). This fundamental property, if non-zero, has serious ramifications for resolving the Baryogenesis problem.

Overview

The project has two main components: (a) the UCN source and (b) the nEDM experiment.

The source was largely completed and shown to be functional in 2026. It is operated primarily though EPICS, with monitoring though MIDAS histories with a MySQL database. It operates on beamline 1U (BL1U), splitting off of 1V (which later becomes BL1A). With a fast kicker magnet, the TUCAN collaboration can kick individual beam buckets to BL1U to take a fraction of beam, while enabling beam to BL1A. Design operating current is 40 uA. The UCN source has two end stations for experiments: one for the nEDM experiment, and the other is planned for PENeLOPE.

The nEDM experiment is the primary experiment for the UCN source and is composed of many subsystems, each with their own controls and DAQ setup. Experiments are generally conducted as follows:

  1. produce UCNs in the source,
  2. open a valve to let the UCNs diffuse to the experimental chamber
  3. store the UCNs in the chamber for some time, while applying high voltage, and RF pulses
  4. open the chamber valve to let the UCNs diffuse to the detectors

The subsystems with DAQ interfaces are as follows:

UCN Source

Produces UCN

Controlled through EPICS, monitored with MIDAS. Some MIDAS controls are implemented, such as the AutoStat page and the UCN sequencer.

Comagnetometer

An atomic gas (199Hg) inhabits the cell the UCNs are stored in. The gas is polarized with a free laser, and that polarization state is also measured with a laser. Measures magnetic field.

DAQ not yet implemented

Cs Magnetometers

An array of glass cells containing Cs gas are distributed inside the magnetically shielded room. The polarization state is also pumped and probed with lasers, this time through fibre optics. Measures magnetic field gradients.

DAQ exists as a set of student python scripts, yet to be integrated into MIDAS

B0 Coil

A coil which produces a highly stable and uniform static magnetic field

DAQ not yet implemented

B1 Coil

A coil which produces the oscillating RF fields for spin flips

DAQ not yet implemented

Shim Coils

An array of coils inside the MSR to homogenize the field

DAQ exists as a python script which controls an arduino, yet to be integrated into MIDAS

The main repository is here, with the arduino code here.

Guiding coils

An array of coils to maintain UCN polarization in their journey to and from the magnetically shielded room

DAQ not yet implemented

Ambient Magnetic Coil (AMC)

A large Helmholtz coil to counteract the cyclotron magnetic field

DAQ not yet implemented

High voltage

A large electric field to tease out the electric dipole moment

DAQ not yet implemented

Ambient monitoring

Monitoring of ambient temperature and magnetic field

Temperature

Measured through "canaries": battery-powered arduinos with a temperature sensor on the TRIUMF IOT network. Integrated into MIDAS. Frontend repo

Magnetic Fields

Measured through fluxgates and a custom DAQ produced by the TRIUMF electronics group. Frontend repo

Machines

The below list is incomplete, needs expanding

DAQ Computers in use by the UCN group (last updated Jul 23, 2026)
Hostname (.triumf.ca) Purpose Location OS Status
daq01.ucn Legacy primary DAQ machine and MIDAS host UCN counting room CentOS7 Active
daq02.ucn Runs digitizer frontend Meson hall B2 CentOS7 Active
daq04.ucn Multi-monitor EPICS control station UCN counting room Ubuntu 24 Active
daq06.ucn Test environment Virtual machine Ubuntu 24 Active
daq07.ucn Laser enclosure frontend Laser enclosure, Meson hall B2 Ubuntu 24 Active
tucan01.ucn New primary DAQ machine and MIDAS host UCN counting room Ubuntu 24 In setup
ktm-readout.ucn Kicker timing monitor frontend and web host Cyclotron roof Ubuntu 24 Active, untested
ktmserver Legacy KTM web host Virtual machine CentOS7 Active

DAQ Software and Setup

Directory Organization

Here we describe the organization and setup of the DAQ computer. While there are many other directories not listed here, they are outside of the core functionality of the main DAQ.

  • /home/ucn/ (shared home)
  • /data3/ (large storage drive)
    • ucn/midas_files (.mid.gz files and similar)
    • ucn/root_files (.root, for analysis, after preprocessing)

Setup Instructions

Here's the general path to setting up the main DAQ machine (steps taken on tucan01.ucn):

Install ubuntu 24

As per the instructions here

Install MySQL

Create partition on drive for MySQL histories

In ZFS you don't really create fixed-size "partitions" the way you would with fdisk/gparted. Instead a pool (created from disks) is carved into datasets (filesystems) or volumes/zvols (block devices). Space is shared from the pool by default, and you constrain size with quota/reservation (for datasets) or a fixed volume size (for zvols).

See existing pools

ucn@tucan01:~$ zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
bpool  1.88G   210M  1.67G        -         -     7%    10%  1.00x    ONLINE  -
rpool   936G  6.09G   930G        -         -     0%     0%  1.00x    ONLINE  -

Clearly rpool is the main filesystem. We want to allocate about 700 GB from this for the mysql database:

sudo zfs create rpool/sqlstorage # create
sudo zfs set reservation=700G rpool/sqlstorage # guarantee the size that other datasets can't eat into
zfs list # check success

Install MySQL

We will install mysql and set the data base location to /sqlstorage (following this tutorial). Note that the mysql error log defaults to /var/log/mysql/error.log in the case of issues.

sudo apt install mysql-server
sudo systemctl status mysql-server # should show enabled and active

Now we find the default database directory, should likely be /var/lib/mysql. If not make the substitute in the commands that follow.

sudo mysql -u root
SELECT @@datadir;
exit;

With this confirmed, we change the data directory:

sudo systemctl stop mysql
sudo systemctl status mysql # confirmed inactive
sudo rsync -av /var/lib/mysql /sqlstorage # copy database to new location
sudo mv /var/lib/mysql /var/lib/mysql.bak # rename old database in case of errors

Now edit the basic settings section of the config file (sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf) to match the following:

#
# * Basic Settings
#
user            = mysql
# pid-file      = /var/run/mysqld/mysqld.pid
# socket        = /var/run/mysqld/mysqld.sock
port            = 3306
datadir         = /sqlstorage/mysql

Even if apparmor is disabled, you still need to change the alias file and re-enable apparmor, otherwise you will get the error Job for mysql.service failed because the control process exited with error code.. To resolve this, edit the apparmor alias file (sudo vim /etc/apparmor.d/tunables/alias) and add the following line to the end:

alias /var/lib/mysql/ -> /sqlstorage/mysql/,

Apply changes by restarting apparmor, then re-disable:

sudo systemctl restart apparmor
sudo systemctl stop apparmor
sudo systemctl disable apparmor
sudo systemctl status apparmor

Then restart the server

sudo systemctl restart mysql

Confirm that it worked by re-checking the data directory inside mysql

sudo mysql -u root
SELECT @@datadir;
exit;

When finished, delete the original directory

sudo rm -rf /var/lib/mysql.bak

Uninstall MySQL (only if needed!)

In the case of serious issue, here are steps to completely purge mysql from your system:

sudo systemctl stop mysql
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
sudo apt autoremove
sudo apt autoclean

Setup MySQL Users and Database

By default there should be a root user which can access the database without any password. Use that and the following commands to set up the database, following the steps in the midas wiki:

sudo mysql -u root

CREATE DATABASE IF NOT EXISTS ucn_history;

CREATE USER 'ucn_reader'@'localhost' IDENTIFIED BY 'password'; # save this password somewhere
CREATE USER 'ucn_writer'@'localhost' IDENTIFIED BY 'password'; # save this password, different from the reader

GRANT SELECT ON ucn_history.* TO ucn_reader@'localhost'; # permissions
GRANT SELECT,INSERT,CREATE,ALTER,INDEX ON ucn_history.* TO 'ucn_writer'@'localhost';

flush privileges;

SHOW GRANTS FOR 'ucn_reader'@'localhost'; # verify that commands worked
SHOW GRANTS FOR 'ucn_writer'@'localhost';

exit;

Setup ODB Connection

First, we check the socket location:

grep sock /etc/mysql/mysql.conf.d/mysqld.cnf

which should result in something like

# socket	= /var/run/mysqld/mysqld.sock

denoting the default location. You can uncomment this line, change it, or leave it as is. We assume that this location is ok and use it in the following.

Now we create the files needed. We do this in /home/ucn/online_tucan01 since we are setting this up in parallel with the already-running instance in /home/ucn/online. If the directory does not exist, create it:

# as user "ucn"
mkdir /home/ucn/online_tucan01

Create ucn_reader file: copy/paste all the following lines

cat <<EOF > /home/ucn/online_tucan01/ucn_reader.txt
server=localhost
port=3306
socket=NULL
database=ucn_history
user=ucn_reader
socket=/var/run/mysqld/mysqld.sock
password=THE PASSWORD FROM EARLIER
EOF

Create ucn_writer file: copy/paste all the following lines

cat <<EOF > /home/ucn/online_tucan01/ucn_writer.txt
server=localhost
port=3306
socket=NULL
database=ucn_history
user=ucn_writer
socket=/datassd/mysql/mysql.sock
password=THE OTHER PASSWORD FROM EARLIER
EOF

Install MIDAS

Install ROOT

Install ROOTANA

Contacts

Some useful contact persons (TRIUMF PIs):

  • R. Picker
  • N. Yazdandoost

Useful Links