92 theMode(this->decodeMode(theConfig.getUntrackedParameter<
std::
string>(
"mode"))),
93 theDir(theConfig.getUntrackedParameter<
std::
string>(
"fileDir")),
94 theAlignmentParameterStore(nullptr),
96 theMinNumHits(
cfg.getParameter<unsigned
int>(
"minNumHits")),
97 theMaximalCor2D(
cfg.getParameter<double>(
"max2Dcorrelation")),
99 ignoreFirstIOVCheck_(
cfg.getUntrackedParameter<
bool>(
"ignoreFirstIOVCheck")),
100 enableAlignableUpdates_(
cfg.getUntrackedParameter<
bool>(
"enableAlignableUpdates")),
101 theLastWrittenIov(0),
102 theGblDoubleBinary(
cfg.getParameter<
bool>(
"doubleBinary")),
103 runAtPCL_(
cfg.getParameter<
bool>(
"runAtPCL")),
104 ignoreHitsWithoutGlobalDerivatives_(
cfg.getParameter<
bool>(
"ignoreHitsWithoutGlobalDerivatives")),
105 skipGlobalPositionRcdCheck_(
cfg.getParameter<
bool>(
"skipGlobalPositionRcdCheck")),
108 enforceSingleIOVInput_(!(enableAlignableUpdates_ && areIOVsSpecified())),
112 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm"
114 <<
"' with output directory '" <<
theDir <<
"'.";
136 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
137 <<
"Running with AlignabeMuon not yet tested.";
147 std::ostringstream message;
149 if (iov_alignments.first().eventID().run() !=
MIN_VAL || iov_alignments.last().eventID().run() !=
MAX_VAL) {
151 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
152 <<
"Validity range is " << iov_alignments.first().eventID().run() <<
" - "
153 << iov_alignments.last().eventID().run() <<
"\n";
156 if (iov_surfaces.first().eventID().run() !=
MIN_VAL || iov_surfaces.last().eventID().run() !=
MAX_VAL) {
158 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
159 <<
"Validity range is " << iov_surfaces.first().eventID().run() <<
" - "
160 << iov_surfaces.last().eventID().run() <<
"\n";
163 if (iov_errors.first().eventID().run() !=
MIN_VAL || iov_errors.last().eventID().run() !=
MAX_VAL) {
165 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
166 <<
"Validity range is " << iov_errors.first().eventID().run() <<
" - "
167 << iov_errors.last().eventID().run() <<
"\n";
171 throw cms::Exception(
"DatabaseError") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize" << message.str();
194 if (!RunRangeSelectionVPSet.empty()) {
195 labelerPlugin =
"RunRangeDependentPedeLabeler";
196 if (pedeLabelerCfg.
exists(
"plugin")) {
198 if ((labelerPluginCfg !=
"PedeLabeler" && labelerPluginCfg !=
"RunRangeDependentPedeLabeler") ||
200 throw cms::Exception(
"BadConfig") <<
"MillePedeAlignmentAlgorithm::initialize"
201 <<
"both RunRangeSelection and generic labeler specified in config file. "
202 <<
"Please get rid of either one of them.\n";
206 if (pedeLabelerCfg.
exists(
"plugin")) {
211 if (!pedeLabelerCfg.
exists(
"plugin")) {
215 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
216 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
234 const std::vector<edm::ParameterSet> mprespset(
236 if (!mprespset.empty()) {
237 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
238 <<
"Apply " << mprespset.end() - mprespset.begin()
239 <<
" previous MillePede constants from 'pedeReaderInputs'.";
245 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end(); iSet != iE;
251 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
252 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
268 throw cms::Exception(
"BadConfig") <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
269 <<
"modes running mille.";
272 if (!moniFile.empty())
273 theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (
theDir + moniFile).c_str());
303 theThresholds->setAlignPCLThresholds(nRecords, thresholdMap);
351 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
352 <<
"Problems reading pede result, but applying!";
369 std::vector<std::string>
files;
373 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
378 filesForLogOutput +=
" " +
file +
",";
379 if (filesForLogOutput.length() != 0)
380 filesForLogOutput.pop_back();
381 edm::LogInfo(
"Alignment") <<
"Based on the config parameter mergeBinaryFiles, using the following "
382 <<
"files as input (assigned weights are indicated by ' -- <weight>'):"
383 << filesForLogOutput;
393 throw cms::Exception(
"BadConfig") <<
"@SUB=MillePedeAlignmentAlgorithm::terminate\n"
394 <<
"Last IOV of 'RunRangeSelection' has not been processed. "
395 <<
"Please reconfigure your source to process the runs at least up to "
400 const auto run = runRange.first;
423 const std::vector<std::string> &plainFiles,
const std::string &theDir) {
424 std::vector<std::string>
files;
425 for (
const auto &plainFile : plainFiles) {
431 char theNumberedInputFileName[200];
432 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
434 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
435 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
438 if (
stat(strippedInputFileName.c_str(), &
buffer) == 0) {
440 files.push_back(theCompleteInputFileName);
441 if (theNumberedInputFileName == theInputFileName) {
454 if (theNumber == 0 && (
files.empty() ||
files.back() != plainFile)) {
455 edm::LogWarning(
"Alignment") <<
"The input file '" << plainFile <<
"' does not exist.";
469 for (
const auto &iTrajTrack :
tracks) {
477 unsigned int refTrajCount = 0;
480 ++iRefTraj, ++refTrajCount) {
487 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
489 const auto offset = tracksPerTraj * refTrajCount;
490 for (
unsigned int iTrack = 0; iTrack < tracksPerTraj; ++iTrack) {
501 std::pair<unsigned int, unsigned int> hitResultXy(0, 0);
502 if (refTrajPtr->isValid()) {
504 if (!refTrajPtr->gblInput().empty()) {
506 unsigned int iHit = 0;
507 unsigned int numPointsWithMeas = 0;
508 std::vector<GblPoint>::iterator itPoint;
509 auto theGblInput = refTrajPtr->gblInput();
510 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
511 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end();
515 if (itPoint->hasMeasurement() >= 1)
519 hitResultXy.first = numPointsWithMeas;
521 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
524 if (refTrajPtr->gblInput().size() == 1) {
526 GblTrajectory aGblTrajectory(refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0);
534 if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >=
theMinNumHits)
537 if (refTrajPtr->gblInput().size() == 2) {
539 GblTrajectory aGblTrajectory(refTrajPtr->gblInput(),
540 refTrajPtr->gblExtDerivatives(),
541 refTrajPtr->gblExtMeasurements(),
542 refTrajPtr->gblExtPrecisions());
544 if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >=
theMinNumHits)
549 std::vector<AlignmentParameters *> parVec(refTrajPtr->recHits().size());
551 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
553 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
557 hitResultXy.first = 0;
562 validHitVecY[iHit] = (flagXY >= 2);
567 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
572 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
574 hitResultXy.first = hitResultXy.second = 0;
579 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
591 const std::vector<bool> &validHitVecY)
const {
593 unsigned int nHitY = 0;
594 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
595 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() :
nullptr);
606 if (validHitVecY[iHit]) {
608 if (pars == parVec[iHit])
621 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::beginRun\n"
622 <<
"Using data (run = " <<
run.run() <<
") prior to the first defined IOV ("
644 std::ostringstream message;
646 message <<
"Trying to cache tracker alignment payloads for a run (" <<
runNumber <<
") in an IOV (" <<
firstRun
647 <<
") that was already cached.\n"
648 <<
"The following records in your input database tag have an IOV "
649 <<
"boundary that does not match your IOV definition:\n";
650 if (geometryRcd.validityInterval().first().eventID().run() >
firstRun) {
651 message <<
" - IdealGeometryRecord '" << geometryRcd.key().name() <<
"' (since "
652 << geometryRcd.validityInterval().first().eventID().run() <<
")\n";
656 message <<
" - GlobalPositionRecord '" << globalPosRcd.
key().
name() <<
"' (since "
659 message <<
" --> ignored\n";
666 message <<
" - TrackerAlignmentRcd '" << alignmentRcd.
key().
name() <<
"' (since "
671 message <<
" - TrackerSurfaceDeformationRcd '" << surfaceRcd.
key().
name() <<
"' (since "
676 message <<
" - TrackerAlignmentErrorExtendedRcd '" << errorRcd.
key().
name() <<
"' (since "
682 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::beginRun\n" << message.str();
739 if (!recHitPtr->isValid())
779 GblPoint &gblPoint) {
781 std::vector<double> theDoubleBufferX, theDoubleBufferY;
782 theDoubleBufferX.clear();
783 theDoubleBufferY.clear();
790 if (!recHitPtr->isValid())
808 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
811 (*iCalib)->derivatives(derivs, *recHitPtr, tsos,
setup,
eventInfo);
812 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
814 globalLabel =
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
815 if (globalLabel > 0 && globalLabel <= 2147483647) {
817 theDoubleBufferX.push_back(iValuesInd->first.first);
818 theDoubleBufferY.push_back(iValuesInd->first.second);
820 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addGlobalData"
821 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
826 if (numGlobals > 0) {
827 Eigen::Matrix<double, 2, Eigen::Dynamic> globalDer{2, numGlobals};
828 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
829 globalDer(0,
i) = theDoubleBufferX[
i];
830 globalDer(1,
i) = theDoubleBufferY[
i];
843 std::vector<float> &globalDerivativesX,
844 std::vector<float> &globalDerivativesY,
845 std::vector<int> &globalLabels,
860 bool hasSplitParameters =
thePedeLabels->hasSplitParameters(ali);
861 const unsigned int alignableLabel =
thePedeLabels->alignableLabel(ali);
863 if (0 == alignableLabel) {
864 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
865 <<
"Label not found, skip Alignable.";
869 const std::vector<bool> &selPars =
params->selector();
873 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
876 if (hasSplitParameters ==
true) {
879 globalLabels.push_back(
thePedeLabels->parameterLabel(alignableLabel, iSel));
890 eventInfo, tsos, ali->
mother(), alidet, globalDerivativesX, globalDerivativesY, globalLabels, lowestParams);
898 std::vector<double> &globalDerivativesX,
899 std::vector<double> &globalDerivativesY,
900 std::vector<int> &globalLabels,
915 bool hasSplitParameters =
thePedeLabels->hasSplitParameters(ali);
916 const unsigned int alignableLabel =
thePedeLabels->alignableLabel(ali);
918 if (0 == alignableLabel) {
919 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
920 <<
"Label not found, skip Alignable.";
924 const std::vector<bool> &selPars =
params->selector();
929 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
931 if (hasSplitParameters ==
true) {
934 globalLabel =
thePedeLabels->parameterLabel(alignableLabel, iSel);
936 if (globalLabel > 0 && globalLabel <= 2147483647) {
937 globalLabels.push_back(globalLabel);
941 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
942 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
952 eventInfo, tsos, ali->
mother(), alidet, globalDerivativesX, globalDerivativesY, globalLabels, lowestParams);
960 std::vector<float> &globalDerivativesX,
961 std::vector<float> &globalDerivativesY,
962 std::vector<int> &globalLabels)
const {
963 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
967 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
969 globalLabels.push_back(
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
970 globalDerivativesX.push_back(iValuesInd->first.first);
971 globalDerivativesY.push_back(iValuesInd->first.second);
1014 if (
recHit->dimension() < 2) {
1016 }
else if (
recHit->detUnit()) {
1017 return recHit->detUnit()->type().isTrackerPixel();
1019 if (dynamic_cast<const ProjectedSiStripRecHit2D *>(
recHit->hit())) {
1036 bool okRead =
reader.read(alis, setUserVars);
1037 bool numMatch =
true;
1039 std::stringstream
out;
1040 out <<
"Read " << alis.size() <<
" alignables";
1046 out <<
", but problems in reading";
1048 out <<
", possibly overwriting previous settings";
1051 if (okRead && allEmpty) {
1053 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1054 }
else if (!alis.empty()) {
1055 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1057 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1063 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1069 for (
const auto &iAli : alignables) {
1072 const auto &parVec(
params->parameters());
1073 const auto &parCov(
params->covariance());
1074 for (
int i = 0;
i < parVec.num_row(); ++
i) {
1075 if (parVec[
i] != 0.)
1077 for (
int j =
i;
j < parCov.num_col(); ++
j) {
1078 if (parCov[
i][
j] != 0.)
1093 if (outFilePlain.empty()) {
1094 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1095 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
1106 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1107 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
1110 }
else if (
loop == 1) {
1112 const std::vector<std::string> inFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeTreeFiles"));
1113 const std::vector<std::string> binFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
1114 if (inFiles.size() != binFiles.size()) {
1115 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1116 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
1117 <<
"differ in size";
1124 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1125 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
1131 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1132 <<
"Problem " << ioerr <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
1137 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1138 <<
"Problem " << ioerr <<
" in writeAlignableAbsolutePositions, " <<
loop;
1147 for (
const auto &iAli : alis) {
1150 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
1151 <<
"No parameters for alignable";
1155 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
1166 thePedeLabels->alignableTracker()->objectIdProvider().typeToName(iAli->alignableObjectId()));
1167 params->setUserVariables(userVars);
1174 if (
mode ==
"full") {
1176 }
else if (
mode ==
"mille") {
1178 }
else if (
mode ==
"pede") {
1180 }
else if (
mode ==
"pedeSteer") {
1182 }
else if (
mode ==
"pedeRun") {
1184 }
else if (
mode ==
"pedeRead") {
1189 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
1197 const std::vector<std::string> &inFiles)
const {
1201 for (std::vector<std::string>::const_iterator iFile = inFiles.begin(); iFile != inFiles.end(); ++iFile) {
1203 const std::vector<AlignmentUserVariables *> mpVars =
1206 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1207 <<
"Error " << ierr <<
" reading from " << inFile <<
", tree " << fromIov
1208 <<
", or problems in addHits";
1211 for (std::vector<AlignmentUserVariables *>::const_iterator
i = mpVars.begin();
i != mpVars.end(); ++
i) {
1221 const std::vector<AlignmentUserVariables *> &mpVars)
const {
1222 bool allOk = (mpVars.size() == alis.size());
1223 std::vector<AlignmentUserVariables *>::const_iterator iUser = mpVars.begin();
1224 for (
auto iAli = alis.cbegin(); iAli != alis.cend() && iUser != mpVars.end(); ++iAli, ++iUser) {
1228 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1241 template <
typename GlobalDerivativeMatrix>
1243 const std::vector<float> &globalDerivativesy,
1244 Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM) {
1245 static_assert(GlobalDerivativeMatrix::RowsAtCompileTime == 2,
"global derivative matrix must have two rows");
1247 for (
size_t i = 0;
i < globalDerivativesx.size(); ++
i) {
1248 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1249 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1255 typename LocalDerivativeMatrix,
1256 typename ResidualMatrix,
1257 typename GlobalDerivativeMatrix>
1259 Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM,
1260 Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1261 Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM)
const {
1263 "'aLocalDerivativesM' and 'aHitResidualsM' must have the "
1264 "same underlying scalar type");
1266 "'aLocalDerivativesM' and 'aGlobalDerivativesM' must have the "
1267 "same underlying scalar type");
1269 Eigen::SelfAdjointEigenSolver<typename CovarianceMatrix::PlainObject> myDiag{aHitCovarianceM};
1271 auto aTranfoToDiagonalSystemInv =
1272 myDiag.eigenvectors().transpose().template cast<typename LocalDerivativeMatrix::Scalar>();
1274 aHitCovarianceM = myDiag.eigenvalues().asDiagonal();
1275 aLocalDerivativesM = aTranfoToDiagonalSystemInv * aLocalDerivativesM;
1276 aHitResidualsM = aTranfoToDiagonalSystemInv * aHitResidualsM;
1277 if (aGlobalDerivativesM.size() > 0) {
1279 aGlobalDerivativesM = aTranfoToDiagonalSystemInv * aGlobalDerivativesM;
1284 template <
typename CovarianceMatrix,
typename Res
idualMatrix,
typename LocalDerivativeMatrix>
1287 unsigned int iVirtualMeas,
1288 Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
1289 Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1290 Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM) {
1293 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1295 aHitCovarianceM(0, 0) = refTrajPtr->measurementErrors()[xIndex][xIndex];
1296 aHitResidualsM(0, 0) = refTrajPtr->measurements()[xIndex];
1298 const auto &locDerivMatrix = refTrajPtr->derivatives();
1299 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1300 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1305 template <
typename CovarianceMatrix,
typename Res
idualMatrix,
typename LocalDerivativeMatrix>
1307 unsigned int iTrajHit,
1308 Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
1309 Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1310 Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM) {
1313 const unsigned int xIndex = iTrajHit * 2;
1314 const unsigned int yIndex = iTrajHit * 2 + 1;
1316 aHitCovarianceM(0, 0) = refTrajPtr->measurementErrors()[xIndex][xIndex];
1317 aHitCovarianceM(0, 1) = refTrajPtr->measurementErrors()[xIndex][yIndex];
1318 aHitCovarianceM(1, 0) = refTrajPtr->measurementErrors()[yIndex][xIndex];
1319 aHitCovarianceM(1, 1) = refTrajPtr->measurementErrors()[yIndex][yIndex];
1321 aHitResidualsM(0, 0) = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1322 aHitResidualsM(1, 0) = refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1324 const auto &locDerivMatrix = refTrajPtr->derivatives();
1325 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1326 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1327 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1333 unsigned int iTrajHit,
1334 const std::vector<int> &globalLabels,
1335 const std::vector<float> &globalDerivativesX,
1336 const std::vector<float> &globalDerivativesY) {
1339 if ((aRecHit)->dimension() == 1) {
1340 return this->
callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1342 return this->
callMille2D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX, globalDerivativesY);
1348 unsigned int iTrajHit,
1349 const std::vector<int> &globalLabels,
1350 const std::vector<float> &globalDerivativesX) {
1352 const unsigned int xIndex = iTrajHit * 2;
1356 const int nLocal = locDerivMatrix.num_col();
1357 std::vector<float> localDerivatives(nLocal);
1358 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1359 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1363 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1364 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1367 const int nGlobal = globalDerivativesX.size();
1372 nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]), &(globalLabels[0]), residX, hitErrX);
1376 aRecHit, &(localDerivatives[0]), nLocal, &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1377 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, residX, hitErrX,
false);
1385 unsigned int iTrajHit,
1386 const std::vector<int> &globalLabels,
1387 const std::vector<float> &globalDerivativesx,
1388 const std::vector<float> &globalDerivativesy) {
1391 if ((aRecHit)->dimension() != 2) {
1392 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1393 <<
"You try to call method for 2D hits for a " << (aRecHit)->
dimension()
1394 <<
"D Hit. Hit gets ignored!";
1398 Eigen::Matrix<double, 2, 2> aHitCovarianceM;
1399 Eigen::Matrix<float, 2, 1> aHitResidualsM;
1400 Eigen::Matrix<float, 2, Eigen::Dynamic> aLocalDerivativesM{2, refTrajPtr->derivatives().num_col()};
1402 this->
addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1403 Eigen::Matrix<float, 2, Eigen::Dynamic> aGlobalDerivativesM{2, globalDerivativesx.size()};
1409 const double corr = aHitCovarianceM(0, 1) /
sqrt(aHitCovarianceM(0, 0) * aHitCovarianceM(1, 1));
1413 switch (aRecHit->geographicalId().subdetId()) {
1417 this->
diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1424 float newResidX = aHitResidualsM(0, 0);
1425 float newResidY = aHitResidualsM(1, 0);
1426 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0, 0));
1427 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1, 1));
1431 std::vector<float> newLocalDerivs(aLocalDerivativesM.size());
1432 Eigen::Map<Eigen::Matrix<float, 2, Eigen::Dynamic, Eigen::RowMajor> >(
1433 newLocalDerivs.data(), aLocalDerivativesM.rows(), aLocalDerivativesM.cols()) = aLocalDerivativesM;
1434 float *newLocalDerivsX = &(newLocalDerivs[0]);
1435 float *newLocalDerivsY = &(newLocalDerivs[aLocalDerivativesM.cols()]);
1439 std::vector<float> newGlobDerivs(aGlobalDerivativesM.size());
1440 Eigen::Map<Eigen::Matrix<float, 2, Eigen::Dynamic, Eigen::RowMajor> >(
1441 newGlobDerivs.data(), aGlobalDerivativesM.rows(), aGlobalDerivativesM.cols()) = aGlobalDerivativesM;
1442 float *newGlobDerivsX = &(newGlobDerivs[0]);
1443 float *newGlobDerivsY = &(newGlobDerivs[aGlobalDerivativesM.cols()]);
1445 const int nLocal = aLocalDerivativesM.cols();
1446 const int nGlobal = aGlobalDerivativesM.cols();
1448 if (diag && (newHitErrX > newHitErrY)) {
1452 std::swap(newLocalDerivsX, newLocalDerivsY);
1453 std::swap(newGlobDerivsX, newGlobDerivsY);
1458 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX, &(globalLabels[0]), newResidX, newHitErrX);
1461 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal, &(globalLabels[0]));
1463 aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, newResidX, newHitErrX,
false);
1465 const bool isReal2DHit = this->
is2D(aRecHit);
1467 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY, &(globalLabels[0]), newResidY, newHitErrY);
1469 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal, &(globalLabels[0]));
1471 aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, newResidY, newHitErrY,
true);
1475 return (isReal2DHit ? 2 : 1);
1480 unsigned int iVirtualMeas) {
1481 Eigen::Matrix<double, 1, 1> aHitCovarianceM;
1482 Eigen::Matrix<float, 1, 1> aHitResidualsM;
1483 Eigen::Matrix<float, 1, Eigen::Dynamic> aLocalDerivativesM{1, refTrajPtr->derivatives().num_col()};
1488 auto aGlobalDerivativesM = Eigen::Matrix<float, 1, 1>::Zero();
1490 float newResidX = aHitResidualsM(0, 0);
1491 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0, 0));
1492 std::vector<float> newLocalDerivsX(aLocalDerivativesM.size());
1493 Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(
1494 newLocalDerivsX.data(), aLocalDerivativesM.rows(), aLocalDerivativesM.cols()) = aLocalDerivativesM;
1496 std::vector<float> newGlobDerivsX(aGlobalDerivativesM.size());
1497 Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(
1498 newGlobDerivsX.data(), aGlobalDerivativesM.rows(), aGlobalDerivativesM.cols()) = aGlobalDerivativesM;
1500 const int nLocal = aLocalDerivativesM.cols();
1501 const int nGlobal = 0;
1503 theMille->mille(nLocal, newLocalDerivsX.data(), nGlobal, newGlobDerivsX.data(), &nGlobal, newResidX, newHitErrX);
1510 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1511 for (TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end(); iBeam != iEnd;
1512 ++iBeam, ++iTsoses) {
1514 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1515 <<
"Beam " << iBeam->getBeamId() <<
" with " << iBeam->parameters().size()
1516 <<
" parameters and " << iBeam->getData().size() <<
" hits.\n There are "
1517 << iTsoses->size() <<
" TSOSes.";
1519 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1526 const std::vector<TrajectoryStateOnSurface> &tsoses) {
1528 std::vector<float> lasLocalDerivsX;
1531 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1538 lasLocalDerivsX.clear();
1545 for (
unsigned int nFitParams = 0; nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1557 const float residual =
hit.localPosition().
x() - tsoses[iHit].localPosition().x();
1559 const float error = 0.003;
1561 theMille->mille(lasLocalDerivsX.size(),
1562 &(lasLocalDerivsX[0]),
1575 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1576 if (doOutputOnStdout) {
1577 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1578 <<
"# Output from addPxbSurvey follows below because "
1579 <<
"doOutputOnStdout is set to True";
1584 pxbSurveyCfg.
getParameter<
unsigned int>(
"toySurveySeed"));
1588 std::vector<SurveyPxbImageLocalFit> measurements;
1594 if (doOutputOnStdout) {
1595 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1596 <<
"Module " <<
i <<
": ";
1621 fidpointvec.push_back(fidpoint0inSurf1frame);
1622 fidpointvec.push_back(fidpoint1inSurf1frame);
1623 fidpointvec.push_back(fidpoint2);
1624 fidpointvec.push_back(fidpoint3);
1634 a = measurements[
i].getLocalParameters();
1638 if (doOutputOnStdout) {
1639 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1640 <<
"a: " <<
a[0] <<
", " <<
a[1] <<
", " <<
a[2] <<
", " <<
a[3]
1641 <<
" S= " <<
sqrt(
a[2] *
a[2] +
a[3] *
a[3]) <<
" phi= " << atan(
a[3] /
a[2])
1642 <<
" chi2= " <<
chi2 << std::endl;
1651 theMille->mille((
int)measurements[
i].getLocalDerivsSize(),
1652 measurements[
i].getLocalDerivsPtr(
j),
1653 (
int)measurements[
i].getGlobalDerivsSize(),
1654 measurements[
i].getGlobalDerivsPtr(
j),
1655 measurements[
i].getGlobalDerivsLabelPtr(
j),
1656 measurements[
i].getResiduum(
j),
1657 measurements[
i].getSigma(
j));
1667 if (runRangeSelection.empty())
1670 const auto runRanges =
1673 return !(runRanges.empty());