GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4ShapedCond.cxx
Go to the documentation of this file.
1// $Id$
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 fuer 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 "TGo4ShapedCond.h"
15
16#include <vector>
17
18#include "TMath.h"
19
20#include "TGo4Log.h"
21
22
23TString TGo4ShapedCond::fgxURL_RESOLUTION ="ellinpts";
24TString TGo4ShapedCond::fgxURL_CX ="ellicx";
25TString TGo4ShapedCond::fgxURL_CY ="ellicy";
26TString TGo4ShapedCond::fgxURL_A1 ="ellia1";
27TString TGo4ShapedCond::fgxURL_A2 ="ellia2";
28TString TGo4ShapedCond::fgxURL_TH ="ellith";
29TString TGo4ShapedCond::fgxURL_SHAPE ="ellishape";
30
31// ----------------------------------------------------------
36// ----------------------------------------------------------
41// ----------------------------------------------------------
45
46// ----------------------------------------------------------
48{
50 std::cout << "**** Geometrical shaped condition with parameters:" << std::endl;
51 std::cout << "**** Shape Type: "<<fiShapeType << "("<<GetShapeName()<<")"<<std::endl;
52 std::cout << "**** Center: ("<<fdCenterX<<","<< fdCenterY<<")" << std::endl;
53 std::cout << "**** Radius: ("<<fdRadius1<<","<< fdRadius2<<")" << std::endl;
54 std::cout << "**** Tilt: "<<fdTheta<<" deg" << std::endl;
55 std::cout << "**** Resolution: "<<fiResolution<<" points" << std::endl;
56}
57
58// ----------------------------------------------------------
59Bool_t TGo4ShapedCond::UpdateFrom(TGo4Condition *cond, Bool_t counts)
60{
61 if (!TGo4PolyCond::UpdateFrom(cond, counts))
62 return kFALSE;
63 if (cond->InheritsFrom(TGo4ShapedCond::Class())) {
64 TGo4ShapedCond *from = (TGo4ShapedCond*) cond;
65 fdCenterX = from->fdCenterX;
66 fdCenterY = from->fdCenterY;
67 fdRadius1 = from->fdRadius1;
68 fdRadius2 = from->fdRadius2;
69 fdTheta = from->fdTheta;
71
73 // TODO: probably later we only update ellipse parameters and render polygon points from that.
74 //PrintCondition();
75 return kTRUE;
76 }
77 std::cout << "Cannot update " << GetName() << " from " << cond->ClassName()
78 << std::endl;
79 return kFALSE;
80}
81
82
83Bool_t TGo4ShapedCond::UpdateFromUrl(const char *rest_url_opt){
84 //if(!TGo4PolyCond::UpdateFromUrl(rest_url_opt)) return kFALSE;
85 // do not always update polygon points, but first reconstruct from shape parameters!
86
87 if(!TGo4Condition::UpdateFromUrl(rest_url_opt)) return kFALSE; // still may change condition base class flags
88
89 TString message;
90 message.Form("TGo4ShapedCond::UpdateFromUrl - condition %s: with url:%s\n", GetName(), rest_url_opt);
91 Double_t x = 0, y = 0, a = 0, b = 0;
92 GetCenter(x, y);
93 GetRadius(a, b); // old values as defaults
94 Double_t theta = GetTheta();
99 theta = GetUrlOptionAsInt(TGo4ShapedCond::fgxURL_TH.Data(), theta);
102
103 if (shapetype == Go4Cond_Shape_Circle) {
104 message.Append(TString::Format("Set to Circle shape with x:%f, y:%f, r:%f, points=%d", x, y, a, resolution));
105 SetCircle(x, y, a, resolution);
106 } else if (shapetype == Go4Cond_Shape_Ellipse) {
107 message.Append(TString::Format("Set to Ellipse shape with x:%f, y:%f, a:%f b:%f,theta:%f, points=%d", x, y, a, b,
108 theta, resolution));
109 SetEllipse(x, y, a, b, theta, resolution);
110 } else if (shapetype == Go4Cond_Shape_Box) {
111 message.Append(TString::Format("Set to Box shape with x:%f, y:%f, a:%f b:%f,theta:%f", x, y, a, b, theta));
112 SetBox(x, y, a, b, theta);
113 } else if (shapetype == Go4Cond_Shape_Free) {
114 message.Append("Set to Free polygon shape!");
115 SetFreeShape();
116 if (!TGo4PolyCond::UpdateFromUrl(rest_url_opt))
117 return kFALSE; // here we might get also different point coordinates...
118 }
119 TGo4Log::Message(1, "%s", message.Data());
120 return kTRUE;
121}
122
123
124void TGo4ShapedCond::SetEllipse(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta, Int_t npoints)
125{
126 fiResolution = npoints;
127 fdCenterX = cx;
128 fdCenterY = cy;
129 fdRadius1 = a1;
130 fdRadius2 = a2;
131 fdTheta = theta;
132 SetEllipse();
133 ResetPolygon();
134}
135
136void TGo4ShapedCond::SetCircle(Double_t cx, Double_t cy, Double_t r, Int_t npoints)
137{
138 fiResolution = npoints;
139 fdCenterX = cx;
140 fdCenterY = cy;
141 fdRadius1 = r;
142 fdRadius2 = r;
143 fdTheta = 0.;
144 SetCircle();
145 ResetPolygon();
146}
147
148void TGo4ShapedCond::SetBox(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta)
149{
150 fiResolution = 4;
151 fdCenterX = cx;
152 fdCenterY = cy;
153 fdRadius1 = a1;
154 fdRadius2 = a2;
155 fdTheta = theta;
156 SetBox();
157 ResetPolygon();
158}
159
160void TGo4ShapedCond::SetCenter(Double_t x, Double_t y)
161{
162 fdCenterX = x;
163 fdCenterY = y;
164 ResetPolygon();
165}
166
167void TGo4ShapedCond::SetRadius(Double_t a1, Double_t a2)
168{
169 fdRadius1 = a1;
170 fdRadius2 = a2;
171 ResetPolygon();
172}
173
174void TGo4ShapedCond::SetTheta(Double_t angle)
175{
176 fdTheta = angle;
177 ResetPolygon();
178}
179
181{
182 // stolen from ROOT TEllipse rendering code. we use it just to calculate polygon points
183 // thanks to Sven Augustin, MPI Heidelberg, for the idea and first version of the code!
184 if (fiResolution == 0)
186 std::vector<Double_t> x(fiResolution + 1), y(fiResolution + 1);
187 if (IsEllipse() || IsCircle())
188 DefineEllipse(x.data(), y.data(), fiResolution);
189 else if (IsBox())
190 DefineBox(x.data(), y.data(), fiResolution);
191 else {
192 return;
193 }
194 SetValues(x.data(), y.data(), fiResolution + 1);
195}
196
197void TGo4ShapedCond::DefineEllipse(Double_t *x, Double_t *y, Int_t n)
198{
199 Double_t dphi = TMath::TwoPi()/n;
200 Double_t ct = TMath::Cos(TMath::Pi()*fdTheta/180);
201 Double_t st = TMath::Sin(TMath::Pi()*fdTheta/180);
202 for (Int_t i = 0; i < n; i++)
203 {
204 Double_t dx = fdRadius1 * TMath::Cos((Double_t) i * dphi);
205 Double_t dy = fdRadius2 * TMath::Sin((Double_t) i * dphi);
206 x[i] = fdCenterX + dx * ct - dy * st;
207 y[i] = fdCenterY + dx * st + dy * ct;
208 }
209 x[n] = x[0];
210 y[n] = y[0];
211}
212
213void TGo4ShapedCond::DefineBox(Double_t *x, Double_t *y, Int_t n)
214{
215 Double_t ct = TMath::Cos(TMath::Pi()*fdTheta/180);
216 Double_t st = TMath::Sin(TMath::Pi()*fdTheta/180);
217 x[0] = fdCenterX + fdRadius1 * ct + fdRadius2 * st;
218 y[0] = fdCenterY + fdRadius1 * st - fdRadius2 * ct;
219 x[1] = fdCenterX + fdRadius1 * ct - fdRadius2 * st;
220 y[1] = fdCenterY + fdRadius1 * st + fdRadius2 * ct;
221 x[2] = fdCenterX - (fdRadius1 * ct + fdRadius2 * st);
222 y[2] = fdCenterY - (fdRadius1 * st - fdRadius2 * ct);
223 x[3] = fdCenterX - (fdRadius1 * ct - fdRadius2 * st);
224 y[3] = fdCenterY - (fdRadius1 * st + fdRadius2 * ct);
225 for(Int_t i=4; i< n+1; ++i)
226 {
227 x[i] = x[0];
228 y[i] = y[0];
229 }
230}
#define GO4ELLIPSECOND_DEFAULTRESOLUTION
@ Go4Cond_Shape_Box
@ Go4Cond_Shape_Free
@ Go4Cond_Shape_None
@ Go4Cond_Shape_Circle
@ Go4Cond_Shape_Ellipse
Double_t GetUrlOptionAsDouble(const char *key, Double_t def_value)
Scan list of url options for key.
virtual Bool_t UpdateFromUrl(const char *rest_url_opt)
Method used by HTTP server to update some fields, specified in URL syntax.
Int_t GetUrlOptionAsInt(const char *key, Int_t def_value)
Scan list of url options for key.
static const char * Message(Int_t prio, const char *text,...) GO4_PRINTF2_ARGS
Display a message.
Definition TGo4Log.cxx:206
void PrintCondition(Bool_t points=kTRUE) override
Printout values.
Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts) override
Copy values from cond to this.
Bool_t UpdateFromUrl(const char *rest_url_opt) override
Method used by HTTP server to update some fields, specified in URL syntax.
virtual void SetValues()
Set values needed, i.e.
void DefineEllipse(Double_t *x, Double_t *y, Int_t n)
Bool_t UpdateFromUrl(const char *rest_url_opt) override
Method used by HTTP server to update some fields, specified in URL syntax.
void SetTheta(Double_t angle)
Bool_t IsCircle() const
void DefineBox(Double_t *x, Double_t *y, Int_t n)
static TString fgxURL_A1
web condition editor keyword used in UpdateFromUrl.
void GetRadius(Double_t &a1, Double_t &a2) const
Bool_t IsBox() const
Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts) override
Copy values from cond to this.
Go4CondShape_t fiShapeType
void SetCenter(Double_t x, Double_t y)
const char * GetShapeName() const
Double_t GetTheta() const
static TString fgxURL_A2
web condition editor keyword used in UpdateFromUrl.
static TString fgxURL_CX
web condition editor keyword used in UpdateFromUrl.
void GetCenter(Double_t &x, Double_t &y) const
Int_t GetResolution() const
static TString fgxURL_CY
web condition editor keyword used in UpdateFromUrl.
virtual ~TGo4ShapedCond()
void SetRadius(Double_t a1, Double_t a2)
static TString fgxURL_SHAPE
web condition editor keyword used in UpdateFromUrl.
static TString fgxURL_TH
web condition editor keyword used in UpdateFromUrl.
Bool_t IsEllipse() const
void PrintCondition(Bool_t points=kTRUE) override
Printout values.
static TString fgxURL_RESOLUTION
web condition editor keyword used in UpdateFromUrl.