File indexing completed on 2024-04-06 11:56:07
0001
0002
0003
0004
0005
0006
0007 #include "Alignment/CommonAlignment/interface/AlignableDet.h"
0008 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
0009 #include "Alignment/CommonAlignment/interface/AlignableExtras.h"
0010 #include "Alignment/CommonAlignment/interface/AlignableBeamSpot.h"
0011 #include "DataFormats/DetId/interface/DetId.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014
0015 #include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
0016
0017
0018 AlignableNavigator::AlignableNavigator(Alignable* tracker, Alignable* muon) {
0019 theMap.clear();
0020
0021 const unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);
0022
0023 if (numNonDets) {
0024 edm::LogWarning("Alignment") << "@SUB=AlignableNavigator"
0025 << "Created with map of size " << theMap.size() << ", but found also " << numNonDets
0026 << " Alignables that have DetId!=0,\nbeing neither "
0027 << "AlignableDet nor AlignableDetUnit. This will "
0028 << "lead to an exception in case alignableFromDetId(..) "
0029 << "is called for one of these DetIds.\n"
0030 << "If there is no exception, you can ignore this message.";
0031 } else {
0032 edm::LogInfo("Alignment") << "@SUB=AlignableNavigator"
0033 << "Created with map of size " << theMap.size() << ".";
0034 }
0035 }
0036
0037
0038 AlignableNavigator::AlignableNavigator(AlignableExtras* extras, Alignable* tracker, Alignable* muon) {
0039 theMap.clear();
0040
0041 unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);
0042
0043 if (extras) {
0044 for (const auto& it : extras->components()) {
0045 numNonDets += this->recursiveGetId(it);
0046 }
0047 }
0048
0049 if (numNonDets) {
0050 edm::LogWarning("Alignment") << "@SUB=AlignableNavigator"
0051 << "Created with map of size " << theMap.size() << ", but found also " << numNonDets
0052 << " Alignables that have DetId!=0,\nbeing neither "
0053 << "AlignableDet nor AlignableDetUnit. This will "
0054 << "lead to an exception in case alignableFromDetId(..) "
0055 << "is called for one of these DetIds.\n"
0056 << "If there is no exception, you can ignore this message.";
0057 } else {
0058 edm::LogInfo("Alignment") << "@SUB=AlignableNavigator"
0059 << "Created with map of size " << theMap.size() << ".";
0060 }
0061 }
0062
0063
0064 AlignableNavigator::AlignableNavigator(const align::Alignables& alignables) {
0065 theMap.clear();
0066
0067 unsigned int numNonDets = 0;
0068 for (const auto& it : alignables) {
0069 numNonDets += this->recursiveGetId(it);
0070 }
0071 if (numNonDets) {
0072 edm::LogWarning("Alignment") << "@SUB=AlignableNavigator"
0073 << "Created with map of size " << theMap.size() << ", but found also " << numNonDets
0074 << " Alignables that have DetId!=0,\nbeing neither "
0075 << "AlignableDet nor AlignableDetUnit. This will "
0076 << "lead to an exception in case alignableFromDetId(..) "
0077 << "is called for one of these DetIds.\n"
0078 << "If there is no exception, you can ignore this message.";
0079 } else {
0080 edm::LogInfo("Alignment") << "@SUB=AlignableNavigator"
0081 << "created with map of size " << theMap.size() << ".";
0082 }
0083 }
0084
0085
0086 AlignableDetOrUnitPtr AlignableNavigator::alignableFromGeomDet(const GeomDet* geomDet) {
0087 return alignableFromDetId(geomDet->geographicalId());
0088 }
0089
0090
0091 AlignableDetOrUnitPtr AlignableNavigator::alignableFromDetId(const DetId& detid) {
0092 MapType::iterator position = theMap.find(detid);
0093 if (position != theMap.end()) {
0094 return position->second;
0095 }
0096
0097 throw cms::Exception("BadLogic") << "[AlignableNavigator::alignableDetFromDetId] DetId " << detid.rawId()
0098 << " not found";
0099
0100 return static_cast<AlignableDet*>(nullptr);
0101 }
0102
0103
0104 unsigned int AlignableNavigator::recursiveGetId(Alignable* alignable) {
0105
0106
0107
0108
0109
0110 if (!alignable)
0111 return 0;
0112
0113 unsigned int nProblem = 0;
0114 const DetId detId(alignable->geomDetId());
0115 if (detId.rawId()) {
0116 AlignableDet* aliDet;
0117 AlignableDetUnit* aliDetUnit;
0118 AlignableBeamSpot* aliBeamSpot;
0119
0120 if ((aliDet = dynamic_cast<AlignableDet*>(alignable))) {
0121 theMap.insert(PairType(detId, aliDet));
0122
0123 } else if ((aliDetUnit = dynamic_cast<AlignableDetUnit*>(alignable))) {
0124 theMap.insert(PairType(detId, aliDetUnit));
0125
0126 } else if ((aliBeamSpot = dynamic_cast<AlignableBeamSpot*>(alignable))) {
0127 theMap.insert(PairType(detId, aliBeamSpot));
0128
0129 } else {
0130 nProblem = 1;
0131
0132
0133
0134
0135 }
0136
0137 if (!nProblem && !this->detAndSubdetInMap(detId)) {
0138 theDetAndSubdet.push_back(std::pair<int, int>(detId.det(), detId.subdetId()));
0139 }
0140 }
0141 const auto& comp = alignable->components();
0142 if (alignable->alignableObjectId() != align::AlignableDet ||
0143 comp.size() > 1) {
0144 for (const auto& it : comp) {
0145 nProblem += this->recursiveGetId(it);
0146 }
0147 }
0148 return nProblem;
0149 }
0150
0151
0152 std::vector<AlignableDetOrUnitPtr> AlignableNavigator::alignablesFromHits(
0153 const std::vector<const TransientTrackingRecHit*>& hitvec) {
0154 std::vector<AlignableDetOrUnitPtr> result;
0155 result.reserve(hitvec.size());
0156
0157 for (std::vector<const TransientTrackingRecHit*>::const_iterator ih = hitvec.begin(), iEnd = hitvec.end(); ih != iEnd;
0158 ++ih) {
0159 result.push_back(this->alignableFromDetId((*ih)->geographicalId()));
0160 }
0161
0162 return result;
0163 }
0164
0165
0166 std::vector<AlignableDetOrUnitPtr> AlignableNavigator::alignablesFromHits(
0167 const TransientTrackingRecHit::ConstRecHitContainer& hitVec) {
0168 std::vector<AlignableDetOrUnitPtr> result;
0169 result.reserve(hitVec.size());
0170
0171 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = hitVec.begin(), iEnd = hitVec.end();
0172 it != iEnd;
0173 ++it) {
0174 result.push_back(this->alignableFromDetId((*it)->geographicalId()));
0175 }
0176
0177 return result;
0178 }
0179
0180
0181 std::vector<AlignableDetOrUnitPtr> AlignableNavigator::alignableDetOrUnits() {
0182 std::vector<AlignableDetOrUnitPtr> result;
0183 result.reserve(theMap.size());
0184
0185 for (MapType::const_iterator iIdAli = theMap.begin(); iIdAli != theMap.end(); ++iIdAli) {
0186 result.push_back(iIdAli->second);
0187 }
0188
0189 return result;
0190 }
0191
0192
0193 bool AlignableNavigator::detAndSubdetInMap(const DetId& detid) const {
0194 int det = detid.det();
0195 int subdet = detid.subdetId();
0196 for (std::vector<std::pair<int, int> >::const_iterator i = theDetAndSubdet.begin(); i != theDetAndSubdet.end(); ++i) {
0197 if (det == i->first && subdet == i->second)
0198 return true;
0199 }
0200 return false;
0201 }