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