Skip to content

Commit

Permalink
Support extraction and binary dump of phase2 tracker geometry.
Browse files Browse the repository at this point in the history
  • Loading branch information
osschar committed Oct 6, 2022
1 parent 52abcef commit a273b50
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 32 deletions.
3 changes: 2 additions & 1 deletion RecoTracker/MkFit/interface/MkFitGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MkFitGeometry {
explicit MkFitGeometry(const TrackerGeometry& geom,
const GeometricSearchTracker& tracker,
const TrackerTopology& ttopo,
std::unique_ptr<mkfit::TrackerInfo> trackerInfo);
std::unique_ptr<mkfit::TrackerInfo> trackerInfo,
const mkfit::LayerNumberConverter& layNConv);
~MkFitGeometry();

int mkFitLayerNumber(DetId detId) const;
Expand Down
86 changes: 67 additions & 19 deletions RecoTracker/MkFit/plugins/MkFitGeometryESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <sstream>

// #define DUMP_MKF_GEO

//------------------------------------------------------------------------------

class MkFitGeometryESProducer : public edm::ESProducer {
Expand Down Expand Up @@ -192,7 +194,9 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,
xy[3][1] = -par[3];
dz = par[2];

// printf("TRAP 0x%x %f %f %f %f\n", detid.rawId(), par[0], par[1], par[2], par[3]);
#ifdef DUMP_MKF_GEO
printf("TRAP 0x%x %f %f %f %f ", detid.rawId(), par[0], par[1], par[2], par[3]);
#endif
} else if (const RectangularPlaneBounds *b2 = dynamic_cast<const RectangularPlaneBounds *>(b)) {
// Rectangular
float dx = b2->width() * 0.5; // half width
Expand All @@ -207,7 +211,9 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,
xy[3][1] = -dy;
dz = b2->thickness() * 0.5; // half thickness

// printf("RECT 0x%x %f %f %f\n", detid.rawId(), dx, dy, dz);
#ifdef DUMP_MKF_GEO
printf("RECT 0x%x %f %f %f ", detid.rawId(), dx, dy, dz);
#endif
} else {
throw cms::Exception("UnimplementedFeature") << "unsupported Bounds class";
}
Expand All @@ -219,6 +225,12 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,
useMatched,
trackerTopo_->isStereo(detid),
trackerTopo_->side(detid) == static_cast<unsigned>(TrackerDetSide::PosEndcap));
#ifdef DUMP_MKF_GEO
printf(" subdet=%d layer=%d side=%d is_stereo=%d --> mkflayer=%d\n",
detid.subdetId(), trackerTopo_->layer(detid),
trackerTopo_->side(detid), trackerTopo_->isStereo(detid),
lay);
#endif

