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

First implementation of GUI plots


Former-commit-id: 7ba7dc88d1025ebb9a2c83ebcd9d4a4185139bc9
parent e3a7a0a3
......@@ -2,112 +2,120 @@
#include "TApplication.h"
#include "TPolyLine3D.h"
#include "TSystem.h"
#include "TROOT.h"
GUI::GUI(bool debugging)
: Algorithm("GUI"){
debug = debugging;
}
void startBrowser(void* gui){
void startDisplay(void* gui){
cout<<"I still run"<<endl;
// TApplication* testApp = new TApplication("example",0, 0);
// TBrowser* test = new TBrowser();
// testApp->Run();
((GUI*)gui)->rootapp = new TApplication("example",0, 0);
((GUI*)gui)->browser = new TBrowser();
// gSystem->Sleep(1);
((GUI*)gui)->rootapp->Run(true);
// Make the TApplicaitons to allow canvases to stay open (for some reason we need two instances for it to work...)
TApplication* app1 = new TApplication("example",0, 0);
TApplication* app2 = new TApplication("example",0, 0);
}
// Create the new canvases
double nDetectors = ((GUI*)gui)->nDetectors;
((GUI*)gui)->trackCanvas = new TCanvas("TrackCanvas","Track canvas");
// ((GUI*)gui)->trackCanvas->Divide();
((GUI*)gui)->hitmapCanvas = new TCanvas("HitMapCanvas","Hit map canvas");
((GUI*)gui)->hitmapCanvas->Divide(ceil(nDetectors/2.),2);
((GUI*)gui)->residualsCanvas = new TCanvas("ResidualsCanvas","Residuals canvas");
((GUI*)gui)->residualsCanvas->Divide(ceil(nDetectors/2.),2);
void update(void*){
while(1){
gSystem->ProcessEvents();
gSystem->Sleep(1);
}
// Run the TApplication
app2->Run(true);
}
void GUI::initialise(Parameters* par){
// Make the local pointer to the global parameters
parameters = par;
// Set up histograms
eventMap = new TH3F("eventMap","eventMap",100,-10,10,100,-10,10,105,-10,200);
// Check the number of devices
nDetectors = parameters->nDetectors;
// TApplication* rootapp = new TApplication("example",0, 0);
// browser = new TBrowser();
// rootapp->Run();
// Make the thread which will run the display
displayThread = new TThread("displayThread", startDisplay, (void*) this);
displayThread->Run();
// rootapp = new TApplication("example",0, 0);
// browser = new TBrowser();
browserThread = new TThread("browserThread", startBrowser, (void*) this);
// browserThread->Run();
updateThread = new TThread("updateThread", update, (void*) 0);
// updateThread->Run();
// Loop over all detectors and load the histograms that we will use
for(int det = 0; det<parameters->nDetectors; det++){
string detectorID = parameters->detectors[det];
string hitmapHisto = "/tbAnalysis/TestAlgorithm/hitmap_"+detectorID;
hitmap[detectorID] = (TH2F*)gDirectory->Get(hitmapHisto.c_str());
string residualHisto = "/tbAnalysis/BasicTracking/residualsX_"+detectorID;
residuals[detectorID] = (TH1F*)gDirectory->Get(residualHisto.c_str());
}
// Set event counter
eventNumber = 0;
}
int GUI::run(Clipboard* clipboard){
// updateThread->Run();
// Get the tracks
// Timepix3Tracks* tracks = (Timepix3Tracks*)clipboard->get("Timepix3","tracks");
// if(tracks == NULL){
// return 1;
// }
//-----------------------------------------
// Draw the objects on the tracking canvas
//-----------------------------------------
trackCanvas->cd();
TH1F* trackChi2 = (TH1F*)gDirectory->Get("/tbAnalysis/BasicTracking/trackChi2");
trackChi2->DrawCopy();
// Update the canvas
trackCanvas->Update();
// rootapp = new TApplication("example",0, 0);
// browser = new TBrowser();
// rootapp->Run(false);
//-----------------------------------------
// Draw the objects on the hitmap canvas
//-----------------------------------------
// browser->Refresh();
/* TCanvas* canv = new TCanvas();
eventMap->DrawCopy("");
// Loop over all tracks. Add the cluster points to the histogram and draw a line for the tracks
for(int iTrack=0; iTrack<tracks->size(); iTrack++){
// Get the track
Timepix3Track* track = (*tracks)[iTrack];
// Get all clusters on the track
Timepix3Clusters trackClusters = track->clusters();
// Fill the event map
for(int iTrackCluster=0; iTrackCluster<trackClusters.size(); iTrackCluster++){
Timepix3Cluster* trackCluster = trackClusters[iTrackCluster];
eventMap->Fill(trackCluster->globalX(), trackCluster->globalY(), trackCluster->globalZ());
// Update the canvas
if(eventNumber == 0){
for(int det = 0; det<parameters->nDetectors; det++){
string detectorID = parameters->detectors[det];
hitmap[detectorID]->SetTitle(detectorID.c_str());
hitmapCanvas->cd(det+1);
hitmap[detectorID]->Draw("colz");
}
ROOT::Math::XYZPoint linestart = track->intercept(0);
ROOT::Math::XYZPoint linestop = track->intercept(200);
TPolyLine3D *line = new TPolyLine3D(2);
line->SetPoint(0,linestart.X(),linestart.Y(),linestart.Z());
line->SetPoint(1,linestop.X(),linestop.Y(),linestop.Z());
line->SetLineColor(2);
line->Draw("same");
}
// Update the canvas
hitmapCanvas->Paint();
hitmapCanvas->Update();
eventMap->DrawCopy("same,box");
canv->Update();
rootapp->Run();
return 1;
*/
//-----------------------------------------
// Draw the objects on the residuals canvas
//-----------------------------------------
// Loop over all detectors and load the hitmap
if(eventNumber == 0){
for(int det = 0; det<parameters->nDetectors; det++){
string detectorID = parameters->detectors[det];
residuals[detectorID]->SetTitle(detectorID.c_str());
residualsCanvas->cd(det+1);
residuals[detectorID]->Draw();
}
}
// Update the canvas
residualsCanvas->Paint();
residualsCanvas->Update();
eventNumber++;
return 1;
// Old code to allow updating of a TBrowser (TBrowser in 5.34 not thread safe, so removed)
// ((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Paint();
// ((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Update();
// gSystem->ProcessEvents();
}
void GUI::finalise(){
// Kill the display thread
displayThread->Kill();
}
......@@ -27,13 +27,22 @@ public:
int run(Clipboard*);
void finalise();
// void startBrowser();
// Canvases to display plots
TCanvas* trackCanvas;
TCanvas* hitmapCanvas;
TCanvas* residualsCanvas;
TApplication* rootapp;
TThread* browserThread;
TThread* updateThread;
TBrowser* browser;
TH3F* eventMap;
// Plot holders
map<string, TH2F*> hitmap;
map<string, TH1F*> residuals;
// Thread to allow display to run in separate thread
TThread* displayThread;
// Misc. member objects
int nDetectors;
int eventNumber;
// TBrowser* browser;
};
......
......@@ -48,41 +48,9 @@ void Analysis::run(){
int check = m_algorithms[algorithmNumber]->run(m_clipboard);
m_algorithms[algorithmNumber]->getStopwatch()->Stop();
if(check == 0) run = false;
// browser->Refresh();
}
// Clear objects from this iteration from the clipboard
m_clipboard->clear();
// TCanvas* canv = (TCanvas*)gDirectory->Get("c1");
// canv->Update();
browser->SetRefreshFlag(true);
browser->Refresh();
// browser->Dump();
// gDirectory->ls();
cout<<gROOT->GetListOfCanvases()->GetSize()<<endl;
// ((TCanvas*)gROOT->GetListOfCanvases()->At(0))->GetListOfPrimitives()->Print();
((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Paint();
// ((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Modified();
((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Update();
// ((TPad*)(((TCanvas*)gROOT->GetListOfCanvases()->At(0))->GetPad(0)))->Modified();
gSystem->ProcessEvents();
// gPad->Dump();
// cout<<"Sleeping"<<endl;
// gSystem->Sleep(10000);
// cout<<"Woken up"<<endl;
// Check if any of the algorithms return a value saying it should stop
if(!run) break;
// Check if we have reached the maximum number of events
......
......@@ -28,12 +28,6 @@
// added. Algorithms have 3 steps: initialise, run and finalise.
//-------------------------------------------------------------------------------
void runAnalysis(void* analysis){
((Analysis*)analysis)->run();
}
// The analysis object to be used
Analysis* analysis;
......@@ -95,28 +89,8 @@ int main(int argc, char *argv[]) {
if(parameters->eventDisplay) analysis->add(eventDisplay);
if(parameters->gui) analysis->add(gui);
TApplication* app = new TApplication("example",0, 0);
analysis->browser = new TBrowser();
// gPad = ((TPad*)(((TCanvas*)gROOT->GetListOfCanvases()->At(0))->GetPad(0)));
// TCanvas* canv = new TCanvas();
// canv->Draw();
// cout<<gPad<<endl;
TThread* anaThread = new TThread("anaThread", runAnalysis, (void*) analysis);
anaThread->Run();
app->Run(true);
cout<<"Still running"<<endl;
while(1){
gSystem->Sleep(5);
((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Modified();
((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Update();
}
// analysis->run();
// Run the analysis
analysis->run();
return 0;
......
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