Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:22

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0007 #include "DetectorDescription/DDCMS/interface/DDVectorRegistry.h"
0008 #include "Geometry/Records/interface/DDVectorRegistryRcd.h"
0009 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0010 #include "DDG4/Geant4Converter.h"
0011 #include "DD4hep/Detector.h"
0012 
0013 #include <iostream>
0014 #include <string>
0015 
0016 using namespace std;
0017 using namespace cms;
0018 using namespace edm;
0019 using namespace dd4hep;
0020 
0021 class DD4hepTestG4Geometry : public one::EDAnalyzer<> {
0022 public:
0023   explicit DD4hepTestG4Geometry(const ParameterSet&);
0024 
0025   void beginJob() override {}
0026   void analyze(Event const& iEvent, EventSetup const&) override;
0027   void endJob() override {}
0028 
0029 private:
0030   const ESInputTag m_tag;
0031   const ESGetToken<DDVectorRegistry, DDVectorRegistryRcd> m_registryToken;
0032   const ESGetToken<DDDetector, IdealGeometryRecord> m_detectorToken;
0033   const string m_detElementPath;
0034   const string m_placedVolPath;
0035 };
0036 
0037 DD4hepTestG4Geometry::DD4hepTestG4Geometry(const ParameterSet& iConfig)
0038     : m_tag(iConfig.getParameter<ESInputTag>("DDDetector")),
0039       m_registryToken(esConsumes(m_tag)),
0040       m_detectorToken(esConsumes(m_tag)) {}
0041 
0042 void DD4hepTestG4Geometry::analyze(const Event&, const EventSetup& iEventSetup) {
0043   LogVerbatim("Geometry") << "\nDD4hepTestG4Geometry::analyze: " << m_tag;
0044 
0045   ESTransientHandle<DDVectorRegistry> reg = iEventSetup.getTransientHandle(m_registryToken);
0046   ESTransientHandle<DDDetector> ddd = iEventSetup.getTransientHandle(m_detectorToken);
0047 
0048   const dd4hep::Detector& detector = *ddd->description();
0049   dd4hep::sim::Geant4Converter g4Geo = dd4hep::sim::Geant4Converter(detector);
0050   g4Geo.debugMaterials = true;
0051   g4Geo.debugElements = true;
0052   g4Geo.debugShapes = true;
0053   g4Geo.debugVolumes = true;
0054   g4Geo.debugPlacements = true;
0055   g4Geo.create(detector.world());
0056 
0057   LogVerbatim("Geometry") << "Done.";
0058 }
0059 
0060 DEFINE_FWK_MODULE(DD4hepTestG4Geometry);