CMS 3D CMS Logo

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