From e27571ec41b3bfd8278569c6a2c74d8f73d5511f Mon Sep 17 00:00:00 2001 From: Fabio Cossutti Date: Tue, 10 Dec 2024 22:00:45 +0100 Subject: [PATCH 1/5] Revert "Revert "Move BTL phi order from 0 to 2pi to -pi to +pi"" This reverts commit 06d30e104bc56cf687bf9722599b95a364470199. --- .../plugins/CmsMTDConstruction.cc | 10 ++++------ .../plugins/CmsMTDConstruction.h | 13 +++++++++++++ RecoMTD/DetLayers/test/mtd_cfg.py | 3 +-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc b/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc index 7d2f1342651b5..2554b25a89881 100644 --- a/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc +++ b/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc @@ -9,8 +9,6 @@ #include "DataFormats/ForwardDetId/interface/ETLDetId.h" #include "Geometry/MTDCommonData/interface/MTDBaseNumber.h" -#include "DataFormats/Math/interface/deltaPhi.h" - using angle_units::operators::convertRadToDeg; template @@ -39,14 +37,14 @@ bool CmsMTDConstruction::mtdOrderPhi(const GeometricTimingDet* a, template bool CmsMTDConstruction::btlOrderPhi(const GeometricTimingDet* a, const GeometricTimingDet* b) { - return static_cast(convertRadToDeg(angle0to2pi::make0To2pi(a->phi()))) < - static_cast(convertRadToDeg(angle0to2pi::make0To2pi(b->phi()))); + return static_cast(convertRadToDeg(makempiToppi(a->phi()))) < + static_cast(convertRadToDeg(makempiToppi(b->phi()))); } template bool CmsMTDConstruction::btlOrderZ(const GeometricTimingDet* a, const GeometricTimingDet* b) { - bool order = (static_cast(convertRadToDeg(angle0to2pi::make0To2pi(a->phi()))) == - static_cast(convertRadToDeg(angle0to2pi::make0To2pi(b->phi())))) && + bool order = (static_cast(convertRadToDeg(makempiToppi(a->phi()))) == + static_cast(convertRadToDeg(makempiToppi(b->phi())))) && (a->translation().z() < b->translation().z()); return order; } diff --git a/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.h b/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.h index d9e322e849507..3bd2beb18c619 100644 --- a/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.h +++ b/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.h @@ -7,6 +7,19 @@ #include "Geometry/MTDCommonData/interface/BTLNumberingScheme.h" #include "Geometry/MTDCommonData/interface/ETLNumberingScheme.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +namespace { + + template + inline constexpr valType makempiToppi(valType angle) { + constexpr valType twoPi = 2. * M_PI; + constexpr valType epsilon = 1.e-13; + auto tmpphi = angle0to2pi::make0To2pi(angle); + return (tmpphi - M_PI > epsilon) ? tmpphi - twoPi : tmpphi; + } +} // namespace + /** * Adds GeometricTimingDets representing final modules to the previous level */ diff --git a/RecoMTD/DetLayers/test/mtd_cfg.py b/RecoMTD/DetLayers/test/mtd_cfg.py index c384f5897e7b6..c4a36421478b0 100644 --- a/RecoMTD/DetLayers/test/mtd_cfg.py +++ b/RecoMTD/DetLayers/test/mtd_cfg.py @@ -65,5 +65,4 @@ process.prod1 = cms.EDAnalyzer("TestBTLNavigation") process.prod2 = cms.EDAnalyzer("TestETLNavigation") -# process.p1 = cms.Path(cms.wait(process.prod)+cms.wait(process.prod1)+process.prod2) -process.p1 = cms.Path(cms.wait(process.prod)+process.prod2) +process.p1 = cms.Path(cms.wait(process.prod)+cms.wait(process.prod1)+process.prod2) From 15bd342be03ebe5d023f29699bd97575125143a2 Mon Sep 17 00:00:00 2001 From: cquarant Date: Tue, 17 Dec 2024 10:46:43 +0100 Subject: [PATCH 2/5] overall update of BTLDetId to match BTL geo v2,v3 (v1 not supported), BTL electronics mapping introduced --- DataFormats/ForwardDetId/interface/BTLDetId.h | 167 +++++++++++---- DataFormats/ForwardDetId/src/BTLDetId.cc | 34 +-- DataFormats/ForwardDetId/src/classes_def.xml | 9 +- DataFormats/TrackReco/src/HitPattern.cc | 2 +- .../interface/BTLElectronicsMapping.h | 80 +++++++ .../interface/BTLNumberingScheme.h | 3 - .../src/BTLElectronicsMapping.cc | 198 ++++++++++++++++++ .../MTDCommonData/src/BTLNumberingScheme.cc | 162 +++++++------- .../test/DD4hep_TestPixelTopology.cc | 8 +- .../plugins/CmsMTDConstruction.cc | 4 +- 10 files changed, 520 insertions(+), 147 deletions(-) create mode 100644 Geometry/MTDCommonData/interface/BTLElectronicsMapping.h create mode 100644 Geometry/MTDCommonData/src/BTLElectronicsMapping.cc diff --git a/DataFormats/ForwardDetId/interface/BTLDetId.h b/DataFormats/ForwardDetId/interface/BTLDetId.h index 0a1bd7eab1699..3b2337cb7e982 100644 --- a/DataFormats/ForwardDetId/interface/BTLDetId.h +++ b/DataFormats/ForwardDetId/interface/BTLDetId.h @@ -2,8 +2,10 @@ #define DataFormats_BTLDetId_BTLDetId_h #include "DataFormats/ForwardDetId/interface/MTDDetId.h" +#include #include #include +#include /** @class BTLDetId @@ -14,29 +16,59 @@ bit 9-8 : crystal type (1 - 3) bit 7-6 : readout unit sequential number within a type ( 1 - 2 ) bit 5-0 : crystal sequential number within a module ( 0 - 15 ) + + // Geometry v3 new DetID (all type 1 modules) + bit 15: kBTLNewFormat (0 - old BTLDetID, 1 - new BTLDetID) + bit 12-10: Readout unit number ( 1 - 6 ) + bit 9-6 : Detector Module ( 1 - 12 ) + bit 5 : Sensor Module inside DM ( 0 - 1 ) + bit 4-0 : Crystal number in a SM ( 1 - 16 ) */ class BTLDetId : public MTDDetId { public: - static constexpr uint32_t kBTLmoduleOffset = 10; - static constexpr uint32_t kBTLmoduleMask = 0x3F; - static constexpr uint32_t kBTLmodTypeOffset = 8; - static constexpr uint32_t kBTLmodTypeMask = 0x3; - static constexpr uint32_t kBTLRUOffset = 6; - static constexpr uint32_t kBTLRUMask = 0x3; + // old BTLDetID RU and module number scheme + static constexpr uint32_t kBTLoldModuleOffset = 10; + static constexpr uint32_t kBTLoldModuleMask = 0x3F; + static constexpr uint32_t kBTLoldModTypeOffset = 8; + static constexpr uint32_t kBTLoldModTypeMask = 0x3; + static constexpr uint32_t kBTLoldRUOffset = 6; + static constexpr uint32_t kBTLoldRUMask = 0x3; + + // New BTLDetID + static constexpr uint32_t kBTLRodOffset = 16; + static constexpr uint32_t kBTLRodMask = 0x3F; + static constexpr uint32_t kBTLRUOffset = 10; + static constexpr uint32_t kBTLRUMask = 0x7; + static constexpr uint32_t kBTLdetectorModOffset = 6; + static constexpr uint32_t kBTLdetectorModMask = 0xF; + static constexpr uint32_t kBTLsensorModOffset = 5; + static constexpr uint32_t kBTLsensorModMask = 0x1; static constexpr uint32_t kBTLCrystalOffset = 0; - static constexpr uint32_t kBTLCrystalMask = 0x3F; + static constexpr uint32_t kBTLCrystalMask = 0x1F; /// range constants, need two sets for the time being (one for tiles and one for bars) static constexpr uint32_t HALF_ROD = 36; static constexpr uint32_t kModulesPerRODBarPhiFlat = 48; static constexpr uint32_t kModulePerTypeBarPhiFlat = 48 / 3; static constexpr uint32_t kRUPerTypeV2 = 2; + static constexpr uint32_t kRUPerRod = 6; static constexpr uint32_t kModulesPerRUV2 = 24; + static constexpr uint32_t kDModulesPerRU = 12; + static constexpr uint32_t kSModulesPerDM = 2; + static constexpr uint32_t kDModulesInRUCol = 3; + static constexpr uint32_t kDModulesInRURow = 4; + static constexpr uint32_t kSModulesInDM = 2; static constexpr uint32_t kCrystalsPerModuleV2 = 16; static constexpr uint32_t kModulesPerTrkV2 = 3; static constexpr uint32_t kCrystalTypes = 3; + // conversion + static constexpr uint32_t kBTLoldFieldMask = 0x3FFFFF; + static constexpr uint32_t kBTLNewFormat = 1 << 15; + + // + // Number of crystals in BTL according to TDR design, valid also for barphiflat scenario: // 16 crystals x 24 modules x 2 readout units/type x 3 types x 36 rods/side x 2 sides // @@ -50,67 +82,120 @@ class BTLDetId : public MTDDetId { /** Construct a null id */ BTLDetId() : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) { id_ |= (MTDType::BTL & kMTDsubdMask) << kMTDsubdOffset; + id_ |= kBTLNewFormat; } /** Construct from a raw value */ - BTLDetId(const uint32_t& raw_id) : MTDDetId(raw_id) { ; } + BTLDetId(const uint32_t& raw_id) : MTDDetId(raw_id) { + uint32_t tmpId = raw_id; + if ((tmpId & kBTLNewFormat) == 0) { + tmpId = newForm(tmpId); + } + id_ = MTDDetId(tmpId).rawId(); + } /** Construct from generic DetId */ - BTLDetId(const DetId& det_id) : MTDDetId(det_id.rawId()) { ; } - - /** Construct from complete geometry information, v1 **/ - BTLDetId(uint32_t zside, uint32_t rod, uint32_t module, uint32_t modtyp, uint32_t crystal) - : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) { - id_ |= (MTDType::BTL & kMTDsubdMask) << kMTDsubdOffset | (zside & kZsideMask) << kZsideOffset | - (rod & kRodRingMask) << kRodRingOffset | (module & kBTLmoduleMask) << kBTLmoduleOffset | - (modtyp & kBTLmodTypeMask) << kBTLmodTypeOffset | ((crystal - 1) & kBTLCrystalMask) << kBTLCrystalOffset; + BTLDetId(const DetId& det_id) : MTDDetId(det_id.rawId()) { + uint32_t tmpId = det_id.rawId(); + if ((tmpId & kBTLNewFormat) == 0) { + tmpId = newForm(tmpId); + } + id_ = MTDDetId(tmpId).rawId(); } - /** Construct from complete geometry information, v2 **/ - BTLDetId(uint32_t zside, uint32_t rod, uint32_t runit, uint32_t module, uint32_t modtyp, uint32_t crystal) + /** Construct from complete geometry information, v2, v3 **/ + /** Geometry v1 is obsolete and not supported **/ + BTLDetId(uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodule, uint32_t crystal) : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) { + //RU, DM, SM & Xtal numbers start from 0 id_ |= (MTDType::BTL & kMTDsubdMask) << kMTDsubdOffset | (zside & kZsideMask) << kZsideOffset | - (rod & kRodRingMask) << kRodRingOffset | (module & kBTLmoduleMask) << kBTLmoduleOffset | - (modtyp & kBTLmodTypeMask) << kBTLmodTypeOffset | (runit & kBTLRUMask) << kBTLRUOffset | - ((crystal - 1) & kBTLCrystalMask) << kBTLCrystalOffset; + (rod & kRodRingMask) << kRodRingOffset | (runit & kBTLRUMask) << kBTLRUOffset | + (dmodule & kBTLdetectorModMask) << kBTLdetectorModOffset | + (smodule & kBTLsensorModMask) << kBTLsensorModOffset | + (crystal & kBTLCrystalMask) << kBTLCrystalOffset; + id_ |= kBTLNewFormat; } // ---------- Common methods ---------- - /** Returns BTL module number. */ - inline int module() const { return (id_ >> kBTLmoduleOffset) & kBTLmoduleMask; } + /** Returns BTL crystal number. */ + inline int crystal() const { return ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask);} - /** Returns BTL crystal type number. */ - inline int modType() const { return (id_ >> kBTLmodTypeOffset) & kBTLmodTypeMask; } + /** Returns BTL crystal number in construction database. */ + inline int crystalConsDB() const { + if (crystal() == kCrystalsPerModuleV2) return -1; + if (smodule() == 0) return kCrystalsPerModuleV2-1 - crystal() ; + else return crystal(); + } - /** Returns BTL crystal number. */ - inline int crystal() const { return ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask) + 1; } + /** Returns BTL detector module number. */ + inline int dmodule() const { return ((id_ >> kBTLdetectorModOffset) & kBTLdetectorModMask); } - /** Returns BTL readout unit number per type. */ - inline int runit() const { return (id_ >> kBTLRUOffset) & kBTLRUMask; } + /** Returns BTL sensor module number. */ + inline int smodule() const { return ((id_ >> kBTLsensorModOffset) & kBTLsensorModMask); } - /** Returns BTL global readout unit number. */ - inline int globalRunit() const { - if (runit() == 0) { - // pre-V2: build a RU identifier from available information - return (module() - 1) / kModulePerTypeBarPhiFlat / kRUPerTypeV2 + 1; - } else if (runit() > 0 && modType() > 0) { - // V2/V3: build global RU identifier from RU per type and type - return (modType() - 1) * kRUPerTypeV2 + runit(); - } - return 0; + /** Returns BTL module number [1-24] (OLD BTL NUMBERING). */ + inline int module() const { + int mod = ((dmodule() % kDModulesInRURow) * (kSModulesInDM * kDModulesInRUCol) + int(dmodule() / kDModulesInRURow) + kDModulesInRUCol * smodule()) + 1; + return mod; + } + + /** Returns BTL crystal type number [1-3] (OLD BTL NUMBERING). */ + inline int modType() const { + int gRU = runit(); + return int(gRU / kRUPerTypeV2 + 1); } + /** Returns BTL readout unit number per type [1-2], from Global RU number [1-6]. */ + inline int runitByType() const { return (runit() % kRUPerTypeV2); } + + /** Returns BTL global readout unit number. */ + inline int runit() const { return ((id_ >> kBTLRUOffset) & kBTLRUMask); } + /** return the row in GeomDet language **/ inline int row(unsigned nrows = kCrystalsPerModuleV2) const { - return (crystal() - 1) % nrows; // anything else for now + return crystal() % nrows; // anything else for now } /** return the column in GeomDetLanguage **/ - inline int column(unsigned nrows = kCrystalsPerModuleV2) const { return (crystal() - 1) / nrows; } + inline int column(unsigned nrows = kCrystalsPerModuleV2) const { return crystal() / nrows; } /** create a Geographical DetId for Tracking **/ BTLDetId geographicalId(CrysLayout lay) const; + + /** conversion from old to new BTLDetID**/ + uint32_t newForm(const uint32_t& rawid) { + uint32_t fixedP = rawid & (0xFFFFFFFF - kBTLoldFieldMask); // unchanged part of id + + // convert old tray number into new tray nymber + uint32_t oldTray = (rawid >> kBTLRodOffset) & kBTLRodMask; + uint32_t newTray = oldTray - 1; + + // convert old module number into detector module + sensor module numbers + uint32_t oldModule = (rawid >> kBTLoldModuleOffset) & kBTLoldModuleMask; + uint32_t detModule = int((oldModule - 1) % (kDModulesInRUCol)) * kDModulesInRURow + + int((oldModule - 1) / (kDModulesInRUCol * kSModulesInDM)); + uint32_t senModule = int((oldModule - 1) / kDModulesInRUCol) % kSModulesInDM; + + // change detector module number if on the negative side + int zside = int(mtdSide()); + if (zside < 1) detModule = detModule - 2 * kDModulesInRURow * (int(detModule/kDModulesInRURow) - 1); + + // convert old RU and type number into new RU number + uint32_t oldRU = (rawid >> kBTLoldRUOffset) & kBTLoldRUMask; + uint32_t oldType = (rawid >> kBTLoldModTypeOffset) & kBTLoldModTypeMask; + uint32_t newRU = ((oldType - 1) * kRUPerTypeV2) + (oldRU-1); + + // get crystal number + uint32_t crystal = (rawid & kBTLCrystalMask) >> kBTLCrystalOffset; + + // return new BTLDetID for v3 geom + return (fixedP | (newTray & kBTLRodMask) << kBTLRodOffset | (newRU & kBTLRUMask) << kBTLRUOffset | + (detModule & kBTLdetectorModMask) << kBTLdetectorModOffset | + (senModule & kBTLsensorModMask) << kBTLsensorModOffset | + ((crystal & kBTLCrystalMask) << kBTLCrystalOffset)) | + kBTLNewFormat; + } }; std::ostream& operator<<(std::ostream&, const BTLDetId&); diff --git a/DataFormats/ForwardDetId/src/BTLDetId.cc b/DataFormats/ForwardDetId/src/BTLDetId.cc index 7a3ab9461fbdc..a0c218bb9d543 100644 --- a/DataFormats/ForwardDetId/src/BTLDetId.cc +++ b/DataFormats/ForwardDetId/src/BTLDetId.cc @@ -1,15 +1,16 @@ #include "DataFormats/ForwardDetId/interface/BTLDetId.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" BTLDetId BTLDetId::geographicalId(CrysLayout lay) const { + // For tracking geometry navigation - - if (lay == CrysLayout::barphiflat) { - // barphiflat: count modules in a rod, combining all types - return BTLDetId(mtdSide(), mtdRR(), module() + kModulePerTypeBarPhiFlat * (modType() - 1), 0, 1); - } else if (lay == CrysLayout::v2 || lay == CrysLayout::v3) { - // v2: set number of crystals to 17 to distinguish from crystal BTLDetId - // v3: set number of crystals to 17 to distinguish from crystal BTLDetId, build V2-like type and RU number as in BTLNumberingScheme - return BTLDetId(mtdSide(), mtdRR(), runit(), module(), modType(), kCrystalsPerModuleV2 + 1); + // v2,v3: set number of crystals to 17 to distinguish from crystal BTLDetId + // v1: obsolete and not supported + + if (lay == CrysLayout::v2 || lay == CrysLayout::v3) { + return BTLDetId(mtdSide(), mtdRR(), runit(), dmodule(), smodule(), kCrystalsPerModuleV2); + } else { + edm::LogWarning("MTDGeom") << "CrysLayout could only be v2 or v3"; } return 0; @@ -20,12 +21,15 @@ BTLDetId BTLDetId::geographicalId(CrysLayout lay) const { std::ostream& operator<<(std::ostream& os, const BTLDetId& id) { os << (MTDDetId&)id; os << " BTL " << std::endl - << " Side : " << id.mtdSide() << std::endl - << " Rod : " << id.mtdRR() << std::endl - << " Crystal type: " << id.modType() << std::endl - << " Readout unit: " << id.runit() << std::endl - << " Global RU : " << id.globalRunit() << std::endl - << " Module : " << id.module() << std::endl - << " Crystal : " << id.crystal() << std::endl; + << " Side : " << id.mtdSide() << std::endl + << " Rod : " << id.mtdRR() << std::endl + << " Crystal type : " << id.modType() << std::endl // crystal type in v1 geometry scheme + << " Runit by Type : " << id.runitByType() << std::endl + << " Readout unit : " << id.runit() << std::endl + << " Detector module: " << id.dmodule() << std::endl + << " Sensor module : " << id.smodule() << std::endl + << " Module : " << id.module() << std::endl + << " Crystal : " << id.crystal() << std::endl + << " Crystal in ConsDB: " << id.crystalConsDB() << std::endl; return os; } diff --git a/DataFormats/ForwardDetId/src/classes_def.xml b/DataFormats/ForwardDetId/src/classes_def.xml index c61a79616422b..f35c116c0b3e9 100644 --- a/DataFormats/ForwardDetId/src/classes_def.xml +++ b/DataFormats/ForwardDetId/src/classes_def.xml @@ -23,8 +23,15 @@ - + + + + newForm(newObj->rawId())); + *newObj=tmp; + ]]> + diff --git a/DataFormats/TrackReco/src/HitPattern.cc b/DataFormats/TrackReco/src/HitPattern.cc index cdc722cc29679..17bc4d0eca57e 100644 --- a/DataFormats/TrackReco/src/HitPattern.cc +++ b/DataFormats/TrackReco/src/HitPattern.cc @@ -143,7 +143,7 @@ namespace { MTDDetId mtdid(id); switch (mtdid.mtdSubDetector()) { case MTDDetId::BTL: - layer = BTLDetId(id).globalRunit(); + layer = BTLDetId(id).runit(); break; case MTDDetId::ETL: layer = ETLDetId(id).mtdRR(); diff --git a/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h b/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h new file mode 100644 index 0000000000000..aa40cee120555 --- /dev/null +++ b/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h @@ -0,0 +1,80 @@ +#ifndef DATAFORMATS_BTLELECTRONICSMAPPING_H +#define DATAFORMATS_BTLELECTRONICSMAPPING_H 1 + +#include +#include + +#include "DataFormats/ForwardDetId/interface/BTLDetId.h" + +/** \brief BTL TOFHIR channel mapping with crystal BTLDetId + Convention: + SiPMside 0 == Minus Side + SiPMside 1 == Plus Side + */ + +class BTLElectronicsMapping { +public: + struct SiPMChPair { + int Minus; + int Plus; + }; + + struct TOFHIRChPair { + int Minus; + int Plus; + }; + + // Map SiPM Channel to crystal bars for Forward module orientation + static constexpr std::array SiPMChannelMapFW{ + {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}}; + // Map SiPM Channel to crystal bars for Backward module orientation + static constexpr std::array SiPMChannelMapBW{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16}}; + + // Map TOFHIR Channel to SiPM Channel + static constexpr std::array THChannelMap{ + {4, 1, 0, 3, 2, 6, 7, 9, 5, 11, 8, 12, 10, 14, 15, 13, + 17, 16, 18, 19, 20, 23, 21, 26, 22, 27, 28, 31, 30, 24, 25, 29}}; + + /** Default constructor -- invalid value */ + BTLElectronicsMapping(); + + // Get SiPM Channel number from crystal + int SiPMCh(uint32_t smodCopy, uint32_t crystal, uint32_t SiPMSide); + int SiPMCh(BTLDetId det, uint32_t SiPMSide); + int SiPMCh(uint32_t rawID, uint32_t SiPMSide); + + SiPMChPair GetSiPMChPair(uint32_t smodCopy, uint32_t crystal); + SiPMChPair GetSiPMChPair(BTLDetId det); + SiPMChPair GetSiPMChPair(uint32_t rawID); + + // Get TOFHIR Channel number from crystal + int TOFHIRCh(uint32_t smodCopy, uint32_t crystal, uint32_t SiPMSide); + int TOFHIRCh(BTLDetId det, uint32_t SiPMSide); + int TOFHIRCh(uint32_t rawID, uint32_t SiPMSide); + + TOFHIRChPair GetTOFHIRChPair(uint32_t smodCopy, uint32_t crystal); + TOFHIRChPair GetTOFHIRChPair(BTLDetId det); + TOFHIRChPair GetTOFHIRChPair(uint32_t rawID); + + // Get xtal from TOFHIR Channel number + int THChToXtal(uint32_t smodCopy, uint32_t THCh); + BTLDetId THChToBTLDetId(uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodCopy, uint32_t THCh); + // int BTLElectronicsMapping::SiPMChToXtal(uint32_t zside, uint32_t smodCopy, uint32_t SiPMCh); + + /** Returns TOFHIR ASIC number in construction database. */ + int TOFHIRASIC(uint32_t dmodule, uint32_t smodCopy); + int TOFHIRASIC(BTLDetId det); + int TOFHIRASIC(uint32_t rawID); + + /** Returns FE board number */ + int FEBoardFromDM(uint32_t dmodule); + int FEBoard(BTLDetId det); + int FEBoard(uint32_t rawID); + +private: +}; + +#endif diff --git a/Geometry/MTDCommonData/interface/BTLNumberingScheme.h b/Geometry/MTDCommonData/interface/BTLNumberingScheme.h index e19b25a57cf4a..09e7b166e142a 100644 --- a/Geometry/MTDCommonData/interface/BTLNumberingScheme.h +++ b/Geometry/MTDCommonData/interface/BTLNumberingScheme.h @@ -9,9 +9,6 @@ class BTLNumberingScheme : public MTDNumberingScheme { static constexpr uint32_t kBTLcrystalLevel = 9; static constexpr uint32_t kBTLmoduleLevel = 8; - static constexpr std::array negModCopy{ - {3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13, 18, 17, 16, 21, 20, 19, 24, 23, 22}}; - // to temporarily map V3 into V2-like input static constexpr std::array globalru2type{ {1, 1, 2, 2, 3, 3}}; diff --git a/Geometry/MTDCommonData/src/BTLElectronicsMapping.cc b/Geometry/MTDCommonData/src/BTLElectronicsMapping.cc new file mode 100644 index 0000000000000..f0105cc7ece80 --- /dev/null +++ b/Geometry/MTDCommonData/src/BTLElectronicsMapping.cc @@ -0,0 +1,198 @@ +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "Geometry/MTDCommonData/interface/BTLElectronicsMapping.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include +#include +#include +BTLElectronicsMapping::BTLElectronicsMapping() {} + +// Get SiPM Channel from crystal ID + +int BTLElectronicsMapping::SiPMCh(uint32_t smodCopy, uint32_t crystal, uint32_t SiPMSide) { + if (0 > int(crystal) || crystal > BTLDetId::kCrystalsPerModuleV2) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::BTLElectronicsMapping(): " + << "****************** Bad crystal number = " << int(crystal); + return 0; + } + + if (0 > int(smodCopy) || smodCopy > BTLDetId::kSModulesPerDM) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad detector module copy = " << int(smodCopy); + return 0; + } + + if (smodCopy == 0) + return BTLElectronicsMapping::SiPMChannelMapFW[crystal + SiPMSide * BTLDetId::kCrystalsPerModuleV2]; + else + return BTLElectronicsMapping::SiPMChannelMapBW[crystal + SiPMSide * BTLDetId::kCrystalsPerModuleV2]; +} + +int BTLElectronicsMapping::SiPMCh(BTLDetId det, uint32_t SiPMSide) { + uint32_t smodCopy = det.smodule(); + uint32_t crystal = det.crystal(); + + return BTLElectronicsMapping::SiPMCh(smodCopy, crystal, SiPMSide); +} + +int BTLElectronicsMapping::SiPMCh(uint32_t rawId, uint32_t SiPMSide) { + BTLDetId theId(rawId); + return BTLElectronicsMapping::SiPMCh(theId, SiPMSide); +} + +BTLElectronicsMapping::SiPMChPair BTLElectronicsMapping::GetSiPMChPair(uint32_t smodCopy, uint32_t crystal) { + BTLElectronicsMapping::SiPMChPair SiPMChs; + SiPMChs.Minus = BTLElectronicsMapping::SiPMCh(smodCopy, crystal, 0); + SiPMChs.Plus = BTLElectronicsMapping::SiPMCh(smodCopy, crystal, 1); + return SiPMChs; +} + +BTLElectronicsMapping::SiPMChPair BTLElectronicsMapping::GetSiPMChPair(BTLDetId det) { + BTLElectronicsMapping::SiPMChPair SiPMChs; + SiPMChs.Minus = BTLElectronicsMapping::SiPMCh(det, 0); + SiPMChs.Plus = BTLElectronicsMapping::SiPMCh(det, 1); + return SiPMChs; +} +BTLElectronicsMapping::SiPMChPair BTLElectronicsMapping::GetSiPMChPair(uint32_t rawID) { + BTLElectronicsMapping::SiPMChPair SiPMChs; + SiPMChs.Minus = BTLElectronicsMapping::SiPMCh(rawID, 0); + SiPMChs.Plus = BTLElectronicsMapping::SiPMCh(rawID, 1); + return SiPMChs; +} + +// Get TOFHIR Channel from crystal ID + +int BTLElectronicsMapping::TOFHIRCh(uint32_t smodCopy, uint32_t crystal, uint32_t SiPMSide) { + int SiPMCh_ = BTLElectronicsMapping::SiPMCh(smodCopy, crystal, SiPMSide); + return BTLElectronicsMapping::THChannelMap[SiPMCh_]; +} + +int BTLElectronicsMapping::TOFHIRCh(BTLDetId det, uint32_t SiPMSide) { + uint32_t smodCopy = det.smodule(); + uint32_t crystal = det.crystal(); + + return BTLElectronicsMapping::TOFHIRCh(smodCopy, crystal, SiPMSide); +} + +int BTLElectronicsMapping::TOFHIRCh(uint32_t rawId, uint32_t SiPMSide) { + BTLDetId theId(rawId); + return BTLElectronicsMapping::TOFHIRCh(theId, SiPMSide); +} + +BTLElectronicsMapping::TOFHIRChPair BTLElectronicsMapping::GetTOFHIRChPair(uint32_t smodCopy, uint32_t crystal) { + BTLElectronicsMapping::TOFHIRChPair TOFHIRChs; + TOFHIRChs.Minus = BTLElectronicsMapping::TOFHIRCh(smodCopy, crystal, 0); + TOFHIRChs.Plus = BTLElectronicsMapping::TOFHIRCh(smodCopy, crystal, 1); + return TOFHIRChs; +} + +BTLElectronicsMapping::TOFHIRChPair BTLElectronicsMapping::GetTOFHIRChPair(BTLDetId det) { + BTLElectronicsMapping::TOFHIRChPair TOFHIRChs; + TOFHIRChs.Minus = BTLElectronicsMapping::TOFHIRCh(det, 0); + TOFHIRChs.Plus = BTLElectronicsMapping::TOFHIRCh(det, 1); + return TOFHIRChs; +} +BTLElectronicsMapping::TOFHIRChPair BTLElectronicsMapping::GetTOFHIRChPair(uint32_t rawID) { + BTLElectronicsMapping::TOFHIRChPair TOFHIRChs; + TOFHIRChs.Minus = BTLElectronicsMapping::TOFHIRCh(rawID, 0); + TOFHIRChs.Plus = BTLElectronicsMapping::TOFHIRCh(rawID, 1); + return TOFHIRChs; +} + +// Get crystal ID from TOFHIR Channel + +int BTLElectronicsMapping::THChToXtal(uint32_t smodCopy, uint32_t THCh) { + if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM < smodCopy) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad detector module copy = " << int(smodCopy); + return 0; + } + + auto THChPos = + std::find(BTLElectronicsMapping::THChannelMap.begin(), BTLElectronicsMapping::THChannelMap.end(), THCh); + int targetSiPMCh = std::distance(BTLElectronicsMapping::THChannelMap.begin(), THChPos); + + std::array SiPMChMap; + if (smodCopy == 0) + SiPMChMap = BTLElectronicsMapping::SiPMChannelMapFW; + else + SiPMChMap = BTLElectronicsMapping::SiPMChannelMapBW; + + auto targetpos = std::find(SiPMChMap.begin(), SiPMChMap.end(), targetSiPMCh); + return std::distance(SiPMChMap.begin(), targetpos) % BTLDetId::kCrystalsPerModuleV2 + 1; +} + +BTLDetId BTLElectronicsMapping::THChToBTLDetId( + uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodCopy, uint32_t THCh) { + if (0 > int(THCh) || 31 < THCh) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad TOFHIR channel = " << int(THCh); + return 0; + } + + if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM < smodCopy) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad detector module copy = " << int(smodCopy); + return 0; + } + + if (0 > int(dmodule) || 12 < dmodule) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad module copy = " << int(dmodule); + return 0; + } + + if (1 > rod || 36 < rod) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad rod copy = " << rod; + return 0; + } + + if (1 < zside) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad side = " << zside; + return 0; + } + + int crystal = BTLElectronicsMapping::THChToXtal(smodCopy, THCh); + + return BTLDetId(zside, rod, runit, dmodule, smodCopy, crystal); +} + +// Get TOFHIR asic number +// if dmodule is odd number (DM range [1-12]) +// SM1 --> TOFHIR A0 (simply 0) +// SM2 --> TOFHIR A1 (simply 1) +// else if dmodule is even number the order is inverted +// SM1 --> TOFHIR A1 (simply 1) +// SM2 --> TOFHIR A0 (simply 0) +int BTLElectronicsMapping::TOFHIRASIC(uint32_t dmodule, uint32_t smodCopy) { + if (dmodule % BTLDetId::kSModulesInDM == 0) return smodCopy; + else return BTLDetId::kSModulesInDM - smodCopy - 1; + } + +int BTLElectronicsMapping::TOFHIRASIC(BTLDetId det) { + uint32_t dmodule = det.dmodule(); + uint32_t smodCopy = det.smodule(); + return BTLElectronicsMapping::TOFHIRASIC(dmodule, smodCopy); +} + +int BTLElectronicsMapping::TOFHIRASIC(uint32_t rawID) { + BTLDetId theId(rawID); + return BTLElectronicsMapping::TOFHIRASIC(theId); +} + + +/** Returns FE board number */ +int BTLElectronicsMapping::FEBoardFromDM(uint32_t dmodule) { return dmodule; } + +int BTLElectronicsMapping::FEBoard(BTLDetId det) { + uint32_t dmodule = det.dmodule(); + return BTLElectronicsMapping::FEBoardFromDM(dmodule); +} + +int BTLElectronicsMapping::FEBoard(uint32_t rawID) { + BTLDetId theId(rawID); + return BTLElectronicsMapping::FEBoard(theId); +} + diff --git a/Geometry/MTDCommonData/src/BTLNumberingScheme.cc b/Geometry/MTDCommonData/src/BTLNumberingScheme.cc index bd06ad10c7606..ae9dd8934052e 100644 --- a/Geometry/MTDCommonData/src/BTLNumberingScheme.cc +++ b/Geometry/MTDCommonData/src/BTLNumberingScheme.cc @@ -1,3 +1,5 @@ +#define EDM_ML_DEBUG + #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "Geometry/MTDCommonData/interface/BTLNumberingScheme.h" @@ -17,7 +19,7 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { LogDebug("MTDGeom") << "BTLNumberingScheme geometry levels = " << nLevels; - uint32_t zside(999), rodCopy(0), runitCopy(0), modCopy(0), modtyp(0), crystal(0); + uint32_t zside(999), rodCopy(0), runitCopy(0), modCopy(0), modtyp(0), crystal(0), dmodCopy(0), smodCopy(0); bool isDD4hepOK(false); if (nLevels == kBTLcrystalLevel + 1) { @@ -26,16 +28,13 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { } } -#ifdef EDM_ML_DEBUG - LogDebug("MTDGeom") << "BTLNumberingScheme::getUnitID(): isDD4hep " << isDD4hepOK; -#endif - auto bareBaseName = [&](std::string_view name) { size_t ipos = name.rfind('_'); return (isDD4hepOK) ? name.substr(0, ipos) : name; }; if (nLevels == kBTLcrystalLevel || isDD4hepOK) { + // barphiflat scenario LogDebug("MTDGeom") << bareBaseName(baseNumber.getLevelName(0)) << "[" << baseNumber.getCopyNumber(0) << "], " << bareBaseName(baseNumber.getLevelName(1)) << "[" << baseNumber.getCopyNumber(1) << "], " << bareBaseName(baseNumber.getLevelName(2)) << "[" << baseNumber.getCopyNumber(2) << "], " @@ -46,7 +45,6 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { << bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "], " << bareBaseName(baseNumber.getLevelName(8)) << "[" << baseNumber.getCopyNumber(8) << "]"; - // barphiflat scenario if (baseNumber.getLevelName(0).find("Timingactive") != std::string_view::npos) { crystal = baseNumber.getCopyNumber(0); @@ -106,70 +104,74 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { } else if (baseNumber.getLevelName(0).find("BTLCrystal") != std::string_view::npos) { // v2 or v3 scenario - crystal = baseNumber.getCopyNumber(0); - modCopy = baseNumber.getCopyNumber(1); - runitCopy = baseNumber.getCopyNumber(2); - rodCopy = baseNumber.getCopyNumber(3); - + // zside copy number const std::string_view& rodName(baseNumber.getLevelName(3)); // name of module volume uint32_t pos = rodName.find("Zpos"); zside = (pos <= rodName.size() ? 1 : 0); - // for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle - // in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side. - if (zside == 0) { - modCopy = negModCopy[modCopy - 1]; - } + // rod (tray) copy number + rodCopy = baseNumber.getCopyNumber(3) - 1; + + // RU, global module and crystal copy numbers + // (make everything start from 0) - bool isV2(bareBaseName(baseNumber.getLevelName(0)).back() != 'l'); - -#ifdef EDM_ML_DEBUG - LogDebug("MTDGeom") << "BTLNumberingScheme::getUnitID(): isV2 " << isV2; -#endif - - if (isV2) { - // V2: the type is embedded in crystal name + // V3: RU number is global RU number + runitCopy = baseNumber.getCopyNumber(2) - 1; + // V2: the type is embedded in crystal name and RU number is by type + if (bareBaseName(baseNumber.getLevelName(0)).back() != 'l') { modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(2)).back()); - } else { - // V3: build type and RU number per type from global RU number - modtyp = globalru2type[runitCopy - 1]; - runitCopy = globalru2ru[runitCopy - 1]; + runitCopy = (modtyp - 1) * BTLDetId::kRUPerTypeV2 + baseNumber.getCopyNumber(2) - 1; } + modCopy = int(baseNumber.getCopyNumber(1)) - 1; + crystal = int(baseNumber.getCopyNumber(0)) - 1; + + // Detector and sensor module numbers from global module number 0-23 + dmodCopy = int((modCopy / BTLDetId::kDModulesInRUCol) / BTLDetId::kSModulesInDM) + (modCopy % BTLDetId::kDModulesInRUCol) * BTLDetId::kDModulesInRURow; + smodCopy = int( modCopy / BTLDetId::kDModulesInRUCol ) % BTLDetId::kSModulesInDM; + // error checking + if (0 > int(crystal) || BTLDetId::kCrystalsPerModuleV2-1 < crystal) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad crystal number = " << int(crystal) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; + return 0; + } - if (1 > crystal || BTLDetId::kCrystalsPerModuleV2 < crystal) { + if (0 > int(modCopy) || BTLDetId::kModulesPerRUV2-1 < modCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad crystal number = " << crystal - << ", Volume Number = " << baseNumber.getCopyNumber(0); + << "****************** Bad module copy = " << int(modCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; return 0; } - if (1 > modtyp || 3 < modtyp) { + if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM-1 < smodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad RU name, Volume Name = " - << bareBaseName(baseNumber.getLevelName(2)); + << "****************** Bad detector module copy = " << int(smodCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; return 0; } - if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) { + if (0 > int(dmodCopy) || BTLDetId::kDModulesPerRU-1 < dmodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad module copy = " << modCopy - << ", Volume Number = " << baseNumber.getCopyNumber(1); + << "****************** Bad detector module copy = " << int(dmodCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; return 0; } - if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) { + if (0 > int(runitCopy) || BTLDetId::kRUPerRod-1 < runitCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad readout unit copy = " << runitCopy - << ", Volume Number = " << baseNumber.getCopyNumber(2); + << "****************** Bad readout unit copy = " << int(runitCopy) + << " module type = " << int(modtyp) + << ", Volume Name= " << baseNumber.getLevelName(2) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(2) - 1; return 0; } - if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) { + if (0 > int(rodCopy) || BTLDetId::HALF_ROD-1 < rodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad rod copy = " << rodCopy - << ", Volume Number = " << baseNumber.getCopyNumber(3); + << "****************** Bad rod copy = " << int(rodCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(3); return 0; } @@ -183,7 +185,7 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { // all inputs are fine. Go ahead and decode - BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, crystal); + BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, dmodCopy, smodCopy, crystal); intindex = thisBTLdetid.rawId(); } else if (nLevels == kBTLmoduleLevel && baseNumber.getLevelName(0).find("BTLModule") != std::string_view::npos) { @@ -198,62 +200,63 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { << bareBaseName(baseNumber.getLevelName(6)) << "[" << baseNumber.getCopyNumber(6) << "], " << bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "]"; - modCopy = baseNumber.getCopyNumber(0); - runitCopy = baseNumber.getCopyNumber(1); - rodCopy = baseNumber.getCopyNumber(2); - const std::string_view& rodName(baseNumber.getLevelName(2)); // name of module volume uint32_t pos = rodName.find("Zpos"); zside = (pos <= rodName.size() ? 1 : 0); - // for negative side swap module numbers betwee sides of the tray, so as to keep the same number for the same phi angle - // in the existing model. This introduces a misalignemtn between module number and volume copy for the negative side. - if (zside == 0) { - modCopy = negModCopy[modCopy - 1]; - } + // rod (tray) copy number + rodCopy = baseNumber.getCopyNumber(2) - 1; - bool isV2(bareBaseName(baseNumber.getLevelName(0)).back() != 'e'); + // RU, and global module copy numbers + // (make everything start from 0) -#ifdef EDM_ML_DEBUG - LogDebug("MTDGeom") << "BTLNumberingScheme::getUnitID(): isV2 " << isV2; -#endif - - if (isV2) { - // V2: the type is embedded in crystal name + // V3: RU number is global RU number + runitCopy = baseNumber.getCopyNumber(1) - 1; + // V2: the type is embedded in crystal name and RU number is by type + if (bareBaseName(baseNumber.getLevelName(0)).back() != 'e') { modtyp = ::atoi(&bareBaseName(baseNumber.getLevelName(1)).back()); - } else { - // V3: build type and RU number per type from global RU number - modtyp = globalru2type[runitCopy - 1]; - runitCopy = globalru2ru[runitCopy - 1]; + runitCopy = (modtyp - 1) * BTLDetId::kRUPerTypeV2 + baseNumber.getCopyNumber(1) - 1; } + modCopy = baseNumber.getCopyNumber(0) - 1; + + // eval detector and sensor module numbers from global module number 1-24 + dmodCopy = int((modCopy / BTLDetId::kDModulesInRUCol) / BTLDetId::kSModulesInDM) + (modCopy % BTLDetId::kDModulesInRUCol) * BTLDetId::kDModulesInRURow; + smodCopy = int( modCopy / BTLDetId::kDModulesInRUCol) % BTLDetId::kSModulesInDM; // error checking - if (1 > modtyp || 3 < modtyp) { + if (0 > int(modCopy) || BTLDetId::kModulesPerRUV2-1 < modCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad RU name, Volume Name = " - << bareBaseName(baseNumber.getLevelName(1)); + << "****************** Bad module copy = " << int(modCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; return 0; } - if (1 > modCopy || BTLDetId::kModulesPerRUV2 < modCopy) { + if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM-1 < smodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad module copy = " << modCopy - << ", Volume Number = " << baseNumber.getCopyNumber(0); + << "****************** Bad detector module copy = " << int(smodCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; return 0; } - if (1 > runitCopy || BTLDetId::kRUPerTypeV2 < runitCopy) { + if (0 > int(dmodCopy) || BTLDetId::kDModulesPerRU-1 < dmodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad readout unit copy = " << runitCopy - << ", Volume Number = " << baseNumber.getCopyNumber(1); + << "****************** Bad detector module copy = " << int(dmodCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; return 0; } - if (1 > rodCopy || BTLDetId::HALF_ROD < rodCopy) { + if (0 > int(runitCopy) || BTLDetId::kRUPerRod-1 < runitCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad rod copy = " << rodCopy - << ", Volume Number = " << baseNumber.getCopyNumber(2); + << "****************** Bad readout unit copy = " << int(runitCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; + return 0; + } + + if (0 > int(rodCopy) || BTLDetId::HALF_ROD-1 < rodCopy) { + edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " + << "****************** Bad rod copy = " << int(rodCopy) + << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(2); return 0; } @@ -265,8 +268,7 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { } // all inputs are fine. Go ahead and decode - - BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, modCopy, modtyp, 0); + BTLDetId thisBTLdetid(zside, rodCopy, runitCopy, dmodCopy, smodCopy, 0); intindex = thisBTLdetid.geographicalId(BTLDetId::CrysLayout::v2).rawId(); } else { @@ -277,8 +279,8 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { } LogDebug("MTDGeom") << "BTL Numbering scheme: " - << " zside = " << zside << " rod = " << rodCopy << " modtyp = " << modtyp << " RU = " << runitCopy - << " module = " << modCopy << " crystal = " << crystal << " Raw Id = " << intindex << "\n" + << " Raw Id = " << intindex << " zside = " << zside << " rod = " << rodCopy << " runit = " << runitCopy + << " dmodule = " << dmodCopy << " smodule = " << smodCopy << " module = " << modCopy+1 << " crystal = " << crystal << "\n" << BTLDetId(intindex); return intindex; diff --git a/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc b/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc index f8720bafec958..31cc46fdc9737 100644 --- a/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc +++ b/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc @@ -294,9 +294,9 @@ void DD4hep_TestPixelTopology::analyze(const edm::Event& iEvent, const edm::Even if (isBarrel) { edm::LogVerbatim("DD4hep_TestPixelTopology") << "geoId= " << modIdBTL.rawId() << " side= " << modIdBTL.mtdSide() - << " RU/mod= " << modIdBTL.globalRunit() << " / " << modIdBTL.module(); + << " RU/mod= " << modIdBTL.runit() << " / " << modIdBTL.module(); sunitt_ << "geoId= " << modIdBTL.rawId() << " side= " << modIdBTL.mtdSide() - << " RU/mod= " << modIdBTL.globalRunit() << " / " << modIdBTL.module(); + << " RU/mod= " << modIdBTL.runit() << " / " << modIdBTL.module(); } else { edm::LogVerbatim("DD4hep_TestPixelTopology") << "geoId= " << modIdETL.rawId() << " side= " << modIdETL.mtdSide() @@ -412,12 +412,12 @@ void DD4hep_TestPixelTopology::analyze(const edm::Event& iEvent, const edm::Even if (isBarrel) { edm::LogVerbatim("DD4hep_TestPixelTopology") << "rawId= " << theIdBTL.rawId() << " geoId= " << geoId.rawId() << " side/rod= " << theIdBTL.mtdSide() - << " / " << theIdBTL.mtdRR() << " RU= " << theIdBTL.globalRunit() + << " / " << theIdBTL.mtdRR() << " RU= " << theIdBTL.runit() << " module/geomodule= " << theIdBTL.module() << " / " << static_cast(geoId).module() << " crys= " << theIdBTL.crystal() << " BTLDetId row/col= " << origRow << " / " << origCol << "\n"; sunitt_ << "rawId= " << theIdBTL.rawId() << " geoId= " << geoId.rawId() << " side/rod= " << theIdBTL.mtdSide() << " / " << theIdBTL.mtdRR() - << " RU= " << theIdBTL.globalRunit() << " module/geomodule= " << theIdBTL.module() << " / " + << " RU= " << theIdBTL.runit() << " module/geomodule= " << theIdBTL.module() << " / " << static_cast(geoId).module() << " crys= " << theIdBTL.crystal() << " BTLDetId row/col= " << origRow << " / " << origCol << "\n"; } else { diff --git a/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc b/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc index 2554b25a89881..9c03f0fd1cdda 100644 --- a/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc +++ b/Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc @@ -148,10 +148,10 @@ GeometricTimingDet* CmsMTDConstruction::buildSubdet(FilteredView& GeometricTimingDet* subdet = new GeometricTimingDet(&fv, thisDet); if (thisDet == GeometricTimingDet::BTL) { - subdet->setGeographicalID(BTLDetId(0, 0, 0, 0, 0)); + subdet->setGeographicalID(BTLDetId(0, 0, 0, 0, 0, 0)); } else if (thisDet == GeometricTimingDet::ETL) { const uint32_t side = subdet->translation().z() > 0 ? 1 : 0; - subdet->setGeographicalID(ETLDetId(side, 0, 0, 0, 0)); + subdet->setGeographicalID(ETLDetId(side, 0, 0, 0, 0, 0)); } else { throw cms::Exception("CmsMTDConstruction") << " ERROR - I was expecting a SubDet, I got a " << fv.name(); } From 32a553bc31003e5ec7745f744c2749af854f61b6 Mon Sep 17 00:00:00 2001 From: cquarant Date: Tue, 17 Dec 2024 11:47:04 +0100 Subject: [PATCH 3/5] removed useless portion of code, add error message if BTL v1 geometry used --- .../interface/BTLElectronicsMapping.h | 1 - .../MTDCommonData/src/BTLNumberingScheme.cc | 62 ++----------------- 2 files changed, 4 insertions(+), 59 deletions(-) diff --git a/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h b/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h index aa40cee120555..42af8cde77e75 100644 --- a/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h +++ b/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h @@ -62,7 +62,6 @@ class BTLElectronicsMapping { // Get xtal from TOFHIR Channel number int THChToXtal(uint32_t smodCopy, uint32_t THCh); BTLDetId THChToBTLDetId(uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodCopy, uint32_t THCh); - // int BTLElectronicsMapping::SiPMChToXtal(uint32_t zside, uint32_t smodCopy, uint32_t SiPMCh); /** Returns TOFHIR ASIC number in construction database. */ int TOFHIRASIC(uint32_t dmodule, uint32_t smodCopy); diff --git a/Geometry/MTDCommonData/src/BTLNumberingScheme.cc b/Geometry/MTDCommonData/src/BTLNumberingScheme.cc index ae9dd8934052e..7bfd69e578c68 100644 --- a/Geometry/MTDCommonData/src/BTLNumberingScheme.cc +++ b/Geometry/MTDCommonData/src/BTLNumberingScheme.cc @@ -47,60 +47,8 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { if (baseNumber.getLevelName(0).find("Timingactive") != std::string_view::npos) { - crystal = baseNumber.getCopyNumber(0); - - modCopy = baseNumber.getCopyNumber(2); - rodCopy = baseNumber.getCopyNumber(3); - - const std::string_view& modName(baseNumber.getLevelName(2)); // name of module volume - uint32_t pos = modName.find("Positive"); - - zside = (pos <= modName.size() ? 1 : 0); - std::string_view baseName = modName.substr(modName.find(':') + 1); - - modtyp = ::atoi(&baseName.at(7)); - if (modtyp == 17) { - modtyp = 2; - } else if (modtyp == 33) { - modtyp = 3; - } - - // error checking - - if (1 > crystal || 64 < crystal) { - edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad crystal number = " << crystal - << ", Volume Number = " << baseNumber.getCopyNumber(0); - return 0; - } - - if (1 > modtyp || 3 < modtyp) { - edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad module name = " << modName - << ", Volume Name = " << baseNumber.getLevelName(2); - return 0; - } - - if (1 > modCopy || 54 < modCopy) { - edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad module copy = " << modCopy - << ", Volume Number = " << baseNumber.getCopyNumber(2); - return 0; - } - - if (1 > rodCopy || 36 < rodCopy) { - edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad rod copy = " << rodCopy - << ", Volume Number = " << baseNumber.getCopyNumber(4); - return 0; - } - - if (1 < zside) { - edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " - << "****************** Bad side = " << zside - << ", Volume Name = " << baseNumber.getLevelName(2); - return 0; - } + edm::LogError("MTDGeom") << "Geometry v1 of BTL not supported, run on a Geometry configuration D95 or latest "; + throw cms::Exception("Configuration") << "Invalid BTL Geometry configuration (v1)"; } else if (baseNumber.getLevelName(0).find("BTLCrystal") != std::string_view::npos) { // v2 or v3 scenario @@ -113,8 +61,7 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { rodCopy = baseNumber.getCopyNumber(3) - 1; // RU, global module and crystal copy numbers - // (make everything start from 0) - + // (everything start from 0) // V3: RU number is global RU number runitCopy = baseNumber.getCopyNumber(2) - 1; // V2: the type is embedded in crystal name and RU number is by type @@ -208,8 +155,7 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { rodCopy = baseNumber.getCopyNumber(2) - 1; // RU, and global module copy numbers - // (make everything start from 0) - + // (everything start from 0) // V3: RU number is global RU number runitCopy = baseNumber.getCopyNumber(1) - 1; // V2: the type is embedded in crystal name and RU number is by type From 6a8a23ade30f5336180de85e5a3dc82b2e73be65 Mon Sep 17 00:00:00 2001 From: cquarant Date: Tue, 17 Dec 2024 15:46:24 +0100 Subject: [PATCH 4/5] updated dummy constructor to new BTLDetId constructor --- RecoMTD/DetLayers/src/MTDDetLayerGeometry.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoMTD/DetLayers/src/MTDDetLayerGeometry.cc b/RecoMTD/DetLayers/src/MTDDetLayerGeometry.cc index 5472945566382..66bda88bc4a05 100644 --- a/RecoMTD/DetLayers/src/MTDDetLayerGeometry.cc +++ b/RecoMTD/DetLayers/src/MTDDetLayerGeometry.cc @@ -78,7 +78,7 @@ DetId MTDDetLayerGeometry::makeDetLayerId(const DetLayer* detLayer) const { return ETLDetId(id.mtdSide(), 0, 0, 0, 0); // Constructor of new geometry is compatible with prev8 } else if (detLayer->subDetector() == GeomDetEnumerators::TimingBarrel) { BTLDetId id(detLayer->basicComponents().front()->geographicalId().rawId()); - return BTLDetId(id.mtdSide(), 0, 0, 0, 0); + return BTLDetId(id.mtdSide(), 0, 0, 0, 0, 0); } else throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module(); } @@ -108,7 +108,7 @@ const DetLayer* MTDDetLayerGeometry::idToLayer(const DetId& id) const { idout = ETLDetId(etlId.mtdSide(), 0, 0, 0, 0); } else if (detId.mtdSubDetector() == 1) { // 1 is BTL BTLDetId btlId(detId.rawId()); - idout = BTLDetId(btlId.mtdSide(), 0, 0, 0, 0); + idout = BTLDetId(btlId.mtdSide(), 0, 0, 0, 0, 0); } else throw cms::Exception("InvalidSubdetId") << detId.subdetId(); From 2413b698843175b2c33a6cef6f9912578fde0f9a Mon Sep 17 00:00:00 2001 From: cquarant Date: Tue, 17 Dec 2024 16:55:25 +0100 Subject: [PATCH 5/5] code formatting --- DataFormats/ForwardDetId/interface/BTLDetId.h | 35 +++++++++------- DataFormats/ForwardDetId/src/BTLDetId.cc | 5 +-- .../interface/BTLElectronicsMapping.h | 5 ++- .../src/BTLElectronicsMapping.cc | 14 +++---- .../MTDCommonData/src/BTLNumberingScheme.cc | 40 ++++++++++--------- .../test/DD4hep_TestPixelTopology.cc | 12 +++--- 6 files changed, 59 insertions(+), 52 deletions(-) diff --git a/DataFormats/ForwardDetId/interface/BTLDetId.h b/DataFormats/ForwardDetId/interface/BTLDetId.h index 3b2337cb7e982..dacc25bb13fbb 100644 --- a/DataFormats/ForwardDetId/interface/BTLDetId.h +++ b/DataFormats/ForwardDetId/interface/BTLDetId.h @@ -67,7 +67,7 @@ class BTLDetId : public MTDDetId { static constexpr uint32_t kBTLoldFieldMask = 0x3FFFFF; static constexpr uint32_t kBTLNewFormat = 1 << 15; - // + // // Number of crystals in BTL according to TDR design, valid also for barphiflat scenario: // 16 crystals x 24 modules x 2 readout units/type x 3 types x 36 rods/side x 2 sides @@ -111,21 +111,23 @@ class BTLDetId : public MTDDetId { id_ |= (MTDType::BTL & kMTDsubdMask) << kMTDsubdOffset | (zside & kZsideMask) << kZsideOffset | (rod & kRodRingMask) << kRodRingOffset | (runit & kBTLRUMask) << kBTLRUOffset | (dmodule & kBTLdetectorModMask) << kBTLdetectorModOffset | - (smodule & kBTLsensorModMask) << kBTLsensorModOffset | - (crystal & kBTLCrystalMask) << kBTLCrystalOffset; + (smodule & kBTLsensorModMask) << kBTLsensorModOffset | (crystal & kBTLCrystalMask) << kBTLCrystalOffset; id_ |= kBTLNewFormat; } // ---------- Common methods ---------- /** Returns BTL crystal number. */ - inline int crystal() const { return ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask);} + inline int crystal() const { return ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask); } /** Returns BTL crystal number in construction database. */ - inline int crystalConsDB() const { - if (crystal() == kCrystalsPerModuleV2) return -1; - if (smodule() == 0) return kCrystalsPerModuleV2-1 - crystal() ; - else return crystal(); + inline int crystalConsDB() const { + if (crystal() == kCrystalsPerModuleV2) + return -1; + if (smodule() == 0) + return kCrystalsPerModuleV2 - 1 - crystal(); + else + return crystal(); } /** Returns BTL detector module number. */ @@ -136,7 +138,9 @@ class BTLDetId : public MTDDetId { /** Returns BTL module number [1-24] (OLD BTL NUMBERING). */ inline int module() const { - int mod = ((dmodule() % kDModulesInRURow) * (kSModulesInDM * kDModulesInRUCol) + int(dmodule() / kDModulesInRURow) + kDModulesInRUCol * smodule()) + 1; + int mod = ((dmodule() % kDModulesInRURow) * (kSModulesInDM * kDModulesInRUCol) + int(dmodule() / kDModulesInRURow) + + kDModulesInRUCol * smodule()) + + 1; return mod; } @@ -173,28 +177,29 @@ class BTLDetId : public MTDDetId { // convert old module number into detector module + sensor module numbers uint32_t oldModule = (rawid >> kBTLoldModuleOffset) & kBTLoldModuleMask; - uint32_t detModule = int((oldModule - 1) % (kDModulesInRUCol)) * kDModulesInRURow + + uint32_t detModule = int((oldModule - 1) % (kDModulesInRUCol)) * kDModulesInRURow + int((oldModule - 1) / (kDModulesInRUCol * kSModulesInDM)); - uint32_t senModule = int((oldModule - 1) / kDModulesInRUCol) % kSModulesInDM; + uint32_t senModule = int((oldModule - 1) / kDModulesInRUCol) % kSModulesInDM; // change detector module number if on the negative side int zside = int(mtdSide()); - if (zside < 1) detModule = detModule - 2 * kDModulesInRURow * (int(detModule/kDModulesInRURow) - 1); + if (zside < 1) + detModule = detModule - 2 * kDModulesInRURow * (int(detModule / kDModulesInRURow) - 1); // convert old RU and type number into new RU number uint32_t oldRU = (rawid >> kBTLoldRUOffset) & kBTLoldRUMask; uint32_t oldType = (rawid >> kBTLoldModTypeOffset) & kBTLoldModTypeMask; - uint32_t newRU = ((oldType - 1) * kRUPerTypeV2) + (oldRU-1); + uint32_t newRU = ((oldType - 1) * kRUPerTypeV2) + (oldRU - 1); // get crystal number uint32_t crystal = (rawid & kBTLCrystalMask) >> kBTLCrystalOffset; // return new BTLDetID for v3 geom - return (fixedP | (newTray & kBTLRodMask) << kBTLRodOffset | (newRU & kBTLRUMask) << kBTLRUOffset | + return (fixedP | (newTray & kBTLRodMask) << kBTLRodOffset | (newRU & kBTLRUMask) << kBTLRUOffset | (detModule & kBTLdetectorModMask) << kBTLdetectorModOffset | (senModule & kBTLsensorModMask) << kBTLsensorModOffset | ((crystal & kBTLCrystalMask) << kBTLCrystalOffset)) | - kBTLNewFormat; + kBTLNewFormat; } }; diff --git a/DataFormats/ForwardDetId/src/BTLDetId.cc b/DataFormats/ForwardDetId/src/BTLDetId.cc index a0c218bb9d543..b865f2f1efab5 100644 --- a/DataFormats/ForwardDetId/src/BTLDetId.cc +++ b/DataFormats/ForwardDetId/src/BTLDetId.cc @@ -2,11 +2,10 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" BTLDetId BTLDetId::geographicalId(CrysLayout lay) const { - // For tracking geometry navigation // v2,v3: set number of crystals to 17 to distinguish from crystal BTLDetId // v1: obsolete and not supported - + if (lay == CrysLayout::v2 || lay == CrysLayout::v3) { return BTLDetId(mtdSide(), mtdRR(), runit(), dmodule(), smodule(), kCrystalsPerModuleV2); } else { @@ -23,7 +22,7 @@ std::ostream& operator<<(std::ostream& os, const BTLDetId& id) { os << " BTL " << std::endl << " Side : " << id.mtdSide() << std::endl << " Rod : " << id.mtdRR() << std::endl - << " Crystal type : " << id.modType() << std::endl // crystal type in v1 geometry scheme + << " Crystal type : " << id.modType() << std::endl // crystal type in v1 geometry scheme << " Runit by Type : " << id.runitByType() << std::endl << " Readout unit : " << id.runit() << std::endl << " Detector module: " << id.dmodule() << std::endl diff --git a/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h b/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h index 42af8cde77e75..9fa4dfaf0ac6f 100644 --- a/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h +++ b/Geometry/MTDCommonData/interface/BTLElectronicsMapping.h @@ -31,7 +31,7 @@ class BTLElectronicsMapping { // Map SiPM Channel to crystal bars for Backward module orientation static constexpr std::array SiPMChannelMapBW{ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16}}; + 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16}}; // Map TOFHIR Channel to SiPM Channel static constexpr std::array THChannelMap{ @@ -61,7 +61,8 @@ class BTLElectronicsMapping { // Get xtal from TOFHIR Channel number int THChToXtal(uint32_t smodCopy, uint32_t THCh); - BTLDetId THChToBTLDetId(uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodCopy, uint32_t THCh); + BTLDetId THChToBTLDetId( + uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodCopy, uint32_t THCh); /** Returns TOFHIR ASIC number in construction database. */ int TOFHIRASIC(uint32_t dmodule, uint32_t smodCopy); diff --git a/Geometry/MTDCommonData/src/BTLElectronicsMapping.cc b/Geometry/MTDCommonData/src/BTLElectronicsMapping.cc index f0105cc7ece80..f751fbd411033 100644 --- a/Geometry/MTDCommonData/src/BTLElectronicsMapping.cc +++ b/Geometry/MTDCommonData/src/BTLElectronicsMapping.cc @@ -160,16 +160,18 @@ BTLDetId BTLElectronicsMapping::THChToBTLDetId( } // Get TOFHIR asic number -// if dmodule is odd number (DM range [1-12]) +// if dmodule is odd number (DM range [1-12]) // SM1 --> TOFHIR A0 (simply 0) // SM2 --> TOFHIR A1 (simply 1) // else if dmodule is even number the order is inverted // SM1 --> TOFHIR A1 (simply 1) // SM2 --> TOFHIR A0 (simply 0) -int BTLElectronicsMapping::TOFHIRASIC(uint32_t dmodule, uint32_t smodCopy) { - if (dmodule % BTLDetId::kSModulesInDM == 0) return smodCopy; - else return BTLDetId::kSModulesInDM - smodCopy - 1; - } +int BTLElectronicsMapping::TOFHIRASIC(uint32_t dmodule, uint32_t smodCopy) { + if (dmodule % BTLDetId::kSModulesInDM == 0) + return smodCopy; + else + return BTLDetId::kSModulesInDM - smodCopy - 1; +} int BTLElectronicsMapping::TOFHIRASIC(BTLDetId det) { uint32_t dmodule = det.dmodule(); @@ -182,7 +184,6 @@ int BTLElectronicsMapping::TOFHIRASIC(uint32_t rawID) { return BTLElectronicsMapping::TOFHIRASIC(theId); } - /** Returns FE board number */ int BTLElectronicsMapping::FEBoardFromDM(uint32_t dmodule) { return dmodule; } @@ -195,4 +196,3 @@ int BTLElectronicsMapping::FEBoard(uint32_t rawID) { BTLDetId theId(rawID); return BTLElectronicsMapping::FEBoard(theId); } - diff --git a/Geometry/MTDCommonData/src/BTLNumberingScheme.cc b/Geometry/MTDCommonData/src/BTLNumberingScheme.cc index 7bfd69e578c68..11815440c7cd6 100644 --- a/Geometry/MTDCommonData/src/BTLNumberingScheme.cc +++ b/Geometry/MTDCommonData/src/BTLNumberingScheme.cc @@ -45,7 +45,6 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { << bareBaseName(baseNumber.getLevelName(7)) << "[" << baseNumber.getCopyNumber(7) << "], " << bareBaseName(baseNumber.getLevelName(8)) << "[" << baseNumber.getCopyNumber(8) << "]"; - if (baseNumber.getLevelName(0).find("Timingactive") != std::string_view::npos) { edm::LogError("MTDGeom") << "Geometry v1 of BTL not supported, run on a Geometry configuration D95 or latest "; throw cms::Exception("Configuration") << "Invalid BTL Geometry configuration (v1)"; @@ -59,7 +58,7 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { // rod (tray) copy number rodCopy = baseNumber.getCopyNumber(3) - 1; - + // RU, global module and crystal copy numbers // (everything start from 0) // V3: RU number is global RU number @@ -74,39 +73,40 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { crystal = int(baseNumber.getCopyNumber(0)) - 1; // Detector and sensor module numbers from global module number 0-23 - dmodCopy = int((modCopy / BTLDetId::kDModulesInRUCol) / BTLDetId::kSModulesInDM) + (modCopy % BTLDetId::kDModulesInRUCol) * BTLDetId::kDModulesInRURow; - smodCopy = int( modCopy / BTLDetId::kDModulesInRUCol ) % BTLDetId::kSModulesInDM; + dmodCopy = int((modCopy / BTLDetId::kDModulesInRUCol) / BTLDetId::kSModulesInDM) + + (modCopy % BTLDetId::kDModulesInRUCol) * BTLDetId::kDModulesInRURow; + smodCopy = int(modCopy / BTLDetId::kDModulesInRUCol) % BTLDetId::kSModulesInDM; // error checking - if (0 > int(crystal) || BTLDetId::kCrystalsPerModuleV2-1 < crystal) { + if (0 > int(crystal) || BTLDetId::kCrystalsPerModuleV2 - 1 < crystal) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad crystal number = " << int(crystal) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; return 0; } - if (0 > int(modCopy) || BTLDetId::kModulesPerRUV2-1 < modCopy) { + if (0 > int(modCopy) || BTLDetId::kModulesPerRUV2 - 1 < modCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad module copy = " << int(modCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; return 0; } - if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM-1 < smodCopy) { + if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM - 1 < smodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad detector module copy = " << int(smodCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; return 0; } - if (0 > int(dmodCopy) || BTLDetId::kDModulesPerRU-1 < dmodCopy) { + if (0 > int(dmodCopy) || BTLDetId::kDModulesPerRU - 1 < dmodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad detector module copy = " << int(dmodCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; return 0; } - if (0 > int(runitCopy) || BTLDetId::kRUPerRod-1 < runitCopy) { + if (0 > int(runitCopy) || BTLDetId::kRUPerRod - 1 < runitCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad readout unit copy = " << int(runitCopy) << " module type = " << int(modtyp) @@ -115,7 +115,7 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { return 0; } - if (0 > int(rodCopy) || BTLDetId::HALF_ROD-1 < rodCopy) { + if (0 > int(rodCopy) || BTLDetId::HALF_ROD - 1 < rodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad rod copy = " << int(rodCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(3); @@ -166,40 +166,41 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { modCopy = baseNumber.getCopyNumber(0) - 1; // eval detector and sensor module numbers from global module number 1-24 - dmodCopy = int((modCopy / BTLDetId::kDModulesInRUCol) / BTLDetId::kSModulesInDM) + (modCopy % BTLDetId::kDModulesInRUCol) * BTLDetId::kDModulesInRURow; - smodCopy = int( modCopy / BTLDetId::kDModulesInRUCol) % BTLDetId::kSModulesInDM; + dmodCopy = int((modCopy / BTLDetId::kDModulesInRUCol) / BTLDetId::kSModulesInDM) + + (modCopy % BTLDetId::kDModulesInRUCol) * BTLDetId::kDModulesInRURow; + smodCopy = int(modCopy / BTLDetId::kDModulesInRUCol) % BTLDetId::kSModulesInDM; // error checking - if (0 > int(modCopy) || BTLDetId::kModulesPerRUV2-1 < modCopy) { + if (0 > int(modCopy) || BTLDetId::kModulesPerRUV2 - 1 < modCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad module copy = " << int(modCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; return 0; } - if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM-1 < smodCopy) { + if (0 > int(smodCopy) || BTLDetId::kSModulesPerDM - 1 < smodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad detector module copy = " << int(smodCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; return 0; } - if (0 > int(dmodCopy) || BTLDetId::kDModulesPerRU-1 < dmodCopy) { + if (0 > int(dmodCopy) || BTLDetId::kDModulesPerRU - 1 < dmodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad detector module copy = " << int(dmodCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(0) - 1; return 0; } - if (0 > int(runitCopy) || BTLDetId::kRUPerRod-1 < runitCopy) { + if (0 > int(runitCopy) || BTLDetId::kRUPerRod - 1 < runitCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad readout unit copy = " << int(runitCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(1) - 1; return 0; } - if (0 > int(rodCopy) || BTLDetId::HALF_ROD-1 < rodCopy) { + if (0 > int(rodCopy) || BTLDetId::HALF_ROD - 1 < rodCopy) { edm::LogWarning("MTDGeom") << "BTLNumberingScheme::getUnitID(): " << "****************** Bad rod copy = " << int(rodCopy) << ", Volume Number (counting from 0)= " << baseNumber.getCopyNumber(2); @@ -225,8 +226,9 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const { } LogDebug("MTDGeom") << "BTL Numbering scheme: " - << " Raw Id = " << intindex << " zside = " << zside << " rod = " << rodCopy << " runit = " << runitCopy - << " dmodule = " << dmodCopy << " smodule = " << smodCopy << " module = " << modCopy+1 << " crystal = " << crystal << "\n" + << " Raw Id = " << intindex << " zside = " << zside << " rod = " << rodCopy + << " runit = " << runitCopy << " dmodule = " << dmodCopy << " smodule = " << smodCopy + << " module = " << modCopy + 1 << " crystal = " << crystal << "\n" << BTLDetId(intindex); return intindex; diff --git a/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc b/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc index 31cc46fdc9737..64317d821e7b5 100644 --- a/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc +++ b/Geometry/MTDGeometryBuilder/test/DD4hep_TestPixelTopology.cc @@ -293,8 +293,8 @@ void DD4hep_TestPixelTopology::analyze(const edm::Event& iEvent, const edm::Even if (isBarrel) { edm::LogVerbatim("DD4hep_TestPixelTopology") - << "geoId= " << modIdBTL.rawId() << " side= " << modIdBTL.mtdSide() - << " RU/mod= " << modIdBTL.runit() << " / " << modIdBTL.module(); + << "geoId= " << modIdBTL.rawId() << " side= " << modIdBTL.mtdSide() << " RU/mod= " << modIdBTL.runit() + << " / " << modIdBTL.module(); sunitt_ << "geoId= " << modIdBTL.rawId() << " side= " << modIdBTL.mtdSide() << " RU/mod= " << modIdBTL.runit() << " / " << modIdBTL.module(); } else { @@ -416,10 +416,10 @@ void DD4hep_TestPixelTopology::analyze(const edm::Event& iEvent, const edm::Even << " module/geomodule= " << theIdBTL.module() << " / " << static_cast(geoId).module() << " crys= " << theIdBTL.crystal() << " BTLDetId row/col= " << origRow << " / " << origCol << "\n"; sunitt_ << "rawId= " << theIdBTL.rawId() << " geoId= " << geoId.rawId() - << " side/rod= " << theIdBTL.mtdSide() << " / " << theIdBTL.mtdRR() - << " RU= " << theIdBTL.runit() << " module/geomodule= " << theIdBTL.module() << " / " - << static_cast(geoId).module() << " crys= " << theIdBTL.crystal() - << " BTLDetId row/col= " << origRow << " / " << origCol << "\n"; + << " side/rod= " << theIdBTL.mtdSide() << " / " << theIdBTL.mtdRR() << " RU= " << theIdBTL.runit() + << " module/geomodule= " << theIdBTL.module() << " / " << static_cast(geoId).module() + << " crys= " << theIdBTL.crystal() << " BTLDetId row/col= " << origRow << " / " << origCol + << "\n"; } else { edm::LogVerbatim("DD4hep_TestPixelTopology") << "geoId= " << modIdETL.rawId() << " side= " << modIdETL.mtdSide()