95 theMode(this->decodeMode(theConfig.getUntrackedParameter<
std::
string>(
"mode"))),
96 theDir(theConfig.getUntrackedParameter<
std::
string>(
"fileDir")),
97 theAlignmentParameterStore(nullptr),
99 theMinNumHits(
cfg.getParameter<unsigned
int>(
"minNumHits")),
100 theMaximalCor2D(
cfg.getParameter<double>(
"max2Dcorrelation")),
102 ignoreFirstIOVCheck_(
cfg.getUntrackedParameter<
bool>(
"ignoreFirstIOVCheck")),
103 enableAlignableUpdates_(
cfg.getUntrackedParameter<
bool>(
"enableAlignableUpdates")),
104 theLastWrittenIov(0),
105 theGblDoubleBinary(
cfg.getParameter<
bool>(
"doubleBinary")),
106 runAtPCL_(
cfg.getParameter<
bool>(
"runAtPCL")),
107 ignoreHitsWithoutGlobalDerivatives_(
cfg.getParameter<
bool>(
"ignoreHitsWithoutGlobalDerivatives")),
108 skipGlobalPositionRcdCheck_(
cfg.getParameter<
bool>(
"skipGlobalPositionRcdCheck")),
111 enforceSingleIOVInput_(!(enableAlignableUpdates_ && areIOVsSpecified())),
115 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm"
117 <<
"' with output directory '" <<
theDir <<
"'.";
139 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
140 <<
"Running with AlignabeMuon not yet tested.";
150 std::ostringstream message;
152 if (iov_alignments.first().eventID().run() !=
MIN_VAL || iov_alignments.last().eventID().run() !=
MAX_VAL) {
154 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
155 <<
"Validity range is " << iov_alignments.first().eventID().run() <<
" - "
156 << iov_alignments.last().eventID().run() <<
"\n";
159 if (iov_surfaces.first().eventID().run() !=
MIN_VAL || iov_surfaces.last().eventID().run() !=
MAX_VAL) {
161 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
162 <<
"Validity range is " << iov_surfaces.first().eventID().run() <<
" - "
163 << iov_surfaces.last().eventID().run() <<
"\n";
166 if (iov_errors.first().eventID().run() !=
MIN_VAL || iov_errors.last().eventID().run() !=
MAX_VAL) {
168 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
169 <<
"Validity range is " << iov_errors.first().eventID().run() <<
" - "
170 << iov_errors.last().eventID().run() <<
"\n";
174 throw cms::Exception(
"DatabaseError") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize" << message.str();
187 auto th = thresholdHandle.
product();
201 if (!RunRangeSelectionVPSet.empty()) {
202 labelerPlugin =
"RunRangeDependentPedeLabeler";
203 if (pedeLabelerCfg.
exists(
"plugin")) {
205 if ((labelerPluginCfg !=
"PedeLabeler" && labelerPluginCfg !=
"RunRangeDependentPedeLabeler") ||
207 throw cms::Exception(
"BadConfig") <<
"MillePedeAlignmentAlgorithm::initialize"
208 <<
"both RunRangeSelection and generic labeler specified in config file. "
209 <<
"Please get rid of either one of them.\n";
213 if (pedeLabelerCfg.
exists(
"plugin")) {
218 if (!pedeLabelerCfg.
exists(
"plugin")) {
222 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
223 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
241 const std::vector<edm::ParameterSet> mprespset(
243 if (!mprespset.empty()) {
244 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
245 <<
"Apply " << mprespset.end() - mprespset.begin()
246 <<
" previous MillePede constants from 'pedeReaderInputs'.";
252 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end(); iSet != iE;
258 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
259 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
275 throw cms::Exception(
"BadConfig") <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
276 <<
"modes running mille.";
279 if (!moniFile.empty())
280 theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (
theDir + moniFile).c_str());
310 theThresholds->setAlignPCLThresholds(nRecords, thresholdMap);
355 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
356 <<
"Problems reading pede result, but applying!";
373 std::vector<std::string>
files;
377 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
382 filesForLogOutput +=
" " +
file +
",";
383 if (filesForLogOutput.length() != 0)
384 filesForLogOutput.pop_back();
385 edm::LogInfo(
"Alignment") <<
"Based on the config parameter mergeBinaryFiles, using the following "
386 <<
"files as input (assigned weights are indicated by ' -- <weight>'):"
387 << filesForLogOutput;
394 throw cms::Exception(
"BadConfig") <<
"@SUB=MillePedeAlignmentAlgorithm::terminate\n"
395 <<
"Last IOV of 'RunRangeSelection' has not been processed. "
396 <<
"Please reconfigure your source to process the runs at least up to "
401 const auto run = runRange.first;
424 const std::vector<std::string> &plainFiles,
const std::string &theDir) {
425 std::vector<std::string>
files;
426 for (
const auto &plainFile : plainFiles) {
432 char theNumberedInputFileName[200];
433 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
435 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
436 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
439 if (
stat(strippedInputFileName.c_str(), &
buffer) == 0) {
441 files.push_back(theCompleteInputFileName);
442 if (theNumberedInputFileName == theInputFileName) {
455 if (theNumber == 0 && (
files.empty() ||
files.back() != plainFile)) {
456 edm::LogWarning(
"Alignment") <<
"The input file '" << plainFile <<
"' does not exist.";
470 for (
const auto &iTrajTrack :
tracks) {
478 unsigned int refTrajCount = 0;
481 ++iRefTraj, ++refTrajCount) {
488 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
490 const auto offset = tracksPerTraj * refTrajCount;
491 for (
unsigned int iTrack = 0; iTrack < tracksPerTraj; ++iTrack) {
502 std::pair<unsigned int, unsigned int> hitResultXy(0, 0);
503 if (refTrajPtr->isValid()) {
505 if (!refTrajPtr->gblInput().empty()) {
507 unsigned int iHit = 0;
508 unsigned int numPointsWithMeas = 0;
509 std::vector<GblPoint>::iterator itPoint;
510 auto theGblInput = refTrajPtr->gblInput();
511 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
512 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end();
516 if (itPoint->hasMeasurement() >= 1)
520 hitResultXy.first = numPointsWithMeas;
522 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
525 if (refTrajPtr->gblInput().size() == 1) {
527 GblTrajectory aGblTrajectory(refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0);
535 if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >=
theMinNumHits)
538 if (refTrajPtr->gblInput().size() == 2) {
540 GblTrajectory aGblTrajectory(refTrajPtr->gblInput(),
541 refTrajPtr->gblExtDerivatives(),
542 refTrajPtr->gblExtMeasurements(),
543 refTrajPtr->gblExtPrecisions());
545 if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >=
theMinNumHits)
550 std::vector<AlignmentParameters *> parVec(refTrajPtr->recHits().size());
552 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
554 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
558 hitResultXy.first = 0;
563 validHitVecY[iHit] = (flagXY >= 2);
568 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
573 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
575 hitResultXy.first = hitResultXy.second = 0;
580 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
592 const std::vector<bool> &validHitVecY)
const {
594 unsigned int nHitY = 0;
595 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
596 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() :
nullptr);
607 if (validHitVecY[iHit]) {
609 if (pars == parVec[iHit])
622 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::beginRun\n"
623 <<
"Using data (run = " <<
run.run() <<
") prior to the first defined IOV ("
645 std::ostringstream message;
647 message <<
"Trying to cache tracker alignment payloads for a run (" <<
runNumber <<
") in an IOV (" <<
firstRun
648 <<
") that was already cached.\n"
649 <<
"The following records in your input database tag have an IOV "
650 <<
"boundary that does not match your IOV definition:\n";
651 if (geometryRcd.validityInterval().first().eventID().run() >
firstRun) {
652 message <<
" - IdealGeometryRecord '" << geometryRcd.key().name() <<
"' (since "
653 << geometryRcd.validityInterval().first().eventID().run() <<
")\n";
657 message <<
" - GlobalPositionRecord '" << globalPosRcd.
key().
name() <<
"' (since "
660 message <<
" --> ignored\n";
667 message <<
" - TrackerAlignmentRcd '" << alignmentRcd.
key().
name() <<
"' (since "
672 message <<
" - TrackerSurfaceDeformationRcd '" << surfaceRcd.
key().
name() <<
"' (since "
677 message <<
" - TrackerAlignmentErrorExtendedRcd '" << errorRcd.
key().
name() <<
"' (since "
683 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::beginRun\n" << message.str();
740 if (!recHitPtr->isValid())
780 GblPoint &gblPoint) {
782 std::vector<double> theDoubleBufferX, theDoubleBufferY;
783 theDoubleBufferX.clear();
784 theDoubleBufferY.clear();
791 if (!recHitPtr->isValid())
809 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
812 (*iCalib)->derivatives(derivs, *recHitPtr, tsos,
setup,
eventInfo);
813 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
815 globalLabel =
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
816 if (globalLabel > 0 && globalLabel <= 2147483647) {
818 theDoubleBufferX.push_back(iValuesInd->first.first);
819 theDoubleBufferY.push_back(iValuesInd->first.second);
821 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addGlobalData"
822 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
827 if (numGlobals > 0) {
828 Eigen::Matrix<double, 2, Eigen::Dynamic> globalDer{2, numGlobals};
829 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
830 globalDer(0,
i) = theDoubleBufferX[
i];
831 globalDer(1,
i) = theDoubleBufferY[
i];
844 std::vector<float> &globalDerivativesX,
845 std::vector<float> &globalDerivativesY,
846 std::vector<int> &globalLabels,
861 bool hasSplitParameters =
thePedeLabels->hasSplitParameters(ali);
862 const unsigned int alignableLabel =
thePedeLabels->alignableLabel(ali);
864 if (0 == alignableLabel) {
865 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
866 <<
"Label not found, skip Alignable.";
870 const std::vector<bool> &selPars =
params->selector();
874 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
877 if (hasSplitParameters ==
true) {
880 globalLabels.push_back(
thePedeLabels->parameterLabel(alignableLabel, iSel));
891 eventInfo, tsos, ali->
mother(), alidet, globalDerivativesX, globalDerivativesY, globalLabels, lowestParams);
899 std::vector<double> &globalDerivativesX,
900 std::vector<double> &globalDerivativesY,
901 std::vector<int> &globalLabels,
916 bool hasSplitParameters =
thePedeLabels->hasSplitParameters(ali);
917 const unsigned int alignableLabel =
thePedeLabels->alignableLabel(ali);
919 if (0 == alignableLabel) {
920 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
921 <<
"Label not found, skip Alignable.";
925 const std::vector<bool> &selPars =
params->selector();
930 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
932 if (hasSplitParameters ==
true) {
935 globalLabel =
thePedeLabels->parameterLabel(alignableLabel, iSel);
937 if (globalLabel > 0 && globalLabel <= 2147483647) {
938 globalLabels.push_back(globalLabel);
942 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
943 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
953 eventInfo, tsos, ali->
mother(), alidet, globalDerivativesX, globalDerivativesY, globalLabels, lowestParams);
961 std::vector<float> &globalDerivativesX,
962 std::vector<float> &globalDerivativesY,
963 std::vector<int> &globalLabels)
const {
964 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
968 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
970 globalLabels.push_back(
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
971 globalDerivativesX.push_back(iValuesInd->first.first);
972 globalDerivativesY.push_back(iValuesInd->first.second);
1015 if (
recHit->dimension() < 2) {
1017 }
else if (
recHit->detUnit()) {
1018 return recHit->detUnit()->type().isTrackerPixel();
1020 if (dynamic_cast<const ProjectedSiStripRecHit2D *>(
recHit->hit())) {
1037 bool okRead =
reader.read(alis, setUserVars);
1038 bool numMatch =
true;
1040 std::stringstream
out;
1041 out <<
"Read " << alis.size() <<
" alignables";
1047 out <<
", but problems in reading";
1049 out <<
", possibly overwriting previous settings";
1052 if (okRead && allEmpty) {
1054 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1055 }
else if (!alis.empty()) {
1056 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1058 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1064 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" <<
out.str();
1070 for (
const auto &iAli : alignables) {
1073 const auto &parVec(
params->parameters());
1074 const auto &parCov(
params->covariance());
1075 for (
int i = 0;
i < parVec.num_row(); ++
i) {
1076 if (parVec[
i] != 0.)
1078 for (
int j =
i;
j < parCov.num_col(); ++
j) {
1079 if (parCov[
i][
j] != 0.)
1094 if (outFilePlain.empty()) {
1095 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1096 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
1107 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1108 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
1111 }
else if (
loop == 1) {
1113 const std::vector<std::string> inFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeTreeFiles"));
1114 const std::vector<std::string> binFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
1115 if (inFiles.size() != binFiles.size()) {
1116 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1117 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
1118 <<
"differ in size";
1125 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1126 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
1132 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1133 <<
"Problem " << ioerr <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
1138 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
1139 <<
"Problem " << ioerr <<
" in writeAlignableAbsolutePositions, " <<
loop;
1148 for (
const auto &iAli : alis) {
1151 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
1152 <<
"No parameters for alignable";
1156 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
1167 thePedeLabels->alignableTracker()->objectIdProvider().typeToName(iAli->alignableObjectId()));
1168 params->setUserVariables(userVars);
1175 if (
mode ==
"full") {
1177 }
else if (
mode ==
"mille") {
1179 }
else if (
mode ==
"pede") {
1181 }
else if (
mode ==
"pedeSteer") {
1183 }
else if (
mode ==
"pedeRun") {
1185 }
else if (
mode ==
"pedeRead") {
1190 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
1198 const std::vector<std::string> &inFiles)
const {
1202 for (std::vector<std::string>::const_iterator iFile = inFiles.begin(); iFile != inFiles.end(); ++iFile) {
1204 const std::vector<AlignmentUserVariables *> mpVars =
1207 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1208 <<
"Error " << ierr <<
" reading from " << inFile <<
", tree " << fromIov
1209 <<
", or problems in addHits";
1212 for (std::vector<AlignmentUserVariables *>::const_iterator
i = mpVars.begin();
i != mpVars.end(); ++
i) {
1222 const std::vector<AlignmentUserVariables *> &mpVars)
const {
1223 bool allOk = (mpVars.size() == alis.size());
1224 std::vector<AlignmentUserVariables *>::const_iterator iUser = mpVars.begin();
1225 for (
auto iAli = alis.cbegin(); iAli != alis.cend() && iUser != mpVars.end(); ++iAli, ++iUser) {
1229 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1242 template <
typename GlobalDerivativeMatrix>
1244 const std::vector<float> &globalDerivativesy,
1245 Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM) {
1246 static_assert(GlobalDerivativeMatrix::RowsAtCompileTime == 2,
"global derivative matrix must have two rows");
1248 for (
size_t i = 0;
i < globalDerivativesx.size(); ++
i) {
1249 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1250 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1256 typename LocalDerivativeMatrix,
1257 typename ResidualMatrix,
1258 typename GlobalDerivativeMatrix>
1260 Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM,
1261 Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1262 Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM)
const {
1264 "'aLocalDerivativesM' and 'aHitResidualsM' must have the "
1265 "same underlying scalar type");
1267 "'aLocalDerivativesM' and 'aGlobalDerivativesM' must have the "
1268 "same underlying scalar type");
1270 Eigen::SelfAdjointEigenSolver<typename CovarianceMatrix::PlainObject> myDiag{aHitCovarianceM};
1272 auto aTranfoToDiagonalSystemInv =
1273 myDiag.eigenvectors().transpose().template cast<typename LocalDerivativeMatrix::Scalar>();
1275 aHitCovarianceM = myDiag.eigenvalues().asDiagonal();
1276 aLocalDerivativesM = aTranfoToDiagonalSystemInv * aLocalDerivativesM;
1277 aHitResidualsM = aTranfoToDiagonalSystemInv * aHitResidualsM;
1278 if (aGlobalDerivativesM.size() > 0) {
1280 aGlobalDerivativesM = aTranfoToDiagonalSystemInv * aGlobalDerivativesM;
1285 template <
typename CovarianceMatrix,
typename Res
idualMatrix,
typename LocalDerivativeMatrix>
1288 unsigned int iVirtualMeas,
1289 Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
1290 Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1291 Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM) {
1294 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1296 aHitCovarianceM(0, 0) = refTrajPtr->measurementErrors()[xIndex][xIndex];
1297 aHitResidualsM(0, 0) = refTrajPtr->measurements()[xIndex];
1299 const auto &locDerivMatrix = refTrajPtr->derivatives();
1300 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1301 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1306 template <
typename CovarianceMatrix,
typename Res
idualMatrix,
typename LocalDerivativeMatrix>
1308 unsigned int iTrajHit,
1309 Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
1310 Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1311 Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM) {
1314 const unsigned int xIndex = iTrajHit * 2;
1315 const unsigned int yIndex = iTrajHit * 2 + 1;
1317 aHitCovarianceM(0, 0) = refTrajPtr->measurementErrors()[xIndex][xIndex];
1318 aHitCovarianceM(0, 1) = refTrajPtr->measurementErrors()[xIndex][yIndex];
1319 aHitCovarianceM(1, 0) = refTrajPtr->measurementErrors()[yIndex][xIndex];
1320 aHitCovarianceM(1, 1) = refTrajPtr->measurementErrors()[yIndex][yIndex];
1322 aHitResidualsM(0, 0) = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1323 aHitResidualsM(1, 0) = refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1325 const auto &locDerivMatrix = refTrajPtr->derivatives();
1326 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1327 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1328 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1334 unsigned int iTrajHit,
1335 const std::vector<int> &globalLabels,
1336 const std::vector<float> &globalDerivativesX,
1337 const std::vector<float> &globalDerivativesY) {
1340 if ((aRecHit)->dimension() == 1) {
1341 return this->
callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1343 return this->
callMille2D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX, globalDerivativesY);
1349 unsigned int iTrajHit,
1350 const std::vector<int> &globalLabels,
1351 const std::vector<float> &globalDerivativesX) {
1353 const unsigned int xIndex = iTrajHit * 2;
1357 const int nLocal = locDerivMatrix.num_col();
1358 std::vector<float> localDerivatives(nLocal);
1359 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1360 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1364 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1365 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1368 const int nGlobal = globalDerivativesX.size();
1373 nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]), &(globalLabels[0]), residX, hitErrX);
1377 aRecHit, &(localDerivatives[0]), nLocal, &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1378 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, residX, hitErrX,
false);
1386 unsigned int iTrajHit,
1387 const std::vector<int> &globalLabels,
1388 const std::vector<float> &globalDerivativesx,
1389 const std::vector<float> &globalDerivativesy) {
1392 if ((aRecHit)->dimension() != 2) {
1393 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1394 <<
"You try to call method for 2D hits for a " << (aRecHit)->
dimension()
1395 <<
"D Hit. Hit gets ignored!";
1399 Eigen::Matrix<double, 2, 2> aHitCovarianceM;
1400 Eigen::Matrix<float, 2, 1> aHitResidualsM;
1401 Eigen::Matrix<float, 2, Eigen::Dynamic> aLocalDerivativesM{2, refTrajPtr->derivatives().num_col()};
1403 this->
addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1404 Eigen::Matrix<float, 2, Eigen::Dynamic> aGlobalDerivativesM{2, globalDerivativesx.size()};
1410 const double corr = aHitCovarianceM(0, 1) /
sqrt(aHitCovarianceM(0, 0) * aHitCovarianceM(1, 1));
1414 switch (aRecHit->geographicalId().subdetId()) {
1418 this->
diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1425 float newResidX = aHitResidualsM(0, 0);
1426 float newResidY = aHitResidualsM(1, 0);
1427 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0, 0));
1428 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1, 1));
1432 std::vector<float> newLocalDerivs(aLocalDerivativesM.size());
1433 Eigen::Map<Eigen::Matrix<float, 2, Eigen::Dynamic, Eigen::RowMajor> >(
1434 newLocalDerivs.data(), aLocalDerivativesM.rows(), aLocalDerivativesM.cols()) = aLocalDerivativesM;
1435 float *newLocalDerivsX = &(newLocalDerivs[0]);
1436 float *newLocalDerivsY = &(newLocalDerivs[aLocalDerivativesM.cols()]);
1440 std::vector<float> newGlobDerivs(aGlobalDerivativesM.size());
1441 Eigen::Map<Eigen::Matrix<float, 2, Eigen::Dynamic, Eigen::RowMajor> >(
1442 newGlobDerivs.data(), aGlobalDerivativesM.rows(), aGlobalDerivativesM.cols()) = aGlobalDerivativesM;
1443 float *newGlobDerivsX = &(newGlobDerivs[0]);
1444 float *newGlobDerivsY = &(newGlobDerivs[aGlobalDerivativesM.cols()]);
1446 const int nLocal = aLocalDerivativesM.cols();
1447 const int nGlobal = aGlobalDerivativesM.cols();
1449 if (diag && (newHitErrX > newHitErrY)) {
1453 std::swap(newLocalDerivsX, newLocalDerivsY);
1454 std::swap(newGlobDerivsX, newGlobDerivsY);
1459 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX, &(globalLabels[0]), newResidX, newHitErrX);
1462 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal, &(globalLabels[0]));
1464 aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, newResidX, newHitErrX,
false);
1466 const bool isReal2DHit = this->
is2D(aRecHit);
1468 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY, &(globalLabels[0]), newResidY, newHitErrY);
1470 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal, &(globalLabels[0]));
1472 aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, newResidY, newHitErrY,
true);
1476 return (isReal2DHit ? 2 : 1);
1481 unsigned int iVirtualMeas) {
1482 Eigen::Matrix<double, 1, 1> aHitCovarianceM;
1483 Eigen::Matrix<float, 1, 1> aHitResidualsM;
1484 Eigen::Matrix<float, 1, Eigen::Dynamic> aLocalDerivativesM{1, refTrajPtr->derivatives().num_col()};
1489 auto aGlobalDerivativesM = Eigen::Matrix<float, 1, 1>::Zero();
1491 float newResidX = aHitResidualsM(0, 0);
1492 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0, 0));
1493 std::vector<float> newLocalDerivsX(aLocalDerivativesM.size());
1494 Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(
1495 newLocalDerivsX.data(), aLocalDerivativesM.rows(), aLocalDerivativesM.cols()) = aLocalDerivativesM;
1497 std::vector<float> newGlobDerivsX(aGlobalDerivativesM.size());
1498 Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(
1499 newGlobDerivsX.data(), aGlobalDerivativesM.rows(), aGlobalDerivativesM.cols()) = aGlobalDerivativesM;
1501 const int nLocal = aLocalDerivativesM.cols();
1502 const int nGlobal = 0;
1504 theMille->mille(nLocal, newLocalDerivsX.data(), nGlobal, newGlobDerivsX.data(), &nGlobal, newResidX, newHitErrX);
1511 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1512 for (TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end(); iBeam != iEnd;
1513 ++iBeam, ++iTsoses) {
1515 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1516 <<
"Beam " << iBeam->getBeamId() <<
" with " << iBeam->parameters().size()
1517 <<
" parameters and " << iBeam->getData().size() <<
" hits.\n There are "
1518 << iTsoses->size() <<
" TSOSes.";
1520 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1527 const std::vector<TrajectoryStateOnSurface> &tsoses) {
1529 std::vector<float> lasLocalDerivsX;
1532 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1533 if (!tsoses[iHit].isValid())
1539 lasLocalDerivsX.clear();
1546 for (
unsigned int nFitParams = 0; nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1558 const float residual =
hit.localPosition().
x() - tsoses[iHit].localPosition().x();
1560 const float error = 0.003;
1562 theMille->mille(lasLocalDerivsX.size(),
1563 &(lasLocalDerivsX[0]),
1576 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1577 if (doOutputOnStdout) {
1578 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1579 <<
"# Output from addPxbSurvey follows below because "
1580 <<
"doOutputOnStdout is set to True";
1585 pxbSurveyCfg.
getParameter<
unsigned int>(
"toySurveySeed"));
1589 std::vector<SurveyPxbImageLocalFit> measurements;
1595 if (doOutputOnStdout) {
1596 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1597 <<
"Module " <<
i <<
": ";
1622 fidpointvec.push_back(fidpoint0inSurf1frame);
1623 fidpointvec.push_back(fidpoint1inSurf1frame);
1624 fidpointvec.push_back(fidpoint2);
1625 fidpointvec.push_back(fidpoint3);
1635 a = measurements[
i].getLocalParameters();
1639 if (doOutputOnStdout) {
1640 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1641 <<
"a: " <<
a[0] <<
", " <<
a[1] <<
", " <<
a[2] <<
", " <<
a[3]
1642 <<
" S= " <<
sqrt(
a[2] *
a[2] +
a[3] *
a[3]) <<
" phi= " << atan(
a[3] /
a[2])
1643 <<
" chi2= " <<
chi2 << std::endl;
1652 theMille->mille((
int)measurements[
i].getLocalDerivsSize(),
1653 measurements[
i].getLocalDerivsPtr(
j),
1654 (
int)measurements[
i].getGlobalDerivsSize(),
1655 measurements[
i].getGlobalDerivsPtr(
j),
1656 measurements[
i].getGlobalDerivsLabelPtr(
j),
1657 measurements[
i].getResiduum(
j),
1658 measurements[
i].getSigma(
j));
1668 if (runRangeSelection.empty())
1671 const auto runRanges =
1674 return !(runRanges.empty());