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