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