CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
RPixPlaneCombinatoryTracking Class Reference

#include <RPixPlaneCombinatoryTracking.h>

Inheritance diagram for RPixPlaneCombinatoryTracking:
RPixDetTrackFinder

Public Member Functions

void findTracks () override
 
void initialize () override
 
 RPixPlaneCombinatoryTracking (edm::ParameterSet const &parameterSet)
 
 ~RPixPlaneCombinatoryTracking () override
 
- Public Member Functions inherited from RPixDetTrackFinder
void clear ()
 
std::vector< CTPPSPixelLocalTrack > const & getLocalTracks () const
 
 RPixDetTrackFinder (edm::ParameterSet const &parameterSet)
 
void setGeometry (const CTPPSGeometry *geometry)
 
void setHits (std::map< CTPPSPixelDetId, std::vector< RPixDetPatternFinder::PointInPlane > > *hitMap)
 
void setListOfPlanes (std::vector< uint32_t > listOfAllPlanes)
 
void setRomanPotId (CTPPSPixelDetId rpId)
 
void setZ0 (double z0)
 
virtual ~RPixDetTrackFinder ()
 

Private Types

typedef std::map< CTPPSPixelDetId, size_t > HitReferences
 
typedef std::vector< std::vector< uint32_t > > PlaneCombinations
 
typedef std::map< HitReferences, PointInPlaneListPointAndReferenceMap
 
typedef std::pair< HitReferences, PointInPlaneListPointAndReferencePair
 
typedef std::vector< RPixDetPatternFinder::PointInPlanePointInPlaneList
 

Private Member Functions

bool calculatePointOnDetector (CTPPSPixelLocalTrack *track, CTPPSPixelDetId planeId, GlobalPoint &planeLineIntercept)
 
uint32_t factorial (uint32_t x) const
 
CTPPSPixelLocalTrack fitTrack (PointInPlaneList pointList)
 
void getHitCombinations (const std::map< CTPPSPixelDetId, PointInPlaneList > &mapOfAllHits, std::map< CTPPSPixelDetId, PointInPlaneList >::iterator mapIterator, HitReferences tmpHitPlaneMap, const PointInPlaneList &tmpHitVector, PointAndReferenceMap &outputMap)
 
void getPlaneCombinations (const std::vector< uint32_t > &inputPlaneList, uint32_t numberToExtract, PlaneCombinations &planeCombinations) const
 
std::vector< PointAndReferencePairorderCombinationsPerNumberOrPoints (PointAndReferenceMap inputMap)
 
PointAndReferenceMap produceAllHitCombination (PlaneCombinations inputPlaneCombination)
 

Static Private Member Functions

static bool functionForPlaneOrdering (PointAndReferencePair a, PointAndReferencePair b)
 

Private Attributes

double maximumChi2OverNDF_
 
double maximumXLocalDistanceFromTrack_
 
double maximumYLocalDistanceFromTrack_
 
PlaneCombinations possiblePlaneCombinations_
 
uint32_t trackMinNumberOfPoints_
 
int verbosity_
 

Additional Inherited Members

- Protected Attributes inherited from RPixDetTrackFinder
const CTPPSGeometrygeometry_
 
std::map< CTPPSPixelDetId, std::vector< RPixDetPatternFinder::PointInPlane > > * hitMap_
 
std::vector< uint32_t > listOfAllPlanes_
 
std::vector< CTPPSPixelLocalTracklocalTrackVector_
 
uint32_t numberOfPlanesPerPot_
 
CTPPSPixelDetId romanPotId_
 
double z0_
 

Detailed Description

Definition at line 24 of file RPixPlaneCombinatoryTracking.h.

Member Typedef Documentation

Definition at line 35 of file RPixPlaneCombinatoryTracking.h.

typedef std::vector<std::vector<uint32_t> > RPixPlaneCombinatoryTracking::PlaneCombinations
private

Definition at line 33 of file RPixPlaneCombinatoryTracking.h.

Definition at line 36 of file RPixPlaneCombinatoryTracking.h.

Definition at line 37 of file RPixPlaneCombinatoryTracking.h.

Definition at line 34 of file RPixPlaneCombinatoryTracking.h.

Constructor & Destructor Documentation

RPixPlaneCombinatoryTracking::RPixPlaneCombinatoryTracking ( edm::ParameterSet const &  parameterSet)

Definition at line 14 of file RPixPlaneCombinatoryTracking.cc.

References Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), maximumChi2OverNDF_, maximumXLocalDistanceFromTrack_, maximumYLocalDistanceFromTrack_, RPixDetTrackFinder::numberOfPlanesPerPot_, trackMinNumberOfPoints_, parallelization::uint(), and verbosity_.

