diff --git a/Detector/DetDriftChamber/CMakeLists.txt b/Detector/DetDriftChamber/CMakeLists.txt index 4a95aeec670ffdb3aa03e681041fb559964f2743..b680276955849c32df5af4e92216e9cab21accf9 100644 --- a/Detector/DetDriftChamber/CMakeLists.txt +++ b/Detector/DetDriftChamber/CMakeLists.txt @@ -4,7 +4,8 @@ ################################################################################ gaudi_subdir(DetDriftChamber v0r0) -gaudi_depends_on_subdirs(GaudiKernel) +gaudi_depends_on_subdirs(Detector/DetSegmentation) +#gaudi_depends_on_subdirs(GaudiKernel) find_package(DD4hep COMPONENTS DDRec DDG4 DDParsers REQUIRED) diff --git a/Detector/DetDriftChamber/compact/det.xml b/Detector/DetDriftChamber/compact/det.xml index 3920c12a1a7197f21cc46719d1ab68bbf9bc9154..84a1ec7b05d00220ac3fda86c50f4d0111b550b7 100644 --- a/Detector/DetDriftChamber/compact/det.xml +++ b/Detector/DetDriftChamber/compact/det.xml @@ -57,9 +57,9 @@ <readouts> <readout name="DriftChamberHitsCollection"> - <segmentation type="NoSegmentation"/> + <segmentation type="GridDriftChamber" delta_phi="8*deg" identifier_phi="phi"/> - <id>system:8,chamber:1,layer:8</id> + <id>system:8,chamber:1,layer:8,phi:16</id> </readout> </readouts> diff --git a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp index 5ac10182ce8a88fe92a8c36bbc5fb0258e117553..c71012156662c8b053567bf2667d535c097016a6 100644 --- a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp +++ b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp @@ -12,6 +12,7 @@ #include "XML/Utilities.h" #include "DDRec/DetectorData.h" #include "DDSegmentation/Segmentation.h" +#include "DetSegmentation/GridDriftChamber.h" using namespace dd4hep; using namespace dd4hep::detail; @@ -74,6 +75,7 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, dd4hep::Tube det_outer_chamber_solid(outer_chamber_radius_min, outer_chamber_radius_max, outer_chamber_length*0.5); dd4hep::Volume det_outer_chamber_vol(det_name+"_outer_chamber_vol", det_outer_chamber_solid, det_mat); + // - layer for(int layer_id=0; layer_id<(inner_chamber_layer_number+outer_chamber_layer_number-1);layer_id++) { double rmin,rmax; diff --git a/Detector/DetSegmentation/.GridDriftChamber.h.swp b/Detector/DetSegmentation/.GridDriftChamber.h.swp new file mode 100644 index 0000000000000000000000000000000000000000..51f757f081f232cc857fcd0ed4b1246ecaf06edb Binary files /dev/null and b/Detector/DetSegmentation/.GridDriftChamber.h.swp differ diff --git a/Detector/DetSegmentation/CMakeLists.txt b/Detector/DetSegmentation/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f6b2611e35080a64fdb67ecb30a2e67729a5364b --- /dev/null +++ b/Detector/DetSegmentation/CMakeLists.txt @@ -0,0 +1,33 @@ +################################################################################# +##Package : DetSegmentation +################################################################################# +gaudi_subdir(DetSegmentation v1r0) + +gaudi_depends_on_subdirs(GaudiKernel) + +find_package(DD4hep COMPONENTS DDRec DDG4 DDParsers REQUIRED) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DD4hep_ROOT}/cmake ) + +include(DD4hep) + +find_package(ROOT COMPONENTS MathCore Physics GenVector Geom REQUIRED) + +gaudi_add_library(DetSegmentation + src/*.cpp + INCLUDE_DIRS DD4hep ROOT + LINK_LIBRARIES GaudiKernel DD4hep ROOT ${DD4hep_COMPONENT_LIBRARIES} + PUBLIC_HEADERS DetSegmentation) + +gaudi_add_module(DetSegmentationPlugin + src/plugins/*.cpp + INCLUDE_DIRS DD4hep ROOT + LINK_LIBRARIES GaudiKernel DD4hep ROOT ${DD4hep_COMPONENT_LIBRARIES} DetSegmentation) + +set(LIBRARY_OUTPUT_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) +message(STATUS "LIBRARY_OUTPUT_PATH -> ${LIBRARY_OUTPUT_PATH}") +dd4hep_generate_rootmap(DetSegmentationPlugin) + +include(CTest) +gaudi_add_test(TestSegmentationPhiEta + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + FRAMEWORK tests/options/phiEtaSegmentation.py) diff --git a/Detector/DetSegmentation/DetSegmentation/GridDriftChamber.h b/Detector/DetSegmentation/DetSegmentation/GridDriftChamber.h new file mode 100644 index 0000000000000000000000000000000000000000..379ad4a19fdbce33a63f009577970534f3f995c3 --- /dev/null +++ b/Detector/DetSegmentation/DetSegmentation/GridDriftChamber.h @@ -0,0 +1,90 @@ +#ifndef DETSEGMENTATION_GRIDDRIFTCHAMBER_H +#define DETSEGMENTATION_GRIDDRIFTCHAMBER_H + +#include "DDSegmentation/Segmentation.h" + +#include "TVector3.h" +#include <cmath> +#include <iostream> + +/** GridDriftChamber Detector/DetSegmentation/DetSegmentation/GridDriftChamber.h GridDriftChamber.h + * + * Segmentation for drift chamber. + * + * @author nalipour + */ + +namespace dd4hep { +namespace DDSegmentation { +class GridDriftChamber : public Segmentation { +public: + /// default constructor using an arbitrary type + GridDriftChamber(const std::string& aCellEncoding); + /// Default constructor used by derived classes passing an existing decoder + GridDriftChamber(const BitFieldCoder* decoder); + /// destructor + virtual ~GridDriftChamber() = default; + + virtual Vector3D position(const CellID& aCellID) const; + virtual CellID cellID(const Vector3D& aLocalPosition, const Vector3D& aGlobalPosition, + const VolumeID& aVolumeID) const; + +// inline double innerRadius() const { return m_innerRadius; } +// inline double detectorLength() const { return m_detectorLength; } + inline double offsetPhi() const { return m_offsetPhi; } + inline double delta_phi() const{ return m_delta_phi; } + inline const std::string& fieldNamePhi() const { return m_phiID; } + // Setters + +// inline void setGeomParams(int layer, double sizePhi) { +// layer_params[layer] = {sizePhi}; +// } + +// void updateParams(int layer) const { +// auto it_end = layer_params.cend(); +// --it_end; +// double size = it_end->second[0]; +// double radius = it_end->second[1]; +// double eps = it_end->second[2]; +// +// auto map_it = layer_params.find(layer); +// if (map_it != layer_params.cend()) { +// size = map_it->second[0]; +// radius = map_it->second[1]; +// eps = map_it->second[2]; +// } +// +// _currentGridSizePhi = size; +// _currentRadius = radius; +// m_epsilon = eps; +// } + + inline double phiFromXY(const Vector3D& aposition) const { + return std::atan2(aposition.Y, aposition.X) + M_PI ; + } + +// inline int returnLayer(double x, double y) const { +// // Hit R position +// double R = std::sqrt(x * x + y * y); +// // Layer +// int layer = int((R - m_innerRadius) / m_cellSize); +// return layer; +// } + +protected: + /* *** nalipour *** */ + double phi(const CellID& cID) const; + + + double m_offsetPhi; + double m_delta_phi; + std::string m_phiID; + + // Current parameters of the layer: sizePhi +// mutable double _currentGridSizePhi; // current size Phi +// mutable double _currentRadius; // current size radius +// mutable double m_epsilon; +}; +} +} +#endif /* DETSEGMENTATION_GRIDDRIFTCHAMBER_H */ diff --git a/Detector/DetSegmentation/src/GridDriftChamber.cpp b/Detector/DetSegmentation/src/GridDriftChamber.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4b1ed216fb0825e1b41a210871ca2451954ee22e --- /dev/null +++ b/Detector/DetSegmentation/src/GridDriftChamber.cpp @@ -0,0 +1,55 @@ +#include "DetSegmentation/GridDriftChamber.h" + +namespace dd4hep { +namespace DDSegmentation { + +/// default constructor using an encoding string +GridDriftChamber::GridDriftChamber(const std::string& cellEncoding) : Segmentation(cellEncoding) { + // define type and description + _type = "GridDriftChamber"; + _description = "Drift chamber segmentation in the global coordinates"; + + registerIdentifier("identifier_phi", "Cell ID identifier for phi", m_phiID, "phi"); + registerParameter("delta_phi", "delta phi", m_delta_phi, 0., SegmentationParameter::LengthUnit); +} + +GridDriftChamber::GridDriftChamber(const BitFieldCoder* decoder) : Segmentation(decoder) { + // define type and description + _type = "GridDriftChamber"; + _description = "Drift chamber segmentation in the global coordinates"; + + registerIdentifier("identifier_phi", "Cell ID identifier for phi", m_phiID, "phi"); + registerParameter("delta_phi", "delta phi", m_delta_phi, 0., SegmentationParameter::LengthUnit); +} + +Vector3D GridDriftChamber::position(const CellID& /*cID*/) const { + Vector3D cellPosition = {0, 0, 0}; + return cellPosition; +} + +CellID GridDriftChamber::cellID(const Vector3D& /*localPosition*/, const Vector3D& globalPosition, + const VolumeID& vID) const { + + CellID cID = vID; + + double phi_hit = phiFromXY(globalPosition); + double posx = globalPosition.X; + double posy = globalPosition.Y; + + int lphi = (int) (phi_hit/m_delta_phi); + _decoder->set(cID, m_phiID, lphi); + +// std::cout << " myliu: " +// << " x: " << posx +// << " y: " << posy +//// << " pre: " << phi_pre +// << " phi_hit: " << phi_hit +// << " lphi: " << lphi +// << std::endl; + return cID; +} + + +REGISTER_SEGMENTATION(GridDriftChamber) +} +} diff --git a/Detector/DetSegmentation/src/plugins/SegmentationFactories.cpp b/Detector/DetSegmentation/src/plugins/SegmentationFactories.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c06d3835694cff4ba0d5419ff370cf4ff96b5e3 --- /dev/null +++ b/Detector/DetSegmentation/src/plugins/SegmentationFactories.cpp @@ -0,0 +1,22 @@ +#include "DD4hep/Factories.h" +#include "DD4hep/detail/SegmentationsInterna.h" + +namespace { +template <typename T> +dd4hep::SegmentationObject* create_segmentation(const dd4hep::BitFieldCoder* decoder) { + return new dd4hep::SegmentationWrapper<T>(decoder); +} +} + +//#include "DetSegmentation/GridEta.h" +//DECLARE_SEGMENTATION(GridEta, create_segmentation<dd4hep::DDSegmentation::GridEta>) + +//#include "DetSegmentation/FCCSWGridPhiEta.h" +//DECLARE_SEGMENTATION(FCCSWGridPhiEta, create_segmentation<dd4hep::DDSegmentation::FCCSWGridPhiEta>) + +//#include "DetSegmentation/GridRPhiEta.h" +//DECLARE_SEGMENTATION(GridRPhiEta, create_segmentation<dd4hep::DDSegmentation::GridRPhiEta>) + +#include "DetSegmentation/GridDriftChamber.h" +DECLARE_SEGMENTATION(GridDriftChamber, create_segmentation<dd4hep::DDSegmentation::GridDriftChamber>) +