GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
GCanvas.h
Go to the documentation of this file.
1#ifndef GRUTCANVAS_H
2#define GRUTCANVAS_H
3
4#include "TROOT.h"
5#include "TCanvas.h"
6#include "TRootCanvas.h"
7
8#include "TH1.h"
9#include "TLine.h"
10#include "TCutG.h"
11
12#include "GH2I.h"
13
14/** \addtogroup GROOT
15 * @{
16 */
17
18///////////////////////////////////////////////////////////////////////////
19///
20/// \class GMarker
21///
22///////////////////////////////////////////////////////////////////////////
23
24class GMarker : public TObject {
25public:
26 GMarker() = default;
27 GMarker(int tmpX, int tmpY, TH1* hist);
28 GMarker(const GMarker& marker) : TObject(marker) { static_cast<const GMarker>(marker).Copy(*this); }
29 GMarker(GMarker&&) noexcept = default;
30 GMarker& operator=(const GMarker&) = default;
31 GMarker& operator=(GMarker&&) noexcept = default;
33 {
34 if(fLineX != nullptr) { fLineX->Delete(); }
35 if(fLineY != nullptr) { fLineY->Delete(); }
36 }
37 void Draw(Option_t* opt = "") override
38 {
39 if(fLineX != nullptr) {
40 fLineX->Draw(opt);
41 }
42 if(fLineY != nullptr) {
43 fLineY->Draw(opt);
44 }
45 }
46 void Print(Option_t* option = "") const override
47 {
48 TObject::Print(option);
49 std::cout << "fLineX = " << fLineX << ", fLineY = " << fLineY << std::endl;
50 TString opt = option;
51 opt.ToLower();
52 if(opt.Contains("a")) {
53 if(fLineX != nullptr) { fLineX->Print(); }
54 if(fLineY != nullptr) { fLineY->Print(); }
55 }
56 }
57
58 void SetColor(Color_t color)
59 {
60 if(fLineX != nullptr) {
61 fLineX->SetLineColor(color);
62 }
63 if(fLineY != nullptr) {
64 fLineY->SetLineColor(color);
65 }
66 }
67
68 void SetStyle(Style_t style)
69 {
70 if(fLineX != nullptr) {
71 fLineX->SetLineStyle(style);
72 }
73 if(fLineY != nullptr) {
74 fLineY->SetLineStyle(style);
75 }
76 }
77 void Update(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax)
78 {
79 if(fLineX != nullptr) {
80 fLineX->SetY1(ymin);
81 fLineX->SetY2(ymax);
82 }
83 if(fLineY != nullptr) {
84 fLineY->SetX1(xmin);
85 fLineY->SetX2(xmax);
86 }
87 }
88
89 void SetLineX(double x1, double x2, double y1, double y2)
90 {
91 if(fLineX == nullptr) {
92 fLineX = new TLine(x1, y1, x2, y2);
93 } else {
94 fLineX->SetX1(x1);
95 fLineX->SetX2(x2);
96 fLineX->SetY1(y1);
97 fLineX->SetY2(y2);
98 }
99 }
100
101 void SetLineY(double x1, double x2, double y1, double y2)
102 {
103 if(fLineY == nullptr) {
104 fLineY = new TLine(x1, y1, x2, y2);
105 } else {
106 fLineY->SetX1(x1);
107 fLineY->SetX2(x2);
108 fLineY->SetY1(y1);
109 fLineY->SetY2(y2);
110 }
111 }
112
113 void SetLocalX(const double& val)
114 {
115 if(fLineX != nullptr) {
116 fLineX->SetX1(val);
117 fLineX->SetX2(val);
118 }
119 }
120 void SetLocalY(const double& val)
121 {
122 if(fLineY != nullptr) {
123 fLineY->SetY1(val);
124 fLineY->SetY2(val);
125 }
126 }
127 void SetBinX(const int& val) { SetLineX(fHist->GetXaxis()->GetBinLowEdge(val), gPad->GetUymin(), fHist->GetXaxis()->GetBinLowEdge(val), gPad->GetUymax()); }
128 void SetBinY(const int& val) { SetLineX(gPad->GetUxmin(), fHist->GetYaxis()->GetBinLowEdge(val), gPad->GetUxmax(), fHist->GetYaxis()->GetBinLowEdge(val)); }
129
130 double GetLocalX() const
131 {
132 if(fLineX == nullptr) { return 0.; }
133 return fLineX->GetX1();
134 }
135 double GetLocalY() const
136 {
137 if(fLineY == nullptr) { return 0.; }
138 return fLineY->GetY1();
139 }
140 int GetBinX() const
141 {
142 if(fLineX == nullptr) { return -1; }
143 return fHist->GetXaxis()->FindBin(fLineX->GetX1());
144 }
145 int GetBinY() const
146 {
147 if(fLineY == nullptr) { return -1; }
148 return fHist->GetYaxis()->FindBin(fLineY->GetY1());
149 }
150
151 void SetHist(const TH1* val) { fHist = val; }
152
153private:
154 const TH1* fHist{nullptr};
155 TLine* fLineX{nullptr};
156 TLine* fLineY{nullptr};
157
158public:
159 void Copy(TObject& object) const override;
160 bool operator<(const GMarker& rhs) const
161 {
162 if(fLineX != nullptr && rhs.fLineX != nullptr) { return fLineX->GetX1() < rhs.fLineX->GetX1(); }
163 return false;
164 }
165 /// \cond CLASSIMP
166 ClassDefOverride(GMarker, 0) // NOLINT(readability-else-after-return)
167 /// \endcond
168};
169
170///////////////////////////////////////////////////////////////////////////
171///
172/// \class GCanvas
173///
174/// Reimplementation of TCanvas. Adds different actions for mouse clicks:
175/// - single click: stores position (only for TLevelScheme).
176/// - double click: add GMarker if the last histogram found in the gPad is 1D or 2D.
177/// - shift click: draw the parent of GH1D histogram on new canvas or draw all
178/// histograms on a new canvas, or (for 2D histograms) create new GH2D from
179/// histogram and draw it on a new canvas (using "colz").
180/// - control click: doesn't do anything right now, code for TCutG is commented out.
181///
182/// For TLevelSchemes we also have:
183/// - mouse wheel to change zoom level
184/// - mouse drag to zoom in
185/// - u unzooms.
186///
187/// Also adds keyboard controls for 1D histograms:
188/// - left/right arrow moves the range left/right by 50%.
189/// - up/down arrow on GH1D histograms selects the next/previous histogram and draws it.
190/// - F2 opens editor.
191/// - F9 shows crosshairs.
192/// - b Set the background, how it is set depends on B.
193/// - B Cycle through types of automatic background subtraction used when projecting with p. Current types include: No subtraction, Fraction of the total, subtract gate from the 3rd marker (gate size set to the distance between marker 1 and 2).
194/// - d Open popup.
195/// - e Expand the x-axis range between the last two markers.
196/// - E Bring up dialogue box used to set desired x-axis range.
197/// - f If markers have been set, do a GPeak fit between last two markers on the last histogram (skewed gaus for gamma-rays with automatic bg).
198/// - F TPeak Fit (skewed gaus for gamma-rays with automatic bg).
199/// - g Simple Gaus fit between the last to marks, displays results of the fit RESULTS STILL NEED TO BE VERIFIED
200/// - i Raw integral of counts between the two markers
201/// - I TODO: Background subtracted integral of counts between the two markers
202/// - l/y Toggle y-axis from linear to logarithmic and vice versa.
203/// - m Toggle on marker mode; when on, the histogram will remember and display the last four clicks as marks on the histogram.
204/// - M Toggle off marker mode.
205/// - n Remove all markers / functions drawn on the histogram.
206/// - N Remove all markers and the LAST function drawn on the histogram.
207/// - o/u Unzoom the entire histogram.
208/// - p If the 1d hist was made using the global ProjectionX/ProjectionY; gating the original 2D matrix this histogram came from is possible by placing markers around the gate and pressing p. The gates spectra is immediately drawn.
209/// - P Draws parent histogram???
210/// - q If markers have been set, fit a GPeak between the last two markers on the first histogram (skewed gaus for gamma-rays with automatic bg).
211/// - r Expand the y-axis range between the last two markers.
212/// - R Bring up the dialogue box used to set the desired y-axis range.
213/// - s Show peak values.
214/// - S Remove peak values.
215///
216/// And for 2D histograms these keyboard controls are added:
217/// - left/right arrow moves the range left/right by 50%.
218/// - up/down arrow moves the range up/down by 50%.
219/// - c Add the initialized cut to the list of cuts (see i).
220/// - e Expand the x- and y-axis between the last two markers.
221/// - E Bring up dialogue box used to set desired x-axis range.
222/// - g Create a cut from the last two markers and add it to the histogram.
223/// - i Initialize a new cut.
224/// - l/z Toggle z-axis from linear to logarithmic and vice versa.
225/// - n Remove all markers / functions drawn on the histogram.
226/// - o/u Unzoom the entire histogram.
227/// - P Get projections from this histogram and draw the first one if it exists.
228/// - r Expand the y-axis between the last two markers.
229/// - R Bring up the dialogue box to set the desired y-axis range.
230/// - s Save the cuts that have been created.
231/// - x Create projection of the histogram onto the x-axis and draw in a new canvas.
232/// - X Create "y summary" of the histogram, i.e. a projection of the first y-bin onto the x-axis that yields a non-empty histogram and draw it on a new canvas.
233/// - y Create projection of the histogram onto the x-axis and draw in a new canvas.
234/// - Y Create "x summary" of the histogram, i.e. a projection of the first x-bin onto the y-axis that yields a non-empty histogram and draw it on a new canvas.
235///
236///////////////////////////////////////////////////////////////////////////
237
238class GCanvas : public TCanvas {
239public:
240 explicit GCanvas(Bool_t build = kTRUE);
241 explicit GCanvas(const char* name, const char* title = "", Int_t form = 1);
242 GCanvas(const char* name, const char* title, Int_t winw, Int_t winh);
243 GCanvas(const char* name, Int_t winw, Int_t winh, Int_t winid);
244 GCanvas(const char* name, const char* title, Int_t wtopx, Int_t wtopy, Int_t winw, Int_t winh, bool gui = false);
245 GCanvas(const GCanvas&) = delete;
246 GCanvas(GCanvas&&) noexcept = delete;
247 GCanvas& operator=(const GCanvas&) = delete;
248 GCanvas& operator=(GCanvas&&) noexcept = delete;
249 ~GCanvas();
250
251#pragma GCC diagnostic push
252#pragma GCC diagnostic ignored "-Woverloaded-virtual"
253 void HandleInput(int event, Int_t x, Int_t y);
254#pragma GCC diagnostic pop
255 void Draw(Option_t* opt = "") override;
256
257 static GCanvas* MakeDefCanvas();
258
259 Int_t GetNMarkers() { return static_cast<Int_t>(fMarkers.size()); }
260 void SetMarkerMode(bool flag = true) { fMarkerMode = flag; }
261
262 static TF1* GetLastFit();
263
264private:
265 void GCanvasInit();
266
267 void UpdateStatsInfo(int, int);
268
269 static double fLastX;
270 static double fLastY;
271
272 bool fGuiEnabled{false};
273
274 bool fMarkerMode{false};
275 std::vector<GMarker*> fMarkers;
276 std::vector<GMarker*> fBackgroundMarkers;
278 std::vector<TCutG*> fCuts;
279 char* fCutName{nullptr};
280 void AddMarker(int, int, TH1* hist);
281 void RemoveMarker(Option_t* opt = "");
282 void OrderMarkers();
283 void RedrawMarkers();
286
287 static std::vector<TH1*> FindHists(int dim = 1);
288 static std::vector<TH1*> FindAllHists();
289
290public:
291 bool HandleArrowKeyPress(Event_t* event, const UInt_t* keysym);
292 bool HandleKeyboardPress(Event_t* event, const UInt_t* keysym);
293 bool HandleMousePress(Int_t event, Int_t x, Int_t y);
294 bool HandleMouseShiftPress(Int_t event, Int_t x, Int_t y);
295 bool HandleMouseControlPress(Int_t event, Int_t x, Int_t y);
296 bool HandleWheel(Int_t event, Int_t x, Int_t y);
297 bool StorePosition(Int_t event, Int_t x, Int_t y);
298 bool Zoom(Int_t event, Int_t x, Int_t y);
299
300private:
301 bool ProcessNonHistKeyboardPress(Event_t* event, const UInt_t* keysym);
302 bool Process1DArrowKeyPress(Event_t* event, const UInt_t* keysym);
303 bool Process1DKeyboardPress(Event_t* event, const UInt_t* keysym);
304 bool Process1DMousePress(Int_t event, Int_t x, Int_t y);
305
306 bool Process2DArrowKeyPress(Event_t* event, const UInt_t* keysym);
307 bool Process2DKeyboardPress(Event_t* event, const UInt_t* keysym);
308 bool Process2DMousePress(Int_t event, Int_t x, Int_t y);
309
310 TRootCanvas* fRootCanvas{nullptr};
311
312 /// \cond CLASSIMP
313 ClassDefOverride(GCanvas, 2) // NOLINT(readability-else-after-return)
314 /// \endcond
315};
316/*! @} */
317#endif
EBackgroundSubtraction
Definition GH2Base.h:14
TH1D * hist
Definition UserFillObj.h:3
static GCanvas * MakeDefCanvas()
Definition GCanvas.cxx:258
GCanvas(Bool_t build=kTRUE)
Definition GCanvas.cxx:86
EBackgroundSubtraction fBackgroundMode
Definition GCanvas.h:277
bool Process2DMousePress(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:1356
bool HandleMouseControlPress(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:462
bool HandleArrowKeyPress(Event_t *event, const UInt_t *keysym)
Definition GCanvas.cxx:348
GCanvas(const GCanvas &)=delete
void GCanvasInit()
Definition GCanvas.cxx:122
bool HandleMousePress(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:382
void RedrawMarkers()
Definition GCanvas.cxx:177
std::vector< TCutG * > fCuts
Definition GCanvas.h:278
bool StorePosition(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:475
bool fGuiEnabled
Definition GCanvas.h:272
bool fMarkerMode
Definition GCanvas.h:274
static double fLastY
Definition GCanvas.h:270
void SetMarkerMode(bool flag=true)
Definition GCanvas.h:260
bool SetBackgroundMarkers()
Definition GCanvas.cxx:191
char * fCutName
Definition GCanvas.h:279
static TF1 * GetLastFit()
Definition GCanvas.cxx:549
bool Process1DKeyboardPress(Event_t *event, const UInt_t *keysym)
Definition GCanvas.cxx:602
bool CycleBackgroundSubtraction()
Definition GCanvas.cxx:219
bool Process1DArrowKeyPress(Event_t *event, const UInt_t *keysym)
Definition GCanvas.cxx:568
bool Process2DKeyboardPress(Event_t *event, const UInt_t *keysym)
Definition GCanvas.cxx:1004
GCanvas(GCanvas &&) noexcept=delete
void OrderMarkers()
Definition GCanvas.cxx:172
bool Process2DArrowKeyPress(Event_t *event, const UInt_t *keysym)
Definition GCanvas.cxx:998
bool Zoom(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:486
void UpdateStatsInfo(int, int)
static std::vector< TH1 * > FindAllHists()
Definition GCanvas.cxx:336
void HandleInput(int event, Int_t x, Int_t y)
Definition GCanvas.cxx:279
std::vector< GMarker * > fBackgroundMarkers
Definition GCanvas.h:276
void Draw(Option_t *opt="") override
Definition GCanvas.cxx:312
bool HandleKeyboardPress(Event_t *event, const UInt_t *keysym)
Definition GCanvas.cxx:362
bool HandleWheel(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:504
void AddMarker(int, int, TH1 *hist)
Definition GCanvas.cxx:137
static double fLastX
Definition GCanvas.h:269
TRootCanvas * fRootCanvas
Definition GCanvas.h:310
bool HandleMouseShiftPress(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:422
std::vector< GMarker * > fMarkers
Definition GCanvas.h:275
void RemoveMarker(Option_t *opt="")
Definition GCanvas.cxx:150
Int_t GetNMarkers()
Definition GCanvas.h:259
bool ProcessNonHistKeyboardPress(Event_t *event, const UInt_t *keysym)
Definition GCanvas.cxx:576
bool Process1DMousePress(Int_t event, Int_t x, Int_t y)
Definition GCanvas.cxx:992
static std::vector< TH1 * > FindHists(int dim=1)
Definition GCanvas.cxx:321
GMarker(GMarker &&) noexcept=default
void SetLocalX(const double &val)
Definition GCanvas.h:113
int GetBinX() const
Definition GCanvas.h:140
TLine * fLineX
Definition GCanvas.h:155
void Draw(Option_t *opt="") override
Definition GCanvas.h:37
void SetLocalY(const double &val)
Definition GCanvas.h:120
void SetStyle(Style_t style)
Definition GCanvas.h:68
void Update(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax)
Definition GCanvas.h:77
void SetLineY(double x1, double x2, double y1, double y2)
Definition GCanvas.h:101
void SetBinY(const int &val)
Definition GCanvas.h:128
int GetBinY() const
Definition GCanvas.h:145
TLine * fLineY
Definition GCanvas.h:156
void Copy(TObject &object) const override
Definition GCanvas.cxx:75
double GetLocalY() const
Definition GCanvas.h:135
GMarker(const GMarker &marker)
Definition GCanvas.h:28
void SetBinX(const int &val)
Definition GCanvas.h:127
void SetHist(const TH1 *val)
Definition GCanvas.h:151
const TH1 * fHist
Definition GCanvas.h:154
bool operator<(const GMarker &rhs) const
Definition GCanvas.h:160
void Print(Option_t *option="") const override
Definition GCanvas.h:46
void SetLineX(double x1, double x2, double y1, double y2)
Definition GCanvas.h:89
double GetLocalX() const
Definition GCanvas.h:130
void SetColor(Color_t color)
Definition GCanvas.h:58
GMarker()=default