DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Fields.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_FIELDS_H
14 #define DD4HEP_FIELDS_H
15 
16 // Framework include files
17 #include <DD4hep/NamedObject.h>
18 #include <DD4hep/Objects.h>
19 
20 // C/C++ include files
21 #include <vector>
22 #include <map>
23 
25 namespace dd4hep {
26 
27  // Forward declarations
29 
31 
40  class CartesianField: public Handle<NamedObject> {
41  public:
42  enum FieldType {
43  UNKNOWN = 0, ELECTRIC = 0x1, MAGNETIC = 0x2, OVERLAY = 0x4,
44  };
45  typedef std::map<std::string, std::map<std::string, std::string> > Properties;
46 
48 
53  class TypedObject : public NamedObject {
54  public:
59  };
60 
62 
67  class Object: public TypedObject {
68  public:
70  typedef std::vector<double> Coefficents;
74  Object();
76  virtual ~Object();
77 
82  virtual void fieldComponents(const double* pos, double* field) = 0;
83  };
84 
86  CartesianField() = default;
87 
89  CartesianField(const CartesianField& e) = default;
90 
92  template <typename Q> CartesianField(const Handle<Q>& e) : Ref_t(e) {
93  }
94 
96  CartesianField& operator=(const CartesianField& f) = default;
97 
99  int fieldType() const {
100  return data<Object>()->field_type;
101  }
102 
104  const char* type() const;
105 
107  bool changesEnergy() const;
108 
110  void value(const Position& pos, Direction& field) const;
111 
113  void value(const Position& pos, double* val) const;
114 
116  void value(const double* pos, double* val) const;
117 
119  Properties& properties() const;
120  };
121 
123 
138  class OverlayedField: public Handle<NamedObject> {
139  public:
140  enum FieldType {
144  };
145  typedef std::map<std::string, std::string> PropertyValues;
146  typedef std::map<std::string, PropertyValues> Properties;
147 
149 
155  public:
158  std::vector<CartesianField> electric_components;
159  std::vector<CartesianField> magnetic_components;
162 
163  public:
165  Object();
167  virtual ~Object();
168  };
169 
171  OverlayedField() = default;
172 
174  template <typename Q> OverlayedField(const Handle<Q>& e) : Ref_t(e) { }
175 
177  OverlayedField(const std::string& name);
178 
180  int fieldType() const {
181  return data<Object>()->field_type;
182  }
183 
185  bool changesEnergy() const;
186 
188  void add(CartesianField field);
189 
191  void combinedElectric(const Position& pos, double* field) const;
192 
194  Direction combinedElectric(const Position& pos) const {
195  double field[3] = { 0e0, 0e0, 0e0 };
196  combinedElectric(pos, field);
197  return {field[0], field[1], field[2]};
198  }
199 
201  void combinedElectric(const double* pos, double* field) const {
202  combinedElectric(Position(pos[0], pos[1], pos[2]), field);
203  }
204 
206  void combinedMagnetic(const Position& pos, double* field) const;
207 
209  Direction combinedMagnetic(const Position& pos) const {
210  double field[3] = { 0e0, 0e0, 0e0 };
211  combinedMagnetic({pos.X(), pos.Y(), pos.Z()}, field);
212  return { field[0], field[1], field[2] };
213  }
214 
216  void combinedMagnetic(const double* pos, double* field) const {
217  combinedMagnetic(Position(pos[0], pos[1], pos[2]), field);
218  }
219 
221  void electricField(const Position& pos, double* field) const;
222 
224  Direction electricField(const Position& pos) const {
225  double field[3] = { 0e0, 0e0, 0e0 };
226  electricField(pos, field);
227  return { field[0], field[1], field[2] };
228  }
229 
231  void electricField(const Position& pos, Direction& field) const {
232  double fld[3] = { 0e0, 0e0, 0e0 };
233  electricField(Position(pos.X(), pos.Y(), pos.Z()), fld);
234  field = { fld[0], fld[1], fld[2] };
235  }
236 
238  void electricField(const double* pos, double* field) const {
239  field[0] = field[1] = field[2] = 0.0;
240  CartesianField f = data<Object>()->electric;
241  f.isValid() ? f.value(pos, field) : combinedElectric(pos, field);
242  }
243 
245  void magneticField(const Position& pos, double* field) const;
246 
248  void magneticField(const double* pos, double* field) const {
249  magneticField(Position(pos[0], pos[1], pos[2]), field);
250  }
251 
253  void magneticField(const double* pos, Direction& field) const {
254  double fld[3] = { 0e0, 0e0, 0e0 };
255  magneticField(Position(pos[0], pos[1], pos[2]), fld);
256  field = { fld[0], fld[1], fld[2] };
257  }
258 
260  Direction magneticField(const Position& pos) const {
261  double field[3] = { 0e0, 0e0, 0e0 };
262  magneticField(pos, field);
263  return { field[0], field[1], field[2] };
264  }
265 
267  void electromagneticField(const Position& pos, double* field) const;
268 
270  void electromagneticField(const double* pos, double* val) const {
271  electromagneticField(Position(pos[0], pos[1], pos[2]), val);
272  }
273 
275  Properties& properties() const;
276  };
277 } /* End namespace dd4hep */
278 #endif // DD4HEP_FIELDS_H
dd4hep::OverlayedField::combinedElectric
void combinedElectric(const Position &pos, double *field) const
Returns the 3 electric field components (x, y, z) if many components are present.
Definition: Fields.cpp:155
dd4hep::CartesianField::changesEnergy
bool changesEnergy() const
Does the field change the energy of charged particles?
Definition: Fields.cpp:51
Objects.h
dd4hep::OverlayedField::OVERLAY
@ OVERLAY
Definition: Fields.h:143
dd4hep::CartesianField::UNKNOWN
@ UNKNOWN
Definition: Fields.h:43
dd4hep::OverlayedField::PropertyValues
std::map< std::string, std::string > PropertyValues
Definition: Fields.h:145
dd4hep::OverlayedField::magneticField
void magneticField(const double *pos, Direction &field) const
Returns the 3 magnetic field components (x, y, z).
Definition: Fields.h:253
dd4hep::OverlayedField::Object::magnetic
CartesianField magnetic
Definition: Fields.h:157
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::CartesianField::Object
Internal data class shared by all handles of a given type.
Definition: Fields.h:67
dd4hep::Handle
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:84
dd4hep::CartesianField::MAGNETIC
@ MAGNETIC
Definition: Fields.h:43
dd4hep::OverlayedField::add
void add(CartesianField field)
Add a new field component.
Definition: Fields.cpp:110
dd4hep::OverlayedField::combinedMagnetic
void combinedMagnetic(const double *pos, double *field) const
Returns the 3 magnetic field components (x, y, z) if many components are present.
Definition: Fields.h:216
dd4hep::Direction
Position Direction
Definition: Fields.h:28
dd4hep::OverlayedField::MAGNETIC
@ MAGNETIC
Definition: Fields.h:142
dd4hep::CartesianField::Object::Coefficents
std::vector< double > Coefficents
Utility definition for concrete implementations.
Definition: Fields.h:70
dd4hep::Handle< NamedObject >::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::OverlayedField::combinedElectric
Direction combinedElectric(const Position &pos) const
Returns the 3 electric field components (x, y, z) if many components are present.
Definition: Fields.h:194
dd4hep::OverlayedField::ELECTRIC
@ ELECTRIC
Definition: Fields.h:141
dd4hep::OverlayedField::properties
Properties & properties() const
Access to properties container.
Definition: Fields.cpp:99
dd4hep::OverlayedField::fieldType
int fieldType() const
Access the field type.
Definition: Fields.h:180
dd4hep::OverlayedField::OverlayedField
OverlayedField(const Handle< Q > &e)
Constructor to be used when reading the already parsed DOM tree.
Definition: Fields.h:174
dd4hep::OverlayedField
Class describing a field overlay with several sources.
Definition: Fields.h:138
dd4hep::CartesianField::CartesianField
CartesianField()=default
Default constructor.
dd4hep::OverlayedField::FieldType
FieldType
Definition: Fields.h:140
dd4hep::OverlayedField::Object::~Object
virtual ~Object()
Default destructor.
Definition: Fields.cpp:87
dd4hep::OverlayedField::combinedMagnetic
void combinedMagnetic(const Position &pos, double *field) const
Returns the 3 magnetic field components (x, y, z) if many components are present.
Definition: Fields.cpp:161
dd4hep::OverlayedField::electromagneticField
void electromagneticField(const double *pos, double *val) const
Returns the 3 electric (val[0]-val[2]) and magnetic field components (val[3]-val[5]).
Definition: Fields.h:270
dd4hep::NamedObject::NamedObject
NamedObject()=default
Standard constructor.
dd4hep::CartesianField::Object::properties
Properties properties
Field extensions.
Definition: Fields.h:72
dd4hep::OverlayedField::electricField
void electricField(const double *pos, double *field) const
Returns the 3 electric field components (x, y, z).
Definition: Fields.h:238
dd4hep::CartesianField::Properties
std::map< std::string, std::map< std::string, std::string > > Properties
Definition: Fields.h:45
dd4hep::OverlayedField::electricField
void electricField(const Position &pos, double *field) const
Returns the 3 electric field components (x, y, z).
dd4hep::OverlayedField::electricField
void electricField(const Position &pos, Direction &field) const
Returns the 3 electric field components (x, y, z).
Definition: Fields.h:231
dd4hep::CartesianField::Object::Object
Object()
Default constructor.
Definition: Fields.cpp:34
dd4hep::CartesianField::fieldType
int fieldType() const
Access the field type.
Definition: Fields.h:99
dd4hep::OverlayedField::Object::electric_components
std::vector< CartesianField > electric_components
Definition: Fields.h:158
NamedObject.h
dd4hep::OverlayedField::electricField
Direction electricField(const Position &pos) const
Returns the 3 electric field components (x, y, z) at a given position.
Definition: Fields.h:224
dd4hep::CartesianField::FieldType
FieldType
Definition: Fields.h:42
dd4hep::CartesianField::operator=
CartesianField & operator=(const CartesianField &f)=default
Assignment operator.
dd4hep::CartesianField::properties
Properties & properties() const
Access to properties container.
Definition: Fields.cpp:56
dd4hep::OverlayedField::Object
Internal data class shared by all handles.
Definition: Fields.h:154
dd4hep::CartesianField::Object::fieldComponents
virtual void fieldComponents(const double *pos, double *field)=0
dd4hep::CartesianField::value
void value(const Position &pos, Direction &field) const
Returns the 3 field components (x, y, z).
Definition: Fields.cpp:61
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::OverlayedField::magneticField
void magneticField(const double *pos, double *field) const
Returns the 3 magnetic field components (x, y, z).
Definition: Fields.h:248
dd4hep::CartesianField::TypedObject::field_type
int field_type
Field type.
Definition: Fields.h:56
dd4hep::OverlayedField::combinedElectric
void combinedElectric(const double *pos, double *field) const
Returns the 3 electric field components (x, y, z) if many components are present.
Definition: Fields.h:201
dd4hep::OverlayedField::Object::Object
Object()
Default constructor.
Definition: Fields.cpp:80
dd4hep::CartesianField::CartesianField
CartesianField(const Handle< Q > &e)
Constructor to be used when reading the already parsed DOM tree.
Definition: Fields.h:92
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::NamedObject
Implementation of a named object.
Definition: NamedObject.h:30
dd4hep::OverlayedField::OverlayedField
OverlayedField()=default
Default constructor.
dd4hep::OverlayedField::Object::magnetic_components
std::vector< CartesianField > magnetic_components
Definition: Fields.h:159
dd4hep::OverlayedField::changesEnergy
bool changesEnergy() const
Does the field change the energy of charged particles?
Definition: Fields.cpp:104
dd4hep::OverlayedField::Object::electric
CartesianField electric
Definition: Fields.h:156
dd4hep::OverlayedField::magneticField
Direction magneticField(const Position &pos) const
Returns the 3 electric field components (x, y, z) at a given position.
Definition: Fields.h:260
dd4hep::OverlayedField::magneticField
void magneticField(const Position &pos, double *field) const
Returns the 3 magnetic field components (x, y, z).
Definition: Fields.cpp:140
dd4hep::CartesianField::ELECTRIC
@ ELECTRIC
Definition: Fields.h:43
dd4hep::OverlayedField::Properties
std::map< std::string, PropertyValues > Properties
Definition: Fields.h:146
dd4hep::CartesianField::TypedObject
Internal data class shared by all handles of a given type.
Definition: Fields.h:53
dd4hep::OverlayedField::Object::properties
Properties properties
Field extensions.
Definition: Fields.h:161
dd4hep::CartesianField::CartesianField
CartesianField(const CartesianField &e)=default
Constructor to be used when reading the already parsed DOM tree.
dd4hep::OverlayedField::electromagneticField
void electromagneticField(const Position &pos, double *field) const
Returns the 3 electric (val[0]-val[2]) and magnetic field components (val[3]-val[5]).
Definition: Fields.cpp:167
dd4hep::CartesianField::OVERLAY
@ OVERLAY
Definition: Fields.h:43
dd4hep::CartesianField::type
const char * type() const
Access the field type (string)
Definition: Fields.cpp:46
dd4hep::CartesianField::Object::~Object
virtual ~Object()
Default destructor.
Definition: Fields.cpp:41
dd4hep::OverlayedField::combinedMagnetic
Direction combinedMagnetic(const Position &pos) const
Returns the 3 magnetic field components (x, y, z) at a given position.
Definition: Fields.h:209
dd4hep::CartesianField
Base class describing any field with 3D cartesian vectors for the field strength.
Definition: Fields.h:40