Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTD Geometry - Numbering scheme update #46977

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 131 additions & 41 deletions DataFormats/ForwardDetId/interface/BTLDetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#define DataFormats_BTLDetId_BTLDetId_h

#include "DataFormats/ForwardDetId/interface/MTDDetId.h"
#include <iostream>
#include <ostream>
#include <array>
#include <bitset>

/**
@class BTLDetId
Expand All @@ -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
//
Expand All @@ -50,67 +82,125 @@ 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 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 type number. */
inline int modType() const { return (id_ >> kBTLmodTypeOffset) & kBTLmodTypeMask; }
/** Returns BTL detector module number. */
inline int dmodule() const { return ((id_ >> kBTLdetectorModOffset) & kBTLdetectorModMask); }

/** Returns BTL crystal number. */
inline int crystal() const { return ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask) + 1; }
/** Returns BTL sensor module number. */
inline int smodule() const { return ((id_ >> kBTLsensorModOffset) & kBTLsensorModMask); }

/** Returns BTL readout unit number per type. */
inline int runit() const { return (id_ >> kBTLRUOffset) & kBTLRUMask; }
/** 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 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 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&);
Expand Down
31 changes: 17 additions & 14 deletions DataFormats/ForwardDetId/src/BTLDetId.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "DataFormats/ForwardDetId/interface/BTLDetId.h"
#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::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);
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;
Expand All @@ -20,12 +20,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;
}
9 changes: 8 additions & 1 deletion DataFormats/ForwardDetId/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
<class name="MTDDetId" ClassVersion="3">
<version ClassVersion="3" checksum="1210976889"/>
</class>
<class name="BTLDetId" ClassVersion="3">
<class name="BTLDetId" ClassVersion="4">
<version ClassVersion="4" checksum="1515591716"/>
<version ClassVersion="3" checksum="1515591716"/>
<ioread sourceClass = "BTLDetId" version="[-3]" targetClass="BTLDetId" source="" target="">
<![CDATA[
BTLDetId tmp(newObj->newForm(newObj->rawId()));
*newObj=tmp;
]]>
</ioread>
</class>
<class name="ETLDetId" ClassVersion="4">
<version ClassVersion="4" checksum="1644731879"/>
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/TrackReco/src/HitPattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
80 changes: 80 additions & 0 deletions Geometry/MTDCommonData/interface/BTLElectronicsMapping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef DATAFORMATS_BTLELECTRONICSMAPPING_H
#define DATAFORMATS_BTLELECTRONICSMAPPING_H 1

#include <ostream>
#include <cstdint>

#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<uint32_t, BTLDetId::kCrystalsPerModuleV2 * 2> 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<uint32_t, BTLDetId::kCrystalsPerModuleV2 * 2> 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<uint32_t, BTLDetId::kCrystalsPerModuleV2 * 2> 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);

/** 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
Loading