forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first steps twoards ODD with Acts::Detector, unit test infrastructure…
… for DD4hep conversion
- Loading branch information
1 parent
b69a47b
commit c68ec76
Showing
28 changed files
with
1,269 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include <Acts/Definitions/Algebra.hpp> | ||
#include <Acts/Geometry/GeometryContext.hpp> | ||
#include <Acts/Plugins/Python/Utilities.hpp> | ||
#include <Acts/Surfaces/Surface.hpp> | ||
#include <Acts/Visualization/GeometryView3D.hpp> | ||
#include <Acts/Visualization/ObjVisualization3D.hpp> | ||
#include <Acts/Visualization/ViewConfig.hpp> | ||
|
||
#include <memory> | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
using namespace Acts; | ||
|
||
namespace Acts::Python { | ||
void addObj(Context& ctx) { | ||
auto [m, mex] = ctx.get("main", "examples"); | ||
|
||
{ | ||
/// Write a collection of surfaces to an '.obj' file | ||
/// | ||
/// @param surfaces is the collection of surfaces | ||
/// @param viewContext is the geometry context | ||
/// @param viewRgb is the color of the surfaces | ||
/// @param fileName is the name of the output file | ||
/// | ||
mex.def("writeSurfacesObj", | ||
[](const std::vector<std::shared_ptr<Surface>>& surfaces, | ||
const GeometryContext& viewContext, | ||
const std::array<int, 3>& viewRgb, const std::string& fileName) { | ||
Acts::ViewConfig sConfig = Acts::ViewConfig{viewRgb}; | ||
Acts::GeometryView3D view3D; | ||
Acts::ObjVisualization3D obj; | ||
|
||
for (const auto& surface : surfaces) { | ||
view3D.drawSurface(obj, *surface, viewContext, | ||
Acts::Transform3::Identity(), sConfig); | ||
} | ||
obj.write(fileName); | ||
}); | ||
} | ||
} | ||
} // namespace Acts::Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env python3 | ||
import os, argparse, pathlib, acts, acts.examples | ||
from acts.examples import dd4hep as acts_dd4hep | ||
|
||
|
||
viewContext = acts.GeometryContext() | ||
viewRgb = [ 120, 55, 0 ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Plugins/DD4hep/include/Acts/Plugins/DD4hep/DD4hepDetectorSurfaceFactory.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2022 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Definitions/Algebra.hpp" | ||
#include "Acts/Definitions/Common.hpp" | ||
#include "Acts/Definitions/Units.hpp" | ||
#include "Acts/Detector/LayerStructureBuilder.hpp" | ||
#include "Acts/Detector/ProtoBinning.hpp" | ||
#include "Acts/Surfaces/Surface.hpp" | ||
|
||
#include <tuple> | ||
#include <vector> | ||
|
||
#include <DD4hep/DD4hepUnits.h> | ||
|
||
class TGeoMatrix; | ||
|
||
namespace dd4hep { | ||
class DetElement; | ||
} | ||
|
||
namespace Acts { | ||
|
||
class DD4hepDetectorElement; | ||
|
||
/// A factory to convert DD4hep DetectorElements into sensitive | ||
/// of passive surfaces | ||
/// | ||
class DD4hepDetectorSurfaceFactory { | ||
public: | ||
/// Collect the senstive surface & detector element | ||
using DD4hepSensitiveSurface = | ||
std::tuple<std::shared_ptr<DD4hepDetectorElement>, | ||
std::shared_ptr<Surface>>; | ||
|
||
/// Collect the passive surfaces | ||
using DD4hepPassiveSurface = std::shared_ptr<Surface>; | ||
|
||
/// Collect passive surface proxies | ||
struct DD4hepPassiveSurfaceProxy { | ||
std::string placement = ""; | ||
}; | ||
|
||
/// Nested cache that records the conversion status | ||
struct Cache { | ||
/// The created detector elements - for the detector store | ||
std::vector<DD4hepSensitiveSurface> sensitiveSurfaces; | ||
/// The created non-const surfaces - for further processing, | ||
std::vector<DD4hepPassiveSurface> passiveSurfaces; | ||
/// The created Proxies for the support surfaces | ||
std::vector<DD4hepPassiveSurfaceProxy> passiveSurfaceProxies; | ||
/// matching and conversion statics: surfaces | ||
std::size_t convertedSurfaces = 0; | ||
/// matching and conversion statistics: materials | ||
std::size_t convertedMaterials = 0; | ||
/// The collected binnings | ||
std::vector<Experimental::ProtoBinning> binnings = {}; | ||
/// The collected supports | ||
std::vector<Experimental::LayerStructureBuilder::Support> supports = {}; | ||
}; | ||
|
||
/// The DD4hep detector element factory | ||
/// | ||
/// @param cfg the configuration struct | ||
/// @param logger a screen output logger | ||
DD4hepDetectorSurfaceFactory( | ||
std::unique_ptr<const Logger> mlogger = getDefaultLogger( | ||
"DD4hepDetectorSurfaceFactory", Acts::Logging::INFO)); | ||
|
||
/// Construction method of the detector elements | ||
/// | ||
/// @param cache [in,out] into which the Elements are filled | ||
/// @param dd4hepElement the detector element representing the super structure | ||
/// | ||
/// @note this method will call the recursive construction | ||
void construct(Cache& cache, const dd4hep::DetElement& dd4hepElement); | ||
|
||
private: | ||
/// @brief auto-calculate the unit length conversion | ||
static constexpr ActsScalar unitLength = | ||
Acts::UnitConstants::mm / dd4hep::millimeter; | ||
|
||
/// Logging instance | ||
std::unique_ptr<const Logger> m_logger; | ||
|
||
// The allows passive proxy positions | ||
std::vector<std::string> allowedPassiveProxies = { | ||
"inner", "outer", "negative", "positive", "representing"}; | ||
|
||
/// Private access to the logger | ||
const Logger& logger() const { return *m_logger; } | ||
|
||
/// Construction method of the detector elements - recursive walk down | ||
/// | ||
/// @param cache [in,out] into which the Elements are filled | ||
/// @param dd4hepElement the detector element representing the super structure | ||
/// @param level the current level of the tree, used for log message output | ||
/// | ||
/// @note this method is called recursively | ||
void recursiveConstruct(Cache& cache, const dd4hep::DetElement& dd4hepElement, | ||
int level); | ||
|
||
/// Method to conver a single senstive detector element | ||
/// | ||
/// @param dd4hepElement the detector element | ||
/// | ||
/// @return a created detector element and surface | ||
DD4hepSensitiveSurface constructSensitiveElement( | ||
const dd4hep::DetElement& dd4hepElement) const; | ||
|
||
/// Method to conver a single senstive detector element | ||
/// | ||
/// @param options the factory creation option | ||
/// @param dd4hepElement the detector element | ||
/// | ||
/// @return a created surface | ||
DD4hepPassiveSurface constructPassiveElement( | ||
const dd4hep::DetElement& dd4hepElement) const; | ||
}; | ||
|
||
} // namespace Acts |
Oops, something went wrong.