CMS 3D CMS Logo

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, AlignableDetOrUnitPtrMapType
 
typedef MapType::value_type PairType
 

Public Member Functions

std::vector< AlignableDetOrUnitPtralignableDetOrUnits ()
 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 (const align::Alignables &)
 Constructor from list of Alignbable. More...
 
std::vector< AlignableDetOrUnitPtralignablesFromHits (const std::vector< const TransientTrackingRecHit * > &hitvec)
 Returns vector AlignableDetOrUnitPtr for given vector of Hits. More...
 
std::vector< AlignableDetOrUnitPtralignablesFromHits (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 26 of file AlignableNavigator.h.

Member Typedef Documentation

Definition at line 40 of file AlignableNavigator.h.

typedef MapType::value_type AlignableNavigator::PairType

Definition at line 41 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  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 }
unsigned int recursiveGetId(Alignable *alignable)
const Alignables & components() const
AlignableNavigator::AlignableNavigator ( const align::Alignables alignables)
explicit

Constructor from list of Alignbable.

Definition at line 66 of file AlignableNavigator.cc.

References recursiveGetId(), and theMap.

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 }
unsigned int recursiveGetId(Alignable *alignable)

Member Function Documentation

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

return all AlignableDetOrUnitPtrs

Definition at line 194 of file AlignableNavigator.cc.

References mps_fire::result, and theMap.

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 }
AlignableDetOrUnitPtr AlignableNavigator::alignableFromDetId ( const DetId detid)

Returns AlignableDetOrUnitPtr corresponding to given DetId.

Definition at line 95 of file AlignableNavigator.cc.

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

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

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

Returns AlignableDetOrUnitPtr corresponding to given GeomDet.

Definition at line 89 of file AlignableNavigator.cc.

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

Referenced by MuonMillepedeAlgorithm::run().

90 {
91  return alignableFromDetId( geomDet->geographicalId() );
92 }
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
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 163 of file AlignableNavigator.cc.

References alignableFromDetId(), and mps_fire::result.

Referenced by MuonMillepedeAlgorithm::run().

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 }
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 179 of file AlignableNavigator.cc.

References alignableFromDetId(), and mps_fire::result.

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 }
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 207 of file AlignableNavigator.cc.

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

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

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 }
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
std::vector< std::pair< int, int > > theDetAndSubdet
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
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 109 of file AlignableNavigator.cc.

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

Referenced by AlignableNavigator(), and size().

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 }
virtual const 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:18
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:186
MapType::value_type PairType
int AlignableNavigator::size ( void  )
inline

Returns number of elements in map.

Definition at line 61 of file AlignableNavigator.h.

References detAndSubdetInMap(), recursiveGetId(), and theMap.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

61 { return theMap.size(); }

Member Data Documentation

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

Definition at line 73 of file AlignableNavigator.h.

Referenced by detAndSubdetInMap(), and recursiveGetId().

MapType AlignableNavigator::theMap
private