CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Alignment/MillePedeAlignmentAlgorithm/src/PedeLabeler.cc

Go to the documentation of this file.
00001 
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 
00013 #include "Alignment/CommonAlignment/interface/Alignable.h"
00014 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00015 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
00016 #include "Alignment/CommonAlignment/interface/AlignableExtras.h"
00017 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
00018 
00019 #include "PedeLabeler.h"
00020 
00021 //___________________________________________________________________________
00022 PedeLabeler::PedeLabeler(const PedeLabelerBase::TopLevelAlignables& alignables,
00023                          const edm::ParameterSet& config)
00024   :PedeLabelerBase(alignables, config)
00025 {
00026   std::vector<Alignable*> alis;
00027   alis.push_back(alignables.aliTracker_);
00028   alis.push_back(alignables.aliMuon_);
00029 
00030   if (alignables.aliExtras_) {
00031     align::Alignables allExtras = alignables.aliExtras_->components();
00032     for ( std::vector<Alignable*>::iterator it = allExtras.begin(); it != allExtras.end(); ++it ) {
00033       alis.push_back(*it);
00034     }
00035   }
00036 
00037   this->buildMap(alis);
00038 }
00039 
00040 //___________________________________________________________________________
00041 PedeLabeler::~PedeLabeler()
00042 {
00043 }
00044 
00045 //___________________________________________________________________________
00047 unsigned int PedeLabeler::alignableLabel(Alignable *alignable) const
00048 {
00049   if (!alignable) return 0;
00050 
00051   AlignableToIdMap::const_iterator position = theAlignableToIdMap.find(alignable);
00052   if (position != theAlignableToIdMap.end()) {
00053     return position->second;
00054   } else {
00055     const DetId detId(alignable->id());
00056     //throw cms::Exception("LogicError") 
00057     edm::LogError("LogicError")
00058       << "@SUB=PedeLabeler::alignableLabel" << "Alignable "
00059       << typeid(*alignable).name() << " not in map, det/subdet/alignableStructureType = "
00060       << detId.det() << "/" << detId.subdetId() << "/" << alignable->alignableObjectId();
00061     return 0;
00062   }
00063 }
00064 
00065 //___________________________________________________________________________
00066 // Return 32-bit unique label for alignable, 0 indicates failure.
00067 unsigned int PedeLabeler::alignableLabelFromParamAndInstance(Alignable *alignable,
00068                                                              unsigned int /*param*/,
00069                                                              unsigned int /*instance*/) const
00070 {
00071   return this->alignableLabel(alignable);
00072 }
00073 
00074 //_________________________________________________________________________
00075 unsigned int PedeLabeler::lasBeamLabel(unsigned int lasBeamId) const
00076 {
00077   UintUintMap::const_iterator position = theLasBeamToLabelMap.find(lasBeamId);
00078   if (position != theLasBeamToLabelMap.end()) {
00079     return position->second;
00080   } else {
00081     //throw cms::Exception("LogicError") 
00082     edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamLabel"
00083                                 << "No label for beam Id " << lasBeamId;
00084     return 0;
00085   }
00086 }
00087 
00088 //_________________________________________________________________________
00089 unsigned int PedeLabeler::parameterLabel(unsigned int aliLabel, unsigned int parNum) const
00090 {
00091   if (parNum >= theMaxNumParam) {
00092     throw cms::Exception("Alignment") << "@SUB=PedeLabeler::parameterLabel" 
00093                                       << "Parameter number " << parNum 
00094                                       << " out of range 0 <= num < " << theMaxNumParam;
00095   }
00096   return aliLabel + parNum;
00097 }
00098 
00099 //___________________________________________________________________________
00100 unsigned int PedeLabeler::paramNumFromLabel(unsigned int paramLabel) const
00101 {
00102   if (paramLabel < theMinLabel) {
00103     edm::LogError("LogicError") << "@SUB=PedeLabeler::paramNumFromLabel"
00104                                 << "Label " << paramLabel << " should be >= " << theMinLabel;
00105     return 0;
00106   }
00107   return (paramLabel - theMinLabel) % theMaxNumParam;
00108 }
00109 
00110 //___________________________________________________________________________
00111 unsigned int PedeLabeler::alignableLabelFromLabel(unsigned int paramLabel) const
00112 {
00113   return paramLabel - this->paramNumFromLabel(paramLabel);
00114 }
00115 
00116 //___________________________________________________________________________
00117 Alignable* PedeLabeler::alignableFromLabel(unsigned int label) const
00118 {
00119   const unsigned int aliLabel = this->alignableLabelFromLabel(label);
00120   if (aliLabel < theMinLabel) return 0; // error already given
00121   
00122   if (theIdToAlignableMap.empty()) const_cast<PedeLabeler*>(this)->buildReverseMap();
00123   IdToAlignableMap::const_iterator position = theIdToAlignableMap.find(aliLabel);
00124   if (position != theIdToAlignableMap.end()) {
00125     return position->second;
00126   } else {
00127     // error only if not in lasBeamMap:
00128     UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
00129     if (position == theLabelToLasBeamMap.end()) {
00130       edm::LogError("LogicError") << "@SUB=PedeLabeler::alignableFromLabel"
00131                                   << "Alignable label " << aliLabel << " not in map.";
00132     }
00133     return 0;
00134   }
00135 }
00136 
00137 //___________________________________________________________________________
00138 unsigned int PedeLabeler::lasBeamIdFromLabel(unsigned int label) const
00139 {
00140   const unsigned int aliLabel = this->alignableLabelFromLabel(label);
00141   if (aliLabel < theMinLabel) return 0; // error already given
00142   
00143   if (theLabelToLasBeamMap.empty()) const_cast<PedeLabeler*>(this)->buildReverseMap();
00144   UintUintMap::const_iterator position = theLabelToLasBeamMap.find(aliLabel);
00145   if (position != theLabelToLasBeamMap.end()) {
00146     return position->second;
00147   } else {
00148     edm::LogError("LogicError") << "@SUB=PedeLabeler::lasBeamIdFromLabel"
00149                                 << "Alignable label " << aliLabel << " not in map.";
00150     return 0;
00151   }
00152 }
00153 
00154 //_________________________________________________________________________
00155 unsigned int PedeLabeler::buildMap(const std::vector<Alignable*> &alis)
00156 {
00157   theAlignableToIdMap.clear(); // just in case of re-use...
00158 
00159   std::vector<Alignable*> allComps;
00160 
00161   for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
00162     if (*iAli) {
00163       allComps.push_back(*iAli);
00164       (*iAli)->recursiveComponents(allComps);
00165     }
00166   }
00167 
00168   unsigned int id = theMinLabel;
00169   for (std::vector<Alignable*>::const_iterator iter = allComps.begin();
00170        iter != allComps.end(); ++iter) {
00171     theAlignableToIdMap.insert(AlignableToIdPair(*iter, id));
00172     id += theMaxNumParam;
00173   }
00174   
00175   // also care about las beams
00176   theLasBeamToLabelMap.clear(); // just in case of re-use...
00177   // FIXME: Temporarily hard code values stolen from 
00178   // https://twiki.cern.ch/twiki/bin/view/CMS/TkLasTrackBasedInterface#Beam_identifier .
00179   unsigned int beamIds[] = {  0,  10,  20,  30,  40,  50,  60,  70, // TEC+ R4
00180                               1,  11,  21,  31,  41,  51,  61,  71, // TEC+ R6
00181                             100, 110, 120, 130, 140, 150, 160, 170, // TEC- R4
00182                             101, 111, 121, 131, 141, 151, 161, 171, // TEC- R6
00183                             200, 210, 220, 230, 240, 250, 260, 270};// AT
00184 
00185   const size_t nBeams = sizeof(beamIds)/sizeof(beamIds[0]);
00186   for (size_t iBeam = 0; iBeam < nBeams; ++iBeam) {
00187     //edm::LogInfo("Alignment") << "Las beam " << beamIds[iBeam] << " gets label " << id << ".";
00188     theLasBeamToLabelMap[beamIds[iBeam]] = id;
00189     id += theMaxNumParam;
00190   }
00191 
00192   // return combined size
00193   return theAlignableToIdMap.size() + theLasBeamToLabelMap.size();
00194 }
00195 
00196 //_________________________________________________________________________
00197 unsigned int PedeLabeler::buildReverseMap()
00198 {
00199 
00200   // alignables
00201   theIdToAlignableMap.clear();  // just in case of re-use...
00202 
00203   for (AlignableToIdMap::iterator it = theAlignableToIdMap.begin();
00204        it != theAlignableToIdMap.end(); ++it) {
00205     const unsigned int key = (*it).second;
00206     Alignable *ali = (*it).first;
00207     theIdToAlignableMap[key] = ali;
00208   }
00209 
00210   // las beams
00211   theLabelToLasBeamMap.clear(); // just in case of re-use...
00212 
00213   for (UintUintMap::const_iterator it = theLasBeamToLabelMap.begin();
00214        it != theLasBeamToLabelMap.end(); ++it) {
00215     theLabelToLasBeamMap[it->second] = it->first; //revert key/value
00216   }
00217 
00218   // return combined size
00219   return theIdToAlignableMap.size() + theLabelToLasBeamMap.size();
00220 }
00221 
00222 #include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerPluginFactory.h"
00223 DEFINE_EDM_PLUGIN(PedeLabelerPluginFactory, PedeLabeler, "PedeLabeler");