Proton Calorimetry/User Interface: Difference between revisions
(→DAQ) |
|||
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==To do list for GUI== | ==To do list for GUI== | ||
* v3.3: | |||
- Upload versions to github | |||
- Update wiki | |||
- Check errors | |||
- Check differences between live calibration and post calibration | |||
* v3.1: | * v3.1: | ||
Line 8: | Line 17: | ||
- Start/Stop button to finish when clicked, not after tinterval ✓ | - Start/Stop button to finish when clicked, not after tinterval ✓ | ||
- Kill shell script from php | - Kill shell script from php ✓ | ||
- Error Bars: check how values are obtained in FTDI | - Error Bars: check how values are obtained in FTDI | ||
- Cache issue, situation has improved but there are some crashes. | - Cache issue, situation has improved but there are some crashes.✓ | ||
- Reverse option: it does not work, always shows same direction. | - Reverse option: it does not work, always shows same direction.✓ | ||
- Fitting of final measurement. | - Fitting of final measurement.✓ | ||
==GUI v3.3== | ==GUI v3.3== | ||
This version of the GUI has three separate webpages: | This version of the GUI has three separate webpages: one for data acquisition (DAQ), one for calibrating data at a desired frequency (Calibrated) and one for the display of previosuly fitted data (Replay). | ||
This version was last modified by Sonia on the 26th of November, 2024. | |||
=== DAQ === | === DAQ === | ||
Line 27: | Line 36: | ||
Single start/stop button that handles the raw acquisition, the live calibration and the postprocessing of the data (fitting it at 25 Hz). | Single start/stop button that handles the raw acquisition, the live calibration and the postprocessing of the data (fitting it at 25 Hz). | ||
To run the GUI we need DAQ.js and DAQ.html. The graph in this webpage displays output_GUI.txt. The actual | To run the GUI we need DAQ.js and DAQ.html. The graph in this webpage displays output_GUI.txt. | ||
File structure: there is an entry textbox, that when clicked assigns the name Run0xy. Three files are produced: YYmmdd_Run0xy_raw.txt, YYmmdd_Run0xy_calibrated.txt and YYmmdd_Run0xy_fitted.txt The actual code work as it follows: | |||
Line 53: | Line 64: | ||
button_message.php sends the word running or stopping to buttonStatus.txt, based on the number of clicks the start/stop button has received. | button_message.php sends the word running or stopping to buttonStatus.txt, based on the number of clicks the start/stop button has received. | ||
=== CALIBRATED === | |||
Performs calibration at a desired frequency, selected from a dropdown menu. It calls calibrateGUI.php, that then calls executeGUI.sh. The shell script calls the cpp code calibrate_rate, that reads the raw data file, calibrates the data and the averages it at the desired frequency. | |||
The graph shows the file output_GUI_Calibrated.txt, that is updated in real time at the desired frequency. | |||
sudo ./calibrate_rate true "$dataDir" "$shortFileName" revB "$frequency" | |||
=== REPLAY === | |||
Replay code is a visualisation tool only. It reads the fitted data, selected from a dropdown menu, and plots every measurement with its fits and values. | |||
==GUI v3.1 and 3.2== | |||
These two versions had some issues because of the FTDI code, so they are skipped. | |||
==GUI v3.01b== | |||
Used for UCLH experiment 2024 | |||
FTDI code: combination of Sonia's + Matt’s -> FTDI_GUI.cpp | |||
Calibrate code: calibrate_fit.cpp | |||
Fit code: sudo ./fit_average false 100 UCLH UCLH/20240418 Run022.txt 25 | |||
- DAQ.js + DAQ.html: show data live | |||
- Replay.js + Replay.html: show data averaged at desired frequency. | |||
==GUI v3.01== | ==GUI v3.01== | ||
Line 68: | Line 93: | ||
As this version is the most stable one with php and sh scripts, below is a detailed explanation of how it works. | As this version is the most stable one with php and sh scripts, below is a detailed explanation of how it works. | ||
DAQ.js calls executeDAQ.php calls executeFTDI.sh and FTDI2 | |||
Need to change the autoclick button: instead of clicking after a certain time it has passed, we now print measurement number + word running to a new file with each measurement, and with last one we print the stopping. If the word stopping is found in the file, the stop button will be automatically clicked. When detector not connected: show an error message to the user (very basic styling for now) + click button to stop acquisition. | |||
Now Measure/Stop button is capable of: | |||
- Starting acquisition | |||
- Stopping when acquisition has finished | |||
- Stop graph when acquiring data | |||
It needs to: | |||
4. Read if detector is not connected and show an error message. | |||
5. Kill the execution of shell script when stop is clicked. | |||
Instead of killing process just execute it based on a word read from a text file. The js calls the button_message.php, that writes the message to a file called buttonStatus.txt | |||
File will either be stopping or running, based on what DAQ is doing. | |||
when live data is being acquired, the change in average.csv is so quick that calibration can’t cope with the speed and skips some measurements | |||
User input values: | |||
$selected_value1 = RunName = Run0xy | |||
$selected_value2 = FSR = 12.5, 350… | |||
$selected_value3 = tINT | |||
$selected_value4 = num_measurements | |||
$selected_value5 = reverse | |||
$selected_value6 = frequency | |||
- Automated File name: we want to start automatically with Run001, and increase it with every run. The increase will happen when the filename box is clicked, but still allow for name modifications if desired. | |||
– Status Messages: adding a textbox where status messages will be display. | |||
==GUI v2.3== | ==GUI v2.3== | ||
Line 165: | Line 238: | ||
- runauto.py: runs GUIrandom.py at the desired time interval (initially 0.02s, to have a refresh rate of 50Hz) | - runauto.py: runs GUIrandom.py at the desired time interval (initially 0.02s, to have a refresh rate of 50Hz) | ||
==GUI version 2.04== | |||
NUC PC + | |||
==Files for GUI visualisation== | ==Files for GUI visualisation== |
Latest revision as of 13:30, 6 December 2024
To do list for GUI
- v3.3:
- Upload versions to github
- Update wiki
- Check errors
- Check differences between live calibration and post calibration
- v3.1:
-MaxY = 1.5*Photodiode ✓
- Status message of running situation for users ✓
- Start/Stop button to finish when clicked, not after tinterval ✓
- Kill shell script from php ✓
- Error Bars: check how values are obtained in FTDI
- Cache issue, situation has improved but there are some crashes.✓
- Reverse option: it does not work, always shows same direction.✓
- Fitting of final measurement.✓
GUI v3.3
This version of the GUI has three separate webpages: one for data acquisition (DAQ), one for calibrating data at a desired frequency (Calibrated) and one for the display of previosuly fitted data (Replay). This version was last modified by Sonia on the 26th of November, 2024.
DAQ
This section handles the data acquisition of the QuARC. The arguments needed for the different codes to run correctly can be directly input by the user in the different textboxes and dropdown menus. Single start/stop button that handles the raw acquisition, the live calibration and the postprocessing of the data (fitting it at 25 Hz).
To run the GUI we need DAQ.js and DAQ.html. The graph in this webpage displays output_GUI.txt.
File structure: there is an entry textbox, that when clicked assigns the name Run0xy. Three files are produced: YYmmdd_Run0xy_raw.txt, YYmmdd_Run0xy_calibrated.txt and YYmmdd_Run0xy_fitted.txt The actual code work as it follows:
The start/stop button calls executeDAQ.php, that then sends the input valus to the shell script executeFTDI.sh. The shell script acquires data live, calibrates it and then fits the data in three separate steps.
1. Data Acquisition: FTDI_GUI.cpp, the code responsible for communicating the FPGA over FTDI that creates the raw file and the date folder. This code also creates the subfolders Raw, Calibrated and Fitted. Three important files, that the GUI will need, are created with this code: first one is GUI/average.csv, that simply writes live raw data in decimal format that will be used for calibration. The second file is runningStatus.txt, this shows the message created by FTDI code: whether the detector is or not connected, the number of measurements that are acquired and/or any other error messages. IF the file includes the word stopping, acquisition has finished and the start/stop button will be clicked automatically.
sudo ./FTDI_GUI usb104 1 "$selected_value2" "$selected_value3" "$selected_value4" 50 "$selected_value1.txt" revB 2 &
2. Calibration: calibrate_fit_GUI.cpp and ./calibrate_singlefit.cpp. The first code, calibrate_fit_GUI.cpp, reads from GUI/average.csv and subtracts background and applies ST calibration. It generates a live file, output_GUI.txt, that is updated with the calibrated data live for GUI visualisation. IT also generates a file with all the calibrated data, but due to the acquisition speed some lines are skipped, that's why we need the second code.
calibrate_singlefit.cpp: reads the raw data file, calibrates it and creates a new file with appropiate header information. At the end of the file, the average of all the measurements as well as a fit applied to this average will be generated.
sudo ./calibrate_fit_GUI "$selected_value1.txt" 1 "$selected_value2" "$selected_value4" revB "$selected_value5" "$selected_value6" "$selected_value3" calibration background.txt shootBack.txt shootFront.txt 2>&1
sudo ./calibrate_singlefit "$date" "$selected_value1.txt" revB "$selected_value3" "$selected_value5" background.txt shootBack.txt shootFront.txt
3. Fitting: once the calibrated file has been generated, with header info, one line per measurement and the averaged value we can proceed to do more fittings. This code averages the data at 25Hz and performs an individual fit for every set of data averaged at 25Hz. The output file generated is Calibrated/YYmmdd_Run0xy_fitted.txt.
sudo ./fit_average "$selected_value5" 100 UCLH "$date" "$selected_value1.txt" "$selected_value6" & #Value 100 is energy, currently not in use.
button_message.php sends the word running or stopping to buttonStatus.txt, based on the number of clicks the start/stop button has received.
CALIBRATED
Performs calibration at a desired frequency, selected from a dropdown menu. It calls calibrateGUI.php, that then calls executeGUI.sh. The shell script calls the cpp code calibrate_rate, that reads the raw data file, calibrates the data and the averages it at the desired frequency. The graph shows the file output_GUI_Calibrated.txt, that is updated in real time at the desired frequency.
sudo ./calibrate_rate true "$dataDir" "$shortFileName" revB "$frequency"
REPLAY
Replay code is a visualisation tool only. It reads the fitted data, selected from a dropdown menu, and plots every measurement with its fits and values.
GUI v3.1 and 3.2
These two versions had some issues because of the FTDI code, so they are skipped.
GUI v3.01b
Used for UCLH experiment 2024
FTDI code: combination of Sonia's + Matt’s -> FTDI_GUI.cpp
Calibrate code: calibrate_fit.cpp
Fit code: sudo ./fit_average false 100 UCLH UCLH/20240418 Run022.txt 25
- DAQ.js + DAQ.html: show data live - Replay.js + Replay.html: show data averaged at desired frequency.
GUI v3.01
This version has been developed on raspberry pi5. The goal of this version is to fix the pending issues of v2.3, specially the behaviour of the Start/Stop button as this has to know when the DAQ is running and how to kill it.
As this version is the most stable one with php and sh scripts, below is a detailed explanation of how it works.
DAQ.js calls executeDAQ.php calls executeFTDI.sh and FTDI2
Need to change the autoclick button: instead of clicking after a certain time it has passed, we now print measurement number + word running to a new file with each measurement, and with last one we print the stopping. If the word stopping is found in the file, the stop button will be automatically clicked. When detector not connected: show an error message to the user (very basic styling for now) + click button to stop acquisition.
Now Measure/Stop button is capable of:
- Starting acquisition
- Stopping when acquisition has finished
- Stop graph when acquiring data
It needs to:
4. Read if detector is not connected and show an error message.
5. Kill the execution of shell script when stop is clicked.
Instead of killing process just execute it based on a word read from a text file. The js calls the button_message.php, that writes the message to a file called buttonStatus.txt
File will either be stopping or running, based on what DAQ is doing.
when live data is being acquired, the change in average.csv is so quick that calibration can’t cope with the speed and skips some measurements
User input values:
$selected_value1 = RunName = Run0xy
$selected_value2 = FSR = 12.5, 350…
$selected_value3 = tINT
$selected_value4 = num_measurements
$selected_value5 = reverse
$selected_value6 = frequency
- Automated File name: we want to start automatically with Run001, and increase it with every run. The increase will happen when the filename box is clicked, but still allow for name modifications if desired.
– Status Messages: adding a textbox where status messages will be display.
GUI v2.3
This version has been developed on raspberry pi5. The code has been split in two main functions: one that creates the graph and one that updates it, to keep up to speed with the acquisition. A summary of the changes can be found on the slides created on the 20th March 2024 (SER_240320_GUI-v2.3.pptx): https://www.hep.ucl.ac.uk/pbt/wikiData/presentations/2024/
Main changes:
- Single start/stop button for DAQ.
- t_INT has a minimum value of 170us. If user inputs a value smaller than this, an error message is displayed and tINT automatically modified to 170us.
- Run time entry box added. This correlates to the number of measurements considering the t_INT decided by the user.
- Auto-adjustment of the y-axis and the x-axis based on the data that is being parsed.
Pending:
- Status message of running situation for users
- Start/Stop button to finish when clicked, not after tinterval
- Kill shell script from php
- Error Bars: check how values are obtained in FTDI
- Cache issue, situation has improved but there are some crashes.
- Reverse option: it does not work, always shows same direction.
- Fitting of final measurement.
(This version has accidentally overwritten v2.2 and therefore is saved on pi5 as GUI v2.2)
GUI v2.2
This version keeps the data display from previous runs that was implemented in version 2.1, and adds elements to perform the data acquisition directly from the GUI. Initial test was to design a simple execute DAQ button that reads the dropdown menus and text boxes with the values defined by the user and uses a shell script to write them to a file called boardvalues.txt.
This version of the GUI can be found on: https://www.hep.ucl.ac.uk/pbt/PDdisplay/escribano/v2.2/
GUI v2.2 on pi5 The newly acquired raspberry pi5 presents a much better reading time than previous version pi4. The GUI is going to be developed directly in this device, as it can be attached to the detector with the intention of acquiring and displaying data live. To be able to execute the FTDI code from a shell script we need to add a passwordless rule in sudoers for the script (/etc/sudoers.d/FTDI_rule) and this allows execution.
We want to acquire data and calibrate it when the button is clicked: new code, calibrateSonia.cpp does the calibration and generates the files that are read by the GUI.
- The arguments required for .FTDI that do not change are hardcoded into the shell script. - The arguments that vary (number of measurements) are read from the textboxes/dropdown menus.
Acquisition from local host using a remote laptop has been successful. This version of the GUI has many changes in comparison to cluster v2.2, so a new version number (2.3) is given and will be described in more detail in a separate section.
GUI version 2.1.b
This version has fixed all of the issues we had in previous versions. Design is the same but the code has been rewritten completely. The key improvements are:
- Zooming feature: Shifting between PDdata and curves when zooming in: two different axis were used for PDdata and fitted data. This has been modified to have only one xScale, defined as a linear scale. This means that the x-axis now utilises numerical datasets instead of categorical, and therefore the zooming of both sets of data is performed equally at the same time.
var xScale = d3.scaleLinear()
.domain([0, setWET])
.range([margins.left, width - margins.right ]);
- Bandwidth separation: Previous version assumed that the separation between PDdata was uniform, but this did not correspond to reality as the PD thicknesses varies. The bandwidth needs to be redefined based on the separation between each PD and the previous one.
bandwidths.push(xPDposition[i+1] - xPDposition[i]);
This version has been developed for Clatterbridge data (12PD) - If using for larger data sets we need to modify the numer of setPhotodiodes and setWET in GUI.js
GUI version 2.06
Located on: https://www.hep.ucl.ac.uk/pbt/PDdisplay/escribano/v2.06/
Improved version based on v 2.05. The start and stop buttons have been changed by a single button that performs both actions, keeping in screen the results from the last data plotted instead of deleting the graph and beam parameters.
Live update + fitting curves.
GUI version 2.05
This version of the GUI can be seen on: https://www.hep.ucl.ac.uk/pbt/PDdisplay/escribano/v2.05/
General information
Developed in JavaScript with d3 and papaparse libraries. This version consists of a single tab, where the user can adjust WET number (mm) and max Y (pC) and select which elements are plotted on the graph, via checkboxes.
Data used for testing GUI: 245 MeV, acquired at The Christie in October 2022
Disclaimer!: The error bars from this version do not correspond to the real error value, as the magnitude has been increased by 5pC for visualisation purposes (defined in the code as extraerror).
Live update
This version provides a live visualisation of the data file. In order to generate a dynamic set of data this two scripts have been developed in Python: GUIrandom.py and runauto.py.
- GUIrandom.py: calculates a random number and multiplies the PD data and the curves by this number. The random number is shown in the terminal.
- runauto.py: runs GUIrandom.py at the desired time interval (initially 0.02s, to have a refresh rate of 50Hz)
GUI version 2.04
NUC PC +
Files for GUI visualisation
The experimental data acquired needs to be calibrated with the acquired shoot-through measurements (back and front) and the background needs to be subtracted. Then, each of the measurements can be fitted to the models, extracting the range and the energy of the beam. There are two different codes to perform this.
Calibrated data: Development of a python code (replay.py) that generates a file with header info followed by the 30k measurements calibrated and with background subtracted. If our initial file is called Run0xy.txt the output of this will be Run0xy_calibrated.txt
python3 replay.py t_INT framerate skipahead reverse folder run background backST frontST
Fitted data: Once the data has been calibrated, we need to perform the fittings and extract the parameters. This code (fit.cpp) utilises Run_0xy.txt and outputs Run0xy_fitted_frequency.txt, where the frequency value is 25Hz by default but can be changed by adding an extra argument to the code line. This takes about 15 second per run for Clatterbridge data.
g++ -o fit fit.cpp `root-config --cflags --glibs` -O3
./fit reverse energy facility folder run (frequency)
Both, fitted and calibrated data for all the runs acquired at Clatterbridge experiment in 2023 are in https://www.hep.ucl.ac.uk/pbt/wikiData/data/GUI-Clatterbridge/
Live Update:
The webpage is reading from file outputGUI.csv, located in the same directory than the GUI js and html files. To visualise it live, we create a shell script that goes through each measurement at a certain time interval, writing the output to the outputGUI.csv file. To execute this, simply we cd into ReplayFinal and then execute the script.
./shellGUI.sh
Uploading Data to HEP Server
Data can be uploaded to the HEP cluster in order to run a webpage with live photodiode data.
- On your local machine:
- Move to the directory containing photodiode data being saved by CoolTerm and the C++ script to generate the CSV file:
cd /Path/To/Data
- Generate the photodiode data with:
root -l "writeCSV.cpp"
- In a new terminal, move to the same directory and run the following command in order to copy this data, line by line, to the plus1 web area:
tail -F -n 1 output.csv | ssh username@plus2.hep.ucl.ac.uk -T 'cat - > /unix/www/html/pbt/PDdisplay/photodiodeValuesAll.csv'
- Move to the directory containing photodiode data being saved by CoolTerm and the C++ script to generate the CSV file:
- On plus2 :
- In a new terminal, move into the directory where the photodiode data is written:
cd /unix/www/html/pbt/PDdisplay/
- Run the following script in that directory:
./outputSingleLine.sh -v photodiodeValuesAll.csv photodiodeValues.csv 0.02
- This will output a single line CSV file - photodiodeValues.csv - every 10ms (100Hz). It's a good idea to set the write rate about 2x faster than the desired frame rate.
- To output this any more or less often, adjust the "waitTime" value at the end (needs to be in seconds).
- To stop displaying each line as it is written, remove the
-v
flag. - Note that this script contains an infinite loop, so to stop it running you need to kill it by hand with Ctrl-C. You may need to do this a few times to get it to quit...
- In a new terminal, move into the directory where the photodiode data is written: