Skip to content

Commit

Permalink
Merge pull request #27735 from bsunanda/Run3-hcx215
Browse files Browse the repository at this point in the history
Run3-hcx215 Transfer ForwardShield algorithm to DD4Hep
  • Loading branch information
cmsbuild authored Aug 10, 2019
2 parents 2958268 + d26700f commit f304045
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Geometry/HcalAlgo/data/cms-test-ddhcalForwardShield-algorithm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>

<open_geometry/>
<close_geometry/>

<IncludeSection>
<Include ref="Geometry/CMSCommonData/data/materials.xml"/>
<Include ref="Geometry/HcalCommonData/data/hcalforwardmaterial.xml"/>
<Include ref="Geometry/CMSCommonData/data/rotations.xml"/>
<Include ref="Geometry/HcalCommonData/data/hcalrotations.xml"/>
<Include ref="Geometry/CMSCommonData/data/normal/cmsextent.xml"/>
<Include ref="Geometry/HcalAlgo/test/data/cms.xml"/>
<Include ref="Geometry/ForwardCommonData/data/bundle/forwardshield.xml"/>
</IncludeSection>

</DDDefinition>
105 changes: 105 additions & 0 deletions Geometry/HcalAlgo/plugins/dd4hep/DDHCalFibreBundle.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "DD4hep/DetFactoryHelper.h"
#include "DataFormats/Math/interface/CMSUnits.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

//#define EDM_ML_DEBUG

using namespace cms_units::operators;

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);
// Header section
double deltaPhi = args.value<double>("DeltaPhi");
double deltaZ = args.value<double>("DeltaZ");
int numberPhi = args.value<int>("NumberPhi");
std::string material = args.value<std::string>("Material");
std::vector<double> areaSection = args.value<std::vector<double> >("AreaSection");
std::vector<double> rStart = args.value<std::vector<double> >("RadiusStart");
std::vector<double> rEnd = args.value<std::vector<double> >("RadiusEnd");
std::vector<int> bundle = args.value<std::vector<int> >("Bundles");
double tilt = args.value<double>("TiltAngle");
std::string childPrefix = args.value<std::string>("Child");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Parent " << args.parentName() << " with " << bundle.size()
<< " children with prefix " << childPrefix << ", material " << material << " with "
<< numberPhi << " bundles along phi; width of"
<< " mother " << deltaZ << " along Z, " << convertRadToDeg(deltaPhi)
<< " along phi and with " << rStart.size() << " different bundle types";
for (unsigned int i = 0; i < areaSection.size(); ++i)
edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Child[" << i << "] Area " << areaSection[i] << " R at Start "
<< rStart[i] << " R at End " << rEnd[i];
edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: NameSpace " << ns.name() << " Tilt Angle "
<< convertRadToDeg(tilt) << " Bundle type at different positions";
for (unsigned int i = 0; i < bundle.size(); ++i) {
edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Position[" << i << "] "
<< " with Type " << bundle[i];
}
#endif

dd4hep::Volume mother = ns.volume(args.parentName());
dd4hep::Material matter = ns.material(material);

