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 Algorithm Migration DDPixBarLayerUpgrade #27587

Merged
merged 7 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<DDDefinition>
<debug>
<debug_shapes/>
<debug_includes/>
<debug_rotations/>
<debug_includes/>
<debug_volumes/>
<debug_constants/>
<!--debug_materials/-->
<debug_namespaces/>
<debug_placements/>
<debug_algorithms/>
</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="world_z" value="5*m"/>
<Constant name="fm" value="1e-12*m"/>
<Constant name="Air" value="materials:Air" type="string"/>
<Constant name="Vacuum" value="materials:Vacuum" type="string"/>
</ConstantsSection>

<IncludeSection>
<Include ref="DetectorDescription/DDCMS/data/testDDPixBarLayerUpgradeAlgorithm.xml"/>
<Include ref="DetectorDescription/DDCMS/data/materials.xml"/>
<Include ref="Geometry/TrackerCommonData/data/PhaseI/pixbarmaterial.xml"/>
<Include ref="Geometry/TrackerCommonData/data/PhaseI/pixbarladderfull0.xml"/>
<Include ref="Geometry/TrackerCommonData/data/PhaseI/pixbarladder.xml"/>
<Include ref="Geometry/TrackerCommonData/data/PhaseI/pixbarlayer0.xml"/>
<Include ref="Geometry/TrackerCommonData/data/PhaseI/pixbarlayer.xml"/>
</IncludeSection>

</DDDefinition>
@@ -0,0 +1,66 @@
<?xml version="1.0"?>
<!--
Modified version: Geometry/TrackerCommonData/data/PhaseI/pixbarlayer0.xml
-->
<DDDefinition>

<SolidSection>
<Box name="MotherOfAllBoxes" dx="10*m" dy="10*m" dz="10*m"/>
</SolidSection>
<LogicalPartSection>
<LogicalPart name="MotherOfAllBoxes">
<rMaterial name="materials:Air"/>
<rSolid name="MotherOfAllBoxes"/>
</LogicalPart>
</LogicalPartSection>

<ConstantsSection label="pixbarlayer0.xml" eval="true">
<Constant name="Ladders" value="12"/>
<Constant name="CoolDist" value="3.03*cm"/>
<Constant name="CoolRadius" value="0.0900*cm"/>
<Constant name="LadderOffset" value="0.220*cm"/>
<Constant name="Cool1Offset" value="0.83*cm"/>
<Constant name="Cool2Offset" value="-0.16*cm"/>
<Constant name="OuterFirst" value="1"/>
<Constant name="PitchFineTune" value="-0.917*deg"/>
<Constant name="OuterOffsetFineTune" value="-0.0467*cm+[pixbarladder:SensorThick]/2"/>
<Constant name="InnerOffsetFineTune" value="-0.0120*cm-[pixbarladder:SensorThick]/2"/>
</ConstantsSection>

<Algorithm name="track:DDPixBarLayerUpgradeAlgo">
<rParent name="pixbarlayer0:PixelBarrelLayer0"/>
<String name="GeneralMaterial" value="materials:Air"/>
<Numeric name="Ladders" value="[pixbarlayer0:Ladders]"/>
<Numeric name="LayerDz" value="[pixbarlayer:LayerDz]"/>
<Numeric name="CoolDz" value="[pixbarlayer:CoolDz]"/>
<Numeric name="CoolThick" value="[pixbarlayer:CoolThick]"/>
<Numeric name="CoolRadius" value="[pixbarlayer0:CoolRadius]"/>
<Numeric name="CoolDist" value="[pixbarlayer0:CoolDist]"/>
<Numeric name="Cool1Offset" value="[pixbarlayer0:Cool1Offset]"/>
<Numeric name="Cool2Offset" value="[pixbarlayer0:Cool2Offset]"/>
<String name="CoolMaterial" value="materials:Bpix_CO2_-20C"/>
<String name="CoolTubeMaterial" value="materials:Bpix_Pipe_Steel"/>
<String name="CoolMaterialHalf" value="pixbarmaterial:Bpix_CO2_-20C_Half"/>
<String name="CoolTubeMaterialHalf" value="pixbarmaterial:Bpix_Pipe_Steel_Half"/>
<String name="LadderName" value="pixbarladderfull0:PixelBarrelLadderFull0"/>
<Numeric name="LadderWidth" value="[pixbarladderfull0:LadderWidth]"/>
<Numeric name="LadderThick" value="[pixbarladderfull0:LadderThick]"/>
<Numeric name="LadderOffset" value="[pixbarlayer0:LadderOffset]"/>
<!-- Numeric name="ActiveWidth" value="[pixbarladderfull0:ActiveWidth]"/-->
<Numeric name="OuterFirst" value="[pixbarlayer0:OuterFirst]"/>
<Numeric name="PitchFineTune" value="[pixbarlayer0:PitchFineTune]"/>
<Numeric name="OuterOffsetFineTune" value="[pixbarlayer0:OuterOffsetFineTune]"/>
<Numeric name="InnerOffsetFineTune" value="[pixbarlayer0:InnerOffsetFineTune]"/>
</Algorithm>

<PosPartSection label="">
<PosPart copyNumber="2">
<rParent name=":world_volume"/>
<rChild name="MotherOfAllBoxes"/>
</PosPart>
<PosPart copyNumber="1">
<rParent name="MotherOfAllBoxes"/>
<rChild name="testDDPixBarLayerUpgradeAlgorithm:PixelBarrelLayer0"/>
</PosPart>
</PosPartSection>
</DDDefinition>
206 changes: 206 additions & 0 deletions DetectorDescription/DDCMS/plugins/DDPixBarLayerUpgradeAlgo.cc
@@ -0,0 +1,206 @@
#include "DD4hep/DetFactoryHelper.h"
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

using namespace geant_units::operators;

static long algorithm(dd4hep::Detector&, cms::DDParsingContext& ctxt, xml_h e, dd4hep::SensitiveDetector&) {
cms::DDNamespace ns(ctxt, e, true);
cms::DDAlgoArguments args(ctxt, e);
std::string parentName = args.parentName();

std::string genMat = args.value<std::string>("GeneralMaterial");
int number = args.value<int>("Ladders");
double layerDz = args.value<double>("LayerDz");
double coolDz = args.value<double>("CoolDz");
double coolThick = args.value<double>("CoolThick");
double coolRadius = args.value<double>("CoolRadius");
double coolDist = args.value<double>("CoolDist");
double cool1Offset = args.value<double>("Cool1Offset");
double cool2Offset = args.value<double>("Cool2Offset");
std::string coolMat = args.value<std::string>("CoolMaterial");
std::string tubeMat = args.value<std::string>("CoolTubeMaterial");
std::string coolMatHalf = args.value<std::string>("CoolMaterialHalf");
std::string tubeMatHalf = args.value<std::string>("CoolTubeMaterial");
double phiFineTune = args.value<double>("PitchFineTune");
double rOuterFineTune = args.value<double>("OuterOffsetFineTune");
double rInnerFineTune = args.value<double>("InnerOffsetFineTune");

// FixMe : Would need ns.vecStr
std::string ladder = args.value<std::string>("LadderName");

double ladderWidth = args.value<double>("LadderWidth");
double ladderThick = args.value<double>("LadderThick");
double ladderOffset = args.value<double>("LadderOffset");
int outerFirst = args.value<int>("OuterFirst");

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo debug: Parent " << parentName << " NameSpace "
<< ns.objName(parentName) << "\n\tLadders " << number << "\tGeneral Material " << genMat
<< "\tLength " << layerDz << "\tSpecification of Cooling Pieces:\n"
<< "\tLength " << coolDz << "\tThickness of Shell " << coolThick << "\tRadial distance "
<< coolDist << "\tMaterials " << coolMat << ", " << tubeMat << std::endl;

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo debug: Full Ladder " << ladder << " width/thickness "
<< ladderWidth << ", " << ladderThick;

double dphi = 2_pi / (double)number;
double x2 = coolDist * sin(0.5 * dphi);
double rtmi = coolDist * cos(0.5 * dphi) - (coolRadius + ladderThick) + rInnerFineTune;
double rmxh = coolDist * cos(0.5 * dphi) + (coolRadius + ladderThick + ladderOffset) + rOuterFineTune;
double rtmx = sqrt(rmxh * rmxh + ladderWidth * ladderWidth / 4.);

std::string name = ns.objName(parentName);

dd4hep::Solid solid = ns.addSolid(name, dd4hep::Tube(rtmi, rtmx, 0.5 * layerDz, 0., 2._pi));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << ns.name() << " Tubs made of " << genMat
<< " from 0. to " << convertRadToDeg(2_pi) << " with Rin " << rtmi << " Rout " << rtmx
<< " ZHalf " << 0.5 * layerDz;

dd4hep::Volume layer = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(genMat)));

// Full Tubes
solid = ns.addSolid(name + "CoolTube", dd4hep::Tube(0., coolRadius, 0.5 * coolDz, 0., 2_pi));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMat
<< " from 0 to " << convertRadToDeg(2_pi) << " with Rout " << coolRadius << " ZHalf "
<< 0.5 * coolDz;

dd4hep::Volume coolTube = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(tubeMat)));

// Half Tubes
solid = ns.addSolid(name + "CoolTubeHalf", dd4hep::Tube(0., coolRadius, 0.5 * coolDz, 0, 1_pi));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMatHalf
<< " from 0 to " << convertRadToDeg(2_pi) << " with Rout " << coolRadius << " ZHalf "
<< 0.5 * coolDz;

dd4hep::Volume coolTubeHalf = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(tubeMatHalf)));

// Full Coolant
name = ns.objName(parentName);

solid = ns.addSolid(name + "Coolant", dd4hep::Tube(0., coolRadius - coolThick, 0.5 * coolDz, 0., 2_pi));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMat
<< " from 0 to " << convertRadToDeg(2._pi) << " with Rout " << coolRadius - coolThick
<< " ZHalf " << 0.5 * coolDz;

dd4hep::Volume cool = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(coolMat)));

coolTube.placeVolume(cool, 1, dd4hep::Transform3D(dd4hep::Rotation3D(), dd4hep::Position(0., 0., 0.)));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << cool.name() << " number 1 positioned in "
<< coolTube.name() << " at (0,0,0) with no rotation";

// Half Coolant

solid = ns.addSolid(name + "CoolantHalf", dd4hep::Tube(0., coolRadius - coolThick, 0.5 * coolDz, 0., 1._pi));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMatHalf
<< " from 0 to " << convertRadToDeg(2._pi) << " with Rout " << coolRadius - coolThick
<< " ZHalf " << 0.5 * coolDz;

dd4hep::Volume coolHalf = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(coolMatHalf)));

coolTubeHalf.placeVolume(coolHalf, 1, dd4hep::Transform3D(dd4hep::Rotation3D(), dd4hep::Position(0., 0., 0.)));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << cool.name() << " number 1 positioned in "
<< coolTube.name() << " at (0,0,0) with no rotation";
int copy = 1, iup = (-1) * outerFirst;
int copyoffset = number + 2;

for (int i = 1; i < number + 1; i++) {
double phi = i * dphi + 90._deg - 0.5 * dphi + phiFineTune; //to start with the interface ladder
double phix, phiy, rrr, rrroffset;
std::string rots;

auto tran = dd4hep::Position();
auto rot = dd4hep::Rotation3D();

iup = -iup;

double dr;

if ((i == 1) || (i == number / 2 + 1)) {
dr = coolRadius + 0.5 * ladderThick + ladderOffset; //interface ladder offset
} else {
dr = coolRadius + 0.5 * ladderThick;
}

if (i % 2 == 1) {
rrr = coolDist * cos(0.5 * dphi) + iup * dr + rOuterFineTune;
} else {
rrr = coolDist * cos(0.5 * dphi) + iup * dr + rInnerFineTune;
}

tran = dd4hep::Position(rrr * cos(phi), rrr * sin(phi), 0);
rots = name + std::to_string(copy);

if (iup > 0) {
phix = phi - 90._deg;
} else {
phix = phi + 90._deg;
}

phiy = phix + 90._deg;

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: Creating a new "
<< "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
<< convertRadToDeg(phiy) << ", 0, 0";

rot = cms::makeRotation3D(90._deg, phix, 90._deg, phiy, 0., 0.);

// FixMe : Would need ns.vecStr
layer.placeVolume(ns.volume(ladder), copy, dd4hep::Transform3D(rot, tran));

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << ladder << " number " << copy << " positioned in "
<< layer.name() << " at " << tran << " with " << rot;

copy++;

rrr = coolDist * cos(0.5 * dphi) + coolRadius / 2.;

rots = name + std::to_string(i + 100);
phix = phi + 90._deg;

if (iup < 0)
phix += dphi;

phiy = phix + 90._deg;

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: Creating a new "
<< "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
<< convertRadToDeg(phiy) << ", 0, 0";

tran = dd4hep::Position(rrr * cos(phi) - x2 * sin(phi), rrr * sin(phi) + x2 * cos(phi), 0.);

rot = cms::makeRotation3D(90._deg, phix, 90._deg, phiy, 0., 0.);

layer.placeVolume(coolTubeHalf, i + 1, dd4hep::Transform3D(rot, tran));

if ((i == 1) || (i == number / 2 + 1)) {
rrroffset = coolDist * cos(0.5 * dphi) + iup * ladderOffset + rOuterFineTune;
tran = dd4hep::Position(
rrroffset * cos(phi) - cool1Offset * sin(phi), rrroffset * sin(phi) + cool1Offset * cos(phi), 0.);

layer.placeVolume(coolTube, copyoffset, dd4hep::Transform3D(dd4hep::Rotation3D(), tran));
;

copyoffset++;
tran = dd4hep::Position(
rrroffset * cos(phi) - cool2Offset * sin(phi), rrroffset * sin(phi) + cool2Offset * cos(phi), 0.);

layer.placeVolume(coolTube, copyoffset, dd4hep::Transform3D(dd4hep::Rotation3D(), tran));
copyoffset++;
}

LogDebug("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << coolTube.name() << " number " << i + 1
<< " positioned in " << layer.name() << " at " << tran << " with " << rot;
}

return cms::s_executed;
}

DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixBarLayerUpgradeAlgo, algorithm);
@@ -0,0 +1,53 @@
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', 'testDDPixBarLayerUpgradeAlgo'),
categories = cms.untracked.vstring('PixelGeom'),
cout = cms.untracked.PSet(
threshold = cms.untracked.string('WARNING'),
noLineBreaks = cms.untracked.bool(True)
),

testDDPixBarLayerUpgradeAlgo = cms.untracked.PSet(
INFO = cms.untracked.PSet(
limit = cms.untracked.int32(0)
),
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('DEBUG'),
PixelGeom = cms.untracked.PSet(
limit = cms.untracked.int32(0)
)
),

destinations = cms.untracked.vstring('cout',
'testDDPixBarLayerUpgradeAlgo')
)


process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath(
'DetectorDescription/DDCMS/data/cms-test-pixbarlayerupgrade-algorithm.xml'
),
appendToDataLabel = cms.string('testPixBarLayerUpgradeAlgo')
)

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

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