Commit cf9c3ca4 authored by Daniel Hynds's avatar Daniel Hynds
Browse files

Updates to timepix3 event loading, monitoring gui and fixed memory leaks


Former-commit-id: 31c2cfc8e04c030002ef2aa119bfc58a925db59e
parent e5fb9194
......@@ -47,20 +47,22 @@ int BasicTracking::run(Clipboard* clipboard){
Timepix3Clusters* tempClusters = (Timepix3Clusters*)clipboard->get(detectorID,"clusters");
if(tempClusters == NULL){
tcout<<"Detector "<<detectorID<<" does not have any clusters on the clipboard"<<endl;
}else{
// Store them
clusters[detectorID] = tempClusters;
detectors.push_back(detectorID);
}
// Store them
clusters[detectorID] = tempClusters;
detectors.push_back(detectorID);
}
// If there are no detectors then stop trying to track
if(detectors.size() == 0) return 0;
if(detectors.size() == 0) return 1;
// Use the first plane as a seeding plane. For something quick, look a cluster in < 100 ns in the next plane, and continue
string reference = parameters->reference;
map<Timepix3Cluster*, bool> used;
// If no clusters on reference plane, stop
if(clusters[reference] == NULL) return 1;
// Loop over all clusters
for(int iSeedCluster=0;iSeedCluster<clusters[reference]->size();iSeedCluster++){
......@@ -86,7 +88,10 @@ int BasicTracking::run(Clipboard* clipboard){
}
// Now should have a track with one cluster from each plane
if(track->nClusters() < 5) continue;
if(track->nClusters() < 5){
delete track;
continue;
}
// Fit the track and save it
track->fit();
......@@ -108,10 +113,8 @@ int BasicTracking::run(Clipboard* clipboard){
}
tcout<<"Made "<<tracks->size()<<" tracks"<<endl;
clipboard->put("Timepix3","tracks",(TestBeamObjects*)tracks);
// cout<<gPad<<endl;
// trackChi2->Draw();
// cout<<gPad<<endl;
if(tracks->size() > 0) clipboard->put("Timepix3","tracks",(TestBeamObjects*)tracks);
return 1;
}
......
......@@ -7,6 +7,7 @@
GUI::GUI(bool debugging)
: Algorithm("GUI"){
debug = debugging;
updateNumber = 500;
}
void startDisplay(void* gui){
......@@ -40,6 +41,7 @@ void GUI::initialise(Parameters* par){
// Make the thread which will run the display
displayThread = new TThread("displayThread", startDisplay, (void*) this);
displayThread->Run();
sleep(2);
// Loop over all detectors and load the histograms that we will use
for(int det = 0; det<parameters->nDetectors; det++){
......@@ -56,6 +58,8 @@ void GUI::initialise(Parameters* par){
int GUI::run(Clipboard* clipboard){
gSystem->ProcessEvents();
//-----------------------------------------
// Draw the objects on the tracking canvas
//-----------------------------------------
......@@ -65,7 +69,10 @@ int GUI::run(Clipboard* clipboard){
trackChi2->DrawCopy();
// Update the canvas
trackCanvas->Update();
if(eventNumber%updateNumber == 0){
// sleep(0.5);
trackCanvas->Update();
}
//-----------------------------------------
// Draw the objects on the hitmap canvas
......@@ -81,8 +88,10 @@ int GUI::run(Clipboard* clipboard){
}
}
// Update the canvas
hitmapCanvas->Paint();
hitmapCanvas->Update();
if(eventNumber%updateNumber == 0) {
hitmapCanvas->Paint();
hitmapCanvas->Update();
}
//-----------------------------------------
// Draw the objects on the residuals canvas
......@@ -98,8 +107,10 @@ int GUI::run(Clipboard* clipboard){
}
}
// Update the canvas
residualsCanvas->Paint();
residualsCanvas->Update();
if(eventNumber%updateNumber == 0){
residualsCanvas->Paint();
residualsCanvas->Update();
}
eventNumber++;
return 1;
......@@ -115,7 +126,7 @@ int GUI::run(Clipboard* clipboard){
void GUI::finalise(){
// Kill the display thread
displayThread->Kill();
// displayThread->Kill();
}
......@@ -42,6 +42,7 @@ public:
// Misc. member objects
int nDetectors;
int eventNumber;
int updateNumber;
// TBrowser* browser;
};
......
......@@ -53,7 +53,7 @@ int TestAlgorithm::run(Clipboard* clipboard){
Timepix3Clusters* referenceClusters = (Timepix3Clusters*)clipboard->get(parameters->reference,"clusters");
if(referenceClusters == NULL){
tcout<<"Reference detector "<<parameters->reference<<" does not have any clusters on the clipboard"<<endl;
return 0;
return 1;
}
// Loop over all Timepix3 and make plots
......@@ -67,14 +67,14 @@ int TestAlgorithm::run(Clipboard* clipboard){
Timepix3Pixels* pixels = (Timepix3Pixels*)clipboard->get(detectorID,"pixels");
if(pixels == NULL){
tcout<<"Detector "<<detectorID<<" does not have any pixels on the clipboard"<<endl;
return 0;
return 1;
}
// Get the clusters
Timepix3Clusters* clusters = (Timepix3Clusters*)clipboard->get(detectorID,"clusters");
if(clusters == NULL){
tcout<<"Detector "<<detectorID<<" does not have any clusters on the clipboard"<<endl;
return 0;
return 1;
}
// Loop over all pixels and make hitmaps
......
......@@ -27,7 +27,7 @@ int Timepix3Clustering::run(Clipboard* clipboard){
Timepix3Pixels* pixels = (Timepix3Pixels*)clipboard->get(detectorID,"pixels");
if(pixels == NULL){
tcout<<"Detector "<<detectorID<<" does not have any pixels on the clipboard"<<endl;
return 0;
return 1;
}
if(debug) tcout<<"Picked up "<<pixels->size()<<" pixels for device "<<detectorID<<endl;
......
......@@ -63,6 +63,8 @@ void Timepix3EventLoader::initialise(Parameters* par){
// If files were stored, register the detector
if(m_nFiles.count(detectorID) > 0){
tcout<<"Registering detector "<<detectorID<<endl;
parameters->registerDetector(detectorID);
// Now that we have all of the data files and mask files for this detector, pass the mask file to parameters
......@@ -79,6 +81,7 @@ void Timepix3EventLoader::initialise(Parameters* par){
int Timepix3EventLoader::run(Clipboard* clipboard){
tcout<<"Current time is "<<parameters->currentTime<<endl;
bool loadedData = false;
// Loop through all registered detectors
for(int det = 0; det<parameters->nDetectors; det++){
......@@ -88,16 +91,21 @@ int Timepix3EventLoader::run(Clipboard* clipboard){
// Make a new container for the data
Timepix3Pixels* deviceData = new Timepix3Pixels();
// Load the next chunk of data
tcout<<"Loading data from "<<detectorID<<endl;
bool data = loadData(detectorID,deviceData);
// If data was loaded then put it on the clipboard
if(data){
loadedData = true;
tcout<<"Loaded "<<deviceData->size()<<" pixels for device "<<detectorID<<endl;
clipboard->put(detectorID,"pixels",(TestBeamObjects*)deviceData);
}
}
// Increment the event time
parameters->currentTime += parameters->eventLength;
// If no data was loaded, tell the event loop to stop
if(!loadedData) return 0;
if(!loadedData) return 2;
// Otherwise tell event loop to keep running
return 1;
......@@ -166,6 +174,8 @@ bool Timepix3EventLoader::loadData(string detectorID, Timepix3Pixels* devicedata
if (retval == 0) continue;
const UChar_t header = ((pixdata & 0xF000000000000000) >> 60) & 0xF;
unsigned int headerInt = ((pixdata & 0xF000000000000000) >> 60) & 0xF;
tcout<<hex<<headerInt<<dec<<endl;
// bitset<64> headerContent(header);
// tcout<<"Header is "<<headerContent<<endl;
......@@ -190,14 +200,25 @@ bool Timepix3EventLoader::loadData(string detectorID, Timepix3Pixels* devicedata
// tcout<<"Pixel time "<<(double)time<<endl;
time += (long long int)(parameters->detector[detectorID]->timingOffset() * 4096. * 40000000.);
tcout<<"Pixel time is "<<((double)time/(4096. * 40000000.))<<endl;
bitset<48> timeInt(time);
tcout<<" or "<<timeInt<<endl;
// If events are loaded based on time intervals, take all hits where the time is within this window
if( parameters->eventLength != 0. &&
((double)time/(4096. * 40000000.)) > (parameters->currentTime + parameters->eventLength) ){
fseek(m_currentFile[detectorID], -1 * sizeof(ULong64_t), SEEK_CUR);
break;
}
Timepix3Pixel* pixel = new Timepix3Pixel(detectorID,row,col,(int)tot,time);
devicedata->push_back(pixel);
npixels++;
}
// Stop when we reach some large number of pixels
if(npixels == 2000) break;
// Stop when we reach some large number of pixels (if events not based on time)
if(parameters->eventLength == 0. && npixels == 2000) break;
}
......
......@@ -37,7 +37,6 @@ void Analysis::run(){
m_events=0;
while(1){
bool run = true;
m_events++;
cout<<"[Analysis] Running over event "<<m_events<<endl;
// Run all algorithms
for(int algorithmNumber = 0; algorithmNumber<m_algorithms.size();algorithmNumber++) {
......@@ -47,6 +46,7 @@ void Analysis::run(){
m_algorithms[algorithmNumber]->getStopwatch()->Start(false);
int check = m_algorithms[algorithmNumber]->run(m_clipboard);
m_algorithms[algorithmNumber]->getStopwatch()->Stop();
if(check == 2) break; // Nothing to be done in this event
if(check == 0) run = false;
}
// Clear objects from this iteration from the clipboard
......@@ -55,8 +55,13 @@ void Analysis::run(){
if(!run) break;
// Check if we have reached the maximum number of events
if(m_parameters->nEvents > 0 && m_events == m_parameters->nEvents) break;
// Increment event number
m_events++;
}
// If running the gui, don't close until the user types a command
if(m_parameters->gui) cin.ignore();
// Loop over all algorithms and finalise them
finaliseAll();
......
......@@ -13,6 +13,8 @@ Parameters::Parameters(){
nEvents = 0;
align = false;
produceMask = false;
currentTime = 0.; // seconds
eventLength = 0.000; //seconds (0.1 ms)
}
void Parameters::help()
......@@ -30,7 +32,7 @@ void Parameters::readCommandLineOptions(int argc, char *argv[]){
cout<<endl;
cout<<"===================| Reading Parameters |===================="<<endl<<endl;
int option; char temp[256];
while ( (option = getopt(argc, argv, "agemd:c:n:h:")) != -1) {
while ( (option = getopt(argc, argv, "agemd:c:n:h:t:")) != -1) {
switch (option) {
case 'a':
align = true;
......@@ -67,6 +69,10 @@ void Parameters::readCommandLineOptions(int argc, char *argv[]){
sscanf( optarg, "%d", &nEvents);
cout<<"Running over "<<nEvents<<" events"<<endl;
break;
case 't':
sscanf( optarg, "%d", &eventLength);
cout<<"Event length is "<<eventLength<<" s"<<endl;
break;
}
}
cout<<endl;
......
......@@ -164,6 +164,8 @@ public:
int nDetectors;
string reference;
string dut;
double currentTime;
double eventLength;
int nEvents;
bool align;
bool eventDisplay;
......
......@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
analysis->add(tpix3EventLoader);
analysis->add(tpix3Clustering);
analysis->add(testAlgorithm);
analysis->add(basicTracking);
// analysis->add(basicTracking);
if(parameters->align) analysis->add(alignment);
if(parameters->produceMask) analysis->add(tpix3MaskCreator);
......
......@@ -6,6 +6,7 @@ RUN=25
DATADIR=${TBCODE}/example/Run${RUN}
CONDFILE=${TBCODE}/cond/cond.dat
HISTOFILE=${TBCODE}/histos/histogramsRun${RUN}.root
NEVENTS=20
NEVENTS=100
EVENTTIME=0
${TBCODE}/bin/tbAnalysis -d ${DATADIR} -c ${CONDFILE} -n ${NEVENTS} -h ${HISTOFILE} -g
${TBCODE}/bin/tbAnalysis -d ${DATADIR} -c ${CONDFILE} -n ${NEVENTS} -h ${HISTOFILE} -t ${EVENTTIME}
......@@ -17,7 +17,11 @@ public:
m_fitterYZ = new TLinearFitter();
m_fitterYZ->SetFormula("pol1");
}
virtual ~Timepix3Track(){}
virtual ~Timepix3Track(){
delete m_fitterXZ;
delete m_fitterYZ;
}
Timepix3Track(Timepix3Track* track){
m_fitterXZ = new TLinearFitter();
m_fitterXZ->SetFormula("pol1");
......
Markdown is supported
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