14  :
16 
17  trackMinNumberOfPoints_ = parameterSet.getParameter<uint>("trackMinNumberOfPoints");
18  verbosity_ = parameterSet.getUntrackedParameter<int> ("verbosity");
19  maximumChi2OverNDF_ = parameterSet.getParameter<double>("maximumChi2OverNDF");
20  maximumXLocalDistanceFromTrack_= parameterSet.getParameter<double>("maximumXLocalDistanceFromTrack");
21  maximumYLocalDistanceFromTrack_= parameterSet.getParameter<double>("maximumYLocalDistanceFromTrack");
22  numberOfPlanesPerPot_ = parameterSet.getParameter<int> ("numberOfPlanesPerPot" );
23 
25  throw cms::Exception("RPixPlaneCombinatoryTracking") << "Minimum number of planes required for tracking is 3, "
26  << "tracking is not possible with "
27  << trackMinNumberOfPoints_ << " hits";
28  }
29 
30 
31 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
RPixDetTrackFinder(edm::ParameterSet const &parameterSet)
def uint(string)
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
RPixPlaneCombinatoryTracking::~RPixPlaneCombinatoryTracking ( )
override

Definition at line 35 of file RPixPlaneCombinatoryTracking.cc.

References possiblePlaneCombinations_.

35  {
37 }

Member Function Documentation

bool RPixPlaneCombinatoryTracking::calculatePointOnDetector ( CTPPSPixelLocalTrack track,
CTPPSPixelDetId  planeId,
GlobalPoint planeLineIntercept 
)
private

Definition at line 458 of file RPixPlaneCombinatoryTracking.cc.

References pfDeepCMVADiscriminatorsJetTags_cfi::denominator, RPixDetTrackFinder::geometry_, CTPPSPixelLocalTrack::getDirectionVector(), CTPPSPixelLocalTrack::getParameterVector(), CTPPSGeometry::getSensor(), CTPPSPixelLocalTrack::getZ0(), CTPPSGeometry::localToGlobal(), DetGeomDesc::rotation(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by findTracks(), and fitTrack().

459  {
460  double z0 = track->getZ0();
462 
463  math::Vector<3>::type pointOnLine(parameters[0], parameters[1], z0);
464  GlobalVector tmpLineUnitVector = track->getDirectionVector();
465  math::Vector<3>::type lineUnitVector(tmpLineUnitVector.x(),tmpLineUnitVector.y(),tmpLineUnitVector.z());
466 
467  CLHEP::Hep3Vector tmpPointLocal(0.,0.,0.);
468  CLHEP::Hep3Vector tmpPointOnPlane = geometry_->localToGlobal(planeId,tmpPointLocal);
469 
470  math::Vector<3>::type pointOnPlane(tmpPointOnPlane.x(), tmpPointOnPlane.y(), tmpPointOnPlane.z());
471  math::Vector<3>::type planeUnitVector(0.,0.,1.);
472 
473  DDRotationMatrix theRotationMatrix = geometry_->getSensor(planeId)->rotation();
474  AlgebraicMatrix33 tmpPlaneRotationMatrixMap;
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));
478 
479  planeUnitVector = tmpPlaneRotationMatrixMap * planeUnitVector;
480 
481  double denominator = ROOT::Math::Dot(lineUnitVector, planeUnitVector);
482  if(denominator==0){
483  edm::LogError("RPixPlaneCombinatoryTracking")
484  << "Error in RPixPlaneCombinatoryTracking::calculatePointOnDetector -> "
485  << "Fitted line and plane are parallel. Removing this track";
486  return false;
487  }
488 
489  double distanceFromLinePoint = ROOT::Math::Dot((pointOnPlane - pointOnLine), planeUnitVector) / denominator;
490 
491  math::Vector<3>::type tmpPlaneLineIntercept = distanceFromLinePoint*lineUnitVector + pointOnLine;
492  planeLineIntercept = GlobalPoint(tmpPlaneLineIntercept[0], tmpPlaneLineIntercept[1], tmpPlaneLineIntercept[2]);
493 
494  return true;
495 
496 }
DDRotationMatrix rotation() const
geometry information
Definition: DetGeomDesc.h:83
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
const DetGeomDesc * getSensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
fixed size vector
Definition: Vector.h:25
T z() const
Definition: PV3DBase.h:64
CLHEP::Hep3Vector localToGlobal(const DetGeomDesc *, const CLHEP::Hep3Vector &) const
const CTPPSGeometry * geometry_
math::Vector< dimension >::type ParameterVector
covariance matrix size
GlobalVector getDirectionVector() const
const ParameterVector & getParameterVector() const
T x() const
Definition: PV3DBase.h:62
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
uint32_t RPixPlaneCombinatoryTracking::factorial ( uint32_t  x) const
inlineprivate

Definition at line 64 of file RPixPlaneCombinatoryTracking.h.

Referenced by initialize().

64  {
65  if(x==0) return 1;
66  return (x == 1 ? x : x * factorial(x - 1));
67  }
uint32_t factorial(uint32_t x) const
void RPixPlaneCombinatoryTracking::findTracks ( )
overridevirtual

Implements RPixDetTrackFinder.

