GeoModel - GeoModelCore
GeoXF.cxx
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GeoModelKernel/GeoXF.h"
6 #include "GeoModelKernel/GeoDefinitions.h"
7 #include <stdexcept>
8 namespace GeoXF
9 {
10 
11 
12 
13  //------------------------------------------------------------------//
14  // //
15  // Implementation of Function //
16  // //
17  //------------------------------------------------------------------//
18 
19  Function::Function ()
20  {
21  }
22 
23  Function::~Function ()
24  {
25  }
26 
27  Product operator * (const Function & a, const Function & b)
28  {
29  return Product (&a, &b);
30  }
31 
32  PreMult operator * (const GeoTrf::Transform3D & xf, const Function & b)
33  {
34  return PreMult (xf, &b);
35  }
36 
37  PostMult operator * (const Function & a, const GeoTrf::Transform3D & xf)
38  {
39  return PostMult (&a, xf);
40  }
41 
42  unsigned int Function::dimensionality () const
43  {
44  return 1;
45  }
46 
47  //------------------------------------------------------------------//
48  // //
49  // Implementation of Product //
50  // //
51  //------------------------------------------------------------------//
52 
53  Product::Product (const Function * arg1,
54  const Function * arg2):m_arg1 (arg1->clone ()),
55  m_arg2 (arg2->clone ())
56  {
57  if (arg1->dimensionality () != arg2->dimensionality ())
58  {
59  throw std::
60  runtime_error ("Warning: dimension mismatch in GeoXF::Product");
61  }
62  }
63 
64 
65  // Every function must override this:
66  Product *Product::clone () const
67  {
68  return new Product (*this);
69  }
70 
71  // Copy constructor:
72  Product::Product (const Product & right):Function (),
73  m_arg1 (right.m_arg1->clone ()), m_arg2 (right.m_arg2->clone ())
74  {
75  }
76 
77 
78  Product::~Product ()
79  {
80  delete m_arg1;
81  delete m_arg2;
82  }
83 
84  unsigned int Product::dimensionality () const
85  {
86  return m_arg1->dimensionality ();
87  }
88 
89  GeoTrf::Transform3D Product::operator () (double x) const
90  {
91  return (*m_arg1) (x) * (*m_arg2) (x);
92  }
93 
94  GeoTrf::Transform3D Product::operator () (const GeoGenfun::Argument & x) const
95  {
96  return (*m_arg1) (x) * (*m_arg2) (x);
97  }
98 
99 
100 
101  //------------------------------------------------------------------//
102  // //
103  // Implementation of PreMult //
104  // //
105  //------------------------------------------------------------------
106 
107  PreMult::PreMult (const GeoTrf::Transform3D & arg1,
108  const Function * arg2):m_arg1 (arg1),
109  m_arg2 (arg2->clone ())
110  {
111  }
112 
113 
114  // Every function must override this:
115  PreMult *PreMult::clone () const
116  {
117  return new PreMult (*this);
118  }
119 
120  // Copy constructor:
121  PreMult::PreMult (const PreMult & right):Function (), m_arg1 (right.m_arg1),
122  m_arg2 (right.m_arg2->clone ())
123  {
124  }
125 
126 
127  PreMult::~PreMult ()
128  {
129  delete m_arg2;
130  }
131 
132  unsigned int PreMult::dimensionality () const
133  {
134  return m_arg2->dimensionality ();
135  }
136 
137  GeoTrf::Transform3D PreMult::operator () (double x) const
138  {
139  return m_arg1 * (*m_arg2) (x);
140  }
141 
142  GeoTrf::Transform3D PreMult::operator () (const GeoGenfun::Argument & x) const
143  {
144  return m_arg1 * (*m_arg2) (x);
145  }
146 
147 
148  //------------------------------------------------------------------//
149  // //
150  // Implementation of PostMult //
151  // //
152  //------------------------------------------------------------------//
153 
154  PostMult::PostMult (const Function * arg1,
155  const GeoTrf::Transform3D & arg2):m_arg1 (arg1->clone ()),
156  m_arg2 (arg2)
157  {
158  }
159 
160 
161  // Every function must override this:
162  PostMult *PostMult::clone () const
163  {
164  return new PostMult (*this);
165  }
166 
167  // Copy constructor:
168  PostMult::PostMult (const PostMult & right):Function (),
169  m_arg1 (right.m_arg1->clone ()), m_arg2 (right.m_arg2)
170  {
171  }
172 
173 
174  PostMult::~PostMult ()
175  {
176  delete m_arg1;
177  }
178 
179  unsigned int PostMult::dimensionality () const
180  {
181  return m_arg1->dimensionality ();
182  }
183 
184  GeoTrf::Transform3D PostMult::operator () (double x) const
185  {
186  return (*m_arg1) (x) * m_arg2;
187  }
188 
189  GeoTrf::Transform3D PostMult::operator () (const GeoGenfun::Argument & x) const
190  {
191  return (*m_arg1) (x) * m_arg2;
192  }
193 
194 
195  Pow::Pow (const GeoTrf::Transform3D & xform, GeoGenfun::GENFUNCTION f):m_xf (xform),
196  m_function (f.clone ())
197  {
198  }
199 
200  Pow::~Pow ()
201  {
202  delete m_function;
203  }
204 
205  GeoTrf::Transform3D Pow::operator() (double x) const
206  {
207  //
208  // Get the translation part and the rotation part:
209  //
210  GeoTrf::RotationMatrix3D rotate = m_xf.rotation ();
211  GeoTrf::Vector3D translate = m_xf.translation ();
212  Eigen::AngleAxis<double> aa(rotate);
213  //
214  // Evaluate the function
215  //
216  double nTimes = (*m_function) (x);
217  //
218  // Modify:
219  //
220  translate *= nTimes;
221  double& delta = aa.angle();
222  delta *= nTimes;
223  //
224  // Now compose these and return a result:
225  //
226  return GeoTrf::Translation3D (translate) * GeoTrf::Transform3D(aa);
227  }
228 
229  GeoTrf::Transform3D Pow::operator () (const GeoGenfun::Argument & argument) const
230  {
231  return operator () (argument[0]);
232  }
233 
234  Pow *Pow::clone () const
235  {
236  return new Pow (*this);
237  }
238 
239  Pow::Pow (const Pow & right):Function (), m_xf (right.m_xf),
240  m_function (right.m_function->clone ())
241  {
242  }
243 
244 }
Definition: GeoXF.h:21