Begin implementation of export fit paramets.

This commit is contained in:
2009-09-13 21:11:48 +00:00
parent 7b0154f131
commit 4b9ae9fe4d
8 changed files with 468 additions and 54 deletions

View File

@ -1226,6 +1226,145 @@ sub PrepParamTable {
}
########################
# ExportParams
# Function return a tab separated table of parameters for the fit
# input should be
# %All
########################
sub ExportParams {
my $erradd = "d";
my $minadd = "_min";
my $maxadd = "_max";
# First assume nothing is shared
my $Shared = 0;
my $TABLE="";
my %All = %{$_[0]};
my @RUNS = ();
if ($All{"RUNSType"}) {
@RUNS = split( /,/, $All{"RunFiles"} );
} else {
@RUNS = split( /,/, $All{"RunNumbers"} );
}
my @Hists = split( /,/, $All{"LRBF"} );
my @FitTypes =();
foreach my $FitType ($All{"FitType1"}, $All{"FitType2"}, $All{"FitType3"}) {
if ( $FitType ne "None" ) { push( @FitTypes, $FitType ); }
}
# Get theory block to determine the size of the table
my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateTheory(@FitTypes);
# For now the line below does not work. Why?
# my $Paramcomp_ref=$All{"Paramcomp_ref"};
my @Paramcomp = @$Paramcomp_ref;
my $Full_T_Block= $All{"Full_T_Block"};
# Extract parameter block form the MSR file
# my $FILENAME=$All{"FILENAME"};
# open (MSRF,q{<},"$FILENAME.msr" );
# my @lines = <MSRF>;
# close(IFILE);
# my $FPBlock_ref=MSR::ExtractParamBlk(@lines);
# my @FPBloc = @$FPBlock_ref;
# Then loop over expected parameters and extract their values and error bar
my $PCount =0;
my $iRun =0;
my $value =0;
my $error = 0;
my $minvalue = 0;
my $maxvalue = 0;
my $Component=1;
foreach my $RUN (@RUNS) {
my $line="$RUN";
$iRun++;
$Component=1;
if ($All{"FitAsyType"} eq "Asymmetry") {
foreach my $FitType (@FitTypes) {
my $Parameters=$Paramcomp[$Component-1];
my @Params = split( /\s+/, $Parameters );
if ( $Component == 1 ) {
unshift( @Params, "Alpha" );
}
# This is the counter for parameters of this component
my $NP=1;
$Shared = 0;
# Change state/label of parameters
foreach my $Param (@Params) {
my $Param_ORG = $Param;
if ( $#FitTypes != 0 && ( $Param ne "Alpha" ) ){
$Param = join( "", $Param, "_", "$Component" );
}
$Shared = $All{"Sh_$Param"};
if ( $Shared!=1 || $iRun == 1 ) {
# It there are multiple runs index the parameters accordingly
$Param=$Param."_".$iRun;
# Check if this parameter has been initialized befor. (should be)
$value = $All{"$Param"};
$error = $All{"$erradd$Param"};
$line=join("\t",$line,$value,$error);
$PCount++;
}
$NP++;
}
$Component++;
}
}
elsif ($All{"FitAsyType"} eq "SingleHist") {
# For a single histogram fit we basically need to repeat this for each hist
foreach my $Hist (@Hists) {
$Component=1;
foreach my $FitType (@FitTypes) {
my $Parameters=$Paramcomp[$Component-1];
my @Params = split( /\s+/, $Parameters );
if ( $Component == 1 ) {
unshift( @Params, ( "N0", "NBg" ) );
}
# This is the counter for parameters of this component
my $NP=1;
$Shared = 0;
# Change state/label of parameters
foreach my $Param (@Params) {
my $Param_ORG = $Param;
$Param=$Param.$Hist;
if ( $#FitTypes != 0 && ( $Param_ORG ne "N0" && $Param_ORG ne "NBg" ) ){
$Param = join( "", $Param, "_", "$Component" );
}
$Shared = $All{"Sh_$Param"};
if ( $Shared!=1 || $iRun == 1 ) {
# It there are multiple runs index the parameters accordingly
$Param=$Param."_".$iRun;
# Check if this parameter has been initialized befor. (should be)
$value = $All{"$Param"};
$error = $All{"$erradd$Param"};
$minvalue = $All{"$Param$minadd"};
$maxvalue = $All{"$Param$maxadd"};
$values=join("\t",$Param,$value,$error,$minvalue,$maxvalue,$RUN);
$ParTable{$PCount}=$values;
$PCount++;
}
$NP++;
}
$Component++;
}
}
}
$TABLE=$TABLE."$line\n"
}
return $TABLE;
}
########################
# RUNFileNameAuto
# Function return the RUN_Line for a given RUN

