From 2a0aa0b2314f5de99d9a24a0bc666faf65dc794c Mon Sep 17 00:00:00 2001 From: Sunanda Date: Thu, 15 Apr 2021 18:10:17 +0200 Subject: [PATCH 1/3] Check in more detail the content of teh geometry --- .../interface/PrintGeomInfoAction.h | 1 + .../PrintGeomInfo/src/PrintGeomInfoAction.cc | 37 ++- .../PrintGeomInfo/test/SimFileCompare.cpp | 272 +++++++++++++++--- .../test/python/runDD4HEP_cfg.py | 2 + .../PrintGeomInfo/test/python/runDDD_cfg.py | 5 +- 5 files changed, 270 insertions(+), 47 deletions(-) diff --git a/SimG4Core/PrintGeomInfo/interface/PrintGeomInfoAction.h b/SimG4Core/PrintGeomInfo/interface/PrintGeomInfoAction.h index 769c384d34321..1ac319ebb449a 100644 --- a/SimG4Core/PrintGeomInfo/interface/PrintGeomInfoAction.h +++ b/SimG4Core/PrintGeomInfo/interface/PrintGeomInfoAction.h @@ -55,6 +55,7 @@ class PrintGeomInfoAction : public SimWatcher, public Observer names_; G4VPhysicalVolume* theTopPV_; G4NavigationHistory fHistory_; diff --git a/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc b/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc index cd93c2609d491..f3a1ff3ddb9ea 100644 --- a/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc +++ b/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc @@ -62,6 +62,7 @@ PrintGeomInfoAction::PrintGeomInfoAction(const edm::ParameterSet &p) { fileLV_ = p.getUntrackedParameter("LVFileName", ""); filePV_ = p.getUntrackedParameter("PVFileName", ""); fileTouch_ = p.getUntrackedParameter("TouchFileName", ""); + fileDetail_ = p.getUntrackedParameter("FileDetail", false); G4cout << "PrintGeomInfoAction:: initialised for dd4hep " << dd4hep_ << " with verbosity levels:" << " Summary " << dumpSummary_ << " LVTree " << dumpLVTree_ << " LVList " << dumpLVList_ << " Material " << dumpMaterial_ << "\n " @@ -72,8 +73,7 @@ PrintGeomInfoAction::PrintGeomInfoAction(const edm::ParameterSet &p) { << " Touchable " << dumpTouch_ << " for names (0-" << nchar_ << ") = " << name_ << "\n " << " Sensitive " << dumpSense_ << " Files " << fileMat_ << ":" << fileSolid_ << ":" << fileLV_ << ":" - << filePV_ << ":" << fileTouch_ << "\n " - << "for " << names_.size() << " names:"; + << filePV_ << ":" << fileTouch_ << " FileDetail " << fileDetail_ << "\n for " << names_.size() << " names:"; for (unsigned int i = 0; i < names_.size(); i++) G4cout << " " << names_[i]; G4cout << G4endl; @@ -432,31 +432,48 @@ void PrintGeomInfoAction::dumpInFile() { if (!fileMat_.empty()) { const G4MaterialTable *matTab = G4Material::GetMaterialTable(); std::ofstream fout(fileMat_.c_str()); - for (std::vector::const_iterator matite = matTab->begin(); matite != matTab->end(); matite++) - fout << (*matite)->GetName() << "\n"; + for (std::vector::const_iterator matite = matTab->begin(); matite != matTab->end(); matite++) { + if (!fileDetail_) + fout << (*matite)->GetName() << "\n"; + else + fout << (*matite)->GetName() << " " << (*matite)->GetRadlen() << " " << (*matite)->GetNuclearInterLength() << "\n"; + } fout.close(); } const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance(); if (!fileSolid_.empty()) { std::ofstream fout(fileSolid_.c_str()); for (std::vector::const_iterator lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) - fout << (*lvcite)->GetSolid()->GetName() << "\n"; + if (!fileDetail_) + fout << (*lvcite)->GetSolid()->GetName() << "\n"; + else + fout << (*lvcite)->GetSolid()->GetName() << " " << (*lvcite)->GetSolid()->GetCubicVolume() << "\n"; fout.close(); } if (!fileLV_.empty()) { std::ofstream fout(fileLV_.c_str()); for (std::vector::const_iterator lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) - fout << (*lvcite)->GetName() << "\n"; + if (!fileDetail_) + fout << (*lvcite)->GetName() << "\n"; + else + fout << (*lvcite)->GetName() << " " << (*lvcite)->GetMass(false,false) << "\n"; fout.close(); } if (!filePV_.empty()) { const G4PhysicalVolumeStore *pvs = G4PhysicalVolumeStore::GetInstance(); std::ofstream fout(filePV_.c_str()); for (std::vector::const_iterator pvcite = pvs->begin(); pvcite != pvs->end(); pvcite++) { - if (dd4hep_) - fout << (*pvcite)->GetName() << "\n"; - else - fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << "\n"; + if (fileDetail_) { + if (dd4hep_) + fout << (*pvcite)->GetName() << " " << (*pvcite)->GetTranslation().x() << " " << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << "\n"; + else + fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << " " << (*pvcite)->GetTranslation().x() << " " << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << "\n"; + } else { + if (dd4hep_) + fout << (*pvcite)->GetName() << "\n"; + else + fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << "\n"; + } } fout.close(); } diff --git a/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp b/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp index ded68bfdce1a7..a3511ef699216 100644 --- a/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp +++ b/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp @@ -6,6 +6,8 @@ // SimFileCompare infile1 infile2 mode debug // infile1 (const char*) File created using DDD // infile2 (const char*) File created using DD4Hep +// type (int) Type of file: material (0), solid (1), +// LogicalVolume (2), PhysicalVolume (3) // mode (int) Treat (0) or not treat (1) names from DDD // deug (int) Single digit number (0 minimum printout) // @@ -20,6 +22,30 @@ #include #include +struct materials { + int occ; + double radl, intl; + materials(int oc = 1, double rd = 0, double in = 0) : occ(oc), radl(rd), intl(in) {} +}; + +struct solids { + int occ; + double volume; + solids(int oc = 1, double vol = 0) : occ(oc), volume(vol) {} +}; + +struct lvs { + int occ; + double mass; + lvs(int oc = 1, double m = 0) : occ(oc), mass(m) {} +}; + +struct pvs { + int occ; + double xx, yy, zz; + pvs(int oc = 1, double x = 0, double y = 0, double z = 0) : occ(oc), xx(x), yy(y), zz(z) {} +}; + std::string removeExtraName(const std::string& name, int debug) { std::string nam(name); std::string nam1 = name.substr(0, 2); @@ -61,68 +87,246 @@ std::string reducedName(const std::string& name, int debug) { return nam; } -void CompareFiles(const char* fileDDD, const char* fileDD4Hep, int mode, int debug) { - std::map nameDDD, nameDD4Hep; +std::vector splitString(const std::string& fLine) { + std::vector result; + int start = 0; + bool empty = true; + for (unsigned i = 0; i <= fLine.size(); i++) { + if (fLine[i] == ' ' || i == fLine.size()) { + if (!empty) { + std::string item(fLine, start, i - start); + result.push_back(item); + empty = true; + } + start = i + 1; + } else { + if (empty) + empty = false; + } + } + return result; +} + +template +void myPrint1(std::map const& obj) { + for (auto it : obj) { + if (it.second.occ > 1) + std::cout << it.first << " : " << it.second.occ << std::endl; + } +} + +template +void myPrint2(std::map const& obj1, std::map const& obj2) { + for (auto it : obj1) { + if (obj2.find(it.first) == obj2.end()) + std::cout << it.first << " appearing " << it.second.occ << " times" << std::endl; + } +} + +void CompareFiles(const char* fileDDD, const char* fileDD4Hep, int type, int mode, int debug) { + std::map matDDD, matDD4Hep; + std::map solidDDD, solidDD4Hep; + std::map lvDDD, lvDD4Hep; + std::map pvDDD, pvDD4Hep; char buffer[100]; std::string name; std::ifstream fInput1(fileDDD); + unsigned int sizeDDD, sizeDD4Hep; if (!fInput1.good()) { std::cout << "Cannot open file " << fileDDD << std::endl; } else { while (fInput1.getline(buffer, 100)) { - name = ((mode == 1) ? removeExtraName(std::string(buffer), debug) : std::string(buffer)); - auto it = nameDDD.find(name); - if (it == nameDDD.end()) - nameDDD[name] = 1; - else - ++(it->second); + std::vector items = splitString(std::string(buffer)); + name = ((mode == 1) ? removeExtraName(items[0], debug) : items[0]); + double r1 = (items.size() > 1) ? atof(items[1].c_str()) : 0; + double r2 = (items.size() > 2) ? atof(items[2].c_str()) : 0; + double r3 = (items.size() > 3) ? atof(items[3].c_str()) : 0; + if (type == 0) { + auto it = matDDD.find(name); + if (it == matDDD.end()) + matDDD[name] = materials(1, r1, r2); + else + ++((it->second).occ); + } else if (type == 1) { + auto it = solidDDD.find(name); + if (it == solidDDD.end()) + solidDDD[name] = solids(1, r1); + else + ++((it->second).occ); + } else if (type == 2) { + auto it = lvDDD.find(name); + if (it == lvDDD.end()) + lvDDD[name] = lvs(1, r1); + else + ++((it->second).occ); + } else { + auto it = pvDDD.find(name); + if (it == pvDDD.end()) + pvDDD[name] = pvs(1, r1, r2, r3); + else + ++((it->second).occ); + } } fInput1.close(); + sizeDDD = ((type == 0) ? matDDD.size() : ((type == 1) ? solidDDD.size() : ((type == 2) ? lvDDD.size() : pvDDD.size()))); } std::ifstream fInput2(fileDD4Hep); if (!fInput2.good()) { std::cout << "Cannot open file " << fileDD4Hep << std::endl; } else { while (fInput2.getline(buffer, 100)) { - name = reducedName(std::string(buffer), debug); - auto it = nameDD4Hep.find(name); - if (it == nameDD4Hep.end()) - nameDD4Hep[name] = 1; - else - ++(it->second); + std::vector items = splitString(std::string(buffer)); + name = reducedName(items[0], debug); + double r1 = (items.size() > 1) ? atof(items[1].c_str()) : 0; + double r2 = (items.size() > 2) ? atof(items[2].c_str()) : 0; + double r3 = (items.size() > 3) ? atof(items[3].c_str()) : 0; + if (type == 0) { + auto it = matDD4Hep.find(name); + if (it == matDD4Hep.end()) + matDD4Hep[name] = materials(1, r1, r2); + else + ++((it->second).occ); + } else if (type == 1) { + auto it = solidDD4Hep.find(name); + if (it == solidDD4Hep.end()) + solidDD4Hep[name] = solids(1, r1); + else + ++((it->second).occ); + } else if (type == 2) { + auto it = lvDD4Hep.find(name); + if (it == lvDD4Hep.end()) + lvDD4Hep[name] = lvs(1, r1); + else + ++((it->second).occ); + } else { + auto it = pvDD4Hep.find(name); + if (it == pvDD4Hep.end()) + pvDD4Hep[name] = pvs(1, r1, r2, r3); + else + ++((it->second).occ); + } } - fInput1.close(); + fInput2.close(); + sizeDD4Hep = ((type == 0) ? matDD4Hep.size() : ((type == 1) ? solidDD4Hep.size() : ((type == 2) ? lvDD4Hep.size() : pvDD4Hep.size()))); } - std::cout << "Reads " << nameDDD.size() << " names from " << fileDDD << " and " << nameDD4Hep.size() << " names from " - << fileDD4Hep << std::endl; + std::cout << "Reads " << sizeDDD << " names from " << fileDDD << " and " << sizeDD4Hep << " names from " << fileDD4Hep << std::endl; std::cout << "\nMore than one entry for a given name in " << fileDDD << std::endl; - for (auto it : nameDDD) { - if (it.second > 1) - std::cout << it.first << " : " << it.second << std::endl; + if (type == 0) { + myPrint1 (matDDD); + } else if (type == 1) { + myPrint1 (solidDDD); + } else if (type == 2) { + myPrint1 (lvDDD); + } else { + myPrint1 (pvDDD); } + std::cout << "\nMore than one entry for a given name in " << fileDD4Hep << std::endl; - for (auto it : nameDD4Hep) { - if (it.second > 1) - std::cout << it.first << " : " << it.second << std::endl; + if (type == 0) { + myPrint1 (matDD4Hep); + } else if (type == 1) { + myPrint1 (solidDD4Hep); + } else if (type == 2) { + myPrint1 (lvDD4Hep); + } else { + myPrint1 (pvDD4Hep); } + std::cout << "\nEntry in " << fileDDD << " not in " << fileDD4Hep << std::endl; - for (auto it : nameDDD) { - if (nameDD4Hep.find(it.first) == nameDD4Hep.end()) - std::cout << it.first << " appearing " << it.second << " times" << std::endl; + if (type == 0) { + myPrint2 (matDDD, matDD4Hep); + } else if (type == 1) { + myPrint2 (solidDDD, solidDD4Hep); + } else if (type == 2) { + myPrint2 (lvDDD, lvDD4Hep); + } else { + myPrint2 (pvDDD, pvDD4Hep); } + std::cout << "\nEntry in " << fileDD4Hep << " not in " << fileDDD << std::endl; - for (auto it : nameDD4Hep) { - if (nameDDD.find(it.first) == nameDDD.end()) - std::cout << it.first << " appearing " << it.second << " times" << std::endl; + if (type == 0) { + myPrint2 (matDD4Hep, matDDD); + } else if (type == 1) { + myPrint2 (solidDD4Hep, solidDDD); + } else if (type == 2) { + myPrint2 (lvDD4Hep, lvDDD); + } else { + myPrint2 (pvDD4Hep, pvDDD); + } + + //Now type specific changes + std::cout << "\nEntries in " << fileDDD << " and " << fileDD4Hep << " do not match in the content\n"; + const double denmin = 0.0001; + int kount1(0), kount2(0); + if (type == 0) { + const double tol1 = 0.00001; + for (auto it1 : matDDD) { + auto it2 = matDD4Hep.find(it1.first); + if (it2 != matDD4Hep.end()) { + ++kount1; + double rdif = 0.5 * (it1.second.radl - it2->second.radl) / std::max(denmin, (it1.second.radl + it2->second.radl)); + double idif = 0.5 * (it1.second.intl - it2->second.intl) / std::max(denmin, (it1.second.intl + it2->second.intl)); + if ((std::abs(rdif) > tol1) || (std::abs(idif) > tol1)) { + ++kount2; + std::cout << it1.first << " Radiation Length " << it1.second.radl << ":" << it2->second.radl << ":" << rdif << " Interaction Length " << it1.second.intl << ":" << it2->second.intl << ":" << idif << std::endl; + } + } + } + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol1 << " or more\n"; + } else if (type == 1) { + const double tol2 = 0.0001; + for (auto it1 : solidDDD) { + auto it2 = solidDD4Hep.find(it1.first); + if (it2 != solidDD4Hep.end()) { + ++kount1; + double vdif = 0.5 * (it1.second.volume - it2->second.volume) / std::max(denmin, (it1.second.volume + it2->second.volume)); + if (std::abs(vdif) > tol2) { + ++kount2; + std::cout << it1.first << " Volume " << it1.second.volume << ":" << it2->second.volume << ":" << vdif << std::endl; + } + } + } + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol2 << " or more\n"; + } else if (type == 2) { + const double tol3 = 0.0001; + for (auto it1 : lvDDD) { + auto it2 = lvDD4Hep.find(it1.first); + if (it2 != lvDD4Hep.end()) { + ++kount1; + double vdif = 0.5 * (it1.second.mass - it2->second.mass) / std::max(denmin, (it1.second.mass + it2->second.mass)); + if (std::abs(vdif) > tol3) { + ++kount2; + std::cout << it1.first << " Mass " << it1.second.mass << ":" << it2->second.mass << ":" << vdif << std::endl; + } + } + } + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol3 << " or more\n"; + } else { + const double tol4 = 0.0001; + for (auto it1 : pvDDD) { + auto it2 = pvDD4Hep.find(it1.first); + if (it2 != pvDD4Hep.end()) { + ++kount1; + double xdif = (it1.second.xx - it2->second.xx); + double ydif = (it1.second.yy - it2->second.yy); + double zdif = (it1.second.zz - it2->second.zz); + if ((std::abs(xdif) > tol4) || (std::abs(ydif) > tol4) || (std::abs(zdif) > tol4)) { + ++kount2; + std::cout << it1.first << " x " << it1.second.xx << ":" << it2->second.xx << ":" << xdif << " y " << it1.second.yy << ":" << it2->second.yy << ":" << ydif << " z " << it1.second.zz << ":" << it2->second.zz << ":" << zdif << std::endl; + } + } + } + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol4 << " or more\n"; } } int main(int argc, char* argv[]) { - if (argc <= 3) { + if (argc <= 4) { std::cout << "Please give a minimum of 2 arguments \n" << "input file name from the DDD run\n" << "input file name from the DD4Hep run\n" + << "type (Material:0, Solid:1, LV:2, PV:3\n" << "mode (treat the name for DDD or not == needed for PV)\n" << "debug flag (0 for minimum printout)\n" << std::endl; @@ -131,8 +335,10 @@ int main(int argc, char* argv[]) { const char* infile1 = argv[1]; const char* infile2 = argv[2]; - int mode = ((argc > 3) ? atoi(argv[3]) : 0); - int debug = ((argc > 4) ? atoi(argv[4]) : 0); - CompareFiles(infile1, infile2, mode, debug); + int type = ((argc > 3) ? atoi(argv[3]) : 0); + if (type < 0 || type > 3) type = 0; + int mode = ((argc > 4) ? atoi(argv[4]) : 0); + int debug = ((argc > 5) ? atoi(argv[5]) : 0); + CompareFiles(infile1, infile2, type, mode, debug); return 0; } diff --git a/SimG4Core/PrintGeomInfo/test/python/runDD4HEP_cfg.py b/SimG4Core/PrintGeomInfo/test/python/runDD4HEP_cfg.py index a5b840de3c96d..0f4fabab119c3 100644 --- a/SimG4Core/PrintGeomInfo/test/python/runDD4HEP_cfg.py +++ b/SimG4Core/PrintGeomInfo/test/python/runDD4HEP_cfg.py @@ -16,6 +16,7 @@ if hasattr(process,'MessageLogger'): process.MessageLogger.G4cerr=dict() process.MessageLogger.G4cout=dict() + process.g4SimHits.Watchers = cms.VPSet(cms.PSet( DumpSummary = cms.untracked.bool(True), DumpLVTree = cms.untracked.bool(False), @@ -37,5 +38,6 @@ LVFileName = cms.untracked.string('lvfileDD4Hep.txt'), PVFileName = cms.untracked.string('pvfileDD4Hep.txt'), TouchFileName = cms.untracked.string('touchfileDD4Hep.txt'), + FileDetail = cms.untracked.bool(True), type = cms.string('PrintGeomInfoAction') )) diff --git a/SimG4Core/PrintGeomInfo/test/python/runDDD_cfg.py b/SimG4Core/PrintGeomInfo/test/python/runDDD_cfg.py index 18af92f3380bd..9e08e479fab45 100644 --- a/SimG4Core/PrintGeomInfo/test/python/runDDD_cfg.py +++ b/SimG4Core/PrintGeomInfo/test/python/runDDD_cfg.py @@ -15,7 +15,6 @@ process.load('FWCore.MessageService.MessageLogger_cfi') - from SimG4Core.PrintGeomInfo.g4PrintGeomInfo_cfi import * process = printGeomInfo(process) @@ -24,9 +23,6 @@ process.MessageLogger.G4cerr=dict() process.MessageLogger.G4cout=dict() - - -process.g4SimHits.g4GeometryDD4hepSource = cms.bool(False) process.g4SimHits.Watchers = cms.VPSet(cms.PSet( DumpSummary = cms.untracked.bool(True), DumpLVTree = cms.untracked.bool(False), @@ -48,5 +44,6 @@ LVFileName = cms.untracked.string('lvfileDDD.txt'), PVFileName = cms.untracked.string('pvfileDDD.txt'), TouchFileName = cms.untracked.string('touchfileDDD.txt'), + FileDetail = cms.untracked.bool(True), type = cms.string('PrintGeomInfoAction') )) From a487a4e799145b6ae75f1656c314a19cbbf8ab61 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Thu, 15 Apr 2021 18:33:58 +0200 Subject: [PATCH 2/3] Code check --- .../PrintGeomInfo/src/PrintGeomInfoAction.cc | 52 ++--- .../PrintGeomInfo/test/SimFileCompare.cpp | 202 ++++++++++-------- 2 files changed, 137 insertions(+), 117 deletions(-) diff --git a/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc b/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc index f3a1ff3ddb9ea..f428d816dc131 100644 --- a/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc +++ b/SimG4Core/PrintGeomInfo/src/PrintGeomInfoAction.cc @@ -73,7 +73,8 @@ PrintGeomInfoAction::PrintGeomInfoAction(const edm::ParameterSet &p) { << " Touchable " << dumpTouch_ << " for names (0-" << nchar_ << ") = " << name_ << "\n " << " Sensitive " << dumpSense_ << " Files " << fileMat_ << ":" << fileSolid_ << ":" << fileLV_ << ":" - << filePV_ << ":" << fileTouch_ << " FileDetail " << fileDetail_ << "\n for " << names_.size() << " names:"; + << filePV_ << ":" << fileTouch_ << " FileDetail " << fileDetail_ + << "\n for " << names_.size() << " names:"; for (unsigned int i = 0; i < names_.size(); i++) G4cout << " " << names_[i]; G4cout << G4endl; @@ -433,10 +434,11 @@ void PrintGeomInfoAction::dumpInFile() { const G4MaterialTable *matTab = G4Material::GetMaterialTable(); std::ofstream fout(fileMat_.c_str()); for (std::vector::const_iterator matite = matTab->begin(); matite != matTab->end(); matite++) { - if (!fileDetail_) - fout << (*matite)->GetName() << "\n"; - else - fout << (*matite)->GetName() << " " << (*matite)->GetRadlen() << " " << (*matite)->GetNuclearInterLength() << "\n"; + if (!fileDetail_) + fout << (*matite)->GetName() << "\n"; + else + fout << (*matite)->GetName() << " " << (*matite)->GetRadlen() << " " << (*matite)->GetNuclearInterLength() + << "\n"; } fout.close(); } @@ -444,36 +446,38 @@ void PrintGeomInfoAction::dumpInFile() { if (!fileSolid_.empty()) { std::ofstream fout(fileSolid_.c_str()); for (std::vector::const_iterator lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) - if (!fileDetail_) - fout << (*lvcite)->GetSolid()->GetName() << "\n"; - else - fout << (*lvcite)->GetSolid()->GetName() << " " << (*lvcite)->GetSolid()->GetCubicVolume() << "\n"; + if (!fileDetail_) + fout << (*lvcite)->GetSolid()->GetName() << "\n"; + else + fout << (*lvcite)->GetSolid()->GetName() << " " << (*lvcite)->GetSolid()->GetCubicVolume() << "\n"; fout.close(); } if (!fileLV_.empty()) { std::ofstream fout(fileLV_.c_str()); for (std::vector::const_iterator lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) - if (!fileDetail_) - fout << (*lvcite)->GetName() << "\n"; - else - fout << (*lvcite)->GetName() << " " << (*lvcite)->GetMass(false,false) << "\n"; + if (!fileDetail_) + fout << (*lvcite)->GetName() << "\n"; + else + fout << (*lvcite)->GetName() << " " << (*lvcite)->GetMass(false, false) << "\n"; fout.close(); } if (!filePV_.empty()) { const G4PhysicalVolumeStore *pvs = G4PhysicalVolumeStore::GetInstance(); std::ofstream fout(filePV_.c_str()); for (std::vector::const_iterator pvcite = pvs->begin(); pvcite != pvs->end(); pvcite++) { - if (fileDetail_) { - if (dd4hep_) - fout << (*pvcite)->GetName() << " " << (*pvcite)->GetTranslation().x() << " " << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << "\n"; - else - fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << " " << (*pvcite)->GetTranslation().x() << " " << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << "\n"; - } else { - if (dd4hep_) - fout << (*pvcite)->GetName() << "\n"; - else - fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << "\n"; - } + if (fileDetail_) { + if (dd4hep_) + fout << (*pvcite)->GetName() << " " << (*pvcite)->GetTranslation().x() << " " + << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << "\n"; + else + fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << " " << (*pvcite)->GetTranslation().x() + << " " << (*pvcite)->GetTranslation().y() << " " << (*pvcite)->GetTranslation().z() << "\n"; + } else { + if (dd4hep_) + fout << (*pvcite)->GetName() << "\n"; + else + fout << (*pvcite)->GetName() << "_" << (*pvcite)->GetCopyNo() << "\n"; + } } fout.close(); } diff --git a/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp b/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp index a3511ef699216..818798aaa0fe1 100644 --- a/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp +++ b/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp @@ -94,7 +94,7 @@ std::vector splitString(const std::string& fLine) { for (unsigned i = 0; i <= fLine.size(); i++) { if (fLine[i] == ' ' || i == fLine.size()) { if (!empty) { - std::string item(fLine, start, i - start); + std::string item(fLine, start, i - start); result.push_back(item); empty = true; } @@ -142,33 +142,34 @@ void CompareFiles(const char* fileDDD, const char* fileDD4Hep, int type, int mod double r2 = (items.size() > 2) ? atof(items[2].c_str()) : 0; double r3 = (items.size() > 3) ? atof(items[3].c_str()) : 0; if (type == 0) { - auto it = matDDD.find(name); - if (it == matDDD.end()) - matDDD[name] = materials(1, r1, r2); - else - ++((it->second).occ); + auto it = matDDD.find(name); + if (it == matDDD.end()) + matDDD[name] = materials(1, r1, r2); + else + ++((it->second).occ); } else if (type == 1) { - auto it = solidDDD.find(name); - if (it == solidDDD.end()) - solidDDD[name] = solids(1, r1); - else - ++((it->second).occ); + auto it = solidDDD.find(name); + if (it == solidDDD.end()) + solidDDD[name] = solids(1, r1); + else + ++((it->second).occ); } else if (type == 2) { - auto it = lvDDD.find(name); - if (it == lvDDD.end()) - lvDDD[name] = lvs(1, r1); - else - ++((it->second).occ); + auto it = lvDDD.find(name); + if (it == lvDDD.end()) + lvDDD[name] = lvs(1, r1); + else + ++((it->second).occ); } else { - auto it = pvDDD.find(name); - if (it == pvDDD.end()) - pvDDD[name] = pvs(1, r1, r2, r3); - else - ++((it->second).occ); + auto it = pvDDD.find(name); + if (it == pvDDD.end()) + pvDDD[name] = pvs(1, r1, r2, r3); + else + ++((it->second).occ); } } fInput1.close(); - sizeDDD = ((type == 0) ? matDDD.size() : ((type == 1) ? solidDDD.size() : ((type == 2) ? lvDDD.size() : pvDDD.size()))); + sizeDDD = + ((type == 0) ? matDDD.size() : ((type == 1) ? solidDDD.size() : ((type == 2) ? lvDDD.size() : pvDDD.size()))); } std::ifstream fInput2(fileDD4Hep); if (!fInput2.good()) { @@ -181,78 +182,80 @@ void CompareFiles(const char* fileDDD, const char* fileDD4Hep, int type, int mod double r2 = (items.size() > 2) ? atof(items[2].c_str()) : 0; double r3 = (items.size() > 3) ? atof(items[3].c_str()) : 0; if (type == 0) { - auto it = matDD4Hep.find(name); - if (it == matDD4Hep.end()) - matDD4Hep[name] = materials(1, r1, r2); - else - ++((it->second).occ); + auto it = matDD4Hep.find(name); + if (it == matDD4Hep.end()) + matDD4Hep[name] = materials(1, r1, r2); + else + ++((it->second).occ); } else if (type == 1) { - auto it = solidDD4Hep.find(name); - if (it == solidDD4Hep.end()) - solidDD4Hep[name] = solids(1, r1); - else - ++((it->second).occ); + auto it = solidDD4Hep.find(name); + if (it == solidDD4Hep.end()) + solidDD4Hep[name] = solids(1, r1); + else + ++((it->second).occ); } else if (type == 2) { - auto it = lvDD4Hep.find(name); - if (it == lvDD4Hep.end()) - lvDD4Hep[name] = lvs(1, r1); - else - ++((it->second).occ); + auto it = lvDD4Hep.find(name); + if (it == lvDD4Hep.end()) + lvDD4Hep[name] = lvs(1, r1); + else + ++((it->second).occ); } else { - auto it = pvDD4Hep.find(name); - if (it == pvDD4Hep.end()) - pvDD4Hep[name] = pvs(1, r1, r2, r3); - else - ++((it->second).occ); + auto it = pvDD4Hep.find(name); + if (it == pvDD4Hep.end()) + pvDD4Hep[name] = pvs(1, r1, r2, r3); + else + ++((it->second).occ); } } fInput2.close(); - sizeDD4Hep = ((type == 0) ? matDD4Hep.size() : ((type == 1) ? solidDD4Hep.size() : ((type == 2) ? lvDD4Hep.size() : pvDD4Hep.size()))); + sizeDD4Hep = ((type == 0) ? matDD4Hep.size() + : ((type == 1) ? solidDD4Hep.size() : ((type == 2) ? lvDD4Hep.size() : pvDD4Hep.size()))); } - std::cout << "Reads " << sizeDDD << " names from " << fileDDD << " and " << sizeDD4Hep << " names from " << fileDD4Hep << std::endl; + std::cout << "Reads " << sizeDDD << " names from " << fileDDD << " and " << sizeDD4Hep << " names from " << fileDD4Hep + << std::endl; std::cout << "\nMore than one entry for a given name in " << fileDDD << std::endl; if (type == 0) { - myPrint1 (matDDD); + myPrint1(matDDD); } else if (type == 1) { - myPrint1 (solidDDD); + myPrint1(solidDDD); } else if (type == 2) { - myPrint1 (lvDDD); + myPrint1(lvDDD); } else { - myPrint1 (pvDDD); + myPrint1(pvDDD); } std::cout << "\nMore than one entry for a given name in " << fileDD4Hep << std::endl; if (type == 0) { - myPrint1 (matDD4Hep); + myPrint1(matDD4Hep); } else if (type == 1) { - myPrint1 (solidDD4Hep); + myPrint1(solidDD4Hep); } else if (type == 2) { - myPrint1 (lvDD4Hep); + myPrint1(lvDD4Hep); } else { - myPrint1 (pvDD4Hep); + myPrint1(pvDD4Hep); } std::cout << "\nEntry in " << fileDDD << " not in " << fileDD4Hep << std::endl; if (type == 0) { - myPrint2 (matDDD, matDD4Hep); + myPrint2(matDDD, matDD4Hep); } else if (type == 1) { - myPrint2 (solidDDD, solidDD4Hep); + myPrint2(solidDDD, solidDD4Hep); } else if (type == 2) { - myPrint2 (lvDDD, lvDD4Hep); + myPrint2(lvDDD, lvDD4Hep); } else { - myPrint2 (pvDDD, pvDD4Hep); + myPrint2(pvDDD, pvDD4Hep); } std::cout << "\nEntry in " << fileDD4Hep << " not in " << fileDDD << std::endl; if (type == 0) { - myPrint2 (matDD4Hep, matDDD); + myPrint2(matDD4Hep, matDDD); } else if (type == 1) { - myPrint2 (solidDD4Hep, solidDDD); + myPrint2(solidDD4Hep, solidDDD); } else if (type == 2) { - myPrint2 (lvDD4Hep, lvDDD); + myPrint2(lvDD4Hep, lvDDD); } else { - myPrint2 (pvDD4Hep, pvDDD); + myPrint2(pvDD4Hep, pvDDD); } //Now type specific changes @@ -264,60 +267,72 @@ void CompareFiles(const char* fileDDD, const char* fileDD4Hep, int type, int mod for (auto it1 : matDDD) { auto it2 = matDD4Hep.find(it1.first); if (it2 != matDD4Hep.end()) { - ++kount1; - double rdif = 0.5 * (it1.second.radl - it2->second.radl) / std::max(denmin, (it1.second.radl + it2->second.radl)); - double idif = 0.5 * (it1.second.intl - it2->second.intl) / std::max(denmin, (it1.second.intl + it2->second.intl)); - if ((std::abs(rdif) > tol1) || (std::abs(idif) > tol1)) { - ++kount2; - std::cout << it1.first << " Radiation Length " << it1.second.radl << ":" << it2->second.radl << ":" << rdif << " Interaction Length " << it1.second.intl << ":" << it2->second.intl << ":" << idif << std::endl; - } + ++kount1; + double rdif = + 0.5 * (it1.second.radl - it2->second.radl) / std::max(denmin, (it1.second.radl + it2->second.radl)); + double idif = + 0.5 * (it1.second.intl - it2->second.intl) / std::max(denmin, (it1.second.intl + it2->second.intl)); + if ((std::abs(rdif) > tol1) || (std::abs(idif) > tol1)) { + ++kount2; + std::cout << it1.first << " Radiation Length " << it1.second.radl << ":" << it2->second.radl << ":" << rdif + << " Interaction Length " << it1.second.intl << ":" << it2->second.intl << ":" << idif << std::endl; + } } } - std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol1 << " or more\n"; + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol1 + << " or more\n"; } else if (type == 1) { const double tol2 = 0.0001; for (auto it1 : solidDDD) { auto it2 = solidDD4Hep.find(it1.first); if (it2 != solidDD4Hep.end()) { - ++kount1; - double vdif = 0.5 * (it1.second.volume - it2->second.volume) / std::max(denmin, (it1.second.volume + it2->second.volume)); - if (std::abs(vdif) > tol2) { - ++kount2; - std::cout << it1.first << " Volume " << it1.second.volume << ":" << it2->second.volume << ":" << vdif << std::endl; - } + ++kount1; + double vdif = + 0.5 * (it1.second.volume - it2->second.volume) / std::max(denmin, (it1.second.volume + it2->second.volume)); + if (std::abs(vdif) > tol2) { + ++kount2; + std::cout << it1.first << " Volume " << it1.second.volume << ":" << it2->second.volume << ":" << vdif + << std::endl; + } } } - std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol2 << " or more\n"; + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol2 + << " or more\n"; } else if (type == 2) { const double tol3 = 0.0001; for (auto it1 : lvDDD) { auto it2 = lvDD4Hep.find(it1.first); if (it2 != lvDD4Hep.end()) { - ++kount1; - double vdif = 0.5 * (it1.second.mass - it2->second.mass) / std::max(denmin, (it1.second.mass + it2->second.mass)); - if (std::abs(vdif) > tol3) { - ++kount2; - std::cout << it1.first << " Mass " << it1.second.mass << ":" << it2->second.mass << ":" << vdif << std::endl; - } + ++kount1; + double vdif = + 0.5 * (it1.second.mass - it2->second.mass) / std::max(denmin, (it1.second.mass + it2->second.mass)); + if (std::abs(vdif) > tol3) { + ++kount2; + std::cout << it1.first << " Mass " << it1.second.mass << ":" << it2->second.mass << ":" << vdif << std::endl; + } } } - std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol3 << " or more\n"; + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol3 + << " or more\n"; } else { const double tol4 = 0.0001; for (auto it1 : pvDDD) { auto it2 = pvDD4Hep.find(it1.first); if (it2 != pvDD4Hep.end()) { - ++kount1; - double xdif = (it1.second.xx - it2->second.xx); - double ydif = (it1.second.yy - it2->second.yy); - double zdif = (it1.second.zz - it2->second.zz); - if ((std::abs(xdif) > tol4) || (std::abs(ydif) > tol4) || (std::abs(zdif) > tol4)) { - ++kount2; - std::cout << it1.first << " x " << it1.second.xx << ":" << it2->second.xx << ":" << xdif << " y " << it1.second.yy << ":" << it2->second.yy << ":" << ydif << " z " << it1.second.zz << ":" << it2->second.zz << ":" << zdif << std::endl; - } + ++kount1; + double xdif = (it1.second.xx - it2->second.xx); + double ydif = (it1.second.yy - it2->second.yy); + double zdif = (it1.second.zz - it2->second.zz); + if ((std::abs(xdif) > tol4) || (std::abs(ydif) > tol4) || (std::abs(zdif) > tol4)) { + ++kount2; + std::cout << it1.first << " x " << it1.second.xx << ":" << it2->second.xx << ":" << xdif << " y " + << it1.second.yy << ":" << it2->second.yy << ":" << ydif << " z " << it1.second.zz << ":" + << it2->second.zz << ":" << zdif << std::endl; + } } } - std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol4 << " or more\n"; + std::cout << "\n " << kount2 << " out of " << kount1 << " entries having discrpancies at the level of " << tol4 + << " or more\n"; } } @@ -326,7 +341,7 @@ int main(int argc, char* argv[]) { std::cout << "Please give a minimum of 2 arguments \n" << "input file name from the DDD run\n" << "input file name from the DD4Hep run\n" - << "type (Material:0, Solid:1, LV:2, PV:3\n" + << "type (Material:0, Solid:1, LV:2, PV:3\n" << "mode (treat the name for DDD or not == needed for PV)\n" << "debug flag (0 for minimum printout)\n" << std::endl; @@ -336,7 +351,8 @@ int main(int argc, char* argv[]) { const char* infile1 = argv[1]; const char* infile2 = argv[2]; int type = ((argc > 3) ? atoi(argv[3]) : 0); - if (type < 0 || type > 3) type = 0; + if (type < 0 || type > 3) + type = 0; int mode = ((argc > 4) ? atoi(argv[4]) : 0); int debug = ((argc > 5) ? atoi(argv[5]) : 0); CompareFiles(infile1, infile2, type, mode, debug); From ab76b8f66281805cc7427bded8460fbd5d728bed Mon Sep 17 00:00:00 2001 From: Sunanda Date: Fri, 16 Apr 2021 12:04:58 +0200 Subject: [PATCH 3/3] CLANG test --- SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp b/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp index 818798aaa0fe1..5949933d170e1 100644 --- a/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp +++ b/SimG4Core/PrintGeomInfo/test/SimFileCompare.cpp @@ -131,7 +131,7 @@ void CompareFiles(const char* fileDDD, const char* fileDD4Hep, int type, int mod char buffer[100]; std::string name; std::ifstream fInput1(fileDDD); - unsigned int sizeDDD, sizeDD4Hep; + unsigned int sizeDDD(0), sizeDD4Hep(0); if (!fInput1.good()) { std::cout << "Cannot open file " << fileDDD << std::endl; } else {