test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
G4CheckOverlap.cc
Go to the documentation of this file.
2 
4 
5 #include "G4RegionStore.hh"
6 #include "G4Region.hh"
7 #include "G4LogicalVolumeStore.hh"
8 #include "G4PhysicalVolumeStore.hh"
9 #include "G4VPhysicalVolume.hh"
10 #include "G4LogicalVolume.hh"
11 #include "G4GeomTestVolume.hh"
12 #include "globals.hh"
13 #include "G4SystemOfUnits.hh"
14 #include "G4GDMLParser.hh"
15 
16 #include <string>
17 
19 
20  std::vector<std::string> nodeNames
21  = p.getParameter<std::vector<std::string> >("NodeNames");
22  std::string PVname = p.getParameter<std::string>("PVname");
23  std::string LVname = p.getParameter<std::string>("LVname");
24  double tolerance
25  = p.getUntrackedParameter<double>("Tolerance", 0.0)*CLHEP::mm;
26  int nPoints = p.getUntrackedParameter<int>("Resolution", 10000);
27  bool verbose = p.getUntrackedParameter<bool>("Verbose", true);
28  bool regionFlag = p.getUntrackedParameter<bool>("RegionFlag", true);
29  bool gdmlFlag = p.getUntrackedParameter<bool>("gdmlFlag", false);
30  int nPrints = p.getUntrackedParameter<int>("ErrorThreshold", 1);
31  int level = p.getUntrackedParameter<int>("Level", 0);
32  int depth = p.getUntrackedParameter<int>("Depth", -1);
33 
34  const G4RegionStore* regStore = G4RegionStore::GetInstance();
35 
36  G4LogicalVolume* lv;
37  const G4PhysicalVolumeStore * pvs = G4PhysicalVolumeStore::GetInstance();
38  unsigned int numPV = pvs->size();
39 
40  unsigned int nn = nodeNames.size();
41  G4cout << "G4OverlapCheck is initialised with "
42  << nodeNames.size() << " nodes; " << " nPoints= " << nPoints
43  << "; tolerance= " << tolerance/mm << " mm; verbose: "
44  << verbose << "\n"
45  << " RegionFlag: " << regionFlag
46  << " PVname: " << PVname << " LVname: " << LVname << G4endl;
47 
48  if(0 < nn) {
49  for (unsigned int ii=0; ii<nn; ++ii) {
50  if("" == nodeNames[ii] || "world" == nodeNames[ii] || "World" == nodeNames[ii] ) {
51  nodeNames[ii] = "DDDWorld";
52  G4cout << "### Check overlaps for DDDWorld " << G4endl;
53  G4VPhysicalVolume* pv = pvs->GetVolume("DDDWorld");
54  G4GeomTestVolume test(pv, tolerance, nPoints, verbose);
55  test.SetErrorsThreshold(nPrints);
56  test.TestRecursiveOverlap(level, depth);
57  } else if(regionFlag) {
58  G4cout << "---------------------------------------------------------------" << G4endl;
59  G4cout << "### Check overlaps for G4Region Node[" << ii << "] : " << nodeNames[ii]
60  << G4endl;
61  G4Region* reg = regStore->GetRegion((G4String)nodeNames[ii]);
62  if(!reg) {
63  G4cout << "### NO G4Region found - EXIT" << G4endl;
64  return;
65  }
66  std::vector<G4LogicalVolume*>::iterator rootLVItr
67  = reg->GetRootLogicalVolumeIterator();
68  unsigned int numRootLV = reg->GetNumberOfRootVolumes();
69 
70  for(unsigned int iLV=0; iLV < numRootLV; ++iLV, ++rootLVItr ) {
71  // Cover each root logical volume in this region
72  lv = *rootLVItr;
73  G4cout << "### Check overlaps for G4LogicalVolume " << lv->GetName() << G4endl;
74  for(unsigned int i=0; i<numPV; ++i) {
75  if(((*pvs)[i])->GetLogicalVolume() == lv) {
76  G4cout << "### Check overlaps for PhysVolume " << ((*pvs)[i])->GetName()
77  << G4endl;
78  // gdml dump only for 1 volume
79  if(gdmlFlag) {
80  G4GDMLParser gdml;
81  gdml.Write(((*pvs)[i])->GetName()+".gdml", (*pvs)[i], true);
82  gdmlFlag = false;
83  }
84 
85  G4GeomTestVolume test(((*pvs)[i]), tolerance, nPoints, verbose);
86  test.SetErrorsThreshold(nPrints);
87  test.TestRecursiveOverlap(level, depth);
88  }
89  }
90  }
91 
92  } else {
93  G4cout << "### Check overlaps for PhysVolume Node[" << ii << "] : " << nodeNames[ii]
94  << G4endl;
95  G4VPhysicalVolume* pv = pvs->GetVolume((G4String)nodeNames[ii]);
96  G4GeomTestVolume test(pv, tolerance, nPoints, verbose);
97  test.SetErrorsThreshold(nPrints);
98  test.TestRecursiveOverlap(level, depth);
99  }
100  }
101  }
102  if("" != PVname) {
103  G4cout << "----------- List of PhysVolumes by name -----------------" << G4endl;
104  for (unsigned int i=0; i<numPV; ++i) {
105  if(PVname == ((*pvs)[i])->GetName()) {
106  G4cout << " ##### PhysVolume " << PVname << " [" << ((*pvs)[i])->GetCopyNo()
107  << "] LV: " << ((*pvs)[i])->GetLogicalVolume()->GetName()
108  << " Mother LV: " << ((*pvs)[i])->GetMotherLogical()->GetName() << G4endl;
109  G4cout << " Translation: " << ((*pvs)[i])->GetObjectTranslation() << G4endl;
110  G4cout << " Rotation: " << ((*pvs)[i])->GetObjectRotationValue() << G4endl;
111  }
112  }
113  }
114  if("" != LVname) {
115  G4cout << "---------- List of Logical Volumes by name ------------------" << G4endl;
116  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
117  unsigned int numLV = lvs->size();
118  for (unsigned int i=0; i<numLV; ++i) {
119  if(LVname == ((*lvs)[i])->GetName()) {
120  G4int np = ((*lvs)[i])->GetNoDaughters();
121  G4cout << " ##### LogVolume " << LVname << " " << np << " daughters" << G4endl;
122  for (G4int j=0; j<np; ++j) {
123  G4VPhysicalVolume* pv = ((*lvs)[i])->GetDaughter(j);
124  if(pv) {
125  G4cout << " PV: " << pv->GetName() << " [" << pv->GetCopyNo() << "]"
126  << " type: " << pv->VolumeType() << " multiplicity: "
127  << pv->GetMultiplicity() << " LV: "
128  << pv->GetLogicalVolume()->GetName() << G4endl;
129  G4cout << " Translation: " << pv->GetObjectTranslation() << G4endl;
130  G4cout << " Rotation: " << pv->GetObjectRotationValue() << G4endl;
131  }
132  }
133  }
134  }
135  }
136  G4cout << "---------------- End of overlap checks ---------------------" << G4endl;
137 }
138 
140 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
int ii
Definition: cuy.py:588
int np
Definition: AMPTWrapper.h:33
int j
Definition: DBlmapReader.cc:9
tuple level
Definition: testEve_cfg.py:34
G4CheckOverlap(edm::ParameterSet const &p)