GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
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 
26 Bool_t TGo4Marker::fgbHASLABEL = kTRUE;
27 Bool_t TGo4Marker::fgbHASCONNECTOR = kTRUE;
28 Bool_t TGo4Marker::fgbXDRAW = kTRUE;
29 Bool_t TGo4Marker::fgbYDRAW = kTRUE;
30 Bool_t TGo4Marker::fgbXBINDRAW = kFALSE;
31 Bool_t TGo4Marker::fgbYBINDRAW = kFALSE;
32 Bool_t TGo4Marker::fgbCONTDRAW = kTRUE;
33 TString TGo4Marker::fgxNUMFORMAT = "%.4E";
34 
35 
37 {
38  return fguInstanceCounter;
39 }
40 
41 
42 TGo4Marker::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 
64 void TGo4Marker::SetDrawPad(TVirtualPad *pad)
65 {
66  fxDrawPad = pad;
67 }
68 
70 {
71  return fxDrawPad != nullptr;
72 }
73 
74 void TGo4Marker::SetHistogram(TH1 *histo)
75 {
76  fxHisto = histo;
77 }
78 
80 {
81  return fxHisto != nullptr;
82 }
83 
84 
85 void 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 
101 void 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 
115 void 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:
123 }
124 
126 {
128 }
129 
130 
131 void 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)
139  }
140 }
141 
143 {
144  TGo4MarkerPainter* painter = new TGo4MarkerPainter(GetName());
145  painter->SetMarker(this);
146  return painter;
147 }
148 
149 void 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 
166 Int_t TGo4Marker::GetXbin() const
167 {
168  if (!CheckHistogram() || !CheckDrawPad())
169  return -1;
170  return fxHisto->GetXaxis()->FindFixBin(fxDrawPad->PadtoX(GetX()));
171 }
172 
173 Int_t TGo4Marker::GetYbin() const
174 {
175  if (!CheckHistogram() || !CheckDrawPad())
176  return -1;
177  return fxHisto->GetYaxis()->FindFixBin(fxDrawPad->PadtoY(GetY()));
178 }
179 
180 Int_t TGo4Marker::GetCont() const
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 
188 Double_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 
197 Double_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 
210 void 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 
234 {
243 }
244 
246 {
255 }
256 
257 void 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 
271 void 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");
290  }
291 }
292 
294 {
295  if (fxPainter) {
296  delete fxPainter;
297  fxPainter = nullptr;
298  }
299 }
TString fxNumFormat
Definition: TGo4Marker.h:206
void SetDrawPad(TVirtualPad *pad)
Definition: TGo4Marker.cxx:64
static Bool_t fgbHASCONNECTOR
Definition: TGo4Marker.h:133
Int_t GetYbin() const
Definition: TGo4Marker.cxx:173
static Bool_t fgbCONTDRAW
Definition: TGo4Marker.h:148
void DisplayToFront(Option_t *opt="") override
void PaintLabel(Option_t *opt="") override
void ResetLabel()
Definition: TGo4Marker.cxx:285
void SetToBin(Int_t xbin, Int_t ybin=0)
Definition: TGo4Marker.cxx:149
Int_t GetCont() const
Definition: TGo4Marker.cxx:180
Bool_t fbXbinDraw
Definition: TGo4Marker.h:197
static Int_t GetInstances()
Definition: TGo4Marker.cxx:36
Bool_t CheckDrawPad() const
Definition: TGo4Marker.cxx:69
virtual void SetMarker(TGo4Marker *mark)
void SetHistogram(TH1 *histo)
Definition: TGo4Marker.cxx:74
static Bool_t fgbXDRAW
Definition: TGo4Marker.h:136
void SaveLabelStyle()
Definition: TGo4Marker.cxx:233
static Bool_t fgbYBINDRAW
Definition: TGo4Marker.h:145
void SetPainted(Bool_t on)
Definition: TGo4Marker.h:166
Double_t GetLabelX() const
Definition: TGo4Marker.cxx:188
static const char * Message(Int_t prio, const char *text,...) GO4_PRINTF2_ARGS
Definition: TGo4Log.cxx:206
Bool_t IsPainted() const
Definition: TGo4Marker.h:167
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)
Definition: TGo4Marker.cxx:257
virtual TGo4MarkerPainter * CreatePainter()
Definition: TGo4Marker.cxx:142
Double_t GetLabelY() const
Definition: TGo4Marker.cxx:197
TGo4MarkerPainter * fxPainter
Definition: TGo4Marker.h:164
const char * GetName() const override
Definition: TGo4Marker.h:101
TH1 * fxHisto
Definition: TGo4Marker.h:209
void Paint(Option_t *opt="") override
Definition: TGo4Marker.cxx:85
Int_t GetXbin() const
Definition: TGo4Marker.cxx:166
void DeletePainter()
Definition: TGo4Marker.cxx:293
Bool_t fbYbinDraw
Definition: TGo4Marker.h:200
Bool_t fbContDraw
Definition: TGo4Marker.h:203
virtual void UnDraw(Option_t *opt="")
Definition: TGo4Marker.cxx:115
void Print(Option_t *opt="") const override
Definition: TGo4Marker.cxx:210
static Bool_t fgbYDRAW
Definition: TGo4Marker.h:139
TVirtualPad * GetDrawPad() const
Definition: TGo4Marker.h:122
Bool_t fbXDraw
Definition: TGo4Marker.h:191
static UInt_t fguInstanceCounter
Definition: TGo4Marker.h:216
Bool_t fbHasConnector
Definition: TGo4Marker.h:188
static Bool_t fgbXBINDRAW
Definition: TGo4Marker.h:142
Bool_t IsVisible() const
Definition: TGo4Marker.h:64
static TString fgxNUMFORMAT
Definition: TGo4Marker.h:151
static Bool_t fgbHASLABEL
Definition: TGo4Marker.h:130
TH1 * GetHistogram() const
Definition: TGo4Marker.h:98
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)
Definition: TGo4Marker.cxx:271
static void PrintLine(const char *text,...)
Definition: TGo4Status.cxx:101
void UnPaintLabel(Option_t *opt="") override
Bool_t fbHasLabel
Definition: TGo4Marker.h:185
TString fxName
Definition: TGo4Marker.h:175
TVirtualPad * fxDrawPad
Definition: TGo4Marker.h:213
Bool_t CheckHistogram() const
Definition: TGo4Marker.cxx:79
void InitLabelStyle()
Definition: TGo4Marker.cxx:245
void Pop() override
Definition: TGo4Marker.cxx:125
void Draw(Option_t *opt="") override
Definition: TGo4Marker.cxx:101
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Definition: TGo4Marker.cxx:131
Bool_t fbYDraw
Definition: TGo4Marker.h:194
virtual ~TGo4Marker()
Definition: TGo4Marker.cxx:57