REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Data Structures | Public Member Functions | Private Member Functions | Private Attributes
TRestMetadataPlot Class Reference

Detailed Description

A helper class to draw the evolution or correlation of metadata information from a set of REST files.

TRestMetadataPlot will allow to take a set or range of files and create TGraph objects with any two metadata members defined in any metadata class inside the REST-ROOT processed files. The class TRestMetadataPlot works in a similar way to TRestAnalysisPlot. While TRestAnalysisPlot serves to draw and combine data from different event observables found at the TRestAnalysisTree, TRestMetadataPlot is used to draw and correlate the metadata information that is found at different metadata classes inside TRestRun.

1. Adding REST files for plotting

This class can be initialized through a RML configuration file where we define the different plots and graphs to be produced. The files that will be used for plot generation can be added to the class using the restManager command as follows:

restManager --c mdPlots.rml --f "/full/or/relative/path/to/data/R012*Hits*.root"

The previous execution will search for the files matching the given pattern, at the path given. I.e. it will collect all the files with run number starting by 012 and containing Hits inside its name.

Each of the files on the filelist produced will be used to generate one point at the graphs defined inside the mdPlots.rml file.

The metadata variables can be specified at the graphs or plots by using the following format TRestMetadataClass::fMetadataMember or TRestMetadataClass->fMetadataMember. Where TRestMetadataClass is the name of the class/object or the name ROOT name associated to the class, and that it is usually retrieved using the method GetName().

2. writing the RML metadata section

The RML section allows to define the main properties of the canvas to be generated, basic or common properties of each plot, and the definition of the plots description and graph properties together with the specification of the metadata to be used in the graph. A working example with minimum modifications can be found at examples/metadataPlot.rml.

This metadata class receives only an optional parameter, previewPlot, that is true by default if it has not been defined. If this parameter is true it will show the produced canvas on screen, and the user will be allowed to interact with it. If not, plots will be just written to disk as defined by the parameter save defined in the main canvas, or in separate plots.

Canvas definition

The canvas will be divided in different pads where the plots defined inside this class will be placed. The canvas section allows us to define the size of the canvas in pixels, how it will be divided, and optionally the file where it will be saved. It is important to notice that the number of pad divisions must be enough to host the total number of plots given.

<canvas size="(1000,400)" divide="(1,1)" save="/tmp/canvas.png"/>

Legend properties

If we use a legend in our plots, we can define its properties and position using the legend key.

An example, of definition of the legend key. The ROOT drawing option lp is used to draw the line and the point. Please, check the documentation of TLegend for other available options.

<legendPosition x1="0.25" x2="0.5" y1="0.5" y2="0.65" option="lp" />
Warning
For the moment this entry is common to all the plots, althought it would be desirable that in the future we are allowed to define the legend properties for each single plot independently. The positions are defined with coordinates relative to the pad using the ROOT object TLegend.

Plot properties

Inside a TRestMetadataPlot RML section we are allowed to define any number of plots, and inside a graph we are allowed to define any number of graphs.

The only mandatory field inside the plot description is the xVariable to be used on the x-axis of the resulting plot.

The parameters that can be defined (see also TRestMetadataPlot::Plot_Info_Set) inside each <plot section are:

Note
As previously mentioned, the xVariable must be a valid metadata member. However, there is one exception where we are allowed to use the timestamp keyword so that the middle time of each run is used on the x-axis.

Graph properties

Inside each plot we can define any number of graphs to be plotted together. Each graph must define a unique name and the corresponding yVariable to be used on the graph data. Those fields are mandatory.

The parameters that can be defined inside each <graph section are:

Including metadata rules, or conditions

When we provide a set of files we may filter the input files passed to the class to create a selection that will follow a certain condition or metadata rule. Only the files fulfilling the given conditions will contribute to the TGraph.

In order to use this feature we need to define the metadataRule parameter specifying the condition to be satisfied. Any numerical operator is allowed, as well as direct string comparison.

The following line inside the <graph definition would force the corresponding graph to include points extracted only from files where the fRunTag metadata member is equal to `Calibration_BIPO`.

<parameter name="metadataRule" value="TRestRun->fRunTag==Calibration_BIPO" />
Warning
for the moment the conditions can be applied to a single metadata member. Or in other words, we cannot create a metadata rule based on the combination of different conditions on different metadata parameters.

Adding panels

Additionally, we can add a pad to the canvas containing basic information. As it is implemented, this panel will only be able to gather the run information from the first file given in the filelist. Therefore it might be useful to show only information common to all the files.

The panel is built defining labels where metadata members given between << >> are replaced by the corresponding run values.

<panel font_size="0.06">
<label value="Run number : <<TRestRun::fRunNumber>>" x="0.25" y="0.9" />
...

The panel it is given at the same level as the <plot, as it will fill a given pad region inside the canvas. Additional keywords are available, and calculated inside the class with all the files passed. Those keywords are also enclosed between << >>, and are the following ones:

Note
All panels will be always placed at the first pads of the canvas, independently of the order given inside the RML file.

RESTsoft - Software for Rare Event Searches with TPCs

History of developments:

2020-June: First concept and implementation

Author
Javier Galan

Definition at line 32 of file TRestMetadataPlot.h.

#include <TRestMetadataPlot.h>

Inheritance diagram for TRestMetadataPlot:
TRestMetadata

Data Structures

struct  Graph_Info_Set
 This structure is used to register the values from a <graph definition inside the RML. More...
 
