File indexing completed on 2024-04-06 12:14:50
0001 #include "DetectorDescription/Core/interface/DDFilter.h"
0002 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0003 #include "DetectorDescription/Core/interface/DDMaterial.h"
0004 #include "DetectorDescription/Core/interface/DDSplit.h"
0005 #include "DetectorDescription/Core/interface/DDValue.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "Geometry/HcalTestBeamData/interface/HcalTB06BeamParametersFromDD.h"
0009
0010 bool HcalTB06BeamParametersFromDD::build(const DDCompactView* cpv,
0011 HcalTB06BeamParameters& php,
0012 const std::string& name1,
0013 const std::string& name2) {
0014 DDSpecificsMatchesValueFilter filter1{DDValue("Volume", name1, 0)};
0015 DDFilteredView fv1(*cpv, filter1);
0016 php.wchambers_ = getNames(fv1);
0017
0018 DDSpecificsMatchesValueFilter filter2{DDValue("ReadOutName", name2, 0)};
0019 DDFilteredView fv2(*cpv, filter2);
0020 bool dodet = fv2.firstChild();
0021 std::vector<std::string> matNames;
0022 std::vector<int> nocc;
0023 while (dodet) {
0024 std::string matName = fv2.logicalPart().material().name().name();
0025 bool notIn = true;
0026 for (unsigned int i = 0; i < matNames.size(); i++) {
0027 if (matName == matNames[i]) {
0028 notIn = false;
0029 nocc[i]++;
0030 }
0031 }
0032 if (notIn) {
0033 matNames.push_back(matName);
0034 nocc.push_back(0);
0035 }
0036 dodet = fv2.next();
0037 }
0038 return build(php, matNames, nocc, name1, name2);
0039 }
0040
0041 bool HcalTB06BeamParametersFromDD::build(const cms::DDCompactView* cpv,
0042 HcalTB06BeamParameters& php,
0043 const std::string& name1,
0044 const std::string& name2) {
0045 const cms::DDFilter filter1("Volume", name1);
0046 cms::DDFilteredView fv1(*cpv, filter1);
0047 php.wchambers_ = getNames(fv1);
0048
0049 const cms::DDFilter filter2("ReadOutName", name2);
0050 cms::DDFilteredView fv2(*cpv, filter2);
0051 std::vector<std::string> matNames;
0052 std::vector<int> nocc;
0053 while (fv2.firstChild()) {
0054 std::string matName = static_cast<std::string>(dd4hep::dd::noNamespace(fv2.materialName()));
0055 ;
0056 bool notIn = true;
0057 for (unsigned int i = 0; i < matNames.size(); i++) {
0058 if (matName == matNames[i]) {
0059 notIn = false;
0060 nocc[i]++;
0061 }
0062 }
0063 if (notIn) {
0064 matNames.push_back(matName);
0065 nocc.push_back(0);
0066 }
0067 }
0068 return build(php, matNames, nocc, name1, name2);
0069 }
0070
0071 bool HcalTB06BeamParametersFromDD::build(HcalTB06BeamParameters& php,
0072 const std::vector<std::string>& matNames,
0073 const std::vector<int>& nocc,
0074 #ifdef EDM_ML_DEBUG
0075 const std::string& name1,
0076 const std::string& name2) {
0077 edm::LogVerbatim("HcalTBSim") << "HcalTB06BeamParametersFromDD:: Names to be tested for Volume = " << name1 << ": "
0078 << php.wchambers_.size() << " paths";
0079 for (unsigned int i = 0; i < php.wchambers_.size(); i++)
0080 edm::LogVerbatim("HcalTBSim") << "HcalTB06BeamParametersFromDD:: (" << i << ") " << php.wchambers_[i];
0081 #else
0082 const std::string&,
0083 const std::string&) {
0084 #endif
0085
0086 if (!matNames.empty()) {
0087 php.material_ = matNames[0];
0088 int occ = nocc[0];
0089 for (unsigned int i = 0; i < matNames.size(); i++) {
0090 if (nocc[i] > occ) {
0091 occ = nocc[i];
0092 php.material_ = matNames[i];
0093 }
0094 }
0095 } else {
0096 php.material_ = "Not Found";
0097 }
0098 #ifdef EDM_ML_DEBUG
0099 edm::LogVerbatim("HcalTBSim") << "HcalTB06BeamParametersFromDD: finds " << matNames.size() << " materials for "
0100 << name2;
0101 for (unsigned k = 0; k < matNames.size(); ++k)
0102 edm::LogVerbatim("HcalTBSim") << "[" << k << "] " << matNames[k] << " " << nocc[k];
0103 edm::LogVerbatim("HcalTBSim") << "HcalTB06BeamParametersFromDD: Material name for ReadOut = " << name2 << ":"
0104 << php.material_;
0105 #endif
0106 return true;
0107 }
0108
0109 std::vector<std::string> HcalTB06BeamParametersFromDD::getNames(DDFilteredView& fv) {
0110 std::vector<std::string> tmp;
0111 bool dodet = fv.firstChild();
0112 while (dodet) {
0113 const DDLogicalPart& log = fv.logicalPart();
0114 bool ok = true;
0115 for (unsigned int i = 0; i < tmp.size(); i++) {
0116 if (!strcmp(tmp[i].c_str(), log.name().name().c_str())) {
0117 ok = false;
0118 break;
0119 }
0120 }
0121 if (ok)
0122 tmp.push_back(log.name().name());
0123 dodet = fv.next();
0124 }
0125 return tmp;
0126 }
0127
0128 std::vector<std::string> HcalTB06BeamParametersFromDD::getNames(cms::DDFilteredView& fv) {
0129 std::vector<std::string> tmp;
0130 while (fv.firstChild()) {
0131 std::string name = static_cast<std::string>(dd4hep::dd::noNamespace(fv.name()));
0132 if (std::find(std::begin(tmp), std::end(tmp), name) == std::end(tmp))
0133 tmp.emplace_back(name);
0134 }
0135 return tmp;
0136 }