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
Layering.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 // Framework include files
16 #include "XML/XMLDetector.h"
17 #include "XML/Layering.h"
18 #include "XML/XMLTags.h"
19 
20 // C/C++ include files
21 #include <algorithm>
22 #include <stdexcept>
23 #include <cfloat>
24 #include <cmath>
25 
26 using namespace std;
27 using namespace DD4hep;
28 using namespace DD4hep::XML;
29 
30 LayerSlice& LayerSlice::operator=(const LayerSlice& c) {
31  if (&c != this) {
32  _sensitive = c._sensitive;
33  _thickness = c._thickness;
34  _material = c._material;
35  }
36  return *this;
37 }
38 
39 Layer::Layer(const Layer& c)
40  : _thickness(c._thickness), _preOffset(c._preOffset), _slices(c._slices) {
41 }
42 
44  if (this != &c) {
47  _slices = c._slices;
48  }
49  return *this;
50 }
51 
53  _thickness = 0.;
54  for (vector<LayerSlice>::const_iterator i = _slices.begin(); i != _slices.end(); ++i)
55  _thickness += (*i)._thickness;
56 }
57 
58 double LayerStack::sectionThickness(size_t is, size_t ie) const {
59  double thick = 0.;
60  if (is > ie)
61  throw runtime_error(
62  "LayerStack::sectionThickness: First index (" + _toString(is) + ") must be <= second index (" + _toString(ie) + ")!");
63  else if (is > _layers.size())
64  throw runtime_error(
65  "LayerStack::sectionThickness: First index (" + _toString(is) + ") out of range. #layers=" + _toString(_layers.size())
66  + ").");
67  else if (ie > _layers.size())
68  throw runtime_error(
69  "LayerStack::sectionThickness: Second index (" + _toString(is) + ") out of range. #layers=" + _toString(_layers.size())
70  + ").");
71  for (size_t i = is; i <= ie; ++i)
72  thick += _layers[i]->thicknessWithPreOffset();
73  return thick;
74 }
75 
77 }
78 
80  LayeringCnv(e).fromCompact(*this);
81 }
82 
84 }
85 
86 const Layer* Layering::layer(size_t which) const {
87  return _stack.layers()[which];
88 }
89 
90 void LayeringCnv::fromCompact(Layering& layering) const {
91  vector<Layer*>& layers = layering.layers();
92  int count = 0;
93  for_each(layers.begin(), layers.end(), deletePtr<Layer>);
94  for (Collection_t c(m_element, _U (layer)); c; ++c) {
95  Layer lay;
96  Component layer = c;
97  int repeat = layer.hasAttr(_U(repeat)) ? layer.repeat() : 1;
98  ++count;
99  for (Collection_t s(c, _U(slice)); s; ++s) {
100  Component slice = s;
101  string mat = slice.materialStr();
102  LayerSlice lslice(slice.isSensitive(), slice.thickness(), mat);
103  lay.add(lslice);
104  }
105  lay.compute();
106  // Add layer to stack once for each repetition
107  for (int k = 0; k < repeat; ++k)
108  layers.push_back(new Layer(lay));
109  }
110  if (0 == count) {
111  throw runtime_error("LayeringCnv::fromCompact: No layer children to be build!");
112  }
113 }
114 
116  Component lay = e;
117  double thickness = 0e0;
118  for (Collection_t s(lay, _U(slice)); s; ++s) {
119  Component slice = s;
120  thickness += slice.thickness();
121  }
122  return thickness;
123 }
124 
126  Component lay = e;
127  double thickness = 0e0;
128  for (Collection_t s(lay, _U(slice)); s; ++s) {
129  Component slice = s;
130  if (slice.isRadiator())
131  thickness += slice.thickness();
132  }
133  return thickness;
134 }
135 
136 void Layering::sensitivePositionsInLayer(XML::Element e, std::vector<double>& sens_pos) const {
137  Component lay = e;
138  double pos=-singleLayerThickness(e)/2.0;
139  for (Collection_t s(lay, _U(slice)); s; ++s) {
140  Component slice = s;
141  pos += slice.thickness();
142 
143  if (slice.isSensitive()){
144  //store the position at the center of the slice
145  sens_pos.push_back(pos - slice.thickness()/2.);
146  }
147  }
148 }
149 
150 
std::vector< Layer * > _layers
Definition: Layering.h:99
std::vector< Layer * > & layers()
Definition: Layering.h:112
void sensitivePositionsInLayer(XML::Element e, std::vector< double > &sens_pos) const
Definition: Layering.cpp:136
Class to convert a layering object from the compact notation.
Definition: Layering.h:138
void fromCompact(Layering &layering) const
Invoke converter.
Definition: Layering.cpp:90
std::string _toString(bool value)
String conversions: boolean value to string.
Definition: Handle.cpp:213
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:556
double sectionThickness(size_t is, size_t ie) const
Definition: Layering.cpp:58
const Layer * layer(size_t which) const
Definition: Layering.cpp:86
#define _U(a)
Definition: XMLTags.h:27
TGeoShape * s
Definition: Volumes.cpp:294
User abstraction class to manipulate XML elements within a document.
Definition: XMLElements.h:686
void add(const LayerSlice &s)
Definition: Layering.h:81
return e
Definition: Volumes.cpp:297
double thickness() const
Access attribute values: thickness.
std::vector< LayerSlice > _slices
Definition: Layering.h:65
double singleLayerThickness(XML::Element e) const
Definition: Layering.cpp:115
bool isSensitive() const
Check if component is sensitive.
Definition: XMLDetector.cpp:29
double _preOffset
Definition: Layering.h:64
Class to describe one layer in a layering stack.
Definition: Layering.h:61
virtual ~Layering()
Default destructor.
Definition: Layering.cpp:83
double _thickness
Definition: Layering.h:63
double absorberThicknessInLayer(XML::Element e) const
Definition: Layering.cpp:125
LayerStack _stack
Definition: Layering.h:140
bool hasAttr(const XmlChar *name) const
Check for the existence of a named attribute.
Definition: XMLElements.h:760
bool isRadiator() const
Check if component is a radiator (absorber)
Definition: XMLDetector.cpp:35
XML Handle class extending the XML handle Dimension.
Definition: XMLDetector.h:39
Class to describe the slice of one layer in a layering stack.
Definition: Layering.h:33
std::string _material
Definition: Layering.h:37
Layering()
Default constructor.
Definition: Layering.cpp:76
std::vector< Layer * > & layers()
Definition: Layering.h:148
double _thickness
Definition: Layering.h:36
std::string materialStr() const
Access material attribute as STL string.
Definition: XMLDetector.cpp:25
XML converter for layering objects.
Definition: Layering.h:171
Layer & operator=(const Layer &c)
Assignment operator.
Definition: Layering.cpp:43
void compute()
Definition: Layering.cpp:52
int repeat() const
Access attribute values: repeat.