CMS 3D CMS Logo

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