From b1bef930084f66d71ff22dd577d9bd8525b50f79 Mon Sep 17 00:00:00 2001 From: Sunanda <sunanda.banerjee@cern.ch> Date: Fri, 16 Jun 2023 03:58:37 +0200 Subject: [PATCH 1/3] Try to provide the dd4hep version of the plugins for passive components of V18 Silicon modules of HGCal --- .../data/dd4hep/testHGCalPassive.xml | 22 +++ .../plugins/dd4hep/DDHGCalPassiveFull.cc | 135 +++++++++++++++ .../plugins/dd4hep/DDHGCalPassivePartial.cc | 157 ++++++++++++++++++ .../test/python/dumpHGCalPassive_cfg.py | 53 ++++-- 4 files changed, 356 insertions(+), 11 deletions(-) create mode 100644 Geometry/HGCalCommonData/data/dd4hep/testHGCalPassive.xml create mode 100644 Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc create mode 100644 Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc diff --git a/Geometry/HGCalCommonData/data/dd4hep/testHGCalPassive.xml b/Geometry/HGCalCommonData/data/dd4hep/testHGCalPassive.xml new file mode 100644 index 0000000000000..4912010a7ab32 --- /dev/null +++ b/Geometry/HGCalCommonData/data/dd4hep/testHGCalPassive.xml @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<DDDefinition> + <open_geometry/> + <close_geometry/> + + <IncludeSection> + <Include ref="Geometry/CMSCommonData/data/materials/2021/v3/materials.xml"/> + <Include ref="Geometry/CMSCommonData/data/rotations.xml"/> + <Include ref="Geometry/CMSCommonData/data/extend/v2/cmsextent.xml"/> + <Include ref="Geometry/CMSCommonData/data/cavernData/2021/v1/cavernData.xml"/> + <Include ref="Geometry/CMSCommonData/data/cms/2026/v5/cms.xml"/> + <Include ref="Geometry/CMSCommonData/data/cmsMother.xml"/> + <Include ref="Geometry/CMSCommonData/data/eta3/etaMax.xml"/> + <Include ref="Geometry/CMSCommonData/data/caloBase/2026/v7/caloBase.xml"/> + <Include ref="Geometry/HGCalCommonData/data/hgcalMaterial/v2/hgcalMaterial.xml"/> + <Include ref="Geometry/HGCalCommonData/data/hgcal/v18/hgcal.xml"/> + <Include ref="Geometry/HGCalCommonData/data/hgcalPassive/v18/hgcalPassive.xml"/> + <Include ref="Geometry/HGCalCommonData/data/hgcalPassive/v18/hgcalpos.xml"/> + </IncludeSection> + + </DDDefinition> + diff --git a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc new file mode 100644 index 0000000000000..eb4535879cebf --- /dev/null +++ b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc @@ -0,0 +1,135 @@ +/////////////////////////////////////////////////////////////////////////////// +// File: DDHGCalPassiveFull.cc +// Description: Geometry factory class for the passive part of a full silicon +// module +// Created by Sunanda Banerjee +/////////////////////////////////////////////////////////////////////////////// + +#include <string> +#include <vector> +#include <sstream> + +#include "DD4hep/DetFactoryHelper.h" +#include "DataFormats/Math/interface/angle_units.h" +#include "DetectorDescription/DDCMS/interface/DDPlugins.h" +#include "DetectorDescription/DDCMS/interface/DDutils.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#define EDM_ML_DEBUG +using namespace angle_units::operators; + +struct HGCalPassiveFull { + HGCalPassiveFull() { + throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassiveFull"; + } + HGCalPassiveFull(cms::DDParsingContext& ctxt, xml_h e) { + cms::DDNamespace ns(ctxt, e, true); + cms::DDAlgoArguments args(ctxt, e); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Creating an instance"; +#endif + std::string parentName = args.parentName(); + std::string material = args.value<std::string>("ModuleMaterial"); + double thick = args.value<double>("ModuleThickness"); + double waferSize = args.value<double>("WaferSize"); + double waferSepar = args.value<double>("SensorSeparation"); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Module " << parentName << " made of " << material << " T " + << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar; +#endif + std::vector<std::string> layerNames = args.value<std::vector<std::string>>("LayerNames"); + std::vector<std::string> materials = args.value<std::vector<std::string>>("LayerMaterials"); + std::vector<double> layerThick = args.value<std::vector<double>>("LayerThickness"); + std::vector<int> copyNumber; +copyNumber.resize(materials.size(), 1); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << layerNames.size() << " types of volumes"; + for (unsigned int i = 0; i < layerNames.size(); ++i) + edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i] + << " filled with " << materials[i]; +#endif + std::vector<int> layerType = args.value<std::vector<int>>("LayerType"); +#ifdef EDM_ML_DEBUG + std::ostringstream st1; + for (unsigned int i = 0; i < layerType.size(); ++i) + st1 << " [" << i << "] " << layerType[i]; + edm::LogVerbatim("HGCalGeom") << "There are " << layerType.size() << " blocks" << st1.str(); + + edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassiveFull..."; +#endif + + static constexpr double tol = 0.00001; + static const double sqrt3 = std::sqrt(3.0); + double rM = 0.5 * (waferSize + waferSepar); + double RM2 = rM / sqrt3; + + // First the mother + std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM}; + std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2}; + std::vector<double> zw = {-0.5 * thick, 0.5 * thick}; + std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0); + dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); + ns.addSolidNS(ns.prepend(parentName), solid); + dd4hep::Material matter = ns.material(material); + dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter); + ns.addVolumeNS(glogM); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << solid.name() << " extruded polygon made of " << matter.name() + << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] + << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] + << " and " << xM.size() << " edges"; + for (unsigned int kk = 0; kk < xM.size(); ++kk) + edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; +#endif + + // Then the layers + std::vector<dd4hep::Volume> glogs(materials.size()); + double zi(-0.5 * thick), thickTot(0.0); + for (unsigned int l = 0; l < layerType.size(); l++) { + unsigned int i = layerType[l]; + if (copyNumber[i] == 1) { + zw[0] = -0.5 * layerThick[i]; + zw[1] = 0.5 * layerThick[i]; + std::string layerName = parentName + layerNames[i]; + solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); + ns.addSolidNS(ns.prepend(layerName), solid); + matter = ns.material(materials[i]); + glogs[i] = dd4hep::Volume(solid.name(), solid, matter); + ns.addVolumeNS(glogs[i]); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Layer " << i << ":" << l << ":" << solid.name() + << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] + << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] + << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges"; + for (unsigned int kk = 0; kk < xM.size(); ++kk) + edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; +#endif + } + dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i])); + glogM.placeVolume(glogs[i], copyNumber[i], tran0); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << glogs[i].name() << " number " << copyNumber[i] + << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation"; +#endif + ++copyNumber[i]; + zi += layerThick[i]; + thickTot += layerThick[i]; + } + if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) { + if (thickTot > thick) { + edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot + << ": thickness of all its components **** ERROR ****"; + } else { + edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot + << " of the components"; + } + } + } +}; + +static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) { + HGCalPassiveFull passiveFullAlgo(ctxt, e); + return cms::s_executed; +} + +DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalPassiveFull, algorithm) diff --git a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc new file mode 100644 index 0000000000000..983252807fd7d --- /dev/null +++ b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc @@ -0,0 +1,157 @@ +/////////////////////////////////////////////////////////////////////////////// +// File: DDHGCalPassivePartial.cc +// Description: Geometry factory class for the passive part of a partial +// silicon module +// Created by Sunanda Banerjee +/////////////////////////////////////////////////////////////////////////////// + +#include <string> +#include <vector> +#include <sstream> + +#include "DD4hep/DetFactoryHelper.h" +#include "DataFormats/Math/interface/angle_units.h" +#include "DetectorDescription/DDCMS/interface/DDPlugins.h" +#include "DetectorDescription/DDCMS/interface/DDutils.h" +#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#define EDM_ML_DEBUG +using namespace angle_units::operators; + +struct HGCalPassivePartial { + HGCalPassivePartial() { + throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassivePartial"; + } + HGCalPassivePartial(cms::DDParsingContext& ctxt, xml_h e) { + cms::DDNamespace ns(ctxt, e, true); + cms::DDAlgoArguments args(ctxt, e); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Creating an instance"; +#endif + std::string parentName = args.parentName(); + std::string material = args.value<std::string>("ModuleMaterial"); + double thick = args.value<double>("ModuleThickness"); + double waferSize = args.value<double>("WaferSize"); + double waferSepar = args.value<double>("SensorSeparation"); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Module " << parentName << " made of " << material << " T " + << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar; +#endif + std::vector<std::string> tags = args.value<std::vector<std::string>>("Tags"); + std::vector<int> partialTypes = args.value<std::vector<int>>("PartialTypes"); + std::vector<int> placementIndex = args.value<std::vector<int>>("{lacementIndex"); + std::vector<std::string> placementIndexTags = args.value<std::vector<std::string>>("PlacementIndexTags"); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags.size() << " variations of wafer types"; + for (unsigned int k = 0; k < tags.size(); ++k) { + for (unsigned int m = 0; m < placementIndex.size(); ++m) { + edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k] + << " Placement Index " << placementIndex[m] << " Tag " << placementIndexTags[m]; + } + } +#endif + std::vector<std::string> layerNames = args.value<std::vector<std::string>>("LayerNames"); + std::vector<std::string> materials = args.value<std::vector<std::string>>("LayerMaterials"); + std::vector<double> layerThick = args.value<std::vector<double>>("LayerThickness"); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << layerNames.size() << " types of volumes"; + for (unsigned int i = 0; i < layerNames.size(); ++i) + edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i] + << " filled with " << materials[i]; +#endif + std::vector<int> layerType = args.value<std::vector<int>>("LayerType"); +#ifdef EDM_ML_DEBUG + std::ostringstream st1; + for (unsigned int i = 0; i < layerType.size(); ++i) + st1 << " [" << i << "] " << layerType[i]; + edm::LogVerbatim("HGCalGeom") << "There are " << layerType.size() << " blocks" << st1.str(); + + edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassivePartial..."; +#endif + + static constexpr double tol = 0.00001; + + // Loop over all types + for (unsigned int k = 0; k < tags.size(); ++k) { + for (unsigned int m = 0; m < placementIndex.size(); ++m) { + // First the mother + std::string mother = parentName + placementIndexTags[m] + tags[k]; + std::vector<std::pair<double, double> > wxy = + HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], (waferSize + waferSepar), 0.0, 0.0, 0.0); + std::vector<double> xM, yM; + for (unsigned int i = 0; i < (wxy.size() - 1); ++i) { + xM.emplace_back(wxy[i].first); + yM.emplace_back(wxy[i].second); + } + std::vector<double> zw = {-0.5 * thick, 0.5 * thick}; + std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0); + dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); + ns.addSolidNS(ns.prepend(mother), solid); + dd4hep::Material matter = ns.material(material); + dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter); + ns.addVolumeNS(glogM); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of " << matter.name() + << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] + << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] + << " and " << xM.size() << " edges"; + for (unsigned int kk = 0; kk < xM.size(); ++kk) + edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; +#endif + + // Then the layers + std::vector<dd4hep::Volume> glogs(materials.size()); + std::vector<int> copyNumber; + copyNumber.resize(materials.size(), 1); + double zi(-0.5 * thick), thickTot(0.0); + for (unsigned int l = 0; l < layerType.size(); l++) { + unsigned int i = layerType[l]; + if (copyNumber[i] == 1) { + zw[0] = -0.5 * layerThick[i]; + zw[1] = 0.5 * layerThick[i]; + std::string layerName = mother + layerNames[i]; + solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); + ns.addSolidNS(ns.prepend(layerName), solid); + matter = ns.material(materials[i]); + glogs[i] = dd4hep::Volume(solid.name(), solid, matter); + ns.addVolumeNS(glogs[i]); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Layer " << i << ":" << l << ":" << solid.name() + << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] + << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] + << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges"; + for (unsigned int kk = 0; kk < xM.size(); ++kk) + edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; +#endif + } + dd4hep::Position tran(0, 0, (zi + 0.5 * layerThick[i])); + glogM.placeVolume(glogs[i], copyNumber[i], tran); +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i] + << " positioned in " << glogM.name() << " at " << tran << " with no rotation"; +#endif + ++copyNumber[i]; + zi += layerThick[i]; + thickTot += layerThick[i]; + } + if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) { + if (thickTot > thick) { + edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot + << ": thickness of all its components **** ERROR ****"; + } else { + edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot + << " of the components"; + } + } + } + } + } +}; + +static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) { + HGCalPassivePartial passivePartialAlgo(ctxt, e); + return cms::s_executed; +} + +DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalPassivePartial, algorithm) diff --git a/Geometry/HGCalCommonData/test/python/dumpHGCalPassive_cfg.py b/Geometry/HGCalCommonData/test/python/dumpHGCalPassive_cfg.py index 43334ff3b88b4..e4ef288e5f2a0 100644 --- a/Geometry/HGCalCommonData/test/python/dumpHGCalPassive_cfg.py +++ b/Geometry/HGCalCommonData/test/python/dumpHGCalPassive_cfg.py @@ -1,14 +1,42 @@ +############################################################################### +# Way to use this: +# cmsRun dumpHGCalPassive_cfg.py type=DDD +# +# Options for type DDD, DD4hep +# +############################################################################### import FWCore.ParameterSet.Config as cms +import os, sys, importlib, re +import FWCore.ParameterSet.VarParsing as VarParsing + +#################################################################### +### SETUP OPTIONS +options = VarParsing.VarParsing('standard') +options.register('type', + "DDD", + VarParsing.VarParsing.multiplicity.singleton, + VarParsing.VarParsing.varType.string, + "type of operations: DDD, DD4hep") + +### get and parse the command line arguments +options.parseArguments() + from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9 process = cms.Process('GeomDump',Phase2C17I13M9) - -geomFile = "Geometry.HGCalCommonData.testHGCalPassiveXML_cfi" -fileName = "hgcalPassiveDDD.root" +if (options.type == "DD4hep"): + geomFile = "Geometry/HGCalCommonData/data/dd4hep/testHGCalPassive.xml" + fileName = "hgcalPassiveDD4hep.root" + process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer", + confGeomXMLFiles = cms.FileInPath(geomFile), + appendToDataLabel = cms.string('DDHGCal')) +else: + geomFile = "Geometry.HGCalCommonData.testHGCalPassiveXML_cfi" + fileName = "hgcalPassiveDDD.root" + process.load(geomFile) print("Geometry file: ", geomFile) print("Output file: ", fileName) -process.load(geomFile) process.load('FWCore.MessageService.MessageLogger_cfi') if 'MessageLogger' in process.__dict__: @@ -24,12 +52,15 @@ 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(fileName)) +if (options.type == "DD4hep"): + process.dump = cms.EDAnalyzer("DDTestDumpFile", + outputFileName = cms.untracked.string(fileName), + DDDetector = cms.ESInputTag('','DDHGCal')) +else: + process.add_(cms.ESProducer("TGeoMgrFromDdd", + verbose = cms.untracked.bool(False), + level = cms.untracked.int32(14))) + process.dump = cms.EDAnalyzer("DumpSimGeometry", + outputFileName = cms.untracked.string(fileName)) process.p = cms.Path(process.dump) From 301701a2c9c2d7d5afd55ae074ce5cf8422facfe Mon Sep 17 00:00:00 2001 From: Sunanda <sunanda.banerjee@cern.ch> Date: Fri, 16 Jun 2023 04:11:56 +0200 Subject: [PATCH 2/3] Code check --- .../plugins/dd4hep/DDHGCalPassiveFull.cc | 61 ++++---- .../plugins/dd4hep/DDHGCalPassivePartial.cc | 137 +++++++++--------- 2 files changed, 98 insertions(+), 100 deletions(-) diff --git a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc index eb4535879cebf..f6a18beb3339d 100644 --- a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc +++ b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // File: DDHGCalPassiveFull.cc -// Description: Geometry factory class for the passive part of a full silicon +// Description: Geometry factory class for the passive part of a full silicon // module // Created by Sunanda Banerjee /////////////////////////////////////////////////////////////////////////////// @@ -19,9 +19,7 @@ using namespace angle_units::operators; struct HGCalPassiveFull { - HGCalPassiveFull() { - throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassiveFull"; - } + HGCalPassiveFull() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassiveFull"; } HGCalPassiveFull(cms::DDParsingContext& ctxt, xml_h e) { cms::DDNamespace ns(ctxt, e, true); cms::DDAlgoArguments args(ctxt, e); @@ -35,18 +33,18 @@ struct HGCalPassiveFull { double waferSepar = args.value<double>("SensorSeparation"); #ifdef EDM_ML_DEBUG edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Module " << parentName << " made of " << material << " T " - << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar; + << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar; #endif std::vector<std::string> layerNames = args.value<std::vector<std::string>>("LayerNames"); std::vector<std::string> materials = args.value<std::vector<std::string>>("LayerMaterials"); std::vector<double> layerThick = args.value<std::vector<double>>("LayerThickness"); std::vector<int> copyNumber; -copyNumber.resize(materials.size(), 1); + copyNumber.resize(materials.size(), 1); #ifdef EDM_ML_DEBUG edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << layerNames.size() << " types of volumes"; for (unsigned int i = 0; i < layerNames.size(); ++i) edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i] - << " filled with " << materials[i]; + << " filled with " << materials[i]; #endif std::vector<int> layerType = args.value<std::vector<int>>("LayerType"); #ifdef EDM_ML_DEBUG @@ -74,10 +72,10 @@ copyNumber.resize(materials.size(), 1); dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter); ns.addVolumeNS(glogM); #ifdef EDM_ML_DEBUG - edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << solid.name() << " extruded polygon made of " << matter.name() - << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] - << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] - << " and " << xM.size() << " edges"; + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << solid.name() << " extruded polygon made of " + << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" + << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" + << scale[1] << " and " << xM.size() << " edges"; for (unsigned int kk = 0; kk < xM.size(); ++kk) edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; #endif @@ -88,28 +86,29 @@ copyNumber.resize(materials.size(), 1); for (unsigned int l = 0; l < layerType.size(); l++) { unsigned int i = layerType[l]; if (copyNumber[i] == 1) { - zw[0] = -0.5 * layerThick[i]; - zw[1] = 0.5 * layerThick[i]; - std::string layerName = parentName + layerNames[i]; - solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); - ns.addSolidNS(ns.prepend(layerName), solid); - matter = ns.material(materials[i]); - glogs[i] = dd4hep::Volume(solid.name(), solid, matter); - ns.addVolumeNS(glogs[i]); + zw[0] = -0.5 * layerThick[i]; + zw[1] = 0.5 * layerThick[i]; + std::string layerName = parentName + layerNames[i]; + solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); + ns.addSolidNS(ns.prepend(layerName), solid); + matter = ns.material(materials[i]); + glogs[i] = dd4hep::Volume(solid.name(), solid, matter); + ns.addVolumeNS(glogs[i]); #ifdef EDM_ML_DEBUG - edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Layer " << i << ":" << l << ":" << solid.name() - << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] - << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] - << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges"; - for (unsigned int kk = 0; kk < xM.size(); ++kk) - edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Layer " << i << ":" << l << ":" << solid.name() + << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << zw[0] + << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] + << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() + << " edges"; + for (unsigned int kk = 0; kk < xM.size(); ++kk) + edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; #endif } dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i])); glogM.placeVolume(glogs[i], copyNumber[i], tran0); #ifdef EDM_ML_DEBUG edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << glogs[i].name() << " number " << copyNumber[i] - << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation"; + << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation"; #endif ++copyNumber[i]; zi += layerThick[i]; @@ -117,16 +116,16 @@ copyNumber.resize(materials.size(), 1); } if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) { if (thickTot > thick) { - edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot - << ": thickness of all its components **** ERROR ****"; + edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot + << ": thickness of all its components **** ERROR ****"; } else { - edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot - << " of the components"; + edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot + << " of the components"; } } } }; - + static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) { HGCalPassiveFull passiveFullAlgo(ctxt, e); return cms::s_executed; diff --git a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc index 983252807fd7d..24b68d4a17101 100644 --- a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc +++ b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc @@ -20,9 +20,7 @@ using namespace angle_units::operators; struct HGCalPassivePartial { - HGCalPassivePartial() { - throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassivePartial"; - } + HGCalPassivePartial() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassivePartial"; } HGCalPassivePartial(cms::DDParsingContext& ctxt, xml_h e) { cms::DDNamespace ns(ctxt, e, true); cms::DDAlgoArguments args(ctxt, e); @@ -36,7 +34,7 @@ struct HGCalPassivePartial { double waferSepar = args.value<double>("SensorSeparation"); #ifdef EDM_ML_DEBUG edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Module " << parentName << " made of " << material << " T " - << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar; + << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar; #endif std::vector<std::string> tags = args.value<std::vector<std::string>>("Tags"); std::vector<int> partialTypes = args.value<std::vector<int>>("PartialTypes"); @@ -46,8 +44,8 @@ struct HGCalPassivePartial { edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags.size() << " variations of wafer types"; for (unsigned int k = 0; k < tags.size(); ++k) { for (unsigned int m = 0; m < placementIndex.size(); ++m) { - edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k] - << " Placement Index " << placementIndex[m] << " Tag " << placementIndexTags[m]; + edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k] + << " Placement Index " << placementIndex[m] << " Tag " << placementIndexTags[m]; } } #endif @@ -75,80 +73,81 @@ struct HGCalPassivePartial { // Loop over all types for (unsigned int k = 0; k < tags.size(); ++k) { for (unsigned int m = 0; m < placementIndex.size(); ++m) { - // First the mother - std::string mother = parentName + placementIndexTags[m] + tags[k]; - std::vector<std::pair<double, double> > wxy = - HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], (waferSize + waferSepar), 0.0, 0.0, 0.0); - std::vector<double> xM, yM; - for (unsigned int i = 0; i < (wxy.size() - 1); ++i) { - xM.emplace_back(wxy[i].first); - yM.emplace_back(wxy[i].second); - } - std::vector<double> zw = {-0.5 * thick, 0.5 * thick}; - std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0); - dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); - ns.addSolidNS(ns.prepend(mother), solid); - dd4hep::Material matter = ns.material(material); - dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter); - ns.addVolumeNS(glogM); + // First the mother + std::string mother = parentName + placementIndexTags[m] + tags[k]; + std::vector<std::pair<double, double>> wxy = + HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], (waferSize + waferSepar), 0.0, 0.0, 0.0); + std::vector<double> xM, yM; + for (unsigned int i = 0; i < (wxy.size() - 1); ++i) { + xM.emplace_back(wxy[i].first); + yM.emplace_back(wxy[i].second); + } + std::vector<double> zw = {-0.5 * thick, 0.5 * thick}; + std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0); + dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); + ns.addSolidNS(ns.prepend(mother), solid); + dd4hep::Material matter = ns.material(material); + dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter); + ns.addVolumeNS(glogM); #ifdef EDM_ML_DEBUG - edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of " << matter.name() - << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] - << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] - << " and " << xM.size() << " edges"; - for (unsigned int kk = 0; kk < xM.size(); ++kk) - edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of " + << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] + << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] + << ":" << scale[1] << " and " << xM.size() << " edges"; + for (unsigned int kk = 0; kk < xM.size(); ++kk) + edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; #endif - // Then the layers - std::vector<dd4hep::Volume> glogs(materials.size()); - std::vector<int> copyNumber; - copyNumber.resize(materials.size(), 1); - double zi(-0.5 * thick), thickTot(0.0); - for (unsigned int l = 0; l < layerType.size(); l++) { - unsigned int i = layerType[l]; - if (copyNumber[i] == 1) { - zw[0] = -0.5 * layerThick[i]; - zw[1] = 0.5 * layerThick[i]; - std::string layerName = mother + layerNames[i]; - solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); - ns.addSolidNS(ns.prepend(layerName), solid); - matter = ns.material(materials[i]); - glogs[i] = dd4hep::Volume(solid.name(), solid, matter); - ns.addVolumeNS(glogs[i]); + // Then the layers + std::vector<dd4hep::Volume> glogs(materials.size()); + std::vector<int> copyNumber; + copyNumber.resize(materials.size(), 1); + double zi(-0.5 * thick), thickTot(0.0); + for (unsigned int l = 0; l < layerType.size(); l++) { + unsigned int i = layerType[l]; + if (copyNumber[i] == 1) { + zw[0] = -0.5 * layerThick[i]; + zw[1] = 0.5 * layerThick[i]; + std::string layerName = mother + layerNames[i]; + solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale); + ns.addSolidNS(ns.prepend(layerName), solid); + matter = ns.material(materials[i]); + glogs[i] = dd4hep::Volume(solid.name(), solid, matter); + ns.addVolumeNS(glogs[i]); #ifdef EDM_ML_DEBUG - edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Layer " << i << ":" << l << ":" << solid.name() - << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] - << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] - << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges"; - for (unsigned int kk = 0; kk < xM.size(); ++kk) - edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; + edm::LogVerbatim("HGCalGeom") + << "DDHGCalPassivePartial: Layer " << i << ":" << l << ":" << solid.name() + << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" + << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" + << scale[1] << " and " << xM.size() << " edges"; + for (unsigned int kk = 0; kk < xM.size(); ++kk) + edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk]; #endif - } - dd4hep::Position tran(0, 0, (zi + 0.5 * layerThick[i])); - glogM.placeVolume(glogs[i], copyNumber[i], tran); + } + dd4hep::Position tran(0, 0, (zi + 0.5 * layerThick[i])); + glogM.placeVolume(glogs[i], copyNumber[i], tran); #ifdef EDM_ML_DEBUG - edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i] - << " positioned in " << glogM.name() << " at " << tran << " with no rotation"; + edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i] + << " positioned in " << glogM.name() << " at " << tran << " with no rotation"; #endif - ++copyNumber[i]; - zi += layerThick[i]; - thickTot += layerThick[i]; - } - if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) { - if (thickTot > thick) { - edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot - << ": thickness of all its components **** ERROR ****"; - } else { - edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot - << " of the components"; - } - } + ++copyNumber[i]; + zi += layerThick[i]; + thickTot += layerThick[i]; + } + if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) { + if (thickTot > thick) { + edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot + << ": thickness of all its components **** ERROR ****"; + } else { + edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " + << thickTot << " of the components"; + } + } } } } }; - + static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) { HGCalPassivePartial passivePartialAlgo(ctxt, e); return cms::s_executed; From aa83b87dd82d4cf4bd801c8c8b4e2237b69a319f Mon Sep 17 00:00:00 2001 From: Sunanda <sunanda.banerjee@cern.ch> Date: Mon, 19 Jun 2023 18:07:36 +0200 Subject: [PATCH 3/3] Bug fix - thanks to Yana --- Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc | 2 +- .../HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc index f6a18beb3339d..8ab3d7fabe133 100644 --- a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc +++ b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassiveFull.cc @@ -15,7 +15,7 @@ #include "DetectorDescription/DDCMS/interface/DDutils.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#define EDM_ML_DEBUG +//#define EDM_ML_DEBUG using namespace angle_units::operators; struct HGCalPassiveFull { diff --git a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc index 24b68d4a17101..1b89f1cbb7951 100644 --- a/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc +++ b/Geometry/HGCalCommonData/plugins/dd4hep/DDHGCalPassivePartial.cc @@ -16,7 +16,7 @@ #include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#define EDM_ML_DEBUG +//#define EDM_ML_DEBUG using namespace angle_units::operators; struct HGCalPassivePartial { @@ -38,7 +38,7 @@ struct HGCalPassivePartial { #endif std::vector<std::string> tags = args.value<std::vector<std::string>>("Tags"); std::vector<int> partialTypes = args.value<std::vector<int>>("PartialTypes"); - std::vector<int> placementIndex = args.value<std::vector<int>>("{lacementIndex"); + std::vector<int> placementIndex = args.value<std::vector<int>>("PlacementIndex"); std::vector<std::string> placementIndexTags = args.value<std::vector<std::string>>("PlacementIndexTags"); #ifdef EDM_ML_DEBUG edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags.size() << " variations of wafer types";