DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
MultiSegmentation.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 // Created: Jun 28, 2013
11 // Author: Christian Grefe, CERN
12 //
13 //==========================================================================
14 
17 #include <DD4hep/Printout.h>
18 
20 #include <iomanip>
21 #include <stdexcept>
22 
23 namespace dd4hep {
24 
25  namespace DDSegmentation {
26 
28  MultiSegmentation::MultiSegmentation(const std::string& cellEncoding)
29  : Segmentation(cellEncoding), m_discriminator(0), m_debug(0)
30  {
31  // define type and description
32  _type = "MultiSegmentation";
33  _description = "Multi-segmenation wrapper segmentation";
34  //registerParameter<int>("debug", "Debug flag", m_debug, 0);
35  registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
36  }
37 
40  : Segmentation(decode), m_discriminator(0), m_debug(0)
41  {
42  // define type and description
43  _type = "MultiSegmentation";
44  _description = "Multi-segmenation wrapper segmentation";
45  //registerParameter<int>("debug", "Debug flag", m_debug, 0);
46  registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
47  }
48 
51  for(Segmentations::iterator i=m_segmentations.begin(); i!=m_segmentations.end(); ++i)
52  delete (*i).segmentation;
53  m_segmentations.clear();
54  }
55 
57  void MultiSegmentation::addSubsegmentation(long key_min, long key_max, Segmentation* entry) {
58  Entry e;
59  e.key_min = key_min;
60  e.key_max = key_max;
61  e.segmentation = entry;
62  m_segmentations.emplace_back(e);
63  }
64 
66  void MultiSegmentation::setDecoder(const BitFieldCoder* newDecoder) {
67  this->Segmentation::setDecoder(newDecoder);
68  for(Segmentations::iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i)
69  (*i).segmentation->setDecoder(newDecoder);
70  m_discriminator = &((*_decoder)[m_discriminatorId]);
71  }
72 
75  if ( m_discriminator ) {
76  long seg_id = m_discriminator->value(cID);
77  for(Segmentations::const_iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i) {
78  const Entry& e = *i;
79  if ( e.key_min<= seg_id && e.key_max >= seg_id ) {
81  if ( m_debug > 0 ) {
82  printout(ALWAYS,"MultiSegmentation","Id: %04X %s", seg_id, s->name().c_str());
83  const Parameters& pars = s->parameters();
84  for( const auto* p : pars ) {
85  printout(ALWAYS,"MultiSegmentation"," Param %s = %s",
86  p->name().c_str(), p->value().c_str());
87  }
88  }
89  return *s;
90  }
91  }
92  }
93  except("MultiSegmentation", "Invalid sub-segmentation identifier!");
94  throw std::string("Invalid sub-segmentation identifier!");
95  }
96 
99  return subsegmentation(cID).position(cID);
100  }
101 
103  CellID MultiSegmentation::cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& vID) const {
104  return subsegmentation(vID).cellID(localPosition, globalPosition, vID);
105  }
106 
107  std::vector<double> MultiSegmentation::cellDimensions(const CellID& cID) const {
108  return subsegmentation(cID).cellDimensions(cID);
109  }
110 
111  } /* namespace DDSegmentation */
112 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::MultiSegmentation::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: MultiSegmentation.cpp:98
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
MultiSegmentation.h
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:114
dd4hep::DDSegmentation::BitFieldElement::value
FieldID value(CellID bitfield) const
calculate this field's value given an external 64 bit bitmap
Definition: BitFieldCoder.cpp:55
dd4hep::DDSegmentation::MultiSegmentation::Entry
Helper structure to describe a sub-segmentation entry.
Definition: MultiSegmentation.h:32
dd4hep::DDSegmentation::MultiSegmentation::addSubsegmentation
virtual void addSubsegmentation(long key_min, long key_max, Segmentation *entry)
Add subsegmentation.
Definition: MultiSegmentation.cpp:57
dd4hep::DDSegmentation::MultiSegmentation::cellDimensions
virtual std::vector< double > cellDimensions(const CellID &cellID) const
Returns a vector<double> of the cellDimensions of the given cell ID in natural order of dimensions,...
Definition: MultiSegmentation.cpp:107
dd4hep::DDSegmentation::MultiSegmentation::setDecoder
virtual void setDecoder(const BitFieldCoder *decoder)
Set the underlying decoder.
Definition: MultiSegmentation.cpp:66
dd4hep::DDSegmentation::Segmentation::name
virtual const std::string & name() const
Access the segmentation name.
Definition: Segmentation.h:96
dd4hep::DDSegmentation::MultiSegmentation::Entry::key_min
long key_min
Definition: MultiSegmentation.h:33
dd4hep::DDSegmentation::MultiSegmentation::subsegmentation
const Segmentation & subsegmentation(const CellID &cellID) const
Access subsegmentation by cell identifier.
Definition: MultiSegmentation.cpp:74
dd4hep::DDSegmentation::MultiSegmentation::Entry::segmentation
Segmentation * segmentation
Definition: MultiSegmentation.h:34
dd4hep::DDSegmentation::Segmentation::parameters
virtual Parameters parameters() const
Access to all parameters.
Definition: Segmentation.cpp:121
dd4hep::DDSegmentation::Parameters
std::vector< Parameter > Parameters
Definition: SegmentationsInterna.h:35
dd4hep::DDSegmentation::MultiSegmentation::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: MultiSegmentation.cpp:103
dd4hep::DDSegmentation::MultiSegmentation::m_segmentations
Segmentations m_segmentations
Sub-segmentaion container.
Definition: MultiSegmentation.h:40
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::MultiSegmentation::Entry::key_max
long key_max
Definition: MultiSegmentation.h:33
dd4hep::DDSegmentation::MultiSegmentation::~MultiSegmentation
virtual ~MultiSegmentation()
Default destructor.
Definition: MultiSegmentation.cpp:50
dd4hep::DDSegmentation::Segmentation::setDecoder
virtual void setDecoder(const BitFieldCoder *decoder)
Set the underlying decoder.
Definition: Segmentation.cpp:100
dd4hep::DDSegmentation::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:162
dd4hep::DDSegmentation::MultiSegmentation::m_discriminatorId
std::string m_discriminatorId
the field name used to discriminate sub-segmentations
Definition: MultiSegmentation.h:43
dd4hep::DDSegmentation::Segmentation::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const =0
Determine the cell ID based on the position.
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDSegmentation::MultiSegmentation::MultiSegmentation
MultiSegmentation(const std::string &cellEncoding="")
Default constructor passing the encoding string.
Definition: MultiSegmentation.cpp:28
dd4hep::DDSegmentation::Segmentation::cellDimensions
virtual std::vector< double > cellDimensions(const CellID &cellID) const
Returns a vector<double> of the cellDimensions of the given cell ID in natural order of dimensions,...
Definition: Segmentation.cpp:195
dd4hep::DDSegmentation::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:160
dd4hep::DDSegmentation::MultiSegmentation::m_discriminator
const BitFieldElement * m_discriminator
Bitfield corresponding to dicriminator identifier.
Definition: MultiSegmentation.h:46
dd4hep::DDSegmentation::MultiSegmentation::m_debug
int m_debug
Debug flags.
Definition: MultiSegmentation.h:49
dd4hep::DDSegmentation::Segmentation
Base class for all segmentations.
Definition: Segmentation.h:75
Printout.h
dd4hep::DDSegmentation::Segmentation::position
virtual Vector3D position(const CellID &cellID) const =0
Determine the local position based on the cell ID.