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