00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4Marker.h"
00017
00018 #include "Riostream.h"
00019
00020 #include "TH1.h"
00021 #include "TROOT.h"
00022 #include "TVirtualPad.h"
00023 #include "snprintf.h"
00024
00025 #include "TGo4MarkerPainter.h"
00026 #include "TGo4Log.h"
00027
00028 UInt_t TGo4Marker::fguInstanceCounter=0;
00029
00030 Bool_t TGo4Marker::fgbHASLABEL=kTRUE;
00031 Bool_t TGo4Marker::fgbHASCONNECTOR=kTRUE;
00032 Bool_t TGo4Marker::fgbXDRAW=kTRUE;
00033 Bool_t TGo4Marker::fgbYDRAW=kTRUE;
00034 Bool_t TGo4Marker::fgbXBINDRAW=kFALSE;
00035 Bool_t TGo4Marker::fgbYBINDRAW=kFALSE;
00036 Bool_t TGo4Marker::fgbCONTDRAW=kTRUE;
00037
00038
00039 TGo4Marker::TGo4Marker(Double_t x, Double_t y, Int_t style)
00040 : TMarker(x,y,style),fxPainter(0),
00041 fbIsPainted(kFALSE), fbVisible(kTRUE), fbHasLabel(kTRUE), fbHasConnector(kTRUE),
00042 fbXDraw(kTRUE), fbYDraw(kTRUE), fbXbinDraw(kTRUE), fbYbinDraw(kTRUE), fbContDraw(kTRUE),
00043 fxHisto(0),fxDrawPad(0)
00044 {
00045 fxName="Marker ";
00046 fxName+=++fguInstanceCounter;
00047 InitLabelStyle();
00048 SetBit(kMustCleanup);
00049 }
00050
00051 TGo4Marker::TGo4Marker()
00052 : TMarker(), fxPainter(0),
00053 fbIsPainted(kFALSE), fbVisible(kTRUE), fbHasLabel(kTRUE), fbHasConnector(kTRUE),
00054 fbXDraw(kTRUE), fbYDraw(kTRUE), fbXbinDraw(kTRUE), fbYbinDraw(kTRUE), fbContDraw(kTRUE),
00055 fxHisto(0),fxDrawPad(0)
00056 {
00057
00058 InitLabelStyle();
00059 SetBit(kMustCleanup);
00060 }
00061
00062 TGo4Marker::~TGo4Marker()
00063 {
00064 UnDraw();
00065 if(fxPainter) delete fxPainter;
00066
00067 }
00068
00069 void TGo4Marker::SetDrawPad(TVirtualPad* pad)
00070 {
00071 fxDrawPad=pad;
00072 }
00073
00074 Bool_t TGo4Marker::CheckDrawPad()
00075 {
00076 return fxDrawPad!=0;
00077 }
00078
00079 void TGo4Marker::SetHistogram(TH1* histo)
00080 {
00081 fxHisto=histo;
00082 }
00083
00084 Bool_t TGo4Marker::CheckHistogram()
00085 {
00086 return fxHisto!=0;
00087 }
00088
00089
00090 void TGo4Marker::Paint(Option_t* opt)
00091 {
00092
00094 if(!CheckDrawPad() && !IsPainted())
00095 {
00096 SetDrawPad(gPad);
00097 if(IsVisible()) SetPainted(kTRUE);
00098 }
00099 if(!IsPainted() || GetDrawPad()!=gPad) return;
00100 TMarker::Paint(opt);
00101 if(fxPainter==0) fxPainter=CreatePainter();
00102
00103 if(fxPainter!=0) fxPainter->PaintLabel(opt);
00104 }
00105
00106 void TGo4Marker::Draw(Option_t* opt)
00107 {
00108 if(IsVisible()) {
00109 if(gPad && gPad->GetListOfPrimitives()->FindObject(this)==0) {
00110 UnDraw();
00111 AppendPad(opt);
00112 SetPainted(kTRUE);
00113 }
00114 } else
00115 UnDraw(opt);
00116
00117 SetDrawPad(gPad);
00118 }
00119
00120 void TGo4Marker::UnDraw(Option_t* opt)
00121 {
00122 SetPainted(kFALSE);
00123 SetDrawPad(0);
00124 gROOT->GetListOfCanvases()->RecursiveRemove(this);
00125 if(fxPainter==0) fxPainter = CreatePainter();
00126
00127 if(fxPainter!=0) fxPainter->UnPaintLabel();
00128 }
00129
00130 void TGo4Marker::Pop()
00131 {
00132 if(fxPainter!=0) fxPainter->DisplayToFront();
00133 }
00134
00135
00136 void TGo4Marker::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00137 {
00138 if(gPad==0) return;
00139 TMarker::ExecuteEvent(event,px,py);
00140 if(event==kButton1Up)
00141 {
00142 if(fxPainter!=0) fxPainter->DisplayToFront();
00143 }
00144 }
00145
00146
00147 TGo4MarkerPainter* TGo4Marker::CreatePainter()
00148 {
00149 TGo4MarkerPainter* painter=new TGo4MarkerPainter(GetName());
00150 painter->SetMarker(this);
00151 return painter;
00152 }
00153
00154 void TGo4Marker::SetToBin(Int_t xbin, Int_t ybin)
00155 {
00156 if(!CheckHistogram()) return;
00157 Int_t bin = fxHisto->GetBin(xbin,ybin);
00158 Stat_t content = fxHisto->GetBinContent(bin);
00159 Double_t x=fxHisto->GetXaxis()->GetBinCenter(xbin);
00160 Double_t y=0;
00161 if(fxHisto->GetDimension()==1)
00162 {
00163 y=content;
00164 }
00165 else if (fxHisto->GetDimension()==2)
00166 {
00167 y=fxHisto->GetYaxis()->GetBinCenter(ybin);
00168 }
00169 SetX(x);
00170 SetY(y);
00171 }
00172
00173
00174 Int_t TGo4Marker::GetXbin()
00175 {
00176 if(!CheckHistogram() || !CheckDrawPad()) return -1;
00177 Int_t binx = fxHisto->GetXaxis()->FindFixBin(fxDrawPad->PadtoX(GetX()));
00178 return binx;
00179 }
00180
00181 Int_t TGo4Marker::GetYbin()
00182 {
00183 if(!CheckHistogram() || !CheckDrawPad()) return -1;
00184 Int_t biny = fxHisto->GetYaxis()->FindFixBin(fxDrawPad->PadtoY(GetY()));
00185 return biny;
00186
00187 }
00188
00189 Int_t TGo4Marker::GetCont()
00190 {
00191 if(!CheckHistogram() || !CheckDrawPad())return -1;
00192 Int_t bin = fxHisto->GetBin(GetXbin(),GetYbin());
00193 Stat_t content = fxHisto->GetBinContent(bin);
00194 return (Int_t) content;
00195 }
00196
00197 Double_t TGo4Marker::GetLabelX()
00198 {
00199 if(!CheckDrawPad()) return 0;
00200 Double_t xoff=0.01*(fxDrawPad->GetUxmax()-fxDrawPad->GetUxmin());
00201 Double_t xpos=GetX()+xoff;
00202 return xpos;
00203 }
00204
00205 Double_t TGo4Marker::GetLabelY()
00206 {
00207 if(!CheckDrawPad()) return 0;
00208 Double_t yoff=0.01*(fxDrawPad->GetUymax()-fxDrawPad->GetUymin());
00209 Double_t ypos=0;
00210 if(GetY()==0)
00211 ypos=(fxDrawPad->GetUymax()-fxDrawPad->GetUymin())/2;
00212 else
00213 ypos=GetY()+yoff;
00214 return ypos;
00215 }
00216
00217 void TGo4Marker::Print(Option_t* opt) const{
00218 TGo4Marker* localthis=const_cast<TGo4Marker*>(this);
00219 localthis->PrintMarker(opt);
00220 }
00221
00222
00223
00224
00225
00226
00227
00228 void TGo4Marker::PrintMarker(Option_t* opt)
00229 {
00230 TString option=opt;
00231 option.ToLower();
00232 TString textbuffer="Marker ";
00233 textbuffer+=GetName();
00234 textbuffer+=" with";
00235 TH1* hist=GetHistogram();
00236 if(hist)
00237 {
00238 textbuffer+=" histogram: ";
00239 textbuffer+=hist->GetName();
00240 }
00241 else
00242 {
00243 textbuffer+="out histogram";
00244 }
00245 Text_t buffer[256];
00246 snprintf(buffer,256,
00247 "\n X: \t\tY: \t\tXbin:\t\tYbin:\t\tCounts:\n %.2f\t\t%.2f\t\t%d\t\t%d\t\t%d",
00248 GetX(), GetY(), GetXbin(),GetYbin(),GetCont());
00249 textbuffer+=buffer;
00250 if(option.Contains("go4log"))
00251 {
00252 TGo4Log::Message(1,textbuffer.Data());
00253 }
00254 else
00255 {
00256 cout << textbuffer.Data() << endl;
00257 }
00258 }
00259
00260 void TGo4Marker::SaveLabelStyle()
00261 {
00262 TGo4Marker::fgbHASLABEL=fbHasLabel;
00263 TGo4Marker::fgbHASCONNECTOR=fbHasConnector;
00264 TGo4Marker::fgbXDRAW=fbXDraw;
00265 TGo4Marker::fgbYDRAW=fbYDraw;
00266 TGo4Marker::fgbXBINDRAW=fbXbinDraw;
00267 TGo4Marker::fgbYBINDRAW=fbYbinDraw;
00268 TGo4Marker::fgbCONTDRAW=fbContDraw;
00269 }
00270
00271 void TGo4Marker::InitLabelStyle()
00272 {
00273 fbHasLabel=TGo4Marker::fgbHASLABEL;
00274 fbHasConnector=TGo4Marker::fgbHASCONNECTOR;
00275 fbXDraw=TGo4Marker::fgbXDRAW;
00276 fbYDraw=TGo4Marker::fgbYDRAW;
00277 fbXbinDraw=TGo4Marker::fgbXBINDRAW;
00278 fbYbinDraw=TGo4Marker::fgbYBINDRAW;
00279 fbContDraw=TGo4Marker::fgbCONTDRAW;
00280 }
00281
00282 void TGo4Marker::ResetLabel()
00283 {
00284 if(fxPainter!=0) {
00285 fxPainter->UnPaintLabel("reset");
00286 fxPainter->PaintLabel();
00287 }
00288 }
00289
00290 void TGo4Marker::DeletePainter()
00291 {
00292 if (fxPainter!=0) {
00293 delete fxPainter;
00294 fxPainter = 0;
00295 }
00296 }
00297
00298