CMS 3D CMS Logo

PrintGeomSolids.cc
Go to the documentation of this file.
1 // system include files
2 #include <map>
3 #include <string>
4 
5 // user include files
21 #include "DD4hep/Detector.h"
22 #include "DD4hep/DD4hepRootPersistency.h"
23 
24 #include "TGeoManager.h"
25 #include "TFile.h"
26 #include "TSystem.h"
27 
29 public:
30  explicit PrintGeomSolids(const edm::ParameterSet&);
31  ~PrintGeomSolids() override {}
32  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
33 
34  void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
35 
36 private:
40 };
41 
43  fromDD4hep_ = ps.getParameter<bool>("fromDD4hep");
44  if (fromDD4hep_)
45  cpvTokenDD4hep_ = esConsumes<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
46  else
47  cpvTokenDDD_ = esConsumes<DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
48 
49  edm::LogVerbatim("PrintGeom") << "PrintGeomSolids created with dd4hep: " << fromDD4hep_;
50 }
51 
54  desc.add<bool>("fromDD4hep", false);
55  descriptions.add("printGeomSolids", desc);
56 }
57 
59  int solids(0);
60  if (fromDD4hep_) {
61  const cms::DDCompactView* cpv = &iSetup.getData(cpvTokenDD4hep_);
62  const cms::DDDetector* det = cpv->detector();
63  TGeoManager const& geom = det->description()->manager();
64  TGeoIterator next(geom.GetTopVolume());
65  TGeoNode* node;
66  TString path;
67  std::vector<std::string> names;
68  while ((node = next())) {
69  next.GetPath(path);
70  std::string name = static_cast<std::string>(node->GetVolume()->GetName());
71  if (std::find(names.begin(), names.end(), name) == names.end()) {
72  edm::LogVerbatim("PrintGeom") << name << " "
73  << static_cast<std::string>(node->GetVolume()->GetShape()->GetTitle());
74  names.emplace_back(name);
75  ++solids;
76  }
77  }
78 
79  } else {
80  const DDCompactView* cpv = &iSetup.getData(cpvTokenDDD_);
81  const auto& gra = cpv->graph();
82  for (DDCompactView::Graph::const_adj_iterator git = gra.begin(); git != gra.end(); ++git) {
83  const DDLogicalPart& ddLP = gra.nodeData(git);
84  const DDSolid& solid = ddLP.solid();
85  edm::LogVerbatim("PrintGeom") << solid.name() << " " << DDSolidShapesName::name(solid.shape());
86  ++solids;
87  }
88  }
89  edm::LogVerbatim("PrintGeom") << "\n\nPrintGeomSolids finds " << solids << " solids";
90 }
91 
92 //define this as a plug-in
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< DDCompactView, IdealGeometryRecord > cpvTokenDDD_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dd4hep::Detector const * description() const
Definition: DDDetector.h:35
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
const std::string names[nVars_]
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
static const char *const name(DDSolidShape s)
Definition: DDSolidShapes.h:33
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > cpvTokenDD4hep_
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
bool getData(T &iHolder) const
Definition: EventSetup.h:122
PrintGeomSolids(const edm::ParameterSet &)
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:123
const N & name() const
Definition: DDBase.h:59
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
~PrintGeomSolids() override
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.