Implemented dynamic number of components and sharing and export using msr2data when appropriate.

This commit is contained in:
salman 2018-02-15 10:00:05 +01:00
parent cf584ae117
commit ae5f95b83a
3 changed files with 2509 additions and 3971 deletions

View File

@ -9,44 +9,50 @@ use QtCore4::isa qw( Qt::MainWindow );
#use QtCore4::isa qw( Qt::Widget ); #use QtCore4::isa qw( Qt::Widget );
use QtCore4::debug qw(ambiguous); use QtCore4::debug qw(ambiguous);
use QtCore4::slots use QtCore4::slots
fileOpen => [], # fileOpen => [],
fileSave => [], fileSave => [],
fileChangeDir => [], fileChangeDir => [],
filePrint => [], # filePrint => [],
fileExit => [], fileExit => [],
parametersExport => [], parametersExport => [],
parametersAppend => [], parametersAppend => [],
editUndo => [], # editUndo => [],
editRedo => [], # editRedo => [],
editCut => [], # editCut => [],
editCopy => [], # editCopy => [],
editPaste => [], # editPaste => [],
helpIndex => [], # helpIndex => [],
helpContents => [], # helpContents => [],
helpAbout => [], helpAbout => [],
CreateAllInput => [], # CreateAllInput => [],
CallMSRCreate => [], # UpdateMSRFileInitTable => [],
UpdateMSRFileInitTable => [], # ActivateT0Hists => [],
ActivateT0Hists => [],
ActivateShComp => [], ActivateShComp => [],
InitializeTab => [], # InitializeTab => [],
TabChanged => [], TabChanged => [],
GoFit => [], GoFit => [],
GoPlot => [], GoPlot => [],
ShowMuSRT0 => [], ShowMuSRT0 => [],
t0Update => [], t0Update => [],
RunSelectionToggle => [], RunSelectionToggle => [],
fileBrowse => [], # fileBrowse => [],
AppendToFunctions => [], AppendToFunctions => [],
InitializeFunctions => [], InitializeFunctions => [],
addFitType => [],
addSharingComp => [],
runsLineNotEmpy => [],
t0UpdateClicked => []; t0UpdateClicked => [];
use Ui_MuSRFit4; use Ui_MuSRFit4;
use MSR;
our $self = "";
our %All = ();
sub NEW { sub NEW {
my ( $class, $parent ) = @_; my ( $class, $parent ) = @_;
$class->SUPER::NEW($parent); $class->SUPER::NEW($parent);
this->{ui} = Ui_MuSRFit4->setupUi(this); $self = Ui_MuSRFit4->setupUi(this);
my %All=CreateAllInput(); %All=CreateAllInput();
} }
# This file is part of MuSRFitGUI. # This file is part of MuSRFitGUI.
@ -86,7 +92,6 @@ sub fileOpen()
sub fileSave() sub fileSave()
{ {
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}.".msr"; my $FILENAME=$All{"FILENAME"}.".msr";
my $file=Qt::FileDialog::getSaveFileName( my $file=Qt::FileDialog::getSaveFileName(
this, this,
@ -139,10 +144,18 @@ sub parametersExport()
{ {
# Exports the fit parameters for a table format file # Exports the fit parameters for a table format file
# This works only after a fit call, i.e. a plot call is not sufficient! # This works only after a fit call, i.e. a plot call is not sufficient!
my %All=CreateAllInput(); my @RUNS = ();
if ($All{"RUNSType"} ) {
@RUNS = split( /,/, $All{"RunFiles"});
} else {
$All{"RunNumbers"} =~ s/[\ \.\~\/\&\*\[\;\>\<\^\$\(\)\`\|\]\'\@]/,/g;
@RUNS = split( /,/, MSR::ExpandRunNumbers($All{"RunNumbers"}) );
}
# Add also a flag for header # Add also a flag for header
$All{"Header"}=1; $All{"Header"}=1;
my $StupidName = $RUNS[0]."+global_tmpl.msr";
my $FILENAME=$All{"FILENAME"}.".dat"; my $FILENAME=$All{"FILENAME"}.".dat";
my $MSR = $All{"FILENAME"}.".msr";
my $file=Qt::FileDialog::getSaveFileName( my $file=Qt::FileDialog::getSaveFileName(
this, this,
"Export parameters to file", "Export parameters to file",
@ -151,10 +164,23 @@ sub parametersExport()
# If the user gave a filename the copy to it # If the user gave a filename the copy to it
if ($file ne "") { if ($file ne "") {
if ($All{"FitAsyType"} eq "Asymmetry") {
# Update All from GUI
%All=CreateAllInput();
# my style
my $Text = MSR::ExportParams(\%All); my $Text = MSR::ExportParams(\%All);
open( DATF,q{>},"$file" ); open( DATF,q{>},"$file" );
print DATF $Text; print DATF $Text;
close(DATF); close(DATF);
} else {
# msr2data style
my $RunList = join(" ",@RUNS);
my $cmd = "cp $MSR $StupidName; msr2data \[".$RunList."\] "." _tmpl new global data -o $file";
my $pid = open(FTO,"$cmd 2>&1 |");
while (<FTO>) {
$self->fitTextOutput->append("$_");
}
}
} }
} }
@ -163,10 +189,18 @@ sub parametersAppend()
{ {
# Appends the fit parameters for a table format file # Appends the fit parameters for a table format file
# This works only after a fit call, i.e. a plot call is not sufficient! # This works only after a fit call, i.e. a plot call is not sufficient!
my %All=CreateAllInput(); my @RUNS = ();
if ($All{"RUNSType"} ) {
@RUNS = split( /,/, $All{"RunFiles"});
} else {
$All{"RunNumbers"} =~ s/[\ \.\~\/\&\*\[\;\>\<\^\$\(\)\`\|\]\'\@]/,/g;
@RUNS = split( /,/, MSR::ExpandRunNumbers($All{"RunNumbers"}) );
}
# Add also a flag for header # Add also a flag for header
$All{"Header"}=0; $All{"Header"}=0;
my $StupidName = $RUNS[0]."+global_tmpl.msr";
my $FILENAME=$All{"FILENAME"}.".dat"; my $FILENAME=$All{"FILENAME"}.".dat";
my $MSR = $All{"FILENAME"}.".msr";
my $file=Qt::FileDialog::getOpenFileName( my $file=Qt::FileDialog::getOpenFileName(
this, this,
"Append parameters to file", "Append parameters to file",
@ -175,10 +209,23 @@ sub parametersAppend()
# If the user gave a filename the copy to it # If the user gave a filename the copy to it
if ($file ne "") { if ($file ne "") {
if ($All{"FitAsyType"} eq "Asymmetry") {
# Update All values from GUI
%All=CreateAllInput();
my $Text = MSR::ExportParams(\%All); my $Text = MSR::ExportParams(\%All);
open( DATF,q{>>},"$file" ); open( DATF,q{>>},"$file" );
print DATF $Text; print DATF $Text;
close(DATF); close(DATF);
} else {
# msr2data style
my $RunList = join(" ",@RUNS);
my $cmd = "cp $MSR $StupidName; msr2data \[".$RunList."\] "." _tmpl global data -o $file";
my $pid = open(FTO,"$cmd 2>&1 |");
while (<FTO>) {
$self->fitTextOutput->append("$_");
}
close(FTO);
}
} }
} }
@ -254,51 +301,49 @@ Copyright 2009-2017 by Zaher Salman
sub CreateAllInput() sub CreateAllInput()
{ {
my %All=();
# From RUNS Tab # From RUNS Tab
# Run data file # Run data file
$All{"RunNumbers"} = this->{ui}->runNumbers->text(); $All{"RunNumbers"} = $self->runNumbers->text();
$All{"RunFiles"} = this->{ui}->runFiles->text(); $All{"RunFiles"} = $self->runFiles->text();
$All{"BeamLine"} = this->{ui}->beamLine->currentText; $All{"BeamLine"} = $self->beamLine->currentText;
$All{"RUNSType"} = this->{ui}->manualFile->isChecked(); $All{"RUNSType"} = $self->manualFile->isChecked();
$All{"YEAR"} = this->{ui}->year->currentText; $All{"YEAR"} = $self->year->currentText;
if (!defined($All{"YEAR"}) || $All{"YEAR"} eq "") { if (!defined($All{"YEAR"}) || $All{"YEAR"} eq "") {
# If year combobox is empty fill it up from 2004 up to current year # If year combobox is empty fill it up from 2004 up to current year
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
my $current_year = 1900 + $yearOffset; my $current_year = 1900 + $yearOffset;
# my @years = ($current_year..2004); # my @years = ($current_year..2004);
# this->{ui}->year->addItems(@years); # $self->year->addItems(@years);
for (my $i=$current_year;$i>=2004;$i--) { for (my $i=$current_year;$i>=2004;$i--) {
this->{ui}->year->addItem($i); $self->year->addItem($i);
} }
} }
# Time range and BINS # Time range and BINS
$All{"Tis"} = this->{ui}->tis->text; $All{"Tis"} = $self->tis->text;
$All{"Tfs"} = this->{ui}->tfs->text; $All{"Tfs"} = $self->tfs->text;
$All{"BINS"} = this->{ui}->bins->text; $All{"BINS"} = $self->bins->text;
$All{"FitAsyType"} = this->{ui}->fitAsyType->currentText; $All{"FitAsyType"} = $self->fitAsyType->currentText;
$All{"FitAsyType"} =~ s/ //g; $All{"FitAsyType"} =~ s/ //g;
$All{"LRBF"} = this->{ui}->histsLRBF->text; $All{"LRBF"} = $self->histsLRBF->text;
my @Hists = split(/,/, $All{"LRBF"} ); my @Hists = split(/,/, $All{"LRBF"} );
# Lifetime corrections in enabled/visible only for SingleHis fits # Lifetime corrections in enabled/visible only for SingleHis fits
if ( $All{"FitAsyType"} eq "SingleHist" ) { if ( $All{"FitAsyType"} eq "SingleHist" ) {
this->{ui}->ltc->setHidden(0); $self->ltc->setHidden(0);
$All{"fittype"}=0; $All{"fittype"}=0;
} else { } else {
this->{ui}->ltc->setHidden(1); $self->ltc->setHidden(1);
$All{"fittype"}=2; $All{"fittype"}=2;
} }
# From Fitting Tab # From Fitting Tab
# Plot range # Plot range
$All{"Xi"}=this->{ui}->xi->text; $All{"Xi"}=$self->xi->text;
$All{"Xf"}=this->{ui}->xf->text; $All{"Xf"}=$self->xf->text;
$All{"Yi"}=this->{ui}->yi->text; $All{"Yi"}=$self->yi->text;
$All{"Yf"}=this->{ui}->yf->text; $All{"Yf"}=$self->yf->text;
$All{"ViewBin"}=this->{ui}->viewBin->text; $All{"ViewBin"}=$self->viewBin->text;
# Life time correction # Life time correction
if (this->{ui}->ltc->isChecked()) { if ($self->ltc->isChecked()) {
$All{"ltc"}="y"; $All{"ltc"}="y";
} else { } else {
$All{"ltc"}="n"; $All{"ltc"}="n";
@ -308,11 +353,11 @@ sub CreateAllInput()
$All{"go"}="PLOT"; $All{"go"}="PLOT";
} }
# Get minimization process # Get minimization process
$All{"Minimization"} = this->{ui}->minimization->currentText(); $All{"Minimization"} = $self->minimization->currentText();
$All{"go"}=$All{"Minimization"}; $All{"go"}=$All{"Minimization"};
# Get Error calculation process # Get Error calculation process
$All{"ErrorCalc"} = this->{ui}->errorCalc->currentText(); $All{"ErrorCalc"} = $self->errorCalc->currentText();
$All{"go"}=$All{"ErrorCalc"}; $All{"go"}=$All{"ErrorCalc"};
# Commands block # Commands block
@ -328,23 +373,23 @@ sub CreateAllInput()
} }
# From MSR File Tab # From MSR File Tab
$All{"TITLE"}= this->{ui}->title->text; $All{"TITLE"}= $self->title->text;
$All{"FILENAME"}= this->{ui}->fileName->text; $All{"FILENAME"}= $self->fileName->text;
# From Fourier Tab # From Fourier Tab
$All{"FUNITS"}= this->{ui}->funits->currentText; $All{"FUNITS"}= $self->funits->currentText;
$All{"FAPODIZATION"}= this->{ui}->fapodization->currentText; $All{"FAPODIZATION"}= $self->fapodization->currentText;
$All{"FPLOT"}= this->{ui}->fplot->currentText; $All{"FPLOT"}= $self->fplot->currentText;
$All{"FPHASE"}=this->{ui}->fphase->text; $All{"FPHASE"}=$self->fphase->text;
# Fourier range # Fourier range
$All{"FrqMin"}=this->{ui}->frqMin->text; $All{"FrqMin"}=$self->frqMin->text;
$All{"FrqMax"}=this->{ui}->frqMax->text; $All{"FrqMax"}=$self->frqMax->text;
# Rotating reference frame parameters # Rotating reference frame parameters
$All{"RRFFrq"}=this->{ui}->rrfFrq->text; $All{"RRFFrq"}=$self->rrfFrq->text;
$All{"RRFPack"}=this->{ui}->rrfPack->text; $All{"RRFPack"}=$self->rrfPack->text;
$All{"RRFPhase"}=this->{ui}->rrfPhase->text; $All{"RRFPhase"}=$self->rrfPhase->text;
$All{"RRFUnits"}=this->{ui}->rrfUnits->currentText; $All{"RRFUnits"}=$self->rrfUnits->currentText;
# Get values of t0 and Bg/Data bins if given # Get values of t0 and Bg/Data bins if given
my $NHist = 1; my $NHist = 1;
@ -383,17 +428,35 @@ sub CreateAllInput()
18,"None" 18,"None"
); );
my $FT1=this->{ui}->fitType1->currentIndex; # Check the number of components
my $FT2=this->{ui}->fitType2->currentIndex; my $numComps = 0;
my $FT3=this->{ui}->fitType3->currentIndex; my $FT1=0;
$All{"FitType1"} = $FTs{$FT1}; my $FT2=0;
$All{"FitType2"} = $FTs{$FT2}; my $FT3=0;
$All{"FitType3"} = $FTs{$FT3};
my @FitTypes =(); my @FitTypes =();
my $FitType=""; my $FT=0;
foreach $FitType ($All{"FitType1"}, $All{"FitType2"}, $All{"FitType3"}) { if (defined($self->numComps)) {
if ( $FitType ne "None" ) { # new style, check the number of components
push( @FitTypes, $FitType ); $numComps = $self->numComps->value;
if ($numComps != $self->columnView->count() ) {
addFitType();
}
} else {
# old style, only 3 componenets
$numComps = 3;
}
$All{"numComps"}=$numComps;
# loop over fitTypes
for (my $i=1;$i<=$numComps;$i++) {
my $FTi=child("Qt::ComboBox","fitType$i");
if ($FTi == 0) {
$All{"FitType$i"} = "None";
} else {
$All{"FitType$i"} = $FTs{$FTi->currentIndex};
}
if ( $All{"FitType$i"} ne "None" ) {
push( @FitTypes, $All{"FitType$i"} );
} }
} }
@ -404,17 +467,20 @@ sub CreateAllInput()
my @Paramcomp = @$Paramcomp_ref; my @Paramcomp = @$Paramcomp_ref;
# Functions block # Functions block
$All{"FunctionsBlock"}=this->{ui}->functionsBlock->toPlainText; $All{"FunctionsBlock"}=$self->functionsBlock->toPlainText;
# and the associated theory block # and the associated theory block
$All{"Func_T_Block"}=this->{ui}->theoryBlock->toPlainText; $All{"Func_T_Block"}=$self->theoryBlock->toPlainText;
# Shared settings are detected here # Shared settings are detected here
$All{"EnableSharing"} = this->{ui}->buttonGroupSharing->isChecked(); $All{"EnableSharing"} = $self->buttonGroupSharing->isChecked();
# Make sure all sharing boxes exist
#addSharingComp();
my $Shared = 0; my $Shared = 0;
my $PCount =0; my $PCount =0;
my $Component=1; my $Component=1;
foreach $FitType (@FitTypes) { foreach my $FitType (@FitTypes) {
my $Parameters=$Paramcomp[$Component-1]; my $Parameters=$Paramcomp[$Component-1];
my @Params = split( /\s+/, $Parameters ); my @Params = split( /\s+/, $Parameters );
@ -457,10 +523,9 @@ sub CreateAllInput()
# check if it is checked # check if it is checked
my $ChkName="shParam_".$Component."_".$NP; my $ChkName="shParam_".$Component."_".$NP;
my $ChkBx = child("Qt::Widget",$ChkName); my $ChkBx = child("Qt::Widget",$ChkName);
$Shared = $ChkBx->isChecked(); if ($ChkBx != 0) {$Shared = $ChkBx->isChecked();}
} }
$All{"Sh_$Param"}=$Shared; $All{"Sh_$Param"}=$Shared;
print "Param $Param is $Shared\n";
$NP++; $NP++;
} }
#Loop on parameters #Loop on parameters
@ -492,7 +557,7 @@ sub CreateAllInput()
my $erradd = "d"; my $erradd = "d";
my $minadd = "_min"; my $minadd = "_min";
my $maxadd = "_max"; my $maxadd = "_max";
my $QTable=this->{ui}->initParamTable; my $QTable=$self->initParamTable;
# TODO: Should not go over all rows, only on parameters. # TODO: Should not go over all rows, only on parameters.
if ($NParam > 0) { if ($NParam > 0) {
# Set appropriate number of rows # Set appropriate number of rows
@ -516,20 +581,15 @@ sub CreateAllInput()
sub CallMSRCreate() sub CallMSRCreate()
{ {
use MSR;
my %All=CreateAllInput();
# Check if the option for checking for existing files is selected # Check if the option for checking for existing files is selected
my $FileExistCheck= this->{ui}->fileExistCheck->isChecked(); my $FileExistCheck= $self->fileExistCheck->isChecked();
my $FILENAME=$All{"FILENAME"}.".msr"; my $FILENAME=$All{"FILENAME"}.".msr";
my $Answer=0; my $Answer=0;
if ($All{"RunNumbers"} ne "" || $All{"RunFiles"} ne "") { if ($All{"RunNumbers"} ne "" || $All{"RunFiles"} ne "") {
if ( $FileExistCheck==1 ) { if ( $FileExistCheck==1 ) {
if (-e $FILENAME) { if (-e $FILENAME) {
# Warning: MSR file exists # Warning: MSR file exists
# my $Warning = "Warning: MSR file $FILENAME Already exists!\nIf you continue it will overwriten.";
my $Warning = "Warning: MSR file $FILENAME Already exists!\nDo you want to overwrite it?"; my $Warning = "Warning: MSR file $FILENAME Already exists!\nDo you want to overwrite it?";
# my $WarningWindow = Qt::MessageBox::information( this, "Warning",$Warning);
# $Answer =1,0 for yes and no # $Answer =1,0 for yes and no
$Answer= Qt::MessageBox::warning( this, "Warning",$Warning, "&No", "&Yes", undef, 1,1); $Answer= Qt::MessageBox::warning( this, "Warning",$Warning, "&No", "&Yes", undef, 1,1);
} }
@ -567,22 +627,24 @@ sub CallMSRCreate()
my $NewRunLine = "runs ".join(" ",(1...$NSpectra)); my $NewRunLine = "runs ".join(" ",(1...$NSpectra));
# Use msr2data to generate global fit MSR file # Use msr2data to generate global fit MSR file
my $RunList = join(" ",@RUNS); my $RunList = join(" ",@RUNS);
my $cmd = "msr2data \[".$RunList."\] "." _tmpl msr-".$RUNS[0]." global"; my $StupidName = $RUNS[0]."+global_tmpl.msr";
# create the global file my $cmd = "cp $RUNS[0]_tmpl.msr $StupidName";
#if ($#RUNS != 0) {
# For multiple runs create global file
$cmd = "msr2data \[".$RunList."\] "." _tmpl msr-".$RUNS[0]." global";
#}
print $cmd."\n"; print $cmd."\n";
my $pid = open(FTO,"$cmd 2>&1 |"); my $pid = open(FTO,"$cmd 2>&1 |");
while (<FTO>) { while (<FTO>) {
this->{ui}->fitTextOutput->append("$_"); $self->fitTextOutput->append("$_");
} }
close(FTO); close(FTO);
# change the stupid name # change the stupid name
my $StupidName = $RUNS[0]."+global_tmpl.msr";
# change stupid default runs line # change stupid default runs line
$cmd = "cp $StupidName $FILENAME; perl -pi -e 's/runs.*?(?=\n)/$NewRunLine/s' $FILENAME"; $cmd = "cp $StupidName $FILENAME; perl -pi -e 's/runs.*?(?=\n)/$NewRunLine/s' $FILENAME";
$pid = open(FTO,"$cmd 2>&1 |"); $pid = open(FTO,"$cmd 2>&1 |");
print $cmd."\n";
while (<FTO>) { while (<FTO>) {
this->{ui}->fitTextOutput->append("$_"); $self->fitTextOutput->append("$_");
} }
close(FTO); close(FTO);
# feed in values of parameters if they exist # feed in values of parameters if they exist
@ -619,7 +681,6 @@ sub CallMSRCreate()
sub UpdateMSRFileInitTable() sub UpdateMSRFileInitTable()
{ {
my %All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}; my $FILENAME=$All{"FILENAME"};
my @lines=(); my @lines=();
if (-e "$FILENAME.msr") { if (-e "$FILENAME.msr") {
@ -627,9 +688,9 @@ sub UpdateMSRFileInitTable()
@lines = <MSRF>; @lines = <MSRF>;
close(MSRF); close(MSRF);
} }
this->{ui}->textMSROutput->setText(""); $self->textMSROutput->setText("");
foreach my $line (@lines) { foreach my $line (@lines) {
this->{ui}->textMSROutput->insertPlainText("$line"); $self->textMSROutput->insertPlainText("$line");
} }
(my $TBlock_ref, my $FPBlock_ref)=MSR::ExtractBlks(@lines); (my $TBlock_ref, my $FPBlock_ref)=MSR::ExtractBlks(@lines);
@ -669,7 +730,7 @@ sub UpdateMSRFileInitTable()
$maxvalue=1.0*$Param[7]; $maxvalue=1.0*$Param[7];
} }
# Now update the initialization tabel # Now update the initialization tabel
my $QTable = this->{ui}->initParamTable; my $QTable = $self->initParamTable;
# print "PCount=$PCount and value=$value\n"; # print "PCount=$PCount and value=$value\n";
if (defined($QTable->item($PCount,0)) & defined($QTable->item($PCount,1)) & defined($QTable->item($PCount,2)) & defined($QTable->item($PCount,3))) { if (defined($QTable->item($PCount,0)) & defined($QTable->item($PCount,1)) & defined($QTable->item($PCount,2)) & defined($QTable->item($PCount,3))) {
$QTable->setItem($PCount,0,Qt::TableWidgetItem()); $QTable->setItem($PCount,0,Qt::TableWidgetItem());
@ -691,7 +752,7 @@ sub UpdateMSRFileInitTable()
sub ActivateT0Hists() sub ActivateT0Hists()
{ {
my %All=CreateAllInput(); $All{"LRBF"}=$self->histsLRBF->text;
my @Hists = split(/,/, $All{"LRBF"} ); my @Hists = split(/,/, $All{"LRBF"} );
my $HistBox = ""; my $HistBox = "";
for (my $iHist=1; $iHist<=4; $iHist++) { for (my $iHist=1; $iHist<=4; $iHist++) {
@ -715,22 +776,28 @@ sub ActivateT0Hists()
sub ActivateShComp() sub ActivateShComp()
{ {
my %All=CreateAllInput(); # Update All from GUI
%All=CreateAllInput();
my @RUNS = split( /,/, MSR::ExpandRunNumbers($All{"RunNumbers"}) ); my @RUNS = split( /,/, MSR::ExpandRunNumbers($All{"RunNumbers"}) );
my @Hists = split( /,/, $All{"LRBF"} ); my @Hists = split( /,/, $All{"LRBF"} );
# Make sure all sharing boxes exist
addSharingComp();
my $NShComps = $self->horizontalLayout->count();
my $sharingComp = "";
my $i = 1;
# Hide all sharing components # Hide all sharing components
this->{ui}->sharingComp1->setHidden(1); for ($i = 1; $i<=$NShComps;$i++) {
this->{ui}->sharingComp2->setHidden(1); $sharingComp = child("Qt::GroupBox","sharingComp$i");
this->{ui}->sharingComp3->setHidden(1); $sharingComp->setHidden(1);
this->{ui}->sharingComp1->setEnabled(0); $sharingComp->setEnabled(0);
this->{ui}->sharingComp2->setEnabled(0); }
this->{ui}->sharingComp3->setEnabled(0);
my @FitTypes =(); my @FitTypes =();
foreach my $FitType ($All{"FitType1"}, $All{"FitType2"}, $All{"FitType3"}) { for ($i=1;$i<=$All{"numComps"};$i++) {
if ( $FitType ne "None" ) { if ( $All{"FitType$i"} ne "None" ) {
push( @FitTypes, $FitType ); push( @FitTypes, $All{"FitType$i"} );
} }
} }
@ -780,7 +847,7 @@ sub ActivateShComp()
$CompShL->setText($All{"FitType$Component"}); $CompShL->setText($All{"FitType$Component"});
# Change state/label of parameters # Change state/label of parameters
for (my $i=1; $i<=9;$i++) { for ($i=1; $i<=9;$i++) {
my $ParamChkBx="shParam_".$Component."_".$i; my $ParamChkBx="shParam_".$Component."_".$i;
my $ChkBx = child("Qt::Widget",$ParamChkBx); my $ChkBx = child("Qt::Widget",$ParamChkBx);
if (defined($Params[$i-1])) { if (defined($Params[$i-1])) {
@ -798,8 +865,9 @@ sub ActivateShComp()
sub InitializeTab() sub InitializeTab()
{ {
my %All=CreateAllInput(); # Update All values from GUI
my $QTable = this->{ui}->initParamTable; %All=CreateAllInput();
my $QTable = $self->initParamTable;
my $NRows = $QTable->rowCount(); my $NRows = $QTable->rowCount();
# Remove any rows in table # Remove any rows in table
@ -846,30 +914,29 @@ sub InitializeTab()
sub TabChanged() sub TabChanged()
{ {
# TODO: First check if there are some runs given, otherwise disbale # TODO: First check if there are some runs given, otherwise disbale
my %All=CreateAllInput(); my $curTab = $self->musrfit_tabs->currentIndex();
my $curTab = this->{ui}->musrfit_tabs->currentIndex();
if ($curTab >= 2 && $curTab <= 4) { if ($curTab >= 2 && $curTab <= 4) {
# First make sure we have sharing initialized # First make sure we have sharing initialized
ActivateShComp(); ActivateShComp();
# Here we need to apply sharing if selected... # Here we need to apply sharing if selected...
InitializeTab(); InitializeTab();
UpdateMSRFileInitTable(); UpdateMSRFileInitTable();
} elsif ($curTab == 7) { } elsif ($curTab == 6) {
# And also setup T0 and Bg bins # And also setup T0 and Bg bins
ActivateT0Hists(); ActivateT0Hists();
} } elsif ($curTab == 7) {
# Initialize FUNCTIONS block only if it has not been initialized yet # Initialize FUNCTIONS block only if it has not been initialized yet
if ($All{"Func_T_Block"} eq "" ) { if ($All{"FunctionsBlock"} eq "" ) {
InitializeFunctions(); InitializeFunctions();
} }
} }
}
sub GoFit() sub GoFit()
{ {
# This function should be able to do both plot and fit, check who called you. # This function should be able to do both plot and fit, check who called you.
my %All=CreateAllInput(); %All=CreateAllInput();
# Check here is the number of histograms makes sense # Check here is the number of histograms makes sense
# other wise give error. # other wise give error.
my @Hists = split( /,/, $All{"LRBF"} ); my @Hists = split( /,/, $All{"LRBF"} );
@ -878,7 +945,7 @@ sub GoFit()
my $Warning = "Error: The number of histograms should be 2 for an asymmetry fit!"; my $Warning = "Error: The number of histograms should be 2 for an asymmetry fit!";
my $WarningWindow = Qt::MessageBox::information( this, "Error",$Warning); my $WarningWindow = Qt::MessageBox::information( this, "Error",$Warning);
} else { } else {
this->{ui}->musrfit_tabs->setCurrentIndex(1); $self->musrfit_tabs->setCurrentIndex(1);
my $Answer=CallMSRCreate(); my $Answer=CallMSRCreate();
my $FILENAME=$All{"FILENAME"}.".msr"; my $FILENAME=$All{"FILENAME"}.".msr";
if ($Answer) { if ($Answer) {
@ -886,13 +953,13 @@ sub GoFit()
my $cmd="musrfit -t $FILENAME; musrview $FILENAME &"; my $cmd="musrfit -t $FILENAME; musrview $FILENAME &";
my $pid = open(FTO,"$cmd 2>&1 |"); my $pid = open(FTO,"$cmd 2>&1 |");
while (<FTO>) { while (<FTO>) {
this->{ui}->fitTextOutput->insertPlainText("$_"); $self->fitTextOutput->insertPlainText("$_");
} }
close(FTO); close(FTO);
} else { } else {
this->{ui}->fitTextOutput->insertPlainText("Cannot find MSR file!"); $self->fitTextOutput->insertPlainText("Cannot find MSR file!");
} }
this->{ui}->fitTextOutput->insertPlainText("-----------------------------------------------------------------------------------------------------------------------------"); $self->fitTextOutput->insertPlainText("-----------------------------------------------------------------------------------------------------------------------------");
# update MSR File tab and initialization table # update MSR File tab and initialization table
UpdateMSRFileInitTable(); UpdateMSRFileInitTable();
} }
@ -903,7 +970,7 @@ sub GoFit()
sub GoPlot() sub GoPlot()
{ {
# This function should be able to do both plot and fit, check who called you. # This function should be able to do both plot and fit, check who called you.
my %All=CreateAllInput(); %All=CreateAllInput();
# Check here is the number of histograms makes sense # Check here is the number of histograms makes sense
# other wise give error. # other wise give error.
my @Hists = split( /,/, $All{"LRBF"} ); my @Hists = split( /,/, $All{"LRBF"} );
@ -919,8 +986,8 @@ sub GoPlot()
my $cmd="musrview $FILENAME &"; my $cmd="musrview $FILENAME &";
my $pid = system($cmd); my $pid = system($cmd);
} else { } else {
this->{ui}->fitTextOutput->insertPlainText("Cannot find MSR file!"); $self->fitTextOutput->insertPlainText("Cannot find MSR file!");
this->{ui}->fitTextOutput->insertPlainText("-----------------------------------------------------------------------------------------------------------------------------"); $self->fitTextOutput->insertPlainText("-----------------------------------------------------------------------------------------------------------------------------");
} }
} }
} }
@ -931,8 +998,7 @@ sub GoPlot()
sub ShowMuSRT0() sub ShowMuSRT0()
{ {
# Open musrt0 to check and adjust t0 , Bg and Data bins # Open musrt0 to check and adjust t0 , Bg and Data bins
my %All=CreateAllInput(); $self->musrfit_tabs->setCurrentIndex(6);
this->{ui}->musrfit_tabs->setCurrentIndex(6);
# Create MSR file and then run musrt0 # Create MSR file and then run musrt0
my $Answer=CallMSRCreate(); my $Answer=CallMSRCreate();
@ -941,7 +1007,7 @@ sub ShowMuSRT0()
if (-e $FILENAME) { if (-e $FILENAME) {
my $cmd="musrt0 $FILENAME &"; my $cmd="musrt0 $FILENAME &";
my $pid = system($cmd); my $pid = system($cmd);
this->{ui}->t0Update->setEnabled(1) $self->t0Update->setEnabled(1)
} else { } else {
print STDERR "Cannot find MSR file!\n"; print STDERR "Cannot find MSR file!\n";
} }
@ -952,7 +1018,7 @@ sub ShowMuSRT0()
sub t0Update() sub t0Update()
{ {
my %All = CreateAllInput(); $All{"LRBF"}=$self->histsLRBF->text;
my @Hists = split(/,/, $All{"LRBF"} ); my @Hists = split(/,/, $All{"LRBF"} );
# Get values of t0 and Bg/Data bins if given # Get values of t0 and Bg/Data bins if given
@ -961,9 +1027,6 @@ sub t0Update()
foreach ("t0","Bg1","Bg2","Data1","Data2") { foreach ("t0","Bg1","Bg2","Data1","Data2") {
my $Name = "$_$NHist"; my $Name = "$_$NHist";
my $tmp=MSR::T0BgData($_,$Hist,$All{"BeamLine"}); my $tmp=MSR::T0BgData($_,$Hist,$All{"BeamLine"});
# if (defined(child("Qt::Widget",$Name))) {
# child("Qt::Widget",$Name)->setText($tmp);
# }
} }
$NHist++ $NHist++
} }
@ -972,29 +1035,28 @@ sub t0Update()
sub RunSelectionToggle() sub RunSelectionToggle()
{ {
my $ManualFile= this->{ui}->manualFile->isChecked(); my $ManualFile= $self->manualFile->isChecked();
if ($ManualFile) { if ($ManualFile) {
# Manual RUN selection # Manual RUN selection
this->{ui}->runsMan->setEnabled(1); $self->runsMan->setEnabled(1);
this->{ui}->runsMan->setHidden(0); $self->runsMan->setHidden(0);
this->{ui}->runNumbers->setText(""); $self->runNumbers->setText("");
this->{ui}->runsAuto->setEnabled(0); $self->runsAuto->setEnabled(0);
this->{ui}->runsAuto->setHidden(1); $self->runsAuto->setHidden(1);
} else { } else {
# Auto RUN selection # Auto RUN selection
this->{ui}->runsMan->setEnabled(0); $self->runsMan->setEnabled(0);
this->{ui}->runsMan->setHidden(1); $self->runsMan->setHidden(1);
this->{ui}->runFiles->setText(""); $self->runFiles->setText("");
this->{ui}->runsAuto->setEnabled(1); $self->runsAuto->setEnabled(1);
this->{ui}->runsAuto->setHidden(0); $self->runsAuto->setHidden(0);
} }
} }
sub fileBrowse() sub fileBrowse()
{ {
my $RunFiles=this->{ui}->runFiles->text(); my $RunFiles=$self->runFiles->text();
print "Runs:$RunFiles\n";
my $files_ref=Qt::FileDialog::getOpenFileNames( my $files_ref=Qt::FileDialog::getOpenFileNames(
"Data files (*.root *.bin)", "Data files (*.root *.bin)",
"./", "./",
@ -1009,45 +1071,45 @@ sub fileBrowse()
# Add files to existing list # Add files to existing list
$RunFiles=join(",",$RunFiles,@files); $RunFiles=join(",",$RunFiles,@files);
} }
this->{ui}->runFiles->setText($RunFiles); $self->runFiles->setText($RunFiles);
} }
sub AppendToFunctions() sub AppendToFunctions()
{ {
my $ParName=this->{ui}->cParamsCombo->currentText(); my $ParName=$self->cParamsCombo->currentText();
my $Full_T_Block=""; my $Full_T_Block="";
my $Constraint=""; my $Constraint="";
if (defined(this->{ui}->theoryBlock->toPlainText)) { if (defined($self->theoryBlock->toPlainText)) {
$Full_T_Block=this->{ui}->theoryBlock->toPlainText; $Full_T_Block=$self->theoryBlock->toPlainText;
} }
if (defined(this->{ui}->constraintLine->text)) { if (defined($self->constraintLine->text)) {
$Constraint=this->{ui}->constraintLine->text; $Constraint=$self->constraintLine->text;
} }
# Then clear the text # Then clear the text
this->{ui}->constraintLine->setText(""); $self->constraintLine->setText("");
# Check how many constraints (lines) in FUNCTIONS Block # Check how many constraints (lines) in FUNCTIONS Block
# my $i=this->{ui}->functionsBlock->blockCount(); # my $i=$self->functionsBlock->blockCount();
my $fun_lines=this->{ui}->functionsBlock->toPlainText(); my $fun_lines=$self->functionsBlock->toPlainText();
my $i= ($fun_lines =~ tr/\n//)+1; my $i= ($fun_lines =~ tr/\n//)+1;
my $ConstLine="fun$i = $Constraint\n"; my $ConstLine="fun$i = $Constraint\n";
this->{ui}->functionsBlock->insertPlainText($ConstLine); $self->functionsBlock->insertPlainText($ConstLine);
# Replace parameter in theory block with fun$i # Replace parameter in theory block with fun$i
$Full_T_Block=~ s/$ParName/fun$i/; $Full_T_Block=~ s/$ParName/fun$i/;
this->{ui}->theoryBlock->setText($Full_T_Block); $self->theoryBlock->setText($Full_T_Block);
} }
sub InitializeFunctions() sub InitializeFunctions()
{ {
my %All=CreateAllInput(); # Update All values from GUI
%All=CreateAllInput();
my @RUNS = split( /,/, MSR::ExpandRunNumbers($All{"RunNumbers"}) ); my @RUNS = split( /,/, MSR::ExpandRunNumbers($All{"RunNumbers"}) );
my @Hists = split( /,/, $All{"LRBF"} ); my @Hists = split( /,/, $All{"LRBF"} );
my @FitTypes =(); my @FitTypes =();
foreach my $FitType ($All{"FitType1"}, $All{"FitType2"}, $All{"FitType3"}) { for (my $i=1;$i<=$All{"numComps"};$i++) {
if ( $FitType ne "None" ) { if ( $All{"FitType$i"} ne "None" ) {
push( @FitTypes, $FitType ); push( @FitTypes, $All{"FitType$i"} );
} }
} }
@ -1058,10 +1120,10 @@ sub InitializeFunctions()
# Initialize Parameters List in function block (constraints). # Initialize Parameters List in function block (constraints).
my $ParametersList=""; my $ParametersList="";
this->{ui}->parametersList->setText(""); $self->parametersList->setText("");
# Counter for function block (with out Alpha etc.) # Counter for function block (with out Alpha etc.)
my $ParCount=0; my $ParCount=0;
this->{ui}->cParamsCombo->clear(); $self->cParamsCombo->clear();
# Possibly use the parameters block to axtract names for the dropdown menu # Possibly use the parameters block to axtract names for the dropdown menu
# this makes sense if we can use fun in map line. Check! # this makes sense if we can use fun in map line. Check!
@ -1094,22 +1156,22 @@ sub InitializeFunctions()
if (defined($Params[$i-1])) { if (defined($Params[$i-1])) {
my $CParam = $Params[$i-1]."_".$Component; my $CParam = $Params[$i-1]."_".$Component;
if ($Params[$i-1] ne "Alpha" && $Params[$i-1] ne "No" && $Params[$i-1] ne "NBg") { if ($Params[$i-1] ne "Alpha" && $Params[$i-1] ne "No" && $Params[$i-1] ne "NBg") {
this->{ui}->cParamsCombo->addItem($CParam); $self->cParamsCombo->addItem($CParam);
$Full_T_Block=~ s/\b$Params[$i-1]\b/$CParam/; $Full_T_Block=~ s/\b$Params[$i-1]\b/$CParam/;
} }
# also enumerate the parameters as should be used in the FUNCTIONS Block # also enumerate the parameters as should be used in the FUNCTIONS Block
$ParCount++; $ParCount++;
$ParametersList=$ParametersList."$CParam \t is \t par$ParCount\n"; $ParametersList=$ParametersList."$CParam \t is \t par$ParCount\n";
this->{ui}->parametersList->setText($ParametersList); $self->parametersList->setText($ParametersList);
} }
} }
$Component++; $Component++;
} }
# Set theory block in Constraints # Set theory block in Constraints
this->{ui}->theoryBlock->setText($Full_T_Block); $self->theoryBlock->setText($Full_T_Block);
# Then clear the text # Then clear the text
this->{ui}->constraintLine->setText(""); $self->constraintLine->setText("");
this->{ui}->functionsBlock->setText(""); $self->functionsBlock->setText("");
} }
@ -1118,7 +1180,7 @@ sub InitializeFunctions()
sub t0UpdateClicked() sub t0UpdateClicked()
{ {
# Read MSR file and get new values of t0,Bg and Data # Read MSR file and get new values of t0,Bg and Data
my %All=CreateAllInput(); #%All=CreateAllInput();
my $FILENAME=$All{"FILENAME"}; my $FILENAME=$All{"FILENAME"};
open (MSRF,q{<},"$FILENAME.msr" ); open (MSRF,q{<},"$FILENAME.msr" );
my @lines = <MSRF>; my @lines = <MSRF>;
@ -1130,7 +1192,6 @@ sub t0UpdateClicked()
my @Hists = split(/,/, $All{"LRBF"} ); my @Hists = split(/,/, $All{"LRBF"} );
my $NHist = $#Hists+1; my $NHist = $#Hists+1;
print "Histograms: $NHist\n";
my $FinHist = 1; my $FinHist = 1;
# First T0s # First T0s
@ -1149,7 +1210,7 @@ sub t0UpdateClicked()
} }
# Finally, disable the update button # Finally, disable the update button
this->{ui}->t0Update->setEnabled(0); $self->t0Update->setEnabled(0);
# t0Update->setText("musrt0") # t0Update->setText("musrt0")
} }
@ -1164,11 +1225,123 @@ sub child {
} else { } else {
$Attrib = 0; $Attrib = 0;
} }
# print "name = $name and attrib = $Attrib\n";
# Return handle on widget # Return handle on widget
return($Attrib); return($Attrib);
} }
sub addFitType {
# Input number of components
my $numComps = $self->numComps->value;
# count number of exisitng components
my $NButtons = $self->columnView->count();
# create ComboBox in theoryFunction parent
my $fitType = Qt::ComboBox( $self->theoryFunction );
# do we have less components that we need
if ($numComps > $NButtons) {
# add as needed
for (my $i=$NButtons+1;$i<=$numComps;$i++) {
my $nameComp = "fitType$i";
$self->columnView->addWidget( $fitType );
$fitType->setObjectName( $nameComp );
$fitType->setMinimumSize( Qt::Size(0, 25) );
$fitType->setMaximumSize( Qt::Size(255, 25) );
$fitType->insertItems(0,
["Exponential",
"Gaussian",
"Stretch Exp.",
"Exponential Cos",
"Gaussian Cos",
"Stretch Cos",
"Lorentzian Dynamic KT",
"Gaussian Dynamic KT",
"Background",
"Lorentzian Kubo-Toyabe LF x Exp",
"Gaussian Kubo-Toyabe LF x Exp",
"Lorentzian Kubo-Toyabe LF x Str Exp",
"Gaussian Kubo-Toyabe LF x Str Exp",
"MolMag",
"Meissner State Model",
"Lor-Gss combi KT",
"Lor-Gss combi KT x Exp",
"Lor-Gss combi KT x SExp",
"None",]);
if ($i==1) {
$fitType->setCurrentIndex(0);
# remove the "None" option for the 1st component
$fitType->removeItem(18);
} else {
$fitType->setCurrentIndex( 18 );
}
}
} else {
for (my $i=$NButtons;$i > $numComps ;$i--) {
# component is there, delete it
my $widget = $self->columnView->itemAt($i-1)->widget();
$widget -> hide();
$self->columnView->removeWidget($widget);
undef $widget;
}
}
}
sub addSharingComp {
# Input number of components
my $numComps = $self->numComps->value;
# count number of exisitng components
my $NShComps = $self->horizontalLayout->count();
my @sharingComps = ();
for (my $i=$NShComps+1;$i<=$numComps;$i++) {
$sharingComps[$i] = Qt::GroupBox( $self->buttonGroupSharing );
my $sizePolicy = Qt::SizePolicy( Qt::SizePolicy::Expanding(), Qt::SizePolicy::MinimumExpanding() );
$self->{$sizePolicy} = $sizePolicy;
$sizePolicy->setHorizontalStretch( 0 );
$sizePolicy->setVerticalStretch( 0 );
$sizePolicy->setHeightForWidth( $sharingComps[$i]->sizePolicy()->hasHeightForWidth() );
# check is this component exists
if (child("Qt::GroupBox","sharingComp$i") == 0) {
$sharingComps[$i]->setObjectName( "sharingComp$i" );
$sharingComps[$i]->setEnabled( 0 );
$sharingComps[$i]->setSizePolicy( $sizePolicy );
$sharingComps[$i]->setAlignment( Qt::AlignLeading() );
$sharingComps[$i]->setTitle("Component $i");
my $layout = Qt::Widget( $sharingComps[$i] );
$layout->setObjectName( "layoutSh$i" );
$layout->setGeometry( Qt::Rect(40, 60, 81, 266) );
my $shBoxLayout = Qt::VBoxLayout( $layout );
$self->{shBoxLayout} = $shBoxLayout;
$shBoxLayout->setSpacing( 0 );
$shBoxLayout->setMargin( 0 );
$shBoxLayout->setObjectName( "shBoxLayout$i" );
$shBoxLayout->setContentsMargins(0, 0, 0, 0 );
my @shParam = ();
for (my $j=1;$j<=9;$j++) {
$shParam[$j] = Qt::CheckBox( $layout );
$self->{shParam} = $shParam[$j];
$shParam[$j]->setObjectName( "shParam_".$i."_$j" );
$shParam[$j]->setText("Param$j");
$shBoxLayout->addWidget( $shParam[$j] );
}
my $compShLabel = Qt::Label( $sharingComps[$i] );
$self->{compShLabel} = $compShLabel;
$compShLabel->setObjectName( "comp".$i."ShLabel" );
$compShLabel->setGeometry( Qt::Rect(2, 30, 141, 20) );
$compShLabel->setWordWrap( 0 );
$self->horizontalLayout->addWidget( $sharingComps[$i] );
# Connect slot
Qt::Object::connect($sharingComps[$i], SIGNAL 'currentIndexChanged()' , $self, SLOT 'InitializeFunctions()' );
$compShLabel->setText("FitType$i");
} else {
print "Exists, skip component $i\n";
}
}
}
sub runsLineNotEmpy()
{
}
1; 1;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff