68 #include <TMatrixDSymEigen.h>
91 theMode(this->decodeMode(theConfig.getUntrackedParameter<std::
string>(
"mode"))),
92 theDir(theConfig.getUntrackedParameter<std::
string>(
"fileDir")),
93 theAlignmentParameterStore(
nullptr),
95 theMinNumHits(cfg.getParameter<unsigned int>(
"minNumHits")),
96 theMaximalCor2D(cfg.getParameter<double>(
"max2Dcorrelation")),
98 theGblDoubleBinary(cfg.getParameter<bool>(
"doubleBinary")),
99 runAtPCL_(cfg.getParameter<bool>(
"runAtPCL")),
100 ignoreHitsWithoutGlobalDerivatives_(cfg.getParameter<bool>(
"ignoreHitsWithoutGlobalDerivatives"))
103 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '"
105 <<
"' with output directory '" <<
theDir <<
"'.";
126 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
127 <<
"Running with AlignabeMuon not yet tested.";
134 const auto& iov_alignments =
136 const auto& iov_surfaces =
138 const auto& iov_errors =
140 if (iov_alignments.first().eventID().run() !=
MIN_VAL ||
141 iov_alignments.last().eventID().run() !=
MAX_VAL) {
143 <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
145 <<
" with multiple IOVs in tag.\n"
146 <<
"Validity range is "
147 << iov_alignments.first().eventID().run() <<
" - "
148 << iov_alignments.last().eventID().run();
150 if (iov_surfaces.first().eventID().run() !=
MIN_VAL ||
151 iov_surfaces.last().eventID().run() !=
MAX_VAL) {
153 <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
154 <<
"\nTrying to apply "
156 <<
" with multiple IOVs in tag.\n"
157 <<
"Validity range is "
158 << iov_surfaces.first().eventID().run() <<
" - "
159 << iov_surfaces.last().eventID().run();
161 if (iov_errors.first().eventID().run() !=
MIN_VAL ||
162 iov_errors.last().eventID().run() !=
MAX_VAL) {
164 <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
165 <<
"\nTrying to apply "
167 <<
" with multiple IOVs in tag.\n"
168 <<
"Validity range is "
169 << iov_errors.first().eventID().run() <<
" - "
170 << iov_errors.last().eventID().run();
187 RunRangeSelectionVPSet);
190 if (RunRangeSelectionVPSet.size()>0) {
191 labelerPlugin =
"RunRangeDependentPedeLabeler";
192 if (pedeLabelerCfg.
exists(
"plugin")) {
194 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
197 <<
"MillePedeAlignmentAlgorithm::initialize"
198 <<
"both RunRangeSelection and generic labeler specified in config file. "
199 <<
"Please get rid of either one of them.\n";
203 if (pedeLabelerCfg.
exists(
"plugin")) {
208 if (!pedeLabelerCfg.
exists(
"plugin")) {
212 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
213 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
216 ->create(labelerPlugin,
228 const std::vector<edm::ParameterSet> mprespset
230 if (!mprespset.empty()) {
231 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
232 <<
"Apply " << mprespset.end() - mprespset.begin()
233 <<
" previous MillePede constants from 'pedeReaderInputs'.";
240 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
241 iSet != iE; ++iSet) {
246 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
247 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
249 theAlignmentParameterStore->applyParameters();
251 theAlignmentParameterStore->resetParameters();
264 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
265 <<
"modes running mille.";
268 if (moniFile.size())
theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (theDir + moniFile).c_str());
274 ->create(fctName, fctCfg));
321 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
322 <<
"Problems reading pede result, but applying!";
343 std::vector<std::string>
files;
347 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
351 for (
const auto&
file: files) filesForLogOutput +=
" " +
file +
",";
352 if (filesForLogOutput.length() != 0) filesForLogOutput.pop_back();
354 <<
"Based on the config parameter mergeBinaryFiles, using the following "
355 <<
"files as input (assigned weights are indicated by ' -- <weight>'):"
356 << filesForLogOutput;
374 std::vector<std::string>
files;
375 for (
const auto& plainFile: plainFiles) {
381 char theNumberedInputFileName[200];
382 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
383 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
384 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
385 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
388 if (stat (strippedInputFileName.c_str(), &buffer) == 0) {
390 files.push_back(theCompleteInputFileName);
391 if (theNumberedInputFileName == theInputFileName) {
404 if (theNumber == 0 && (files.size() == 0 || files.back() != plainFile)) {
406 <<
"The input file '" << plainFile <<
"' does not exist.";
420 for (
const auto& iTrajTrack:
tracks) {
428 unsigned int refTrajCount = 0;
430 for (
auto iRefTraj = trajectories.cbegin(), iRefTrajE = trajectories.cend();
431 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
438 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
440 const auto offset = tracksPerTraj*refTrajCount;
441 for (
unsigned int iTrack = 0; iTrack < tracksPerTraj; ++iTrack) {
443 nHitXy.first, nHitXy.second);
451 std::pair<unsigned int, unsigned int>
456 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
457 if (refTrajPtr->isValid()) {
461 if (refTrajPtr->gblInput().size() > 0) {
463 unsigned int iHit = 0;
464 unsigned int numPointsWithMeas = 0;
465 std::vector<GblPoint>::iterator itPoint;
466 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
467 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
468 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
469 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
470 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
473 hitResultXy.first = numPointsWithMeas;
475 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
477 if (refTrajPtr->gblInput().size() == 1) {
479 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
489 if (refTrajPtr->gblInput().size() == 2) {
491 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
497 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
499 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
501 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
502 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
505 hitResultXy.first = 0;
508 if (flagXY >= 1) ++hitResultXy.first;
509 validHitVecY[iHit] = (flagXY >= 2);
514 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
519 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
521 hitResultXy.first = hitResultXy.second = 0;
526 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
539 const std::vector<bool> &validHitVecY)
const
542 unsigned int nHitY = 0;
543 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
544 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
555 if (validHitVecY[iHit]) {
557 if (pars == parVec[iHit]) ++nHitY;
613 if (!recHitPtr->isValid())
return 0;
640 unsigned int iHit,
GblPoint &gblPoint)
643 std::vector<double> theDoubleBufferX, theDoubleBufferY;
644 theDoubleBufferX.clear();
645 theDoubleBufferY.clear();
652 if (!recHitPtr->isValid())
return 0;
658 tsos, alidet, alidet, theDoubleBufferX,
664 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
667 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
668 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
670 globalLabel =
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
671 if (globalLabel > 0 && globalLabel <= 2147483647) {
673 theDoubleBufferX.push_back(iValuesInd->first.first);
674 theDoubleBufferY.push_back(iValuesInd->first.second);
677 <<
"@SUB=MillePedeAlignmentAlgorithm::addGlobalData"
678 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
685 TMatrixD globalDer(2,numGlobals);
686 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
687 globalDer(0,
i) = theDoubleBufferX[
i];
688 globalDer(1,
i) = theDoubleBufferY[
i];
701 std::vector<float> &globalDerivativesX,
702 std::vector<float> &globalDerivativesY,
703 std::vector<int> &globalLabels,
707 if (!ali)
return true;
709 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
714 if (!lowestParams) lowestParams = params;
716 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
717 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
719 if (0 == alignableLabel) {
720 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
721 <<
"Label not found, skip Alignable.";
725 const std::vector<bool> &selPars = params->
selector();
729 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
731 globalDerivativesX.push_back(derivs[iSel][kLocalX]
732 /thePedeSteer->cmsToPedeFactor(iSel));
733 if (hasSplitParameters==
true) {
734 globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
736 globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
738 globalDerivativesY.push_back(derivs[iSel][kLocalY]
739 /thePedeSteer->cmsToPedeFactor(iSel));
743 if (thePedeSteer->isNoHiera(ali))
return true;
746 return this->globalDerivativesHierarchy(eventInfo,
747 tsos, ali->
mother(), alidet,
748 globalDerivativesX, globalDerivativesY,
749 globalLabels, lowestParams);
757 std::vector<double> &globalDerivativesX,
758 std::vector<double> &globalDerivativesY,
759 std::vector<int> &globalLabels,
763 if (!ali)
return true;
765 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
770 if (!lowestParams) lowestParams = params;
772 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
773 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
775 if (0 == alignableLabel) {
776 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
777 <<
"Label not found, skip Alignable.";
781 const std::vector<bool> &selPars = params->
selector();
786 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
788 if (hasSplitParameters==
true) {
789 globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
791 globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
793 if (globalLabel > 0 && globalLabel <= 2147483647) {
794 globalLabels.push_back(globalLabel);
795 globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
796 globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
799 <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
800 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
805 if (thePedeSteer->isNoHiera(ali))
return true;
808 return this->globalDerivativesHierarchy(eventInfo,
809 tsos, ali->
mother(), alidet,
810 globalDerivativesX, globalDerivativesY,
811 globalLabels, lowestParams);
819 std::vector<float> &globalDerivativesX,
820 std::vector<float> &globalDerivativesY,
821 std::vector<int> &globalLabels)
const
823 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
826 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
827 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
829 globalLabels.push_back(
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
830 globalDerivativesX.push_back(iValuesInd->first.first);
831 globalDerivativesY.push_back(iValuesInd->first.second);
875 if (recHit->dimension() < 2) {
877 }
else if (recHit->detUnit()) {
878 return recHit->detUnit()->type().isTrackerPixel();
880 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
896 std::vector<Alignable*> alis;
897 bool okRead = reader.
read(alis, setUserVars);
898 bool numMatch =
true;
900 std::stringstream
out;
901 out <<
"Read " << alis.size() <<
" alignables";
906 if (!okRead) out <<
", but problems in reading";
907 if (!allEmpty) out <<
", possibly overwriting previous settings";
910 if (okRead && allEmpty) {
912 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
913 }
else if (alis.size()) {
914 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
916 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
922 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
930 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
931 iAli != alignables.end(); ++iAli) {
936 for (
int i = 0;
i < parVec.num_row(); ++
i) {
937 if (parVec[
i] != 0.)
return false;
938 for (
int j =
i;
j < parCov.num_col(); ++
j) {
939 if (parCov[
i][
j] != 0.)
return false;
954 if (outFilePlain.empty()) {
955 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
956 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
967 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
968 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
971 }
else if (loop == 1) {
973 const std::vector<std::string> inFiles
975 const std::vector<std::string> binFiles
977 if (inFiles.size() != binFiles.size()) {
978 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
979 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
987 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
988 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
994 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
995 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
1000 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
1001 <<
" in writeAlignableAbsolutePositions, " <<
loop;
1011 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
1014 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
1015 <<
"No parameters for alignable";
1019 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
1036 if (mode ==
"full") {
1038 }
else if (mode ==
"mille") {
1040 }
else if (mode ==
"pede") {
1042 }
else if (mode ==
"pedeSteer") {
1044 }
else if (mode ==
"pedeRun") {
1046 }
else if (mode ==
"pedeRead") {
1051 <<
"Unknown mode '" << mode
1052 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
1059 const std::vector<std::string> &inFiles)
const
1064 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
1065 iFile != inFiles.end(); ++iFile) {
1067 const std::vector<AlignmentUserVariables*> mpVars =
1070 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1071 <<
"Error " << ierr <<
" reading from " << inFile
1072 <<
", tree " << fromIov <<
", or problems in addHits";
1075 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
1076 i != mpVars.end(); ++
i) {
1086 const std::vector<AlignmentUserVariables*> &mpVars)
const
1088 bool allOk = (mpVars.size() == alis.size());
1089 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1090 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1091 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1095 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1109 const std::vector<float> &globalDerivativesy,
1110 TMatrixF &aGlobalDerivativesM)
1113 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
1114 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1115 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1121 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1122 TMatrixF &aGlobalDerivativesM)
const
1124 TMatrixDSymEigen myDiag(aHitCovarianceM);
1125 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1126 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1127 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1128 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1134 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1135 aTranfoToDiagonalSystemInvF.Invert();
1137 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1140 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1141 if (aGlobalDerivativesM.GetNoElements() > 0) {
1143 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1150 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1151 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1155 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1159 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1162 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1169 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1170 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1177 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1178 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1182 const unsigned int xIndex = iTrajHit*2;
1183 const unsigned int yIndex = iTrajHit*2+1;
1187 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1188 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1189 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1190 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1193 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1194 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1201 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1202 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1203 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1210 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1211 const std::vector<float> &globalDerivativesX,
1212 const std::vector<float> &globalDerivativesY)
1216 if((aRecHit)->dimension() == 1) {
1217 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1219 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1220 globalDerivativesX, globalDerivativesY);
1228 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1229 const std::vector<float> &globalDerivativesX)
1232 const unsigned int xIndex = iTrajHit*2;
1236 const int nLocal = locDerivMatrix.num_col();
1237 std::vector<float> localDerivatives(nLocal);
1238 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1239 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1243 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1244 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1247 const int nGlobal = globalDerivativesX.size();
1251 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1252 &(globalLabels[0]), residX, hitErrX);
1255 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1256 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1257 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1258 iTrajHit, residX, hitErrX,
false);
1267 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1268 const std::vector<float> &globalDerivativesx,
1269 const std::vector<float> &globalDerivativesy)
1273 if((aRecHit)->dimension() != 2) {
1274 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1275 <<
"You try to call method for 2D hits for a "
1277 <<
"D Hit. Hit gets ignored!";
1281 TMatrixDSym aHitCovarianceM(2);
1282 TMatrixF aHitResidualsM(2,1);
1283 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1285 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1286 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1287 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1292 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1293 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1295 switch(aRecHit->geographicalId().subdetId()) {
1299 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1306 float newResidX = aHitResidualsM(0,0);
1307 float newResidY = aHitResidualsM(1,0);
1308 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1309 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1310 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1311 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1312 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1313 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1314 const int nLocal = aLocalDerivativesM.GetNcols();
1315 const int nGlobal = aGlobalDerivativesM.GetNcols();
1317 if (diag && (newHitErrX > newHitErrY)) {
1321 std::swap(newLocalDerivsX, newLocalDerivsY);
1322 std::swap(newGlobDerivsX, newGlobDerivsY);
1327 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1328 &(globalLabels[0]), newResidX, newHitErrX);
1331 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1332 &(globalLabels[0]));
1333 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1334 iTrajHit, newResidX, newHitErrX,
false);
1336 const bool isReal2DHit = this->
is2D(aRecHit);
1338 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1339 &(globalLabels[0]), newResidY, newHitErrY);
1341 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1342 &(globalLabels[0]));
1343 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1344 iTrajHit, newResidY, newHitErrY,
true);
1348 return (isReal2DHit ? 2 : 1);
1355 TMatrixDSym aHitCovarianceM(1);
1356 TMatrixF aHitResidualsM(1,1);
1357 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1359 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1362 TMatrixF aGlobalDerivativesM(1,1);
1363 aGlobalDerivativesM(0,0) = 0;
1365 float newResidX = aHitResidualsM(0,0);
1366 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1367 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1368 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1369 const int nLocal = aLocalDerivativesM.GetNcols();
1370 const int nGlobal = 0;
1372 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1373 &nGlobal, newResidX, newHitErrX);
1381 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1382 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1383 iBeam != iEnd; ++iBeam, ++iTsoses){
1385 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1386 <<
"Beam " << iBeam->getBeamId() <<
" with "
1387 << iBeam->parameters().size() <<
" parameters and "
1388 << iBeam->getData().size() <<
" hits.\n There are "
1389 << iTsoses->size() <<
" TSOSes.";
1391 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1398 const std::vector<TrajectoryStateOnSurface> &tsoses)
1401 std::vector<float> lasLocalDerivsX;
1404 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1405 if (!tsoses[iHit].isValid())
continue;
1410 lasLocalDerivsX.clear();
1415 tsoses[iHit], lasAli, lasAli,
1418 for (
unsigned int nFitParams = 0;
1419 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1423 lasLocalDerivsX.push_back(derivative);
1431 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1433 const float error = 0.003;
1445 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1446 if (doOutputOnStdout) {
1448 <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1449 <<
"# Output from addPxbSurvey follows below because "
1450 <<
"doOutputOnStdout is set to True";
1458 std::vector<SurveyPxbImageLocalFit> measurements;
1465 if (doOutputOnStdout) {
1467 <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1468 <<
"Module " <<
i <<
": ";
1493 fidpointvec.push_back(fidpoint0inSurf1frame);
1494 fidpointvec.push_back(fidpoint1inSurf1frame);
1495 fidpointvec.push_back(fidpoint2);
1496 fidpointvec.push_back(fidpoint3);
1507 a = measurements[
i].getLocalParameters();
1511 if (doOutputOnStdout)
1514 <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1515 <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1516 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1517 <<
" phi= " << atan(a[3]/a[2])
1518 <<
" chi2= " << chi2 << std::endl;
1523 theMonitor->fillPxbSurveyHistsLocalPars(a[0],a[1],
sqrt(a[2]*a[2]+a[3]*a[3]),atan(a[3]/a[2]));
1529 theMille->mille((
int)measurements[
i].getLocalDerivsSize(),
1530 measurements[
i].getLocalDerivsPtr(
j),
1531 (
int)measurements[
i].getGlobalDerivsSize(),
1532 measurements[
i].getGlobalDerivsPtr(
j),
1533 measurements[
i].getGlobalDerivsLabelPtr(
j),
1534 measurements[
i].getResiduum(
j),
1535 measurements[
i].getSigma(
j));
virtual bool processesEvents() override
Returns whether MP should process events in the current configuration.
unsigned int hitsX() const
get number of hits for x-measurement
const TimeTypeSpecs timeTypeSpecs[]
std::vector< int > theIntBuffer
T getParameter(std::string const &) const
unsigned int firstFixedParameter() const
void globalDerivativesCalibration(const TransientTrackingRecHit::ConstRecHitPointer &recHit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo, std::vector< float > &globalDerivativesX, std::vector< float > &globalDerivativesY, std::vector< int > &globalLabels) const
adding derivatives from integrated calibrations
T getUntrackedParameter(std::string const &, T const &) const
std::vector< AlignmentUserVariables * > readMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, int &ierr)
unsigned int size() const
number of parameters
void resetParameters(void)
reset parameters, correlations, user variables
virtual bool supportsCalibrations() override
Returns whether MP supports calibrations.
std::unique_ptr< MillePedeMonitor > theMonitor
void increaseHitsX(unsigned int add=1)
increase hits for x-measurement
bool read(std::vector< Alignable * > &alignables, bool setUserVars)
virtual bool setParametersForRunRange(const RunRange &runrange) override
Derivative< X, A >::type derivative(const A &_)
virtual void endRun(const EventInfo &, const EndRunInfo &, const edm::EventSetup &)
Run on run products, e.g. TkLAS.
std::vector< coord_t > fidpoint_t
void increaseHitsY(unsigned int add=1)
increase hits for y-measurement
std::vector< Alignable * > theAlignables
virtual void endLuminosityBlock(const edm::EventSetup &) override
called at end of luminosity block
TrajectoryFactoryBase::ReferenceTrajectoryCollection RefTrajColl
std::vector< ParameterSet > VParameterSet
std::unique_ptr< TrajectoryFactoryBase > theTrajectoryFactory
bool theDoSurveyPixelBarrel
void writeAlignableOriginalPositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable original (before misalignment) absolute positions
std::unique_ptr< gbl::MilleBinary > theBinary
int addGlobalData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, gbl::GblPoint &gblPoint)
unsigned int theMinNumHits
bool exists(std::string const ¶meterName) const
checks if a parameter exists
bool globalDerivativesHierarchy(const EventInfo &eventInfo, const TrajectoryStateOnSurface &tsos, Alignable *ali, const AlignableDetOrUnitPtr &alidet, std::vector< float > &globalDerivativesX, std::vector< float > &globalDerivativesY, std::vector< int > &globalLabels, AlignmentParameters *&lowestParams) const
recursively adding derivatives and labels, false if problems
void restoreCachedTransformations(void)
restore the previously cached position, rotation and other parameters
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
std::vector< std::string > getExistingFormattedFiles(const std::vector< std::string > &plainFiles, const std::string &theDir)
unsigned int addHitCount(const std::vector< AlignmentParameters * > &parVec, const std::vector< bool > &validHitVecY) const
virtual LocalPoint localPosition() const
virtual bool addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals) override
Pass integrated calibrations to Millepede (they are not owned by Millepede!)
const AlgebraicMatrix & derivatives() const
matrix of local derivatives: columns are parameters, rows are hits
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
int callMille2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy)
std::pair< RunNumber, RunNumber > RunRange
const bool ignoreHitsWithoutGlobalDerivatives_
void addLasBeam(const EventInfo &eventInfo, const TkFittedLasBeam &lasBeam, const std::vector< TrajectoryStateOnSurface > &tsoses)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
const ConstTrajTrackPairCollection & trajTrackPairs() const
define event information passed to algorithms
unsigned int doIO(int loop) const
int callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX, const std::vector< float > &globalDerivativesY)
calls callMille1D or callMille2D
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
U second(std::pair< T, U > const &p)
const AlgebraicVector & parameters(void) const
Get alignment parameters.
virtual void beginLuminosityBlock(const edm::EventSetup &) override
called at begin of luminosity block (resets Mille binary in mille mode)
std::string doDice(const fidpoint_t &fidpointvec, const idPair_t &id, const bool rotate=false)
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
int callMille1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX)
calls Mille for 1D hits
void addLaserData(const EventInfo &eventInfo, const TkFittedLasBeamCollection &tkLasBeams, const TsosVectorCollection &tkLasBeamTsoses)
int addMeasurementData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, AlignmentParameters *¶ms)
bool isMode(unsigned int testMode) const
Container::value_type value_type
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
virtual AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const =0
Get derivatives of selected parameters.
CLHEP::HepMatrix AlgebraicMatrix
const std::vector< Scalar > & parameters() const
parallel to derivatives()
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool is2D(HitType hitType)
unsigned int getBeamId(void) const
return the full beam identifier
AlignmentParameterStore * theAlignmentParameterStore
directory for all kind of files
unsigned int hitsY() const
get number of hits for y-measurement
bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
true if hit belongs to 2D detector (currently tracker specific)
void diagonalize(TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM, TMatrixF &theGlobalDerivativesM) const
std::unique_ptr< PedeLabelerBase > thePedeLabels
edm::ParameterSet theConfig
const TkFittedLasBeamCollection * tkLasBeams() const
std::unique_ptr< PedeSteerer > thePedeSteer
void addGlobals(const std::vector< int > &aLabels, const TMatrixD &aDerivatives)
Add global derivatives to a point.
virtual void terminate() override
Called at end of job.
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
virtual void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Called at beginning of job.
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
bool addHits(const std::vector< Alignable * > &alis, const std::vector< AlignmentUserVariables * > &mpVars) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
void writeMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, bool validCheck, int &ierr)
bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector< std::string > &inFiles) const
bool areEmptyParams(const std::vector< Alignable * > &alignables) const
void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas)
adds data for virtual measurements from reference trajectory
bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange)
read pede input defined by 'psetName', flag to create/not create MillePedeVariables ...
CLHEP::HepVector AlgebraicVector
std::pair< unsigned int, unsigned int > addReferenceTrajectory(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
fill mille for a trajectory, returning number of x/y hits ([0,0] if 'bad' trajectory) ...
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
const SiStripDetId & getDetId(void) const
void addRefTrackData2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM, TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
adds data from reference trajectory from a specific Hit
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
std::vector< IntegratedCalibrationBase * > theCalibrations
int size(void) const
Get number of parameters.
std::vector< float > theFloatBufferX
void makeGlobDerivMatrix(const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy, TMatrixF &aGlobalDerivativesM)
void addUntrackedParameter(std::string const &name, T const &value)
Class to hold one picture of the BPix survey.
T const * product() const
std::vector< value_t > localpars_t
virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm on trajectories and tracks.
void buildUserVariables(const std::vector< Alignable * > &alignables) const
add MillePedeVariables for each AlignmentParameters (exception if no parameters...)
MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg)
Constructor.
virtual ~MillePedeAlignmentAlgorithm()
Destructor.
std::vector< TkFittedLasBeam > TkFittedLasBeamCollection
const reco::BeamSpot & beamSpot() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
void cacheTransformations(void)
cache the current position, rotation and other parameters
std::vector< float > theFloatBufferY
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
void addRefTrackVirtualMeas1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM, TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
adds data for a specific virtual measurement from reference trajectory
static const count_t nMsrmts
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable current absolute positions
void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg)
add measurement data from PXB survey
unsigned int decodeMode(const std::string &mode) const
std::string fullPath() const
std::unique_ptr< AlignableNavigator > theAlignableNavigator
const std::vector< SiStripLaserRecHit2D > & getData(void) const
access the collection of hits
void writeOrigRigidBodyAlignmentParameters(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write RigidBodyAlignmentParameters as applied on top of original positions
std::vector< std::vector< TrajectoryStateOnSurface > > TsosVectorCollection
define run information passed to algorithms (in endRun)
const TsosVectorCollection * tkLasBeamTsoses() const
might be null!
const AlgebraicSymMatrix & covariance(void) const
Get parameter covariance matrix.
Constructor of the full muon geometry.
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
Alignable * mother() const
Return pointer to container alignable (if any)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
tuple size
Write out results.
T get(const Candidate &c)
bool setAllDefault(unsigned int nParam)
set default values for all data concerning nParam (false if nParam out of range)
std::unique_ptr< Mille > theMille