CMS 3D CMS Logo

BaseCkfTrajectoryBuilder.cc
Go to the documentation of this file.
2 
8 
9 
17 
21 
27 
29  std::unique_ptr<TrajectoryFilter> filter,
30  std::unique_ptr<TrajectoryFilter> inOutFilter):
31  theUpdator(nullptr),
32  thePropagatorAlong(nullptr),
33  thePropagatorOpposite(nullptr),
34  theEstimator(nullptr),
35  theTTRHBuilder(nullptr),
36  theMeasurementTracker(nullptr),
37  theFilter(std::move(filter)),
38  theInOutFilter(std::move(inOutFilter)),
39  theUpdatorName(conf.getParameter<std::string>("updator")),
40  thePropagatorAlongName(conf.getParameter<std::string>("propagatorAlong")),
41  thePropagatorOppositeName(conf.getParameter<std::string>("propagatorOpposite")),
42  theEstimatorName(conf.getParameter<std::string>("estimator")),
43  theRecHitBuilderName(conf.getParameter<std::string>("TTRHBuilder"))
44 {
45  if (conf.exists("clustersToSkip")) edm::LogError("BaseCkfTrajectoryBuilder") << "ERROR: " << typeid(*this).name() << " has a clustersToSkip parameter set";
46 }
47 
48 
50 }
51 
53  return std::unique_ptr<TrajectoryFilter>{TrajectoryFilterFactory::get()->create(pset.getParameter<std::string>("ComponentType"), pset, iC)};
54 }
55 
56 void
58 {
59 
60 
61  TrajectorySeed::range hitRange = seed.recHits();
62 
63  PTrajectoryStateOnDet pState( seed.startingState());
64  const GeomDet* gdet = theMeasurementTracker->geomTracker()->idToDet(pState.detId());
65  TSOS outerState = trajectoryStateTransform::transientState(pState, &(gdet->surface()),
67 
68 
69  for (TrajectorySeed::const_iterator ihit = hitRange.first; ihit != hitRange.second; ihit++) {
70 
71  TrackingRecHit::RecHitPointer recHit = ihit->cloneSH();
72  const GeomDet* hitGeomDet = recHit->det();
73 
74  const DetLayer* hitLayer =
75  theMeasurementTracker->geometricSearchTracker()->detLayer(ihit->geographicalId());
76 
77  TSOS invalidState( hitGeomDet->surface());
78  if (ihit == hitRange.second - 1) {
79  // the seed trajectory state should correspond to this hit
80  if (&gdet->surface() != &hitGeomDet->surface()) {
81  edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: the seed state is not on the surface of the detector of the last seed hit";
82  return; // FIXME: should throw exception
83  }
84 
85  //TSOS updatedState = outerstate;
86  result.emplace(invalidState, outerState, recHit, 0, hitLayer);
87  }
88  else {
89  TSOS innerState = backwardPropagator(seed)->propagate(outerState,hitGeomDet->surface());
90 
91  // try to recover if propagation failed
92  if UNLIKELY(!innerState.isValid())
93  innerState =
94  trajectoryStateTransform::transientState(pState, &(hitGeomDet->surface()),
96 
97  if(innerState.isValid()) {
98  TSOS innerUpdated = theUpdator->update(innerState,*recHit);
99  result.emplace(invalidState, innerUpdated, recHit, 0, hitLayer);
100  }
101  }
102  }
103 
104  // method for debugging
105  // fix somehow
106  // fillSeedHistoDebugger(result.begin(),result.end());
107 
108 }
109 
110 
113 {
114  TempTrajectory result(seed.direction(),seed.nHits());
115  seedMeasurements(seed, result);
116 
117  LogDebug("CkfPattern")
118  <<" initial trajectory from the seed: "<<PrintoutHelper::dumpCandidate(result,true);
119 
120  return result;
121 }
122 
123 
125 {
126  if UNLIKELY(traj.measurements().size() > 400) {
127  edm::LogError("BaseCkfTrajectoryBuilder_InfiniteLoop");
128  LogTrace("BaseCkfTrajectoryBuilder_InfiniteLoop") <<
129  "Cropping Track After 400 Measurements:\n" <<
130  " Last predicted state: " << traj.lastMeasurement().predictedState() << "\n" <<
131  " Last layer subdetector: " << (traj.lastLayer() ? traj.lastLayer()->subDetector() : -1) << "\n" <<
132  " Found hits: " << traj.foundHits() << ", lost hits: " << traj.lostHits() << "\n\n";
133  return false;
134  }
135  // Called after each new hit is added to the trajectory, to see if it is
136  // worth continuing to build this track candidate.
137  if (inOut) {
138  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
139  return theInOutFilter->toBeContinued(traj);
140  } else {
141  return theFilter->toBeContinued(traj);
142  }
143 }
144 
145 
146  bool BaseCkfTrajectoryBuilder::qualityFilter( const TempTrajectory& traj, bool inOut) const
147 {
148  // Called after building a trajectory is completed, to see if it is good enough
149  // to keep.
150  if (inOut) {
151  // if (theInOutFilter == 0) edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: trying to use dedicated filter for in-out tracking phase, when none specified";
152  return theInOutFilter->qualityFilter(traj);
153  } else {
154  return theFilter->qualityFilter(traj);
155  }
156 }
157 
158 
159 void
160 BaseCkfTrajectoryBuilder::addToResult (boost::shared_ptr<const TrajectorySeed> const & seed, TempTrajectory& tmptraj,
162  bool inOut) const
163 {
164  // quality check
165  if ( !qualityFilter(tmptraj, inOut) ) return;
166  Trajectory traj = tmptraj.toTrajectory();
167  traj.setSharedSeed(seed);
168  // discard latest dummy measurements
169  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid()) traj.pop();
170  LogDebug("CkfPattern")<<inOut<<"=inOut option. pushing a Trajectory with: "<<traj.foundHits()<<" found hits. "<<traj.lostHits()
171  <<" lost hits. Popped :"<<(tmptraj.measurements().size())-(traj.measurements().size())<<" hits.";
172  result.push_back(std::move(traj));
173 }
174 
175 
176 void
179  bool inOut) const
180 {
181  // quality check
182  if ( !qualityFilter(tmptraj, inOut) ) return;
183  // discard latest dummy measurements
184  TempTrajectory traj = tmptraj;
185  while (!traj.empty() && !traj.lastMeasurement().recHit()->isValid()) traj.pop();
186  LogDebug("CkfPattern")<<inOut<<"=inOut option. pushing a TempTrajectory with: "<<traj.foundHits()<<" found hits. "<<traj.lostHits()
187  <<" lost hits. Popped :"<<(tmptraj.measurements().size())-(traj.measurements().size())<<" hits.";
188  result.push_back(std::move(traj));
189 }
190 
191 void
194  bool inOut) const
195 {
196  // quality check
197  if ( !qualityFilter(traj, inOut) ) return;
198  // discard latest dummy measurements
199  while (!traj.empty() && !traj.lastMeasurement().recHitR().isValid()) traj.pop();
200  LogDebug("CkfPattern")<<inOut<<"=inOut option. pushing a TempTrajectory with: "<<traj.foundHits()<<" found hits. "<<traj.lostHits();
201  // <<" lost hits. Popped :"<<(ttraj.measurements().size())-(traj.measurements().size())<<" hits.";
202  result.push_back(std::move(traj));
203 }
204 
205 
206 
209 {
210  if (traj.empty())
211  {
212  //set the currentState to be the one from the trajectory seed starting point
213  PTrajectoryStateOnDet const & ptod = seed.startingState();
214  DetId id(ptod.detId());
216  const Surface * surface=&g->surface();
217 
218 
221  return StateAndLayers(currentState,theNavigationSchool->nextLayers(*lastLayer,*currentState.freeState(), traj.direction()) );
222  }
223  else
224  {
225  TSOS const & currentState = traj.lastMeasurement().updatedState();
226  return StateAndLayers(currentState,theNavigationSchool->nextLayers(*traj.lastLayer(), *currentState.freeState(), traj.direction()) );
227  }
228 }
229 
231 {
232  // possibly do some sanity check here
234 }
235 
237 {
238  std::cerr << "ERROR SetEvent called on " << typeid(*this).name() << ( theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
239 }
240 
242 {
243  std::cerr << "ERROR unSet called on " << typeid(*this).name() << ( theMeasurementTracker ? " with valid " : "witout any ") << "MeasurementTrackerEvent" << std::endl;
244 }
245 
248  edm::ESHandle<Propagator> propagatorAlongHandle;
249  edm::ESHandle<Propagator> propagatorOppositeHandle;
252 
253  iSetup.get<TrackingComponentsRecord>().get(theUpdatorName, updatorHandle);
254  iSetup.get<TrackingComponentsRecord>().get(thePropagatorAlongName, propagatorAlongHandle);
255  iSetup.get<TrackingComponentsRecord>().get(thePropagatorOppositeName, propagatorOppositeHandle);
256  iSetup.get<TrackingComponentsRecord>().get(theEstimatorName, estimatorHandle);
257  iSetup.get<TransientRecHitRecord>().get(theRecHitBuilderName, recHitBuilderHandle);
258 
259  theUpdator = updatorHandle.product();
260  thePropagatorAlong = propagatorAlongHandle.product();
261  thePropagatorOpposite = propagatorOppositeHandle.product();
262  theEstimator = estimatorHandle.product();
263  theTTRHBuilder = recHitBuilderHandle.product();
264 
265  setData(data);
266  if(theFilter) theFilter->setEvent(iEvent, iSetup);
267  if(theInOutFilter) theInOutFilter->setEvent(iEvent, iSetup);
268  setEvent_(iEvent, iSetup);
269 }
#define LogDebug(id)
PropagationDirection direction() const
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:254
T getParameter(std::string const &) const
int foundHits() const
Definition: Trajectory.h:225
int lostHits() const
Definition: Trajectory.h:236
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
#define nullptr
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
int foundHits() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
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
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:196
virtual const MagneticField * magneticField() const =0
int iEvent
Definition: GenABIO.cc:224
void seedMeasurements(const TrajectorySeed &seed, TempTrajectory &result) const
Trajectory toTrajectory() const
Convert to a standard Trajectory.
recHitContainer::const_iterator const_iterator
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:174
FreeTrajectoryState const * freeState(bool withErrors=true) const
const TransientTrackingRecHitBuilder * theTTRHBuilder
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
std::pair< const_iterator, const_iterator > range
static std::unique_ptr< TrajectoryFilter > createTrajectoryFilter(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
std::unique_ptr< TrajectoryFilter > theInOutFilter
unsigned int detId() const
void addToResult(boost::shared_ptr< const TrajectorySeed > const &seed, TempTrajectory &traj, TrajectoryContainer &result, bool inOut=false) const
const std::string thePropagatorAlongName
#define LogTrace(id)
static std::string dumpCandidate(const Candidate &candidate, bool showErrors=false)
std::shared_ptr< TrackingRecHit const > RecHitPointer
void setSharedSeed(const boost::shared_ptr< const TrajectorySeed > &seed)
Definition: Trajectory.h:334
StateAndLayers findStateAndLayers(const TrajectorySeed &seed, const TempTrajectory &traj) const
const MeasurementTrackerEvent * theMeasurementTracker
Definition: DetId.h:18
PTrajectoryStateOnDet const & startingState() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
void pop()
Definition: Trajectory.cc:29
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&...args) const
NavigationDirection.
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:53
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:82
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
std::pair< TSOS, std::vector< const DetLayer * > > StateAndLayers
T get() const
Definition: EventSetup.h:71
const NavigationSchool * theNavigationSchool
const Propagator * backwardPropagator(const TrajectorySeed &seed) const
TrajectoryStateOnSurface const & updatedState() const
size_type size() const
Definition: bqueue.h:167
#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
T get(const Candidate &c)
Definition: component.h:55
const Chi2MeasurementEstimatorBase * theEstimator
Definition: event.py:1
std::unique_ptr< TrajectoryFilter > theFilter
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
int lostHits() const