GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4Marker.cxx
Go to the documentation of this file.
1 // $Id: TGo4Marker.cxx 933 2013-01-29 15:27:58Z 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 für 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 "Riostream.h"
17 #include "TH1.h"
18 #include "TROOT.h"
19 #include "TVirtualPad.h"
20 #include "snprintf.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 
37 TGo4Marker::TGo4Marker(Double_t x, Double_t y, Int_t style)
38 : TMarker(x,y,style),fxPainter(0),
39  fbIsPainted(kFALSE), fbVisible(kTRUE), fbHasLabel(kTRUE), fbHasConnector(kTRUE),
40  fbXDraw(kTRUE), fbYDraw(kTRUE), fbXbinDraw(kTRUE), fbYbinDraw(kTRUE), fbContDraw(kTRUE),
41  fxHisto(0),fxDrawPad(0)
42 {
43  fxName="Marker ";
46  SetBit(kMustCleanup);
47 }
48 
50 : TMarker(), fxPainter(0),
51  fbIsPainted(kFALSE), fbVisible(kTRUE), fbHasLabel(kTRUE), fbHasConnector(kTRUE),
52  fbXDraw(kTRUE), fbYDraw(kTRUE), fbXbinDraw(kTRUE), fbYbinDraw(kTRUE), fbContDraw(kTRUE),
53  fxHisto(0),fxDrawPad(0)
54 {
55 //++fguInstanceCounter; // do not increment instances by streaming
57  SetBit(kMustCleanup);
58 }
59 
61 {
62  UnDraw();
63  if(fxPainter) delete fxPainter;
64 // if(fguInstanceCounter>0) --fguInstanceCounter;
65 }
66 
67 void TGo4Marker::SetDrawPad(TVirtualPad* pad)
68 {
69  fxDrawPad=pad;
70 }
71 
73 {
74  return fxDrawPad!=0;
75 }
76 
77 void TGo4Marker::SetHistogram(TH1* histo)
78 {
79  fxHisto=histo;
80 }
81 
83 {
84  return fxHisto!=0;
85 }
86 
87 
88 void TGo4Marker::Paint(Option_t* opt)
89 {
90  //if(!IsPainted() || GetDrawPad()!=gPad) return;
92  if(!CheckDrawPad() && !IsPainted())
93  {
94  SetDrawPad(gPad);
95  if(IsVisible()) SetPainted(kTRUE);
96  }
97  if(!IsPainted() || GetDrawPad()!=gPad) return; // supress invisible markers (optional)
98  TMarker::Paint(opt);
100  // marker subclass may not provide a real painter, then we skip painting:
101  if(fxPainter!=0) fxPainter->PaintLabel(opt);
102 }
103 
104 void TGo4Marker::Draw(Option_t* opt)
105 {
106  if(IsVisible()) {
107  if(gPad && gPad->GetListOfPrimitives()->FindObject(this)==0) {
108  UnDraw();
109  AppendPad(opt);
110  SetPainted(kTRUE);
111  }
112  } else
113  UnDraw(opt);
114 
115  SetDrawPad(gPad); // need this to calculate coords even for invisible marker
116 }
117 
118 void TGo4Marker::UnDraw(Option_t* opt)
119 {
120  SetPainted(kFALSE);
121  SetDrawPad(0);
122  gROOT->GetListOfCanvases()->RecursiveRemove(this);
123  if(fxPainter==0) fxPainter = CreatePainter();
124  // marker subclass may not provide a real painter, then we skip unpainting:
125  if(fxPainter!=0) fxPainter->UnPaintLabel();
126 }
127 
129 {
131 }
132 
133 
134 void TGo4Marker::ExecuteEvent(Int_t event, Int_t px, Int_t py)
135 {
136 if(gPad==0) return;
137 TMarker::ExecuteEvent(event,px,py);
138 if(event==kButton1Up)
139  {
141  }
142 }
143 
144 
146 {
148  painter->SetMarker(this);
149  return painter;
150 }
151 
152 void TGo4Marker::SetToBin(Int_t xbin, Int_t ybin)
153 {
154 if(!CheckHistogram()) return;
155 Int_t bin = fxHisto->GetBin(xbin,ybin);
156 Stat_t content = fxHisto->GetBinContent(bin);
157 Double_t x=fxHisto->GetXaxis()->GetBinCenter(xbin);
158 Double_t y=0;
159 if(fxHisto->GetDimension()==1)
160  {
161  y=content;
162  }
163 else if (fxHisto->GetDimension()==2)
164  {
165  y=fxHisto->GetYaxis()->GetBinCenter(ybin);
166  }
167 SetX(x);
168 SetY(y);
169 }
170 
171 
173 {
174 if(!CheckHistogram() || !CheckDrawPad()) return -1;
175 Int_t binx = fxHisto->GetXaxis()->FindFixBin(fxDrawPad->PadtoX(GetX()));
176 return binx;
177 }
178 
180 {
181 if(!CheckHistogram() || !CheckDrawPad()) return -1;
182 Int_t biny = fxHisto->GetYaxis()->FindFixBin(fxDrawPad->PadtoY(GetY()));
183 return biny;
184 
185 }
186 
188 {
189 if(!CheckHistogram() || !CheckDrawPad())return -1;
190 Int_t bin = fxHisto->GetBin(GetXbin(),GetYbin());
191 Stat_t content = fxHisto->GetBinContent(bin);
192 return (Int_t) content;
193 }
194 
196 {
197 if(!CheckDrawPad()) return 0;
198 Double_t xoff=0.01*(fxDrawPad->GetUxmax()-fxDrawPad->GetUxmin());
199 Double_t xpos=GetX()+xoff;
200 return xpos;
201 }
202 
204 {
205 if(!CheckDrawPad()) return 0;
206 Double_t yoff=0.01*(fxDrawPad->GetUymax()-fxDrawPad->GetUymin());
207 Double_t ypos=0;
208 if(GetY()==0)
209  ypos=(fxDrawPad->GetUymax()-fxDrawPad->GetUymin())/2; // case of 1d histo
210 else
211  ypos=GetY()+yoff; // 2d histo near cursor point
212 return ypos;
213 }
214 
215 void TGo4Marker::Print(Option_t* opt) const{
216  TGo4Marker* localthis=const_cast<TGo4Marker*>(this);
217  localthis->PrintMarker(opt);
218 }
219 
220 //void TGo4Marker::DeleteMarker()
221 //{
222 // Delete("");
223 //}
224 
225 
226 void TGo4Marker::PrintMarker(Option_t* opt)
227 {
228  TString option=opt;
229  option.ToLower();
230  TString textbuffer="Marker ";
231  textbuffer+=GetName();
232  textbuffer+=" with";
233  TH1* hist=GetHistogram();
234  if(hist) {
235  textbuffer+=" histogram: ";
236  textbuffer+=hist->GetName();
237  } else
238  textbuffer+="out histogram";
239 
240  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",
241  GetX(), GetY(), GetXbin(),GetYbin(),GetCont());
242  if(option.Contains("go4log"))
243  TGo4Log::Message(1,textbuffer.Data());
244  else
245  std::cout << textbuffer.Data() << std::endl;
246 }
247 
249 {
258 }
259 
261 {
270 }
271 
273 {
274  if(fxPainter!=0) {
275  fxPainter->UnPaintLabel("reset");
277  }
278 }
279 
281 {
282  if (fxPainter!=0) {
283  delete fxPainter;
284  fxPainter = 0;
285  }
286 }
Bool_t IsVisible()
Definition: TGo4Marker.h:77
TString fxNumFormat
Definition: TGo4Marker.h:211
void SetDrawPad(TVirtualPad *pad)
Definition: TGo4Marker.cxx:67
static Bool_t fgbHASCONNECTOR
Definition: TGo4Marker.h:144
virtual const char * GetName() const
Definition: TGo4Marker.h:116
virtual void Pop()
Definition: TGo4Marker.cxx:128
static Bool_t fgbCONTDRAW
Definition: TGo4Marker.h:159
Bool_t IsPainted()
Definition: TGo4Marker.h:172
Int_t GetCont()
Definition: TGo4Marker.cxx:187
void ResetLabel()
Definition: TGo4Marker.cxx:272
void SetToBin(Int_t xbin, Int_t ybin=0)
Definition: TGo4Marker.cxx:152
virtual void Paint(Option_t *opt="")
Definition: TGo4Marker.cxx:88
Bool_t fbXbinDraw
Definition: TGo4Marker.h:202
virtual void Print(Option_t *opt="") const
Definition: TGo4Marker.cxx:215
Int_t GetXbin()
Definition: TGo4Marker.cxx:172
virtual void SetMarker(TGo4Marker *mark)
void SetHistogram(TH1 *histo)
Definition: TGo4Marker.cxx:77
static Bool_t fgbXDRAW
Definition: TGo4Marker.h:147
void SaveLabelStyle()
Definition: TGo4Marker.cxx:248
Bool_t CheckHistogram()
Definition: TGo4Marker.cxx:82
static Bool_t fgbYBINDRAW
Definition: TGo4Marker.h:156
void SetPainted(Bool_t on)
Definition: TGo4Marker.h:171
TH1 * GetHistogram() const
Definition: TGo4Marker.h:113
virtual void DisplayToFront(Option_t *opt="")
virtual void PaintLabel(Option_t *opt="")
TVirtualPad * GetDrawPad()
Definition: TGo4Marker.h:131
virtual TGo4MarkerPainter * CreatePainter()
Definition: TGo4Marker.cxx:145
Int_t GetYbin()
Definition: TGo4Marker.cxx:179
TGo4MarkerPainter * fxPainter
Definition: TGo4Marker.h:169
TH1 * fxHisto
Definition: TGo4Marker.h:214
virtual void Draw(Option_t *opt="")
Definition: TGo4Marker.cxx:104
void DeletePainter()
Definition: TGo4Marker.cxx:280
Bool_t fbYbinDraw
Definition: TGo4Marker.h:205
Bool_t fbContDraw
Definition: TGo4Marker.h:208
virtual void UnDraw(Option_t *opt="")
Definition: TGo4Marker.cxx:118
Double_t GetLabelY()
Definition: TGo4Marker.cxx:203
void PrintMarker(Option_t *opt="")
Definition: TGo4Marker.cxx:226
static Bool_t fgbYDRAW
Definition: TGo4Marker.h:150
static const char * Message(Int_t prio, const char *text,...)
Definition: TGo4Log.cxx:209
Bool_t fbXDraw
Definition: TGo4Marker.h:196
static UInt_t fguInstanceCounter
Definition: TGo4Marker.h:221
Bool_t fbHasConnector
Definition: TGo4Marker.h:193
static Bool_t fgbXBINDRAW
Definition: TGo4Marker.h:153
static TString fgxNUMFORMAT
Definition: TGo4Marker.h:162
Double_t GetLabelX()
Definition: TGo4Marker.cxx:195
static Bool_t fgbHASLABEL
Definition: TGo4Marker.h:141
Bool_t fbHasLabel
Definition: TGo4Marker.h:190
TString fxName
Definition: TGo4Marker.h:180
TVirtualPad * fxDrawPad
Definition: TGo4Marker.h:218
Bool_t CheckDrawPad()
Definition: TGo4Marker.cxx:72
void InitLabelStyle()
Definition: TGo4Marker.cxx:260
virtual void UnPaintLabel(Option_t *opt="")
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: TGo4Marker.cxx:134
Bool_t fbYDraw
Definition: TGo4Marker.h:199
virtual ~TGo4Marker()
Definition: TGo4Marker.cxx:60