CMS 3D CMS Logo

BaseCkfTrajectoryBuilder.cc
Go to the documentation of this file.
2 
8 
16 
20 
26 
28  std::unique_ptr<TrajectoryFilter> filter,
29  std::unique_ptr<TrajectoryFilter> inOutFilter)
30  : theSeedAs5DHit(conf.getParameter<bool>("seedAs5DHit")),
31  theFilter(std::move(filter)),
32  theInOutFilter(std::move(inOutFilter)),
33  theUpdatorName(conf.getParameter<std::string>("updator")),
34  thePropagatorAlongName(conf.getParameter<std::string>("propagatorAlong")),
35  thePropagatorOppositeName(conf.getParameter<std::string>("propagatorOpposite")),
36  theEstimatorName(conf.getParameter<std::string>("estimator")),
37  theRecHitBuilderName(conf.getParameter<std::string>("TTRHBuilder")) {
38  if (conf.exists("clustersToSkip"))
39  edm::LogError("BaseCkfTrajectoryBuilder")
40  << "ERROR: " << typeid(*this).name() << " has a clustersToSkip parameter set";
41 }
42 
44 
47  return TrajectoryFilterFactory::get()->create(pset.getParameter<std::string>("ComponentType"), pset, iC);
48 }
49 
52  TrajectorySeed::range hitRange = seed.recHits();
53 
54  PTrajectoryStateOnDet pState(seed.startingState());
55  const GeomDet* gdet = theMeasurementTracker->geomTracker()->idToDet(pState.detId());
56  TSOS outerState =
57  trajectoryStateTransform::transientState(pState, &(gdet->surface()), forwardPropagator(seed)->magneticField());
58 
59  if (as5D) {
61  TSOS invalidState(gdet->surface());
62  auto hitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer(pState.detId());
63  result.emplace(invalidState, outerState, recHit, 0, hitLayer);
64  return;
65  }
66 
67  for (TrajectorySeed::const_iterator ihit = hitRange.first; ihit != hitRange.second; ihit++) {
68  TrackingRecHit::RecHitPointer recHit = ihit->cloneSH();
69  const GeomDet* hitGeomDet = recHit->det();
70 
71  const DetLayer* hitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer(ihit->geographicalId());
72 
73  TSOS invalidState(hitGeomDet->surface());
74  if (ihit == hitRange.second - 1) {
75  // the seed trajectory state should correspond to this hit
76  if (&gdet->surface() != &hitGeomDet->surface()) {
77  edm::LogError("CkfPattern")
78  << "CkfTrajectoryBuilder error: the seed state is not on the surface of the detector of the last seed hit";
79  return; // FIXME: should throw exception
80  }
81 
82  //TSOS updatedState = outerstate;
83  result.emplace(invalidState, outerState, recHit, 0, hitLayer);
84  } else {
85  TSOS innerState = backwardPropagator(seed)->propagate(outerState, hitGeomDet->surface());
86 
87  // try to recover if propagation failed
88  if
89  UNLIKELY(!innerState.isValid())
91  pState, &(hitGeomDet->surface()), forwardPropagator(seed)->magneticField());
92 
93  if (innerState.isValid()) {
94  TSOS innerUpdated = theUpdator->update(innerState, *recHit);
95  result.emplace(invalidState, innerUpdated, recHit, 0, hitLayer);
96  }
97  }
98  }
99 
100  // method for debugging
101  // fix somehow
102  // fillSeedHistoDebugger(result.begin(),result.end());
103 }
104 
106  TempTrajectory result(seed.direction(), seed.nHits());
108 
109  LogDebug("CkfPattern") << " initial trajectory from the seed: " << PrintoutHelper::dumpCandidate(result, true);
110 
111  return result;
112 }
113 
115  if
116  UNLIKELY(traj.measurements().size() > 400) {
117  edm::LogError("BaseCkfTrajectoryBuilder_InfiniteLoop");
118  LogTrace("BaseCkfTrajectoryBuilder_InfiniteLoop")
119  << "Cropping Track After 400 Measurements:\n"
120  << " Last predicted state: " << traj.lastMeasurement().predictedState() << "\n"
121  << " Last layer subdetector: " << (traj.lastLayer() ? traj.lastLayer()->subDetector() : -1) << "\n"
122  << " Found hits: " << traj.foundHits() << ", lost hits: " << traj.lostHits() << "\n\n";
123  return false;
124  }
125  // Called after each new hit is added to the trajectory, to see if it is
126  // worth continuing to build this track candidate.
127  if (inOut) {
128  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
129  return theInOutFilter->toBeContinued(traj);
130  } else {
131  return theFilter->toBeContinued(traj);
132  }
133 }
134 
135 bool BaseCkfTrajectoryBuilder::qualityFilter(const TempTrajectory& traj, bool inOut) const {
136  // Called after building a trajectory is completed, to see if it is good enough
137  // to keep.
138  if (inOut) {
139  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
140  return theInOutFilter->qualityFilter(traj);
141  } else {
142  return theFilter->qualityFilter(traj);
143  }
144 }
145 
146 void BaseCkfTrajectoryBuilder::addToResult(std::shared_ptr<const TrajectorySeed> const& seed,
147  TempTrajectory& tmptraj,
149  bool inOut) const {
150  // quality check
151  if (!qualityFilter(tmptraj, inOut))
152  return;
153  Trajectory traj = tmptraj.toTrajectory();
154  traj.setSharedSeed(seed);
155  // discard latest dummy measurements
156  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid())
157  traj.pop();
158  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a Trajectory with: " << traj.foundHits() << " found hits. "
159  << traj.lostHits()
160  << " lost hits. Popped :" << (tmptraj.measurements().size()) - (traj.measurements().size())
161  << " hits.";
162  result.push_back(std::move(traj));
163 }
164 
167  bool inOut) const {
168  // quality check
169  if (!qualityFilter(tmptraj, inOut))
170  return;
171  // discard latest dummy measurements
172  TempTrajectory traj = tmptraj;
173  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid())
174  traj.pop();
175  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a TempTrajectory with: " << traj.foundHits()
176  << " found hits. " << traj.lostHits()
177  << " lost hits. Popped :" << (tmptraj.measurements().size()) - (traj.measurements().size())
178  << " hits.";
179  result.push_back(std::move(traj));
180 }
181 
183  // quality check
184  if (!qualityFilter(traj, inOut))
185  return;
186  // discard latest dummy measurements
187  while (!traj.empty() && !traj.lastMeasurement().recHitR().isValid())
188  traj.pop();
189  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a TempTrajectory with: " << traj.foundHits()
190  << " found hits. " << traj.lostHits();
191  // <<" lost hits. Popped :"<<(ttraj.measurements().size())-(traj.measurements().size())<<" hits.";
192  result.push_back(std::move(traj));
193 }
194 
196  const TrajectorySeed& seed, const TempTrajectory& traj) const {
197  if (traj.empty()) {
198  //set the currentState to be the one from the trajectory seed starting point
199  PTrajectoryStateOnDet const& ptod = seed.startingState();
200  DetId id(ptod.detId());
202  const Surface* surface = &g->surface();
203 
204  TSOS currentState(
207  return StateAndLayers(currentState,
208  theNavigationSchool->nextLayers(*lastLayer, *currentState.freeState(), traj.direction()));
209  } else {
210  TSOS const& currentState = traj.lastMeasurement().updatedState();
211  return StateAndLayers(
212  currentState, theNavigationSchool->nextLayers(*traj.lastLayer(), *currentState.freeState(), traj.direction()));
213  }
214 }
215 
217  // possibly do some sanity check here
219 }
220 
222  std::cerr << "ERROR SetEvent called on " << typeid(*this).name()
223  << (theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
224 }
225 
227  std::cerr << "ERROR unSet called on " << typeid(*this).name()
228  << (theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
229 }
230 
232  const edm::EventSetup& iSetup,
233  const MeasurementTrackerEvent* data) {
235  edm::ESHandle<Propagator> propagatorAlongHandle;
236  edm::ESHandle<Propagator> propagatorOppositeHandle;
239 
240  iSetup.get<TrackingComponentsRecord>().get(theUpdatorName, updatorHandle);
241  iSetup.get<TrackingComponentsRecord>().get(thePropagatorAlongName, propagatorAlongHandle);
242  iSetup.get<TrackingComponentsRecord>().get(thePropagatorOppositeName, propagatorOppositeHandle);
243  iSetup.get<TrackingComponentsRecord>().get(theEstimatorName, estimatorHandle);
244  iSetup.get<TransientRecHitRecord>().get(theRecHitBuilderName, recHitBuilderHandle);
245 
246  theUpdator = updatorHandle.product();
247  thePropagatorAlong = propagatorAlongHandle.product();
248  thePropagatorOpposite = propagatorOppositeHandle.product();
249  theEstimator = estimatorHandle.product();
250  theTTRHBuilder = recHitBuilderHandle.product();
251 
252  setData(data);
253  if (theFilter)
254  theFilter->setEvent(iEvent, iSetup);
255  if (theInOutFilter)
256  theInOutFilter->setEvent(iEvent, iSetup);
257  setEvent_(iEvent, iSetup);
258 }
#define LogDebug(id)
PropagationDirection direction() const
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
T getParameter(std::string const &) const
int foundHits() const
Definition: Trajectory.h:206
std::pair< const_iterator, const_iterator > range
int lostHits() const
Definition: Trajectory.h:217
const TrackingGeometry * geomTracker() const
TrajectoryStateOnSurface const & predictedState() const
ConstRecHitPointer const & recHit() const
bool empty() const
True if trajectory has no measurements.
void setData(const MeasurementTrackerEvent *data)
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
const DataContainer & measurements() const
BaseCkfTrajectoryBuilder(const edm::ParameterSet &conf, std::unique_ptr< TrajectoryFilter > filter, std::unique_ptr< TrajectoryFilter > inOutFilter=0)
bool exists(std::string const &parameterName) const
checks if a parameter exists
const TrajectoryStateUpdator * theUpdator
virtual const GeomDet * idToDet(DetId) const =0
void addToResult(std::shared_ptr< const TrajectorySeed > const &seed, TempTrajectory &traj, TrajectoryContainer &result, bool inOut=false) const
int foundHits() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
void seedMeasurements(const TrajectorySeed &seed, TempTrajectory &result, bool as5D) const
const TrajectoryMeasurement & lastMeasurement() const
bool qualityFilter(const TempTrajectory &traj, bool inOut=false) const
virtual void setEvent_(const edm::Event &iEvent, const edm::EventSetup &iSetup)=0
PropagationDirection direction() const
DataContainer const & measurements() const
Definition: Trajectory.h:178
virtual const MagneticField * magneticField() const =0
int iEvent
Definition: GenABIO.cc:224
Trajectory toTrajectory() const
Convert to a standard Trajectory.
recHitContainer::const_iterator const_iterator
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
FreeTrajectoryState const * freeState(bool withErrors=true) const
const TransientTrackingRecHitBuilder * theTTRHBuilder
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
static std::unique_ptr< TrajectoryFilter > createTrajectoryFilter(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
std::unique_ptr< TrajectoryFilter > theInOutFilter
unsigned int detId() const
const std::string thePropagatorAlongName
#define LogTrace(id)
static std::string dumpCandidate(const Candidate &candidate, bool showErrors=false)
std::shared_ptr< TrackingRecHit const > RecHitPointer
StateAndLayers findStateAndLayers(const TrajectorySeed &seed, const TempTrajectory &traj) const
const MeasurementTrackerEvent * theMeasurementTracker
Definition: DetId.h:17
PTrajectoryStateOnDet const & startingState() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
void pop()
Definition: Trajectory.cc:30
std::pair< TSOS, std::vector< const DetLayer * > > StateAndLayers
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&...args) const
std::vector< TempTrajectory > TempTrajectoryContainer
void setEvent(const edm::Event &event) const override
range recHits() const
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
void setSharedSeed(const std::shared_ptr< const TrajectorySeed > &seed)
Definition: Trajectory.h:316
const Propagator * thePropagatorOpposite
void moveToResult(TempTrajectory &&traj, TempTrajectoryContainer &result, bool inOut=false) const
void emplace(Args &&...args)
unsigned int nHits() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
T get() const
Definition: EventSetup.h:73
const NavigationSchool * theNavigationSchool
const Propagator * backwardPropagator(const TrajectorySeed &seed) const
TrajectoryStateOnSurface const & updatedState() const
size_type size() const
Definition: bqueue.h:201
#define UNLIKELY(x)
Definition: Likely.h:21
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
T const * product() const
Definition: ESHandle.h:86
const GeometricSearchTracker * geometricSearchTracker() const
std::vector< Trajectory > TrajectoryContainer
def move(src, dest)
Definition: eostools.py:511
const std::string thePropagatorOppositeName
const Chi2MeasurementEstimatorBase * theEstimator
Definition: event.py:1
std::unique_ptr< TrajectoryFilter > theFilter
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
int lostHits() const