Definition at line 164 of file RPixPlaneCombinatoryTracking.cc.

References CTPPSPixelLocalTrack::addHit(), calculatePointOnDetector(), SoftLeptonByDistance_cfi::distance, Exception, spr::find(), fitTrack(), RPixDetTrackFinder::geometry_, CTPPSPixelLocalTrack::getChiSquaredOverNDF(), CTPPSPixelLocalTrack::getHits(), CTPPSPixelLocalTrack::getNDF(), getPlaneCombinations(), CTPPSGeometry::getSensor(), RPixDetTrackFinder::hitMap_, mps_fire::i, CTPPSPixelLocalTrack::isValid(), RPixDetTrackFinder::listOfAllPlanes_, RPixDetTrackFinder::localTrackVector_, maximumChi2OverNDF_, maximumXLocalDistanceFromTrack_, maximumYLocalDistanceFromTrack_, orderCombinationsPerNumberOrPoints(), point, possiblePlaneCombinations_, produceAllHitCombination(), RPixDetTrackFinder::romanPotId_, DetGeomDesc::rotation(), CTPPSPixelDetId::setPlane(), mathSSE::sqrt(), trackMinNumberOfPoints_, verbosity_, PV3DBase< T, PVType, FrameType >::x(), hit::x, PV3DBase< T, PVType, FrameType >::y(), and hit::y.

