CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
48  return TrajectoryFilterFactory::get()->create(pset.getParameter<std::string>("ComponentType"), pset, iC);
49 }
50 
53  PTrajectoryStateOnDet pState(seed.startingState());
54  const GeomDet* gdet = theMeasurementTracker->geomTracker()->idToDet(pState.detId());
55  TSOS outerState =
56  trajectoryStateTransform::transientState(pState, &(gdet->surface()), forwardPropagator(seed)->magneticField());
57 
58  if (as5D) {
59  TrackingRecHit::RecHitPointer recHit(new TRecHit5DParamConstraint(*gdet, outerState));
60  TSOS invalidState(gdet->surface());
61  auto hitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer(pState.detId());
62  result.emplace(invalidState, outerState, recHit, 0, hitLayer);
63  return;
64  }
65 
66  for (auto ihit = seed.recHits().begin(); ihit != seed.recHits().end(); ihit++) {
67  TrackingRecHit::RecHitPointer recHit = ihit->cloneSH();
68  const GeomDet* hitGeomDet = recHit->det();
69 
70  const DetLayer* hitLayer = theMeasurementTracker->geometricSearchTracker()->detLayer(ihit->geographicalId());
71 
72  TSOS invalidState(hitGeomDet->surface());
73  if (ihit == seed.recHits().end() - 1) {
74  // the seed trajectory state should correspond to this hit
75  if (&gdet->surface() != &hitGeomDet->surface()) {
76  edm::LogError("CkfPattern")
77  << "CkfTrajectoryBuilder error: the seed state is not on the surface of the detector of the last seed hit";
78  return; // FIXME: should throw exception
79  }
80 
81  //TSOS updatedState = outerstate;
82  result.emplace(invalidState, outerState, recHit, 0, hitLayer);
83  } else {
84  TSOS innerState = backwardPropagator(seed)->propagate(outerState, hitGeomDet->surface());
85 
86  // try to recover if propagation failed
87  if UNLIKELY (!innerState.isValid())
89  pState, &(hitGeomDet->surface()), forwardPropagator(seed)->magneticField());
90 
91  if (innerState.isValid()) {
92  TSOS innerUpdated = theUpdator->update(innerState, *recHit);
93  result.emplace(invalidState, innerUpdated, recHit, 0, hitLayer);
94  }
95  }
96  }
97 
98  // method for debugging
99  // fix somehow
100  // fillSeedHistoDebugger(result.begin(),result.end());
101 }
102 
104  TempTrajectory result(seed.direction(), seed.nHits());
106 
107  LogDebug("CkfPattern") << " initial trajectory from the seed: " << PrintoutHelper::dumpCandidate(result, true);
108 
109  return result;
110 }
111 
113  if UNLIKELY (traj.measurements().size() > 400) {
114  edm::LogError("BaseCkfTrajectoryBuilder_InfiniteLoop");
115  LogTrace("BaseCkfTrajectoryBuilder_InfiniteLoop")
116  << "Cropping Track After 400 Measurements:\n"
117  << " Last predicted state: " << traj.lastMeasurement().predictedState() << "\n"
118  << " Last layer subdetector: " << (traj.lastLayer() ? traj.lastLayer()->subDetector() : -1) << "\n"
119  << " Found hits: " << traj.foundHits() << ", lost hits: " << traj.lostHits() << "\n\n";
120  return false;
121  }
122  // Called after each new hit is added to the trajectory, to see if it is
123  // worth continuing to build this track candidate.
124  if (inOut) {
125  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
126  return theInOutFilter->toBeContinued(traj);
127  } else {
128  return theFilter->toBeContinued(traj);
129  }
130 }
131 
132 bool BaseCkfTrajectoryBuilder::qualityFilter(const TempTrajectory& traj, bool inOut) const {
133  // Called after building a trajectory is completed, to see if it is good enough
134  // to keep.
135  if (inOut) {
136  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
137  return theInOutFilter->qualityFilter(traj);
138  } else {
139  return theFilter->qualityFilter(traj);
140  }
141 }
142 
143 void BaseCkfTrajectoryBuilder::addToResult(std::shared_ptr<const TrajectorySeed> const& seed,
144  TempTrajectory& tmptraj,
146  bool inOut) const {
147  // quality check
148  if (!qualityFilter(tmptraj, inOut))
149  return;
150  Trajectory traj = tmptraj.toTrajectory();
151  traj.setSharedSeed(seed);
152  // discard latest dummy measurements
153  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid())
154  traj.pop();
155  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a Trajectory with: " << traj.foundHits() << " found hits. "
156  << traj.lostHits()
157  << " lost hits. Popped :" << (tmptraj.measurements().size()) - (traj.measurements().size())
158  << " hits.";
159  result.push_back(std::move(traj));
160 }
161 
164  bool inOut) const {
165  // quality check
166  if (!qualityFilter(tmptraj, inOut))
167  return;
168  // discard latest dummy measurements
169  TempTrajectory traj = tmptraj;
170  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid())
171  traj.pop();
172  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a TempTrajectory with: " << traj.foundHits()
173  << " found hits. " << traj.lostHits()
174  << " lost hits. Popped :" << (tmptraj.measurements().size()) - (traj.measurements().size())
175  << " hits.";
176  result.push_back(std::move(traj));
177 }
178 
180  // quality check
181  if (!qualityFilter(traj, inOut))
182  return;
183  // discard latest dummy measurements
184  while (!traj.empty() && !traj.lastMeasurement().recHitR().isValid())
185  traj.pop();
186  LogDebug("CkfPattern") << inOut << "=inOut option. pushing a TempTrajectory with: " << traj.foundHits()
187  << " found hits. " << traj.lostHits();
188  // <<" lost hits. Popped :"<<(ttraj.measurements().size())-(traj.measurements().size())<<" hits.";
189  result.push_back(std::move(traj));
190 }
191 
193  const TrajectorySeed& seed, const TempTrajectory& traj) const {
194  if (traj.empty()) {
195  //set the currentState to be the one from the trajectory seed starting point
196  PTrajectoryStateOnDet const& ptod = seed.startingState();
197  DetId id(ptod.detId());
199  const Surface* surface = &g->surface();
200 
201  TSOS currentState(
204  return StateAndLayers(currentState,
205  theNavigationSchool->nextLayers(*lastLayer, *currentState.freeState(), traj.direction()));
206  } else {
207  TSOS const& currentState = traj.lastMeasurement().updatedState();
208  return StateAndLayers(
209  currentState, theNavigationSchool->nextLayers(*traj.lastLayer(), *currentState.freeState(), traj.direction()));
210  }
211 }
212 
214  // possibly do some sanity check here
216 }
217 
219  std::cerr << "ERROR SetEvent called on " << typeid(*this).name()
220  << (theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
221 }
222 
224  std::cerr << "ERROR unSet called on " << typeid(*this).name()
225  << (theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
226 }
227 
229  const edm::EventSetup& iSetup,
230  const MeasurementTrackerEvent* data) {
236 
237  setData(data);
238  if (theFilter)
239  theFilter->setEvent(iEvent, iSetup);
240  if (theInOutFilter)
241  theInOutFilter->setEvent(iEvent, iSetup);
242  setEvent_(iEvent, iSetup);
243 }
PropagationDirection direction() const
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
int foundHits() const
Definition: Trajectory.h:206
int lostHits() const
Definition: Trajectory.h:217
TrajectoryStateOnSurface const & predictedState() const
ConstRecHitPointer const & recHit() const
bool empty() const
True if trajectory has no measurements.
uint16_t *__restrict__ id
void setData(const MeasurementTrackerEvent *data)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorAlongToken
const Propagator * forwardPropagator(const TrajectorySeed &seed) const
const DataContainer & measurements() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
const TrajectoryStateUpdator * theUpdator
tuple magneticField
void addToResult(std::shared_ptr< const TrajectorySeed > const &seed, TempTrajectory &traj, TrajectoryContainer &result, bool inOut=false) const
int foundHits() const
Log< level::Error, false > LogError
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
#define LogTrace(id)
void seedMeasurements(const TrajectorySeed &seed, TempTrajectory &result, bool as5D) const
tuple result
Definition: mps_fire.py:311
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
bool getData(T &iHolder) const
Definition: EventSetup.h:128
PropagationDirection direction() const
DataContainer const & measurements() const
Definition: Trajectory.h:178
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
int iEvent
Definition: GenABIO.cc:224
Trajectory toTrajectory() const
Convert to a standard Trajectory.
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
FreeTrajectoryState const * freeState(bool withErrors=true) const
const TransientTrackingRecHitBuilder * theTTRHBuilder
const edm::ESGetToken< Chi2MeasurementEstimatorBase, TrackingComponentsRecord > theEstimatorToken
def move
Definition: eostools.py:511
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
T end() const
Definition: Range.h:16
const TrackerGeomDet * idToDet(DetId) const override
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
RecHitRange recHits() const
const MeasurementTrackerEvent * theMeasurementTracker
Definition: DetId.h:17
const TrackerGeometry * geomTracker() const
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorOppositeToken
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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
BaseCkfTrajectoryBuilder(const edm::ParameterSet &conf, edm::ConsumesCollector iC, std::unique_ptr< TrajectoryFilter > filter, std::unique_ptr< TrajectoryFilter > inOutFilter=nullptr)
void emplace(Args &&...args)
virtual const MagneticField * magneticField() const =0
unsigned int nHits() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
const NavigationSchool * theNavigationSchool
T begin() const
Definition: Range.h:15
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
#define get
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > theRecHitBuilderToken
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
void setEvent(const edm::Event &event) const override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< TrajectoryStateUpdator, TrackingComponentsRecord > theUpdatorToken
const GeometricSearchTracker * geometricSearchTracker() const
std::vector< Trajectory > TrajectoryContainer
const Chi2MeasurementEstimatorBase * theEstimator
std::unique_ptr< TrajectoryFilter > theFilter
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
int lostHits() const
#define LogDebug(id)