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 c5f080cabfaf57df907032b1c04055f84cfef414..84a1ec7b05d00220ac3fda86c50f4d0111b550b7 100644 --- a/Detector/DetDriftChamber/compact/det.xml +++ b/Detector/DetDriftChamber/compact/det.xml @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <lccdd> - + <info name="DriftChamber" - title="Test with Drift Chamber" - author="Tao Lin" - url="http://github.com/cepc/CEPCSW" - status="development" - version="v0"> - <comment>Test with Drift Chamber</comment> + title="Test with Drift Chamber" + author="Tao Lin" + url="http://github.com/cepc/CEPCSW" + status="development" + version="v0"> + <comment>Test with Drift Chamber</comment> </info> <includes> @@ -34,7 +34,10 @@ <constant name="SDT_outer_chamber_radius_min" value="1085*mm"/> <constant name="SDT_outer_chamber_radius_max" value="SDT_radius_max"/> <constant name="SDT_outer_chamber_length" value="SDT_length"/> - + + <constant name="SDT_inner_chamber_layer_number" value="67"/> + <constant name="SDT_outer_chamber_layer_number" value="63"/> + <constant name="SDT_chamber_layer_width" value="10*mm"/> </define> @@ -49,18 +52,14 @@ <detectors> <detector id="1" name="DriftChamber" type="DriftChamber" readout="DriftChamberHitsCollection" vis="VisibleBlue" sensitive="true"> <!-- Use cm as unit if you want to use Pandora for reconstruction --> - </detector> + </detector> </detectors> - + <readouts> <readout name="DriftChamberHitsCollection"> - <!-- <segmentation type="NoSegmentation"/> --> + <segmentation type="GridDriftChamber" delta_phi="8*deg" identifier_phi="phi"/> - <segmentation type="CartesianGridXYZ" - grid_size_x="1*cm" - grid_size_y="1*cm" - grid_size_z="1*cm"/> - <id>system:8,chamber:1,x:-16,y:-16,z:-16</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 9df294c519aae1ef28ac002acc678f8fd8331d44..c71012156662c8b053567bf2667d535c097016a6 100644 --- a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp +++ b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp @@ -3,6 +3,7 @@ //-------------------------------------------------------------------- // // Author: Tao Lin +// Mengyao Liu // //==================================================================== @@ -11,13 +12,18 @@ #include "XML/Utilities.h" #include "DDRec/DetectorData.h" #include "DDSegmentation/Segmentation.h" +#include "DetSegmentation/GridDriftChamber.h" + +using namespace dd4hep; +using namespace dd4hep::detail; +using namespace dd4hep::rec ; #define MYDEBUG(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << x << std::endl; #define MYDEBUGVAL(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << #x << ": " << x << std::endl; static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, - xml_h e, - dd4hep::SensitiveDetector sens) { + xml_h e, + dd4hep::SensitiveDetector sens) { // ======================================================================= // Parameter Definition // ======================================================================= @@ -27,7 +33,7 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, std::string det_name = x_det.nameStr(); std::string det_type = x_det.typeStr(); - // - global + // - global double chamber_radius_min = theDetector.constant<double>("SDT_radius_min"); double chamber_radius_max = theDetector.constant<double>("SDT_radius_max"); double chamber_length = theDetector.constant<double>("SDT_length"); @@ -42,6 +48,11 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, double outer_chamber_radius_max = theDetector.constant<double>("SDT_outer_chamber_radius_max"); double outer_chamber_length = theDetector.constant<double>("SDT_outer_chamber_length"); + // - layer + int inner_chamber_layer_number = theDetector.constant<int>("SDT_inner_chamber_layer_number"); + int outer_chamber_layer_number = theDetector.constant<int>("SDT_outer_chamber_layer_number"); + double chamber_layer_width = theDetector.constant<double>("SDT_chamber_layer_width"); + // ======================================================================= // Detector Construction // ======================================================================= @@ -51,8 +62,8 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, dd4hep::Volume motherVol = theDetector.pickMotherVolume(sdet); dd4hep::Material det_mat(theDetector.material("Air")); - - // - global + + // - global dd4hep::Tube det_solid(chamber_radius_min, chamber_radius_max, chamber_length*0.5); dd4hep::Volume det_vol(det_name+"_vol", det_solid, det_mat); @@ -60,39 +71,59 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, dd4hep::Tube det_inner_chamber_solid(inner_chamber_radius_min, inner_chamber_radius_max, inner_chamber_length*0.5); dd4hep::Volume det_inner_chamber_vol(det_name+"_inner_chamber_vol", det_inner_chamber_solid, det_mat); - dd4hep::Transform3D transform_inner_chamber(dd4hep::Rotation3D(), - dd4hep::Position(0,0,0)); - dd4hep::PlacedVolume det_inner_chamber_phy = det_vol.placeVolume(det_inner_chamber_vol, - transform_inner_chamber); - det_inner_chamber_phy.addPhysVolID("chamber", 0); - if ( x_det.isSensitive() ) { - dd4hep::SensitiveDetector sd = sens; - det_inner_chamber_vol.setSensitiveDetector(sens); - sd.setType("tracker"); - } - - - // - outer 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; + std::string layer_name; + dd4hep::Volume* current_vol_ptr = nullptr; + + if(layer_id<inner_chamber_layer_number){ + current_vol_ptr = &det_inner_chamber_vol; + rmin = inner_chamber_radius_min+(layer_id*chamber_layer_width); + rmax = rmin+chamber_layer_width; + layer_name = det_name+"_inner_chamber_vol"+_toString(layer_id,"_layer%d"); + }else{ + current_vol_ptr = &det_outer_chamber_vol; + rmin = outer_chamber_radius_min+((layer_id-inner_chamber_layer_number)*chamber_layer_width); + rmax = rmin+chamber_layer_width; + layer_name = det_name+"_outer_chamber_vol"+_toString(layer_id,"_layer%d"); + } + /// Construction of drift chamber layers + dd4hep::Tube layer_solid(rmin,rmax,chamber_length*0.5); + dd4hep::Volume layer_vol(layer_name,layer_solid,det_mat); + dd4hep::Transform3D transform_layer(dd4hep::Rotation3D(),dd4hep::Position(0.,0.,0.)); + dd4hep::PlacedVolume layer_phy = (*current_vol_ptr).placeVolume(layer_vol, transform_layer); + layer_phy.addPhysVolID("layer",layer_id); + + /// Set drift chamber layers to sensitive detector + dd4hep::SensitiveDetector sd = sens; + layer_vol.setSensitiveDetector(sens); + sd.setType("tracker"); + } + + // - place in det + // inner + dd4hep::Transform3D transform_inner_chamber(dd4hep::Rotation3D(), + dd4hep::Position(0,0,0)); + dd4hep::PlacedVolume det_inner_chamber_phy = det_vol.placeVolume(det_inner_chamber_vol, + transform_inner_chamber); + det_inner_chamber_phy.addPhysVolID("chamber", 0); + + // outer dd4hep::Transform3D transform_outer_chamber(dd4hep::Rotation3D(), - dd4hep::Position(0,0,0)); + dd4hep::Position(0,0,0)); dd4hep::PlacedVolume det_outer_chamber_phy = det_vol.placeVolume(det_outer_chamber_vol, - transform_outer_chamber); - - det_inner_chamber_phy.addPhysVolID("chamber", 1); - if ( x_det.isSensitive() ) { - dd4hep::SensitiveDetector sd = sens; - det_outer_chamber_vol.setSensitiveDetector(sens); - sd.setType("tracker"); - } - + transform_inner_chamber); + det_outer_chamber_phy.addPhysVolID("chamber", 1); // - place in world dd4hep::Transform3D transform(dd4hep::Rotation3D(), - dd4hep::Position(0,0,0)); + dd4hep::Position(0,0,0)); dd4hep::PlacedVolume phv = motherVol.placeVolume(det_vol,transform); 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>) +