CMS 3D CMS Logo

DD4hep_DDDWorld.cc
Go to the documentation of this file.
4 #include "DDG4/Geant4Converter.h"
5 #include "DDG4/Geant4GeometryInfo.h"
6 #include "DDG4/Geant4Mapping.h"
7 #include "DD4hep/Detector.h"
8 #include "DD4hep/Printout.h"
9 
10 #include "G4RunManagerKernel.hh"
11 #include "G4PVPlacement.hh"
12 #include "G4TransportationManager.hh"
13 
14 using namespace edm;
15 using namespace cms;
16 using namespace dd4hep;
17 using namespace dd4hep::sim;
18 
19 DDDWorld::DDDWorld(const DDDetector* ddd, dd4hep::sim::Geant4GeometryMaps::VolumeMap& map) {
20  LogVerbatim("SimG4CoreApplication") << "DD4hep_DDDWorld: initialization of DDDWorld...";
21 
22  DetElement world = ddd->description()->world();
23  printout(INFO, "SimDD4CMS", "+++ DDDWorld::DDDWorld start... %s", world.name());
24  const Detector& detector = *ddd->description();
25  Geant4Converter g4Geo(detector);
26  Geant4GeometryInfo* geometry = g4Geo.create(world).detach();
27  map = geometry->g4Volumes;
28 
29  auto it = geometry->g4Volumes.find(detector.worldVolume().ptr());
30  LogVerbatim("Geometry") << "The world is " << it->first.name();
31 
32  if (geometry) {
33  LogVerbatim("Geometry").log([&](auto& log) {
34  for (auto iter = map.begin(); iter != map.end(); ++iter) {
35  log << iter->first.name() << " = ";
36  if (iter->second)
37  log << iter->second->GetName() << "; ";
38  else
39  log << "***none***; ";
40  }
41  log << "\n";
42  });
43  }
44  m_world = geometry->world();
45 
46  setAsWorld(m_world);
47  printout(INFO, "SimDD4CMS", "+++ DDDWorld::DDDWorld done!");
48 
49  LogVerbatim("SimG4CoreApplication") << "DD4hep_DDDWorld: initialization of DDDWorld done.";
50 }
51 
53 
54 void DDDWorld::setAsWorld(G4VPhysicalVolume* pv) {
55  G4RunManagerKernel* kernel = G4RunManagerKernel::GetRunManagerKernel();
56 
57  if (kernel)
58  kernel->DefineWorldVolume(pv);
59  else
60  edm::LogError("SimG4CoreGeometry") << "cms::DDDWorld::setAsWorld: No G4RunManagerKernel?";
61 
62  edm::LogInfo("SimG4CoreGeometry") << " World volume defined ";
63 }
64 
65 void DDDWorld::workerSetAsWorld(G4VPhysicalVolume* pv) {
66  G4RunManagerKernel* kernel = G4RunManagerKernel::GetRunManagerKernel();
67  if (kernel) {
68  kernel->WorkerDefineWorldVolume(pv);
69  // The following does not get done in WorkerDefineWorldVolume()
70  // because we don't use G4MTRunManager
71  G4TransportationManager* transM = G4TransportationManager::GetTransportationManager();
72  transM->SetWorldForTracking(pv);
73  } else
74  edm::LogError("SimG4CoreGeometry") << "cms::DDDWorld::workerSetAsWorld: No G4RunManagerKernel?";
75 
76  edm::LogInfo("SimG4CoreGeometry") << " World volume defined (for worker) ";
77 }
Log< level::Info, true > LogVerbatim
dd4hep::Detector const * description() const
Definition: DDDetector.h:35
Log< level::Error, false > LogError
DDDWorld(const DDCompactView *pDD, const cms::DDCompactView *pDD4hep, SensitiveDetectorCatalog &, int verb, bool cuts, bool pcut)
Definition: DDDWorld.cc:23
~DDDWorld()
Definition: DDDWorld.cc:70
def pv(vc)
Definition: MetAnalyzer.py:7
Namespace of DDCMS conversion namespace.
Log< level::Info, false > LogInfo
HLT enums.