File indexing completed on 2024-04-06 12:15:18
0001 #include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
0002 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0003 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005
0006
0007
0008 MuonGeometryNumbering::MuonGeometryNumbering(const MuonGeometryConstants &muonConstants) {
0009
0010 theLevelPart = muonConstants.getValue("level");
0011 theSuperPart = muonConstants.getValue("super");
0012 theBasePart = muonConstants.getValue("base");
0013 theStartCopyNo = muonConstants.getValue("xml_starts_with_copyno");
0014
0015
0016
0017 if (theBasePart != 1) {
0018 edm::LogWarning("MuonGeom") << "MuonGeometryNumbering finds unusual base constant:" << theBasePart;
0019 }
0020 if (theSuperPart < 100) {
0021 edm::LogWarning("MuonGeom") << "MuonGeometryNumbering finds unusual super constant:" << theSuperPart;
0022 }
0023 if (theLevelPart < 10 * theSuperPart) {
0024 edm::LogWarning("MuonGeom") << "MuonGeometryNumbering finds unusual level constant:" << theLevelPart;
0025 }
0026 if ((theStartCopyNo != 0) && (theStartCopyNo != 1)) {
0027 edm::LogWarning("MuonGeom") << "MuonGeometryNumbering finds unusual start value for copy numbers:"
0028 << theStartCopyNo;
0029 }
0030
0031 #ifdef EDM_ML_DEBUG
0032 edm::LogVerbatim("MuonGeom") << "MuonGeometryNumbering configured with"
0033 << " Level = " << theLevelPart << " Super = " << theSuperPart
0034 << " Base = " << theBasePart << " StartCopyNo = " << theStartCopyNo;
0035 #endif
0036 }
0037
0038 MuonBaseNumber MuonGeometryNumbering::geoHistoryToBaseNumber(const DDGeoHistory &history) const {
0039 MuonBaseNumber num;
0040
0041 #ifdef EDM_ML_DEBUG
0042 edm::LogVerbatim("MuonGeom") << "MuonGeometryNumbering create MuonBaseNumber for " << history;
0043 #endif
0044
0045
0046 DDGeoHistory::const_iterator cur = history.begin();
0047 DDGeoHistory::const_iterator end = history.end();
0048 while (cur != end) {
0049 const DDLogicalPart &ddlp = cur->logicalPart();
0050 const int tag = getInt("CopyNoTag", ddlp) / theLevelPart;
0051 if (tag > 0) {
0052 const int offset = getInt("CopyNoOffset", ddlp);
0053 const int copyno = (cur->copyno()) + offset % theSuperPart;
0054 const int super = offset / theSuperPart;
0055 num.addBase(tag, super, copyno - theStartCopyNo);
0056 }
0057 cur++;
0058 }
0059
0060 #ifdef EDM_ML_DEBUG
0061 edm::LogVerbatim("MuonGeom") << "MuonGeometryNumbering::" << num.getLevels();
0062 for (int i = 1; i <= num.getLevels(); i++) {
0063 edm::LogVerbatim("MuonGeom") << "[" << i << "] " << num.getSuperNo(i) << " " << num.getBaseNo(i);
0064 }
0065 #endif
0066
0067 return num;
0068 }
0069
0070 MuonBaseNumber MuonGeometryNumbering::geoHistoryToBaseNumber(const cms::ExpandedNodes &nodes) const {
0071 MuonBaseNumber num;
0072
0073 int ctr(0);
0074 for (auto const &it : nodes.tags) {
0075 int tag = it / theLevelPart;
0076 if (tag > 0) {
0077 int offset = nodes.offsets[ctr];
0078 int copyno = nodes.copyNos[ctr] + offset % theSuperPart;
0079 int super = offset / theSuperPart;
0080 num.addBase(tag, super, copyno - theStartCopyNo);
0081 }
0082 ++ctr;
0083 }
0084 return num;
0085 }
0086
0087 int MuonGeometryNumbering::getInt(const std::string &s, const DDLogicalPart &part) const {
0088 DDValue val(s);
0089 std::vector<const DDsvalues_type *> result = part.specifics();
0090 std::vector<const DDsvalues_type *>::iterator it = result.begin();
0091 bool foundIt = false;
0092 for (; it != result.end(); ++it) {
0093 foundIt = DDfetch(*it, val);
0094 if (foundIt)
0095 break;
0096 }
0097 if (foundIt) {
0098 std::vector<double> temp = val.doubles();
0099 if (temp.size() != 1) {
0100 edm::LogError("MuonGeom") << "MuonGeometryNumbering:: ERROR: I need only 1 " << s << " in DDLogicalPart "
0101 << part.name();
0102 abort();
0103 }
0104 return int(temp[0]);
0105 } else
0106 return 0;
0107 }