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 
40  solidShape_[ddbox] = "Box";
41  solidShape_[ddtubs] = "Tube";
42  solidShape_[ddtrap] = "Trapezoid";
43  solidShape_[ddcons] = "Cone";
44  solidShape_[ddpolycone_rz] = "Polycone_rz";
45  solidShape_[ddpolyhedra_rz] = "Polyhedra_rz";
46  solidShape_[ddpolycone_rrz] = "Polycone_rrz";
47  solidShape_[ddpolyhedra_rrz] = "Polyhedra_rrz";
48  solidShape_[ddtorus] = "Torus";
49  solidShape_[ddunion] = "UnionSolid";
50  solidShape_[ddsubtraction] = "SubtractionSolid";
51  solidShape_[ddintersection] = "IntersectionSolid";
52  solidShape_[ddreflected] = "ReflectedSolid";
53  solidShape_[ddshapeless] = "ShapelessSolid";
54  solidShape_[ddpseudotrap] = "PseudoTrapezoid";
55  solidShape_[ddtrunctubs] = "TruncatedTube";
56  solidShape_[ddsphere] = "Sphere";
57  solidShape_[ddorb] = "Orb";
58  solidShape_[ddellipticaltube] = "EllipticalTube";
59  solidShape_[ddellipsoid] = "Ellipsoid";
60  solidShape_[ddparallelepiped] = "Parallelepiped";
61  solidShape_[ddcuttubs] = "CutTubs";
62  solidShape_[dd_not_init] = "Unknown";
63 }
64 
66 
68 
70  (*job)()->get<IdealGeometryRecord>().get(pDD);
71  const DDCompactView* cpv = &(*pDD);
72 
73  const DDCompactView::graph_type & gra = cpv->graph();
75  solidMap_.clear();
77  git != gra.end(); ++git) {
78  const DDLogicalPart & ddLP = gra.nodeData(git);
79  addSolid(ddLP);
80  ++i;
81  if (git->size()) {
82  // ask for children of ddLP
83  for (DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
84  cit != git->end(); ++cit) {
85  const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
86  addSolid(ddcurLP);
87  }
88  }
89  }
90  G4cout << "Finds " << solidMap_.size() << " different solids in the tree"
91  << G4endl;
92 }
93 
95  const DDSolid& solid = part.solid();
96  std::map<DDSolidShape,std::string>::iterator it = solidShape_.find(solid.shape());
97  std::string name = solid.name().name();
98  if (it == solidShape_.end()) solidMap_[name] = dd_not_init;
99  else solidMap_[name] = it->first;
100 //G4cout << "Solid " << name << " is of shape " << solidMap_[name] << G4endl;
101 }
102 
104  theTopPV_ = getTopPV();
105  if (theTopPV_) {
106  lvs_.clear(); sls_.clear(); 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(); sls_.clear(); touch_.clear();
117  fillLV(*lvcite);
119  }
120  }
121  }
122  }
123 }
124 
125 void PrintGeomSummary::fillLV(G4LogicalVolume * lv) {
126 
127  if (std::find(lvs_.begin(),lvs_.end(),lv) == lvs_.end()) lvs_.push_back(lv);
128  G4VSolid* sl = lv->GetSolid();
129  if (std::find(sls_.begin(),sls_.end(),sl) == sls_.end()) sls_.push_back(sl);
130  touch_.push_back(lv);
131  for(int ii = 0; ii < (int)(lv->GetNoDaughters()); ii++)
132  fillLV(lv->GetDaughter(ii)->GetLogicalVolume());
133 }
134 
136 
137  //---------- Dump number of objects of each class
138  out << G4endl << G4endl
139  << "@@@@@@@@@@@@@@@@@@ Dumping Summary For Node " << name << G4endl;
140  out << " Number of G4VSolid's: " << sls_.size() << G4endl;
141  out << " Number of G4LogicalVolume's: " << lvs_.size() << G4endl;
142  out << " Number of Touchable's: " << touch_.size() << G4endl;
143  //First the solids
144  out << G4endl << "Occurence of each type of shape among Solids" << G4endl;
145  kount_.clear();
146  for (std::vector<G4VSolid*>::iterator it=sls_.begin(); it!=sls_.end(); ++it) {
147  std::string name = (*it)->GetName();
148  addName(name);
149  }
150  printSummary(out);
151  //Then the logical volumes
152  out << G4endl << "Occurence of each type of shape among Logical Volumes"
153  << G4endl;
154  kount_.clear();
155  for (std::vector<G4LogicalVolume*>::iterator it = lvs_.begin();
156  it != lvs_.end(); ++it) {
157  std::string name = ((*it)->GetSolid())->GetName();
158  addName(name);
159  }
160  printSummary(out);
161  //Finally the touchables
162  out << G4endl << "Occurence of each type of shape among Touchables"
163  << G4endl;
164  kount_.clear();
165  for (std::vector<G4LogicalVolume*>::iterator it = touch_.begin();
166  it != touch_.end(); ++it) {
167  std::string name = ((*it)->GetSolid())->GetName();
168  addName(name);
169  }
170  printSummary(out);
171 }
172 
173 G4VPhysicalVolume * PrintGeomSummary::getTopPV() {
174 
175  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
176 }
177 
179  bool refl(false);
180  if (name.find("_refl") < name.size()) {
181  refl = true;
182  name = name.substr(0,(name.find("_refl")));
183  }
184  std::map<std::string,DDSolidShape>::const_iterator jt=solidMap_.find(name);
185  DDSolidShape shape = (jt == solidMap_.end()) ? dd_not_init : jt->second;
186  std::map<DDSolidShape,std::pair<int,int>>::iterator itr = kount_.find(shape);
187  if (itr == kount_.end()) {
188  kount_[shape] = (refl) ? std::pair<int,int>(0,1) : std::pair<int,int>(1,0);
189  } else {
190  kount_[shape] = (refl) ?
191  std::pair<int,int>(((itr->second).first),++((itr->second).second)) :
192  std::pair<int,int>(++((itr->second).first),((itr->second).second));
193  }
194 }
195 
196 void PrintGeomSummary::printSummary(std::ostream & out) {
197  int k(0);
198  for (std::map<DDSolidShape,std::pair<int,int> >::iterator itr=kount_.begin();
199  itr != kount_.end(); ++itr, ++k) {
200  std::string shape = solidShape_[itr->first];
201  out << "Shape [" << k << "] " << shape << " # " << (itr->second).first
202  << " : " << (itr->second).second << G4endl;
203  }
204 }
205 
std::map< DDSolidShape, std::string > solidShape_
T getUntrackedParameter(std::string const &, T const &) const
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:6
const graph_type & graph() const
Provides read-only access to the data structure of the compact-view.
const N & nodeData(const edge_type &) const
Definition: adjgraph.h:317
G4VPhysicalVolume * getTopPV()
G4VPhysicalVolume * theTopPV_
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
std::vector< double >::size_type index_type
Definition: adjgraph.h:15
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
type of data representation of DDCompactView
Definition: DDCompactView.h:90
A DDSolid represents the shape of a part.
Definition: DDSolid.h:37
U second(std::pair< T, U > const &p)
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:140
std::map< DDSolidShape, std::pair< int, int > > kount_
std::vector< std::string > nodeNames_
void fillLV(G4LogicalVolume *lv)
ii
Definition: cuy.py:588
int k[5][pyjets_maxn]
part
Definition: HCALResponse.h:20
std::vector< G4VSolid * > sls_
void dumpSummary(std::ostream &out, std::string name)
std::vector< G4LogicalVolume * > lvs_
adj_list::const_iterator const_adj_iterator
Definition: adjgraph.h:125
Pt3D refl(const Pt3D &p)
adj_iterator begin()
Definition: adjgraph.h:197
void update(const BeginOfJob *job)
This routine will be called when the appropriate signal arrives.
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
std::map< std::string, DDSolidShape > solidMap_
adj_iterator end()
Definition: adjgraph.h:199