CMS 3D CMS Logo

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