CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RunRangeDependentPedeLabeler.cc
Go to the documentation of this file.
1 
11 #include <algorithm>
12 
15 
22 
24 
25 //___________________________________________________________________________
28  :PedeLabelerBase(alignables, config)
29 {
30  std::vector<Alignable*> alis;
31  alis.push_back(alignables.aliTracker_);
32  alis.push_back(alignables.aliMuon_);
33 
34  if (alignables.aliExtras_) {
35  align::Alignables allExtras = alignables.aliExtras_->components();
36  for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
37  alis.push_back(*it);
38  }
39  }
40 
41  this->buildRunRangeDependencyMap(alignables.aliTracker_,
42  alignables.aliMuon_,
43  alignables.aliExtras_,
44  config);
45  this->buildMap(alis);
46 }
47 
48 //___________________________________________________________________________
49 
51 {
52 }
53 
54 //___________________________________________________________________________
57 {
58  if (!alignable) return 0;
59 
60  AlignableToIdMap::const_iterator position = theAlignableToIdMap.find(alignable);
61  if (position != theAlignableToIdMap.end()) {
62  return position->second;
63  } else {
64  const DetId detId(alignable->id());
65  //throw cms::Exception("LogicError")
66  edm::LogError("LogicError")
67  << "@SUB=RunRangeDependentPedeLabeler::alignableLabel" << "Alignable "
68  << typeid(*alignable).name() << " not in map, det/subdet/alignableStructureType = "
69  << detId.det() << "/" << detId.subdetId() << "/" << alignable->alignableObjectId();
70  return 0;
71  }
72 }
73 
74 //___________________________________________________________________________
75 // Return 32-bit unique label for alignable, 0 indicates failure.
77  unsigned int param,
78  unsigned int instance) const
79 {
80  if (!alignable) return 0;
81 
82  AlignableToIdMap::const_iterator position = theAlignableToIdMap.find(alignable);
83  if (position != theAlignableToIdMap.end()) {
84  AlignableToRunRangeRangeMap::const_iterator positionAli = theAlignableToRunRangeRangeMap.find(alignable);
85  if (positionAli != theAlignableToRunRangeRangeMap.end()) {
86  RunRangeParamMap::const_iterator positionParam = (*positionAli).second.find(param);
87  if (positionParam!=(*positionAli).second.end()) {
88  if (instance>=(*positionParam).second.size()) {
89  throw cms::Exception("Alignment") << "@SUB=RunRangeDependentPedeLabeler::alignableLabelFromParamAndRunRange"
90  << "RunRangeIdx out of bounds";
91  }
92  return position->second + instance * theParamInstanceOffset;
93  } else {
94  return position->second;
95  }
96  } else {
97  return position->second;
98  }
99  } else {
100  const DetId detId(alignable->id());
101  //throw cms::Exception("LogicError")
102  edm::LogError("LogicError")
103  << "@SUB=RunRangeDependentPedeLabeler::alignableLabel" << "Alignable "
104  << typeid(*alignable).name() << " not in map, det/subdet/alignableStructureType = "
105  << detId.det() << "/" << detId.subdetId() << "/" << alignable->alignableObjectId();
106  return 0;
107  }
108 }
109 
110 //_________________________________________________________________________
111 unsigned int RunRangeDependentPedeLabeler::lasBeamLabel(unsigned int lasBeamId) const
112 {
113  UintUintMap::const_iterator position = theLasBeamToLabelMap.find(lasBeamId);
114  if (position != theLasBeamToLabelMap.end()) {
115  return position->second;
116  } else {
117  //throw cms::Exception("LogicError")
118  edm::LogError("LogicError") << "@SUB=RunRangeDependentPedeLabeler::lasBeamLabel"
119  << "No label for beam Id " << lasBeamId;
120  return 0;
121  }
122 }
123 
124 //_________________________________________________________________________
125 unsigned int RunRangeDependentPedeLabeler::parameterLabel(unsigned int aliLabel, unsigned int parNum) const
126 {
127  if (parNum >= theMaxNumParam) {
128  throw cms::Exception("Alignment") << "@SUB=RunRangeDependentPedeLabeler::parameterLabel"
129  << "Parameter number " << parNum
130  << " out of range 0 <= num < " << theMaxNumParam;
131  }
132  return aliLabel + parNum;
133 }
134 
135 //_________________________________________________________________________
136 unsigned int RunRangeDependentPedeLabeler::parameterLabel(Alignable *alignable, unsigned int parNum,
138  const TrajectoryStateOnSurface &tsos) const
139 {
140  if (!alignable) return 0;
141 
142  if (parNum >= theMaxNumParam) {
143  throw cms::Exception("Alignment") << "@SUB=RunRangeDependentPedeLabeler::parameterLabel"
144  << "Parameter number " << parNum
145  << " out of range 0 <= num < " << theMaxNumParam;
146  }
147 
148  AlignableToIdMap::const_iterator position = theAlignableToIdMap.find(alignable);
149  if (position != theAlignableToIdMap.end()) {
150 
151  AlignableToRunRangeRangeMap::const_iterator positionAli = theAlignableToRunRangeRangeMap.find(alignable);
152  if (positionAli != theAlignableToRunRangeRangeMap.end()) {
153 
154  RunRangeParamMap::const_iterator positionParam = (*positionAli).second.find(parNum);
155  if (positionParam!=(*positionAli).second.end()) {
156 
157  int offset = 0;
158  const RunRangeVector & runRanges = (*positionParam).second;
159  for (RunRangeVector::const_iterator iRunRange = runRanges.begin();
160  iRunRange != runRanges.end();
161  ++iRunRange) {
162  if (eventInfo.eventId_.run() >= iRunRange->first &&
163  eventInfo.eventId_.run() <= iRunRange->second) {
164  return position->second + offset * theParamInstanceOffset + parNum;
165  }
166  offset++;
167  }
168  const DetId detId(alignable->id());
169  edm::LogError("LogicError")
170  << "@SUB=RunRangeDependentPedeLabeler::parameterLabel" << "Instance for Alignable "
171  << typeid(*alignable).name() << " not in map, det/subdet/alignableStructureType = "
172  << detId.det() << "/" << detId.subdetId() << "/" << alignable->alignableObjectId()
173  << " for run " << eventInfo.eventId_.run();
174  return 0;
175  } else {
176  return position->second + parNum;
177  }
178 
179  } else {
180  return position->second + parNum;
181  }
182  } else {
183  const DetId detId(alignable->id());
184  //throw cms::Exception("LogicError")
185  edm::LogError("LogicError")
186  << "@SUB=RunRangeDependentPedeLabeler::parameterLabel" << "Alignable "
187  << typeid(*alignable).name() << " not in map, det/subdet/alignableStructureType = "
188  << detId.det() << "/" << detId.subdetId() << "/" << alignable->alignableObjectId();
189  return 0;
190  }
191 }
192 
193 //_________________________________________________________________________
195 {
196  AlignableToRunRangeRangeMap::const_iterator positionAli = theAlignableToRunRangeRangeMap.find(alignable);
197  if (positionAli != theAlignableToRunRangeRangeMap.end()) return true;
198  return false;
199 }
200 
201 //_________________________________________________________________________
203 {
204  AlignableToRunRangeRangeMap::const_iterator positionAli = theAlignableToRunRangeRangeMap.find(alignable);
205  if (positionAli != theAlignableToRunRangeRangeMap.end()) {
206 
207  size_t nRunRanges = 1;
208  if (param==-1) {
209  for (RunRangeParamMap::const_iterator iParam = (*positionAli).second.begin();
210  iParam != (*positionAli).second.end();
211  ++iParam) {
212  nRunRanges = std::max(nRunRanges, iParam->second.size());
213  }
214  return nRunRanges;
215  } else {
216  RunRangeParamMap::const_iterator iParam = (*positionAli).second.find(param);
217  if (iParam != (*positionAli).second.end()) {
218  return iParam->second.size();
219  } else {
220  return 1;
221  }
222  }
223  }
224 
225  return 1;
226 }
227 
228 //___________________________________________________________________________
229 unsigned int RunRangeDependentPedeLabeler::paramNumFromLabel(unsigned int paramLabel) const
230 {
231  if (paramLabel < theMinLabel) {
232  edm::LogError("LogicError") << "@SUB=RunRangeDependentPedeLabeler::paramNumFromLabel"
233  << "Label " << paramLabel << " should be >= " << theMinLabel;
234  return 0;
235  }
236  return (paramLabel - theMinLabel) % theMaxNumParam;
237 }
238 
239 //___________________________________________________________________________
240 unsigned int RunRangeDependentPedeLabeler::alignableLabelFromLabel(unsigned int paramLabel) const
241 {
242  return paramLabel - this->paramNumFromLabel(paramLabel);
243 }
244 
245 //___________________________________________________________________________
247 {
248  const unsigned int aliLabel = this->alignableLabelFromLabel(label);
249  if (aliLabel < theMinLabel) return 0; // error already given
250 
251  if (theIdToAlignableMap.empty()) const_cast<RunRangeDependentPedeLabeler*>(this)->buildReverseMap();
252  IdToAlignableMap::const_iterator position = theIdToAlignableMap.find(aliLabel);
253  if (position != theIdToAlignableMap.end()) {
254  return position->second;
255  } else {
256  // error only if not in lasBeamMap:
257  UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
258  if (position == theLabelToLasBeamMap.end()) {
259  edm::LogError("LogicError") << "@SUB=RunRangeDependentPedeLabeler::alignableFromLabel"
260  << "Alignable label " << aliLabel << " not in map.";
261  }
262  return 0;
263  }
264 }
265 
266 //___________________________________________________________________________
268 {
269  const unsigned int aliLabel = this->alignableLabelFromLabel(label);
270  if (aliLabel < theMinLabel) return 0; // error already given
271 
272  if (theLabelToLasBeamMap.empty()) const_cast<RunRangeDependentPedeLabeler*>(this)->buildReverseMap();
273  UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
274  if (position != theLabelToLasBeamMap.end()) {
275  return position->second;
276  } else {
277  edm::LogError("LogicError") << "@SUB=RunRangeDependentPedeLabeler::lasBeamIdFromLabel"
278  << "Alignable label " << aliLabel << " not in map.";
279  return 0;
280  }
281 }
282 
284 {
285  Alignable* ali = alignableFromLabel(label);
286  unsigned int firstLabel = alignableLabel(ali);
287  return (label-firstLabel)/theMaxNumParam;
288 }
289 
292 {
293  Alignable* ali = alignableFromLabel(label);
294 
295  AlignableToRunRangeRangeMap::const_iterator positionAli = theAlignableToRunRangeRangeMap.find(ali);
296  if (positionAli==theAlignableToRunRangeRangeMap.end())
297  return theOpenRunRange;
298 
299  unsigned int firstLabel = alignableLabel(ali);
300  unsigned int runRangeIndex = (label-firstLabel)/theParamInstanceOffset;
301  unsigned int paramNum = this->paramNumFromLabel(label);
302 
303  RunRangeParamMap::const_iterator positionParam = (*positionAli).second.find(paramNum);
304  if (positionParam==(*positionAli).second.end()) {
305  return theOpenRunRange;
306  }
307 
308  return positionParam->second[runRangeIndex];
309 }
310 
311 //__________________________________________________________________________________________________
312 std::vector<std::string> RunRangeDependentPedeLabeler::decompose(const std::string &s,
313  std::string::value_type delimiter) const
314 {
315  std::vector<std::string> result;
316 
317  std::string::size_type previousPos = 0;
318  while (true) {
319  const std::string::size_type delimiterPos = s.find(delimiter, previousPos);
320  if (delimiterPos == std::string::npos) {
321  result.push_back(s.substr(previousPos)); // until end
322  break;
323  }
324  result.push_back(s.substr(previousPos, delimiterPos - previousPos));
325  previousPos = delimiterPos + 1; // +1: skip delimiter
326  }
327 
328  return result;
329 }
330 
331 //__________________________________________________________________________________________________
332 std::vector<unsigned int> RunRangeDependentPedeLabeler::convertParamSel(const std::string &selString) const
333 {
334  std::vector<unsigned int> result;
335  for (std::string::size_type pos = 0; pos < selString.size(); ++pos) {
336  if (selString[pos]=='1') result.push_back(pos);
337  }
338  return result;
339 }
340 
342  AlignableMuon* aliMuon,
343  AlignableExtras *aliExtras,
344  const edm::ParameterSet &config)
345 {
346  static bool oldRunRangeSelectionWarning = false;
347 
349 
350  AlignmentParameterSelector selector(aliTracker, aliMuon, aliExtras);
351 
352  std::vector<char> paramSelDummy(6, '1');
353 
354  const std::vector<edm::ParameterSet> RunRangeSelectionVPSet =
355  config.getUntrackedParameter<std::vector<edm::ParameterSet> >("RunRangeSelection");
356 
357  for (std::vector<edm::ParameterSet>::const_iterator iter = RunRangeSelectionVPSet.begin();
358  iter != RunRangeSelectionVPSet.end();
359  ++iter) {
360 
361  const std::vector<std::string> tempRunRanges = (*iter).getParameter<std::vector<std::string> >("RunRanges");
362  if (tempRunRanges.size()==0) {
363  throw cms::Exception("BadConfig") << "@SUB=RunRangeDependentPedeLabeler::buildRunRangeDependencyMap\n"
364  << "RunRanges empty\n";
365  }
366 
369  long int temp;
370  for (std::vector<std::string>::const_iterator iRunRange = tempRunRanges.begin();
371  iRunRange != tempRunRanges.end();
372  ++iRunRange) {
373  if ((*iRunRange).find(':')==std::string::npos) {
374 
376  temp = strtol((*iRunRange).c_str(), 0, 0);
377  if (temp!=-1) first = temp;
378 
379  } else {
380 
381  if (!oldRunRangeSelectionWarning) {
382  edm::LogWarning("BadConfig") << "@SUB=RunRangeDependentPedeLabeler::buildRunRangeDependencyMap"
383  << "Config file contains old format for 'RunRangeSelection'. Only the start run\n"
384  << "number is used internally. The number of the last run is ignored and can be\n"
385  << "safely removed from the config file.\n";
386  oldRunRangeSelectionWarning = true;
387  }
388 
389  std::vector<std::string> tokens = edm::tokenize(*iRunRange, ":");
391  temp = strtol(tokens[0].c_str(), 0, 0);
392  if (temp!=-1) first = temp;
393 
394  }
395 
396  RunRanges.push_back(std::pair<cond::Time_t,cond::Time_t>(first, cond::timeTypeSpecs[cond::runnumber].endValue));
397  }
398 
399  for (unsigned int i = 0;i<RunRanges.size()-1;++i) {
400  RunRanges[i].second = RunRanges[i+1].first - 1;
401  if (RunRanges[i].first > RunRanges[i].second) {
402  throw cms::Exception("BadConfig") << "@SUB=RunRangeDependentPedeLabeler::buildRunRangeDependencyMap\n"
403  << "Inconsistency in 'RunRangeSelection' parameter set.";
404  }
405  }
406 
407  const std::vector<std::string> selStrings = (*iter).getParameter<std::vector<std::string> >("selector");
408  for (std::vector<std::string>::const_iterator iSel = selStrings.begin();
409  iSel != selStrings.end();
410  ++iSel) {
411  std::vector<std::string> decompSel(this->decompose(*iSel, ','));
412 
413  if (decompSel.size()!=2) {
414  throw cms::Exception("BadConfig") << "@SUB=RunRangeDependentPedeLabeler::buildRunRangeDependencyMap\n"
415  << *iSel <<" should have at least 2 ','-separated parts\n";
416  }
417 
418  std::vector<unsigned int> selParam = this->convertParamSel(decompSel[1]);
419  selector.clear();
420  selector.addSelection(decompSel[0], paramSelDummy);
421 
422  const std::vector<Alignable*> &alis = selector.selectedAlignables();
423  for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
424  iAli != alis.end();
425  ++iAli) {
426  for (std::vector<unsigned int>::const_iterator iParam = selParam.begin();
427  iParam != selParam.end();
428  ++iParam) {
429  AlignableToRunRangeRangeMap::const_iterator positionAli = theAlignableToRunRangeRangeMap.find(*iAli);
430  if (positionAli!=theAlignableToRunRangeRangeMap.end()) {
431 
432  AlignmentParameters *AliParams = (*positionAli).first->alignmentParameters();
433  if (static_cast<int>(selParam[selParam.size()-1]) >= AliParams->size()) {
434  throw cms::Exception("BadConfig") << "@SUB=RunRangeDependentPedeLabeler::buildRunRangeDependencyMap\n"
435  << "mismatch in number of parameters\n";
436  }
437 
438  RunRangeParamMap::const_iterator positionParam = (*positionAli).second.find(*iParam);
439  if (positionParam!=(*positionAli).second.end()) {
440  throw cms::Exception("BadConfig") << "@SUB=RunRangeDependentPedeLabeler::buildRunRangeDependencyMap\n"
441  << "RunRange range for parameter specified twice\n";
442  }
443  }
444 
445  theAlignableToRunRangeRangeMap[*iAli][*iParam] = RunRanges;
446  }
447  }
448  }
449  }
450 
451  return theAlignableToRunRangeRangeMap.size();
452 }
453 
454 //_________________________________________________________________________
455 unsigned int RunRangeDependentPedeLabeler::buildMap(const std::vector<Alignable*> &alis)
456 {
457  theAlignableToIdMap.clear(); // just in case of re-use...
458 
459  std::vector<Alignable*> allComps;
460 
461  for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
462  if (*iAli) {
463  allComps.push_back(*iAli);
464  (*iAli)->recursiveComponents(allComps);
465  }
466  }
467 
468  unsigned int id = theMinLabel;
469  for (std::vector<Alignable*>::const_iterator iter = allComps.begin();
470  iter != allComps.end(); ++iter) {
471  theAlignableToIdMap.insert(AlignableToIdPair(*iter, id));
472  id += theMaxNumParam;
473  }
474 
475  // also care about las beams
476  theLasBeamToLabelMap.clear(); // just in case of re-use...
477  // FIXME: Temporarily hard code values stolen from
478  // https://twiki.cern.ch/twiki/bin/view/CMS/TkLasTrackBasedInterface#Beam_identifier .
479  unsigned int beamIds[] = { 0, 10, 20, 30, 40, 50, 60, 70, // TEC+ R4
480  1, 11, 21, 31, 41, 51, 61, 71, // TEC+ R6
481  100, 110, 120, 130, 140, 150, 160, 170, // TEC- R4
482  101, 111, 121, 131, 141, 151, 161, 171, // TEC- R6
483  200, 210, 220, 230, 240, 250, 260, 270};// AT
484 
485  const size_t nBeams = sizeof(beamIds)/sizeof(beamIds[0]);
486  for (size_t iBeam = 0; iBeam < nBeams; ++iBeam) {
487  //edm::LogInfo("Alignment") << "Las beam " << beamIds[iBeam] << " gets label " << id << ".";
488  theLasBeamToLabelMap[beamIds[iBeam]] = id;
489  id += theMaxNumParam;
490  }
491 
492  // return combined size
493  return theAlignableToIdMap.size() + theLasBeamToLabelMap.size();
494 }
495 
496 //_________________________________________________________________________
498 {
499 
500  // alignables
501  theIdToAlignableMap.clear(); // just in case of re-use...
502 
503  for (AlignableToIdMap::iterator it = theAlignableToIdMap.begin();
504  it != theAlignableToIdMap.end(); ++it) {
505  const unsigned int key = (*it).second;
506  Alignable *ali = (*it).first;
507  const unsigned int nInstances = this->numberOfParameterInstances(ali, -1);
508  for (unsigned int iInstance=0;iInstance<nInstances;++iInstance) {
509  theIdToAlignableMap[key+iInstance*theParamInstanceOffset] = ali;
510  }
511  }
512 
513  // las beams
514  theLabelToLasBeamMap.clear(); // just in case of re-use...
515 
516  for (UintUintMap::const_iterator it = theLasBeamToLabelMap.begin();
517  it != theLasBeamToLabelMap.end(); ++it) {
518  theLabelToLasBeamMap[it->second] = it->first; //revert key/value
519  }
520 
521  // return combined size
522  return theIdToAlignableMap.size() + theLabelToLasBeamMap.size();
523 }
524 
RunNumber_t run() const
Definition: EventID.h:42
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
unsigned int lasBeamLabel(unsigned int lasBeamId) const
AlignableToIdMap::value_type AlignableToIdPair
UintUintMap theLabelToLasBeamMap
labels for las beams
unsigned int lasBeamIdFromLabel(unsigned int label) const
AlignmentAlgorithmBase::RunRange RunRange
Time_t beginValue
Definition: Time.h:45
unsigned int alignableLabel(Alignable *alignable) const
Return 32-bit unique label for alignable, 0 indicates failure.
static PFTauRenderPlugin instance
Alignable * alignableFromLabel(unsigned int label) const
static const unsigned int theMinLabel
uint16_t size_type
unsigned int numberOfParameterInstances(Alignable *alignable, int param=-1) const
returns the number of instances for a given parameter
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
const RunRange theOpenRunRange
static const unsigned int theMaxNumParam
U second(std::pair< T, U > const &p)
unsigned int alignableLabelFromLabel(unsigned int label) const
alignable label from parameter label (works also for alignable label...)
void clear()
remove all selected Alignables and geometrical restrictions
unsigned long long Time_t
Definition: Time.h:16
unsigned int buildReverseMap()
returns size of map
const T & max(const T &a, const T &b)
unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const
tuple result
Definition: query.py:137
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
AlignableToRunRangeRangeMap theAlignableToRunRangeRangeMap
providing unique ID for alignable, space for param IDs
unsigned int offset(bool)
bool first
Definition: L1TdeRCT.cc:94
Container::value_type value_type
IdToAlignableMap theIdToAlignableMap
providing unique ID for alignable, space for param IDs
Alignables components() const
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
Definition: DetId.h:20
unsigned int runRangeIndexFromLabel(unsigned int label) const
const RunRange & runRangeFromLabel(unsigned int label) const
int size(void) const
Get number of parameters.
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator
Definition: Parse.cc:57
UintUintMap theLasBeamToLabelMap
reverse map
static const unsigned int theParamInstanceOffset
std::vector< RunRange > RunRanges
std::vector< Alignable * > Alignables
Definition: Utilities.h:28
unsigned int addSelection(const std::string &name, const std::vector< char > &paramSel)
unsigned int buildRunRangeDependencyMap(AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *extras, const edm::ParameterSet &config)
RunRangeDependentPedeLabeler(const PedeLabelerBase::TopLevelAlignables &alignables, const edm::ParameterSet &config)
constructor from three Alignables (null pointers allowed )
list key
Definition: combine.py:13
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const
returns the label for a given alignable parameter number combination
unsigned int paramNumFromLabel(unsigned int paramLabel) const
parameter number, 0 &lt;= .. &lt; theMaxNumParam, belonging to unique parameter label
std::vector< unsigned int > convertParamSel(const std::string &selString) const
Constructor of the full muon geometry.
Definition: AlignableMuon.h:36
bool hasSplitParameters(Alignable *alignable) const
returns true if the alignable has parameters that are split into various bins
unsigned int buildMap(const std::vector< Alignable * > &alis)
returns size of map
std::vector< std::string > decompose(const std::string &s, std::string::value_type delimiter) const
define event information passed to algorithms