Skip to content

Commit

Permalink
Merge branch 'master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch authored Nov 25, 2023
2 parents d132b82 + e47d569 commit 262c20c
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 71 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DD4hep)
#################

SET( DD4hep_VERSION_MAJOR 1 )
SET( DD4hep_VERSION_MINOR 26 )
SET( DD4hep_VERSION_PATCH 0 )
SET( DD4hep_VERSION_MINOR 27 )
SET( DD4hep_VERSION_PATCH 1 )

#######################
# Basic project setup #
Expand Down Expand Up @@ -137,6 +137,10 @@ if(DD4HEP_USE_GEANT4)
IF(NOT Geant4_builtin_clhep_FOUND)
SET(DD4HEP_USE_CLHEP TRUE)
ENDIF()
if(Geant4_CXX_STANDARD MATCHES "[0-9]+" AND Geant4_CXX_STANDARD LESS ${CMAKE_CXX_STANDARD})
message(FATAL_ERROR "Geant4 was compiled with C++${Geant4_CXX_STANDARD}, but DD4hep requires C++${CMAKE_CXX_STANDARD}")
endif()

DD4HEP_SETUP_GEANT4_TARGETS()
# Geant4 sets the CLHEP include directory to include_directories, we undo this here
# we don't do this inside DD4hep_SETUP_GEANT4_TARGETS, because that is also used in
Expand Down
31 changes: 28 additions & 3 deletions DDCAD/src/plugins/CADPlugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,36 @@
#include <DDCAD/ASSIMPWriter.h>

// C/C++ include files
#include <filesystem>

using namespace std;
using namespace dd4hep;
using namespace dd4hep::detail;

/// If the path to the CAD file does not directly exist try to resolve it:
static string resolve_path(xml_h e, const string& file) {
error_code errc;
std::string fname;
/// Use the xml utilities in the DocumentHandler to resolve the relative path
if ( file.length() > 7 && file.substr(0,7) == "file://" )
fname = file.substr(7);
else
fname = file;
if ( !filesystem::exists(fname, errc) ) {
string fn = xml::DocumentHandler::system_path(e, fname);
if ( fn.length() > 7 && fn.substr(0,7) == "file://" )
fn = fn.substr(7);
if ( !std::filesystem::exists(fn, errc) ) {
auto fp = filesystem::path(xml::DocumentHandler::system_path(e)).parent_path();
except("CAD_Shape","+++ CAD file: %s (= %s + %s) is not accessible [%d: %s]",
fn.c_str(), fp.c_str(), fname.c_str(),
errc.value(), errc.message().c_str());
}
return fn;
}
return fname;
}