mkfit::LayerInfo &layer_info = trk_info.layer_nc(lay);
if (lgc_map) {
Expand Down Expand Up @@ -252,51 +264,64 @@ void MkFitGeometryESProducer::fillShapeAndPlacement(const GeomDet *det,

//==============================================================================

// Ideally these functions would also:
// 0. Setup LayerInfo data (which is now done in auto-generated code).
// Some data-members are a bit over specific, esp/ bools for CMS sub-detectors.
// 1. Establish short module ids (now done in MkFitGeometry constructor).
// 2. Store module normal and strip direction vectors
// 3. ? Any other information ?
// These functions do the following:
// 0. Detect bounding cylinder of each layer.
// 1. Setup LayerInfo data.
// 2. Establish short module ids.
// 3. Store module normal and strip direction vectors.
// 4. Extract stereo coverage holes where they exist (TEC, all but last 3 double-layers).
//
// Plugin DumpMkFitGeometry.cc can then be used to export this for stand-alone.
// Would also need to be picked up with tk-ntuple converter (to get module ids as
// they will now be used as indices into module info vectors).
//
// An attempt at export cmsRun config is in python/dumpMkFitGeometry.py
// See python/dumpMkFitGeometry.py and dumpMkFitGeometryPhase2.py

void MkFitGeometryESProducer::addPixBGeometry(mkfit::TrackerInfo &trk_info) {
#ifdef DUMP_MKF_GEO
printf("\n*** addPixBGeometry\n\n");
#endif
for (auto &det : trackerGeom_->detsPXB()) {
fillShapeAndPlacement(det, trk_info);
}
}

void MkFitGeometryESProducer::addPixEGeometry(mkfit::TrackerInfo &trk_info) {
#ifdef DUMP_MKF_GEO
printf("\n*** addPixEGeometry\n\n");
#endif
for (auto &det : trackerGeom_->detsPXF()) {
fillShapeAndPlacement(det, trk_info);
}
}

void MkFitGeometryESProducer::addTIBGeometry(mkfit::TrackerInfo &trk_info) {
#ifdef DUMP_MKF_GEO
printf("\n*** addTIBGeometry\n\n");
#endif
for (auto &det : trackerGeom_->detsTIB()) {
fillShapeAndPlacement(det, trk_info);
}
}

void MkFitGeometryESProducer::addTOBGeometry(mkfit::TrackerInfo &trk_info) {
#ifdef DUMP_MKF_GEO
printf("\n*** addTOBGeometry\n\n");
#endif
for (auto &det : trackerGeom_->detsTOB()) {
fillShapeAndPlacement(det, trk_info);
}
}

void MkFitGeometryESProducer::addTIDGeometry(mkfit::TrackerInfo &trk_info) {
#ifdef DUMP_MKF_GEO
printf("\n*** addTIDGeometry\n\n");
#endif
for (auto &det : trackerGeom_->detsTID()) {
fillShapeAndPlacement(det, trk_info);
}
}

void MkFitGeometryESProducer::addTECGeometry(mkfit::TrackerInfo &trk_info) {
#ifdef DUMP_MKF_GEO
printf("\n*** addTECGeometry\n\n");
#endif
// For TEC we also need to discover hole in radial extents.
layer_gap_map_t lgc_map;
for (auto &det : trackerGeom_->detsTEC()) {
Expand Down Expand Up @@ -330,6 +355,15 @@ namespace {
// PIXE-, TID-, TEC-
1.0, 1.0, 1.0, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 10.25, 7.5, 10.25, 7.5, 10.25, 7.5, 10.25, 7.5, 10.25, 7.5, 10.25, 7.5, 10.25, 7.5, 10.25, 7.5, 10.25, 7.5
};
const float phase2QBins[] = {
// TODO: Review these numbers.
// PIXB, TOB
2.0, 2.0, 2.0, 2.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0,
// PIXE+, TEC+
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6,
// PIXE-, TEC-
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6
};
}
// clang-format on
//------------------------------------------------------------------------------
Expand All @@ -340,13 +374,19 @@ std::unique_ptr<MkFitGeometry> MkFitGeometryESProducer::produce(const TrackerRec
trackerGeom_ = &iRecord.get(geomToken_);
trackerTopo_ = &iRecord.get(ttopoToken_);

const float *qBinDefaults = nullptr;

// std::string path = "Geometry/TrackerCommonData/data/";
if (trackerGeom_->isThere(GeomDetEnumerators::P1PXB) || trackerGeom_->isThere(GeomDetEnumerators::P1PXEC)) {
edm::LogInfo("MkFitGeometryESProducer") << "Extracting PhaseI geometry";
trackerInfo->create_layers(18, 27, 27);
qBinDefaults = phase1QBins;
} else if (trackerGeom_->isThere(GeomDetEnumerators::P2PXB) || trackerGeom_->isThere(GeomDetEnumerators::P2PXEC) ||
trackerGeom_->isThere(GeomDetEnumerators::P2OTB) || trackerGeom_->isThere(GeomDetEnumerators::P2OTEC)) {
throw cms::Exception("UnimplementedFeature") << "PhaseII geometry extraction";
edm::LogInfo("MkFitGeometryESProducer") << "Extracting PhaseII geometry";
layerNrConv_.reset(mkfit::TkLayout::phase2);
trackerInfo->create_layers(16, 22, 22);
qBinDefaults = phase2QBins;
} else {
throw cms::Exception("UnimplementedFeature") << "unsupported / unknowen geometry version";
}
Expand All @@ -366,19 +406,27 @@ std::unique_ptr<MkFitGeometry> MkFitGeometryESProducer::produce(const TrackerRec
addTOBGeometry(*trackerInfo);
addTECGeometry(*trackerInfo);

// r_in/out kept as squres until here, root them
// r_in/out kept as squares until here, root them
unsigned int n_mod = 0;
for (int i = 0; i < trackerInfo->n_layers(); ++i) {
auto &li = trackerInfo->layer_nc(i);
li.set_r_in_out(std::sqrt(li.rin()), std::sqrt(li.rout()));
li.set_propagate_to(li.is_barrel() ? li.r_mean() : li.z_mean());
li.set_q_bin(phase1QBins[i]);
li.set_q_bin(qBinDefaults[i]);
unsigned int maxsid = li.shrink_modules();
// Make sure the short id fits in the 12 bits...
assert(maxsid < 1u << 11);

n_mod += maxsid;

// Make sure the short id fits in the 14 bits...
assert(maxsid < 1u << 13);
assert(n_mod > 0);
}
#ifdef DUMP_MKF_GEO
printf("Total number of modules %u, 14-bits fit up to %u modules\n", n_mod, 1u << 13);
#endif

return std::make_unique<MkFitGeometry>(
iRecord.get(geomToken_), iRecord.get(trackerToken_), iRecord.get(ttopoToken_), std::move(trackerInfo));
iRecord.get(geomToken_), iRecord.get(trackerToken_), iRecord.get(ttopoToken_), std::move(trackerInfo), layerNrConv_);
}

DEFINE_FWK_EVENTSETUP_MODULE(MkFitGeometryESProducer);
16 changes: 6 additions & 10 deletions RecoTracker/MkFit/src/MkFitGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ namespace {
MkFitGeometry::MkFitGeometry(const TrackerGeometry& geom,
const GeometricSearchTracker& tracker,
const TrackerTopology& ttopo,
std::unique_ptr<mkfit::TrackerInfo> trackerInfo)
std::unique_ptr<mkfit::TrackerInfo> trackerInfo,
const mkfit::LayerNumberConverter& layNConv)
: ttopo_(&ttopo),
lnc_{std::make_unique<mkfit::LayerNumberConverter>(mkfit::TkLayout::phase1)},
lnc_{std::make_unique<mkfit::LayerNumberConverter>(layNConv)},
trackerInfo_(std::move(trackerInfo)) {
if (geom.numberOfLayers(PixelSubdetector::PixelBarrel) != 4 ||
geom.numberOfLayers(PixelSubdetector::PixelEndcap) != 3) {
throw cms::Exception("Assert") << "For now this code works only with phase1 tracker, you have something else";
}
if (lnc_->getEra() != mkfit::TkLayout::phase1 && lnc_->getEra() != mkfit::TkLayout::phase2)
throw cms::Exception("Assert") << "This code works only with phase1 and phase2 tracker, you have something else";

// Create DetLayer structure
dets_.resize(lnc_->nLayers(), nullptr);
Expand All @@ -49,12 +48,9 @@ MkFitGeometry::MkFitGeometry(const TrackerGeometry& geom,
const auto subdet = detId.subdetId();
const auto layer = ttopo.layer(detId);

// TODO: mono/stereo structure is still hardcoded for phase0/1 strip tracker
setDet(subdet, layer, monoLayer, detId, lay);
if (((subdet == StripSubdetector::TIB or subdet == StripSubdetector::TOB) and (layer == 1 or layer == 2)) or
subdet == StripSubdetector::TID or subdet == StripSubdetector::TEC) {
if (lnc_->doesHaveStereo(subdet, layer))
setDet(subdet, layer, stereoLayer, detId, lay);
}
}
}

Expand Down
57 changes: 57 additions & 0 deletions RecoTracker/MkFit/test/dumpMkFitGeometryPhase2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import FWCore.ParameterSet.Config as cms

### from Configuration.Eras.Era_Run3_cff import Run3
### from Configuration.Eras.Era_Phase2C17I13M9_cff import Phase2C17I13M9
### from Configuration.ProcessModifiers.trackingMkFit_cff import trackingMkFit

### process = cms.Process('DUMP',Run3,trackingMkFit)
process = cms.Process('DUMP')

# import of standard configurations
###process.load('Configuration.StandardSequences.Services_cff')
###process.load('FWCore.MessageService.MessageLogger_cfi')
###process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
###process.load('Configuration.StandardSequences.MagneticField_cff')
###process.load('Configuration.StandardSequences.Reconstruction_cff')
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
from Configuration.AlCa.autoCond import autoCond
process.GlobalTag.globaltag = autoCond['run2_mc']
process.load('Configuration.Geometry.GeometryExtended2026D88Reco_cff')

##from Configuration.AlCa.GlobalTag import GlobalTag
### process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2021_realistic', '')
###process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T21', '')

###process.load('Configuration.Geometry.GeometryExtended2026D88Reco_cff')

# process.es_prefer_ZDC = cms.ESPrefer("ZdcGeometryFromDBEP", "")
# process.es_prefer_ecb = cms.ESPrefer("EcalBarrelGeometryFromDBEP", "")
# process.es_prefer_ece = cms.ESPrefer("EcalEndcapGeometryFromDBEP", "")
# process.es_prefer_Hcal = cms.ESPrefer("HcalGeometryFromDBEP", "")
# process.es_prefer_calt = cms.ESPrefer("CaloTowerGeometryFromDBEP", "")
# process.es_prefer_Cstr = cms.ESPrefer("CastorGeometryFromDBEP", "")
# process.es_prefer_GEM = cms.ESPrefer("GEMGeometryESModule", "gemGeometry")
# process.es_prefer_trk = cms.ESPrefer("TrackerGeometricDetESModule", "trackerNumberingGeometryDB")
# process.es_prefer_trkd = cms.ESPrefer("TrackerDigiGeometryESModule", "trackerGeometryDB")
# process.es_prefer_mkf = cms.ESPrefer("MkFitGeometryESProducer", "mkFitGeometryESProducer")

process.MessageLogger.cerr.threshold = "INFO"
process.MessageLogger.cerr.MkFitGeometryESProducer = dict(limit=-1)

process.source = cms.Source("EmptySource")
process.maxEvents.input = 1


process.add_(cms.ESProducer("MkFitGeometryESProducer"))

defaultOutputFileName="phase2-trackerinfo.bin"

# level: 0 - no printout; 1 - print layers, 2 - print modules
# outputFileName: binary dump file; no dump if empty string
process.dump = cms.EDAnalyzer("DumpMkFitGeometry",
level = cms.untracked.int32(1),
outputFileName = cms.untracked.string(defaultOutputFileName)
)

print("Requesting MkFit geometry dump into file:", defaultOutputFileName, "\n");
process.p = cms.Path(process.dump)
24 changes: 23 additions & 1 deletion RecoTracker/MkFitCMS/interface/LayerNumberConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@

namespace mkfit {

enum struct TkLayout { phase0 = 0, phase1 = 1 };
enum struct TkLayout { phase0 = 0, phase1 = 1, phase2 = 2 };

class LayerNumberConverter {
public:
LayerNumberConverter(TkLayout layout) : lo_(layout) {}
void reset(TkLayout layout) { lo_= layout; }
unsigned int nLayers() const {
if (lo_ == TkLayout::phase0)
return 69;
if (lo_ == TkLayout::phase1)
return 72;
if (lo_ == TkLayout::phase2)
return 60; // 4 + 12 + 2*(12 + 10) = 16 + 22 + 22 = 60
return 10;
}
TkLayout getEra() const { return lo_; }
int convertLayerNumber(int det, int lay, bool useMatched, int isStereo, bool posZ) const {
if (lo_ == TkLayout::phase2) {
if (det == 1) return lay - 1;
if (det == 2) return 16 + lay - 1 + (posZ ? 0 : 22);
if (det == 5) return 4 + (2 * (lay - 1)) + isStereo;
if (det == 4) return 16 + 12 + (2 * (lay - 1)) + isStereo + (posZ ? 0 : 22);
throw std::runtime_error("bad subDet");
}

if (det == 1 || det == 3 || det == 5) {
return convertBarrelLayerNumber(det, lay, useMatched, isStereo);
} else {
Expand All @@ -33,6 +45,16 @@ namespace mkfit {
}
return -1;
}
bool doesHaveStereo(int det, int lay) const {
if (lo_ == TkLayout::phase2) {
if (det == 1 || det == 2) return false;
if (det == 4 || det == 5) return true;
throw std::runtime_error("bad subDet");
}
if (det == 3 || det == 5) { return lay == 1 || lay == 2; }
if (det == 4 || det == 6) { return true; }
return false;
}

int convertBarrelLayerNumber(int cmsswdet, int cmsswlay, bool useMatched, int isStereo) const {
int lOffset = 0;
Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/MkFitCore/interface/Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace mkfit {

static constexpr int kMinChargePerCM = 1620;
static constexpr int kChargePerCMBits = 8;
static constexpr int kDetIdInLayerBits = 12;
static constexpr int kDetIdInLayerBits = 14;
static constexpr int kClusterSizeBits = 5;
static constexpr int kMaxClusterSize = (1 << kClusterSizeBits) - 1;

Expand Down

0 comments on commit a273b50

Please sign in to comment.