// Create the rotation matrices
double dPhi = deltaPhi / numberPhi;
std::vector<dd4hep::Rotation3D> rotation;
for (int i = 0; i < numberPhi; ++i) {
double phi = -0.5 * deltaPhi + (i + 0.5) * dPhi;
dd4hep::Rotation3D rot = cms::makeRotation3D(90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
#ifdef EDM_ML_DEBUG
double phideg = convertRadToDeg(phi);
edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new rotation " << 90 << "," << phideg << "," << 90
<< "," << (phideg + 90) << ", 0, 0";
#endif
rotation.emplace_back(rot);
}

// Create the solids and logical parts
std::vector<dd4hep::Volume> logs;
for (unsigned int i = 0; i < areaSection.size(); ++i) {
double r0 = rEnd[i] / std::cos(tilt);
double dStart = areaSection[i] / (2 * dPhi * rStart[i]);
double dEnd = areaSection[i] / (2 * dPhi * r0);
std::string name = childPrefix + std::to_string(i);
dd4hep::Solid solid = dd4hep::ConeSegment(
0.5 * deltaZ, rStart[i] - dStart, rStart[i] + dStart, r0 - dEnd, r0 + dEnd, -0.5 * dPhi, 0.5 * dPhi);
ns.addSolidNS(name, solid);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new solid " << name << " a cons with dZ " << deltaZ
<< " rStart " << rStart[i] - dStart << ":" << rStart[i] + dStart << " rEnd "
<< r0 - dEnd << ":" << r0 + dEnd << " Phi " << convertRadToDeg(-0.5 * dPhi) << ":"
<< convertRadToDeg(0.5 * dPhi);
#endif
dd4hep::Volume log(name, solid, matter);
ns.addVolumeNS(log);
logs.emplace_back(log);
}

// Now posiiton them
int copy = 0;
int nY = static_cast<int>(bundle.size()) / numberPhi;
for (unsigned int i = 0; i < bundle.size(); i++) {
dd4hep::Position tran(0, 0, 0);
int ir = static_cast<int>(i) / nY;
if (ir >= numberPhi)
ir = numberPhi - 1;
int ib = bundle[i];
copy++;
if (ib >= 0 && ib < (int)(logs.size())) {
mother.placeVolume(logs[ib], copy, dd4hep::Transform3D(rotation[ir], tran));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: " << logs[ib].name() << " number " << copy
<< " positioned in " << mother.name() << " at (0, 0, 0)" << tran << " with "
<< rotation[ir];
#endif
}
}
return 1;
}

// first argument is the type from the xml file
DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalFibreBundle, algorithm);
14 changes: 14 additions & 0 deletions Geometry/HcalAlgo/python/testGeomForwardShield_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import FWCore.ParameterSet.Config as cms

XMLIdealGeometryESSource = cms.ESSource("XMLIdealGeometryESSource",
geomXMLFiles = cms.vstring('Geometry/CMSCommonData/data/materials.xml',
'Geometry/HcalCommonData/data/hcalforwardmaterial.xml',
'Geometry/CMSCommonData/data/rotations.xml',
'Geometry/HcalCommonData/data/hcalrotations.xml',
'Geometry/CMSCommonData/data/normal/cmsextent.xml',
'Geometry/HcalAlgo/test/data/cms.xml',
'Geometry/ForwardCommonData/data/bundle/forwardshield.xml'),
rootNodeName = cms.string('cms:OCMS')
)


29 changes: 29 additions & 0 deletions Geometry/HcalAlgo/test/python/dumpForwardShield_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("DUMP")

process.load("Geometry.HcalAlgo.testGeomForwardShield_cfi")
process.load('FWCore.MessageService.MessageLogger_cfi')

if 'MessageLogger' in process.__dict__:
process.MessageLogger.categories.append('G4cerr')
process.MessageLogger.categories.append('G4cout')
process.MessageLogger.categories.append('HCalGeom')

process.source = cms.Source("EmptySource")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

process.add_(cms.ESProducer("TGeoMgrFromDdd",
verbose = cms.untracked.bool(False),
level = cms.untracked.int32(14)
))


process.dump = cms.EDAnalyzer("DumpSimGeometry",
outputFileName = cms.untracked.string('ForwardShieldDDD.root')
)

process.p = cms.Path(process.dump)
25 changes: 25 additions & 0 deletions Geometry/HcalAlgo/test/python/testForwardShield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("DDForwardShieldTest")

process.load('FWCore.MessageService.MessageLogger_cfi')
process.source = cms.Source("EmptySource")
process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

process.MessageLogger.cerr.FwkReport.reportEvery = 5
if hasattr(process,'MessageLogger'):
process.MessageLogger.categories.append('HCalGeom')

process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath('Geometry/HcalAlgo/data/cms-test-ddhcalForwardShield-algorithm.xml'),
appendToDataLabel = cms.string('DDHCalFibreBundle')
)

process.testDump = cms.EDAnalyzer("DDTestDumpFile",
outputFileName = cms.untracked.string('ForwardShieldDD4Hep.root'),
DDDetector = cms.ESInputTag('','DDHCalFibreBundle')
)

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

0 comments on commit f304045

Please sign in to comment.