65 #include <TMatrixDSymEigen.h>
85 theConfig(cfg), theMode(this->decodeMode(theConfig.getUntrackedParameter<std::
string>(
"mode"))),
86 theDir(theConfig.getUntrackedParameter<std::
string>(
"fileDir")),
87 theAlignmentParameterStore(0), theAlignables(), theAlignableNavigator(0),
88 theMonitor(0), theMille(0), thePedeLabels(0), thePedeSteer(0),
89 theTrajectoryFactory(0),
90 theMinNumHits(cfg.getParameter<unsigned int>(
"minNumHits")),
91 theMaximalCor2D(cfg.getParameter<double>(
"max2Dcorrelation")),
93 theBinary(0),theGblDoubleBinary(cfg.getParameter<bool>(
"doubleBinary"))
96 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm" <<
"Start in mode '"
98 <<
"' with output directory '" <<
theDir <<
"'.";
131 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
132 <<
"Running with AlignabeMuon not yet tested.";
147 RunRangeSelectionVPSet);
150 if (RunRangeSelectionVPSet.size()>0) {
151 labelerPlugin =
"RunRangeDependentPedeLabeler";
152 if (pedeLabelerCfg.
exists(
"plugin")) {
154 if ((labelerPluginCfg!=
"PedeLabeler" && labelerPluginCfg!=
"RunRangeDependentPedeLabeler") ||
157 <<
"MillePedeAlignmentAlgorithm::initialize"
158 <<
"both RunRangeSelection and generic labeler specified in config file. "
159 <<
"Please get rid of either one of them.\n";
163 if (pedeLabelerCfg.
exists(
"plugin")) {
168 if (!pedeLabelerCfg.
exists(
"plugin")) {
172 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
173 <<
"Using plugin '" << labelerPlugin <<
"' to generate labels.";
187 const std::vector<edm::ParameterSet> mprespset
189 if (!mprespset.empty()) {
190 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::initialize"
191 <<
"Apply " << mprespset.end() - mprespset.begin()
192 <<
" previous MillePede constants from 'pedeReaderInputs'.";
199 for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
200 iSet != iE; ++iSet) {
205 <<
"MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
206 <<
"pedeReaderInputs entry " << iSet - mprespset.begin() <<
'.';
223 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
224 <<
"modes running mille.";
264 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
265 <<
"Problems reading pede result, but applying!";
282 std::vector<std::string>
files;
286 const std::vector<std::string> plainFiles
288 for (std::vector<std::string>::const_iterator
i = plainFiles.begin(), iEnd = plainFiles.end();
316 for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
317 iTrajTrack != tracks.end(); ++iTrajTrack) {
325 unsigned int refTrajCount = 0;
326 for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
327 iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
332 const std::pair<unsigned int, unsigned int> nHitXy
335 if (
theMonitor && (nHitXy.first || nHitXy.second)) {
339 (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
348 std::pair<unsigned int, unsigned int>
353 std::pair<unsigned int, unsigned int> hitResultXy(0,0);
354 if (refTrajPtr->isValid()) {
358 if (refTrajPtr->gblInput().size() > 0) {
360 unsigned int iHit = 0;
361 unsigned int numPointsWithMeas = 0;
362 std::vector<GblPoint>::iterator itPoint;
363 std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
364 for (
unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
365 for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
366 if (this->
addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
return hitResultXy;
367 if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
370 hitResultXy.first = numPointsWithMeas;
372 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits)
return hitResultXy;
374 if (refTrajPtr->gblInput().size() == 1) {
376 GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
386 if (refTrajPtr->gblInput().size() == 2) {
388 GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
394 std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
396 std::vector<bool> validHitVecY(refTrajPtr->recHits().size(),
false);
398 for (
unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
399 const int flagXY = this->
addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
402 hitResultXy.first = 0;
405 if (flagXY >= 1) ++hitResultXy.first;
406 validHitVecY[iHit] = (flagXY >= 2);
411 for (
unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
416 if (hitResultXy.first == 0 || hitResultXy.first <
theMinNumHits) {
418 hitResultXy.first = hitResultXy.second = 0;
423 hitResultXy.second = this->
addHitCount(parVec, validHitVecY);
436 const std::vector<bool> &validHitVecY)
const
439 unsigned int nHitY = 0;
440 for (
unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
441 Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
452 if (validHitVecY[iHit]) {
454 if (pars == parVec[iHit]) ++nHitY;
489 if (!recHitPtr->isValid())
return 0;
514 unsigned int iHit,
GblPoint &gblPoint)
517 std::vector<double> theDoubleBufferX, theDoubleBufferY;
518 theDoubleBufferX.clear();
519 theDoubleBufferY.clear();
526 if (!recHitPtr->isValid())
return 0;
532 tsos, alidet, alidet, theDoubleBufferX,
538 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
541 (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
542 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
545 if (globalLabel > 0 && globalLabel <= 2147483647) {
547 theDoubleBufferX.push_back(iValuesInd->first.first);
548 theDoubleBufferY.push_back(iValuesInd->first.second);
550 std::cerr <<
"MillePedeAlignmentAlgorithm::addGlobalData: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
557 TMatrixD globalDer(2,numGlobals);
558 for (
unsigned int i = 0;
i < numGlobals; ++
i) {
559 globalDer(0,
i) = theDoubleBufferX[
i];
560 globalDer(1,
i) = theDoubleBufferY[
i];
573 std::vector<float> &globalDerivativesX,
574 std::vector<float> &globalDerivativesY,
575 std::vector<int> &globalLabels,
579 if (!ali)
return true;
581 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
586 if (!lowestParams) lowestParams = params;
588 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
589 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
591 if (0 == alignableLabel) {
592 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
593 <<
"Label not found, skip Alignable.";
597 const std::vector<bool> &selPars = params->
selector();
601 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
603 globalDerivativesX.push_back(derivs[iSel][kLocalX]
604 /thePedeSteer->cmsToPedeFactor(iSel));
605 if (hasSplitParameters==
true) {
606 globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
608 globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
610 globalDerivativesY.push_back(derivs[iSel][kLocalY]
611 /thePedeSteer->cmsToPedeFactor(iSel));
615 if (thePedeSteer->isNoHiera(ali))
return true;
618 return this->globalDerivativesHierarchy(eventInfo,
619 tsos, ali->
mother(), alidet,
620 globalDerivativesX, globalDerivativesY,
621 globalLabels, lowestParams);
629 std::vector<double> &globalDerivativesX,
630 std::vector<double> &globalDerivativesY,
631 std::vector<int> &globalLabels,
635 if (!ali)
return true;
637 if (
false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
642 if (!lowestParams) lowestParams = params;
644 bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
645 const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
647 if (0 == alignableLabel) {
648 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
649 <<
"Label not found, skip Alignable.";
653 const std::vector<bool> &selPars = params->
selector();
658 for (
unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
660 if (hasSplitParameters==
true) {
661 globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
663 globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
665 if (globalLabel > 0 && globalLabel <= 2147483647) {
666 globalLabels.push_back(globalLabel);
667 globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
668 globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
670 std::cerr <<
"MillePedeAlignmentAlgorithm::globalDerivativesHierarchy: Invalid label " << globalLabel <<
" <= 0 or > 2147483647" << std::endl;
675 if (thePedeSteer->isNoHiera(ali))
return true;
678 return this->globalDerivativesHierarchy(eventInfo,
679 tsos, ali->
mother(), alidet,
680 globalDerivativesX, globalDerivativesY,
681 globalLabels, lowestParams);
689 std::vector<float> &globalDerivativesX,
690 std::vector<float> &globalDerivativesY,
691 std::vector<int> &globalLabels)
const
693 std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
696 (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
697 for (
auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
700 globalDerivativesX.push_back(iValuesInd->first.first);
701 globalDerivativesY.push_back(iValuesInd->first.second);
745 if (recHit->dimension() < 2) {
747 }
else if (recHit->detUnit()) {
748 return recHit->detUnit()->type().isTrackerPixel();
750 if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) {
766 std::vector<Alignable*> alis;
767 bool okRead = reader.
read(alis, setUserVars);
768 bool numMatch =
true;
770 std::stringstream
out;
771 out <<
"Read " << alis.size() <<
" alignables";
776 if (!okRead) out <<
", but problems in reading";
777 if (!allEmpty) out <<
", possibly overwriting previous settings";
780 if (okRead && allEmpty) {
782 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
783 }
else if (alis.size()) {
784 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
786 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
792 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
800 for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
801 iAli != alignables.end(); ++iAli) {
806 for (
int i = 0;
i < parVec.num_row(); ++
i) {
807 if (parVec[
i] != 0.)
return false;
808 for (
int j =
i;
j < parCov.num_col(); ++
j) {
809 if (parCov[
i][
j] != 0.)
return false;
824 if (outFilePlain.empty()) {
825 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
826 <<
"treeFile parameter empty => skip writing for 'loop' " <<
loop;
837 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
838 <<
"Problem " << ioerr <<
" in writeAlignableOriginalPositions";
841 }
else if (loop == 1) {
843 const std::vector<std::string> inFiles
845 const std::vector<std::string> binFiles
847 if (inFiles.size() != binFiles.size()) {
848 edm::LogWarning(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
849 <<
"'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
857 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO"
858 <<
"Problem " << ioerr <<
" writing MillePedeVariables";
864 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
865 <<
" in writeOrigRigidBodyAlignmentParameters, " <<
loop;
870 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::doIO" <<
"Problem " << ioerr
871 <<
" in writeAlignableAbsolutePositions, " <<
loop;
881 for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
884 throw cms::Exception(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
885 <<
"No parameters for alignable";
889 for (
unsigned int iPar = 0; iPar < userVars->
size(); ++iPar) {
906 if (mode ==
"full") {
908 }
else if (mode ==
"mille") {
910 }
else if (mode ==
"pede") {
912 }
else if (mode ==
"pedeSteer") {
914 }
else if (mode ==
"pedeRun") {
916 }
else if (mode ==
"pedeRead") {
921 <<
"Unknown mode '" << mode
922 <<
"', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
929 const std::vector<std::string> &inFiles)
const
934 for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
935 iFile != inFiles.end(); ++iFile) {
937 const std::vector<AlignmentUserVariables*> mpVars =
940 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
941 <<
"Error " << ierr <<
" reading from " << inFile
942 <<
", tree " << fromIov <<
", or problems in addHits";
945 for (std::vector<AlignmentUserVariables*>::const_iterator
i = mpVars.begin();
946 i != mpVars.end(); ++
i) {
956 const std::vector<AlignmentUserVariables*> &mpVars)
const
958 bool allOk = (mpVars.size() == alis.size());
959 std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
960 for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
961 iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
965 if (!mpVarNew || !mpVarOld || mpVarOld->
size() != mpVarNew->
size()) {
979 const std::vector<float> &globalDerivativesy,
980 TMatrixF &aGlobalDerivativesM)
983 for (
unsigned int i = 0;
i < globalDerivativesx.size(); ++
i) {
984 aGlobalDerivativesM(0,
i) = globalDerivativesx[
i];
985 aGlobalDerivativesM(1,
i) = globalDerivativesy[
i];
991 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
992 TMatrixF &aGlobalDerivativesM)
const
994 TMatrixDSymEigen myDiag(aHitCovarianceM);
995 TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
996 TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
997 TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
998 TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1004 aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1005 aTranfoToDiagonalSystemInvF.Invert();
1007 aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1010 aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1011 aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1017 unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1018 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1022 const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1026 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1029 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1036 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1037 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1044 unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1045 TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1049 const unsigned int xIndex = iTrajHit*2;
1050 const unsigned int yIndex = iTrajHit*2+1;
1054 aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1055 aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1056 aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1057 aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1060 aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1061 aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1068 for (
int i = 0;
i < locDerivMatrix.num_col(); ++
i) {
1069 aLocalDerivativesM(0,
i) = locDerivMatrix[xIndex][
i];
1070 aLocalDerivativesM(1,
i) = locDerivMatrix[yIndex][
i];
1077 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1078 const std::vector<float> &globalDerivativesX,
1079 const std::vector<float> &globalDerivativesY)
1083 if((aRecHit)->dimension() == 1) {
1084 return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1086 return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1087 globalDerivativesX, globalDerivativesY);
1095 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1096 const std::vector<float> &globalDerivativesX)
1099 const unsigned int xIndex = iTrajHit*2;
1103 const int nLocal = locDerivMatrix.num_col();
1104 std::vector<float> localDerivatives(nLocal);
1105 for (
unsigned int i = 0;
i < localDerivatives.size(); ++
i) {
1106 localDerivatives[
i] = locDerivMatrix[xIndex][
i];
1110 float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1111 float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1114 const int nGlobal = globalDerivativesX.size();
1118 theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1119 &(globalLabels[0]), residX, hitErrX);
1122 theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1123 &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1124 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1125 iTrajHit, residX, hitErrX,
false);
1134 unsigned int iTrajHit,
const std::vector<int> &globalLabels,
1135 const std::vector<float> &globalDerivativesx,
1136 const std::vector<float> &globalDerivativesy)
1140 if((aRecHit)->dimension() != 2) {
1141 edm::LogError(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1142 <<
"You try to call method for 2D hits for a "
1144 <<
"D Hit. Hit gets ignored!";
1148 TMatrixDSym aHitCovarianceM(2);
1149 TMatrixF aHitResidualsM(2,1);
1150 TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1152 this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1153 TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1154 this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1159 const double corr = aHitCovarianceM(0,1) /
sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1160 if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1162 switch(aRecHit->geographicalId().subdetId()) {
1166 this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1173 float newResidX = aHitResidualsM(0,0);
1174 float newResidY = aHitResidualsM(1,0);
1175 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1176 float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1177 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1178 float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1179 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1180 float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1181 const int nLocal = aLocalDerivativesM.GetNcols();
1182 const int nGlobal = aGlobalDerivativesM.GetNcols();
1184 if (diag && (newHitErrX > newHitErrY)) {
1188 std::swap(newLocalDerivsX, newLocalDerivsY);
1189 std::swap(newGlobDerivsX, newGlobDerivsY);
1194 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1195 &(globalLabels[0]), newResidX, newHitErrX);
1198 theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1199 &(globalLabels[0]));
1200 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1201 iTrajHit, newResidX, newHitErrX,
false);
1203 const bool isReal2DHit = this->is2D(aRecHit);
1205 theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1206 &(globalLabels[0]), newResidY, newHitErrY);
1208 theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1209 &(globalLabels[0]));
1210 theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1211 iTrajHit, newResidY, newHitErrY,
true);
1215 return (isReal2DHit ? 2 : 1);
1222 TMatrixDSym aHitCovarianceM(1);
1223 TMatrixF aHitResidualsM(1,1);
1224 TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1226 this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1229 TMatrixF aGlobalDerivativesM(1,1);
1230 aGlobalDerivativesM(0,0) = 0;
1232 float newResidX = aHitResidualsM(0,0);
1233 float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1234 float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1235 float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1236 const int nLocal = aLocalDerivativesM.GetNcols();
1237 const int nGlobal = 0;
1239 theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1240 &nGlobal, newResidX, newHitErrX);
1248 TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1249 for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1250 iBeam != iEnd; ++iBeam, ++iTsoses){
1252 edm::LogInfo(
"Alignment") <<
"@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1253 <<
"Beam " << iBeam->getBeamId() <<
" with "
1254 << iBeam->parameters().size() <<
" parameters and "
1255 << iBeam->getData().size() <<
" hits.\n There are "
1256 << iTsoses->size() <<
" TSOSes.";
1258 this->
addLasBeam(eventInfo, *iBeam, *iTsoses);
1265 const std::vector<TrajectoryStateOnSurface> &tsoses)
1268 std::vector<float> lasLocalDerivsX;
1271 for (
unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1272 if (!tsoses[iHit].isValid())
continue;
1277 lasLocalDerivsX.clear();
1282 tsoses[iHit], lasAli, lasAli,
1285 for (
unsigned int nFitParams = 0;
1286 nFitParams < static_cast<unsigned int>(lasBeam.
parameters().size());
1290 lasLocalDerivsX.push_back(derivative);
1298 const float residual = hit.
localPosition().x() - tsoses[iHit].localPosition().x();
1300 const float error = 0.003;
1312 const bool doOutputOnStdout(pxbSurveyCfg.
getParameter<
bool>(
"doOutputOnStdout"));
1313 if (doOutputOnStdout)
std::cout <<
"# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1320 std::vector<SurveyPxbImageLocalFit> measurements;
1327 if (doOutputOnStdout)
std::cout <<
"Module " <<
i <<
": ";
1351 fidpointvec.push_back(fidpoint0inSurf1frame);
1352 fidpointvec.push_back(fidpoint1inSurf1frame);
1353 fidpointvec.push_back(fidpoint2);
1354 fidpointvec.push_back(fidpoint3);
1359 dicer.
doDice(fidpointvec,measurements[i].getIdPair(),
outfile);
1365 a = measurements[
i].getLocalParameters();
1369 if (doOutputOnStdout)
1371 std::cout <<
"a: " << a[0] <<
", " << a[1] <<
", " << a[2] <<
", " << a[3]
1372 <<
" S= " <<
sqrt(a[2]*a[2]+a[3]*a[3])
1373 <<
" phi= " << atan(a[3]/a[2])
1374 <<
" chi2= " << chi2 << std::endl;
1386 measurements[i].getLocalDerivsPtr(
j),
1387 (
int)measurements[i].getGlobalDerivsSize(),
1388 measurements[i].getGlobalDerivsPtr(
j),
1389 measurements[i].getGlobalDerivsLabelPtr(
j),
1390 measurements[i].getResiduum(
j),
1391 measurements[i].getSigma(
j));
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
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 &_)
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)
Call 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)
virtual void terminate(const edm::EventSetup &iSetup)
Call at end of job.
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)
virtual void endRun(const EventInfo &eventInfo, const EndRunInfo &runInfo, const edm::EventSetup &setup)
Run on run products, e.g. TkLAS.
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
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)