164  {
165 
166  //The loop search for all the possible tracks starting from the one with the smallest chiSquare/NDF
167  //The loop stops when the number of planes with recorded hits is less than the minimum number of planes required
168  //or if the track with minimum chiSquare found has a chiSquare higher than the maximum required
169 
170  while(hitMap_->size()>=trackMinNumberOfPoints_){
171 
172  if(verbosity_>=1) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Number of plane with hits "<<hitMap_->size();
173  if(verbosity_>=2) for(const auto & plane : *hitMap_) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"\tarm "<<plane.first.arm()
174  <<" station "<<plane.first.station()
175  <<" rp " <<plane.first.rp()
176  <<" plane "<<plane.first.plane()
177  <<" : "<<plane.second.size();
178 
179  //I create the map of all the possible combinations of a group of trackMinNumberOfPoints_ points
180  //and the key keeps the reference of which planes and which hit numbers form the combination
181  PointAndReferenceMap mapOfAllMinRequiredPoint;
182  //I produce the map for all cominations of all hits with all trackMinNumberOfPoints_ plane combinations
183  mapOfAllMinRequiredPoint =produceAllHitCombination(possiblePlaneCombinations_);
184 
185  //Fit all the possible combinations with minimum number of planes required and find the track with minimum chi2
186  double theMinChiSquaredOverNDF = maximumChi2OverNDF_+1.; //in order to break the loop in case no track is found;
187  HitReferences pointMapWithMinChiSquared;
188  PointInPlaneList pointsWithMinChiSquared;
189  CTPPSPixelLocalTrack bestTrack;
190 
191  if(verbosity_>2) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Number of combinations of trackMinNumberOfPoints_ planes "
192  <<mapOfAllMinRequiredPoint.size();
193  for(const auto & pointsAndRef : mapOfAllMinRequiredPoint){
194  CTPPSPixelLocalTrack tmpTrack = fitTrack(pointsAndRef.second);
195  double tmpChiSquaredOverNDF = tmpTrack.getChiSquaredOverNDF();
196  if(verbosity_>=2) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"ChiSquare of the present track "<<tmpChiSquaredOverNDF;
197  if(!tmpTrack.isValid() || tmpChiSquaredOverNDF>maximumChi2OverNDF_ || tmpChiSquaredOverNDF==0.) continue; //validity check
198  if(tmpChiSquaredOverNDF<theMinChiSquaredOverNDF){
199  theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
200  pointMapWithMinChiSquared = pointsAndRef.first;
201  pointsWithMinChiSquared = pointsAndRef.second;
202  bestTrack = tmpTrack;
203  }
204  }
205 
206  //The loop on the fit of all tracks is done, the track with minimum chiSquared is found
207  // and it is verified that it complies with the maximumChi2OverNDF_ requirement
208  if(theMinChiSquaredOverNDF > maximumChi2OverNDF_) break;
209 
210  //The list of planes not included in the minimum chiSquare track is produced.
211  std::vector<uint32_t> listOfExcludedPlanes;
212  for(const auto & plane : listOfAllPlanes_){
213  CTPPSPixelDetId tmpRpId = romanPotId_; //in order to avoid to modify the data member
214  tmpRpId.setPlane(plane);
215  CTPPSPixelDetId planeDetId = tmpRpId;
216  if(pointMapWithMinChiSquared.find(planeDetId)==pointMapWithMinChiSquared.end())
217  listOfExcludedPlanes.push_back(plane);
218  }
219 
220  //I produce all the possible combinations of planes to be added to the track,
221  //excluding the case of no other plane added since it has been already fitted.
222  PlaneCombinations planePointedHitListCombination;
223  for(uint32_t i=1; i<=listOfExcludedPlanes.size(); ++i){
224  PlaneCombinations tmpPlaneCombination;
225  getPlaneCombinations(listOfExcludedPlanes,i,tmpPlaneCombination);
226  for(const auto & combination : tmpPlaneCombination) planePointedHitListCombination.push_back(combination);
227  }
228 
229  //I produce all the possible combinations of points to be added to the track
230  PointAndReferenceMap mapOfAllPointWithAtLeastBestFitSelected;
231  PointAndReferenceMap mapOfPointCombinationToBeAdded;
232  mapOfPointCombinationToBeAdded = produceAllHitCombination(planePointedHitListCombination);
233  //The found hit combination is added to the hits selected by the best fit;
234  for(const auto & element : mapOfPointCombinationToBeAdded){
235  HitReferences newPointMap = pointMapWithMinChiSquared;
236  PointInPlaneList newPoints = pointsWithMinChiSquared;
237  for(const auto & pointRef : element.first ) newPointMap[pointRef.first] = pointRef.second; //add the new point reference
238  for(const auto & point : element.second) newPoints.push_back(point);
239  mapOfAllPointWithAtLeastBestFitSelected[newPointMap]=newPoints;
240  }
241 
242  //I fit all the possible combination of the minimum plane best fit hits plus hits from the other planes
243  if(verbosity_>=1) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Minimum chiSquare over NDF for all the tracks "<<theMinChiSquaredOverNDF;
244 
245  // I look for the tracks with maximum number of points with a chiSquare over NDF smaller than maximumChi2OverNDF_
246  // If more than one track fulfill the chiSquare requirement with the same number of points I choose the one with smaller chiSquare
247  std::vector<PointAndReferencePair > orderedVectorOfAllPointWithAtLeastBestFitSelected =
248  orderCombinationsPerNumberOrPoints(mapOfAllPointWithAtLeastBestFitSelected);
249  int currentNumberOfPlanes = 0;
250  theMinChiSquaredOverNDF = maximumChi2OverNDF_+1.; //in order to break the loop in case no track is found;
251  bool foundTrackWithCurrentNumberOfPlanes = false;
252  for(const auto & pointsAndRef : orderedVectorOfAllPointWithAtLeastBestFitSelected){
253  int tmpNumberOfPlanes = pointsAndRef.second.size();
254  // If a valid track has been already found with an higher number of planes the loop stops.
255  if(foundTrackWithCurrentNumberOfPlanes && tmpNumberOfPlanes<currentNumberOfPlanes) break;
256  CTPPSPixelLocalTrack tmpTrack = fitTrack(pointsAndRef.second);
257  double tmpChiSquaredOverNDF = tmpTrack.getChiSquaredOverNDF();
258  if(!tmpTrack.isValid() || tmpChiSquaredOverNDF>maximumChi2OverNDF_ || tmpChiSquaredOverNDF==0.) continue; //validity check
259  if(tmpChiSquaredOverNDF<theMinChiSquaredOverNDF){
260  theMinChiSquaredOverNDF = tmpChiSquaredOverNDF;
261  pointMapWithMinChiSquared = pointsAndRef.first;
262  bestTrack = tmpTrack;
263  currentNumberOfPlanes = tmpNumberOfPlanes;
264  foundTrackWithCurrentNumberOfPlanes = true;
265  }
266  }
267 
268  if(verbosity_>=1) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"The best track has " << bestTrack.getNDF()/2 + 2 ;
269 
270  std::vector<uint32_t> listOfPlaneNotUsedForFit = listOfAllPlanes_;
271  //remove the hits belonging to the tracks from the full list of hits
272  for(const auto & hitToErase : pointMapWithMinChiSquared){
273  std::map<CTPPSPixelDetId, PointInPlaneList >::iterator hitMapElement = hitMap_->find(hitToErase.first);
274  if(hitMapElement==hitMap_->end()){
275  throw cms::Exception("RPixPlaneCombinatoryTracking")
276  <<"The found tracks has hit belonging to a plane which does not have hits";
277  }
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);
282  //if the plane at which the hit was erased is empty it is removed from the hit map
283  if(hitMapElement->second.empty()) hitMap_->erase(hitMapElement);
284  }
285 
286  //search for hit on the other planes which may belong to the same track
287  //even if they did not contributed to the track
288  // in case of multiple hit, the closest one to the track will be considered
289  //If an hit is found these will not be erased from the list of all hits
290  //If not hit is found, the point on the plane intersecting the track will be saved by a CTPPSPixelFittedRecHit
291  //with the isRealHit_ flag set to false
292  for(const auto & plane : listOfPlaneNotUsedForFit){
293  CTPPSPixelDetId tmpPlaneId = romanPotId_; //in order to avoid to modify the data member
294  tmpPlaneId.setPlane(plane);
295  std::unique_ptr<CTPPSPixelFittedRecHit>
296  fittedRecHit(new CTPPSPixelFittedRecHit());
297  GlobalPoint pointOnDet;
298  calculatePointOnDetector(&bestTrack, tmpPlaneId, pointOnDet);
299 
300 
301  if(hitMap_->find(tmpPlaneId) != hitMap_->end()){
302  //I convert the hit search window defined in local coordinated into global
303  //This avoids to convert the global plane-line intersection in order not to call the the geometry
305 
306  DDRotationMatrix theRotationMatrix = geometry_->getSensor(tmpPlaneId)->rotation();
307  AlgebraicMatrix33 tmpPlaneRotationMatrixMap;
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));
311 
312  maxGlobalPointDistance = tmpPlaneRotationMatrixMap * maxGlobalPointDistance;
313  //I avoid the Sqrt since it will not be saved
314  double maximumXdistance = maxGlobalPointDistance[0]*maxGlobalPointDistance[0];
315  double maximumYdistance = maxGlobalPointDistance[1]*maxGlobalPointDistance[1];
316  double minimumDistance = 1. + maximumXdistance + maximumYdistance; // to be sure that the first min distance is from a real point
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){
324  LocalPoint residuals(xResidual,yResidual,0.);
325  math::Error<3>::type globalError = hit.globalError;
326  LocalPoint pulls(xResidual/std::sqrt(globalError[0][0]),yResidual/std::sqrt(globalError[1][1]),0.);
327  fittedRecHit.reset(new CTPPSPixelFittedRecHit(hit.recHit, pointOnDet, residuals, pulls));
328  fittedRecHit->setIsRealHit(true);
329  }
330  }
331  }
332  else{
333  LocalPoint fakePoint;
334  LocalError fakeError;
335  CTPPSPixelRecHit fakeRecHit(fakePoint,fakeError);
336  fittedRecHit.reset(new CTPPSPixelFittedRecHit(fakeRecHit, pointOnDet, fakePoint, fakePoint));
337  }
338 
339  bestTrack.addHit(tmpPlaneId, *fittedRecHit);
340 
341  }
342 
343  localTrackVector_.push_back(bestTrack);
344 
345  int pointForTracking = 0;
346  int pointOnTrack = 0;
347 
348  if(verbosity_>=1){
349  for(const auto & planeHits : bestTrack.getHits()){
350  for(const auto & fittedhit : planeHits){
351  if(fittedhit.getIsUsedForFit()) ++pointForTracking;
352  if(fittedhit.getIsRealHit()) ++pointOnTrack;
353  }
354  }
355  edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Best track has "<<pointForTracking<<" points used for the fit and "
356  << pointOnTrack<<" points belonging to the track\n";
357  }
358 
359  } //close of the while loop on all the hits
360 
361  return;
362 
363 }
std::map< HitReferences, PointInPlaneList > PointAndReferenceMap
DDRotationMatrix rotation() const
geometry information
Definition: DetGeomDesc.h:83
std::map< CTPPSPixelDetId, size_t > HitReferences
bool calculatePointOnDetector(CTPPSPixelLocalTrack *track, CTPPSPixelDetId planeId, GlobalPoint &planeLineIntercept)
std::vector< PointAndReferencePair > orderCombinationsPerNumberOrPoints(PointAndReferenceMap inputMap)
T y() const
Definition: PV3DBase.h:63
ErrorD< N >::type type
Definition: Error.h:33
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< CTPPSPixelLocalTrack > localTrackVector_
const DetGeomDesc * getSensor(unsigned int id) const
returns geometry of a detector performs necessary checks, returns NULL if fails
CTPPSPixelLocalTrack fitTrack(PointInPlaneList pointList)
fixed size vector
Definition: Vector.h:25
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< RPixDetPatternFinder::PointInPlane > PointInPlaneList
float getChiSquaredOverNDF() const
std::map< CTPPSPixelDetId, std::vector< RPixDetPatternFinder::PointInPlane > > * hitMap_
void addHit(unsigned int detId, const CTPPSPixelFittedRecHit &hit)
std::vector< uint32_t > listOfAllPlanes_
void setPlane(uint32_t pl)
const edm::DetSetVector< CTPPSPixelFittedRecHit > & getHits() const
const CTPPSGeometry * geometry_
PointAndReferenceMap produceAllHitCombination(PlaneCombinations inputPlaneCombination)
CTPPSPixelDetId romanPotId_
T x() const
Definition: PV3DBase.h:62
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
std::vector< std::vector< uint32_t > > PlaneCombinations
*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
Definition: invegas.h:5
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
CTPPSPixelLocalTrack RPixPlaneCombinatoryTracking::fitTrack ( PointInPlaneList  pointList)
private

