Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
6e4d5a7e
Commit
6e4d5a7e
authored
Jul 07, 2017
by
Daniel Hynds
Browse files
first commit of clicpix2 event loading
Former-commit-id: 321cd3f4817a3970c5688a622bc994c54b349cfd
parent
6ea57a62
Changes
2
Hide whitespace changes
Inline
Side-by-side
branches/trunk/algorithms/Clicpix2EventLoader.C
0 → 100644
View file @
6e4d5a7e
#include
"Clicpix2EventLoader.h"
Clicpix2EventLoader
::
Clicpix2EventLoader
(
bool
debugging
)
:
Algorithm
(
"Clicpix2EventLoader"
){
debug
=
debugging
;
}
void
Clicpix2EventLoader
::
initialise
(
Parameters
*
par
){
parameters
=
par
;
// File structure is RunX/CLICpix2/data.csv
// Take input directory from global parameters
string
inputDirectory
=
parameters
->
inputDirectory
+
"/CLICpix2"
;
// Open the root directory
DIR
*
directory
=
opendir
(
inputDirectory
.
c_str
());
if
(
directory
==
NULL
){
tcout
<<
"Directory "
<<
inputDirectory
<<
" does not exist"
<<
endl
;
return
;}
dirent
*
entry
;
dirent
*
file
;
// Read the entries in the folder
while
(
entry
=
readdir
(
directory
)){
// Check for the data file
string
filename
=
inputDirectory
+
"/"
+
entry
->
d_name
;
if
(
filename
.
find
(
".csv"
)
!=
string
::
npos
){
m_filename
=
filename
;
}
}
// If no data was loaded, give a warning
if
(
m_filename
.
length
()
==
0
)
tcout
<<
"Warning: no data file was found for CLICpix2 in "
<<
inputDirectory
<<
endl
;
// Open the data file for later
m_file
.
open
(
m_filename
.
c_str
());
// Make histograms for debugging
hHitMap
=
new
TH2F
(
"hitMap"
,
"hitMap"
,
128
,
0
,
128
,
128
,
0
,
128
);
hPixelToT
=
new
TH1F
(
"pixelToT"
,
"pixelToT"
,
100
,
0
,
100
);
hPixelsPerFrame
=
new
TH1F
(
"pixelsPerFrame"
,
"pixelsPerFrame"
,
1000
,
0
,
1000
);
// Initialise member variables
m_eventNumber
=
0
;
}
StatusCode
Clicpix2EventLoader
::
run
(
Clipboard
*
clipboard
){
// Assume that the CLICpix is the DUT (if running this algorithm
string
detectorID
=
parameters
->
DUT
;
// If have reached the end of file, close it and exit program running
if
(
m_file
.
eof
()){
m_file
.
close
();
return
Failure
;
}
// Otherwise load a new frame
// Pixel container, shutter information
Pixels
*
pixels
=
new
Pixels
();
long
double
shutterStartTime
,
shutterStopTime
;
string
data
;
int
npixels
=
0
;
// Read file and load data
while
(
getline
(
m_file
,
data
)){
// Check if this is a header
if
(
data
.
find
(
"====="
)
!=
string
::
npos
){
istringstream
header
(
data
);
char
guff
;
int
frameNumber
;
header
>>
guff
>>
frameNumber
>>
guff
;
continue
;
}
// If we are at the end of a frame then the next character will be a "="
char
c
=
m_file
.
peek
();
if
(
strcmp
(
&
c
,
"="
)
==
0
)
break
;
// Otherwise load data
int
row
(
0
),
col
(
0
),
hitFlag
(
0
),
tot
(
0
),
toa
(
0
);
char
comma
;
long
int
time
;
istringstream
pixelData
(
data
);
pixelData
>>
col
>>
comma
>>
row
>>
comma
>>
hitFlag
>>
comma
>>
tot
>>
comma
>>
toa
;
tot
++
;
// If this pixel is masked, do not save it
if
(
parameters
->
detector
[
detectorID
]
->
masked
(
col
,
row
))
continue
;
Pixel
*
pixel
=
new
Pixel
(
detectorID
,
row
,
col
,
tot
,
0
);
pixels
->
push_back
(
pixel
);
npixels
++
;
hHitMap
->
Fill
(
col
,
row
);
hPixelToT
->
Fill
(
tot
);
}
// Now set the event time so that the Timepix3 data is loaded correctly
// parameters->currentTime = shutterStartTime;
// parameters->eventLength = (shutterStopTime-shutterStartTime);
// Put the data on the clipboard
if
(
pixels
->
size
()
>
0
)
clipboard
->
put
(
detectorID
,
"pixels"
,(
TestBeamObjects
*
)
pixels
);
// Fill histograms
hPixelsPerFrame
->
Fill
(
npixels
);
// Return value telling analysis to keep running
return
Success
;
}
void
Clicpix2EventLoader
::
finalise
(){
if
(
debug
)
tcout
<<
"Analysed "
<<
m_eventNumber
<<
" events"
<<
endl
;
}
branches/trunk/algorithms/Clicpix2EventLoader.h
0 → 100644
View file @
6e4d5a7e
#ifndef Clicpix2EventLoader_H
#define Clicpix2EventLoader_H 1
#include
"Algorithm.h"
#include
<iostream>
#include
"TH1F.h"
#include
"TH2F.h"
#include
"TCanvas.h"
#include
"Pixel.h"
#include
"Cluster.h"
#include
"Track.h"
#include
<fstream>
#include
<sstream>
#include
<stdio.h>
#include
<dirent.h>
#include
<string.h>
class
Clicpix2EventLoader
:
public
Algorithm
{
public:
// Constructors and destructors
Clicpix2EventLoader
(
bool
);
~
Clicpix2EventLoader
(){}
// Functions
void
initialise
(
Parameters
*
);
StatusCode
run
(
Clipboard
*
);
void
finalise
();
// Histograms for several devices
map
<
string
,
TH2F
*>
plotPerDevice
;
// Single histograms
TH1F
*
singlePlot
;
// Member variables
int
m_eventNumber
;
string
m_filename
;
ifstream
m_file
;
TH2F
*
hHitMap
;
TH1F
*
hPixelToT
;
TH1F
*
hPixelsPerFrame
;
};
#endif // Clicpix2EventLoader_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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