View File

@ -1,6 +1,6 @@
# Form implementation generated from reading ui file 'MuSRFit.ui'
#
# Created: Thu Sep 10 08:22:47 2009
# Created: Sun Sep 13 23:09:01 2009
# by: The PerlQt User Interface Compiler (puic)
#
# WARNING! All changes made in this file will be lost!
@ -19,6 +19,8 @@ use Qt::slots
fileChangeDir => [],
filePrint => [],
fileExit => [],
parametersExport => [],
parametersAppend => [],
editUndo => [],
editRedo => [],
editCut => [],
@ -179,6 +181,7 @@ use Qt::attributes qw(
ShowT0
MenuBar
fileMenu
Parameters
editMenu
Options
helpMenu
@ -206,6 +209,8 @@ use Qt::attributes qw(
Action_2
Action_3
optionsnew_itemAction
parametersExport_AsAction
parametersAppend_ToAction
);
@ -1513,6 +1518,8 @@ sub NEW
Action_2= Qt::Action(this, "Action_2");
Action_3= Qt::Action(this, "Action_3");
optionsnew_itemAction= Qt::Action(this, "optionsnew_itemAction");
parametersExport_AsAction= Qt::Action(this, "parametersExport_AsAction");
parametersAppend_ToAction= Qt::Action(this, "parametersAppend_ToAction");
toolBar = Qt::ToolBar("", this, &DockTop);
@ -1538,6 +1545,11 @@ sub NEW
fileExitAction->addTo( fileMenu );
MenuBar->insertItem( "", fileMenu, 2 );
Parameters = Qt::PopupMenu( this );
parametersExport_AsAction->addTo( Parameters );
parametersAppend_ToAction->addTo( Parameters );
MenuBar->insertItem( "", Parameters, 3 );
editMenu = Qt::PopupMenu( this );
editUndoAction->addTo( editMenu );
editRedoAction->addTo( editMenu );
@ -1545,21 +1557,21 @@ sub NEW
editCutAction->addTo( editMenu );
editCopyAction->addTo( editMenu );
editPasteAction->addTo( editMenu );
MenuBar->insertItem( "", editMenu, 3 );
MenuBar->insertItem( "", editMenu, 4 );
Options = Qt::PopupMenu( this );
FileExistCheck->addTo( Options );
ManualFile->addTo( Options );
MenuBar->insertItem( "", Options, 4 );
MenuBar->insertItem( "", Options, 5 );
helpMenu = Qt::PopupMenu( this );
helpContentsAction->addTo( helpMenu );
helpIndexAction->addTo( helpMenu );
helpMenu->insertSeparator();
helpAboutAction->addTo( helpMenu );
MenuBar->insertItem( "", helpMenu, 5 );
MenuBar->insertItem( "", helpMenu, 6 );
MenuBar->insertSeparator( 6 );
MenuBar->insertSeparator( 7 );
languageChange();
my $resize = Qt::Size(579, 501);
@ -1590,6 +1602,8 @@ sub NEW
Qt::Object::connect(PlotMSR_2, SIGNAL "pressed()", this, SLOT "GoPlot()");
Qt::Object::connect(Browse, SIGNAL "clicked()", this, SLOT "fileBrowse()");
Qt::Object::connect(BeamLine, SIGNAL "activated(int)", this, SLOT "T0Update()");
Qt::Object::connect(parametersExport_AsAction, SIGNAL "activated()", this, SLOT "parametersExport()");
Qt::Object::connect(parametersAppend_ToAction, SIGNAL "activated()", this, SLOT "parametersAppend()");
setTabOrder(musrfit_tabs, RunNumbers);
setTabOrder(RunNumbers, BeamLine);
@ -1883,8 +1897,8 @@ sub languageChange
fileOpenAction->setText( trUtf8("&Open MSR...") );
fileOpenAction->setMenuText( trUtf8("&Open MSR...") );
fileOpenAction->setAccel( Qt::KeySequence( trUtf8("Ctrl+O") ) );
fileSaveAction->setText( trUtf8("&Save MSR") );
fileSaveAction->setMenuText( trUtf8("&Save MSR") );
fileSaveAction->setText( trUtf8("&Save MSR...") );
fileSaveAction->setMenuText( trUtf8("&Save MSR...") );
fileSaveAction->setStatusTip( trUtf8("&Save MSR") );
fileSaveAction->setAccel( Qt::KeySequence( trUtf8("Ctrl+S") ) );
fileSaveAsAction->setText( trUtf8("Save MSR &As...") );
@ -1939,11 +1953,16 @@ sub languageChange
Action_3->setText( trUtf8("Unnamed") );
optionsnew_itemAction->setText( trUtf8("new item") );
optionsnew_itemAction->setMenuText( trUtf8("new item") );
parametersExport_AsAction->setText( trUtf8("&Export As...") );
parametersExport_AsAction->setMenuText( trUtf8("&Export As...") );
parametersAppend_ToAction->setText( trUtf8("&Append To...") );
parametersAppend_ToAction->setMenuText( trUtf8("&Append To...") );
toolBar->setLabel( trUtf8("Tools") );
MenuBar->findItem( 2 )->setText( trUtf8("&File") );
MenuBar->findItem( 3 )->setText( trUtf8("&Edit") );
MenuBar->findItem( 4 )->setText( trUtf8("Options") );
MenuBar->findItem( 5 )->setText( trUtf8("&Help") );
MenuBar->findItem( 3 )->setText( trUtf8("Parameters") );
MenuBar->findItem( 4 )->setText( trUtf8("&Edit") );
MenuBar->findItem( 5 )->setText( trUtf8("Options") );
MenuBar->findItem( 6 )->setText( trUtf8("&Help") );
}
@ -2018,6 +2037,54 @@ sub fileExit
}
sub parametersExport
{
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}.".dat";
my $file=Qt::FileDialog::getSaveFileName(
"$FILENAME",
"Data Files (*.dat)",
this,
"export file dialog",
"Choose a filename to export to");
# If the user gave a filename the copy to it
if ($file ne "") {
my $Text = MSR::ExportParams(\%All);
print $Text;
}
}
sub parametersAppend
{
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}.".dat";
my $file=Qt::FileDialog::getOpneFileName(
"./",
"Data Files (*.dat)",
this,
"append file dialog",
"Choose a filename to append to");
# If the user gave a filename the copy to it
if ($file ne "") {
if (-e $FILENAME) {
my $Text = MSR::ExportParams(\%All);
print $Text;
} else {
if ($file ne "") {
my $Warning = "Warning: No data file found yet!";
my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
}
}
}
MSR::ExportParams(\%All);
}
sub editUndo
{
print "MuSRFitform->editUndo(): Not implemented yet.\n";
@ -2168,7 +2235,7 @@ sub CreateAllInput
$All{"Paramcomp_ref"}=$Paramcomp_ref;
my @Paramcomp = @$Paramcomp_ref;
# TODO: Read initial values of paramets from tabel
# Read initial values of paramets from tabel
my $erradd = "d";
my $minadd = "_min";
my $maxadd = "_max";

View File

@ -22,8 +22,8 @@
</property>
<property name="minimumSize">
<size>
<width>21</width>
<height>227</height>
<width>23</width>
<height>246</height>
</size>
</property>
<property name="caption">
@ -3905,6 +3905,10 @@
<separator/>
<action name="fileExitAction"/>
</item>
<item text="Parameters" name="Parameters">
<action name="parametersExport_AsAction"/>
<action name="parametersAppend_ToAction"/>
</item>
<item text="&amp;Edit" name="editMenu">
<action name="editUndoAction"/>
<action name="editRedoAction"/>
@ -3986,10 +3990,10 @@
<iconset>image3</iconset>
</property>
<property name="text">
<string>&amp;Save MSR</string>
<string>&amp;Save MSR...</string>
</property>
<property name="menuText">
<string>&amp;Save MSR</string>
<string>&amp;Save MSR...</string>
</property>
<property name="statusTip">
<string>&amp;Save MSR</string>
@ -4308,6 +4312,28 @@
<string>new item</string>
</property>
</action>
<action>
<property name="name">
<cstring>parametersExport_AsAction</cstring>
</property>
<property name="text">
<string>&amp;Export As...</string>
</property>
<property name="menuText">
<string>&amp;Export As...</string>
</property>
</action>
<action>
<property name="name">
<cstring>parametersAppend_ToAction</cstring>
</property>
<property name="text">
<string>&amp;Append To...</string>
</property>
<property name="menuText">
<string>&amp;Append To...</string>
</property>
</action>
</actions>
<images>
<image name="image0">
@ -4483,6 +4509,18 @@
<receiver>MuSRFitform</receiver>
<slot>T0Update()</slot>
</connection>
<connection>
<sender>parametersExport_AsAction</sender>
<signal>activated()</signal>
<receiver>MuSRFitform</receiver>
<slot>parametersExport()</slot>
</connection>
<connection>
<sender>parametersAppend_ToAction</sender>
<signal>activated()</signal>
<receiver>MuSRFitform</receiver>
<slot>parametersAppend()</slot>
</connection>
</connections>
<tabstops>
<tabstop>musrfit_tabs</tabstop>
@ -4573,6 +4611,8 @@
<slot>fileChangeDir()</slot>
<slot>filePrint()</slot>
<slot>fileExit()</slot>
<slot>parametersExport()</slot>
<slot>parametersAppend()</slot>
<slot>editUndo()</slot>
<slot>editRedo()</slot>
<slot>editCut()</slot>

View File

@ -93,6 +93,51 @@ void Form1::fileExit()
Qt::Application::exit( 0 );
}
void Form1::parametersExport()
{
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}.".dat";
my $file=Qt::FileDialog::getSaveFileName(
"$FILENAME",
"Data Files (*.dat)",
this,
"export file dialog",
"Choose a filename to export to");
# If the user gave a filename the copy to it
if ($file ne "") {
my $Text = MSR::ExportParams(\%All);
print $Text;
}
}
void Form1::parametersAppend()
{
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}.".dat";
my $file=Qt::FileDialog::getOpneFileName(
"./",
"Data Files (*.dat)",
this,
"append file dialog",
"Choose a filename to append to");
# If the user gave a filename the copy to it
if ($file ne "") {
if (-e $FILENAME) {
my $Text = MSR::ExportParams(\%All);
print $Text;
} else {
if ($file ne "") {
my $Warning = "Warning: No data file found yet!";
my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
}
}
}
MSR::ExportParams(\%All);
}
void Form1::editUndo()
{
@ -247,7 +292,7 @@ void MuSRFitform::CreateAllInput()
$All{"Paramcomp_ref"}=$Paramcomp_ref;
my @Paramcomp = @$Paramcomp_ref;
# TODO: Read initial values of paramets from tabel
# Read initial values of paramets from tabel
my $erradd = "d";
my $minadd = "_min";
my $maxadd = "_max";

View File

@ -1226,6 +1226,145 @@ sub PrepParamTable {
}
########################
# ExportParams
# Function return a tab separated table of parameters for the fit
# input should be
# %All
########################
sub ExportParams {
my $erradd = "d";
my $minadd = "_min";
my $maxadd = "_max";
# First assume nothing is shared
my $Shared = 0;
my $TABLE="";
my %All = %{$_[0]};
my @RUNS = ();
if ($All{"RUNSType"}) {
@RUNS = split( /,/, $All{"RunFiles"} );
} else {
@RUNS = split( /,/, $All{"RunNumbers"} );
}
my @Hists = split( /,/, $All{"LRBF"} );
my @FitTypes =();
foreach my $FitType ($All{"FitType1"}, $All{"FitType2"}, $All{"FitType3"}) {
if ( $FitType ne "None" ) { push( @FitTypes, $FitType ); }
}
# Get theory block to determine the size of the table
my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateTheory(@FitTypes);
# For now the line below does not work. Why?
# my $Paramcomp_ref=$All{"Paramcomp_ref"};
my @Paramcomp = @$Paramcomp_ref;
my $Full_T_Block= $All{"Full_T_Block"};
# Extract parameter block form the MSR file
# my $FILENAME=$All{"FILENAME"};
# open (MSRF,q{<},"$FILENAME.msr" );
# my @lines = <MSRF>;
# close(IFILE);
# my $FPBlock_ref=MSR::ExtractParamBlk(@lines);
# my @FPBloc = @$FPBlock_ref;
# Then loop over expected parameters and extract their values and error bar
my $PCount =0;
my $iRun =0;
my $value =0;
my $error = 0;
my $minvalue = 0;
my $maxvalue = 0;
my $Component=1;
foreach my $RUN (@RUNS) {
my $line="$RUN";
$iRun++;
$Component=1;
if ($All{"FitAsyType"} eq "Asymmetry") {
foreach my $FitType (@FitTypes) {
my $Parameters=$Paramcomp[$Component-1];
my @Params = split( /\s+/, $Parameters );
if ( $Component == 1 ) {
unshift( @Params, "Alpha" );
}
# This is the counter for parameters of this component
my $NP=1;
$Shared = 0;
# Change state/label of parameters
foreach my $Param (@Params) {
my $Param_ORG = $Param;
if ( $#FitTypes != 0 && ( $Param ne "Alpha" ) ){
$Param = join( "", $Param, "_", "$Component" );
}
$Shared = $All{"Sh_$Param"};
if ( $Shared!=1 || $iRun == 1 ) {
# It there are multiple runs index the parameters accordingly
$Param=$Param."_".$iRun;
# Check if this parameter has been initialized befor. (should be)
$value = $All{"$Param"};
$error = $All{"$erradd$Param"};
$line=join("\t",$line,$value,$error);
$PCount++;
}
$NP++;
}
$Component++;
}
}
elsif ($All{"FitAsyType"} eq "SingleHist") {
# For a single histogram fit we basically need to repeat this for each hist
foreach my $Hist (@Hists) {
$Component=1;
foreach my $FitType (@FitTypes) {
my $Parameters=$Paramcomp[$Component-1];
my @Params = split( /\s+/, $Parameters );
if ( $Component == 1 ) {
unshift( @Params, ( "N0", "NBg" ) );
}
# This is the counter for parameters of this component
my $NP=1;
$Shared = 0;
# Change state/label of parameters
foreach my $Param (@Params) {
my $Param_ORG = $Param;
$Param=$Param.$Hist;
if ( $#FitTypes != 0 && ( $Param_ORG ne "N0" && $Param_ORG ne "NBg" ) ){
$Param = join( "", $Param, "_", "$Component" );
}
$Shared = $All{"Sh_$Param"};
if ( $Shared!=1 || $iRun == 1 ) {
# It there are multiple runs index the parameters accordingly
$Param=$Param."_".$iRun;
# Check if this parameter has been initialized befor. (should be)
$value = $All{"$Param"};
$error = $All{"$erradd$Param"};
$minvalue = $All{"$Param$minadd"};
$maxvalue = $All{"$Param$maxadd"};
$values=join("\t",$Param,$value,$error,$minvalue,$maxvalue,$RUN);
$ParTable{$PCount}=$values;
$PCount++;
}
$NP++;
}
$Component++;
}
}
}
$TABLE=$TABLE."$line\n"
}
return $TABLE;
}
########################
# RUNFileNameAuto
# Function return the RUN_Line for a given RUN

View File

@ -1,6 +1,6 @@
# Form implementation generated from reading ui file 'MuSRFit.ui'
#
# Created: Fri Sep 11 15:56:45 2009
# Created: Sun Sep 13 23:02:53 2009
# by: The PerlQt User Interface Compiler (puic)
#
# WARNING! All changes made in this file will be lost!
@ -585,7 +585,7 @@ sub NEW
setName("MuSRFitform" );
}
setSizePolicy(Qt::SizePolicy(3, 3, 1, 1, this->sizePolicy()->hasHeightForWidth()) );
setMinimumSize(Qt::Size(21, 251) );
setMinimumSize(Qt::Size(23, 246) );
setIcon($image0 );
setCentralWidget(Qt::Widget(this, "qt_central_widget"));
@ -2208,16 +2208,8 @@ sub parametersExport
# If the user gave a filename the copy to it
if ($file ne "") {
# TODO: check if the extension is correct, or add it.
if (-e $FILENAME) {
# my $cmd="cp $FILENAME $file";
# my $pid=system($cmd);
} else {
if ($file ne "") {
# my $Warning = "Warning: No MSR file found yet!";
# my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
}
}
my $Text = MSR::ExportParams(\%All);
print $Text;
}
}
@ -2227,8 +2219,8 @@ sub parametersAppend
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}.".dat";
my $file=Qt::FileDialog::getSaveFileName(
"$FILENAME",
my $file=Qt::FileDialog::getOpneFileName(
"./",
"Data Files (*.dat)",
this,
"append file dialog",
@ -2236,17 +2228,17 @@ sub parametersAppend
# If the user gave a filename the copy to it
if ($file ne "") {
# TODO: check if the extension is correct, or add it.
if (-e $FILENAME) {
# my $cmd="cp $FILENAME $file";
# my $pid=system($cmd);
my $Text = MSR::ExportParams(\%All);
print $Text;
} else {
if ($file ne "") {
# my $Warning = "Warning: No MSR file found yet!";
# my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
my $Warning = "Warning: No data file found yet!";
my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
}
}
}
MSR::ExportParams(\%All);
}

View File

@ -22,8 +22,8 @@
</property>
<property name="minimumSize">
<size>
<width>21</width>
<height>251</height>
<width>23</width>
<height>246</height>
</size>
</property>
<property name="caption">

View File

@ -106,16 +106,8 @@ void Form1::parametersExport()
# If the user gave a filename the copy to it
if ($file ne "") {
# TODO: check if the extension is correct, or add it.
if (-e $FILENAME) {
# my $cmd="cp $FILENAME $file";
# my $pid=system($cmd);
} else {
if ($file ne "") {
# my $Warning = "Warning: No MSR file found yet!";
# my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
}
}
my $Text = MSR::ExportParams(\%All);
print $Text;
}
}
@ -124,8 +116,8 @@ void Form1::parametersAppend()
{
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}.".dat";
my $file=Qt::FileDialog::getSaveFileName(
"$FILENAME",
my $file=Qt::FileDialog::getOpneFileName(
"./",
"Data Files (*.dat)",
this,
"append file dialog",
@ -133,17 +125,17 @@ void Form1::parametersAppend()
# If the user gave a filename the copy to it
if ($file ne "") {
# TODO: check if the extension is correct, or add it.
if (-e $FILENAME) {
# my $cmd="cp $FILENAME $file";
# my $pid=system($cmd);
my $Text = MSR::ExportParams(\%All);
print $Text;
} else {
if ($file ne "") {
# my $Warning = "Warning: No MSR file found yet!";
# my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
my $Warning = "Warning: No data file found yet!";
my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
}
}
}
MSR::ExportParams(\%All);
}