DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Layering.cpp
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_NONE
14 
15 // Framework include files
16 #include <DD4hep/Primitives.h>
17 #include <DD4hep/Printout.h>
18 #include <XML/Layering.h>
19 #include <XML/XML.h>
20 
22  _thickness = 0.;
23  for (std::vector<LayerSlice>::const_iterator i = _slices.begin(); i != _slices.end(); ++i)
24  _thickness += (*i)._thickness;
25 }
26 
27 double dd4hep::LayerStack::sectionThickness(std::size_t is, std::size_t ie) const {
28  double thick = 0.;
29  if (is > ie)
30  except("LayerStack",
31  "sectionThickness: First index (%ld) must be <= second index (%ld)!", is, ie);
32  else if (is > _layers.size())
33  except("LayerStack",
34  "sectionThickness: First index (%ld) out of range. #layers=%ld).", is, _layers.size());
35  else if (ie > _layers.size())
36  except("LayerStack",
37  "sectionThickness: Second index (%ld) out of range. #layers=%ld).", is, _layers.size());
38  for (std::size_t i = is; i <= ie; ++i)
39  thick += _layers[i]->thicknessWithPreOffset();
40  return thick;
41 }
42 
44  std::vector<Layer*>& layers = layering.layers();
45  int count = 0;
46  for_each(layers.begin(), layers.end(), detail::deletePtr<Layer>);
47  for( xml_coll_t c(m_element, _U (layer)); c; ++c ) {
48  Layer lay;
49  xml_comp_t layer = c;
50  int repeat = layer.hasAttr(_U(repeat)) ? layer.repeat() : 1;
51  ++count;
52  for (xml_coll_t s(c, _U(slice)); s; ++s) {
53  xml_comp_t slice = s;
54  std::string material = slice.materialStr();
55  LayerSlice lslice(slice.isSensitive(), slice.thickness(), material);
56  lay.add(lslice);
57  }
58  lay.compute();
59  // Add layer to stack once for each repetition
60  for( int k = 0; k < repeat; ++k )
61  layers.emplace_back(new Layer(lay));
62  }
63  if (0 == count) {
64  throw std::runtime_error("LayeringCnv::fromCompact: No layer children to be build!");
65  }
66 }
67 
69  xml::LayeringCnv(e).fromCompact(*this);
70 }
71 
72 const dd4hep::Layer* dd4hep::Layering::layer(std::size_t which) const {
73  return _stack.layers()[which];
74 }
75 
77  xml_comp_t lay = e;
78  double thickness = 0e0;
79  for (xml_coll_t s(lay, _U(slice)); s; ++s) {
80  xml_comp_t slice = s;
81  thickness += slice.thickness();
82  }
83  return thickness;
84 }
85 
87  xml_comp_t lay = e;
88  double thickness = 0e0;
89  for (xml_coll_t s(lay, _U(slice)); s; ++s) {
90  xml_comp_t slice = s;
91  if (slice.isRadiator())
92  thickness += slice.thickness();
93  }
94  return thickness;
95 }
96 
97 void dd4hep::Layering::sensitivePositionsInLayer(xml_elt_t e, std::vector<double>& sens_pos) const {
98  xml_comp_t lay = e;
99  double pos =- singleLayerThickness(e)/2.0;
100  for (xml_coll_t s(lay, _U(slice)); s; ++s) {
101  xml_comp_t slice = s;
102  pos += slice.thickness();
103  if (slice.isSensitive()){
104  //store the position at the center of the slice
105  sens_pos.emplace_back(pos - slice.thickness()/2.);
106  }
107  }
108 }
109 
110 
112  std::vector<Layer*>& layers = this->layers();
113  for_each(layers.begin(), layers.end(), detail::deletePtr<Layer>);
114  layers.clear();
115 }
116 #endif
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
dd4hep::Layering::absorberThicknessInLayer
double absorberThicknessInLayer(xml::Element e) const
Definition: Layering.cpp:86
dd4hep::Layering::Layering
Layering()=default
Default constructor.
dd4hep::Layering::layer
const Layer * layer(size_t which) const
Definition: Layering.cpp:72
dd4hep::xml::LayeringCnv::fromCompact
void fromCompact(Layering &layering) const
Invoke converter.
Definition: Layering.cpp:43
dd4hep::xml::LayeringCnv
XML converter for layering objects.
Definition: Layering.h:149
dd4hep::Layer
Class to describe one layer in a layering stack.
Definition: Layering.h:56
xml_comp_t
dd4hep::xml::Component xml_comp_t
Definition: XML.h:33
dd4hep::Layering::sensitivePositionsInLayer
void sensitivePositionsInLayer(xml::Element e, std::vector< double > &sens_pos) const
Definition: Layering.cpp:97
dd4hep::Layer::add
void add(const LayerSlice &slice)
Definition: Layering.h:76
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::LayerStack::sectionThickness
double sectionThickness(size_t is, size_t ie) const
Definition: Layering.cpp:27
Layering.h
dd4hep::Layering
Class to convert a layering object from the compact notation.
Definition: Layering.h:116
Primitives.h
dd4hep::LayerSlice
Class to describe the slice of one layer in a layering stack.
Definition: Layering.h:32
XML.h
dd4hep::xml::Element
User abstraction class to manipulate XML elements within a document.
Definition: XMLElements.h:769
dd4hep::Layering::singleLayerThickness
double singleLayerThickness(xml::Element e) const
Definition: Layering.cpp:76
dd4hep::Layering::layers
std::vector< Layer * > & layers()
Definition: Layering.h:126
dd4hep::Layer::compute
void compute()
Definition: Layering.cpp:21
dd4hep::Layer::_slices
std::vector< LayerSlice > _slices
Definition: Layering.h:60
Printout.h
dd4hep::Layering::~Layering
~Layering()
Default destructor.
Definition: Layering.cpp:111
dd4hep::Layer::_thickness
double _thickness
Definition: Layering.h:58