CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
RoadSearchTrackCandidateMakerAlgorithm Class Reference

#include <RoadSearchTrackCandidateMakerAlgorithm.h>

Public Member Functions

bool chooseStartingLayers (std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > > &RecHitsByLayer, std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > >::iterator ilyr0, const std::multimap< int, const DetLayer * > &layer_map, std::set< const DetLayer * > &good_layers, std::vector< const DetLayer * > &middle_layers, RoadSearchCloud::RecHitVector &recHits_middle)
 
Trajectory createSeedTrajectory (FreeTrajectoryState &fts, const TrackingRecHit *InnerHit, const DetLayer *innerHitLayer)
 
std::vector< TrajectoryextrapolateTrajectory (const Trajectory &inputTrajectory, RoadSearchCloud::RecHitVector &theLayerHits, const DetLayer *innerHitLayer, const TrackingRecHit *outerHit, const DetLayer *outerHitLayer)
 
std::vector
< TrajectoryMeasurement
FindBestHit (const TrajectoryStateOnSurface &tsosBefore, const std::set< const GeomDet * > &theDets, edm::OwnVector< TrackingRecHit > &theHits)
 
std::vector
< TrajectoryMeasurement
FindBestHits (const TrajectoryStateOnSurface &tsosBefore, const std::set< const GeomDet * > &theDets, const SiStripRecHitMatcher *theHitMatcher, edm::OwnVector< TrackingRecHit > &theHits)
 
std::vector
< TrajectoryMeasurement
FindBestHitsByDet (const TrajectoryStateOnSurface &tsosBefore, const std::set< const GeomDet * > &theDets, edm::OwnVector< TrackingRecHit > &theHits)
 
FreeTrajectoryState initialTrajectory (const edm::EventSetup &es, const TrackingRecHit *InnerHit, const TrackingRecHit *OuterHit)
 
FreeTrajectoryState initialTrajectoryFromTriplet (const edm::EventSetup &es, const TrackingRecHit *InnerHit, const TrackingRecHit *MiddleHit, const TrackingRecHit *OuterHit)
 
TrackCandidateCollection PrepareTrackCandidates (std::vector< Trajectory > &theTrajectories)
 
 RoadSearchTrackCandidateMakerAlgorithm (const edm::ParameterSet &conf)
 
void run (const RoadSearchCloudCollection *input, const edm::Event &e, const edm::EventSetup &es, TrackCandidateCollection &output)
 Runs the algorithm. More...
 
 ~RoadSearchTrackCandidateMakerAlgorithm ()
 

Private Attributes

edm::ParameterSet conf_
 
bool CosmicReco_
 
double cosmicSeedPt_
 
bool CosmicTrackMerging_
 
bool debug_
 
bool debugCosmics_
 
double initialVertexErrorXY_
 
bool lstereo [128]
 
const MagneticFieldmagField
 
double maxPropagationDistance
 
std::string measurementTrackerName_
 
int MinChunkLength_
 
int nFoundMin_
 
bool NoFieldCosmic_
 
bool splitMatchedHits_
 
PropagatorWithMaterialtheAloPropagator
 
AnalyticalPropagatortheAnalyticalPropagator
 
double theChi2Cut
 
MeasurementEstimatortheEstimator
 
SiStripRecHitMatchertheHitMatcher
 
const MeasurementTrackertheMeasurementTracker
 
unsigned int theNumHitCut
 
PropagatorWithMaterialthePropagator
 
PropagatorWithMaterialtheRevPropagator
 
KFTrajectorySmoothertheSmoother
 
TrajectoryCleanerBySharedHitstheTrajectoryCleaner
 
TrajectoryStateTransformtheTransformer
 
TrajectoryStateUpdatortheUpdator
 
const TrackerGeometrytrackerGeom
 
const
TransientTrackingRecHitBuilder
ttrhBuilder
 

Detailed Description

Definition at line 52 of file RoadSearchTrackCandidateMakerAlgorithm.h.

Constructor & Destructor Documentation

RoadSearchTrackCandidateMakerAlgorithm::RoadSearchTrackCandidateMakerAlgorithm ( const edm::ParameterSet conf)

Definition at line 73 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References Chi2MeasurementEstimatorESProducer_cfi::Chi2MeasurementEstimator, conf_, CosmicReco_, cosmicSeedPt_, CosmicTrackMerging_, debug_, debugCosmics_, edm::ParameterSet::getParameter(), initialVertexErrorXY_, maxPropagationDistance, measurementTrackerName_, MinChunkLength_, nFoundMin_, splitMatchedHits_, theChi2Cut, theEstimator, theNumHitCut, theTrajectoryCleaner, theTransformer, and theUpdator.

73  : conf_(conf) {
74 
75  theNumHitCut = (unsigned int)conf_.getParameter<int>("NumHitCut");
76  theChi2Cut = conf_.getParameter<double>("HitChi2Cut");
77 
79  theUpdator = new KFUpdator();
82 
83  CosmicReco_ = conf_.getParameter<bool>("StraightLineNoBeamSpotCloud");
84  CosmicTrackMerging_ = conf_.getParameter<bool>("CosmicTrackMerging");
85  MinChunkLength_ = conf_.getParameter<int>("MinimumChunkLength");
86  nFoundMin_ = conf_.getParameter<int>("nFoundMin");
87 
88  initialVertexErrorXY_ = conf_.getParameter<double>("InitialVertexErrorXY");
89  splitMatchedHits_ = conf_.getParameter<bool>("SplitMatchedHits");
90  cosmicSeedPt_ = conf_.getParameter<double>("CosmicSeedPt");
91 
92  measurementTrackerName_ = conf_.getParameter<std::string>("MeasurementTrackerName");
93 
94  debug_ = false;
95  debugCosmics_ = false;
96 
97  maxPropagationDistance = 1000.0; // 10m
98 }
T getParameter(std::string const &) const
RoadSearchTrackCandidateMakerAlgorithm::~RoadSearchTrackCandidateMakerAlgorithm ( )

Definition at line 100 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References theEstimator, theTrajectoryCleaner, theTransformer, and theUpdator.

100  {
101  delete theEstimator;
102  delete theUpdator;
103  delete theTransformer;
104  delete theTrajectoryCleaner;
105  // delete theMeasurementTracker;
106 
107 }

Member Function Documentation

bool RoadSearchTrackCandidateMakerAlgorithm::chooseStartingLayers ( std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > > &  RecHitsByLayer,
std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > >::iterator  ilyr0,
const std::multimap< int, const DetLayer * > &  layer_map,
std::set< const DetLayer * > &  good_layers,
std::vector< const DetLayer * > &  middle_layers,
RoadSearchCloud::RecHitVector recHits_middle 
)

Definition at line 1191 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References CosmicReco_, lstereo, and nFoundMin_.

Referenced by run().

1198 {
1199  const unsigned int max_middle_layers = 2;
1200 
1201  // consider the best nFoundMin layers + other layers with only one hit
1202  // This has implications, based on the way we locate the hits.
1203  // For now, use only the low occupancy layers in the first pass
1204  //const int nfound_min = min_chunk_length-1;
1205  //const int nfound_min = 4;
1206  std::multimap<int, const DetLayer*>::const_iterator ilm = layer_map.begin();
1207  int ngoodlayers = 0;
1208  while (ilm != layer_map.end()) {
1209  if (ngoodlayers >= nFoundMin_ && ilm->first > 1) break;
1210  //if (ilm->first > 1) break;
1211  good_layers.insert(ilm->second);
1212  ++ngoodlayers;
1213  ++ilm;
1214  }
1215 
1216  // choose intermediate layers
1217  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilayer = ilyr0+1;
1218  ilayer != recHitsByLayer.end(); ++ilayer) {
1219  // only use useful layers
1220  if (good_layers.find(ilayer->first) == good_layers.end()) continue;
1221  // only use stereo layers
1222  if (!CosmicReco_ && !lstereo[ilayer-recHitsByLayer.begin()]) continue;
1223  middle_layers.push_back(ilayer->first);
1224  if (middle_layers.size() >= max_middle_layers) break;
1225  }
1226 
1227  for (std::vector<const DetLayer*>::iterator ml = middle_layers.begin();
1228  ml!=middle_layers.end();++ml){
1229  unsigned int middle_layers_found = 0;
1230  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr = recHitsByLayer.begin();
1231  ilyr != recHitsByLayer.end(); ++ilyr) {
1232  if (ilyr->first == *ml){
1233  for (RoadSearchCloud::RecHitVector::const_iterator ih = ilyr->second.begin();
1234  ih != ilyr->second.end(); ++ih) {
1235  recHits_middle.push_back(*ih);
1236  }
1237  ++middle_layers_found;
1238  }
1239  if (middle_layers_found == middle_layers.size()) continue;
1240  }
1241 
1242  }
1243  return (recHits_middle.size()>0);
1244 }
Trajectory RoadSearchTrackCandidateMakerAlgorithm::createSeedTrajectory ( FreeTrajectoryState fts,
const TrackingRecHit InnerHit,
const DetLayer innerHitLayer 
)

Definition at line 1407 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References alongMomentum, TransientTrackingRecHitBuilder::build(), gather_cfg::cout, debug_, TrajectorySeed::direction(), MeasurementEstimator::estimate(), TrajectoryStateOnSurface::globalMomentum(), TrackerGeometry::idToDet(), edm::detail::isnan(), TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localDirection(), SiStripRecHitMatcher::match(), oppositeToMomentum, PV3DBase< T, PVType, FrameType >::perp(), TrajectoryStateTransform::persistentState(), PropagatorWithMaterial::propagate(), Propagator::propagationDirection(), Trajectory::push(), edm::OwnVector< T, P >::push_back(), GeomDet::surface(), theEstimator, theHitMatcher, thePropagator, theTransformer, theUpdator, trackerGeom, ttrhBuilder, and TrajectoryStateUpdator::update().

Referenced by run().

1411 {
1412  Trajectory theSeedTrajectory;
1413 
1414  // Need to put the first hit on the trajectory
1415  const GeomDet* innerDet = trackerGeom->idToDet((theInnerHit)->geographicalId());
1416  const TrajectoryStateOnSurface innerState =
1417  thePropagator->propagate(fts,innerDet->surface());
1418  if ( !innerState.isValid() ||
1419  std::isnan(innerState.globalMomentum().perp())) {
1420  if (debug_) std::cout<<"*******DISASTER ********* seed doesn't make it to first hit!!!!!" << std::endl;
1421  return theSeedTrajectory;
1422  }
1424  // if this first hit is a matched hit, it should be updated for the trajectory
1425  const SiStripMatchedRecHit2D *origHit = dynamic_cast<const SiStripMatchedRecHit2D *>(theInnerHit);
1426  if (origHit !=0){
1427  const GluedGeomDet *gdet = dynamic_cast<const GluedGeomDet*>(innerDet);
1428  const SiStripMatchedRecHit2D *corrHit = theHitMatcher->match(origHit,gdet,innerState.localDirection());
1429  if (corrHit!=0){
1430  intrhit = ttrhBuilder->build(&(*corrHit));
1431  delete corrHit;
1432  }
1433  }
1434 
1435  MeasurementEstimator::HitReturnType est = theEstimator->estimate(innerState, *intrhit);
1436  if (!est.first) return theSeedTrajectory;
1437  TrajectoryStateOnSurface innerUpdated= theUpdator->update( innerState,*intrhit);
1438  if (debug_) std::cout<<"InnerUpdated: " << innerUpdated << std::endl;
1439  if (!innerUpdated.isValid() ||
1440  std::isnan(innerUpdated.globalMomentum().perp())) {
1441  if (debug_) std::cout<<"Trajectory updated with first hit is invalid!!!" << std::endl;
1442  return theSeedTrajectory;
1443  }
1444  TrajectoryMeasurement tm = TrajectoryMeasurement(innerState, innerUpdated, &(*intrhit),est.second,theInnerHitLayer);
1445 
1446  PTrajectoryStateOnDet* pFirstStateTwo = theTransformer->persistentState(innerUpdated,
1447  intrhit->geographicalId().rawId());
1448  edm::OwnVector<TrackingRecHit> newHitsTwo;
1449  newHitsTwo.push_back(intrhit->hit()->clone());
1450 
1451  TrajectorySeed tmpseedTwo = TrajectorySeed(*pFirstStateTwo,
1452  newHitsTwo,
1453  alongMomentum);
1455  tmpseedTwo = TrajectorySeed(*pFirstStateTwo,
1456  newHitsTwo,
1458  }
1459 
1460  delete pFirstStateTwo;
1461 
1462  //Trajectory seedTraj(tmpseedTwo, alongMomentum);
1463  theSeedTrajectory = Trajectory(tmpseedTwo, tmpseedTwo.direction());
1464 
1465  theSeedTrajectory.push(tm,est.second);
1466 
1467  return theSeedTrajectory;
1468 }
PropagationDirection direction() const
T perp() const
Definition: PV3DBase.h:66
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:143
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
SiStripMatchedRecHit2D * match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection) const
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
LocalVector localDirection() const
void push_back(D *&d)
Definition: OwnVector.h:290
bool isnan(float x)
Definition: math.h:13
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
PTrajectoryStateOnDet * persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid) const
virtual const GeomDet * idToDet(DetId) const
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
std::pair< bool, double > HitReturnType
GlobalVector globalMomentum() const
tuple cout
Definition: gather_cfg.py:41
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::vector< Trajectory > RoadSearchTrackCandidateMakerAlgorithm::extrapolateTrajectory ( const Trajectory inputTrajectory,
RoadSearchCloud::RecHitVector theLayerHits,
const DetLayer innerHitLayer,
const TrackingRecHit outerHit,
const DetLayer outerHitLayer 
)

