GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ShapedCond.cxx
Go to the documentation of this file.
1 // $Id: TGo4ShapedCond.cxx 3061 2021-03-12 15:13:42Z linev $
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 "TMath.h"
17 
18 #include "TGo4Log.h"
19 
20 
21 TString TGo4ShapedCond::fgxURL_RESOLUTION ="ellinpts";
22 TString TGo4ShapedCond::fgxURL_CX ="ellicx";
23 TString TGo4ShapedCond::fgxURL_CY ="ellicy";
24 TString TGo4ShapedCond::fgxURL_A1 ="ellia1";
25 TString TGo4ShapedCond::fgxURL_A2 ="ellia2";
26 TString TGo4ShapedCond::fgxURL_TH ="ellith";
27 TString TGo4ShapedCond::fgxURL_SHAPE ="ellishape";
28 
29 // ----------------------------------------------------------
31  TGo4PolyCond(), fiResolution(GO4ELLIPSECOND_DEFAULTRESOLUTION),fdCenterX(0),fdCenterY(0), fdRadius1(0),fdRadius2(0), fdTheta(0),fiShapeType(Go4Cond_Shape_None)
32 {
33 }
34 // ----------------------------------------------------------
35 TGo4ShapedCond::TGo4ShapedCond(const char* name, const char* title) :
36  TGo4PolyCond(name,title), fiResolution(GO4ELLIPSECOND_DEFAULTRESOLUTION),fdCenterX(0),fdCenterY(0), fdRadius1(0),fdRadius2(0), fdTheta(0),fiShapeType(Go4Cond_Shape_None)
37 {
38 }
39 // ----------------------------------------------------------
41 {
42 
43 }
44 
45 
46 // ----------------------------------------------------------
47 void TGo4ShapedCond::PrintCondition(Bool_t points)
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 
59 // ----------------------------------------------------------
60 Bool_t TGo4ShapedCond::UpdateFrom(TGo4Condition * cond, Bool_t counts)
61 {
62  if (!TGo4PolyCond::UpdateFrom(cond, counts))
63  return kFALSE;
64  if (cond->InheritsFrom(TGo4ShapedCond::Class())) {
65  TGo4ShapedCond *from = (TGo4ShapedCond*) cond;
66  fdCenterX = from->fdCenterX;
67  fdCenterY = from->fdCenterY;
68  fdRadius1 = from->fdRadius1;
69  fdRadius2 = from->fdRadius2;
70  fdTheta = from->fdTheta;
71  fiResolution = from->fiResolution;
72 
73  fiShapeType = from->fiShapeType;
74  // TODO: probably later we only update ellipse parameters and render polygon points from that.
75  //PrintCondition();
76  return kTRUE;
77  }
78  std::cout << "Cannot update " << GetName() << " from " << cond->ClassName()
79  << std::endl;
80  return kFALSE;
81 }
82 
83 
84 Bool_t TGo4ShapedCond::UpdateFromUrl(const char* rest_url_opt){
85  //if(!TGo4PolyCond::UpdateFromUrl(rest_url_opt)) return kFALSE;
86  // do not always update polygon points, but first reconstruct from shape parameters!
87 
88  if(!TGo4Condition::UpdateFromUrl(rest_url_opt)) return kFALSE; // still may change condition base class flags
89 
90  TString message;
91  message.Form("TGo4ShapedCond::UpdateFromUrl - condition %s: with url:%s\n", GetName(), rest_url_opt);
92  Double_t x=0,y=0,a=0,b=0;
93  GetCenter(x,y);
94  GetRadius(a,b); // old values as defaults
95  Double_t theta=GetTheta();
100  theta=GetUrlOptionAsInt(TGo4ShapedCond::fgxURL_TH.Data(), theta);
103 
104 
105  if(shapetype==Go4Cond_Shape_Circle)
106  {
107  message.Append(TString::Format("Set to Circle shape with x:%f, y:%f, r:%f, points=%d", x,y,a,resolution));
108  SetCircle(x,y,a,resolution);
109 
110  }
111  else if(shapetype==Go4Cond_Shape_Ellipse)
112  {
113  message.Append(TString::Format("Set to Ellipse shape with x:%f, y:%f, a:%f b:%f,theta:%f, points=%d",
114  x, y, a, b, theta, resolution));
115  SetEllipse(x,y,a,b,theta, resolution);
116  }
117  else if(shapetype==Go4Cond_Shape_Box)
118  {
119  message.Append(TString::Format("Set to Box shape with x:%f, y:%f, a:%f b:%f,theta:%f",
120  x, y, a, b, theta));
121  SetBox(x,y,a,b,theta);
122  }
123  else if(shapetype==Go4Cond_Shape_Free)
124  {
125  message.Append(TString::Format("Set to Free polygon shape!"));
126  SetFreeShape();
127  if(!TGo4PolyCond::UpdateFromUrl(rest_url_opt)) return kFALSE; // here we might get also different point coordinates...
128  }
129  TGo4Log::Message(1,message.Data());
130  return kTRUE;
131 }
132 
133 
134 void TGo4ShapedCond::SetEllipse(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta, Int_t npoints)
135 {
136  fiResolution=npoints;
137  fdCenterX=cx;
138  fdCenterY=cy;
139  fdRadius1=a1;
140  fdRadius2=a2;
141  fdTheta=theta;
142  SetEllipse();
143  ResetPolygon();
144 }
145 
146 
147 void TGo4ShapedCond::SetCircle(Double_t cx, Double_t cy, Double_t r, Int_t npoints)
148 {
149  fiResolution=npoints;
150  fdCenterX=cx;
151  fdCenterY=cy;
152  fdRadius1=r;
153  fdRadius2=r;
154  fdTheta=0.;
155  SetCircle();
156  ResetPolygon();
157 }
158 
159 void TGo4ShapedCond::SetBox(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta)
160 {
161  fiResolution=4;
162  fdCenterX=cx;
163  fdCenterY=cy;
164  fdRadius1=a1;
165  fdRadius2=a2;
166  fdTheta=theta;
167  SetBox();
168  ResetPolygon();
169 }
170 
171 void TGo4ShapedCond::SetCenter(Double_t x, Double_t y)
172 {
173  fdCenterX=x;
174  fdCenterY=y;
175  ResetPolygon();
176 }
177 
178 void TGo4ShapedCond::SetRadius(Double_t a1, Double_t a2)
179 {
180  fdRadius1=a1;
181  fdRadius2=a2;
182  ResetPolygon();
183 }
184 
185 void TGo4ShapedCond::SetTheta(Double_t angle)
186 {
187  fdTheta=angle;
188  ResetPolygon();
189 }
190 
192 {
193  // stolen from ROOT TEllipse rendering code. we use it just to calculate polygon points
194  // thanks to Sven Augustin, MPI Heidelberg, for the idea and first version of the code!
196  Double_t *x = new Double_t[fiResolution+1];
197  Double_t *y = new Double_t[fiResolution+1];
198  if(IsEllipse() || IsCircle())
200  else if(IsBox())
201  DefineBox(x,y,fiResolution);
202  else
203  {
204  delete[] x;
205  delete[] y;
206  return;
207  }
208  SetValues(x,y, fiResolution+1);
209 
210  delete[] x;
211  delete[] y;
212 
213 }
214 
215 
216 void TGo4ShapedCond::DefineEllipse(Double_t *x, Double_t *y, Int_t n)
217 {
218  Double_t dx,dy;
219  Double_t dphi = TMath::TwoPi()/n;
220  Double_t ct = TMath::Cos(TMath::Pi()*fdTheta/180);
221  Double_t st = TMath::Sin(TMath::Pi()*fdTheta/180);
222  for (Int_t i = 0; i < n; i++)
223  {
224  dx = fdRadius1 * TMath::Cos((Double_t) i * dphi);
225  dy = fdRadius2 * TMath::Sin((Double_t) i * dphi);
226  x[i] = fdCenterX + dx * ct - dy * st;
227  y[i] = fdCenterY + dx * st + dy * ct;
228  }
229  x[n] = x[0];
230  y[n] = y[0];
231 
232  // from SvenA. for circle only
233  // const Int_t n = 30; //i.e., 12 degrees per slice
234  // Double_t x[n+1], y[n+1];
235  // Double_t dphi = TMath::TwoPi()/n;
236  // for (Int_t i=0; i<n; i++)
237  // {
238  // x[i] = x0 + rad * TMath::Cos(i*dphi);
239  // y[i] = y0 + rad * TMath::Sin(i*dphi);
240  // }
241  // x[n] = x[0];
242  // y[n] = y[0];
243 
244 
245 
246 }
247 
248 void TGo4ShapedCond::DefineBox(Double_t *x, Double_t *y, Int_t n)
249 {
250  Double_t ct = TMath::Cos(TMath::Pi()*fdTheta/180);
251  Double_t st = TMath::Sin(TMath::Pi()*fdTheta/180);
252  x[0] = fdCenterX + fdRadius1 * ct + fdRadius2 * st;
253  y[0] = fdCenterY + fdRadius1 * st - fdRadius2 * ct;
254  x[1] = fdCenterX + fdRadius1 * ct - fdRadius2 * st;
255  y[1] = fdCenterY + fdRadius1 * st + fdRadius2 * ct;
256  x[2] = fdCenterX - (fdRadius1 * ct + fdRadius2 * st);
257  y[2] = fdCenterY - (fdRadius1 * st - fdRadius2 * ct);
258  x[3] = fdCenterX - (fdRadius1 * ct - fdRadius2 * st);
259  y[3] = fdCenterY - (fdRadius1 * st + fdRadius2 * ct);
260  for(Int_t i=4; i< n+1; ++i)
261  {
262  x[i] = x[0];
263  y[i] = y[0];
264  }
265 }
void SetTheta(Double_t angle)
virtual void PrintCondition(Bool_t points=kTRUE)
void GetRadius(Double_t &a1, Double_t &a2)
Double_t fdCenterX
static TString fgxURL_TH
void DefineEllipse(Double_t *x, Double_t *y, Int_t n)
Bool_t IsCircle() const
static TString fgxURL_SHAPE
const char * GetShapeName()
Double_t fdRadius2
Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts)
static TString fgxURL_A1
Bool_t IsEllipse() const
void DefineBox(Double_t *x, Double_t *y, Int_t n)
Int_t GetResolution()
virtual void SetValues()
Definition: TGo4Condition.h:93
void SetRadius(Double_t a1, Double_t a2)
Bool_t IsBox() const
void SetCenter(Double_t x, Double_t y)
tuple a
Definition: go4init.py:12
virtual Bool_t UpdateFromUrl(const char *rest_url_opt)
virtual Bool_t UpdateFromUrl(const char *rest_url_opt)
virtual Bool_t UpdateFromUrl(const char *rest_url_opt)
static TString fgxURL_CY
static TString fgxURL_CX
static const char * Message(Int_t prio, const char *text,...)
Definition: TGo4Log.cxx:207
static TString fgxURL_A2
virtual void PrintCondition(Bool_t points=kTRUE)
Double_t fdRadius1
void GetCenter(Double_t &x, Double_t &y)
static TString fgxURL_RESOLUTION
Double_t fdCenterY
Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts)
Go4CondShape_t fiShapeType
Double_t GetTheta()
virtual ~TGo4ShapedCond()
Int_t GetUrlOptionAsInt(const char *key, Int_t def_value)
#define GO4ELLIPSECOND_DEFAULTRESOLUTION
Double_t GetUrlOptionAsDouble(const char *key, Double_t def_value)