CMS 3D CMS Logo

PrintGeomInfoAction.cc
Go to the documentation of this file.
2 
5 
15 
16 #include "G4Run.hh"
17 #include "G4PhysicalVolumeStore.hh"
18 #include "G4LogicalVolumeStore.hh"
19 #include "G4VPhysicalVolume.hh"
20 #include "G4LogicalVolume.hh"
21 #include "G4VSolid.hh"
22 #include "G4Material.hh"
23 #include "G4Track.hh"
24 #include "G4VisAttributes.hh"
25 #include "G4UserLimits.hh"
26 #include "G4TransportationManager.hh"
27 
28 #include <set>
29 #include <map>
30 
31 using namespace CLHEP;
32 
34  _dumpSummary = p.getUntrackedParameter<bool>("DumpSummary", true);
35  _dumpLVTree = p.getUntrackedParameter<bool>("DumpLVTree", true);
36  _dumpMaterial = p.getUntrackedParameter<bool>("DumpMaterial", false);
37  _dumpLVList = p.getUntrackedParameter<bool>("DumpLVList", false);
38  _dumpLV = p.getUntrackedParameter<bool>("DumpLV", false);
39  _dumpSolid = p.getUntrackedParameter<bool>("DumpSolid", false);
40  _dumpAtts = p.getUntrackedParameter<bool>("DumpAttributes", false);
41  _dumpPV = p.getUntrackedParameter<bool>("DumpPV", false);
42  _dumpRotation = p.getUntrackedParameter<bool>("DumpRotation", false);
43  _dumpReplica = p.getUntrackedParameter<bool>("DumpReplica", false);
44  _dumpTouch = p.getUntrackedParameter<bool>("DumpTouch", false);
45  _dumpSense = p.getUntrackedParameter<bool>("DumpSense", false);
46  name = p.getUntrackedParameter<std::string>("Name", "*");
47  nchar = name.find("*");
48  name.assign(name, 0, nchar);
49  names = p.getUntrackedParameter<std::vector<std::string> >("Names");
50  G4cout << "PrintGeomInfoAction:: initialised with verbosity levels:"
51  << " Summary " << _dumpSummary << " LVTree " << _dumpLVTree << " LVList " << _dumpLVList << " Material "
52  << _dumpMaterial << "\n "
53  << " LV " << _dumpLV << " Solid " << _dumpSolid << " Attribs " << _dumpAtts
54  << "\n "
55  << " PV " << _dumpPV << " Rotation " << _dumpRotation << " Replica " << _dumpReplica
56  << "\n "
57  << " Touchable " << _dumpTouch << " for names (0-" << nchar << ") = " << name
58  << "\n "
59  << " Sensitive " << _dumpSense << " for " << names.size() << " namess";
60  for (unsigned int i = 0; i < names.size(); i++)
61  G4cout << " " << names[i];
62  G4cout << G4endl;
63 }
64 
66 
68  if (_dumpSense) {
70  (*job)()->get<IdealGeometryRecord>().get(pDD);
71 
72  G4cout << "PrintGeomInfoAction::Get Printout of Sensitive Volumes "
73  << "for " << names.size() << " Readout Units" << G4endl;
74  for (unsigned int i = 0; i < names.size(); i++) {
75  std::string attribute = "ReadOutName";
76  std::string sd = names[i];
77  DDSpecificsMatchesValueFilter filter{DDValue(attribute, sd, 0)};
78  DDFilteredView fv(*pDD, filter);
79  G4cout << "PrintGeomInfoAction:: Get Filtered view for " << attribute << " = " << sd << G4endl;
80  bool dodet = fv.firstChild();
81 
82  std::string spaces = spacesFromLeafDepth(1);
83 
84  while (dodet) {
85  const DDLogicalPart &log = fv.logicalPart();
86  std::string lvname = log.name().name();
87  DDTranslation tran = fv.translation();
88  std::vector<int> copy = fv.copyNumbers();
89 
90  unsigned int leafDepth = copy.size();
91  G4cout << leafDepth << spaces << "### VOLUME = " << lvname << " Copy No";
92  for (int k = leafDepth - 1; k >= 0; k--)
93  G4cout << " " << copy[k];
94  G4cout << " Centre at " << tran << " (r = " << tran.Rho() << ", phi = " << tran.phi() / deg << ")" << G4endl;
95  dodet = fv.next();
96  }
97  }
98  }
99 }
100 
102  theTopPV = getTopPV();
103 
104  if (_dumpSummary)
105  dumpSummary(G4cout);
106  if (_dumpLVTree)
107  dumpG4LVTree(G4cout);
108 
109  //---------- Dump list of objects of each class with detail of parameters
110  if (_dumpMaterial)
111  dumpMaterialList(G4cout);
112  if (_dumpLVList)
113  dumpG4LVList(G4cout);
114 
115  //---------- Dump LV and PV information
116  if (_dumpLV || _dumpPV || _dumpTouch)
117  dumpHierarchyTreePVLV(G4cout);
118 }
119 
121  //---------- Dump number of objects of each class
122  out << " @@@@@@@@@@@@@@@@@@ Dumping G4 geometry objects Summary " << G4endl;
123  if (theTopPV == nullptr) {
124  out << " No volume created " << G4endl;
125  return;
126  }
127  out << " @@@ Geometry built inside world volume: " << theTopPV->GetName() << G4endl;
128  // Get number of solids (< # LV if several LV share a solid)
129  const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
130  std::vector<G4LogicalVolume *>::const_iterator lvcite;
131  std::set<G4VSolid *> theSolids;
132  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
133  theSolids.insert((*lvcite)->GetSolid());
134  out << " Number of G4VSolid's: " << theSolids.size() << G4endl;
135  out << " Number of G4LogicalVolume's: " << lvs->size() << G4endl;
136  const G4PhysicalVolumeStore *pvs = G4PhysicalVolumeStore::GetInstance();
137  out << " Number of G4VPhysicalVolume's: " << pvs->size() << G4endl;
138  out << " Number of Touchable's: " << countNoTouchables() << G4endl;
139  const G4MaterialTable *matTab = G4Material::GetMaterialTable();
140  out << " Number of G4Material's: " << matTab->size() << G4endl;
141 }
142 
144  out << " @@@@@@@@@@@@@@@@ DUMPING G4LogicalVolume's List " << G4endl;
145  const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
146  std::vector<G4LogicalVolume *>::const_iterator lvcite;
147  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
148  out << "LV:" << (*lvcite)->GetName() << "\tMaterial: " << (*lvcite)->GetMaterial()->GetName() << G4endl;
149 }
150 
152  out << " @@@@@@@@@@@@@@@@ DUMPING G4LogicalVolume's Tree " << G4endl;
153  G4LogicalVolume *lv = getTopLV();
154  dumpG4LVLeaf(lv, 0, 1, out);
155 }
156 
158  out << " @@@@@@@@@@@@@@@@ DUMPING G4Material List ";
159  const G4MaterialTable *matTab = G4Material::GetMaterialTable();
160  out << " with " << matTab->size() << " materials " << G4endl;
161  std::vector<G4Material *>::const_iterator matite;
162  for (matite = matTab->begin(); matite != matTab->end(); matite++)
163  out << "Material: " << (*matite) << G4endl;
164 }
165 
166 void PrintGeomInfoAction::dumpG4LVLeaf(G4LogicalVolume *lv,
167  unsigned int leafDepth,
168  unsigned int count,
169  std::ostream &out) {
170  for (unsigned int ii = 0; ii < leafDepth; ii++)
171  out << " ";
172  out << " LV:(" << leafDepth << ") " << lv->GetName() << " (" << count << ")" << G4endl;
173  //--- If a volume is placed n types as daughter of this LV, it should only be counted once
174  std::map<G4LogicalVolume *, unsigned int> lvCount;
175  std::map<G4LogicalVolume *, unsigned int>::const_iterator cite;
176  for (int ii = 0; ii < lv->GetNoDaughters(); ii++) {
177  cite = lvCount.find(lv->GetDaughter(ii)->GetLogicalVolume());
178  if (cite != lvCount.end())
179  lvCount[cite->first] = (cite->second) + 1;
180  else
181  lvCount.insert(std::pair<G4LogicalVolume *, unsigned int>(lv->GetDaughter(ii)->GetLogicalVolume(), 1));
182  }
183  for (cite = lvCount.begin(); cite != lvCount.end(); cite++)
184  dumpG4LVLeaf((cite->first), leafDepth + 1, (cite->second), out);
185 }
186 
188  int nTouch = 0;
189  G4LogicalVolume *lv = getTopLV();
190  add1touchable(lv, nTouch);
191  return nTouch;
192 }
193 
194 void PrintGeomInfoAction::add1touchable(G4LogicalVolume *lv, int &nTouch) {
195  int siz = lv->GetNoDaughters();
196  for (int ii = 0; ii < siz; ii++)
197  add1touchable(lv->GetDaughter(ii)->GetLogicalVolume(), ++nTouch);
198 }
199 
201  //dumps in the following order:
202  // 1) a LV with details
203  // 2) list of PVs daughters of this LV with details
204  // 3) list of LVs daughters of this LV and for each go to 1)
205 
206  //----- Get top PV
207  G4LogicalVolume *topLV = getTopLV();
208 
209  //----- Dump this leaf (it will recursively dump all the tree)
210  dumpHierarchyLeafPVLV(topLV, 0, out);
211  dumpPV(theTopPV, 0, out);
212 
213  //----- Dump the touchables (it will recursively dump all the tree)
214  if (_dumpTouch)
215  dumpTouch(theTopPV, 0, out);
216 }
217 
218 void PrintGeomInfoAction::dumpHierarchyLeafPVLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out) {
219  //----- Dump this LV
220  dumpLV(lv, leafDepth, out);
221 
222  //----- Get LV daughters from list of PV daughters
223  mmlvpv lvpvDaughters;
224  std::set<G4LogicalVolume *> lvDaughters;
225  int NoDaughters = lv->GetNoDaughters();
226  while ((NoDaughters--) > 0) {
227  G4VPhysicalVolume *pvD = lv->GetDaughter(NoDaughters);
228  lvpvDaughters.insert(mmlvpv::value_type(pvD->GetLogicalVolume(), pvD));
229  lvDaughters.insert(pvD->GetLogicalVolume());
230  }
231 
232  std::set<G4LogicalVolume *>::const_iterator scite;
233  mmlvpv::const_iterator mmcite;
234 
235  //----- Dump daughters PV and LV
236  for (scite = lvDaughters.begin(); scite != lvDaughters.end(); scite++) {
237  std::pair<mmlvpv::iterator, mmlvpv::iterator> mmER = lvpvDaughters.equal_range(*scite);
238  //----- Dump daughters PV of this LV
239  for (mmcite = mmER.first; mmcite != mmER.second; mmcite++)
240  dumpPV((*mmcite).second, leafDepth + 1, out);
241  //----- Dump daughters LV
242  dumpHierarchyLeafPVLV(*scite, leafDepth + 1, out);
243  }
244 }
245 
246 void PrintGeomInfoAction::dumpLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out) {
247  std::string spaces = spacesFromLeafDepth(leafDepth);
248 
249  //----- dump name
250  if (_dumpLV) {
251  out << leafDepth << spaces << "$$$ VOLUME = " << lv->GetName() << " Solid: " << lv->GetSolid()->GetName()
252  << " MATERIAL: " << lv->GetMaterial()->GetName() << G4endl;
253  if (_dumpSolid)
254  dumpSolid(lv->GetSolid(), leafDepth, out); //----- dump solid
255 
256  //----- dump LV info
257  //--- material
258  if (_dumpAtts) {
259  //--- Visualisation attributes
260  const G4VisAttributes *fVA = lv->GetVisAttributes();
261  if (fVA != nullptr) {
262  out << spaces << " VISUALISATION ATTRIBUTES: " << G4endl;
263  out << spaces << " IsVisible " << fVA->IsVisible() << G4endl;
264  out << spaces << " IsDaughtersInvisible " << fVA->IsDaughtersInvisible() << G4endl;
265  out << spaces << " Colour " << fVA->GetColour() << G4endl;
266  out << spaces << " LineStyle " << fVA->GetLineStyle() << G4endl;
267  out << spaces << " LineWidth " << fVA->GetLineWidth() << G4endl;
268  out << spaces << " IsForceDrawingStyle " << fVA->IsForceDrawingStyle() << G4endl;
269  out << spaces << " ForcedDrawingStyle " << fVA->GetForcedDrawingStyle() << G4endl;
270  }
271 
272  //--- User Limits
273  G4UserLimits *fUL = lv->GetUserLimits();
274  G4Track dummy;
275  if (fUL != nullptr) {
276  out << spaces << " MaxAllowedStep " << fUL->GetMaxAllowedStep(dummy) << G4endl;
277  out << spaces << " UserMaxTrackLength " << fUL->GetUserMaxTrackLength(dummy) << G4endl;
278  out << spaces << " UserMaxTime " << fUL->GetUserMaxTime(dummy) << G4endl;
279  out << spaces << " UserMinEkine " << fUL->GetUserMinEkine(dummy) << G4endl;
280  out << spaces << " UserMinRange " << fUL->GetUserMinRange(dummy) << G4endl;
281  }
282 
283  //--- other LV info
284  if (lv->GetSensitiveDetector())
285  out << spaces << " IS SENSITIVE DETECTOR " << G4endl;
286  if (lv->GetFieldManager())
287  out << spaces << " FIELD ON " << G4endl;
288 
289  // Pointer (possibly NULL) to optimisation info objects.
290  out << spaces << " Quality for optimisation, average number of voxels to be spent per content "
291  << lv->GetSmartless() << G4endl;
292 
293  // Pointer (possibly NULL) to G4FastSimulationManager object.
294  if (lv->GetFastSimulationManager())
295  out << spaces << " Logical Volume is an envelope for a FastSimulationManager " << G4endl;
296  out << spaces << " Weight used in the event biasing technique = " << lv->GetBiasWeight() << G4endl;
297  }
298  }
299 }
300 
301 void PrintGeomInfoAction::dumpPV(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out) {
302  std::string spaces = spacesFromLeafDepth(leafDepth);
303 
304  //----- PV info
305  if (_dumpPV) {
306  std::string mother = "World";
307  if (pv->GetMotherLogical())
308  mother = pv->GetMotherLogical()->GetName();
309  out << leafDepth << spaces << "### VOLUME = " << pv->GetName() << " Copy No " << pv->GetCopyNo() << " in " << mother
310  << " at " << pv->GetTranslation();
311  }
312  if (!pv->IsReplicated()) {
313  if (_dumpPV) {
314  if (pv->GetRotation() == nullptr)
315  out << " with no rotation" << G4endl;
316  else if (!_dumpRotation)
317  out << " with rotation" << G4endl; //just rotation name
318  else
319  out << " with rotation " << *(pv->GetRotation()) << G4endl;
320  }
321  } else {
322  if (_dumpReplica) {
323  out << spaces << " It is replica: " << G4endl;
324  EAxis axis;
325  int nReplicas;
326  double width;
327  double offset;
328  bool consuming;
329  pv->GetReplicationData(axis, nReplicas, width, offset, consuming);
330  out << spaces << " axis " << axis << G4endl << spaces << " nReplicas " << nReplicas << G4endl;
331  if (pv->GetParameterisation() != nullptr)
332  out << spaces << " It is parameterisation " << G4endl;
333  else
334  out << spaces << " width " << width << G4endl << spaces << " offset " << offset << G4endl << spaces
335  << " consuming" << consuming << G4endl;
336  if (pv->GetParameterisation() != nullptr)
337  out << spaces << " It is parameterisation " << G4endl;
338  }
339  }
340 }
341 
342 void PrintGeomInfoAction::dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out) {
343  std::string spaces = spacesFromLeafDepth(leafDepth);
344  if (leafDepth == 0)
345  fHistory.SetFirstEntry(pv);
346  else
347  fHistory.NewLevel(pv, kNormal, pv->GetCopyNo());
348 
349  G4ThreeVector globalpoint = fHistory.GetTopTransform().Inverse().TransformPoint(G4ThreeVector(0, 0, 0));
350  G4LogicalVolume *lv = pv->GetLogicalVolume();
351 
352  std::string mother = "World";
353  if (pv->GetMotherLogical())
354  mother = pv->GetMotherLogical()->GetName();
355  std::string lvname = lv->GetName();
356  lvname.assign(lvname, 0, nchar);
357  if (lvname == name)
358  out << leafDepth << spaces << "### VOLUME = " << lv->GetName() << " Copy No " << pv->GetCopyNo() << " in " << mother
359  << " global position of centre " << globalpoint << " (r = " << globalpoint.perp()
360  << ", phi = " << globalpoint.phi() / deg << ")" << G4endl;
361 
362  int NoDaughters = lv->GetNoDaughters();
363  while ((NoDaughters--) > 0) {
364  G4VPhysicalVolume *pvD = lv->GetDaughter(NoDaughters);
365  if (!pvD->IsReplicated())
366  dumpTouch(pvD, leafDepth + 1, out);
367  }
368 
369  if (leafDepth > 0)
370  fHistory.BackLevel();
371 }
372 
374  std::string spaces;
375  unsigned int ii;
376  for (ii = 0; ii < leafDepth; ii++) {
377  spaces += " ";
378  }
379  return spaces;
380 }
381 
382 void PrintGeomInfoAction::dumpSolid(G4VSolid *sol, unsigned int leafDepth, std::ostream &out) {
383  std::string spaces = spacesFromLeafDepth(leafDepth);
384  out << spaces << *(sol) << G4endl;
385 }
386 
387 G4VPhysicalVolume *PrintGeomInfoAction::getTopPV() {
388  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
389 }
390 
391 G4LogicalVolume *PrintGeomInfoAction::getTopLV() { return theTopPV->GetLogicalVolume(); }
void add1touchable(G4LogicalVolume *lv, int &nTouch)
std::multimap< G4LogicalVolume *, G4VPhysicalVolume *, std::less< G4LogicalVolume * > > mmlvpv
T getUntrackedParameter(std::string const &, T const &) const
void dumpMaterialList(std::ostream &out=std::cout)
void dumpSummary(std::ostream &out=std::cout)
PrintGeomInfoAction(edm::ParameterSet const &p)
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const N & name() const
Definition: DDBase.h:74
void dumpPV(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out=std::cout)
def copy(args, dbName)
nav_type copyNumbers() const
return the stack of copy numbers
void dumpHierarchyTreePVLV(std::ostream &out=std::cout)
const std::string names[nVars_]
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
void dumpG4LVTree(std::ostream &out=std::cout)
bool next()
set current node to the next node in the filtered tree
void dumpSolid(G4VSolid *sol, unsigned int leafDepth, std::ostream &out=std::cout)
void dumpLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out=std::cout)
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)
ii
Definition: cuy.py:590
int k[5][pyjets_maxn]
G4VPhysicalVolume * getTopPV()
void dumpHierarchyLeafPVLV(G4LogicalVolume *lv, unsigned int leafDepth, std::ostream &out=std::cout)
double sd
G4LogicalVolume * getTopLV()
void dumpG4LVList(std::ostream &out=std::cout)
void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth, std::ostream &out=std::cout)
void update(const BeginOfJob *job) override
This routine will be called when the appropriate signal arrives.
bool firstChild()
set the current node to the first child ...
const DDTranslation & translation() const
The absolute translation of the current node.
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
void dumpG4LVLeaf(G4LogicalVolume *lv, unsigned int leafDepth, unsigned int count, std::ostream &out=std::cout)