CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
AlignableNavigator Class Reference

#include <AlignableNavigator.h>

Public Types

typedef std::map< DetId,
AlignableDetOrUnitPtr
MapType
 
typedef MapType::value_type PairType
 

Public Member Functions

std::vector
< AlignableDetOrUnitPtr
alignableDetOrUnits ()
 return all AlignableDetOrUnitPtrs More...
 
AlignableDetOrUnitPtr alignableFromDetId (const DetId &detid)
 Returns AlignableDetOrUnitPtr corresponding to given DetId. More...
 
AlignableDetOrUnitPtr alignableFromGeomDet (const GeomDet *geomDet)
 Returns AlignableDetOrUnitPtr corresponding to given GeomDet. More...
 
 AlignableNavigator (Alignable *tracker, Alignable *muon=0)
 Constructor from one or two Alignables. More...
 
 AlignableNavigator (AlignableExtras *extras, Alignable *tracker, Alignable *muon=0)
 Constructor from one or two Alignables. More...
 
 AlignableNavigator (std::vector< Alignable * > alignables)
 Constructor from list of Alignbable. More...
 
std::vector
< AlignableDetOrUnitPtr
alignablesFromHits (const std::vector< const TransientTrackingRecHit * > &hitvec)
 Returns vector AlignableDetOrUnitPtr for given vector of Hits. More...
 
std::vector
< AlignableDetOrUnitPtr
alignablesFromHits (const TransientTrackingRecHit::ConstRecHitContainer &hitVec)
 Returns vector of AlignableDetOrUnitPtr for given vector of Hits. More...
 
bool detAndSubdetInMap (const DetId &detid) const
 Given a DetId, returns true if DetIds with this detector and subdetector id are in the map (not necessarily the exact DetId) More...
 
int size (void)
 Returns number of elements in map. More...
 

Private Member Functions

unsigned int recursiveGetId (Alignable *alignable)
 

Private Attributes

std::vector< std::pair< int,
int > > 
theDetAndSubdet
 
MapType theMap
 

Detailed Description

A class to navigate from a DetId to the corresponding AlignableDetOrUnitPtr. A map is created at construction time from all sub-structures of the constructor's argument(s) that are AlignableDet or AlignableDetUnit.

Definition at line 25 of file AlignableNavigator.h.

Member Typedef Documentation

Definition at line 39 of file AlignableNavigator.h.

typedef MapType::value_type AlignableNavigator::PairType

Definition at line 40 of file AlignableNavigator.h.

Constructor & Destructor Documentation

AlignableNavigator::AlignableNavigator ( Alignable tracker,
Alignable muon = 0 
)
explicit

Constructor from one or two Alignables.

Definition at line 18 of file AlignableNavigator.cc.

References recursiveGetId(), and theMap.

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 }
unsigned int recursiveGetId(Alignable *alignable)
AlignableNavigator::AlignableNavigator ( AlignableExtras extras,
Alignable tracker,
Alignable muon = 0 
)
explicit

Constructor from one or two Alignables.

Definition at line 39 of file AlignableNavigator.cc.

References AlignableExtras::components(), recursiveGetId(), and theMap.

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 }
unsigned int recursiveGetId(Alignable *alignable)
Alignables components() const
std::vector< Alignable * > Alignables
Definition: Utilities.h:28
AlignableNavigator::AlignableNavigator ( std::vector< Alignable * >  alignables)
explicit

Constructor from list of Alignbable.

Definition at line 67 of file AlignableNavigator.cc.

References recursiveGetId(), and theMap.

68 {
69  theMap.clear();
70 
71  unsigned int numNonDets = 0;
72  for ( std::vector<Alignable*>::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 }
unsigned int recursiveGetId(Alignable *alignable)

Member Function Documentation

std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignableDetOrUnits ( )

return all AlignableDetOrUnitPtrs

Definition at line 195 of file AlignableNavigator.cc.

References query::result, and theMap.

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 }
tuple result
Definition: query.py:137
AlignableDetOrUnitPtr AlignableNavigator::alignableFromDetId ( const DetId detid)

Returns AlignableDetOrUnitPtr corresponding to given DetId.

Definition at line 96 of file AlignableNavigator.cc.

References edm::hlt::Exception, position, DetId::rawId(), and theMap.

Referenced by MillePedeAlignmentAlgorithm::addLasBeam(), MillePedeAlignmentAlgorithm::addMeasurementData(), MillePedeAlignmentAlgorithm::addPxbSurvey(), alignableFromGeomDet(), alignablesFromHits(), SurveyInputCSCfromPins::analyze(), MuonGeometrySVGTemplate::analyze(), CSCAlignmentCorrections::applyAlignment(), AlignmentMonitorTemplate::event(), AlignmentMonitorGeneric::event(), ApeSettingAlgorithm::initialize(), MuonAlignment::moveAlignableGlobalCoord(), MuonAlignment::moveAlignableLocalCoord(), MuonResidualsFromTrack::MuonResidualsFromTrack(), CSCChamberFitter::radiusCorrection(), KalmanAlignmentTrackRefitter::refitTracks(), and ApeSettingAlgorithm::terminate().

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 }
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
static int position[264][3]
Definition: ReadPGInfo.cc:509
AlignableDetOrUnitPtr AlignableNavigator::alignableFromGeomDet ( const GeomDet geomDet)

Returns AlignableDetOrUnitPtr corresponding to given GeomDet.

Definition at line 90 of file AlignableNavigator.cc.

References alignableFromDetId(), and GeomDet::geographicalId().

Referenced by CurrentAlignmentKFUpdator::includeCurrentAlignmentEstimate(), MuonMillepedeAlgorithm::run(), and HIPAlignmentAlgorithm::run().

91 {
92  return alignableFromDetId( geomDet->geographicalId() );
93 }
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:72
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignablesFromHits ( const std::vector< const TransientTrackingRecHit * > &  hitvec)

Returns vector AlignableDetOrUnitPtr for given vector of Hits.

Definition at line 164 of file AlignableNavigator.cc.

References alignableFromDetId(), and query::result.

Referenced by SingleTrajectoryUpdator::process(), MuonMillepedeAlgorithm::run(), and HIPAlignmentAlgorithm::run().

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 }
tuple result
Definition: query.py:137
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignablesFromHits ( const TransientTrackingRecHit::ConstRecHitContainer hitVec)

Returns vector of AlignableDetOrUnitPtr for given vector of Hits.

Definition at line 180 of file AlignableNavigator.cc.

References query::result.

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 }
tuple result
Definition: query.py:137
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
bool AlignableNavigator::detAndSubdetInMap ( const DetId detid) const

Given a DetId, returns true if DetIds with this detector and subdetector id are in the map (not necessarily the exact DetId)

Definition at line 208 of file AlignableNavigator.cc.

References DetId::det(), i, DetId::subdetId(), and theDetAndSubdet.

Referenced by AlignmentMonitorTemplate::event(), AlignmentMonitorMuonResiduals::event(), recursiveGetId(), MuonMillepedeAlgorithm::run(), and HIPAlignmentAlgorithm::run().

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
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
std::vector< std::pair< int, int > > theDetAndSubdet
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
unsigned int AlignableNavigator::recursiveGetId ( Alignable alignable)
private

Add recursively DetId-AlignableDetOrUnitPtr pairs to map. Returns number of Alignables with DetId!=0 which are (illegaly) neither AlignableDet nor AlignableDetUnit and are thus not added to the map.

Definition at line 110 of file AlignableNavigator.cc.

References align::AlignableDet, Alignable::alignableObjectId(), Alignable::components(), detAndSubdetInMap(), Alignable::geomDetId(), theDetAndSubdet, and theMap.

Referenced by AlignableNavigator().

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 }
virtual Alignables components() const =0
Return vector of all direct components.
unsigned int recursiveGetId(Alignable *alignable)
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
Definition: DetId.h:20
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...
const DetId & geomDetId() const
Definition: Alignable.h:177
MapType::value_type PairType
int AlignableNavigator::size ( void  )
inline

Returns number of elements in map.

Definition at line 60 of file AlignableNavigator.h.

References theMap.

60 { return theMap.size(); }

Member Data Documentation

std::vector<std::pair<int,int> > AlignableNavigator::theDetAndSubdet
private

Definition at line 72 of file AlignableNavigator.h.

Referenced by detAndSubdetInMap(), and recursiveGetId().

MapType AlignableNavigator::theMap
private