struct  Panel_Info
 This structure is used to register the values from a <panel definition inside the RML. More...
 
struct  Plot_Info_Set
 This structure is used to register the values from a <plot definition inside the RML. More...
 

Public Member Functions

 ClassDefOverride (TRestMetadataPlot, 3)
 
void GenerateCanvas ()
 The main method of this class, collecting the input files, producing the TGraphs and generating the plots inside the main canvas.
 
TVector2 GetCanvasDivisions () const
 It will return the number of divisions inside the canvas.
 
TVector2 GetCanvasSize () const
 It will return the canvas size in pixel units.
 
Int_t GetPlotIndex (TString plotName)
 It returns the index of the array correspoding to the plot with the given plotName.
 
void Initialize () override
 Initialization of TRestMetadataPlot data members.
 
void PrintMetadata () override
 Implemented it in the derived metadata class to print out specific metadata information. More...
 
void SaveCanvasToPDF (TString fileName)
 A method to execute the generation of an output file with the contents of the TCanvas as it is. The name of the output file is given through the argument.
 
void SaveGraphToPDF (TString fileName, Int_t nPlot=0, Int_t nGraph=0)
 A method to execute the generation of a particular graph from a plot inside the canvas using the index of the plot, and the index of the graph. The name of the output file is given through the argument.
 
void SavePlotToPDF (TString fileName, Int_t n=0)
 A method to execute the generation of a plot inside the canvas using the index of the plot. The name of the output file is given through the argument.
 
void SetOutputPlotsFilename (TString fname)
 It will set the filename of the plots output file to be generated when GenerateCanvas is called.
 
 TRestMetadataPlot ()
 Default constructor.
 
 TRestMetadataPlot (const char *configFilename, const char *name="")
 Constructor loading data from a config file. More...
 
virtual ~TRestMetadataPlot ()
 Default destructor.
 

Private Member Functions

void AddFile (TString fileName)
 It creates a new TRestRun object extracted from the fileName, and it adds it to the list of input files beloning to this class.
 
void AddFileFromEnv ()
 We can add input file from parameter "inputFile".
 
void AddFileFromExternalRun ()
 We can add input file from process's output file.
 
void InitFromConfigFile () override
 Initialization of TRestMetadataPlot members through a RML file.
 
Graph_Info_Set SetupGraphFromConfigFile (TiXmlElement *ele, Plot_Info_Set info)
 It fills the components of a Graph_Info_set object using the definition inside a <graph element.
 

Private Attributes

TVector2 fCanvasDivisions
 The number of canvas divisions on X and Y.
 
TString fCanvasSave
 A std::string to define the output filename where to store the canvas.
 
TVector2 fCanvasSize
 The size of the canvas window in pixels.
 
TCanvas * fCombinedCanvas
 Output canvas.
 
Int_t fLabelFont
 The font label size.
 
Double_t fLabelOffsetX = 1.1
 A label offset to be applied in the x-label (not tested)
 
Double_t fLabelOffsetY = 1.3
 A label offset to be applied in the y-label (not tested)
 
Double_t fLabelScaleX = 1.2
 A label title scale to be applied in the x-label (not tested)
 
Double_t fLabelScaleY = 1.3
 A label title scale to be applied in the y-label (not tested)
 
TString fLegendOption = "lp"
 The legend drawing option.
 
Double_t fLegendX1 = 0.7
 The X1 legend position.
 
Double_t fLegendX2 = 0.88
 The X2 legend position.
 
Double_t fLegendY1 = 0.75
 The Y1 legend position.
 
Double_t fLegendY2 = 0.88
 The Y2 legend position.
 
Int_t fNFiles
 The total number of files for plotting added to this class.
 
std::vector< Panel_InfofPanels
 A std::vector with the defined panels.
 
std::vector< std::string > fPlotNamesCheck
 A std::vector to double check that there are no repeated graph names.
 
std::vector< Plot_Info_SetfPlots
 A std::vector with the defined plots.
 
TRestRunfRun
 TRestRun to handle output file.
 
std::vector< std::string > fRunInputFileName
 To keep a list of files used.
 
Double_t fTicksScaleX = 1.5
 A label ticks scale to be applied in the x-label (not tested)
 
Double_t fTicksScaleY = 1.5
 A label ticks scale to be applied in the y-label (not tested)
 

Additional Inherited Members

Constructor & Destructor Documentation

◆ TRestMetadataPlot()

TRestMetadataPlot::TRestMetadataPlot ( const char *  configFilename,
const char *  name = "" 
)

Constructor loading data from a config file.

If no configuration path is defined using TRestMetadata::SetConfigFilePath the path to the config file must be specified using full path, absolute or relative.

The default behaviour is that the config file must be specified with full path, absolute or relative.

Parameters
configFilenameA const char* giving the path to an RML file.
nameThe name of the specific metadata. It will be used to find the corresponding TRestGeant4Metadata section inside the RML.

Definition at line 268 of file TRestMetadataPlot.cxx.

Member Function Documentation

◆ PrintMetadata()

void TRestMetadataPlot::PrintMetadata ( )
inlineoverridevirtual

Implemented it in the derived metadata class to print out specific metadata information.

Prints metadata content on screen. Usually overloaded by the derived metadata class.

Reimplemented from TRestMetadata.

Definition at line 178 of file TRestMetadataPlot.h.


The documentation for this class was generated from the following files: