Skip to content

Commit

Permalink
Merge pull request #26386 from ianna/dd4hep-mdt-geometry-v1
Browse files Browse the repository at this point in the history
DD4hep: add an algorithm needed to build MTD geometry
  • Loading branch information
cmsbuild committed Apr 10, 2019
2 parents 8447308 + 8e6f64b commit efc8045
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 3 deletions.
2 changes: 2 additions & 0 deletions DetectorDescription/DDCMS/interface/DDAlgoArguments.h
Expand Up @@ -14,6 +14,8 @@ namespace cms
{
using DD3Vector = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;

static constexpr long s_executed = 1l;

constexpr unsigned int hash( const char* str, int h = 0 )
{
return !str[h] ? 5381 : ( hash( str, h+1 )*33 ) ^ str[h];
Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/plugins/DDDefinitions2Objects.cc
Expand Up @@ -1236,7 +1236,7 @@ template <> void Converter<DDLAlgorithm>::operator()(xml_h element) const {
"DD4CMS","+++ Start executing algorithm %s....", type.c_str());

long ret = PluginService::Create<long>(type, &description, ns.context(), &element, &sd);
if(ret == 1) {
if(ret == s_executed) {
printout(ns.context()->debug_algorithms ? ALWAYS : DEBUG,
"DD4CMS", "+++ Executed algorithm: %08lX = %s", ret, name.c_str());
return;
Expand Down
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/plugins/DDPixBarLayerAlgo.cc
Expand Up @@ -118,7 +118,7 @@ static long algorithm(Detector& description, cms::DDParsingContext& ctxt, xml_h
<< "rotation: " << rots << "\t90., "
<< convertRadToDeg( phix ) << ", 90.," << convertRadToDeg( phiy )
<< ", 0, 0";
rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0.,0.);
rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);

//cpv.position(ladderHalf, layer, copy, tran, rot);
pv = layer.placeVolume(ladderHalfVol, copy, Transform3D(rot,tran));
Expand Down
58 changes: 58 additions & 0 deletions Geometry/EcalAlgo/test/python/testEcalGeometry.py
@@ -0,0 +1,58 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("EcalGeometryTest")

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', 'ecalGeometry'),
categories = cms.untracked.vstring('Geometry'),
cout = cms.untracked.PSet(
threshold = cms.untracked.string('WARNING'),
noLineBreaks = cms.untracked.bool(True)
),
ecalGeometry = 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'),
Geometry = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
)
),
destinations = cms.untracked.vstring('cout',
'ecalGeometry')
)

process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath('Geometry/EcalCommonData/data/dd4hep/cms-ecal-geometry.xml'),
appendToDataLabel = cms.string('Ecal')
)

process.DDSpecParRegistryESProducer = cms.ESProducer("DDSpecParRegistryESProducer",
appendToDataLabel = cms.string('Ecal')
)

process.DDVectorRegistryESProducer = cms.ESProducer("DDVectorRegistryESProducer",
appendToDataLabel = cms.string('Ecal')
)

process.test = cms.EDAnalyzer("DDCMSDetector",
DDDetector = cms.ESInputTag('Ecal')
)

process.p = cms.Path(process.test)
69 changes: 69 additions & 0 deletions Geometry/EcalCommonData/data/dd4hep/cms-ecal-geometry.xml
@@ -0,0 +1,69 @@
<?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_materials/>
<debug_visattr/>
<debug_specpars/>
</debug>

<open_geometry/>
<close_geometry/>

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

<IncludeSection>
<Include ref='Geometry/CMSCommonData/data/materials.xml'/>
<Include ref='Geometry/CMSCommonData/data/rotations.xml'/>
<Include ref='Geometry/CMSCommonData/data/extend/v2/cmsextent.xml'/>
<Include ref='Geometry/CMSCommonData/data/cms/2023/v2/cms.xml'/>
<Include ref='Geometry/CMSCommonData/data/eta3/etaMax.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsMother.xml'/>
<Include ref='Geometry/CMSCommonData/data/caloBase/2023/v1/caloBase.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsCalo.xml'/>
<Include ref='Geometry/CMSCommonData/data/muonBase/2023/v2/muonBase.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsMuon.xml'/>
<Include ref='Geometry/CMSCommonData/data/mgnt.xml'/>
<Include ref='Geometry/CMSCommonData/data/beampipe/2023/v1/beampipe.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsBeam/2023/v1/cmsBeam.xml'/>
<Include ref='Geometry/CMSCommonData/data/muonMB.xml'/>
<Include ref='Geometry/CMSCommonData/data/muonMagnet.xml'/>
<Include ref='Geometry/CMSCommonData/data/cavern/2017/v2/cavern.xml'/>
<Include ref='Geometry/CMSCommonData/data/cavernData/2017/v1/cavernData.xml'/>
<Include ref='Geometry/CMSCommonData/data/cavernFloor/2017/v1/cavernFloor.xml'/>
<Include ref='Geometry/CMSCommonData/data/caloBase/2023/v2/caloBase.xml'/>
<Include ref='Geometry/EcalCommonData/data/ectkcable.xml'/>
<Include ref='Geometry/EcalCommonData/data/PhaseII/eregalgo.xml'/>
<Include ref='Geometry/EcalCommonData/data/ebalgo.xml'/>
<Include ref='Geometry/EcalCommonData/data/ebcon.xml'/>
<Include ref='Geometry/EcalCommonData/data/ebrot.xml'/>
<Include ref='Geometry/EcalCommonData/data/eecon.xml'/>
<Include ref='Geometry/EcalCommonData/data/PhaseII/escon.xml'/>
<Include ref='Geometry/EcalCommonData/data/PhaseII/esalgo.xml'/>
<Include ref='Geometry/TrackerCommonData/data/trackermaterial.xml'/>
</IncludeSection>

<PosPartSection label="">
<PosPart copyNumber="1">
<rParent name=":world_volume"/>
<rChild name="cms:OCMS"/>
</PosPart>
</PosPartSection>
</DDDefinition>
6 changes: 5 additions & 1 deletion Geometry/MTDGeometryBuilder/test/python/testMTDGeometry.py
Expand Up @@ -55,4 +55,8 @@
DDDetector = cms.ESInputTag('MTD')
)

process.p = cms.Path(process.test)
process.dump = cms.EDAnalyzer("DDTestDumpFile",
DDDetector = cms.ESInputTag('MTD')
)

process.p = cms.Path(process.test+process.dump)
72 changes: 72 additions & 0 deletions Geometry/TrackerCommonData/data/dd4hep/cms-tracker-geometry.xml
@@ -0,0 +1,72 @@
<?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_materials/>
<debug_visattr/>
<debug_specpars/>
</debug>

<open_geometry/>
<close_geometry/>

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

<IncludeSection>
<Include ref='Geometry/CMSCommonData/data/materials.xml'/>
<Include ref='Geometry/CMSCommonData/data/rotations.xml'/>
<Include ref='Geometry/CMSCommonData/data/extend/v2/cmsextent.xml'/>
<Include ref='Geometry/CMSCommonData/data/cms/2023/v2/cms.xml'/>
<Include ref='Geometry/CMSCommonData/data/eta3/etaMax.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsMother.xml'/>
<Include ref='Geometry/CMSCommonData/data/caloBase/2023/v1/caloBase.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsCalo.xml'/>
<Include ref='Geometry/CMSCommonData/data/muonBase/2023/v2/muonBase.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsMuon.xml'/>
<Include ref='Geometry/CMSCommonData/data/mgnt.xml'/>
<Include ref='Geometry/CMSCommonData/data/beampipe/2023/v1/beampipe.xml'/>
<Include ref='Geometry/CMSCommonData/data/cmsBeam/2023/v1/cmsBeam.xml'/>
<Include ref='Geometry/CMSCommonData/data/muonMB.xml'/>
<Include ref='Geometry/CMSCommonData/data/muonMagnet.xml'/>
<Include ref='Geometry/CMSCommonData/data/cavern/2017/v2/cavern.xml'/>
<Include ref='Geometry/CMSCommonData/data/cavernData/2017/v1/cavernData.xml'/>
<Include ref='Geometry/CMSCommonData/data/cavernFloor/2017/v1/cavernFloor.xml'/>
<Include ref='Geometry/CMSCommonData/data/caloBase/2023/v2/caloBase.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml'/>
<Include ref='Geometry/TrackerCommonData/data/pixfwdCommon.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker613/pixfwd.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker404/pixbar.xml'/>
<Include ref='Geometry/TrackerCommonData/data/trackermaterial.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker404/otst.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker613/tracker.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker613/pixel.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker404/trackerbar.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker404/trackerfwd.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker404/trackerStructureTopology.xml'/>
<Include ref='Geometry/TrackerCommonData/data/PhaseII/TiltedTracker613/pixelStructureTopology.xml'/>
</IncludeSection>

<PosPartSection label="">
<PosPart copyNumber="1">
<rParent name=":world_volume"/>
<rChild name="cms:OCMS"/>
</PosPart>
</PosPartSection>
</DDDefinition>
8 changes: 8 additions & 0 deletions Geometry/TrackerCommonData/plugins/BuildFile.xml
Expand Up @@ -3,3 +3,11 @@
<use name="FWCore/PluginManager"/>
<flags EDM_PLUGIN="1"/>
</library>

<library name="DD4hep_TrackerGeometryPlugins" file="dd4hep/*.cc">
<use name="DetectorDescription/DDCMS"/>
<use name="dd4hep"/>
<lib name="Geom"/>
<use name="rootgeom"/>
<flags DD4HEP_PLUGIN="1"/>
</library>
131 changes: 131 additions & 0 deletions Geometry/TrackerCommonData/plugins/dd4hep/DDTrackerRingAlgo.cc
@@ -0,0 +1,131 @@
#include "DD4hep/DetFactoryHelper.h"
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

using namespace std;
using namespace dd4hep;
using namespace cms;
using namespace geant_units::operators;

namespace {
long algorithm(Detector& /* description */,
cms::DDParsingContext& ctxt, xml_h e,
SensitiveDetector& /* sens */)
{
DDNamespace ns(ctxt, e, true);
DDAlgoArguments args(ctxt, e);
Volume mother = ns.volume(args.parentName());
string childName = args.value<string>("ChildName");
Volume child = ns.volume(childName);

string parentName = args.parentName();
int n = args.value<int>("N");
int startCopyNo = args.value<int>("StartCopyNo");
int incrCopyNo = args.value<int>("IncrCopyNo");
double rangeAngle = args.value<double>("RangeAngle");
double startAngle = args.value<double>("StartAngle");
double radius = args.value<double>("Radius");
vector<double> center = args.value<vector<double> >("Center");
bool isZPlus = args.value<int>("IsZPlus") == 1;
double tiltAngle = args.value<double>("TiltAngle");
bool isFlipped = args.value<int>("IsFlipped") == 1;
double delta = 0.;

if(abs(rangeAngle - 360.0_deg) < 0.001_deg) {
delta = rangeAngle/double(n);
} else {
if(n > 1) {
delta = rangeAngle/double(n-1);
} else {
delta = 0.;
}
}

LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parameters for position"
<< "ing:: n " << n << " Start, Range, Delta "
<< convertRadToDeg(startAngle) << " "
<< convertRadToDeg(rangeAngle) << " " << convertRadToDeg(delta)
<< " Radius " << radius << " Centre " << center[0]
<< ", " << center[1] << ", "<< center[2];

LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parent " << parentName
<< "\tChild " << childName << " NameSpace "
<< ns.name();

Rotation3D flipRot, tiltRot, phiRot, globalRot; // Identity
Rotation3D flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix; // Identity matrix

// flipMatrix calculus
if(isFlipped) {
LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
<< "\t90., 180., "
<< "90., 90., "
<< "180., 0.";
flipRot = makeRotation3D(90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0._deg);
flipMatrix = flipRot;
}
// tiltMatrix calculus
if(isZPlus) {
LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
<< "\t90., 90., "
<< convertRadToDeg(tiltAngle) << ", 180., "
<< convertRadToDeg(90._deg - tiltAngle) << ", 0.";
tiltRot = makeRotation3D(90._deg, 90._deg, tiltAngle, 180._deg, 90._deg - tiltAngle, 0._deg);
tiltMatrix = tiltRot;
if(isFlipped) { tiltMatrix *= flipMatrix; }
}
else {
LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
<< "\t90., 90., "
<< convertRadToDeg(tiltAngle) << ", 0., "
<< convertRadToDeg(90._deg + tiltAngle) << ", 0.";
tiltRot = makeRotation3D(90._deg, 90._deg, tiltAngle, 0._deg, 90._deg + tiltAngle, 0._deg);
tiltMatrix = tiltRot;
if(isFlipped) { tiltMatrix *= flipMatrix; }
}

// Loops for all phi values
double theta = 90._deg;
int copy = startCopyNo;
double phi = startAngle;

for(int i = 0; i < n; ++i) {
// phiRotMatrix calculus
double phix = phi;
double phiy = phix + 90._deg;
double phideg = convertRadToDeg(phix);
if(phideg != 0.) {
LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: "
<< "\t90., " << convertRadToDeg(phix)
<< ", 90.," << convertRadToDeg(phiy)
<<", 0., 0.";
phiRot = makeRotation3D(theta, phix, theta, phiy, 0., 0.);
phiRotMatrix = phiRot;
}

// globalRot def
globalRotMatrix = phiRotMatrix * tiltMatrix;
globalRot = Rotation3D(globalRotMatrix);

// translation def
double xpos = radius*cos(phi) + center[0];
double ypos = radius*sin(phi) + center[1];
double zpos = center[2];
Position tran(xpos, ypos, zpos);

// Positions child with respect to parent
mother.placeVolume(child, copy, Transform3D(globalRot, tran));
LogDebug("TrackerGeom") << "DDTrackerRingAlgo test " << child << " number "
<< copy << " positioned in " << mother << " at "
<< tran << " with " << globalRot;

copy += incrCopyNo;
phi += delta;
}
return s_executed;
}
}
// first argument is the type from the xml file
DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTrackerRingAlgo,::algorithm)

0 comments on commit efc8045

Please sign in to comment.