CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions
CMSG4CheckOverlap Class Reference

#include <CMSG4CheckOverlap.h>

Public Member Functions

 CMSG4CheckOverlap (edm::ParameterSet const &p, std::string &regFile, CustomUIsession *, G4VPhysicalVolume *world)
 
 ~CMSG4CheckOverlap ()=default
 

Private Member Functions

void makeReportForGeometry (std::ofstream &fout, G4VPhysicalVolume *world)
 
void makeReportForMaterials (std::ofstream &fout)
 
void makeReportForOverlaps (std::ofstream &fout, const edm::ParameterSet &p, G4VPhysicalVolume *world)
 

Detailed Description

Definition at line 11 of file CMSG4CheckOverlap.h.

Constructor & Destructor Documentation

◆ CMSG4CheckOverlap()

CMSG4CheckOverlap::CMSG4CheckOverlap ( edm::ParameterSet const &  p,
std::string &  regFile,
CustomUIsession session,
G4VPhysicalVolume *  world 
)

Definition at line 33 of file CMSG4CheckOverlap.cc.

References groupFilesInBlocks::fout, g4SimHits_cfi::gdmlFlag, relativeConstraints::geom, makeReportForGeometry(), makeReportForMaterials(), makeReportForOverlaps(), MillePedeFileConverter_cfg::out, AlCaHLTBitMon_ParallelJobs::p, g4SimHits_cfi::PVname, CMSG4RegionReporter::ReportRegions(), run_AlCaRecoTriggerBitsUpdateWorkflow::session, contentValuesCheck::ss, and AlCaHLTBitMon_QueryRunRegistry::string.

36  {
37  bool mat = p.getParameter<bool>("MaterialFlag");
38  const std::string& ss = p.getParameter<std::string>("OutputBaseName");
39  if (ss.empty()) {
40  edm::LogWarning("SimG4CoreGeometry")
41  << "CMSG4CheckOverlap: OutputFileBaseName is not provided - no check is performed";
42  return;
43  }
44  if (mat) {
45  const std::string sss = "Materials_" + ss + ".txt";
46  std::ofstream fout(sss.c_str(), std::ios::out);
47  if (fout.fail()) {
48  edm::LogWarning("SimG4CoreGeometry")
49  << "CMSG4CheckOverlap: file <" << sss << "> is not opened - no report provided";
50  } else {
51  edm::LogVerbatim("SimG4CoreGeometry") << "CMSG4CheckOverlap: output file <" << sss << "> is opened";
53  fout.close();
54  }
55  }
56 
57  bool reg = p.getParameter<bool>("RegionFlag");
58  if (reg) {
59  const std::string qqq = (regFile.empty()) ? ss : regFile;
60  const std::string sss = "Regions_" + qqq + ".txt";
62  rrep.ReportRegions(sss);
63  }
64 
65  bool geom = p.getParameter<bool>("GeomFlag");
66  if (geom) {
67  const std::string sss = "Geometry_" + ss + ".txt";
68  std::ofstream fout(sss.c_str(), std::ios::out);
69  if (fout.fail()) {
70  edm::LogWarning("SimG4CoreGeometry")
71  << "CMSG4CheckOverlap: file <" << sss << "> is not opened - no report provided";
72  } else {
73  edm::LogVerbatim("SimG4CoreGeometry") << "CMSG4CheckOverlap: output file <" << sss << "> is opened";
74  session->sendToFile(&fout);
76  session->stopSendToFile();
77  fout.close();
78  }
79  }
80 
81  bool gdmlFlag = p.getParameter<bool>("gdmlFlag");
82  if (gdmlFlag) {
83  std::string PVname = p.getParameter<std::string>("PVname");
84  if (PVname.empty() || PVname == "world" || PVname == "World") {
85  G4GDMLParser gdml = nullptr;
86  gdml.SetRegionExport(true);
87  gdml.SetEnergyCutsExport(true);
88  gdml.SetSDExport(true);
89  gdml.Write(ss + ".gdml", world, true);
90  }
91  }
92 
93  bool oFlag = p.getParameter<bool>("OverlapFlag");
94  if (oFlag) {
95  const std::string sss = "Overlaps_" + ss + ".txt";
96  std::ofstream fout(sss.c_str(), std::ios::out);
97  if (fout.fail()) {
98  edm::LogWarning("SimG4CoreGeometry")
99  << "CMSG4CheckOverlap: file <" << sss << "> is not opened - no report provided";
100  } else {
101  edm::LogVerbatim("SimG4CoreGeometry") << "CMSG4CheckOverlap: output file <" << ss << "> is opened";
102  session->sendToFile(&fout);
103  makeReportForOverlaps(fout, p, world);
104  session->stopSendToFile();
105  fout.close();
106  }
107  }
108 }
void makeReportForGeometry(std::ofstream &fout, G4VPhysicalVolume *world)
Log< level::Info, true > LogVerbatim
void makeReportForMaterials(std::ofstream &fout)
void ReportRegions(const std::string &ss)
void makeReportForOverlaps(std::ofstream &fout, const edm::ParameterSet &p, G4VPhysicalVolume *world)
Log< level::Warning, false > LogWarning

