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.

A plot generated with TRestMetadataPlot using the example metadataPlot.rml

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:

An example of panel information generated using the <panel section
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. More...
 
TVector2 GetCanvasDivisions () const
 It will return the number of divisions inside the canvas. More...
 
TVector2 GetCanvasSize () const
 It will return the canvas size in pixel units. More...
 
Int_t GetPlotIndex (TString plotName)
 It returns the index of the array correspoding to the plot with the given plotName. More...
 
void Initialize () override
 Initialization of TRestMetadataPlot data members. More...
 
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. More...
 
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. More...
 
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. More...
 
void SetOutputPlotsFilename (TString fname)
 It will set the filename of the plots output file to be generated when GenerateCanvas is called. More...
 
 TRestMetadataPlot ()
 Default constructor. More...
 
 TRestMetadataPlot (const char *configFilename, const char *name="")
 Constructor loading data from a config file. More...
 
virtual ~TRestMetadataPlot ()
 Default destructor. More...
 

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. More...
 
void AddFileFromEnv ()
 We can add input file from parameter "inputFile". More...
 
void AddFileFromExternalRun ()
 We can add input file from process's output file. More...
 
void InitFromConfigFile () override
 Initialization of TRestMetadataPlot members through a RML file. More...
 
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. More...
 

Private Attributes

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

Additional Inherited Members

Constructor & Destructor Documentation

◆ TRestMetadataPlot() [1/2]

TRestMetadataPlot::TRestMetadataPlot ( )

Default constructor.

Definition at line 252 of file TRestMetadataPlot.cxx.

◆ TRestMetadataPlot() [2/2]

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.

◆ ~TRestMetadataPlot()

TRestMetadataPlot::~TRestMetadataPlot ( )
virtual

Default destructor.

Definition at line 278 of file TRestMetadataPlot.cxx.

Member Function Documentation

◆ AddFile()

void TRestMetadataPlot::AddFile ( TString  fileName)
private

It creates a new TRestRun object extracted from the fileName, and it adds it to the list of input files beloning to this class.

Definition at line 534 of file TRestMetadataPlot.cxx.

◆ AddFileFromEnv()

void TRestMetadataPlot::AddFileFromEnv ( )
private

We can add input file from parameter "inputFile".

Definition at line 566 of file TRestMetadataPlot.cxx.

◆ AddFileFromExternalRun()

void TRestMetadataPlot::AddFileFromExternalRun ( )
private

We can add input file from process's output file.

Definition at line 546 of file TRestMetadataPlot.cxx.

◆ GenerateCanvas()

void TRestMetadataPlot::GenerateCanvas ( )

The main method of this class, collecting the input files, producing the TGraphs and generating the plots inside the main canvas.

Definition at line 591 of file TRestMetadataPlot.cxx.

◆ GetCanvasDivisions()

TVector2 TRestMetadataPlot::GetCanvasDivisions ( ) const
inline

It will return the number of divisions inside the canvas.

Definition at line 193 of file TRestMetadataPlot.h.

◆ GetCanvasSize()

TVector2 TRestMetadataPlot::GetCanvasSize ( ) const
inline

It will return the canvas size in pixel units.

Definition at line 190 of file TRestMetadataPlot.h.

◆ GetPlotIndex()

Int_t TRestMetadataPlot::GetPlotIndex ( TString  plotName)

It returns the index of the array correspoding to the plot with the given plotName.

Definition at line 579 of file TRestMetadataPlot.cxx.

◆ InitFromConfigFile()

void TRestMetadataPlot::InitFromConfigFile ( )
overrideprivatevirtual

Initialization of TRestMetadataPlot members through a RML file.

Reimplemented from TRestMetadata.

Definition at line 300 of file TRestMetadataPlot.cxx.

◆ Initialize()

void TRestMetadataPlot::Initialize ( )
overridevirtual

Initialization of TRestMetadataPlot data members.

Reimplemented from TRestMetadata.

Definition at line 285 of file TRestMetadataPlot.cxx.

◆ 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.

◆ SaveCanvasToPDF()

void TRestMetadataPlot::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.

Definition at line 956 of file TRestMetadataPlot.cxx.

◆ SaveGraphToPDF()

void TRestMetadataPlot::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.

Definition at line 991 of file TRestMetadataPlot.cxx.

◆ SavePlotToPDF()

void TRestMetadataPlot::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.

Definition at line 962 of file TRestMetadataPlot.cxx.

◆ SetOutputPlotsFilename()

void TRestMetadataPlot::SetOutputPlotsFilename ( TString  fname)
inline

It will set the filename of the plots output file to be generated when GenerateCanvas is called.

Definition at line 185 of file TRestMetadataPlot.h.

