Commit 6e4d5a7e authored by Daniel Hynds's avatar Daniel Hynds
Browse files

first commit of clicpix2 event loading

Former-commit-id: 321cd3f4817a3970c5688a622bc994c54b349cfd
parent 6ea57a62
#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;
// 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
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
// Check if this is a header
if(data.find("=====") != string::npos){
istringstream header(data);
char guff; int frameNumber;
header >> guff >> frameNumber >> guff;
// 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;
// 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);
// 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
// Return value telling analysis to keep running
return Success;
void Clicpix2EventLoader::finalise(){
if(debug) tcout<<"Analysed "<<m_eventNumber<<" events"<<endl;
#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 {
// Constructors and destructors
// 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
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