/*************************************************************************** PMusrWiz.cpp Author: Andreas Suter e-mail: andreas.suter@psi.ch ***************************************************************************/ /*************************************************************************** * Copyright (C) 2007-2021 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. * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "musrWiz.h" #include "PTheoTemplate.h" #include "PMusrfitFunc.h" #include "PMusrWiz.h" //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** * @brief PMsrData::PMsrData */ PMsrData::PMsrData() { fTemplate = -1; fMsrFileName = QString(""); fRunNumber = -1; fInstitute = "PSI"; fInstrument = "HAL9500"; fFitType = FIT_TYPE_SINGLE_HISTO; fTypeOfMeasurement = MEASURE_UNDEF; fT0Tag = T0_FROM_FILE; fT0 = -1; QDate date = QDate::currentDate(); fYear = QString("%1").arg(date.year()); fPacking = 1; fFitStart = 0.0; fFitEnd = 10.0; fCommands = ""; fTheo = ""; } //------------------------------------------------------------------------- /** * @brief PMsrData::~PMsrData */ PMsrData::~PMsrData() { } //------------------------------------------------------------------------- /** * @brief PMsrData::getFitTypeString * @return */ QString PMsrData::getFitTypeString() { QString str("UnDef"); switch (fFitType) { case FIT_TYPE_ASYMMETRY: str = QString("Asymmetry"); break; case FIT_TYPE_ASYMMETRY_RRF: str = QString("Asymmetry RRF"); break; case FIT_TYPE_SINGLE_HISTO: str = QString("Single Histo"); break; case FIT_TYPE_SINGLE_HISTO_RRF: str = QString("Single Histo RRF"); break; case FIT_TYPE_MU_MINUS: str = QString("Mu Minus"); break; case FIT_TYPE_NONE_MUSR: str = QString("None Musr"); break; case FIT_TYPE_UNDEF: default: break; } return str; } //------------------------------------------------------------------------- /** * @brief PMsrData::setParam * @param idx * @param param */ void PMsrData::setParam(int idx, PParam param) { if (idx >= fParam.size()) fParam.resize(idx+1); fParam[idx] = param; } //------------------------------------------------------------------------- /** * @brief PMsrData::setMap * @param idx * @param map */ void PMsrData::setMap(int idx, PParam map) { if (idx >= fMap.size()) fMap.resize(idx+1); fMap[idx] = map; } //------------------------------------------------------------------------- /** * @brief PMsrData::appendParam * @param param */ void PMsrData::appendParam(QVector param) { // check if parameter is aleady present. If yes, ignore it, otherwise add it bool present = false; for (int i=0; i map) { // check if map is aleady present. If yes, replace it, otherwise add it bool present = false; for (int i=0; i fMap.size())) return; fMap[idx].setName(name); } //------------------------------------------------------------------------- /** * @brief PMsrData::setFunc * @param funNo * @param str */ void PMsrData::setFunc(int funNo, QString str) { if (funNo < 0) return; // check if not already present for (int i=0; i fParam.size()) return param; return fParam[idx]; } //------------------------------------------------------------------------- /** * @brief PMsrData::getMap * @param idx * @return */ PParam PMsrData::getMap(int idx) { PParam map; if (idx >= fMap.size()) return map; return fMap[idx]; } //------------------------------------------------------------------------- /** * @brief PMsrData::getFuncNo * @param idx * @return */ int PMsrData::getFuncNo(int idx) { if ((idx < 0) || (idx >= fFunc.size())) return -1; return fFunc[idx].number; } //------------------------------------------------------------------------- /** * @brief PMsrData::isPresent * @param funStr * @return */ bool PMsrData::isPresent(const QString funStr) { for (int i=0; i fParam[i+1].getNumber()) { swap = fParam[i]; fParam[i] = fParam[i+1]; fParam[i+1] = swap; swapped = true; } } } } else if (whichVec == "map") { PParam swap; while (swapped) { swapped = false; j++; for (int i=0; i < fMap.size() - j; i++) { if (fMap[i].getNumber() > fMap[i+1].getNumber()) { swap = fMap[i]; fMap[i] = fMap[i+1]; fMap[i+1] = swap; swapped = true; } } } } else if (whichVec == "func") { PFunc swap; while (swapped) { swapped = false; j++; for (int i=0; i < fFunc.size() - j; i++) { if (fFunc[i].number > fFunc[i+1].number) { swap = fFunc[i]; fFunc[i] = fFunc[i+1]; fFunc[i+1] = swap; swapped = true; } } } } } //------------------------------------------------------------------------- /** * @brief PMsrData::removeFunc * @param funList */ void PMsrData::removeFunc(QVector &funList) { int idx; for (int i=0; iused Theory"); QPlainTextEdit *theoTextEdit = new QPlainTextEdit(theo); theoTextEdit->setReadOnly(true); QPlainTextEdit *funcTextEdit = 0; if (!func.isEmpty()) { funcTextEdit = new QPlainTextEdit(func); funcTextEdit->setReadOnly(true); } QPushButton *cancel = new QPushButton("&Cancel"); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(label); layout->addWidget(theoTextEdit); if (funcTextEdit) layout->addWidget(funcTextEdit); layout->addWidget(cancel); setLayout(layout); connect(cancel, SIGNAL(pressed()), this, SLOT(accept())); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** * @brief PIntroPage::PIntroPage * @param data * @param parent */ PIntroPage::PIntroPage(PAdmin *admin, PMsrData *data, QWidget *parent) : QWizardPage(parent), fAdmin(admin), fMsrData(data) { setTitle("

