67 #include <TMatrixDSymEigen.h>
90 theConfig(cfg), theMode(this->decodeMode(theConfig.getUntrackedParameter<std::
string>(
"mode"))),
91 theDir(theConfig.getUntrackedParameter<std::
string>(
"fileDir")),
92 theAlignmentParameterStore(0), theAlignables(), theAlignableNavigator(0),
93 theMonitor(0), theMille(0), thePedeLabels(0), thePedeSteer(0),
94 theTrajectoryFactory(0),
95 theMinNumHits(cfg.getParameter<unsigned int>(
"minNumHits")),
96 theMaximalCor2D(cfg.getParameter<double>(
"max2Dcorrelation")),
98 theBinary(0),theGblDoubleBinary(cfg.getParameter<bool>(
"doubleBinary"))
101 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '"
103 <<
"' with output directory '" <<
theDir <<
"'.";
136 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
137 <<
"Running with AlignabeMuon not yet tested.";
152 RunRangeSelectionVPSet);
155 if (RunRangeSelectionVPSet.size()>0) {
156 labelerPlugin =
"RunRangeDependentPedeLabeler";
157 if (pedeLabelerCfg.
exists(
"plugin")) {
159 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
162 <<
"MillePedeAlignmentAlgorithm::initialize"
163 <<
"both RunRangeSelection and generic labeler specified in config file. "
164 <<
"Please get rid of either one of them.\n";
168 if (pedeLabelerCfg.
exists(
"plugin")) {
173 if (!pedeLabelerCfg.
exists(
"plugin")) {
177 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
178 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
192 const std::vector<edm::ParameterSet> mprespset
194 if (!mprespset.empty()) {
195 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
196 <<
"Apply " << mprespset.end() - mprespset.begin()
197 <<
" previous MillePede constants from 'pedeReaderInputs'.";
204 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
205 iSet != iE; ++iSet) {
210 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
211 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
228 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
229 <<
"modes running mille.";
284 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
285 <<
"Problems reading pede result, but applying!";
306 std::vector<std::string>
files;
310 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
314 for (
const auto&
file: files) filesForLogOutput +=
" " +
file +
",";
315 if (filesForLogOutput.length() != 0) filesForLogOutput.pop_back();
317 <<
"Based on the config parameter mergeBinaryFiles, using the following "
318 <<
"files as input (assigned weights are indicated by ' -- <weight>'):"
319 << filesForLogOutput;
337 std::vector<std::string>
files;
338 for (
const auto& plainFile: plainFiles) {
344 char theNumberedInputFileName[200];
345 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
346 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
347 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
348 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
351 if (stat (strippedInputFileName.c_str(), &buffer) == 0) {
353 files.push_back(theCompleteInputFileName);
354 if (theNumberedInputFileName == theInputFileName) {
364 <<
"The input file '" << strippedInputFileName <<
"' does not exist.";
380 for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
381 iTrajTrack != tracks.end(); ++iTrajTrack) {
389 unsigned int refTrajCount = 0;
390 for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
391 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
396 const std::pair<unsigned int, unsigned int> nHitXy
399 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
403 (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
411 std::pair<unsigned int, unsigned int>
416 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
417 if (refTrajPtr->isValid()) {
421 if (refTrajPtr->gblInput().size() > 0) {
423 unsigned int iHit = 0;
424 unsigned int numPointsWithMeas = 0;
425 std::vector<GblPoint>::iterator itPoint;
426 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
427 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
428 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
429 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
430 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
433 hitResultXy.first = numPointsWithMeas;
435 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
437 if (refTrajPtr->gblInput().size() == 1) {
439 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
449 if (refTrajPtr->gblInput().size() == 2) {
451 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
457 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
459 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
461 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
462 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
465 hitResultXy.first = 0;
468 if (flagXY >= 1) ++hitResultXy.first;
469 validHitVecY[iHit] = (flagXY >= 2);
474 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
479 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
481 hitResultXy.first = hitResultXy.second = 0;
486 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
499 const std::vector<bool> &validHitVecY)
const
502 unsigned int nHitY = 0;
503 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
504 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
515 if (validHitVecY[iHit]) {
517 if (pars == parVec[iHit]) ++nHitY;
559 if (!recHitPtr->isValid())
return 0;
584 unsigned int iHit,
GblPoint &gblPoint)
587 std::vector<double> theDoubleBufferX, theDoubleBufferY;
588 theDoubleBufferX.clear();
589 theDoubleBufferY.clear();
596 if (!recHitPtr->isValid())
return 0;
602 tsos, alidet, alidet, theDoubleBufferX,
608 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
611 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
612 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
615 if (globalLabel > 0 && globalLabel <= 2147483647) {
617 theDoubleBufferX.push_back(iValuesInd->first.first);
618 theDoubleBufferY.push_back(iValuesInd->first.second);
620 std::cerr <<
"MillePedeAlignmentAlgorithm::addGlobalData: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
627 TMatrixD globalDer(2,numGlobals);
628 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
629 globalDer(0,
i) = theDoubleBufferX[
i];
630 globalDer(1,
i) = theDoubleBufferY[
i];
643 std::vector<float> &globalDerivativesX,
644 std::vector<float> &globalDerivativesY,
645 std::vector<int> &globalLabels,
649 if (!ali)
return true;
651 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
656 if (!lowestParams) lowestParams = params;
658 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
659 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
661 if (0 == alignableLabel) {
662 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
663 <<
"Label not found, skip Alignable.";
667 const std::vector<bool> &selPars = params->
selector();
671 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
673 globalDerivativesX.push_back(derivs[iSel][kLocalX]
674 /thePedeSteer->cmsToPedeFactor(iSel));
675 if (hasSplitParameters==
true) {
676 globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
678 globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
680 globalDerivativesY.push_back(derivs[iSel][kLocalY]
681 /thePedeSteer->cmsToPedeFactor(iSel));
685 if (thePedeSteer->isNoHiera(ali))
return true;
688 return this->globalDerivativesHierarchy(eventInfo,
689 tsos, ali->
mother(), alidet,
690 globalDerivativesX, globalDerivativesY,
691 globalLabels, lowestParams);
699 std::vector<double> &globalDerivativesX,
700 std::vector<double> &globalDerivativesY,
701 std::vector<int> &globalLabels,
705 if (!ali)
return true;
707 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
712 if (!lowestParams) lowestParams = params;
714 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
715 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
717 if (0 == alignableLabel) {
718 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
719 <<
"Label not found, skip Alignable.";
723 const std::vector<bool> &selPars = params->
selector();
728 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
730 if (hasSplitParameters==
true) {
731 globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
733 globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
735 if (globalLabel > 0 && globalLabel <= 2147483647) {
736 globalLabels.push_back(globalLabel);
737 globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
738 globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
740 std::cerr <<
"MillePedeAlignmentAlgorithm::globalDerivativesHierarchy: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
745 if (thePedeSteer->isNoHiera(ali))
return true;
748 return this->globalDerivativesHierarchy(eventInfo,
749 tsos, ali->
mother(), alidet,
750 globalDerivativesX, globalDerivativesY,
751 globalLabels, lowestParams);
759 std::vector<float> &globalDerivativesX,
760 std::vector<float> &globalDerivativesY,
761 std::vector<int> &globalLabels)
const
763 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
766 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
767 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
770 globalDerivativesX.push_back(iValuesInd->first.first);
771 globalDerivativesY.push_back(iValuesInd->first.second);
815 if (recHit->dimension() < 2) {
817 }
else if (recHit->detUnit()) {
818 return recHit->detUnit()->type().isTrackerPixel();
820 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
836 std::vector<Alignable*> alis;
837 bool okRead = reader.
read(alis, setUserVars);
838 bool numMatch =
true;
840 std::stringstream
out;
841 out <<
"Read " << alis.size() <<
" alignables";
846 if (!okRead) out <<
", but problems in reading";
847 if (!allEmpty) out <<
", possibly overwriting previous settings";
850 if (okRead && allEmpty) {
852 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
853 }
else if (alis.size()) {
854 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
856 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
862 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
870 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
871 iAli != alignables.end(); ++iAli) {
876 for (
int i = 0;
i < parVec.num_row(); ++
i) {
877 if (parVec[
i] != 0.)
return false;
878 for (
int j =
i;
j < parCov.num_col(); ++
j) {
879 if (parCov[
i][
j] != 0.)
return false;
894 if (outFilePlain.empty()) {
895 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
896 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
907 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
908 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
911 }
else if (loop == 1) {
913 const std::vector<std::string> inFiles
915 const std::vector<std::string> binFiles
917 if (inFiles.size() != binFiles.size()) {
918 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
919 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
927 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
928 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
934 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
935 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
940 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
941 <<
" in writeAlignableAbsolutePositions, " <<
loop;
951 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
954 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
955 <<
"No parameters for alignable";
959 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
976 if (mode ==
"full") {
978 }
else if (mode ==
"mille") {
980 }
else if (mode ==
"pede") {
982 }
else if (mode ==
"pedeSteer") {
984 }
else if (mode ==
"pedeRun") {
986 }
else if (mode ==
"pedeRead") {
991 <<
"Unknown mode '" << mode
992 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
999 const std::vector<std::string> &inFiles)
const
1004 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
1005 iFile != inFiles.end(); ++iFile) {
1007 const std::vector<AlignmentUserVariables*> mpVars =
1010 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1011 <<
"Error " << ierr <<
" reading from " << inFile
1012 <<
", tree " << fromIov <<
", or problems in addHits";
1015 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
1016 i != mpVars.end(); ++
i) {
1026 const std::vector<AlignmentUserVariables*> &mpVars)
const
1028 bool allOk = (mpVars.size() == alis.size());
1029 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1030 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1031 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1035 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1049 const std::vector<float> &globalDerivativesy,
1050 TMatrixF &aGlobalDerivativesM)
1053 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
1054 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1055 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1061 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1062 TMatrixF &aGlobalDerivativesM)
const
1064 TMatrixDSymEigen myDiag(aHitCovarianceM);
1065 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1066 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1067 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1068 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1074 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1075 aTranfoToDiagonalSystemInvF.Invert();
1077 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1080 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1081 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1087 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1088 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1092 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1096 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1099 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1106 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1107 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1114 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1115 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1119 const unsigned int xIndex = iTrajHit*2;
1120 const unsigned int yIndex = iTrajHit*2+1;
1124 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1125 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1126 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1127 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1130 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1131 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1138 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1139 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1140 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1147 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1148 const std::vector<float> &globalDerivativesX,
1149 const std::vector<float> &globalDerivativesY)
1153 if((aRecHit)->dimension() == 1) {
1154 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1156 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1157 globalDerivativesX, globalDerivativesY);
1165 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1166 const std::vector<float> &globalDerivativesX)
1169 const unsigned int xIndex = iTrajHit*2;
1173 const int nLocal = locDerivMatrix.num_col();
1174 std::vector<float> localDerivatives(nLocal);
1175 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1176 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1180 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1181 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1184 const int nGlobal = globalDerivativesX.size();
1188 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1189 &(globalLabels[0]), residX, hitErrX);
1192 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1193 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1194 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1195 iTrajHit, residX, hitErrX,
false);
1204 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1205 const std::vector<float> &globalDerivativesx,
1206 const std::vector<float> &globalDerivativesy)
1210 if((aRecHit)->dimension() != 2) {
1211 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1212 <<
"You try to call method for 2D hits for a "
1214 <<
"D Hit. Hit gets ignored!";
1218 TMatrixDSym aHitCovarianceM(2);
1219 TMatrixF aHitResidualsM(2,1);
1220 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1222 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1223 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1224 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1229 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1230 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1232 switch(aRecHit->geographicalId().subdetId()) {
1236 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1243 float newResidX = aHitResidualsM(0,0);
1244 float newResidY = aHitResidualsM(1,0);
1245 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1246 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1247 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1248 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1249 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1250 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1251 const int nLocal = aLocalDerivativesM.GetNcols();
1252 const int nGlobal = aGlobalDerivativesM.GetNcols();
1254 if (diag && (newHitErrX > newHitErrY)) {
1258 std::swap(newLocalDerivsX, newLocalDerivsY);
1259 std::swap(newGlobDerivsX, newGlobDerivsY);
1264 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1265 &(globalLabels[0]), newResidX, newHitErrX);
1268 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1269 &(globalLabels[0]));
1270 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1271 iTrajHit, newResidX, newHitErrX,
false);
1273 const bool isReal2DHit = this->
is2D(aRecHit);
1275 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1276 &(globalLabels[0]), newResidY, newHitErrY);
1278 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1279 &(globalLabels[0]));
1280 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1281 iTrajHit, newResidY, newHitErrY,
true);
1285 return (isReal2DHit ? 2 : 1);
1292 TMatrixDSym aHitCovarianceM(1);
1293 TMatrixF aHitResidualsM(1,1);
1294 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1296 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1299 TMatrixF aGlobalDerivativesM(1,1);
1300 aGlobalDerivativesM(0,0) = 0;
1302 float newResidX = aHitResidualsM(0,0);
1303 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1304 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1305 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1306 const int nLocal = aLocalDerivativesM.GetNcols();
1307 const int nGlobal = 0;
1309 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1310 &nGlobal, newResidX, newHitErrX);
1318 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1319 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1320 iBeam != iEnd; ++iBeam, ++iTsoses){
1322 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1323 <<
"Beam " << iBeam->getBeamId() <<
" with "
1324 << iBeam->parameters().size() <<
" parameters and "
1325 << iBeam->getData().size() <<
" hits.\n There are "
1326 << iTsoses->size() <<
" TSOSes.";
1328 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1335 const std::vector<TrajectoryStateOnSurface> &tsoses)
1338 std::vector<float> lasLocalDerivsX;
1341 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1342 if (!tsoses[iHit].isValid())
continue;
1347 lasLocalDerivsX.clear();
1352 tsoses[iHit], lasAli, lasAli,
1355 for (
unsigned int nFitParams = 0;
1356 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1360 lasLocalDerivsX.push_back(derivative);
1368 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1370 const float error = 0.003;
1382 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1383 if (doOutputOnStdout)
std::cout <<
"# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1390 std::vector<SurveyPxbImageLocalFit> measurements;
1397 if (doOutputOnStdout)
std::cout <<
"Module " <<
i <<
": ";
1421 fidpointvec.push_back(fidpoint0inSurf1frame);
1422 fidpointvec.push_back(fidpoint1inSurf1frame);
1423 fidpointvec.push_back(fidpoint2);
1424 fidpointvec.push_back(fidpoint3);
1429 dicer.
doDice(fidpointvec,measurements[i].getIdPair(),
outfile);
1435 a = measurements[
i].getLocalParameters();
1439 if (doOutputOnStdout)
1441 std::cout <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1442 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1443 <<
" phi= " << atan(a[3]/a[2])
1444 <<
" chi2= " << chi2 << std::endl;
1456 measurements[i].getLocalDerivsPtr(
j),
1457 (
int)measurements[i].getGlobalDerivsSize(),
1458 measurements[i].getGlobalDerivsPtr(
j),
1459 measurements[i].getGlobalDerivsLabelPtr(
j),
1460 measurements[i].getResiduum(
j),
1461 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.
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
virtual unsigned int alignableLabel(Alignable *alignable) const =0
bool theDoSurveyPixelBarrel
void writeAlignableOriginalPositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable original (before misalignment) absolute positions
void fillPxbSurveyHistsLocalPars(const float &a0, const float &a1, const float &S, const float &phi)
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
PedeSteerer * thePedeSteer
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 unsigned int lasBeamLabel(unsigned int lasBeamId) const =0
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
void fillPxbSurveyHistsChi2(const float &chi2)
define event information passed to algorithms
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
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)
gbl::MilleBinary * theBinary
bool isMode(unsigned int testMode) const
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()
void fillUsedTrack(const reco::Track *track, unsigned int nHitX, unsigned int nHitY)
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
virtual bool setParametersForRunRange(const RunRange &runrange)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool is2D(HitType hitType)
PedeLabelerBase * thePedeLabels
int runPede(const std::string &masterSteer) const
run pede, masterSteer should be as returned from buildMasterSteer(...)
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
AlignableNavigator * theAlignableNavigator
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
edm::ParameterSet theConfig
const TkFittedLasBeamCollection * tkLasBeams() const
std::string buildMasterSteer(const std::vector< std::string > &binaryFiles)
construct (and return name of) master steering file from config, binaryFiles etc. ...
void addGlobals(const std::vector< int > &aLabels, const TMatrixD &aDerivatives)
Add global derivatives to a point.
Container::value_type value_type
void mille(int NLC, const float *derLc, int NGL, const float *derGl, const int *label, float rMeas, float sigma)
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
MillePedeMonitor * theMonitor
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 buildSubSteer(AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
construct steering files about hierarchy, fixing etc. an keep track of their names ...
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
void fillTrack(const reco::Track *track)
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.
virtual unsigned int calibrationLabel(const IntegratedCalibrationBase *calib, unsigned int paramNum) const
label for parameter 'paramNum' (counted from 0) of an integrated calibration
void buildUserVariables(const std::vector< Alignable * > &alignables) const
add MillePedeVariables for each AlignmentParameters (exception if no parameters...)
MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg)
Constructor.
TrajectoryFactoryBase * theTrajectoryFactory
virtual ~MillePedeAlignmentAlgorithm()
Destructor.
virtual void addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals)
tell labeler to treat also integrated calibrations
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
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const =0
void fillRefTrajectory(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
std::vector< float > theFloatBufferY
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
Millepede-II (binary) record.
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
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)
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
Alignable * mother() const
Return pointer to container alignable (if any)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
T get(const Candidate &c)
const align::Alignables & alignables(void) const
get all alignables
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
bool setAllDefault(unsigned int nParam)
set default values for all data concerning nParam (false if nParam out of range)
virtual void terminate()
Called at end of job.