Definition at line 367 of file RPixPlaneCombinatoryTracking.cc.

References CTPPSPixelLocalTrack::addHit(), calculatePointOnDetector(), spr::goodTrack(), CTPPSPixelFittedRecHit::setIsUsedForFit(), CTPPSPixelLocalTrack::setValid(), mathSSE::sqrt(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and RPixDetTrackFinder::z0_.

Referenced by findTracks().

367  {
368 
369  uint32_t const numberOfPlanes = 6;
373 
374  //The matrices and vector xyCoordinates, varianceMatrix and varianceMatrix are built from the points
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_;
384 
385  AlgebraicMatrix33 globalError = pointList[iHit].globalError;
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);
390  } else {
391  varianceMatrix(2*iHit, 2*iHit) = 1.;
392  varianceMatrix(2*iHit + 1, 2*iHit + 1) = 1.;
393  }
394  }
395 
396  //Get real point variance matrix
397  if (!varianceMatrix.Invert()) {
398  edm::LogError("RPixPlaneCombinatoryTracking") << "Error in RPixPlaneCombinatoryTracking::fitTrack -> "
399  << "Point variance matrix is singular, skipping.";
400  CTPPSPixelLocalTrack badTrack;
401  badTrack.setValid(false);
402  return badTrack;
403  }
404 
405  math::Error<4>::type covarianceMatrix = ROOT::Math::SimilarityT(zMatrix, varianceMatrix);
406 
407  //To have the real parameter covariance matrix, covarianceMatrix needs to be inverted
408  if (!covarianceMatrix.Invert()) {
409  edm::LogError("RPixPlaneCombinatoryTracking") << "Error in RPixPlaneCombinatoryTracking::fitTrack -> "
410  << "Parameter covariance matrix is singular, skipping.";
411  CTPPSPixelLocalTrack badTrack;
412  badTrack.setValid(false);
413  return badTrack;
414  }
415 
416  // track parameters: (x0, y0, tx, ty); x = x0 + tx*(z-z0)
417  math::Vector<4>::type zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates =
418  ROOT::Math::Transpose(zMatrix) * varianceMatrix * xyCoordinates;
419  math::Vector<4>::type parameterVector =
420  covarianceMatrix * zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates;
421  math::Vector<2*numberOfPlanes>::type xyCoordinatesMinusZmatrixTimesParameters =
422  xyCoordinates - (zMatrix * parameterVector);
423 
424  double chiSquare =
425  ROOT::Math::Dot(xyCoordinatesMinusZmatrixTimesParameters, (varianceMatrix * xyCoordinatesMinusZmatrixTimesParameters));
426 
427  CTPPSPixelLocalTrack goodTrack(z0_, parameterVector, covarianceMatrix, chiSquare);
428  goodTrack.setValid(true);
429 
430  for(const auto & hit : pointList){
431  CLHEP::Hep3Vector globalPoint = hit.globalPoint;
432  GlobalPoint pointOnDet;
433  bool foundPoint = calculatePointOnDetector(&goodTrack, hit.detId, pointOnDet);
434  if(!foundPoint){
435  CTPPSPixelLocalTrack badTrack;
436  badTrack.setValid(false);
437  return badTrack;
438  }
439  double xResidual = globalPoint.x() - pointOnDet.x();
440  double yResidual = globalPoint.y() - pointOnDet.y();
441  LocalPoint residuals(xResidual,yResidual);
442 
443  math::Error<3>::type globalError(hit.globalError);
444  LocalPoint pulls(xResidual/std::sqrt(globalError(0, 0)),yResidual/std::sqrt(globalError(0, 0)));
445 
446  CTPPSPixelFittedRecHit fittedRecHit(hit.recHit, pointOnDet, residuals, pulls);
447  fittedRecHit.setIsUsedForFit(true);
448  goodTrack.addHit(hit.detId, fittedRecHit);
449  }
450 
451  return goodTrack;
452 
453 }
ROOT::Math::SMatrix< double, N, M > type
Definition: Matrix.h:10
bool calculatePointOnDetector(CTPPSPixelLocalTrack *track, CTPPSPixelDetId planeId, GlobalPoint &planeLineIntercept)
T y() const
Definition: PV3DBase.h:63
ErrorD< N >::type type
Definition: Error.h:33
fixed size vector
Definition: Vector.h:25
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
T sqrt(T t)
Definition: SSEVec.h:18
T x() const
Definition: PV3DBase.h:62
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
static bool RPixPlaneCombinatoryTracking::functionForPlaneOrdering ( PointAndReferencePair  a,
PointAndReferencePair  b 
)
inlinestaticprivate