Definition at line 1472 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References TransientTrackingRecHitBuilder::build(), gather_cfg::cout, debug_, GeometricSearchTracker::detLayer(), MeasurementEstimator::estimate(), MeasurementTracker::geometricSearchTracker(), TrajectoryStateOnSurface::globalPosition(), TrackerGeometry::idToDet(), TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localDirection(), TrajectoryStateOnSurface::localError(), TrackingRecHit::localPosition(), TrajectoryStateOnSurface::localPosition(), LogDebug, PV3DBase< T, PVType, FrameType >::mag(), SiStripRecHitMatcher::match(), maxPropagationDistance, Trajectory::measurements(), p1, p2, PV3DBase< T, PVType, FrameType >::perp(), GloballyPositioned< T >::position(), LocalTrajectoryError::positionError(), PropagatorWithMaterial::propagate(), Trajectory::push(), mathSSE::sqrt(), GeomDet::surface(), theEstimator, theHitMatcher, theMeasurementTracker, thePropagator, theUpdator, trackerGeom, ttrhBuilder, TrajectoryStateUpdator::update(), PV3DBase< T, PVType, FrameType >::x(), LocalError::xx(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by run().

1477 {
1478  std::vector<Trajectory> newTrajectories;
1479 
1480  for(RoadSearchCloud::RecHitVector::const_iterator ihit = theLayerHits.begin();
1481  ihit != theLayerHits.end(); ihit++) {
1482  Trajectory traj = theTrajectory;
1483  const DetLayer* thisLayer =
1484  theMeasurementTracker->geometricSearchTracker()->detLayer((*ihit)->geographicalId());
1485  if (thisLayer == innerHitLayer){
1486  // Right now we are assuming that ONLY single hit layers are in this initial collection
1487  //if (thisLayer == innerHitLayer && !(ihit->recHit() == innerHit->recHit())){
1488  // if (debug_) std::cout<<"On inner hit layer, but have wrong hit?!?!?" << std::endl;
1489  continue;
1490  }
1491  if (thisLayer == outerHitLayer){
1492  LocalPoint p1 = (*ihit)->localPosition();
1493  LocalPoint p2 = outerHit->localPosition();
1494  if (p1.x()!=p2.x() || p1.y()!=p2.y()) continue;
1495  }
1496  // extrapolate
1497 
1499 
1500  if (debug_){
1501  if (rhit->isValid()) {
1502  LogDebug("RoadSearch") << "RecHit " << ihit-theLayerHits.begin()
1503  << ", det " << rhit->det() << ", r/phi/z = "
1504  << rhit->globalPosition().perp() << " "
1505  << rhit->globalPosition().phi() << " "
1506  << rhit->globalPosition().z();
1507  } else {
1508  LogDebug("RoadSearch") << "RecHit " << ihit-theLayerHits.begin()
1509  << " (invalid)";
1510  }
1511  }
1512 
1513  const GeomDet* det = trackerGeom->idToDet(rhit->geographicalId());
1514 
1515  TrajectoryStateOnSurface predTsos;
1516  TrajectoryStateOnSurface currTsos;
1517 
1518  if (traj.measurements().empty()) {
1519  //predTsos = thePropagator->propagate(fts, det->surface());
1520  if (debug_) std::cout<<"BIG ERROR!!! How did we make it to here with no trajectory measurements?!?!?"<<std::endl;
1521  } else {
1522  currTsos = traj.measurements().back().updatedState();
1523  predTsos = thePropagator->propagate(currTsos, det->surface());
1524  }
1525  if (!predTsos.isValid()){
1526  continue;
1527  }
1528  GlobalVector propagationDistance = predTsos.globalPosition() - currTsos.globalPosition();
1529  if (propagationDistance.mag() > maxPropagationDistance) continue;
1530  if (debug_) {
1531  std::cout << "currTsos (x/y/z): "
1532  << currTsos.globalPosition().x() << " / "
1533  << currTsos.globalPosition().y() << " / "
1534  << currTsos.globalPosition().z() << std::endl;
1535  std::cout << "predTsos (x/y/z): "
1536  << predTsos.globalPosition().x() << " / "
1537  << predTsos.globalPosition().y() << " / "
1538  << predTsos.globalPosition().z() << std::endl;
1539  std::cout << "Propagation distance1 is " << propagationDistance.mag() << std::endl;
1540  }
1542  if (debug_){
1543  std::cout<< "trajectory at r/z=" << det->surface().position().perp()
1544  << " " << det->surface().position().z()
1545  << ", hit " << ihit-theLayerHits.begin()
1546  << " local prediction " << predTsos.localPosition().x()
1547  << " +- " << sqrt(predTsos.localError().positionError().xx())
1548  << ", hit at " << rhit->localPosition().x() << " +- " << sqrt(rhit->localPositionError().xx())
1549  << std::endl;
1550  }
1551 
1552  // update
1553  // first correct for angle
1554 
1555  const SiStripMatchedRecHit2D *origHit = dynamic_cast<const SiStripMatchedRecHit2D *>(*ihit);
1556  if (origHit !=0){
1557  const GluedGeomDet *gdet = dynamic_cast<const GluedGeomDet*>(rhit->det());
1558  const SiStripMatchedRecHit2D *corrHit = theHitMatcher->match(origHit,gdet,predTsos.localDirection());
1559  if (corrHit!=0){
1560  rhit = ttrhBuilder->build(&(*corrHit));
1561  delete corrHit;
1562  }
1563  }
1564 
1566  if (debug_) std::cout << "estimation: " << est.first << " " << est.second << std::endl;
1567  if (!est.first) continue;
1568  currTsos = theUpdator->update(predTsos, *rhit);
1569  tm = TrajectoryMeasurement(predTsos, currTsos, &(*rhit),est.second,thisLayer);
1570  traj.push(tm,est.second);
1571  newTrajectories.push_back(traj);
1572 
1573 
1574  }
1575 
1576  return newTrajectories;
1577 }
#define LogDebug(id)
float xx() const
Definition: LocalError.h:19
T perp() const
Definition: PV3DBase.h:66
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
SiStripMatchedRecHit2D * match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection) const
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
LocalVector localDirection() const
T y() const
Definition: PV3DBase.h:57
GlobalPoint globalPosition() const
LocalError positionError() const
DataContainer const & measurements() const
Definition: Trajectory.h:169
T mag() const
Definition: PV3DBase.h:61
T sqrt(T t)
Definition: SSEVec.h:28
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
T z() const
Definition: PV3DBase.h:58
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
const LocalTrajectoryError & localError() const
double p2[4]
Definition: TauolaWrapper.h:90
virtual const GeomDet * idToDet(DetId) const
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
std::pair< bool, double > HitReturnType
double p1[4]
Definition: TauolaWrapper.h:89
tuple cout
Definition: gather_cfg.py:41
const GeometricSearchTracker * geometricSearchTracker() const
T x() const
Definition: PV3DBase.h:56
virtual LocalPoint localPosition() const =0
const PositionType & position() const
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::vector< TrajectoryMeasurement > RoadSearchTrackCandidateMakerAlgorithm::FindBestHit ( const TrajectoryStateOnSurface tsosBefore,
const std::set< const GeomDet * > &  theDets,
edm::OwnVector< TrackingRecHit > &  theHits 
)

Definition at line 897 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References edm::OwnVector< T, P >::begin(), TransientTrackingRecHitBuilder::build(), gather_cfg::cout, debug_, GeometricSearchTracker::detLayer(), edm::OwnVector< T, P >::end(), MeasurementEstimator::estimate(), MeasurementTracker::geometricSearchTracker(), TrajectoryStateOnSurface::globalPosition(), TrackerGeometry::idToDet(), TrajectoryStateOnSurface::isValid(), PV3DBase< T, PVType, FrameType >::mag(), maxPropagationDistance, PropagatorWithMaterial::propagate(), TrajectoryStateOnSurface::surface(), theEstimator, theMeasurementTracker, thePropagator, theUpdator, trackerGeom, ttrhBuilder, and TrajectoryStateUpdator::update().

900 {
901 
902  std::vector<TrajectoryMeasurement> theBestHits;
903 
904  double bestchi = 10000.0;
905  // extrapolate to all detectors from the list
906  std::map<const GeomDet*, TrajectoryStateOnSurface> dmmap;
907  for (std::set<const GeomDet*>::iterator idet = theDets.begin();
908  idet != theDets.end(); ++idet) {
909  TrajectoryStateOnSurface predTsos = thePropagator->propagate(tsosBefore, (**idet).surface());
910  if (predTsos.isValid()) {
911  GlobalVector propagationDistance = predTsos.globalPosition() - tsosBefore.globalPosition();
912  if (propagationDistance.mag() > maxPropagationDistance) continue;
913  dmmap.insert(std::make_pair(*idet, predTsos));
914  }
915  }
916  // evaluate hit residuals
917  std::map<const GeomDet*, TrajectoryMeasurement> dtmmap;
919  ih != theHits.end(); ++ih) {
920  const GeomDet* det = trackerGeom->idToDet(ih->geographicalId());
921 
922  std::map<const GeomDet*, TrajectoryStateOnSurface>::iterator idm = dmmap.find(det);
923  if (idm == dmmap.end()) continue;
924  TrajectoryStateOnSurface predTsos = idm->second;
927 
928  // Take the best hit on any Det
929  if (est.first) {
930  TrajectoryStateOnSurface currTsos = theUpdator->update(predTsos, *rhit);
931  if (est.second < bestchi){
932  if(!theBestHits.empty()){
933  theBestHits.erase(theBestHits.begin());
934  }
935  bestchi = est.second;
936  TrajectoryMeasurement tm(predTsos, currTsos, &(*rhit),est.second,
937  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
938  theBestHits.push_back(tm);
939  }
940  }
941  }
942 
943  if (theBestHits.empty()){
944  if (debug_) std::cout<< "no hits to add! " <<std::endl;
945  }
946  else{
947  for (std::vector<TrajectoryMeasurement>::const_iterator im=theBestHits.begin();im!=theBestHits.end();++im)
948  if (debug_) std::cout<<" Measurement on layer "
949  << theMeasurementTracker->geometricSearchTracker()->detLayer(im->recHit()->geographicalId())
950  << " with estimate " << im->estimate()<<std::endl ;
951  }
952 
953  return theBestHits;
954 }
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
GlobalPoint globalPosition() const
iterator begin()
Definition: OwnVector.h:236
T mag() const
Definition: PV3DBase.h:61
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
virtual const GeomDet * idToDet(DetId) const
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
std::pair< bool, double > HitReturnType
iterator end()
Definition: OwnVector.h:243
const Surface & surface() const
tuple cout
Definition: gather_cfg.py:41
const GeometricSearchTracker * geometricSearchTracker() const
std::vector< TrajectoryMeasurement > RoadSearchTrackCandidateMakerAlgorithm::FindBestHits ( const TrajectoryStateOnSurface tsosBefore,
const std::set< const GeomDet * > &  theDets,
const SiStripRecHitMatcher theHitMatcher,
edm::OwnVector< TrackingRecHit > &  theHits 
)

