GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4Marker.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4Marker.h"
15
16#include "TH1.h"
17#include "TROOT.h"
18#include "TVirtualPad.h"
19
20#include "TGo4MarkerPainter.h"
21#include "TGo4Log.h"
22#include "TGo4Status.h"
23
25
26Bool_t TGo4Marker::fgbHASLABEL = kTRUE;
27Bool_t TGo4Marker::fgbHASCONNECTOR = kTRUE;
28Bool_t TGo4Marker::fgbXDRAW = kTRUE;
29Bool_t TGo4Marker::fgbYDRAW = kTRUE;
30Bool_t TGo4Marker::fgbXBINDRAW = kFALSE;
31Bool_t TGo4Marker::fgbYBINDRAW = kFALSE;
32Bool_t TGo4Marker::fgbCONTDRAW = kTRUE;
33TString TGo4Marker::fgxNUMFORMAT = "%.4E";
34
35
40
41
42TGo4Marker::TGo4Marker(Double_t x, Double_t y, Int_t style) : TMarker(x,y,style)
43{
44 fxName = "Marker ";
47 SetBit(kMustCleanup);
48}
49
51{
52//++fguInstanceCounter; // do not increment instances by streaming
54 SetBit(kMustCleanup);
55}
56
58{
59 UnDraw();
60 if(fxPainter) delete fxPainter;
61// if(fguInstanceCounter>0) --fguInstanceCounter;
62}
63
64void TGo4Marker::SetDrawPad(TVirtualPad *pad)
65{
66 fxDrawPad = pad;
67}
68
70{
71 return fxDrawPad != nullptr;
72}
73
75{
76 fxHisto = histo;
77}
78
80{
81 return fxHisto != nullptr;
82}
83
84
85void TGo4Marker::Paint(Option_t *opt)
86{
87 //if(!IsPainted() || GetDrawPad()!=gPad) return;
89 if(!CheckDrawPad() && !IsPainted())
90 {
91 SetDrawPad(gPad);
92 if(IsVisible()) SetPainted(kTRUE);
93 }
94 if(!IsPainted() || GetDrawPad()!=gPad) return; // supress invisible markers (optional)
95 TMarker::Paint(opt);
97 // marker subclass may not provide a real painter, then we skip painting:
98 if(fxPainter) fxPainter->PaintLabel(opt);
99}
100
101void TGo4Marker::Draw(Option_t *opt)
102{
103 if(IsVisible()) {
104 if(gPad && gPad->GetListOfPrimitives()->FindObject(this)==nullptr) {
105 UnDraw();
106 AppendPad(opt);
107 SetPainted(kTRUE);
108 }
109 } else
110 UnDraw(opt);
111
112 SetDrawPad(gPad); // need this to calculate coords even for invisible marker
113}
114
115void TGo4Marker::UnDraw(Option_t *opt)
116{
117 SetPainted(kFALSE);
118 SetDrawPad(nullptr);
119 gROOT->GetListOfCanvases()->RecursiveRemove(this);
120
121 // marker subclass may not provide a real painter, then we skip unpainting:
122 if(fxPainter) fxPainter->UnPaintLabel();
123}
124
126{
127 if(fxPainter) fxPainter->DisplayToFront();
128}
129
130
131void TGo4Marker::ExecuteEvent(Int_t event, Int_t px, Int_t py)
132{
133 if (!gPad)
134 return;
135 TMarker::ExecuteEvent(event, px, py);
136 if (event == kButton1Up) {
137 if (fxPainter)
138 fxPainter->DisplayToFront();
139 }
140}
141
143{
144 auto painter = new TGo4MarkerPainter(GetName());
145 painter->SetMarker(this);
146 return painter;
147}
148
149void TGo4Marker::SetToBin(Int_t xbin, Int_t ybin)
150{
151 if (!CheckHistogram())
152 return;
153 Int_t bin = fxHisto->GetBin(xbin, ybin);
154 Stat_t content = fxHisto->GetBinContent(bin);
155 Double_t x = fxHisto->GetXaxis()->GetBinCenter(xbin);
156 Double_t y = 0;
157 if (fxHisto->GetDimension() == 1) {
158 y = content;
159 } else if (fxHisto->GetDimension() == 2) {
160 y = fxHisto->GetYaxis()->GetBinCenter(ybin);
161 }
162 SetX(x);
163 SetY(y);
164}
165
167{
168 if (!CheckHistogram() || !CheckDrawPad())
169 return -1;
170 return fxHisto->GetXaxis()->FindFixBin(fxDrawPad->PadtoX(GetX()));
171}
172
174{
175 if (!CheckHistogram() || !CheckDrawPad())
176 return -1;
177 return fxHisto->GetYaxis()->FindFixBin(fxDrawPad->PadtoY(GetY()));
178}
179
181{
182 if (!CheckHistogram() || !CheckDrawPad())
183 return -1;
184 Int_t bin = fxHisto->GetBin(GetXbin(), GetYbin());
185 return (Int_t) fxHisto->GetBinContent(bin);
186}
187
188Double_t TGo4Marker::GetLabelX() const
189{
190 if (!CheckDrawPad())
191 return 0;
192 Double_t xoff = 0.01 * (fxDrawPad->GetUxmax() - fxDrawPad->GetUxmin());
193 Double_t xpos = GetX() + xoff;
194 return xpos;
195}
196
197Double_t TGo4Marker::GetLabelY() const
198{
199 if (!CheckDrawPad())
200 return 0;
201 Double_t yoff = 0.01 * (fxDrawPad->GetUymax() - fxDrawPad->GetUymin());
202 Double_t ypos = 0;
203 if (GetY() == 0)
204 ypos = (fxDrawPad->GetUymax() - fxDrawPad->GetUymin()) / 2; // case of 1d histo
205 else
206 ypos = GetY() + yoff; // 2d histo near cursor point
207 return ypos;
208}
209
210void TGo4Marker::Print(Option_t *opt) const
211{
212 TString textbuffer = "Marker ";
213 textbuffer += GetName();
214 textbuffer += " with";
215 TH1 *hist = GetHistogram();
216 if (hist) {
217 textbuffer += " histogram: ";
218 textbuffer += hist->GetName();
219 } else
220 textbuffer += "out histogram";
221
222 textbuffer += TString::Format("\n X: \t\tY: \t\tXbin:\t\tYbin:\t\tCounts:\n %.2f\t\t%.2f\t\t%d\t\t%d\t\t%d",
223 GetX(), GetY(), GetXbin(), GetYbin(), GetCont());
224
225 TString option = opt;
226 option.ToLower();
227 if (option.Contains("go4log"))
228 TGo4Log::Message(1, "%s", textbuffer.Data());
229 else
230 TGo4Status::PrintLine("%s", textbuffer.Data());
231}
232
244
256
257void TGo4Marker::SetGlobalStyle(Bool_t HASLABEL, Bool_t HASCONNECTOR, Bool_t XDRAW, Bool_t YDRAW,
258 Bool_t XBINDRAW, Bool_t YBINDRAW, Bool_t CONTDRAW, const char *NUMFORMAT)
259{
260 TGo4Marker::fgbHASLABEL = HASLABEL;
261 TGo4Marker::fgbHASCONNECTOR = HASCONNECTOR;
262 TGo4Marker::fgbXDRAW = XDRAW;
263 TGo4Marker::fgbYDRAW = YDRAW;
264 TGo4Marker::fgbXBINDRAW = XBINDRAW;
265 TGo4Marker::fgbYBINDRAW = YBINDRAW;
266 TGo4Marker::fgbCONTDRAW = CONTDRAW;
267 TGo4Marker::fgxNUMFORMAT = NUMFORMAT;
268
269}
270
271void TGo4Marker::GetGlobalStyle(Bool_t &HASLABEL, Bool_t &HASCONNECTOR, Bool_t &XDRAW, Bool_t &YDRAW,
272 Bool_t &XBINDRAW, Bool_t &YBINDRAW, Bool_t &CONTDRAW, TString &NUMFORMAT)
273{
274 HASLABEL = TGo4Marker::fgbHASLABEL;
275 HASCONNECTOR = TGo4Marker::fgbHASCONNECTOR;
276 XDRAW = TGo4Marker::fgbXDRAW;
277 YDRAW = TGo4Marker::fgbYDRAW;
278 XBINDRAW = TGo4Marker::fgbXBINDRAW;
279 YBINDRAW = TGo4Marker::fgbYBINDRAW;
280 CONTDRAW = TGo4Marker::fgbCONTDRAW;
281 NUMFORMAT = TGo4Marker::fgxNUMFORMAT;
282}
283
284
286{
287 if (fxPainter) {
288 fxPainter->UnPaintLabel("reset");
289 fxPainter->PaintLabel();
290 }
291}
292
294{
295 if (fxPainter) {
296 delete fxPainter;
297 fxPainter = nullptr;
298 }
299}
static const char * Message(Int_t prio, const char *text,...) GO4_PRINTF2_ARGS
Display a message.
Definition TGo4Log.cxx:206
Int_t GetXbin() const
Deliver x axis bin number of work histogram at marker position.
Bool_t fbYbinDraw
If true, draw corresponding value as label on working pad.
Definition TGo4Marker.h:199
TString fxNumFormat
format string for all label numbers.
Definition TGo4Marker.h:205
TH1 * fxHisto
Reference to currently used histogram (for bin contents).
Definition TGo4Marker.h:208
Bool_t CheckDrawPad() const
True if current draw pad is still existing.
static Bool_t fgbYBINDRAW
default setting for all markers of ybindraw flag.
Definition TGo4Marker.h:145
static Bool_t fgbYDRAW
default setting for all markers of ydraw flag.
Definition TGo4Marker.h:139
void SetToBin(Int_t xbin, Int_t ybin=0)
Set marker to position according to work histogram axis.
Bool_t fbXbinDraw
If true, draw corresponding value as label on working pad.
Definition TGo4Marker.h:196
static Bool_t fgbCONTDRAW
default setting for all markers of bin content flag.
Definition TGo4Marker.h:148
TVirtualPad * fxDrawPad
Remember last pad used for Draw.
Definition TGo4Marker.h:212
static UInt_t fguInstanceCounter
use this counter for automatic naming and coloring
Definition TGo4Marker.h:215
void ResetLabel()
Will reset label position to defaults.
void DeletePainter()
void InitLabelStyle()
Initialize label setup from static default variables.
void Print(Option_t *opt="") const override
Implement standard root print.
static Bool_t fgbXDRAW
default setting for all markers of xdraw flag.
Definition TGo4Marker.h:136
void SaveLabelStyle()
This will save draw flags into static default setup.
Bool_t fbXDraw
If true, draw corresponding value as label on working pad.
Definition TGo4Marker.h:190
TGo4MarkerPainter * fxPainter
Painter instance to display the condition in root pad.
Definition TGo4Marker.h:164
Bool_t fbHasLabel
Switch marker label on or off.
Definition TGo4Marker.h:184
Double_t GetLabelY() const
Calculate initial label coordinate from marker position.
static Bool_t fgbXBINDRAW
default setting for all markers of xbindraw flag.
Definition TGo4Marker.h:142
Bool_t IsPainted() const
Definition TGo4Marker.h:167
const char * GetName() const override
TMarker is not TNamed, so we implement name ourself.
Definition TGo4Marker.h:101
static Bool_t fgbHASLABEL
default setting for all markers of label on/off flag.
Definition TGo4Marker.h:130
virtual TGo4MarkerPainter * CreatePainter()
Factory method to generate (optional subclass) implementation for painter.
void SetHistogram(TH1 *histo)
TVirtualPad * GetDrawPad() const
Definition TGo4Marker.h:122
void Paint(Option_t *opt="") override
Display marker with plain root canvas and in go4 viewpanel.
static void SetGlobalStyle(Bool_t HASLABEL, Bool_t HASCONNECTOR, Bool_t XDRAW, Bool_t YDRAW, Bool_t XBINDRAW, Bool_t YBINDRAW, Bool_t CONTDRAW, const char *NUMFORMAT)
static Bool_t fgbHASCONNECTOR
default setting for all markers of connector line flag.
Definition TGo4Marker.h:133
Bool_t IsVisible() const
Definition TGo4Marker.h:64
Int_t GetCont() const
Deliver bin content of work histogram at marker position.
static Int_t GetInstances()
Bool_t CheckHistogram() const
True if current histogram is still existing.
Int_t GetYbin() const
Deliver y axis bin number of work histogram at marker position.
virtual void UnDraw(Option_t *opt="")
Erase view of this marker from the pad.
Bool_t fbYDraw
If true, draw corresponding value as label on working pad.
Definition TGo4Marker.h:193
virtual ~TGo4Marker()
Bool_t fbHasConnector
Switch connection line between marker and label on or off.
Definition TGo4Marker.h:187
void SetDrawPad(TVirtualPad *pad)
TH1 * GetHistogram() const
Definition TGo4Marker.h:98
TString fxName
since TMarker is not TNamed, we provide identifier string here:
Definition TGo4Marker.h:174
void Pop() override
Re-implement TObject method to pop all our views to front.
static void GetGlobalStyle(Bool_t &HASLABEL, Bool_t &HASCONNECTOR, Bool_t &XDRAW, Bool_t &YDRAW, Bool_t &XBINDRAW, Bool_t &YBINDRAW, Bool_t &CONTDRAW, TString &NUMFORMAT)
Bool_t fbContDraw
If true, draw corresponding value as label on working pad.
Definition TGo4Marker.h:202
void Draw(Option_t *opt="") override
Draw this marker on current pad.
void SetPainted(Bool_t on)
Definition TGo4Marker.h:166
static TString fgxNUMFORMAT
default setting for all conditions with format string for numbers.
Definition TGo4Marker.h:151
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Reimplemented to pop our labels to front when selected.
Double_t GetLabelX() const
Calculate initial label coordinate from marker position.
static void PrintLine(const char *text,...)
Print single line of debug output with appropriate indent.