Definition at line 56 of file RPixPlaneCombinatoryTracking.h.

References orderCombinationsPerNumberOrPoints().

Referenced by orderCombinationsPerNumberOrPoints().

58  {
59  return (a.second.size() > b.second.size()); }
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void RPixPlaneCombinatoryTracking::getHitCombinations ( const std::map< CTPPSPixelDetId, PointInPlaneList > &  mapOfAllHits,
std::map< CTPPSPixelDetId, PointInPlaneList >::iterator  mapIterator,
HitReferences  tmpHitPlaneMap,
const PointInPlaneList tmpHitVector,
PointAndReferenceMap outputMap 
)
private

Definition at line 90 of file RPixPlaneCombinatoryTracking.cc.

References mps_fire::i.

Referenced by produceAllHitCombination().

96 {
97  //At this point I selected one hit per plane
98  if (mapIterator == mapOfAllHits.end())
99  {
100  outputMap[tmpHitPlaneMap] = tmpHitVector;
101  return;
102  }
103  for (size_t i=0; i<mapIterator->second.size(); i++){
104  HitReferences newHitPlaneMap = tmpHitPlaneMap;
105  newHitPlaneMap[mapIterator->first] = i;
106  PointInPlaneList newVector = tmpHitVector;
107  newVector.push_back(mapIterator->second[i]);
108  std::map<CTPPSPixelDetId, PointInPlaneList >::iterator tmpMapIterator = mapIterator;
109  getHitCombinations(mapOfAllHits, ++tmpMapIterator, newHitPlaneMap, newVector, outputMap);
110  }
111 }
std::map< CTPPSPixelDetId, size_t > HitReferences
void getHitCombinations(const std::map< CTPPSPixelDetId, PointInPlaneList > &mapOfAllHits, std::map< CTPPSPixelDetId, PointInPlaneList >::iterator mapIterator, HitReferences tmpHitPlaneMap, const PointInPlaneList &tmpHitVector, PointAndReferenceMap &outputMap)
std::vector< RPixDetPatternFinder::PointInPlane > PointInPlaneList
void RPixPlaneCombinatoryTracking::getPlaneCombinations ( const std::vector< uint32_t > &  inputPlaneList,
uint32_t  numberToExtract,
PlaneCombinations planeCombinations 
) const
private

