Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
b15d59cc
Commit
b15d59cc
authored
Nov 06, 2018
by
Simon Spannagel
Browse files
Rename Timepix3MaskCreator -> MaskCreatorTimepix3, make DETECTOR_MODULE, TYPE="Timepix3"
parent
39cebd92
Pipeline
#573548
passed with stages
in 7 minutes and 28 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/modules/
Timepix3
MaskCreator/CMakeLists.txt
→
src/modules/MaskCreator
Timepix3
/CMakeLists.txt
View file @
b15d59cc
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_GLOBAL_MODULE
(
MODULE_NAME
)
CORRYVRECKAN_DETECTOR_MODULE
(
MODULE_NAME
)
CORRYVRECKAN_DETECTOR_TYPE
(
${
MODULE_NAME
}
"Timepix3"
)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES
(
${
MODULE_NAME
}
Timepix3MaskCreator.cpp
# ADD SOURCE FILES HERE...
MaskCreatorTimepix3.cpp
)
# Provide standard install target
...
...
src/modules/MaskCreatorTimepix3/MaskCreatorTimepix3.cpp
0 → 100644
View file @
b15d59cc
#include "MaskCreatorTimepix3.h"
#include <fstream>
#include <istream>
using
namespace
corryvreckan
;
MaskCreatorTimepix3
::
MaskCreatorTimepix3
(
Configuration
config
,
std
::
shared_ptr
<
Detector
>
detector
)
:
Module
(
std
::
move
(
config
),
detector
),
m_detector
(
detector
)
{}
StatusCode
MaskCreatorTimepix3
::
run
(
Clipboard
*
clipboard
)
{
// Get the pixels
Pixels
*
pixels
=
reinterpret_cast
<
Pixels
*>
(
clipboard
->
get
(
m_detector
->
name
(),
"pixels"
));
if
(
pixels
==
nullptr
)
{
LOG
(
DEBUG
)
<<
"Detector "
<<
m_detector
->
name
()
<<
" does not have any pixels on the clipboard"
;
return
NoData
;
}
LOG
(
DEBUG
)
<<
"Picked up "
<<
pixels
->
size
()
<<
" pixels for device "
<<
m_detector
->
name
();
// Loop over all pixels
for
(
auto
&
pixel
:
(
*
pixels
))
{
// Enter another pixel hit for this channel
int
channelID
=
pixel
->
row
()
+
256
*
pixel
->
column
();
pixelhits
[
channelID
]
++
;
}
return
Success
;
}
void
MaskCreatorTimepix3
::
finalise
()
{
// Get the trimdac file
std
::
string
trimdacfile
=
m_detector
->
maskFile
();
// Calculate what the mean number of hits was
double
meanHits
=
0
;
for
(
int
col
=
0
;
col
<
256
;
col
++
)
{
for
(
int
row
=
0
;
row
<
256
;
row
++
)
{
int
channelID
=
row
+
256
*
col
;
meanHits
+=
pixelhits
[
channelID
];
}
}
meanHits
/=
(
256.
*
256.
);
// Make the new file name
std
::
string
newtrimdacfile
=
trimdacfile
;
newtrimdacfile
.
replace
(
newtrimdacfile
.
end
()
-
4
,
newtrimdacfile
.
end
(),
"_masked.txt"
);
// Open the old mask file
std
::
ifstream
trimdacs
;
trimdacs
.
open
(
trimdacfile
.
c_str
());
// Open the new mask file for writing
std
::
ofstream
newtrimdacs
;
newtrimdacs
.
open
(
newtrimdacfile
.
c_str
());
// Copy the header from the old to the new file
std
::
string
line
;
getline
(
trimdacs
,
line
);
newtrimdacs
<<
line
<<
std
::
endl
;
int
t_col
,
t_row
,
t_trim
,
t_mask
,
t_tpen
;
// Loop again and mask any pixels which are noisy
for
(
int
col
=
0
;
col
<
256
;
col
++
)
{
for
(
int
row
=
0
;
row
<
256
;
row
++
)
{
int
channelID
=
row
+
256
*
col
;
if
(
pixelhits
[
channelID
]
>
10
*
meanHits
)
{
trimdacs
>>
t_col
>>
t_row
>>
t_trim
>>
t_mask
>>
t_tpen
;
newtrimdacs
<<
t_col
<<
"
\t
"
<<
t_row
<<
"
\t
"
<<
t_trim
<<
"
\t
"
<<
"1"
<<
"
\t
"
<<
t_tpen
<<
std
::
endl
;
LOG
(
INFO
)
<<
"Masking pixel "
<<
col
<<
","
<<
row
<<
" on detector "
<<
m_detector
->
name
();
LOG
(
INFO
)
<<
"Number of counts: "
<<
pixelhits
[
channelID
];
}
else
{
// Just copy the existing line
trimdacs
>>
t_col
>>
t_row
>>
t_trim
>>
t_mask
>>
t_tpen
;
newtrimdacs
<<
t_col
<<
"
\t
"
<<
t_row
<<
"
\t
"
<<
t_trim
<<
"
\t
"
<<
t_mask
<<
"
\t
"
<<
t_tpen
<<
std
::
endl
;
}
}
}
// Close the files when finished
trimdacs
.
close
();
newtrimdacs
.
close
();
// This is a bit of a fudge. If the old trimdac file was a software-generated file (with name CHIPID_trimdac_masked.txt)
// then the new file will have an additional _masked in the name. In fact we want to replace the old file. So we now
// check if this is the case, and move the new file where we want it
if
(
trimdacfile
.
find
(
"trimdac_masked"
)
!=
std
::
string
::
npos
)
{
int
result
=
rename
(
newtrimdacfile
.
c_str
(),
trimdacfile
.
c_str
());
if
(
result
==
0
)
LOG
(
INFO
)
<<
"Trimdac file "
<<
trimdacfile
<<
" updated"
;
if
(
result
!=
0
)
LOG
(
INFO
)
<<
"Could not update trimdac file "
<<
trimdacfile
;
}
}
src/modules/
Timepix3
MaskCreator
/
Timepix3MaskCreator.h
→
src/modules/MaskCreatorTimepix3
/
MaskCreator
Timepix3
.h
View file @
b15d59cc
...
...
@@ -8,20 +8,20 @@
namespace
corryvreckan
{
/** @ingroup Modules
*/
class
Timepix3
MaskCreator
:
public
Module
{
class
MaskCreator
Timepix3
:
public
Module
{
public:
// Constructors and destructors
Timepix3
MaskCreator
(
Configuration
config
,
std
::
vector
<
std
::
shared_ptr
<
Detector
>
>
detector
s
);
~
Timepix3
MaskCreator
()
{}
MaskCreator
Timepix3
(
Configuration
config
,
std
::
shared_ptr
<
Detector
>
detector
);
~
MaskCreator
Timepix3
()
{}
// Functions
void
initialise
();
StatusCode
run
(
Clipboard
*
clipboard
);
void
finalise
();
// Member variables
std
::
map
<
std
::
string
,
std
::
map
<
int
,
int
>>
pixelhits
;
private:
std
::
shared_ptr
<
Detector
>
m_detector
;
std
::
map
<
int
,
int
>
pixelhits
;
};
}
// namespace corryvreckan
#endif // TIMEPIX3MASKCREATOR_H
src/modules/
Timepix3
MaskCreator/README.md
→
src/modules/MaskCreator
Timepix3
/README.md
View file @
b15d59cc
File moved
src/modules/Timepix3MaskCreator/Timepix3MaskCreator.cpp
deleted
100644 → 0
View file @
39cebd92
#include "Timepix3MaskCreator.h"
#include <fstream>
#include <istream>
using
namespace
corryvreckan
;
Timepix3MaskCreator
::
Timepix3MaskCreator
(
Configuration
config
,
std
::
vector
<
std
::
shared_ptr
<
Detector
>>
detectors
)
:
Module
(
std
::
move
(
config
),
std
::
move
(
detectors
))
{}
void
Timepix3MaskCreator
::
initialise
()
{
//
// // Make histograms for each Timepix3
// for(auto& detector : get_detectors()){
//
// // Check if they are a Timepix3
// if(detector->type() != "Timepix3") continue;
//
// // Simple hit map to look for hit pixels
// string name = "pixelhits_"+detector->name();
// pixelhits[detector->name()] = new
// TH2F(name.c_str(),name.c_str(),256,0,256,256,0,256);
//
// }
}
StatusCode
Timepix3MaskCreator
::
run
(
Clipboard
*
clipboard
)
{
// Loop over all Timepix3 and for each device perform the clustering
for
(
auto
&
detector
:
get_detectors
())
{
// Check if they are a Timepix3
if
(
detector
->
type
()
!=
"Timepix3"
)
continue
;
// Get the pixels
Pixels
*
pixels
=
reinterpret_cast
<
Pixels
*>
(
clipboard
->
get
(
detector
->
name
(),
"pixels"
));
if
(
pixels
==
nullptr
)
{
LOG
(
DEBUG
)
<<
"Detector "
<<
detector
->
name
()
<<
" does not have any pixels on the clipboard"
;
continue
;
}
LOG
(
DEBUG
)
<<
"Picked up "
<<
pixels
->
size
()
<<
" pixels for device "
<<
detector
->
name
();
// Loop over all pixels
for
(
auto
&
pixel
:
(
*
pixels
))
{
// Enter another pixel hit for this channel
int
channelID
=
pixel
->
row
()
+
256
*
pixel
->
column
();
pixelhits
[
detector
->
name
()][
channelID
]
++
;
}
}
return
Success
;
}
void
Timepix3MaskCreator
::
finalise
()
{
// Loop through all registered detectors
for
(
auto
&
detector
:
get_detectors
())
{
// Check if they are a Timepix3
if
(
detector
->
type
()
!=
"Timepix3"
)
continue
;
// Get the trimdac file
std
::
string
trimdacfile
=
detector
->
maskFile
();
// Calculate what the mean number of hits was
double
meanHits
=
0
;
for
(
int
col
=
0
;
col
<
256
;
col
++
)
{
for
(
int
row
=
0
;
row
<
256
;
row
++
)
{
int
channelID
=
row
+
256
*
col
;
meanHits
+=
pixelhits
[
detector
->
name
()][
channelID
];
}
}
meanHits
/=
(
256.
*
256.
);
// Make the new file name
std
::
string
newtrimdacfile
=
trimdacfile
;
newtrimdacfile
.
replace
(
newtrimdacfile
.
end
()
-
4
,
newtrimdacfile
.
end
(),
"_masked.txt"
);
// Open the old mask file
std
::
ifstream
trimdacs
;
trimdacs
.
open
(
trimdacfile
.
c_str
());
// Open the new mask file for writing
std
::
ofstream
newtrimdacs
;
newtrimdacs
.
open
(
newtrimdacfile
.
c_str
());
// Copy the header from the old to the new file
std
::
string
line
;
getline
(
trimdacs
,
line
);
newtrimdacs
<<
line
<<
std
::
endl
;
int
t_col
,
t_row
,
t_trim
,
t_mask
,
t_tpen
;
// Loop again and mask any pixels which are noisy
for
(
int
col
=
0
;
col
<
256
;
col
++
)
{
for
(
int
row
=
0
;
row
<
256
;
row
++
)
{
int
channelID
=
row
+
256
*
col
;
if
(
pixelhits
[
detector
->
name
()][
channelID
]
>
10
*
meanHits
)
{
trimdacs
>>
t_col
>>
t_row
>>
t_trim
>>
t_mask
>>
t_tpen
;
newtrimdacs
<<
t_col
<<
"
\t
"
<<
t_row
<<
"
\t
"
<<
t_trim
<<
"
\t
"
<<
"1"
<<
"
\t
"
<<
t_tpen
<<
std
::
endl
;
LOG
(
INFO
)
<<
"Masking pixel "
<<
col
<<
","
<<
row
<<
" on detector "
<<
detector
->
name
();
LOG
(
INFO
)
<<
"Number of counts: "
<<
pixelhits
[
detector
->
name
()][
channelID
];
}
else
{
// Just copy the existing line
trimdacs
>>
t_col
>>
t_row
>>
t_trim
>>
t_mask
>>
t_tpen
;
newtrimdacs
<<
t_col
<<
"
\t
"
<<
t_row
<<
"
\t
"
<<
t_trim
<<
"
\t
"
<<
t_mask
<<
"
\t
"
<<
t_tpen
<<
std
::
endl
;
}
}
}
// Close the files when finished
trimdacs
.
close
();
newtrimdacs
.
close
();
// This is a bit of a fudge. If the old trimdac file was a
// software-generated file (with name
// CHIPID_trimdac_masked.txt) then the new file will have an additional
// _masked in the name.
// In fact we want to replace the old file. So we now check if this is the
// case, and move the
// new file where we want it
if
(
trimdacfile
.
find
(
"trimdac_masked"
)
!=
std
::
string
::
npos
)
{
int
result
=
rename
(
newtrimdacfile
.
c_str
(),
trimdacfile
.
c_str
());
if
(
result
==
0
)
LOG
(
INFO
)
<<
"Trimdac file "
<<
trimdacfile
<<
" updated"
;
if
(
result
!=
0
)
LOG
(
INFO
)
<<
"Could not update trimdac file "
<<
trimdacfile
;
}
}
}
Write
Preview
Supports
Markdown
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