Definition at line 957 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References edm::OwnVector< T, P >::begin(), TransientTrackingRecHitBuilder::build(), gather_cfg::cout, debug_, GeometricSearchTracker::detLayer(), edm::OwnVector< T, P >::end(), MeasurementEstimator::estimate(), TrajectoryMeasurement::estimate(), MeasurementTracker::geometricSearchTracker(), TrajectoryStateOnSurface::globalPosition(), TrackerGeometry::idToDet(), TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localDirection(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localPosition(), PV3DBase< T, PVType, FrameType >::mag(), SiStripRecHitMatcher::match(), maxPropagationDistance, LocalTrajectoryError::positionError(), PropagatorWithMaterial::propagate(), TrajectoryMeasurement::recHit(), python.multivaluedict::sort(), mathSSE::sqrt(), GeomDet::surface(), TrajectoryStateOnSurface::surface(), theEstimator, theMeasurementTracker, thePropagator, theUpdator, trackerGeom, ttrhBuilder, TrajectoryStateUpdator::update(), PV3DBase< T, PVType, FrameType >::x(), LocalError::xx(), PV3DBase< T, PVType, FrameType >::y(), LocalError::yy(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by run().

962 {
963 
964 
965  std::vector<TrajectoryMeasurement> theBestHits;
966  //TrajectoryMeasurement* theBestTM = 0;
967  TrajectoryMeasurement theBestTM;
968  bool firstTM = true;
969 
970  // extrapolate to all detectors from the list
971  std::map<const GeomDet*, TrajectoryStateOnSurface> dmmap;
972  for (std::set<const GeomDet*>::iterator idet = theDets.begin();
973  idet != theDets.end(); ++idet) {
974  TrajectoryStateOnSurface predTsos = thePropagator->propagate(tsosBefore, (**idet).surface());
975  if (predTsos.isValid()) {
976  GlobalVector propagationDistance = predTsos.globalPosition() - tsosBefore.globalPosition();
977  if (propagationDistance.mag() > maxPropagationDistance) continue;
978  dmmap.insert(std::make_pair(*idet, predTsos));
979  }
980  }
981 
982  if(debug_) std::cout << "TRAJECTORY INTERSECTS " << dmmap.size() << " DETECTORS." << std::endl;
983 
984  // evaluate hit residuals
985  std::map<const GeomDet*, TrajectoryMeasurement> dtmmap;
986  for (edm::OwnVector<TrackingRecHit>::const_iterator ih = theHits.begin(); ih != theHits.end(); ++ih) {
987  const GeomDet* det = trackerGeom->idToDet(ih->geographicalId());
988  //if (*isl != theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()))
989  // std::cout <<" You don't know what you're doing !!!!" << std::endl;
990 
991  std::map<const GeomDet*, TrajectoryStateOnSurface>::iterator idm = dmmap.find(det);
992  if (idm == dmmap.end()) continue;
993  TrajectoryStateOnSurface predTsos = idm->second;
995 
996  const SiStripMatchedRecHit2D *origHit = dynamic_cast<const SiStripMatchedRecHit2D *>(&(*ih));
997  if (origHit !=0){
998  const GluedGeomDet *gdet = dynamic_cast<const GluedGeomDet*>(det);
999  const SiStripMatchedRecHit2D *corrHit = theHitMatcher->match(origHit,gdet,predTsos.localDirection());
1000  if (corrHit!=0){
1001  rhit = ttrhBuilder->build(&(*corrHit));
1002  delete corrHit;
1003  }
1004  }
1005 
1006  if (debug_) {
1007  std::cout << "predTSOS (x/y/z): " << predTsos.globalPosition().x()<< " / " << predTsos.globalPosition().y()<< " / " << predTsos.globalPosition().z() << std::endl;
1008  std::cout << "local position x: " << predTsos.localPosition().x() << "+-" << sqrt(predTsos.localError().positionError().xx()) << std::endl;
1009  std::cout << "local position y: " << predTsos.localPosition().y() << "+-" << sqrt(predTsos.localError().positionError().yy()) << std::endl;
1010  std::cout << "rhit local position x: " << rhit->localPosition().x() << "+-" << sqrt(rhit->localPositionError().xx()) << std::endl;
1011  std::cout << "rhit local position y: " << rhit->localPosition().y() << "+-" << sqrt(rhit->localPositionError().yy()) << std::endl;
1012  }
1013 
1015  if (debug_) std::cout<< "hit " << ih-theHits.begin()
1016  << ": est = " << est.first << " " << est.second <<std::endl;
1017 
1018 
1019  // Take the best hit on a given Det
1020  if (est.first) {
1022  TrajectoryStateOnSurface currTsos = theUpdator->update(predTsos, *rhit);
1023  std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.find(det);
1024  if (idtm == dtmmap.end()) {
1025  tm = TrajectoryMeasurement (predTsos, currTsos, &(*rhit),est.second,
1026  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
1027  dtmmap.insert(std::make_pair(det, tm));
1028  } else if (idtm->second.estimate() > est.second) {
1029  dtmmap.erase(idtm);
1030  tm = TrajectoryMeasurement(predTsos, currTsos, &(*rhit),est.second,
1031  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
1032  dtmmap.insert(std::make_pair(det, tm));
1033  }
1034  if ((firstTM)){
1035  theBestTM = tm;
1036  if (debug_) std::cout <<"Initialize best to " << theBestTM.estimate() << std::endl;
1037  firstTM = false;
1038  }
1039  else if (!firstTM) {
1040  if (debug_) std::cout << "Current best is " << theBestTM.estimate() << " while this hit is " << est.second;
1041  if (est.second < theBestTM.estimate()) {
1042  if (debug_) std::cout << " so replace it " ;
1043  theBestTM = tm;
1044  }
1045  if (debug_) std::cout << std::endl;
1046  }
1047  }
1048  }
1049  if (debug_) std::cout<< "Hits(Dets) to add: " << dtmmap.size() <<std::endl;
1050  if (!dtmmap.empty()) {
1051 
1052  std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer, TrajectoryMeasurement*> > OverlapHits;
1053  for (std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.begin();
1054  idtm != dtmmap.end(); ++idtm) {
1055  OverlapHits.push_back(std::make_pair(idtm->second.recHit(),&idtm->second));
1056 
1057  if (debug_) std::cout<<" Measurement on layer "
1058  << theMeasurementTracker->geometricSearchTracker()->detLayer(idtm->second.recHit()->geographicalId())
1059  << " with estimate " << idtm->second.estimate()<<std::endl ;
1060  }
1061  if (debug_)
1062  std::cout<<" Best Measurement is on layer "
1063  << theMeasurementTracker->geometricSearchTracker()->detLayer(theBestTM.recHit()->geographicalId())
1064  << " with estimate " << theBestTM.estimate()<<std::endl ;
1065 
1066 
1067  if (dtmmap.size()==1){ // only one hit so we can just return that one
1068  for (std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.begin();
1069  idtm != dtmmap.end(); ++idtm) {
1070  TrajectoryMeasurement itm = idtm->second;
1071  if (debug_) std::cout<<" Measurement on layer "
1072  << theMeasurementTracker->geometricSearchTracker()->detLayer(itm.recHit()->geographicalId())
1073  << " with estimate " << itm.estimate()<<std::endl ;
1074  theBestHits.push_back(itm);
1075  }
1076  }
1077  else if (dtmmap.size()>=2) { // try for the overlaps -- first have to sort inside out
1078 
1079  if (debug_) std::cout<<"Unsorted OverlapHits has size " <<OverlapHits.size() << std::endl;
1080 
1081  for (std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer,TrajectoryMeasurement*> >::iterator irh =OverlapHits.begin();
1082  irh!=OverlapHits.end();++irh){
1083  if (debug_) std::cout << "Hit " << irh-OverlapHits.begin()
1084  << " on det " << irh->first->det()
1085  << " detLayer "
1086  << theMeasurementTracker->geometricSearchTracker()->detLayer(irh->first->geographicalId())
1087  << ", r/phi/z = "
1088  << irh->first->globalPosition().perp() << " "
1089  << irh->first->globalPosition().phi() << " "
1090  << irh->first->globalPosition().z()
1091  << std::endl;
1092  }
1093 
1094  std::sort( OverlapHits.begin(),OverlapHits.end(),SortHitTrajectoryPairsByGlobalPosition());
1095  if (debug_) std::cout<<"Sorted OverlapHits has size " <<OverlapHits.size() << std::endl;
1096 
1097  float workingBestChi2 = 1000000.0;
1098  std::vector<TrajectoryMeasurement> workingBestHits;
1099 
1100  std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer,TrajectoryMeasurement*> >::iterator irh1;
1101  std::vector<std::pair<TransientTrackingRecHit::ConstRecHitPointer,TrajectoryMeasurement*> >::iterator irh2;
1102  for (irh1 =OverlapHits.begin(); irh1!=--OverlapHits.end(); ++irh1){
1103  theBestHits.clear();
1104  float running_chi2=0;
1105  if (debug_) std::cout << "Hit " << irh1-OverlapHits.begin()
1106  << " on det " << irh1->first->det()
1107  << " detLayer "
1108  << theMeasurementTracker->geometricSearchTracker()->detLayer(irh1->first->geographicalId())
1109  << ", r/phi/z = "
1110 
1111  << irh1->first->globalPosition().perp() << " "
1112  << irh1->first->globalPosition().phi() << " "
1113  << irh1->first->globalPosition().z()
1114  << std::endl;
1115 
1116  TrajectoryStateOnSurface currTsos = irh1->second->updatedState();
1118  theBestHits.push_back(*(irh1->second));
1119  if (debug_) std::cout<<"Added first hit with chi2 = " << irh1->second->estimate() << std::endl;
1120  running_chi2 += irh1->second->estimate();
1121  for (irh2 = irh1; irh2!=OverlapHits.end(); ++irh2){
1122  if (irh2 == irh1) continue;
1124  const GeomDet* det = irh2->first->det();
1125  // extrapolate the trajectory to the next hit
1126  TrajectoryStateOnSurface predTsos = thePropagator->propagate(currTsos, det->surface());
1127  // test if matches
1128  if (predTsos.isValid()){
1130  if (debug_) std::cout<<"Added overlap hit with est = " << est.first << " " << est.second << std::endl;
1131  if (est.first){
1132  TrajectoryMeasurement tm(predTsos, currTsos, &(*rh),est.second,
1133  theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()));
1134  theBestHits.push_back(tm);
1135  running_chi2 += est.second ;
1136  }
1137  else { // couldn't add 2nd hit so return best single hit
1138  }
1139  }
1140 
1141  }
1142  if (theBestHits.size()==dtmmap.size()){ // added the best hit in every layer
1143  if (debug_) std::cout<<"Added all "<<theBestHits.size()<<" hits out of " << dtmmap.size() << std::endl;
1144  break;
1145  }
1146  // Didn't add hits from every Det
1147  if (theBestHits.size() < dtmmap.size()){
1148  if (debug_) std::cout<<"Added only "<<theBestHits.size()<<" hits out of " << dtmmap.size() << std::endl;
1149  // Take the combination with the most hits
1150  if (theBestHits.size() > workingBestHits.size()){
1151  if (debug_) std::cout<<"Current combo has more hits so replace best" << std::endl;
1152  workingBestHits = theBestHits;
1153  }
1154  // has same number of hits as best, so check chi2
1155  else if (theBestHits.size() == workingBestHits.size()){
1156  if (running_chi2< workingBestChi2){
1157  if (debug_) std::cout<<"Current combo has same # of hits but lower chi2 so replace best" << std::endl;
1158  workingBestHits = theBestHits;
1159  workingBestChi2 = running_chi2;
1160  }
1161  }
1162  }
1163  }
1164  if (theBestHits.size()<2){
1165  if (debug_) std::cout<<"Only one good hit in overlap"<<std::endl;
1166  if (debug_) std::cout<<" Added hit on layer on det "
1167  << theBestTM.recHit()->det()
1168  << " detLayer "
1169  << theMeasurementTracker->geometricSearchTracker()->detLayer(theBestTM.recHit()->geographicalId())
1170  << ", r/phi/z = "
1171  << theBestTM.recHit()->globalPosition().perp() << " "
1172  << theBestTM.recHit()->globalPosition().phi() << " "
1173  << theBestTM.recHit()->globalPosition().z()
1174  << " with estimate " << theBestTM.estimate()<<std::endl ;
1175  theBestHits.clear();
1176  theBestHits.push_back(theBestTM);
1177  }
1178 
1179  }
1180  else {
1181  if (debug_)std::cout << "ERROR: Unexpected size from DTMMAP = " << dtmmap.size() << std::endl;
1182  theBestHits.push_back(theBestTM);
1183  }
1184  }
1185 
1186  return theBestHits;
1187 }
float xx() const
Definition: LocalError.h:19
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
SiStripMatchedRecHit2D * match(const SiStripRecHit2D *monoRH, const SiStripRecHit2D *stereoRH, const GluedGeomDet *gluedDet, LocalVector trackdirection) const
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
LocalVector localDirection() const
T y() const
Definition: PV3DBase.h:57
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
LocalError positionError() const
iterator begin()
Definition: OwnVector.h:236
T mag() const
Definition: PV3DBase.h:61
float yy() const
Definition: LocalError.h:21
T sqrt(T t)
Definition: SSEVec.h:28
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
T z() const
Definition: PV3DBase.h:58
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
const LocalTrajectoryError & localError() const
virtual const GeomDet * idToDet(DetId) const
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
std::pair< bool, double > HitReturnType
iterator end()
Definition: OwnVector.h:243
const Surface & surface() const
tuple cout
Definition: gather_cfg.py:41
const GeometricSearchTracker * geometricSearchTracker() const
T x() const
Definition: PV3DBase.h:56
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
std::vector< TrajectoryMeasurement > RoadSearchTrackCandidateMakerAlgorithm::FindBestHitsByDet ( const TrajectoryStateOnSurface tsosBefore,
const std::set< const GeomDet * > &  theDets,
edm::OwnVector< TrackingRecHit > &  theHits 
)

Definition at line 835 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References edm::OwnVector< T, P >::begin(), TransientTrackingRecHitBuilder::build(), GeometricSearchTracker::detLayer(), edm::OwnVector< T, P >::end(), MeasurementEstimator::estimate(), MeasurementTracker::geometricSearchTracker(), TrajectoryStateOnSurface::globalPosition(), TrackerGeometry::idToDet(), TrajectoryStateOnSurface::isValid(), PV3DBase< T, PVType, FrameType >::mag(), maxPropagationDistance, PropagatorWithMaterial::propagate(), TrajectoryStateOnSurface::surface(), theEstimator, theMeasurementTracker, thePropagator, theUpdator, trackerGeom, ttrhBuilder, and TrajectoryStateUpdator::update().

839 {
840 
841  //edm::OwnVector<TrackingRecHit> theBestHits;
842  std::vector<TrajectoryMeasurement> theBestHits;
843 
844  // extrapolate to all detectors from the list
845  std::map<const GeomDet*, TrajectoryStateOnSurface> dmmap;
846  for (std::set<const GeomDet*>::iterator idet = theDets.begin();
847  idet != theDets.end(); ++idet) {
848  TrajectoryStateOnSurface predTsos = thePropagator->propagate(tsosBefore, (**idet).surface());
849  if (predTsos.isValid()) {
850  GlobalVector propagationDistance = predTsos.globalPosition() - tsosBefore.globalPosition();
851  if (propagationDistance.mag() > maxPropagationDistance) continue;
852  dmmap.insert(std::make_pair(*idet, predTsos));
853  }
854  }
855  // evaluate hit residuals
856  std::map<const GeomDet*, TrajectoryMeasurement> dtmmap;
858  ih != theHits.end(); ++ih) {
859  const GeomDet* det = trackerGeom->idToDet(ih->geographicalId());
860 
861  std::map<const GeomDet*, TrajectoryStateOnSurface>::iterator idm = dmmap.find(det);
862  if (idm == dmmap.end()) continue;
863  TrajectoryStateOnSurface predTsos = idm->second;
866 
867  // Take the best hit on a given Det
868  if (est.first) {
869  TrajectoryStateOnSurface currTsos = theUpdator->update(predTsos, *rhit);
870  std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.find(det);
871  if (idtm == dtmmap.end()) {
872  TrajectoryMeasurement tm(predTsos, currTsos, &(*rhit),est.second,
873  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
874  dtmmap.insert(std::make_pair(det, tm));
875  } else if (idtm->second.estimate() > est.second) {
876  dtmmap.erase(idtm);
877  TrajectoryMeasurement tm(predTsos, currTsos, &(*rhit),est.second,
878  theMeasurementTracker->geometricSearchTracker()->detLayer(ih->geographicalId()));
879  dtmmap.insert(std::make_pair(det, tm));
880  }
881  }
882  }
883 
884  if (!dtmmap.empty()) {
885  for (std::map<const GeomDet*, TrajectoryMeasurement>::iterator idtm = dtmmap.begin();
886  idtm != dtmmap.end(); ++idtm) {
887  TrajectoryMeasurement itm = idtm->second;
888  theBestHits.push_back(itm);
889  }
890  }
891 
892  return theBestHits;
893 }
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
GlobalPoint globalPosition() const
iterator begin()
Definition: OwnVector.h:236
T mag() const
Definition: PV3DBase.h:61
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
virtual const GeomDet * idToDet(DetId) const
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
std::pair< bool, double > HitReturnType
iterator end()
Definition: OwnVector.h:243
const Surface & surface() const
const GeometricSearchTracker * geometricSearchTracker() const
FreeTrajectoryState RoadSearchTrackCandidateMakerAlgorithm::initialTrajectory ( const edm::EventSetup es,
const TrackingRecHit InnerHit,
const TrackingRecHit OuterHit 
)

Definition at line 1246 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References abs, alpha, FastLine::c(), funct::C, funct::cos(), CosmicReco_, cosmicSeedPt_, gather_cfg::cout, GlobalErrorBase< T, ErrorWeightType >::cxx(), GlobalErrorBase< T, ErrorWeightType >::czz(), debug_cff::d0, debug_cff::d1, debug_, TrackingRecHit::geographicalId(), TrackerGeometry::idToDet(), initialVertexErrorXY_, SurfaceOrientation::inner, FastHelix::isValid(), linearFit(), TrackingRecHit::localPosition(), TrackingRecHit::localPositionError(), LogDebug, M_PI, magField, FastLine::n1(), FastLine::n2(), NoFieldCosmic_, SurfaceOrientation::outer, FreeTrajectoryState::parameters(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), lumiQueryAPI::q, funct::sin(), mathSSE::sqrt(), FastHelix::stateAtVertex(), theAloPropagator, thePropagator, theRevPropagator, GeomDet::toGlobal(), trackerGeom, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), LocalError::yy(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by run().

1249 {
1250  FreeTrajectoryState fts;
1251 
1252  GlobalPoint inner = trackerGeom->idToDet(theInnerHit->geographicalId())->surface().toGlobal(theInnerHit->localPosition());
1253  GlobalPoint outer = trackerGeom->idToDet(theOuterHit->geographicalId())->surface().toGlobal(theOuterHit->localPosition());
1254 
1255  LogDebug("RoadSearch") << "inner hit: r/phi/z = "<< inner.perp() << " " << inner.phi() << " " << inner.z() ;
1256  LogDebug("RoadSearch") << "outer hit: r/phi/z = "<< outer.perp() << " " << outer.phi() << " " << outer.z() ;
1257 
1258  // hits should be reasonably separated in r
1259  const double dRmin = 0.1; // cm
1260  if (outer.perp() - inner.perp() < dRmin) return fts;
1261  //GlobalPoint vertexPos(0,0,0);
1262  const double dr2 = initialVertexErrorXY_*initialVertexErrorXY_;
1263  //const double dr2 = 0.0015*0.0015;
1264  //const double dr2 = 0.2*0.2;
1265  const double dz2 = 5.3*5.3;
1266 
1267  // linear z extrapolation of two hits have to be inside tracker ( |z| < 275 cm)
1268  FastLine linearFit(outer, inner);
1269  double z_0 = -linearFit.c()/linearFit.n2();
1270  if ( std::abs(z_0) > 275 && !CosmicReco_ ) return fts;
1271 
1272  GlobalError vertexErr(dr2,
1273  0, dr2,
1274  0, 0, dz2);
1275  //TrivialVertex vtx( vertexPos, vertexErr);
1276  //FastHelix helix(outerHit.globalPosition(),
1277  // (*innerHit).globalPosition(),
1278  // vtx.position());
1279 
1280  double x0=0.0,y0=0.0,z0=0.0;
1281  double phi0 = -999.0;
1282  if (NoFieldCosmic_){
1283  phi0=atan2(outer.y()-inner.y(),outer.x()-inner.x());
1285  if (inner.y()<outer.y()){
1286  if (debug_) std::cout<<"Flipping direction!!!" << std::endl;
1287  thePropagator = theRevPropagator;
1288  phi0=phi0-M_PI;
1289  }
1290  double alpha=atan2(inner.y(),inner.x());
1291  double d1=sqrt(inner.x()*inner.x()+inner.y()*inner.y());
1292  double d0=-d1*sin(alpha-phi0); x0=d0*sin(phi0); y0=-d0*cos(phi0);
1293  double l1=0.0,l2=0.0;
1294  if (fabs(cos(phi0))>0.1){
1295  l1=(inner.x()-x0)/cos(phi0);l2=(outer.x()-x0)/cos(phi0);
1296  }else{
1297  l1=(inner.y()-y0)/sin(phi0);l2=(outer.y()-y0)/sin(phi0);
1298  }
1299  z0=(l2*inner.z()-l1*outer.z())/(l2-l1);
1300  }
1301  //FastHelix helix(outer, inner, vertexPos, es);
1302  FastHelix helix(outer, inner, GlobalPoint(x0,y0,z0), es);
1303  if (!NoFieldCosmic_ && !helix.isValid()) return fts;
1304 
1306  float zErr = vertexErr.czz();
1307  float transverseErr = vertexErr.cxx(); // assume equal cxx cyy
1308  C(3, 3) = transverseErr;
1309  C(4, 4) = zErr;
1310  CurvilinearTrajectoryError initialError(C);
1311 
1312  if (NoFieldCosmic_) {
1313  TrackCharge q = 1;
1314  FastLine flfit(outer, inner);
1315  double dzdr = -flfit.n1()/flfit.n2();
1316  if (inner.y()<outer.y()) dzdr*=-1;
1317 
1318  GlobalPoint XYZ0(x0,y0,z0);
1319  if (debug_) std::cout<<"Initial Point (x0/y0/z0): " << x0 <<'\t'<< y0 <<'\t'<< z0 << std::endl;
1320  GlobalVector PXYZ(cosmicSeedPt_*cos(phi0),
1321  cosmicSeedPt_*sin(phi0),
1322  cosmicSeedPt_*dzdr);
1323  GlobalTrajectoryParameters thePars(XYZ0,PXYZ,q,magField);
1325  CErr *= 5.0;
1326  // CErr(3,3) = (theInnerHit->localPositionError().yy()*theInnerHit->localPositionError().yy() +
1327  // theOuterHit->localPositionError().yy()*theOuterHit->localPositionError().yy());
1328  fts = FreeTrajectoryState(thePars,
1329  CartesianTrajectoryError(CErr));
1330  if (debug_) std::cout<<"\nInitial CError (dx/dy/dz): " << CErr(1,1) <<'\t'<< CErr(2,2) <<'\t'<< CErr(3,3) << std::endl;
1331  if (debug_) std::cout<<"\n\ninner dy = " << theInnerHit->localPositionError().yy() <<"\t\touter dy = " << theOuterHit->localPositionError().yy() << std::endl;
1332  }
1333  else {
1334  fts = FreeTrajectoryState( helix.stateAtVertex().parameters(), initialError);
1335  }
1336  // RoadSearchSeedFinderAlgorithm::initialError( *outerHit, *(*innerHit),
1337  // vertexPos, vertexErr));
1338 
1339  return fts;
1340 }
#define LogDebug(id)
float alpha
Definition: AMPTWrapper.h:95
T perp() const
Definition: PV3DBase.h:66
tuple d0
Definition: debug_cff.py:3
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
tuple d1
Definition: debug_cff.py:7
int TrackCharge
Definition: TrackCharge.h:4
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual const GeomDet * idToDet(DetId) const
#define M_PI
Definition: BFit3D.cc:3
void linearFit(T const *__restrict__ x, T const *__restrict__ y, int ndat, T const *__restrict__ sigy2, T &slope, T &intercept, T &covss, T &covii, T &covsi)
Definition: LinearFit.h:26
tuple cout
Definition: gather_cfg.py:41
T x() const
Definition: PV3DBase.h:56
FreeTrajectoryState RoadSearchTrackCandidateMakerAlgorithm::initialTrajectoryFromTriplet ( const edm::EventSetup es,
const TrackingRecHit InnerHit,
const TrackingRecHit MiddleHit,
const TrackingRecHit OuterHit 
)

Definition at line 1342 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References abs, FastLine::c(), funct::C, DeDxDiscriminatorTools::charge(), GlobalTrajectoryParameters::charge(), CosmicReco_, gather_cfg::cout, debug_, TrackingRecHit::geographicalId(), TrackerGeometry::idToDet(), initialVertexErrorXY_, SurfaceOrientation::inner, edm::detail::isnan(), FastHelix::isValid(), linearFit(), TrackingRecHit::localPosition(), LogDebug, magField, GlobalTrajectoryParameters::momentum(), FastLine::n2(), SurfaceOrientation::outer, FreeTrajectoryState::parameters(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), GlobalTrajectoryParameters::position(), FastHelix::stateAtVertex(), theAloPropagator, thePropagator, theRevPropagator, GeomDet::toGlobal(), trackerGeom, PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by run().

1346 {
1347  FreeTrajectoryState fts;
1348 
1349  GlobalPoint inner = trackerGeom->idToDet(theInnerHit->geographicalId())->surface().toGlobal(theInnerHit->localPosition());
1350  GlobalPoint middle= trackerGeom->idToDet(theMiddleHit->geographicalId())->surface().toGlobal(theMiddleHit->localPosition());
1351  GlobalPoint outer = trackerGeom->idToDet(theOuterHit->geographicalId())->surface().toGlobal(theOuterHit->localPosition());
1352 
1353  LogDebug("RoadSearch") << "inner hit: r/phi/z = "<< inner.perp() << " " << inner.phi() << " " << inner.z() ;
1354  LogDebug("RoadSearch") << "middlehit: r/phi/z = "<< inner.perp() << " " << inner.phi() << " " << inner.z() ;
1355  LogDebug("RoadSearch") << "outer hit: r/phi/z = "<< outer.perp() << " " << outer.phi() << " " << outer.z() ;
1356 
1357  // hits should be reasonably separated in r
1358  const double dRmin = 0.1; // cm
1359  if (outer.perp() - inner.perp() < dRmin) return fts;
1360  const double dr2 = initialVertexErrorXY_*initialVertexErrorXY_;
1361  const double dz2 = 5.3*5.3;
1362 
1363  // linear z extrapolation of two hits have to be inside tracker ( |z| < 275 cm)
1364  FastLine linearFit(outer, inner);
1365  double z_0 = -linearFit.c()/linearFit.n2();
1366  if ( std::abs(z_0) > 275 && !CosmicReco_ ) return fts;
1367 
1368 
1369  FastHelix helix(outer, middle, inner, es);
1370  // check that helix is OK
1371  if (!helix.isValid() ||
1372  std::isnan(helix.stateAtVertex().parameters().momentum().perp())) return fts;
1373  // simple cuts on pt and dz
1374  if (helix.stateAtVertex().parameters().momentum().perp() < 0.5 ||
1375  std::abs(helix.stateAtVertex().parameters().position().z()) > 550.0)
1376  return fts;
1377 
1379  float zErr = dz2;
1380  float transverseErr = dr2; // assume equal cxx cyy
1381  C(3, 3) = transverseErr;
1382  C(4, 4) = zErr;
1383  CurvilinearTrajectoryError initialError(C);
1384 
1385 
1387  GlobalVector gv=helix.stateAtVertex().parameters().momentum();
1388  float charge=helix.stateAtVertex().parameters().charge();
1389 
1390  if (CosmicReco_ && gv.y()>0){
1391  if (debug_) std::cout<<"Flipping direction!!!" << std::endl;
1393  gv=-1.*gv;
1394  charge=-1.*charge;
1395  }
1396 
1397  GlobalTrajectoryParameters Gtp(inner,gv,int(charge),&(*magField));
1398  fts = FreeTrajectoryState(Gtp, initialError);
1399 
1400  //fts = FreeTrajectoryState( helix.stateAtVertex().parameters(), initialError);
1401 
1402  return fts;
1403 }
#define LogDebug(id)
T perp() const
Definition: PV3DBase.h:66
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
double charge(const std::vector< uint8_t > &Ampls)
bool isnan(float x)
Definition: math.h:13
T z() const
Definition: PV3DBase.h:58
virtual const GeomDet * idToDet(DetId) const
void linearFit(T const *__restrict__ x, T const *__restrict__ y, int ndat, T const *__restrict__ sigy2, T &slope, T &intercept, T &covss, T &covii, T &covsi)
Definition: LinearFit.h:26
tuple cout
Definition: gather_cfg.py:41
TrackCandidateCollection RoadSearchTrackCandidateMakerAlgorithm::PrepareTrackCandidates ( std::vector< Trajectory > &  theTrajectories)

Definition at line 1580 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References alongMomentum, TrajectoryMeasurement::backwardPredictedState(), TrajectoryCleanerBySharedHits::clean(), clone(), CosmicTrackMerging_, gather_cfg::cout, debug_, debugCosmics_, GeometricSearchTracker::detLayer(), MeasurementEstimator::estimate(), TrajectoryMeasurement::forwardPredictedState(), MeasurementTracker::geometricSearchTracker(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), i, TrackerGeometry::idToDet(), TrajectoryStateOnSurface::isValid(), j, gen::k, Trajectory::lastMeasurement(), PV3DBase< T, PVType, FrameType >::mag(), maxPropagationDistance, Trajectory::measurements(), TrajectoryStateTransform::persistentState(), PV3DBase< T, PVType, FrameType >::phi(), AnalyticalPropagator::propagate(), PropagatorWithMaterial::propagate(), Trajectory::push(), edm::OwnVector< T, P >::push_back(), DetId::rawId(), TrajectoryMeasurement::recHit(), Trajectory::recHits(), Trajectory::seed(), splitMatchedHits_, evf::utils::state, GeomDet::surface(), theAloPropagator, theAnalyticalPropagator, theEstimator, theMeasurementTracker, theSmoother, theTrajectoryCleaner, theTransformer, theUpdator, trackerGeom, KFTrajectorySmoother::trajectories(), TrajectoryStateUpdator::update(), TrajectoryMeasurement::updatedState(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by run().

1581 {
1582 
1583  TrackCandidateCollection theCollection;
1584 
1585  theTrajectoryCleaner->clean(theTrajectories);
1586 
1587  //==========NEW CODE ==========
1588 
1589  if(CosmicTrackMerging_) {
1590 
1591  //generate vector of *valid* trajectories -> traj
1592  std::vector<Trajectory> traj;
1593 
1594  //keep track of trajectories which are used during merging
1595  std::vector<bool> trajUsed;
1596 
1597  for (std::vector<Trajectory>::iterator it = theTrajectories.begin(); it != theTrajectories.end(); ++it) {
1598  if (it->isValid()) {
1599  traj.push_back(*it);
1600  trajUsed.push_back(false);
1601  }
1602  }
1603 
1604  if(debugCosmics_) {
1605  std::cout << "==========ENTERING COSMIC MODE===========" << std::endl;
1606  // int t=0;
1607  for (std::vector<Trajectory>::iterator it = traj.begin(); it != traj.end(); it++) {
1608  std::cout << "Trajectory " << it-traj.begin() << " has "<<it->recHits().size()<<" hits and is valid: " << it->isValid() << std::endl;
1609  TransientTrackingRecHit::ConstRecHitContainer itHits = it->recHits();
1610 
1611 
1612  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=itHits.begin(); rhit!=itHits.end(); ++rhit)
1613  std::cout << "-->good hit position: " << (*rhit)->globalPosition().x() << ", "
1614  << (*rhit)->globalPosition().y() << ", "<< (*rhit)->globalPosition().z() << std::endl;
1615 
1616  }
1617  }
1618 
1619  //double nested looop to find trajectories that match in phi
1620  for ( unsigned int i = 0; i < traj.size(); ++i) {
1621  if (trajUsed[i]) continue;
1622  for ( unsigned int j = i+1; j != traj.size(); ++j) {
1623  if (trajUsed[j]) continue;
1624 
1625  if (debugCosmics_) std::cout<< "Trajectory " <<i<< " has "<<traj[i].recHits().size()<<" hits with chi2=" << traj[i].chiSquared() << " and is valid"<<std::endl;
1626  if (debugCosmics_) std::cout<< "Trajectory " <<j<< " has "<<traj[j].recHits().size()<<" hits with chi2=" << traj[j].chiSquared() << " and is valid"<<std::endl;
1627 
1628  TrajectoryMeasurement firstTraj1 = traj[i].firstMeasurement();
1629  TrajectoryMeasurement firstTraj2 = traj[j].firstMeasurement();
1630  TrajectoryStateOnSurface firstTraj1TSOS = firstTraj1.updatedState();
1631  TrajectoryStateOnSurface firstTraj2TSOS = firstTraj2.updatedState();
1632 
1633 
1634  if(debugCosmics_)
1635  std::cout << "phi1: " << firstTraj1TSOS.globalMomentum().phi()
1636  << " phi2: " << firstTraj2TSOS.globalMomentum().phi()
1637  << " --> delta_phi: " << firstTraj1TSOS.globalMomentum().phi()-firstTraj2TSOS.globalMomentum().phi() << std::endl;
1638 
1639  //generate new trajectory if delta_phi<0.3
1640  //use phi of momentum vector associated to *innermost* hit of trajectories
1641  if( fabs(firstTraj1TSOS.globalMomentum().phi()-firstTraj2TSOS.globalMomentum().phi())<0.3 ) {
1642  if(debugCosmics_) std::cout << "-->match successful" << std::endl;
1643  } else {
1644  if(debugCosmics_) std::cout << "-->match not successful" << std::endl;
1645  }
1646  if( fabs(firstTraj1TSOS.globalMomentum().phi()-firstTraj2TSOS.globalMomentum().phi())>0.3 ) continue;
1647 
1648 
1649  //choose starting trajectory: use trajectory in lower hemisphere (with y<0) to start new combined trajectory
1650  //use y position of outermost hit
1651  TrajectoryMeasurement lastTraj1 = traj[i].lastMeasurement();
1652  TrajectoryMeasurement lastTraj2 = traj[j].lastMeasurement();
1653  TrajectoryStateOnSurface lastTraj1TSOS = lastTraj1.updatedState();
1654  TrajectoryStateOnSurface lastTraj2TSOS = lastTraj2.updatedState();
1655 
1656  if(debugCosmics_){
1657  std::cout<<"Traj1 first (x/y/z): "
1658  << firstTraj1TSOS.globalPosition().x() <<" / "
1659  << firstTraj1TSOS.globalPosition().y() <<" / "
1660  << firstTraj1TSOS.globalPosition().z()
1661  << " phi: " << firstTraj1TSOS.globalMomentum().phi() << std::endl;
1662  std::cout<<"Traj1 last (x/y/z): "
1663  << lastTraj1TSOS.globalPosition().x() <<" / "
1664  << lastTraj1TSOS.globalPosition().y() <<" / "
1665  << lastTraj1TSOS.globalPosition().z()
1666  << " phi: " << lastTraj1TSOS.globalMomentum().phi() << std::endl;
1667 
1668  std::cout<<"Traj2 first (x/y/z): "
1669  << firstTraj2TSOS.globalPosition().x() <<" / "
1670  << firstTraj2TSOS.globalPosition().y() <<" / "
1671  << firstTraj2TSOS.globalPosition().z()
1672  << " phi: " << firstTraj2TSOS.globalMomentum().phi() << std::endl;
1673  std::cout<<"Traj2 last (x/y/z): "
1674  << lastTraj2TSOS.globalPosition().x() <<" / "
1675  << lastTraj2TSOS.globalPosition().y() <<" / "
1676  << lastTraj2TSOS.globalPosition().z()
1677  << " phi: " << lastTraj2TSOS.globalMomentum().phi() << std::endl;
1678 
1679  }
1680 
1681  Trajectory *upperTrajectory, *lowerTrajectory;
1682 
1683  TrajectoryStateOnSurface lowerTSOS1,upperTSOS1;
1684  if (lastTraj1TSOS.globalPosition().y()<firstTraj1TSOS.globalPosition().y()) {
1685  lowerTSOS1=lastTraj1TSOS; upperTSOS1=firstTraj1TSOS;
1686  }
1687  else {
1688  lowerTSOS1=firstTraj1TSOS; upperTSOS1=lastTraj1TSOS;
1689  }
1690  TrajectoryStateOnSurface lowerTSOS2;
1691  if (lastTraj2TSOS.globalPosition().y()<firstTraj2TSOS.globalPosition().y()) lowerTSOS2=lastTraj2TSOS;
1692  else lowerTSOS2=firstTraj2TSOS;
1693  if(lowerTSOS1.globalPosition().y() > lowerTSOS2.globalPosition().y()) {
1694  if(debugCosmics_)
1695  std::cout << "-->case A: "<< lowerTSOS1.globalPosition().y() << " > " << lowerTSOS2.globalPosition().y() << std::endl;
1696 
1697  upperTrajectory = &(traj[i]);
1698  lowerTrajectory = &(traj[j]);
1699 
1700  } else {
1701  if(debugCosmics_)
1702  std::cout << "-->case B: "<< lowerTSOS1.globalPosition().y() << " < " << lowerTSOS2.globalPosition().y() << std::endl;
1703 
1704  upperTrajectory = &(traj[j]);
1705  lowerTrajectory = &(traj[i]);
1706  }
1707 
1708  std::vector<Trajectory> freshStartUpperTrajectory = theSmoother->trajectories(*upperTrajectory);
1709  std::vector<Trajectory> freshStartLowerTrajectory = theSmoother->trajectories(*lowerTrajectory);
1710  //--JR
1711  if (freshStartUpperTrajectory.empty() || freshStartLowerTrajectory .empty()){
1712  if (debugCosmics_) std::cout << " the smoother has failed."<<std::endl;
1713  continue;
1714  }
1715  //--JR
1716  TrajectoryStateOnSurface NewFirstTsos = freshStartUpperTrajectory.begin()->lastMeasurement().updatedState();
1717  TrajectoryStateOnSurface forwardTsos = freshStartUpperTrajectory.begin()->firstMeasurement().forwardPredictedState();
1718  TrajectoryStateOnSurface backwardTsos = freshStartUpperTrajectory.begin()->lastMeasurement().backwardPredictedState();
1719 
1720  Trajectory freshStartTrajectory = *freshStartUpperTrajectory.begin();
1721  if(debugCosmics_) std::cout << "seed hit updatedState: " << NewFirstTsos.globalMomentum().x() << ", " << NewFirstTsos.globalMomentum().y() << ", " << NewFirstTsos.globalMomentum().z() << std::endl;
1722  if(debugCosmics_) std::cout << "seed hit updatedState (pos x/y/z): " << NewFirstTsos.globalPosition().x() << ", " << NewFirstTsos.globalPosition().y() << ", " << NewFirstTsos.globalPosition().z() << std::endl;
1723  if(debugCosmics_) std::cout << "seed hit forwardPredictedState: " << forwardTsos.globalMomentum().x() << ", " << forwardTsos.globalMomentum().y() << ", " << forwardTsos.globalMomentum().z() << std::endl;
1724  if(debugCosmics_) std::cout << "seed hit forwardPredictedState (pos x/y/z): " << forwardTsos.globalPosition().x() << ", " << forwardTsos.globalPosition().y() << ", " << forwardTsos.globalPosition().z() << std::endl;
1725  if(debugCosmics_) std::cout << "seed hit backwardPredictedState: " << backwardTsos.globalMomentum().x() << ", " << backwardTsos.globalMomentum().y() << ", " << backwardTsos.globalMomentum().z() << std::endl;
1726  if(debugCosmics_) std::cout << "seed hit backwardPredictedState (pos x/y/z): " << backwardTsos.globalPosition().x() << ", " << backwardTsos.globalPosition().y() << ", " << backwardTsos.globalPosition().z() << std::endl;
1727 
1728  if(debugCosmics_) std::cout<<"#hits for upper trajectory: " << freshStartTrajectory.measurements().size() << std::endl;
1729 
1730  //loop over hits in upper trajectory and add them to lower trajectory
1732 
1733  if(debugCosmics_) std::cout << "loop over hits in lower trajectory..." << std::endl;
1734 
1735  bool addHitToFreshStartTrajectory = false;
1736  bool propagationFailed = false;
1737  int lostHits = 0;
1738  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=ttHits.begin(); rhit!=ttHits.end(); ++rhit){
1739 
1740  if(debugCosmics_ && lostHits>0){
1741  std::cout << " Lost " << lostHits << " of " << ttHits.size() << " on lower trajectory " << std::endl;
1742  std::cout << " Lost " << ((float)lostHits/(float)ttHits.size()) << " of hits of on lower trajectory " << std::endl;
1743  }
1744  if ((float)lostHits/(float)ttHits.size() > 0.5) {
1745  propagationFailed = true;
1746  break;
1747  }
1748  if(debugCosmics_) std::cout << "-->hit position: " << (*rhit)->globalPosition().x() << ", " << (*rhit)->globalPosition().y() << ", "<< (*rhit)->globalPosition().z() << std::endl;
1749 
1750  TrajectoryStateOnSurface predTsos;
1751  TrajectoryStateOnSurface currTsos;
1753 
1755 
1756 
1757 
1758  /*
1759  if( rh->isValid() ) {
1760  if(debugCosmics_) std::cout << "-->hit is valid"<<std::endl;
1761  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
1762 
1763  std::vector<TrajectoryMeasurement> measL = freshStartTrajectory.measurements();
1764  bool alreadyUsed = false;
1765  for (std::vector<TrajectoryMeasurement>::iterator mh=measL.begin();mh!=measL.end();++mh) {
1766  if (rh->geographicalId().rawId()==mh->recHit()->geographicalId().rawId()) {
1767  if (debugCosmics_) std::cout << "this hit is already in the trajectory, skip it" << std::endl;
1768  alreadyUsed = true;
1769  break;
1770  }
1771  }
1772  if (alreadyUsed) continue;
1773  //std::vector<TrajectoryMeasurement> measU = freshStartUpperTrajectory[0].measurements();
1774  if (freshStartTrajectory.direction()==0) {
1775  std::vector<TrajectoryMeasurement>::iterator ml;
1776  for (ml=measL.begin();ml!=measL.end();++ml) {
1777  if (debugCosmics_) std::cout << "hit y="<<ml->recHit()->globalPosition().y()
1778  << " tsos validity fwd="<<ml->forwardPredictedState().isValid()
1779  << " bwd="<<ml->backwardPredictedState().isValid()
1780  << " upd="<<ml->updatedState().isValid()
1781  <<std::endl;
1782  if (ml->recHit()->globalPosition().y()>(*rhit)->globalPosition().y() && ml!=measL.begin()) {
1783  break;
1784  }
1785  }
1786  if ((ml-1)->forwardPredictedState().isValid()) currTsos = (ml-1)->forwardPredictedState();
1787  else currTsos = (ml-1)->backwardPredictedState();
1788 
1789  if (debugCosmics_) std::cout << "currTsos y=" << currTsos.globalPosition().y() << std::endl;
1790  }
1791  else {
1792  std::vector<TrajectoryMeasurement>::reverse_iterator ml;
1793  for (ml=measL.rbegin();ml!=measL.rend();++ml) {
1794  if (debugCosmics_) std::cout << "hit y="<<ml->recHit()->globalPosition().y()
1795  << " tsos validity fwd="<<ml->forwardPredictedState().isValid()
1796  << " bwd="<<ml->backwardPredictedState().isValid()
1797  << " upd="<<ml->updatedState().isValid()
1798  <<std::endl;
1799  if (ml->recHit()->globalPosition().y()>(*rhit)->globalPosition().y() && ml!=measL.rbegin()) {
1800  break;
1801  }
1802  }
1803  if ((ml-1)->forwardPredictedState().isValid()) {
1804  currTsos = (ml-1)->forwardPredictedState();
1805  }
1806  else {
1807  currTsos = (ml-1)->backwardPredictedState();
1808  }
1809 
1810  if (debugCosmics_) std::cout << "reverse. currTsos y=" << currTsos.globalPosition().y() << std::endl;
1811  }
1812 
1813 
1814  }
1815  */
1816 
1817 
1818  if( rh->isValid() ) {
1819  if(debugCosmics_) std::cout << "-->hit is valid"<<std::endl;
1820  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
1821  if( addHitToFreshStartTrajectory==false ) {
1822  //first hit from upper trajectory that is being added to lower trajectory requires usage of backwardPredictedState (of lower trajectory)
1823  currTsos = freshStartTrajectory.lastMeasurement().backwardPredictedState();
1824  } else {
1825  //remaining hits from upper trajectory that are being added to lower trajectory require usage of forwardPredictedState
1826  currTsos = freshStartTrajectory.lastMeasurement().forwardPredictedState();
1827  }
1828 
1829  if(debugCosmics_) std::cout << "current TSOS: " << currTsos.globalPosition().x() << ", " << currTsos.globalPosition().y() << ", " << currTsos.globalPosition().z() << ", " << std::endl;
1830 
1831  predTsos = theAloPropagator->propagate(currTsos, det->surface());
1832 
1833  if (!predTsos.isValid()) {
1834  if(debugCosmics_) std::cout<<"predTsos is not valid!" <<std::endl;
1835  //propagationFailed = true;
1836  ++lostHits;
1837  //break;
1838  continue;
1839  }
1840  GlobalVector propagationDistance = predTsos.globalPosition() - currTsos.globalPosition();
1841  if (propagationDistance.mag() > maxPropagationDistance) continue;
1842 
1843  if(debugCosmics_) std::cout << "predicted TSOS: " << predTsos.globalPosition().x() << ", " << predTsos.globalPosition().y() << ", " << predTsos.globalPosition().z() << ", " << std::endl;
1845  if (!est.first) {
1846  if(debugCosmics_) std::cout<<"Failed to add one of the original hits on a low occupancy layer!!!!" << std::endl;
1847  //propagationFailed = true;
1848  ++lostHits;
1849  //break;
1850  continue;
1851  }
1852 
1853  currTsos = theUpdator->update(predTsos, *rh);
1854  if(debugCosmics_) std::cout << "current updated TSOS: " << currTsos.globalPosition().x() << ", " << currTsos.globalPosition().y() << ", " << currTsos.globalPosition().z() << ", " << std::endl;
1855  tm = TrajectoryMeasurement(predTsos, currTsos,&(*rh),est.second,theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()));
1856  freshStartTrajectory.push(tm,est.second);
1857  addHitToFreshStartTrajectory=true;
1858 
1859  }
1860 
1861  if(debugCosmics_) std::cout<<"#hits for new trajectory (his from upper trajectory added): " << freshStartTrajectory.measurements().size() << std::endl;
1862  }
1863 
1864  if (propagationFailed) {
1865  if (debugCosmics_) std::cout<<"Propagation failed so go to next trajectory" << std::endl;
1866  continue;
1867  }
1868 
1869  //put final trajectory together
1870  if(debugCosmics_) std::cout << "put final trajectory together..." << std::endl;
1872  TransientTrackingRecHit::ConstRecHitContainer tttempHits = freshStartTrajectory.recHits(splitMatchedHits_);
1873 
1874  for (int k=tttempHits.size()-1; k>=0; k--) {
1875  if(debugCosmics_) std::cout << "-->good hit position: " << tttempHits[k]->globalPosition().x() << ", " << tttempHits[k]->globalPosition().y() << ", "<< tttempHits[k]->globalPosition().z() << std::endl;
1876  goodHits.push_back(tttempHits[k]->hit()->clone());
1877  }
1878  TrajectoryStateOnSurface firstState;
1879 
1880  // check if Trajectory from seed is on first hit of the cloud, if not, propagate
1881  // exclude if first state on first hit is not valid
1882  DetId FirstHitId = (*(freshStartTrajectory.recHits().end()-1))->geographicalId(); //was begin
1883 
1884  TrajectoryMeasurement maxYMeasurement = freshStartTrajectory.lastMeasurement();
1885  const GeomDet* det = trackerGeom->idToDet(FirstHitId);
1886  firstState = theAnalyticalPropagator->propagate(maxYMeasurement.updatedState(),det->surface());
1887  if (firstState.isValid() == false) continue;
1888  PTrajectoryStateOnDet *state = theTransformer->persistentState(firstState,FirstHitId.rawId());
1889 
1890  //generate new trajectory seed
1891  TrajectoryStateOnSurface firstTSOS = freshStartTrajectory.lastMeasurement().updatedState();
1892  if(debugCosmics_) std::cout << "generate new trajectory seed with hit (x/y/z): " << firstTSOS.globalPosition().x() << ", " << firstTSOS.globalPosition().y() << ", " << firstTSOS.globalPosition().z() << ", " << std::endl;
1893  TransientTrackingRecHit::ConstRecHitPointer rhit = freshStartTrajectory.lastMeasurement().recHit();
1894  PTrajectoryStateOnDet* pFirstState = TrajectoryStateTransform().persistentState(NewFirstTsos,rhit->geographicalId().rawId());
1896  newHits.push_back(rhit->hit()->clone());
1897  TrajectorySeed tmpseed = TrajectorySeed(*pFirstState,newHits,alongMomentum);
1898 
1899  theCollection.push_back(TrackCandidate(goodHits,freshStartTrajectory.seed(),*state));
1900  delete state;
1901  delete pFirstState;
1902 
1903  //trajectory usage
1904  trajUsed[i]=true;
1905  trajUsed[j]=true;
1906 
1907  } //for loop trajectory2
1908 
1909  } //for loop trajectory1
1910 
1911  //add all trajectories to the resulting vector if they have *not* been used by the trajectory merging algorithm
1912  for ( unsigned int i = 0; i < traj.size(); ++i) {
1913 
1914  if (trajUsed[i]==true) continue;
1915 
1916  if (debugCosmics_) std::cout<< "Trajectory (not merged) has "<<traj[i].recHits().size()<<" hits with chi2=" << traj[i].chiSquared() << " and is valid? "<< traj[i].isValid()<<std::endl;
1919  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=ttHits.begin(); rhit!=ttHits.end(); ++rhit){
1920  goodHits.push_back((*rhit)->hit()->clone());
1921  }
1922  TrajectoryStateOnSurface firstState;
1923 
1924  // check if Trajectory from seed is on first hit of the cloud, if not, propagate
1925  // exclude if first state on first hit is not valid
1926  DetId FirstHitId = (*(traj[i].recHits().begin()))->geographicalId();
1927 
1928  // propagate back to first hit
1929  TrajectoryMeasurement firstMeasurement = traj[i].measurements()[0];
1930  const GeomDet* det = trackerGeom->idToDet(FirstHitId);
1931  firstState = theAnalyticalPropagator->propagate(firstMeasurement.updatedState(), det->surface());
1932  if (firstState.isValid()) {
1933  PTrajectoryStateOnDet *state = theTransformer->persistentState(firstState,FirstHitId.rawId());
1934  theCollection.push_back(TrackCandidate(goodHits,traj[i].seed(),*state));
1935  delete state;
1936  }
1937  }
1938  if (debugCosmics_) std::cout << "Original collection had " << theTrajectories.size()
1939  << " candidates. Merged collection has " << theCollection.size() << std::endl;
1940  } //if(CosmicTrackMerging_)
1941 
1942 
1943  if(!CosmicTrackMerging_) {
1944  for (std::vector<Trajectory>::const_iterator it = theTrajectories.begin(); it != theTrajectories.end(); it++) {
1945  if (debug_) std::cout<< " Trajectory has "<<it->recHits().size()<<" hits with chi2=" << it->chiSquared() << " and is valid? "<<it->isValid()<<std::endl;
1946  if (it->isValid()){
1947 
1950  for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator rhit=ttHits.begin(); rhit!=ttHits.end(); ++rhit){
1951  goodHits.push_back((*rhit)->hit()->clone());
1952  }
1953  TrajectoryStateOnSurface firstState;
1954 
1955  // check if Trajectory from seed is on first hit of the cloud, if not, propagate
1956  // exclude if first state on first hit is not valid
1957  DetId FirstHitId = (*(it->recHits().begin()))->geographicalId();
1958 
1959  // propagate back to first hit
1960  TrajectoryMeasurement firstMeasurement = it->measurements()[0];
1961  const GeomDet* det = trackerGeom->idToDet(FirstHitId);
1962  firstState = theAnalyticalPropagator->propagate(firstMeasurement.updatedState(), det->surface());
1963  if (firstState.isValid() == false) continue;
1964  PTrajectoryStateOnDet *state = theTransformer->persistentState(firstState,FirstHitId.rawId());
1965  theCollection.push_back(TrackCandidate(goodHits,it->seed(),*state));
1966  delete state;
1967 
1968  }
1969  }
1970  }
1971 
1972  return theCollection;
1973 }
int i
Definition: DBlmapReader.cc:9
TrajectoryStateOnSurface propagate(const FreeTrajectoryState &fts, const Plane &plane) const
propagation to plane
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:231
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
TrajectoryStateOnSurface forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
std::vector< TrackCandidate > TrackCandidateCollection
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
virtual void clean(TrajectoryPointerContainer &) const
T y() const
Definition: PV3DBase.h:57
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
virtual std::vector< Trajectory > trajectories(const Trajectory &aTraj) const
DataContainer const & measurements() const
Definition: Trajectory.h:169
void push_back(D *&d)
Definition: OwnVector.h:290
T mag() const
Definition: PV3DBase.h:61
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:147
T z() const
Definition: PV3DBase.h:58
int j
Definition: DBlmapReader.cc:9
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
TrajectoryStateOnSurface updatedState() const
PTrajectoryStateOnDet * persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid) const
virtual const GeomDet * idToDet(DetId) const
int k[5][pyjets_maxn]
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:20
std::pair< bool, double > HitReturnType
T * clone(const T *tp)
Definition: Ptr.h:42
char state
Definition: procUtils.cc:75
GlobalVector globalMomentum() const
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
tuple cout
Definition: gather_cfg.py:41
const GeometricSearchTracker * geometricSearchTracker() const
T x() const
Definition: PV3DBase.h:56
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
tuple size
Write out results.
TrajectoryStateOnSurface backwardPredictedState() const
Access to backward predicted state (from smoother)
void RoadSearchTrackCandidateMakerAlgorithm::run ( const RoadSearchCloudCollection input,
const edm::Event e,
const edm::EventSetup es,
TrackCandidateCollection output 
)

