Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:45:13

0001 /**
0002  * \file PedeLabeler.cc
0003  *
0004  *  \author    : Gero Flucke
0005  *  date       : October 2006
0006  *  $Revision: 1.7 $
0007  *  $Date: 2010/10/26 20:49:42 $
0008  *  (last update by $Author: flucke $)
0009  */
0010 
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include "Alignment/CommonAlignment/interface/Alignable.h"
0014 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0015 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
0016 #include "Alignment/CommonAlignment/interface/AlignableExtras.h"
0017 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
0018 
0019 #include "PedeLabeler.h"
0020 
0021 //___________________________________________________________________________
0022 PedeLabeler::PedeLabeler(const PedeLabelerBase::TopLevelAlignables& alignables, const edm::ParameterSet& config)
0023     : PedeLabelerBase(alignables, config) {
0024   align::Alignables alis;
0025   alis.push_back(alignables.aliTracker_);
0026   alis.push_back(alignables.aliMuon_);
0027 
0028   if (alignables.aliExtras_) {
0029     for (const auto& ali : alignables.aliExtras_->components()) {
0030       alis.push_back(ali);
0031     }
0032   }
0033 
0034   this->buildMap(alis);
0035   this->buildReverseMap();
0036 }
0037 
0038 //___________________________________________________________________________
0039 PedeLabeler::~PedeLabeler() {}
0040 
0041 //___________________________________________________________________________
0042 /// Return 32-bit unique label for alignable, 0 indicates failure.
0043 unsigned int PedeLabeler::alignableLabel(Alignable* alignable) const {
0044   if (!alignable)
0045     return 0;
0046 
0047   AlignableToIdMap::const_iterator position = theAlignableToIdMap.find(alignable);
0048   if (position != theAlignableToIdMap.end()) {
0049     return position->second;
0050   } else {
0051     const DetId detId(alignable->id());
0052     //throw cms::Exception("LogicError")
0053     edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableLabel"
0054                                 << "Alignable " << typeid(*alignable).name()
0055                                 << " not in map, det/subdet/alignableStructureType = " << detId.det() << "/"
0056                                 << detId.subdetId() << "/" << alignable->alignableObjectId();
0057     return 0;
0058   }
0059 }
0060 
0061 //___________________________________________________________________________
0062 // Return 32-bit unique label for alignable, 0 indicates failure.
0063 unsigned int PedeLabeler::alignableLabelFromParamAndInstance(Alignable* alignable,
0064                                                              unsigned int /*param*/,
0065                                                              unsigned int /*instance*/) const {
0066   return this->alignableLabel(alignable);
0067 }
0068 
0069 //_________________________________________________________________________
0070 unsigned int PedeLabeler::lasBeamLabel(unsigned int lasBeamId) const {
0071   UintUintMap::const_iterator position = theLasBeamToLabelMap.find(lasBeamId);
0072   if (position != theLasBeamToLabelMap.end()) {
0073     return position->second;
0074   } else {
0075     //throw cms::Exception("LogicError")
0076     edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamLabel"
0077                                 << "No label for beam Id " << lasBeamId;
0078     return 0;
0079   }
0080 }
0081 
0082 //_________________________________________________________________________
0083 unsigned int PedeLabeler::parameterLabel(unsigned int aliLabel, unsigned int parNum) const {
0084   if (parNum >= theMaxNumParam) {
0085     throw cms::Exception("Alignment") << "@SUB=PedeLabeler::parameterLabel"
0086                                       << "Parameter number " << parNum << " out of range 0 <= num < " << theMaxNumParam;
0087   }
0088   return aliLabel + parNum;
0089 }
0090 
0091 //___________________________________________________________________________
0092 unsigned int PedeLabeler::paramNumFromLabel(unsigned int paramLabel) const {
0093   if (paramLabel < theMinLabel) {
0094     edm::LogError("LogicError") << "@SUB=PedeLabeler::paramNumFromLabel"
0095                                 << "Label " << paramLabel << " should be >= " << theMinLabel;
0096     return 0;
0097   }
0098   return (paramLabel - theMinLabel) % theMaxNumParam;
0099 }
0100 
0101 //___________________________________________________________________________
0102 unsigned int PedeLabeler::alignableLabelFromLabel(unsigned int paramLabel) const {
0103   return paramLabel - this->paramNumFromLabel(paramLabel);
0104 }
0105 
0106 //___________________________________________________________________________
0107 Alignable* PedeLabeler::alignableFromLabel(unsigned int label) const {
0108   const unsigned int aliLabel = this->alignableLabelFromLabel(label);
0109   if (aliLabel < theMinLabel)
0110     return nullptr;  // error already given
0111 
0112   IdToAlignableMap::const_iterator position = theIdToAlignableMap.find(aliLabel);
0113   if (position != theIdToAlignableMap.end()) {
0114     return position->second;
0115   } else {
0116     // error only if not in lasBeamMap:
0117     UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
0118     if (position == theLabelToLasBeamMap.end()) {
0119       edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableFromLabel"
0120                                   << "Alignable label " << aliLabel << " not in map.";
0121     }
0122     return nullptr;
0123   }
0124 }
0125 
0126 //___________________________________________________________________________
0127 unsigned int PedeLabeler::lasBeamIdFromLabel(unsigned int label) const {
0128   const unsigned int aliLabel = this->alignableLabelFromLabel(label);
0129   if (aliLabel < theMinLabel)
0130     return 0;  // error already given
0131 
0132   UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
0133   if (position != theLabelToLasBeamMap.end()) {
0134     return position->second;
0135   } else {
0136     edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamIdFromLabel"
0137                                 << "Alignable label " << aliLabel << " not in map.";
0138     return 0;
0139   }
0140 }
0141 
0142 //_________________________________________________________________________
0143 unsigned int PedeLabeler::buildMap(const align::Alignables& alis) {
0144   theAlignableToIdMap.clear();  // just in case of re-use...
0145 
0146   align::Alignables allComps;
0147 
0148   for (const auto& iAli : alis) {
0149     if (iAli) {
0150       allComps.push_back(iAli);
0151       iAli->recursiveComponents(allComps);
0152     }
0153   }
0154 
0155   unsigned int id = theMinLabel;
0156   for (const auto& iter : allComps) {
0157     theAlignableToIdMap.insert(AlignableToIdPair(iter, id));
0158     id += theMaxNumParam;
0159   }
0160 
0161   // also care about las beams
0162   theLasBeamToLabelMap.clear();  // just in case of re-use...
0163   // FIXME: Temporarily hard code values stolen from
0164   // https://twiki.cern.ch/twiki/bin/view/CMS/TkLasTrackBasedInterface#Beam_identifier .
0165   unsigned int beamIds[] = {0,   10,  20,  30,  40,  50,  60,  70,    // TEC+ R4
0166                             1,   11,  21,  31,  41,  51,  61,  71,    // TEC+ R6
0167                             100, 110, 120, 130, 140, 150, 160, 170,   // TEC- R4
0168                             101, 111, 121, 131, 141, 151, 161, 171,   // TEC- R6
0169                             200, 210, 220, 230, 240, 250, 260, 270};  // AT
0170 
0171   const size_t nBeams = sizeof(beamIds) / sizeof(beamIds[0]);
0172   for (size_t iBeam = 0; iBeam < nBeams; ++iBeam) {
0173     //edm::LogInfo("Alignment") << "Las beam " << beamIds[iBeam] << " gets label " << id << ".";
0174     theLasBeamToLabelMap[beamIds[iBeam]] = id;
0175     id += theMaxNumParam;
0176   }
0177 
0178   // return combined size
0179   return theAlignableToIdMap.size() + theLasBeamToLabelMap.size();
0180 }
0181 
0182 //_________________________________________________________________________
0183 unsigned int PedeLabeler::buildReverseMap() {
0184   // alignables
0185   theIdToAlignableMap.clear();  // just in case of re-use...
0186 
0187   for (const auto& it : theAlignableToIdMap) {
0188     theIdToAlignableMap[it.second] = it.first;
0189   }
0190 
0191   // las beams
0192   theLabelToLasBeamMap.clear();  // just in case of re-use...
0193 
0194   for (const auto& it : theLasBeamToLabelMap) {
0195     theLabelToLasBeamMap[it.second] = it.first;  //revert key/value
0196   }
0197 
0198   // return combined size
0199   return theIdToAlignableMap.size() + theLabelToLasBeamMap.size();
0200 }
0201 
0202 #include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerPluginFactory.h"
0203 DEFINE_EDM_PLUGIN(PedeLabelerPluginFactory, PedeLabeler, "PedeLabeler");