Skip to content

Commit

Permalink
Merge branch 'master' into ddrec-const-detector
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch authored Oct 19, 2023
2 parents 1ae088d + 88ed20d commit ee2705f
Show file tree
Hide file tree
Showing 32 changed files with 965 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
LCG: ["dev4/x86_64-centos7-clang12-opt"]
LCG: ["dev4/x86_64-el9-clang16-opt"]
steps:
- uses: actions/checkout@v3
- uses: cvmfs-contrib/github-action-cvmfs@v3
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
150 changes: 150 additions & 0 deletions DDCore/include/DDSegmentation/CartesianGridXYStaggered.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
//==========================================================================




/*
* CartesianGridXYStaggered.h
*
* Created on: September 15, 2023
* Author: Sebouh J. Paul, UCR
*/

#ifndef DDSEGMENTATION_CARTESIANGRIDXYSTAGGERED_H
#define DDSEGMENTATION_CARTESIANGRIDXYSTAGGERED_H

#include "DDSegmentation/CartesianGrid.h"

namespace dd4hep {
namespace DDSegmentation {

/// Segmentation base class describing cartesian grid segmentation in the X-Y plane
class CartesianGridXYStaggered: public CartesianGrid {
public:
/// Default constructor passing the encoding string
CartesianGridXYStaggered(const std::string& cellEncoding = "");
/// Default constructor used by derived classes passing an existing decoder
CartesianGridXYStaggered(const BitFieldCoder* decoder);
/// destructor
virtual ~CartesianGridXYStaggered();

/// determine the position based on the cell ID
virtual Vector3D position(const CellID& cellID) const;
/// determine the cell ID based on the position
virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& volumeID) const;
/// access the grid size in X
double gridSizeX() const {
return _gridSizeX;
}
/// access the grid size in Y
double gridSizeY() const {
return _gridSizeY;
}
/// access the coordinate offset in X
double offsetX() const {
return _offsetX;
}
/// access the coordinate offset in Y
double offsetY() const {
return _offsetY;
}
/// access the field name used for X
const std::string& fieldNameX() const {
return _xId;
}
/// access the field name used for Y
const std::string& fieldNameY() const {
return _yId;
}
/// access the staggering option in X
int staggerX() const {
return _staggerX;
}
/// access the staggering option in Y
int staggerY() const {
return _staggerY;
}
/// access the keyword used to determine which volumes to stagger
const std::string& staggerKeyword() const {
return _staggerKeyword;
}
/// set the grid size in X
void setGridSizeX(double cellSize) {
_gridSizeX = cellSize;
}
/// set the grid size in Y
void setGridSizeY(double cellSize) {
_gridSizeY = cellSize;
}
/// set the coordinate offset in X
void setOffsetX(double offset) {
_offsetX = offset;
}
/// set the coordinate offset in Y
void setOffsetY(double offset) {
_offsetY = offset;
}
/// set the field name used for X
void setFieldNameX(const std::string& fieldName) {
_xId = fieldName;
}
/// set the field name used for Y
void setFieldNameY(const std::string& fieldName) {
_yId = fieldName;
}
/// set the staggering option in X
void setStaggerX(int staggerX) {
_staggerX = staggerX;
}
/// set the staggering option in Y
void setStaggerY(int staggerY) {
_staggerY = staggerY;
}
/// set the keyword used to determine which volumes to stagger
void setStaggerKeyword(const std::string& staggerKeyword) {
_staggerKeyword = staggerKeyword;
}
/** \brief Returns a vector<double> of the cellDimensions of the given cell ID
in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi
Returns a vector of the cellDimensions of the given cell ID
\param cellID is ignored as all cells have the same dimension
\return std::vector<double> size 2:
-# size in x
-# size in y
*/
virtual std::vector<double> cellDimensions(const CellID& cellID) const;

protected:
/// the grid size in X
double _gridSizeX;
/// the coordinate offset in X
double _offsetX;
/// staggering option in X. 0 = no staggering. 1 = stagger by _gridSizeX/2.0 in odd layers
int _staggerX;
/// the grid size in Y
double _gridSizeY;
/// the coordinate offset in Y
double _offsetY;
/// staggering option in Y. 0 = no staggering. 1 = stagger by _gridSizeY/2.0 in odd layers
int _staggerY;
/// the field name used for X
std::string _xId;
/// the field name used for Y
std::string _yId;
/// the keyword used to determine which volumes to stagger
std::string _staggerKeyword;
};

} /* namespace DDSegmentation */
} /* namespace dd4hep */
#endif // DDSEGMENTATION_CARTESIANGRIDXYSTAGGERED_H
131 changes: 131 additions & 0 deletions DDCore/include/DDSegmentation/HexGrid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
//==========================================================================

