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.

References recursiveGetId(), and theMap.

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 }
unsigned int recursiveGetId(Alignable *alignable)
Log< level::Info, false > LogInfo
Log< level::Warning, false > LogWarning

◆ 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.

References AlignableExtras::components(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, recursiveGetId(), and theMap.

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 }
const Alignables & components() const
unsigned int recursiveGetId(Alignable *alignable)
Log< level::Info, false > LogInfo
Log< level::Warning, false > LogWarning

◆ AlignableNavigator() [3/3]

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

Constructor from list of Alignbable.

Definition at line 64 of file AlignableNavigator.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, recursiveGetId(), and theMap.

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 }
unsigned int recursiveGetId(Alignable *alignable)
Log< level::Info, false > LogInfo
Log< level::Warning, false > LogWarning

Member Function Documentation

◆ alignableDetOrUnits()

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

return all AlignableDetOrUnitPtrs

Definition at line 181 of file AlignableNavigator.cc.

References mps_fire::result, and theMap.

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 }

◆ alignableFromDetId()

AlignableDetOrUnitPtr AlignableNavigator::alignableFromDetId ( const DetId detid)

◆ alignableFromGeomDet()

AlignableDetOrUnitPtr AlignableNavigator::alignableFromGeomDet ( const GeomDet geomDet)

Returns AlignableDetOrUnitPtr corresponding to given GeomDet.

Definition at line 86 of file AlignableNavigator.cc.

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

86  {
87  return alignableFromDetId(geomDet->geographicalId());
88 }
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.

◆ 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.

References alignableFromDetId(), and mps_fire::result.

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 }
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.

◆ 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.

References alignableFromDetId(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, and mps_fire::result.

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 }
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.

◆ 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.

References ALCARECOPPSCalTrackBasedSel_cff::detid, mps_fire::i, theDetAndSubdet, and trackerHitRTTI::vector.

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

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 }
std::vector< std::pair< int, int > > theDetAndSubdet

◆ 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.

References align::AlignableDet, Alignable::alignableObjectId(), AlCaHLTBitMon_QueryRunRegistry::comp, Alignable::components(), detAndSubdetInMap(), hcalRecHitTable_cff::detId, Alignable::geomDetId(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, theDetAndSubdet, and theMap.

Referenced by AlignableNavigator().

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

◆ size()

int AlignableNavigator::size ( void  )
inline

Returns number of elements in map.

Definition at line 55 of file AlignableNavigator.h.

References theMap.

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

55 { return theMap.size(); }

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