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()
36  << " nodes:" << G4endl;
37  for (unsigned int ii=0; ii<nodeNames_.size(); ii++)
38  G4cout << "Node[" << ii << "] : " << nodeNames_[ii] << G4endl;
39 
42  solidShape_[DDSolidShape::ddtrap] = "Trapezoid";
45  solidShape_[DDSolidShape::ddpolyhedra_rz] = "Polyhedra_rz";
46  solidShape_[DDSolidShape::ddpolycone_rrz] = "Polycone_rrz";
47  solidShape_[DDSolidShape::ddpolyhedra_rrz] = "Polyhedra_rrz";
49  solidShape_[DDSolidShape::ddunion] = "UnionSolid";
50  solidShape_[DDSolidShape::ddsubtraction] = "SubtractionSolid";
51  solidShape_[DDSolidShape::ddintersection] = "IntersectionSolid";
52  solidShape_[DDSolidShape::ddshapeless] = "ShapelessSolid";
53  solidShape_[DDSolidShape::ddpseudotrap] = "PseudoTrapezoid";
54  solidShape_[DDSolidShape::ddtrunctubs] = "TruncatedTube";
56  solidShape_[DDSolidShape::ddellipticaltube] = "EllipticalTube";
58  solidShape_[DDSolidShape::ddextrudedpolygon]= "ExtrudedPolygon";
60 }
61 
63 
65 
67  (*job)()->get<IdealGeometryRecord>().get(pDD);
68  const DDCompactView* cpv = &(*pDD);
69 
70  const auto & gra = cpv->graph();
71 
74 
76  solidMap_.clear();
77  for( adjl_iterator git=gra.begin();
78  git != gra.end(); ++git) {
79  const DDLogicalPart & ddLP = gra.nodeData(git);
80  addSolid(ddLP);
81  ++i;
82  if (!git->empty()) {
83  // ask for children of ddLP
84  for( Graph::edge_list::const_iterator cit = git->begin();
85  cit != git->end(); ++cit) {
86  const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
87  addSolid(ddcurLP);
88  }
89  }
90  }
91  G4cout << "Finds " << solidMap_.size() << " different solids in the tree"
92  << G4endl;
93 }
94 
96  const DDSolid& solid = part.solid();
97  std::map<DDSolidShape,std::string>::iterator it = solidShape_.find(solid.shape());
98  std::string name = solid.name().name();
99  if (it == solidShape_.end()) solidMap_[name] = DDSolidShape::dd_not_init;
100  else solidMap_[name] = it->first;
101 //G4cout << "Solid " << name << " is of shape " << solidMap_[name] << G4endl;
102 }
103 
105  theTopPV_ = getTopPV();
106  if (theTopPV_) {
107  lvs_.clear(); sls_.clear(); touch_.clear();
108  fillLV(theTopPV_->GetLogicalVolume());
109  std::string name = theTopPV_->GetName();
110  dumpSummary(G4cout,name);
111 
112  for (unsigned int k=0; k<nodeNames_.size(); ++k) {
113  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
114  std::vector<G4LogicalVolume *>::const_iterator lvcite;
115  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
116  if ((*lvcite)->GetName() == (G4String)(nodeNames_[k])) {
117  lvs_.clear(); sls_.clear(); touch_.clear();
118  fillLV(*lvcite);
120  }
121  }
122  }
123  }
124 }
125 
126 void PrintGeomSummary::fillLV(G4LogicalVolume * lv) {
127 
128  if (std::find(lvs_.begin(),lvs_.end(),lv) == lvs_.end()) lvs_.push_back(lv);
129  G4VSolid* sl = lv->GetSolid();
130  if (std::find(sls_.begin(),sls_.end(),sl) == sls_.end()) sls_.push_back(sl);
131  touch_.push_back(lv);
132  for(int ii = 0; ii < (int)(lv->GetNoDaughters()); ii++)
133  fillLV(lv->GetDaughter(ii)->GetLogicalVolume());
134 }
135 
137 
138  //---------- Dump number of objects of each class
139  out << G4endl << G4endl
140  << "@@@@@@@@@@@@@@@@@@ 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"
154  << G4endl;
155  kount_.clear();
156  for (std::vector<G4LogicalVolume*>::iterator it = lvs_.begin();
157  it != lvs_.end(); ++it) {
158  std::string name = ((*it)->GetSolid())->GetName();
159  addName(name);
160  }
161  printSummary(out);
162  //Finally the touchables
163  out << G4endl << "Occurence of each type of shape among Touchables"
164  << G4endl;
165  kount_.clear();
166  for (std::vector<G4LogicalVolume*>::iterator it = touch_.begin();
167  it != touch_.end(); ++it) {
168  std::string name = ((*it)->GetSolid())->GetName();
169  addName(name);
170  }
171  printSummary(out);
172 }
173 
174 G4VPhysicalVolume * PrintGeomSummary::getTopPV() {
175 
176  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
177 }
178 
180  bool refl(false);
181  if (name.find("_refl") < name.size()) {
182  refl = true;
183  name = name.substr(0,(name.find("_refl")));
184  }
185  std::map<std::string,DDSolidShape>::const_iterator jt=solidMap_.find(name);
186  DDSolidShape shape = (jt == solidMap_.end()) ? DDSolidShape::dd_not_init : jt->second;
187  std::map<DDSolidShape,std::pair<int,int>>::iterator itr = kount_.find(shape);
188  if (itr == kount_.end()) {
189  kount_[shape] = (refl) ? std::pair<int,int>(0,1) : std::pair<int,int>(1,0);
190  } else {
191  kount_[shape] = (refl) ?
192  std::pair<int,int>(((itr->second).first),++((itr->second).second)) :
193  std::pair<int,int>(++((itr->second).first),((itr->second).second));
194  }
195 }
196 
197 void PrintGeomSummary::printSummary(std::ostream & out) {
198  int k(0);
199  for (std::map<DDSolidShape,std::pair<int,int> >::iterator itr=kount_.begin();
200  itr != kount_.end(); ++itr, ++k) {
201  std::string shape = solidShape_[itr->first];
202  out << "Shape [" << k << "] " << shape << " # " << (itr->second).first
203  << " : " << (itr->second).second << G4endl;
204  }
205 }
206 
std::map< DDSolidShape, std::string > solidShape_
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:78
void printSummary(std::ostream &out)
DDSolidShape
Definition: DDSolidShapes.h:4
G4VPhysicalVolume * getTopPV()
G4VPhysicalVolume * theTopPV_
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
#define nullptr
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:83
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
U second(std::pair< T, U > const &p)
~PrintGeomSummary() override
std::vector< G4LogicalVolume * > touch_
PrintGeomSummary(edm::ParameterSet const &p)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:138
Graph::const_adj_iterator adjl_iterator
std::map< DDSolidShape, std::pair< int, int > > kount_
std::vector< std::string > nodeNames_
void fillLV(G4LogicalVolume *lv)
ii
Definition: cuy.py:589
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
std::vector< G4VSolid * > sls_
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:86
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:125
const std::string & name() const
Returns the name.
Definition: DDName.cc:88
std::map< std::string, DDSolidShape > solidMap_