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 
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 =
65  trajectoryStateTransform::transientState(pState, &(gdet->surface()), forwardPropagator(seed)->magneticField());
66 
67  if (as5D) {
68  TrackingRecHit::RecHitPointer recHit(new TRecHit5DParamConstraint(*gdet, outerState));
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 }
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:122
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
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
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)