CMS 3D CMS Logo

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