Introduction

"); setSubTitle("This wizard will help you to create your msr-file."); fMsrFileName = new QLineEdit(); fMsrFileName->setToolTip("enter msr-file name or leave it empty."); fMsrFileName->setWhatsThis("If empty the file name will be generate,\nbased on the run number, the fit type\nand the type of measurement."); fYear = new QLineEdit(); fYear->setValidator(new QIntValidator()); QDate date = QDate::currentDate(); fYear->setText(QString("%1").arg(date.year())); fYear->setToolTip("year when the run took place."); fYear->setWhatsThis("The year is used to generate\nthe RUN header information where\nmusrfit will look for the data."); fRunNumber = new QLineEdit(); fRunNumber->setValidator(new QIntValidator()); fRunNumber->setText(QString("%1").arg(fMsrData->getRunNumber())); fRunNumber->setToolTip("enter the run number here."); fInstitute = new QComboBox(); QStringList list = fAdmin->getInstituteList(); // get list form the instrument_def's list.prepend("UnDef"); fInstitute->addItems(list); int idx = fInstitute->findText(fAdmin->getDefaultInstitute()); if (idx != -1) fInstitute->setCurrentIndex(idx); fInstrument = new QComboBox(); list.clear(); list << fAdmin->getInstrumentList(fMsrData->getInstitute()); list.prepend("UnDef"); fInstrument->addItems(list); idx = fInstrument->findText(fAdmin->getDefaultInstrument()); if (idx != -1) fInstrument->setCurrentIndex(idx); fFitType = new QComboBox(); list.clear(); list << "UnDef" << "Single Histo" << "Single Histo RRF" << "Asymmetry" << "Asymmetry RRF" << "Mu Minus" << "None muSR"; fFitType->addItems(list); idx = fFitType->findText(fAdmin->getDefaultFitType()); fFitType->setCurrentIndex(idx); fMeasurementType = new QComboBox(); list.clear(); list << "UnDef" << "ZF" << "TF" << "LF"; fMeasurementType->addItems(list); fMeasurementType->setCurrentIndex(fMsrData->getTypeOfMeasurement()); fT0 = new QComboBox(); list.clear(); list << "from data file" << "call musrT0" << "enter here"; fT0->addItems(list); fT0->setCurrentIndex(fMsrData->getT0Tag()); fT0->setWhatsThis("choose if you want the t0's from the data file,\ncall musrT0 after the msr-files is generated,\nor enter the values within the wizard."); QFormLayout *layout = new QFormLayout; layout->addRow("Add msr-file name:", fMsrFileName); layout->addRow("Year:", fYear); layout->addRow("Run Number:", fRunNumber); layout->addRow("Institute:", fInstitute); layout->addRow("Instrument:", fInstrument); layout->addRow("Fit Type:", fFitType); layout->addRow("Type of Measurement:", fMeasurementType); layout->addRow("T0's:", fT0); setLayout(layout); registerField("runNumber*", fRunNumber); QObject::connect(fInstitute, SIGNAL(activated(int)), this, SLOT(handleInstituteChanged(int))); QObject::connect(fFitType, SIGNAL(activated(int)), this , SLOT(handleFitType(int))); QObject::connect(fMeasurementType, SIGNAL(activated(int)), this, SLOT(checkSetup(int))); QObject::connect(fT0, SIGNAL(activated(int)), this, SLOT(handleT0(int))); } //------------------------------------------------------------------------- void PIntroPage::handleInstituteChanged(int idx) { QString str = fInstitute->itemText(idx); QStringList list = fAdmin->getInstrumentList(str); list.prepend("UnDef"); fInstrument->clear(); fInstrument->addItems(list); } //------------------------------------------------------------------------- /** * @brief PIntroPage::handleFitType * @param idx */ void PIntroPage::handleFitType(int idx) { if ( (idx != FIT_TYPE_SINGLE_HISTO) && (idx != FIT_TYPE_ASYMMETRY) ){ QMessageBox::warning(0, "WARNING", "Currently only fit type: single histo and asymmetry available."); fFitType->setCurrentIndex(FIT_TYPE_SINGLE_HISTO); } } //------------------------------------------------------------------------- /** * @brief PIntroPage::checkSetup * @param idx */ void PIntroPage::checkSetup(int idx) { QString measure(""); PInstrument *instru = fAdmin->getInstrument(fInstitute->currentText(), fInstrument->currentText()); QVector setup; switch (idx) { case MEASURE_ZF: setup = instru->getZFSetups(); measure = "ZF"; break; case MEASURE_TF: setup = instru->getTFSetups(); measure = "TF"; break; case MEASURE_LF: setup = instru->getLFSetups(); measure = "LF"; QMessageBox::information(0, "INFO", "Not yet implemented."); break; case MEASURE_UNDEF: default: break; } if (setup.size() == 0) { QString msg = QString("Didn't find any setup for:\nInstitute: %1\nInstrument: %2").arg(fInstitute->currentText()).arg(fInstrument->currentText()); QMessageBox::critical(0, "ERROR", msg); return; } else if (setup.size() == 1) { if (setup[0].getName() == "Default") { fMsrData->setSetup("Default"); return; } } QStringList items; for (int i=0; isetSetup(setupName); } } //------------------------------------------------------------------------- /** * @brief PIntroPage::handleT0 * @param idx */ void PIntroPage::handleT0(int idx) { bool ok; if (idx == T0_ENTER_WIZ) { int t0 = QInputDialog::getInt(this, "Enter T0:", "T0:", 0, 0, 2147483647, 1, &ok); if (ok) fMsrData->setT0(t0); } } //------------------------------------------------------------------------- /** * @brief PIntroPage::nextId * @return */ int PIntroPage::nextId() const { return PMusrWiz::ePageTheory; } //------------------------------------------------------------------------- /** * @brief PIntroPage::validatePage * @return */ bool PIntroPage::validatePage() { fMsrData->setMsrFileName(fMsrFileName->text()); fMsrData->setYear(fYear->text()); fMsrData->setRunNumber(fRunNumber->text().toInt()); if (fInstitute->currentIndex() == INST_UNDEF) return false; fMsrData->setInstitute(fInstitute->currentText()); if (fInstrument->currentIndex() == 0) // i.e. undefined return false; fMsrData->setInstrument(fInstrument->currentText()); if (fFitType->currentIndex() == FIT_TYPE_UNDEF) return false; fMsrData->setFitType(fFitType->currentIndex()); if (fMeasurementType->currentIndex() == MEASURE_UNDEF) return false; fMsrData->setTypeOfMeasurement(fMeasurementType->currentIndex()); fMsrData->setT0Tag(fT0->currentIndex()); return true; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** * @brief PTheoPage::PTheoPage * @param data * @param parent */ PTheoPage::PTheoPage(PAdmin *admin, PMsrData *data, QWidget *parent) : QWizardPage(parent), fAdmin(admin), fMsrData(data) { fTheoBlockNo = 0; fTheoValid = false; fHaveMap = false; fHaveFunc = false; setTitle("

