Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* LayeringExtensionImpl.cpp
*
* Created on: Mar 6, 2014
* Author: cgrefe
*/
#include "DDRec/Extensions/LayeringExtensionImpl.h"
#include "DD4hep/LCDD.h"
#include "TGeoManager.h"
namespace DD4hep {
namespace DDRec {
using Geometry::DetElement;
using std::vector;
using std::map;
/// Default constructor
LayeringExtensionImpl::LayeringExtensionImpl() {
}
/// Copy constructor
//LayeringExtensionImpl::LayeringExtensionImpl(const LayeringExtensionImpl& e, const DetElement& d) {}
/// Destructor
LayeringExtensionImpl::~LayeringExtensionImpl() {
}
/// Access to the total number of layers
int LayeringExtensionImpl::numberOfLayers() const {
return _layerMap.size();
}
/// Access to the total number of sensors in a given layer index
int LayeringExtensionImpl::numberOfSensors(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).sensors.size();
}
/// Access to the layer DetElement for the given index
DetElement LayeringExtensionImpl::layer(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).layer;
}
/// Access to the sensitive DetElements of a given layer index
const vector<DetElement>& LayeringExtensionImpl::sensors(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).sensors;
}
/// Access to the non-sensitive DetElements of a given layer index
const vector<DetElement>& LayeringExtensionImpl::absorbers(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).absorbers;
}
/// Access the total thickness of the sub detector
double LayeringExtensionImpl::totalThickness() const {
map<int, LayerAttributes>::iterator it = _layerMap.begin();
while (it != _layerMap.end()) {
LayerAttributes& attributes = it->second;
if (not attributes.isCalculated) {
attributes.calculate();
}
++it;
}
}
/// Access the total radiation length of the sub detector
double LayeringExtensionImpl::totalRadiationLength() const {
map<int, LayerAttributes>::iterator it = _layerMap.begin();
while (it != _layerMap.end()) {
LayerAttributes& attributes = it->second;
if (not attributes.isCalculated) {
attributes.calculate();
}
++it;
}
}
/// Access the total nuclear interaction length of the sub detector
double LayeringExtensionImpl::totalInteractionLength() const {
map<int, LayerAttributes>::iterator it = _layerMap.begin();
while (it != _layerMap.end()) {
LayerAttributes& attributes = it->second;
if (not attributes.isCalculated) {
attributes.calculate();
}
interaction_length += attributes.interactionLength;
++it;
}
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
}
/// Access the total thickness of the layer with the given index
double LayeringExtensionImpl::thickness(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).thickness;
}
/// Access the total radiation length of the layer with the given index
double LayeringExtensionImpl::radiationLength(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).radiationLength;
}
/// Access the total nuclear interaction length of the layer with the given index
double LayeringExtensionImpl::interactionLength(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).interactionLength;
}
/// Access the total thickness of all non-sensitive elements of the layer with the given index
double LayeringExtensionImpl::absorberThickness(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).absorberThickness;
}
/// Access the total radiation length of all non-sensitive elements of the layer with the given index
double LayeringExtensionImpl::absorberRadiationLength(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).absorberRadiationLength;
}
/// Access the total nuclear interaction length of all non-sensitive elements of the layer with the given index
double LayeringExtensionImpl::absorberInteractionLength(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).absorberInteractionLength;
}
/// Access the total thickness of all sensitive elements of the layer with the given index
double LayeringExtensionImpl::sensorThickness(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).sensorThickness;
}
/// Access the total radiation length of all sensitive elements of the layer with the given index
double LayeringExtensionImpl::sensorRadiationLength(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).sensorRadiationLength;
}
/// Access the total nuclear interaction length of all sensitive elements of the layer with the given index
double LayeringExtensionImpl::sensorInteractionLength(int layerIndex) const {
checkMap(layerIndex);
return _layerMap.at(layerIndex).sensorInteractionLength;
}
/// Stores the layer information for the given layer index
void LayeringExtensionImpl::setLayer(int layerIndex, Geometry::DetElement layer_elt, const Position& normal) {
LayerAttributes& layerAttributes = _layerMap[layerIndex];
layerAttributes.normal = normal.Unit();
layerAttributes.isCalculated = false;
}
/// Helper method to check validity of layer entry
void LayeringExtensionImpl::checkMap(int layerIndex) const {
map<int, LayerAttributes>::iterator it;
it = _layerMap.find(layerIndex);
if (it == _layerMap.end()) {
std::stringstream err;
err << "No entry found for layer" << layerIndex;
throw std::out_of_range(err.str());
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
}
if (not it->second.isCalculated) {
it->second.calculate();
}
}
LayeringExtensionImpl::LayerAttributes::LayerAttributes() :
thickness(0.), radiationLength(0.), interactionLength(0.), absorberThickness(0.), absorberRadiationLength(0.), absorberInteractionLength(
0.), sensorThickness(0.), sensorRadiationLength(0.), sensorInteractionLength(0.), isCalculated(false) {
_tgeoManager = Geometry::LCDD::getInstance().world().volume()->GetGeoManager();
}
void LayeringExtensionImpl::LayerAttributes::calculate() {
// reset all values
sensors.clear();
absorbers.clear();
thickness = 0.;
radiationLength = 0.;
interactionLength = 0.;
absorberThickness = 0.;
absorberRadiationLength = 0.;
absorberInteractionLength = 0.;
sensorThickness = 0.;
sensorRadiationLength = 0.;
sensorInteractionLength = 0.;
// add all children recursively starting from top
addElement(this->layer);
isCalculated = true;
}
double LayeringExtensionImpl::LayerAttributes::addElement(const DetElement& det) {
double daughterThickness = 0.;
double thisThickness = 0.;
const DetElement::Children& children = det.children();
DetElement::Children::const_iterator it = children.begin();
while (it != children.end()) {
daughterThickness += addElement(it->second);
++it;
}
Geometry::Volume volume = det.volume();
if (volume.isValid() and volume.solid().isValid()) {
Geometry::Solid solid = volume.solid();
Geometry::Material material = volume.material();
double origin[3] = { 0., 0., 0. };
double direction[3] = { normal.x(), normal.y(), normal.z() };
double reverse_direction[3] = { -normal.x(), -normal.y(), -normal.z() };
thisThickness = solid->DistFromInside(origin, direction) + solid->DistFromInside(origin, reverse_direction);
// if daughters had volumes with thicknesses subtract those
double effectiveThickness = thisThickness - daughterThickness;
double radLength = effectiveThickness / material.radLength();
double intLength = effectiveThickness / material.intLength();
thickness += effectiveThickness;
interactionLength += intLength;
radiationLength += radLength;
if (volume.isSensitive()) {
sensorThickness += thickness;
sensorInteractionLength += intLength;
sensorRadiationLength += radLength;
sensors.push_back(det);
} else {
absorbers.push_back(det);
absorberThickness += thickness;
absorberInteractionLength += intLength;
absorberRadiationLength += radLength;
}
}
return thisThickness;
}
} /* namespace DDRec */
} /* namespace DD4hep */