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();
110 
111  pvs_.clear();
112  fillPV(theTopPV_);
113  G4cout << " Number of G4VPhysicalVolume's for " << name << ": " << pvs_.size() << G4endl;
114 
115  for (unsigned int k = 0; k < nodeNames_.size(); ++k) {
116  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
117  std::vector<G4LogicalVolume*>::const_iterator lvcite;
118  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
119  if ((*lvcite)->GetName() == (G4String)(nodeNames_[k])) {
120  lvs_.clear();
121  sls_.clear();
122  touch_.clear();
123  fillLV(*lvcite);
125  }
126  }
127  const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
128  std::vector<G4VPhysicalVolume*>::const_iterator pvcite;
129  for (pvcite = pvs->begin(); pvcite != pvs->end(); pvcite++) {
130  if ((*pvcite)->GetName() == (G4String)(nodeNames_[k])) {
131  pvs_.clear();
132  fillPV(*pvcite);
133  G4cout << " Number of G4VPhysicalVolume's for " << nodeNames_[k] << ": " << pvs_.size() << G4endl;
134  }
135  }
136  }
137  }
138 }
139 
140 void PrintGeomSummary::fillLV(G4LogicalVolume* lv) {
141  if (std::find(lvs_.begin(), lvs_.end(), lv) == lvs_.end())
142  lvs_.push_back(lv);
143  G4VSolid* sl = lv->GetSolid();
144  if (std::find(sls_.begin(), sls_.end(), sl) == sls_.end())
145  sls_.push_back(sl);
146  touch_.push_back(lv);
147  for (int ii = 0; ii < (int)(lv->GetNoDaughters()); ii++)
148  fillLV(lv->GetDaughter(ii)->GetLogicalVolume());
149 }
150 
151 void PrintGeomSummary::fillPV(G4VPhysicalVolume* pv) {
152  if (std::find(pvs_.begin(), pvs_.end(), pv) == pvs_.end())
153  pvs_.push_back(pv);
154  for (int ii = 0; ii < (int)(pv->GetLogicalVolume()->GetNoDaughters()); ii++)
155  fillPV(pv->GetLogicalVolume()->GetDaughter(ii));
156 }
157 
159  //---------- Dump number of objects of each class
160  out << G4endl << G4endl << "@@@@@@@@@@@@@@@@@@ Dumping Summary For Node " << name << G4endl;
161  out << " Number of G4VSolid's: " << sls_.size() << G4endl;
162  out << " Number of G4LogicalVolume's: " << lvs_.size() << G4endl;
163  out << " Number of Touchable's: " << touch_.size() << G4endl;
164  //First the solids
165  out << G4endl << "Occurence of each type of shape among Solids" << G4endl;
166  kount_.clear();
167  for (std::vector<G4VSolid*>::iterator it = sls_.begin(); it != sls_.end(); ++it) {
168  std::string name = (*it)->GetName();
169  addName(name);
170  }
171  printSummary(out);
172  //Then the logical volumes
173  out << G4endl << "Occurence of each type of shape among Logical Volumes" << G4endl;
174  kount_.clear();
175  for (std::vector<G4LogicalVolume*>::iterator it = lvs_.begin(); it != lvs_.end(); ++it) {
176  std::string name = ((*it)->GetSolid())->GetName();
177  addName(name);
178  }
179  printSummary(out);
180  //Finally the touchables
181  out << G4endl << "Occurence of each type of shape among Touchables" << G4endl;
182  kount_.clear();
183  for (std::vector<G4LogicalVolume*>::iterator it = touch_.begin(); it != touch_.end(); ++it) {
184  std::string name = ((*it)->GetSolid())->GetName();
185  addName(name);
186  }
187  printSummary(out);
188 }
189 
190 G4VPhysicalVolume* PrintGeomSummary::getTopPV() {
191  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
192 }
193 
195  bool refl(false);
196  if (name.find("_refl") < name.size()) {
197  refl = true;
198  name = name.substr(0, (name.find("_refl")));
199  }
200  std::map<std::string, DDSolidShape>::const_iterator jt = solidMap_.find(name);
201  DDSolidShape shape = (jt == solidMap_.end()) ? DDSolidShape::dd_not_init : jt->second;
202  std::map<DDSolidShape, std::pair<int, int>>::iterator itr = kount_.find(shape);
203  if (itr == kount_.end()) {
204  kount_[shape] = (refl) ? std::pair<int, int>(0, 1) : std::pair<int, int>(1, 0);
205  } else {
206  kount_[shape] = (refl) ? std::pair<int, int>(((itr->second).first), ++((itr->second).second))
207  : std::pair<int, int>(++((itr->second).first), ((itr->second).second));
208  }
209 }
210 
211 void PrintGeomSummary::printSummary(std::ostream& out) {
212  int k(0);
213  for (std::map<DDSolidShape, std::pair<int, int>>::iterator itr = kount_.begin(); itr != kount_.end(); ++itr, ++k) {
214  std::string shape = solidShape_[itr->first];
215  out << "Shape [" << k << "] " << shape << " # " << (itr->second).first << " : " << (itr->second).second << G4endl;
216  }
217 }
PrintGeomSummary::lvs_
std::vector< G4LogicalVolume * > lvs_
Definition: PrintGeomSummary.h:45
mps_fire.i
i
Definition: mps_fire.py:428
DDSolidShape
DDSolidShape
Definition: DDSolidShapes.h:6
ESTransientHandle.h
DDSolidShape::ddtrap
DDSolidShape::ddtorus
BeginOfJob.h
PrintGeomSummary::dumpSummary
void dumpSummary(std::ostream &out, std::string name)
Definition: PrintGeomSummary.cc:158
PrintGeomSummary::pvs_
std::vector< G4VPhysicalVolume * > pvs_
Definition: PrintGeomSummary.h:47
DDSolidShape::ddpseudotrap
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
DDSolidShape::ddpolyhedra_rrz
DDSplit.h
PrintGeomSummary::~PrintGeomSummary
~PrintGeomSummary() override
Definition: PrintGeomSummary.cc:61
PrintGeomSummary::solidMap_
std::map< std::string, DDSolidShape > solidMap_
Definition: PrintGeomSummary.h:43
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
PrintGeomSummary::kount_
std::map< DDSolidShape, std::pair< int, int > > kount_
Definition: PrintGeomSummary.h:48
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
DDCompactView.h
DDSolid::shape
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:119
PrintGeomSummary::sls_
std::vector< G4VSolid * > sls_
Definition: PrintGeomSummary.h:46
BeginOfRun.h
part
part
Definition: HCALResponse.h:20
DDFilteredView.h
DDSolidShape::ddtubs
DDCompactView::graph
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
Definition: DDCompactView.cc:59
PrintGeomSummary::solidShape_
std::map< DDSolidShape, std::string > solidShape_
Definition: PrintGeomSummary.h:42
adjl_iterator
Graph::const_adj_iterator adjl_iterator
Definition: GeometryInfoDump.cc:19
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDSolidShape::ddtrunctubs
DDSolidShape::ddpolyhedra_rz
DDBase::name
const N & name() const
Definition: DDBase.h:59
PrintGeomSummary::addName
void addName(std::string name)
Definition: PrintGeomSummary.cc:194
DDSolid.h
BeginOfJob
Definition: BeginOfJob.h:8
dqmdumpme.k
k
Definition: dqmdumpme.py:60
DDValue.h
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDCompactView::Graph
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
DDSolidShape::ddellipticaltube
edm::ParameterSet
Definition: ParameterSet.h:47
DDSolidShape::ddsphere
DDSolidShape::ddcons
DDLogicalPart
A DDLogicalPart aggregates information concerning material, solid and sensitveness ....
Definition: DDLogicalPart.h:93
createfilelist.int
int
Definition: createfilelist.py:10
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
DDFilter.h
PrintGeomSummary::theTopPV_
G4VPhysicalVolume * theTopPV_
Definition: PrintGeomSummary.h:44
DDName::name
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
PrintGeomSummary::getTopPV
G4VPhysicalVolume * getTopPV()
Definition: PrintGeomSummary.cc:190
BeginOfRun
Definition: BeginOfRun.h:6
IdealGeometryRecord.h
PrintGeomSummary::touch_
std::vector< G4LogicalVolume * > touch_
Definition: PrintGeomSummary.h:45
DDLogicalPart.h
DDSolidShape::dd_not_init
FSQDQM_cfi.pvs
pvs
Definition: FSQDQM_cfi.py:12
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
PrintGeomSummary::printSummary
void printSummary(std::ostream &out)
Definition: PrintGeomSummary.cc:211
PrintGeomSummary::fillPV
void fillPV(G4VPhysicalVolume *pv)
Definition: PrintGeomSummary.cc:151
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DDSolidShape::ddbox
PrintGeomSummary::PrintGeomSummary
PrintGeomSummary(edm::ParameterSet const &p)
Definition: PrintGeomSummary.cc:32
math::Graph< DDLogicalPart, DDPosData * >::index_type
std::vector< double >::size_type index_type
Definition: Graph.h:15
PrintGeomSummary::addSolid
void addSolid(const DDLogicalPart &part)
Definition: PrintGeomSummary.cc:90
DDSolidShape::ddextrudedpolygon
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
DDSolidShape::ddshapeless
DDSolid
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
PrintGeomSummary::fillLV
void fillLV(G4LogicalVolume *lv)
Definition: PrintGeomSummary.cc:140
PrintGeomSummary.h
DDSolidShape::ddcuttubs
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
DDSolidShape::ddpolycone_rrz
math::Graph< DDLogicalPart, DDPosData * >
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ecalTB2006H4_GenSimDigiReco_cfg.G4cout
G4cout
Definition: ecalTB2006H4_GenSimDigiReco_cfg.py:285
PrintGeomSummary::update
void update(const BeginOfJob *job) override
This routine will be called when the appropriate signal arrives.
Definition: PrintGeomSummary.cc:63
DDSolidShape::ddsubtraction
DDSolidShape::ddintersection
PrintGeomSummary::nodeNames_
std::vector< std::string > nodeNames_
Definition: PrintGeomSummary.h:41
truncPyr::refl
Pt3D refl(const Pt3D &p)
Definition: TruncatedPyramid.cc:144
DDSolidShape::ddunion
cuy.ii
ii
Definition: cuy.py:590
DDSolidShape::ddpolycone_rz
math::Graph< DDLogicalPart, DDPosData * >::const_adj_iterator
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105