DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fields.cpp
Go to the documentation of this file.
1 // $Id$
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 #include "DD4hep/Handle.inl"
16 #include "DD4hep/Fields.h"
17 #include "DD4hep/InstanceCount.h"
18 
19 using namespace std;
20 using namespace DD4hep::Geometry;
21 
24 
27 
28 namespace {
29  void calculate_combined_field(vector<CartesianField>& v, const double* pos, double* field) {
30  for (vector<CartesianField>::iterator i = v.begin(); i != v.end(); ++i)
31  (*i).value(pos, field);
32  }
33 }
34 
36 CartesianField::Object::Object()
37  : NamedObject(), type(UNKNOWN) {
39 }
40 
44 }
45 
47 const char* CartesianField::type() const {
48  return m_element->GetTitle();
49 }
50 
53  return ELECTRIC == (fieldType() & ELECTRIC);
54 }
55 
58  return data<Object>()->properties;
59 }
60 
62 void CartesianField::value(const Position& pos, Direction& field) const {
63  value(pos,(double*)&field);
64 }
65 
67 void CartesianField::value(const Position& pos, double* val) const {
68  value((double*)&pos,val);
69 }
70 
72 void CartesianField::value(const double* pos, double* val) const {
73  data<Object>()->fieldComponents(pos, val);
74 }
75 
78  : type(0), electric(), magnetic() {
80 }
81 
85 }
86 
89  : Ref_t() {
90  assign(new Object(), nam, "overlay_field");
91 }
92 
95  return data<Object>()->properties;
96 }
97 
100  int field = data<Object>()->type;
102 }
103 
106  if (field.isValid()) {
107  Object* o = data<Object>();
108  if (o) {
109  int typ = field.fieldType();
110  bool isEle = field.ELECTRIC == (typ & field.ELECTRIC);
111  bool isMag = field.MAGNETIC == (typ & field.MAGNETIC);
112  if (isEle) {
113  vector < CartesianField > &v = o->electric_components;
114  v.push_back(field);
115  o->type |= field.ELECTRIC;
116  o->electric = v.size() == 1 ? field : CartesianField();
117  }
118  if (isMag) {
119  vector < CartesianField > &v = o->magnetic_components;
120  v.push_back(field);
121  o->type |= field.MAGNETIC;
122  o->magnetic = v.size() == 1 ? field : CartesianField();
123  }
124  if (isMag || isEle)
125  return;
126  throw runtime_error("OverlayedField::add: Attempt to add an unknown field type.");
127  }
128  throw runtime_error("OverlayedField::add: Attempt to add to an invalid object.");
129  }
130  throw runtime_error("OverlayedField::add: Attempt to add an invalid field.");
131 }
132 
134 void OverlayedField::combinedElectric(const double* pos, double* field) const {
135  field[0] = field[1] = field[2] = 0.;
136  calculate_combined_field(data<Object>()->electric_components, pos, field);
137 }
138 
140 void OverlayedField::combinedMagnetic(const double* pos, double* field) const {
141  field[0] = field[1] = field[2] = 0.;
142  calculate_combined_field(data<Object>()->magnetic_components, pos, field);
143 }
144 
146 void OverlayedField::electromagneticField(const double* pos, double* field) const {
147  Object* o = data<Object>();
148  field[0] = field[1] = field[2] = 0.;
149  calculate_combined_field(o->electric_components, pos, field);
150  calculate_combined_field(o->magnetic_components, pos, field + 3);
151 }
DD4hep::Geometry::CartesianField electric
Definition: Fields.h:147
Properties & properties() const
Access to properties container.
Definition: Fields.cpp:94
Internal data class shared by all handles of a given type.
Definition: Fields.h:60
bool changesEnergy() const
Does the field change the energy of charged particles?
Definition: Fields.cpp:99
void combinedMagnetic(const Position &pos, double *field) const
Returns the 3 magnetic field components (x, y, z) if many components are present. ...
Definition: Fields.h:188
Object()
Default constructor.
Definition: Fields.cpp:77
int fieldType() const
Access the field type.
Definition: Fields.h:88
Internal data class shared by all handles.
Definition: Fields.h:144
void add(CartesianField field)
Add a new field component.
Definition: Fields.cpp:105
std::map< std::string, PropertyValues > Properties
Definition: Fields.h:52
static void decrement(T *)
Decrement count according to type information.
std::map< std::string, PropertyValues > Properties
Definition: Fields.h:136
std::vector< DD4hep::Geometry::CartesianField > electric_components
Definition: Fields.h:149
const char * type() const
Access the field type (string)
Definition: Fields.cpp:47
Implementation of a named object.
Definition: NamedObject.h:31
OverlayedField::Object OverlayedFieldObject
Definition: Fields.cpp:25
bool changesEnergy() const
Does the field change the energy of charged particles?
Definition: Fields.cpp:52
std::vector< DD4hep::Geometry::CartesianField > magnetic_components
Definition: Fields.h:150
void electromagneticField(const Position &pos, double *val) const
Returns the 3 electric (val[0]-val[2]) and magnetic field components (val[3]-val[5]).
Definition: Fields.h:230
OverlayedField()=default
Default constructor.
int type() const
Access the field type.
Definition: Fields.h:169
ROOT::Math::XYZVector Position
Definition: Objects.h:75
Position Direction
Definition: Fields.h:31
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Definition: Handle.h:176
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
virtual ~Object()
Default destructor.
Definition: Fields.cpp:42
Properties & properties() const
Access to properties container.
Definition: Fields.cpp:57
virtual ~Object()
Default destructor.
Definition: Fields.cpp:83
View * v
Definition: MultiView.cpp:30
Handle class describing any field with 3D cartesian vectors for the field strength.
Definition: Fields.h:46
void combinedElectric(const Position &pos, double *field) const
Returns the 3 electric field components (x, y, z) if many components are present. ...
Definition: Fields.h:180
CartesianField::Object CartesianFieldObject
Definition: Fields.cpp:22
DD4hep::Geometry::CartesianField magnetic
Definition: Fields.h:148
DD4HEP_INSTANTIATE_HANDLE(CartesianFieldObject)
void value(const Position &pos, Direction &field) const
Returns the 3 field components (x, y, z).
Definition: Fields.cpp:62