GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4Marker.cxx
Go to the documentation of this file.
1 // $Id: TGo4Marker.cxx 2850 2020-05-18 14:01:38Z linev $
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 <iostream>
17 
18 #include "TH1.h"
19 #include "TROOT.h"
20 #include "TVirtualPad.h"
21 
22 #include "TGo4MarkerPainter.h"
23 #include "TGo4Log.h"
24 
26 
27 Bool_t TGo4Marker::fgbHASLABEL = kTRUE;
28 Bool_t TGo4Marker::fgbHASCONNECTOR = kTRUE;
29 Bool_t TGo4Marker::fgbXDRAW = kTRUE;
30 Bool_t TGo4Marker::fgbYDRAW = kTRUE;
31 Bool_t TGo4Marker::fgbXBINDRAW = kFALSE;
32 Bool_t TGo4Marker::fgbYBINDRAW = kFALSE;
33 Bool_t TGo4Marker::fgbCONTDRAW = kTRUE;
34 TString TGo4Marker::fgxNUMFORMAT = "%.4E";
35 
36 
38 {
39  return fguInstanceCounter;
40 }
41 
42 
43 TGo4Marker::TGo4Marker(Double_t x, Double_t y, Int_t style)
44 : TMarker(x,y,style),fxPainter(0),
45  fbIsPainted(kFALSE), fbVisible(kTRUE), fbHasLabel(kTRUE), fbHasConnector(kTRUE),
46  fbXDraw(kTRUE), fbYDraw(kTRUE), fbXbinDraw(kTRUE), fbYbinDraw(kTRUE), fbContDraw(kTRUE),
47  fxHisto(0),fxDrawPad(0)
48 {
49  fxName="Marker ";
52  SetBit(kMustCleanup);
53 }
54 
56 : TMarker(), fxPainter(0),
57  fbIsPainted(kFALSE), fbVisible(kTRUE), fbHasLabel(kTRUE), fbHasConnector(kTRUE),
58  fbXDraw(kTRUE), fbYDraw(kTRUE), fbXbinDraw(kTRUE), fbYbinDraw(kTRUE), fbContDraw(kTRUE),
59  fxHisto(0),fxDrawPad(0)
60 {
61 //++fguInstanceCounter; // do not increment instances by streaming
63  SetBit(kMustCleanup);
64 }
65 
67 {
68  UnDraw();
69  if(fxPainter) delete fxPainter;
70 // if(fguInstanceCounter>0) --fguInstanceCounter;
71 }
72 
73 void TGo4Marker::SetDrawPad(TVirtualPad* pad)
74 {
75  fxDrawPad=pad;
76 }
77 
79 {
80  return fxDrawPad!=0;
81 }
82 
83 void TGo4Marker::SetHistogram(TH1* histo)
84 {
85  fxHisto=histo;
86 }
87 
89 {
90  return fxHisto!=0;
91 }
92 
93 
94 void TGo4Marker::Paint(Option_t* opt)
95 {
96  //if(!IsPainted() || GetDrawPad()!=gPad) return;
98  if(!CheckDrawPad() && !IsPainted())
99  {
100  SetDrawPad(gPad);
101  if(IsVisible()) SetPainted(kTRUE);
102  }
103  if(!IsPainted() || GetDrawPad()!=gPad) return; // supress invisible markers (optional)
104  TMarker::Paint(opt);
106  // marker subclass may not provide a real painter, then we skip painting:
107  if(fxPainter!=0) fxPainter->PaintLabel(opt);
108 }
109 
110 void TGo4Marker::Draw(Option_t* opt)
111 {
112  if(IsVisible()) {
113  if(gPad && gPad->GetListOfPrimitives()->FindObject(this)==0) {
114  UnDraw();
115  AppendPad(opt);
116  SetPainted(kTRUE);
117  }
118  } else
119  UnDraw(opt);
120 
121  SetDrawPad(gPad); // need this to calculate coords even for invisible marker
122 }
123 
124 void TGo4Marker::UnDraw(Option_t* opt)
125 {
126  SetPainted(kFALSE);
127  SetDrawPad(0);
128  gROOT->GetListOfCanvases()->RecursiveRemove(this);
129 
130  // Sergey: 15.07.2019. Not sure if painter has to be created to remove marker (from pad where it never was drawn?)
131  // if(fxPainter==0) fxPainter = CreatePainter();
132 
133  // marker subclass may not provide a real painter, then we skip unpainting:
134  if(fxPainter!=0) fxPainter->UnPaintLabel();
135 }
136 
138 {
140 }
141 
142 
143 void TGo4Marker::ExecuteEvent(Int_t event, Int_t px, Int_t py)
144 {
145  if (gPad == 0)
146  return;
147  TMarker::ExecuteEvent(event, px, py);
148  if (event == kButton1Up) {
149  if (fxPainter != 0)
151  }
152 }
153 
155 {
157  painter->SetMarker(this);
158  return painter;
159 }
160 
161 void TGo4Marker::SetToBin(Int_t xbin, Int_t ybin)
162 {
163  if (!CheckHistogram())
164  return;
165  Int_t bin = fxHisto->GetBin(xbin, ybin);
166  Stat_t content = fxHisto->GetBinContent(bin);
167  Double_t x = fxHisto->GetXaxis()->GetBinCenter(xbin);
168  Double_t y = 0;
169  if (fxHisto->GetDimension() == 1) {
170  y = content;
171  } else if (fxHisto->GetDimension() == 2) {
172  y = fxHisto->GetYaxis()->GetBinCenter(ybin);
173  }
174  SetX(x);
175  SetY(y);
176 }
177 
179 {
180  if (!CheckHistogram() || !CheckDrawPad())
181  return -1;
182  Int_t binx = fxHisto->GetXaxis()->FindFixBin(fxDrawPad->PadtoX(GetX()));
183  return binx;
184 }
185 
187 {
188  if (!CheckHistogram() || !CheckDrawPad())
189  return -1;
190  Int_t biny = fxHisto->GetYaxis()->FindFixBin(fxDrawPad->PadtoY(GetY()));
191  return biny;
192 }
193 
195 {
196  if (!CheckHistogram() || !CheckDrawPad())
197  return -1;
198  Int_t bin = fxHisto->GetBin(GetXbin(), GetYbin());
199  Stat_t content = fxHisto->GetBinContent(bin);
200  return (Int_t)content;
201 }
202 
204 {
205  if (!CheckDrawPad())
206  return 0;
207  Double_t xoff = 0.01 * (fxDrawPad->GetUxmax() - fxDrawPad->GetUxmin());
208  Double_t xpos = GetX() + xoff;
209  return xpos;
210 }
211 
213 {
214  if (!CheckDrawPad())
215  return 0;
216  Double_t yoff = 0.01 * (fxDrawPad->GetUymax() - fxDrawPad->GetUymin());
217  Double_t ypos = 0;
218  if (GetY() == 0)
219  ypos = (fxDrawPad->GetUymax() - fxDrawPad->GetUymin()) / 2; // case of 1d histo
220  else
221  ypos = GetY() + yoff; // 2d histo near cursor point
222  return ypos;
223 }
224 
225 void TGo4Marker::Print(Option_t *opt) const
226 {
227  TGo4Marker *localthis = const_cast<TGo4Marker *>(this);
228  localthis->PrintMarker(opt);
229 }
230 
231 //void TGo4Marker::DeleteMarker()
232 //{
233 // Delete("");
234 //}
235 
236 void TGo4Marker::PrintMarker(Option_t *opt)
237 {
238  TString option = opt;
239  option.ToLower();
240  TString textbuffer = "Marker ";
241  textbuffer += GetName();
242  textbuffer += " with";
243  TH1 *hist = GetHistogram();
244  if (hist) {
245  textbuffer += " histogram: ";
246  textbuffer += hist->GetName();
247  } else
248  textbuffer += "out histogram";
249 
250  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",
251  GetX(), GetY(), GetXbin(), GetYbin(), GetCont());
252  if (option.Contains("go4log"))
253  TGo4Log::Message(1, textbuffer.Data());
254  else
255  std::cout << textbuffer.Data() << std::endl;
256 }
257 
259 {
268 }
269 
271 {
280 }
281 
282 void TGo4Marker::SetGlobalStyle(Bool_t HASLABEL, Bool_t HASCONNECTOR, Bool_t XDRAW, Bool_t YDRAW,
283  Bool_t XBINDRAW, Bool_t YBINDRAW, Bool_t CONTDRAW, const char *NUMFORMAT)
284 {
285  TGo4Marker::fgbHASLABEL = HASLABEL;
286  TGo4Marker::fgbHASCONNECTOR = HASCONNECTOR;
287  TGo4Marker::fgbXDRAW = XDRAW;
288  TGo4Marker::fgbYDRAW = YDRAW;
289  TGo4Marker::fgbXBINDRAW = XBINDRAW;
290  TGo4Marker::fgbYBINDRAW = YBINDRAW;
291  TGo4Marker::fgbCONTDRAW = CONTDRAW;
292  TGo4Marker::fgxNUMFORMAT = NUMFORMAT;
293 
294 }
295 
296 void TGo4Marker::GetGlobalStyle(Bool_t &HASLABEL, Bool_t &HASCONNECTOR, Bool_t &XDRAW, Bool_t &YDRAW,
297  Bool_t &XBINDRAW, Bool_t &YBINDRAW, Bool_t &CONTDRAW, TString &NUMFORMAT)
298 {
299  HASLABEL = TGo4Marker::fgbHASLABEL;
300  HASCONNECTOR = TGo4Marker::fgbHASCONNECTOR;
301  XDRAW = TGo4Marker::fgbXDRAW;
302  YDRAW = TGo4Marker::fgbYDRAW;
303  XBINDRAW = TGo4Marker::fgbXBINDRAW;
304  YBINDRAW = TGo4Marker::fgbYBINDRAW;
305  CONTDRAW = TGo4Marker::fgbCONTDRAW;
306  NUMFORMAT = TGo4Marker::fgxNUMFORMAT;
307 }
308 
309 
311 {
312  if (fxPainter != 0) {
313  fxPainter->UnPaintLabel("reset");
315  }
316 }
317 
319 {
320  if (fxPainter != 0) {
321  delete fxPainter;
322  fxPainter = 0;
323  }
324 }
Bool_t IsVisible()
Definition: TGo4Marker.h:66
TString fxNumFormat
Definition: TGo4Marker.h:208
void SetDrawPad(TVirtualPad *pad)
Definition: TGo4Marker.cxx:73
static Bool_t fgbHASCONNECTOR
Definition: TGo4Marker.h:135
virtual const char * GetName() const
Definition: TGo4Marker.h:103
virtual void Pop()
Definition: TGo4Marker.cxx:137
static Bool_t fgbCONTDRAW
Definition: TGo4Marker.h:150
Bool_t IsPainted()
Definition: TGo4Marker.h:169
Int_t GetCont()
Definition: TGo4Marker.cxx:194
void ResetLabel()
Definition: TGo4Marker.cxx:310
void SetToBin(Int_t xbin, Int_t ybin=0)
Definition: TGo4Marker.cxx:161
virtual void Paint(Option_t *opt="")
Definition: TGo4Marker.cxx:94
Bool_t fbXbinDraw
Definition: TGo4Marker.h:199
static Int_t GetInstances()
Definition: TGo4Marker.cxx:37
virtual void Print(Option_t *opt="") const
Definition: TGo4Marker.cxx:225
Int_t GetXbin()
Definition: TGo4Marker.cxx:178
virtual void SetMarker(TGo4Marker *mark)
void SetHistogram(TH1 *histo)
Definition: TGo4Marker.cxx:83
static Bool_t fgbXDRAW
Definition: TGo4Marker.h:138
void SaveLabelStyle()
Definition: TGo4Marker.cxx:258
Bool_t CheckHistogram()
Definition: TGo4Marker.cxx:88
static Bool_t fgbYBINDRAW
Definition: TGo4Marker.h:147
void SetPainted(Bool_t on)
Definition: TGo4Marker.h:168
TH1 * GetHistogram() const
Definition: TGo4Marker.h:100
virtual void DisplayToFront(Option_t *opt="")
virtual void PaintLabel(Option_t *opt="")
TVirtualPad * GetDrawPad()
Definition: TGo4Marker.h:124
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:282
virtual TGo4MarkerPainter * CreatePainter()
Definition: TGo4Marker.cxx:154
Int_t GetYbin()
Definition: TGo4Marker.cxx:186
TGo4MarkerPainter * fxPainter
Definition: TGo4Marker.h:166
TH1 * fxHisto
Definition: TGo4Marker.h:211
virtual void Draw(Option_t *opt="")
Definition: TGo4Marker.cxx:110
void DeletePainter()
Definition: TGo4Marker.cxx:318
Bool_t fbYbinDraw
Definition: TGo4Marker.h:202
Bool_t fbContDraw
Definition: TGo4Marker.h:205
virtual void UnDraw(Option_t *opt="")
Definition: TGo4Marker.cxx:124
Double_t GetLabelY()
Definition: TGo4Marker.cxx:212
void PrintMarker(Option_t *opt="")
Definition: TGo4Marker.cxx:236
static Bool_t fgbYDRAW
Definition: TGo4Marker.h:141
static const char * Message(Int_t prio, const char *text,...)
Definition: TGo4Log.cxx:209
Bool_t fbXDraw
Definition: TGo4Marker.h:193
static UInt_t fguInstanceCounter
Definition: TGo4Marker.h:218
Bool_t fbHasConnector
Definition: TGo4Marker.h:190
static Bool_t fgbXBINDRAW
Definition: TGo4Marker.h:144
static TString fgxNUMFORMAT
Definition: TGo4Marker.h:153
Double_t GetLabelX()
Definition: TGo4Marker.cxx:203
static Bool_t fgbHASLABEL
Definition: TGo4Marker.h:132
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:296
Bool_t fbHasLabel
Definition: TGo4Marker.h:187
TString fxName
Definition: TGo4Marker.h:177
TVirtualPad * fxDrawPad
Definition: TGo4Marker.h:215
Bool_t CheckDrawPad()
Definition: TGo4Marker.cxx:78
void InitLabelStyle()
Definition: TGo4Marker.cxx:270
virtual void UnPaintLabel(Option_t *opt="")
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: TGo4Marker.cxx:143
Bool_t fbYDraw
Definition: TGo4Marker.h:196
virtual ~TGo4Marker()
Definition: TGo4Marker.cxx:66