Commit 16944dd4 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'master' into documentation

parents 2bb02c01 64746348
Pipeline #428069 passed with stages
in 4 minutes and 43 seconds
#include "OnlineMonitor.h"
#include <TVirtualPadEditor.h>
#include <regex>
using namespace corryvreckan;
using namespace std;
......@@ -8,7 +9,39 @@ OnlineMonitor::OnlineMonitor(Configuration config, std::vector<Detector*> detect
: Module(std::move(config), std::move(detectors)) {
canvasTitle = m_config.get<std::string>("canvasTitle", "Corryvreckan Testbeam Monitor");
updateNumber = m_config.get<int>("update", 500);
;
// Set up overview plots:
canvas_overview = m_config.getMatrix<std::string>("Overview",
{{"BasicTracking/trackChi2"},
{"TestAlgorithm/clusterTot_%REFERENCE%"},
{"TestAlgorithm/hitmap_%REFERENCE%", "colz"},
{"BasicTracking/residualsX_%REFERENCE%"}});
// Set up individual plots for the DUT
canvas_dutplots = m_config.getMatrix<std::string>("DUTPlots",
{{"Clicpix2EventLoader/hitMap", "colz"},
{"Clicpix2EventLoader/hitMapDiscarded", "colz"},
{"Clicpix2EventLoader/pixelToT"},
{"Clicpix2EventLoader/pixelToA"},
{"Clicpix2EventLoader/pixelCnt", "log"},
{"Clicpix2EventLoader/pixelsPerFrame", "log"},
{"DUTAnalysis/clusterTotAssociated"},
{"DUTAnalysis/associatedTracksVersusTime"}});
canvas_tracking =
m_config.getMatrix<std::string>("Tracking", {{"BasicTracking/trackChi2"}, {"BasicTracking/trackAngleX"}});
canvas_hitmaps = m_config.getMatrix<std::string>("HitMaps", {{"TestAlgorithm/hitmap_%DETECTOR%", "colz"}});
canvas_residuals = m_config.getMatrix<std::string>("Residuals", {{"BasicTracking/residualsX_%DETECTOR%"}});
canvas_cx = m_config.getMatrix<std::string>("CorrelationX", {{"TestAlgorithm/correlationX_%DETECTOR%"}});
canvas_cx2d =
m_config.getMatrix<std::string>("CorrelationX2D", {{"TestAlgorithm/correlationX_2Dlocal_%DETECTOR%", "colz"}});
canvas_cy = m_config.getMatrix<std::string>("CorrelationY", {{"TestAlgorithm/correlationY_%DETECTOR%"}});
canvas_cy2d =
m_config.getMatrix<std::string>("CorrelationY2D", {{"TestAlgorithm/correlationY_2Dlocal_%DETECTOR%", "colz"}});
canvas_charge = m_config.getMatrix<std::string>("ChargeDistributions", {{"Timepix3Clustering/clusterTot_%DETECTOR%"}});
canvas_time = m_config.getMatrix<std::string>("EventTimes", {{"TestAlgorithm/eventTimes_%DETECTOR%"}});
}
void OnlineMonitor::initialise() {
......@@ -28,83 +61,21 @@ void OnlineMonitor::initialise() {
gui->m_mainFrame->DontCallClose();
// Add canvases and histograms
AddCanvas("Overview", canvas_overview);
AddCanvas("Tracking", canvas_tracking);
AddCanvas("HitMaps", canvas_hitmaps);
AddCanvas("Residuals", canvas_residuals);
AddCanvas("EventTimes", canvas_time);
AddCanvas("ChargeDistributions", canvas_charge);
//=== Overview canvas
AddButton("Overview", "OverviewCanvas");
// track chi2
AddHisto("OverviewCanvas", "/corryvreckan/BasicTracking/trackChi2");
// reference plane map, residuals
string reference = m_config.get<std::string>("reference");
string tot = "/corryvreckan/TestAlgorithm/clusterTot_" + reference;
AddHisto("OverviewCanvas", tot);
string hitmap = "/corryvreckan/TestAlgorithm/hitmap_" + reference;
AddHisto("OverviewCanvas", hitmap, "colz");
string residuals = "/corryvreckan/BasicTracking/residualsX_" + reference;
AddHisto("OverviewCanvas", residuals);
//=== Track canvas
AddButton("Tracking", "TrackCanvas");
AddHisto("TrackCanvas", "/corryvreckan/BasicTracking/trackChi2");
AddHisto("TrackCanvas", "/corryvreckan/BasicTracking/trackAngleX");
//=== Per detector canvases
AddButton("HitMaps", "HitmapCanvas");
AddButton("Residuals", "ResidualCanvas");
AddButton("EventTimes", "EventTimeCanvas");
AddButton("CorrelationsX", "CorrelationXCanvas");
AddButton("CorrelationsY", "CorrelationYCanvas");
AddButton("CorrelationsX2D", "CorrelationX2DCanvas");
AddButton("CorrelationsY2D", "CorrelationY2DCanvas");
AddButton("ChargeDistributions", "ChargeDistributionCanvas");
AddButton("DUTPlots", "DUTCanvas");
// Per detector histograms
for(auto& detector : get_detectors()) {
string detectorID = detector->name();
string hitmap = "/corryvreckan/TestAlgorithm/hitmap_" + detectorID;
AddHisto("HitmapCanvas", hitmap, "colz");
string chargeHisto = "/corryvreckan/Timepix3Clustering/clusterTot_" + detectorID;
AddHisto("ChargeDistributionCanvas", chargeHisto);
string eventTimeHisto = "/corryvreckan/TestAlgorithm/eventTimes_" + detectorID;
AddHisto("EventTimeCanvas", eventTimeHisto);
string correlationXHisto = "/corryvreckan/TestAlgorithm/correlationX_" + detectorID;
AddHisto("CorrelationXCanvas", correlationXHisto);
string correlationX2DHisto = "/corryvreckan/TestAlgorithm/correlationX_2Dlocal_" + detectorID;
AddHisto("CorrelationX2DCanvas", correlationX2DHisto, "colz");
string correlationYHisto = "/corryvreckan/TestAlgorithm/correlationY_" + detectorID;
AddHisto("CorrelationYCanvas", correlationYHisto);
string correlationY2DHisto = "/corryvreckan/TestAlgorithm/correlationY_2Dlocal_" + detectorID;
AddHisto("CorrelationY2DCanvas", correlationY2DHisto, "colz");
// Hisograms below not available for DUTs:
if(detectorID == m_config.get<std::string>("DUT")) {
continue;
}
AddCanvas("CorrelationsX", canvas_cx);
AddCanvas("CorrelationsY", canvas_cy);
AddCanvas("CorrelationsX2D", canvas_cx2d);
AddCanvas("CorrelationsY2D", canvas_cy2d);
string residualHisto = "/corryvreckan/BasicTracking/residualsX_" + detectorID;
AddHisto("ResidualCanvas", residualHisto);
}
if(get_detector(m_config.get<std::string>("DUT"))->type() == "CLICpix2") {
AddHisto("DUTCanvas", "/corryvreckan/Clicpix2EventLoader/hitMap", "colz");
AddHisto("DUTCanvas", "/corryvreckan/Clicpix2EventLoader/hitMapDiscarded", "colz");
AddHisto("DUTCanvas", "/corryvreckan/Clicpix2EventLoader/pixelToT");
AddHisto("DUTCanvas", "/corryvreckan/Clicpix2EventLoader/pixelToA");
AddHisto("DUTCanvas", "/corryvreckan/Clicpix2EventLoader/pixelCnt", "", true);
AddHisto("DUTCanvas", "/corryvreckan/Clicpix2EventLoader/pixelsPerFrame", "", true);
AddHisto("DUTCanvas", "/corryvreckan/DUTAnalysis/clusterTotAssociated", "");
AddHisto("DUTCanvas", "/corryvreckan/DUTAnalysis/associatedTracksVersusTime", "");
}
AddCanvas("DUTPlots", canvas_dutplots);
// Set up the main frame before drawing
// Exit button
string exitButton = "StopMonitoring";
gui->buttons[exitButton] = new TGTextButton(gui->buttonMenu, exitButton.c_str());
......@@ -158,8 +129,52 @@ void OnlineMonitor::finalise() {
LOG(DEBUG) << "Analysed " << eventNumber << " events";
}
void OnlineMonitor::AddCanvas(std::string canvas_title, Matrix<std::string> canvas_plots) {
std::string canvas_name = canvas_title + "Canvas";
gui->buttons[canvas_title] = new TGTextButton(gui->buttonMenu, canvas_title.c_str());
gui->buttonMenu->AddFrame(gui->buttons[canvas_title], new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10));
string command = "Display(=\"" + canvas_name + "\")";
LOG(INFO) << "Connecting button with command " << command.c_str();
gui->buttons[canvas_title]->Connect("Pressed()", "corryvreckan::GuiDisplay", gui, command.c_str());
AddPlots(canvas_name, canvas_plots);
}
void OnlineMonitor::AddPlots(std::string canvas_name, Matrix<std::string> canvas_plots) {
for(auto plot : canvas_plots) {
// Add default plotting style if not set:
plot.resize(2, "");
// Do we need to plot with a LogY scale?
bool log_scale = (plot.back().find("log") != std::string::npos) ? true : false;
// Replace other placeholders and add histogram
std::string name = std::regex_replace(plot.front(), std::regex("%DUT%"), m_config.get<std::string>("DUT"));
name = std::regex_replace(name, std::regex("%REFERENCE%"), m_config.get<std::string>("reference"));
// Do we have a detector placeholder?
if(name.find("%DETECTOR%") != std::string::npos) {
LOG(DEBUG) << "Adding plot " << name << " for all detectors.";
for(auto& detector : get_detectors()) {
AddHisto(canvas_name,
std::regex_replace(name, std::regex("%DETECTOR%"), detector->name()),
plot.back(),
log_scale);
}
} else {
// Single histogram only.
AddHisto(canvas_name, name, plot.back(), log_scale);
}
}
}
void OnlineMonitor::AddHisto(string canvasName, string histoName, string style, bool logy) {
// Add "corryvreckan" namespace:
histoName = "/corryvreckan/" + histoName;
TH1* histogram = (TH1*)gDirectory->Get(histoName.c_str());
if(histogram) {
gui->histograms[canvasName].push_back((TH1*)gDirectory->Get(histoName.c_str()));
......@@ -169,11 +184,3 @@ void OnlineMonitor::AddHisto(string canvasName, string histoName, string style,
LOG(WARNING) << "Histogram " << histoName << " does not exist";
}
}
void OnlineMonitor::AddButton(string buttonName, string canvasName) {
gui->buttons[buttonName] = new TGTextButton(gui->buttonMenu, buttonName.c_str());
gui->buttonMenu->AddFrame(gui->buttons[buttonName], new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10));
string command = "Display(=\"" + canvasName + "\")";
LOG(INFO) << "Connecting button with command " << command.c_str();
gui->buttons[buttonName]->Connect("Pressed()", "corryvreckan::GuiDisplay", gui, command.c_str());
}
......@@ -41,13 +41,20 @@ namespace corryvreckan {
TApplication* app;
GuiDisplay* gui;
private:
void AddCanvas(std::string canvas_title, Matrix<std::string> canvas_plots);
void AddPlots(std::string canvas_name, Matrix<std::string> canvas_plots);
void AddHisto(std::string, std::string, std::string style = "", bool logy = false);
void AddButton(std::string, std::string);
// Member variables
int eventNumber;
int updateNumber;
std::string canvasTitle;
// Canvases and their plots:
Matrix<std::string> canvas_dutplots, canvas_overview, canvas_tracking, canvas_hitmaps, canvas_residuals, canvas_cx,
canvas_cy, canvas_cx2d, canvas_cy2d, canvas_charge, canvas_time;
};
} // namespace corryvreckan
#endif // OnlineMonitor_H
# OnlineMonitor
**Maintainer**: Daniel Hynds (<daniel.hynds@cern.ch>)
**Status**: Functional - some minor fixes needed
**Maintainer**: Daniel Hynds (<daniel.hynds@cern.ch>), Simon Spannagel (<simon.spannagel@cern.ch>)
**Status**: Functional
### Description
This module opens a GUI to monitor the progress of Corryvreckan reconstruction. Each canvas contains real time plots of the reconstruction, updated every 500 events. Plots are used from the `BasicTracking` and `TestAlgorithm` modules.
This module opens a GUI to monitor the progress of the reconstruction.
Since Linux allows concurrent (reading) file access, this can already e started while a run is recorded to disk and thus serves as online monitoring tool during data taking.
A set of canvases is available to display a variety of information ranging from hitmaps and basic correlation plots to more advances results such as tracking quality and track angles.
The plots on each of the canvases contain real time data, automatically updated every `update` events.
Users should be able to exit `OnlineMonitor` and leave the reconstruction still running, but currently this causes a crash.
The displayed plots and their source can be configured via the framework configuration file.
Here, each canvas is configured via a matrix containing the path of the plot and its plotting options in each row, e.g.
```toml
DUTPlots = [["Clicpix2EventLoader/hitMap", "colz"],
["Clicpix2EventLoader/pixelCnt", "log"]]
```
The allowed plotting options comprise all drawing options offered by ROOT.
In addition, the `log` keyword is supported, which switches the Y axis of the respective plot to a logarithmic scale.
Several keywords can be used in the plot path, which are parsed and interpreted by the OnlineMonitor module:
* `%DETECTOR%`: If this keyword is found, the plot is added for each of the available detectors by replacing the keyword with the respective detector name.
* `%DUT%`: This keyword is replaced by the vale of the `DUT` configuration key of the framework.
* `%REFERENCE%`: This keyword is replaced by the vale of the `reference` configuration key of the framework.
The "corryvreckan" namespace i not required to be added to the plot path.
### Parameters
* `reference`: Name of the reference plane.
* `update`: Number of events after which to update, defaults to `500`.
* `canvasTitle`: Title of the canvas window to be shown, defaults to `Corryvreckan Testbeam Monitor`.
* `canvasTitle`: Title of the GUI window to be shown, defaults to `Corryvreckan Testbeam Monitor`. This parameter can be used to e.g. display the current run number in the window title.
* `Overview`: List of plots to be placed on the "Overview" canvas of the online monitor. The list of plots created in the default configuration is listed below.
* `DUTPlots`: List of plots to be placed on the "DUTPlots" canvas of the online monitor. By default, this canvas is empty and should be customized for the respective DUT.
* `HitMaps`: List of plots to be placed on the "HitMaps" canvas of the online monitor. By default, this canvas displays `TestAlgorithm/hitmap_%DETECTOR%` for all detectors.
* `Tracking`: List of plots to be placed on the "Tracking" canvas of the online monitor. The list of plots created in the default configuration is listed below.
* `Residuals`: List of plots to be placed on the "Residuals" canvas of the online monitor. By default, this canvas displays `BasicTracking/residualsX_%DETECTOR%` for all detectors.
* `CorrelationX`: List of plots to be placed on the "CorrelationX" canvas of the online monitor. By default, this canvas displays `TestAlgorithm/correlationX_%DETECTOR%` for all detectors.
* `CorrelationY`: List of plots to be placed on the "CorrelationY" canvas of the online monitor. By default, this canvas displays `TestAlgorithm/correlationY_%DETECTOR%` for all detectors.
* `CorrelationX2D`: List of plots to be placed on the "CorrelationX2D" canvas of the online monitor. By default, this canvas displays `TestAlgorithm/correlationX_2Dlocal_%DETECTOR%` for all detectors.
* `CorrelationY2D`: List of plots to be placed on the "CorrelationY2D" canvas of the online monitor. By default, this canvas displays `TestAlgorithm/correlationY_2Dlocal_%DETECTOR%` for all detectors.
* `ChargeDistributions`: List of plots to be placed on the "ChargeDistributions" canvas of the online monitor. By default, this canvas displays `Timepix3Clustering/clusterTot_%DETECTOR%` for all detectors.
* `EventTimes`: List of plots to be placed on the "EventTimes" canvas of the online monitor. By default, this canvas displays `TestAlgorithm/eventTimes_%DETECTOR%` for all detectors.
### Plots produced
Overview canvas:
......@@ -24,20 +56,18 @@ Tracking canvas:
* Track chi^2
* Track angle in X
For each detector the following plots are produced:
* Hitmap canvas: 2D hitmap
* Residuals canvas: residual in X histogram
* Event times canvas: event times histogram
* Correlations X canvas: correlation in X plot
* Correlations Y canvas: correlation in Y plot
* 2D Correlations X canvas: 2D correlation in X plot
* 2D Correlations Y canvas: 2D correlation in Y plot
* Charge distributions canvas: cluster ToT - broken at the moment
### Usage
```toml
[OnlineMonitor]
reference = "W0013_E03"
update = 200
DUTPlots = [["Clicpix2EventLoader/hitMap", "colz"],
[Clicpix2EventLoader/hitMapDiscarded", "colz"],
[Clicpix2EventLoader/pixelToT"],
[Clicpix2EventLoader/pixelToA"],
[Clicpix2EventLoader/pixelCnt", "log"],
[Clicpix2EventLoader/pixelsPerFrame", "log"],
[DUTAnalysis/clusterTotAssociated"],
[DUTAnalysis/associatedTracksVersusTime"]]
```
Parameters to be used in multiple modules can also be defined globally at the top of the configuration file. This is highly encouraged for parameters such as `DUT` and `reference`.
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