27 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Minimum number of planes required for tracking is 3, " 28 <<
"tracking is not possible with " 46 if(
verbosity_>=2)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Number of combinations = "<<numberOfCombinations;
53 for(
const auto &
num : vec){
66 uint32_t numberOfPlanes = inputPlaneList.size();
68 bitmask.resize(numberOfPlanes, 0);
69 planeCombinations.clear();
73 planeCombinations.push_back(std::vector<uint32_t>());
74 for (uint32_t
i = 0;
i < numberOfPlanes; ++
i) {
75 if (bitmask[
i]) planeCombinations.back().push_back(inputPlaneList.at(i));
77 }
while (std::prev_permutation(bitmask.begin(), bitmask.end()));
90 const std::map<CTPPSPixelDetId, PointInPlaneList > &mapOfAllHits,
91 std::map<CTPPSPixelDetId, PointInPlaneList >::iterator mapIterator,
97 if (mapIterator == mapOfAllHits.end())
99 outputMap[tmpHitPlaneMap] = tmpHitVector;
102 for (
size_t i=0;
i<mapIterator->second.size();
i++){
104 newHitPlaneMap[mapIterator->first] =
i;
106 newVector.push_back(mapIterator->second[
i]);
107 std::map<CTPPSPixelDetId, PointInPlaneList >::iterator tmpMapIterator = mapIterator;
108 getHitCombinations(mapOfAllHits, ++tmpMapIterator, newHitPlaneMap, newVector, outputMap);
122 for(
const auto & planeCombination : inputPlaneCombination){
124 std::map<CTPPSPixelDetId, PointInPlaneList > selectedCombinationHitOnPlane;
125 bool allPlaneAsHits =
true;
130 for(
const auto & plane : planeCombination){
135 <<
" rp " <<planeDetId.
rp()<<
" plane "<<planeDetId.
plane();
136 allPlaneAsHits =
false;
139 if(selectedCombinationHitOnPlane.find(planeDetId)!=selectedCombinationHitOnPlane.end()){
141 <<
"selectedCombinationHitOnPlane contains already detId "<<planeDetId
142 <<
"Error in the algorithm which created all the possible plane combinations";
144 selectedCombinationHitOnPlane[planeDetId] = (*hitMap_)[planeDetId];
146 if(!allPlaneAsHits)
continue;
149 auto mapIterator=selectedCombinationHitOnPlane.begin();
152 getHitCombinations(selectedCombinationHitOnPlane,mapIterator,tmpHitPlaneMap,tmpHitVector,mapOfAllPoints);
153 if(
verbosity_>=2)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Number of possible tracks "<<mapOfAllPoints.size();
157 return mapOfAllPoints;
173 <<
" station "<<plane.first.station()
174 <<
" rp " <<plane.first.rp()
175 <<
" plane "<<plane.first.plane()
176 <<
" : "<<plane.second.size();
190 if(
verbosity_>=2)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Number of combinations of trackMinNumberOfPoints_ planes " 191 <<mapOfAllMinRequiredPoint.size();
192 for(
const auto & pointsAndRef : mapOfAllMinRequiredPoint){
195 if(
verbosity_>=2)
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;
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) planePointedHitListCombination.push_back(combination);
233 for(
const auto & element : mapOfPointCombinationToBeAdded){
236 for(
const auto & pointRef : element.first ) newPointMap[pointRef.first] = pointRef.second;
237 for(
const auto &
point : element.second) newPoints.push_back(
point);
238 mapOfAllPointWithAtLeastBestFitSelected[newPointMap]=newPoints;
242 if(
verbosity_>=1)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Minimum chiSquare over NDF for all the tracks "<<theMinChiSquaredOverNDF;
246 std::vector<PointAndReferencePair > orderedVectorOfAllPointWithAtLeastBestFitSelected =
248 int currentNumberOfPlanes = 0;
250 bool foundTrackWithCurrentNumberOfPlanes =
false;
251 for(
const auto & pointsAndRef : orderedVectorOfAllPointWithAtLeastBestFitSelected){
252 int tmpNumberOfPlanes = pointsAndRef.second.size();
254 if(foundTrackWithCurrentNumberOfPlanes && tmpNumberOfPlanes<currentNumberOfPlanes)
break;
258 if(tmpChiSquaredOverNDF<theMinChiSquaredOverNDF){
259 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
260 pointMapWithMinChiSquared = pointsAndRef.first;
261 bestTrack = tmpTrack;
262 currentNumberOfPlanes = tmpNumberOfPlanes;
263 foundTrackWithCurrentNumberOfPlanes =
true;
271 for(
const auto & hitToErase : pointMapWithMinChiSquared){
272 std::map<CTPPSPixelDetId, PointInPlaneList >::iterator hitMapElement = hitMap_->find(hitToErase.first);
273 if(hitMapElement==hitMap_->end()){
275 <<
"The found tracks has hit belonging to a plane which does not have hits";
277 std::vector<uint32_t>::iterator planeIt;
278 planeIt =
std::find (listOfPlaneNotUsedForFit.begin(), listOfPlaneNotUsedForFit.end(), hitToErase.first.plane());
279 listOfPlaneNotUsedForFit.erase(planeIt);
280 hitMapElement->second.erase(hitMapElement->second.begin()+hitToErase.second);
282 if(hitMapElement->second.empty()) hitMap_->erase(hitMapElement);
291 for(
const auto & plane : listOfPlaneNotUsedForFit){
294 std::unique_ptr<CTPPSPixelFittedRecHit>
300 if(hitMap_->find(tmpPlaneId) != hitMap_->end()){
307 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0), tmpPlaneRotationMatrixMap(0, 1), tmpPlaneRotationMatrixMap(0, 2),
308 tmpPlaneRotationMatrixMap(1, 0), tmpPlaneRotationMatrixMap(1, 1), tmpPlaneRotationMatrixMap(1, 2),
309 tmpPlaneRotationMatrixMap(2, 0), tmpPlaneRotationMatrixMap(2, 1), tmpPlaneRotationMatrixMap(2, 2));
311 maxGlobalPointDistance = tmpPlaneRotationMatrixMap * maxGlobalPointDistance;
313 double maximumXdistance = maxGlobalPointDistance[0]*maxGlobalPointDistance[0];
314 double maximumYdistance = maxGlobalPointDistance[1]*maxGlobalPointDistance[1];
315 double minimumDistance = 1. + maximumXdistance + maximumYdistance;
316 for(
const auto &
hit : (*hitMap_)[tmpPlaneId]){
317 double xResidual =
hit.globalPoint.
x() - pointOnDet.
x();
318 double yResidual =
hit.globalPoint.
y() - pointOnDet.
y();
319 double xDistance = xResidual*xResidual;
320 double yDistance = yResidual*yResidual;
321 double distance = xDistance + yDistance;
322 if(xDistance < maximumXdistance && yDistance < maximumYdistance && distance < minimumDistance){
327 fittedRecHit->setIsRealHit(
true);
338 bestTrack.
addHit(tmpPlaneId, *fittedRecHit);
344 int pointForTracking = 0;
345 int pointOnTrack = 0;
348 for(
const auto & planeHits : bestTrack.
getHits()){
349 for(
const auto & fittedhit : planeHits){
350 if(fittedhit.getIsUsedForFit()) ++pointForTracking;
351 if(fittedhit.getIsRealHit()) ++pointOnTrack;
354 edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Best track has "<<pointForTracking<<
" points used for the fit and " 355 << pointOnTrack<<
" points belonging to the track\n";
376 static const std::map< unsigned int, std::map< CTPPSPixelDetId,std::vector<bool> > > isPlaneShifted =
380 {rpId_arm0_st2,{
false,
false,
false,
false,
false,
false}},
381 {rpId_arm1_st2,{
false,
false,
false,
false,
false,
false}}
386 {rpId_arm0_st2,{
true,
false,
true,
true,
false,
false}},
387 {rpId_arm1_st2,{
false,
false,
false,
false,
false,
false}}
392 {rpId_arm0_st2,{
false,
false,
false,
false,
false,
false}},
393 {rpId_arm1_st2,{
false,
false,
false,
false,
false,
false}}
398 {rpId_arm0_st2,{
false,
true,
false,
true,
false,
true}},
399 {rpId_arm1_st2,{
false,
false,
false,
false,
false,
false}}
404 {rpId_arm0_st2,{
false,
true,
false,
true,
false,
true}},
405 {rpId_arm1_st2,{
false,
false,
true,
false,
true,
true}}
410 {rpId_arm0_st2,{
false,
false,
false,
false,
false,
false}},
411 {rpId_arm1_st2,{
false,
false,
false,
false,
false,
false}}
415 const auto& shiftStatusInitialRun = std::prev(isPlaneShifted.upper_bound(run));
416 unsigned short shiftedROC = 10;
433 unsigned short bxShiftedPlanesUsed = 0;
434 unsigned short bxNonShiftedPlanesUsed = 0;
435 unsigned short hitInShiftedROC = 0;
437 auto const& fittedHits =
track.getHits();
438 auto const& planeFlags = (shiftStatusInitialRun->second).at(
romanPotId_);
440 for(
const auto & planeHits : fittedHits){
442 for(
const auto &
hit : planeHits){
443 if(
hit.getIsUsedForFit()){
444 if(pixelIndices.
getROCId(
hit.minPixelCol(),
hit.minPixelRow()) == shiftedROC) hitInShiftedROC++;
445 if(planeFlags.at(plane)) bxShiftedPlanesUsed++;
446 else if(planeFlags != std::vector<bool>(6,
false)) bxNonShiftedPlanesUsed++;
460 if(bxShiftedPlanesUsed + bxNonShiftedPlanesUsed > 6){
461 throw cms::Exception(
"RPixPlaneCombinatoryTracking")<<
"Error in RPixPlaneCombinatoryTracking::findTracks -> " <<
"More than six points found for a track, skipping.";
465 throw cms::Exception(
"RPixPlaneCombinatoryTracking")<<
"Error in RPixPlaneCombinatoryTracking::findTracks -> " <<
"recoInfo has not been set properly.";
470 << shiftStatusInitialRun->first<<
"\nTrack reconstructed with: "<<bxShiftedPlanesUsed<<
" bx-shifted planes, "<<bxNonShiftedPlanesUsed<<
" non-bx-shifted planes, "<<hitInShiftedROC
471 <<
" hits in the bx-shifted ROC"<<
"\nrecoInfo = "<<(
unsigned short)
track.getRecoInfo();
472 if(planeFlags != std::vector<bool>(6,
false))
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"The shifted ROC is ROC"<<shiftedROC;
483 uint32_t
const numberOfPlanes = 6;
489 for(uint32_t iHit = 0; iHit < numberOfPlanes; iHit++) {
490 if (iHit < pointList.size()) {
491 CLHEP::Hep3Vector globalPoint = pointList[iHit].globalPoint;
492 xyCoordinates[2*iHit] = globalPoint.x() ;
493 xyCoordinates[2*iHit + 1] = globalPoint.y() ;
494 zMatrix (2*iHit, 0) = 1. ;
495 zMatrix (2*iHit, 2) = globalPoint.z()-
z0_;
496 zMatrix (2*iHit + 1, 1) = 1. ;
497 zMatrix (2*iHit+ 1 , 3) = globalPoint.z()-
z0_;
500 varianceMatrix(2*iHit, 2*iHit) = globalError(0, 0);
501 varianceMatrix(2*iHit, 2*iHit + 1) = globalError(0, 1);
502 varianceMatrix(2*iHit + 1, 2*iHit) = globalError(1, 0);
503 varianceMatrix(2*iHit + 1, 2*iHit + 1) = globalError(1, 1);
505 varianceMatrix(2*iHit, 2*iHit) = 1.;
506 varianceMatrix(2*iHit + 1, 2*iHit + 1) = 1.;
511 if (!varianceMatrix.Invert()) {
512 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 513 <<
"Point variance matrix is singular, skipping.";
522 if (!covarianceMatrix.Invert()) {
523 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 524 <<
"Parameter covariance matrix is singular, skipping.";
532 ROOT::Math::Transpose(zMatrix) * varianceMatrix * xyCoordinates;
534 covarianceMatrix * zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates;
536 xyCoordinates - (zMatrix * parameterVector);
539 ROOT::Math::Dot(xyCoordinatesMinusZmatrixTimesParameters, (varianceMatrix * xyCoordinatesMinusZmatrixTimesParameters));
544 for(
const auto &
hit : pointList){
545 CLHEP::Hep3Vector globalPoint =
hit.globalPoint;
553 double xResidual = globalPoint.x() - pointOnDet.
x();
554 double yResidual = globalPoint.y() - pointOnDet.
y();
562 goodTrack.
addHit(
hit.detId, fittedRecHit);
575 double z0 = track->
getZ0();
582 CLHEP::Hep3Vector tmpPointLocal(0.,0.,0.);
590 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0), tmpPlaneRotationMatrixMap(0, 1), tmpPlaneRotationMatrixMap(0, 2),
591 tmpPlaneRotationMatrixMap(1, 0), tmpPlaneRotationMatrixMap(1, 1), tmpPlaneRotationMatrixMap(1, 2),
592 tmpPlaneRotationMatrixMap(2, 0), tmpPlaneRotationMatrixMap(2, 1), tmpPlaneRotationMatrixMap(2, 2));
594 planeUnitVector = tmpPlaneRotationMatrixMap * planeUnitVector;
596 double denominator = ROOT::Math::Dot(lineUnitVector, planeUnitVector);
599 <<
"Error in RPixPlaneCombinatoryTracking::calculatePointOnDetector -> " 600 <<
"Fitted line and plane are parallel. Removing this track";
604 double distanceFromLinePoint = ROOT::Math::Dot((pointOnPlane - pointOnLine), planeUnitVector) /
denominator;
607 planeLineIntercept =
GlobalPoint(tmpPlaneLineIntercept[0], tmpPlaneLineIntercept[1], tmpPlaneLineIntercept[2]);
615 std::vector<RPixPlaneCombinatoryTracking::PointAndReferencePair >
619 std::vector<PointAndReferencePair > sortedVector(inputMap.begin(),inputMap.end());
~RPixPlaneCombinatoryTracking() override
T getParameter(std::string const &) const
std::map< HitReferences, PointInPlaneList > PointAndReferenceMap
T getUntrackedParameter(std::string const &, T const &) const
ROOT::Math::SMatrix< double, N, M > type
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
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< CTPPSPixelLocalTrack > localTrackVector_
double maximumXLocalDistanceFromTrack_
void getHitCombinations(const std::map< CTPPSPixelDetId, PointInPlaneList > &mapOfAllHits, std::map< CTPPSPixelDetId, PointInPlaneList >::iterator mapIterator, HitReferences tmpHitPlaneMap, const PointInPlaneList &tmpHitVector, PointAndReferenceMap &outputMap)
const DetGeomDesc * getSensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
CTPPSPixelLocalTrack fitTrack(PointInPlaneList pointList)
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
std::vector< RPixDetPatternFinder::PointInPlane > PointInPlaneList
float getChiSquaredOverNDF() const
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
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)
const edm::DetSetVector< CTPPSPixelFittedRecHit > & getHits() const
RotationMatrix rotation() const
geometry information
uint32_t trackMinNumberOfPoints_
const CTPPSGeometry * geometry_
math::Vector< dimension >::type ParameterVector
covariance matrix size
PointAndReferenceMap produceAllHitCombination(PlaneCombinations inputPlaneCombination)
GlobalVector getDirectionVector() const
const ParameterVector & getParameterVector() const
CTPPSPixelDetId romanPotId_
static bool functionForPlaneOrdering(PointAndReferencePair a, PointAndReferencePair b)
PlaneCombinations possiblePlaneCombinations_
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
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
void getPlaneCombinations(const std::vector< uint32_t > &inputPlaneList, uint32_t numberToExtract, PlaneCombinations &planeCombinations) const
void setValid(bool valid)