Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:44

0001 #include "SimG4Core/DD4hepGeometry/interface/DD4hep_DDDWorld.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0004 #include "DDG4/Geant4Converter.h"
0005 #include "DDG4/Geant4GeometryInfo.h"
0006 #include "DDG4/Geant4Mapping.h"
0007 #include "DD4hep/Detector.h"
0008 #include "DD4hep/Printout.h"
0009 
0010 #include "G4RunManagerKernel.hh"
0011 #include "G4PVPlacement.hh"
0012 #include "G4TransportationManager.hh"
0013 
0014 using namespace edm;
0015 using namespace cms;
0016 using namespace dd4hep;
0017 using namespace dd4hep::sim;
0018 
0019 DDDWorld::DDDWorld(const DDDetector* ddd, dd4hep::sim::Geant4GeometryMaps::VolumeMap& map) {
0020   LogVerbatim("SimG4CoreApplication") << "DD4hep_DDDWorld: initialization of DDDWorld...";
0021 
0022   DetElement world = ddd->description()->world();
0023   printout(INFO, "SimDD4CMS", "+++ DDDWorld::DDDWorld start... %s", world.name());
0024   const Detector& detector = *ddd->description();
0025   Geant4Converter g4Geo(detector);
0026   Geant4GeometryInfo* geometry = g4Geo.create(world).detach();
0027   map = geometry->g4Volumes;
0028 
0029   auto it = geometry->g4Volumes.find(detector.worldVolume().ptr());
0030   LogVerbatim("Geometry") << "The world is " << it->first.name();
0031 
0032   if (geometry) {
0033     LogVerbatim("Geometry").log([&](auto& log) {
0034       for (auto iter = map.begin(); iter != map.end(); ++iter) {
0035         log << iter->first.name() << " = ";
0036         if (iter->second)
0037           log << iter->second->GetName() << "; ";
0038         else
0039           log << "***none***; ";
0040       }
0041       log << "\n";
0042     });
0043   }
0044   m_world = geometry->world();
0045 
0046   setAsWorld(m_world);
0047   printout(INFO, "SimDD4CMS", "+++ DDDWorld::DDDWorld done!");
0048 
0049   LogVerbatim("SimG4CoreApplication") << "DD4hep_DDDWorld: initialization of DDDWorld done.";
0050 }
0051 
0052 DDDWorld::~DDDWorld() {}
0053 
0054 void DDDWorld::setAsWorld(G4VPhysicalVolume* pv) {
0055   G4RunManagerKernel* kernel = G4RunManagerKernel::GetRunManagerKernel();
0056 
0057   if (kernel)
0058     kernel->DefineWorldVolume(pv);
0059   else
0060     edm::LogError("SimG4CoreGeometry") << "cms::DDDWorld::setAsWorld: No G4RunManagerKernel?";
0061 
0062   edm::LogInfo("SimG4CoreGeometry") << " World volume defined ";
0063 }
0064 
0065 void DDDWorld::workerSetAsWorld(G4VPhysicalVolume* pv) {
0066   G4RunManagerKernel* kernel = G4RunManagerKernel::GetRunManagerKernel();
0067   if (kernel) {
0068     kernel->WorkerDefineWorldVolume(pv);
0069     // The following does not get done in WorkerDefineWorldVolume()
0070     // because we don't use G4MTRunManager
0071     G4TransportationManager* transM = G4TransportationManager::GetTransportationManager();
0072     transM->SetWorldForTracking(pv);
0073   } else
0074     edm::LogError("SimG4CoreGeometry") << "cms::DDDWorld::workerSetAsWorld: No G4RunManagerKernel?";
0075 
0076   edm::LogInfo("SimG4CoreGeometry") << " World volume defined (for worker) ";
0077 }