REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDataSetPlot.h
1 /*************************************************************************
2  * This file is part of the REST software framework. *
3  * *
4  * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5  * For more information see https://gifna.unizar.es/trex *
6  * *
7  * REST is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * REST is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have a copy of the GNU General Public License along with *
18  * REST in $REST_PATH/LICENSE. *
19  * If not, see https://www.gnu.org/licenses/. *
20  * For the list of contributors see $REST_PATH/CREDITS. *
21  *************************************************************************/
22 
23 #ifndef REST_TRestDataSetPlot
24 #define REST_TRestDataSetPlot
25 
26 #include "THStack.h"
27 #include "TLatex.h"
28 #include "TLegend.h"
29 #include "TRestDataSet.h"
30 #include "TRestMetadata.h"
31 
35  public:
37  struct HistoInfo {
38  std::string name = "";
39  std::string drawOption = "";
40  std::vector<std::string> variable;
41  std::vector<TVector2> range;
42  std::vector<Int_t> nBins;
43  Int_t lineColor;
44  Int_t lineWidth;
45  Int_t lineStyle;
46  Int_t fillColor;
47  Int_t fillStyle;
48  Bool_t statistics = false;
49  TRestCut* histoCut = nullptr;
50  TH1* histo = nullptr;
51  };
52 
54  struct PlotInfo {
55  std::string name = "";
56  std::string title = "";
57 
58  std::string save = "";
59 
60  std::string stackDrawOption = "nostack";
61 
62  Double_t normalize;
63  std::string scale = "";
64  Bool_t logX = false;
65  Bool_t logY = false;
66  Bool_t logZ = false;
67  Bool_t gridX = false;
68  Bool_t gridY = false;
69  Bool_t legendOn = false;
70 
71  Double_t xOffset;
72  Double_t yOffset;
73 
74  Double_t marginLeft;
75  Double_t marginRight;
76  Double_t marginTop;
77  Double_t marginBottom;
78 
79  Bool_t timeDisplay;
80 
81  std::string labelX;
82  std::string labelY;
83 
84  std::vector<HistoInfo> histos;
85 
86  THStack* hs = nullptr;
87  TLegend* legend = nullptr;
88  };
89 
91  struct PanelInfo {
92  Float_t font_size;
93  Int_t precision;
94 
95  std::vector<std::pair<std::array<std::string, 3>, TVector2>> variablePos;
96  std::vector<std::pair<std::array<std::string, 3>, TVector2>> metadataPos;
97  std::vector<std::pair<std::array<std::string, 3>, TVector2>> obsPos;
98  std::vector<std::pair<std::array<std::string, 3>, TVector2>> expPos;
99 
100  TRestCut* panelCut = nullptr;
101 
102  std::vector<TLatex*> text;
103  };
104 
106  private:
108  const std::map<std::string, int> ColorIdMap{{"white", kWhite}, {"black", kBlack}, {"gray", kGray},
109  {"red", kRed}, {"green", kGreen}, {"blue", kBlue},
110  {"yellow", kYellow}, {"magenta", kMagenta}, {"cyan", kCyan},
111  {"orange", kOrange}, {"spring", kSpring}, {"teal", kTeal},
112  {"azure", kAzure}, {"violet", kViolet}, {"pink", kPink}};
113 
115  const std::map<std::string, int> LineStyleMap{
116  {"solid", kSolid}, {"dashed", kDashed}, {"dotted", kDotted}, {"dashDotted", kDashDotted}};
117 
119  const std::map<std::string, int> FillStyleMap{
120  {"dotted", kFDotted1}, {"dashed", kFDashed1}, {"dotted1", kFDotted1},
121  {"dotted2", kFDotted2}, {"dotted3", kFDotted3}, {"hatched1", kFHatched1},
122  {"hatched2", kHatched2}, {"hatched3", kFHatched3}, {"hatched4", kFHatched4},
123  {"wicker", kFWicker}, {"scales", kFScales}, {"bricks", kFBricks},
124  {"snowflakes", kFSnowflakes}, {"circles", kFCircles}, {"tiles", kFTiles},
125  {"mondrian", kFMondrian}, {"diamonds", kFDiamonds}, {"waves1", kFWaves1},
126  {"dashed1", kFDashed1}, {"dashed2", kFDashed2}, {"alhambra", kFAlhambra},
127  {"waves2", kFWaves2}, {"stars1", kFStars1}, {"stars2", kFStars2},
128  {"pyramids", kFPyramids}, {"frieze", kFFrieze}, {"metopes", kFMetopes},
129  {"empty", kFEmpty}, {"solid", kFSolid}};
130 
131  private:
133  std::string fDataSetName = "";
134 
136  std::string fOutputFileName = "";
137 
139  TRestCut* fCut = nullptr;
140 
142  Int_t fPaletteStyle = 57;
143 
145  Bool_t fPreviewPlot = true;
146 
148  Double_t fLegendX1 = 0.7;
149  Double_t fLegendY1 = 0.75;
150  Double_t fLegendX2 = 0.88;
151  Double_t fLegendY2 = 0.88;
152 
154  TVector2 fCanvasSize = TVector2(800, 600);
155  TVector2 fCanvasDivisions = TVector2(2, 2);
156  TVector2 fCanvasDivisionMargins = TVector2(0.01, 0.01);
157 
159  std::vector<PlotInfo> fPlots;
160 
162  std::vector<PanelInfo> fPanels;
163 
164  void InitFromConfigFile() override;
165 
166  public:
167  void Initialize() override;
168  void PrintMetadata() override;
169 
171 
172  void PlotCombinedCanvas();
173 
174  void ReadPlotInfo();
175  void ReadPanelInfo();
176 
177  void CleanUp();
178 
179  TRestCut* ReadCut(TRestCut* cut, TiXmlElement* ele = nullptr);
180  Int_t GetIDFromMapString(const std::map<std::string, int>& mapStr, const std::string& in);
181 
183  TRestDataSetPlot(const char* configFilename, std::string name = "");
185 
186  ClassDefOverride(TRestDataSetPlot, 2);
187 };
188 #endif
A class to help on cuts definitions. To be used with TRestAnalysisTree.
Definition: TRestCut.h:31
Perform the plot over datasets.
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 col...
std::vector< PanelInfo > fPanels
Vector with panels/label options.
TRestCut * ReadCut(TRestCut *cut, TiXmlElement *ele=nullptr)
this function is used to add the different cuts provided in different metadata sections,...
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.
const std::map< std::string, int > LineStyleMap
LineStyleMap as enum "ELineStyle" defined in TAttLine.h.
std::string fDataSetName
Name of the dataset to be imported.
void ReadPlotInfo()
This function reads the config file plot info and stores it in a vector of PlotInfo.
void ReadPanelInfo()
This function reads the config file panel info and stores it in a vector of PanelInfo.
void GenerateDataSetFromFilePattern(TRestDataSet &dataSet)
This functions generates a dataSet based on the information of the rml file. A TRestDataSet is pased ...
Int_t fPaletteStyle
Palette style.
const std::map< std::string, int > FillStyleMap
FillStyleMap as enum "EFillStyle" defined in TAttFill.h.
TRestDataSetPlot()
Default constructor.
TRestCut * fCut
Global cut for the entire dataSet.
Bool_t fPreviewPlot
Preview plot.
const std::map< std::string, int > ColorIdMap
Maps for internal use only.
void PrintMetadata() override
Prints on screen the information about the metadata members of TRestDataSetPlot.
TVector2 fCanvasSize
Canvas options, size, divisions and margins.
std::string fOutputFileName
OutputFileName.
~TRestDataSetPlot()
Default destructor.
Double_t fLegendX1
Legend position and size.
std::vector< PlotInfo > fPlots
Vector with plots/pads options.
void InitFromConfigFile() override
Initialization of specific TRestDataSetPlot members through an RML file.
void CleanUp()
Clean up histos and text but note that the metadata is unchanged.
It allows to group a number of runs that satisfy given metadata conditions.
Definition: TRestDataSet.h:34
A base class for any REST metadata class.
Definition: TRestMetadata.h:74
Nested classes for internal use only.
Auxiliary class for panels/labels.
Auxiliary struct for plots/pads.