CMS 3D CMS Logo

PrintGeomInfoAction.cc
Go to the documentation of this file.
4 
17 
18 #include "DD4hep/DD4hepUnits.h"
19 #include "DD4hep/Filter.h"
20 
21 #include "G4LogicalVolumeStore.hh"
22 #include "G4LogicalVolume.hh"
23 #include "G4VSolid.hh"
24 #include "G4Material.hh"
25 #include "G4NavigationHistory.hh"
26 #include "G4PhysicalVolumeStore.hh"
27 #include "G4Run.hh"
28 #include "G4Track.hh"
29 #include "G4TransportationManager.hh"
30 #include "G4UserLimits.hh"
31 #include "G4VisAttributes.hh"
32 #include "G4VPhysicalVolume.hh"
33 
34 #include <algorithm>
35 #include <fstream>
36 #include <map>
37 #include <set>
38 #include <string>
39 #include <vector>
40 
42 
43 typedef std::multimap<G4LogicalVolume *, G4VPhysicalVolume *, std::less<G4LogicalVolume *> > mmlvpv;
44 
45 class PrintGeomInfoAction : public SimWatcher, public Observer<const BeginOfRun *> {
46 public:
48  ~PrintGeomInfoAction() override = default;
49 
51  void beginRun(edm::EventSetup const &) override;
52 
53 private:
54  void update(const BeginOfRun *run) override;
55  void dumpSummary(std::ostream &out = G4cout);
56  void dumpG4LVList(std::ostream &out = G4cout);
57  void dumpG4LVTree(std::ostream &out = G4cout);
58  void dumpMaterialList(std::ostream &out = G4cout);
59  void dumpG4LVLeaf(G4LogicalVolume *lv, unsigned int leafDepth, unsigned int count, std::ostream &out = G4cout);
60  int countNoTouchables();
61  void add1touchable(G4LogicalVolume *lv, int &nTouch);
62  void dumpHierarchyTreePVLV(std::ostream &out = G4cout);
63  void dumpHierarchyLeafPVLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out = G4cout);
64  void dumpLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out = G4cout);
65  void dumpPV(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out = G4cout);
66  void dumpSolid(G4VSolid *sol, unsigned int leafDepth, std::ostream &out = G4cout);
67  void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out = G4cout);
68  void dumpInFile();
69  void getTouch(G4VPhysicalVolume *pv, unsigned int leafDepth, unsigned int copym, std::vector<std::string> &touches);
70  std::string spacesFromLeafDepth(unsigned int leafDepth);
71  G4VPhysicalVolume *getTopPV();
72  G4LogicalVolume *getTopLV();
73 
74 private:
77 
83  int nchar_;
86  std::vector<std::string> names_;
87  G4VPhysicalVolume *theTopPV_;
88  G4NavigationHistory fHistory_;
89 };
90 
92  dumpSummary_ = p.getUntrackedParameter<bool>("DumpSummary", true);
93  dumpLVTree_ = p.getUntrackedParameter<bool>("DumpLVTree", true);
94  dumpLVList_ = p.getUntrackedParameter<bool>("DumpLVList", false);
95  dumpMaterial_ = p.getUntrackedParameter<bool>("DumpMaterial", false);
96  dumpLV_ = p.getUntrackedParameter<bool>("DumpLV", false);
97  dumpSolid_ = p.getUntrackedParameter<bool>("DumpSolid", false);
98  dumpAtts_ = p.getUntrackedParameter<bool>("DumpAttributes", false);
99  dumpPV_ = p.getUntrackedParameter<bool>("DumpPV", false);
100  dumpRotation_ = p.getUntrackedParameter<bool>("DumpRotation", false);
101  dumpReplica_ = p.getUntrackedParameter<bool>("DumpReplica", false);
102  dumpTouch_ = p.getUntrackedParameter<bool>("DumpTouch", false);
103  dumpSense_ = p.getUntrackedParameter<bool>("DumpSense", false);
104  dd4hep_ = p.getUntrackedParameter<bool>("DD4hep", false);
105  name_ = p.getUntrackedParameter<std::string>("Name", "*");
106  nchar_ = name_.find('*');
107  name_.assign(name_, 0, nchar_);
108  names_ = p.getUntrackedParameter<std::vector<std::string> >("Names");
109  fileMat_ = p.getUntrackedParameter<std::string>("MaterialFileName", "");
110  fileSolid_ = p.getUntrackedParameter<std::string>("SolidFileName", "");
111  fileLV_ = p.getUntrackedParameter<std::string>("LVFileName", "");
112  filePV_ = p.getUntrackedParameter<std::string>("PVFileName", "");
113  fileTouch_ = p.getUntrackedParameter<std::string>("TouchFileName", "");
114  fileDetail_ = p.getUntrackedParameter<bool>("FileDetail", false);
115  G4cout << "PrintGeomInfoAction:: initialised for dd4hep " << dd4hep_ << " with verbosity levels:"
116  << " Summary " << dumpSummary_ << " LVTree " << dumpLVTree_ << " LVList " << dumpLVList_ << " Material "
117  << dumpMaterial_ << G4endl << " "
118  << " LV " << dumpLV_ << " Solid " << dumpSolid_ << " Attribs " << dumpAtts_ << G4endl
119  << " "
120  << " PV " << dumpPV_ << " Rotation " << dumpRotation_ << " Replica " << dumpReplica_ << G4endl
121  << " "
122  << " Touchable " << dumpTouch_ << " for names (0-" << nchar_ << ") = " << name_ << G4endl
123  << " "
124  << " Sensitive " << dumpSense_ << " Files " << fileMat_ << ":" << fileSolid_ << ":" << fileLV_ << ":"
125  << filePV_ << ":" << fileTouch_ << " FileDetail " << fileDetail_ << G4endl
126  << " for " << names_.size() << " names:";
127  for (unsigned int i = 0; i < names_.size(); i++)
128  G4cout << " " << names_[i];
129  G4cout << G4endl;
130 }
131 
133  if (dd4hep_) {
135  G4cout << "PrintGeomInfoAction::Initialize ESGetToken for cms::DDCompactView" << G4endl;
136  } else {
138  G4cout << "PrintGeomInfoAction::Initialize ESGetToken for DDCompactView" << G4endl;
139  }
140 }
141 
143  if (dumpSense_) {
144  if (dd4hep_) {
145  const cms::DDCompactView *pDD = &es.getData(dd4hepToken_);
146 
147  G4cout << "PrintGeomInfoAction::Get Printout of Sensitive Volumes "
148  << "for " << names_.size() << " Readout Units" << G4endl;
149  for (unsigned int i = 0; i < names_.size(); i++) {
150  std::string sd = names_[i];
151  const cms::DDFilter filter("ReadOutName", sd);
152  cms::DDFilteredView fv(*pDD, filter);
153  G4cout << "PrintGeomInfoAction:: Get Filtered view for ReadOutName = " << sd << G4endl;
154  G4cout << "Lengths are in mm, angles in degrees" << G4endl;
155 
156  std::string spaces = spacesFromLeafDepth(1);
157 
158  while (fv.firstChild()) {
159  auto tran = fv.translation() / dd4hep::mm;
160  std::vector<int> copy = fv.copyNos();
161  auto lvname = fv.name();
162  unsigned int leafDepth = copy.size();
163  G4cout << leafDepth << spaces << "### VOLUME = " << lvname << " Copy No";
164  for (unsigned int k = 0; k < leafDepth; ++k)
165  G4cout << " " << copy[k];
166  G4cout << " Centre at " << tran << " (r = " << tran.Rho() << ", phi = " << convertRadToDeg(tran.phi()) << ")"
167  << G4endl;
168  }
169  }
170  } else {
171  const DDCompactView *pDD = &es.getData(dddToken_);
172 
173  G4cout << "PrintGeomInfoAction::Get Printout of Sensitive Volumes "
174  << "for " << names_.size() << " Readout Units" << G4endl;
175  for (unsigned int i = 0; i < names_.size(); i++) {
176  std::string attribute = "ReadOutName";
177  std::string sd = names_[i];
178  DDSpecificsMatchesValueFilter filter{DDValue(attribute, sd, 0)};
179  DDFilteredView fv(*pDD, filter);
180  G4cout << "PrintGeomInfoAction:: Get Filtered view for " << attribute << " = " << sd << G4endl;
181  G4cout << "Lengths are in mm, angles in degrees" << G4endl;
182  bool dodet = fv.firstChild();
183 
184  std::string spaces = spacesFromLeafDepth(1);
185 
186  while (dodet) {
187  const DDLogicalPart &log = fv.logicalPart();
188  std::string lvname = log.name().name();
189  DDTranslation tran = fv.translation();
190  std::vector<int> copy = fv.copyNumbers();
191 
192  unsigned int leafDepth = copy.size();
193  G4cout << leafDepth << spaces << "### VOLUME = " << lvname << " Copy No";
194  for (int k = leafDepth - 1; k >= 0; k--)
195  G4cout << " " << copy[k];
196  G4cout << " Centre at " << tran << " (r = " << tran.Rho() << ", phi = " << convertRadToDeg(tran.phi()) << ")"
197  << G4endl;
198  dodet = fv.next();
199  }
200  }
201  }
202  }
203 }
204 
206  //Now take action
207  theTopPV_ = getTopPV();
208 
209  if (dumpSummary_)
211  if (dumpLVTree_)
213 
214  //---------- Dump list of objects of each class with detail of parameters
215  if (dumpMaterial_)
217  if (dumpLVList_)
219 
220  //---------- Dump LV and PV information
221  if (dumpLV_ || dumpPV_ || dumpTouch_)
223 
224  dumpInFile();
225 }
226 
228  //---------- Dump number of objects of each class
229  out << " @@@@@@@@@@@@@@@@@@ Dumping G4 geometry objects Summary " << G4endl;
230  if (theTopPV_ == nullptr) {
231  out << " No volume created " << G4endl;
232  return;
233  }
234  out << " @@@ Geometry built inside world volume: " << theTopPV_->GetName() << G4endl;
235  // Get number of solids (< # LV if several LV share a solid)
236  const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
237  std::vector<G4LogicalVolume *>::const_iterator lvcite;
238  std::set<G4VSolid *> theSolids;
239  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
240  theSolids.insert((*lvcite)->GetSolid());
241  out << " Number of G4VSolid's: " << theSolids.size() << G4endl;
242  out << " Number of G4LogicalVolume's: " << lvs->size() << G4endl;
243  const G4PhysicalVolumeStore *pvs = G4PhysicalVolumeStore::GetInstance();
244  out << " Number of G4VPhysicalVolume's: " << pvs->size() << G4endl;
245  out << " Number of Touchable's: " << countNoTouchables() << G4endl;
246  const G4MaterialTable *matTab = G4Material::GetMaterialTable();
247  out << " Number of G4Material's: " << matTab->size() << G4endl;
248 }
249 
251  out << " @@@@@@@@@@@@@@@@ DUMPING G4LogicalVolume's List " << G4endl;
252  const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
253  std::vector<G4LogicalVolume *>::const_iterator lvcite;
254  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
255  out << "LV:" << (*lvcite)->GetName() << "\tMaterial: " << (*lvcite)->GetMaterial()->GetName() << G4endl;
256 }
257 
259  out << " @@@@@@@@@@@@@@@@ DUMPING G4LogicalVolume's Tree " << G4endl;
260  G4LogicalVolume *lv = getTopLV();
261  dumpG4LVLeaf(lv, 0, 1, out);
262 }
263 
265  out << " @@@@@@@@@@@@@@@@ DUMPING G4Material List ";
266  const G4MaterialTable *matTab = G4Material::GetMaterialTable();
267  out << " with " << matTab->size() << " materials " << G4endl;
268  std::vector<G4Material *>::const_iterator matite;
269  for (matite = matTab->begin(); matite != matTab->end(); matite++)
270  out << "Material: " << (*matite) << G4endl;
271 }
272 
273 void PrintGeomInfoAction::dumpG4LVLeaf(G4LogicalVolume *lv,
274  unsigned int leafDepth,
275  unsigned int count,
276  std::ostream &out) {
277  for (unsigned int ii = 0; ii < leafDepth; ii++)
278  out << " ";
279  out << " LV:(" << leafDepth << ") " << lv->GetName() << " (" << count << ")" << G4endl;
280  //--- If a volume is placed n types as daughter of this LV, it should only be counted once
281  std::map<G4LogicalVolume *, unsigned int> lvCount;
282  std::map<G4LogicalVolume *, unsigned int>::const_iterator cite;
283  int siz = lv->GetNoDaughters();
284  for (int ii = 0; ii < siz; ii++) {
285  cite = lvCount.find(lv->GetDaughter(ii)->GetLogicalVolume());
286  if (cite != lvCount.end())
287  lvCount[cite->first] = (cite->second) + 1;
288  else
289  lvCount.insert(std::pair<G4LogicalVolume *, unsigned int>(lv->GetDaughter(ii)->GetLogicalVolume(), 1));
290  }
291  for (cite = lvCount.begin(); cite != lvCount.end(); cite++)
292  dumpG4LVLeaf((cite->first), leafDepth + 1, (cite->second), out);
293 }
294 
296  int nTouch = 0;
297  G4LogicalVolume *lv = getTopLV();
298  add1touchable(lv, nTouch);
299  return nTouch;
300 }
301 
302 void PrintGeomInfoAction::add1touchable(G4LogicalVolume *lv, int &nTouch) {
303  int siz = lv->GetNoDaughters();
304  for (int ii = 0; ii < siz; ii++)
305  add1touchable(lv->GetDaughter(ii)->GetLogicalVolume(), ++nTouch);
306 }
307 
309  //dumps in the following order:
310  // 1) a LV with details
311  // 2) list of PVs daughters of this LV with details
312  // 3) list of LVs daughters of this LV and for each go to 1)
313 
314  //----- Get top PV
315  G4LogicalVolume *topLV = getTopLV();
316 
317  //----- Dump this leaf (it will recursively dump all the tree)
318  dumpHierarchyLeafPVLV(topLV, 0, out);
319  dumpPV(theTopPV_, 0, out);
320 
321  //----- Dump the touchables (it will recursively dump all the tree)
322  if (dumpTouch_)
323  dumpTouch(theTopPV_, 0, out);
324 }
325 
326 void PrintGeomInfoAction::dumpHierarchyLeafPVLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out) {
327  //----- Dump this LV
328  dumpLV(lv, leafDepth, out);
329 
330  //----- Get LV daughters from list of PV daughters
331  mmlvpv lvpvDaughters;
332  std::set<G4LogicalVolume *> lvDaughters;
333  int NoDaughters = lv->GetNoDaughters();
334  while ((NoDaughters--) > 0) {
335  G4VPhysicalVolume *pvD = lv->GetDaughter(NoDaughters);
336  lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
337  lvDaughters.insert(pvD->GetLogicalVolume());
338  }
339 
340  std::set<G4LogicalVolume *>::const_iterator scite;
341  mmlvpv::const_iterator mmcite;
342 
343  //----- Dump daughters PV and LV
344  for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
345  std::pair<mmlvpv::iterator, mmlvpv::iterator> mmER = lvpvDaughters.equal_range(*scite);
346  //----- Dump daughters PV of this LV
347  for (mmcite = mmER.first; mmcite != mmER.second; mmcite++)
348  dumpPV((*mmcite).second, leafDepth + 1, out);
349  //----- Dump daughters LV
350  dumpHierarchyLeafPVLV(*scite, leafDepth + 1, out);
351  }
352 }
353 
354 void PrintGeomInfoAction::dumpLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out) {
355  std::string spaces = spacesFromLeafDepth(leafDepth);
356 
357  //----- dump name
358  if (dumpLV_) {
359  out << leafDepth << spaces << "$$$ VOLUME = " << lv->GetName() << " Solid: " << lv->GetSolid()->GetName()
360  << " MATERIAL: " << lv->GetMaterial()->GetName() << G4endl;
361  if (dumpSolid_)
362  dumpSolid(lv->GetSolid(), leafDepth, out); //----- dump solid
363 
364  //----- dump LV info
365  //--- material
366  if (dumpAtts_) {
367  //--- Visualisation attributes
368  const G4VisAttributes *fVA = lv->GetVisAttributes();
369  if (fVA != nullptr) {
370  out << spaces << " VISUALISATION ATTRIBUTES: " << G4endl;
371  out << spaces << " IsVisible " << fVA->IsVisible() << G4endl;
372  out << spaces << " IsDaughtersInvisible " << fVA->IsDaughtersInvisible() << G4endl;
373  out << spaces << " Colour " << fVA->GetColour() << G4endl;
374  out << spaces << " LineStyle " << fVA->GetLineStyle() << G4endl;
375  out << spaces << " LineWidth " << fVA->GetLineWidth() << G4endl;
376  out << spaces << " IsForceDrawingStyle " << fVA->IsForceDrawingStyle() << G4endl;
377  out << spaces << " ForcedDrawingStyle " << fVA->GetForcedDrawingStyle() << G4endl;
378  }
379 
380  //--- User Limits
381  G4UserLimits *fUL = lv->GetUserLimits();
382  G4Track dummy;
383  if (fUL != nullptr) {
384  out << spaces << " MaxAllowedStep " << fUL->GetMaxAllowedStep(dummy) << G4endl;
385  out << spaces << " UserMaxTrackLength " << fUL->GetUserMaxTrackLength(dummy) << G4endl;
386  out << spaces << " UserMaxTime " << fUL->GetUserMaxTime(dummy) << G4endl;
387  out << spaces << " UserMinEkine " << fUL->GetUserMinEkine(dummy) << G4endl;
388  out << spaces << " UserMinRange " << fUL->GetUserMinRange(dummy) << G4endl;
389  }
390 
391  //--- other LV info
392  if (lv->GetSensitiveDetector())
393  out << spaces << " IS SENSITIVE DETECTOR " << G4endl;
394  if (lv->GetFieldManager())
395  out << spaces << " FIELD ON " << G4endl;
396 
397  // Pointer (possibly NULL) to optimisation info objects.
398  out << spaces << " Quality for optimisation, average number of voxels to be spent per content "
399  << lv->GetSmartless() << G4endl;
400 
401  // Pointer (possibly NULL) to G4FastSimulationManager object.
402  if (lv->GetFastSimulationManager())
403  out << spaces << " Logical Volume is an envelope for a FastSimulationManager " << G4endl;
404  out << spaces << " Weight used in the event biasing technique = " << lv->GetBiasWeight() << G4endl;
405  }
406  }
407 }
408 
409 void PrintGeomInfoAction::dumpPV(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out) {
410  std::string spaces = spacesFromLeafDepth(leafDepth);
411 
412  //----- PV info
413  if (dumpPV_) {
414  std::string mother = "World";
415  if (pv->GetMotherLogical())
416  mother = pv->GetMotherLogical()->GetName();
417  out << leafDepth << spaces << "### VOLUME = " << pv->GetName() << " Copy No " << pv->GetCopyNo() << " in " << mother
418  << " at " << pv->GetTranslation();
419  }
420  if (!pv->IsReplicated()) {
421  if (dumpPV_) {
422  if (pv->GetRotation() == nullptr)
423  out << " with no rotation" << G4endl;
424  else if (!dumpRotation_)
425  out << " with rotation" << G4endl; //just rotation name
426  else
427  out << " with rotation " << *(pv->GetRotation()) << G4endl;
428  }
429  } else {
430  if (dumpReplica_) {
431  out << spaces << " It is replica: " << G4endl;
432  EAxis axis;
433  int nReplicas;
434  double width;
435  double offset;
436  bool consuming;
437  pv->GetReplicationData(axis, nReplicas, width, offset, consuming);
438  out << spaces << " axis " << axis << G4endl << spaces << " nReplicas " << nReplicas << G4endl;
439  if (pv->GetParameterisation() != nullptr)
440  out << spaces << " It is parameterisation " << G4endl;
441  else
442  out << spaces << " width " << width << G4endl << spaces << " offset " << offset << G4endl << spaces
443  << " consuming" << consuming << G4endl;
444  if (pv->GetParameterisation() != nullptr)
445  out << spaces << " It is parameterisation " << G4endl;
446  }
447  }
448 }
449 
450 void PrintGeomInfoAction::dumpSolid(G4VSolid *sol, unsigned int leafDepth, std::ostream &out) {
451  std::string spaces = spacesFromLeafDepth(leafDepth);
452  out << spaces << *(sol) << G4endl;
453 }
454 
455 void PrintGeomInfoAction::dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out) {
456  std::string spaces = spacesFromLeafDepth(leafDepth);
457  if (leafDepth == 0)
458  fHistory_.SetFirstEntry(pv);
459  else
460  fHistory_.NewLevel(pv, kNormal, pv->GetCopyNo());
461 
462  G4ThreeVector globalpoint = fHistory_.GetTopTransform().Inverse().TransformPoint(G4ThreeVector(0, 0, 0));
463  G4LogicalVolume *lv = pv->GetLogicalVolume();
464 
465  std::string mother = "World";
466  if (pv->GetMotherLogical())
467  mother = pv->GetMotherLogical()->GetName();
468  std::string lvname = lv->GetName();
469  lvname.assign(lvname, 0, nchar_);
470  if (lvname == name_)
471  out << leafDepth << spaces << "### VOLUME = " << lv->GetName() << " Copy No " << pv->GetCopyNo() << " in " << mother
472  << " global position of centre " << globalpoint << " (r = " << globalpoint.perp()
473  << ", phi = " << convertRadToDeg(globalpoint.phi()) << ")" << G4endl;
474 
475  int NoDaughters = lv->GetNoDaughters();
476  while ((NoDaughters--) > 0) {
477  G4VPhysicalVolume *pvD = lv->GetDaughter(NoDaughters);
478  if (!pvD->IsReplicated())
479  dumpTouch(pvD, leafDepth + 1, out);
480  }
481 
482  if (leafDepth > 0)
483  fHistory_.BackLevel();
484 }
485 
487  //---------- Dump number objects of each class in a file
488  if (theTopPV_ != nullptr) {
489  if (!fileMat_.empty()) {
490  const G4MaterialTable *matTab = G4Material::GetMaterialTable();
491  std::ofstream fout(fileMat_.c_str());
492  for (std::vector<G4Material *>::const_iterator matite = matTab->begin(); matite != matTab->end(); matite++) {
493  if (!fileDetail_)
494  fout << (*matite)->GetName() << G4endl;
495  else
496  fout << (*matite)->GetName() << " " << (*matite)->GetRadlen() << " " << (*matite)->GetNuclearInterLength()
497  << G4endl;
498  }
499  fout.close();
500  }
501  const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
502  if (!fileSolid_.empty()) {
503  std::ofstream fout(fileSolid_.c_str());
504  for (std::vector<G4LogicalVolume *>::const_iterator lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
505  if (!fileDetail_)
506  fout << (*lvcite)->GetSolid()->GetName() << G4endl;
507  else
508  fout << (*lvcite)->GetSolid()->GetName() << " " << (*lvcite)->GetSolid()->GetCubicVolume() << G4endl;
509  fout.close();
510  }
511  if (!fileLV_.empty()) {
512  std::ofstream fout(fileLV_.c_str());
513  for (std::vector<G4LogicalVolume *>::const_iterator lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
514  if (!fileDetail_)
515  fout << (*lvcite)->GetName() << G4endl;
516  else
517  fout << (*lvcite)->GetName() << " " << (*lvcite)->GetMass(false, false) << G4endl;
518  fout.close();
519  }
520  if (!filePV_.empty()) {
521  const G4PhysicalVolumeStore *pvs = G4PhysicalVolumeStore::GetInstance();
522  std::ofstream fout(filePV_.c_str());
523  for (std::vector<G4VPhysicalVolume *>::const_iterator pvcite = pvs->begin(); pvcite != pvs->end(); pvcite++) {
524  if (fileDetail_) {
525  if (dd4hep_)
526  fout << (*pvcite)->GetName() << " " << (*pvcite)->GetTranslation().x() << " "
527  << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << G4endl;
528  else
529  fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << " " << (*pvcite)->GetTranslation().x()
530  << " " << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << G4endl;
531  } else {
532  if (dd4hep_)
533  fout << (*pvcite)->GetName() << G4endl;
534  else
535  fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << G4endl;
536  }
537  }
538  fout.close();
539  }
540  if (!fileTouch_.empty()) {
541  std::ofstream fout(fileTouch_.c_str());
542  std::vector<std::string> touches;
543  getTouch(theTopPV_, 0, 1, touches);
544  std::sort(touches.begin(), touches.end());
545  for (const auto &touch : touches)
546  fout << touch << G4endl;
547  fout.close();
548  }
549  }
550 }
551 
552 void PrintGeomInfoAction::getTouch(G4VPhysicalVolume *pv,
553  unsigned int leafDepth,
554  unsigned int copym,
555  std::vector<std::string> &touches) {
556  if (leafDepth == 0)
557  fHistory_.SetFirstEntry(pv);
558  else
559  fHistory_.NewLevel(pv, kNormal, pv->GetCopyNo());
560 
561  std::string mother = "World";
562  if (pv->GetMotherLogical())
563  mother = static_cast<std::string>(dd4hep::dd::noNamespace(pv->GetMotherLogical()->GetName()));
564 
565  G4LogicalVolume *lv = pv->GetLogicalVolume();
566  std::string lvname = static_cast<std::string>(dd4hep::dd::noNamespace(lv->GetName()));
567  unsigned int copy = static_cast<unsigned int>(pv->GetCopyNo());
568 
569  std::string name = lvname + ":" + std::to_string(copy) + "_" + mother + ":" + std::to_string(copym);
570  touches.emplace_back(name);
571 
572  int NoDaughters = lv->GetNoDaughters();
573  while ((NoDaughters--) > 0) {
574  G4VPhysicalVolume *pvD = lv->GetDaughter(NoDaughters);
575  if (!pvD->IsReplicated())
576  getTouch(pvD, leafDepth + 1, copy, touches);
577  }
578 
579  if (leafDepth > 0)
580  fHistory_.BackLevel();
581 }
582 
584  std::string spaces;
585  unsigned int ii;
586  for (ii = 0; ii < leafDepth; ii++) {
587  spaces += " ";
588  }
589  return spaces;
590 }
591 
592 G4VPhysicalVolume *PrintGeomInfoAction::getTopPV() {
593  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
594 }
595 
596 G4LogicalVolume *PrintGeomInfoAction::getTopLV() { return theTopPV_->GetLogicalVolume(); }
597 
600 
void add1touchable(G4LogicalVolume *lv, int &nTouch)
std::multimap< G4LogicalVolume *, G4VPhysicalVolume *, std::less< G4LogicalVolume * > > mmlvpv
#define DEFINE_SIMWATCHER(type)
PrintGeomInfoAction(edm::ParameterSet const &p)
nav_type copyNumbers() const
return the stack of copy numbers
G4VPhysicalVolume * theTopPV_
void dumpSolid(G4VSolid *sol, unsigned int leafDepth, std::ostream &out=G4cout)
const std::vector< int > copyNos() const
The list of the volume copy numbers.
void getTouch(G4VPhysicalVolume *pv, unsigned int leafDepth, unsigned int copym, std::vector< std::string > &touches)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
std::string to_string(const V &value)
Definition: OMSAccess.h:71
void dumpG4LVLeaf(G4LogicalVolume *lv, unsigned int leafDepth, unsigned int count, std::ostream &out=G4cout)
G4NavigationHistory fHistory_
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepToken_
std::vector< std::string > names_
std::string_view name() const
void dumpG4LVTree(std::ostream &out=G4cout)
bool next()
set current node to the next node in the filtered tree
void dumpPV(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out=G4cout)
void dumpSummary(std::ostream &out=G4cout)
void registerConsumes(edm::ConsumesCollector) override
def pv(vc)
Definition: MetAnalyzer.py:7
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::string spacesFromLeafDepth(unsigned int leafDepth)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
bool firstChild()
set the current node to the first child
ii
Definition: cuy.py:589
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out=G4cout)
constexpr float sol
Definition: Config.h:48
G4VPhysicalVolume * getTopPV()
void dumpLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out=G4cout)
G4LogicalVolume * getTopLV()
bool firstChild()
set the current node to the first child ...
void beginRun(edm::EventSetup const &) override
void dumpMaterialList(std::ostream &out=G4cout)
void dumpHierarchyLeafPVLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out=G4cout)
void dumpG4LVList(std::ostream &out=G4cout)
const DDTranslation & translation() const
The absolute translation of the current node.
~PrintGeomInfoAction() override=default
void dumpHierarchyTreePVLV(std::ostream &out=G4cout)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
edm::ESGetToken< DDCompactView, IdealGeometryRecord > dddToken_
const Translation translation() const