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

added online monitor


Former-commit-id: d9a1bc098ce039fce495cb47b364cc68f8d7581e
parent e69a6fb3
#include "OnlineMonitor.h"
#include <TVirtualPadEditor.h>
OnlineMonitor::OnlineMonitor(bool debugging)
: Algorithm("OnlineMonitor"){
debug = debugging;
updateNumber = 500;
}
void OnlineMonitor::initialise(Parameters* par){
// Make the local pointer to the global parameters
parameters = par;
// TApplication keeps the canvases persistent
app = new TApplication("example",0, 0);
// Make the GUI
gui = new GuiDisplay();
// Make the main window object and set the attributes
gui->m_mainFrame = new TGMainFrame(gClient->GetRoot(), 400, 400);
gui->m_mainFrame->SetCleanup(kDeepCleanup);
gui->m_mainFrame->DontCallClose();
// Add canvases and histograms
// Track canvas
// AddCanvas("TrackCanvas");
// AddButton("Tracking","TrackCanvas");
// AddHisto("TrackCanvas","/tbAnalysis/BasicTracking/trackChi2");
// AddHisto("TrackCanvas","/tbAnalysis/BasicTracking/trackAngleX");
// Hitmap canvas
AddCanvas("HitmapCanvas");
AddButton("HitMap","HitmapCanvas");
// AddHisto("HitmapCanvas","/tbAnalysis/TestAlgorithm/clusterTot_W0013_G03");
// AddHisto("HitmapCanvas","/tbAnalysis/TestAlgorithm/eventTimes_W0013_G03");
// AddHisto("HitmapCanvas","/tbAnalysis/TestAlgorithm/hitmap_W0013_G03","colz");
// Per detector histograms
for(int det = 0; det<parameters->nDetectors; det++){
string detectorID = parameters->detectors[det];
string hitmap = "/tbAnalysis/TestAlgorithm/hitmap_"+detectorID;
AddHisto("HitmapCanvas",hitmap,"colz");
// string chargeHisto = "/tbAnalysis/TestAlgorithm/clusterTot_"+detectorID;
// AddHisto("HitmapCanvas",chargeHisto);
// if(parameters->excludedFromTracking[detectorID]) continue;
// string residualHisto = "/tbAnalysis/BasicTracking/residualsX_"+detectorID;
// AddHisto(residualsCanvas,residualHisto);
}
// Set up the main frame before drawing
gui->m_mainFrame->SetWindowName("CLIC Tesbeam Monitoring");
gui->m_mainFrame->MapSubwindows();
gui->m_mainFrame->Resize();
// Draw the main frame
gui->m_mainFrame->MapWindow();
// Initialise member variables
eventNumber = 0;
}
StatusCode OnlineMonitor::run(Clipboard* clipboard){
// Draw all histograms
if(eventNumber%updateNumber == 0){
int nCanvases = gui->canvasVector.size();
for(int i=0;i<nCanvases;i++){
gui->canvasVector[i]->GetCanvas()->Paint();
gui->canvasVector[i]->GetCanvas()->Update();
}
}
gSystem->ProcessEvents();
eventNumber++;
return Success;
}
void OnlineMonitor::finalise(){
if(debug) tcout<<"Analysed "<<eventNumber<<" events"<<endl;
}
void OnlineMonitor::AddCanvas(string canvasName){
gui->canvases[canvasName] = new TRootEmbeddedCanvas(canvasName.c_str(), gui->m_mainFrame, 600, 400);
gui->canvasVector.push_back(gui->canvases[canvasName]);
gui->m_mainFrame->AddFrame(gui->canvases[canvasName],
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10));
}
void OnlineMonitor::AddStackedCanvas(string canvasName){
this->AddCanvas(canvasName);
gui->stackedCanvas[gui->canvases[canvasName]] = true;
}
void OnlineMonitor::AddHisto(string canvasName, string histoName, string style){
gui->histograms[gui->canvases[canvasName]].push_back((TH1*)gDirectory->Get(histoName.c_str()));
gui->styles[gui->histograms[gui->canvases[canvasName]].back()] = style;
}
void OnlineMonitor::AddButton(string buttonName, string canvasName){
gui->buttons[buttonName] = new TGTextButton(gui->m_mainFrame, buttonName.c_str());
gui->m_mainFrame->AddFrame(gui->buttons[buttonName], new TGLayoutHints(kLHintsLeft, 10, 10, 10, 1));
string command = "Display(=\"" + canvasName + "\")";
tcout<<"Connecting button with command "<<command.c_str()<<endl;
gui->buttons[buttonName]->Connect("Pressed()", "GuiDisplay", gui, command.c_str());
}
#ifndef OnlineMonitor_H
#define OnlineMonitor_H 1
#include "Algorithm.h"
#include <iostream>
#include "Pixel.h"
#include "Cluster.h"
#include "Track.h"
#include "GuiDisplay.h"
// ROOT includes
#include "TH1F.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TGCanvas.h"
#include "TGFrame.h"
#include "TGTextEntry.h"
#include "TGDockableFrame.h"
#include "TGMenu.h"
#include "TApplication.h"
#include <RQ_OBJECT.h>
#include "TROOT.h"
#include "TSystem.h"
#include "TRootEmbeddedCanvas.h"
class OnlineMonitor : public Algorithm {
public:
// Constructors and destructors
OnlineMonitor(bool);
~OnlineMonitor(){}
// Functions
void initialise(Parameters*);
StatusCode run(Clipboard*);
void finalise();
// Application to allow display persistancy
TApplication* app;
GuiDisplay* gui;
void AddCanvas(string);
void AddStackedCanvas(string);
void AddHisto(string, string, string style="");
void AddButton(string, string);
// Member variables
int eventNumber;
int updateNumber;
};
#endif // OnlineMonitor_H
......@@ -30,6 +30,7 @@
#include "Timepix1Correlator.h"
#include "ClicpixAnalysis.h"
#include "DataDump.h"
#include "OnlineMonitor.h"
//-------------------------------------------------------------------------------
// The Steering is effectively the executable. It reads command line
......@@ -41,7 +42,7 @@
Analysis* analysis;
// Handle user interruption
// This allows you to ^C at any point in a controlled way
// This allows you to ^\ to exit at any point in a controlled way
void userException(int sig){
cout<<endl<<"User interrupted"<<endl;
analysis->finaliseAll();
......@@ -50,8 +51,8 @@ void userException(int sig){
int main(int argc, char *argv[]) {
// Register escape behaviour
signal(SIGINT, userException);
// Register escape behaviour (^\)
signal(SIGQUIT, userException);
// New parameters object
Parameters* parameters = new Parameters();
......@@ -77,7 +78,7 @@ int main(int argc, char *argv[]) {
Timepix1Correlator* correlator = new Timepix1Correlator(debug);
ClicpixAnalysis* clicpixAnalysis = new ClicpixAnalysis(debug);
DataDump* dataDump = new DataDump(debug);
OnlineMonitor* onlineMonitor = new OnlineMonitor(debug);
// =========================================================================
// Steering file begins
// =========================================================================
......@@ -86,13 +87,13 @@ int main(int argc, char *argv[]) {
// parameters->reference = "W0013_G03";
// parameters->DUT = "W0005_E02";
// parameters->DUT = "W0002_J05";
// parameters->reference = "W0013_G03";
parameters->reference = "W0013_G03";
// parameters->DUT = "W0019_L08";
// parameters->DUT = "W0019_F07";
parameters->DUT = "W0019_F07";
// Clicpix parameters
parameters->reference = "Mim-osa02";
parameters->DUT = "CLi-CPix";
// parameters->reference = "Mim-osa02";
// parameters->DUT = "CLi-CPix";
parameters->detectorToAlign = parameters->DUT;
parameters->excludedFromTracking[parameters->DUT] = true;
......@@ -106,6 +107,7 @@ int main(int argc, char *argv[]) {
parameters->excludedFromTracking["W0005_H03"] = true;
parameters->excludedFromTracking["W0013_F09"] = true;
clicpixAnalysis->timepix3Telescope = true;
// spatialTracking->debug = true;
//testAlgorithm->makeCorrelations = true;
//dataDump->m_detector = parameters->DUT;
......@@ -126,19 +128,20 @@ int main(int argc, char *argv[]) {
// Initialise the analysis object and add algorithms to run
analysis = new Analysis(parameters);
// analysis->add(tpix1EventLoader);
analysis->add(fileReader);
analysis->add(tpix1Clustering);
analysis->add(spatialTracking);
// analysis->add(fileReader);
// analysis->add(tpix1Clustering);
// analysis->add(spatialTracking);
// analysis->add(correlator);
// analysis->add(tpix3EventLoader);
// analysis->add(tpix3Clustering);
// analysis->add(testAlgorithm);
// analysis->add(basicTracking);
// analysis->add(dutAnalysis);
analysis->add(clicpixAnalysis);
analysis->add(tpix3EventLoader);
analysis->add(tpix3Clustering);
analysis->add(testAlgorithm);
analysis->add(basicTracking);
analysis->add(dutAnalysis);
// analysis->add(clicpixAnalysis);
// analysis->add(fileWriter);
// analysis->add(dataDump);
analysis->add(onlineMonitor);
if(parameters->align) analysis->add(alignment);
if(parameters->produceMask) analysis->add(tpix3MaskCreator);
if(parameters->eventDisplay) analysis->add(eventDisplay);
......
#ifndef GUIDISPLAY_H
#define GUIDISPLAY_H 1
#include "TestBeamObject.h"
// ROOT includes
#include "TH1F.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TGCanvas.h"
#include "TGFrame.h"
#include "TGTextEntry.h"
#include "TGDockableFrame.h"
#include "TGMenu.h"
#include "TApplication.h"
#include <RQ_OBJECT.h>
#include "TROOT.h"
#include "TSystem.h"
#include "TRootEmbeddedCanvas.h"
class GuiDisplay : public TestBeamObject {
RQ_OBJECT("GuiDisplay")
public:
// Constructors and destructors
GuiDisplay(){};
~GuiDisplay(){}
// Graphics associated with GUI
TGMainFrame* m_mainFrame;
vector<TRootEmbeddedCanvas*> canvasVector;
map<string, TRootEmbeddedCanvas*> canvases;
map<TRootEmbeddedCanvas*, vector<TH1*>> histograms;
map<TH1*,string> styles;
map<string, TGTextButton*> buttons;
map<TRootEmbeddedCanvas*, bool> stackedCanvas;
// Button functions
inline void Display(char* canvasName){
if(canvases.count(canvasName) == 0){
cout<<"Canvas does not exist, exiting"<<endl;
return;
}
TRootEmbeddedCanvas* canvas = canvases[canvasName];
int nHistograms = histograms[canvas].size();
canvas->GetCanvas()->Clear();
canvas->GetCanvas()->cd();
if(!stackedCanvas[canvas]){
if(nHistograms < 4) canvas->GetCanvas()->Divide(nHistograms);
else canvas->GetCanvas()->Divide(ceil(nHistograms/2.),2);
}
for(int i=0;i<nHistograms;i++){
if(!stackedCanvas[canvas]) canvas->GetCanvas()->cd(i+1);
string style = styles[histograms[canvas][i]];
if(stackedCanvas[canvas]){
style = "same";
histograms[canvas][i]->SetLineColor(i+1);
}
histograms[canvas][i]->Draw(style.c_str());
}
canvases[canvasName]->GetCanvas()->Paint();
canvases[canvasName]->GetCanvas()->Update();
};
// ROOT I/O class definition - update version number when you change this class!
ClassDef(GuiDisplay,0)
};
#endif // GUIDISPLAY_H
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