64 #include <TMatrixDSymEigen.h>
88 theMode(this->decodeMode(theConfig.getUntrackedParameter<std::
string>(
"mode"))),
89 theDir(theConfig.getUntrackedParameter<std::
string>(
"fileDir")),
90 theAlignmentParameterStore(
nullptr),
92 theMinNumHits(cfg.getParameter<unsigned int>(
"minNumHits")),
93 theMaximalCor2D(cfg.getParameter<double>(
"max2Dcorrelation")),
95 theGblDoubleBinary(cfg.getParameter<bool>(
"doubleBinary")),
96 runAtPCL_(cfg.getParameter<bool>(
"runAtPCL")),
97 ignoreHitsWithoutGlobalDerivatives_(cfg.getParameter<bool>(
"ignoreHitsWithoutGlobalDerivatives"))
100 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '"
102 <<
"' with output directory '" <<
theDir <<
"'.";
123 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
124 <<
"Running with AlignabeMuon not yet tested.";
139 RunRangeSelectionVPSet);
142 if (RunRangeSelectionVPSet.size()>0) {
143 labelerPlugin =
"RunRangeDependentPedeLabeler";
144 if (pedeLabelerCfg.
exists(
"plugin")) {
146 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
149 <<
"MillePedeAlignmentAlgorithm::initialize"
150 <<
"both RunRangeSelection and generic labeler specified in config file. "
151 <<
"Please get rid of either one of them.\n";
155 if (pedeLabelerCfg.
exists(
"plugin")) {
160 if (!pedeLabelerCfg.
exists(
"plugin")) {
164 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
165 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
168 ->create(labelerPlugin,
180 const std::vector<edm::ParameterSet> mprespset
182 if (!mprespset.empty()) {
183 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
184 <<
"Apply " << mprespset.end() - mprespset.begin()
185 <<
" previous MillePede constants from 'pedeReaderInputs'.";
192 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
193 iSet != iE; ++iSet) {
198 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
199 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
201 theAlignmentParameterStore->applyParameters();
203 theAlignmentParameterStore->resetParameters();
216 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
217 <<
"modes running mille.";
220 if (moniFile.size())
theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (theDir + moniFile).c_str());
226 ->create(fctName, fctCfg));
273 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
274 <<
"Problems reading pede result, but applying!";
295 std::vector<std::string>
files;
299 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
303 for (
const auto&
file: files) filesForLogOutput +=
" " +
file +
",";
304 if (filesForLogOutput.length() != 0) filesForLogOutput.pop_back();
306 <<
"Based on the config parameter mergeBinaryFiles, using the following "
307 <<
"files as input (assigned weights are indicated by ' -- <weight>'):"
308 << filesForLogOutput;
326 std::vector<std::string>
files;
327 for (
const auto& plainFile: plainFiles) {
333 char theNumberedInputFileName[200];
334 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
335 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
336 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
337 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
340 if (stat (strippedInputFileName.c_str(), &buffer) == 0) {
342 files.push_back(theCompleteInputFileName);
343 if (theNumberedInputFileName == theInputFileName) {
356 if (theNumber == 0 && (files.size() == 0 || files.back() != plainFile)) {
358 <<
"The input file '" << plainFile <<
"' does not exist.";
372 for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
373 iTrajTrack != tracks.end(); ++iTrajTrack) {
381 unsigned int refTrajCount = 0;
382 for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
383 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
388 const std::pair<unsigned int, unsigned int> nHitXy
391 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
395 (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
396 theMonitor->fillUsedTrack(trackPtr, nHitXy.first, nHitXy.second);
403 std::pair<unsigned int, unsigned int>
408 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
409 if (refTrajPtr->isValid()) {
413 if (refTrajPtr->gblInput().size() > 0) {
415 unsigned int iHit = 0;
416 unsigned int numPointsWithMeas = 0;
417 std::vector<GblPoint>::iterator itPoint;
418 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
419 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
420 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
421 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
422 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
425 hitResultXy.first = numPointsWithMeas;
427 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
429 if (refTrajPtr->gblInput().size() == 1) {
431 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
441 if (refTrajPtr->gblInput().size() == 2) {
443 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
449 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
451 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
453 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
454 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
457 hitResultXy.first = 0;
460 if (flagXY >= 1) ++hitResultXy.first;
461 validHitVecY[iHit] = (flagXY >= 2);
466 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
471 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
473 hitResultXy.first = hitResultXy.second = 0;
478 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
491 const std::vector<bool> &validHitVecY)
const
494 unsigned int nHitY = 0;
495 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
496 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
507 if (validHitVecY[iHit]) {
509 if (pars == parVec[iHit]) ++nHitY;
565 if (!recHitPtr->isValid())
return 0;
592 unsigned int iHit,
GblPoint &gblPoint)
595 std::vector<double> theDoubleBufferX, theDoubleBufferY;
596 theDoubleBufferX.clear();
597 theDoubleBufferY.clear();
604 if (!recHitPtr->isValid())
return 0;
610 tsos, alidet, alidet, theDoubleBufferX,
616 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
619 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
620 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
622 globalLabel =
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
623 if (globalLabel > 0 && globalLabel <= 2147483647) {
625 theDoubleBufferX.push_back(iValuesInd->first.first);
626 theDoubleBufferY.push_back(iValuesInd->first.second);
628 std::cerr <<
"MillePedeAlignmentAlgorithm::addGlobalData: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
635 TMatrixD globalDer(2,numGlobals);
636 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
637 globalDer(0,
i) = theDoubleBufferX[
i];
638 globalDer(1,
i) = theDoubleBufferY[
i];
651 std::vector<float> &globalDerivativesX,
652 std::vector<float> &globalDerivativesY,
653 std::vector<int> &globalLabels,
657 if (!ali)
return true;
659 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
664 if (!lowestParams) lowestParams = params;
666 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
667 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
669 if (0 == alignableLabel) {
670 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
671 <<
"Label not found, skip Alignable.";
675 const std::vector<bool> &selPars = params->
selector();
679 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
681 globalDerivativesX.push_back(derivs[iSel][kLocalX]
682 /thePedeSteer->cmsToPedeFactor(iSel));
683 if (hasSplitParameters==
true) {
684 globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
686 globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
688 globalDerivativesY.push_back(derivs[iSel][kLocalY]
689 /thePedeSteer->cmsToPedeFactor(iSel));
693 if (thePedeSteer->isNoHiera(ali))
return true;
696 return this->globalDerivativesHierarchy(eventInfo,
697 tsos, ali->
mother(), alidet,
698 globalDerivativesX, globalDerivativesY,
699 globalLabels, lowestParams);
707 std::vector<double> &globalDerivativesX,
708 std::vector<double> &globalDerivativesY,
709 std::vector<int> &globalLabels,
713 if (!ali)
return true;
715 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
720 if (!lowestParams) lowestParams = params;
722 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
723 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
725 if (0 == alignableLabel) {
726 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
727 <<
"Label not found, skip Alignable.";
731 const std::vector<bool> &selPars = params->
selector();
736 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
738 if (hasSplitParameters==
true) {
739 globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
741 globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
743 if (globalLabel > 0 && globalLabel <= 2147483647) {
744 globalLabels.push_back(globalLabel);
745 globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
746 globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
748 std::cerr <<
"MillePedeAlignmentAlgorithm::globalDerivativesHierarchy: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
753 if (thePedeSteer->isNoHiera(ali))
return true;
756 return this->globalDerivativesHierarchy(eventInfo,
757 tsos, ali->
mother(), alidet,
758 globalDerivativesX, globalDerivativesY,
759 globalLabels, lowestParams);
767 std::vector<float> &globalDerivativesX,
768 std::vector<float> &globalDerivativesY,
769 std::vector<int> &globalLabels)
const
771 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
774 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
775 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
777 globalLabels.push_back(
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
778 globalDerivativesX.push_back(iValuesInd->first.first);
779 globalDerivativesY.push_back(iValuesInd->first.second);
823 if (recHit->dimension() < 2) {
825 }
else if (recHit->detUnit()) {
826 return recHit->detUnit()->type().isTrackerPixel();
828 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
844 std::vector<Alignable*> alis;
845 bool okRead = reader.
read(alis, setUserVars);
846 bool numMatch =
true;
848 std::stringstream
out;
849 out <<
"Read " << alis.size() <<
" alignables";
854 if (!okRead) out <<
", but problems in reading";
855 if (!allEmpty) out <<
", possibly overwriting previous settings";
858 if (okRead && allEmpty) {
860 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
861 }
else if (alis.size()) {
862 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
864 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
870 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
878 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
879 iAli != alignables.end(); ++iAli) {
884 for (
int i = 0;
i < parVec.num_row(); ++
i) {
885 if (parVec[
i] != 0.)
return false;
886 for (
int j =
i;
j < parCov.num_col(); ++
j) {
887 if (parCov[
i][
j] != 0.)
return false;
902 if (outFilePlain.empty()) {
903 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
904 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
915 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
916 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
919 }
else if (loop == 1) {
921 const std::vector<std::string> inFiles
923 const std::vector<std::string> binFiles
925 if (inFiles.size() != binFiles.size()) {
926 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
927 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
935 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
936 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
942 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
943 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
948 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
949 <<
" in writeAlignableAbsolutePositions, " <<
loop;
959 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
962 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
963 <<
"No parameters for alignable";
967 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
984 if (mode ==
"full") {
986 }
else if (mode ==
"mille") {
988 }
else if (mode ==
"pede") {
990 }
else if (mode ==
"pedeSteer") {
992 }
else if (mode ==
"pedeRun") {
994 }
else if (mode ==
"pedeRead") {
999 <<
"Unknown mode '" << mode
1000 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
1007 const std::vector<std::string> &inFiles)
const
1012 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
1013 iFile != inFiles.end(); ++iFile) {
1015 const std::vector<AlignmentUserVariables*> mpVars =
1018 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1019 <<
"Error " << ierr <<
" reading from " << inFile
1020 <<
", tree " << fromIov <<
", or problems in addHits";
1023 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
1024 i != mpVars.end(); ++
i) {
1034 const std::vector<AlignmentUserVariables*> &mpVars)
const
1036 bool allOk = (mpVars.size() == alis.size());
1037 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1038 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1039 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1043 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1057 const std::vector<float> &globalDerivativesy,
1058 TMatrixF &aGlobalDerivativesM)
1061 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
1062 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1063 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1069 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1070 TMatrixF &aGlobalDerivativesM)
const
1072 TMatrixDSymEigen myDiag(aHitCovarianceM);
1073 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1074 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1075 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1076 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1082 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1083 aTranfoToDiagonalSystemInvF.Invert();
1085 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1088 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1089 if (aGlobalDerivativesM.GetNoElements() > 0) {
1091 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1098 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1099 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1103 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1107 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1110 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1117 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1118 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1125 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1126 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1130 const unsigned int xIndex = iTrajHit*2;
1131 const unsigned int yIndex = iTrajHit*2+1;
1135 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1136 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1137 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1138 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1141 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1142 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1149 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1150 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1151 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1158 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1159 const std::vector<float> &globalDerivativesX,
1160 const std::vector<float> &globalDerivativesY)
1164 if((aRecHit)->dimension() == 1) {
1165 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1167 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1168 globalDerivativesX, globalDerivativesY);
1176 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1177 const std::vector<float> &globalDerivativesX)
1180 const unsigned int xIndex = iTrajHit*2;
1184 const int nLocal = locDerivMatrix.num_col();
1185 std::vector<float> localDerivatives(nLocal);
1186 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1187 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1191 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1192 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1195 const int nGlobal = globalDerivativesX.size();
1199 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1200 &(globalLabels[0]), residX, hitErrX);
1203 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1204 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1205 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1206 iTrajHit, residX, hitErrX,
false);
1215 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1216 const std::vector<float> &globalDerivativesx,
1217 const std::vector<float> &globalDerivativesy)
1221 if((aRecHit)->dimension() != 2) {
1222 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1223 <<
"You try to call method for 2D hits for a "
1225 <<
"D Hit. Hit gets ignored!";
1229 TMatrixDSym aHitCovarianceM(2);
1230 TMatrixF aHitResidualsM(2,1);
1231 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1233 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1234 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1235 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1240 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1241 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1243 switch(aRecHit->geographicalId().subdetId()) {
1247 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1254 float newResidX = aHitResidualsM(0,0);
1255 float newResidY = aHitResidualsM(1,0);
1256 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1257 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1258 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1259 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1260 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1261 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1262 const int nLocal = aLocalDerivativesM.GetNcols();
1263 const int nGlobal = aGlobalDerivativesM.GetNcols();
1265 if (diag && (newHitErrX > newHitErrY)) {
1269 std::swap(newLocalDerivsX, newLocalDerivsY);
1270 std::swap(newGlobDerivsX, newGlobDerivsY);
1275 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1276 &(globalLabels[0]), newResidX, newHitErrX);
1279 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1280 &(globalLabels[0]));
1281 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1282 iTrajHit, newResidX, newHitErrX,
false);
1284 const bool isReal2DHit = this->
is2D(aRecHit);
1286 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1287 &(globalLabels[0]), newResidY, newHitErrY);
1289 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1290 &(globalLabels[0]));
1291 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1292 iTrajHit, newResidY, newHitErrY,
true);
1296 return (isReal2DHit ? 2 : 1);
1303 TMatrixDSym aHitCovarianceM(1);
1304 TMatrixF aHitResidualsM(1,1);
1305 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1307 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1310 TMatrixF aGlobalDerivativesM(1,1);
1311 aGlobalDerivativesM(0,0) = 0;
1313 float newResidX = aHitResidualsM(0,0);
1314 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1315 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1316 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1317 const int nLocal = aLocalDerivativesM.GetNcols();
1318 const int nGlobal = 0;
1320 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1321 &nGlobal, newResidX, newHitErrX);
1329 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1330 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1331 iBeam != iEnd; ++iBeam, ++iTsoses){
1333 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1334 <<
"Beam " << iBeam->getBeamId() <<
" with "
1335 << iBeam->parameters().size() <<
" parameters and "
1336 << iBeam->getData().size() <<
" hits.\n There are "
1337 << iTsoses->size() <<
" TSOSes.";
1339 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1346 const std::vector<TrajectoryStateOnSurface> &tsoses)
1349 std::vector<float> lasLocalDerivsX;
1352 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1353 if (!tsoses[iHit].isValid())
continue;
1358 lasLocalDerivsX.clear();
1363 tsoses[iHit], lasAli, lasAli,
1366 for (
unsigned int nFitParams = 0;
1367 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1371 lasLocalDerivsX.push_back(derivative);
1379 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1381 const float error = 0.003;
1393 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1394 if (doOutputOnStdout)
std::cout <<
"# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1401 std::vector<SurveyPxbImageLocalFit> measurements;
1408 if (doOutputOnStdout)
std::cout <<
"Module " <<
i <<
": ";
1432 fidpointvec.push_back(fidpoint0inSurf1frame);
1433 fidpointvec.push_back(fidpoint1inSurf1frame);
1434 fidpointvec.push_back(fidpoint2);
1435 fidpointvec.push_back(fidpoint3);
1440 dicer.
doDice(fidpointvec,measurements[i].getIdPair(),
outfile);
1446 a = measurements[
i].getLocalParameters();
1450 if (doOutputOnStdout)
1452 std::cout <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1453 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1454 <<
" phi= " << atan(a[3]/a[2])
1455 <<
" chi2= " << chi2 << std::endl;
1460 theMonitor->fillPxbSurveyHistsLocalPars(a[0],a[1],
sqrt(a[2]*a[2]+a[3]*a[3]),atan(a[3]/a[2]));
1466 theMille->mille((
int)measurements[i].getLocalDerivsSize(),
1467 measurements[i].getLocalDerivsPtr(
j),
1468 (
int)measurements[i].getGlobalDerivsSize(),
1469 measurements[i].getGlobalDerivsPtr(
j),
1470 measurements[i].getGlobalDerivsLabelPtr(
j),
1471 measurements[i].getResiduum(
j),
1472 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
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.
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)
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