CMS 3D CMS Logo

DDTestNavigateGeometry.cc
Go to the documentation of this file.
11 #include "DD4hep/Detector.h"
12 #include "DD4hep/DD4hepRootPersistency.h"
13 #include "DD4hep/DetectorTools.h"
14 #include "DD4hep/VolumeProcessor.h"
15 
16 #include <iostream>
17 #include <string>
18 
19 using namespace std;
20 using namespace cms;
21 using namespace edm;
22 using namespace dd4hep;
23 
24 class DDTestNavigateGeometry : public one::EDAnalyzer<> {
25 public:
26  explicit DDTestNavigateGeometry(const ParameterSet&);
27 
28  void beginJob() override {}
29  void analyze(Event const& iEvent, EventSetup const&) override;
30  void endJob() override {}
31 
32 private:
34  const string m_detElementPath;
35  const string m_placedVolPath;
36 
37 };
38 
40  : m_tag(iConfig.getParameter<ESInputTag>("DDDetector")),
41  m_detElementPath(iConfig.getParameter<string>("detElementPath")),
42  m_placedVolPath(iConfig.getParameter<string>("placedVolumePath"))
43 {}
44 
45 void
47 {
48  LogVerbatim("Geometry") << "\nDDTestNavigateGeometry::analyze: " << m_tag;
49 
50  const DDVectorRegistryRcd& regRecord = iEventSetup.get<DDVectorRegistryRcd>();
52  regRecord.get(m_tag.module(), reg);
53 
54  LogVerbatim("Geometry").log([&reg](auto& log) {
55  for(const auto& p: reg->vectors) {
56  log << "\n " << p.first << " => ";
57  for(const auto& i : p.second)
58  log << i << ", ";
59  }
60  });
61 
62  const GeometryFileRcd& ddRecord = iEventSetup.get<GeometryFileRcd>();
64  ddRecord.get(m_tag.module(), ddd);
65 
66  const dd4hep::Detector& detector = *ddd->description();
67 
68  DetElement startDetEl, world = detector.world();
69  LogVerbatim("Geometry") << "World placement path " << world.placementPath()
70  << ", path " << world.path();
71  PlacedVolume startPVol = world.placement();
72  if( !m_detElementPath.empty()) {
73  LogVerbatim("Geometry") << "Det element path is " << m_detElementPath;
74  startDetEl = dd4hep::detail::tools::findElement(detector, m_detElementPath);
75  if(startDetEl.isValid())
76  LogVerbatim("Geometry") << "Found starting DetElement!\n";
77  }
78  else if( !m_placedVolPath.empty()) {
79  LogVerbatim("Geometry") << "Placed volume path is " << m_placedVolPath;
80  startPVol = dd4hep::detail::tools::findNode(world.placement(), m_placedVolPath);
81  if(startPVol.isValid())
82  LogVerbatim("Geometry") << "Found srarting PlacedVolume!\n";
83  }
84  if( !startPVol.isValid()) {
85  if( !startDetEl.isValid()) {
86  except("VolumeScanner", "Failed to find start conditions for the volume scan");
87  }
88  startPVol = startDetEl.placement();
89  }
90 
92  LogVerbatim("Geometry") << startPVol.name();
93  PlacedVolumeScanner().scanPlacements(proc, startPVol, 0, true);
94 
95  LogVerbatim("Geometry") << "VolumeScanner" << "+++ Visited a total of %d placed volumes." << proc.count();
96 }
97 
DDTestNavigateGeometry(const ParameterSet &)
TrainProcessor *const proc
Definition: MVATrainer.cc:101
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
dd4hep::PlacedVolume PlacedVolume
LogVerbatim & log(F &&iF)
Namespace of DDCMS conversion namespace.
void analyze(Event const &iEvent, EventSetup const &) override
HLT enums.
T get() const
Definition: EventSetup.h:71
const std::string & module() const
Definition: ESInputTag.h:99