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