Theory

"); QString str = QString("Now you will need to enter your theory - fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); fTheo = new QPlainTextEdit(); fTheo->setWhatsThis("Enter the theory function here."); fEditTemplate = new QCheckBox("Edit Template"); fEditTemplate->setToolTip("if checked, it allows to edit the template"); fEditTemplate->hide(); fClearAll = new QPushButton(); fClearAll->setText("Clear All"); fClearAll->setToolTip("will clear the theory edit field."); fClearAll->setWhatsThis("will clear the theory edit field."); fCheckTheo = new QPushButton(); fCheckTheo->setText("Check"); fCheckTheo->setToolTip("check if the theory is valid."); fCheckTheo->setWhatsThis("Check is the theory string is valid."); QVector templ = fAdmin->getTheoTemplates(); QVector funcs = fAdmin->getMusrfitFunc(); fTheoSelect = new QComboBox(); QStringList list; // all the templates defined in musrfit_func.xml for (int i=0; iaddItems(list); fTheoSelect->setWhatsThis("select some predef. theory functions.\nFor all theory functions available check the help"); fTheoAdd = new QPushButton("Add"); QHBoxLayout *hLayout = new QHBoxLayout(); hLayout->addWidget(fTheoSelect); hLayout->addWidget(fTheoAdd); QFormLayout *layout = new QFormLayout; layout->addRow("Enter Theory:", fTheo); layout->addRow(fEditTemplate); layout->addRow("Clear Theory:", fClearAll); layout->addRow("Pre Def. Theory Select:", hLayout); layout->addRow("Press for Validation:", fCheckTheo); setLayout(layout); QObject::connect(fEditTemplate, SIGNAL(stateChanged(int)), this, SLOT(templateState(int))); QObject::connect(fClearAll, SIGNAL(clicked()), this, SLOT(clearAll())); QObject::connect(fCheckTheo, SIGNAL(clicked()), this, SLOT(checkTheory())); QObject::connect(fTheoAdd, SIGNAL(clicked()), this, SLOT(addTheory())); } //------------------------------------------------------------------------- void PTheoPage::initializePage() { QString str = QString("Now you will need to enter your theory. Fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); } //------------------------------------------------------------------------- /** * @brief PTheoPage::nextId * @return */ int PTheoPage::nextId() const { if (fHaveFunc) return PMusrWiz::ePageFunctions; else if (fHaveMap) return PMusrWiz::ePageMaps; else return PMusrWiz::ePageParameters; } //------------------------------------------------------------------------- /** * @brief PTheoPage::validatePage * @return */ bool PTheoPage::validatePage() { if (fTheo->toPlainText().isEmpty()) return false; fMsrData->clearParam(); fFunList.clear(); // fMsrData->clearFunc(); fMsrData->clearMap(); checkTheory(); if (!fTheoValid) return false; // transfer theory string fMsrData->setTheory(fTheo->toPlainText()); // transfer found parameters fMsrData->setParam(fParamList); // transfer found maps fMsrData->setMap(fMapList); // transfer found functions if (fHaveFunc) { QString funStr; for (int i=0; iisPresent(funStr)) { funStr = QString("fun%1 = ??").arg(fFunList[i]); fMsrData->setFunc(fFunList[i], funStr); } } } // check if it is necessary to eliminate functions which are not present anymore if (fFunList.size() != fMsrData->getNoOfFunc()) { // remove functions from fMsrData which are NOT found in fFuncList fMsrData->removeFunc(fFunList); } return true; } //------------------------------------------------------------------------- /** * */ void PTheoPage::templateState(int state) { if (state == Qt::Checked) { fTheo->setTextInteractionFlags(Qt::TextEditorInteraction); fMsrData->setTemplate(-1); fEditTemplate->hide(); fEditTemplate->setCheckState(Qt::Unchecked); } } //------------------------------------------------------------------------- /** * */ void PTheoPage::clearAll() { fTheo->clear(); fTheo->setTextInteractionFlags(Qt::TextEditorInteraction); fEditTemplate->hide(); fMsrData->setTemplate(-1); } //------------------------------------------------------------------------- /** * @brief PTheoPage::addTheory */ void PTheoPage::addTheory() { int idx = fTheoSelect->currentIndex(); bool isTempl = false; QString item = fTheoSelect->currentText(); if (item.startsWith("T:")) { fEditTemplate->show(); isTempl = true; } QString theo(""); bool emptyTheo = false; if (fTheo->toPlainText().isEmpty()) { // empty theory emptyTheo = true; theo = getTheoryFunction(idx); if (theo == "??") return; fTheo->setPlainText(theo); } else { // theory already has some stuff emptyTheo = false; theo = getTheoryFunction(idx); if (theo == "??") return; fTheo->appendPlainText("+"); fTheo->appendPlainText(theo); } if (isTempl && emptyTheo) { fTheo->setTextInteractionFlags(Qt::TextBrowserInteraction); fMsrData->setTemplate(idx); fMsrData->setTemplate(fAdmin->getTheoTemplate(idx)); } } //------------------------------------------------------------------------- /** * @brief PTheoPage::checkTheory */ void PTheoPage::checkTheory() { fTheoValid = false; // reset all lists: fParamList.clear(); fMapList.clear(); fFunList.clear(); // check theory the following way: // (i) make sure that line by line is a valid function // (ii) make a collection of parameters with names suggested // (iii) make a collection of functions if present // (iv) make a map list if present QString str = fTheo->toPlainText(); QStringList line = str.split("\n"); bool ok = true; PMusrfitFunc func; for (int i=0; igetMusrfitFunc(strList[0]); if (func.getName() == "UnDef") { // function not found QString str = QString("**ERROR** in line %1, '%2' is not a recognized musrfit function.").arg(i+1).arg(line[i]); QMessageBox::critical(0, "Check Theory", str); // eventually it would be nice to highlight the faulty line return; } ok = analyzeTokens(line[i], func.getNoOfParam()); if (!ok) { QString str = QString("**ERROR** in line %1.\n %2 takes %3 parameter.").arg(i+1).arg(func.getName()).arg(func.getNoOfParam()); QMessageBox::critical(0, "Check Theory", str); // eventually it would be nice to highlight the faulty line return; } } } if (fMapList.size() > 0) fHaveMap = true; else fHaveMap = false; if (fFunList.size() > 0) fHaveFunc = true; else fHaveFunc = false; fTheoValid = true; QObject *obj = sender(); if (obj == fCheckTheo) QMessageBox::information(0, "Check Theory", "Theory seems to be OK."); } //------------------------------------------------------------------------- /** * @brief PTheoPage::getTheoryFunction * @param idx * @return */ QString PTheoPage::getTheoryFunction(int idx) { QString result("??"); QVector templ = fAdmin->getTheoTemplates(); QVector func = fAdmin->getMusrfitFunc(); static int mapCount = 1; if (idx >= templ.size()) { // deal with musrfit functions if (idx >= templ.size() + func.size()) return result; result = func[idx-templ.size()].getAbbrv(); for (int i=0; igetMusrfitFunc(theo); if (func.getName() == "UnDef") { // something is fundamentaly wrong return; } QString str; par.setNumber(paramNo); str = QString("%1_%2").arg(func.getFuncParam(paramIdx-1).getParamName()).arg(fTheoBlockNo); par.setName(str); par.setValue(func.getFuncParam(paramIdx-1).getParamValue()); if (par.getName().contains("Ph_")) par.setStep(10.0); else par.setStep(par.getValue() * 0.1); // keep parameter entry fParamList.push_back(par); } //------------------------------------------------------------------------- /** * @brief PTheoPage::dealWithMap * @param theo * @param mapNo * @param paramIdx */ void PTheoPage::dealWithMap(QString theo, int mapNo, int paramIdx) { // check if mapNo is already in the map list for (int i=0; igetMusrfitFunc(theo); if (func.getName() == "UnDef") { // something is fundamentaly wrong return; } map.setNumber(mapNo); str = QString("%1_%2").arg(func.getFuncParam(paramIdx-1).getParamName()).arg(mapNo); map.setName(str); fMapList.push_back(map); } } //------------------------------------------------------------------------- /** * @brief PTheoPage::dealWithFun * @param funNo */ void PTheoPage::dealWithFun(int funNo) { // check if funNo is already in the fun list for (int i=0; iMaps"); QString str = QString("Here you can fine tune your map template names. Fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); // sort maps fMsrData->sort("map"); fMapPageLayout = new QFormLayout; setLayout(fMapPageLayout); // make sure that the map list is empty fMapGuiVec.clear(); // fill Map PParamGui mapGui; PParam map; // check if this is a template. If this is the case, fill fMsrData maps with the template info. if (fMsrData->isTemplate()) { PTheoTemplate templ = fMsrData->getTemplate(); fMsrData->clearMap(); for (int i=0; isetMap(i, templ.getMap(i)); } } for (int i=0; igetNoOfMap(); i++) { map = fMsrData->getMap(i); mapGui.paramName = new QLineEdit(map.getName()); mapGui.paramVal = new QLineEdit("3.45"); mapGui.paramStep = new QLineEdit("0.01"); mapGui.paramBoundLow = new QLineEdit(); mapGui.paramBoundHigh = new QLineEdit(); fMapGuiVec.push_back(mapGui); } QHBoxLayout *hLayout; // header hLayout = new QHBoxLayout(); mapGui.paramName = new QLineEdit("Name"); mapGui.paramName->setReadOnly(true); mapGui.paramVal = new QLineEdit("Value"); mapGui.paramVal->setReadOnly(true); mapGui.paramStep = new QLineEdit("Step"); mapGui.paramStep->setReadOnly(true); mapGui.paramBoundLow = new QLineEdit("BoundLow"); mapGui.paramBoundLow->setReadOnly(true); mapGui.paramBoundHigh = new QLineEdit("BoundHigh"); mapGui.paramBoundHigh->setReadOnly(true); hLayout->addWidget(mapGui.paramName); hLayout->addWidget(mapGui.paramVal); hLayout->addWidget(mapGui.paramStep); hLayout->addWidget(mapGui.paramBoundLow); hLayout->addWidget(mapGui.paramBoundHigh); fMapPageLayout->addRow("No", hLayout); for (int i=0; iaddWidget(fMapGuiVec[i].paramName); hLayout->addWidget(fMapGuiVec[i].paramVal); hLayout->addWidget(fMapGuiVec[i].paramStep); hLayout->addWidget(fMapGuiVec[i].paramBoundLow); hLayout->addWidget(fMapGuiVec[i].paramBoundHigh); fMapPageLayout->addRow(QString("map%1").arg(i+1), hLayout); } fShowTheo = new QPushButton("Show &Theory"); fMapPageLayout->addRow(fShowTheo); update(); connect(fShowTheo, SIGNAL(pressed()), this, SLOT(showTheo())); } //------------------------------------------------------------------------- /** * @brief PMapPage::validatePage * @return */ bool PMapPage::validatePage() { // collect the map information PParam map; QString str; double dval; bool ok; for (int i=0; igetMap(i).getNumber()); str = fMapGuiVec[i].paramName->text(); map.setName(str); dval = fMapGuiVec[i].paramVal->text().toDouble(&ok); if (ok) map.setValue(dval); else map.setValue(0.0); dval = fMapGuiVec[i].paramStep->text().toDouble(&ok); if (ok) map.setStep(dval); else map.setStep(0.0); map.setPosErr("none"); map.setBoundLow(fMapGuiVec[i].paramBoundLow->text()); map.setBoundHigh(fMapGuiVec[i].paramBoundHigh->text()); fMsrData->setMap(i, map); } return true; } //------------------------------------------------------------------------- /** * @brief PMapPage::showTheo */ void PMapPage::showTheo() { PShowTheo *showTheo = new PShowTheo(fMsrData->getTheory(), fMsrData->getFuncAll(), this); showTheo->show(); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** * @brief PFuncPage::PFuncPage */ PFuncPage::PFuncPage(PMsrData *data, QWidget *parent) : QWizardPage(parent), fMsrData(data) { setTitle("

