CMS 3D CMS Logo

PedeLabeler.cc
Go to the documentation of this file.
1 
12 
18 
19 #include "PedeLabeler.h"
20 
21 //___________________________________________________________________________
23  : PedeLabelerBase(alignables, config) {
24  align::Alignables alis;
25  alis.push_back(alignables.aliTracker_);
26  alis.push_back(alignables.aliMuon_);
27 
28  if (alignables.aliExtras_) {
29  for (const auto& ali : alignables.aliExtras_->components()) {
30  alis.push_back(ali);
31  }
32  }
33 
34  this->buildMap(alis);
35  this->buildReverseMap();
36 }
37 
38 //___________________________________________________________________________
40 
41 //___________________________________________________________________________
43 unsigned int PedeLabeler::alignableLabel(Alignable* alignable) const {
44  if (!alignable)
45  return 0;
46 
47  AlignableToIdMap::const_iterator position = theAlignableToIdMap.find(alignable);
48  if (position != theAlignableToIdMap.end()) {
49  return position->second;
50  } else {
51  const DetId detId(alignable->id());
52  //throw cms::Exception("LogicError")
53  edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableLabel"
54  << "Alignable " << typeid(*alignable).name()
55  << " not in map, det/subdet/alignableStructureType = " << detId.det() << "/"
56  << detId.subdetId() << "/" << alignable->alignableObjectId();
57  return 0;
58  }
59 }
60 
61 //___________________________________________________________________________
62 // Return 32-bit unique label for alignable, 0 indicates failure.
64  unsigned int /*param*/,
65  unsigned int /*instance*/) const {
66  return this->alignableLabel(alignable);
67 }
68 
69 //_________________________________________________________________________
70 unsigned int PedeLabeler::lasBeamLabel(unsigned int lasBeamId) const {
71  UintUintMap::const_iterator position = theLasBeamToLabelMap.find(lasBeamId);
72  if (position != theLasBeamToLabelMap.end()) {
73  return position->second;
74  } else {
75  //throw cms::Exception("LogicError")
76  edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamLabel"
77  << "No label for beam Id " << lasBeamId;
78  return 0;
79  }
80 }
81 
82 //_________________________________________________________________________
83 unsigned int PedeLabeler::parameterLabel(unsigned int aliLabel, unsigned int parNum) const {
84  if (parNum >= theMaxNumParam) {
85  throw cms::Exception("Alignment") << "@SUB=PedeLabeler::parameterLabel"
86  << "Parameter number " << parNum << " out of range 0 <= num < " << theMaxNumParam;
87  }
88  return aliLabel + parNum;
89 }
90 
91 //___________________________________________________________________________
92 unsigned int PedeLabeler::paramNumFromLabel(unsigned int paramLabel) const {
93  if (paramLabel < theMinLabel) {
94  edm::LogError("LogicError") << "@SUB=PedeLabeler::paramNumFromLabel"
95  << "Label " << paramLabel << " should be >= " << theMinLabel;
96  return 0;
97  }
98  return (paramLabel - theMinLabel) % theMaxNumParam;
99 }
100 
101 //___________________________________________________________________________
102 unsigned int PedeLabeler::alignableLabelFromLabel(unsigned int paramLabel) const {
103  return paramLabel - this->paramNumFromLabel(paramLabel);
104 }
105 
106 //___________________________________________________________________________
108  const unsigned int aliLabel = this->alignableLabelFromLabel(label);
109  if (aliLabel < theMinLabel)
110  return nullptr; // error already given
111 
112  IdToAlignableMap::const_iterator position = theIdToAlignableMap.find(aliLabel);
113  if (position != theIdToAlignableMap.end()) {
114  return position->second;
115  } else {
116  // error only if not in lasBeamMap:
117  UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
118  if (position == theLabelToLasBeamMap.end()) {
119  edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableFromLabel"
120  << "Alignable label " << aliLabel << " not in map.";
121  }
122  return nullptr;
123  }
124 }
125 
126 //___________________________________________________________________________
127 unsigned int PedeLabeler::lasBeamIdFromLabel(unsigned int label) const {
128  const unsigned int aliLabel = this->alignableLabelFromLabel(label);
129  if (aliLabel < theMinLabel)
130  return 0; // error already given
131 
132  UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
133  if (position != theLabelToLasBeamMap.end()) {
134  return position->second;
135  } else {
136  edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamIdFromLabel"
137  << "Alignable label " << aliLabel << " not in map.";
138  return 0;
139  }
140 }
141 
142 //_________________________________________________________________________
143 unsigned int PedeLabeler::buildMap(const align::Alignables& alis) {
144  theAlignableToIdMap.clear(); // just in case of re-use...
145 
146  align::Alignables allComps;
147 
148  for (const auto& iAli : alis) {
149  if (iAli) {
150  allComps.push_back(iAli);
151  iAli->recursiveComponents(allComps);
152  }
153  }
154 
155  unsigned int id = theMinLabel;
156  for (const auto& iter : allComps) {
157  theAlignableToIdMap.insert(AlignableToIdPair(iter, id));
158  id += theMaxNumParam;
159  }
160 
161  // also care about las beams
162  theLasBeamToLabelMap.clear(); // just in case of re-use...
163  // FIXME: Temporarily hard code values stolen from
164  // https://twiki.cern.ch/twiki/bin/view/CMS/TkLasTrackBasedInterface#Beam_identifier .
165  unsigned int beamIds[] = {0, 10, 20, 30, 40, 50, 60, 70, // TEC+ R4
166  1, 11, 21, 31, 41, 51, 61, 71, // TEC+ R6
167  100, 110, 120, 130, 140, 150, 160, 170, // TEC- R4
168  101, 111, 121, 131, 141, 151, 161, 171, // TEC- R6
169  200, 210, 220, 230, 240, 250, 260, 270}; // AT
170 
171  const size_t nBeams = sizeof(beamIds) / sizeof(beamIds[0]);
172  for (size_t iBeam = 0; iBeam < nBeams; ++iBeam) {
173  //edm::LogInfo("Alignment") << "Las beam " << beamIds[iBeam] << " gets label " << id << ".";
174  theLasBeamToLabelMap[beamIds[iBeam]] = id;
175  id += theMaxNumParam;
176  }
177 
178  // return combined size
179  return theAlignableToIdMap.size() + theLasBeamToLabelMap.size();
180 }
181 
182 //_________________________________________________________________________
184  // alignables
185  theIdToAlignableMap.clear(); // just in case of re-use...
186 
187  for (const auto& it : theAlignableToIdMap) {
188  theIdToAlignableMap[it.second] = it.first;
189  }
190 
191  // las beams
192  theLabelToLasBeamMap.clear(); // just in case of re-use...
193 
194  for (const auto& it : theLasBeamToLabelMap) {
195  theLabelToLasBeamMap[it.second] = it.first; //revert key/value
196  }
197 
198  // return combined size
199  return theIdToAlignableMap.size() + theLabelToLasBeamMap.size();
200 }
201 
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
Alignable * alignableFromLabel(unsigned int label) const override
Definition: PedeLabeler.cc:107
unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const override
Definition: PedeLabeler.cc:63
static const unsigned int theMinLabel
PedeLabeler(const PedeLabelerBase::TopLevelAlignables &alignables, const edm::ParameterSet &config)
constructor from three Alignables (null pointers allowed )
Definition: PedeLabeler.cc:22
Definition: config.py:1
unsigned int lasBeamLabel(unsigned int lasBeamId) const override
Definition: PedeLabeler.cc:70
unsigned int buildReverseMap()
returns size of map
Definition: PedeLabeler.cc:183
static const unsigned int theMaxNumParam
UintUintMap theLabelToLasBeamMap
labels for las beams
Definition: PedeLabeler.h:78
char const * label
unsigned int paramNumFromLabel(unsigned int paramLabel) const override
parameter number, 0 <= .. < theMaxNumParam, belonging to unique parameter label
Definition: PedeLabeler.cc:92
AlignableToIdMap::value_type AlignableToIdPair
Definition: PedeLabeler.h:65
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
~PedeLabeler() override
destructor
Definition: PedeLabeler.cc:39
IdToAlignableMap theIdToAlignableMap
providing unique ID for alignable, space for param IDs
Definition: PedeLabeler.h:76
unsigned int buildMap(const align::Alignables &)
returns size of map
Definition: PedeLabeler.cc:143
AlignableToIdMap theAlignableToIdMap
Definition: PedeLabeler.h:75
unsigned int alignableLabelFromLabel(unsigned int label) const override
alignable label from parameter label (works also for alignable label...)
Definition: PedeLabeler.cc:102
const Alignables & components() const
Definition: DetId.h:17
UintUintMap theLasBeamToLabelMap
reverse map
Definition: PedeLabeler.h:77
unsigned int lasBeamIdFromLabel(unsigned int label) const override
Definition: PedeLabeler.cc:127
unsigned int alignableLabel(Alignable *alignable) const override
Return 32-bit unique label for alignable, 0 indicates failure.
Definition: PedeLabeler.cc:43
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const override
returns the label for a given alignable parameter number combination
Definition: PedeLabeler.cc:83
static int position[264][3]
Definition: ReadPGInfo.cc:289
#define DEFINE_EDM_PLUGIN(factory, type, name)