Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:37

0001 /** \file PedeLabelerBase.cc
0002  *
0003  * Baseclass for pede labelers
0004  *
0005  *  Original author: Andreas Mussgiller, January 2011
0006  *
0007  *  $Date: 2011/02/23 16:58:34 $
0008  *  $Revision: 1.3 $
0009  *  (last update by $Author: mussgill $)
0010  */
0011 
0012 #include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerBase.h"
0013 
0014 #include "Alignment/CommonAlignmentParametrization/interface/RigidBodyAlignmentParameters.h"
0015 #include "Alignment/CommonAlignmentAlgorithm/interface/IntegratedCalibrationBase.h"
0016 
0017 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0018 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
0019 
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 
0022 // NOTE: Changing '+14' makes older binary files unreadable...
0023 const unsigned int PedeLabelerBase::theMaxNumParam = RigidBodyAlignmentParameters::N_PARAM + 14;
0024 // NOTE: Changing the offset of '700000' makes older binary files unreadable...
0025 const unsigned int PedeLabelerBase::theParamInstanceOffset = 700000;
0026 const unsigned int PedeLabelerBase::theMinLabel = 1;  // must be > 0
0027 
0028 PedeLabelerBase::PedeLabelerBase(const TopLevelAlignables &alignables, const edm::ParameterSet &config)
0029     : theOpenRunRange(std::make_pair<RunNumber, RunNumber>(
0030           RunNumber(cond::timeTypeSpecs[cond::runnumber].beginValue),  // since we know we have a runnumber here, we can
0031           RunNumber(
0032               cond::timeTypeSpecs[cond::runnumber].endValue))),  // simply convert the Time_t to make the compiler happy
0033       topLevelAlignables_(alignables),
0034       alignableObjectId_{AlignableObjectId::commonObjectIdProvider(alignables.aliTracker_, alignables.aliMuon_)} {}
0035 
0036 //___________________________________________________________________________
0037 std::pair<IntegratedCalibrationBase *, unsigned int> PedeLabelerBase::calibrationParamFromLabel(
0038     unsigned int label) const {
0039   // Quick check whether label is in range of calibration labels:
0040   if (!theCalibrationLabels.empty() && label >= theCalibrationLabels.front().second) {
0041     // Loop on all known IntegratedCalibration's:
0042     for (auto iCal = theCalibrationLabels.begin(); iCal != theCalibrationLabels.end(); ++iCal) {
0043       if (label >= iCal->second && label < iCal->second + iCal->first->numParameters()) {
0044         // Label fits in range for this calibration, so return calibration
0045         // and subtract first label of this calibration from label.
0046         return std::make_pair(iCal->first, label - iCal->second);
0047       }
0048     }
0049     edm::LogError("LogicError") << "@SUB=PedeLabelerBase::calibrationParamFromLabel"
0050                                 << "Label " << label << "larger than first calibration's label, "
0051                                 << "but no calibration fits!";
0052   }
0053 
0054   // Return that nothing fits:
0055   return std::pair<IntegratedCalibrationBase *, unsigned int>(nullptr, 0);
0056 }
0057 
0058 //___________________________________________________________________________
0059 unsigned int PedeLabelerBase::firstFreeLabel() const {
0060   unsigned int nextId = this->firstNonAlignableLabel();
0061 
0062   for (auto iCal = theCalibrationLabels.begin(); iCal != theCalibrationLabels.end(); ++iCal) {
0063     nextId += iCal->first->numParameters();
0064   }
0065 
0066   return nextId;
0067 }
0068 
0069 //___________________________________________________________________________
0070 unsigned int PedeLabelerBase::firstNonAlignableLabel() const {
0071   return this->parameterInstanceOffset() * this->maxNumberOfParameterInstances() + 1;
0072 }
0073 
0074 //___________________________________________________________________________
0075 unsigned int PedeLabelerBase::calibrationLabel(const IntegratedCalibrationBase *calib, unsigned int paramNum) const {
0076   if (!calib) {
0077     throw cms::Exception("LogicError") << "PedeLabelerBase::calibrationLabel: "
0078                                        << "nullPtr passed!\n";
0079   }
0080 
0081   // loop on all known IntegratedCalibration's
0082   for (auto iCal = theCalibrationLabels.begin(); iCal != theCalibrationLabels.end(); ++iCal) {
0083     if (iCal->first == calib) {  // found IntegratedCalibrationBase
0084       if (paramNum < iCal->first->numParameters()) {
0085         return iCal->second + paramNum;
0086       } else {  // paramNum out of range!
0087         edm::LogError("LogicError") << "@SUB=PedeLabelerBase::calibrationLabel"
0088                                     << "IntegratedCalibration " << calib->name() << " has only "
0089                                     << iCal->first->numParameters() << " parameters, but " << paramNum << "requested!";
0090       }
0091     }
0092   }
0093 
0094   edm::LogError("LogicError") << "@SUB=PedeLabelerBase::calibrationLabel"
0095                               << "IntegratedCalibration " << calib->name() << " not known or too few parameters.";
0096 
0097   return 0;
0098 }
0099 
0100 //___________________________________________________________________________
0101 void PedeLabelerBase::addCalibrations(const std::vector<IntegratedCalibrationBase *> &iCals) {
0102   unsigned int nextId = this->firstFreeLabel();  // so far next free label
0103 
0104   // Now foresee labels for new calibrations:
0105   for (auto iCal = iCals.begin(); iCal != iCals.end(); ++iCal) {
0106     if (*iCal) {
0107       theCalibrationLabels.push_back(std::make_pair(*iCal, nextId));
0108       nextId += (*iCal)->numParameters();
0109     } else {
0110       edm::LogError("LogicError") << "@SUB=PedeLabelerBase::addCalibrations"
0111                                   << "Ignoring nullPtr.";
0112     }
0113   }
0114 }