Functions

"); QString str = QString("Now you will need to enter your functions. Fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); fFunc = new QPlainTextEdit(); fFunc->setWhatsThis("Enter the function(s) here."); fShowTheo = new QPushButton("Show &Theory"); QFormLayout *layout = new QFormLayout; layout->addRow("Enter Function(s):", fFunc); layout->addRow(fShowTheo); setLayout(layout); connect(fShowTheo, SIGNAL(pressed()), this, SLOT(showTheo())); } //------------------------------------------------------------------------- /** * @brief PFuncPage::showTheo */ void PFuncPage::showTheo() { PShowTheo *showTheo = new PShowTheo(fMsrData->getTheory(), "", this); showTheo->show(); } //------------------------------------------------------------------------- /** * @brief PFuncPage::nextId * @return */ int PFuncPage::nextId() const { if (fMsrData->getNoOfMap() > 0) return PMusrWiz::ePageMaps; else return PMusrWiz::ePageParameters; } //------------------------------------------------------------------------- /** * */ void PFuncPage::initializePage() { QString str = QString("Now you will need to enter your functions. Fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); // check if this is a template. If this is the case, fill fMsrData functions with the template info. if (fMsrData->isTemplate()) { // fill functions according to the template PTheoTemplate templ = fMsrData->getTemplate(); fMsrData->clearFunc(); for (int i=0; isetFunc(templ.getFuncNo(i), templ.getFunc(i)); } } fMsrData->sort("func"); fFunc->clear(); for (int i=0; igetNoOfFunc(); i++) { fFunc->appendPlainText(fMsrData->getFunc(fMsrData->getFuncNo(i))); } } //------------------------------------------------------------------------- /** * */ void PFuncPage::cleanupPage() { fMsrData->clearFunc(); // keep the function information QString str = fFunc->toPlainText(); QStringList funList = str.split("\n"); int funNo=0; for (int i=0; isetFunc(funNo, funList[i]); } } //------------------------------------------------------------------------- /** * @brief PFuncPage::validatePage * @return */ bool PFuncPage::validatePage() { QVector paramList; QVector mapList; QString str = fFunc->toPlainText(); QString sstr; QString tok; int idx = 0, parNo, mapNo; bool ok; // collect potentially present parameters PParam param; while ((idx = str.indexOf("par", idx)) != -1) { tok = ""; idx += 3; while (str[idx].isDigit()) { tok += str[idx++]; } parNo = tok.toInt(&ok); if (ok) { param.setNumber(parNo); sstr = QString("par%1").arg(parNo); param.setName(sstr); param.setValue(0.0); param.setStep(0.1); paramList.push_back(param); } } fMsrData->appendParam(paramList); // collect potentially present maps str = fFunc->toPlainText(); PParam map; idx = 0; while ((idx = str.indexOf("map", idx)) != -1) { tok = ""; idx += 3; while (str[idx].isDigit()) { tok += str[idx++]; } mapNo = tok.toInt(&ok); if (ok) { map.setNumber(mapNo); sstr = QString("map%1").arg(mapNo); map.setName(sstr); mapList.push_back(map); } } fMsrData->appendMap(mapList); // keep the function information str = fFunc->toPlainText(); QStringList funList = str.split("\n"); int funNo = 0; fMsrData->clearFunc(); for (int i=0; isetFunc(i, funList[i]); } return true; } //------------------------------------------------------------------------- /** * @brief PFuncPage::getFuncNo * @param str * @return */ int PFuncPage::getFuncNo(const QString str) { QString strNo = str; // str should have to form fun = , where is an int if (!str.startsWith("fun")) return -1; strNo.remove(0, 3); // get rid of 'fun' int idx = strNo.indexOf("="); if (idx == -1) return -1; strNo.remove(idx, str.length()-idx); bool ok; int ival = strNo.toInt(&ok); if (!ok) return -1; return ival; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** * @brief PParamPage::PParamPage */ PParamPage::PParamPage(PMsrData *data, QWidget *parent) : QWizardPage(parent), fMsrData(data) { fParameterPageLayout = 0; } //------------------------------------------------------------------------- /** * @brief PParamPage::nextId * @return */ int PParamPage::nextId() const { return PMusrWiz::ePageFitInfo; } //------------------------------------------------------------------------- /** * @brief PParamPage::initializePage */ void PParamPage::initializePage() { // sort parameter vector fMsrData->sort("param"); setTitle("

