CMS 3D CMS Logo

PrintGeomSummary.cc
Go to the documentation of this file.
2 
5 
16 
17 #include "G4Run.hh"
18 #include "G4PhysicalVolumeStore.hh"
19 #include "G4LogicalVolumeStore.hh"
20 #include "G4VPhysicalVolume.hh"
21 #include "G4LogicalVolume.hh"
22 #include "G4VSolid.hh"
23 #include "G4Material.hh"
24 #include "G4Track.hh"
25 #include "G4VisAttributes.hh"
26 #include "G4UserLimits.hh"
27 #include "G4TransportationManager.hh"
28 
29 #include <set>
30 #include <map>
31 
33  std::vector<std::string> defNames;
34  nodeNames_ = p.getUntrackedParameter<std::vector<std::string>>("NodeNames", defNames);
35  G4cout << "PrintGeomSummary:: initialised for " << nodeNames_.size() << " nodes:" << G4endl;
36  for (unsigned int ii = 0; ii < nodeNames_.size(); ii++)
37  G4cout << "Node[" << ii << "] : " << nodeNames_[ii] << G4endl;
38 
41  solidShape_[DDSolidShape::ddtrap] = "Trapezoid";
44  solidShape_[DDSolidShape::ddpolyhedra_rz] = "Polyhedra_rz";
45  solidShape_[DDSolidShape::ddpolycone_rrz] = "Polycone_rrz";
46  solidShape_[DDSolidShape::ddpolyhedra_rrz] = "Polyhedra_rrz";
48  solidShape_[DDSolidShape::ddunion] = "UnionSolid";
49  solidShape_[DDSolidShape::ddsubtraction] = "SubtractionSolid";
50  solidShape_[DDSolidShape::ddintersection] = "IntersectionSolid";
51  solidShape_[DDSolidShape::ddshapeless] = "ShapelessSolid";
52  solidShape_[DDSolidShape::ddpseudotrap] = "PseudoTrapezoid";
53  solidShape_[DDSolidShape::ddtrunctubs] = "TruncatedTube";
55  solidShape_[DDSolidShape::ddellipticaltube] = "EllipticalTube";
57  solidShape_[DDSolidShape::ddextrudedpolygon] = "ExtrudedPolygon";
59 }
60 
62 
65  (*job)()->get<IdealGeometryRecord>().get(pDD);
66  const DDCompactView* cpv = &(*pDD);
67 
68  const auto& gra = cpv->graph();
69 
72 
73  Graph::index_type i = 0;
74  solidMap_.clear();
75  for (adjl_iterator git = gra.begin(); git != gra.end(); ++git) {
76  const DDLogicalPart& ddLP = gra.nodeData(git);
77  addSolid(ddLP);
78  ++i;
79  if (!git->empty()) {
80  // ask for children of ddLP
81  for (Graph::edge_list::const_iterator cit = git->begin(); cit != git->end(); ++cit) {
82  const DDLogicalPart& ddcurLP = gra.nodeData(cit->first);
83  addSolid(ddcurLP);
84  }
85  }
86  }
87  G4cout << "Finds " << solidMap_.size() << " different solids in the tree" << G4endl;
88 }
89 
91  const DDSolid& solid = part.solid();
92  std::map<DDSolidShape, std::string>::iterator it = solidShape_.find(solid.shape());
93  std::string name = solid.name().name();
94  if (it == solidShape_.end())
96  else
97  solidMap_[name] = it->first;
98  //G4cout << "Solid " << name << " is of shape " << solidMap_[name] << G4endl;
99 }
100 
102  theTopPV_ = getTopPV();
103  if (theTopPV_) {
104  lvs_.clear();
105  sls_.clear();
106  touch_.clear();
107  fillLV(theTopPV_->GetLogicalVolume());
108  std::string name = theTopPV_->GetName();
109  dumpSummary(G4cout, name);
110 
111  for (unsigned int k = 0; k < nodeNames_.size(); ++k) {
112  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
113  std::vector<G4LogicalVolume*>::const_iterator lvcite;
114  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
115  if ((*lvcite)->GetName() == (G4String)(nodeNames_[k])) {
116  lvs_.clear();
117  sls_.clear();
118  touch_.clear();
119  fillLV(*lvcite);
121  }
122  }
123  }
124  }
125 }
126 
127 void PrintGeomSummary::fillLV(G4LogicalVolume* lv) {
128  if (std::find(lvs_.begin(), lvs_.end(), lv) == lvs_.end())
129  lvs_.push_back(lv);
130  G4VSolid* sl = lv->GetSolid();
131  if (std::find(sls_.begin(), sls_.end(), sl) == sls_.end())
132  sls_.push_back(sl);
133  touch_.push_back(lv);
134  for (int ii = 0; ii < (int)(lv->GetNoDaughters()); ii++)
135  fillLV(lv->GetDaughter(ii)->GetLogicalVolume());
136 }
137 
139  //---------- Dump number of objects of each class
140  out << G4endl << G4endl << "@@@@@@@@@@@@@@@@@@ Dumping Summary For Node " << name << G4endl;
141  out << " Number of G4VSolid's: " << sls_.size() << G4endl;
142  out << " Number of G4LogicalVolume's: " << lvs_.size() << G4endl;
143  out << " Number of Touchable's: " << touch_.size() << G4endl;
144  //First the solids
145  out << G4endl << "Occurence of each type of shape among Solids" << G4endl;
146  kount_.clear();
147  for (std::vector<G4VSolid*>::iterator it = sls_.begin(); it != sls_.end(); ++it) {
148  std::string name = (*it)->GetName();
149  addName(name);
150  }
151  printSummary(out);
152  //Then the logical volumes
153  out << G4endl << "Occurence of each type of shape among Logical Volumes" << G4endl;
154  kount_.clear();
155  for (std::vector<G4LogicalVolume*>::iterator it = lvs_.begin(); it != lvs_.end(); ++it) {
156  std::string name = ((*it)->GetSolid())->GetName();
157  addName(name);
158  }
159  printSummary(out);
160  //Finally the touchables
161  out << G4endl << "Occurence of each type of shape among Touchables" << G4endl;
162  kount_.clear();
163  for (std::vector<G4LogicalVolume*>::iterator it = touch_.begin(); it != touch_.end(); ++it) {
164  std::string name = ((*it)->GetSolid())->GetName();
165  addName(name);
166  }
167  printSummary(out);
168 }
169 
170 G4VPhysicalVolume* PrintGeomSummary::getTopPV() {
171  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
172 }
173 
175  bool refl(false);
176  if (name.find("_refl") < name.size()) {
177  refl = true;
178  name = name.substr(0, (name.find("_refl")));
179  }
180  std::map<std::string, DDSolidShape>::const_iterator jt = solidMap_.find(name);
181  DDSolidShape shape = (jt == solidMap_.end()) ? DDSolidShape::dd_not_init : jt->second;
182  std::map<DDSolidShape, std::pair<int, int>>::iterator itr = kount_.find(shape);
183  if (itr == kount_.end()) {
184  kount_[shape] = (refl) ? std::pair<int, int>(0, 1) : std::pair<int, int>(1, 0);
185  } else {
186  kount_[shape] = (refl) ? std::pair<int, int>(((itr->second).first), ++((itr->second).second))
187  : std::pair<int, int>(++((itr->second).first), ((itr->second).second));
188  }
189 }
190 
191 void PrintGeomSummary::printSummary(std::ostream& out) {
192  int k(0);
193  for (std::map<DDSolidShape, std::pair<int, int>>::iterator itr = kount_.begin(); itr != kount_.end(); ++itr, ++k) {
194  std::string shape = solidShape_[itr->first];
195  out << "Shape [" << k << "] " << shape << " # " << (itr->second).first << " : " << (itr->second).second << G4endl;
196  }
197 }
std::vector< G4VSolid * > sls_
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double >::size_type index_type
Definition: Graph.h:16
void addName(std::string name)
void addSolid(const DDLogicalPart &part)
const N & name() const
Definition: DDBase.h:74
void printSummary(std::ostream &out)
std::map< DDSolidShape, std::string > solidShape_
#define nullptr
DDSolidShape
Definition: DDSolidShapes.h:6
G4VPhysicalVolume * getTopPV()
G4VPhysicalVolume * theTopPV_
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
U second(std::pair< T, U > const &p)
~PrintGeomSummary() override
PrintGeomSummary(edm::ParameterSet const &p)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:138
Graph::const_adj_iterator adjl_iterator
std::vector< std::string > nodeNames_
void fillLV(G4LogicalVolume *lv)
ii
Definition: cuy.py:590
int k[5][pyjets_maxn]
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
void update(const BeginOfJob *job) override
This routine will be called when the appropriate signal arrives.
part
Definition: HCALResponse.h:20
void dumpSummary(std::ostream &out, std::string name)
std::vector< G4LogicalVolume * > lvs_
Pt3D refl(const Pt3D &p)
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:125
std::vector< G4LogicalVolume * > touch_
std::map< std::string, DDSolidShape > solidMap_
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
std::map< DDSolidShape, std::pair< int, int > > kount_