◆ ~CMSG4CheckOverlap()

CMSG4CheckOverlap::~CMSG4CheckOverlap ( )
default

Member Function Documentation

◆ makeReportForGeometry()

void CMSG4CheckOverlap::makeReportForGeometry ( std::ofstream &  fout,
G4VPhysicalVolume *  world 
)
private

Definition at line 167 of file CMSG4CheckOverlap.cc.

References groupFilesInBlocks::fout, and FSQDQM_cfi::pvs.

Referenced by CMSG4CheckOverlap().

167  {
168  const G4RegionStore* regs = G4RegionStore::GetInstance();
169  const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
170  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
171  int numPV = pvs->size();
172  int numLV = lvs->size();
173  int nreg = regs->size();
174  fout << "====================================================================="
175  << "\n";
176  fout << "NumberOfRegions " << nreg << "\n";
177  fout << "NumberOfLogicalVolumes " << numLV << "\n";
178  fout << "NumberOfPhysicalVolumes " << numPV << "\n";
179  fout << "====================================================================="
180  << "\n";
181  G4GeometryManager::GetInstance()->CloseGeometry(true, true, world);
182  fout << "====================================================================="
183  << "\n";
184 }

◆ makeReportForMaterials()

void CMSG4CheckOverlap::makeReportForMaterials ( std::ofstream &  fout)
private

Definition at line 110 of file CMSG4CheckOverlap.cc.

References hltHgcalLayerClustersEE_cfi::ecut, groupFilesInBlocks::fout, and mps_fire::i.

Referenced by CMSG4CheckOverlap().

110  {
111  int nelm = G4Element::GetNumberOfElements();
112  int nmat = G4Material::GetNumberOfMaterials();
113  G4ProductionCutsTable* theCoupleTable = G4ProductionCutsTable::GetProductionCutsTable();
114  int ncouples = theCoupleTable->GetTableSize();
115  fout << "====================================================================="
116  << "\n";
117  fout << "NumberOfElements " << nelm << "\n";
118  fout << "NumberOfMaterials " << nmat << "\n";
119  fout << "NumberOfCouples " << ncouples << "\n";
120  fout << "====================================================================="
121  << "\n";
122  fout << "ElementsDump:"
123  << "\n";
124  G4ElementTable* elmtab = G4Element::GetElementTable();
125  fout << *elmtab;
126  fout << "====================================================================="
127  << "\n";
128  G4MaterialTable* mattab = G4Material::GetMaterialTable();
129  fout << "MaterialsDump:"
130  << "\n";
131  //fout << *mattab << "\n";
132  for (int i = 0; i < nmat; ++i) {
133  fout << "### Material " << i << " " << ((*mattab)[i])->GetNumberOfElements() << " elements\n";
134  fout << (*mattab)[i] << "\n";
135  }
136  fout << "====================================================================="
137  << "\n";
138  fout << "MaterialsCutsCoupleDump:"
139  << "\n";
140  const std::vector<G4double>* gcut = theCoupleTable->GetEnergyCutsVector(0);
141  const std::vector<G4double>* ecut = theCoupleTable->GetEnergyCutsVector(1);
142  const std::vector<G4double>* pcut = theCoupleTable->GetEnergyCutsVector(2);
143  const std::vector<G4double>* icut = theCoupleTable->GetEnergyCutsVector(3);
144  for (int i = 0; i < ncouples; ++i) {
145  const G4MaterialCutsCouple* couple = theCoupleTable->GetMaterialCutsCouple(i);
146  const G4ProductionCuts* aCut = couple->GetProductionCuts();
147  fout << "Index : " << i << " used in the geometry : ";
148  if (couple->IsUsed()) {
149  fout << "Yes\n";
150  } else {
151  fout << "No \n";
152  }
153  fout << " Material : " << couple->GetMaterial()->GetName() << "\n";
154  fout << " Range cuts : "
155  << " gamma " << G4BestUnit(aCut->GetProductionCut(0), "Length") << " e- "
156  << G4BestUnit(aCut->GetProductionCut(1), "Length") << " e+ "
157  << G4BestUnit(aCut->GetProductionCut(2), "Length") << " proton "
158  << G4BestUnit(aCut->GetProductionCut(3), "Length") << "\n";
159  fout << " Energy thresholds : ";
160  fout << " gamma " << G4BestUnit((*gcut)[i], "Energy") << " e- " << G4BestUnit((*ecut)[i], "Energy")
161  << " e+ " << G4BestUnit((*pcut)[i], "Energy") << " proton " << G4BestUnit((*icut)[i], "Energy") << "\n";
162  }
163  fout << "======================================================================"
164  << "\n";
165 }

◆ makeReportForOverlaps()

void CMSG4CheckOverlap::makeReportForOverlaps ( std::ofstream &  fout,
const edm::ParameterSet p,
G4VPhysicalVolume *  world 
)
private

Definition at line 186 of file CMSG4CheckOverlap.cc.

References relativeConstraints::empty, groupFilesInBlocks::fout, g4SimHits_cfi::gdmlFlag, mps_fire::i, cuy::ii, dqmiolumiharvest::j, isotrackApplyRegressor::k, g4SimHits_cfi::LVname, groupFilesInBlocks::nn, np, AlCaHLTBitMon_ParallelJobs::p, g4SimHits_cfi::PVname, FSQDQM_cfi::pvs, AlCaHLTBitMon_QueryRunRegistry::string, builder_last_value_cfg::test, tolerance, and verbose.

Referenced by CMSG4CheckOverlap().

188  {
189  std::vector<std::string> nodeNames = p.getParameter<std::vector<std::string>>("NodeNames");
190  std::string PVname = p.getParameter<std::string>("PVname");
191  std::string LVname = p.getParameter<std::string>("LVname");
192  double tolerance = p.getParameter<double>("Tolerance") * CLHEP::mm;
193  int nPoints = p.getParameter<int>("Resolution");
194  bool verbose = p.getParameter<bool>("Verbose");
195  bool regionFlag = p.getParameter<bool>("RegionFlag");
196  bool gdmlFlag = p.getParameter<bool>("gdmlFlag");
197  int nPrints = p.getParameter<int>("ErrorThreshold");
198 
199  const G4RegionStore* regStore = G4RegionStore::GetInstance();
200 
201  G4LogicalVolume* lv;
202  const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
203  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
204  unsigned int numPV = pvs->size();
205  unsigned int numLV = lvs->size();
206  unsigned int nn = nodeNames.size();
207 
208  std::vector<G4String> savedgdml;
209 
210  fout << "====================================================================="
211  << "\n";
212  fout << "CMSG4OverlapCheck is initialised with " << nodeNames.size() << " nodes; "
213  << " nPoints= " << nPoints << "; tolerance= " << tolerance / CLHEP::mm << " mm; verbose: " << verbose << "\n"
214  << " RegionFlag: " << regionFlag << " PVname: " << PVname << " LVname: " << LVname << "\n"
215  << " Nlv= " << numLV << " Npv= " << numPV << "\n";
216  fout << "====================================================================="
217  << "\n";
218 
219  G4GDMLParser* gdml = nullptr;
220  if (gdmlFlag) {
221  gdml = new G4GDMLParser();
222  gdml->SetRegionExport(true);
223  gdml->SetEnergyCutsExport(true);
224  gdml->SetSDExport(true);
225  }
226  if (0 < nn) {
227  for (unsigned int ii = 0; ii < nn; ++ii) {
228  if (nodeNames[ii].empty() || "world" == nodeNames[ii] || "World" == nodeNames[ii]) {
229  nodeNames[ii] = world->GetName();
230  fout << "### Check overlaps for World "
231  << "\n";
232  G4GeomTestVolume test(world, tolerance, nPoints, verbose);
233  test.SetErrorsThreshold(nPrints);
234  test.TestOverlapInTree();
235  } else if (regionFlag) {
236  fout << "---------------------------------------------------------------"
237  << "\n";
238  fout << "### Check overlaps for G4Region Node[" << ii << "] : " << nodeNames[ii] << "\n";
239  G4Region* reg = regStore->GetRegion((G4String)nodeNames[ii]);
240  std::vector<G4LogicalVolume*>::iterator rootLVItr = reg->GetRootLogicalVolumeIterator();
241  unsigned int numRootLV = reg->GetNumberOfRootVolumes();
242  fout << " " << numRootLV << " Root Logical Volumes in this region"
243  << "\n";
244 
245  for (unsigned int iLV = 0; iLV < numRootLV; ++iLV, ++rootLVItr) {
246  // Cover each root logical volume in this region
247  lv = *rootLVItr;
248  fout << "### Check overlaps for G4LogicalVolume " << lv->GetName() << "\n";
249  for (unsigned int i = 0; i < numPV; ++i) {
250  if (((*pvs)[i])->GetLogicalVolume() == lv) {
251  G4String pvname = ((*pvs)[i])->GetName();
252  G4bool isNew = true;
253  for (unsigned int k = 0; k < savedgdml.size(); ++k) {
254  if (pvname == savedgdml[k]) {
255  isNew = false;
256  break;
257  }
258  }
259  if (!isNew) {
260  fout << "### Check overlaps for PhysVolume " << pvname << " is skipted because was already done"
261  << "\n";
262  continue;
263  }
264  savedgdml.push_back(pvname);
265  fout << "### Check overlaps for PhysVolume " << pvname << "\n";
266  // gdml dump only for 1 volume
267  if (gdmlFlag) {
268  gdml->Write(pvname + ".gdml", (*pvs)[i], true);
269  }
270  G4GeomTestVolume test(((*pvs)[i]), tolerance, nPoints, verbose);
271  test.SetErrorsThreshold(nPrints);
272  test.TestOverlapInTree();
273  }
274  }
275  }
276  } else {
277  fout << "### Check overlaps for PhysVolume Node[" << ii << "] : " << nodeNames[ii] << "\n";
278  G4VPhysicalVolume* pv = pvs->GetVolume((G4String)nodeNames[ii]);
279  G4GeomTestVolume test(pv, tolerance, nPoints, verbose);
280  test.SetErrorsThreshold(nPrints);
281  test.TestOverlapInTree();
282  }
283  }
284  }
285  if (!PVname.empty()) {
286  fout << "----------- List of PhysVolumes by name -----------------"
287  << "\n";
288  for (unsigned int i = 0; i < numPV; ++i) {
289  if (PVname == (*pvs)[i]->GetName()) {
290  fout << " ##### PhysVolume " << PVname << " [" << ((*pvs)[i])->GetCopyNo()
291  << "] LV: " << ((*pvs)[i])->GetLogicalVolume()->GetName()
292  << " Mother LV: " << ((*pvs)[i])->GetMotherLogical()->GetName()
293  << " Region: " << ((*pvs)[i])->GetLogicalVolume()->GetRegion()->GetName() << "\n";
294  fout << " Translation: " << ((*pvs)[i])->GetObjectTranslation() << "\n";
295  fout << " Rotation: " << ((*pvs)[i])->GetObjectRotationValue() << "\n";
296  if (gdmlFlag) {
297  gdml->Write(PVname + ".gdml", (*pvs)[i], true);
298  }
299  }
300  }
301  }
302  if (!LVname.empty()) {
303  fout << "---------- List of Logical Volumes by name ------------------"
304  << "\n";
305  for (unsigned int i = 0; i < numLV; ++i) {
306  if (LVname == ((*lvs)[i])->GetName()) {
307  G4int np = ((*lvs)[i])->GetNoDaughters();
308  fout << " ##### LogVolume " << LVname << " " << np << " daughters"
309  << " Region: " << ((*lvs)[i])->GetRegion()->GetName() << "\n";
310  fout << *(((*lvs)[i])->GetSolid()) << "\n";
311  for (G4int j = 0; j < np; ++j) {
312  G4VPhysicalVolume* pv = ((*lvs)[i])->GetDaughter(j);
313  if (pv) {
314  fout << " PV: " << pv->GetName() << " [" << pv->GetCopyNo() << "]"
315  << " type: " << pv->VolumeType() << " multiplicity: " << pv->GetMultiplicity()
316  << " LV: " << pv->GetLogicalVolume()->GetName() << "\n";
317  fout << " Translation: " << pv->GetObjectTranslation() << "\n";
318  fout << " Rotation: " << pv->GetObjectRotationValue() << "\n";
319  fout << *(pv->GetLogicalVolume()->GetSolid()) << "\n";
320  }
321  }
322  }
323  }
324  }
325  fout << "---------------- End of overlap checks ---------------------"
326  << "\n";
327  delete gdml;
328 }
bool verbose
const double tolerance
int np
Definition: AMPTWrapper.h:43
ii
Definition: cuy.py:589