From 45d6b32886379383a46dd208a6c20e780848ecad Mon Sep 17 00:00:00 2001 From: Andres Vargas Date: Tue, 30 Jul 2019 09:20:47 +0200 Subject: [PATCH] DD4hep Tracker DDPixPhase1FwdDiskAlgo Migration && test Geometry/TrackerCommonData/plugins/DDPixPhase1FwdDiskAlgo.cc --- .../data/cms-test-ddpixphase1fwddisk-algo.xml | 33 +++++ .../DDCMS/data/testDDPixPhase1FwdDiskAlgo.xml | 66 ++++++++++ .../DDCMS/plugins/DDPixPhase1FwdDiskAlgo.cc | 121 ++++++++++++++++++ .../python/testDDPixPhase1FwdDiskAlgorithm.py | 48 +++++++ 4 files changed, 268 insertions(+) create mode 100644 DetectorDescription/DDCMS/data/cms-test-ddpixphase1fwddisk-algo.xml create mode 100644 DetectorDescription/DDCMS/data/testDDPixPhase1FwdDiskAlgo.xml create mode 100644 DetectorDescription/DDCMS/plugins/DDPixPhase1FwdDiskAlgo.cc create mode 100644 DetectorDescription/DDCMS/test/python/testDDPixPhase1FwdDiskAlgorithm.py diff --git a/DetectorDescription/DDCMS/data/cms-test-ddpixphase1fwddisk-algo.xml b/DetectorDescription/DDCMS/data/cms-test-ddpixphase1fwddisk-algo.xml new file mode 100644 index 0000000000000..258333ce410f6 --- /dev/null +++ b/DetectorDescription/DDCMS/data/cms-test-ddpixphase1fwddisk-algo.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DetectorDescription/DDCMS/data/testDDPixPhase1FwdDiskAlgo.xml b/DetectorDescription/DDCMS/data/testDDPixPhase1FwdDiskAlgo.xml new file mode 100644 index 0000000000000..b251a9068a05d --- /dev/null +++ b/DetectorDescription/DDCMS/data/testDDPixPhase1FwdDiskAlgo.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 7.12*mm, 2.62*mm, -1.88*mm, -6.38*mm, -10.88*mm, + 11.62*mm, 7.12*mm, 2.62*mm, -1.88*mm, -6.38*mm, -10.88*mm, + 7.12*mm, 2.62*mm, -1.88*mm, -6.38*mm, -10.88*mm, + 11.62*mm, 7.12*mm, 2.62*mm, -1.88*mm, -6.38*mm, -10.88*mm + + + + + + + + + + + + + + + + + + + diff --git a/DetectorDescription/DDCMS/plugins/DDPixPhase1FwdDiskAlgo.cc b/DetectorDescription/DDCMS/plugins/DDPixPhase1FwdDiskAlgo.cc new file mode 100644 index 0000000000000..81de5df0c3b1d --- /dev/null +++ b/DetectorDescription/DDCMS/plugins/DDPixPhase1FwdDiskAlgo.cc @@ -0,0 +1,121 @@ +/////////////////////////////////////////////////////////////////////////////// +// File: DDPixPhase1FwdDiskAlgo.cc +// Description: Position n copies at given z-values +/////////////////////////////////////////////////////////////////////////////// +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "DetectorDescription/DDCMS/interface/DDPlugins.h" +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/Printout.h" + +#include "DataFormats/Math/interface/GeantUnits.h" + +#include + +using namespace geant_units::operators; // _deg and convertRadToDeg + +static long algorithm(dd4hep::Detector& /* description */, + cms::DDParsingContext& ctxt, + xml_h e, + dd4hep::SensitiveDetector& /* sens */) { + cms::DDNamespace ns(ctxt, e, true); + cms::DDAlgoArguments args(ctxt, e); + + int nBlades; //Number of blades + int startCopyNo; //Start Copy number + double bladeAngle; //Angle of blade rotation aroung y-axis + double bladeTilt; //Tilt of the blade around x-axis + double zPlane; //Common shift in z for all blades + std::vector bladeZShift; //Shift in Z of individual blades + double anchorR; //Distance of beam line to anchor point + + std::string childName; //Child name + std::string rotName; //Name of the base rotation matrix + std::string flagString; //Flag if a blade is present + + dd4hep::Volume mother = ns.volume(args.parentName()); + dd4hep::PlacedVolume pv; + + startCopyNo = args.find("startCopyNo") ? args.value("StartCopyNo") : 1; + nBlades = args.value("NumberOfBlades"); + bladeAngle = args.value("BladeAngle"); + bladeTilt = args.value("BladeTilt"); + zPlane = args.value("BladeCommonZ"); + anchorR = args.value("AnchorRadius"); + + bladeZShift = args.value >("BladeZShift"); + + childName = args.value("ChildName"); + rotName = args.value("RotationName"); + flagString = args.value("FlagString"); + + dd4hep::Volume child = ns.volume(childName); + + edm::LogVerbatim("TrackerGeom") << "DDPixFwdDiskAlgo debug: Parent " << mother.name() << "\tChild " << child.name() + << " NameSpace " << ns.name() << "\tRot Name " << rotName << "\tCopyNo (Start/Total) " + << startCopyNo << ", " << nBlades << "\tAngles " << convertRadToDeg(bladeAngle) + << ", " << convertRadToDeg(bladeTilt) << "\tZshifts " << zPlane << "\tAnchor Radius " + << anchorR; + + for (int iBlade = 0; iBlade < nBlades; ++iBlade) { + edm::LogVerbatim("TrackerGeom") << "DDPixFwdDiskAlgo: Blade " << iBlade << " flag " << flagString[iBlade] + << " zshift " << bladeZShift[iBlade]; + } + + double deltaPhi = 360.0_deg / (double)nBlades; + int copyNo = startCopyNo; + std::string flagSelector = "Y"; + + for (int iBlade = 0; iBlade < nBlades; ++iBlade) { + if (flagString[iBlade] == flagSelector[0]) { + std::string rotstr = rotName[0] + std::to_string(double(copyNo)); + double phi = (iBlade + 0.5) * deltaPhi; + double phiy = atan2(cos(phi), -sin(phi)); + double thety = acos(sin(bladeTilt)); + double phix = atan2(cos(bladeAngle) * sin(phi) + cos(phi) * sin(bladeTilt) * sin(bladeAngle), + cos(phi) * cos(bladeAngle) - sin(phi) * sin(bladeTilt) * sin(bladeAngle)); + double thetx = acos(-cos(bladeTilt) * sin(bladeAngle)); + double phiz = atan2(sin(phi) * sin(bladeAngle) - cos(phi) * cos(bladeAngle) * sin(bladeTilt), + cos(phi) * sin(bladeAngle) + cos(bladeAngle) * sin(phi) * sin(bladeTilt)); + double thetz = acos(cos(bladeTilt) * cos(bladeAngle)); + + auto rot = dd4hep::Rotation3D(); + + auto irot = ctxt.rotations.find(ns.prepend(rotstr)); + + if (irot != ctxt.rotations.end()) { + edm::LogVerbatim("TrackerGeom") << "DDPixPhase1FwdDiskAlgo test: Creating a new " + << "rotation: " << rotstr << "\t" << convertRadToDeg(thetx) << ", " + << convertRadToDeg(phix) << ", " << convertRadToDeg(thety) << ", " + << convertRadToDeg(phiy) << ", " << convertRadToDeg(thetz) << ", " + << convertRadToDeg(phiz); + + edm::LogVerbatim("TrackerGeom") << "Rotation Matrix (" << convertRadToDeg(phi) << ", " + << convertRadToDeg(bladeAngle) << ", " << convertRadToDeg(bladeTilt) << ") " + << cos(phi) * cos(bladeAngle) << ", " + << (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)) + << ", " + << (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)) + << ", " << sin(phi) * cos(bladeAngle) << ", " + << (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)) + << ", " + << (-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)) + << ", " << -sin(bladeAngle) << ", " << cos(bladeAngle) * sin(bladeTilt) << ", " + << cos(bladeAngle) * cos(bladeTilt); + rot = cms::makeRotation3D(thetx, phix, thety, phiy, thetz, phiz); + } + double xpos = -anchorR * sin(phi); + double ypos = anchorR * cos(phi); + double zpos = zPlane + bladeZShift[iBlade % nBlades]; + + dd4hep::Position tran(xpos, ypos, zpos); + pv = mother.placeVolume(child, copyNo, dd4hep::Transform3D(rot, tran)); + edm::LogVerbatim("TrackerGeom") << "DDPixFwdDiskAlgo test: " << pv.name() << ": " << childName << " number " + << copyNo << " positioned in " << mother.name() << " at " << tran << " with " + << rot; + } + copyNo++; + } + return cms::s_executed; +} + +DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixPhase1FwdDiskAlgo, algorithm) diff --git a/DetectorDescription/DDCMS/test/python/testDDPixPhase1FwdDiskAlgorithm.py b/DetectorDescription/DDCMS/test/python/testDDPixPhase1FwdDiskAlgorithm.py new file mode 100644 index 0000000000000..e51907c14b46c --- /dev/null +++ b/DetectorDescription/DDCMS/test/python/testDDPixPhase1FwdDiskAlgorithm.py @@ -0,0 +1,48 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("DDCMSDetectorTest") + +process.source = cms.Source("EmptySource") +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) ) + +process.MessageLogger = cms.Service( + "MessageLogger", + statistics = cms.untracked.vstring('cout', 'testDDPixPhase1FwdDiskAlgo'), + categories = cms.untracked.vstring('TrackerGeom'), + cout = cms.untracked.PSet( + threshold = cms.untracked.string('WARNING'), + noLineBreaks = cms.untracked.bool(True) + ), + testDDPixPhase1FwdDiskAlgo = cms.untracked.PSet( + INFO = cms.untracked.PSet( + limit = cms.untracked.int32(0) + ), + noLineBreaks = cms.untracked.bool(True), + DEBUG = cms.untracked.PSet( + limit = cms.untracked.int32(0) + ), + WARNING = cms.untracked.PSet( + limit = cms.untracked.int32(0) + ), + ERROR = cms.untracked.PSet( + limit = cms.untracked.int32(0) + ), + threshold = cms.untracked.string('INFO'), + TrackerGeom = cms.untracked.PSet( + limit = cms.untracked.int32(-1) + ) + ), + destinations = cms.untracked.vstring('cout', + 'testDDPixPhase1FwdDiskAlgo') +) + +process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer", + confGeomXMLFiles = cms.FileInPath('DetectorDescription/DDCMS/data/cms-test-ddpixphase1fwddisk-algo.xml'), + appendToDataLabel = cms.string('testDDPixPhase1FwdDiskAlgo') +) + +process.testDump = cms.EDAnalyzer("DDTestDumpFile", + DDDetector = cms.ESInputTag('','testDDPixPhase1FwdDiskAlgo') +) + +process.p = cms.Path(process.testDump)