CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Alignment/MillePedeAlignmentAlgorithm/src/PedeLabelerBase.cc

Go to the documentation of this file.
00001 
00012 #include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerBase.h"
00013 
00014 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
00015 #include "Alignment/CommonAlignmentAlgorithm/interface/IntegratedCalibrationBase.h"
00016 
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 
00019 // NOTE: Changing '+14' makes older binary files unreadable...
00020 const unsigned int PedeLabelerBase::theMaxNumParam = RigidBodyAlignmentParameters::N_PARAM + 14;
00021 // NOTE: Changing the offset of '700000' makes older binary files unreadable...
00022 const unsigned int PedeLabelerBase::theParamInstanceOffset = 700000;
00023 const unsigned int PedeLabelerBase::theMinLabel = 1; // must be > 0
00024 
00025 PedeLabelerBase::PedeLabelerBase(const TopLevelAlignables &alignables,
00026                                  const edm::ParameterSet &config)
00027   :theOpenRunRange(std::make_pair<RunNumber,RunNumber>(cond::timeTypeSpecs[cond::runnumber].beginValue,
00028                                                        cond::timeTypeSpecs[cond::runnumber].endValue))
00029 {
00030   
00031 }
00032 
00033 //___________________________________________________________________________
00034 std::pair<IntegratedCalibrationBase*, unsigned int>
00035 PedeLabelerBase::calibrationParamFromLabel(unsigned int label) const
00036 {
00037   // Quick check whether label is in range of calibration labels:
00038   if (!theCalibrationLabels.empty() && label >= theCalibrationLabels.front().second) {
00039     // Loop on all known IntegratedCalibration's:
00040     for (auto iCal = theCalibrationLabels.begin(); iCal != theCalibrationLabels.end(); ++iCal) {
00041       if (label >= iCal->second && label < iCal->second + iCal->first->numParameters()) {
00042         // Label fits in range for this calibration, so return calibration
00043         // and subtract first label of this calibration from label.
00044         return std::make_pair(iCal->first, label - iCal->second);
00045       }
00046     }
00047     edm::LogError("LogicError") << "@SUB=PedeLabelerBase::calibrationParamFromLabel"
00048                                 << "Label " << label << "larger than first calibration's label, "
00049                                 << "but no calibration fits!";
00050   }
00051 
00052   // Return that nothing fits:
00053   return std::pair<IntegratedCalibrationBase*, unsigned int>(0,0);
00054 }
00055 
00056 //___________________________________________________________________________
00057 unsigned int PedeLabelerBase::firstFreeLabel() const
00058 {
00059   unsigned int nextId = this->firstNonAlignableLabel();
00060 
00061   for (auto iCal = theCalibrationLabels.begin(); iCal != theCalibrationLabels.end(); ++iCal) {
00062     nextId += iCal->first->numParameters();
00063   }
00064 
00065   return nextId;
00066 }
00067 
00068 //___________________________________________________________________________
00069 unsigned int PedeLabelerBase::firstNonAlignableLabel() const
00070 {
00071   
00072   return this->parameterInstanceOffset() * this->maxNumberOfParameterInstances() + 1;
00073 }
00074 
00075 //___________________________________________________________________________
00076 unsigned int PedeLabelerBase::calibrationLabel(const IntegratedCalibrationBase* calib,
00077                                                unsigned int paramNum) const
00078 {
00079   if (!calib) {
00080     throw cms::Exception("LogicError") << "PedeLabelerBase::calibrationLabel: "
00081                                        << "nullPtr passed!\n";
00082   }
00083 
00084   // loop on all known IntegratedCalibration's
00085   for (auto iCal = theCalibrationLabels.begin(); iCal != theCalibrationLabels.end(); ++iCal) {
00086     if (iCal->first == calib) { // found IntegratedCalibrationBase
00087       if (paramNum < iCal->first->numParameters()) {
00088         return iCal->second + paramNum;
00089       } else { // paramNum out of range!
00090         edm::LogError("LogicError")
00091           << "@SUB=PedeLabelerBase::calibrationLabel" << "IntegratedCalibration "
00092           << calib->name() << " has only " << iCal->first->numParameters()
00093           << " parameters, but " << paramNum << "requested!";
00094       }
00095     }
00096   }
00097   
00098   edm::LogError("LogicError")
00099     << "@SUB=PedeLabelerBase::calibrationLabel" << "IntegratedCalibration "
00100     << calib->name() << " not known or too few parameters.";
00101   
00102   return 0;
00103 }
00104 
00105 //___________________________________________________________________________
00106 void PedeLabelerBase::addCalibrations(const std::vector<IntegratedCalibrationBase*> &iCals)
00107 {
00108   unsigned int nextId = this->firstFreeLabel(); // so far next free label
00109 
00110   // Now foresee labels for new calibrations:
00111   for (auto iCal = iCals.begin(); iCal != iCals.end(); ++iCal) {
00112     if (*iCal) {
00113       theCalibrationLabels.push_back(std::make_pair(*iCal, nextId));
00114       nextId += (*iCal)->numParameters();
00115     } else {
00116       edm::LogError("LogicError")
00117         << "@SUB=PedeLabelerBase::addCalibrations" << "Ignoring nullPtr.";
00118     }
00119   }
00120 }