Skip to content

Commit

Permalink
remove the need for an evaluator beyond geometry construction
Browse files Browse the repository at this point in the history
  • Loading branch information
ianna committed Nov 30, 2020
1 parent 443bc36 commit 8fe826b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 282 deletions.
Expand Up @@ -402,7 +402,7 @@ void Converter<DDLConstant>::operator()(xml_h element) const {
DDRegistry* res = _option<DDRegistry>();
xml_dim_t constant = element;
xml_dim_t par = constant.parent();
bool eval = par.hasAttr(_U(eval)) ? par.attr<bool>(_U(eval)) : false;
bool eval = par.hasAttr(_U(eval)) ? par.attr<bool>(_U(eval)) : true;
string val = constant.valueStr();
string nam = constant.nameStr();
string real = ns.prepend(nam);
Expand Down Expand Up @@ -1003,6 +1003,10 @@ void Converter<Parameter>::operator()(xml_h element) const {
#endif

size_t idx = value.find('[');
if (idx == string::npos && type == "number") {
registry.specpars[specParName].numpars[name].emplace_back(dd4hep::_toDouble(value));
return;
}
if (idx == string::npos || type == "string") {
registry.specpars[specParName].spars[name].emplace_back(std::move(value));
return;
Expand Down
13 changes: 13 additions & 0 deletions DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc
Expand Up @@ -12,6 +12,12 @@ using namespace std;
using namespace cms;
using namespace edm;

#ifdef HAVE_GEANT4_UNITS
#define MM_2_CM 1.0
#else
#define MM_2_CM 0.1
#endif

class DDTestSpecParsFilter : public one::EDAnalyzer<> {
public:
explicit DDTestSpecParsFilter(const ParameterSet& iConfig)
Expand Down Expand Up @@ -62,6 +68,13 @@ void DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup)
}
log << "\n ";
}
for (const auto& kl : t.second->numpars) {
log << kl.first << " = ";
for (const auto& kil : kl.second) {
log << kil / MM_2_CM << " ";
}
log << "\n ";
}
}
});
std::cout << "*** Check names in a path after filtering:\n";
Expand Down
5 changes: 1 addition & 4 deletions DetectorDescription/DDCMS/src/DDFilteredView.cc
Expand Up @@ -841,10 +841,7 @@ double DDFilteredView::getNextValue(const std::string& key) const {
double result(0.0);

if (currentSpecPar_ != nullptr) {
std::string_view svalue = currentSpecPar_->strValue(key);
if (!svalue.empty()) {
result = dd4hep::_toDouble({svalue.data(), svalue.size()});
} else if (currentSpecPar_->hasValue(key)) {
if (currentSpecPar_->hasValue(key)) {
auto const& nitem = currentSpecPar_->numpars.find(key);
if (nitem != end(currentSpecPar_->numpars)) {
result = nitem->second[0];
Expand Down
Expand Up @@ -63,6 +63,7 @@ std::unique_ptr<GeometricDet> DDDCmsTrackerContruction::construct(const cms::DDC
std::vector<int> const& detidShifts) {
std::string attribute("TkDDDStructure");
cms::DDFilteredView fv(cpv, cms::DDFilter(attribute));
fv.firstChild();

CmsTrackerStringToEnum theCmsTrackerStringToEnum;
if (theCmsTrackerStringToEnum.type(ExtractStringFromDDD<cms::DDFilteredView>::getString("TkDDDStructure", &fv)) !=
Expand Down
47 changes: 23 additions & 24 deletions SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc
Expand Up @@ -28,7 +28,12 @@ using namespace std;
using namespace cms;
using namespace edm;
using namespace dd4hep;
using geant_units::operators::convertCmToMm;

#ifdef HAVE_GEANT4_UNITS
#define MM_2_CM 1.0
#else
#define MM_2_CM 0.1
#endif

namespace {
bool sortByName(const std::pair<G4LogicalVolume*, const dd4hep::SpecPar*>& p1,
Expand Down Expand Up @@ -108,13 +113,17 @@ void DD4hepTestDDDWorld::initialize(const dd4hep::sim::Geant4GeometryMaps::Volum
LogVerbatim("Geometry").log([&](auto& log) {
for (auto const& it : vmap) {
for (auto const& fit : specs_) {
for (auto const& sit : fit.second->spars) {
for (auto const& sit : fit.second->numpars) {
log << sit.first << " = " << sit.second[0] << "\n";
}
for (auto const& pit : fit.second->paths) {
log << dd4hep::dd::realTopName(pit) << "\n";
log << " compare equal to " << dd4hep::dd::noNamespace(it.first.name()) << " ... ";
if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) {
const std::string_view selection = dd4hep::dd::realTopName(pit);
const std::string_view name = dd4hep::dd::noNamespace(it.first.name());
log << selection << "\n";
log << " compare equal to " << name << " ... ";
if (!(dd4hep::dd::isRegex(selection))
? dd4hep::dd::compareEqual(name, selection)
: regex_match(name.begin(), name.end(), regex(std::string(selection)))) {
vec_.emplace_back(std::make_pair<G4LogicalVolume*, const dd4hep::SpecPar*>(&*it.second, &*fit.second));
log << " are equal!\n";
} else
Expand Down Expand Up @@ -142,7 +151,7 @@ void DD4hepTestDDDWorld::update() {
log << "DD4hepTestDDDWorld::update()\n";
for (const auto& t : vec_) {
log << t.first->GetName() << ":\n";
for (const auto& kl : t.second->spars) {
for (const auto& kl : t.second->numpars) {
log << kl.first << " = ";
for (const auto& kil : kl.second) {
log << kil << ", ";
Expand All @@ -161,24 +170,16 @@ void DD4hepTestDDDWorld::update() {
// search for production cuts
// you must have four of them: e+ e- gamma proton
//
auto gammacutStr = it.second->strValue("ProdCutsForGamma");

// Geant4 expects mm units. DD4hep returns cm, so must convert to mm.
double gammacut = convertCmToMm(dd4hep::_toDouble({gammacutStr.data(), gammacutStr.size()}));

auto electroncutStr = it.second->strValue("ProdCutsForElectrons");
double electroncut = convertCmToMm(dd4hep::_toDouble({electroncutStr.data(), electroncutStr.size()}));

auto positroncutStr = it.second->strValue("ProdCutsForPositrons");
double positroncut = convertCmToMm(dd4hep::_toDouble({positroncutStr.data(), positroncutStr.size()}));

double protoncut = 0.0;
auto protoncutStr = it.second->strValue("ProdCutsForProtons");
if (it.second->hasValue("ProdCutsForProtons")) {
protoncut = convertCmToMm(dd4hep::_toDouble({protoncutStr.data(), protoncutStr.size()}));
} else {
double gammacut = it.second->dblValue("ProdCutsForGamma") / MM_2_CM;
double electroncut = it.second->dblValue("ProdCutsForElectrons") / MM_2_CM;
double positroncut = it.second->dblValue("ProdCutsForPositrons") / MM_2_CM;
double protoncut = it.second->dblValue("ProdCutsForProtons") / MM_2_CM;
if (protoncut == 0) {
protoncut = electroncut;
}

//
// For the moment I assume all of the four are set
//
Expand All @@ -189,10 +190,8 @@ void DD4hepTestDDDWorld::update() {
prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
if (verbosity_ > 0) {
LogVerbatim("Geometry") << "DDG4ProductionCuts : Setting cuts for " << regName
<< "\n Electrons: " << electroncutStr << " (" << electroncut
<< ")\n Positrons: " << positroncutStr << " (" << positroncut
<< ")\n Gamma : " << gammacutStr << " (" << gammacut
<< ")\n Protons : " << protoncutStr << " (" << protoncut << ")\n";
<< "\n Electrons: " << electroncut << " mm\n Positrons: " << positroncut
<< " mm\n Gamma : " << gammacut << " mm\n Protons : " << protoncut << " mm\n";
}
}
}
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions SimG4Core/DD4hepGeometry/test/runTest.sh
Expand Up @@ -4,7 +4,6 @@ function die { echo $1: status $2 ; exit $2; }

F1=${LOCAL_TEST_DIR}/python/testG4Geometry.py
F2=${LOCAL_TEST_DIR}/python/testG4Regions.py
F3=${LOCAL_TEST_DIR}/python/testZMM_13TeV_TuneCUETP8M1_cfi_GEN_SIM.py

echo " testing SimG4Core/DD4hepGeometry"

Expand All @@ -13,5 +12,3 @@ echo "===== Test \"cmsRun testG4Geometry.py\" ===="
(cmsRun $F1) || die "Failure using cmsRun $F1" $?
echo "===== Test \"cmsRun testG4Regions.py\" ===="
(cmsRun $F2) || die "Failure using cmsRun $F2" $?
echo "===== Test \"cmsRun testZMM_13TeV_TuneCUETP8M1_cfi_GEN_SIM.py\" ===="
######## FIXME: (cmsRun $F3) || die "Failure using cmsRun $F3" $?

0 comments on commit 8fe826b

Please sign in to comment.