Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for smartless configuration of volumes in Geant4 #1367

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DDCore/include/DD4hep/CartesianGridXY.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ namespace dd4hep {
/// Copy constructor
CartesianGridXY(const CartesianGridXY& e) = default;
/// Copy Constructor from segmentation base object
CartesianGridXY(const Segmentation& e) : Handle<Object>(e) { }
CartesianGridXY(const Segmentation& e) : Handle<Object>(e) { }
/// Copy constructor from handle
CartesianGridXY(const Handle<Object>& e) : Handle<Object>(e) { }
CartesianGridXY(const Handle<Object>& e) : Handle<Object>(e) { }
/// Copy constructor from other equivalent handle
template <typename Q> CartesianGridXY(const Handle<Q>& e) : Handle<Object>(e) { }
template <typename Q> CartesianGridXY(const Handle<Q>& e) : Handle<Object>(e) { }
/// Assignment operator
CartesianGridXY& operator=(const CartesianGridXY& seg) = default;
/// Equality operator
Expand Down
27 changes: 13 additions & 14 deletions DDCore/include/DD4hep/Volumes.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,9 @@ namespace dd4hep {
/// Default destructor
virtual ~PlacedVolumeExtension();
/// Move assignment
PlacedVolumeExtension& operator=(PlacedVolumeExtension&& copy) {
magic = std::move(copy.magic);
params = std::move(copy.params);
volIDs = std::move(copy.volIDs);
return *this;
}
PlacedVolumeExtension& operator=(PlacedVolumeExtension&& copy);
/// Assignment operator
PlacedVolumeExtension& operator=(const PlacedVolumeExtension& copy) {
magic = copy.magic;
params = copy.params;
volIDs = copy.volIDs;
return *this;
}
PlacedVolumeExtension& operator=(const PlacedVolumeExtension& copy);
/// TGeoExtension overload: Method called whenever requiring a pointer to the extension
virtual TGeoExtension *Grab() override;
/// TGeoExtension overload: Method called always when the pointer to the extension is not needed anymore
Expand Down Expand Up @@ -329,6 +319,8 @@ namespace dd4hep {
Handle<TGeoVolume> reflected;
/// Reference to properties
TList* properties { nullptr };
/// Geant4 optimization flag: Smartless
unsigned char smartLess = 0xFF; // MUST match Volume::NO_SMARTLESS_OPTIMIZATION

/// Default destructor
virtual ~VolumeExtension();
Expand Down Expand Up @@ -393,9 +385,11 @@ namespace dd4hep {
Y_axis = 1UL << 9,
Z_axis = 1UL << 10,
Rho_axis = 1UL << 11,
Phi_axis = 1UL << 12
Phi_axis = 1UL << 12,
};
enum g4_optimizations {
NO_SMARTLESS_OPTIMIZATION = 0xFF,
};

public:
/// Default constructor
Volume() = default;
Expand Down Expand Up @@ -650,6 +644,11 @@ namespace dd4hep {
/// Test if this volume is an assembly structure
bool isAssembly() const;

/// Set the smartless option for G4 voxelization. Returns previous value
unsigned char setSmartlessValue(unsigned char value);
/// access the smartless option for G4 voxelization
unsigned char smartlessValue() const;

/// Set the volume's option value
const Volume& setOption(const std::string& opt) const;
/// Access the volume's option value
Expand Down
6 changes: 5 additions & 1 deletion DDCore/include/Parsers/detail/Dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,15 @@ namespace dd4hep {
double eunit() const;
/// Access min/max parameters: eunit
double eunit(double default_value) const;
/// Access layers attribute
int layers() const;
/// Access layers attribute
int layers(int default_value) const;
/// Access min/max parameters: lunit
double lunit() const;
/// Access min/max parameters: lunit
double lunit(double default_value) const;

/// Access constants: temperature
double temperature() const;
/// Access constants: temperature
Expand Down
1 change: 1 addition & 0 deletions DDCore/include/Parsers/detail/Dimension.imp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ XML_ATTR_ACCESSOR(int, nsides)
XML_ATTR_ACCESSOR(int, nsides_inner)
XML_ATTR_ACCESSOR(int, nsides_outer)
XML_ATTR_ACCESSOR(int, number)
XML_ATTR_ACCESSOR(int, layers)
XML_ATTR_ACCESSOR(int, repeat)
XML_ATTR_ACCESSOR(bool, reflect)
XML_ATTR_ACCESSOR_BOOL(reflect)
Expand Down
14 changes: 14 additions & 0 deletions DDCore/src/ObjectExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using namespace dd4hep;

#define EXTENSION_DEBUG 0

namespace {
std::string obj_type(void* ptr) {
ObjectExtensions* o = (ObjectExtensions*)ptr;
Expand Down Expand Up @@ -67,6 +69,12 @@ void* ObjectExtensions::addExtension(unsigned long long int key, ExtensionEntry*
if ( e->object() ) {
auto j = extensions.find(key);
if (j == extensions.end()) {
#if EXTENSION_DEBUG
auto* p = e->object();
ExtensionEntry* ptr = (ExtensionEntry*)e;
printout(ALWAYS,"addExtension","+++ Add extension with key: %016llX --> %p [%s]",
key, p, typeName(typeid(*ptr)).c_str());
#endif
extensions[key] = e;
return e->object();
}
Expand Down Expand Up @@ -97,6 +105,9 @@ void* ObjectExtensions::removeExtension(unsigned long long int key, bool destroy
/// Access an existing extension object from the detector element
void* ObjectExtensions::extension(unsigned long long int key) const {
const auto j = extensions.find(key);
#if EXTENSION_DEBUG
printout(ALWAYS,"extension","+++ Get extension with key: %016llX", key);
#endif
if (j != extensions.end()) {
return (*j).second->object();
}
Expand All @@ -107,6 +118,9 @@ void* ObjectExtensions::extension(unsigned long long int key) const {
/// Access an existing extension object from the detector element
void* ObjectExtensions::extension(unsigned long long int key, bool alert) const {
const auto j = extensions.find(key);
#if EXTENSION_DEBUG
printout(ALWAYS,"extension","+++ Get extension with key: %016llX", key);
#endif
if (j != extensions.end()) {
return (*j).second->object();
}
Expand Down
35 changes: 32 additions & 3 deletions DDCore/src/Volumes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ namespace {
PlacedVolume::Object* _data(const PlacedVolume& v) {
PlacedVolume::Object* o = _userExtension(v);
if (o) return o;
throw std::runtime_error("dd4hep: Attempt to access invalid handle of type: PlacedVolume");
except("PlacedVolume::_data", "+++ Attempt to access invalid handle of type: PlacedVolume");
return nullptr;
}
/// Accessor to the data part of the Volume
Volume::Object* _data(const Volume& v, bool throw_exception = true) {
Expand All @@ -97,7 +98,8 @@ namespace {
return o;
else if (!throw_exception)
return nullptr;
throw std::runtime_error("dd4hep: Attempt to access invalid handle of type: PlacedVolume");
except("Volume::_data", "+++ Attempt to access invalid handle of type: Volume");
return nullptr;
}

class VolumeImport {
Expand Down Expand Up @@ -297,7 +299,6 @@ namespace {

}


/// Perform scan
void ReflectionBuilder::execute() const {
TGeoIterator next(detector.manager().GetTopVolume());
Expand Down Expand Up @@ -376,6 +377,21 @@ PlacedVolumeExtension::~PlacedVolumeExtension() {
DECREMENT_COUNTER;
}

/// Move assignment
PlacedVolumeExtension& PlacedVolumeExtension::operator=(PlacedVolumeExtension&& copy) {
magic = std::move(copy.magic);
params = std::move(copy.params);
volIDs = std::move(copy.volIDs);
return *this;
}
/// Assignment operator
PlacedVolumeExtension& PlacedVolumeExtension::operator=(const PlacedVolumeExtension& copy) {
magic = copy.magic;
params = copy.params;
volIDs = copy.volIDs;
return *this;
}

/// TGeoExtension overload: Method called whenever requiring a pointer to the extension
TGeoExtension* PlacedVolumeExtension::Grab() {
++this->refCount;
Expand Down Expand Up @@ -708,6 +724,19 @@ bool Volume::isAssembly() const {
return m_element ? m_element->IsAssembly() : false;
}

/// Set the smartless option for G4 voxelization. Returns previous value
unsigned char Volume::setSmartlessValue(unsigned char new_value) {
Object* obj = _data(*this);
unsigned char tmp = obj->smartLess;
obj->smartLess = new_value;
return tmp;
}

/// access the smartless option for G4 voxelization
unsigned char Volume::smartlessValue() const {
return _data(*this)->smartLess;
}

/// Divide volume into subsections (See the ROOT manuloa for details)
Volume Volume::divide(const std::string& divname, int iaxis, int ndiv,
double start, double step, int numed, const char* option) {
Expand Down
16 changes: 13 additions & 3 deletions DDCore/src/plugins/Compact2Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ template <> void Converter<Parallelworld_Volume>::operator()(xml_h element) cons
vol.name(), anchor.path().c_str(), vis.name());
}

/// Read material entries from a seperate file in one of the include sections of the geometry
/// Process include statements in various sub-tags of compact
template <> void Converter<DetElementInclude>::operator()(xml_h element) const {
std::string type = element.hasAttr(_U(type)) ? element.attr<std::string>(_U(type)) : std::string("xml");
if ( type == "xml" ) {
Expand All @@ -1626,8 +1626,12 @@ template <> void Converter<DetElementInclude>::operator()(xml_h element) const {
Converter<Compact>(this->description)(node);
else if ( tag == "define" )
xml_coll_t(node, _U(constant)).for_each(Converter<Constant>(this->description));
else if ( tag == "readout" )
Converter<Readout>(this->description)(node);
else if ( tag == "readouts" )
xml_coll_t(node, _U(readout)).for_each(Converter<Readout>(this->description));
else if ( tag == "region" )
Converter<Region>(this->description)(node);
else if ( tag == "regions" )
xml_coll_t(node, _U(region)).for_each(Converter<Region>(this->description));
else if ( tag == "limits" || tag == "limitsets" )
Expand Down Expand Up @@ -1656,6 +1660,7 @@ template <> void Converter<DetElementInclude>::operator()(xml_h element) const {
}
}

/// Main compact conversion entry point
template <> void Converter<Compact>::operator()(xml_h element) const {
static int num_calls = 0;
char text[32];
Expand Down Expand Up @@ -1720,8 +1725,8 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
if (element.hasChild(_U(info)))
(Converter<Header>(description))(xml_h(compact.child(_U(info))));

xml_coll_t(compact, _U(properties)).for_each(_U(attributes), Converter<Property>(description));
/// These two must be parsed early, because they are needed by the detector constructors
xml_coll_t(compact, _U(properties)).for_each(_U(attributes), Converter<Property>(description));
xml_coll_t(compact, _U(properties)).for_each(_U(constant), Converter<PropertyConstant>(description));
xml_coll_t(compact, _U(properties)).for_each(_U(matrix), Converter<PropertyTable>(description));
xml_coll_t(compact, _U(properties)).for_each(_U(plugin), Converter<Plugin> (description));
Expand All @@ -1730,13 +1735,15 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
xml_coll_t(compact, _U(materials)).for_each(_U(element), Converter<Atom>(description));
xml_coll_t(compact, _U(materials)).for_each(_U(material), Converter<Material>(description));
xml_coll_t(compact, _U(materials)).for_each(_U(plugin), Converter<Plugin> (description));

printout(DEBUG, "Compact", "++ Converting visualization attributes...");
xml_coll_t(compact, _U(display)).for_each(_U(include), Converter<DetElementInclude>(description));
xml_coll_t(compact, _U(display)).for_each(_U(vis), Converter<VisAttr>(description));

printout(DEBUG, "Compact", "++ Converting limitset structures...");
xml_coll_t(compact, _U(limits)).for_each(_U(include), Converter<DetElementInclude>(description));
xml_coll_t(compact, _U(limits)).for_each(_U(limitset), Converter<LimitSet>(description));

printout(DEBUG, "Compact", "++ Converting region structures...");
xml_coll_t(compact, _U(regions)).for_each(_U(include), Converter<DetElementInclude>(description));
xml_coll_t(compact, _U(regions)).for_each(_U(region), Converter<Region>(description));
Expand All @@ -1746,7 +1753,9 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
}
if ( open_geometry ) description.init();
printout(DEBUG, "Compact", "++ Converting readout structures...");
xml_coll_t(compact, _U(readouts)).for_each(_U(include), Converter<DetElementInclude>(description));
xml_coll_t(compact, _U(readouts)).for_each(_U(readout), Converter<Readout>(description));

printout(DEBUG, "Compact", "++ Converting included files with subdetector structures...");
xml_coll_t(compact, _U(detectors)).for_each(_U(include), Converter<DetElementInclude>(description));
printout(DEBUG, "Compact", "++ Converting detector structures...");
Expand All @@ -1767,6 +1776,7 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
ReflectionBuilder rb(description);
rb.execute();
}
/// Load plugin and process them as indicated
xml_coll_t(compact, _U(plugins)).for_each(_U(plugin), Converter<Plugin> (description));
xml_coll_t(compact, _U(plugins)).for_each(_U(include), Converter<XMLFile> (description));
xml_coll_t(compact, _U(plugins)).for_each(_U(xml), Converter<XMLFile> (description));
Expand Down
11 changes: 5 additions & 6 deletions DDCore/src/segmentations/CartesianGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Created: Jun 28, 2013
// Author: Christian Grefe, CERN
//
//==========================================================================
/*
* CartesianGrid.cpp
*
* Created on: Jun 28, 2013
* Author: Christian Grefe, CERN
*/

/// Framework include files
#include <DDSegmentation/CartesianGrid.h>

namespace dd4hep {

namespace DDSegmentation {

/// Default constructor used by derived classes passing the encoding string
Expand Down
13 changes: 6 additions & 7 deletions DDCore/src/segmentations/CartesianGridXY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Created: Jun 28, 2013
// Author: Christian Grefe, CERN
//
//==========================================================================
/*
* CartesianGridXY.cpp
*
* Created on: Jun 28, 2013
* Author: Christian Grefe, CERN
*/

/// Framework include files
#include <DDSegmentation/CartesianGridXY.h>

namespace dd4hep {
namespace DDSegmentation {

namespace DDSegmentation {

/// default constructor using an encoding string
CartesianGridXY::CartesianGridXY(const std::string& cellEncoding) :
Expand Down
13 changes: 6 additions & 7 deletions DDCore/src/segmentations/CartesianGridXYStaggered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Created: Sept 15, 2023
// Author: Sebouh J. Paul, UCR
//
//==========================================================================
/*
* CartesianGridXYStaggered.cpp
*
* Created on: Sept 15, 2023
* Author: Sebouh J. Paul, UCR
*/

/// Framework include files
#include <DDSegmentation/CartesianGridXYStaggered.h>

namespace dd4hep {
namespace DDSegmentation {

namespace DDSegmentation {

/// default constructor using an encoding string
CartesianGridXYStaggered::CartesianGridXYStaggered(const std::string& cellEncoding)
Expand Down
10 changes: 4 additions & 6 deletions DDCore/src/segmentations/CartesianGridXYZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Created: Jun 28, 2013
// Author: Christian Grefe, CERN
//
//==========================================================================
/*
* CartesianGridXYZ.cpp
*
* Created on: Jun 28, 2013
* Author: Christian Grefe, CERN
*/

/// Framework include files
#include <DDSegmentation/CartesianGridXYZ.h>

namespace dd4hep {
Expand Down
10 changes: 4 additions & 6 deletions DDCore/src/segmentations/CartesianGridXZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Created: Jun 28, 2013
// Author: Christian Grefe, CERN
//
//==========================================================================
/*
* CartesianGridXZ.cpp
*
* Created on: Jun 28, 2013
* Author: Christian Grefe, CERN
*/

/// Framework include files
#include <DDSegmentation/CartesianGridXZ.h>

namespace dd4hep {
Expand Down
Loading
Loading