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 (std::vector<std::string>::const_iterator
i = files.begin(), iEnd = files.end();
i != iEnd; ++
i) {
315 filesForLogOutput +=
" " + *
i;
317 edm::LogInfo(
"Alignment") <<
"Based on the config parameter mergeBinaryFiles, using the following files as input:" << filesForLogOutput;
335 std::vector<std::string>
files;
336 for (std::vector<std::string>::const_iterator
i = plainFiles.begin(), iEnd = plainFiles.end();
i != iEnd; ++
i) {
342 char theNumberedInputFileName[200];
343 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
344 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
347 if (stat (theCompleteInputFileName.c_str(), &buffer) == 0) {
349 files.push_back(theCompleteInputFileName);
350 if (theNumberedInputFileName == theInputFileName) {
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);
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;
553 if (!recHitPtr->isValid())
return 0;
578 unsigned int iHit,
GblPoint &gblPoint)
581 std::vector<double> theDoubleBufferX, theDoubleBufferY;
582 theDoubleBufferX.clear();
583 theDoubleBufferY.clear();
590 if (!recHitPtr->isValid())
return 0;
596 tsos, alidet, alidet, theDoubleBufferX,
602 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
605 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
606 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
609 if (globalLabel > 0 && globalLabel <= 2147483647) {
611 theDoubleBufferX.push_back(iValuesInd->first.first);
612 theDoubleBufferY.push_back(iValuesInd->first.second);
614 std::cerr <<
"MillePedeAlignmentAlgorithm::addGlobalData: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
621 TMatrixD globalDer(2,numGlobals);
622 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
623 globalDer(0,
i) = theDoubleBufferX[
i];
624 globalDer(1,
i) = theDoubleBufferY[
i];
637 std::vector<float> &globalDerivativesX,
638 std::vector<float> &globalDerivativesY,
639 std::vector<int> &globalLabels,
643 if (!ali)
return true;
645 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
650 if (!lowestParams) lowestParams = params;
652 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
653 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
655 if (0 == alignableLabel) {
656 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
657 <<
"Label not found, skip Alignable.";
661 const std::vector<bool> &selPars = params->
selector();
665 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
667 globalDerivativesX.push_back(derivs[iSel][kLocalX]
668 /thePedeSteer->cmsToPedeFactor(iSel));
669 if (hasSplitParameters==
true) {
670 globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
672 globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
674 globalDerivativesY.push_back(derivs[iSel][kLocalY]
675 /thePedeSteer->cmsToPedeFactor(iSel));
679 if (thePedeSteer->isNoHiera(ali))
return true;
682 return this->globalDerivativesHierarchy(eventInfo,
683 tsos, ali->
mother(), alidet,
684 globalDerivativesX, globalDerivativesY,
685 globalLabels, lowestParams);
693 std::vector<double> &globalDerivativesX,
694 std::vector<double> &globalDerivativesY,
695 std::vector<int> &globalLabels,
699 if (!ali)
return true;
701 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
706 if (!lowestParams) lowestParams = params;
708 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
709 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
711 if (0 == alignableLabel) {
712 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
713 <<
"Label not found, skip Alignable.";
717 const std::vector<bool> &selPars = params->
selector();
722 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
724 if (hasSplitParameters==
true) {
725 globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
727 globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
729 if (globalLabel > 0 && globalLabel <= 2147483647) {
730 globalLabels.push_back(globalLabel);
731 globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
732 globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
734 std::cerr <<
"MillePedeAlignmentAlgorithm::globalDerivativesHierarchy: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
739 if (thePedeSteer->isNoHiera(ali))
return true;
742 return this->globalDerivativesHierarchy(eventInfo,
743 tsos, ali->
mother(), alidet,
744 globalDerivativesX, globalDerivativesY,
745 globalLabels, lowestParams);
753 std::vector<float> &globalDerivativesX,
754 std::vector<float> &globalDerivativesY,
755 std::vector<int> &globalLabels)
const
757 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
760 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
761 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
764 globalDerivativesX.push_back(iValuesInd->first.first);
765 globalDerivativesY.push_back(iValuesInd->first.second);
809 if (recHit->dimension() < 2) {
811 }
else if (recHit->detUnit()) {
812 return recHit->detUnit()->type().isTrackerPixel();
814 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
830 std::vector<Alignable*> alis;
831 bool okRead = reader.
read(alis, setUserVars);
832 bool numMatch =
true;
834 std::stringstream
out;
835 out <<
"Read " << alis.size() <<
" alignables";
840 if (!okRead) out <<
", but problems in reading";
841 if (!allEmpty) out <<
", possibly overwriting previous settings";
844 if (okRead && allEmpty) {
846 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
847 }
else if (alis.size()) {
848 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
850 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
856 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
864 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
865 iAli != alignables.end(); ++iAli) {
870 for (
int i = 0;
i < parVec.num_row(); ++
i) {
871 if (parVec[
i] != 0.)
return false;
872 for (
int j =
i;
j < parCov.num_col(); ++
j) {
873 if (parCov[
i][
j] != 0.)
return false;
888 if (outFilePlain.empty()) {
889 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
890 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
901 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
902 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
905 }
else if (loop == 1) {
907 const std::vector<std::string> inFiles
909 const std::vector<std::string> binFiles
911 if (inFiles.size() != binFiles.size()) {
912 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
913 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
921 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
922 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
928 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
929 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
934 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
935 <<
" in writeAlignableAbsolutePositions, " <<
loop;
945 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
948 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
949 <<
"No parameters for alignable";
953 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
970 if (mode ==
"full") {
972 }
else if (mode ==
"mille") {
974 }
else if (mode ==
"pede") {
976 }
else if (mode ==
"pedeSteer") {
978 }
else if (mode ==
"pedeRun") {
980 }
else if (mode ==
"pedeRead") {
985 <<
"Unknown mode '" << mode
986 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
993 const std::vector<std::string> &inFiles)
const
998 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
999 iFile != inFiles.end(); ++iFile) {
1001 const std::vector<AlignmentUserVariables*> mpVars =
1004 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1005 <<
"Error " << ierr <<
" reading from " << inFile
1006 <<
", tree " << fromIov <<
", or problems in addHits";
1009 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
1010 i != mpVars.end(); ++
i) {
1020 const std::vector<AlignmentUserVariables*> &mpVars)
const
1022 bool allOk = (mpVars.size() == alis.size());
1023 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1024 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1025 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1029 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1043 const std::vector<float> &globalDerivativesy,
1044 TMatrixF &aGlobalDerivativesM)
1047 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
1048 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1049 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1055 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1056 TMatrixF &aGlobalDerivativesM)
const
1058 TMatrixDSymEigen myDiag(aHitCovarianceM);
1059 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1060 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1061 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1062 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1068 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1069 aTranfoToDiagonalSystemInvF.Invert();
1071 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1074 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1075 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1081 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1082 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1086 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1090 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1093 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1100 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1101 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1108 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1109 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1113 const unsigned int xIndex = iTrajHit*2;
1114 const unsigned int yIndex = iTrajHit*2+1;
1118 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1119 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1120 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1121 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1124 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1125 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1132 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1133 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1134 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1141 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1142 const std::vector<float> &globalDerivativesX,
1143 const std::vector<float> &globalDerivativesY)
1147 if((aRecHit)->dimension() == 1) {
1148 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1150 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1151 globalDerivativesX, globalDerivativesY);
1159 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1160 const std::vector<float> &globalDerivativesX)
1163 const unsigned int xIndex = iTrajHit*2;
1167 const int nLocal = locDerivMatrix.num_col();
1168 std::vector<float> localDerivatives(nLocal);
1169 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1170 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1174 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1175 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1178 const int nGlobal = globalDerivativesX.size();
1182 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1183 &(globalLabels[0]), residX, hitErrX);
1186 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1187 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1188 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1189 iTrajHit, residX, hitErrX,
false);
1198 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1199 const std::vector<float> &globalDerivativesx,
1200 const std::vector<float> &globalDerivativesy)
1204 if((aRecHit)->dimension() != 2) {
1205 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1206 <<
"You try to call method for 2D hits for a "
1208 <<
"D Hit. Hit gets ignored!";
1212 TMatrixDSym aHitCovarianceM(2);
1213 TMatrixF aHitResidualsM(2,1);
1214 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1216 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1217 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1218 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1223 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1224 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1226 switch(aRecHit->geographicalId().subdetId()) {
1230 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1237 float newResidX = aHitResidualsM(0,0);
1238 float newResidY = aHitResidualsM(1,0);
1239 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1240 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1241 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1242 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1243 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1244 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1245 const int nLocal = aLocalDerivativesM.GetNcols();
1246 const int nGlobal = aGlobalDerivativesM.GetNcols();
1248 if (diag && (newHitErrX > newHitErrY)) {
1252 std::swap(newLocalDerivsX, newLocalDerivsY);
1253 std::swap(newGlobDerivsX, newGlobDerivsY);
1258 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1259 &(globalLabels[0]), newResidX, newHitErrX);
1262 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1263 &(globalLabels[0]));
1264 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1265 iTrajHit, newResidX, newHitErrX,
false);
1267 const bool isReal2DHit = this->is2D(aRecHit);
1269 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1270 &(globalLabels[0]), newResidY, newHitErrY);
1272 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1273 &(globalLabels[0]));
1274 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1275 iTrajHit, newResidY, newHitErrY,
true);
1279 return (isReal2DHit ? 2 : 1);
1286 TMatrixDSym aHitCovarianceM(1);
1287 TMatrixF aHitResidualsM(1,1);
1288 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1290 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1293 TMatrixF aGlobalDerivativesM(1,1);
1294 aGlobalDerivativesM(0,0) = 0;
1296 float newResidX = aHitResidualsM(0,0);
1297 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1298 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1299 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1300 const int nLocal = aLocalDerivativesM.GetNcols();
1301 const int nGlobal = 0;
1303 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1304 &nGlobal, newResidX, newHitErrX);
1312 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1313 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1314 iBeam != iEnd; ++iBeam, ++iTsoses){
1316 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1317 <<
"Beam " << iBeam->getBeamId() <<
" with "
1318 << iBeam->parameters().size() <<
" parameters and "
1319 << iBeam->getData().size() <<
" hits.\n There are "
1320 << iTsoses->size() <<
" TSOSes.";
1322 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1329 const std::vector<TrajectoryStateOnSurface> &tsoses)
1332 std::vector<float> lasLocalDerivsX;
1335 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1336 if (!tsoses[iHit].isValid())
continue;
1341 lasLocalDerivsX.clear();
1346 tsoses[iHit], lasAli, lasAli,
1349 for (
unsigned int nFitParams = 0;
1350 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1354 lasLocalDerivsX.push_back(derivative);
1362 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1364 const float error = 0.003;
1376 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1377 if (doOutputOnStdout)
std::cout <<
"# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1384 std::vector<SurveyPxbImageLocalFit> measurements;
1391 if (doOutputOnStdout)
std::cout <<
"Module " <<
i <<
": ";
1415 fidpointvec.push_back(fidpoint0inSurf1frame);
1416 fidpointvec.push_back(fidpoint1inSurf1frame);
1417 fidpointvec.push_back(fidpoint2);
1418 fidpointvec.push_back(fidpoint3);
1423 dicer.
doDice(fidpointvec,measurements[i].getIdPair(),
outfile);
1429 a = measurements[
i].getLocalParameters();
1433 if (doOutputOnStdout)
1435 std::cout <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1436 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1437 <<
" phi= " << atan(a[3]/a[2])
1438 <<
" chi2= " << chi2 << std::endl;
1450 measurements[i].getLocalDerivsPtr(
j),
1451 (
int)measurements[i].getGlobalDerivsSize(),
1452 measurements[i].getGlobalDerivsPtr(
j),
1453 measurements[i].getGlobalDerivsLabelPtr(
j),
1454 measurements[i].getResiduum(
j),
1455 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.