CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

XF.cc
Go to the documentation of this file.
1 #include "CLHEP/Fields/XF.h"
2 #include <assert.h>
3 #include <iostream>
4 namespace XF
5 {
6 
7 
8 
9  //------------------------------------------------------------------//
10  // //
11  // Implementation of Function //
12  // //
13  //------------------------------------------------------------------//
14 
16  {
17  }
18 
20  {
21  }
22 
23  Product operator * (const Function & a, const Function & b)
24  {
25  return Product (&a, &b);
26  }
27 
29  {
30  return PreMult (xf, &b);
31  }
32 
34  {
35  return PostMult (&a, xf);
36  }
37 
38  unsigned int Function::dimensionality () const
39  {
40  return 1;
41  }
42 
43  //------------------------------------------------------------------//
44  // //
45  // Implementation of Product //
46  // //
47  //------------------------------------------------------------------//
48 
49  Product::Product (const Function * arg1,
50  const Function * arg2):_arg1 (arg1->clone ()),
51  _arg2 (arg2->clone ())
52  {
53  if (arg1->dimensionality () != arg2->dimensionality ())
54  {
55  std::cout <<"Warning: dimension mismatch in XF::Product" << std::endl;
56  assert(0);
57  }
58  }
59 
60 
61  // Every function must override this:
63  {
64  return new Product (*this);
65  }
66 
67  // Copy constructor:
68  Product::Product (const Product & right):Function (),
69  _arg1 (right._arg1->clone ()), _arg2 (right._arg2->clone ())
70  {
71  }
72 
73 
75  {
76  delete _arg1;
77  delete _arg2;
78  }
79 
80  unsigned int Product::dimensionality () const
81  {
82  return _arg1->dimensionality ();
83  }
84 
86  {
87  return (*_arg1) (x) * (*_arg2) (x);
88  }
89 
91  {
92  return (*_arg1) (x) * (*_arg2) (x);
93  }
94 
95 
96 
97  //------------------------------------------------------------------//
98  // //
99  // Implementation of PreMult //
100  // //
101  //------------------------------------------------------------------//
102 
104  const Function * arg2):_arg1 (arg1),
105  _arg2 (arg2->clone ())
106  {
107  }
108 
109 
110  // Every function must override this:
112  {
113  return new PreMult (*this);
114  }
115 
116  // Copy constructor:
117  PreMult::PreMult (const PreMult & right):Function (), _arg1 (right._arg1),
118  _arg2 (right._arg2->clone ())
119  {
120  }
121 
122 
124  {
125  delete _arg2;
126  }
127 
128  unsigned int PreMult::dimensionality () const
129  {
130  return _arg2->dimensionality ();
131  }
132 
134  {
135  return _arg1 * (*_arg2) (x);
136  }
137 
139  {
140  return _arg1 * (*_arg2) (x);
141  }
142 
143 
144  //------------------------------------------------------------------//
145  // //
146  // Implementation of PostMult //
147  // //
148  //------------------------------------------------------------------//
149 
151  const HepGeom::Transform3D & arg2):_arg1 (arg1->clone ()),
152  _arg2 (arg2)
153  {
154  }
155 
156 
157  // Every function must override this:
159  {
160  return new PostMult (*this);
161  }
162 
163  // Copy constructor:
165  _arg1 (right._arg1->clone ()), _arg2 (right._arg2)
166  {
167  }
168 
169 
171  {
172  delete _arg1;
173  }
174 
175  unsigned int PostMult::dimensionality () const
176  {
177  return _arg1->dimensionality ();
178  }
179 
181  {
182  return (*_arg1) (x) * _arg2;
183  }
184 
186  {
187  return (*_arg1) (x) * _arg2;
188  }
189 
190 
191  Pow::Pow (const HepGeom::Transform3D & xform, Genfun::GENFUNCTION f):xf (xform),
192  function (f.clone ())
193  {
194  }
195 
197  {
198  delete function;
199  }
200 
202  {
203  //
204  // Get the translation part and the rotation part:
205  //
206  CLHEP::HepRotation rotate = xf.getRotation ();
207  CLHEP::Hep3Vector translate = xf.getTranslation ();
208  CLHEP::HepAxisAngle aa = rotate.axisAngle ();
209  //
210  // Evaluate the function
211  //
212  double nTimes = (*function) (x);
213  //
214  // Modify:
215  //
216  translate *= nTimes;
217  aa.setDelta (aa.delta () * nTimes);
218  //
219  // Now compose these and return a result:
220  //
221  return HepGeom::Translate3D (translate) * HepGeom::Rotate3D (aa.delta (),
222  aa.axis ());
223  }
224 
226  {
227  return operator () (argument[0]);
228  }
229 
230  Pow *Pow::clone () const
231  {
232  return new Pow (*this);
233  }
234 
235  Pow::Pow (const Pow & right):Function (), xf (right.xf),
236  function (right.function->clone ())
237  {
238  }
239 
240 }