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