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 }
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 33 of file RPixPlaneCombinatoryTracking.cc.

References possiblePlaneCombinations_.

33  {
35 }

Member Function Documentation

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

Definition at line 455 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().

456  {
457  double z0 = track->getZ0();
459 
460  math::Vector<3>::type pointOnLine(parameters[0], parameters[1], z0);
461  GlobalVector tmpLineUnitVector = track->getDirectionVector();
462  math::Vector<3>::type lineUnitVector(tmpLineUnitVector.x(),tmpLineUnitVector.y(),tmpLineUnitVector.z());
463 
464  CLHEP::Hep3Vector tmpPointLocal(0.,0.,0.);
465  CLHEP::Hep3Vector tmpPointOnPlane = geometry_->localToGlobal(planeId,tmpPointLocal);
466 
467  math::Vector<3>::type pointOnPlane(tmpPointOnPlane.x(), tmpPointOnPlane.y(), tmpPointOnPlane.z());
468  math::Vector<3>::type planeUnitVector(0.,0.,1.);
469 
470  DetGeomDesc::RotationMatrix theRotationMatrix = geometry_->getSensor(planeId)->rotation();
471  AlgebraicMatrix33 tmpPlaneRotationMatrixMap;
472  theRotationMatrix.GetComponents(tmpPlaneRotationMatrixMap(0, 0), tmpPlaneRotationMatrixMap(0, 1), tmpPlaneRotationMatrixMap(0, 2),
473  tmpPlaneRotationMatrixMap(1, 0), tmpPlaneRotationMatrixMap(1, 1), tmpPlaneRotationMatrixMap(1, 2),
474  tmpPlaneRotationMatrixMap(2, 0), tmpPlaneRotationMatrixMap(2, 1), tmpPlaneRotationMatrixMap(2, 2));
475 
476  planeUnitVector = tmpPlaneRotationMatrixMap * planeUnitVector;
477 
478  double denominator = ROOT::Math::Dot(lineUnitVector, planeUnitVector);
479  if(denominator==0){
480  edm::LogError("RPixPlaneCombinatoryTracking")
481  << "Error in RPixPlaneCombinatoryTracking::calculatePointOnDetector -> "
482  << "Fitted line and plane are parallel. Removing this track";
483  return false;
484  }
485 
486  double distanceFromLinePoint = ROOT::Math::Dot((pointOnPlane - pointOnLine), planeUnitVector) / denominator;
487 
488  math::Vector<3>::type tmpPlaneLineIntercept = distanceFromLinePoint*lineUnitVector + pointOnLine;
489  planeLineIntercept = GlobalPoint(tmpPlaneLineIntercept[0], tmpPlaneLineIntercept[1], tmpPlaneLineIntercept[2]);
490 
491  return true;
492 
493 }
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
RotationMatrix rotation() const
geometry information
Definition: DetGeomDesc.h:65
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 RotationMatrix
Definition: DetGeomDesc.h:39
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 161 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.

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

