Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DD4Hep: Tracker DDPixFwdDisk Algorithm #27627

Merged
merged 13 commits into from Jul 31, 2019
33 changes: 33 additions & 0 deletions DetectorDescription/DDCMS/data/cms-test-ddpixfwddisk-algo.xml
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<DDDefinition>
<debug>
<debug_shapes/>
<debug_includes/>
<debug_rotations/>
<debug_volumes/>
<debug_materials/>
<debug_constants/>
<debug_namespaces/>
<debug_placements/>
<debug_algorithms/>
<debug_specpars/>
</debug>
<open_geometry/>
<close_geometry/>

<ConstantsSection label="" eval="true">
<Constant name="world_x" value="5*m"/>
<Constant name="world_y" value="5*m"/>
<Constant name="fm" value="1e-12*m"/>
<Constant name="world_z" value="5*m"/>
<Constant name="Air" value="materials:Air" type="string"/>
<Constant name="Vacuum" value="materials:Vacuum" type="string"/>
</ConstantsSection>

<IncludeSection>
<Include ref="DetectorDescription/DDCMS/data/testDDPixFwdDiskAlgo.xml"/>
<Include ref="Geometry/TrackerCommonData/data/PhaseI/PixelForward/pixfwdDisks.xml"/>
<Include ref="DetectorDescription/DDCMS/data/materials.xml"/>
</IncludeSection>

</DDDefinition>
66 changes: 66 additions & 0 deletions DetectorDescription/DDCMS/data/testDDPixFwdDiskAlgo.xml
@@ -0,0 +1,66 @@
<?xml version="1.0"?>
<DDDefinition>

<SolidSection>
<Box name="MotherOfAllBoxes" dx="10*m" dy="10*m" dz="10*m"/>
<Box name="ChildVolume" dx="10*m" dy="10*m" dz="10*m"/>
</SolidSection>

<LogicalPartSection>
<LogicalPart name="MotherOfAllBoxes">
<rMaterial name="materials:Air"/>
<rSolid name="MotherOfAllBoxes"/>
</LogicalPart>
<LogicalPart name="ChildVolume">
<rMaterial name="materials:Air"/>
<rSolid name="ChildVolume"/>
</LogicalPart>
</LogicalPartSection>

<ConstantsSection label="pixfwdInnerDisk1.xml" eval="true">
<Constant name="InnerRingRMin" value="37.5*mm"/>
<Constant name="InnerRingRMax" value="[InnerRingRMin]+2.0*mm"/>
<Constant name="InnerRingCFRMin" value="[InnerRingRMax]"/>
<Constant name="InnerRingCFRMax" value="[InnerRingCFRMin]+0.5*mm"/>
<Constant name="InnerRingHalfWidth" value="15.0*mm"/>
<Constant name="InnerRingZ" value="[pixfwdDisks:DiskHalfWidth]-[InnerRingHalfWidth]"/>
<Constant name="OuterRingRMax" value="116.6*mm"/>
<Constant name="OuterRingRMin" value="[OuterRingRMax]-2.00*mm"/>
<Constant name="OuterRingCFRMax" value="[OuterRingRMin]"/>
<Constant name="OuterRingCFRMin" value="[OuterRingCFRMax]-0.5*mm"/>
<Constant name="OuterRingHalfWidth" value="14*mm"/>
<Constant name="OuterRingZ" value="[pixfwdDisks:DiskHalfWidth]-[OuterRingHalfWidth]"/>
</ConstantsSection>

<Algorithm name="track:DDPixFwdDiskAlgo">
<rParent name="testDDPixFwdDiskAlgo:MotherOfAllBoxes"/>
<String name="ChildName" value="testDDPixFwdDiskAlgo:ChildVolume"/>
<Numeric name="StartCopyNo" value="0"/>
<Numeric name="NumberOfBlades" value="22"/>
<Numeric name="BladeAngle" value="20*deg"/>
<Numeric name="BladeTilt" value="12*deg"/>
<Numeric name="BladeCommonZ" value="-18.7*mm"/>
<Vector name="BladeZShift" type="numeric" nEntries="22">
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
</Vector>

<Numeric name="AnchorRadius" value="78.7*mm"/>
<String name="RotationName" value="pixfwdInnerDisk1:PixInner"/>
<String name="FlagString" value="YYYYYYYYYYYYYYYYYYYYYY"/>
</Algorithm>

<PosPartSection label="">
<PosPart copyNumber="2">
<rParent name=":world_volume"/>
<rChild name="MotherOfAllBoxes"/>
</PosPart>
<PosPart copyNumber="100">
<rParent name="MotherOfAllBoxes"/>
<rChild name="testDDPixFwdDiskAlgo:ChildVolume"/>
</PosPart>
</PosPartSection>

</DDDefinition>
129 changes: 129 additions & 0 deletions DetectorDescription/DDCMS/plugins/DDPixFwdDiskAlgo.cc
@@ -0,0 +1,129 @@
///////////////////////////////////////////////////////////////////////////////
// File: DDPixFwdDiskAlgo.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 <sstream>

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<double> 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<int>("StartCopyNo") : 1;
nBlades = args.value<int>("NumberOfBlades");
bladeAngle = args.value<double>("BladeAngle");
bladeTilt = args.value<double>("BladeTilt");
zPlane = args.value<double>("BladeCommonZ");
anchorR = args.value<double>("AnchorRadius");

bladeZShift = args.value<std::vector<double> >("BladeZShift");

childName = args.value<std::string>("ChildName");
rotName = args.value<std::string>("RotationName");
flagString = args.value<std::string>("FlagString");

if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr)
childName = ns.name() + childName;

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 phix = atan2(sin(phi) * cos(bladeAngle), cos(phi) * cos(bladeAngle));
double thetx = acos(-sin(bladeAngle));
double phiy = atan2((cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)),
(-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)));

double thety = acos(cos(bladeAngle) * sin(bladeTilt));
double phiz = atan2((-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)),
(sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)));

double thetz = acos(cos(bladeAngle) * cos(bladeTilt));

auto rot = dd4hep::Rotation3D();

auto irot = ctxt.rotations.find(ns.prepend(rotstr));

if (irot != ctxt.rotations.end()) {
edm::LogVerbatim("TrackerGeom") << "DDPixFwdDiskAlgo 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) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt));
double ypos = anchorR * (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt));
double zpos = anchorR * (cos(bladeAngle) * sin(bladeTilt)) + zPlane + bladeZShift[iBlade];

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++;
}

edm::LogVerbatim("TrackerGeom") << "Finished....";
return cms::s_executed;
}

DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixFwdDiskAlgo, algorithm)
48 changes: 48 additions & 0 deletions DetectorDescription/DDCMS/test/python/testDDPixFwdDiskAlgo.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', 'testDDPixFwdDiskAlgo'),
categories = cms.untracked.vstring('PixFwdGeom'),
cout = cms.untracked.PSet(
threshold = cms.untracked.string('WARNING'),
noLineBreaks = cms.untracked.bool(True)
),
testDDPixFwdDiskAlgo = 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'),
PixFwdGeom = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
)
),
destinations = cms.untracked.vstring('cout',
'testDDPixFwdDiskAlgo')
)

process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath('DetectorDescription/DDCMS/data/cms-test-ddpixfwddisk-algo.xml'),
appendToDataLabel = cms.string('testDDPixFwdDiskAlgo')
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('','testDDPixFwdDiskAlgo')
)

process.p = cms.Path(process.testDump)