REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestAnalysisPlot.h
1 
12 #ifndef RestCore_TRestAnalysisPlot
13 #define RestCore_TRestAnalysisPlot
14 
15 #include <TCanvas.h>
16 #include <TH3D.h>
17 #include <TLatex.h>
18 #include <TRestRun.h>
19 
20 #include "TRestAnalysisTree.h"
21 
22 const int REST_MAX_TAGS = 15;
23 
24 // as enum "EColor" defined in Rtypes.h
25 // as enum "ELineStyle" defined in TAttLine.h
26 // as enum "EFillStyle" defined in TAttFill.h
27 const std::map<std::string, int> ColorIdMap{
28  {"white", kWhite}, {"black", kBlack}, {"gray", kGray}, {"red", kRed}, {"green", kGreen},
29  {"blue", kBlue}, {"yellow", kYellow}, {"magenta", kMagenta}, {"cyan", kCyan}, {"orange", kOrange},
30  {"spring", kSpring}, {"teal", kTeal}, {"azure", kAzure}, {"violet", kViolet}, {"pink", kPink}};
31 const std::map<std::string, int> LineStyleMap{
32  {"solid", kSolid}, {"dashed", kDashed}, {"dotted", kDotted}, {"dashDotted", kDashDotted}};
33 const std::map<std::string, int> FillStyleMap{
34  {"dotted", kFDotted1}, {"dashed", kFDashed1}, {"dotted1", kFDotted1},
35  {"dotted2", kFDotted2}, {"dotted3", kFDotted3}, {"hatched1", kFHatched1},
36  {"hatched2", kHatched2}, {"hatched3", kFHatched3}, {"hatched4", kFHatched4},
37  {"wicker", kFWicker}, {"scales", kFScales}, {"bricks", kFBricks},
38  {"snowflakes", kFSnowflakes}, {"circles", kFCircles}, {"tiles", kFTiles},
39  {"mondrian", kFMondrian}, {"diamonds", kFDiamonds}, {"waves1", kFWaves1},
40  {"dashed1", kFDashed1}, {"dashed2", kFDashed2}, {"alhambra", kFAlhambra},
41  {"waves2", kFWaves2}, {"stars1", kFStars1}, {"stars2", kFStars2},
42  {"pyramids", kFPyramids}, {"frieze", kFFrieze}, {"metopes", kFMetopes},
43  {"empty", kFEmpty}, {"solid", kFSolid}};
44 
46  public:
47  struct HistoInfoSet {
48  std::string name; // will be shown in the legend
49  std::string range; // output histo std::string for TTree::Draw(), e.g. name+range = htemp(100,0,1000)
50  Bool_t status;
51 
52  std::string plotString; // draw std::string for TTree::Draw()
53  std::string cutString; // cut std::string for TTree::Draw()
54  std::string weight;
55  std::map<std::string, std::string>
56  classifyMap; // select the input files to draw the histogram, if their
57  // TRestRun::Get() returns the assumed std::string
58  std::string drawOption; // draw option for TTree::Draw()
59 
60  Int_t lineColor;
61  Int_t lineWidth;
62  Int_t lineStyle;
63  Int_t fillColor;
64  Int_t fillStyle;
65 
66  TH3F* ptr = nullptr;
67  TH3F* operator->() const { return ptr; }
68  };
69 
70  struct PlotInfoSet {
71  std::string name;
72  std::string title;
73 
74  Double_t normalize;
75  std::string scale;
76  Bool_t logX;
77  Bool_t logY;
78  Bool_t logZ;
79  Bool_t gridX;
80  Bool_t gridY;
81  Bool_t staticsOn;
82  Bool_t legendOn;
83  Bool_t annotationOn;
84 
85  Double_t xOffset;
86  Double_t yOffset;
87 
88  Bool_t timeDisplay;
89 
90  std::string labelX;
91  std::string labelY;
92 
93  TVector2 rangeX; // absolute x range(e.g. 1000~3000 keV), same as SetRangeUser()
94  TVector2 rangeY; // absolute y range(e.g. 1000~3000 keV), same as SetRangeUser()
95 
96  Double_t marginLeft;
97  Double_t marginRight;
98  Double_t marginTop;
99  Double_t marginBottom;
100 
101  Int_t ticksX;
102  Int_t ticksY;
103 
104  std::string save;
105 
106  std::vector<HistoInfoSet> histos;
107  };
108 
109  struct PanelInfo {
110  Float_t font_size;
111  Int_t precision;
112 
113  std::vector<Float_t> posX;
114  std::vector<Float_t> posY;
115 
116  std::vector<std::string> label;
117  };
118 
119  private:
120  void InitFromConfigFile() override;
121  HistoInfoSet SetupHistogramFromConfigFile(TiXmlElement* ele, PlotInfoSet info);
122 
123  Int_t fNFiles;
124  // canvas option
125  TVector2 fCanvasSize;
126  TVector2 fCanvasDivisions;
127  TVector2 fCanvasDivisionMargins;
128  TString fCanvasSave;
129  Int_t fPaletteStyle;
130 
131  Int_t fLabelFont;
132  Double_t fLabelOffsetX = 1.1;
133  Double_t fLabelOffsetY = 1.3;
134  Double_t fLabelScaleX = 1.2;
135  Double_t fLabelScaleY = 1.3;
136  Double_t fTicksScaleX = 1.5;
137  Double_t fTicksScaleY = 1.5;
138 
139  Double_t fLegendX1 = 0.7;
140  Double_t fLegendY1 = 0.75;
141  Double_t fLegendX2 = 0.88;
142  Double_t fLegendY2 = 0.88;
143 
144  // plots information
145  std::vector<PlotInfoSet> fPlots;
146  std::vector<PanelInfo> fPanels;
147 
148  std::vector<std::string> fPlotNamesCheck;
149 
150  TRestRun* fRun;
151  std::vector<TString> fRunInputFileName;
152  TCanvas* fCombinedCanvas;
153  Long64_t fDrawNEntries;
154  Long64_t fDrawFirstEntry;
155 
156  void AddFileFromExternalRun();
157  void AddFileFromEnv();
158 
159  TRestAnalysisTree* GetTree(const TString& fileName);
160  TRestRun* GetRunInfo(const TString& fileName);
161  bool IsDynamicRange(const TString& rangeString);
162  Int_t GetColorIDFromString(const std::string& in);
163  Int_t GetFillStyleIDFromString(const std::string& in);
164  Int_t GetLineStyleIDFromString(const std::string& in);
165 
166  protected:
167  public:
168  void Initialize() override;
169 
170  void PrintMetadata() override {}
171 
172  void AddFile(const TString& fileName);
173  void SetFile(const TString& fileName);
174 
175  void SaveCanvasToPDF(const TString& fileName);
176  void SavePlotToPDF(const TString& fileName, Int_t n = 0);
177  void SaveHistoToPDF(const TString& fileName, Int_t nPlot = 0, Int_t nHisto = 0);
178 
179  void SetOutputPlotsFilename(const TString& name) { fCanvasSave = name; }
180 
181  Int_t GetPlotIndex(const TString& plotName);
182  inline TVector2 GetCanvasSize() const { return fCanvasSize; }
183  inline TVector2 GetCanvasDivisions() const { return fCanvasDivisions; }
184 
185  void SetTreeEntryRange(Long64_t NEntries = TTree::kMaxEntries, Long64_t FirstEntry = 0) {
186  fDrawNEntries = NEntries;
187  fDrawFirstEntry = FirstEntry;
188  }
189  void PlotCombinedCanvas();
190 
191  // Constructor
193  TRestAnalysisPlot(const char* configFilename, const char* name = "");
194  // Destructor
195  virtual ~TRestAnalysisPlot();
196 
197  ClassDefOverride(TRestAnalysisPlot, 4);
198 };
199 #endif
void Initialize() override
Making default settings.
Long64_t fDrawNEntries
Output canvas.
std::vector< TString > fRunInputFileName
TRestRun to handle output file.
TCanvas * fCombinedCanvas
TRestRun to handle input file.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
REST core data-saving helper based on TTree.
A base class for any REST metadata class.
Definition: TRestMetadata.h:74
Data provider and manager in REST.
Definition: TRestRun.h:18