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  unsigned int nn = nodeNames.size();
40 
41  std::vector<G4String> savedgdml;
42 
43  G4cout << "G4OverlapCheck is initialised with "
44  << nodeNames.size() << " nodes; " << " nPoints= " << nPoints
45  << "; tolerance= " << tolerance/mm << " mm; verbose: "
46  << verbose << "\n"
47  << " RegionFlag: " << regionFlag
48  << " PVname: " << PVname << " LVname: " << LVname << G4endl;
49 
50  if(0 < nn) {
51  for (unsigned int ii=0; ii<nn; ++ii) {
52  if("" == nodeNames[ii] || "world" == nodeNames[ii] || "World" == nodeNames[ii] ) {
53  nodeNames[ii] = "DDDWorld";
54  G4cout << "### Check overlaps for DDDWorld " << G4endl;
55  G4VPhysicalVolume* pv = pvs->GetVolume("DDDWorld");
56  G4GeomTestVolume test(pv, tolerance, nPoints, verbose);
57  test.SetErrorsThreshold(nPrints);
58  test.TestRecursiveOverlap(level, depth);
59  } else if(regionFlag) {
60  G4cout << "---------------------------------------------------------------" << G4endl;
61  G4cout << "### Check overlaps for G4Region Node[" << ii << "] : " << nodeNames[ii]
62  << G4endl;
63  G4Region* reg = regStore->GetRegion((G4String)nodeNames[ii]);
64  if(!reg) {
65  G4cout << "### NO G4Region found - EXIT" << G4endl;
66  return;
67  }
68  std::vector<G4LogicalVolume*>::iterator rootLVItr
69  = reg->GetRootLogicalVolumeIterator();
70  unsigned int numRootLV = reg->GetNumberOfRootVolumes();
71  G4cout << " " << numRootLV << " Root Logical Volumes in this region" << G4endl;
72 
73  for(unsigned int iLV=0; iLV < numRootLV; ++iLV, ++rootLVItr ) {
74  // Cover each root logical volume in this region
75  lv = *rootLVItr;
76  G4cout << "### Check overlaps for G4LogicalVolume " << lv->GetName() << G4endl;
77  for(unsigned int i=0; i<numPV; ++i) {
78  if(((*pvs)[i])->GetLogicalVolume() == lv) {
79  G4String pvname = ((*pvs)[i])->GetName();
80  G4bool isNew = true;
81  for(unsigned int k=0; k<savedgdml.size(); ++k) {
82  if(pvname == savedgdml[k]) {
83  isNew = false;
84  break;
85  }
86  }
87  if(!isNew) {
88  G4cout << "### Check overlaps for PhysVolume " << pvname
89  << " is skipted because was already done" << G4endl;
90  continue;
91  }
92  savedgdml.push_back(pvname);
93  G4cout << "### Check overlaps for PhysVolume " << pvname
94  << G4endl;
95  // gdml dump only for 1 volume
96  if(gdmlFlag) {
97  G4GDMLParser gdml;
98  gdml.Write(pvname+".gdml", (*pvs)[i], true);
99  }
100  G4GeomTestVolume test(((*pvs)[i]), tolerance, nPoints, verbose);
101  test.SetErrorsThreshold(nPrints);
102  test.TestRecursiveOverlap(level, depth);
103  }
104  }
105  }
106 
107  } else {
108  G4cout << "### Check overlaps for PhysVolume Node[" << ii << "] : " << nodeNames[ii]
109  << G4endl;
110  G4VPhysicalVolume* pv = pvs->GetVolume((G4String)nodeNames[ii]);
111  G4GeomTestVolume test(pv, tolerance, nPoints, verbose);
112  test.SetErrorsThreshold(nPrints);
113  test.TestRecursiveOverlap(level, depth);
114  }
115  }
116  }
117  if("" != PVname) {
118  G4cout << "----------- List of PhysVolumes by name -----------------" << G4endl;
119  for (unsigned int i=0; i<numPV; ++i) {
120  if(PVname == ((*pvs)[i])->GetName()) {
121  G4cout << " ##### PhysVolume " << PVname << " [" << ((*pvs)[i])->GetCopyNo()
122  << "] LV: " << ((*pvs)[i])->GetLogicalVolume()->GetName()
123  << " Mother LV: " << ((*pvs)[i])->GetMotherLogical()->GetName() << G4endl;
124  G4cout << " Translation: " << ((*pvs)[i])->GetObjectTranslation() << G4endl;
125  G4cout << " Rotation: " << ((*pvs)[i])->GetObjectRotationValue() << G4endl;
126  }
127  }
128  }
129  if("" != LVname) {
130  G4cout << "---------- List of Logical Volumes by name ------------------" << G4endl;
131  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
132  unsigned int numLV = lvs->size();
133  for (unsigned int i=0; i<numLV; ++i) {
134  if(LVname == ((*lvs)[i])->GetName()) {
135  G4int np = ((*lvs)[i])->GetNoDaughters();
136  G4cout << " ##### LogVolume " << LVname << " " << np << " daughters" << G4endl;
137  for (G4int j=0; j<np; ++j) {
138  G4VPhysicalVolume* pv = ((*lvs)[i])->GetDaughter(j);
139  if(pv) {
140  G4cout << " PV: " << pv->GetName() << " [" << pv->GetCopyNo() << "]"
141  << " type: " << pv->VolumeType() << " multiplicity: "
142  << pv->GetMultiplicity() << " LV: "
143  << pv->GetLogicalVolume()->GetName() << G4endl;
144  G4cout << " Translation: " << pv->GetObjectTranslation() << G4endl;
145  G4cout << " Rotation: " << pv->GetObjectRotationValue() << G4endl;
146  }
147  }
148  }
149  }
150  }
151  G4cout << "---------------- End of overlap checks ---------------------" << G4endl;
152 }
153 
155 
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)