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=nullptr)
 Constructor from one or two Alignables. More...
 
 AlignableNavigator (AlignableExtras *extras, Alignable *tracker, Alignable *muon=nullptr)
 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 25 of file AlignableNavigator.h.

Member Typedef Documentation

◆ MapType

Definition at line 36 of file AlignableNavigator.h.

◆ PairType

typedef MapType::value_type AlignableNavigator::PairType

Definition at line 37 of file AlignableNavigator.h.

Constructor & Destructor Documentation

◆ AlignableNavigator() [1/3]

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

Constructor from one or two Alignables.

Definition at line 18 of file AlignableNavigator.cc.

18  {
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 }

References recursiveGetId(), and theMap.

◆ AlignableNavigator() [2/3]

AlignableNavigator::AlignableNavigator ( AlignableExtras extras,
Alignable tracker,
Alignable muon = nullptr 
)
explicit

Constructor from one or two Alignables.

Definition at line 38 of file AlignableNavigator.cc.

38  {
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 }

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

◆ AlignableNavigator() [3/3]

AlignableNavigator::AlignableNavigator ( const align::Alignables alignables)
explicit

Constructor from list of Alignbable.

Definition at line 64 of file AlignableNavigator.cc.

64  {
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 }

References recursiveGetId(), and theMap.

Member Function Documentation

◆ alignableDetOrUnits()

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

return all AlignableDetOrUnitPtrs

Definition at line 181 of file AlignableNavigator.cc.

181  {
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 }

References mps_fire::result, and theMap.

◆ alignableFromDetId()

AlignableDetOrUnitPtr AlignableNavigator::alignableFromDetId ( const DetId detid)

Returns AlignableDetOrUnitPtr corresponding to given DetId.

Definition at line 91 of file AlignableNavigator.cc.

91  {
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 }

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(), CSCChamberFitter::radiusCorrection(), and ApeSettingAlgorithm::terminate().

◆ alignableFromGeomDet()

AlignableDetOrUnitPtr AlignableNavigator::alignableFromGeomDet ( const GeomDet geomDet)

Returns AlignableDetOrUnitPtr corresponding to given GeomDet.

Definition at line 86 of file AlignableNavigator.cc.

86  {
87  return alignableFromDetId(geomDet->geographicalId());
88 }

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

◆ alignablesFromHits() [1/2]

std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignablesFromHits ( const std::vector< const TransientTrackingRecHit * > &  hitvec)

Returns vector AlignableDetOrUnitPtr for given vector of Hits.

Definition at line 152 of file AlignableNavigator.cc.

153  {
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 }

References alignableFromDetId(), and mps_fire::result.

◆ alignablesFromHits() [2/2]

std::vector< AlignableDetOrUnitPtr > AlignableNavigator::alignablesFromHits ( const TransientTrackingRecHit::ConstRecHitContainer hitVec)

Returns vector of AlignableDetOrUnitPtr for given vector of Hits.

Definition at line 166 of file AlignableNavigator.cc.

167  {
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 }

References alignableFromDetId(), and mps_fire::result.

◆ detAndSubdetInMap()

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

193  {
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 }

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

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

◆ recursiveGetId()

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

104  {
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 }

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

Referenced by AlignableNavigator().

◆ size()

int AlignableNavigator::size ( void  )
inline

Returns number of elements in map.

Definition at line 55 of file AlignableNavigator.h.

55 { return theMap.size(); }

References theMap.

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

Member Data Documentation

◆ theDetAndSubdet

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

Definition at line 67 of file AlignableNavigator.h.

Referenced by detAndSubdetInMap(), and recursiveGetId().

◆ theMap

MapType AlignableNavigator::theMap
private
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
AlCaHLTBitMon_QueryRunRegistry.comp
string comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
mps_fire.i
i
Definition: mps_fire.py:428
AlignableNavigator::PairType
MapType::value_type PairType
Definition: AlignableNavigator.h:37
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
AlignableNavigator::recursiveGetId
unsigned int recursiveGetId(Alignable *alignable)
Definition: AlignableNavigator.cc:104
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
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.
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
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
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::theDetAndSubdet
std::vector< std::pair< int, int > > theDetAndSubdet
Definition: AlignableNavigator.h:67
align::AlignableDet
Definition: StructureType.h:20
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
Exception
Definition: hltDiff.cc:245
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