REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Loading...
Searching...
No Matches
TRestDataSetPlot Class Reference

Detailed Description

Perform the plot over datasets.

Default constructor.

This class is meant to perform the plots over a TRestDataSet and it is meant to replace TRestAnalysisPlot. A dataset is should be provided as input file in order to perform de plots, in addition the possibility to provide a file pattern is also supported for backward compatibility although this method will be deprecated. The rml file has been modified with respect to TRestAnalysisPlot, major changes are that now a TRestCut must be defined in advance in order to perform the cuts over the dataset, in addition the panel/label metadata has been changed in order to distinguish between metadata, variables or observable values.

The rml file can be splitted in three main blocks that are detailed below;

  • Basic TRestDataSetPlot parameters: global variables to perform the plot such as canvas size, pad divisions, preview or outputFile info.
  • Panel: it defines different labels that will be written in a pad, it accepts different parameters such as metadata info, variable values, and observable values, that can be written in the panel. A cut can be provided to a panel in order to print the info after appliying a particular cut.
  • Plots: It contains the info to produce a plot at the pad level. A plot consists of a set of histograms that can be plot together using THStack, note that only 1D and 2D histograms are supported. The histograms are defined inside the plot metadata section and one or two variables must be provided (1D or 2D histos) besides the range, while a cut can be set at the histogram level.

Basic TRestDataSetPlot parameters

  • name: Name of the TRestDataSetPlot class and canvas.
  • title: Title of the TRestDataSetPlot class and canvas.
  • dataSetName: Name of the dataSet to be used to perform the plots. Note that if this variable is empty, it will use the name of the inputfile provided at restManager.
  • outputFileName: Name of the output file to be generated. Note that if this variable is empty, it will use the name of the outputFile provided at restManager, if still empty no outputFile will we generated. Note that it supports several formats such as root, pdf, eps, jpg,... If the output file is a root file, the different histograms and metadata will be saved besides the canvas.
  • previewPlot: If true the plot (canvas) is displayed and can be modified before saving it.
  • paletteStyle: Style of the palette to be used in all the plots.
  • legendX1: Start position of the legend in the X axis.
  • legendY1: Start position of the legend in the Y axis.
  • legendX2: End position of the legend in the X axis.
  • legendY2: End position of the legend in the Y axis.
  • canvasSize: TVector2 with the size of the canvas in points.
  • canvasDivisions: TVector2 with the divisions of the canvas e.g. (3, 2) --> 3 x 2.

The key addCut can be povided in order to perform the cut to the entire dataSet. Note that the TRestCut must be defined inside the rml and several cuts can be added.

Example of TRestDataSetPlot basic parameters with a set of TRestCuts:

<TRestDataSetPlot name="restplot" title="Basic Plots" previewPlot="true" canvasSize="(1200,1200)"
canvasDivisions="(2,2)" verboseLevel="info">
<addCut name="North"/>
<addCut name="TrackBalance"/>
<TRestCut name="North" verboseLevel="info">
<cut name="c1" variable="alphaTrackAna_originZ" condition="<0"/>
<TRestCut name="TrackBalance" verboseLevel="info">
<cut name="c2" variable="alphaTrackAna_trackBalanceX" condition=">0.9"/>
<cut name="c3" variable="alphaTrackAna_trackBalanceY" condition=">0.9"/>
</TRestDataSetPlot>
A class to help on cuts definitions. To be used with TRestAnalysisTree.
Definition TRestCut.h:31

Panel

Basic panel parameters:

  • font_size: Font size of the entire panel.
  • precision: Precision for the values to be written.
  • delimiter: Delimiter to be used between the label and the value, by default is ": ".
  • value: If true/ON panel is displayed, otherwise is ignored.

Panel keys

Different keys are provided:

  • metadata is meant for the metadata info inside the TRestDataSet (as a RelevantQuantity). They must be written between square brackets, e.g. [TRestRun::fRunTag].
  • variable for a predefined variable.These can be any of entries, runLength (in hours), startTime, endTime, meanRate (in Hz), cuts, panelCuts, cutNames or panelCutNames. They must be written between double square brackets, e.g. [[entries]].
  • observable for the mean value of an observable. They must contain a '_' character in the name in order to be recognized as an observable, e.g. alphaTrackAna_angle.
  • expression for a mathematical expression that can contain any of the previous. You can also use multiple independent mathematical expressions by encapsulating them with brace brackets, e.g. {[[meanRate]]*24*3600} #pm {sqrt([[entries]])/[[runLength]]*24}.

