Finished implementing FUNCTIONS block in development branch. Next, add it to production branch and debug.

This commit is contained in:
salman 2010-06-08 11:36:35 +00:00
parent 5d4683ff1f
commit 93f48a677d
4 changed files with 123 additions and 100 deletions

View File

@ -124,6 +124,21 @@ sub CreateMSR {
my ($Full_T_Block,$Paramcomp_ref)=MSR::CreateTheory(@FitTypes);
my @Paramcomp = @$Paramcomp_ref;
# If we have a FUNCTIONS Block the Full_T_Block should be
# replaced by Func_T_Block
$FUNCTIONS_Block = $EMPTY;
if ($All{"FunctionsBlock"} ne $EMPTY) {
$FUNCTIONS_Block = "
###############################################################
FUNCTIONS
###############################################################
".$All{"FunctionsBlock"}."\n";
$Full_T_Block=$All{"Func_T_Block"};
# remove all _N to end (may fail with large number of parameters)
$Full_T_Block =~ s/_\d\b//g;
}
# Counter for RUNS
my $iRun = 1;
@ -344,7 +359,6 @@ FITPARAMETER
$PCount $Param $value $error $error $minvalue $maxvalue";
}
$Full_T_Block = "
###############################################################
THEORY
@ -352,14 +366,6 @@ THEORY
$Full_T_Block
";
$FUNCTIONS_Block = $EMPTY;
if ($All{"FunctionsBlock"} ne $EMPTY) {
$FUNCTIONS_Block = "
###############################################################
FUNCTIONS
###############################################################".
$All{"FunctionsBlock"}."\n";
}
$RUN_Block =
"###############################################################
@ -481,6 +487,20 @@ sub CreateMSRSingleHist {
my ($Full_T_Block,$Paramcomp_ref)=MSR::CreateTheory(@FitTypes);
my @Paramcomp = @$Paramcomp_ref;
# If we have a FUNCTIONS Block the Full_T_Block should be
# replaced by Func_T_Block
$FUNCTIONS_Block = $EMPTY;
if ($All{"FunctionsBlock"} ne $EMPTY) {
$FUNCTIONS_Block = "
###############################################################
FUNCTIONS
###############################################################
".$All{"FunctionsBlock"}."\n";
$Full_T_Block=$All{"Func_T_Block"};
# remove all _N to end
$Full_T_Block =~ s/_\d\b//g;
}
# Counter for RUNS
my $iRun = 1;
@ -725,16 +745,6 @@ THEORY
$Full_T_Block
";
$FUNCTIONS_Block = $EMPTY;
if ($All{"FunctionsBlock"} ne $EMPTY) {
$FUNCTIONS_Block = "
###############################################################
FUNCTIONS
###############################################################".
$All{"FunctionsBlock"}."\n";
}
$RUN_Block =
"###############################################################
$RUN_Block";

View File

@ -1,6 +1,6 @@
# Form implementation generated from reading ui file 'MuSRFit.ui'
#
# Created: Mon Jun 7 18:29:05 2010
# Created: Tue Jun 8 13:35:32 2010
# by: The PerlQt User Interface Compiler (puic)
#
# WARNING! All changes made in this file will be lost!
@ -43,7 +43,7 @@ use Qt::slots
RunSelectionToggle => [],
fileBrowse => [],
AppendToFunctions => [],
ResetFunctions => [];
InitializeFunctions => [];
use Qt::attributes qw(
musrfit_tabs
RUNSPage
@ -1583,7 +1583,7 @@ sub NEW
setName("MuSRFitform" );
}
setSizePolicy(Qt::SizePolicy(3, 3, 1, 1, this->sizePolicy()->hasHeightForWidth()) );
setMinimumSize(Qt::Size(21, 264) );
setMinimumSize(Qt::Size(21, 275) );
setIcon($image0 );
setCentralWidget(Qt::Widget(this, "qt_central_widget"));
@ -1594,7 +1594,6 @@ sub NEW
musrfit_tabs->setSizePolicy( Qt::SizePolicy(7, 7, 1, 1, musrfit_tabs->sizePolicy()->hasHeightForWidth()) );
musrfit_tabs->setMinimumSize( Qt::Size(560, 400) );
musrfit_tabs->setMaximumSize( Qt::Size(95, 32767) );
musrfit_tabs->setMouseTracking( 0 );
RUNSPage = Qt::Widget(musrfit_tabs, "RUNSPage");
@ -2840,7 +2839,10 @@ sub NEW
Qt::Object::connect(T0, SIGNAL "activated()", this, SLOT "ShowMuSRT0()");
Qt::Object::connect(Plot, SIGNAL "activated()", this, SLOT "GoPlot()");
Qt::Object::connect(AddConstraint, SIGNAL "clicked()", this, SLOT "AppendToFunctions()");
Qt::Object::connect(ResetFunc, SIGNAL "clicked()", this, SLOT "ActivateShComp()");
Qt::Object::connect(ResetFunc, SIGNAL "clicked()", this, SLOT "InitializeFunctions()");
Qt::Object::connect(FitType1, SIGNAL "activated(const QString&)", this, SLOT "InitializeFunctions()");
Qt::Object::connect(FitType2, SIGNAL "activated(int)", this, SLOT "InitializeFunctions()");
Qt::Object::connect(FitType3, SIGNAL "activated(int)", this, SLOT "InitializeFunctions()");
setTabOrder(musrfit_tabs, RunNumbers);
setTabOrder(RunNumbers, BeamLine);
@ -3532,6 +3534,8 @@ sub CreateAllInput
# Functions block
$All{"FunctionsBlock"}=FunctionsBlock->text;
# and the associated theory block
$All{"Func_T_Block"}=TheoryBlock->text;
# Read initial values of paramets from tabel
my $erradd = "d";
@ -3610,8 +3614,6 @@ sub CreateAllInput
$All{"FILENAME"}="TMP";
}
# Return Hash with all important values
return %All;
@ -3801,7 +3803,7 @@ sub ActivateShComp
my $ParamChkBx="ShParam_".$Component."_".$i;
my $ChkBx = child($ParamChkBx);
# my $CParam = $Params[$i-1]."_".$Component;
if ($Params[$i-1] ne "" && $Params[$i-1] ne "Alpha" && $Params[$i-1] ne "N0" && $Params[$i-1] ne "NBg") {
if ($Params[$i-1] ne "" ) {
$ChkBx->setHidden(0);
$ChkBx->setEnabled(1);
$ChkBx ->setText($Params[$i-1]);
@ -3868,6 +3870,11 @@ sub TabChanged
# And also setup T0 and Bg bins
ActivateT0Hists();
# Initialize FUNCTIONS block only if it has not been initialized yet
if ($All{"Func_T_Block"} eq "" ) {
InitializeFunctions();
}
}
sub GoFit
@ -4039,7 +4046,7 @@ sub AppendToFunctions
}
sub ResetFunctions
sub InitializeFunctions
{
my %All=CreateAllInput();
@ -4054,38 +4061,51 @@ sub ResetFunctions
# Get number of parameters 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"};
my $Param="";
# Initialize Parameters List in function block (constraints).
my $ParametersList="";
ParametersList->setText("");
# Counter for function block (with out Alpha etc.)
my $ParCount=0;
CParamsCombo->clear();
# my $CParam = $Params[$i-1]."_".$Component;
# CParamsCombo->insertItem($CParam,-1);
# $Full_T_Block=~ s/\b$Params[$i-1]\b/$CParam/;
my $Component=1;
foreach my $FitType (@FitTypes) {
my $Parameters=$Paramcomp[$Component-1];
my @Params = split( /\s+/, $Parameters );
# Also update Parameters List for the Functions block
(my $Ptmp,my $tmp)=split(/_/,$Param);
if ($Ptmp ne "" && $Ptmp ne "Alpha" && $Ptmp ne "N0" && $Ptmp ne "NBg") {
# Alpha, N0 and NBg are counted in the parameters
if ( $Component == 1 && $All{"FitAsyType"} eq "Asymmetry" ) {
unshift( @Params, "Alpha" );
}
elsif ( $Component == 1 && $All{"FitAsyType"} eq "SingleHist" ) {
unshift( @Params, ( "N0", "NBg" ) );
}
# Add list to the constraints drop down menu
for (my $i=1; $i<=9;$i++) {
my $CParam = $Params[$i-1]."_".$Component;
if ($Params[$i-1] ne "" ) {
if ($Params[$i-1] ne "Alpha" && $Params[$i-1] ne "N0" && $Params[$i-1] ne "NBg") {
CParamsCombo->insertItem($CParam,-1);
$Full_T_Block=~ s/\b$Params[$i-1]\b/$CParam/;
}
# also enumerate the parameters as should be used in the FUNCTIONS Block
$ParCount++;
$ParametersList=$ParametersList."$Param is par$ParCount\n";
$ParametersList=$ParametersList."$CParam \t is \t par$ParCount\n";
ParametersList->setText($ParametersList);
}
}
$Component++;
}
# Set theory block in Constraints
TheoryBlock->setText($Full_T_Block);
# Then clear the text
ConstraintLine->setText("");
FunctionsBlock->setText("");
}
1;

View File

@ -22,8 +22,8 @@
</property>
<property name="minimumSize">
<size>
<width>23</width>
<height>270</height>
<width>21</width>
<height>275</height>
</size>
</property>
<property name="caption">
@ -5346,7 +5346,25 @@
<sender>ResetFunc</sender>
<signal>clicked()</signal>
<receiver>MuSRFitform</receiver>
<slot>ActivateShComp()</slot>
<slot>InitializeFunctions()</slot>
</connection>
<connection>
<sender>FitType1</sender>
<signal>activated(const QString&amp;)</signal>
<receiver>MuSRFitform</receiver>
<slot>InitializeFunctions()</slot>
</connection>
<connection>
<sender>FitType2</sender>
<signal>activated(int)</signal>
<receiver>MuSRFitform</receiver>
<slot>InitializeFunctions()</slot>
</connection>
<connection>
<sender>FitType3</sender>
<signal>activated(int)</signal>
<receiver>MuSRFitform</receiver>
<slot>InitializeFunctions()</slot>
</connection>
</connections>
<tabstops>
@ -5455,8 +5473,7 @@
<slot>RunSelectionToggle()</slot>
<slot>fileBrowse()</slot>
<slot>AppendToFunctions()</slot>
<slot>ResetFunctions()</slot>
<slot>InitializeFunction()</slot>
<slot>InitializeFunctions()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@ -341,9 +341,6 @@ void MuSRFitform::CreateAllInput()
$All{"FunctionsBlock"}=FunctionsBlock->text;
# and the associated theory block
$All{"Func_T_Block"}=TheoryBlock->text;
if ($All{"Func_T_Block"} eq "") {
InitializeFunction();
}
# Read initial values of paramets from tabel
my $erradd = "d";
@ -665,6 +662,11 @@ void MuSRFitform::TabChanged()
UpdateMSRFileInitTable();
# And also setup T0 and Bg bins
ActivateT0Hists();
# Initialize FUNCTIONS block only if it has not been initialized yet
if ($All{"Func_T_Block"} eq "" ) {
InitializeFunctions();
}
}
@ -827,7 +829,7 @@ void MuSRFitform::AppendToFunctions()
TheoryBlock->setText($Full_T_Block);
}
void MuSRFitform::ResetFunctions()
void MuSRFitform::InitializeFunctions()
{
my %All=CreateAllInput();
my @RUNS = split( /,/, $All{"RunNumbers"} );
@ -841,68 +843,42 @@ void MuSRFitform::ResetFunctions()
# Get number of parameters 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"};
my $Param="";
# Initialize Parameters List in function block (constraints).
my $ParametersList="";
ParametersList->setText("");
# Counter for function block (with out Alpha etc.)
my $ParCount=0;
CParamsCombo->clear();
# my $CParam = $Params[$i-1]."_".$Component;
# CParamsCombo->insertItem($CParam,-1);
# $Full_T_Block=~ s/\b$Params[$i-1]\b/$CParam/;
# Also update Parameters List for the Functions block
(my $Ptmp,my $tmp)=split(/_/,$Param);
if ($Ptmp ne "" && $Ptmp ne "Alpha" && $Ptmp ne "N0" && $Ptmp ne "NBg") {
$ParCount++;
$ParametersList=$ParametersList."$Param is par$ParCount\n";
ParametersList->setText($ParametersList);
}
# Set theory block in Constraints
TheoryBlock->setText($Full_T_Block);
# Then clear the text
ConstraintLine->setText("");
FunctionsBlock->setText("");
}
void MuSRFitform::InitializeFunction()
{
my %All=CreateAllInput();
my @RUNS = split( /,/, $All{"RunNumbers"} );
my @FitTypes =();
foreach my $FitType ($All{"FitType1"}, $All{"FitType2"}, $All{"FitType3"}) {
if ( $FitType ne "None" ) {
push( @FitTypes, $FitType );
}
}
# Get number of parameters to determine the size of the table
my ($Full_T_Block,$Paramcomp_ref)= MSR::CreateTheory(@FitTypes);
my @Paramcomp = @$Paramcomp_ref;
my $Full_T_Block= $All{"Full_T_Block"};
my $Component=1;
foreach my $FitType (@FitTypes) {
my $Parameters=$Paramcomp[$Component-1];
my @Params = split( /\s+/, $Parameters );
# Alpha, N0 and NBg are counted in the parameters
if ( $Component == 1 && $All{"FitAsyType"} eq "Asymmetry" ) {
unshift( @Params, "Alpha" );
}
elsif ( $Component == 1 && $All{"FitAsyType"} eq "SingleHist" ) {
unshift( @Params, ( "N0", "NBg" ) );
}
# Add list to the constraints drop down menu
for (my $i=1; $i<=9;$i++) {
my $CParam = $Params[$i-1]."_".$Component;
if ($Params[$i-1] ne "" ) {
if ($Params[$i-1] ne "Alpha" && $Params[$i-1] ne "N0" && $Params[$i-1] ne "NBg") {
CParamsCombo->insertItem($CParam,-1);
$Full_T_Block=~ s/\b$Params[$i-1]\b/$CParam/;
}
# also enumerate the parameters as should be used in the FUNCTIONS Block
$ParCount++;
$ParametersList=$ParametersList."$CParam \t is \t par$ParCount\n";
ParametersList->setText($ParametersList);
}
}
$Component++;
}