25 throw cms::Exception(
"RPixPlaneCombinatoryTracking") <<
"Minimum number of planes required for tracking is 3, " 26 <<
"tracking is not possible with " 46 if(
verbosity_>=2)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Number of combinations = "<<numberOfCombinations;
53 for(
const auto &
num : vec){
67 uint32_t numberOfPlanes = inputPlaneList.size();
69 bitmask.resize(numberOfPlanes, 0);
70 planeCombinations.clear();
74 planeCombinations.push_back(std::vector<uint32_t>());
75 for (uint32_t
i = 0;
i < numberOfPlanes; ++
i) {
76 if (bitmask[
i]) planeCombinations.back().push_back(inputPlaneList.at(i));
78 }
while (std::prev_permutation(bitmask.begin(), bitmask.end()));
91 const std::map<CTPPSPixelDetId, PointInPlaneList > &mapOfAllHits,
92 std::map<CTPPSPixelDetId, PointInPlaneList >::iterator mapIterator,
98 if (mapIterator == mapOfAllHits.end())
100 outputMap[tmpHitPlaneMap] = tmpHitVector;
103 for (
size_t i=0;
i<mapIterator->second.size();
i++){
105 newHitPlaneMap[mapIterator->first] =
i;
107 newVector.push_back(mapIterator->second[
i]);
108 std::map<CTPPSPixelDetId, PointInPlaneList >::iterator tmpMapIterator = mapIterator;
109 getHitCombinations(mapOfAllHits, ++tmpMapIterator, newHitPlaneMap, newVector, outputMap);
123 for(
const auto & planeCombination : inputPlaneCombination){
125 std::map<CTPPSPixelDetId, PointInPlaneList > selectedCombinationHitOnPlane;
126 bool allPlaneAsHits =
true;
131 for(
const auto & plane : planeCombination){
136 <<
" rp " <<planeDetId.
rp()<<
" plane "<<planeDetId.
plane();
137 allPlaneAsHits =
false;
140 if(selectedCombinationHitOnPlane.find(planeDetId)!=selectedCombinationHitOnPlane.end()){
142 <<
"selectedCombinationHitOnPlane contains already detId "<<planeDetId
143 <<
"Error in the algorithm which created all the possible plane combinations";
145 selectedCombinationHitOnPlane[planeDetId] = (*hitMap_)[planeDetId];
147 if(!allPlaneAsHits)
continue;
150 auto mapIterator=selectedCombinationHitOnPlane.begin();
153 getHitCombinations(selectedCombinationHitOnPlane,mapIterator,tmpHitPlaneMap,tmpHitVector,mapOfAllPoints);
154 if(
verbosity_>2)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Number of possible tracks "<<mapOfAllPoints.size();
158 return mapOfAllPoints;
174 <<
" station "<<plane.first.station()
175 <<
" rp " <<plane.first.rp()
176 <<
" plane "<<plane.first.plane()
177 <<
" : "<<plane.second.size();
191 if(
verbosity_>2)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Number of combinations of trackMinNumberOfPoints_ planes " 192 <<mapOfAllMinRequiredPoint.size();
193 for(
const auto & pointsAndRef : mapOfAllMinRequiredPoint){
196 if(
verbosity_>=2)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"ChiSquare of the present track "<<tmpChiSquaredOverNDF;
198 if(tmpChiSquaredOverNDF<theMinChiSquaredOverNDF){
199 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
200 pointMapWithMinChiSquared = pointsAndRef.first;
201 pointsWithMinChiSquared = pointsAndRef.second;
202 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) planePointedHitListCombination.push_back(combination);
234 for(
const auto & element : mapOfPointCombinationToBeAdded){
237 for(
const auto & pointRef : element.first ) newPointMap[pointRef.first] = pointRef.second;
238 for(
const auto &
point : element.second) newPoints.push_back(
point);
239 mapOfAllPointWithAtLeastBestFitSelected[newPointMap]=newPoints;
243 if(
verbosity_>=1)
edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Minimum chiSquare over NDF for all the tracks "<<theMinChiSquaredOverNDF;
247 std::vector<PointAndReferencePair > orderedVectorOfAllPointWithAtLeastBestFitSelected =
249 int currentNumberOfPlanes = 0;
251 bool foundTrackWithCurrentNumberOfPlanes =
false;
252 for(
const auto & pointsAndRef : orderedVectorOfAllPointWithAtLeastBestFitSelected){
253 int tmpNumberOfPlanes = pointsAndRef.second.size();
255 if(foundTrackWithCurrentNumberOfPlanes && tmpNumberOfPlanes<currentNumberOfPlanes)
break;
259 if(tmpChiSquaredOverNDF<theMinChiSquaredOverNDF){
260 theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
261 pointMapWithMinChiSquared = pointsAndRef.first;
262 bestTrack = tmpTrack;
263 currentNumberOfPlanes = tmpNumberOfPlanes;
264 foundTrackWithCurrentNumberOfPlanes =
true;
272 for(
const auto & hitToErase : pointMapWithMinChiSquared){
273 std::map<CTPPSPixelDetId, PointInPlaneList >::iterator hitMapElement = hitMap_->find(hitToErase.first);
274 if(hitMapElement==hitMap_->end()){
276 <<
"The found tracks has hit belonging to a plane which does not have hits";
278 std::vector<uint32_t>::iterator planeIt;
279 planeIt =
std::find (listOfPlaneNotUsedForFit.begin(), listOfPlaneNotUsedForFit.end(), hitToErase.first.plane());
280 listOfPlaneNotUsedForFit.erase(planeIt);
281 hitMapElement->second.erase(hitMapElement->second.begin()+hitToErase.second);
283 if(hitMapElement->second.empty()) hitMap_->erase(hitMapElement);
292 for(
const auto & plane : listOfPlaneNotUsedForFit){
295 std::unique_ptr<CTPPSPixelFittedRecHit>
301 if(hitMap_->find(tmpPlaneId) != hitMap_->end()){
308 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0), tmpPlaneRotationMatrixMap(0, 1), tmpPlaneRotationMatrixMap(0, 2),
309 tmpPlaneRotationMatrixMap(1, 0), tmpPlaneRotationMatrixMap(1, 1), tmpPlaneRotationMatrixMap(1, 2),
310 tmpPlaneRotationMatrixMap(2, 0), tmpPlaneRotationMatrixMap(2, 1), tmpPlaneRotationMatrixMap(2, 2));
312 maxGlobalPointDistance = tmpPlaneRotationMatrixMap * maxGlobalPointDistance;
314 double maximumXdistance = maxGlobalPointDistance[0]*maxGlobalPointDistance[0];
315 double maximumYdistance = maxGlobalPointDistance[1]*maxGlobalPointDistance[1];
316 double minimumDistance = 1. + maximumXdistance + maximumYdistance;
317 for(
const auto &
hit : (*hitMap_)[tmpPlaneId]){
318 double xResidual =
hit.globalPoint.
x() - pointOnDet.
x();
319 double yResidual =
hit.globalPoint.
y() - pointOnDet.
y();
320 double xDistance = xResidual*xResidual;
321 double yDistance = yResidual*yResidual;
322 double distance = xDistance + yDistance;
323 if(xDistance < maximumXdistance && yDistance < maximumYdistance && distance < minimumDistance){
328 fittedRecHit->setIsRealHit(
true);
339 bestTrack.
addHit(tmpPlaneId, *fittedRecHit);
345 int pointForTracking = 0;
346 int pointOnTrack = 0;
349 for(
const auto & planeHits : bestTrack.
getHits()){
350 for(
const auto & fittedhit : planeHits){
351 if(fittedhit.getIsUsedForFit()) ++pointForTracking;
352 if(fittedhit.getIsRealHit()) ++pointOnTrack;
355 edm::LogInfo(
"RPixPlaneCombinatoryTracking")<<
"Best track has "<<pointForTracking<<
" points used for the fit and " 356 << pointOnTrack<<
" points belonging to the track\n";
369 uint32_t
const numberOfPlanes = 6;
375 for(uint32_t iHit = 0; iHit < numberOfPlanes; iHit++) {
376 if (iHit < pointList.size()) {
377 CLHEP::Hep3Vector globalPoint = pointList[iHit].globalPoint;
378 xyCoordinates[2*iHit] = globalPoint.x() ;
379 xyCoordinates[2*iHit + 1] = globalPoint.y() ;
380 zMatrix (2*iHit, 0) = 1. ;
381 zMatrix (2*iHit, 2) = globalPoint.z()-
z0_;
382 zMatrix (2*iHit + 1, 1) = 1. ;
383 zMatrix (2*iHit+ 1 , 3) = globalPoint.z()-
z0_;
386 varianceMatrix(2*iHit, 2*iHit) = globalError(0, 0);
387 varianceMatrix(2*iHit, 2*iHit + 1) = globalError(0, 1);
388 varianceMatrix(2*iHit + 1, 2*iHit) = globalError(1, 0);
389 varianceMatrix(2*iHit + 1, 2*iHit + 1) = globalError(1, 1);
391 varianceMatrix(2*iHit, 2*iHit) = 1.;
392 varianceMatrix(2*iHit + 1, 2*iHit + 1) = 1.;
397 if (!varianceMatrix.Invert()) {
398 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 399 <<
"Point variance matrix is singular, skipping.";
408 if (!covarianceMatrix.Invert()) {
409 edm::LogError(
"RPixPlaneCombinatoryTracking") <<
"Error in RPixPlaneCombinatoryTracking::fitTrack -> " 410 <<
"Parameter covariance matrix is singular, skipping.";
418 ROOT::Math::Transpose(zMatrix) * varianceMatrix * xyCoordinates;
420 covarianceMatrix * zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates;
422 xyCoordinates - (zMatrix * parameterVector);
425 ROOT::Math::Dot(xyCoordinatesMinusZmatrixTimesParameters, (varianceMatrix * xyCoordinatesMinusZmatrixTimesParameters));
430 for(
const auto &
hit : pointList){
431 CLHEP::Hep3Vector globalPoint =
hit.globalPoint;
439 double xResidual = globalPoint.x() - pointOnDet.
x();
440 double yResidual = globalPoint.y() - pointOnDet.
y();
448 goodTrack.
addHit(
hit.detId, fittedRecHit);
460 double z0 = track->
getZ0();
467 CLHEP::Hep3Vector tmpPointLocal(0.,0.,0.);
475 theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0), tmpPlaneRotationMatrixMap(0, 1), tmpPlaneRotationMatrixMap(0, 2),
476 tmpPlaneRotationMatrixMap(1, 0), tmpPlaneRotationMatrixMap(1, 1), tmpPlaneRotationMatrixMap(1, 2),
477 tmpPlaneRotationMatrixMap(2, 0), tmpPlaneRotationMatrixMap(2, 1), tmpPlaneRotationMatrixMap(2, 2));
479 planeUnitVector = tmpPlaneRotationMatrixMap * planeUnitVector;
481 double denominator = ROOT::Math::Dot(lineUnitVector, planeUnitVector);
484 <<
"Error in RPixPlaneCombinatoryTracking::calculatePointOnDetector -> " 485 <<
"Fitted line and plane are parallel. Removing this track";
489 double distanceFromLinePoint = ROOT::Math::Dot((pointOnPlane - pointOnLine), planeUnitVector) /
denominator;
492 planeLineIntercept =
GlobalPoint(tmpPlaneLineIntercept[0], tmpPlaneLineIntercept[1], tmpPlaneLineIntercept[2]);
500 std::vector<RPixPlaneCombinatoryTracking::PointAndReferencePair >
504 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
DDRotationMatrix rotation() const
geometry information
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
uint32_t numberOfPlanesPerPot_
std::map< CTPPSPixelDetId, std::vector< RPixDetPatternFinder::PointInPlane > > * hitMap_
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
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
void findTracks() override
CTPPSPixelDetId romanPotId_
static bool functionForPlaneOrdering(PointAndReferencePair a, PointAndReferencePair b)
PlaneCombinations possiblePlaneCombinations_
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
std::vector< std::vector< uint32_t > > PlaneCombinations
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)