364  {
365 
366  uint32_t const numberOfPlanes = 6;
370 
371  //The matrices and vector xyCoordinates, varianceMatrix and varianceMatrix are built from the points
372  for(uint32_t iHit = 0; iHit < numberOfPlanes; iHit++) {
373  if (iHit < pointList.size()) {
374  CLHEP::Hep3Vector globalPoint = pointList[iHit].globalPoint;
375  xyCoordinates[2*iHit] = globalPoint.x() ;
376  xyCoordinates[2*iHit + 1] = globalPoint.y() ;
377  zMatrix (2*iHit, 0) = 1. ;
378  zMatrix (2*iHit, 2) = globalPoint.z()-z0_;
379  zMatrix (2*iHit + 1, 1) = 1. ;
380  zMatrix (2*iHit+ 1 , 3) = globalPoint.z()-z0_;
381 
382  AlgebraicMatrix33 globalError = pointList[iHit].globalError;
383  varianceMatrix(2*iHit, 2*iHit) = globalError(0, 0);
384  varianceMatrix(2*iHit, 2*iHit + 1) = globalError(0, 1);
385  varianceMatrix(2*iHit + 1, 2*iHit) = globalError(1, 0);
386  varianceMatrix(2*iHit + 1, 2*iHit + 1) = globalError(1, 1);
387  } else {
388  varianceMatrix(2*iHit, 2*iHit) = 1.;
389  varianceMatrix(2*iHit + 1, 2*iHit + 1) = 1.;
390  }
391  }
392 
393  //Get real point variance matrix
394  if (!varianceMatrix.Invert()) {
395  edm::LogError("RPixPlaneCombinatoryTracking") << "Error in RPixPlaneCombinatoryTracking::fitTrack -> "
396  << "Point variance matrix is singular, skipping.";
397  CTPPSPixelLocalTrack badTrack;
398  badTrack.setValid(false);
399  return badTrack;
400  }
401 
402  math::Error<4>::type covarianceMatrix = ROOT::Math::SimilarityT(zMatrix, varianceMatrix);
403 
404  //To have the real parameter covariance matrix, covarianceMatrix needs to be inverted
405  if (!covarianceMatrix.Invert()) {
406  edm::LogError("RPixPlaneCombinatoryTracking") << "Error in RPixPlaneCombinatoryTracking::fitTrack -> "
407  << "Parameter covariance matrix is singular, skipping.";
408  CTPPSPixelLocalTrack badTrack;
409  badTrack.setValid(false);
410  return badTrack;
411  }
412 
413  // track parameters: (x0, y0, tx, ty); x = x0 + tx*(z-z0)
414  math::Vector<4>::type zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates =
415  ROOT::Math::Transpose(zMatrix) * varianceMatrix * xyCoordinates;
416  math::Vector<4>::type parameterVector =
417  covarianceMatrix * zMatrixTransposeTimesVarianceMatrixTimesXyCoordinates;
418  math::Vector<2*numberOfPlanes>::type xyCoordinatesMinusZmatrixTimesParameters =
419  xyCoordinates - (zMatrix * parameterVector);
420 
421  double chiSquare =
422  ROOT::Math::Dot(xyCoordinatesMinusZmatrixTimesParameters, (varianceMatrix * xyCoordinatesMinusZmatrixTimesParameters));
423 
424  CTPPSPixelLocalTrack goodTrack(z0_, parameterVector, covarianceMatrix, chiSquare);
425  goodTrack.setValid(true);
426 
427  for(const auto & hit : pointList){
428  CLHEP::Hep3Vector globalPoint = hit.globalPoint;
429  GlobalPoint pointOnDet;
430  bool foundPoint = calculatePointOnDetector(&goodTrack, hit.detId, pointOnDet);
431  if(!foundPoint){
432  CTPPSPixelLocalTrack badTrack;
433  badTrack.setValid(false);
434  return badTrack;
435  }
436  double xResidual = globalPoint.x() - pointOnDet.x();
437  double yResidual = globalPoint.y() - pointOnDet.y();
438  LocalPoint residuals(xResidual,yResidual);
439 
440  math::Error<3>::type globalError(hit.globalError);
441  LocalPoint pulls(xResidual/std::sqrt(globalError(0, 0)),yResidual/std::sqrt(globalError(0, 0)));
442 
443  CTPPSPixelFittedRecHit fittedRecHit(hit.recHit, pointOnDet, residuals, pulls);
444  fittedRecHit.setIsUsedForFit(true);
445  goodTrack.addHit(hit.detId, fittedRecHit);
446  }
447 
448  return goodTrack;
449 
450 }
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 87 of file RPixPlaneCombinatoryTracking.cc.

References mps_fire::i.

Referenced by produceAllHitCombination().

93 {
94  //At this point I selected one hit per plane
95  if (mapIterator == mapOfAllHits.end())
96  {
97  outputMap[tmpHitPlaneMap] = tmpHitVector;
98  return;
99  }
100  for (size_t i=0; i<mapIterator->second.size(); i++){
101  HitReferences newHitPlaneMap = tmpHitPlaneMap;
102  newHitPlaneMap[mapIterator->first] = i;
103  PointInPlaneList newVector = tmpHitVector;
104  newVector.push_back(mapIterator->second[i]);
105  std::map<CTPPSPixelDetId, PointInPlaneList >::iterator tmpMapIterator = mapIterator;
106  getHitCombinations(mapOfAllHits, ++tmpMapIterator, newHitPlaneMap, newVector, outputMap);
107  }
108 }
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 62 of file RPixPlaneCombinatoryTracking.cc.

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

Referenced by findTracks(), and initialize().

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

Implements RPixDetTrackFinder.

Definition at line 39 of file RPixPlaneCombinatoryTracking.cc.

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

39  {
40 
41  uint32_t numberOfCombinations = factorial(numberOfPlanesPerPot_)/
44  if(verbosity_>=2) edm::LogInfo("RPixPlaneCombinatoryTracking")<<"Number of combinations = "<<numberOfCombinations;
45  possiblePlaneCombinations_.reserve(numberOfCombinations);
46 
48 
49  if(verbosity_>=2) {
50  for( const auto & vec : possiblePlaneCombinations_){
51  for( const auto & num : vec){
52  edm::LogInfo("RPixPlaneCombinatoryTracking")<<num<<" - ";
53  }
54  edm::LogInfo("RPixPlaneCombinatoryTracking");
55  }
56  }
57 }
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 498 of file RPixPlaneCombinatoryTracking.cc.

References functionForPlaneOrdering().

Referenced by findTracks(), and functionForPlaneOrdering().

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

Definition at line 113 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().

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