-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a utility function to print all solids with their shape type
- Loading branch information
Sunanda
committed
Aug 26, 2021
1 parent
bebf6ce
commit 6fce9dd
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from SimG4Core.PrintGeomInfo.printGeomSolids_cfi import * | ||
|
||
from Configuration.ProcessModifiers.dd4hep_cff import dd4hep | ||
|
||
dd4hep.toModify(printGeomSolids, | ||
fromDD4Hep = cms.bool(True), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// system include files | ||
#include <map> | ||
#include <string> | ||
|
||
// user include files | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/one/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/PluginManager/interface/ModuleDef.h" | ||
#include "DetectorDescription/Core/interface/DDCompactView.h" | ||
#include "DetectorDescription/Core/interface/DDSolid.h" | ||
#include "DetectorDescription/Core/interface/DDSolidShapes.h" | ||
#include "DetectorDescription/DDCMS/interface/DDCompactView.h" | ||
#include "DetectorDescription/DDCMS/interface/DDDetector.h" | ||
#include "Geometry/Records/interface/IdealGeometryRecord.h" | ||
#include "DD4hep/Detector.h" | ||
#include "DD4hep/DD4hepRootPersistency.h" | ||
|
||
#include "TGeoManager.h" | ||
#include "TFile.h" | ||
#include "TSystem.h" | ||
|
||
class PrintGeomSolids : public edm::one::EDAnalyzer<> { | ||
public: | ||
explicit PrintGeomSolids(const edm::ParameterSet&); | ||
~PrintGeomSolids() override {} | ||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); | ||
|
||
void analyze(edm::Event const& iEvent, edm::EventSetup const&) override; | ||
|
||
private: | ||
edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_; | ||
edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4Hep_; | ||
bool fromDD4Hep_; | ||
}; | ||
|
||
PrintGeomSolids::PrintGeomSolids(const edm::ParameterSet& ps) { | ||
fromDD4Hep_ = ps.getParameter<bool>("fromDD4Hep"); | ||
if (fromDD4Hep_) | ||
cpvTokenDD4Hep_ = esConsumes<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag()); | ||
else | ||
cpvTokenDDD_ = esConsumes<DDCompactView, IdealGeometryRecord>(edm::ESInputTag()); | ||
|
||
edm::LogVerbatim("PrintGeom") << "PrintGeomSolids created with dd4hep: " << fromDD4Hep_; | ||
} | ||
|
||
void PrintGeomSolids::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<bool>("fromDD4Hep", false); | ||
descriptions.add("printGeomSolids", desc); | ||
} | ||
|
||
void PrintGeomSolids::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { | ||
int solids(0); | ||
if (fromDD4Hep_) { | ||
edm::ESTransientHandle<cms::DDCompactView> cpv = iSetup.getTransientHandle(cpvTokenDD4Hep_); | ||
const cms::DDDetector* det = cpv->detector(); | ||
TGeoManager const& geom = det->description()->manager(); | ||
TGeoIterator next(geom.GetTopVolume()); | ||
TGeoNode *node; | ||
TString path; | ||
std::vector<std::string> names; | ||
while (( node = next())) { | ||
next.GetPath( path ); | ||
std::string name = static_cast<std::string>(node->GetVolume()->GetName()); | ||
if (std::find(names.begin(), names.end(), name) == names.end()) { | ||
edm::LogVerbatim("PrintGeom") << name << " " << static_cast<std::string>(node->GetVolume()->GetShape()->GetTitle()); | ||
names.emplace_back(name); | ||
++solids; | ||
} | ||
} | ||
|
||
} else { | ||
edm::ESTransientHandle<DDCompactView> cpv = iSetup.getTransientHandle(cpvTokenDDD_); | ||
const auto& gra = cpv->graph(); | ||
for (DDCompactView::Graph::const_adj_iterator git = gra.begin(); git != gra.end(); ++git) { | ||
const DDLogicalPart& ddLP = gra.nodeData(git); | ||
const DDSolid& solid = ddLP.solid(); | ||
edm::LogVerbatim("PrintGeom") << solid.name() << " " << DDSolidShapesName::name(solid.shape()); | ||
++solids; | ||
} | ||
} | ||
edm::LogVerbatim("PrintGeom") << "\n\nPrintGeomSolids finds " << solids << " solids"; | ||
} | ||
|
||
//define this as a plug-in | ||
DEFINE_FWK_MODULE(PrintGeomSolids); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from Configuration.Eras.Era_Run3_cff import Run3 | ||
process = cms.Process('G4PrintGeometry',Run3) | ||
process.load('Configuration.Geometry.GeometryExtended2021Reco_cff') | ||
|
||
#from Configuration.Eras.Era_Run3_dd4hep_cff import Run3_dd4hep | ||
#process = cms.Process('G4PrintGeometry',Run3_dd4hep) | ||
#process.load('Configuration.Geometry.GeometryDD4hepExtended2021Reco_cff') | ||
|
||
process.load('SimGeneral.HepPDTESSource.pdt_cfi') | ||
|
||
process.load('IOMC.RandomEngine.IOMC_cff') | ||
process.load('IOMC.EventVertexGenerators.VtxSmearedFlat_cfi') | ||
process.load('GeneratorInterface.Core.generatorSmeared_cfi') | ||
process.load('FWCore.MessageService.MessageLogger_cfi') | ||
process.load('SimG4Core.Application.g4SimHits_cfi') | ||
process.load('SimG4Core.PrintGeomInfo.printGeomSolids_cff') | ||
|
||
if hasattr(process,'MessageLogger'): | ||
process.MessageLogger.G4cout=dict() | ||
process.MessageLogger.G4cerr=dict() | ||
process.MessageLogger.PrintGeom=dict() | ||
|
||
process.source = cms.Source("EmptySource") | ||
|
||
process.generator = cms.EDProducer("FlatRandomEGunProducer", | ||
PGunParameters = cms.PSet( | ||
PartID = cms.vint32(14), | ||
MinEta = cms.double(-3.5), | ||
MaxEta = cms.double(3.5), | ||
MinPhi = cms.double(-3.14159265359), | ||
MaxPhi = cms.double(3.14159265359), | ||
MinE = cms.double(9.99), | ||
MaxE = cms.double(10.01) | ||
), | ||
AddAntiParticle = cms.bool(False), | ||
Verbosity = cms.untracked.int32(0), | ||
firstRun = cms.untracked.uint32(1) | ||
) | ||
|
||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(1) | ||
) | ||
|
||
process.g4SimHits.UseMagneticField = False | ||
process.g4SimHits.Physics.type = 'SimG4Core/Physics/DummyPhysics' | ||
process.g4SimHits.Physics.DummyEMPhysics = True | ||
process.g4SimHits.Physics.DefaultCutValue = 10. | ||
|
||
process.p1 = cms.Path(process.generator*process.VtxSmeared*process.generatorSmeared*process.g4SimHits*process.printGeomSolids) |