Commit 9935e416 authored by Daniel Hynds's avatar Daniel Hynds
Browse files

Added new class for clicpix event loading with Timepix3 telescope

Former-commit-id: f3697851612dba0d551d48e068b1a42e32bcc0bd
parent 454d0031
#include "CLICpixEventLoader.h"
CLICpixEventLoader::CLICpixEventLoader(bool debugging)
: Algorithm("CLICpixEventLoader"){
debug = debugging;
m_filename = "";
void CLICpixEventLoader::initialise(Parameters* par){
parameters = par;
// File structure is RunX/CLICpix/RunX.dat
// Take input directory from global parameters
string inputDirectory = parameters->inputDirectory + "/CLICpix";
// 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(".dat") != 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 CLICpix in "<<inputDirectory<<endl;
// Open the data file for later;
StatusCode CLICpixEventLoader::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
return Failure;
// Otherwise load a new frame
// Pixel container, shutter information
Pixels* pixels;
long double shutterStartTime, shutterStopTime;
string data;
// Read file and load data
// If line is empty then we have finished this event, stop looping
if(data.length() == 0) break;
// Check if this is a header/shutter/power info
if(data.find("PWR_RISE") != string::npos || data.find("PWR_FALL") != string::npos) continue;
if(data.find("SHT_RISE") != string::npos){
// Read the shutter start time
long int timeInt; string name;
istringstream header(data);
header >> name >> timeInt;
shutterStartTime = (double)timeInt/(4096. * 40000000.);
if(data.find("SHT_FALL") != string::npos){
// Read the shutter stop time
long int timeInt; string name;
istringstream header(data);
header >> name >> timeInt;
shutterStopTime = (double)timeInt/(4096. * 40000000.);
// Otherwise load data
int row, col, tot;
long int time;
istringstream pixelData(data);
pixelData >> col >> row >> tot;
Pixel* pixel = new Pixel(detectorID,row,col,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
// Return value telling analysis to keep running
return Success;
void CLICpixEventLoader::finalise(){
if(debug) tcout<<"Analysed "<<m_eventNumber<<" events"<<endl;
#ifndef CLICpixEventLoader_H
#define CLICpixEventLoader_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>
class CLICpixEventLoader : public Algorithm {
// Constructors and destructors
// Functions
void initialise(Parameters*);
StatusCode run(Clipboard*);
void finalise();
// Member variables
int m_eventNumber;
string m_filename;
ifstream m_file;
#endif // CLICpixEventLoader_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment