CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PedeLabeler.cc
Go to the documentation of this file.
1 
12 
18 
19 #include "PedeLabeler.h"
20 
21 //___________________________________________________________________________
24  :PedeLabelerBase(alignables, config)
25 {
26  std::vector<Alignable*> alis;
27  alis.push_back(alignables.aliTracker_);
28  alis.push_back(alignables.aliMuon_);
29 
30  if (alignables.aliExtras_) {
31  align::Alignables allExtras = alignables.aliExtras_->components();
32  for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
33  alis.push_back(*it);
34  }
35  }
36 
37  this->buildMap(alis);
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 0; // error already given
121 
122  if (theIdToAlignableMap.empty()) const_cast<PedeLabeler*>(this)->buildReverseMap();
123  IdToAlignableMap::const_iterator position = theIdToAlignableMap.find(aliLabel);
124  if (position != theIdToAlignableMap.end()) {
125  return position->second;
126  } else {
127  // error only if not in lasBeamMap:
128  UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
129  if (position == theLabelToLasBeamMap.end()) {
130  edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableFromLabel"
131  << "Alignable label " << aliLabel << " not in map.";
132  }
133  return 0;
134  }
135 }
136 
137 //___________________________________________________________________________
138 unsigned int PedeLabeler::lasBeamIdFromLabel(unsigned int label) const
139 {
140  const unsigned int aliLabel = this->alignableLabelFromLabel(label);
141  if (aliLabel < theMinLabel) return 0; // error already given
142 
143  if (theLabelToLasBeamMap.empty()) const_cast<PedeLabeler*>(this)->buildReverseMap();
144  UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
145  if (position != theLabelToLasBeamMap.end()) {
146  return position->second;
147  } else {
148  edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamIdFromLabel"
149  << "Alignable label " << aliLabel << " not in map.";
150  return 0;
151  }
152 }
153 
154 //_________________________________________________________________________
155 unsigned int PedeLabeler::buildMap(const std::vector<Alignable*> &alis)
156 {
157  theAlignableToIdMap.clear(); // just in case of re-use...
158 
159  std::vector<Alignable*> allComps;
160 
161  for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
162  if (*iAli) {
163  allComps.push_back(*iAli);
164  (*iAli)->recursiveComponents(allComps);
165  }
166  }
167 
168  unsigned int id = theMinLabel;
169  for (std::vector<Alignable*>::const_iterator iter = allComps.begin();
170  iter != allComps.end(); ++iter) {
172  id += theMaxNumParam;
173  }
174 
175  // also care about las beams
176  theLasBeamToLabelMap.clear(); // just in case of re-use...
177  // FIXME: Temporarily hard code values stolen from
178  // https://twiki.cern.ch/twiki/bin/view/CMS/TkLasTrackBasedInterface#Beam_identifier .
179  unsigned int beamIds[] = { 0, 10, 20, 30, 40, 50, 60, 70, // TEC+ R4
180  1, 11, 21, 31, 41, 51, 61, 71, // TEC+ R6
181  100, 110, 120, 130, 140, 150, 160, 170, // TEC- R4
182  101, 111, 121, 131, 141, 151, 161, 171, // TEC- R6
183  200, 210, 220, 230, 240, 250, 260, 270};// AT
184 
185  const size_t nBeams = sizeof(beamIds)/sizeof(beamIds[0]);
186  for (size_t iBeam = 0; iBeam < nBeams; ++iBeam) {
187  //edm::LogInfo("Alignment") << "Las beam " << beamIds[iBeam] << " gets label " << id << ".";
188  theLasBeamToLabelMap[beamIds[iBeam]] = id;
189  id += theMaxNumParam;
190  }
191 
192  // return combined size
193  return theAlignableToIdMap.size() + theLasBeamToLabelMap.size();
194 }
195 
196 //_________________________________________________________________________
198 {
199 
200  // alignables
201  theIdToAlignableMap.clear(); // just in case of re-use...
202 
203  for (AlignableToIdMap::iterator it = theAlignableToIdMap.begin();
204  it != theAlignableToIdMap.end(); ++it) {
205  const unsigned int key = (*it).second;
206  Alignable *ali = (*it).first;
207  theIdToAlignableMap[key] = ali;
208  }
209 
210  // las beams
211  theLabelToLasBeamMap.clear(); // just in case of re-use...
212 
213  for (UintUintMap::const_iterator it = theLasBeamToLabelMap.begin();
214  it != theLasBeamToLabelMap.end(); ++it) {
215  theLabelToLasBeamMap[it->second] = it->first; //revert key/value
216  }
217 
218  // return combined size
219  return theIdToAlignableMap.size() + theLabelToLasBeamMap.size();
220 }
221 
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const
Definition: PedeLabeler.cc:67
unsigned int lasBeamLabel(unsigned int lasBeamId) const
Definition: PedeLabeler.cc:75
unsigned int paramNumFromLabel(unsigned int paramLabel) const
parameter number, 0 &lt;= .. &lt; theMaxNumParam, belonging to unique parameter label
Definition: PedeLabeler.cc:100
~PedeLabeler()
destructor
Definition: PedeLabeler.cc:41
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
unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const
returns the label for a given alignable parameter number combination
Definition: PedeLabeler.cc:89
unsigned int buildReverseMap()
returns size of map
Definition: PedeLabeler.cc:197
static const unsigned int theMaxNumParam
UintUintMap theLabelToLasBeamMap
labels for las beams
Definition: PedeLabeler.h:80
AlignableToIdMap::value_type AlignableToIdPair
Definition: PedeLabeler.h:67
IdToAlignableMap theIdToAlignableMap
providing unique ID for alignable, space for param IDs
Definition: PedeLabeler.h:78
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
AlignableToIdMap theAlignableToIdMap
Definition: PedeLabeler.h:77
Alignables components() const
Alignable * alignableFromLabel(unsigned int label) const
Definition: PedeLabeler.cc:117
Definition: DetId.h:18
unsigned int alignableLabel(Alignable *alignable) const
Return 32-bit unique label for alignable, 0 indicates failure.
Definition: PedeLabeler.cc:47
UintUintMap theLasBeamToLabelMap
reverse map
Definition: PedeLabeler.h:79
unsigned int alignableLabelFromLabel(unsigned int label) const
alignable label from parameter label (works also for alignable label...)
Definition: PedeLabeler.cc:111
std::vector< Alignable * > Alignables
Definition: Utilities.h:28
unsigned int lasBeamIdFromLabel(unsigned int label) const
Definition: PedeLabeler.cc:138
static int position[264][3]
Definition: ReadPGInfo.cc:509
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned int buildMap(const std::vector< Alignable * > &alis)
returns size of map
Definition: PedeLabeler.cc:155