CMS 3D CMS Logo

AlignableNavigator.cc
Go to the documentation of this file.
1 // \file AlignableNavigator.cc
2 //
3 // $Revision: 1.22 $
4 // $Date: 2010/09/10 10:30:03 $
5 // (last update by $Author: mussgill $)
6 
14 
16 
17 //_____________________________________________________________________________
19  theMap.clear();
20 
21  const unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);
22 
23  if (numNonDets) {
24  edm::LogWarning("Alignment") << "@SUB=AlignableNavigator"
25  << "Created with map of size " << theMap.size() << ", but found also " << numNonDets
26  << " Alignables that have DetId!=0,\nbeing neither "
27  << "AlignableDet nor AlignableDetUnit. This will "
28  << "lead to an exception in case alignableFromDetId(..) "
29  << "is called for one of these DetIds.\n"
30  << "If there is no exception, you can ignore this message.";
31  } else {
32  edm::LogInfo("Alignment") << "@SUB=AlignableNavigator"
33  << "Created with map of size " << theMap.size() << ".";
34  }
35 }
36 
37 //_____________________________________________________________________________
39  theMap.clear();
40 
41  unsigned int numNonDets = this->recursiveGetId(tracker) + this->recursiveGetId(muon);
42 
43  if (extras) {
44  for (const auto& it : extras->components()) {
45  numNonDets += this->recursiveGetId(it);
46  }
47  }
48 
49  if (numNonDets) {
50  edm::LogWarning("Alignment") << "@SUB=AlignableNavigator"
51  << "Created with map of size " << theMap.size() << ", but found also " << numNonDets
52  << " Alignables that have DetId!=0,\nbeing neither "
53  << "AlignableDet nor AlignableDetUnit. This will "
54  << "lead to an exception in case alignableFromDetId(..) "
55  << "is called for one of these DetIds.\n"
56  << "If there is no exception, you can ignore this message.";
57  } else {
58  edm::LogInfo("Alignment") << "@SUB=AlignableNavigator"
59  << "Created with map of size " << theMap.size() << ".";
60  }
61 }
62 
63 //_____________________________________________________________________________
65  theMap.clear();
66 
67  unsigned int numNonDets = 0;
68  for (const auto& it : alignables) {
69  numNonDets += this->recursiveGetId(it);
70  }
71  if (numNonDets) {
72  edm::LogWarning("Alignment") << "@SUB=AlignableNavigator"
73  << "Created with map of size " << theMap.size() << ", but found also " << numNonDets
74  << " Alignables that have DetId!=0,\nbeing neither "
75  << "AlignableDet nor AlignableDetUnit. This will "
76  << "lead to an exception in case alignableFromDetId(..) "
77  << "is called for one of these DetIds.\n"
78  << "If there is no exception, you can ignore this message.";
79  } else {
80  edm::LogInfo("Alignment") << "@SUB=AlignableNavigator"
81  << "created with map of size " << theMap.size() << ".";
82  }
83 }
84 
85 //_____________________________________________________________________________
87  return alignableFromDetId(geomDet->geographicalId());
88 }
89 
90 //_____________________________________________________________________________
92  MapType::iterator position = theMap.find(detid);
93  if (position != theMap.end()) {
94  return position->second;
95  }
96 
97  throw cms::Exception("BadLogic") << "[AlignableNavigator::alignableDetFromDetId] DetId " << detid.rawId()
98  << " not found";
99 
100  return static_cast<AlignableDet*>(nullptr);
101 }
102 
103 //_____________________________________________________________________________
105  // Recursive method to get the detIds of an alignable and its childs
106  // and add them to the map.
107  // Returns number of Alignables with DetId which are neither AlignableDet
108  // nor AlignableDetUnit and are thus not added to the map.
109 
110  if (!alignable)
111  return 0;
112 
113  unsigned int nProblem = 0;
114  const DetId detId(alignable->geomDetId());
115  if (detId.rawId()) {
116  AlignableDet* aliDet;
117  AlignableDetUnit* aliDetUnit;
118  AlignableBeamSpot* aliBeamSpot;
119 
120  if ((aliDet = dynamic_cast<AlignableDet*>(alignable))) {
121  theMap.insert(PairType(detId, aliDet));
122 
123  } else if ((aliDetUnit = dynamic_cast<AlignableDetUnit*>(alignable))) {
124  theMap.insert(PairType(detId, aliDetUnit));
125 
126  } else if ((aliBeamSpot = dynamic_cast<AlignableBeamSpot*>(alignable))) {
127  theMap.insert(PairType(detId, aliBeamSpot));
128 
129  } else {
130  nProblem = 1; // equivalent to '++nProblem;' which could confuse to be ina loop...
131  // Cannot be an exception since it happens (illegaly) in Muon DT hierarchy:
132  // throw cms::Exception("BadLogic")
133  // << "[AlignableNavigator::recursiveGetId] Alignable with DetId " << detId.rawId()
134  // << " neither AlignableDet nor AlignableDetUnit";
135  }
136 
137  if (!nProblem && !this->detAndSubdetInMap(detId)) {
138  theDetAndSubdet.push_back(std::pair<int, int>(detId.det(), detId.subdetId()));
139  }
140  }
141  const auto& comp = alignable->components();
142  if (alignable->alignableObjectId() != align::AlignableDet ||
143  comp.size() > 1) { // Non-glued AlignableDets contain themselves
144  for (const auto& it : comp) {
145  nProblem += this->recursiveGetId(it);
146  }
147  }
148  return nProblem;
149 }
150 
151 //_____________________________________________________________________________
152 std::vector<AlignableDetOrUnitPtr> AlignableNavigator::alignablesFromHits(
153  const std::vector<const TransientTrackingRecHit*>& hitvec) {
154  std::vector<AlignableDetOrUnitPtr> result;
155  result.reserve(hitvec.size());
156 
157  for (std::vector<const TransientTrackingRecHit*>::const_iterator ih = hitvec.begin(), iEnd = hitvec.end(); ih != iEnd;
158  ++ih) {
159  result.push_back(this->alignableFromDetId((*ih)->geographicalId()));
160  }
161 
162  return result;
163 }
164 
165 //_____________________________________________________________________________
166 std::vector<AlignableDetOrUnitPtr> AlignableNavigator::alignablesFromHits(
168  std::vector<AlignableDetOrUnitPtr> result;
169  result.reserve(hitVec.size());
170 
171  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = hitVec.begin(), iEnd = hitVec.end();
172  it != iEnd;
173  ++it) {
174  result.push_back(this->alignableFromDetId((*it)->geographicalId()));
175  }
176 
177  return result;
178 }
179 
180 //_____________________________________________________________________________
181 std::vector<AlignableDetOrUnitPtr> AlignableNavigator::alignableDetOrUnits() {
182  std::vector<AlignableDetOrUnitPtr> result;
183  result.reserve(theMap.size());
184 
185  for (MapType::const_iterator iIdAli = theMap.begin(); iIdAli != theMap.end(); ++iIdAli) {
186  result.push_back(iIdAli->second);
187  }
188 
189  return result;
190 }
191 
192 //_____________________________________________________________________________
194  int det = detid.det();
195  int subdet = detid.subdetId();
196  for (std::vector<std::pair<int, int> >::const_iterator i = theDetAndSubdet.begin(); i != theDetAndSubdet.end(); ++i) {
197  if (det == i->first && subdet == i->second)
198  return true;
199  }
200  return false;
201 }
const Alignables & components() const
AlignableDetOrUnitPtr alignableFromGeomDet(const GeomDet *geomDet)
Returns AlignableDetOrUnitPtr corresponding to given GeomDet.
bool detAndSubdetInMap(const DetId &detid) const
Given a DetId, returns true if DetIds with this detector and subdetector id are in the map (not neces...
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
AlignableNavigator(Alignable *tracker, Alignable *muon=nullptr)
Constructor from one or two Alignables.
unsigned int recursiveGetId(Alignable *alignable)
std::vector< std::pair< int, int > > theDetAndSubdet
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
virtual const Alignables & components() const =0
Return vector of all direct components.
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
std::vector< ConstRecHitPointer > ConstRecHitContainer
Log< level::Info, false > LogInfo
Definition: DetId.h:17
std::vector< AlignableDetOrUnitPtr > alignableDetOrUnits()
return all AlignableDetOrUnitPtrs
const DetId & geomDetId() const
Definition: Alignable.h:177
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
static int position[264][3]
Definition: ReadPGInfo.cc:289
std::vector< AlignableDetOrUnitPtr > alignablesFromHits(const std::vector< const TransientTrackingRecHit *> &hitvec)
Returns vector AlignableDetOrUnitPtr for given vector of Hits.
Log< level::Warning, false > LogWarning
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
MapType::value_type PairType