00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Riostream.h"
00013 #include "TROOT.h"
00014 #include "TMath.h"
00015 #include "TCrown.h"
00016 #include "TVirtualPad.h"
00017
00018 ClassImp(TCrown)
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 TCrown::TCrown(): TEllipse()
00055 {
00056
00057
00058
00059
00060 }
00061
00062
00063
00064 TCrown::TCrown(Double_t x1, Double_t y1,Double_t radin, Double_t radout,Double_t phimin,Double_t phimax)
00065 :TEllipse(x1,y1,radin,radout,phimin,phimax,0)
00066 {
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 }
00082
00083
00084
00085 TCrown::TCrown(const TCrown &crown) : TEllipse(crown)
00086 {
00087
00088
00089
00090
00091 ((TCrown&)crown).Copy(*this);
00092 }
00093
00094
00095
00096 TCrown::~TCrown()
00097 {
00098
00099
00100
00101 }
00102
00103
00104
00105 void TCrown::Copy(TObject &crown) const
00106 {
00107
00108
00109
00110
00111 TEllipse::Copy(crown);
00112 }
00113
00114
00115
00116 Int_t TCrown::DistancetoPrimitive(Int_t px, Int_t py)
00117 {
00118
00119
00120
00121
00122
00123
00124
00125 const Double_t kPI = TMath::Pi();
00126 Double_t x = gPad->PadtoX(gPad->AbsPixeltoX(px)) - fX1;
00127 Double_t y = gPad->PadtoY(gPad->AbsPixeltoY(py)) - fY1;
00128
00129 Double_t r1 = fR1;
00130 Double_t r2 = fR2;
00131 Double_t r = TMath::Sqrt(x*x+y*y);
00132
00133 if (r1>r2) {
00134 r1 = fR2;
00135 r2 = fR1;
00136 }
00137
00138 Int_t dist = 9999;
00139 if (r > r2) return dist;
00140 if (r < r1) return dist;
00141 if (fPhimax-fPhimin < 360) {
00142 Double_t phi = 180*TMath::ACos(x/r)/kPI;
00143 if (y<0) phi = 360-phi;
00144 Double_t phi1 = fPhimin;
00145 Double_t phi2 = fPhimax;
00146 if (phi1<0) phi1=phi1+360;
00147 if (phi2<0) phi2=phi2+360;
00148 if (phi2<phi1) {
00149 if (phi < phi1 && phi > phi2) return dist;
00150 } else {
00151 if (phi < phi1) return dist;
00152 if (phi > phi2) return dist;
00153 }
00154 }
00155
00156 if (GetFillColor() && GetFillStyle()) {
00157 return 0;
00158 } else {
00159 if (TMath::Abs(r2-r)/r2 < 0.02) return 0;
00160 if (TMath::Abs(r1-r)/r1 < 0.02) return 0;
00161 }
00162 return dist;
00163 }
00164
00165
00166
00167 void TCrown::DrawCrown(Double_t x1, Double_t y1,Double_t radin,Double_t radout,Double_t phimin,Double_t phimax,Option_t *option)
00168 {
00169
00170
00171
00172
00173 TCrown *newcrown = new TCrown(x1, y1, radin, radout, phimin, phimax);
00174 TAttLine::Copy(*newcrown);
00175 TAttFill::Copy(*newcrown);
00176 newcrown->SetBit(kCanDelete);
00177 newcrown->AppendPad(option);
00178 }
00179
00180
00181
00182 void TCrown::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00183 {
00184
00185
00186
00187
00188
00189
00190 TEllipse::ExecuteEvent(event,px,py);
00191 }
00192
00193
00194
00195 void TCrown::Paint(Option_t *)
00196 {
00197
00198
00199
00200
00201 const Double_t kPI = TMath::Pi();
00202 const Int_t np = 40;
00203 static Double_t x[2*np+3], y[2*np+3];
00204 TAttLine::Modify();
00205 TAttFill::Modify();
00206
00207 Double_t angle,dx,dy;
00208 Double_t dphi = (fPhimax-fPhimin)*kPI/(180*np);
00209 Double_t ct = TMath::Cos(kPI*fTheta/180);
00210 Double_t st = TMath::Sin(kPI*fTheta/180);
00211 Int_t i;
00212
00213 for (i=0;i<=np;i++) {
00214 angle = fPhimin*kPI/180 + Double_t(i)*dphi;
00215 dx = fR2*TMath::Cos(angle);
00216 dy = fR2*TMath::Sin(angle);
00217 x[i] = fX1 + dx*ct - dy*st;
00218 y[i] = fY1 + dx*st + dy*ct;
00219 }
00220
00221 for (i=0;i<=np;i++) {
00222 angle = fPhimin*kPI/180 + Double_t(i)*dphi;
00223 dx = fR1*TMath::Cos(angle);
00224 dy = fR1*TMath::Sin(angle);
00225 x[2*np-i+1] = fX1 + dx*ct - dy*st;
00226 y[2*np-i+1] = fY1 + dx*st + dy*ct;
00227 }
00228 x[2*np+2] = x[0];
00229 y[2*np+2] = y[0];
00230 if (fPhimax-fPhimin >= 360 ) {
00231
00232 if (GetFillColor() && GetFillStyle()) {
00233 gPad->PaintFillArea(2*np+2,x,y);
00234 }
00235
00236 if (GetLineStyle()) {
00237 gPad->PaintPolyLine(np+1,x,y);
00238 gPad->PaintPolyLine(np+1,&x[np+1],&y[np+1]);
00239 }
00240 } else {
00241
00242 if (GetFillColor() && GetFillStyle()) gPad->PaintFillArea(2*np+2,x,y);
00243 if (GetLineStyle()) gPad->PaintPolyLine(2*np+3,x,y);
00244 }
00245 }
00246
00247
00248
00249 void TCrown::SavePrimitive(ostream &out, Option_t * )
00250 {
00251
00252
00253
00254
00255 out<<" "<<endl;
00256 if (gROOT->ClassSaved(TCrown::Class())) {
00257 out<<" ";
00258 } else {
00259 out<<" TCrown *";
00260 }
00261 out<<"crown = new TCrown("<<fX1<<","<<fY1<<","<<fR1<<","<<fR2
00262 <<","<<fPhimin<<","<<fPhimax<<");"<<endl;
00263
00264 SaveFillAttributes(out,"crown",0,1001);
00265 SaveLineAttributes(out,"crown",1,1,1);
00266
00267 if (GetNoEdges()) out<<" crown->SetNoEdges();"<<endl;
00268
00269 out<<" crown->Draw();"<<endl;
00270 }