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 }
AlignableNavigator::detAndSubdetInMap
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...
Definition: AlignableNavigator.cc:193
mps_fire.i
i
Definition: mps_fire.py:428
AlignableBeamSpot.h
MessageLogger.h
AlignableDetUnit.h
GeomDet
Definition: GeomDet.h:27
muon
Definition: MuonCocktails.h:17
AlignableNavigator::PairType
MapType::value_type PairType
Definition: AlignableNavigator.h:37
AlignableNavigator::AlignableNavigator
AlignableNavigator(Alignable *tracker, Alignable *muon=nullptr)
Constructor from one or two Alignables.
Definition: AlignableNavigator.cc:18
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
Alignable
Definition: Alignable.h:27
AlignableExtras.h
AlignableNavigator::recursiveGetId
unsigned int recursiveGetId(Alignable *alignable)
Definition: AlignableNavigator.cc:104
AlignableDet.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
AlignableNavigator::alignableFromGeomDet
AlignableDetOrUnitPtr alignableFromGeomDet(const GeomDet *geomDet)
Returns AlignableDetOrUnitPtr corresponding to given GeomDet.
Definition: AlignableNavigator.cc:86
AlignableDetOrUnitPtr
Definition: AlignableDetOrUnitPtr.h:30
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
AlignableDet
Definition: AlignableDet.h:8
DetId
Definition: DetId.h:17
AlignableExtras::components
const Alignables & components() const
Definition: AlignableExtras.h:32
Alignable::alignableObjectId
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
AlignableExtras
Definition: AlignableExtras.h:19
AlignableNavigator.h
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
PbPb_ZMuSkimMuonDPG_cff.tracker
tracker
Definition: PbPb_ZMuSkimMuonDPG_cff.py:60
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
TrackingRecHit::ConstRecHitContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: TrackingRecHit.h:32
AlignableBeamSpot
Definition: AlignableBeamSpot.h:19
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
Alignable::geomDetId
const DetId & geomDetId() const
Definition: Alignable.h:177
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
AlignableNavigator::alignablesFromHits
std::vector< AlignableDetOrUnitPtr > alignablesFromHits(const std::vector< const TransientTrackingRecHit * > &hitvec)
Returns vector AlignableDetOrUnitPtr for given vector of Hits.
Definition: AlignableNavigator.cc:152
AlignableNavigator::theDetAndSubdet
std::vector< std::pair< int, int > > theDetAndSubdet
Definition: AlignableNavigator.h:67
align::AlignableDet
Definition: StructureType.h:20
align::Alignables
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
AlignableNavigator::alignableFromDetId
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
Definition: AlignableNavigator.cc:91
DetId.h
Exception
Definition: hltDiff.cc:246
Exception.h
AlignableNavigator::alignableDetOrUnits
std::vector< AlignableDetOrUnitPtr > alignableDetOrUnits()
return all AlignableDetOrUnitPtrs
Definition: AlignableNavigator.cc:181
AlignableNavigator::theMap
MapType theMap
Definition: AlignableNavigator.h:66
mps_fire.result
result
Definition: mps_fire.py:311
Alignable::components
virtual const Alignables & components() const =0
Return vector of all direct components.
AlignableDetUnit
Definition: AlignableDetUnit.h:12