Runs the algorithm.

Definition at line 109 of file RoadSearchTrackCandidateMakerAlgorithm.cc.

References alongMomentum, AnalyticalPropagator_cfi::AnalyticalPropagator, anyDirection, chooseStartingLayers(), TrajectoryCleanerBySharedHits::clean(), conf_, CosmicReco_, gather_cfg::cout, createSeedTrajectory(), debug_, debugCosmics_, GeometricSearchTracker::detLayer(), TrajectorySeed::direction(), MeasurementEstimator::estimate(), extrapolateTrajectory(), FindBestHits(), MeasurementTracker::geometricSearchTracker(), edm::EventSetup::get(), edm::ParameterSet::getParameter(), TrajectoryStateOnSurface::globalPosition(), FreeTrajectoryState::hasError(), i, TrackerGeometry::idToDet(), initialTrajectory(), initialTrajectoryFromTriplet(), MagneticField::inTesla(), TrajectoryStateOnSurface::isValid(), Trajectory::isValid(), KFTrajectorySmootherESProducer_cfi::KFTrajectorySmoother, Trajectory::lastMeasurement(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localPosition(), LogDebug, lstereo, PV3DBase< T, PVType, FrameType >::mag(), magField, maxPropagationDistance, Trajectory::measurements(), measurementTrackerName_, MinChunkLength_, nFoundMin_, NoFieldCosmic_, oppositeToMomentum, PV3DBase< T, PVType, FrameType >::perp(), TrajectoryStateTransform::persistentState(), LocalTrajectoryError::positionError(), PrepareTrackCandidates(), edm::ESHandle< class >::product(), edm::OwnVector< T, P >::push_back(), TrajectoryMeasurement::recHit(), edm::second(), edm::OwnVector< T, P >::size(), python.multivaluedict::sort(), mathSSE::sqrt(), GeomDet::surface(), theAloPropagator, theAnalyticalPropagator, theEstimator, theHitMatcher, theMeasurementTracker, theNumHitCut, thePropagator, theRevPropagator, theSmoother, theTrajectoryCleaner, theUpdator, GeomDet::toGlobal(), patCandidatesForDimuonsSequences_cff::tracker, trackerGeom, KFTrajectorySmoother::trajectories(), ttrhBuilder, TrajectoryStateUpdator::update(), MeasurementTracker::update(), TrajectoryMeasurement::updatedState(), PV3DBase< T, PVType, FrameType >::x(), LocalError::xx(), PV3DBase< T, PVType, FrameType >::y(), LocalError::yy(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by RoadSearchTrackCandidateMaker::produce().

113 {
114 
115  //
116  // right now, track candidates are just filled from cleaned
117  // clouds. The trajectory of the seed is taken as the initial
118  // trajectory for the final fit
119  //
120 
121  //
122  // get the transient builder
123  //
125  std::string builderName = conf_.getParameter<std::string>("TTRHBuilder");
126  es.get<TransientRecHitRecord>().get(builderName,theBuilder);
127  ttrhBuilder = theBuilder.product();
128 
129  edm::ESHandle<MeasurementTracker> measurementTrackerHandle;
130  es.get<CkfComponentsRecord>().get(measurementTrackerName_, measurementTrackerHandle);
131  theMeasurementTracker = measurementTrackerHandle.product();
132 
133  std::vector<Trajectory> FinalTrajectories;
134 
135 
136  // need this to sort recHits, sorting done after getting seed because propagationDirection is needed
137  // get tracker geometry
139  es.get<TrackerDigiGeometryRecord>().get(tracker);
140  trackerGeom = tracker.product();
141 
143  es.get<IdealMagneticFieldRecord>().get(magField_);
144  magField = magField_.product();
145 
146  NoFieldCosmic_ = (CosmicReco_ && (magField->inTesla(GlobalPoint(0,0,0)).mag() < 0.01));
147 
149  //const MeasurementTracker* theMeasurementTracker = new MeasurementTracker(es,mt_params); // will need this later
150 
154 
156 
157  //KFTrajectorySmoother theSmoother(*theRevPropagator, *theUpdator, *theEstimator);
159 
160  // get hit matcher
162 
163  //debug_ = true;
164  //if (input->size()>0) debug_ = true;
165 
166  LogDebug("RoadSearch") << "Clean Clouds input size: " << input->size();
167  if (debug_) std::cout << std::endl << std::endl
168  << "*** NEW EVENT: Clean Clouds input size: " << input->size() << std::endl;
169 
170  int i_c = 0;
171  int nchit = 0;
172  for ( RoadSearchCloudCollection::const_iterator cloud = input->begin(); cloud != input->end(); ++cloud ) {
173 
174  // fill rechits from cloud into new
175  RoadSearchCloud::RecHitVector recHits = cloud->recHits();
176  nchit = recHits.size();
177 
178  std::vector<Trajectory> CloudTrajectories;
179 
180  if (!CosmicReco_){
181  std::sort(recHits.begin(),recHits.end(),SortHitPointersByGlobalPosition(tracker.product(),alongMomentum));
182  }
183  else {
184  std::sort(recHits.begin(),recHits.end(),SortHitPointersByY(*tracker));
185  }
186 
187  const unsigned int nlost_max = 2;
188 
189  // make a list of layers in cloud and mark stereo layers
190 
191  const unsigned int max_layers = 128;
192 
193  // collect hits in cloud by layer
194  std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > > RecHitsByLayer;
195  std::map<const DetLayer*, int> cloud_layer_reference; // for debugging
196  std::map<const DetLayer*, int>::iterator hiter;
197  for(RoadSearchCloud::RecHitVector::const_iterator ihit = recHits.begin();
198  ihit != recHits.end(); ihit++) {
199  // only use useful layers
200  const DetLayer* thisLayer =
201  theMeasurementTracker->geometricSearchTracker()->detLayer((*ihit)->geographicalId());
202 
203  std::map<const DetLayer*, int>::const_iterator ilyr = cloud_layer_reference.find(thisLayer);
204  if (ilyr==cloud_layer_reference.end())
205  cloud_layer_reference.insert(std::make_pair( thisLayer, RecHitsByLayer.size()));
206 
207  if (!RecHitsByLayer.empty() && RecHitsByLayer.back().first == thisLayer) { // Same as previous layer
208  RecHitsByLayer.back().second.push_back(*ihit);
209  }
210  else { // check if this is a new layer
211  if (ilyr != cloud_layer_reference.end()){// Not a New Layer
212  int ilayer = ilyr->second;
213  (RecHitsByLayer.begin()+ilayer)->second.push_back(*ihit);
214  }
215  else{// New Layer
216  if (RecHitsByLayer.size() >= max_layers) break; // should never happen
217  lstereo[RecHitsByLayer.size()] = false;
218  if ((*ihit)->localPositionError().yy()<1.) lstereo[RecHitsByLayer.size()] = true;
220  rhc.push_back(*ihit);
221  RecHitsByLayer.push_back(std::make_pair(thisLayer, rhc));
222  }
223  }
224  }
225 
226  LogDebug("RoadSearch")<<"Cloud #"<<i_c<<" has "<<recHits.size()<<" hits in "<<RecHitsByLayer.size()<<" layers ";
227  if (debug_) std::cout <<"Cloud "<<i_c<<" has "<<recHits.size()<<" hits in " <<RecHitsByLayer.size() << " layers " <<std::endl;;
228  ++i_c;
229 
230  if (debug_){
231  int ntothit = 0;
232 
233  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilhv = RecHitsByLayer.begin();
234  ilhv != RecHitsByLayer.end(); ++ilhv) {
235  std::cout<<" Layer " << ilhv-RecHitsByLayer.begin() << " has " << ilhv->second.size() << " hits " << std::endl;
236  }
237  std::cout<<std::endl;
238  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilhv = RecHitsByLayer.begin();
239  ilhv != RecHitsByLayer.end(); ++ilhv) {
240  RoadSearchCloud::RecHitVector theLayerHits = ilhv->second;
241  for (RoadSearchCloud::RecHitVector::const_iterator ihit = theLayerHits.begin();
242  ihit != theLayerHits.end(); ++ihit) {
243 
244  GlobalPoint gp = trackerGeom->idToDet((*ihit)->geographicalId())->surface().toGlobal((*ihit)->localPosition());
245  if (CosmicReco_){
246  std::cout << " Hit "<< ntothit
247  << " x/y/z = "
248  << gp.x() << " " << gp.y() << " " << gp.z()
249  <<" in layer " << ilhv-RecHitsByLayer.begin()
250  << " is hit " << (ihit-theLayerHits.begin())+1
251  << " of " << theLayerHits.size() << std::endl;
252  }
253  else {
254  std::cout << " Hit "<< ntothit
255  << " r/z = "
256  << gp.perp() << " " << gp.z()
257  <<" in layer " << ilhv-RecHitsByLayer.begin()
258  << " is hit " << (ihit-theLayerHits.begin())+1
259  << " of " << theLayerHits.size() << std::endl;
260  }
261  ntothit++;
262  }
263  }
264  std::cout<<std::endl;
265  }
266 
267  // try to start from all layers until the chunk is too short
268  //
269 
270  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr0 = RecHitsByLayer.begin();
271  ilyr0 != RecHitsByLayer.end(); ++ilyr0) {
272 
273  unsigned int ilayer0 = (unsigned int)(ilyr0-RecHitsByLayer.begin());
274  if (ilayer0 > RecHitsByLayer.size()-MinChunkLength_) continue;
275 
276  std::vector<Trajectory> ChunkTrajectories;
277  std::vector<Trajectory> CleanChunks;
278  bool all_chunk_layers_used = false;
279 
280  if (debug_) std::cout << "*** START NEW CHUNK --> layer range (" << ilyr0-RecHitsByLayer.begin()
281  << "-" << RecHitsByLayer.size()-1 << ")";
282 
283  // collect hits from the starting layer
284  RoadSearchCloud::RecHitVector recHits_start = ilyr0->second;
285 
286  //
287  // Step 1: find small tracks (chunks) made of hits
288  // in layers with low occupancy
289  //
290 
291  // find layers with small number of hits
292  // TODO: try to keep earliest layers + at least one stereo layer
293  std::multimap<int, const DetLayer*> layer_map;
294  std::map<const DetLayer*, int> layer_reference; // for debugging
295  // skip starting layer, as it is always included
296  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilayer = ilyr0+1;
297  ilayer != RecHitsByLayer.end(); ++ilayer) {
298  layer_map.insert(std::make_pair(ilayer->second.size(), ilayer->first));
299  layer_reference.insert(std::make_pair(ilayer->first, ilayer-RecHitsByLayer.begin()));
300  }
301 
302  if (debug_) {
303  std::cout<<std::endl<<" Available layers are: " << std::endl;
304  for (std::multimap<int, const DetLayer*>::iterator ilm1 = layer_map.begin();
305  ilm1 != layer_map.end(); ++ilm1) {
306  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(ilm1->second);
307  if (ilr != layer_reference.end() && debug_)
308  std::cout << "Layer " << ilr->second << " with " << ilm1->first <<" hits" <<std::endl;;
309  }
310  }
311 
312  //const int max_middle_layers = 2;
313  std::set<const DetLayer*> the_good_layers;
314  std::vector<const DetLayer*> the_middle_layers;
315  RoadSearchCloud::RecHitVector the_recHits_middle;
316 
317  // bool StartLayers =
318  chooseStartingLayers(RecHitsByLayer,ilyr0,layer_map,the_good_layers,the_middle_layers,the_recHits_middle);
319  if (debug_) {
320  std::cout << " From new code... With " << the_good_layers.size() << " useful layers: ";
321  for (std::set<const DetLayer*>::iterator igl = the_good_layers.begin();
322  igl!= the_good_layers.end(); ++igl){
323  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(*igl);
324  if (ilr != layer_reference.end()) std::cout << " " << ilr->second;
325  }
326  std::cout << std::endl;
327  std::cout << " From new code... and middle layers: ";
328  for (std::vector<const DetLayer*>::iterator iml = the_middle_layers.begin();
329  iml!= the_middle_layers.end(); ++iml){
330  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(*iml);
331  if (ilr != layer_reference.end()) std::cout << " " << ilr->second;
332  }
333  std::cout << std::endl;
334  }
335  RoadSearchCloud::RecHitVector recHits_inner = recHits_start;
336  RoadSearchCloud::RecHitVector recHits_outer = the_recHits_middle;
337  std::set<const DetLayer*> good_layers = the_good_layers;
338  unsigned int ngoodlayers = good_layers.size();
339 
340  if (debug_)
341  std::cout<<"Found " << recHits_inner.size() << " inner hits and " << recHits_outer.size() << " outer hits" << std::endl;
342 
343  // collect hits in useful layers
344  std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > > goodHits;
345  // mark layers that will be skipped in first pass
346  std::set<const DetLayer*> skipped_layers;
347  std::map<int, const DetLayer*> skipped_layer_detmap;
348 
349 
350  goodHits.push_back(*ilyr0); // save hits from starting layer
351  // save hits from other good layers
352  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr = ilyr0+1;
353  ilyr != RecHitsByLayer.end(); ++ilyr) {
354  if (good_layers.find(ilyr->first) != good_layers.end()){
355  goodHits.push_back(*ilyr);
356  }
357  else {
358  skipped_layers.insert(ilyr->first);
359  std::map<const DetLayer*, int>::iterator ilr = layer_reference.find(ilyr->first);
360  if (ilr != layer_reference.end())
361  skipped_layer_detmap.insert(std::make_pair(ilr->second,ilyr->first));
362  else
363  if (debug_) std::cout<<"Couldn't find thisLayer to insert into map..."<<std::endl;
364  }
365  }
366 
367  // try various hit combinations
368  for (RoadSearchCloud::RecHitVector::const_iterator innerHit = recHits_inner.begin();
369  innerHit != recHits_inner.end(); ++innerHit) {
370 
371  const DetLayer* innerHitLayer =
372  theMeasurementTracker->geometricSearchTracker()->detLayer((*innerHit)->geographicalId());
373 
374 
375  RoadSearchCloud::RecHitVector::iterator middleHit, outerHit;
376  RoadSearchCloud::RecHitVector::iterator firstHit, lastHit;
377 
378  bool triplets = (CosmicReco_ && (magField->inTesla(GlobalPoint(0,0,0)).mag() > 0.01));
379 
380  if (!triplets){
381  firstHit = recHits_outer.begin();
382  lastHit = recHits_outer.end();
383  }
384  else if (triplets){
385  firstHit = recHits_outer.begin()+1;
386  lastHit = recHits_outer.end();
387  }
388 
389  for (RoadSearchCloud::RecHitVector::iterator outerHit = firstHit; outerHit != lastHit; ++outerHit) {
390 
391  const DetLayer* middleHitLayer = 0;
392  if (triplets){
393  middleHit = outerHit-1;
394  middleHitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer((*middleHit)->geographicalId());
395  }
396  const DetLayer* outerHitLayer =
397  theMeasurementTracker->geometricSearchTracker()->detLayer((*outerHit)->geographicalId());
398  if (middleHitLayer == outerHitLayer) continue;
399 
401  if (!triplets){
402  if (debug_){
403  std::map<const DetLayer*, int>::iterator ilro = layer_reference.find(outerHitLayer);
404  if (ilro != layer_reference.end()) {
405  std::cout << "Try trajectory with Inner Hit on Layer " << ilayer0 << " and " ;
406  std::cout << "Outer Hit on Layer " << ilro->second << std::endl;
407  }
408  }
409  fts = initialTrajectory(es,*innerHit,*outerHit);
410  }
411  else if (triplets){
412  if (debug_){
413  std::map<const DetLayer*, int>::iterator ilrm = layer_reference.find(middleHitLayer);
414  std::map<const DetLayer*, int>::iterator ilro = layer_reference.find(outerHitLayer);
415  if (ilro != layer_reference.end() && ilrm != layer_reference.end()) {
416  std::cout << "Try trajectory with Hits on Layers " << ilayer0 << " , "
417  << ilrm->second << " and " << ilro->second << std::endl;
418  }
419  }
420  fts = initialTrajectoryFromTriplet(es,*innerHit,*middleHit,*outerHit);
421  }
422 
423  if (!fts.hasError()) continue;
424  if (debug_) std::cout<<"FTS: " << fts << std::endl;
425 
426  Trajectory seedTraj = createSeedTrajectory(fts,*innerHit,innerHitLayer);
427 
428  std::vector<Trajectory> rawTrajectories;
429  if (seedTraj.isValid() && !seedTraj.measurements().empty() ) rawTrajectories.push_back(seedTraj);//GC
430  //rawTrajectories.push_back(seedTraj);
431 
432  int ntested = 0;
433  // now loop on hits
434  std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr_start = (goodHits.begin()+1);
435  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilhv = ilyr_start;
436  ilhv != goodHits.end(); ++ilhv) {
437  RoadSearchCloud::RecHitVector& hits = ilhv->second;
438  //std::vector<Trajectory> newTrajectories;
439  ++ntested;
440  if (debug_){
441  std::map<const DetLayer*, int>::iterator ilr = cloud_layer_reference.find(ilhv->first);
442  if (ilr != cloud_layer_reference.end())
443  std::cout << "extrapolating " << rawTrajectories.size()
444  << " trajectories to layer " << ilr->second
445  << " which has " << hits.size() << " hits " << std::endl;
446  }
447 
448  std::vector<Trajectory>newTrajectories;
449  for (std::vector<Trajectory>::const_iterator it = rawTrajectories.begin();
450  it != rawTrajectories.end(); it++) {
451  if (debug_) std::cout << "extrapolating Trajectory #" << it-rawTrajectories.begin() << std::endl;
452  if (it->direction()==alongMomentum) thePropagator = theAloPropagator;//GC
454 
455  std::vector<Trajectory> theTrajectories = extrapolateTrajectory(*it,hits,
456  innerHitLayer, *outerHit, outerHitLayer);
457  if (theTrajectories.empty()) {
458  if (debug_) std::cout<<" Could not add the hit in this layer " << std::endl;
459  if (debug_){
460  std::cout << " --> trajectory " << it-rawTrajectories.begin()
461  << " has "<<it->recHits().size()<<" hits after "
462  << (ilhv-ilyr_start+1) << " tested (ntested=" <<ntested<<") "
463  << " --> misses="<< (ilhv-ilyr_start+1)-(it->recHits().size()-1)
464  << " but there are " << (goodHits.end() - ilhv)
465  <<" more layers in first pass and "<< skipped_layers.size() <<" skipped layers " <<std::endl;
466 
467 
468  }
469  // layer missed
470  if ((ilhv-ilyr_start+1)-(it->recHits().size()-1) <= nlost_max){
471  newTrajectories.push_back(*it);
472  }
473  }
474  else{ // added hits in this layers
475  for (std::vector<Trajectory>::const_iterator it = theTrajectories.begin();
476  it != theTrajectories.end(); it++) {
477  newTrajectories.push_back(*it);
478  }
479  }
480  } // end loop over rawTrajectories
481  rawTrajectories = newTrajectories;
482  if (newTrajectories.empty()) break;
483  }
484  if (rawTrajectories.size()==0){
485  continue;
486  if (debug_) std::cout<<" --> yields ZERO raw trajectories!" << std::endl;
487  }
488  if (debug_){
489  for (std::vector<Trajectory>::const_iterator it = rawTrajectories.begin();
490  it != rawTrajectories.end(); it++) {
491  std::cout << " --> yields trajectory with "<<it->recHits().size()<<" hits with chi2="
492  <<it->chiSquared()<<" and is valid? "<<it->isValid() <<std::endl;
493  }
494  }
495  std::vector<Trajectory> rawCleaned;
496  theTrajectoryCleaner->clean(rawTrajectories);
497  for (std::vector<Trajectory>::const_iterator itr = rawTrajectories.begin();
498  itr != rawTrajectories.end(); ++itr) {
499  // see how many layers have been found
500  if (!itr->isValid()) continue;
501  std::set<const DetLayer*> used_layers;
502  Trajectory::DataContainer tmv = itr->measurements();
503  for (Trajectory::DataContainer::iterator itm = tmv.begin();
504  itm != tmv.end(); ++itm) {
506  if (!rh->isValid()) continue;
507  used_layers.insert(theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()));
508  }
509 
510  // need to subtract 1 from used_layers since it includes the starting layer
511  if (debug_) std::cout<<"Used " << (used_layers.size()-1) << " layers out of " << ngoodlayers
512  << " good layers, so " << ngoodlayers - (used_layers.size()-1) << " missed "
513  << std::endl;
514  if ((int)used_layers.size() < nFoundMin_) continue;
515  unsigned int nlostlayers = ngoodlayers - (used_layers.size()-1);
516  if (nlostlayers > nlost_max) continue;
517 
518  rawCleaned.push_back(*itr);
519 
520  }
521  if (!rawCleaned.empty()) {
522  ChunkTrajectories.insert(ChunkTrajectories.end(), rawCleaned.begin(), rawCleaned.end());
523  }
524  } // END LOOP OVER OUTER HITS
525  } // END LOOP OVER INNER HITS
526  // At this point we have made all the trajectories from the low occupancy layers
527  // We clean these trajectories first, and then try to add hits from the skipped layers
528 
529  // }
530  if (debug_) std::cout << "Clean the " << ChunkTrajectories.size()<<" trajectories for this chunk" << std::endl;
531  // clean the intermediate result
532  theTrajectoryCleaner->clean(ChunkTrajectories);
533  for (std::vector<Trajectory>::const_iterator it = ChunkTrajectories.begin();
534  it != ChunkTrajectories.end(); it++) {
535  if (it->isValid()) CleanChunks.push_back(*it);
536  }
537  if (debug_) std::cout <<"After cleaning there are " << CleanChunks.size() << " trajectories for this chunk" << std::endl;
538 
539 
540  // ********************* BEGIN NEW ADDITION
541 
542  //
543  // Step 2: recover measurements from busy layers
544  //
545 
546  std::vector<Trajectory> extendedChunks;
547 
548 
549  // see if there are layers that we skipped
550 
551  if (debug_){
552  if (skipped_layers.empty()) {
553  std::cout << "all layers were used in first pass" << std::endl;
554  } else {
555  std::cout << "There are " << skipped_layer_detmap.size() << " skipped layers:";
556  for (std::map<int, const DetLayer*>::const_iterator imap = skipped_layer_detmap.begin();
557  imap!=skipped_layer_detmap.end(); imap++){
558  std::cout<< " " <<imap->first;
559  }
560  std::cout << std::endl;
561  }
562  }
563 
564  for (std::vector<Trajectory>::const_iterator i = CleanChunks.begin();
565  i != CleanChunks.end(); i++) {
566  if (!(*i).isValid()) continue;
567  if (debug_) std::cout<< "Now process CleanChunk trajectory " << i-CleanChunks.begin() << std::endl;
568  bool all_layers_used = false;
569  if (skipped_layers.empty() && i->measurements().size() >= theNumHitCut) {
570  if (debug_) std::cout<<"The trajectory has " << i->measurements().size()
571  << " hits from a cloud of " << RecHitsByLayer.size()
572  << " layers and a chunk of " << (RecHitsByLayer.size() - ilayer0) << " layers " << std::endl;
573  extendedChunks.insert(extendedChunks.end(), *i);
574  if (i->measurements().size() >= (RecHitsByLayer.size() - ilayer0)){
575  all_layers_used = true;
576  break;
577  }
578  }
579  else {
580 
581  Trajectory temptraj = *i;
582  Trajectory::DataContainer tmv = (*i).measurements();
583  if (tmv.size()+skipped_layer_detmap.size() < theNumHitCut) continue;
584 
585  // Debug dump of hits
586  if (debug_){
587  for (Trajectory::DataContainer::const_iterator ih=tmv.begin();
588  ih!=tmv.end();++ih){
590  const DetLayer* Layer =
591  theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId());
592  std::map<const DetLayer*, int>::iterator ilr = cloud_layer_reference.find(Layer);
593  if (ilr != cloud_layer_reference.end())
594  std::cout << " Hit #"<<ih-tmv.begin() << " of " << tmv.size()
595  <<" is on Layer " << ilr->second << std::endl;
596  else
597  std::cout << " Layer for Hit #"<<ih-tmv.begin() <<" can't be found " << std::endl;
598  std::cout<<" updatedState:\n" << ih->updatedState() << std::endl;
599  std::cout<<" predictState:\n" << ih->predictedState() << std::endl;
600  }
601  }
602 
603  // Loop over the layers in the cloud
604 
605  std::set<const DetLayer*> final_layers;
606  Trajectory::DataContainer::const_iterator im = tmv.begin();
607  Trajectory::DataContainer::const_iterator im2 = tmv.begin();
608 
609  TrajectoryMeasurement firstMeasurement = i->firstMeasurement();
610  const DetLayer* firstDetLayer =
611  theMeasurementTracker->geometricSearchTracker()->detLayer(firstMeasurement.recHit()->geographicalId());
612 
613  std::vector<Trajectory> freshStartv = theSmoother->trajectories(*i);
614 
615  if(debug_) std::cout<<"Smoothing has returned " << freshStartv.size() <<" trajectory " << std::endl;
616  if (!freshStartv.empty()){
617  if(debug_) std::cout<< "Smoothing of trajectory " <<i-CleanChunks.begin() << " has succeeded with " << freshStartv.begin()->measurements().size() << " hits and a chi2 of " << freshStartv.begin()->chiSquared() <<" for " << freshStartv.begin()->ndof() << " DOF. Now add hits." <<std::endl;
618  } else {
619  if (debug_) std::cout<< "Smoothing of trajectory " <<i-CleanChunks.begin() <<" has failed"<<std::endl;
620  continue;
621  }
622 
623  Trajectory freshStart = *freshStartv.begin();
624  std::vector<TrajectoryMeasurement> freshStartTM = freshStart.measurements();
625 
626  if (debug_) {
627  for (std::vector<TrajectoryMeasurement>::const_iterator itm = freshStartTM.begin();itm != freshStartTM.end(); ++itm){
628  std::cout<<"Trajectory hit " << itm-freshStartTM.begin() <<" updatedState:\n" << itm->updatedState() << std::endl;
629  }
630  }
631 
632  TrajectoryStateOnSurface NewFirstTsos = freshStart.lastMeasurement().updatedState();
633  if(debug_) std::cout<<"NewFirstTSOS is valid? " << NewFirstTsos.isValid() << std::endl;
634  if(debug_) std::cout << " NewFirstTSOS:\n " << NewFirstTsos << std::endl;
636 
637  if(debug_) {
638  std::cout<< "First hit for fresh start on det " << rh->det() << ", r/phi/z = " << rh->globalPosition().perp() << " " << rh->globalPosition().phi() << " " << rh->globalPosition().z();
639  }
640 
641  PTrajectoryStateOnDet* pFirstState = TrajectoryStateTransform().persistentState(NewFirstTsos,
642  rh->geographicalId().rawId());
644  newHits.push_back(rh->hit()->clone());
645 
646  TrajectorySeed tmpseed = TrajectorySeed(*pFirstState,
647  newHits,
648  i->direction());
649 
651  if (i->direction()==oppositeToMomentum) thePropagator = theRevPropagator;
652 
653  delete pFirstState;
654 
655 
656  Trajectory newTrajectory(tmpseed,tmpseed.direction());
657 
658  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
659  TrajectoryStateOnSurface invalidState(new BasicSingleTrajectoryState(det->surface()));
660  newTrajectory.push(TrajectoryMeasurement(invalidState, NewFirstTsos, rh, 0, firstDetLayer));
661  final_layers.insert(firstDetLayer);
662 
663  if(debug_) std::cout << "TRAJ is valid: " << newTrajectory.isValid() <<std::endl;
664 
665  TrajectoryStateOnSurface testTsos = newTrajectory.measurements().back().updatedState();
666 
667  if(debug_) {
668  std::cout << "testTSOS is valid!!" << testTsos.isValid() << std::endl;
669  std::cout << " testTSOS (x/y/z): " << testTsos.globalPosition().x()<< " / " << testTsos.globalPosition().y()<< " / " << testTsos.globalPosition().z() << std::endl;
670  std::cout << " local position x: " << testTsos.localPosition().x() << "+-" << sqrt(testTsos.localError().positionError().xx()) << std::endl;
671  }
672 
673  if (firstDetLayer != ilyr0->first){
674  if (debug_) std::cout<<"!!! ERROR !!! firstDetLayer ("<<firstDetLayer<<") != ilyr0 ( " <<ilyr0->first <<")"<< std::endl;
675  }
676  ++im;
677 
678  if (debug_){
679  std::map<const DetLayer*, int>::iterator ilr = cloud_layer_reference.find(firstDetLayer);
680  if (ilr != cloud_layer_reference.end() ){
681  std::cout << " First hit is on layer " << ilr->second << std::endl;
682  }
683  }
684  for (std::vector<std::pair<const DetLayer*, RoadSearchCloud::RecHitVector > >::iterator ilyr = ilyr0+1;
685  ilyr != RecHitsByLayer.end(); ++ilyr) {
686 
687  TrajectoryStateOnSurface predTsos;
688  TrajectoryStateOnSurface currTsos;
690 
691  if(debug_)
692  std::cout<<"Trajectory has " << newTrajectory.measurements().size() << " measurements with " << (RecHitsByLayer.end()-ilyr)
693  << " remaining layers " << std::endl;
694 
695  if (im != tmv.end()) im2 = im;
696  TransientTrackingRecHit::ConstRecHitPointer rh = im2->recHit(); // Current
697  if (rh->isValid() &&
698  theMeasurementTracker->geometricSearchTracker()->detLayer(rh->geographicalId()) == ilyr->first) {
699 
700  if (debug_) std::cout<<" Layer " << ilyr-RecHitsByLayer.begin() <<" has a good hit " << std::endl;
701  ++im;
702 
703  const GeomDet* det = trackerGeom->idToDet(rh->geographicalId());
704 
705  currTsos = newTrajectory.measurements().back().updatedState();
706  predTsos = thePropagator->propagate(currTsos, det->surface());
707  if (!predTsos.isValid()) continue;
708  GlobalVector propagationDistance = predTsos.globalPosition() - currTsos.globalPosition();
709  if (propagationDistance.mag() > maxPropagationDistance) continue;
711  if(debug_) {
712  std::cout << "Propagation distance2 is " << propagationDistance.mag() << std::endl;
713  std::cout << "predTSOS is valid!!" << std::endl;
714  std::cout << " predTSOS (x/y/z): " << predTsos.globalPosition().x()<< " / " << predTsos.globalPosition().y()<< " / " << predTsos.globalPosition().z() << std::endl;
715  std::cout << " local position x: " << predTsos.localPosition().x() << "+-" << sqrt(predTsos.localError().positionError().xx()) << std::endl;
716  std::cout << " local position y: " << predTsos.localPosition().y() << "+-" << sqrt(predTsos.localError().positionError().yy()) << std::endl;
717  std::cout << "currTSOS is valid!! " << currTsos.isValid() << std::endl;
718  std::cout << " currTSOS (x/y/z): " << currTsos.globalPosition().x()<< " / " << currTsos.globalPosition().y()<< " / " << currTsos.globalPosition().z() << std::endl;
719  std::cout << " local position x: " << currTsos.localPosition().x() << "+-" << sqrt(currTsos.localError().positionError().xx()) << std::endl;
720  std::cout << " local position y: " << currTsos.localPosition().y() << "+-" << sqrt(currTsos.localError().positionError().yy()) << std::endl;
721  }
722 
723  if (!est.first) {
724  if (debug_) std::cout<<"Failed to add one of the original hits on a low occupancy layer!!!!" << std::endl;
725  continue;
726  }
727  currTsos = theUpdator->update(predTsos, *rh);
728  tm = TrajectoryMeasurement(predTsos, currTsos, &(*rh),est.second,ilyr->first);
729 
730  const TrajectoryStateOnSurface theTSOS = newTrajectory.lastMeasurement().updatedState();
731 
732  //std::cout << "11TsosBefore (x/y/z): " << theTSOS.globalPosition().x()<< " / " << theTSOS.globalPosition().y()<< " / " << theTSOS.globalPosition().z() << std::endl;
733  //std::cout << " 11local position x: " << theTSOS.localPosition().x() << "+-" << sqrt(theTSOS.localError().positionError().xx()) << std::endl;
734  //std::cout << " 11local position y: " << theTSOS.localPosition().y() << "+-" << sqrt(theTSOS.localError().positionError().yy()) << std::endl;
735 
736 
737 
738  newTrajectory.push(tm,est.second);
739  final_layers.insert(ilyr->first);
740  }
741  else{
742  if (debug_) std::cout<<" Layer " << ilyr-RecHitsByLayer.begin() <<" is one of the skipped layers " << std::endl;
743 
744  //collect hits in the skipped layer
745  edm::OwnVector<TrackingRecHit> skipped_hits;
746  std::set<const GeomDet*> dets;
747  for (RoadSearchCloud::RecHitVector::const_iterator ih = ilyr->second.begin();
748  ih != ilyr->second.end(); ++ih) {
749  skipped_hits.push_back((*ih)->clone());
750  dets.insert(trackerGeom->idToDet((*ih)->geographicalId()));
751  }
752 
753  if(debug_){
754  std::cout<<" ---> probing missing hits (nh="<< skipped_hits.size() << ", nd=" << dets.size()
755  << ") in layer " << ilyr-RecHitsByLayer.begin() <<std::endl;
756  }
757 
758  const TrajectoryStateOnSurface theTSOS = newTrajectory.lastMeasurement().updatedState();
759 
760  //std::cout << "TsosBefore (x/y/z): " << theTSOS.globalPosition().x()<< " / " << theTSOS.globalPosition().y()<< " / " << theTSOS.globalPosition().z() << std::endl;
761  //std::cout << " local position x: " << theTSOS.localPosition().x() << "+-" << sqrt(theTSOS.localError().positionError().xx()) << std::endl;
762  //std::cout << " local position y: " << theTSOS.localPosition().y() << "+-" << sqrt(theTSOS.localError().positionError().yy()) << std::endl;
763 
764  std::vector<TrajectoryMeasurement> theGoodHits = FindBestHits(theTSOS,dets,theHitMatcher,skipped_hits);
765  if (!theGoodHits.empty()){
766  final_layers.insert(ilyr->first);
767  if (debug_) std::cout<<"Found " << theGoodHits.size() << " good hits to add" << std::endl;
768  for (std::vector<TrajectoryMeasurement>::const_iterator im=theGoodHits.begin();im!=theGoodHits.end();++im){
769  newTrajectory.push(*im,im->estimate());
770  }
771  }
772  }
773  } // END 2nd PASS LOOP OVER LAYERS IN CLOUD
774 
775  if (debug_) std::cout<<"Finished loop over layers in cloud. Trajectory now has " <<newTrajectory.measurements().size()
776  << " hits. " << std::endl;
777  if (debug_) std::cout<<"The trajectory has " << newTrajectory.measurements().size() <<" hits on " << final_layers.size()
778  << " layers from a cloud of " << RecHitsByLayer.size()
779  << " layers and a chunk of " << (RecHitsByLayer.size() - ilayer0) << " layers " << std::endl;
780  if (newTrajectory.measurements().size() >= theNumHitCut)
781  extendedChunks.insert(extendedChunks.end(), newTrajectory);
782  if (final_layers.size() >= (RecHitsByLayer.size() - ilayer0)){
783  if (debug_) std::cout<<"All layers of the chunk have been used..." << std::endl;
784  all_layers_used = true;
785  }
786  } // END ELSE TO RECOVER SKIPPED LAYERS
787  if (all_layers_used) {
788  if (debug_) std::cout << "All layers were used, so break....." << std::endl;
789  all_chunk_layers_used = true;
790  break;
791  }
792  if (debug_) std::cout<<"Going to next clean chunk....." << std::endl;
793  } // END LOOP OVER CLEAN CHUNKS
794  if (debug_) std::cout<< "Now Clean the " << extendedChunks.size() << " extended chunks " <<std::endl;
795  if (extendedChunks.size() > 1) theTrajectoryCleaner->clean(extendedChunks);
796  for (std::vector<Trajectory>::const_iterator it = extendedChunks.begin();
797  it != extendedChunks.end(); it++) {
798  if (it->isValid()) CloudTrajectories.push_back(*it);
799  }
800  if (all_chunk_layers_used) break;
801  }
802 
803  // ********************* END NEW ADDITION
804 
805  if (debug_) std::cout<< "Finished with the cloud, so clean the "
806  << CloudTrajectories.size() << " cloud trajectories "<<std::endl ;
807  theTrajectoryCleaner->clean(CloudTrajectories);
808  for (std::vector<Trajectory>::const_iterator it = CloudTrajectories.begin();
809  it != CloudTrajectories.end(); it++) {
810  if (it->isValid()) FinalTrajectories.push_back(*it);
811  }
812 
813  if (debug_) std::cout<<" Final trajectories now has size " << FinalTrajectories.size()<<std::endl ;
814 
815  } // End loop over Cloud Collection
816 
817 
818  if (debug_) std::cout<< " Finished loop over all clouds " <<std::endl;
819 
820  output = PrepareTrackCandidates(FinalTrajectories);
821 
822  delete theAloPropagator;
823  delete theRevPropagator;
825  delete theHitMatcher;
826  delete theSmoother;
827 
828  if (debug_ || debugCosmics_) std::cout<< "Found " << output.size() << " track candidate(s)."<<std::endl;
829 
830 }
#define LogDebug(id)
PropagationDirection direction() const
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:19
T perp() const
Definition: PV3DBase.h:66
FreeTrajectoryState initialTrajectory(const edm::EventSetup &es, const TrackingRecHit *InnerHit, const TrackingRecHit *OuterHit)
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TransientTrackingRecHit &hit) const =0
FreeTrajectoryState initialTrajectoryFromTriplet(const edm::EventSetup &es, const TrackingRecHit *InnerHit, const TrackingRecHit *MiddleHit, const TrackingRecHit *OuterHit)
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
virtual void update(const edm::Event &) const
std::vector< Trajectory > extrapolateTrajectory(const Trajectory &inputTrajectory, RoadSearchCloud::RecHitVector &theLayerHits, const DetLayer *innerHitLayer, const TrackingRecHit *outerHit, const DetLayer *outerHitLayer)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
size_type size() const
Definition: OwnVector.h:262
virtual void clean(TrajectoryPointerContainer &) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:57
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
LocalError positionError() const
U second(std::pair< T, U > const &p)
virtual std::vector< Trajectory > trajectories(const Trajectory &aTraj) const
DataContainer const & measurements() const
Definition: Trajectory.h:169
void push_back(D *&d)
Definition: OwnVector.h:290
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
T mag() const
Definition: PV3DBase.h:61
float yy() const
Definition: LocalError.h:21
T sqrt(T t)
Definition: SSEVec.h:28
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:147
T z() const
Definition: PV3DBase.h:58
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
Trajectory createSeedTrajectory(FreeTrajectoryState &fts, const TrackingRecHit *InnerHit, const DetLayer *innerHitLayer)
TrajectoryStateOnSurface updatedState() const
PTrajectoryStateOnDet * persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid) const
const LocalTrajectoryError & localError() const
virtual const GeomDet * idToDet(DetId) const
tuple input
Definition: collect_tpl.py:10
std::pair< bool, double > HitReturnType
bool isValid() const
Definition: Trajectory.h:225
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< TrajectoryMeasurement > FindBestHits(const TrajectoryStateOnSurface &tsosBefore, const std::set< const GeomDet * > &theDets, const SiStripRecHitMatcher *theHitMatcher, edm::OwnVector< TrackingRecHit > &theHits)
tuple cout
Definition: gather_cfg.py:41
std::vector< const TrackingRecHit * > RecHitVector
bool chooseStartingLayers(std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > > &RecHitsByLayer, std::vector< std::pair< const DetLayer *, RoadSearchCloud::RecHitVector > >::iterator ilyr0, const std::multimap< int, const DetLayer * > &layer_map, std::set< const DetLayer * > &good_layers, std::vector< const DetLayer * > &middle_layers, RoadSearchCloud::RecHitVector &recHits_middle)
const GeometricSearchTracker * geometricSearchTracker() const
T x() const
Definition: PV3DBase.h:56
TrackCandidateCollection PrepareTrackCandidates(std::vector< Trajectory > &theTrajectories)
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37