Note that the time-related variables startTime, endTime and runLength (then meanRate too) are obtained from the TRestDataSet and not the RDataFrame of the TRestDataSet, thus they are not afected by the cuts. All the keys have the following parameters:

  • value: Name of the metadata, variable or observable value.
  • label: String of the label that will be written before the observable value.
  • units: String with the units to be appended to the label.
  • x: X position of the label inside the pad
  • y: Y position of the label inside the pad
  • precision: Precision of the value to be written, by default is set to the panel precision. Only valid for expression key. You can use a number or printf-style formatting specifier (e.g. %.3f). If the expression contains multiple values encapsulated with brace brackets, you can independently set the precision for each value by separating them with a comma, e.g. 2,%.3f.

The key addCut can be povided in order to perform the cut to the panel. Note that the TRestCut must be defined inside the rml.

Example of panel rule:

<panel font_size="0.05" precision="3">
<metadata value="[TRestRun::fRunTag]" label="Run tag" x="0.25" y="0.82" />
<variable value="[[entries]]" label="Entries" x="0.25" y="0.58" />
<observable value="alphaTrackAna_angle" label="Mean Angle" units="rad" x="0.25" y="0.01" />
<expression value="cos(alphaTrackAna_angle)^2" label="Cosine of the mean angle" units="" x="0.25"
y="0.12" precision="5" />
<expression value="({[[meanRate]]*24*3600} #pm {sqrt([[entries]])/[[runLength]]*24})" label="Mean
rate: "
units="per day" x="0.05" y="0.54" precision="%g,%.1g" />
<addCut name="Fiducial"/>
</panel>

Plot

Basic plot parameters:

  • name: Name of the plot
  • title: Title of the plot
  • xlabel: Title of the label in the X axis
  • ylabel: Title of the label in the Y axis
  • logX;logY;logZ: If true plot log scale in the corresponding axis (X, Y or Z)
  • gridX;gridY: If true plot grid in the corresponding axis (X or Y)
  • marginLeft;marginRight;marginTop;marginBottom: Margins size
  • legend: If true/ON it plots the legend
  • stackOption: THStack draw option to be used, note that by default is set to NOSTACK
  • timeDisplay: If true/ON time display is set in the X axis
  • norm: Normalization constant in which the plot will be normalized, e.g. use 1 in case you want to normalize by 1.
  • scale: Divide all the histogram bins by a constant given by scale. You may use any mathematical expression in combination with the special keywords: binSize, entries, runLength (in hours) and integral. Adding a scale will make the histogram to be drawn with errors. To avoid this, set parameter option to 'hist' in the histogram.
  • value: If true/ON plot is displayed, otherwise is ignored
  • save: String with the name of the output file in which the plot will be saved in a separated file, several formats are supported (root, pdf, eps, jpg,...)

Histogram:

Use the histo key inside plot to add the plot parameters. You can add as many histograms as you want but note that only 1D and 2D histograms are supported.

  • name: Name of the histogram
  • option: Draw option to be used, note that by default is set to COLZ
  • lineColor: Color of the line used in the histogram.
  • lineWidth: Width of the line used in the histogram.
  • lineStyle: Line style to be used in the histogram.
  • fillStyle: Fill style to used in the histogram.
  • fillColor: Fill color to used in the histogram.
  • stats: If true/ON it plots histogram statistics.

In order to add one or two variables to the histogram please use the variable key. In order to perform a 2D plot you should add two variable keys, where the first one corresponds to the X axis. The variable key has the following parameters:

  • **name**: Name of the observable to be plotted, the observable must be defined inside the dataSet.
  • **range**: TVector2 with the range of the variable to be plotted
  • **nBins**: Number of bins that will be used in the histogram. The key

addCut` can be povided in order to perform the cut to the histogram. Note that the TRestCut must be defined inside the rml.

Example of plot rule:

<plot name="TrackOrigin" title="TrackOrigin" xlabel="X [mm]" ylabel="Y [mm]" save="HitMapUpwards.pdf"
value="ON" >
<histo name="HitMapUpwards" >
<variable name="alphaTrackAna_originX" range="(0,250)" nbins="256" />
<variable name="alphaTrackAna_originY" range="(0,250)" nbins="256" />
<addCut name="Upwards"/>
</histo>
</plot>

Full example

Following example creates one panel and three plots including one or two histograms:

<TRestManager name="alphaTrack" title="alphaTrack" verboseLevel="info">
<TRestDataSetPlot name="alphaTrackPlot" title="Basic Plots for alpha tracks" previewPlot="true"
canvasSize="(1200,1200)" canvasDivisions="(2,2)" verboseLevel="info"
outputFileName="Plots_[TRestRun::fRunTag]_plots.root">
<addCut name="North"/>
<addCut name="TrackBalance"/>
<TRestCut name="North" verboseLevel="info">
<cut name="c1" variable="alphaTrackAna_originZ" condition="<0"/>
<TRestCut name="Fiducial" verboseLevel="info">
<cut name="c2" variable="alphaTrackAna_originX" condition=">20"/>
<cut name="c3" variable="alphaTrackAna_originX" condition="<225"/>
<cut name="c4" variable="alphaTrackAna_originY" condition=">20"/>
<cut name="c5" variable="alphaTrackAna_originY" condition="<225"/>
<TRestCut name="Upwards" verboseLevel="info">
<cut name="c6" variable="alphaTrackAna_downwards" condition="==false"/>
<TRestCut name="Downwards" verboseLevel="info">
<cut name="c7" variable="alphaTrackAna_downwards" condition="==true"/>
<TRestCut name="TrackBalance" verboseLevel="info">
<cut name="c8" variable="alphaTrackAna_trackBalanceX" condition=">0.9"/>
<cut name="c9" variable="alphaTrackAna_trackBalanceY" condition=">0.9"/>
<panel font_size="0.05" precision="3">
<variable label="Summary" x="0.25" y="0.9"/>
<metadata value="[TRestRun::fRunTag]" label="Run tag" x="0.25" y="0.82"/>
<variable value="[[startTime]]" label="Data starts" x="0.25" y="0.74"/>
<variable value="[[endTime]]" label="Data ends" x="0.25" y="0.66"/>
<variable value="[[entries]]" label="Entries" x="0.25" y="0.58"/>
<variable value="[[runLength]]" label="Run duration" units="hours" x="0.25" y="0.50"/>
<observable value="alphaTrackAna_angle" label="Mean Angle" units="rad" x="0.25" y="0.42"/>
<addCut name="Fiducial"/>
</panel>
<plot name="TrackOrigin" title="TrackOrigin" xlabel="X [mm]" ylabel="Y [mm]" save="" value="ON"
stats="ON">
<variable name="alphaTrackAna_originX" range="(0,250)" nbins="256"/>
<variable name="alphaTrackAna_originY" range="(0,250)" nbins="256"/>
</plot>
<plot name="Spectra" title="Spectra" xlabel="Amplitude(ADC)" ylabel="Counts" legend="ON" value="ON"
save="Spectra.pdf">
<histo name="SpectraDownwards">
<variable name="alphaTrackAna_totalEnergy" range="(0,1000000)" nbins="200"/>
<addCut name="Fiducial"/>
<addCut name="Downwards"/>
</histo>
<histo name="SpectraUpwards">
<variable name="alphaTrackAna_totalEnergy" range="(0,1000000)" nbins="200"/>
<parameter name="lineColor" value="1"/>
<addCut name="Fiducial"/>
<addCut name="Upwards"/>
</histo>
</plot>
<plot name="Rate" title="Rate" xlabel="Date/time" ylabel="Rate (Hz)" legend="ON" value="ON"
scale="binSize" timeDisplay="ON">
<histo name="RateDownwards">
<variable name="timeStamp" range="" nbins="100"/>
<addCut name="Downwards"/>
</histo>
<histo name="RateUpwards">
<variable name="timeStamp" range="" nbins="100"/>
<parameter name="lineColor" value="1"/>
<addCut name="Upwards"/>
</histo>
</plot>
</TRestDataSetPlot>
<addTask command="alphaTrackPlot->PlotCombinedCanvas()" value="ON"/>
Managing applications and executing tasks.

Running example

restManager --c thisExample.rml --f FileWithDataSet.root

Figure to be added (a png image should be uploaded to the ./images/ directory)


REST-for-Physics - Software for Rare Event Searches Toolkit

History of developments:

2023-04: First implementation of TRestDataSetPlot, based on TRestAnalysisPlot JuanAn Garcia

2024-05: Extend some functionalities, Álvaro Ezquerro

Author
: JuanAn Garcia e-mail: juana.nosp@m.ngp@.nosp@m.uniza.nosp@m.r.es

ClassImp(TRestDataSetPlot); */

/**

Definition at line 33 of file TRestDataSetPlot.h.

#include <TRestDataSetPlot.h>

Inheritance diagram for TRestDataSetPlot:
TRestMetadata

Data Structures

struct  HistoInfo
 Nested classes for internal use only. More...
struct  PanelInfo
 Auxiliary class for panels/labels. More...
struct  PlotInfo
 Auxiliary struct for plots/pads. More...

Public Member Functions

 ClassDefOverride (TRestDataSetPlot, 3)
void CleanUp ()
 Clean up histos and text but note that the metadata is unchanged.
void GenerateDataSetFromFilePattern (TRestDataSet &dataSet)
 This functions generates a dataSet based on the information of the rml file. A TRestDataSet is pased as reference and will be overwritten.
Int_t GetIDFromMapString (const std::map< std::string, int > &mapStr, const std::string &in)
 This functions gets the ID from a map string that is passed by reference. It is used to translate colors, line styles and fill styles from the string to an integer value.
void Initialize () override
 Function to initialize input/output event members and define the section name.
void PlotCombinedCanvas ()
 This functions performs the plot of the combined canvas with the different panels and plots.
void PrintMetadata () override
 Prints on screen the information about the metadata members of TRestDataSetPlot.
TRestCut * ReadCut (TRestCut *cut, TiXmlElement *ele=nullptr)
 this function is used to add the different cuts provided in different metadata sections, it uses as parameter the cut where the cut is meant to be added and returns the added cut. If *cut is a nullptr it just instantiate it
void ReadPanelInfo ()
 This function reads the config file panel info and stores it in a vector of PanelInfo.
void ReadPlotInfo ()
 This function reads the config file plot info and stores it in a vector of PlotInfo.
 TRestDataSetPlot (const char *configFilename, std::string name="")
 Constructor loading data from a config file.
 ~TRestDataSetPlot ()
 Default destructor.

Private Member Functions

void InitFromConfigFile () override
 Initialization of specific TRestDataSetPlot members through an RML file.

Private Attributes

const std::map< std::string, int > ColorIdMap
 Maps for internal use only.
TVector2 fCanvasDivisionMargins = TVector2(0.01, 0.01)
TVector2 fCanvasDivisions = TVector2(2, 2)
TVector2 fCanvasSize = TVector2(800, 600)
 Canvas options, size, divisions and margins.
TRestCut * fCut = nullptr
 Global cut for the entire dataSet.
std::string fDataSetName = ""
 Name of the dataset to be imported.
const std::map< std::string, int > FillStyleMap
 FillStyleMap as enum "EFillStyle" defined in TAttFill.h.
Double_t fLegendX1 = 0.7
 Legend position and size.
Double_t fLegendX2 = 0.88
Double_t fLegendY1 = 0.75
Double_t fLegendY2 = 0.88
std::string fOutputFileName = ""
 OutputFileName.
Int_t fPaletteStyle = 57
 Palette style.
std::vector< PanelInfo > fPanels
 Vector with panels/label options.
std::vector< PlotInfo > fPlots
 Vector with plots/pads options.
Bool_t fPreviewPlot = true
 Preview plot.
const std::map< std::string, int > LineStyleMap
 LineStyleMap as enum "ELineStyle" defined in TAttLine.h.

Additional Inherited Members

Constructor & Destructor Documentation

◆ TRestDataSetPlot() [1/2]

TRestDataSetPlot::TRestDataSetPlot ( )

Definition at line 304 of file TRestDataSetPlot.cxx.

◆ TRestDataSetPlot() [2/2]

TRestDataSetPlot::TRestDataSetPlot ( const char * configFilename,
std::string name = "" )

Constructor loading data from a config file.

Definition at line 309 of file TRestDataSetPlot.cxx.

◆ ~TRestDataSetPlot()

TRestDataSetPlot::~TRestDataSetPlot ( )

Default destructor.

Definition at line 319 of file TRestDataSetPlot.cxx.

Member Function Documentation

◆ CleanUp()

void TRestDataSetPlot::CleanUp ( )

Clean up histos and text but note that the metadata is unchanged.

Definition at line 1015 of file TRestDataSetPlot.cxx.

◆ GenerateDataSetFromFilePattern()

void TRestDataSetPlot::GenerateDataSetFromFilePattern ( TRestDataSet & dataSet)

This functions generates a dataSet based on the information of the rml file. A TRestDataSet is pased as reference and will be overwritten.

Definition at line 527 of file TRestDataSetPlot.cxx.

◆ GetIDFromMapString()

Int_t TRestDataSetPlot::GetIDFromMapString ( const std::map< std::string, int > & mapStr,
const std::string & in )

This functions gets the ID from a map string that is passed by reference. It is used to translate colors, line styles and fill styles from the string to an integer value.

Definition at line 1037 of file TRestDataSetPlot.cxx.

◆ InitFromConfigFile()

void TRestDataSetPlot::InitFromConfigFile ( )
overrideprivatevirtual

Initialization of specific TRestDataSetPlot members through an RML file.

Reimplemented from TRestMetadata.

Definition at line 330 of file TRestDataSetPlot.cxx.

◆ Initialize()

void TRestDataSetPlot::Initialize ( )
overridevirtual

Function to initialize input/output event members and define the section name.

Reimplemented from TRestMetadata.

Definition at line 325 of file TRestDataSetPlot.cxx.

◆ PlotCombinedCanvas()

void TRestDataSetPlot::PlotCombinedCanvas ( )

This functions performs the plot of the combined canvas with the different panels and plots.

Build the histograms and add them to the THStack

Definition at line 626 of file TRestDataSetPlot.cxx.

◆ PrintMetadata()

void TRestDataSetPlot::PrintMetadata ( )
overridevirtual

Prints on screen the information about the metadata members of TRestDataSetPlot.

Reimplemented from TRestMetadata.

Definition at line 1053 of file TRestDataSetPlot.cxx.

◆ ReadCut()

TRestCut * TRestDataSetPlot::ReadCut ( TRestCut * cut,
TiXmlElement * ele = nullptr )

this function is used to add the different cuts provided in different metadata sections, it uses as parameter the cut where the cut is meant to be added and returns the added cut. If *cut is a nullptr it just instantiate it

Definition at line 348 of file TRestDataSetPlot.cxx.

◆ ReadPanelInfo()

void TRestDataSetPlot::ReadPanelInfo ( )

This function reads the config file panel info and stores it in a vector of PanelInfo.

Definition at line 369 of file TRestDataSetPlot.cxx.

◆ ReadPlotInfo()

void TRestDataSetPlot::ReadPlotInfo ( )

This function reads the config file plot info and stores it in a vector of PlotInfo.

Definition at line 449 of file TRestDataSetPlot.cxx.

Field Documentation

◆ ColorIdMap

const std::map<std::string, int> TRestDataSetPlot::ColorIdMap
private
Initial value:
{{"white", kWhite}, {"black", kBlack}, {"gray", kGray},
{"red", kRed}, {"green", kGreen}, {"blue", kBlue},
{"yellow", kYellow}, {"magenta", kMagenta}, {"cyan", kCyan},
{"orange", kOrange}, {"spring", kSpring}, {"teal", kTeal},
{"azure", kAzure}, {"violet", kViolet}, {"pink", kPink}}

Maps for internal use only.

ColorIdMap as enum "EColor" defined in Rtypes.h

Definition at line 109 of file TRestDataSetPlot.h.

◆ fCanvasDivisionMargins

TVector2 TRestDataSetPlot::fCanvasDivisionMargins = TVector2(0.01, 0.01)
private

Definition at line 157 of file TRestDataSetPlot.h.

◆ fCanvasDivisions

TVector2 TRestDataSetPlot::fCanvasDivisions = TVector2(2, 2)
private

Definition at line 156 of file TRestDataSetPlot.h.

◆ fCanvasSize

TVector2 TRestDataSetPlot::fCanvasSize = TVector2(800, 600)
private

Canvas options, size, divisions and margins.

Definition at line 155 of file TRestDataSetPlot.h.

◆ fCut

TRestCut* TRestDataSetPlot::fCut = nullptr
private

Global cut for the entire dataSet.

Definition at line 140 of file TRestDataSetPlot.h.

◆ fDataSetName

std::string TRestDataSetPlot::fDataSetName = ""
private

Name of the dataset to be imported.

Definition at line 134 of file TRestDataSetPlot.h.

◆ FillStyleMap

const std::map<std::string, int> TRestDataSetPlot::FillStyleMap
private
Initial value:
{
{"dotted", kFDotted1}, {"dashed", kFDashed1}, {"dotted1", kFDotted1},
{"dotted2", kFDotted2}, {"dotted3", kFDotted3}, {"hatched1", kFHatched1},
{"hatched2", kHatched2}, {"hatched3", kFHatched3}, {"hatched4", kFHatched4},
{"wicker", kFWicker}, {"scales", kFScales}, {"bricks", kFBricks},
{"snowflakes", kFSnowflakes}, {"circles", kFCircles}, {"tiles", kFTiles},
{"mondrian", kFMondrian}, {"diamonds", kFDiamonds}, {"waves1", kFWaves1},
{"dashed1", kFDashed1}, {"dashed2", kFDashed2}, {"alhambra", kFAlhambra},
{"waves2", kFWaves2}, {"stars1", kFStars1}, {"stars2", kFStars2},
{"pyramids", kFPyramids}, {"frieze", kFFrieze}, {"metopes", kFMetopes},
{"empty", kFEmpty}, {"solid", kFSolid}}

FillStyleMap as enum "EFillStyle" defined in TAttFill.h.

Definition at line 120 of file TRestDataSetPlot.h.

◆ fLegendX1

Double_t TRestDataSetPlot::fLegendX1 = 0.7
private

Legend position and size.

Definition at line 149 of file TRestDataSetPlot.h.

◆ fLegendX2

Double_t TRestDataSetPlot::fLegendX2 = 0.88
private

Definition at line 151 of file TRestDataSetPlot.h.

◆ fLegendY1

Double_t TRestDataSetPlot::fLegendY1 = 0.75
private

Definition at line 150 of file TRestDataSetPlot.h.

◆ fLegendY2

Double_t TRestDataSetPlot::fLegendY2 = 0.88
private

Definition at line 152 of file TRestDataSetPlot.h.

◆ fOutputFileName

std::string TRestDataSetPlot::fOutputFileName = ""
private

OutputFileName.

Definition at line 137 of file TRestDataSetPlot.h.

◆ fPaletteStyle

Int_t TRestDataSetPlot::fPaletteStyle = 57
private

Palette style.

Definition at line 143 of file TRestDataSetPlot.h.

◆ fPanels

std::vector<PanelInfo> TRestDataSetPlot::fPanels
private

Vector with panels/label options.

Definition at line 163 of file TRestDataSetPlot.h.

◆ fPlots

std::vector<PlotInfo> TRestDataSetPlot::fPlots
private

Vector with plots/pads options.

Definition at line 160 of file TRestDataSetPlot.h.

◆ fPreviewPlot

Bool_t TRestDataSetPlot::fPreviewPlot = true
private

Preview plot.

Definition at line 146 of file TRestDataSetPlot.h.

◆ LineStyleMap

const std::map<std::string, int> TRestDataSetPlot::LineStyleMap
private
Initial value:
{
{"solid", kSolid}, {"dashed", kDashed}, {"dotted", kDotted}, {"dashDotted", kDashDotted}}

LineStyleMap as enum "ELineStyle" defined in TAttLine.h.

Definition at line 116 of file TRestDataSetPlot.h.


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