Commit 0fcece18 authored by Daniel Hynds's avatar Daniel Hynds
Browse files

large improvements to canvas operation, can now rescale, zoom, save files,...

large improvements to canvas operation, can now rescale, zoom, save files, etc. while viewing. Improved timing and addition of new plots


Former-commit-id: a01ed7737f7bc3a6f3e80dd0faed1b92e82d5619
parent 566d128b
......@@ -10,27 +10,6 @@ GUI::GUI(bool debugging)
updateNumber = 500;
}
void startDisplay(void* gui){
// Make the TApplicaitons to allow canvases to stay open (for some reason we need two instances for it to work...)
TApplication* app = 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)->globalHitmapCanvas = new TCanvas("GlobalHitmapCanvas","Global hit map canvas");
((GUI*)gui)->globalHitmapCanvas->Divide(ceil(nDetectors/2.),2);
((GUI*)gui)->residualsCanvas = new TCanvas("ResidualsCanvas","Residuals canvas");
((GUI*)gui)->residualsCanvas->Divide(ceil(nDetectors/2.),2);
// Run the TApplication
((GUI*)gui)->app->Run(true);
}
void GUI::initialise(Parameters* par){
// Make the local pointer to the global parameters
......@@ -39,127 +18,97 @@ void GUI::initialise(Parameters* par){
// Check the number of devices
nDetectors = parameters->nDetectors;
// TApplication keeps the canvases persistent
app = new TApplication("example",0, 0);
//========= Add each canvas that is wanted =========//
TCanvas* trackCanvas = new TCanvas("TrackCanvas","Track canvas");
addCanvas(trackCanvas);
TCanvas* hitmapCanvas = new TCanvas("HitMapCanvas","Hit map canvas");
addCanvas(hitmapCanvas);
// trackCanvas = new TCanvas("TrackCanvas","Track canvas");
// hitmapCanvas = new TCanvas("HitMapCanvas","Hit map canvas");
// hitmapCanvas->Divide(ceil(nDetectors/2.),2);
// globalHitmapCanvas = new TCanvas("GlobalHitmapCanvas","Global hit map canvas");
// globalHitmapCanvas->Divide(ceil(nDetectors/2.),2);
// residualsCanvas = new TCanvas("ResidualsCanvas","Residuals canvas");
// residualsCanvas->Divide(ceil(nDetectors/2.),2);
// Make the thread which will run the display
displayThread = new TThread("displayThread", startDisplay, (void*) this);
displayThread->Run();
sleep(2);
TCanvas* residualsCanvas = new TCanvas("ResidualsCanvas","Residuals canvas");
addCanvas(residualsCanvas);
//========= Add each histogram =========//
// Loop over all detectors and load the histograms that we will use
// Individual plots
TH1F* trackChi2 = (TH1F*)gDirectory->Get("/tbAnalysis/BasicTracking/trackChi2");
addPlot(trackCanvas,(TH1*)trackChi2);
// Per detector histograms
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());
TH2F* hitmap = (TH2F*)gDirectory->Get(hitmapHisto.c_str());
addPlot(hitmapCanvas,hitmap,"colz");
string residualHisto = "/tbAnalysis/BasicTracking/residualsX_"+detectorID;
residuals[detectorID] = (TH1F*)gDirectory->Get(residualHisto.c_str());
string globalHitmapHisto = "/tbAnalysis/TestAlgorithm/clusterPositionGlobal_"+detectorID;
globalHitmap[detectorID] = (TH2F*)gDirectory->Get(globalHitmapHisto.c_str());
TH1F* residuals = (TH1F*)gDirectory->Get(residualHisto.c_str());
addPlot(residualsCanvas,residuals);
}
// Divide the canvases if needed
for(int iCanvas=0;iCanvas<canvases.size();iCanvas++){
int nHistograms = histograms[canvases[iCanvas]].size();
if(nHistograms == 1) continue;
if(nHistograms < 4) canvases[iCanvas]->Divide(nHistograms);
else canvases[iCanvas]->Divide(ceil(nHistograms/2.),2);
}
// Draw all histograms
for(int iCanvas=0;iCanvas<canvases.size();iCanvas++){
canvases[iCanvas]->cd();
vector<TH1*> histos = histograms[canvases[iCanvas]];
int nHistograms = histos.size();
for(int iHisto=0;iHisto<nHistograms;iHisto++){
canvases[iCanvas]->cd(iHisto+1);
string style = styles[histos[iHisto]];
histos[iHisto]->Draw(style.c_str());
}
}
// Set event counter
eventNumber = 0;
}
StatusCode GUI::run(Clipboard* clipboard){
//-----------------------------------------
// Draw the objects on the tracking canvas
//-----------------------------------------
trackCanvas->cd();
TH1F* trackChi2 = (TH1F*)gDirectory->Get("/tbAnalysis/BasicTracking/trackChi2");
trackChi2->Draw();
// Update the canvas
// Draw all histograms
if(eventNumber%updateNumber == 0){
trackCanvas->Update();
}
//-----------------------------------------
// Draw the objects on the hitmap canvas
//-----------------------------------------
// 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");
}
}
// Update the canvas
if(eventNumber%updateNumber == 0) {
hitmapCanvas->Paint();
hitmapCanvas->Update();
}
//-----------------------------------------
// Draw the objects on the globalHitmap canvas
//-----------------------------------------
// Update the canvas
if(eventNumber == 0){
for(int det = 0; det<parameters->nDetectors; det++){
string detectorID = parameters->detectors[det];
globalHitmap[detectorID]->SetTitle(detectorID.c_str());
globalHitmapCanvas->cd(det+1);
globalHitmap[detectorID]->Draw("colz");
for(int iCanvas=0;iCanvas<canvases.size();iCanvas++){
canvases[iCanvas]->Paint();
canvases[iCanvas]->Update();
}
}
// Update the canvas
if(eventNumber%updateNumber == 0) {
// globalHitmapCanvas->Paint();
globalHitmapCanvas->Update();
}
//-----------------------------------------
// Draw the objects on the residuals canvas
//-----------------------------------------
gSystem->ProcessEvents();
// 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
if(eventNumber%updateNumber == 0){
residualsCanvas->Paint();
residualsCanvas->Update();
// gSystem->ProcessEvents();
}
eventNumber++;
return Success;
// 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
cout<<"Killing thread"<<endl;
displayThread->Kill();
cout<<"Killed"<<endl;
void GUI::addCanvas(TCanvas* canvas){
canvases.push_back(canvas);
}
void GUI::addPlot(TCanvas* canvas, TH1* histogram, std::string style){
histograms[canvas].push_back(histogram);
styles[histogram] = style;
}
......@@ -27,28 +27,22 @@ public:
StatusCode run(Clipboard*);
void finalise();
TApplication* app;
// Canvases to display plots
TCanvas* trackCanvas;
TCanvas* hitmapCanvas;
TCanvas* globalHitmapCanvas;
TCanvas* residualsCanvas;
// Plot holders
map<string, TH2F*> hitmap;
map<string, TH2F*> globalHitmap;
map<string, TH1F*> residuals;
vector<TCanvas*> canvases;
map<TCanvas*,vector<TH1*>> histograms;
map<TH1*,string> styles;
// Thread to allow display to run in separate thread
TThread* displayThread;
// Add plots and canvases
void addPlot(TCanvas*, TH1*, string style = "");
void addCanvas(TCanvas*);
// Application to allow display of canvases
TApplication* app;
// Misc. member objects
int nDetectors;
int eventNumber;
int updateNumber;
// TBrowser* browser;
};
......
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