66 #include <TMatrixDSymEigen.h>
89 theConfig(cfg), theMode(this->decodeMode(theConfig.getUntrackedParameter<std::
string>(
"mode"))),
90 theDir(theConfig.getUntrackedParameter<std::
string>(
"fileDir")),
91 theAlignmentParameterStore(0), theAlignables(), theAlignableNavigator(0),
92 theMonitor(0), theMille(0), thePedeLabels(0), thePedeSteer(0),
93 theTrajectoryFactory(0),
94 theMinNumHits(cfg.getParameter<unsigned int>(
"minNumHits")),
95 theMaximalCor2D(cfg.getParameter<double>(
"max2Dcorrelation")),
97 theBinary(0),theGblDoubleBinary(cfg.getParameter<bool>(
"doubleBinary"))
100 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '"
102 <<
"' with output directory '" <<
theDir <<
"'.";
135 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
136 <<
"Running with AlignabeMuon not yet tested.";
151 RunRangeSelectionVPSet);
154 if (RunRangeSelectionVPSet.size()>0) {
155 labelerPlugin =
"RunRangeDependentPedeLabeler";
156 if (pedeLabelerCfg.
exists(
"plugin")) {
158 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
161 <<
"MillePedeAlignmentAlgorithm::initialize"
162 <<
"both RunRangeSelection and generic labeler specified in config file. "
163 <<
"Please get rid of either one of them.\n";
167 if (pedeLabelerCfg.
exists(
"plugin")) {
172 if (!pedeLabelerCfg.
exists(
"plugin")) {
176 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
177 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
191 const std::vector<edm::ParameterSet> mprespset
193 if (!mprespset.empty()) {
194 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
195 <<
"Apply " << mprespset.end() - mprespset.begin()
196 <<
" previous MillePede constants from 'pedeReaderInputs'.";
203 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
204 iSet != iE; ++iSet) {
209 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
210 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
227 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
228 <<
"modes running mille.";
283 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
284 <<
"Problems reading pede result, but applying!";
305 std::vector<std::string>
files;
309 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
313 for (std::vector<std::string>::const_iterator
i = files.begin(), iEnd = files.end();
i != iEnd; ++
i) {
314 filesForLogOutput +=
" " + *
i;
316 edm::LogInfo(
"Alignment") <<
"Based on the config parameter mergeBinaryFiles, using the following files as input:" << filesForLogOutput;
334 std::vector<std::string>
files;
335 for (std::vector<std::string>::const_iterator
i = plainFiles.begin(), iEnd = plainFiles.end();
i != iEnd; ++
i) {
341 char theNumberedInputFileName[200];
342 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
343 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
346 if (stat (theCompleteInputFileName.c_str(), &buffer) == 0) {
348 files.push_back(theCompleteInputFileName);
349 if (theNumberedInputFileName == theInputFileName) {
373 for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
374 iTrajTrack != tracks.end(); ++iTrajTrack) {
382 unsigned int refTrajCount = 0;
383 for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
384 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
389 const std::pair<unsigned int, unsigned int> nHitXy
392 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
396 (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
404 std::pair<unsigned int, unsigned int>
409 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
410 if (refTrajPtr->isValid()) {
414 if (refTrajPtr->gblInput().size() > 0) {
416 unsigned int iHit = 0;
417 unsigned int numPointsWithMeas = 0;
418 std::vector<GblPoint>::iterator itPoint;
419 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
420 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
421 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
422 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
423 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
426 hitResultXy.first = numPointsWithMeas;
428 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
430 if (refTrajPtr->gblInput().size() == 1) {
432 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
442 if (refTrajPtr->gblInput().size() == 2) {
444 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
450 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
452 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
454 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
455 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
458 hitResultXy.first = 0;
461 if (flagXY >= 1) ++hitResultXy.first;
462 validHitVecY[iHit] = (flagXY >= 2);
467 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
472 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
474 hitResultXy.first = hitResultXy.second = 0;
479 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
492 const std::vector<bool> &validHitVecY)
const
495 unsigned int nHitY = 0;
496 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
497 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
508 if (validHitVecY[iHit]) {
510 if (pars == parVec[iHit]) ++nHitY;
552 if (!recHitPtr->isValid())
return 0;
577 unsigned int iHit,
GblPoint &gblPoint)
580 std::vector<double> theDoubleBufferX, theDoubleBufferY;
581 theDoubleBufferX.clear();
582 theDoubleBufferY.clear();
589 if (!recHitPtr->isValid())
return 0;
595 tsos, alidet, alidet, theDoubleBufferX,
601 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
604 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
605 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
608 if (globalLabel > 0 && globalLabel <= 2147483647) {
610 theDoubleBufferX.push_back(iValuesInd->first.first);
611 theDoubleBufferY.push_back(iValuesInd->first.second);
613 std::cerr <<
"MillePedeAlignmentAlgorithm::addGlobalData: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
620 TMatrixD globalDer(2,numGlobals);
621 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
622 globalDer(0,
i) = theDoubleBufferX[
i];
623 globalDer(1,
i) = theDoubleBufferY[
i];
636 std::vector<float> &globalDerivativesX,
637 std::vector<float> &globalDerivativesY,
638 std::vector<int> &globalLabels,
642 if (!ali)
return true;
644 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
649 if (!lowestParams) lowestParams = params;
651 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
652 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
654 if (0 == alignableLabel) {
655 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
656 <<
"Label not found, skip Alignable.";
660 const std::vector<bool> &selPars = params->
selector();
664 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
666 globalDerivativesX.push_back(derivs[iSel][kLocalX]
667 /thePedeSteer->cmsToPedeFactor(iSel));
668 if (hasSplitParameters==
true) {
669 globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
671 globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
673 globalDerivativesY.push_back(derivs[iSel][kLocalY]
674 /thePedeSteer->cmsToPedeFactor(iSel));
678 if (thePedeSteer->isNoHiera(ali))
return true;
681 return this->globalDerivativesHierarchy(eventInfo,
682 tsos, ali->
mother(), alidet,
683 globalDerivativesX, globalDerivativesY,
684 globalLabels, lowestParams);
692 std::vector<double> &globalDerivativesX,
693 std::vector<double> &globalDerivativesY,
694 std::vector<int> &globalLabels,
698 if (!ali)
return true;
700 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
705 if (!lowestParams) lowestParams = params;
707 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
708 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
710 if (0 == alignableLabel) {
711 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
712 <<
"Label not found, skip Alignable.";
716 const std::vector<bool> &selPars = params->
selector();
721 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
723 if (hasSplitParameters==
true) {
724 globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
726 globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
728 if (globalLabel > 0 && globalLabel <= 2147483647) {
729 globalLabels.push_back(globalLabel);
730 globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
731 globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
733 std::cerr <<
"MillePedeAlignmentAlgorithm::globalDerivativesHierarchy: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
738 if (thePedeSteer->isNoHiera(ali))
return true;
741 return this->globalDerivativesHierarchy(eventInfo,
742 tsos, ali->
mother(), alidet,
743 globalDerivativesX, globalDerivativesY,
744 globalLabels, lowestParams);
752 std::vector<float> &globalDerivativesX,
753 std::vector<float> &globalDerivativesY,
754 std::vector<int> &globalLabels)
const
756 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
759 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
760 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
763 globalDerivativesX.push_back(iValuesInd->first.first);
764 globalDerivativesY.push_back(iValuesInd->first.second);
808 if (recHit->dimension() < 2) {
810 }
else if (recHit->detUnit()) {
811 return recHit->detUnit()->type().isTrackerPixel();
813 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
829 std::vector<Alignable*> alis;
830 bool okRead = reader.
read(alis, setUserVars);
831 bool numMatch =
true;
833 std::stringstream
out;
834 out <<
"Read " << alis.size() <<
" alignables";
839 if (!okRead) out <<
", but problems in reading";
840 if (!allEmpty) out <<
", possibly overwriting previous settings";
843 if (okRead && allEmpty) {
845 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
846 }
else if (alis.size()) {
847 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
849 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
855 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
863 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
864 iAli != alignables.end(); ++iAli) {
869 for (
int i = 0;
i < parVec.num_row(); ++
i) {
870 if (parVec[
i] != 0.)
return false;
871 for (
int j =
i;
j < parCov.num_col(); ++
j) {
872 if (parCov[
i][
j] != 0.)
return false;
887 if (outFilePlain.empty()) {
888 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
889 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
900 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
901 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
904 }
else if (loop == 1) {
906 const std::vector<std::string> inFiles
908 const std::vector<std::string> binFiles
910 if (inFiles.size() != binFiles.size()) {
911 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
912 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
920 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
921 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
927 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
928 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
933 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
934 <<
" in writeAlignableAbsolutePositions, " <<
loop;
944 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
947 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
948 <<
"No parameters for alignable";
952 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
969 if (mode ==
"full") {
971 }
else if (mode ==
"mille") {
973 }
else if (mode ==
"pede") {
975 }
else if (mode ==
"pedeSteer") {
977 }
else if (mode ==
"pedeRun") {
979 }
else if (mode ==
"pedeRead") {
984 <<
"Unknown mode '" << mode
985 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
992 const std::vector<std::string> &inFiles)
const
997 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
998 iFile != inFiles.end(); ++iFile) {
1000 const std::vector<AlignmentUserVariables*> mpVars =
1003 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1004 <<
"Error " << ierr <<
" reading from " << inFile
1005 <<
", tree " << fromIov <<
", or problems in addHits";
1008 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
1009 i != mpVars.end(); ++
i) {
1019 const std::vector<AlignmentUserVariables*> &mpVars)
const
1021 bool allOk = (mpVars.size() == alis.size());
1022 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1023 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1024 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1028 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1042 const std::vector<float> &globalDerivativesy,
1043 TMatrixF &aGlobalDerivativesM)
1046 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
1047 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1048 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1054 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1055 TMatrixF &aGlobalDerivativesM)
const
1057 TMatrixDSymEigen myDiag(aHitCovarianceM);
1058 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1059 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1060 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1061 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1067 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1068 aTranfoToDiagonalSystemInvF.Invert();
1070 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1073 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1074 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1080 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1081 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1085 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1089 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1092 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1099 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1100 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1107 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1108 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1112 const unsigned int xIndex = iTrajHit*2;
1113 const unsigned int yIndex = iTrajHit*2+1;
1117 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1118 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1119 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1120 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1123 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1124 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1131 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1132 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1133 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1140 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1141 const std::vector<float> &globalDerivativesX,
1142 const std::vector<float> &globalDerivativesY)
1146 if((aRecHit)->dimension() == 1) {
1147 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1149 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1150 globalDerivativesX, globalDerivativesY);
1158 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1159 const std::vector<float> &globalDerivativesX)
1162 const unsigned int xIndex = iTrajHit*2;
1166 const int nLocal = locDerivMatrix.num_col();
1167 std::vector<float> localDerivatives(nLocal);
1168 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1169 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1173 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1174 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1177 const int nGlobal = globalDerivativesX.size();
1181 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1182 &(globalLabels[0]), residX, hitErrX);
1185 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1186 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1187 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1188 iTrajHit, residX, hitErrX,
false);
1197 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1198 const std::vector<float> &globalDerivativesx,
1199 const std::vector<float> &globalDerivativesy)
1203 if((aRecHit)->dimension() != 2) {
1204 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1205 <<
"You try to call method for 2D hits for a "
1207 <<
"D Hit. Hit gets ignored!";
1211 TMatrixDSym aHitCovarianceM(2);
1212 TMatrixF aHitResidualsM(2,1);
1213 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1215 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1216 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1217 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1222 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1223 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1225 switch(aRecHit->geographicalId().subdetId()) {
1229 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1236 float newResidX = aHitResidualsM(0,0);
1237 float newResidY = aHitResidualsM(1,0);
1238 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1239 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1240 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1241 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1242 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1243 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1244 const int nLocal = aLocalDerivativesM.GetNcols();
1245 const int nGlobal = aGlobalDerivativesM.GetNcols();
1247 if (diag && (newHitErrX > newHitErrY)) {
1251 std::swap(newLocalDerivsX, newLocalDerivsY);
1252 std::swap(newGlobDerivsX, newGlobDerivsY);
1257 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1258 &(globalLabels[0]), newResidX, newHitErrX);
1261 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1262 &(globalLabels[0]));
1263 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1264 iTrajHit, newResidX, newHitErrX,
false);
1266 const bool isReal2DHit = this->is2D(aRecHit);
1268 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1269 &(globalLabels[0]), newResidY, newHitErrY);
1271 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1272 &(globalLabels[0]));
1273 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1274 iTrajHit, newResidY, newHitErrY,
true);
1278 return (isReal2DHit ? 2 : 1);
1285 TMatrixDSym aHitCovarianceM(1);
1286 TMatrixF aHitResidualsM(1,1);
1287 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1289 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1292 TMatrixF aGlobalDerivativesM(1,1);
1293 aGlobalDerivativesM(0,0) = 0;
1295 float newResidX = aHitResidualsM(0,0);
1296 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1297 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1298 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1299 const int nLocal = aLocalDerivativesM.GetNcols();
1300 const int nGlobal = 0;
1302 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1303 &nGlobal, newResidX, newHitErrX);
1311 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1312 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1313 iBeam != iEnd; ++iBeam, ++iTsoses){
1315 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1316 <<
"Beam " << iBeam->getBeamId() <<
" with "
1317 << iBeam->parameters().size() <<
" parameters and "
1318 << iBeam->getData().size() <<
" hits.\n There are "
1319 << iTsoses->size() <<
" TSOSes.";
1321 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1328 const std::vector<TrajectoryStateOnSurface> &tsoses)
1331 std::vector<float> lasLocalDerivsX;
1334 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1335 if (!tsoses[iHit].isValid())
continue;
1340 lasLocalDerivsX.clear();
1345 tsoses[iHit], lasAli, lasAli,
1348 for (
unsigned int nFitParams = 0;
1349 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1353 lasLocalDerivsX.push_back(derivative);
1361 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1363 const float error = 0.003;
1375 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1376 if (doOutputOnStdout)
std::cout <<
"# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1383 std::vector<SurveyPxbImageLocalFit> measurements;
1390 if (doOutputOnStdout)
std::cout <<
"Module " <<
i <<
": ";
1414 fidpointvec.push_back(fidpoint0inSurf1frame);
1415 fidpointvec.push_back(fidpoint1inSurf1frame);
1416 fidpointvec.push_back(fidpoint2);
1417 fidpointvec.push_back(fidpoint3);
1422 dicer.
doDice(fidpointvec,measurements[i].getIdPair(),
outfile);
1428 a = measurements[
i].getLocalParameters();
1432 if (doOutputOnStdout)
1434 std::cout <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1435 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1436 <<
" phi= " << atan(a[3]/a[2])
1437 <<
" chi2= " << chi2 << std::endl;
1449 measurements[i].getLocalDerivsPtr(
j),
1450 (
int)measurements[i].getGlobalDerivsSize(),
1451 measurements[i].getGlobalDerivsPtr(
j),
1452 measurements[i].getGlobalDerivsLabelPtr(
j),
1453 measurements[i].getResiduum(
j),
1454 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)
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.
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)
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)
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)
int addGlobalData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, GblPoint &gblPoint)
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
std::vector< std::string > getExistingFormattedFiles(const std::vector< std::string > plainFiles, std::string theDir)
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.