/*
* HexGrid.h
*
* Created on: August 9, 2023
* Author: Sebouh J. Paul, UC Riverside
*/

#ifndef DDSEGMENTATION_HEXGRID_H
#define DDSEGMENTATION_HEXGRID_H

#include "DDSegmentation/Segmentation.h"

namespace dd4hep {
namespace DDSegmentation {

/// Segmentation base class describing hexagonal grid segmentation, with or without staggering
class HexGrid: public Segmentation {
public:
/// Destructor
virtual ~HexGrid();
//protected:
/// Default constructor used by derived classes passing the encoding string
HexGrid(const std::string& cellEncoding = "");
/// Default constructor used by derived classes passing an existing decoder
HexGrid(const BitFieldCoder* decoder);

/// determine the position based on the cell ID
virtual Vector3D position(const CellID& cellID) const;
/// determine the cell ID based on the position
virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& volumeID) const;
// access the stagger mode: 0=no stagger; 1=stagger cycling through 3 offsets
int stagger() const {
return _stagger;
}

/// access the grid size
double sideLength() const {
return _sideLength;
}
/// access the coordinate offset in X
double offsetX() const {
return _offsetX;
}
/// access the coordinate offset in Y
double offsetY() const {
return _offsetY;
}
/// access the field name used for X
const std::string& fieldNameX() const {
return _xId;
}
/// access the field name used for Y
const std::string& fieldNameY() const {
return _yId;
}
/// access the keyword for staggering
const std::string& staggerKeyword() const {
return _staggerKeyword;
}

/// set the stagger mode: 0=no stagger; 1=stagger cycling through 3 offsets
void setStagger(int stagger) {
_stagger= stagger;
}
/// set the grid size in X
void setSideLength(double cellSize) {
_sideLength = cellSize;
}
/// set the coordinate offset in X
void setOffsetX(double offset) {
_offsetX = offset;
}
/// set the coordinate offset in Y
void setOffsetY(double offset) {
_offsetY = offset;
}
/// set the field name used for X
void setFieldNameX(const std::string& fieldName) {
_xId = fieldName;
}
/// set the field name used for Y
void setFieldNameY(const std::string& fieldName) {
_yId = fieldName;
}
/// set the keyword used to determine which volumes to stagger
void setStaggerKeyword(const std::string& staggerKeyword) {
_staggerKeyword = staggerKeyword;
}
/** \brief Returns a vector<double> of the cellDimensions of the given cell ID
in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi
Returns a vector of the cellDimensions of the given cell ID
\param cellID is ignored as all cells have the same dimension
\return std::vector<double> size 2:
-# size in x
-# size in y
*/
virtual std::vector<double> cellDimensions(const CellID& cellID) const;

protected:
/// the stagger mode: 0=off ; 1=cycle through 3 different offsets (H3)
// 2=cycle through 4 differnt offsets (H4)
int _stagger;
/// the length of one side of a hexagon
double _sideLength;
/// the coordinate offset in X
double _offsetX;
/// the coordinate offset in Y
double _offsetY;
/// the field name used for X
std::string _xId;
/// the field name used for Y
std::string _yId;
/// the keyword used to determine which volumes to stagger
std::string _staggerKeyword;
};

} /* namespace DDSegmentation */
} /* namespace dd4hep */
#endif // DDSEGMENTATION_HEXGRID_H
Loading

0 comments on commit ee2705f

Please sign in to comment.