Skip to content

Commit

Permalink
Merge pull request #46911 from fabiocos/fc-mtdtopo20241202
Browse files Browse the repository at this point in the history
MTD geometry: add BTL topology to MTDTopology, reorganize dependencies
  • Loading branch information
cmsbuild authored Dec 12, 2024
2 parents c8d5f21 + 4193a38 commit ab76956
Show file tree
Hide file tree
Showing 43 changed files with 458 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
#include "Geometry/CommonDetUnit/interface/GeomDetType.h"

class MTDGeometry;
class MTDTopology;
class MTDGeomDetType;
class PMTDParameters;

class MTDGeomBuilderFromGeometricTimingDet {
public:
MTDGeometry* build(const GeometricTimingDet* gd, const PMTDParameters& ptp, const MTDTopology* tTopo);
MTDGeometry* build(const GeometricTimingDet* gd, const PMTDParameters& ptp);

private:
void buildPixel(std::vector<const GeometricTimingDet*> const&,
Expand All @@ -28,7 +27,6 @@ class MTDGeomBuilderFromGeometricTimingDet {
double scaleFactor = 1.) const;

std::map<std::string, const MTDGeomDetType*> theMTDDetTypeMap;
const MTDTopology* theTopo;
};

#endif
2 changes: 1 addition & 1 deletion Geometry/MTDGeometryBuilder/interface/MTDGeomUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
#include "Geometry/MTDGeometryBuilder/interface/ProxyMTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/RectangularMTDTopology.h"
#include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h"

namespace edm {
class Event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
#include "DataFormats/ForwardDetId/interface/MTDDetId.h"
#include "DataFormats/ForwardDetId/interface/BTLDetId.h"
#include "DataFormats/ForwardDetId/interface/ETLDetId.h"
#include <Geometry/CommonDetUnit/interface/GeomDet.h>

Expand All @@ -12,6 +12,20 @@

class MTDTopology {
public:
struct BTLLayout {
// number of logical rods, i.e. rows of sensor modules along eta/z in phi, and of modules per rod
static constexpr uint32_t nBTLphi_ = BTLDetId::HALF_ROD * BTLDetId::kModulesPerTrkV2;
static constexpr uint32_t nBTLeta_ =
2 * BTLDetId::kRUPerTypeV2 * BTLDetId::kCrystalTypes * BTLDetId::kModulesPerRUV2 / BTLDetId::kModulesPerTrkV2;
static constexpr uint32_t nBTLmodules_ = nBTLphi_ * nBTLeta_;

std::array<uint32_t, nBTLmodules_> btlDetId_;
std::array<uint32_t, nBTLmodules_> btlPhi_;
std::array<uint32_t, nBTLmodules_> btlEta_;
};

using BTLValues = BTLLayout;

struct ETLfaceLayout {
uint32_t idDiscSide_; // disc face identifier
uint32_t idDetType1_; // module type id identifier for first row
Expand All @@ -22,10 +36,24 @@ class MTDTopology {

using ETLValues = std::vector<ETLfaceLayout>;

MTDTopology(const int& topologyMode, const ETLValues& etl);
MTDTopology(const int& topologyMode, const BTLValues& btl, const ETLValues& etl);

int getMTDTopologyMode() const { return mtdTopologyMode_; }

uint32_t btlRods() const { return btlVals_.nBTLphi_; }
uint32_t btlModulesPerRod() const { return btlVals_.nBTLeta_; }
uint32_t btlModules() const { return btlVals_.nBTLmodules_; }

// BTL topology navigation is based on a predefined order of dets in MTDGeometry, mapped onto phi/eta grid

std::pair<uint32_t, uint32_t> btlIndex(const uint32_t detId) const;
uint32_t btlidFromIndex(const uint32_t iphi, const uint32_t ieta) const;

// BTL topology navigation methods, find index of closest module along eta or phi

uint32_t phishiftBTL(const uint32_t detid, const int phiShift) const;
uint32_t etashiftBTL(const uint32_t detid, const int etaShift) const;

// ETL topology navigation is based on a predefined order of dets in sector

static bool orderETLSector(const GeomDet*& gd1, const GeomDet*& gd2);
Expand All @@ -39,6 +67,8 @@ class MTDTopology {
private:
const int mtdTopologyMode_;

const BTLValues btlVals_;

const ETLValues etlVals_;

static constexpr size_t failIndex_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/Records/interface/PMTDParametersRcd.h"
#include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
#include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
#include "Geometry/Records/interface/MTDTopologyRcd.h"

// Alignments
#include "CondFormats/Alignment/interface/Alignments.h"
Expand Down Expand Up @@ -45,7 +43,6 @@ class MTDDigiGeometryESModule : public edm::ESProducer {
const std::string myLabel_;

edm::ESGetToken<GeometricTimingDet, IdealGeometryRecord> geomTimingDetToken_;
edm::ESGetToken<MTDTopology, MTDTopologyRcd> mtdTopoToken_;
edm::ESGetToken<PMTDParameters, PMTDParametersRcd> pmtdParamsToken_;

//alignment
Expand All @@ -69,7 +66,6 @@ MTDDigiGeometryESModule::MTDDigiGeometryESModule(const edm::ParameterSet& p)
auto cc = setWhatProduced(this);
const edm::ESInputTag kEmpty;
geomTimingDetToken_ = cc.consumesFrom<GeometricTimingDet, IdealGeometryRecord>(kEmpty);
mtdTopoToken_ = cc.consumesFrom<MTDTopology, MTDTopologyRcd>(kEmpty);
pmtdParamsToken_ = cc.consumesFrom<PMTDParameters, PMTDParametersRcd>(kEmpty);

{
Expand Down Expand Up @@ -109,12 +105,10 @@ std::unique_ptr<MTDGeometry> MTDDigiGeometryESModule::produce(const MTDDigiGeome
//
GeometricTimingDet const& gD = iRecord.get(geomTimingDetToken_);

MTDTopology const& tTopo = iRecord.get(mtdTopoToken_);

PMTDParameters const& ptp = iRecord.get(pmtdParamsToken_);

MTDGeomBuilderFromGeometricTimingDet builder;
std::unique_ptr<MTDGeometry> mtd(builder.build(&(gD), ptp, &tTopo));
std::unique_ptr<MTDGeometry> mtd(builder.build(&(gD), ptp));

if (applyAlignment_) {
// Since fake is fully working when checking for 'empty', we should get rid of applyAlignment_!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h"
#include "Geometry/MTDCommonData/interface/MTDTopologyMode.h"
#include "Geometry/Records/interface/MTDTopologyRcd.h"
#include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
#include "Geometry/Records/interface/PMTDParametersRcd.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
#include "Geometry/Records/interface/MTDDigiGeometryRecord.h"

#include <memory>

Expand All @@ -25,13 +27,18 @@ class MTDTopologyEP : public edm::ESProducer {
ReturnType produce(const MTDTopologyRcd&);

private:
void fillParameters(const PMTDParameters&, int& mtdTopologyMode, MTDTopology::ETLValues&);
void fillBTLtopology(const MTDGeometry&, MTDTopology::BTLValues&);
void fillETLtopology(const PMTDParameters&, int& mtdTopologyMode, MTDTopology::ETLValues&);

const edm::ESGetToken<PMTDParameters, PMTDParametersRcd> token_;
edm::ESGetToken<MTDGeometry, MTDDigiGeometryRecord> mtdgeoToken_;
edm::ESGetToken<PMTDParameters, PMTDParametersRcd> mtdparToken_;
};

MTDTopologyEP::MTDTopologyEP(const edm::ParameterSet& conf)
: token_{setWhatProduced(this).consumesFrom<PMTDParameters, PMTDParametersRcd>(edm::ESInputTag())} {}
MTDTopologyEP::MTDTopologyEP(const edm::ParameterSet& conf) {
auto cc = setWhatProduced(this);
mtdgeoToken_ = cc.consumesFrom<MTDGeometry, MTDDigiGeometryRecord>(edm::ESInputTag());
mtdparToken_ = cc.consumesFrom<PMTDParameters, PMTDParametersRcd>(edm::ESInputTag());
}

void MTDTopologyEP::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription ttc;
Expand All @@ -40,21 +47,47 @@ void MTDTopologyEP::fillDescriptions(edm::ConfigurationDescriptions& description

MTDTopologyEP::ReturnType MTDTopologyEP::produce(const MTDTopologyRcd& iRecord) {
int mtdTopologyMode;
MTDTopology::BTLValues btlVals;
MTDTopology::ETLValues etlVals;

fillParameters(iRecord.get(token_), mtdTopologyMode, etlVals);
// build BTL topology content from MTDGeometry

return std::make_unique<MTDTopology>(mtdTopologyMode, etlVals);
}
fillBTLtopology(iRecord.get(mtdgeoToken_), btlVals);

void MTDTopologyEP::fillParameters(const PMTDParameters& ptp, int& mtdTopologyMode, MTDTopology::ETLValues& etlVals) {
mtdTopologyMode = ptp.topologyMode_;
// build ETL topology and topology mode information from PMTDParameters

// for legacy geometry scenarios no topology informastion is stored, only for newer ETL 2-discs layout
fillETLtopology(iRecord.get(mtdparToken_), mtdTopologyMode, etlVals);

if (mtdTopologyMode <= static_cast<int>(MTDTopologyMode::Mode::barphiflat)) {
return;
return std::make_unique<MTDTopology>(mtdTopologyMode, btlVals, etlVals);
}

void MTDTopologyEP::fillBTLtopology(const MTDGeometry& mtdgeo, MTDTopology::BTLValues& btlVals) {
MTDTopology::BTLLayout tmpLayout;
uint32_t index(0), iphi(1), ieta(0);
if (mtdgeo.detsBTL().size() != tmpLayout.nBTLmodules_) {
throw cms::Exception("MTDTopologyEP") << "Inconsistent size of BTL structure arrays";
}
for (const auto& det : mtdgeo.detsBTL()) {
ieta++;

tmpLayout.btlDetId_[index] = det->geographicalId().rawId();
tmpLayout.btlPhi_[index] = iphi;
tmpLayout.btlEta_[index] = ieta;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MTDTopologyEP") << "MTDTopology BTL# " << index << " id= " << det->geographicalId().rawId()
<< " iphi/ieta= " << iphi << " / " << ieta;
#endif
if (ieta == tmpLayout.nBTLeta_) {
iphi++;
ieta = 0;
}
index++;
}
btlVals = tmpLayout;
}

void MTDTopologyEP::fillETLtopology(const PMTDParameters& ptp, int& mtdTopologyMode, MTDTopology::ETLValues& etlVals) {
mtdTopologyMode = ptp.topologyMode_;

// Check on the internal consistency of thr ETL layout information provided by parameters

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h"

#include "FWCore/Utilities/interface/typelookup.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "Geometry/MTDGeometryBuilder/interface/MTDGeomDetUnit.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDPixelTopologyBuilder.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ForwardDetId/interface/MTDDetId.h"
#include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
#include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
#include "DataFormats/GeometrySurface/interface/MediumProperties.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand All @@ -33,18 +33,13 @@ namespace {
}
} // namespace

MTDGeometry* MTDGeomBuilderFromGeometricTimingDet::build(const GeometricTimingDet* gd,
const PMTDParameters& ptp,
const MTDTopology* tTopo) {
MTDGeometry* MTDGeomBuilderFromGeometricTimingDet::build(const GeometricTimingDet* gd, const PMTDParameters& ptp) {
theMTDDetTypeMap.clear();

MTDGeometry* tracker = new MTDGeometry(gd);
std::vector<const GeometricTimingDet*> comp;
gd->deepComponents(comp);

if (tTopo)
theTopo = tTopo;

//define a vector which associate to the detid subdetector index -1 (from 0 to 5) the GeometridDet enumerator to be able to know which type of subdetector it is

std::vector<GeometricTimingDet::GTDEnumType> gdsubdetmap(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,101 @@
#include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "Geometry/MTDCommonData/interface/MTDTopologyMode.h"

MTDTopology::MTDTopology(const int& topologyMode, const ETLValues& etl)
: mtdTopologyMode_(topologyMode), etlVals_(etl) {}
#include <utility>

MTDTopology::MTDTopology(const int& topologyMode, const BTLValues& btl, const ETLValues& etl)
: mtdTopologyMode_(topologyMode), btlVals_(btl), etlVals_(etl) {}

std::pair<uint32_t, uint32_t> MTDTopology::btlIndex(const uint32_t detId) const {
size_t index(0);
bool found(false);
for (const auto& theid : btlVals_.btlDetId_) {
if (theid == detId) {
found = true;
break;
}
index++;
}
if (found) {
return std::make_pair(btlVals_.btlPhi_[index], btlVals_.btlEta_[index]);
} else {
edm::LogWarning("MTDTopology") << "Searching BTL topology for BTLDetId " << detId
<< " not in BTL geometry structure";
return std::make_pair(std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max());
}
}

uint32_t MTDTopology::btlidFromIndex(const uint32_t iphi, const uint32_t ieta) const {
uint32_t res(0);
for (uint32_t index = 0; index < btlVals_.nBTLmodules_; index++) {
if (iphi == btlVals_.btlPhi_[index] && ieta == btlVals_.btlEta_[index]) {
res = btlVals_.btlDetId_[index];
break;
}
}
return res;
}

uint32_t MTDTopology::phishiftBTL(const uint32_t detid, const int phiShift) const {
if (phiShift == 0) {
edm::LogWarning("MTDTopology") << "asking of a null phiShift in BTL";
return failIndex_;
}
// search for the next detector, check only sign from input
int sh = phiShift > 0 ? 1 : -1;
size_t index(0);
bool found(false);
for (const auto& theid : btlVals_.btlDetId_) {
if (theid == detid) {
found = true;
break;
}
index++;
}
if (found) {
int newIndex = index + sh * btlVals_.nBTLeta_;
if (newIndex >= static_cast<int>(btlVals_.nBTLmodules_)) {
newIndex = newIndex - btlVals_.nBTLmodules_;
} else if (newIndex < 0) {
newIndex = newIndex + btlVals_.nBTLmodules_;
}
return newIndex;
} else {
edm::LogWarning("MTDTopology") << "Searching for non existent BTLDetId " << detid;
return failIndex_;
}
}

uint32_t MTDTopology::etashiftBTL(const uint32_t detid, const int etaShift) const {
if (etaShift == 0) {
edm::LogWarning("MTDTopology") << "asking of a null etaShift in BTL";
return failIndex_;
}
// search for the next detector, check only sign from input
int sh = etaShift > 0 ? 1 : -1;
size_t index(0);
bool found(false);
for (const auto& theid : btlVals_.btlDetId_) {
if (theid == detid) {
found = true;
break;
}
index++;
}
if (found) {
int newIndex = index + sh;
if (newIndex < 0 || newIndex >= static_cast<int>(btlVals_.nBTLmodules_)) {
return failIndex_;
} else if (btlVals_.btlPhi_[newIndex] != btlVals_.btlPhi_[index]) {
return failIndex_;
}
return newIndex;
} else {
edm::LogWarning("MTDTopology") << "Searching for non existent BTLDetId " << detid;
return failIndex_;
}
}

bool MTDTopology::orderETLSector(const GeomDet*& gd1, const GeomDet*& gd2) {
ETLDetId det1(gd1->geographicalId().rawId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"

#include "Geometry/Records/interface/MTDTopologyRcd.h"
#include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDGeomDetUnit.h"
#include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
Expand Down
Loading

0 comments on commit ab76956

Please sign in to comment.