Fit Parameters

"); QString str = QString("Here you can fine tune your parameters. Fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); fParameterPageLayout = new QFormLayout; setLayout(fParameterPageLayout); // make sure that parameter list is empty fParamGuiVec.clear(); // fill parameters PParamGui paramGui; PParam param; // if a template replace the parameters found so far by the template parameter settings if (fMsrData->isTemplate()) { fMsrData->clearParam(); PTheoTemplate templ = fMsrData->getTemplate(); for (int i=0; isetParam(i, templ.getParam(i)); } } for (int i=0; igetNoOfParam(); i++) { param = fMsrData->getParam(i); paramGui.paramName = new QLineEdit(param.getName()); paramGui.paramVal = new QLineEdit(QString("%1").arg(param.getValue())); paramGui.paramStep = new QLineEdit(QString("%1").arg(param.getStep())); paramGui.paramBoundLow = new QLineEdit(); paramGui.paramBoundHigh = new QLineEdit(); fParamGuiVec.push_back(paramGui); } QHBoxLayout *hLayout; // header hLayout = new QHBoxLayout(); paramGui.paramName = new QLineEdit("Name"); paramGui.paramName->setReadOnly(true); paramGui.paramVal = new QLineEdit("Value"); paramGui.paramVal->setReadOnly(true); paramGui.paramStep = new QLineEdit("Step"); paramGui.paramStep->setReadOnly(true); paramGui.paramBoundLow = new QLineEdit("BoundLow"); paramGui.paramBoundLow->setReadOnly(true); paramGui.paramBoundHigh = new QLineEdit("BoundHigh"); paramGui.paramBoundHigh->setReadOnly(true); hLayout->addWidget(paramGui.paramName); hLayout->addWidget(paramGui.paramVal); hLayout->addWidget(paramGui.paramStep); hLayout->addWidget(paramGui.paramBoundLow); hLayout->addWidget(paramGui.paramBoundHigh); fParameterPageLayout->addRow("No", hLayout); for (int i=0; iaddWidget(fParamGuiVec[i].paramName); hLayout->addWidget(fParamGuiVec[i].paramVal); hLayout->addWidget(fParamGuiVec[i].paramStep); hLayout->addWidget(fParamGuiVec[i].paramBoundLow); hLayout->addWidget(fParamGuiVec[i].paramBoundHigh); fParameterPageLayout->addRow(QString("%1").arg(i+1), hLayout); } fShowTheo = new QPushButton("Show &Theory"); fParameterPageLayout->addRow(fShowTheo); update(); connect(fShowTheo, SIGNAL(pressed()), this, SLOT(showTheo())); } //------------------------------------------------------------------------- /** * @brief PParamPage::validatePage * @return */ bool PParamPage::validatePage() { PParam param; QString str; double dval; bool ok; for (int i=0; igetParam(i).getNumber()); str = fParamGuiVec[i].paramName->text(); param.setName(str); dval = fParamGuiVec[i].paramVal->text().toDouble(&ok); if (ok) param.setValue(dval); else param.setValue(0.0); dval = fParamGuiVec[i].paramStep->text().toDouble(&ok); if (ok) param.setStep(dval); else param.setStep(0.0); param.setPosErr("none"); param.setBoundLow(fParamGuiVec[i].paramBoundLow->text()); param.setBoundHigh(fParamGuiVec[i].paramBoundHigh->text()); fMsrData->setParam(i, param); } return true; } //------------------------------------------------------------------------- /** * @brief PParamPage::showTheo */ void PParamPage::showTheo() { PShowTheo *showTheo = new PShowTheo(fMsrData->getTheory(), fMsrData->getFuncAll(), this); showTheo->show(); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** * @brief PFitInfoPage::PFitInfoPage */ PFitInfoPage::PFitInfoPage(PMsrData *data, QWidget *parent) : QWizardPage(parent), fMsrData(data) { setTitle("

