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  std::map<std::string, int> shapes;
61  if (fromDD4hep_) {
62  const cms::DDCompactView* cpv = &iSetup.getData(cpvTokenDD4hep_);
63  const cms::DDDetector* det = cpv->detector();
64  TGeoManager const& geom = det->description()->manager();
65  TGeoIterator next(geom.GetTopVolume());
66  TGeoNode* node;
67  TString path;
68  std::vector<std::string> names;
69  while ((node = next())) {
70  next.GetPath(path);
71  std::string name = static_cast<std::string>(node->GetVolume()->GetName());
72  if (std::find(names.begin(), names.end(), name) == names.end()) {
73  edm::LogVerbatim("PrintGeom") << name << " "
74  << static_cast<std::string>(node->GetVolume()->GetShape()->GetTitle());
75  names.emplace_back(name);
76  std::string shape = node->GetVolume()->GetShape()->GetTitle();
77  if (shapes.find(shape) == shapes.end())
78  shapes.emplace(std::make_pair(shape, 1));
79  else
80  ++shapes[shape];
81  ++solids;
82  }
83  }
84 
85  } else {
86  const DDCompactView* cpv = &iSetup.getData(cpvTokenDDD_);
87  const auto& gra = cpv->graph();
88  for (DDCompactView::Graph::const_adj_iterator git = gra.begin(); git != gra.end(); ++git) {
89  const DDLogicalPart& ddLP = gra.nodeData(git);
90  const DDSolid& solid = ddLP.solid();
91  edm::LogVerbatim("PrintGeom") << solid.name() << " " << DDSolidShapesName::name(solid.shape());
93  if (shapes.find(shape) == shapes.end())
94  shapes.emplace(std::make_pair(shape, 1));
95  else
96  ++shapes[shape];
97  ++solids;
98  }
99  }
100  edm::LogVerbatim("PrintGeom") << "\n\nPrintGeomSolids finds " << solids << " solids\n\n";
101  for (std::map<std::string, int>::iterator itr = shapes.begin(); itr != shapes.end(); ++itr) {
102  edm::LogVerbatim("PrintGeom") << "Shape:" << itr->first << " # " << itr->second;
103  }
104 }
105 
106 //define this as a plug-in
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::ESGetToken< DDCompactView, IdealGeometryRecord > cpvTokenDDD_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PrintGeomSolids(const edm::ParameterSet &)
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:123
const N & name() const
Definition: DDBase.h:58
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.