71 #include <TMatrixDSymEigen.h> 94 theMode(this->decodeMode(theConfig.getUntrackedParameter<
std::
string>(
"mode"))),
95 theDir(theConfig.getUntrackedParameter<
std::
string>(
"fileDir")),
96 theAlignmentParameterStore(
nullptr),
98 theMinNumHits(cfg.getParameter<unsigned
int>(
"minNumHits")),
99 theMaximalCor2D(cfg.getParameter<double>(
"max2Dcorrelation")),
101 ignoreFirstIOVCheck_(cfg.getUntrackedParameter<bool>(
"ignoreFirstIOVCheck")),
102 enableAlignableUpdates_(cfg.getUntrackedParameter<bool>(
"enableAlignableUpdates")),
103 theLastWrittenIov(0),
104 theGblDoubleBinary(cfg.getParameter<bool>(
"doubleBinary")),
105 runAtPCL_(cfg.getParameter<bool>(
"runAtPCL")),
106 ignoreHitsWithoutGlobalDerivatives_(cfg.getParameter<bool>(
"ignoreHitsWithoutGlobalDerivatives")),
107 skipGlobalPositionRcdCheck_(cfg.getParameter<bool>(
"skipGlobalPositionRcdCheck")),
111 enforceSingleIOVInput_(!(enableAlignableUpdates_ && areIOVsSpecified())),
115 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '" 117 <<
"' with output directory '" <<
theDir <<
"'.";
138 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize" 139 <<
"Running with AlignabeMuon not yet tested.";
145 const auto& iov_alignments =
147 const auto& iov_surfaces =
149 const auto& iov_errors =
154 if (iov_alignments.first().eventID().run() !=
MIN_VAL ||
155 iov_alignments.last().eventID().run() !=
MAX_VAL) {
158 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n" 159 <<
"Validity range is " 160 << iov_alignments.first().eventID().run() <<
" - " 161 << iov_alignments.last().eventID().run() <<
"\n";
164 if (iov_surfaces.first().eventID().run() !=
MIN_VAL ||
165 iov_surfaces.last().eventID().run() !=
MAX_VAL) {
167 <<
"\nTrying to apply " 169 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n" 170 <<
"Validity range is " 171 << iov_surfaces.first().eventID().run() <<
" - " 172 << iov_surfaces.last().eventID().run() <<
"\n";
175 if (iov_errors.first().eventID().run() !=
MIN_VAL ||
176 iov_errors.last().eventID().run() !=
MAX_VAL) {
178 <<
"\nTrying to apply " 180 <<
" with multiple IOVs in tag without specifying 'RunRangeSelection'.\n" 181 <<
"Validity range is " 182 << iov_errors.first().eventID().run() <<
" - " 183 << iov_errors.last().eventID().run() <<
"\n";
188 <<
"@SUB=MillePedeAlignmentAlgorithm::initialize" << message.str();
205 RunRangeSelectionVPSet);
208 if (RunRangeSelectionVPSet.size()>0) {
209 labelerPlugin =
"RunRangeDependentPedeLabeler";
210 if (pedeLabelerCfg.
exists(
"plugin")) {
212 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
215 <<
"MillePedeAlignmentAlgorithm::initialize" 216 <<
"both RunRangeSelection and generic labeler specified in config file. " 217 <<
"Please get rid of either one of them.\n";
221 if (pedeLabelerCfg.
exists(
"plugin")) {
226 if (!pedeLabelerCfg.
exists(
"plugin")) {
230 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize" 231 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
234 ->create(labelerPlugin,
246 const std::vector<edm::ParameterSet> mprespset
248 if (!mprespset.empty()) {
249 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize" 250 <<
"Apply " << mprespset.end() - mprespset.begin()
251 <<
" previous MillePede constants from 'pedeReaderInputs'.";
258 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
259 iSet != iE; ++iSet) {
264 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of " 265 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
267 theAlignmentParameterStore->applyParameters();
269 theAlignmentParameterStore->resetParameters();
282 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for " 283 <<
"modes running mille.";
286 if (moniFile.size())
theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (theDir + moniFile).c_str());
292 ->create(fctName, fctCfg));
360 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange" 361 <<
"Problems reading pede result, but applying!";
383 std::vector<std::string>
files;
387 const std::vector<std::string> plainFiles(
theConfig.
getParameter<std::vector<std::string> >(
"mergeBinaryFiles"));
391 for (
const auto&
file: files) filesForLogOutput +=
" " +
file +
",";
392 if (filesForLogOutput.length() != 0) filesForLogOutput.pop_back();
394 <<
"Based on the config parameter mergeBinaryFiles, using the following " 395 <<
"files as input (assigned weights are indicated by ' -- <weight>'):" 396 << filesForLogOutput;
404 <<
"@SUB=MillePedeAlignmentAlgorithm::terminate\n" 405 <<
"Last IOV of 'RunRangeSelection' has not been processed. " 406 <<
"Please reconfigure your source to process the runs at least up to " 411 const auto run = runRange.first;
434 std::vector<std::string>
files;
435 for (
const auto& plainFile: plainFiles) {
441 char theNumberedInputFileName[200];
442 sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
443 std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
444 const auto endOfStrippedFileName = theCompleteInputFileName.rfind(
" --");
445 const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
448 if (
stat (strippedInputFileName.c_str(), &buffer) == 0) {
450 files.push_back(theCompleteInputFileName);
451 if (theNumberedInputFileName == theInputFileName) {
464 if (theNumber == 0 && (files.size() == 0 || files.back() != plainFile)) {
466 <<
"The input file '" << plainFile <<
"' does not exist.";
480 for (
const auto& iTrajTrack:
tracks) {
488 unsigned int refTrajCount = 0;
490 for (
auto iRefTraj = trajectories.cbegin(), iRefTrajE = trajectories.cend();
491 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
498 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
500 const auto offset = tracksPerTraj*refTrajCount;
501 for (
unsigned int iTrack = 0; iTrack < tracksPerTraj; ++iTrack) {
503 nHitXy.first, nHitXy.second);
511 std::pair<unsigned int, unsigned int>
516 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
517 if (refTrajPtr->isValid()) {
521 if (refTrajPtr->gblInput().size() > 0) {
523 unsigned int iHit = 0;
524 unsigned int numPointsWithMeas = 0;
525 std::vector<GblPoint>::iterator itPoint;
526 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
527 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
528 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
529 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
530 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
533 hitResultXy.first = numPointsWithMeas;
535 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
537 if (refTrajPtr->gblInput().size() == 1) {
539 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
549 if (refTrajPtr->gblInput().size() == 2) {
551 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
557 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
559 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
561 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
562 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
565 hitResultXy.first = 0;
568 if (flagXY >= 1) ++hitResultXy.first;
569 validHitVecY[iHit] = (flagXY >= 2);
574 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
579 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
581 hitResultXy.first = hitResultXy.second = 0;
586 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
599 const std::vector<bool> &validHitVecY)
const 602 unsigned int nHitY = 0;
603 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
604 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
615 if (validHitVecY[iHit]) {
617 if (pars == parVec[iHit]) ++nHitY;
633 <<
"@SUB=MillePedeAlignmentAlgorithm::beginRun\n" 634 <<
"Using data (run = " << run.
run()
635 <<
") prior to the first defined IOV (" <<
firstIOV_ <<
").";
661 <<
"Trying to cache tracker alignment payloads for a run (" <<
runNumber 662 <<
") in an IOV (" <<
firstRun <<
") that was already cached.\n" 663 <<
"The following records in your input database tag have an IOV " 664 <<
"boundary that does not match your IOV definition:\n";
665 if (geometryRcd.validityInterval().first().eventID().run() >
firstRun) {
667 <<
" - IdealGeometryRecord '" << geometryRcd.key().name()
669 << geometryRcd.validityInterval().first().eventID().run() <<
")\n";
674 <<
" - GlobalPositionRecord '" << globalPosRcd.
key().
name()
678 message <<
" --> ignored\n";
686 <<
" - TrackerAlignmentRcd '" << alignmentRcd.
key().
name()
693 <<
" - TrackerSurfaceDeformationRcd '" << surfaceRcd.
key().
name()
700 <<
" - TrackerAlignmentErrorExtendedRcd '" << errorRcd.
key().
name()
708 <<
"@SUB=MillePedeAlignmentAlgorithm::beginRun\n" << message.str();
763 if (!recHitPtr->isValid())
return 0;
790 unsigned int iHit,
GblPoint &gblPoint)
793 std::vector<double> theDoubleBufferX, theDoubleBufferY;
794 theDoubleBufferX.clear();
795 theDoubleBufferY.clear();
802 if (!recHitPtr->isValid())
return 0;
808 tsos, alidet, alidet, theDoubleBufferX,
814 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
817 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
818 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
820 globalLabel =
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
821 if (globalLabel > 0 && globalLabel <= 2147483647) {
823 theDoubleBufferX.push_back(iValuesInd->first.first);
824 theDoubleBufferY.push_back(iValuesInd->first.second);
827 <<
"@SUB=MillePedeAlignmentAlgorithm::addGlobalData" 828 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
835 TMatrixD globalDer(2,numGlobals);
836 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
837 globalDer(0,
i) = theDoubleBufferX[
i];
838 globalDer(1,
i) = theDoubleBufferY[
i];
851 std::vector<float> &globalDerivativesX,
852 std::vector<float> &globalDerivativesY,
853 std::vector<int> &globalLabels,
857 if (!ali)
return true;
864 if (!lowestParams) lowestParams = params;
866 bool hasSplitParameters =
thePedeLabels->hasSplitParameters(ali);
867 const unsigned int alignableLabel =
thePedeLabels->alignableLabel(ali);
869 if (0 == alignableLabel) {
870 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy" 871 <<
"Label not found, skip Alignable.";
875 const std::vector<bool> &selPars = params->
selector();
879 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
881 globalDerivativesX.push_back(derivs[iSel][
kLocalX]
883 if (hasSplitParameters==
true) {
884 globalLabels.push_back(
thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
886 globalLabels.push_back(
thePedeLabels->parameterLabel(alignableLabel, iSel));
888 globalDerivativesY.push_back(derivs[iSel][
kLocalY]
897 tsos, ali->
mother(), alidet,
898 globalDerivativesX, globalDerivativesY,
899 globalLabels, lowestParams);
907 std::vector<double> &globalDerivativesX,
908 std::vector<double> &globalDerivativesY,
909 std::vector<int> &globalLabels,
913 if (!ali)
return true;
920 if (!lowestParams) lowestParams = params;
922 bool hasSplitParameters =
thePedeLabels->hasSplitParameters(ali);
923 const unsigned int alignableLabel =
thePedeLabels->alignableLabel(ali);
925 if (0 == alignableLabel) {
926 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy" 927 <<
"Label not found, skip Alignable.";
931 const std::vector<bool> &selPars = params->
selector();
936 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
938 if (hasSplitParameters==
true) {
939 globalLabel =
thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
941 globalLabel =
thePedeLabels->parameterLabel(alignableLabel, iSel);
943 if (globalLabel > 0 && globalLabel <= 2147483647) {
944 globalLabels.push_back(globalLabel);
949 <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy" 950 <<
"Invalid label " << globalLabel <<
" <= 0 or > 2147483647";
959 tsos, ali->
mother(), alidet,
960 globalDerivativesX, globalDerivativesY,
961 globalLabels, lowestParams);
969 std::vector<float> &globalDerivativesX,
970 std::vector<float> &globalDerivativesY,
971 std::vector<int> &globalLabels)
const 973 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
976 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
977 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
979 globalLabels.push_back(
thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
980 globalDerivativesX.push_back(iValuesInd->first.first);
981 globalDerivativesY.push_back(iValuesInd->first.second);
1025 if (recHit->dimension() < 2) {
1027 }
else if (recHit->detUnit()) {
1028 return recHit->detUnit()->type().isTrackerPixel();
1030 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
1046 std::vector<Alignable*> alis;
1047 bool okRead = reader.
read(alis, setUserVars);
1048 bool numMatch =
true;
1050 std::stringstream
out;
1051 out <<
"Read " << alis.size() <<
" alignables";
1056 if (!okRead) out <<
", but problems in reading";
1057 if (!allEmpty) out <<
", possibly overwriting previous settings";
1060 if (okRead && allEmpty) {
1062 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1063 }
else if (alis.size()) {
1064 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1066 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1072 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1080 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
1081 iAli != alignables.end(); ++iAli) {
1086 for (
int i = 0;
i < parVec.num_row(); ++
i) {
1087 if (parVec[
i] != 0.)
return false;
1088 for (
int j =
i;
j < parCov.num_col(); ++
j) {
1089 if (parCov[
i][
j] != 0.)
return false;
1104 if (outFilePlain.empty()) {
1105 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" 1106 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
1117 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" 1118 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
1121 }
else if (loop == 1) {
1123 const std::vector<std::string> inFiles
1125 const std::vector<std::string> binFiles
1127 if (inFiles.size() != binFiles.size()) {
1128 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" 1129 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' " 1130 <<
"differ in size";
1137 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" 1138 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
1144 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
1145 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
1150 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
1151 <<
" in writeAlignableAbsolutePositions, " <<
loop;
1161 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
1164 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables" 1165 <<
"No parameters for alignable";
1169 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
1186 if (mode ==
"full") {
1188 }
else if (mode ==
"mille") {
1190 }
else if (mode ==
"pede") {
1192 }
else if (mode ==
"pedeSteer") {
1194 }
else if (mode ==
"pedeRun") {
1196 }
else if (mode ==
"pedeRead") {
1201 <<
"Unknown mode '" << mode
1202 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
1209 const std::vector<std::string> &inFiles)
const 1214 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
1215 iFile != inFiles.end(); ++iFile) {
1217 const std::vector<AlignmentUserVariables*> mpVars =
1220 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics" 1221 <<
"Error " << ierr <<
" reading from " << inFile
1222 <<
", tree " << fromIov <<
", or problems in addHits";
1225 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
1226 i != mpVars.end(); ++
i) {
1236 const std::vector<AlignmentUserVariables*> &mpVars)
const 1238 bool allOk = (mpVars.size() == alis.size());
1239 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1240 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1241 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1245 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
1259 const std::vector<float> &globalDerivativesy,
1260 TMatrixF &aGlobalDerivativesM)
1263 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
1264 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
1265 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
1271 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1272 TMatrixF &aGlobalDerivativesM)
const 1274 TMatrixDSymEigen myDiag(aHitCovarianceM);
1275 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1276 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1277 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1278 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1284 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1285 aTranfoToDiagonalSystemInvF.Invert();
1287 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1290 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1291 if (aGlobalDerivativesM.GetNoElements() > 0) {
1293 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1300 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1301 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1305 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1309 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1312 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1319 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1320 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1327 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1328 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1332 const unsigned int xIndex = iTrajHit*2;
1333 const unsigned int yIndex = iTrajHit*2+1;
1337 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1338 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1339 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1340 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1343 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1344 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1351 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1352 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1353 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1360 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1361 const std::vector<float> &globalDerivativesX,
1362 const std::vector<float> &globalDerivativesY)
1366 if((aRecHit)->dimension() == 1) {
1367 return this->
callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1369 return this->
callMille2D(refTrajPtr, iTrajHit, globalLabels,
1370 globalDerivativesX, globalDerivativesY);
1378 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1379 const std::vector<float> &globalDerivativesX)
1382 const unsigned int xIndex = iTrajHit*2;
1386 const int nLocal = locDerivMatrix.num_col();
1387 std::vector<float> localDerivatives(nLocal);
1388 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1389 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1393 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1394 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1397 const int nGlobal = globalDerivativesX.size();
1401 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1402 &(globalLabels[0]), residX, hitErrX);
1405 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1406 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1407 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1408 iTrajHit, residX, hitErrX,
false);
1417 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1418 const std::vector<float> &globalDerivativesx,
1419 const std::vector<float> &globalDerivativesy)
1423 if((aRecHit)->dimension() != 2) {
1424 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D" 1425 <<
"You try to call method for 2D hits for a " 1427 <<
"D Hit. Hit gets ignored!";
1431 TMatrixDSym aHitCovarianceM(2);
1432 TMatrixF aHitResidualsM(2,1);
1433 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1435 this->
addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1436 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1442 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1445 switch(aRecHit->geographicalId().subdetId()) {
1449 this->
diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1456 float newResidX = aHitResidualsM(0,0);
1457 float newResidY = aHitResidualsM(1,0);
1458 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1459 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1460 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1461 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1462 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1463 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1464 const int nLocal = aLocalDerivativesM.GetNcols();
1465 const int nGlobal = aGlobalDerivativesM.GetNcols();
1467 if (diag && (newHitErrX > newHitErrY)) {
1471 std::swap(newLocalDerivsX, newLocalDerivsY);
1472 std::swap(newGlobDerivsX, newGlobDerivsY);
1477 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1478 &(globalLabels[0]), newResidX, newHitErrX);
1481 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1482 &(globalLabels[0]));
1483 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1484 iTrajHit, newResidX, newHitErrX,
false);
1486 const bool isReal2DHit = this->
is2D(aRecHit);
1488 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1489 &(globalLabels[0]), newResidY, newHitErrY);
1491 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1492 &(globalLabels[0]));
1493 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1494 iTrajHit, newResidY, newHitErrY,
true);
1498 return (isReal2DHit ? 2 : 1);
1505 TMatrixDSym aHitCovarianceM(1);
1506 TMatrixF aHitResidualsM(1,1);
1507 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1512 TMatrixF aGlobalDerivativesM(1,1);
1513 aGlobalDerivativesM(0,0) = 0;
1515 float newResidX = aHitResidualsM(0,0);
1516 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1517 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1518 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1519 const int nLocal = aLocalDerivativesM.GetNcols();
1520 const int nGlobal = 0;
1522 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1523 &nGlobal, newResidX, newHitErrX);
1531 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1532 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1533 iBeam != iEnd; ++iBeam, ++iTsoses){
1535 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData" 1536 <<
"Beam " << iBeam->getBeamId() <<
" with " 1537 << iBeam->parameters().size() <<
" parameters and " 1538 << iBeam->getData().size() <<
" hits.\n There are " 1539 << iTsoses->size() <<
" TSOSes.";
1541 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1548 const std::vector<TrajectoryStateOnSurface> &tsoses)
1551 std::vector<float> lasLocalDerivsX;
1554 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1555 if (!tsoses[iHit].isValid())
continue;
1560 lasLocalDerivsX.clear();
1565 tsoses[iHit], lasAli, lasAli,
1568 for (
unsigned int nFitParams = 0;
1569 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1573 lasLocalDerivsX.push_back(derivative);
1581 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1583 const float error = 0.003;
1595 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1596 if (doOutputOnStdout) {
1598 <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey" 1599 <<
"# Output from addPxbSurvey follows below because " 1600 <<
"doOutputOnStdout is set to True";
1608 std::vector<SurveyPxbImageLocalFit> measurements;
1615 if (doOutputOnStdout) {
1617 <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey" 1618 <<
"Module " <<
i <<
": ";
1643 fidpointvec.push_back(fidpoint0inSurf1frame);
1644 fidpointvec.push_back(fidpoint1inSurf1frame);
1645 fidpointvec.push_back(fidpoint2);
1646 fidpointvec.push_back(fidpoint3);
1657 a = measurements[
i].getLocalParameters();
1661 if (doOutputOnStdout)
1664 <<
"@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey" 1665 <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1666 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1667 <<
" phi= " << atan(a[3]/a[2])
1668 <<
" chi2= " << chi2 << std::endl;
1673 theMonitor->fillPxbSurveyHistsLocalPars(a[0],a[1],
sqrt(a[2]*a[2]+a[3]*a[3]),atan(a[3]/a[2]));
1679 theMille->mille((
int)measurements[
i].getLocalDerivsSize(),
1680 measurements[
i].getLocalDerivsPtr(
j),
1681 (
int)measurements[
i].getGlobalDerivsSize(),
1682 measurements[
i].getGlobalDerivsPtr(
j),
1683 measurements[
i].getGlobalDerivsLabelPtr(
j),
1684 measurements[
i].getResiduum(
j),
1685 measurements[
i].getSigma(
j));
1694 const auto runRangeSelection =
1697 if (runRangeSelection.empty())
return false;
1699 const auto runRanges =
1703 return !(runRanges.empty());
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
const align::RunNumber firstIOV_
virtual bool supportsCalibrations() override
Returns whether MP supports calibrations.
std::unique_ptr< MillePedeMonitor > theMonitor
void increaseHitsX(unsigned int add=1)
increase hits for x-measurement
bool read(std::vector< Alignable * > &alignables, bool setUserVars)
virtual bool setParametersForRunRange(const RunRange &runrange) override
const bool enableAlignableUpdates_
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
const EventID & eventID() const
void increaseHitsY(unsigned int add=1)
increase hits for y-measurement
std::vector< Alignable * > theAlignables
virtual void endLuminosityBlock(const edm::EventSetup &) override
called at end of luminosity block
TrajectoryFactoryBase::ReferenceTrajectoryCollection RefTrajColl
std::vector< ParameterSet > VParameterSet
std::unique_ptr< TrajectoryFactoryBase > theTrajectoryFactory
bool theDoSurveyPixelBarrel
void writeAlignableOriginalPositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable original (before misalignment) absolute positions
std::unique_ptr< gbl::MilleBinary > theBinary
int addGlobalData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, gbl::GblPoint &gblPoint)
align::RunNumber RunNumber
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
def setup(process, global_tag, zero_tesla=False)
void restoreCachedTransformations(void)
restore the previously cached position, rotation and other parameters
std::shared_ptr< PedeLabelerBase > thePedeLabels
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
std::vector< std::string > getExistingFormattedFiles(const std::vector< std::string > &plainFiles, const std::string &theDir)
unsigned int addHitCount(const std::vector< AlignmentParameters * > &parVec, const std::vector< bool > &validHitVecY) const
virtual LocalPoint localPosition() const
virtual bool addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals) override
Pass integrated calibrations to Millepede (they are not owned by Millepede!)
const AlgebraicMatrix & derivatives() const
matrix of local derivatives: columns are parameters, rows are hits
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
int callMille2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const bool ignoreFirstIOVCheck_
const bool ignoreHitsWithoutGlobalDerivatives_
void addLasBeam(const EventInfo &eventInfo, const TkFittedLasBeam &lasBeam, const std::vector< TrajectoryStateOnSurface > &tsoses)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
const ConstTrajTrackPairCollection & trajTrackPairs() const
define event information passed to algorithms
unsigned int doIO(int loop) const
int callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX, const std::vector< float > &globalDerivativesY)
calls callMille1D or callMille2D
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
U second(std::pair< T, U > const &p)
const AlgebraicVector & parameters(void) const
Get alignment parameters.
virtual void beginLuminosityBlock(const edm::EventSetup &) override
called at begin of luminosity block (resets Mille binary in mille mode)
std::vector< align::RunNumber > cachedRuns_
std::string doDice(const fidpoint_t &fidpointvec, const idPair_t &id, const bool rotate=false)
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
int callMille1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX)
calls Mille for 1D hits
void addLaserData(const EventInfo &eventInfo, const TkFittedLasBeamCollection &tkLasBeams, const TsosVectorCollection &tkLasBeamTsoses)
int addMeasurementData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, AlignmentParameters *¶ms)
bool isMode(unsigned int testMode) const
Container::value_type value_type
virtual void beginRun(const edm::Run &run, const edm::EventSetup &setup, bool changed) override
called at begin of run
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
CLHEP::HepMatrix AlgebraicMatrix
const std::vector< Scalar > & parameters() const
parallel to derivatives()
RunRanges makeNonOverlappingRunRanges(const edm::VParameterSet &runRanges, const RunNumber &defaultRun)
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
RunRanges makeUniqueRunRanges(const edm::VParameterSet &runRanges, const RunNumber &defaultRun)
unsigned int getBeamId(void) const
return the full beam identifier
AlignmentParameterStore * theAlignmentParameterStore
directory for all kind of files
unsigned int hitsY() const
get number of hits for y-measurement
bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
true if hit belongs to 2D detector (currently tracker specific)
const char * name() const
void diagonalize(TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM, TMatrixF &theGlobalDerivativesM) const
edm::ParameterSet theConfig
Namespace for the general broken lines package.
const TkFittedLasBeamCollection * tkLasBeams() const
std::unique_ptr< PedeSteerer > thePedeSteer
bool areIOVsSpecified() const
virtual bool storeAlignments() override
Returns whether MP produced results to be stored.
void addGlobals(const std::vector< int > &aLabels, const TMatrixD &aDerivatives)
Add global derivatives to a point.
virtual void terminate() override
Called at end of job.
const bool skipGlobalPositionRcdCheck_
virtual void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Called at beginning of job.
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
bool addHits(const std::vector< Alignable * > &alis, const std::vector< AlignmentUserVariables * > &mpVars) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
void writeMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, bool validCheck, int &ierr)
bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector< std::string > &inFiles) const
bool areEmptyParams(const std::vector< Alignable * > &alignables) const
void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas)
adds data for virtual measurements from reference trajectory
bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange)
read pede input defined by 'psetName', flag to create/not create MillePedeVariables ...
std::pair< unsigned int, unsigned int > addReferenceTrajectory(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
fill mille for a trajectory, returning number of x/y hits ([0,0] if 'bad' trajectory) ...
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
const SiStripDetId & getDetId(void) const
void addRefTrackData2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM, TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
adds data from reference trajectory from a specific Hit
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
std::vector< IntegratedCalibrationBase * > theCalibrations
int size(void) const
Get number of parameters.
std::vector< float > theFloatBufferX
void makeGlobDerivMatrix(const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy, TMatrixF &aGlobalDerivativesM)
void addUntrackedParameter(std::string const &name, T const &value)
Class to hold one picture of the BPix survey.
std::vector< value_t > localpars_t
virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm on trajectories and tracks.
void buildUserVariables(const std::vector< Alignable * > &alignables) const
add MillePedeVariables for each AlignmentParameters (exception if no parameters...)
align::RunNumber lastProcessedRun_
MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg)
Constructor.
const bool enforceSingleIOVInput_
virtual ~MillePedeAlignmentAlgorithm()
Destructor.
std::vector< TkFittedLasBeam > TkFittedLasBeamCollection
const reco::BeamSpot & beamSpot() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
void cacheTransformations(void)
cache the current position, rotation and other parameters
std::vector< float > theFloatBufferY
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
void addRefTrackVirtualMeas1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM, TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
adds data for a specific virtual measurement from reference trajectory
static const count_t nMsrmts
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable current absolute positions
eventInfo
add run, event number and lumi section
void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg)
add measurement data from PXB survey
const IOVSyncValue & first() const
unsigned int decodeMode(const std::string &mode) const
std::string fullPath() const
std::unique_ptr< AlignableNavigator > theAlignableNavigator
const std::vector< SiStripLaserRecHit2D > & getData(void) const
access the collection of hits
const align::RunRanges uniqueRunRanges_
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)
ValidityInterval const & validityInterval() const
virtual AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const =0
Get derivatives of selected parameters.
T const * product() const
Alignable * mother() const
Return pointer to container alignable (if any)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void throwException(const std::string &message, const std::string &methodName)
T get(const Candidate &c)
bool setAllDefault(unsigned int nParam)
set default values for all data concerning nParam (false if nParam out of range)
std::unique_ptr< Mille > theMille
virtual EventSetupRecordKey key() const