28 <<
"Minimum number of planes required for tracking is 3, " 40 uint32_t numberOfCombinations =
44 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Number of combinations = " << numberOfCombinations;
51 for (
const auto &
num : vec) {
63 uint32_t numberToExtract,
65 uint32_t numberOfPlanes = inputPlaneList.size();
67 bitmask.resize(numberOfPlanes, 0);
68 planeCombinations.clear();
72 planeCombinations.emplace_back();
73 for (uint32_t
i = 0;
i < numberOfPlanes; ++
i) {
75 planeCombinations.back().push_back(inputPlaneList.at(
i));
77 }
while (std::prev_permutation(bitmask.begin(), bitmask.end()));
89 std::map<CTPPSPixelDetId, PointInPlaneList>::iterator mapIterator,
94 if (mapIterator == mapOfAllHits.end()) {
95 outputMap[tmpHitPlaneMap] = tmpHitVector;
98 for (
size_t i = 0;
i < mapIterator->second.size();
i++) {
100 newHitPlaneMap[mapIterator->first] =
i;
102 newVector.push_back(mapIterator->second[
i]);
103 std::map<CTPPSPixelDetId, PointInPlaneList>::iterator tmpMapIterator = mapIterator;
104 getHitCombinations(mapOfAllHits, ++tmpMapIterator, newHitPlaneMap, newVector, outputMap);
116 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Searching for all combinations...";
118 for (
const auto &planeCombination : inputPlaneCombination) {
119 std::map<CTPPSPixelDetId, PointInPlaneList> selectedCombinationHitOnPlane;
120 bool allPlaneAsHits =
true;
125 for (
const auto &plane : planeCombination) {
131 <<
"No data on arm " << planeDetId.
arm() <<
" station " << planeDetId.
station() <<
" rp " 132 << planeDetId.
rp() <<
" plane " << planeDetId.
plane();
133 allPlaneAsHits =
false;
136 if (selectedCombinationHitOnPlane.find(planeDetId) != selectedCombinationHitOnPlane.end()) {
138 <<
"selectedCombinationHitOnPlane contains already detId " << planeDetId
139 <<
"Error in the algorithm which created all the possible plane combinations";
141 selectedCombinationHitOnPlane[planeDetId] = (*hitMap_)[planeDetId];
147 auto mapIterator = selectedCombinationHitOnPlane.begin();
150 getHitCombinations(selectedCombinationHitOnPlane, mapIterator, tmpHitPlaneMap, tmpHitVector, mapOfAllPoints);
152 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Number of possible tracks " << mapOfAllPoints.size();
156 return mapOfAllPoints;
168 unsigned int hitNum = 0;
169 for (
const auto &plane : *
hitMap_) {
170 hitNum += plane.second.size();
173 if (
hitMap_->size() == 2 && hitNum == 2) {
179 for (
const auto &plane : *
hitMap_) {
180 if (plane.second.size() > 1)
182 GlobalPoint gP(plane.second[0].globalPoint.x(), plane.second[0].globalPoint.y(), plane.second[0].globalPoint.z());
185 pIPL.push_back(plane.second[0]);
194 double xatz0 = xat0 + tx *
z0;
195 double yatz0 = yat0 + ty *
z0;
198 ROOT::Math::SVector<double, 10>
v(0.01, 0.0, 0.01, 0.0, 0.0, 0.01, 0.0, 0.0, 0.0, 0.01);
204 for (
const auto &hhit : pIPL) {
205 GlobalPoint pOD(hhit.globalPoint.x(), hhit.globalPoint.y(), hhit.globalPoint.z());
210 track.addHit(hhit.detId, usedRecHit);
220 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Number of plane with hits " <<
hitMap_->size();
222 for (
const auto &plane : *
hitMap_)
224 <<
"\tarm " << plane.first.arm() <<
" station " << plane.first.station() <<
" rp " << plane.first.rp()
225 <<
" plane " << plane.first.plane() <<
" : " << plane.second.size();
241 <<
"Number of combinations of trackMinNumberOfPoints_ planes " << mapOfAllMinRequiredPoint.size();
242 for (
const auto &pointsAndRef : mapOfAllMinRequiredPoint) {
246 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"ChiSquare of the present track " << tmpChiSquaredOverNDF;
249 if (tmpChiSquaredOverNDF < theMinChiSquaredOverNDF) {
250 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
251 pointMapWithMinChiSquared = pointsAndRef.first;
252 pointsWithMinChiSquared = pointsAndRef.second;
253 bestTrack = tmpTrack;
263 std::vector<uint32_t> listOfExcludedPlanes;
268 if (pointMapWithMinChiSquared.find(planeDetId) == pointMapWithMinChiSquared.end())
269 listOfExcludedPlanes.push_back(plane);
275 for (uint32_t
i = 1;
i <= listOfExcludedPlanes.size(); ++
i) {
278 for (
const auto &combination : tmpPlaneCombination)
279 planePointedHitListCombination.push_back(combination);
287 for (
const auto &element : mapOfPointCombinationToBeAdded) {
290 for (
const auto &pointRef : element.first)
291 newPointMap[pointRef.first] = pointRef.second;
292 for (
const auto &
point : element.second)
293 newPoints.push_back(
point);
294 mapOfAllPointWithAtLeastBestFitSelected[newPointMap] = newPoints;
300 <<
"Minimum chiSquare over NDF for all the tracks " << theMinChiSquaredOverNDF;
304 std::vector<PointAndReferencePair> orderedVectorOfAllPointWithAtLeastBestFitSelected =
306 int currentNumberOfPlanes = 0;
308 bool foundTrackWithCurrentNumberOfPlanes =
false;
309 for (
const auto &pointsAndRef : orderedVectorOfAllPointWithAtLeastBestFitSelected) {
310 int tmpNumberOfPlanes = pointsAndRef.second.size();
312 if (foundTrackWithCurrentNumberOfPlanes && tmpNumberOfPlanes < currentNumberOfPlanes)
318 if (tmpChiSquaredOverNDF < theMinChiSquaredOverNDF) {
319 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
320 pointMapWithMinChiSquared = pointsAndRef.first;
321 bestTrack = tmpTrack;
322 currentNumberOfPlanes = tmpNumberOfPlanes;
323 foundTrackWithCurrentNumberOfPlanes =
true;
328 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"The best track has " << bestTrack.
ndf() / 2 + 2;
332 for (
const auto &hitToErase : pointMapWithMinChiSquared) {
333 std::map<CTPPSPixelDetId, PointInPlaneList>::iterator hitMapElement =
hitMap_->find(hitToErase.first);
334 if (hitMapElement ==
hitMap_->end()) {
336 <<
"The found tracks has hit belonging to a plane which does not have hits";
338 std::vector<uint32_t>::iterator planeIt;
339 planeIt =
std::find(listOfPlaneNotUsedForFit.begin(), listOfPlaneNotUsedForFit.end(), hitToErase.first.plane());
340 listOfPlaneNotUsedForFit.erase(planeIt);
341 hitMapElement->second.erase(hitMapElement->second.begin() + hitToErase.second);
343 if (hitMapElement->second.empty())
353 for (
const auto &plane : listOfPlaneNotUsedForFit) {
368 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0),
369 tmpPlaneRotationMatrixMap(0, 1),
370 tmpPlaneRotationMatrixMap(0, 2),
371 tmpPlaneRotationMatrixMap(1, 0),
372 tmpPlaneRotationMatrixMap(1, 1),
373 tmpPlaneRotationMatrixMap(1, 2),
374 tmpPlaneRotationMatrixMap(2, 0),
375 tmpPlaneRotationMatrixMap(2, 1),
376 tmpPlaneRotationMatrixMap(2, 2));
378 maxGlobalPointDistance = tmpPlaneRotationMatrixMap * maxGlobalPointDistance;
380 double maximumXdistance = maxGlobalPointDistance[0] * maxGlobalPointDistance[0];
381 double maximumYdistance = maxGlobalPointDistance[1] * maxGlobalPointDistance[1];
383 double minimumDistance = 1. + maximumXdistance + maximumYdistance;
384 for (
const auto &
hit : (*
hitMap_)[tmpPlaneId]) {
385 double xResidual =
hit.globalPoint.
x() - pointOnDet.
x();
386 double yResidual =
hit.globalPoint.
y() - pointOnDet.
y();
387 double xDistance = xResidual * xResidual;
388 double yDistance = yResidual * yResidual;
389 double distance = xDistance + yDistance;
390 if (xDistance < maximumXdistance && yDistance < maximumYdistance &&
distance < minimumDistance) {
391 LocalPoint residuals(xResidual, yResidual, 0.);
394 fittedRecHit = std::make_unique<CTPPSPixelFittedRecHit>(
hit.recHit, pointOnDet, residuals, pulls);
395 fittedRecHit->setIsRealHit(
true);
402 fittedRecHit = std::make_unique<CTPPSPixelFittedRecHit>(fakeRecHit, pointOnDet, fakePoint, fakePoint);
405 bestTrack.
addHit(tmpPlaneId, *fittedRecHit);
410 int pointForTracking = 0;
411 int pointOnTrack = 0;
414 for (
const auto &planeHits : bestTrack.
hits()) {
415 for (
const auto &fittedhit : planeHits) {
416 if (fittedhit.isUsedForFit())
418 if (fittedhit.isRealHit())
423 <<
"Best track has " << pointForTracking <<
" points used for the fit and " << pointOnTrack
424 <<
" points belonging to the track\n";
442 static const std::map<unsigned int, std::map<CTPPSPixelDetId, std::vector<bool> > > isPlaneShifted = {
445 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
446 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
450 {rpId_arm0_st2, {
true,
false,
true,
true,
false,
false}},
451 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
455 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
456 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
460 {rpId_arm0_st2, {
false,
true,
false,
true,
false,
true}},
461 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
465 {rpId_arm0_st2, {
false,
true,
false,
true,
false,
true}},
466 {rpId_arm1_st2, {
false,
false,
true,
false,
true,
true}}
470 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
471 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
473 const auto &shiftStatusInitialRun = std::prev(isPlaneShifted.upper_bound(
run));
474 unsigned short shiftedROC = 10;
488 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Analyzing run: " <<
run <<
"\nTrack belongs to Arm " 493 unsigned short bxShiftedPlanesUsed = 0;
494 unsigned short bxNonShiftedPlanesUsed = 0;
495 unsigned short hitInShiftedROC = 0;
497 auto const &fittedHits =
track.hits();
498 auto const &planeFlags = (shiftStatusInitialRun->second).at(
romanPotId_);
500 for (
const auto &planeHits : fittedHits) {
502 for (
const auto &
hit : planeHits) {
503 if (
hit.isUsedForFit()) {
504 if (pixelIndices.
getROCId(
hit.minPixelCol(),
hit.minPixelRow()) == shiftedROC)
506 if (planeFlags.at(plane))
507 bxShiftedPlanesUsed++;
508 else if (planeFlags != std::vector<bool>(6,
false))
509 bxNonShiftedPlanesUsed++;
517 if (hitInShiftedROC < 3)
520 if (bxShiftedPlanesUsed == 0 && bxNonShiftedPlanesUsed == 0)
523 if (bxShiftedPlanesUsed == 3 && bxNonShiftedPlanesUsed == 0)
526 if (bxShiftedPlanesUsed == 0 && bxNonShiftedPlanesUsed == 3)
529 if (bxShiftedPlanesUsed > 0 && bxNonShiftedPlanesUsed > 0)
533 if (bxShiftedPlanesUsed + bxNonShiftedPlanesUsed > 6) {
534 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::findTracks -> " 535 <<
"More than six points found for a track, skipping.";
539 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::findTracks -> " 540 <<
"recoInfo has not been set properly.";
546 <<
"\nFirst run with this bx-shift configuration: " << shiftStatusInitialRun->first
547 <<
"\nTrack reconstructed with: " << bxShiftedPlanesUsed <<
" bx-shifted planes, " << bxNonShiftedPlanesUsed
548 <<
" non-bx-shifted planes, " << hitInShiftedROC <<
" hits in the bx-shifted ROC" 549 <<
"\nrecoInfo = " << (
unsigned short)
track.recoInfo();
550 if (planeFlags != std::vector<bool>(6,
false))
551 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"The shifted ROC is ROC" << shiftedROC;
560 uint32_t
const numberOfPlanes = 6;
566 for (uint32_t iHit = 0; iHit < numberOfPlanes; iHit++) {
567 if (iHit < pointList.size()) {
568 const auto &globalPoint = pointList[iHit].globalPoint;
569 xyCoordinates[2 * iHit] = globalPoint.x();
570 xyCoordinates[2 * iHit + 1] = globalPoint.y();
571 zMatrix(2 * iHit, 0) = 1.;
572 zMatrix(2 * iHit, 2) = globalPoint.z() -
z0_;
573 zMatrix(2 * iHit + 1, 1) = 1.;
574 zMatrix(2 * iHit + 1, 3) = globalPoint.z() -
z0_;
577 varianceMatrix(2 * iHit, 2 * iHit) = globalError(0, 0);
578 varianceMatrix(2 * iHit, 2 * iHit + 1) = globalError(0, 1);
579 varianceMatrix(2 * iHit + 1, 2 * iHit) = globalError(1, 0);
580 varianceMatrix(2 * iHit + 1, 2 * iHit + 1) = globalError(1, 1);
582 varianceMatrix(2 * iHit, 2 * iHit) = 1.;
583 varianceMatrix(2 * iHit + 1, 2 * iHit + 1) = 1.;
588 if (!varianceMatrix.Invert()) {
589 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 590 <<
"Point variance matrix is singular, skipping.";
599 if (!covarianceMatrix.Invert()) {
600 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 601 <<
"Parameter covariance matrix is singular, skipping.";
609 ROOT::Math::Transpose(zMatrix) * varianceMatrix * xyCoordinates;
610 math::Vector<4>::type parameterVector = covarianceMatrix * zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates;
612 xyCoordinates - (zMatrix * parameterVector);
614 double chiSquare = ROOT::Math::Dot(xyCoordinatesMinusZmatrixTimesParameters,
615 (varianceMatrix * xyCoordinatesMinusZmatrixTimesParameters));
620 for (
const auto &
hit : pointList) {
621 const auto &globalPoint =
hit.globalPoint;
629 double xResidual = globalPoint.x() - pointOnDet.
x();
630 double yResidual = globalPoint.y() - pointOnDet.
y();
665 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0),
666 tmpPlaneRotationMatrixMap(0, 1),
667 tmpPlaneRotationMatrixMap(0, 2),
668 tmpPlaneRotationMatrixMap(1, 0),
669 tmpPlaneRotationMatrixMap(1, 1),
670 tmpPlaneRotationMatrixMap(1, 2),
671 tmpPlaneRotationMatrixMap(2, 0),
672 tmpPlaneRotationMatrixMap(2, 1),
673 tmpPlaneRotationMatrixMap(2, 2));
675 planeUnitVector = tmpPlaneRotationMatrixMap * planeUnitVector;
677 double denominator = ROOT::Math::Dot(lineUnitVector, planeUnitVector);
680 <<
"Error in RPixPlaneCombinatoryTracking::calculatePointOnDetector -> " 681 <<
"Fitted line and plane are parallel. Removing this track";
685 double distanceFromLinePoint = ROOT::Math::Dot((pointOnPlane - pointOnLine), planeUnitVector) /
denominator;
688 planeLineIntercept =
GlobalPoint(tmpPlaneLineIntercept[0], tmpPlaneLineIntercept[1], tmpPlaneLineIntercept[2]);
695 std::vector<RPixPlaneCombinatoryTracking::PointAndReferencePair>
697 std::vector<PointAndReferencePair> sortedVector(inputMap.begin(), inputMap.end());
~RPixPlaneCombinatoryTracking() override
uint32_t factorial(uint32_t x) const
T getParameter(std::string const &) const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
double maximumYLocalDistanceFromTrack_
RPixPlaneCombinatoryTracking(edm::ParameterSet const ¶meterSet)
std::map< CTPPSPixelDetId, size_t > HitReferences
bool calculatePointOnDetector(CTPPSPixelLocalTrack *track, CTPPSPixelDetId planeId, GlobalPoint &planeLineIntercept)
std::vector< PointAndReferencePair > orderCombinationsPerNumberOrPoints(PointAndReferenceMap inputMap)
double maximumChi2OverNDF_
Global3DPoint GlobalPoint
CTPPSpixelLocalTrackReconstructionInfo
Vector localToGlobal(const DetGeomDesc *, const Vector &) const
void getPlaneCombinations(const std::vector< uint32_t > &inputPlaneList, uint32_t numberToExtract, PlaneCombinations &planeCombinations) const
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
DetGeomDesc::Translation Vector
T getUntrackedParameter(std::string const &, T const &) const
float chiSquaredOverNDF() const
std::vector< CTPPSPixelLocalTrack > localTrackVector_
std::map< HitReferences, PointInPlaneList > PointAndReferenceMap
double maximumXLocalDistanceFromTrack_
void getHitCombinations(const std::map< CTPPSPixelDetId, PointInPlaneList > &mapOfAllHits, std::map< CTPPSPixelDetId, PointInPlaneList >::iterator mapIterator, HitReferences tmpHitPlaneMap, const PointInPlaneList &tmpHitVector, PointAndReferenceMap &outputMap)
CTPPSPixelLocalTrack fitTrack(PointInPlaneList pointList)
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
std::vector< RPixDetPatternFinder::PointInPlane > PointInPlaneList
void initialize() override
const DetGeomDesc * sensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
uint32_t numberOfPlanesPerPot_
std::map< CTPPSPixelDetId, std::vector< RPixDetPatternFinder::PointInPlane > > * hitMap_
void findTracks(int run) override
void setIsUsedForFit(bool usedForFit)
void addHit(unsigned int detId, const CTPPSPixelFittedRecHit &hit)
std::vector< uint32_t > listOfAllPlanes_
void setPlane(uint32_t pl)
Log< level::Info, false > LogInfo
ROOT::Math::SMatrix< double, N, M > type
uint32_t trackMinNumberOfPoints_
void setIsRealHit(bool realHit)
Vector rpTranslation(unsigned int id) const
const CTPPSGeometry * geometry_
math::Vector< dimension >::type ParameterVector
covariance matrix size
const RotationMatrix & rotation() const
int getROCId(const int col, const int row) const
PointAndReferenceMap produceAllHitCombination(PlaneCombinations inputPlaneCombination)
const edm::DetSetVector< CTPPSPixelFittedRecHit > & hits() const
CTPPSPixelDetId romanPotId_
static bool functionForPlaneOrdering(PointAndReferencePair a, PointAndReferencePair b)
PlaneCombinations possiblePlaneCombinations_
std::vector< std::vector< uint32_t > > PlaneCombinations
ROOT::Math::Rotation3D RotationMatrix
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
void setValid(bool valid)