CMS 3D CMS Logo

BaseCkfTrajectoryBuilder.cc
Go to the documentation of this file.
2 
8 
16 
20 
25 
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  theUpdatorToken(iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("updator")))),
34  thePropagatorAlongToken(iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("propagatorAlong")))),
35  thePropagatorOppositeToken(
36  iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("propagatorOpposite")))),
37  theEstimatorToken(iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("estimator")))),
38  theRecHitBuilderToken(iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("TTRHBuilder")))) {
39  if (conf.exists("clustersToSkip"))
40  edm::LogError("BaseCkfTrajectoryBuilder")
41  << "ERROR: " << typeid(*this).name() << " has a clustersToSkip parameter set";
42 }
43 
45 
47  iDesc.add<bool>("seedAs5DHit", false);
48  iDesc.add<std::string>("updator", "KFUpdator");
49  iDesc.add<std::string>("propagatorAlong", "PropagatorWithMaterial");
50  iDesc.add<std::string>("propagatorOpposite", "PropagatorWithMaterialOpposite");
51  iDesc.add<std::string>("estimator", "Chi2");
52  iDesc.add<std::string>("TTRHBuilder", "WithTrackAngle");
53 }
54 
57  return TrajectoryFilterFactory::get()->create(pset.getParameter<std::string>("ComponentType"), pset, iC);
58 }
59 
62  PTrajectoryStateOnDet pState(seed.startingState());
63  const GeomDet* gdet = theMeasurementTracker->geomTracker()->idToDet(pState.detId());
64  TSOS outerState =
66 
67  if (as5D) {
69  TSOS invalidState(gdet->surface());
70  auto hitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer(pState.detId());
71  result.emplace(invalidState, outerState, recHit, 0, hitLayer);
72  return;
73  }
74 
75  for (auto ihit = seed.recHits().begin(); ihit != seed.recHits().end(); ihit++) {
76  TrackingRecHit::RecHitPointer recHit = ihit->cloneSH();
77  const GeomDet* hitGeomDet = recHit->det();
78 
79  const DetLayer* hitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer(ihit->geographicalId());
80 
81  TSOS invalidState(hitGeomDet->surface());
82  if (ihit == seed.recHits().end() - 1) {
83  // the seed trajectory state should correspond to this hit
84  if (&gdet->surface() != &hitGeomDet->surface()) {
85  edm::LogError("CkfPattern")
86  << "CkfTrajectoryBuilder error: the seed state is not on the surface of the detector of the last seed hit";
87  return; // FIXME: should throw exception
88  }
89 
90  //TSOS updatedState = outerstate;
91  result.emplace(invalidState, outerState, recHit, 0, hitLayer);
92  } else {
93  TSOS innerState = backwardPropagator(seed)->propagate(outerState, hitGeomDet->surface());
94 
95  // try to recover if propagation failed
96  if UNLIKELY (!innerState.isValid())
98  pState, &(hitGeomDet->surface()), forwardPropagator(seed)->magneticField());
99 
100  if (innerState.isValid()) {
101  TSOS innerUpdated = theUpdator->update(innerState, *recHit);
102  result.emplace(invalidState, innerUpdated, recHit, 0, hitLayer);
103  }
104  }
105  }
106 
107  // method for debugging
108  // fix somehow
109  // fillSeedHistoDebugger(result.begin(),result.end());
110 }
111 
113  TempTrajectory result(seed.direction(), seed.nHits());
115 
116  LogDebug("CkfPattern") << " initial trajectory from the seed: " << PrintoutHelper::dumpCandidate(result, true);
117 
118  return result;
119 }
120 
122  if UNLIKELY (traj.measurements().size() > 400) {
123  edm::LogError("BaseCkfTrajectoryBuilder_InfiniteLoop");
124  LogTrace("BaseCkfTrajectoryBuilder_InfiniteLoop")
125  << "Cropping Track After 400 Measurements:\n"
126  << " Last predicted state: " << traj.lastMeasurement().predictedState() << "\n"
127  << " Last layer subdetector: " << (traj.lastLayer() ? traj.lastLayer()->subDetector() : -1) << "\n"
128  << " Found hits: " << traj.foundHits() << ", lost hits: " << traj.lostHits() << "\n\n";
129  return false;
130  }
131  // Called after each new hit is added to the trajectory, to see if it is
132  // worth continuing to build this track candidate.
133  if (inOut) {
134  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
135  return theInOutFilter->toBeContinued(traj);
136  } else {
137  return theFilter->toBeContinued(traj);
138  }
139 }
140 
141 bool BaseCkfTrajectoryBuilder::qualityFilter(const TempTrajectory& traj, bool inOut) const {
142  // Called after building a trajectory is completed, to see if it is good enough
143  // to keep.
144  if (inOut) {
145  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
146  return theInOutFilter->qualityFilter(traj);
147  } else {
148  return theFilter->qualityFilter(traj);
149  }
150 }
151 
152 void BaseCkfTrajectoryBuilder::addToResult(std::shared_ptr<const TrajectorySeed> const& seed,
153  TempTrajectory& tmptraj,
155  bool inOut) const {
156  // quality check
157  if (!qualityFilter(tmptraj, inOut))
158  return;
159  Trajectory traj = tmptraj.toTrajectory();
160  traj.setSharedSeed(seed);
161  // discard latest dummy measurements
162  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid())
163  traj.pop();
164  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a Trajectory with: " << traj.foundHits() << " found hits. "
165  << traj.lostHits()
166  << " lost hits. Popped :" << (tmptraj.measurements().size()) - (traj.measurements().size())
167  << " hits.";
168  result.push_back(std::move(traj));
169 }
170 
173  bool inOut) const {
174  // quality check
175  if (!qualityFilter(tmptraj, inOut))
176  return;
177  // discard latest dummy measurements
178  TempTrajectory traj = tmptraj;
179  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid())
180  traj.pop();
181  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a TempTrajectory with: " << traj.foundHits()
182  << " found hits. " << traj.lostHits()
183  << " lost hits. Popped :" << (tmptraj.measurements().size()) - (traj.measurements().size())
184  << " hits.";
185  result.push_back(std::move(traj));
186 }
187 
189  // quality check
190  if (!qualityFilter(traj, inOut))
191  return;
192  // discard latest dummy measurements
193  while (!traj.empty() && !traj.lastMeasurement().recHitR().isValid())
194  traj.pop();
195  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a TempTrajectory with: " << traj.foundHits()
196  << " found hits. " << traj.lostHits();
197  // <<" lost hits. Popped :"<<(ttraj.measurements().size())-(traj.measurements().size())<<" hits.";
198  result.push_back(std::move(traj));
199 }
200 
202  const TrajectorySeed& seed, const TempTrajectory& traj) const {
203  if (traj.empty()) {
204  //set the currentState to be the one from the trajectory seed starting point
205  PTrajectoryStateOnDet const& ptod = seed.startingState();
206  DetId id(ptod.detId());
208  const Surface* surface = &g->surface();
209 
210  TSOS currentState(
213  return StateAndLayers(currentState,
214  theNavigationSchool->nextLayers(*lastLayer, *currentState.freeState(), traj.direction()));
215  } else {
216  TSOS const& currentState = traj.lastMeasurement().updatedState();
217  return StateAndLayers(
218  currentState, theNavigationSchool->nextLayers(*traj.lastLayer(), *currentState.freeState(), traj.direction()));
219  }
220 }
221 
223  // possibly do some sanity check here
225 }
226 
228  std::cerr << "ERROR SetEvent called on " << typeid(*this).name()
229  << (theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
230 }
231 
233  std::cerr << "ERROR unSet called on " << typeid(*this).name()
234  << (theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
235 }
236 
238  const edm::EventSetup& iSetup,
239  const MeasurementTrackerEvent* data) {
245 
246  setData(data);
247  if (theFilter)
248  theFilter->setEvent(iEvent, iSetup);
249  if (theInOutFilter)
250  theInOutFilter->setEvent(iEvent, iSetup);
251  setEvent_(iEvent, iSetup);
252 }
StateAndLayers findStateAndLayers(const TrajectorySeed &seed, const TempTrajectory &traj) const
PropagationDirection direction() const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
TrajectoryStateOnSurface const & predictedState() const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void setData(const MeasurementTrackerEvent *data)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorAlongToken
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
const Propagator * backwardPropagator(const TrajectorySeed &seed) const
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
const TrajectoryStateUpdator * theUpdator
int lostHits() const
Definition: Trajectory.h:217
Log< level::Error, false > LogError
int foundHits() const
Definition: Trajectory.h:206
const DataContainer & measurements() const
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
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
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
unsigned int detId() const
#define LogTrace(id)
void seedMeasurements(const TrajectorySeed &seed, TempTrajectory &result, bool as5D) const
DataContainer const & measurements() const
Definition: Trajectory.h:178
virtual void setEvent_(const edm::Event &iEvent, const edm::EventSetup &iSetup)=0
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
int iEvent
Definition: GenABIO.cc:224
bool qualityFilter(const TempTrajectory &traj, bool inOut=false) const
const TransientTrackingRecHitBuilder * theTTRHBuilder
const edm::ESGetToken< Chi2MeasurementEstimatorBase, TrackingComponentsRecord > theEstimatorToken
const TrajectoryMeasurement & lastMeasurement() const
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&... args) const
static std::unique_ptr< TrajectoryFilter > createTrajectoryFilter(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
std::unique_ptr< TrajectoryFilter > theInOutFilter
int foundHits() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
int lostHits() const
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
const TrackerGeomDet * idToDet(DetId) const override
static std::string dumpCandidate(const Candidate &candidate, bool showErrors=false)
std::shared_ptr< TrackingRecHit const > RecHitPointer
const MeasurementTrackerEvent * theMeasurementTracker
Definition: DetId.h:17
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorOppositeToken
void moveToResult(TempTrajectory &&traj, TempTrajectoryContainer &result, bool inOut=false) const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
Trajectory toTrajectory() const
Convert to a standard Trajectory.
void pop()
Definition: Trajectory.cc:30
std::pair< TSOS, std::vector< const DetLayer * > > StateAndLayers
size_type size() const
Definition: bqueue.h:201
std::vector< TempTrajectory > TempTrajectoryContainer
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
void setSharedSeed(const std::shared_ptr< const TrajectorySeed > &seed)
Definition: Trajectory.h:316
TrajectoryStateOnSurface const & updatedState() const
const Propagator * thePropagatorOpposite
const GeometricSearchTracker * geometricSearchTracker() const
BaseCkfTrajectoryBuilder(const edm::ParameterSet &conf, edm::ConsumesCollector iC, std::unique_ptr< TrajectoryFilter > filter, std::unique_ptr< TrajectoryFilter > inOutFilter=nullptr)
virtual const MagneticField * magneticField() const =0
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void addToResult(std::shared_ptr< const TrajectorySeed > const &seed, TempTrajectory &traj, TrajectoryContainer &result, bool inOut=false) const
FreeTrajectoryState const * freeState(bool withErrors=true) const
const NavigationSchool * theNavigationSchool
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
#define UNLIKELY(x)
Definition: Likely.h:21
#define get
const TrackerGeometry * geomTracker() const
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > theRecHitBuilderToken
void setEvent(const edm::Event &event) const override
const edm::ESGetToken< TrajectoryStateUpdator, TrackingComponentsRecord > theUpdatorToken
std::vector< Trajectory > TrajectoryContainer
def move(src, dest)
Definition: eostools.py:511
const Chi2MeasurementEstimatorBase * theEstimator
Definition: event.py:1
std::unique_ptr< TrajectoryFilter > theFilter
ConstRecHitPointer const & recHit() const
bool empty() const
True if trajectory has no measurements.
#define LogDebug(id)