Fit Info

"); QString str = QString("Collect necessary fit information. Fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); fFitRangeStart = new QLineEdit("0.0"); fFitRangeStart->setValidator(new QDoubleValidator()); fFitRangeEnd = new QLineEdit("9.0"); fFitRangeEnd->setValidator(new QDoubleValidator()); QHBoxLayout *hLayout = new QHBoxLayout(); hLayout->addWidget(fFitRangeStart); hLayout->addWidget(fFitRangeEnd); fPacking = new QLineEdit("1"); fPacking->setValidator(new QIntValidator()); fCommands = new QPlainTextEdit(); fCommands->setPlainText("#MAX_LIKELIHOOD\nPRINT_LEVEL 2\nMINIMIZE\nMINOS\nSAVE"); QFormLayout *layout = new QFormLayout; layout->addRow("Fit Range:", hLayout); layout->addRow("Packing:", fPacking); layout->addRow("Commands:", fCommands); setLayout(layout); } //------------------------------------------------------------------------- /** * @brief PFitInfoPage::initializePage */ void PFitInfoPage::initializePage() { QString str = QString("Collect necessary fit information. Fit type: %1").arg(fMsrData->getFitTypeString()); setSubTitle(str); } //------------------------------------------------------------------------- /** * @brief PFitInfoPage::nextId * @return */ int PFitInfoPage::nextId() const { return PMusrWiz::ePageConclusion; } //------------------------------------------------------------------------- /** * @brief PFitInfoPage::validatePage * @return */ bool PFitInfoPage::validatePage() { bool ok; int ival = fPacking->text().toInt(&ok); if (ok) fMsrData->setPacking(ival); double dval = fFitRangeStart->text().toDouble(&ok); if (ok) fMsrData->setFitStart(dval); dval = fFitRangeEnd->text().toDouble(&ok); if (ok) fMsrData->setFitEnd(dval); fMsrData->setCmd(fCommands->toPlainText()); return true; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** * @brief PConclusionPage::PConclusionPage */ PConclusionPage::PConclusionPage(PAdmin *admin, PMsrData *data, QString *msrFilePath, QWidget *parent) : QWizardPage(parent), fMsrFilePath(msrFilePath), fAdmin(admin), fMsrData(data) { QDir ddir = QDir(*fMsrFilePath); setTitle("

