work on the scripting part of mupp. Preparing for the step of parameter transformation.

This commit is contained in:
suter_a 2020-04-23 16:35:55 +02:00
parent fe537efa6e
commit dbefdc69a4
8 changed files with 220 additions and 69 deletions

View File

@ -256,7 +256,7 @@ PmuppGui::PmuppGui( QStringList fln, QWidget *parent, Qt::WindowFlags f )
// setup widgets
fBoxLayout_Main = new QBoxLayout(QBoxLayout::TopToBottom);
fBoxLayout_Main->setGeometry(QRect(10, 40, 600, 400));
fBoxLayout_Main->setGeometry(QRect(10, 40, 600, 500));
fBoxLayout_Top = new QBoxLayout(QBoxLayout::LeftToRight);
fGridLayout_Left = new QGridLayout();
@ -329,23 +329,39 @@ PmuppGui::PmuppGui( QStringList fln, QWidget *parent, Qt::WindowFlags f )
fBoxLayout_Top->addLayout(fGridLayout_Left);
fBoxLayout_Top->addLayout(fGridLayout_Right);
fCmdLineHistory = new QPlainTextEdit(this);
fCmdLineHistory->setReadOnly(true);
fCmdLineHistory->setMaximumBlockCount(50);
// fill cmd history
for (int i=0; i<fCmdHistory.size(); i++)
fCmdLineHistory->insertPlainText(QString("%1\n").arg(fCmdHistory[i]));
fCmdLine = new QLineEdit(this);
fCmdLine->installEventFilter(this);
fCmdLine->setText("$ ");
fCmdLine->setFocus(); // sets the keyboard focus
fExitButton = new QPushButton("E&xit", this);
QVBoxLayout *cmdLayout = new QVBoxLayout;
QLabel *cmdLabel = new QLabel("History:");
cmdLayout->addWidget(cmdLabel);
cmdLayout->addWidget(fCmdLineHistory);
cmdLayout->addWidget(fCmdLine);
fBoxLayout_Cmd = new QBoxLayout(QBoxLayout::LeftToRight);
fBoxLayout_Cmd->addWidget(fCmdLine);
fBoxLayout_Cmd->addLayout(cmdLayout);
fBoxLayout_Cmd->addWidget(fExitButton);
fBoxLayout_Cmd->setAlignment(fCmdLine, Qt::AlignBottom);
fBoxLayout_Cmd->setAlignment(fExitButton, Qt::AlignBottom);
QFrame* hline = new QFrame();
hline->setFrameShape(QFrame::HLine);
hline->setFrameShadow(QFrame::Sunken);
fCmdSplitter = new QSplitter(Qt::Vertical, this);
QWidget *topWidget = new QWidget(this); // only needed since splitter needs a QWidget
topWidget->setLayout(fBoxLayout_Top);
QWidget *cmdWidget = new QWidget(this); // only needed since splitter needs a QWidget
cmdWidget->setLayout(fBoxLayout_Cmd);
fCmdSplitter->addWidget(topWidget);
fCmdSplitter->addWidget(cmdWidget);
fBoxLayout_Main->addLayout(fBoxLayout_Top);
fBoxLayout_Main->addWidget(hline);
fBoxLayout_Main->addLayout(fBoxLayout_Cmd);
fBoxLayout_Main->addWidget(fCmdSplitter);
// establish all the necessary signal/slots
connect(fRefreshCollection, SIGNAL( pressed() ), this, SLOT( refresh() ));
@ -718,16 +734,19 @@ void PmuppGui::normVal()
void PmuppGui::helpCmds()
{
QMessageBox::information(this, "cmd help", "<b>help:</b> this help.<br>"\
"<b>exit/quit:</b> close mupp.<br>"\
"<b>load:</b> calls the open file dialog.<br>"\
"<b>ditto</b>: addX/Y for the new selection as for the previous ones.<br>"\
"<b>dump collections:</b> dumps all currently loaded collections.<br>"\
"<b>dump XY:</b> dumps X/Y tree.<br>"\
"<b>refresh:</b> refresh the currently selected collection.<br>"\
"<b>plot:</b> plot the X/Y data.<br>"\
"<b>exit/quit:</b> close mupp.<br>"\
"<b>load:</b> calls the open file dialog.<br>"\
"<b>norm &lt;flag&gt;:</b> normalize plots to maximum if &lt;flag&gt; is true<br>"\
"<b>macro &lt;fln&gt;:</b> saves the X/Y data as a ROOT macro (*.C).<br>"\
"<b>path &lt;macroPath&gt;:</b> sets the path to the place where the macros will be saved.<br>"\
"<b>select collection &lt;nn&gt;:</b> select collection in GUI.<br>"\
"<b>plot:</b> plot the X/Y data.<br>"\
"<b>refresh:</b> refresh the currently selected collection.<br>"\
"<b>select &lt;nn&gt;:</b> select collection in GUI.<br>"\
"&nbsp;&nbsp;&nbsp;&nbsp;&lt;nn&gt; is either the collection name or the row number.<br>"\
"<b>x &lt;param_name&gt; / y &lt;param_name&gt;:</b> add the parameter to the select axis.<br>"\
"<b>flush:</b> flush the history buffer.");
}
@ -787,6 +806,7 @@ bool PmuppGui::eventFilter(QObject *o, QEvent *e)
if (fCmdHistory.size() >= 50)
fCmdHistory.removeFirst();
fCmdHistory.push_back(cmd);
fCmdLineHistory->insertPlainText(QString("%1\n").arg(cmd));
}
}
return false;
@ -866,9 +886,6 @@ void PmuppGui::readCmdHistory()
//----------------------------------------------------------------------------------------------------
void PmuppGui::writeCmdHistory()
{
if (fCmdHistory.size() == 0)
return;
QProcessEnvironment procEnv = QProcessEnvironment::systemEnvironment();
QString home = procEnv.value("HOME", "");
if (home.isEmpty())
@ -877,7 +894,7 @@ void PmuppGui::writeCmdHistory()
QString pathName = home + "/.musrfit/mupp/";
QDir dir(pathName);
if (!dir.exists()) {
// directory $HOME/.musrfit/musredit does not exist hence create it
// directory $HOME/.musrfit/mupp does not exist hence create it
dir.mkpath(pathName);
}
pathName += "mupp_history.txt";
@ -1014,13 +1031,23 @@ void PmuppGui::remove()
/**
* @brief PmuppGui::addX
*/
void PmuppGui::addX()
void PmuppGui::addX(QString param)
{
QString paramName("");
if (!param.isEmpty()) {
// check that param exists
if (fParamList->findItems(param, Qt::MatchFixedString).empty()) {
QMessageBox::critical(this, "**ERROR**", QString("Parameter X '%1' not found").arg(param));
return;
}
paramName = param;
} else {
// get the parameter name from the parameter list widget
QListWidgetItem *item = fParamList->currentItem();
if (item == 0)
return;
QString paramName = item->text();
paramName = item->text();
}
int idx = fColList->currentRow();
QString xLabel = QString("%1 (-%2-)").arg(paramName).arg(idx);
@ -1046,13 +1073,23 @@ void PmuppGui::addX()
/**
* @brief PmuppGui::addY
*/
void PmuppGui::addY()
void PmuppGui::addY(QString param)
{
QString paramName("");
if (!param.isEmpty()) {
// check that param exists
if (fParamList->findItems(param, Qt::MatchFixedString).empty()) {
QMessageBox::critical(this, "**ERROR**", QString("Parameter Y '%1' not found").arg(param));
return;
}
paramName = param;
} else {
// get the parameter name from the parameter list widget
QListWidgetItem *item = fParamList->currentItem();
if (item == 0)
return;
QString paramName = item->text();
paramName = item->text();
}
int idx = fColList->currentRow();
QString yLabel = QString("%1 (-%2-)").arg(paramName).arg(idx);
@ -1900,13 +1937,39 @@ void PmuppGui::handleCmds()
}
fMacroPath.replace(envVar.prepend("$"), fullPath);
}
} else if (cmd.startsWith("select collection") || cmd.startsWith("sc")) {
} else if (cmd.startsWith("select") || cmd.startsWith("sc")) {
selectCollection(cmd);
} else if (cmd.startsWith("x")) {
QStringList tok = cmd.split(" ", QString::SkipEmptyParts);
addX(tok[1]);
} else if (cmd.startsWith("y")) {
QStringList tok = cmd.split(" ", QString::SkipEmptyParts);
addY(tok[1]);
} else if (cmd.startsWith("ditto")) {
addDitto();
} else if (cmd.startsWith("norm")) {
QStringList tok = cmd.split(" ", QString::SkipEmptyParts);
if (tok.size() != 2) {
QMessageBox::critical(this, "**ERROR**", "found wrong norm cmd, will ignore it.");
return;
}
if (!tok[1].trimmed().compare("true", Qt::CaseInsensitive)) {
fNormalizeAction->setChecked(true);
} else if (!tok[1].trimmed().compare("false", Qt::CaseInsensitive)) {
fNormalizeAction->setChecked(false);
} else {
QMessageBox::critical(this, "**ERROR**", "found wrong norm cmd, will ignore it.");
return;
}
} else if (cmd.startsWith("flush")) {
fCmdHistory.clear();
fCmdLine->setText("$ ");
fCmdLineHistory->clear();
fCmdLineHistory->insertPlainText("$");
} else if (cmd.startsWith("help")) {
helpCmds();
} else {
helpCmds();
}
}
@ -2148,8 +2211,8 @@ void PmuppGui::selectCollection(QString cmd)
bool ok;
int ival, pos=-1;
QString str = cmd;
if (cmd.contains("select collection")) {
str.remove("select collection");
if (cmd.contains("select")) {
str.remove("select");
str = str.trimmed();
} else if (cmd.contains("sc")) {
pos = cmd.indexOf("sc");
@ -2163,6 +2226,9 @@ void PmuppGui::selectCollection(QString cmd)
if (ok) { // it is a number
if (ival < fColList->count())
fColList->setCurrentRow(ival);
else
QMessageBox::critical(this, "**ERROR**",
QString("Found Row Selection %1 which is > #Selections=%2").arg(ival).arg(fColList->count()));
} else { // assume it is a collection name
for (int i=0; i<fColList->count(); i++) {
if (fColList->item(i)->text() == str) {

View File

@ -41,6 +41,7 @@
#include <QListWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QEvent>
#include <QProcess>
@ -170,6 +171,8 @@ private:
QPushButton *fRemoveX;
QPushButton *fRemoveY;
QPushButton *fPlot;
QSplitter *fCmdSplitter;
QPlainTextEdit *fCmdLineHistory;
QLineEdit *fCmdLine;
QPushButton *fExitButton;
@ -198,8 +201,8 @@ private:
private slots:
void refresh();
void remove();
void addX();
void addY();
void addX(QString param="");
void addY(QString param="");
void removeX();
void removeY();
void addDitto();

View File

@ -51,6 +51,7 @@ PmuppScript::PmuppScript(QStringList script) :
fLoadPath = QString("./");
fSavePath = QString("./");
fSelected = -2; // nothing selected
fNorm = false;
fAdmin = new PmuppAdmin();
}
@ -98,10 +99,12 @@ int PmuppScript::executeScript()
status = selectAll();
} else if (cmd.startsWith("select ")) {
status = select(cmd);
} else if (cmd.startsWith("addX")) {
} else if (cmd.startsWith("x")) {
status = addX(cmd);
} else if (cmd.startsWith("addY")) {
} else if (cmd.startsWith("y")) {
status = addY(cmd);
} else if (cmd.startsWith("norm")) {
fNorm = true;
} else if (cmd.startsWith("plot")) {
status = plot(cmd);
} else if (cmd.startsWith("macro")) {
@ -504,6 +507,7 @@ int PmuppScript::macro(const QString str, const QString plotFln)
QString collName;
int count=0;
double x_min=0.0, x_max=0.0, x_min_new=0.0, x_max_new=0.0, y_min=0.0, y_max=0.0, y_min_new=0.0, y_max_new=0.0;
double dval, y_min_norm=1.0e10;
for (int i=0; i<fPlotInfo.size(); i++) {
// get collection name
collName = fParamDataHandler->GetCollectionName(i);
@ -547,15 +551,27 @@ int PmuppScript::macro(const QString str, const QString plotFln)
}
fout << " // y-values" << endl;
for (int k=0; k<yy.size(); k++) {
fout << " yy[" << k << "]=" << yy[k] << ";" << endl;
dval = yy[k];
if (fNorm) {
dval /= y_max;
if (dval < y_min_norm)
y_min_norm = dval;
}
fout << " yy[" << k << "]=" << dval << ";" << endl;
}
fout << " // yyNegErr-values" << endl;
for (int k=0; k<yyNegErr.size(); k++) {
fout << " yyNegErr[" << k << "]=" << fabs(yyNegErr[k]) << ";" << endl;
dval = fabs(yyNegErr[k]);
if (fNorm)
dval /= fabs(y_max);
fout << " yyNegErr[" << k << "]=" << dval << ";" << endl;
}
fout << " // yyPosErr-values" << endl;
for (int k=0; k<yyPosErr.size(); k++) {
fout << " yyPosErr[" << k << "]=" << yyPosErr[k] << ";" << endl;
dval = fabs(yyPosErr[k]);
if (fNorm)
dval /= fabs(y_max);
fout << " yyPosErr[" << k << "]=" << dval << ";" << endl;
}
fout << endl;
fout << " TGraphAsymmErrors *g_" << i << "_" << j << " = new TGraphAsymmErrors(nn, xx, yy, null, null, yyNegErr, yyPosErr);" << endl;
@ -574,6 +590,11 @@ int PmuppScript::macro(const QString str, const QString plotFln)
diff = y_max_new - y_min_new;
y_min = y_min_new - 0.05 * diff;
y_max = y_max_new + 0.05 * diff;
if (fNorm) {
diff = 1.0 - y_min_norm;
y_min = y_min_norm - 0.05 * diff;
y_max = 1.0 + 0.05 * diff;
}
// plotting
fout << " //**********" << endl;
@ -686,22 +707,42 @@ QString PmuppScript::getNicerLabel(const QString label)
{
QString nice = label;
if (label == "dataE")
if (label == "dataE") {
nice = "E (keV)";
else if (label == "dataT")
} else if (label == "dataT") {
nice = "T (K)";
else if (label == "dataB")
} else if (label == "dataB") {
nice = "B (G)";
else if (!label.compare("sigma", Qt::CaseInsensitive))
} else if (!label.compare("sigma", Qt::CaseInsensitive)) {
if (fNorm)
nice = "#sigma/max(#sigma)";
else
nice = "#sigma (1/#mus)";
else if (!label.compare("lambda", Qt::CaseInsensitive))
} else if (!label.compare("lambda", Qt::CaseInsensitive)) {
if (fNorm)
nice = "#lambda/max(#lambda)";
else
nice = "#lambda (1/#mus)";
else if (!label.compare("rate", Qt::CaseInsensitive))
} else if (!label.compare("rate", Qt::CaseInsensitive)) {
if (fNorm)
nice = "Rate/max(Rate)";
else
nice = "Rate (1/#mus)";
else if (!label.compare("alpha_LR", Qt::CaseInsensitive))
} else if (!label.compare("alpha_LR", Qt::CaseInsensitive)) {
if (fNorm)
nice = "#alpha_{LR}/max(#alpha_{LR})";
else
nice = "#alpha_{LR}";
else if (!label.compare("alpha_TB", Qt::CaseInsensitive))
} else if (!label.compare("alpha_TB", Qt::CaseInsensitive)) {
if (fNorm)
nice = "#alpha_{TB}/max(#alpha_{TB})";
else
nice = "#alpha_{TB}";
} else {
if (fNorm) {
nice = label + "/ max(" + label + ")";
}
}
return nice;
}

View File

@ -80,6 +80,7 @@ class PmuppScript : public QObject
PmuppPlotEntry fPlotEntry;
QVector<PmuppPlotEntry> fPlotInfo;
bool fNorm;
QString fLoadPath;
QString fSavePath;

View File

@ -9,8 +9,8 @@ load YBCO-40nm-T120K-FC150mT-Escan.db
selectAll
addX dataE
addY Field
x dataE
y Field
savePath ./
plot FieldVsEnergy.pdf

View File

@ -0,0 +1,19 @@
# This is a comment
loadPath ./
load YBCO-40nm-FC-E3p8keV-B10mT-Tscan.db
load YBCO-40nm-FC-E3p8keV-B150mT-Tscan.db
selectAll
norm
x dataT
y Field
savePath ./
plot FieldVsTemp.pdf
macro FieldVsTemp.C
# end

View File

@ -0,0 +1,18 @@
# This is a comment
loadPath ./
load YBCO-40nm-FC-E3p8keV-B10mT-Tscan.db
load YBCO-40nm-FC-E3p8keV-B150mT-Tscan.db
selectAll
x dataT
y Sigma
savePath ./
plot SigmaVsTemp.pdf
macro SigmaVsTemp.C
# end

View File

@ -72,8 +72,9 @@ void mupp_syntax()
cout << " select <nn> : selects collection <nn>, where <nn> is either the number" << endl;
cout << " of the collections, or its name, e.g. " << endl;
cout << " select YBCO-40nm-T5K-FC150mT-Escan.db" << endl;
cout << " addX <label> : add <label> as a x-variable. Only one is allowed." << endl;
cout << " addY <label(s)>: add <label(s)> as y-variable. Multiple labls are possible." << endl;
cout << " x <label> : add <label> as a x-variable. Only one is allowed." << endl;
cout << " y <label(s)> : add <label(s)> as y-variable. Multiple labls are possible." << endl;
cout << " norm : normalize data to maximum." << endl;
cout << " savePath <dir> : set the save path to <dir>. The place where the macros," << endl;
cout << " and/or the plot output will be saved." << endl;
cout << " plot <fln> : where <fln> is the file name with extension under which" << endl;
@ -195,7 +196,7 @@ int mupp_script_syntax_check(QStringList &list)
cerr << "****************" << endl;
return -1;
}
} else if (str.startsWith("addX")) {
} else if (str.startsWith("x")) {
tok = str.split(' ', QString::SkipEmptyParts);
if (tok.size() != 2) {
cerr << endl;
@ -204,7 +205,7 @@ int mupp_script_syntax_check(QStringList &list)
cerr << "****************" << endl;
return -1;
}
} else if (str.startsWith("addY")) {
} else if (str.startsWith("y")) {
tok = str.split(' ', QString::SkipEmptyParts);
if (tok.size() < 2) {
cerr << endl;
@ -283,21 +284,23 @@ int mupp_script_syntax_check(QStringList &list)
cerr << "****************" << endl;
return -2;
}
} else if (str.startsWith("norm")) {
// nothing-to-be-done
} else {
cerr << endl;
cerr << "*********" << endl;
cerr << "**ERROR** found unrecognized script command: '" << str.toLatin1().constData() << "'." << endl;
cerr << "*********" << endl;
cerr << " Currently supported:" << endl;
cerr << " load <coll(s)>, where <coll(s)> is a file-name-list of collections (*.db, *.dat)" << endl;
cerr << " loadPath <path>, where <path> is the load path accepting bash variables like $HOME, etc." << endl;
cerr << " addX <var-name>, where <var-name> is a data tag of the db/dat-file." << endl;
cerr << " addY <var-name>, where <var-name> is a data tag of the db/dat-file." << endl;
cerr << " select <nn>, where <nn> is the row-number or collection name of the collection to be selected." << endl;
cerr << " selectAll, i.e. already set addX, addY will apply to ALL collections present." << endl;
cerr << " savePath <path>, where <path> is the save path accepting bash variables like $HOME, etc." << endl;
cerr << " plot <fln>, where <fln> is the file name with extension under which the plot should be saved." << endl;
cerr << " macro <fln>, where <fln> is the file name under which the root macro should be saved." << endl;
cerr << " load <coll(s)> : where <coll(s)> is a file-name-list of collections (*.db, *.dat)" << endl;
cerr << " loadPath <path> : where <path> is the load path accepting bash variables like $HOME, etc." << endl;
cerr << " x <var-name> : where <var-name> is a data tag of the db/dat-file." << endl;
cerr << " y <var-name> : where <var-name> is a data tag of the db/dat-file." << endl;
cerr << " select <nn> : where <nn> is the row-number or collection name of the collection to be selected." << endl;
cerr << " selectAll : i.e. already set addX, addY will apply to ALL collections present." << endl;
cerr << " savePath <path> : where <path> is the save path accepting bash variables like $HOME, etc." << endl;
cerr << " plot <fln> : where <fln> is the file name with extension under which the plot should be saved." << endl;
cerr << " macro <fln> : where <fln> is the file name under which the root macro should be saved." << endl;
cerr << endl;
return -3;
}