27 <<
"Minimum number of planes required for tracking is 3, " 39 uint32_t numberOfCombinations =
43 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Number of combinations = " << numberOfCombinations;
50 for (
const auto &
num : vec) {
62 uint32_t numberToExtract,
64 uint32_t numberOfPlanes = inputPlaneList.size();
66 bitmask.resize(numberOfPlanes, 0);
67 planeCombinations.clear();
71 planeCombinations.push_back(std::vector<uint32_t>());
72 for (uint32_t
i = 0;
i < numberOfPlanes; ++
i) {
74 planeCombinations.back().push_back(inputPlaneList.at(i));
76 }
while (std::prev_permutation(bitmask.begin(), bitmask.end()));
88 std::map<CTPPSPixelDetId, PointInPlaneList>::iterator mapIterator,
93 if (mapIterator == mapOfAllHits.end()) {
94 outputMap[tmpHitPlaneMap] = tmpHitVector;
97 for (
size_t i = 0;
i < mapIterator->second.size();
i++) {
99 newHitPlaneMap[mapIterator->first] =
i;
101 newVector.push_back(mapIterator->second[
i]);
102 std::map<CTPPSPixelDetId, PointInPlaneList>::iterator tmpMapIterator = mapIterator;
103 getHitCombinations(mapOfAllHits, ++tmpMapIterator, newHitPlaneMap, newVector, outputMap);
115 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Searching for all combinations...";
117 for (
const auto &planeCombination : inputPlaneCombination) {
118 std::map<CTPPSPixelDetId, PointInPlaneList> selectedCombinationHitOnPlane;
119 bool allPlaneAsHits =
true;
124 for (
const auto &plane : planeCombination) {
130 <<
"No data on arm " << planeDetId.
arm() <<
" station " << planeDetId.
station() <<
" rp " 131 << planeDetId.
rp() <<
" plane " << planeDetId.
plane();
132 allPlaneAsHits =
false;
135 if (selectedCombinationHitOnPlane.find(planeDetId) != selectedCombinationHitOnPlane.end()) {
137 <<
"selectedCombinationHitOnPlane contains already detId " << planeDetId
138 <<
"Error in the algorithm which created all the possible plane combinations";
140 selectedCombinationHitOnPlane[planeDetId] = (*hitMap_)[planeDetId];
146 auto mapIterator = selectedCombinationHitOnPlane.begin();
149 getHitCombinations(selectedCombinationHitOnPlane, mapIterator, tmpHitPlaneMap, tmpHitVector, mapOfAllPoints);
151 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Number of possible tracks " << mapOfAllPoints.size();
155 return mapOfAllPoints;
167 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Number of plane with hits " <<
hitMap_->size();
169 for (
const auto &plane : *
hitMap_)
171 <<
"\tarm " << plane.first.arm() <<
" station " << plane.first.station() <<
" rp " << plane.first.rp()
172 <<
" plane " << plane.first.plane() <<
" : " << plane.second.size();
188 <<
"Number of combinations of trackMinNumberOfPoints_ planes " << mapOfAllMinRequiredPoint.size();
189 for (
const auto &pointsAndRef : mapOfAllMinRequiredPoint) {
193 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"ChiSquare of the present track " << tmpChiSquaredOverNDF;
196 if (tmpChiSquaredOverNDF < theMinChiSquaredOverNDF) {
197 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
198 pointMapWithMinChiSquared = pointsAndRef.first;
199 pointsWithMinChiSquared = pointsAndRef.second;
200 bestTrack = tmpTrack;
210 std::vector<uint32_t> listOfExcludedPlanes;
215 if (pointMapWithMinChiSquared.find(planeDetId) == pointMapWithMinChiSquared.end())
216 listOfExcludedPlanes.push_back(plane);
222 for (uint32_t
i = 1;
i <= listOfExcludedPlanes.size(); ++
i) {
225 for (
const auto &combination : tmpPlaneCombination)
226 planePointedHitListCombination.push_back(combination);
234 for (
const auto &element : mapOfPointCombinationToBeAdded) {
237 for (
const auto &pointRef : element.first)
238 newPointMap[pointRef.first] = pointRef.second;
239 for (
const auto &
point : element.second)
240 newPoints.push_back(
point);
241 mapOfAllPointWithAtLeastBestFitSelected[newPointMap] = newPoints;
247 <<
"Minimum chiSquare over NDF for all the tracks " << theMinChiSquaredOverNDF;
251 std::vector<PointAndReferencePair> orderedVectorOfAllPointWithAtLeastBestFitSelected =
253 int currentNumberOfPlanes = 0;
255 bool foundTrackWithCurrentNumberOfPlanes =
false;
256 for (
const auto &pointsAndRef : orderedVectorOfAllPointWithAtLeastBestFitSelected) {
257 int tmpNumberOfPlanes = pointsAndRef.second.size();
259 if (foundTrackWithCurrentNumberOfPlanes && tmpNumberOfPlanes < currentNumberOfPlanes)
265 if (tmpChiSquaredOverNDF < theMinChiSquaredOverNDF) {
266 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
267 pointMapWithMinChiSquared = pointsAndRef.first;
268 bestTrack = tmpTrack;
269 currentNumberOfPlanes = tmpNumberOfPlanes;
270 foundTrackWithCurrentNumberOfPlanes =
true;
275 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"The best track has " << bestTrack.
ndf() / 2 + 2;
279 for (
const auto &hitToErase : pointMapWithMinChiSquared) {
280 std::map<CTPPSPixelDetId, PointInPlaneList>::iterator hitMapElement = hitMap_->find(hitToErase.first);
281 if (hitMapElement == hitMap_->end()) {
283 <<
"The found tracks has hit belonging to a plane which does not have hits";
285 std::vector<uint32_t>::iterator planeIt;
286 planeIt =
std::find(listOfPlaneNotUsedForFit.begin(), listOfPlaneNotUsedForFit.end(), hitToErase.first.plane());
287 listOfPlaneNotUsedForFit.erase(planeIt);
288 hitMapElement->second.erase(hitMapElement->second.begin() + hitToErase.second);
290 if (hitMapElement->second.empty())
291 hitMap_->erase(hitMapElement);
300 for (
const auto &plane : listOfPlaneNotUsedForFit) {
307 if (hitMap_->find(tmpPlaneId) != hitMap_->end()) {
315 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0),
316 tmpPlaneRotationMatrixMap(0, 1),
317 tmpPlaneRotationMatrixMap(0, 2),
318 tmpPlaneRotationMatrixMap(1, 0),
319 tmpPlaneRotationMatrixMap(1, 1),
320 tmpPlaneRotationMatrixMap(1, 2),
321 tmpPlaneRotationMatrixMap(2, 0),
322 tmpPlaneRotationMatrixMap(2, 1),
323 tmpPlaneRotationMatrixMap(2, 2));
325 maxGlobalPointDistance = tmpPlaneRotationMatrixMap * maxGlobalPointDistance;
327 double maximumXdistance = maxGlobalPointDistance[0] * maxGlobalPointDistance[0];
328 double maximumYdistance = maxGlobalPointDistance[1] * maxGlobalPointDistance[1];
330 double minimumDistance = 1. + maximumXdistance + maximumYdistance;
331 for (
const auto &
hit : (*hitMap_)[tmpPlaneId]) {
332 double xResidual =
hit.globalPoint.
x() - pointOnDet.
x();
333 double yResidual =
hit.globalPoint.
y() - pointOnDet.
y();
334 double xDistance = xResidual * xResidual;
335 double yDistance = yResidual * yResidual;
336 double distance = xDistance + yDistance;
337 if (xDistance < maximumXdistance && yDistance < maximumYdistance && distance < minimumDistance) {
338 LocalPoint residuals(xResidual, yResidual, 0.);
342 fittedRecHit->setIsRealHit(
true);
352 bestTrack.
addHit(tmpPlaneId, *fittedRecHit);
357 int pointForTracking = 0;
358 int pointOnTrack = 0;
361 for (
const auto &planeHits : bestTrack.
hits()) {
362 for (
const auto &fittedhit : planeHits) {
363 if (fittedhit.isUsedForFit())
365 if (fittedhit.isRealHit())
370 <<
"Best track has " << pointForTracking <<
" points used for the fit and " << pointOnTrack
371 <<
" points belonging to the track\n";
389 static const std::map<unsigned int, std::map<CTPPSPixelDetId, std::vector<bool> > > isPlaneShifted = {
392 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
393 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
397 {rpId_arm0_st2, {
true,
false,
true,
true,
false,
false}},
398 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
402 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
403 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
407 {rpId_arm0_st2, {
false,
true,
false,
true,
false,
true}},
408 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
412 {rpId_arm0_st2, {
false,
true,
false,
true,
false,
true}},
413 {rpId_arm1_st2, {
false,
false,
true,
false,
true,
true}}
417 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
418 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
420 const auto &shiftStatusInitialRun = std::prev(isPlaneShifted.upper_bound(run));
421 unsigned short shiftedROC = 10;
435 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Analyzing run: " << run <<
"\nTrack belongs to Arm " 440 unsigned short bxShiftedPlanesUsed = 0;
441 unsigned short bxNonShiftedPlanesUsed = 0;
442 unsigned short hitInShiftedROC = 0;
444 auto const &fittedHits =
track.hits();
445 auto const &planeFlags = (shiftStatusInitialRun->second).at(
romanPotId_);
447 for (
const auto &planeHits : fittedHits) {
449 for (
const auto &
hit : planeHits) {
450 if (
hit.isUsedForFit()) {
451 if (pixelIndices.
getROCId(
hit.minPixelCol(),
hit.minPixelRow()) == shiftedROC)
453 if (planeFlags.at(plane))
454 bxShiftedPlanesUsed++;
455 else if (planeFlags != std::vector<bool>(6,
false))
456 bxNonShiftedPlanesUsed++;
464 if (hitInShiftedROC < 3)
467 if (bxShiftedPlanesUsed == 0 && bxNonShiftedPlanesUsed == 0)
470 if (bxShiftedPlanesUsed == 3 && bxNonShiftedPlanesUsed == 0)
473 if (bxShiftedPlanesUsed == 0 && bxNonShiftedPlanesUsed == 3)
476 if (bxShiftedPlanesUsed > 0 && bxNonShiftedPlanesUsed > 0)
480 if (bxShiftedPlanesUsed + bxNonShiftedPlanesUsed > 6) {
481 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::findTracks -> " 482 <<
"More than six points found for a track, skipping.";
486 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::findTracks -> " 487 <<
"recoInfo has not been set properly.";
493 <<
"\nFirst run with this bx-shift configuration: " << shiftStatusInitialRun->first
494 <<
"\nTrack reconstructed with: " << bxShiftedPlanesUsed <<
" bx-shifted planes, " << bxNonShiftedPlanesUsed
495 <<
" non-bx-shifted planes, " << hitInShiftedROC <<
" hits in the bx-shifted ROC" 496 <<
"\nrecoInfo = " << (
unsigned short)
track.recoInfo();
497 if (planeFlags != std::vector<bool>(6,
false))
498 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"The shifted ROC is ROC" << shiftedROC;
507 uint32_t
const numberOfPlanes = 6;
513 for (uint32_t iHit = 0; iHit < numberOfPlanes; iHit++) {
514 if (iHit < pointList.size()) {
515 CLHEP::Hep3Vector globalPoint = pointList[iHit].globalPoint;
516 xyCoordinates[2 * iHit] = globalPoint.x();
517 xyCoordinates[2 * iHit + 1] = globalPoint.y();
518 zMatrix(2 * iHit, 0) = 1.;
519 zMatrix(2 * iHit, 2) = globalPoint.z() -
z0_;
520 zMatrix(2 * iHit + 1, 1) = 1.;
521 zMatrix(2 * iHit + 1, 3) = globalPoint.z() -
z0_;
524 varianceMatrix(2 * iHit, 2 * iHit) = globalError(0, 0);
525 varianceMatrix(2 * iHit, 2 * iHit + 1) = globalError(0, 1);
526 varianceMatrix(2 * iHit + 1, 2 * iHit) = globalError(1, 0);
527 varianceMatrix(2 * iHit + 1, 2 * iHit + 1) = globalError(1, 1);
529 varianceMatrix(2 * iHit, 2 * iHit) = 1.;
530 varianceMatrix(2 * iHit + 1, 2 * iHit + 1) = 1.;
535 if (!varianceMatrix.Invert()) {
536 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 537 <<
"Point variance matrix is singular, skipping.";
546 if (!covarianceMatrix.Invert()) {
547 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 548 <<
"Parameter covariance matrix is singular, skipping.";
556 ROOT::Math::Transpose(zMatrix) * varianceMatrix * xyCoordinates;
557 math::Vector<4>::type parameterVector = covarianceMatrix * zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates;
559 xyCoordinates - (zMatrix * parameterVector);
561 double chiSquare = ROOT::Math::Dot(xyCoordinatesMinusZmatrixTimesParameters,
562 (varianceMatrix * xyCoordinatesMinusZmatrixTimesParameters));
567 for (
const auto &
hit : pointList) {
568 CLHEP::Hep3Vector globalPoint =
hit.globalPoint;
576 double xResidual = globalPoint.x() - pointOnDet.
x();
577 double yResidual = globalPoint.y() - pointOnDet.
y();
585 goodTrack.
addHit(
hit.detId, fittedRecHit);
597 double z0 = track->
z0();
604 CLHEP::Hep3Vector tmpPointLocal(0., 0., 0.);
612 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0),
613 tmpPlaneRotationMatrixMap(0, 1),
614 tmpPlaneRotationMatrixMap(0, 2),
615 tmpPlaneRotationMatrixMap(1, 0),
616 tmpPlaneRotationMatrixMap(1, 1),
617 tmpPlaneRotationMatrixMap(1, 2),
618 tmpPlaneRotationMatrixMap(2, 0),
619 tmpPlaneRotationMatrixMap(2, 1),
620 tmpPlaneRotationMatrixMap(2, 2));
622 planeUnitVector = tmpPlaneRotationMatrixMap * planeUnitVector;
624 double denominator = ROOT::Math::Dot(lineUnitVector, planeUnitVector);
625 if (denominator == 0) {
627 <<
"Error in RPixPlaneCombinatoryTracking::calculatePointOnDetector -> " 628 <<
"Fitted line and plane are parallel. Removing this track";
632 double distanceFromLinePoint = ROOT::Math::Dot((pointOnPlane - pointOnLine), planeUnitVector) /
denominator;
635 planeLineIntercept =
GlobalPoint(tmpPlaneLineIntercept[0], tmpPlaneLineIntercept[1], tmpPlaneLineIntercept[2]);
642 std::vector<RPixPlaneCombinatoryTracking::PointAndReferencePair>
644 std::vector<PointAndReferencePair> sortedVector(inputMap.begin(), inputMap.end());
~RPixPlaneCombinatoryTracking() override
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
const ParameterVector & parameterVector() const
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
uint32_t factorial(uint32_t x) const
CTPPSpixelLocalTrackReconstructionInfo
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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)
const edm::DetSetVector< CTPPSPixelFittedRecHit > & hits() const
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
int getROCId(const int col, const int row) const
uint32_t numberOfPlanesPerPot_
std::map< CTPPSPixelDetId, std::vector< RPixDetPatternFinder::PointInPlane > > * hitMap_
void findTracks(int run) override
float chiSquaredOverNDF() const
void setIsUsedForFit(bool usedForFit)
CLHEP::Hep3Vector localToGlobal(const DetGeomDesc *, const CLHEP::Hep3Vector &) const
void addHit(unsigned int detId, const CTPPSPixelFittedRecHit &hit)
std::vector< uint32_t > listOfAllPlanes_
void setPlane(uint32_t pl)
RotationMatrix rotation() const
geometry information
ROOT::Math::SMatrix< double, N, M > type
uint32_t trackMinNumberOfPoints_
const DetGeomDesc * sensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
const CTPPSGeometry * geometry_
math::Vector< dimension >::type ParameterVector
covariance matrix size
PointAndReferenceMap produceAllHitCombination(PlaneCombinations inputPlaneCombination)
CTPPSPixelDetId romanPotId_
static bool functionForPlaneOrdering(PointAndReferencePair a, PointAndReferencePair b)
PlaneCombinations possiblePlaneCombinations_
GlobalVector directionVector() const
std::vector< std::vector< uint32_t > > PlaneCombinations
ROOT::Math::Rotation3D RotationMatrix
ParameterSet const & parameterSet(Provenance const &provenance)
*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 getPlaneCombinations(const std::vector< uint32_t > &inputPlaneList, uint32_t numberToExtract, PlaneCombinations &planeCombinations) const
void setValid(bool valid)