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