Skip to content

Commit

Permalink
Merge pull request #31337 from vargasa/FixGeoNav
Browse files Browse the repository at this point in the history
DD4hep: CmsTrackerLevelBuilder Fix Tracker Geometry Navigation
  • Loading branch information
cmsbuild authored Sep 9, 2020
2 parents 4d53853 + e39cdcf commit 61a1541
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 40 deletions.
3 changes: 3 additions & 0 deletions DetectorDescription/DDCMS/interface/DDFilteredView.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,7 @@ namespace cms {
};
} // namespace cms

//stream geoHistory
std::ostream& operator<<(std::ostream& os, const std::vector<const cms::Node*>& hst);

#endif
6 changes: 6 additions & 0 deletions DetectorDescription/DDCMS/src/DDFilteredView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,9 @@ dd4hep::Solid DDFilteredView::solid() const { return (volume().volume().solid())
unsigned short DDFilteredView::copyNum() const { return (volume().copyNumber()); }

std::string_view DDFilteredView::materialName() const { return (volume().material().name()); }

std::ostream& operator<<(std::ostream& os, const std::vector<const cms::Node*>& hst) {
for (auto nd = hst.rbegin(); nd != hst.rend(); ++nd)
os << "/" << (*nd)->GetName();
return os;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void CmsDetConstruction<FilteredView>::buildComponent(FilteredView& fv,
bool dodets = fv.firstChild(); // descend to the first Layer
while (dodets) {
buildSmallDetsforGlued(fv, det, attribute);
dodets = fv.nextSibling(); // go to next layer
/*
dodets = setNext(fv);
/*
Add algo to sort the merged DET
*/
}
Expand All @@ -80,7 +80,7 @@ void CmsDetConstruction<FilteredView>::buildComponent(FilteredView& fv,
bool dodets = fv.firstChild();
while (dodets) {
buildSmallDetsforStack(fv, det, attribute);
dodets = fv.nextSibling();
dodets = setNext(fv);
}
fv.parent();
}
Expand Down
2 changes: 2 additions & 0 deletions Geometry/TrackerNumberingBuilder/plugins/CmsDetConstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class CmsDetConstruction : public CmsTrackerLevelBuilder<FilteredView> {
void buildDets(const FilteredView&, GeometricDet*, const std::string&);
void buildSmallDetsforGlued(FilteredView&, GeometricDet*, const std::string&);
void buildSmallDetsforStack(FilteredView&, GeometricDet*, const std::string&);
bool setNext(cms::DDFilteredView& fv) { return fv.firstChild(); }
bool setNext(DDFilteredView& fv) { return fv.nextSibling(); }
};

#endif // Geometry_TrackerNumberingBuilder_CmsDetConstruction_H
21 changes: 9 additions & 12 deletions Geometry/TrackerNumberingBuilder/plugins/CmsTrackerLevelBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,23 @@ template <class FilteredView>
void CmsTrackerLevelBuilder<FilteredView>::build(FilteredView& fv,
GeometricDet* tracker,
const std::string& attribute) {
LogTrace("GeometricDetBuilding") //<< std::string(3 * fv.history().size(), '-') << "+ "
<< ExtractStringFromDDD<FilteredView>::getString(attribute, &fv) << " " << tracker->type() << " "
<< tracker->name() << std::endl;
edm::LogVerbatim("TrackerGeometryBuilder") << "CmsTrackerLevelBuilder::build "
<< " Building: " << fv.geoHistory();

edm::LogVerbatim("TrackerGeometryBuilder") << ExtractStringFromDDD<FilteredView>::getString(attribute, &fv) << " "
<< tracker->type() << " " << tracker->name() << std::endl;

bool doLayers = fv.firstChild(); // descend to the first Layer

while (doLayers) {
buildComponent(fv, tracker, attribute);
doLayers = fv.nextSibling(); // go to next layer
if constexpr (std::is_same_v<FilteredView, DDFilteredView>) {
edm::LogVerbatim("TrackerGeometryBuilder") << "CmsTrackerLevelbuilder<DDFilteredView>::build" << fv.geoHistory();

doLayers = fv.nextSibling();
} else if constexpr (std::is_same_v<FilteredView, cms::DDFilteredView>) {
edm::LogVerbatim("TrackerGeometryBuilder") << "CmsTrackerLevelbuilder<cms::DDFilteredView>::build";
std::vector<const cms::Node*> hst = fv.geoHistory();
std::string path;
for (auto nd = hst.rbegin(); nd != hst.rend(); ++nd) {
path += "/" + std::string((*nd)->GetName());
}
edm::LogVerbatim("TrackerGeometryBuilder") << path;
edm::LogVerbatim("TrackerGeometryBuilder")
<< "CmsTrackerLevelbuilder<cms::DDFilteredView>::build" << fv.geoHistory();
doLayers = fv.firstChild();
}
}

Expand Down
30 changes: 15 additions & 15 deletions SimG4CMS/Tracker/src/TrackerG4SimHitNumberingScheme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ void TrackerG4SimHitNumberingScheme::buildAll() {

for (auto& theSD : allSensitiveDets) {
auto const& t = theSD->translation();
edm::LogVerbatim("TrackerSimInfoNumbering") << "::buildAll" << theSD->geographicalID().rawId() << "\t" << t;
theNavigator.LocateGlobalPointAndSetup(G4ThreeVector(t.x(), t.y(), t.z()));
G4TouchableHistory* hist = theNavigator.CreateTouchableHistory();
assert(!!hist);
TrackerG4SimHitNumberingScheme::Nav_Story st;
touchToNavStory(hist, st);

for (const std::pair<int, std::string>& p : st)
edm::LogVerbatim("TrackerSimInfoNumbering") << "Nav_Story\t" << p.first << "\t" << p.second;

directMap_[st] = theSD->geographicalID();

LogDebug("TrackerSimDebugNumbering") << " INSERTING LV " << hist->GetVolume()->GetLogicalVolume()->GetName()
Expand All @@ -55,27 +60,24 @@ void TrackerG4SimHitNumberingScheme::buildAll() {

void TrackerG4SimHitNumberingScheme::touchToNavStory(const G4VTouchable* v,
TrackerG4SimHitNumberingScheme::Nav_Story& st) {
#ifdef DEBUG
std::vector<int> debugint;
std::vector<std::string> debugstring;
#endif

int levels = v->GetHistoryDepth();

for (int k = 0; k <= levels; ++k) {
if (v->GetVolume(k)->GetLogicalVolume()->GetName() != "TOBInactive") {
st.emplace_back(
std::pair<int, std::string>(v->GetVolume(k)->GetCopyNo(), v->GetVolume(k)->GetLogicalVolume()->GetName()));
#ifdef DEBUG
debugint.emplace_back(v->GetVolume(k)->GetCopyNo());
debugstring.emplace_back(v->GetVolume(k)->GetLogicalVolume()->GetName());
#endif
}
}
#ifdef DEBUG
LogDebug("TrackerSimDebugNumbering") << " G4 TrackerG4SimHitNumberingScheme " << debugint;
for (u_int32_t jj = 0; jj < debugstring.size(); jj++)
LogDebug("TrackerSimDebugNumbering") << " " << debugstring[jj];
#endif

for (const int& i : debugint)
edm::LogVerbatim("TrackerSimInfoNumbering") << " G4 TrackerG4SimHitNumberingScheme " << i;
for (const std::string& s : debugstring)
edm::LogVerbatim("TrackerSimInfoNumbering") << " " << s;
}

unsigned int TrackerG4SimHitNumberingScheme::g4ToNumberingScheme(const G4VTouchable* v) {
Expand All @@ -85,20 +87,18 @@ unsigned int TrackerG4SimHitNumberingScheme::g4ToNumberingScheme(const G4VToucha
TrackerG4SimHitNumberingScheme::Nav_Story st;
touchToNavStory(v, st);

#ifdef DEBUG
dumpG4VPV(v);
LogDebug("TrackerSimDebugNumbering") << " Returning: " << directMap_[st];
#endif
edm::LogVerbatim("TrackerSimInfoNumbering") << " Returning: " << directMap_[st];

return directMap_[st];
}

void TrackerG4SimHitNumberingScheme::dumpG4VPV(const G4VTouchable* v) {
int levels = v->GetHistoryDepth();

LogDebug("TrackerSimDebugNumbering") << " NAME : " << v->GetVolume()->GetLogicalVolume()->GetName();
edm::LogVerbatim("TrackerSimInfoNumbering") << " NAME : " << v->GetVolume()->GetLogicalVolume()->GetName();
for (int k = 0; k <= levels; k++) {
LogDebug("TrackerSimInfoNumbering") << " Hist: " << v->GetVolume(k)->GetLogicalVolume()->GetName() << " Copy "
<< v->GetVolume(k)->GetCopyNo();
edm::LogVerbatim("TrackerSimInfoNumbering")
<< " Hist: " << v->GetVolume(k)->GetLogicalVolume()->GetName() << " Copy " << v->GetVolume(k)->GetCopyNo();
}
}
6 changes: 5 additions & 1 deletion SimG4Core/Configuration/test/dd4hep_ZMM_Run3_Step1_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
process.load('Configuration.Geometry.GeometryDD4hepExtended2021_cff') # there w

process.MessageLogger.categories.append("TrackerGeometryBuilder");
process.MessageLogger.categories.append("TrackerSimInfoNumbering");


process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(10),
output = cms.optional.untracked.allowed(cms.int32,cms.PSet)
Expand Down Expand Up @@ -72,7 +76,7 @@
dataTier = cms.untracked.string('GEN-SIM'),
filterName = cms.untracked.string('')
),
fileName = cms.untracked.string('file:step1_ZMM.root'),
fileName = cms.untracked.string('file:step1_ZMM_dd4hep.root'),
outputCommands = process.FEVTDEBUGEventContent.outputCommands,
splitLevel = cms.untracked.int32(0)
)
Expand Down
4 changes: 2 additions & 2 deletions SimG4Core/Configuration/test/dd4hep_ZMM_Run3_Step2_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Input source
process.source = cms.Source("PoolSource",
dropDescendantsOfDroppedBranches = cms.untracked.bool(False),
fileNames = cms.untracked.vstring('file:step1_ZMM.root'),
fileNames = cms.untracked.vstring('file:step1_ZMM_dd4hep.root'),
inputCommands = cms.untracked.vstring(
'keep *',
'drop *_genParticles_*_*',
Expand Down Expand Up @@ -91,7 +91,7 @@
dataTier = cms.untracked.string('GEN-SIM-DIGI-RAW'),
filterName = cms.untracked.string('')
),
fileName = cms.untracked.string('file:step2_ZMM.root'),
fileName = cms.untracked.string('file:step2_ZMM_dd4hep.root'),
outputCommands = process.FEVTDEBUGHLTEventContent.outputCommands,
splitLevel = cms.untracked.int32(0)
)
Expand Down
4 changes: 2 additions & 2 deletions SimG4Core/Configuration/test/dd4hep_ZMM_Run3_Step3_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# Input source
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('file:step2_ZMM.root'),
fileNames = cms.untracked.vstring('file:step2_ZMM_dd4hep.root'),
secondaryFileNames = cms.untracked.vstring()
)

Expand Down Expand Up @@ -78,7 +78,7 @@
dataTier = cms.untracked.string('GEN-SIM-RECO'),
filterName = cms.untracked.string('')
),
fileName = cms.untracked.string('file:step3_ZMM.root'),
fileName = cms.untracked.string('file:step3_ZMM_dd4hep.root'),
outputCommands = process.RECOSIMEventContent.outputCommands,
splitLevel = cms.untracked.int32(0)
)
Expand Down
6 changes: 5 additions & 1 deletion SimG4Core/Configuration/test/ddd_ZMM_Run3_Step1_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
process.load('Configuration.Geometry.GeometryExtended2021_cff') # there w

process.MessageLogger.categories.append("TrackerGeometryBuilder");
process.MessageLogger.categories.append("TrackerSimInfoNumbering");


process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(10),
output = cms.optional.untracked.allowed(cms.int32,cms.PSet)
Expand Down Expand Up @@ -72,7 +76,7 @@
dataTier = cms.untracked.string('GEN-SIM'),
filterName = cms.untracked.string('')
),
fileName = cms.untracked.string('file:step1_ZMM.root'),
fileName = cms.untracked.string('file:step1_ZMM_ddd.root'),
outputCommands = process.FEVTDEBUGEventContent.outputCommands,
splitLevel = cms.untracked.int32(0)
)
Expand Down
4 changes: 2 additions & 2 deletions SimG4Core/Configuration/test/ddd_ZMM_Run3_Step2_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Input source
process.source = cms.Source("PoolSource",
dropDescendantsOfDroppedBranches = cms.untracked.bool(False),
fileNames = cms.untracked.vstring('file:step1_ZMM.root'),
fileNames = cms.untracked.vstring('file:step1_ZMM_ddd.root'),
inputCommands = cms.untracked.vstring(
'keep *',
'drop *_genParticles_*_*',
Expand Down Expand Up @@ -91,7 +91,7 @@
dataTier = cms.untracked.string('GEN-SIM-DIGI-RAW'),
filterName = cms.untracked.string('')
),
fileName = cms.untracked.string('file:step2_ZMM.root'),
fileName = cms.untracked.string('file:step2_ZMM_ddd.root'),
outputCommands = process.FEVTDEBUGHLTEventContent.outputCommands,
splitLevel = cms.untracked.int32(0)
)
Expand Down
4 changes: 2 additions & 2 deletions SimG4Core/Configuration/test/ddd_ZMM_Run3_Step3_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# Input source
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('file:step2_ZMM.root'),
fileNames = cms.untracked.vstring('file:step2_ZMM_ddd.root'),
secondaryFileNames = cms.untracked.vstring()
)

Expand Down Expand Up @@ -78,7 +78,7 @@
dataTier = cms.untracked.string('GEN-SIM-RECO'),
filterName = cms.untracked.string('')
),
fileName = cms.untracked.string('file:step3_ZMM.root'),
fileName = cms.untracked.string('file:step3_ZMM_ddd.root'),
outputCommands = process.RECOSIMEventContent.outputCommands,
splitLevel = cms.untracked.int32(0)
)
Expand Down

0 comments on commit 61a1541

Please sign in to comment.