385 lines
15 KiB
C++
385 lines
15 KiB
C++
/****************************************************************************
|
|
|
|
PGetAsymmetryRunBlockDialog.cpp
|
|
|
|
Author: Andreas Suter
|
|
e-mail: andreas.suter@psi.ch
|
|
|
|
*****************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Copyright (C) 2009-2025 by Andreas Suter *
|
|
* andreas.suter@psi.ch *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
|
|
/**
|
|
* @file PGetAsymmetryRunBlockDialog.cpp
|
|
* @brief Implementation of the PGetAsymmetryRunBlockDialog class.
|
|
* @details This file implements the dialog for creating asymmetry-type RUN blocks
|
|
* in msr files. It handles user input validation and generates properly formatted
|
|
* msr-file text for all asymmetry RUN block parameters.
|
|
*
|
|
* @author Andreas Suter
|
|
* @date 2009-2025
|
|
* @copyright Copyright (C) 2009-2025 by Andreas Suter
|
|
* @license GNU General Public License v2 or later
|
|
*/
|
|
|
|
#include <QLineEdit>
|
|
#include <QValidator>
|
|
#include <QComboBox>
|
|
#include <QMessageBox>
|
|
#include <QDesktopServices>
|
|
#include <QUrl>
|
|
|
|
#include "PGetAsymmetryRunBlockDialog.h"
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Constructs the asymmetry RUN block dialog.
|
|
*
|
|
* @details Initializes the dialog UI and sets up input validators for all
|
|
* numeric fields. The dialog is created as modal.
|
|
*
|
|
* @par Input Validators:
|
|
* - Integer validators: histogram numbers, data ranges, background ranges, t0 values, packing, alpha, beta
|
|
* - Double validators: fixed background values, fit range
|
|
*
|
|
* @param helpUrl URL to the online documentation for asymmetry RUN blocks.
|
|
*/
|
|
PGetAsymmetryRunBlockDialog::PGetAsymmetryRunBlockDialog(const QString helpUrl) : fHelpUrl(helpUrl)
|
|
{
|
|
setupUi(this);
|
|
|
|
setModal(true);
|
|
|
|
fForwardHistoNo_lineEdit->setValidator( new QIntValidator(fForwardHistoNo_lineEdit) );
|
|
fBackwardHistoNo_lineEdit->setValidator( new QIntValidator(fBackwardHistoNo_lineEdit) );
|
|
fDataForwardStart_lineEdit->setValidator( new QIntValidator(fDataForwardStart_lineEdit) );
|
|
fDataForwardEnd_lineEdit->setValidator( new QIntValidator(fDataForwardEnd_lineEdit) );
|
|
fDataBackwardStart_lineEdit->setValidator( new QIntValidator(fDataBackwardStart_lineEdit) );
|
|
fDataBackwardEnd_lineEdit->setValidator( new QIntValidator(fDataBackwardEnd_lineEdit) );
|
|
fBackgroundForwardStart_lineEdit->setValidator( new QIntValidator(fBackgroundForwardStart_lineEdit) );
|
|
fBackgroundForwardEnd_lineEdit->setValidator( new QIntValidator(fBackgroundForwardEnd_lineEdit) );
|
|
fBackgroundBackwardStart_lineEdit->setValidator( new QIntValidator(fBackgroundBackwardStart_lineEdit) );
|
|
fBackgroundBackwardEnd_lineEdit->setValidator( new QIntValidator(fBackgroundBackwardEnd_lineEdit) );
|
|
fBackgroundForwardFix_lineEdit->setValidator( new QDoubleValidator(fBackgroundForwardFix_lineEdit) );
|
|
fBackgroundBackwardFix_lineEdit->setValidator( new QDoubleValidator(fBackgroundBackwardFix_lineEdit) );
|
|
fFitRangeStart_lineEdit->setValidator( new QDoubleValidator(fFitRangeStart_lineEdit) );
|
|
fFitRangeEnd_lineEdit->setValidator( new QDoubleValidator(fFitRangeEnd_lineEdit) );
|
|
fPacking_lineEdit->setValidator( new QIntValidator(fPacking_lineEdit) );
|
|
fAlpha_lineEdit->setValidator( new QIntValidator(fAlpha_lineEdit) );
|
|
fBeta_lineEdit->setValidator( new QIntValidator(fBeta_lineEdit) );
|
|
fT0Forward_lineEdit->setValidator( new QIntValidator(fT0Forward_lineEdit) );
|
|
fT0Backward_lineEdit->setValidator( new QIntValidator(fT0Backward_lineEdit) );
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the RUN header line for the asymmetry block.
|
|
*
|
|
* @details Creates the first line of the RUN block containing the run file name,
|
|
* beamline identifier, institute name, and data file format. The beamline is
|
|
* converted to uppercase.
|
|
*
|
|
* @return Formatted RUN header string, e.g.:
|
|
* "RUN data001 GPS PSI ROOT (name beamline institute data-file-format)\n"
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getRunHeaderInfo()
|
|
{
|
|
QString str;
|
|
|
|
str = "RUN " + fRunFileName_lineEdit->text() + " ";
|
|
str += fBeamline_lineEdit->text().toUpper() + " ";
|
|
str += fInstitute_comboBox->currentText() + " ";
|
|
str += fFileFormat_comboBox->currentText() + " (name beamline institute data-file-format)\n";
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the alpha parameter line for the asymmetry block.
|
|
*
|
|
* @details Alpha is the detector efficiency ratio correction parameter used in
|
|
* asymmetry calculations: A = (N_F - alpha * N_B) / (N_F + alpha * N_B).
|
|
* The parameter typically references a fit parameter number.
|
|
*
|
|
* @param[out] present Set to true if an alpha value was entered, false if empty
|
|
* (default alpha=1 will be used).
|
|
*
|
|
* @return Formatted alpha parameter string, e.g.: "alpha 1\n"
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getAlphaParameter(bool &present)
|
|
{
|
|
QString str = "alpha " + fAlpha_lineEdit->text() + "\n";
|
|
|
|
if (str.isEmpty())
|
|
present = false;
|
|
else
|
|
present = true;
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the beta parameter line for the asymmetry block.
|
|
*
|
|
* @details Beta is the detector phase correction parameter, typically used for
|
|
* correcting phase differences between forward and backward detectors.
|
|
* The parameter typically references a fit parameter number.
|
|
*
|
|
* @param[out] present Set to true if a beta value was entered, false if empty
|
|
* (default beta=1 will be used).
|
|
*
|
|
* @return Formatted beta parameter string, e.g.: "beta 1\n"
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getBetaParameter(bool &present)
|
|
{
|
|
QString str = "beta " + fBeta_lineEdit->text() + "\n";
|
|
|
|
if (str.isEmpty())
|
|
present = false;
|
|
else
|
|
present = true;
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the parameter map line for the asymmetry block.
|
|
*
|
|
* @details The map line defines the mapping between theory function parameters
|
|
* and the fit parameters defined in the FITPARAMETER block. It should contain
|
|
* only space-separated integers.
|
|
*
|
|
* @param[out] valid Set to true if the map contains only digits and spaces,
|
|
* false if invalid characters are found.
|
|
*
|
|
* @return Formatted map string, e.g.: "map 1 2 3 4\n"
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getMap(bool &valid)
|
|
{
|
|
QString str = fMap_lineEdit->text().trimmed().remove(" ");
|
|
|
|
// check if potentially proper map line
|
|
for (int i=0; i<str.length(); i++) {
|
|
if (!str[i].isDigit()) {
|
|
valid = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
str = "map " + fMap_lineEdit->text() + "\n";
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the background specification for the asymmetry block.
|
|
*
|
|
* @details Creates either a "background" line (bin ranges for background estimation)
|
|
* or a "backgr.fix" line (fixed background values). Only one type should be specified.
|
|
*
|
|
* @par Background Types:
|
|
* - background: Four integers specifying bin ranges [forward_start, forward_end, backward_start, backward_end]
|
|
* - backgr.fix: Two doubles specifying fixed background counts for forward and backward detectors
|
|
*
|
|
* @param[out] valid Set to true if valid background info is provided, false if
|
|
* no background info given (a default "background 0 10 0 10" is returned).
|
|
*
|
|
* @return Formatted background string, e.g.: "background 50 150 50 150\n"
|
|
* or "backgr.fix 15.3 14.8\n"
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getBackground(bool &valid)
|
|
{
|
|
QString str = "";
|
|
|
|
valid = true;
|
|
|
|
// check that either backgr.fix or background is given, but not both
|
|
if (fBackgroundForwardStart_lineEdit->text().isEmpty() && fBackgroundForwardEnd_lineEdit->text().isEmpty() &&
|
|
fBackgroundBackwardStart_lineEdit->text().isEmpty() && fBackgroundBackwardEnd_lineEdit->text().isEmpty() &&
|
|
fBackgroundForwardFix_lineEdit->text().isEmpty() && fBackgroundBackwardFix_lineEdit->text().isEmpty()) {
|
|
valid = false;
|
|
str = "background 0 10 0 10\n";
|
|
} else {
|
|
if (!fBackgroundForwardStart_lineEdit->text().isEmpty()) { // assume the rest is given, not fool prove but ...
|
|
str = "background ";
|
|
str += fBackgroundForwardStart_lineEdit->text() + " ";
|
|
str += fBackgroundForwardEnd_lineEdit->text() + " ";
|
|
str += fBackgroundBackwardStart_lineEdit->text() + " ";
|
|
str += fBackgroundBackwardEnd_lineEdit->text() + "\n";
|
|
}
|
|
if (!fBackgroundForwardFix_lineEdit->text().isEmpty()) { // assume the rest is given, not fool prove but ...
|
|
str = "backgr.fix ";
|
|
str += fBackgroundForwardFix_lineEdit->text() + " ";
|
|
str += fBackgroundBackwardFix_lineEdit->text() + "\n";
|
|
}
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the data range specification for the asymmetry block.
|
|
*
|
|
* @details Creates the "data" line specifying the histogram bin ranges to be
|
|
* used for fitting. Four values are required: start and end bins for both
|
|
* forward and backward histograms.
|
|
*
|
|
* @param[out] valid Set to true if all four data range values are provided,
|
|
* false if any are missing.
|
|
*
|
|
* @return Formatted data range string, e.g.: "data 100 8000 100 8000\n"
|
|
* Returns empty string if values are missing.
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getData(bool &valid)
|
|
{
|
|
QString str = "";
|
|
|
|
if (fDataForwardStart_lineEdit->text().isEmpty() || fDataForwardEnd_lineEdit->text().isEmpty() ||
|
|
fDataBackwardStart_lineEdit->text().isEmpty() || fDataBackwardEnd_lineEdit->text().isEmpty()) {
|
|
valid = false;
|
|
} else {
|
|
str = "data ";
|
|
str += fDataForwardStart_lineEdit->text() + " ";
|
|
str += fDataForwardEnd_lineEdit->text() + " ";
|
|
str += fDataBackwardStart_lineEdit->text() + " ";
|
|
str += fDataBackwardEnd_lineEdit->text() + "\n";
|
|
valid = true;
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the T0 (time zero) specification for the asymmetry block.
|
|
*
|
|
* @details Creates the "t0" line specifying the time zero bin for both forward
|
|
* and backward histograms. T0 is the bin corresponding to muon implantation time.
|
|
*
|
|
* @param[out] present Set to true if both t0 values are provided, false otherwise.
|
|
*
|
|
* @return Formatted t0 string, e.g.: "t0 250 250\n"
|
|
* Returns empty string if values are missing.
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getT0(bool &present)
|
|
{
|
|
QString str = "";
|
|
|
|
if (!fT0Forward_lineEdit->text().isEmpty() && !fT0Forward_lineEdit->text().isEmpty()) {
|
|
str = "t0 ";
|
|
str += fT0Forward_lineEdit->text() + " ";
|
|
str += fT0Backward_lineEdit->text() + "\n";
|
|
present = true;
|
|
} else {
|
|
present = false;
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the fit range specification for the asymmetry block.
|
|
*
|
|
* @details Creates the "fit" line specifying the time range (in microseconds)
|
|
* over which the fit will be performed.
|
|
*
|
|
* @param[out] valid Set to true if both fit range values are provided, false if
|
|
* missing (a default range [0.0, 10.0] is returned).
|
|
*
|
|
* @return Formatted fit range string, e.g.: "fit 0.5 9.5\n"
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getFitRange(bool &valid)
|
|
{
|
|
QString str = "";
|
|
|
|
if (fFitRangeStart_lineEdit->text().isEmpty() || fFitRangeEnd_lineEdit->text().isEmpty()) {
|
|
str += "fit 0.0 10.0\n";
|
|
valid = false;
|
|
} else {
|
|
str += "fit ";
|
|
str += fFitRangeStart_lineEdit->text() + " ";
|
|
str += fFitRangeEnd_lineEdit->text() + "\n";
|
|
valid = true;
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Generates the packing (rebinning) specification for the asymmetry block.
|
|
*
|
|
* @details Creates the "packing" line specifying how many histogram bins should
|
|
* be combined into one. A packing of 1 means no rebinning, 2 means combine
|
|
* pairs of bins, etc.
|
|
*
|
|
* @param[out] present Set to true if a packing value was provided, false if
|
|
* missing (a default packing of 1 is returned).
|
|
*
|
|
* @return Formatted packing string, e.g.: "packing 10\n"
|
|
*/
|
|
QString PGetAsymmetryRunBlockDialog::getPacking(bool &present)
|
|
{
|
|
QString str = "";
|
|
|
|
if (fPacking_lineEdit->text().isEmpty()) {
|
|
present = false;
|
|
str += "packing 1\n";
|
|
} else {
|
|
present = true;
|
|
str += "packing " + fPacking_lineEdit->text() + "\n\n";
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
/**
|
|
* @brief Opens the online help documentation for asymmetry RUN blocks.
|
|
*
|
|
* @details Attempts to open the help URL in the system's default web browser
|
|
* using QDesktopServices. If the URL is empty, displays an informational message.
|
|
* If the browser fails to open, displays an error message with a clickable link.
|
|
*/
|
|
void PGetAsymmetryRunBlockDialog::helpContent()
|
|
{
|
|
if (fHelpUrl.isEmpty()) {
|
|
QMessageBox::information(this, "INFO", "Will eventually show a help window");
|
|
} else {
|
|
bool ok = QDesktopServices::openUrl(QUrl(fHelpUrl, QUrl::TolerantMode));
|
|
if (!ok) {
|
|
QString msg = QString("<p>Sorry: Couldn't open default web-browser for the help.<br>Please try: <a href=\"%1\">musrfit docu</a> in your web-browser.").arg(fHelpUrl);
|
|
QMessageBox::critical( nullptr, tr("FATAL ERROR"), msg, QMessageBox::Close );
|
|
}
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// END
|
|
//----------------------------------------------------------------------------------------------------
|