CMS 3D CMS Logo

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