67 #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"))
101 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '"
103 <<
"' with output directory '" <<
theDir <<
"'.";
124 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
125 <<
"Running with AlignabeMuon not yet tested.";
140 RunRangeSelectionVPSet);
143 if (RunRangeSelectionVPSet.size()>0) {
144 labelerPlugin =
"RunRangeDependentPedeLabeler";
145 if (pedeLabelerCfg.
exists(
"plugin")) {
147 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
150 <<
"MillePedeAlignmentAlgorithm::initialize"
151 <<
"both RunRangeSelection and generic labeler specified in config file. "
152 <<
"Please get rid of either one of them.\n";
156 if (pedeLabelerCfg.
exists(
"plugin")) {
161 if (!pedeLabelerCfg.
exists(
"plugin")) {
165 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
166 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
169 ->create(labelerPlugin,
181 const std::vector<edm::ParameterSet> mprespset
183 if (!mprespset.empty()) {
184 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
185 <<
"Apply " << mprespset.end() - mprespset.begin()
186 <<
" previous MillePede constants from 'pedeReaderInputs'.";
193 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
194 iSet != iE; ++iSet) {
199 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
200 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
202 theAlignmentParameterStore->applyParameters();
204 theAlignmentParameterStore->resetParameters();
217 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
218 <<
"modes running mille.";
221 if (moniFile.size())
theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (theDir + moniFile).c_str());
227 ->create(fctName, fctCfg));
274 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
275 <<
"Problems reading pede result, but applying!";
296 std::vector<std::string>
files;
300 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
304 for (
const auto&
file: files) filesForLogOutput +=
" " +
file +
",";
305 if (filesForLogOutput.length() != 0) filesForLogOutput.pop_back();
307 <<
"Based on the config parameter mergeBinaryFiles, using the following "
308 <<
"files as input (assigned weights are indicated by ' -- <weight>'):"
309 << filesForLogOutput;
327 std::vector<std::string>
files;
328 for (
const auto& plainFile: plainFiles) {
334 char theNumberedInputFileName[200];
335 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
336 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
337 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
338 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
341 if (stat (strippedInputFileName.c_str(), &buffer) == 0) {
343 files.push_back(theCompleteInputFileName);
344 if (theNumberedInputFileName == theInputFileName) {
354 <<
"The input file '" << strippedInputFileName <<
"' does not exist.";
370 for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
371 iTrajTrack != tracks.end(); ++iTrajTrack) {
379 unsigned int refTrajCount = 0;
380 for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
381 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
386 const std::pair<unsigned int, unsigned int> nHitXy
389 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
393 (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
394 theMonitor->fillUsedTrack(trackPtr, nHitXy.first, nHitXy.second);
401 std::pair<unsigned int, unsigned int>
406 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
407 if (refTrajPtr->isValid()) {
411 if (refTrajPtr->gblInput().size() > 0) {
413 unsigned int iHit = 0;
414 unsigned int numPointsWithMeas = 0;
415 std::vector<GblPoint>::iterator itPoint;
416 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
417 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
418 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
419 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
420 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
423 hitResultXy.first = numPointsWithMeas;
425 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
427 if (refTrajPtr->gblInput().size() == 1) {
429 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
439 if (refTrajPtr->gblInput().size() == 2) {
441 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
447 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
449 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
451 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
452 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
455 hitResultXy.first = 0;
458 if (flagXY >= 1) ++hitResultXy.first;
459 validHitVecY[iHit] = (flagXY >= 2);
464 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
469 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
471 hitResultXy.first = hitResultXy.second = 0;
476 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
489 const std::vector<bool> &validHitVecY)
const
492 unsigned int nHitY = 0;
493 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
494 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
505 if (validHitVecY[iHit]) {
507 if (pars == parVec[iHit]) ++nHitY;
549 if (!recHitPtr->isValid())
return 0;
574 unsigned int iHit,
GblPoint &gblPoint)
577 std::vector<double> theDoubleBufferX, theDoubleBufferY;
578 theDoubleBufferX.clear();
579 theDoubleBufferY.clear();
586 if (!recHitPtr->isValid())
return 0;
592 tsos, alidet, alidet, theDoubleBufferX,
598 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
601 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
602 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
604 globalLabel =
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
605 if (globalLabel > 0 && globalLabel <= 2147483647) {
607 theDoubleBufferX.push_back(iValuesInd->first.first);
608 theDoubleBufferY.push_back(iValuesInd->first.second);
610 std::cerr <<
"MillePedeAlignmentAlgorithm::addGlobalData: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
617 TMatrixD globalDer(2,numGlobals);
618 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
619 globalDer(0,
i) = theDoubleBufferX[
i];
620 globalDer(1,
i) = theDoubleBufferY[
i];
633 std::vector<float> &globalDerivativesX,
634 std::vector<float> &globalDerivativesY,
635 std::vector<int> &globalLabels,
639 if (!ali)
return true;
641 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
646 if (!lowestParams) lowestParams = params;
648 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
649 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
651 if (0 == alignableLabel) {
652 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
653 <<
"Label not found, skip Alignable.";
657 const std::vector<bool> &selPars = params->
selector();
661 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
663 globalDerivativesX.push_back(derivs[iSel][kLocalX]
664 /thePedeSteer->cmsToPedeFactor(iSel));
665 if (hasSplitParameters==
true) {
666 globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
668 globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
670 globalDerivativesY.push_back(derivs[iSel][kLocalY]
671 /thePedeSteer->cmsToPedeFactor(iSel));
675 if (thePedeSteer->isNoHiera(ali))
return true;
678 return this->globalDerivativesHierarchy(eventInfo,
679 tsos, ali->
mother(), alidet,
680 globalDerivativesX, globalDerivativesY,
681 globalLabels, lowestParams);
689 std::vector<double> &globalDerivativesX,
690 std::vector<double> &globalDerivativesY,
691 std::vector<int> &globalLabels,
695 if (!ali)
return true;
697 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
702 if (!lowestParams) lowestParams = params;
704 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
705 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
707 if (0 == alignableLabel) {
708 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
709 <<
"Label not found, skip Alignable.";
713 const std::vector<bool> &selPars = params->
selector();
718 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
720 if (hasSplitParameters==
true) {
721 globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
723 globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
725 if (globalLabel > 0 && globalLabel <= 2147483647) {
726 globalLabels.push_back(globalLabel);
727 globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
728 globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
730 std::cerr <<
"MillePedeAlignmentAlgorithm::globalDerivativesHierarchy: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
735 if (thePedeSteer->isNoHiera(ali))
return true;
738 return this->globalDerivativesHierarchy(eventInfo,
739 tsos, ali->
mother(), alidet,
740 globalDerivativesX, globalDerivativesY,
741 globalLabels, lowestParams);
749 std::vector<float> &globalDerivativesX,
750 std::vector<float> &globalDerivativesY,
751 std::vector<int> &globalLabels)
const
753 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
756 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
757 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
759 globalLabels.push_back(
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
760 globalDerivativesX.push_back(iValuesInd->first.first);
761 globalDerivativesY.push_back(iValuesInd->first.second);
805 if (recHit->dimension() < 2) {
807 }
else if (recHit->detUnit()) {
808 return recHit->detUnit()->type().isTrackerPixel();
810 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
826 std::vector<Alignable*> alis;
827 bool okRead = reader.
read(alis, setUserVars);
828 bool numMatch =
true;
830 std::stringstream
out;
831 out <<
"Read " << alis.size() <<
" alignables";
836 if (!okRead) out <<
", but problems in reading";
837 if (!allEmpty) out <<
", possibly overwriting previous settings";
840 if (okRead && allEmpty) {
842 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
843 }
else if (alis.size()) {
844 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
846 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
852 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
860 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
861 iAli != alignables.end(); ++iAli) {
866 for (
int i = 0;
i < parVec.num_row(); ++
i) {
867 if (parVec[
i] != 0.)
return false;
868 for (
int j =
i;
j < parCov.num_col(); ++
j) {
869 if (parCov[
i][
j] != 0.)
return false;
884 if (outFilePlain.empty()) {
885 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
886 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
897 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
898 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
901 }
else if (loop == 1) {
903 const std::vector<std::string> inFiles
905 const std::vector<std::string> binFiles
907 if (inFiles.size() != binFiles.size()) {
908 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
909 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
917 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
918 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
924 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
925 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
930 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
931 <<
" in writeAlignableAbsolutePositions, " <<
loop;
941 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
944 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
945 <<
"No parameters for alignable";
949 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
966 if (mode ==
"full") {
968 }
else if (mode ==
"mille") {
970 }
else if (mode ==
"pede") {
972 }
else if (mode ==
"pedeSteer") {
974 }
else if (mode ==
"pedeRun") {
976 }
else if (mode ==
"pedeRead") {
981 <<
"Unknown mode '" << mode
982 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
989 const std::vector<std::string> &inFiles)
const
994 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
995 iFile != inFiles.end(); ++iFile) {
997 const std::vector<AlignmentUserVariables*> mpVars =
1000 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1001 <<
"Error " << ierr <<
" reading from " << inFile
1002 <<
", tree " << fromIov <<
", or problems in addHits";
1005 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
1006 i != mpVars.end(); ++
i) {
1016 const std::vector<AlignmentUserVariables*> &mpVars)
const
1018 bool allOk = (mpVars.size() == alis.size());
1019 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1020 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1021 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1025 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1039 const std::vector<float> &globalDerivativesy,
1040 TMatrixF &aGlobalDerivativesM)
1043 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
1044 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1045 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1051 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1052 TMatrixF &aGlobalDerivativesM)
const
1054 TMatrixDSymEigen myDiag(aHitCovarianceM);
1055 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1056 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1057 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1058 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1064 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1065 aTranfoToDiagonalSystemInvF.Invert();
1067 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1070 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1071 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1077 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1078 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1082 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1086 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1089 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1096 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1097 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1104 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1105 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1109 const unsigned int xIndex = iTrajHit*2;
1110 const unsigned int yIndex = iTrajHit*2+1;
1114 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1115 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1116 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1117 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1120 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1121 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1128 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1129 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1130 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1137 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1138 const std::vector<float> &globalDerivativesX,
1139 const std::vector<float> &globalDerivativesY)
1143 if((aRecHit)->dimension() == 1) {
1144 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1146 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1147 globalDerivativesX, globalDerivativesY);
1155 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1156 const std::vector<float> &globalDerivativesX)
1159 const unsigned int xIndex = iTrajHit*2;
1163 const int nLocal = locDerivMatrix.num_col();
1164 std::vector<float> localDerivatives(nLocal);
1165 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1166 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1170 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1171 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1174 const int nGlobal = globalDerivativesX.size();
1178 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1179 &(globalLabels[0]), residX, hitErrX);
1182 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1183 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1184 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1185 iTrajHit, residX, hitErrX,
false);
1194 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1195 const std::vector<float> &globalDerivativesx,
1196 const std::vector<float> &globalDerivativesy)
1200 if((aRecHit)->dimension() != 2) {
1201 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1202 <<
"You try to call method for 2D hits for a "
1204 <<
"D Hit. Hit gets ignored!";
1208 TMatrixDSym aHitCovarianceM(2);
1209 TMatrixF aHitResidualsM(2,1);
1210 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1212 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1213 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1214 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1219 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1220 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1222 switch(aRecHit->geographicalId().subdetId()) {
1226 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1233 float newResidX = aHitResidualsM(0,0);
1234 float newResidY = aHitResidualsM(1,0);
1235 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1236 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1237 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1238 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1239 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1240 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1241 const int nLocal = aLocalDerivativesM.GetNcols();
1242 const int nGlobal = aGlobalDerivativesM.GetNcols();
1244 if (diag && (newHitErrX > newHitErrY)) {
1248 std::swap(newLocalDerivsX, newLocalDerivsY);
1249 std::swap(newGlobDerivsX, newGlobDerivsY);
1254 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1255 &(globalLabels[0]), newResidX, newHitErrX);
1258 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1259 &(globalLabels[0]));
1260 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1261 iTrajHit, newResidX, newHitErrX,
false);
1263 const bool isReal2DHit = this->
is2D(aRecHit);
1265 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1266 &(globalLabels[0]), newResidY, newHitErrY);
1268 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1269 &(globalLabels[0]));
1270 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1271 iTrajHit, newResidY, newHitErrY,
true);
1275 return (isReal2DHit ? 2 : 1);
1282 TMatrixDSym aHitCovarianceM(1);
1283 TMatrixF aHitResidualsM(1,1);
1284 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1286 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1289 TMatrixF aGlobalDerivativesM(1,1);
1290 aGlobalDerivativesM(0,0) = 0;
1292 float newResidX = aHitResidualsM(0,0);
1293 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1294 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1295 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1296 const int nLocal = aLocalDerivativesM.GetNcols();
1297 const int nGlobal = 0;
1299 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1300 &nGlobal, newResidX, newHitErrX);
1308 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1309 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1310 iBeam != iEnd; ++iBeam, ++iTsoses){
1312 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1313 <<
"Beam " << iBeam->getBeamId() <<
" with "
1314 << iBeam->parameters().size() <<
" parameters and "
1315 << iBeam->getData().size() <<
" hits.\n There are "
1316 << iTsoses->size() <<
" TSOSes.";
1318 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1325 const std::vector<TrajectoryStateOnSurface> &tsoses)
1328 std::vector<float> lasLocalDerivsX;
1331 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1332 if (!tsoses[iHit].isValid())
continue;
1337 lasLocalDerivsX.clear();
1342 tsoses[iHit], lasAli, lasAli,
1345 for (
unsigned int nFitParams = 0;
1346 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1350 lasLocalDerivsX.push_back(derivative);
1358 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1360 const float error = 0.003;
1372 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1373 if (doOutputOnStdout)
std::cout <<
"# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1380 std::vector<SurveyPxbImageLocalFit> measurements;
1387 if (doOutputOnStdout)
std::cout <<
"Module " <<
i <<
": ";
1411 fidpointvec.push_back(fidpoint0inSurf1frame);
1412 fidpointvec.push_back(fidpoint1inSurf1frame);
1413 fidpointvec.push_back(fidpoint2);
1414 fidpointvec.push_back(fidpoint3);
1419 dicer.
doDice(fidpointvec,measurements[i].getIdPair(),
outfile);
1425 a = measurements[
i].getLocalParameters();
1429 if (doOutputOnStdout)
1431 std::cout <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1432 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1433 <<
" phi= " << atan(a[3]/a[2])
1434 <<
" chi2= " << chi2 << std::endl;
1439 theMonitor->fillPxbSurveyHistsLocalPars(a[0],a[1],
sqrt(a[2]*a[2]+a[3]*a[3]),atan(a[3]/a[2]));
1445 theMille->mille((
int)measurements[i].getLocalDerivsSize(),
1446 measurements[i].getLocalDerivsPtr(
j),
1447 (
int)measurements[i].getGlobalDerivsSize(),
1448 measurements[i].getGlobalDerivsPtr(
j),
1449 measurements[i].getGlobalDerivsLabelPtr(
j),
1450 measurements[i].getResiduum(
j),
1451 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)
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
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
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
virtual void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store)
Called at beginning of job.
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
const AlgebraicVector & parameters(void) const
Get alignment parameters.
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
virtual bool setParametersForRunRange(const RunRange &runrange)
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.
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 bool addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals)
Pass integrated calibrations to Millepede (they are not owned by Millepede!)
virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo)
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)
tuple size
Write out results.
T get(const Candidate &c)
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
bool setAllDefault(unsigned int nParam)
set default values for all data concerning nParam (false if nParam out of range)
std::unique_ptr< Mille > theMille
virtual void terminate()
Called at end of job.