Member Data Documentation

edm::ParameterSet RoadSearchTrackCandidateMakerAlgorithm::conf_
private
bool RoadSearchTrackCandidateMakerAlgorithm::CosmicReco_
private
double RoadSearchTrackCandidateMakerAlgorithm::cosmicSeedPt_
private
bool RoadSearchTrackCandidateMakerAlgorithm::CosmicTrackMerging_
private
bool RoadSearchTrackCandidateMakerAlgorithm::debug_
private
bool RoadSearchTrackCandidateMakerAlgorithm::debugCosmics_
private
double RoadSearchTrackCandidateMakerAlgorithm::initialVertexErrorXY_
private
bool RoadSearchTrackCandidateMakerAlgorithm::lstereo[128]
private

Definition at line 151 of file RoadSearchTrackCandidateMakerAlgorithm.h.

Referenced by chooseStartingLayers(), and run().

const MagneticField* RoadSearchTrackCandidateMakerAlgorithm::magField
private
double RoadSearchTrackCandidateMakerAlgorithm::maxPropagationDistance
private
std::string RoadSearchTrackCandidateMakerAlgorithm::measurementTrackerName_
private
int RoadSearchTrackCandidateMakerAlgorithm::MinChunkLength_
private
int RoadSearchTrackCandidateMakerAlgorithm::nFoundMin_
private
bool RoadSearchTrackCandidateMakerAlgorithm::NoFieldCosmic_
private