◆ SetupGraphFromConfigFile()

TRestMetadataPlot::Graph_Info_Set TRestMetadataPlot::SetupGraphFromConfigFile ( TiXmlElement *  ele,
Plot_Info_Set  info 
)
private

It fills the components of a Graph_Info_set object using the definition inside a <graph element.

Definition at line 494 of file TRestMetadataPlot.cxx.

Field Documentation

◆ fCanvasDivisions

TVector2 TRestMetadataPlot::fCanvasDivisions
private

The number of canvas divisions on X and Y.

Definition at line 117 of file TRestMetadataPlot.h.

◆ fCanvasSave

TString TRestMetadataPlot::fCanvasSave
private

A std::string to define the output filename where to store the canvas.

Definition at line 120 of file TRestMetadataPlot.h.

◆ fCanvasSize

TVector2 TRestMetadataPlot::fCanvasSize
private

The size of the canvas window in pixels.

Definition at line 114 of file TRestMetadataPlot.h.

◆ fCombinedCanvas

TCanvas* TRestMetadataPlot::fCombinedCanvas
private

Output canvas.

Definition at line 168 of file TRestMetadataPlot.h.

◆ fLabelFont

Int_t TRestMetadataPlot::fLabelFont
private

The font label size.

Definition at line 123 of file TRestMetadataPlot.h.

◆ fLabelOffsetX

Double_t TRestMetadataPlot::fLabelOffsetX = 1.1
private

A label offset to be applied in the x-label (not tested)

Definition at line 126 of file TRestMetadataPlot.h.

◆ fLabelOffsetY

Double_t TRestMetadataPlot::fLabelOffsetY = 1.3
private

A label offset to be applied in the y-label (not tested)

Definition at line 128 of file TRestMetadataPlot.h.

◆ fLabelScaleX

Double_t TRestMetadataPlot::fLabelScaleX = 1.2
private

A label title scale to be applied in the x-label (not tested)

Definition at line 131 of file TRestMetadataPlot.h.

◆ fLabelScaleY

Double_t TRestMetadataPlot::fLabelScaleY = 1.3
private

A label title scale to be applied in the y-label (not tested)

Definition at line 133 of file TRestMetadataPlot.h.

◆ fLegendOption

TString TRestMetadataPlot::fLegendOption = "lp"
private

The legend drawing option.

Definition at line 150 of file TRestMetadataPlot.h.

◆ fLegendX1

Double_t TRestMetadataPlot::fLegendX1 = 0.7
private

The X1 legend position.

Definition at line 141 of file TRestMetadataPlot.h.

◆ fLegendX2

Double_t TRestMetadataPlot::fLegendX2 = 0.88
private

The X2 legend position.

Definition at line 145 of file TRestMetadataPlot.h.

◆ fLegendY1

Double_t TRestMetadataPlot::fLegendY1 = 0.75
private

The Y1 legend position.

Definition at line 143 of file TRestMetadataPlot.h.

◆ fLegendY2

Double_t TRestMetadataPlot::fLegendY2 = 0.88
private

The Y2 legend position.

Definition at line 147 of file TRestMetadataPlot.h.

◆ fNFiles

Int_t TRestMetadataPlot::fNFiles
private

The total number of files for plotting added to this class.

Definition at line 111 of file TRestMetadataPlot.h.

◆ fPanels

std::vector<Panel_Info> TRestMetadataPlot::fPanels
private

A std::vector with the defined panels.

Definition at line 156 of file TRestMetadataPlot.h.

◆ fPlotNamesCheck

std::vector<std::string> TRestMetadataPlot::fPlotNamesCheck
private

A std::vector to double check that there are no repeated graph names.

Definition at line 159 of file TRestMetadataPlot.h.

◆ fPlots

std::vector<Plot_Info_Set> TRestMetadataPlot::fPlots
private

A std::vector with the defined plots.

Definition at line 153 of file TRestMetadataPlot.h.

◆ fRun

TRestRun* TRestMetadataPlot::fRun
private

TRestRun to handle output file.

Definition at line 162 of file TRestMetadataPlot.h.

◆ fRunInputFileName

std::vector<std::string> TRestMetadataPlot::fRunInputFileName
private

To keep a list of files used.

Definition at line 165 of file TRestMetadataPlot.h.

◆ fTicksScaleX

Double_t TRestMetadataPlot::fTicksScaleX = 1.5
private

A label ticks scale to be applied in the x-label (not tested)

Definition at line 136 of file TRestMetadataPlot.h.

◆ fTicksScaleY

Double_t TRestMetadataPlot::fTicksScaleY = 1.5
private

A label ticks scale to be applied in the y-label (not tested)

Definition at line 138 of file TRestMetadataPlot.h.


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