Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
Takin
mag-core
Commits
25542386
Commit
25542386
authored
Jul 12, 2018
by
Tobias WEBER
Browse files
data normalisation
parent
277e7299
Changes
7
Hide whitespace changes
Inline
Side-by-side
tools/cli/funcs.cpp
View file @
25542386
...
...
@@ -549,6 +549,23 @@ std::shared_ptr<Symbol> func_add_pointwise(CliParserContext & ctx, const std::ve
return
symRet
;
}
/**
* normalise dataset to monitor counter
*/
std
::
shared_ptr
<
Symbol
>
func_normtomon
(
CliParserContext
&
ctx
,
std
::
shared_ptr
<
Symbol
>
arg
)
{
if
(
!
arg
||
arg
->
GetType
()
!=
SymbolType
::
DATASET
)
{
ctx
.
PrintError
(
"Expected a data set."
);
return
nullptr
;
}
const
auto
&
dat
=
dynamic_cast
<
const
SymbolDataset
&>
(
*
arg
);
return
std
::
make_shared
<
SymbolDataset
>
(
dat
.
GetValue
().
norm
(
0
));
}
// ----------------------------------------------------------------------------
...
...
@@ -668,6 +685,8 @@ std::unordered_map<std::string, std::tuple<std::shared_ptr<Symbol>(*)
std
::
make_pair
(
"typeof"
,
std
::
make_tuple
(
&
func_typeof
,
"return symbol type"
)),
std
::
make_pair
(
"sizeof"
,
std
::
make_tuple
(
&
func_sizeof
,
"return symbol size"
)),
std
::
make_pair
(
"toarray"
,
std
::
make_tuple
(
&
func_array
,
"convert a dataset to an array"
)),
std
::
make_pair
(
"normtomon"
,
std
::
make_tuple
(
&
func_normtomon
,
"normalise data set to monitor counter"
)),
};
/**
...
...
tools/in20/command.cpp
View file @
25542386
...
...
@@ -198,6 +198,13 @@ void CommandLineWidget::CommandEntered()
// add successful commands to completer
UpdateCompleter
();
// save last result to workspace
if
(
auto
*
workspace
=
m_parsectx
.
GetWorkspace
();
workspace
)
{
workspace
->
insert_or_assign
(
"__last__"
,
sym
);
m_parsectx
.
EmitWorkspaceUpdated
(
"__last__"
);
}
}
else
{
...
...
tools/in20/data.cpp
View file @
25542386
...
...
@@ -99,7 +99,7 @@ std::tuple<bool, Dataset> Dataset::convert_instr_file(const char* pcFile)
{
std
::
vector
<
t_real
>
thedat
,
theerr
;
copy_interleave
(
filedata
[
idx
].
begin
(),
filedata
[
idx
].
end
(),
std
::
back_inserter
(
thedat
),
numpolstates
,
polstate
);
std
::
transform
(
fil
edat
a
[
idx
]
.
begin
(),
fil
edat
a
[
idx
]
.
end
(),
std
::
back_inserter
(
theerr
),
std
::
transform
(
th
edat
.
begin
(),
th
edat
.
end
(),
std
::
back_inserter
(
theerr
),
[](
t_real
y
)
->
t_real
{
if
(
tl
::
float_equal
<
t_real
>
(
y
,
0
))
...
...
@@ -116,7 +116,7 @@ std::tuple<bool, Dataset> Dataset::convert_instr_file(const char* pcFile)
{
std
::
vector
<
t_real
>
thedat
,
theerr
;
copy_interleave
(
filedata
[
idx
].
begin
(),
filedata
[
idx
].
end
(),
std
::
back_inserter
(
thedat
),
numpolstates
,
polstate
);
std
::
transform
(
fil
edat
a
[
idx
]
.
begin
(),
fil
edat
a
[
idx
]
.
end
(),
std
::
back_inserter
(
theerr
),
std
::
transform
(
th
edat
.
begin
(),
th
edat
.
end
(),
std
::
back_inserter
(
theerr
),
[](
t_real
y
)
->
t_real
{
if
(
tl
::
float_equal
<
t_real
>
(
y
,
0
))
...
...
@@ -407,6 +407,60 @@ Data operator /(const Data& dat1, t_real d)
return
dat1
*
t_real
(
1
)
/
d
;
}
/**
* normalise to monitor counter
*/
Data
Data
::
norm
(
std
::
size_t
monidx
)
const
{
if
(
GetNumCounters
()
!=
GetNumMonitors
())
{
print_err
(
"Number of monitors has to be equal to the number of detector counters."
);
return
*
this
;
}
if
(
monidx
>=
GetNumMonitors
())
{
print_err
(
"Invalid monitor selected."
);
return
*
this
;
}
Data
datret
=
*
this
;
// normalise all counters
for
(
std
::
size_t
detidx
=
0
;
detidx
<
GetNumCounters
();
++
detidx
)
{
const
auto
&
det
=
GetCounter
(
detidx
);
const
auto
&
deterr
=
GetCounterErrors
(
detidx
);
const
auto
&
mon
=
GetMonitor
(
monidx
);
const
auto
&
monerr
=
GetMonitorErrors
(
monidx
);
if
(
det
.
size
()
!=
deterr
.
size
()
||
det
.
size
()
!=
mon
.
size
()
||
det
.
size
()
!=
monerr
.
size
())
{
print_err
(
"Data, monitor and error columns have to be of equal size."
" [det="
,
det
.
size
(),
" deterr="
,
deterr
.
size
(),
" mon="
,
mon
.
size
(),
", monerr="
,
monerr
.
size
(),
"]"
);
return
*
this
;
}
// newcnts = cnts/mon
for
(
std
::
size_t
pt
=
0
;
pt
<
det
.
size
();
++
pt
)
{
datret
.
m_counts
[
detidx
][
pt
]
=
det
[
pt
]
/
mon
[
pt
];
datret
.
m_counts_err
[
detidx
][
pt
]
=
std
::
sqrt
(
std
::
pow
(
deterr
[
pt
]
/
mon
[
pt
],
2
)
+
std
::
pow
(
-
monerr
[
pt
]
*
det
[
pt
]
/
(
mon
[
pt
]
*
mon
[
pt
]),
2
));
}
}
// normalise monitor with itself
for
(
std
::
size_t
pt
=
0
;
pt
<
GetMonitor
(
monidx
).
size
();
++
pt
)
{
datret
.
m_monitors
[
monidx
][
pt
]
=
1.
;
datret
.
m_monitors_err
[
monidx
][
pt
]
=
0.
;
}
return
datret
;
}
// ----------------------------------------------------------------------------
...
...
@@ -535,4 +589,18 @@ Dataset operator -(const Dataset& dat1)
return
dataset
;
}
/**
* normalise to monitor counter
*/
Dataset
Dataset
::
norm
(
std
::
size_t
mon
)
const
{
Dataset
dataset
;
for
(
std
::
size_t
ch
=
0
;
ch
<
GetNumChannels
();
++
ch
)
dataset
.
AddChannel
(
GetChannel
(
ch
).
norm
());
return
dataset
;
}
// ----------------------------------------------------------------------------
tools/in20/data.h
View file @
25542386
...
...
@@ -96,6 +96,9 @@ public:
m_x_names
.
push_back
(
"ax"
+
std
::
to_string
(
GetNumAxes
()));
}
public:
Data
norm
(
std
::
size_t
mon
=
0
)
const
;
// binary operators
friend
Data
operator
+
(
const
Data
&
dat1
,
const
Data
&
dat2
);
...
...
@@ -111,6 +114,7 @@ public:
friend
const
Data
&
operator
+
(
const
Data
&
dat
);
friend
Data
operator
-
(
const
Data
&
dat
);
// different ways of uniting data containers
static
Data
add_pointwise
(
const
Data
&
dat1
,
const
Data
&
dat2
);
static
Data
append
(
const
Data
&
dat1
,
const
Data
&
dat2
);
...
...
@@ -132,6 +136,9 @@ public:
void
AddChannel
(
const
Data
&
data
)
{
m_data
.
push_back
(
data
);
}
void
AddChannel
(
Data
&&
data
)
{
m_data
.
emplace_back
(
std
::
move
(
data
));
}
public:
Dataset
norm
(
std
::
size_t
mon
=
0
)
const
;
// binary operators
friend
Dataset
operator
+
(
const
Dataset
&
dat1
,
const
Dataset
&
dat2
);
...
...
@@ -147,6 +154,7 @@ public:
friend
const
Dataset
&
operator
+
(
const
Dataset
&
dat
);
friend
Dataset
operator
-
(
const
Dataset
&
dat
);
// different ways of uniting data sets
static
Dataset
add_pointwise
(
const
Dataset
&
dat1
,
const
Dataset
&
dat2
);
static
Dataset
append
(
const
Dataset
&
dat1
,
const
Dataset
&
dat2
);
...
...
tools/in20/filebrowser.cpp
View file @
25542386
...
...
@@ -45,7 +45,10 @@ FileBrowserWidget::FileBrowserWidget(QWidget *pParent, QSettings *pSettings)
// ------------------------------------------------------------------------
// connections
connect
(
pBtnFolders
,
&
QPushButton
::
clicked
,
this
,
&
FileBrowserWidget
::
SelectFolder
);
connect
(
pCheckMultiSelect
,
&
QCheckBox
::
stateChanged
,
this
,
&
FileBrowserWidget
::
SetMultiSelect
);
connect
(
pCheckMultiSelect
,
&
QCheckBox
::
stateChanged
,
[
this
](
bool
checked
)
{
m_pListFiles
->
setSelectionMode
(
checked
?
QAbstractItemView
::
ExtendedSelection
:
QAbstractItemView
::
SingleSelection
);
});
connect
(
pBtnTransfer
,
&
QPushButton
::
clicked
,
this
,
&
FileBrowserWidget
::
TransferSelectedToWorkspace
);
connect
(
m_pEditFolder
,
&
QLineEdit
::
textChanged
,
this
,
&
FileBrowserWidget
::
SetFolder
);
connect
(
m_pListFiles
,
&
QListWidget
::
currentItemChanged
,
this
,
&
FileBrowserWidget
::
SetFile
);
...
...
@@ -163,12 +166,6 @@ void FileBrowserWidget::SetFile(QListWidgetItem* pCur)
}
void
FileBrowserWidget
::
SetMultiSelect
(
int
checked
)
{
bool
bMultiSel
=
checked
!=
0
;
m_pListFiles
->
setSelectionMode
(
bMultiSel
?
QAbstractItemView
::
MultiSelection
:
QAbstractItemView
::
SingleSelection
);
}
/**
* a file in the list was double-clicked
...
...
tools/in20/filebrowser.h
View file @
25542386
...
...
@@ -43,9 +43,7 @@ public:
protected:
void
SelectFolder
();
void
SetFolder
(
const
QString
&
str
);
void
SetFile
(
QListWidgetItem
*
pCur
);
void
SetMultiSelect
(
int
checked
);
void
FileDoubleClicked
(
QListWidgetItem
*
pItem
);
void
TransferSelectedToWorkspace
();
...
...
tools/in20/workspace.cpp
View file @
25542386
...
...
@@ -203,8 +203,9 @@ void WorkSpaceWidget::UpdateList()
// remove superfluous symbols from list widget
for
(
int
idx
=
m_pListFiles
->
count
()
-
1
;
idx
>=
0
;
--
idx
)
{
std
::
string
ident
=
m_pListFiles
->
item
(
idx
)
->
text
().
toStdString
();
if
(
m_workspace
.
find
(
ident
)
==
m_workspace
.
end
())
// only keep datasets
auto
iter
=
m_workspace
.
find
(
m_pListFiles
->
item
(
idx
)
->
text
().
toStdString
());
if
(
iter
==
m_workspace
.
end
()
||
(
!
iter
->
second
)
||
iter
->
second
->
GetType
()
!=
SymbolType
::
DATASET
)
delete
m_pListFiles
->
item
(
idx
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment