File indexing completed on 2023-10-25 09:32:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012
0013 #include "Alignment/CommonAlignment/interface/Alignable.h"
0014 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0015 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
0016 #include "Alignment/CommonAlignment/interface/AlignableExtras.h"
0017 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
0018
0019 #include "PedeLabeler.h"
0020
0021
0022 PedeLabeler::PedeLabeler(const PedeLabelerBase::TopLevelAlignables& alignables, const edm::ParameterSet& config)
0023 : PedeLabelerBase(alignables, config) {
0024 align::Alignables alis;
0025 alis.push_back(alignables.aliTracker_);
0026 alis.push_back(alignables.aliMuon_);
0027
0028 if (alignables.aliExtras_) {
0029 for (const auto& ali : alignables.aliExtras_->components()) {
0030 alis.push_back(ali);
0031 }
0032 }
0033
0034 this->buildMap(alis);
0035 this->buildReverseMap();
0036 }
0037
0038
0039 PedeLabeler::~PedeLabeler() {}
0040
0041
0042
0043 unsigned int PedeLabeler::alignableLabel(const Alignable* alignable) const {
0044 if (!alignable)
0045 return 0;
0046
0047 AlignableToIdMap::const_iterator position = theAlignableToIdMap.find(alignable);
0048 if (position != theAlignableToIdMap.end()) {
0049 return position->second;
0050 } else {
0051 const DetId detId(alignable->id());
0052
0053 edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableLabel"
0054 << "Alignable " << typeid(*alignable).name()
0055 << " not in map, det/subdet/alignableStructureType = " << detId.det() << "/"
0056 << detId.subdetId() << "/" << alignable->alignableObjectId();
0057 return 0;
0058 }
0059 }
0060
0061
0062
0063 unsigned int PedeLabeler::alignableLabelFromParamAndInstance(const Alignable* alignable,
0064 unsigned int ,
0065 unsigned int ) const {
0066 return this->alignableLabel(alignable);
0067 }
0068
0069
0070 unsigned int PedeLabeler::lasBeamLabel(unsigned int lasBeamId) const {
0071 UintUintMap::const_iterator position = theLasBeamToLabelMap.find(lasBeamId);
0072 if (position != theLasBeamToLabelMap.end()) {
0073 return position->second;
0074 } else {
0075
0076 edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamLabel"
0077 << "No label for beam Id " << lasBeamId;
0078 return 0;
0079 }
0080 }
0081
0082
0083 unsigned int PedeLabeler::parameterLabel(unsigned int aliLabel, unsigned int parNum) const {
0084 if (parNum >= theMaxNumParam) {
0085 throw cms::Exception("Alignment") << "@SUB=PedeLabeler::parameterLabel"
0086 << "Parameter number " << parNum << " out of range 0 <= num < " << theMaxNumParam;
0087 }
0088 return aliLabel + parNum;
0089 }
0090
0091
0092 unsigned int PedeLabeler::paramNumFromLabel(unsigned int paramLabel) const {
0093 if (paramLabel < theMinLabel) {
0094 edm::LogError("LogicError") << "@SUB=PedeLabeler::paramNumFromLabel"
0095 << "Label " << paramLabel << " should be >= " << theMinLabel;
0096 return 0;
0097 }
0098 return (paramLabel - theMinLabel) % theMaxNumParam;
0099 }
0100
0101
0102 unsigned int PedeLabeler::alignableLabelFromLabel(unsigned int paramLabel) const {
0103 return paramLabel - this->paramNumFromLabel(paramLabel);
0104 }
0105
0106
0107 Alignable* PedeLabeler::alignableFromLabel(unsigned int label) const {
0108 const unsigned int aliLabel = this->alignableLabelFromLabel(label);
0109 if (aliLabel < theMinLabel)
0110 return nullptr;
0111
0112 IdToAlignableMap::const_iterator position = theIdToAlignableMap.find(aliLabel);
0113 if (position != theIdToAlignableMap.end()) {
0114 return position->second;
0115 } else {
0116
0117 UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
0118 if (position == theLabelToLasBeamMap.end()) {
0119 edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableFromLabel"
0120 << "Alignable label " << aliLabel << " not in map.";
0121 }
0122 return nullptr;
0123 }
0124 }
0125
0126
0127 unsigned int PedeLabeler::lasBeamIdFromLabel(unsigned int label) const {
0128 const unsigned int aliLabel = this->alignableLabelFromLabel(label);
0129 if (aliLabel < theMinLabel)
0130 return 0;
0131
0132 UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
0133 if (position != theLabelToLasBeamMap.end()) {
0134 return position->second;
0135 } else {
0136 edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamIdFromLabel"
0137 << "Alignable label " << aliLabel << " not in map.";
0138 return 0;
0139 }
0140 }
0141
0142
0143 unsigned int PedeLabeler::buildMap(const align::Alignables& alis) {
0144 theAlignableToIdMap.clear();
0145
0146 align::Alignables allComps;
0147
0148 for (const auto& iAli : alis) {
0149 if (iAli) {
0150 allComps.push_back(iAli);
0151 iAli->recursiveComponents(allComps);
0152 }
0153 }
0154
0155 unsigned int id = theMinLabel;
0156 for (const auto& iter : allComps) {
0157 theAlignableToIdMap.insert(AlignableToIdPair(iter, id));
0158 id += theMaxNumParam;
0159 }
0160
0161
0162 theLasBeamToLabelMap.clear();
0163
0164
0165 unsigned int beamIds[] = {0, 10, 20, 30, 40, 50, 60, 70,
0166 1, 11, 21, 31, 41, 51, 61, 71,
0167 100, 110, 120, 130, 140, 150, 160, 170,
0168 101, 111, 121, 131, 141, 151, 161, 171,
0169 200, 210, 220, 230, 240, 250, 260, 270};
0170
0171 const size_t nBeams = sizeof(beamIds) / sizeof(beamIds[0]);
0172 for (size_t iBeam = 0; iBeam < nBeams; ++iBeam) {
0173
0174 theLasBeamToLabelMap[beamIds[iBeam]] = id;
0175 id += theMaxNumParam;
0176 }
0177
0178
0179 return theAlignableToIdMap.size() + theLasBeamToLabelMap.size();
0180 }
0181
0182
0183 unsigned int PedeLabeler::buildReverseMap() {
0184
0185 theIdToAlignableMap.clear();
0186
0187 for (const auto& it : theAlignableToIdMap) {
0188 theIdToAlignableMap[it.second] = it.first;
0189 }
0190
0191
0192 theLabelToLasBeamMap.clear();
0193
0194 for (const auto& it : theLasBeamToLabelMap) {
0195 theLabelToLasBeamMap[it.second] = it.first;
0196 }
0197
0198
0199 return theIdToAlignableMap.size() + theLabelToLasBeamMap.size();
0200 }
0201
0202 #include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerPluginFactory.h"
0203 DEFINE_EDM_PLUGIN(PedeLabelerPluginFactory, PedeLabeler, "PedeLabeler");