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")),
99 runAtPCL_(cfg.getParameter<bool>(
"runAtPCL"))
102 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '"
104 <<
"' with output directory '" <<
theDir <<
"'.";
125 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
126 <<
"Running with AlignabeMuon not yet tested.";
141 RunRangeSelectionVPSet);
144 if (RunRangeSelectionVPSet.size()>0) {
145 labelerPlugin =
"RunRangeDependentPedeLabeler";
146 if (pedeLabelerCfg.
exists(
"plugin")) {
148 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
151 <<
"MillePedeAlignmentAlgorithm::initialize"
152 <<
"both RunRangeSelection and generic labeler specified in config file. "
153 <<
"Please get rid of either one of them.\n";
157 if (pedeLabelerCfg.
exists(
"plugin")) {
162 if (!pedeLabelerCfg.
exists(
"plugin")) {
166 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
167 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
170 ->create(labelerPlugin,
182 const std::vector<edm::ParameterSet> mprespset
184 if (!mprespset.empty()) {
185 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
186 <<
"Apply " << mprespset.end() - mprespset.begin()
187 <<
" previous MillePede constants from 'pedeReaderInputs'.";
194 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
195 iSet != iE; ++iSet) {
200 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
201 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
203 theAlignmentParameterStore->applyParameters();
205 theAlignmentParameterStore->resetParameters();
218 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
219 <<
"modes running mille.";
222 if (moniFile.size())
theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (theDir + moniFile).c_str());
228 ->create(fctName, fctCfg));
275 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
276 <<
"Problems reading pede result, but applying!";
297 std::vector<std::string>
files;
301 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
305 for (
const auto&
file: files) filesForLogOutput +=
" " +
file +
",";
306 if (filesForLogOutput.length() != 0) filesForLogOutput.pop_back();
308 <<
"Based on the config parameter mergeBinaryFiles, using the following "
309 <<
"files as input (assigned weights are indicated by ' -- <weight>'):"
310 << filesForLogOutput;
328 std::vector<std::string>
files;
329 for (
const auto& plainFile: plainFiles) {
335 char theNumberedInputFileName[200];
336 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
337 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
338 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
339 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
342 if (stat (strippedInputFileName.c_str(), &buffer) == 0) {
344 files.push_back(theCompleteInputFileName);
345 if (theNumberedInputFileName == theInputFileName) {
358 if (theNumber == 0 && (files.size() == 0 || files.back() != plainFile)) {
360 <<
"The input file '" << plainFile <<
"' does not exist.";
374 for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
375 iTrajTrack != tracks.end(); ++iTrajTrack) {
383 unsigned int refTrajCount = 0;
384 for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
385 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
390 const std::pair<unsigned int, unsigned int> nHitXy
393 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
397 (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
398 theMonitor->fillUsedTrack(trackPtr, nHitXy.first, nHitXy.second);
405 std::pair<unsigned int, unsigned int>
410 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
411 if (refTrajPtr->isValid()) {
415 if (refTrajPtr->gblInput().size() > 0) {
417 unsigned int iHit = 0;
418 unsigned int numPointsWithMeas = 0;
419 std::vector<GblPoint>::iterator itPoint;
420 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
421 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
422 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
423 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
424 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
427 hitResultXy.first = numPointsWithMeas;
429 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
431 if (refTrajPtr->gblInput().size() == 1) {
433 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
443 if (refTrajPtr->gblInput().size() == 2) {
445 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
451 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
453 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
455 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
456 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
459 hitResultXy.first = 0;
462 if (flagXY >= 1) ++hitResultXy.first;
463 validHitVecY[iHit] = (flagXY >= 2);
468 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
473 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
475 hitResultXy.first = hitResultXy.second = 0;
480 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
493 const std::vector<bool> &validHitVecY)
const
496 unsigned int nHitY = 0;
497 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
498 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
509 if (validHitVecY[iHit]) {
511 if (pars == parVec[iHit]) ++nHitY;
567 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 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1095 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1096 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1100 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1104 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1107 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1114 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1115 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1122 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1123 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1127 const unsigned int xIndex = iTrajHit*2;
1128 const unsigned int yIndex = iTrajHit*2+1;
1132 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1133 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1134 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1135 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1138 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1139 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1146 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1147 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1148 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1155 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1156 const std::vector<float> &globalDerivativesX,
1157 const std::vector<float> &globalDerivativesY)
1161 if((aRecHit)->dimension() == 1) {
1162 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1164 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1165 globalDerivativesX, globalDerivativesY);
1173 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1174 const std::vector<float> &globalDerivativesX)
1177 const unsigned int xIndex = iTrajHit*2;
1181 const int nLocal = locDerivMatrix.num_col();
1182 std::vector<float> localDerivatives(nLocal);
1183 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1184 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1188 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1189 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1192 const int nGlobal = globalDerivativesX.size();
1196 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1197 &(globalLabels[0]), residX, hitErrX);
1200 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1201 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1202 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1203 iTrajHit, residX, hitErrX,
false);
1212 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1213 const std::vector<float> &globalDerivativesx,
1214 const std::vector<float> &globalDerivativesy)
1218 if((aRecHit)->dimension() != 2) {
1219 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1220 <<
"You try to call method for 2D hits for a "
1222 <<
"D Hit. Hit gets ignored!";
1226 TMatrixDSym aHitCovarianceM(2);
1227 TMatrixF aHitResidualsM(2,1);
1228 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1230 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1231 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1232 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1237 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1238 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1240 switch(aRecHit->geographicalId().subdetId()) {
1244 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1251 float newResidX = aHitResidualsM(0,0);
1252 float newResidY = aHitResidualsM(1,0);
1253 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1254 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1255 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1256 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1257 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1258 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1259 const int nLocal = aLocalDerivativesM.GetNcols();
1260 const int nGlobal = aGlobalDerivativesM.GetNcols();
1262 if (diag && (newHitErrX > newHitErrY)) {
1266 std::swap(newLocalDerivsX, newLocalDerivsY);
1267 std::swap(newGlobDerivsX, newGlobDerivsY);
1272 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1273 &(globalLabels[0]), newResidX, newHitErrX);
1276 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1277 &(globalLabels[0]));
1278 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1279 iTrajHit, newResidX, newHitErrX,
false);
1281 const bool isReal2DHit = this->
is2D(aRecHit);
1283 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1284 &(globalLabels[0]), newResidY, newHitErrY);
1286 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1287 &(globalLabels[0]));
1288 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1289 iTrajHit, newResidY, newHitErrY,
true);
1293 return (isReal2DHit ? 2 : 1);
1300 TMatrixDSym aHitCovarianceM(1);
1301 TMatrixF aHitResidualsM(1,1);
1302 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1304 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1307 TMatrixF aGlobalDerivativesM(1,1);
1308 aGlobalDerivativesM(0,0) = 0;
1310 float newResidX = aHitResidualsM(0,0);
1311 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1312 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1313 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1314 const int nLocal = aLocalDerivativesM.GetNcols();
1315 const int nGlobal = 0;
1317 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1318 &nGlobal, newResidX, newHitErrX);
1326 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1327 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1328 iBeam != iEnd; ++iBeam, ++iTsoses){
1330 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1331 <<
"Beam " << iBeam->getBeamId() <<
" with "
1332 << iBeam->parameters().size() <<
" parameters and "
1333 << iBeam->getData().size() <<
" hits.\n There are "
1334 << iTsoses->size() <<
" TSOSes.";
1336 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1343 const std::vector<TrajectoryStateOnSurface> &tsoses)
1346 std::vector<float> lasLocalDerivsX;
1349 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1350 if (!tsoses[iHit].isValid())
continue;
1355 lasLocalDerivsX.clear();
1360 tsoses[iHit], lasAli, lasAli,
1363 for (
unsigned int nFitParams = 0;
1364 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1368 lasLocalDerivsX.push_back(derivative);
1376 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1378 const float error = 0.003;
1390 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1391 if (doOutputOnStdout)
std::cout <<
"# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1398 std::vector<SurveyPxbImageLocalFit> measurements;
1405 if (doOutputOnStdout)
std::cout <<
"Module " <<
i <<
": ";
1429 fidpointvec.push_back(fidpoint0inSurf1frame);
1430 fidpointvec.push_back(fidpoint1inSurf1frame);
1431 fidpointvec.push_back(fidpoint2);
1432 fidpointvec.push_back(fidpoint3);
1437 dicer.
doDice(fidpointvec,measurements[i].getIdPair(),
outfile);
1443 a = measurements[
i].getLocalParameters();
1447 if (doOutputOnStdout)
1449 std::cout <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1450 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1451 <<
" phi= " << atan(a[3]/a[2])
1452 <<
" chi2= " << chi2 << std::endl;
1457 theMonitor->fillPxbSurveyHistsLocalPars(a[0],a[1],
sqrt(a[2]*a[2]+a[3]*a[3]),atan(a[3]/a[2]));
1463 theMille->mille((
int)measurements[i].getLocalDerivsSize(),
1464 measurements[i].getLocalDerivsPtr(
j),
1465 (
int)measurements[i].getGlobalDerivsSize(),
1466 measurements[i].getGlobalDerivsPtr(
j),
1467 measurements[i].getGlobalDerivsLabelPtr(
j),
1468 measurements[i].getResiduum(
j),
1469 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
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
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.
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
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.