Create

"); setSubTitle("Now we create the msr-file."); QVBoxLayout *vLayout = new QVBoxLayout; fMsrPathFileLabel = new QLabel("Current msr-File Path:"); fMsrFilePathLineEdit = new QLineEdit(ddir.absolutePath()); fMsrFilePathLineEdit->setReadOnly(true); fSaveAsMsrFile = new QPushButton("Save As (msr-file path)"); fSaveAsTemplate = new QPushButton("Save As (template)"); vLayout->addWidget(fMsrPathFileLabel); vLayout->addWidget(fMsrFilePathLineEdit); vLayout->addWidget(fSaveAsMsrFile); vLayout->addStretch(1); vLayout->addWidget(fSaveAsTemplate); setLayout(vLayout); connect(fSaveAsMsrFile, SIGNAL(pressed()), this, SLOT(saveAsMsrFile())); connect(fSaveAsTemplate, SIGNAL(pressed()), this, SLOT(saveAsTemplate())); } //------------------------------------------------------------------------- void PConclusionPage::saveAsMsrFile() { QString str = QFileDialog::getExistingDirectory(this, tr("Save in Directory"), "./", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (!str.isEmpty()) { *fMsrFilePath = str; fMsrFilePathLineEdit->setText(str); } } //------------------------------------------------------------------------- /** * */ void PConclusionPage::saveAsTemplate() { bool newTemplate = false; QStringList list; list << ""; for (int i=0; igetTheoTemplateSize(); i++) list << fAdmin->getTheoTemplate(i).getName(); bool ok; QString result = QInputDialog::getItem(this, "Save As Template", "Template Name", list, 0, false, &ok); if (!ok) return; if (result == "") { QString text(""); result = QInputDialog::getText(this, "New Template Name", "Enter Template Name", QLineEdit::Normal, text, &ok); if (!ok) return; // analyze the name: it has to start with 'T: ' if (!result.startsWith("T: ")) result.prepend("T: "); newTemplate = true; } // read musrfit_funcs.xml QString path = std::getenv("HOME"); QString pathFln = path + "/.musrfit/musrWiz/musrfit_funcs.xml"; bool found = false; if (QFile::exists(pathFln)) { found = true; } if (!found) { QMessageBox::critical(this, "ERROR", "Couldn't find musrfit_funcs.xml"); return; } QFile fin(pathFln); if (!fin.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::critical(this, "ERROR", "Couldn't open musrfit_funcs.xml for reading."); return; } QTextStream in(&fin); QString data = in.readAll(); fin.close(); int idx, idxEnd; QString insertStr, errMsg; if (newTemplate) { // new template // first find the proper place where to insert the new template idx = data.lastIndexOf(""); if (idx == -1) { QMessageBox::critical(this, "ERROR", "Couldn't find last theo_template. Something is very wrong."); return; } idx = data.indexOf("