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 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Number of plane with hits " <<
hitMap_->size();
170 for (
const auto &plane : *
hitMap_)
172 <<
"\tarm " << plane.first.arm() <<
" station " << plane.first.station() <<
" rp " << plane.first.rp()
173 <<
" plane " << plane.first.plane() <<
" : " << plane.second.size();
189 <<
"Number of combinations of trackMinNumberOfPoints_ planes " << mapOfAllMinRequiredPoint.size();
190 for (
const auto &pointsAndRef : mapOfAllMinRequiredPoint) {
194 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"ChiSquare of the present track " << tmpChiSquaredOverNDF;
197 if (tmpChiSquaredOverNDF < theMinChiSquaredOverNDF) {
198 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
199 pointMapWithMinChiSquared = pointsAndRef.first;
200 pointsWithMinChiSquared = pointsAndRef.second;
201 bestTrack = tmpTrack;
211 std::vector<uint32_t> listOfExcludedPlanes;
216 if (pointMapWithMinChiSquared.find(planeDetId) == pointMapWithMinChiSquared.end())
217 listOfExcludedPlanes.push_back(plane);
223 for (uint32_t
i = 1;
i <= listOfExcludedPlanes.size(); ++
i) {
226 for (
const auto &combination : tmpPlaneCombination)
227 planePointedHitListCombination.push_back(combination);
235 for (
const auto &element : mapOfPointCombinationToBeAdded) {
238 for (
const auto &pointRef : element.first)
239 newPointMap[pointRef.first] = pointRef.second;
240 for (
const auto &
point : element.second)
241 newPoints.push_back(
point);
242 mapOfAllPointWithAtLeastBestFitSelected[newPointMap] = newPoints;
248 <<
"Minimum chiSquare over NDF for all the tracks " << theMinChiSquaredOverNDF;
252 std::vector<PointAndReferencePair> orderedVectorOfAllPointWithAtLeastBestFitSelected =
254 int currentNumberOfPlanes = 0;
256 bool foundTrackWithCurrentNumberOfPlanes =
false;
257 for (
const auto &pointsAndRef : orderedVectorOfAllPointWithAtLeastBestFitSelected) {
258 int tmpNumberOfPlanes = pointsAndRef.second.size();
260 if (foundTrackWithCurrentNumberOfPlanes && tmpNumberOfPlanes < currentNumberOfPlanes)
266 if (tmpChiSquaredOverNDF < theMinChiSquaredOverNDF) {
267 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
268 pointMapWithMinChiSquared = pointsAndRef.first;
269 bestTrack = tmpTrack;
270 currentNumberOfPlanes = tmpNumberOfPlanes;
271 foundTrackWithCurrentNumberOfPlanes =
true;
276 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"The best track has " << bestTrack.
ndf() / 2 + 2;
280 for (
const auto &hitToErase : pointMapWithMinChiSquared) {
281 std::map<CTPPSPixelDetId, PointInPlaneList>::iterator hitMapElement = hitMap_->find(hitToErase.first);
282 if (hitMapElement == hitMap_->end()) {
284 <<
"The found tracks has hit belonging to a plane which does not have hits";
286 std::vector<uint32_t>::iterator planeIt;
287 planeIt =
std::find(listOfPlaneNotUsedForFit.begin(), listOfPlaneNotUsedForFit.end(), hitToErase.first.plane());
288 listOfPlaneNotUsedForFit.erase(planeIt);
289 hitMapElement->second.erase(hitMapElement->second.begin() + hitToErase.second);
291 if (hitMapElement->second.empty())
292 hitMap_->erase(hitMapElement);
301 for (
const auto &plane : listOfPlaneNotUsedForFit) {
308 if (hitMap_->find(tmpPlaneId) != hitMap_->end()) {
316 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0),
317 tmpPlaneRotationMatrixMap(0, 1),
318 tmpPlaneRotationMatrixMap(0, 2),
319 tmpPlaneRotationMatrixMap(1, 0),
320 tmpPlaneRotationMatrixMap(1, 1),
321 tmpPlaneRotationMatrixMap(1, 2),
322 tmpPlaneRotationMatrixMap(2, 0),
323 tmpPlaneRotationMatrixMap(2, 1),
324 tmpPlaneRotationMatrixMap(2, 2));
326 maxGlobalPointDistance = tmpPlaneRotationMatrixMap * maxGlobalPointDistance;
328 double maximumXdistance = maxGlobalPointDistance[0] * maxGlobalPointDistance[0];
329 double maximumYdistance = maxGlobalPointDistance[1] * maxGlobalPointDistance[1];
331 double minimumDistance = 1. + maximumXdistance + maximumYdistance;
332 for (
const auto &
hit : (*hitMap_)[tmpPlaneId]) {
333 double xResidual =
hit.globalPoint.
x() - pointOnDet.
x();
334 double yResidual =
hit.globalPoint.
y() - pointOnDet.
y();
335 double xDistance = xResidual * xResidual;
336 double yDistance = yResidual * yResidual;
337 double distance = xDistance + yDistance;
338 if (xDistance < maximumXdistance && yDistance < maximumYdistance && distance < minimumDistance) {
339 LocalPoint residuals(xResidual, yResidual, 0.);
342 fittedRecHit = std::make_unique<CTPPSPixelFittedRecHit>(
hit.recHit, pointOnDet, residuals, pulls);
343 fittedRecHit->setIsRealHit(
true);
350 fittedRecHit = std::make_unique<CTPPSPixelFittedRecHit>(fakeRecHit, pointOnDet, fakePoint, fakePoint);
353 bestTrack.
addHit(tmpPlaneId, *fittedRecHit);
358 int pointForTracking = 0;
359 int pointOnTrack = 0;
362 for (
const auto &planeHits : bestTrack.
hits()) {
363 for (
const auto &fittedhit : planeHits) {
364 if (fittedhit.isUsedForFit())
366 if (fittedhit.isRealHit())
371 <<
"Best track has " << pointForTracking <<
" points used for the fit and " << pointOnTrack
372 <<
" points belonging to the track\n";
390 static const std::map<unsigned int, std::map<CTPPSPixelDetId, std::vector<bool> > > isPlaneShifted = {
393 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
394 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
398 {rpId_arm0_st2, {
true,
false,
true,
true,
false,
false}},
399 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
403 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
404 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
408 {rpId_arm0_st2, {
false,
true,
false,
true,
false,
true}},
409 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
413 {rpId_arm0_st2, {
false,
true,
false,
true,
false,
true}},
414 {rpId_arm1_st2, {
false,
false,
true,
false,
true,
true}}
418 {rpId_arm0_st2, {
false,
false,
false,
false,
false,
false}},
419 {rpId_arm1_st2, {
false,
false,
false,
false,
false,
false}}
421 const auto &shiftStatusInitialRun = std::prev(isPlaneShifted.upper_bound(run));
422 unsigned short shiftedROC = 10;
436 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"Analyzing run: " << run <<
"\nTrack belongs to Arm "
441 unsigned short bxShiftedPlanesUsed = 0;
442 unsigned short bxNonShiftedPlanesUsed = 0;
443 unsigned short hitInShiftedROC = 0;
445 auto const &fittedHits =
track.hits();
446 auto const &planeFlags = (shiftStatusInitialRun->second).at(
romanPotId_);
448 for (
const auto &planeHits : fittedHits) {
450 for (
const auto &
hit : planeHits) {
451 if (
hit.isUsedForFit()) {
452 if (pixelIndices.
getROCId(
hit.minPixelCol(),
hit.minPixelRow()) == shiftedROC)
454 if (planeFlags.at(plane))
455 bxShiftedPlanesUsed++;
456 else if (planeFlags != std::vector<bool>(6,
false))
457 bxNonShiftedPlanesUsed++;
465 if (hitInShiftedROC < 3)
468 if (bxShiftedPlanesUsed == 0 && bxNonShiftedPlanesUsed == 0)
471 if (bxShiftedPlanesUsed == 3 && bxNonShiftedPlanesUsed == 0)
474 if (bxShiftedPlanesUsed == 0 && bxNonShiftedPlanesUsed == 3)
477 if (bxShiftedPlanesUsed > 0 && bxNonShiftedPlanesUsed > 0)
481 if (bxShiftedPlanesUsed + bxNonShiftedPlanesUsed > 6) {
482 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::findTracks -> "
483 <<
"More than six points found for a track, skipping.";
487 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::findTracks -> "
488 <<
"recoInfo has not been set properly.";
494 <<
"\nFirst run with this bx-shift configuration: " << shiftStatusInitialRun->first
495 <<
"\nTrack reconstructed with: " << bxShiftedPlanesUsed <<
" bx-shifted planes, " << bxNonShiftedPlanesUsed
496 <<
" non-bx-shifted planes, " << hitInShiftedROC <<
" hits in the bx-shifted ROC"
497 <<
"\nrecoInfo = " << (
unsigned short)
track.recoInfo();
498 if (planeFlags != std::vector<bool>(6,
false))
499 edm::LogInfo(
"RPixPlaneCombinatoryTracking") <<
"The shifted ROC is ROC" << shiftedROC;
508 uint32_t
const numberOfPlanes = 6;
514 for (uint32_t iHit = 0; iHit < numberOfPlanes; iHit++) {
515 if (iHit < pointList.size()) {
516 const auto &globalPoint = pointList[iHit].globalPoint;
517 xyCoordinates[2 * iHit] = globalPoint.x();
518 xyCoordinates[2 * iHit + 1] = globalPoint.y();
519 zMatrix(2 * iHit, 0) = 1.;
520 zMatrix(2 * iHit, 2) = globalPoint.z() -
z0_;
521 zMatrix(2 * iHit + 1, 1) = 1.;
522 zMatrix(2 * iHit + 1, 3) = globalPoint.z() -
z0_;
525 varianceMatrix(2 * iHit, 2 * iHit) = globalError(0, 0);
526 varianceMatrix(2 * iHit, 2 * iHit + 1) = globalError(0, 1);
527 varianceMatrix(2 * iHit + 1, 2 * iHit) = globalError(1, 0);
528 varianceMatrix(2 * iHit + 1, 2 * iHit + 1) = globalError(1, 1);
530 varianceMatrix(2 * iHit, 2 * iHit) = 1.;
531 varianceMatrix(2 * iHit + 1, 2 * iHit + 1) = 1.;
536 if (!varianceMatrix.Invert()) {
537 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> "
538 <<
"Point variance matrix is singular, skipping.";
547 if (!covarianceMatrix.Invert()) {
548 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> "
549 <<
"Parameter covariance matrix is singular, skipping.";
557 ROOT::Math::Transpose(zMatrix) * varianceMatrix * xyCoordinates;
558 math::Vector<4>::type parameterVector = covarianceMatrix * zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates;
560 xyCoordinates - (zMatrix * parameterVector);
562 double chiSquare = ROOT::Math::Dot(xyCoordinatesMinusZmatrixTimesParameters,
563 (varianceMatrix * xyCoordinatesMinusZmatrixTimesParameters));
568 for (
const auto &
hit : pointList) {
569 const auto &globalPoint =
hit.globalPoint;
577 double xResidual = globalPoint.x() - pointOnDet.
x();
578 double yResidual = globalPoint.y() - pointOnDet.
y();
586 goodTrack.
addHit(
hit.detId, fittedRecHit);
598 double z0 = track->
z0();
613 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0),
614 tmpPlaneRotationMatrixMap(0, 1),
615 tmpPlaneRotationMatrixMap(0, 2),
616 tmpPlaneRotationMatrixMap(1, 0),
617 tmpPlaneRotationMatrixMap(1, 1),
618 tmpPlaneRotationMatrixMap(1, 2),
619 tmpPlaneRotationMatrixMap(2, 0),
620 tmpPlaneRotationMatrixMap(2, 1),
621 tmpPlaneRotationMatrixMap(2, 2));
623 planeUnitVector = tmpPlaneRotationMatrixMap * planeUnitVector;
625 double denominator = ROOT::Math::Dot(lineUnitVector, planeUnitVector);
626 if (denominator == 0) {
628 <<
"Error in RPixPlaneCombinatoryTracking::calculatePointOnDetector -> "
629 <<
"Fitted line and plane are parallel. Removing this track";
633 double distanceFromLinePoint = ROOT::Math::Dot((pointOnPlane - pointOnLine), planeUnitVector) /
denominator;
636 planeLineIntercept =
GlobalPoint(tmpPlaneLineIntercept[0], tmpPlaneLineIntercept[1], tmpPlaneLineIntercept[2]);
643 std::vector<RPixPlaneCombinatoryTracking::PointAndReferencePair>
645 std::vector<PointAndReferencePair> sortedVector(inputMap.begin(), inputMap.end());
~RPixPlaneCombinatoryTracking() override
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
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
DetGeomDesc::Translation Vector
Vector localToGlobal(const DetGeomDesc *, const Vector &) 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)
const edm::DetSetVector< CTPPSPixelFittedRecHit > & hits() const
CTPPSPixelLocalTrack fitTrack(PointInPlaneList pointList)
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
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)
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_
const DetGeomDesc * sensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
T getParameter(std::string const &) const
const CTPPSGeometry * geometry_
math::Vector< dimension >::type ParameterVector
covariance matrix size
PointAndReferenceMap produceAllHitCombination(PlaneCombinations inputPlaneCombination)
CTPPSPixelDetId romanPotId_
static bool functionForPlaneOrdering(PointAndReferencePair a, PointAndReferencePair b)
const RotationMatrix & rotation() const
PlaneCombinations possiblePlaneCombinations_
GlobalVector directionVector() const
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 getPlaneCombinations(const std::vector< uint32_t > &inputPlaneList, uint32_t numberToExtract, PlaneCombinations &planeCombinations) const
void setValid(bool valid)