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
LayeringExtensionImpl.cpp
Go to the documentation of this file.
1 /*
2  * LayeringExtensionImpl.cpp
3  *
4  * Created on: Mar 6, 2014
5  * Author: cgrefe
6  */
7 
9 
10 #include "DD4hep/LCDD.h"
11 
12 #include "TGeoManager.h"
13 
14 namespace DD4hep {
15 namespace DDRec {
16 
18 
19 using std::vector;
20 using std::map;
21 
24 }
25 
27 //LayeringExtensionImpl::LayeringExtensionImpl(const LayeringExtensionImpl& e, const DetElement& d) {}
28 
31 }
32 
35  return _layerMap.size();
36 }
37 
39 int LayeringExtensionImpl::numberOfSensors(int layerIndex) const {
40  checkMap(layerIndex);
41  return _layerMap.at(layerIndex).sensors.size();
42 }
43 
46  checkMap(layerIndex);
47  return _layerMap.at(layerIndex).layer;
48 }
49 
51 const vector<DetElement>& LayeringExtensionImpl::sensors(int layerIndex) const {
52  checkMap(layerIndex);
53  return _layerMap.at(layerIndex).sensors;
54 }
55 
57 const vector<DetElement>& LayeringExtensionImpl::absorbers(int layerIndex) const {
58  checkMap(layerIndex);
59  return _layerMap.at(layerIndex).absorbers;
60 }
61 
64  map<int, LayerAttributes>::iterator it = _layerMap.begin();
65  double thick_ness = 0.;
66  while (it != _layerMap.end()) {
67  LayerAttributes& attributes = it->second;
68  if (not attributes.isCalculated) {
69  attributes.calculate();
70  }
71  thick_ness += attributes.thickness;
72  ++it;
73  }
74  return thick_ness;
75 }
76 
79  map<int, LayerAttributes>::iterator it = _layerMap.begin();
80  double radiation_length = 0.;
81  while (it != _layerMap.end()) {
82  LayerAttributes& attributes = it->second;
83  if (not attributes.isCalculated) {
84  attributes.calculate();
85  }
86  radiation_length += attributes.radiationLength;
87  ++it;
88  }
89  return radiation_length;
90 }
91 
94  map<int, LayerAttributes>::iterator it = _layerMap.begin();
95  double interaction_length = 0.;
96  while (it != _layerMap.end()) {
97  LayerAttributes& attributes = it->second;
98  if (not attributes.isCalculated) {
99  attributes.calculate();
100  }
101  interaction_length += attributes.interactionLength;
102  ++it;
103  }
104  return interaction_length;
105 }
106 
108 double LayeringExtensionImpl::thickness(int layerIndex) const {
109  checkMap(layerIndex);
110  return _layerMap.at(layerIndex).thickness;
111 }
112 
114 double LayeringExtensionImpl::radiationLength(int layerIndex) const {
115  checkMap(layerIndex);
116  return _layerMap.at(layerIndex).radiationLength;
117 }
118 
120 double LayeringExtensionImpl::interactionLength(int layerIndex) const {
121  checkMap(layerIndex);
122  return _layerMap.at(layerIndex).interactionLength;
123 }
124 
126 double LayeringExtensionImpl::absorberThickness(int layerIndex) const {
127  checkMap(layerIndex);
128  return _layerMap.at(layerIndex).absorberThickness;
129 }
130 
133  checkMap(layerIndex);
134  return _layerMap.at(layerIndex).absorberRadiationLength;
135 }
136 
139  checkMap(layerIndex);
140  return _layerMap.at(layerIndex).absorberInteractionLength;
141 }
142 
144 double LayeringExtensionImpl::sensorThickness(int layerIndex) const {
145  checkMap(layerIndex);
146  return _layerMap.at(layerIndex).sensorThickness;
147 }
148 
150 double LayeringExtensionImpl::sensorRadiationLength(int layerIndex) const {
151  checkMap(layerIndex);
152  return _layerMap.at(layerIndex).sensorRadiationLength;
153 }
154 
157  checkMap(layerIndex);
158  return _layerMap.at(layerIndex).sensorInteractionLength;
159 }
160 
162 void LayeringExtensionImpl::setLayer(int layerIndex, Geometry::DetElement layer_elt, const Position& normal) {
163  LayerAttributes& layerAttributes = _layerMap[layerIndex];
164  layerAttributes.layer = layer_elt;
165  layerAttributes.normal = normal.Unit();
166  layerAttributes.isCalculated = false;
167 }
168 
170 void LayeringExtensionImpl::checkMap(int layerIndex) const {
171  map<int, LayerAttributes>::iterator it;
172  it = _layerMap.find(layerIndex);
173  if (it == _layerMap.end()) {
174  // TODO throw exception
175  }
176  if (not it->second.isCalculated) {
177  it->second.calculate();
178  }
179 }
180 
182  thickness(0.), radiationLength(0.), interactionLength(0.), absorberThickness(0.), absorberRadiationLength(0.), absorberInteractionLength(
183  0.), sensorThickness(0.), sensorRadiationLength(0.), sensorInteractionLength(0.), isCalculated(false) {
184  _tgeoManager = Geometry::LCDD::getInstance().world().volume()->GetGeoManager();
185 }
186 
188  // reset all values
189  sensors.clear();
190  absorbers.clear();
191  thickness = 0.;
192  radiationLength = 0.;
193  interactionLength = 0.;
194  absorberThickness = 0.;
197  sensorThickness = 0.;
200  // add all children recursively starting from top
201  addElement(this->layer);
202  isCalculated = true;
203 }
204 
206  double daughterThickness = 0.;
207  double thisThickness = 0.;
208 
209  const DetElement::Children& children = det.children();
210  DetElement::Children::const_iterator it = children.begin();
211  while (it != children.end()) {
212  daughterThickness += addElement(it->second);
213  ++it;
214  }
215 
216  Geometry::Volume volume = det.volume();
217  if (volume.isValid() and volume.solid().isValid()) {
218  Geometry::Solid solid = volume.solid();
219  Geometry::Material material = volume.material();
220  double origin[3] = { 0., 0., 0. };
221  double direction[3] = { normal.x(), normal.y(), normal.z() };
222  double reverse_direction[3] = { -normal.x(), -normal.y(), -normal.z() };
223  thisThickness = solid->DistFromInside(origin, direction) + solid->DistFromInside(origin, reverse_direction);
224  // if daughters had volumes with thicknesses subtract those
225  double effectiveThickness = thisThickness - daughterThickness;
226  double radLength = effectiveThickness / material.radLength();
227  double intLength = effectiveThickness / material.intLength();
228  thickness += effectiveThickness;
229  interactionLength += intLength;
230  radiationLength += radLength;
231  if (volume.isSensitive()) {
233  sensorInteractionLength += intLength;
234  sensorRadiationLength += radLength;
235  sensors.push_back(det);
236  } else {
237  absorbers.push_back(det);
239  absorberInteractionLength += intLength;
240  absorberRadiationLength += radLength;
241  }
242  }
243  return thisThickness;
244 }
245 
246 } /* namespace DDRec */
247 } /* namespace DD4hep */
virtual double totalThickness() const
Access the total thickness of the sub detector.
std::map< int, LayerAttributes > _layerMap
virtual const std::vector< Geometry::DetElement > & absorbers(int layerIndex) const
Access to the non-sensitive DetElements of a given layer index.
Solid solid() const
Access to Solid (Shape)
Definition: Volumes.cpp:693
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
Volume volume() const
Access to the logical volume of the detector element's placement.
Definition: Detector.cpp:311
Handle class describing a material.
Definition: Objects.h:300
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
double intLength() const
Access the interaction length of the underlying material.
Definition: Objects.cpp:225
virtual double totalRadiationLength() const
Access the total radiation length of the sub detector.
const Children & children() const
Access to the list of children.
Definition: Detector.cpp:207
static LCDD & getInstance(void)
—Factory method----—
Definition: LCDDImp.cpp:87
virtual double thickness(int layerIndex) const
Access the total thickness of the layer with the given index.
virtual double sensorThickness(int layerIndex) const
Access the total thickness of all sensitive elements of the layer with the given index.
virtual double absorberRadiationLength(int layerIndex) const
Access the total radiation length of all non-sensitive elements of the layer with the given index...
DD4hep::Geometry::DetElement DetElement
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:237
virtual int numberOfSensors(int layerIndex) const
Access to the total number of sensors in a given layer index.
void checkMap(int layerIndex) const
Map to store layer attributes.
double radLength() const
Access the radiation length of the underlying material.
Definition: Objects.cpp:213
virtual double radiationLength(int layerIndex) const
Access the total radiation length of the layer with the given index.
virtual double absorberThickness(int layerIndex) const
Access the total thickness of all non-sensitive elements of the layer with the given index...
virtual const std::vector< Geometry::DetElement > & sensors(int layerIndex) const
Access to the sensitive DetElements of a given layer index.
virtual int numberOfLayers() const
Access to the total number of layers.
virtual double absorberInteractionLength(int layerIndex) const
Access the total nuclear interaction length of all non-sensitive elements of the layer with the given...
Handle class describing a detector element.
Definition: Detector.h:172
Geometry::Position Position
Shortcut to use geometrical positions.
virtual double sensorRadiationLength(int layerIndex) const
Access the total radiation length of all sensitive elements of the layer with the given index...
virtual Geometry::DetElement layer(int layerIndex) const
Access to the layer DetElement for the given index.
std::map< std::string, DetElement > Children
Definition: Detector.h:202
Material material() const
Access to the Volume material.
Definition: Volumes.cpp:557
void setLayer(int layerIndex, Geometry::DetElement layer, const Position &normal)
Stores the layer information for the given layer index.
void calculate()
Helper method to calculate attributes from layer.
virtual double totalInteractionLength() const
Access the total nuclear interaction length of the sub detector.
bool isSensitive() const
Accessor if volume is sensitive (ie. is attached to a sensitive detector)
Definition: Volumes.cpp:749
virtual double interactionLength(int layerIndex) const
Access the total nuclear interaction length of the layer with the given index.
virtual double sensorInteractionLength(int layerIndex) const
Access the total nuclear interaction length of all sensitive elements of the layer with the given ind...