Definition at line 65 of file RPixPlaneCombinatoryTracking.cc.

References mps_fire::i, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by findTracks(), and initialize().

66 {
67  uint32_t numberOfPlanes = inputPlaneList.size();
68  std::string bitmask(numberToExtract, 1); // numberToExtract leading 1's
69  bitmask.resize(numberOfPlanes, 0); // numberOfPlanes-numberToExtract trailing 0's
70  planeCombinations.clear();
71 
72  // store the combination and permute bitmask
73  do {
74  planeCombinations.push_back(std::vector<uint32_t>());
75  for (uint32_t i = 0; i < numberOfPlanes; ++i) { // [0..numberOfPlanes-1] integers
76  if (bitmask[i]) planeCombinations.back().push_back(inputPlaneList.at(i));
77  }
78  } while (std::prev_permutation(bitmask.begin(), bitmask.end()));
79 
80  return;
81 }
void RPixPlaneCombinatoryTracking::initialize ( void  )
overridevirtual

Implements RPixDetTrackFinder.

Definition at line 41 of file RPixPlaneCombinatoryTracking.cc.

References factorial(), getPlaneCombinations(), RPixDetTrackFinder::listOfAllPlanes_, pileupDistInMC::num, RPixDetTrackFinder::numberOfPlanesPerPot_, possiblePlaneCombinations_, trackMinNumberOfPoints_, and verbosity_.

41  {
42 
43  uint32_t numberOfCombinations = factorial(numberOfPlanesPerPot_)/
46  if(verbosity_>=2) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Number of combinations = "<<numberOfCombinations;
47  possiblePlaneCombinations_.reserve(numberOfCombinations);
48 
50 
51  if(verbosity_>=2) {
52  for( const auto & vec : possiblePlaneCombinations_){
53  for( const auto & num : vec){
54  edm::LogInfo("RPixPlaneCombinatoryTracking")<<num<<" - ";
55  }
56  edm::LogInfo("RPixPlaneCombinatoryTracking");
57  }
58  }
59 
60 }
uint32_t factorial(uint32_t x) const
std::vector< uint32_t > listOfAllPlanes_
void getPlaneCombinations(const std::vector< uint32_t > &inputPlaneList, uint32_t numberToExtract, PlaneCombinations &planeCombinations) const
std::vector< RPixPlaneCombinatoryTracking::PointAndReferencePair > RPixPlaneCombinatoryTracking::orderCombinationsPerNumberOrPoints ( PointAndReferenceMap  inputMap)
private

Definition at line 501 of file RPixPlaneCombinatoryTracking.cc.

References functionForPlaneOrdering().

Referenced by findTracks(), and functionForPlaneOrdering().

502  {
503 
504  std::vector<PointAndReferencePair > sortedVector(inputMap.begin(),inputMap.end());
505  std::sort(sortedVector.begin(),sortedVector.end(),functionForPlaneOrdering);
506 
507  return sortedVector;
508 
509 }
static bool functionForPlaneOrdering(PointAndReferencePair a, PointAndReferencePair b)
RPixPlaneCombinatoryTracking::PointAndReferenceMap RPixPlaneCombinatoryTracking::produceAllHitCombination ( PlaneCombinations  inputPlaneCombination)
private