static void* read_CAD_Volume(Detector& dsc, int argc, char** argv) {
string fname;
double scale = 1.0;
Expand Down Expand Up @@ -61,7 +86,7 @@ DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_read_CAD_volumes,read_CAD_Volume)
static Handle<TObject> create_CAD_Shape(Detector& dsc, xml_h e) {
xml_elt_t elt(e);
cad::ASSIMPReader rdr(dsc);
string fname = elt.attr<string>(_U(ref));
string fname = resolve_path(e, elt.attr<string>(_U(ref)));
long flags = elt.hasAttr(_U(flags)) ? elt.attr<long>(_U(flags)) : 0;
double unit = elt.hasAttr(_U(unit)) ? elt.attr<double>(_U(unit)) : dd4hep::cm;

Expand Down Expand Up @@ -97,7 +122,7 @@ DECLARE_XML_SHAPE(CAD_Shape__shape_constructor,create_CAD_Shape)

static Handle<TObject> create_CAD_Assembly(Detector& dsc, xml_h e) {
xml_elt_t elt(e);
string fname = elt.attr<string>(_U(ref));
string fname = resolve_path(e, elt.attr<string>(_U(ref)));
double unit = elt.hasAttr(_U(unit)) ? elt.attr<double>(_U(unit)) : dd4hep::cm;
auto volumes = cad::ASSIMPReader(dsc).readVolumes(fname, unit);
if ( volumes.empty() ) {
Expand Down Expand Up @@ -159,8 +184,8 @@ DECLARE_XML_VOLUME(CAD_Assembly__volume_constructor,create_CAD_Assembly)
*/
static Handle<TObject> create_CAD_Volume(Detector& dsc, xml_h e) {
xml_elt_t elt(e);
string fname = elt.attr<string>(_U(ref));
double unit = elt.attr<double>(_U(unit));
string fname = resolve_path(e, elt.attr<string>(_U(ref)));
long flags = elt.hasAttr(_U(flags)) ? elt.attr<long>(_U(flags)) : 0;
cad::ASSIMPReader rdr(dsc);

Expand Down
2 changes: 1 addition & 1 deletion DDCore/include/DD4hep/Detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace dd4hep {
is not present. Otherwise an empty detector container is returned.
*/
virtual const std::vector<DetElement>& detectors(const std::string& type,
bool throw_exc=false) = 0;
bool throw_exc=false) const = 0;

/// Access a set of subdetectors according to several sensitive types.
virtual std::vector<DetElement> detectors(const std::string& type1,
Expand Down
2 changes: 1 addition & 1 deletion DDCore/include/DD4hep/DetectorImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ namespace dd4hep {
- If throw_exc is set to true, an exception is thrown if the type
is not present. Otherwise an empty detector container is returned.
*/
virtual const std::vector<DetElement>& detectors(const std::string& type, bool throw_exc) override;
virtual const std::vector<DetElement>& detectors(const std::string& type, bool throw_exc) const override;

/// Access a set of subdetectors according to several sensitive types.
virtual std::vector<DetElement> detectors(const std::string& type1,
Expand Down
9 changes: 5 additions & 4 deletions DDCore/src/DetectorImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ Material DetectorImp::material(const string& name) const {

/// Internal helper to map detector types once the geometry is closed
void DetectorImp::mapDetectorTypes() {
m_detectorTypes[""] = {};
for( const auto& i : m_detectors ) {
DetElement det(i.second);
if ( det.parent().isValid() ) { // Exclude 'world'
Expand Down Expand Up @@ -571,15 +572,15 @@ vector<string> DetectorImp::detectorTypes() const {
}

/// Access a set of subdetectors according to the sensitive type.
const vector<DetElement>& DetectorImp::detectors(const string& type, bool throw_exc) {
const vector<DetElement>& DetectorImp::detectors(const string& type, bool throw_exc) const {
if ( m_manager->IsClosed() ) {
DetectorTypeMap::const_iterator i=m_detectorTypes.find(type);
if ( i != m_detectorTypes.end() ) return (*i).second;
if ( throw_exc ) {
DetectorTypeMap::const_iterator i=m_detectorTypes.find(type);
if ( i != m_detectorTypes.end() ) return (*i).second;
throw runtime_error("detectors("+type+"): Detectors of this type do not exist in the current setup!");
}
// return empty vector instead of exception
return m_detectorTypes[ type ] ;
return m_detectorTypes.at("") ;
}
throw runtime_error("detectors("+type+"): Detectors can only selected by type once the geometry is closed!");
}
Expand Down
33 changes: 28 additions & 5 deletions DDCore/src/plugins/Compact2Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
#include <TMath.h>

// C/C++ include files
#include <climits>
#include <filesystem>
#include <iostream>
#include <iomanip>
#include <climits>
#include <set>

using namespace std;
Expand Down Expand Up @@ -1443,17 +1444,38 @@ template <> void Converter<IncludeFile>::operator()(xml_h element) const {
template <> void Converter<JsonFile>::operator()(xml_h element) const {
string base = xml::DocumentHandler::system_directory(element);
string file = element.attr<string>(_U(ref));
vector<char*> argv{&file[0],&base[0]};
vector<char*> argv{&file[0], &base[0]};
description.apply("DD4hep_JsonProcessor",int(argv.size()), &argv[0]);
}

/// Read alignment entries from a seperate file in one of the include sections of the geometry
template <> void Converter<XMLFile>::operator()(xml_h element) const {
PrintLevel level = s_debug.includes ? ALWAYS : DEBUG;
string fname = element.attr<string>(_U(ref));
if ( s_debug.includes ) {
printout(ALWAYS, "Compact","++ Processing xml document %s.", fname.c_str());
size_t idx = fname.find("://");
std::error_code ec;

if ( idx == string::npos && filesystem::exists(fname, ec) ) {
// Regular file without protocol specification
printout(level, "Compact","++ Processing xml document %s.", fname.c_str());
this->description.fromXML(fname);
}
else if ( idx == string::npos ) {
// File relative to location of xml tag (protocol specification not possible)
string location = xml::DocumentHandler::system_path(element, fname);
printout(level, "Compact","++ Processing xml document %s.", location.c_str());
this->description.fromXML(location);
}
else if ( idx > 0 ) {
// File with protocol specification: must trust the location and the parser capabilities
printout(level, "Compact","++ Processing xml document %s.", fname.c_str());
this->description.fromXML(fname);
}
else {
// Are there any other possibilities ?
printout(level, "Compact","++ Processing xml document %s.", fname.c_str());
this->description.fromXML(fname);
}
this->description.fromXML(fname);
}

/// Read material entries from a seperate file in one of the include sections of the geometry
Expand Down Expand Up @@ -1716,6 +1738,7 @@ template <> void Converter<Compact>::operator()(xml_h element) const {
}
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));
}

#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion DDCore/src/plugins/DetectorChecksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace {
return v.data() != 0;
}
inline double check_null(double d) {
if ( abs(d) < 1e-12 )
if ( fabs(d) < 1e-12 )
return 0e0;
else
return d;
Expand Down
6 changes: 6 additions & 0 deletions DDCore/src/plugins/ReadoutSegmentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ DECLARE_SEGMENTATION(CartesianGridYZ,create_segmentation<dd4hep::DDSegmentation:
#include "DDSegmentation/CartesianGridXYZ.h"
DECLARE_SEGMENTATION(CartesianGridXYZ,create_segmentation<dd4hep::DDSegmentation::CartesianGridXYZ>)

#include "DDSegmentation/CartesianGridXYStaggered.h"
DECLARE_SEGMENTATION(CartesianGridXYStaggered,dd4hep::create_segmentation<dd4hep::DDSegmentation::CartesianGridXYStaggered>)

#include "DDSegmentation/CartesianStripX.h"
DECLARE_SEGMENTATION(CartesianStripX,create_segmentation<dd4hep::DDSegmentation::CartesianStripX>)

Expand Down Expand Up @@ -75,3 +78,6 @@ DECLARE_SEGMENTATION(ProjectiveCylinder,create_segmentation<dd4hep::DDSegmentati

#include "DDSegmentation/MultiSegmentation.h"
DECLARE_SEGMENTATION(MultiSegmentation,create_segmentation<dd4hep::DDSegmentation::MultiSegmentation>)

#include "DDSegmentation/HexGrid.h"
DECLARE_SEGMENTATION(HexGrid,create_segmentation<dd4hep::DDSegmentation::HexGrid>)
4 changes: 0 additions & 4 deletions DDCore/src/segmentations/CartesianGridXYStaggered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,3 @@ std::vector<double> CartesianGridXYStaggered::cellDimensions(const CellID& cellI

} /* namespace DDSegmentation */
} /* namespace dd4hep */

// This is done DDCore/src/plugins/ReadoutSegmentations.cpp so the plugin is not part of libDDCore
// needs also #include "DD4hep/Factories.h"
// DECLARE_SEGMENTATION(CartesianGridXYStaggered,dd4hep::create_segmentation<dd4hep::DDSegmentation::CartesianGridXYStaggered>)
2 changes: 0 additions & 2 deletions DDCore/src/segmentations/HexGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,3 @@ namespace dd4hep {

} /* namespace DDSegmentation */
} /* namespace dd4hep */

DECLARE_SEGMENTATION(HexGrid, create_segmentation<dd4hep::DDSegmentation::HexGrid>)
5 changes: 5 additions & 0 deletions DDEve/src/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "DD4hep/Printout.h"

// ROOT include files
#include "TROOT.h"
#include "TH2.h"
#include "TFile.h"
#include "TSystem.h"
Expand Down Expand Up @@ -270,7 +271,11 @@ void Display::UnregisterEvents(View* view) {

/// Open standard message box
void Display::MessageBox(PrintLevel level, const string& text, const string& title) const {
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,9,2)
string path = TString::Format("%s/", TROOT::GetIconPath().Data()).Data();
#else
string path = TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")).Data();
#endif
const TGPicture* pic = 0;
if ( level == VERBOSE )
pic = client().GetPicture((path+"mb_asterisk_s.xpm").c_str());
Expand Down
5 changes: 5 additions & 0 deletions DDEve/src/EventControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "DD4hep/InstanceCount.h"

// ROOT include files
#include <TROOT.h>
#include <TSystem.h>
#include <TGTab.h>
#include <TGLabel.h>
Expand Down Expand Up @@ -158,7 +159,11 @@ void EventControl::OnNewEvent(EventHandler& handler) {

/// User callback to add elements to the control
void EventControl::OnBuild() {
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,9,2)
string icondir = TString::Format("%s/", TROOT::GetIconPath().Data()).Data();
#else
string icondir = TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")).Data();
#endif
TGGroupFrame* group = new TGGroupFrame(m_frame,"Event I/O Control");
TGCompositeFrame* top = new TGHorizontalFrame(group);
TGPictureButton* b = 0;
Expand Down
9 changes: 9 additions & 0 deletions DDEve/src/GenericEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <stdexcept>

/// ROOT include files
#include "TROOT.h"
#include "TGMsgBox.h"
#include "TSystem.h"
#include <climits>
Expand Down Expand Up @@ -136,7 +137,11 @@ bool GenericEventHandler::Open(const string& file_type, const string& file_name)
err = "\nAn exception occurred \n"
"while opening event data:\n" + string(e.what()) + "\n\n";
}
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,9,2)
string path = TString::Format("%s/stop_t.xpm", TROOT::GetIconPath().Data()).Data();
#else
string path = TString::Format("%s/icons/stop_t.xpm", gSystem->Getenv("ROOTSYS")).Data();
#endif
const TGPicture* pic = gClient->GetPicture(path.c_str());
new TGMsgBox(gClient->GetRoot(),0,"Failed to open event data",err.c_str(),pic,
kMBDismiss,0,kVerticalFrame,kTextLeft|kTextCenterY);
Expand All @@ -157,7 +162,11 @@ bool GenericEventHandler::NextEvent() {
throw runtime_error("+++ EventHandler::readEvent: No file open!");
}
catch(const exception& e) {
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,9,2)
string path = TString::Format("%s/stop_t.xpm", TROOT::GetIconPath().Data()).Data();
#else
string path = TString::Format("%s/icons/stop_t.xpm", gSystem->Getenv("ROOTSYS")).Data();
#endif
string err = "\nAn exception occurred \n"
"while reading a new event:\n" + string(e.what()) + "\n\n";
const TGPicture* pic = gClient->GetPicture(path.c_str());
Expand Down
2 changes: 1 addition & 1 deletion DDG4/include/DDG4/Geant4SensDetAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// Geant4 include files
#include <G4ThreeVector.hh>
#include <G4VTouchable.hh>

// C/C++ include files
#include <vector>
Expand All @@ -28,7 +29,6 @@
class G4HCofThisEvent;
class G4Step;
class G4Event;
class G4VTouchable;
class G4TouchableHistory;
class G4VHitsCollection;
class G4VReadOutGeometry;
Expand Down
3 changes: 2 additions & 1 deletion DDG4/include/DDG4/Geant4TouchableHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
#ifndef DDG4_GEANT4TOUCHABLEHANDLER_H
#define DDG4_GEANT4TOUCHABLEHANDLER_H

#include <G4VTouchable.hh>

// C/C++ include files
#include <vector>
#include <string>

// Forward declarations
class G4VPhysicalVolume;
class G4VTouchable;
class G4Step;

/// Namespace for the AIDA detector description toolkit
Expand Down
2 changes: 1 addition & 1 deletion DDG4/include/DDG4/Geant4VolumeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <DD4hep/IDDescriptor.h>
#include <DDG4/Geant4Primitives.h>

#include <G4VTouchable.hh>
// Geant4 forward declarations
class G4VTouchable;
class G4VPhysicalVolume;


Expand Down
2 changes: 1 addition & 1 deletion DDG4/plugins/Geant4SDActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace dd4hep {
double hit_deposit = contrib.deposit;
Hit* hit = new Hit(contrib, hit_momentum, hit_deposit);

if (h.trackDef() != G4OpticalPhoton::OpticalPhotonDefinition()) {
if (h.trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) {
step->GetTrack()->SetTrackStatus(fStopAndKill);
}
hit->cellID = cellID(step);
Expand Down
2 changes: 1 addition & 1 deletion DDG4/python/DDSim/Helper/Gun.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):
self.momentumMin = 0 * GeV
self._momentumMax_EXTRA = {'help': "Maximal momentum when using distribution (default = 0.0)"}
self.momentumMax = 10 * GeV
self._energy_EXTRA = {'help': "The kinetic energy for the particle gun.\n\n"
self._energy_EXTRA = {'help': "Total energy (including mass) for the particle gun.\n\n"
"If not None, it will overwrite the setting of momentumMin and momentumMax"}
self.energy = None

Expand Down
2 changes: 1 addition & 1 deletion DDRec/include/DDRec/CellIDPositionConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace dd4hep {
public:

/// The constructor - takes the main description object.
CellIDPositionConverter( Detector& description ) : _description( &description ) {
CellIDPositionConverter(const Detector& description ) : _description( &description ) {
_volumeManager = VolumeManager::getVolumeManager(description);
}

Expand Down
4 changes: 2 additions & 2 deletions DDRec/include/DDRec/MaterialScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace dd4hep {
private:

/// Reference to detector setup
Detector& m_detector;
const Detector& m_detector;
/// Material manager
std::unique_ptr<MaterialManager> m_materialMgr; //!
/// Local cache: subdetector placements
Expand All @@ -64,7 +64,7 @@ namespace dd4hep {
public:

/// Standard constructor for the master instance
MaterialScan(Detector& description);
MaterialScan(const Detector& description);

/// Default destructor
virtual ~MaterialScan();
Expand Down
Loading

0 comments on commit 262c20c

Please sign in to comment.