Definition at line 118 of file RoadSearchTrackCandidateMakerAlgorithm.h.

Referenced by initialTrajectory(), and run().

bool RoadSearchTrackCandidateMakerAlgorithm::splitMatchedHits_
private
PropagatorWithMaterial* RoadSearchTrackCandidateMakerAlgorithm::theAloPropagator
private
AnalyticalPropagator* RoadSearchTrackCandidateMakerAlgorithm::theAnalyticalPropagator
private

Definition at line 142 of file RoadSearchTrackCandidateMakerAlgorithm.h.

Referenced by PrepareTrackCandidates(), and run().

double RoadSearchTrackCandidateMakerAlgorithm::theChi2Cut
private
MeasurementEstimator* RoadSearchTrackCandidateMakerAlgorithm::theEstimator
private
SiStripRecHitMatcher* RoadSearchTrackCandidateMakerAlgorithm::theHitMatcher
private
const MeasurementTracker* RoadSearchTrackCandidateMakerAlgorithm::theMeasurementTracker
private
unsigned int RoadSearchTrackCandidateMakerAlgorithm::theNumHitCut
private
PropagatorWithMaterial* RoadSearchTrackCandidateMakerAlgorithm::thePropagator
private
PropagatorWithMaterial* RoadSearchTrackCandidateMakerAlgorithm::theRevPropagator
private
KFTrajectorySmoother* RoadSearchTrackCandidateMakerAlgorithm::theSmoother
private

Definition at line 146 of file RoadSearchTrackCandidateMakerAlgorithm.h.

Referenced by PrepareTrackCandidates(), and run().

TrajectoryCleanerBySharedHits* RoadSearchTrackCandidateMakerAlgorithm::theTrajectoryCleaner
private
TrajectoryStateTransform* RoadSearchTrackCandidateMakerAlgorithm::theTransformer
private
TrajectoryStateUpdator* RoadSearchTrackCandidateMakerAlgorithm::theUpdator
private
const TrackerGeometry* RoadSearchTrackCandidateMakerAlgorithm::trackerGeom
private
const TransientTrackingRecHitBuilder* RoadSearchTrackCandidateMakerAlgorithm::ttrhBuilder
private