Definition at line 116 of file RPixPlaneCombinatoryTracking.cc.

References CTPPSDetId::arm(), Exception, getHitCombinations(), RPixDetTrackFinder::hitMap_, CTPPSPixelDetId::plane(), RPixDetTrackFinder::romanPotId_, CTPPSDetId::rp(), CTPPSPixelDetId::setPlane(), CTPPSDetId::station(), and verbosity_.

Referenced by findTracks().

116  {
117 
118  PointAndReferenceMap mapOfAllPoints;
119  CTPPSPixelDetId tmpRpId = romanPotId_; //in order to avoid to modify the data member
120 
121  if(verbosity_>2) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Searching for all combinations...";
122  //Loop on all the plane combinations
123  for( const auto & planeCombination : inputPlaneCombination){
124 
125  std::map<CTPPSPixelDetId, PointInPlaneList > selectedCombinationHitOnPlane;
126  bool allPlaneAsHits = true;
127 
128  //Loop on all the possible combinations
129  //In this loop the selectedCombinationHitOnPlane is filled
130  //and cases in which one of the selected plane is empty are skipped
131  for( const auto & plane : planeCombination){
132  tmpRpId.setPlane(plane);
133  CTPPSPixelDetId planeDetId = tmpRpId;
134  if(hitMap_->find(planeDetId) == hitMap_->end()){
135  if(verbosity_>2) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"No data on arm "<<planeDetId.arm()<<" station "<<planeDetId.station()
136  <<" rp " <<planeDetId.rp()<<" plane "<<planeDetId.plane();
137  allPlaneAsHits = false;
138  break;
139  }
140  if(selectedCombinationHitOnPlane.find(planeDetId)!=selectedCombinationHitOnPlane.end()){
141  throw cms::Exception("RPixPlaneCombinatoryTracking")
142  <<"selectedCombinationHitOnPlane contains already detId "<<planeDetId
143  <<"Error in the algorithm which created all the possible plane combinations";
144  }
145  selectedCombinationHitOnPlane[planeDetId] = (*hitMap_)[planeDetId];
146  }
147  if(!allPlaneAsHits) continue;
148 
149  //I add the all the hit combinations to the full list of plane combinations
150  auto mapIterator=selectedCombinationHitOnPlane.begin();
151  HitReferences tmpHitPlaneMap; //empty map of plane id and hit number needed the getHitCombinations algorithm
152  PointInPlaneList tmpHitVector; //empty vector of hits needed for the getHitCombinations algorithm
153  getHitCombinations(selectedCombinationHitOnPlane,mapIterator,tmpHitPlaneMap,tmpHitVector,mapOfAllPoints);
154  if(verbosity_>2) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Number of possible tracks "<<mapOfAllPoints.size();
155 
156  } //end of loops on all the combinations
157 
158  return mapOfAllPoints;
159 
160 }
uint32_t station() const
Definition: CTPPSDetId.h:63
std::map< HitReferences, PointInPlaneList > PointAndReferenceMap
uint32_t plane() const
std::map< CTPPSPixelDetId, size_t > HitReferences
void getHitCombinations(const std::map< CTPPSPixelDetId, PointInPlaneList > &mapOfAllHits, std::map< CTPPSPixelDetId, PointInPlaneList >::iterator mapIterator, HitReferences tmpHitPlaneMap, const PointInPlaneList &tmpHitVector, PointAndReferenceMap &outputMap)
std::vector< RPixDetPatternFinder::PointInPlane > PointInPlaneList
std::map< CTPPSPixelDetId, std::vector< RPixDetPatternFinder::PointInPlane > > * hitMap_
uint32_t arm() const
Definition: CTPPSDetId.h:52
void setPlane(uint32_t pl)
CTPPSPixelDetId romanPotId_
uint32_t rp() const
Definition: CTPPSDetId.h:74

Member Data Documentation

double RPixPlaneCombinatoryTracking::maximumChi2OverNDF_
private

Definition at line 41 of file RPixPlaneCombinatoryTracking.h.

Referenced by findTracks(), and RPixPlaneCombinatoryTracking().

double RPixPlaneCombinatoryTracking::maximumXLocalDistanceFromTrack_
private

Definition at line 42 of file RPixPlaneCombinatoryTracking.h.

Referenced by findTracks(), and RPixPlaneCombinatoryTracking().

double RPixPlaneCombinatoryTracking::maximumYLocalDistanceFromTrack_
private

Definition at line 43 of file RPixPlaneCombinatoryTracking.h.

Referenced by findTracks(), and RPixPlaneCombinatoryTracking().

PlaneCombinations RPixPlaneCombinatoryTracking::possiblePlaneCombinations_
private
uint32_t RPixPlaneCombinatoryTracking::trackMinNumberOfPoints_
private
int RPixPlaneCombinatoryTracking::verbosity_
private