CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LayerMeasurements.cc
Go to the documentation of this file.
11 using namespace std;
12 
13 vector<TrajectoryMeasurement>
15  const TrajectoryStateOnSurface& startingState,
16  const Propagator& prop,
17  const MeasurementEstimator& est) const
18 {
20  vector<DetWithState> compatDets = layer.compatibleDets( startingState, prop, est);
21 
22  vector<TrajectoryMeasurement> result;
23  if (compatDets.empty()) {
24  pair<bool, TrajectoryStateOnSurface> compat =
25  layer.compatible( startingState, prop, est);
26 
27 
28  if ( compat.first) {
29  result.push_back( TrajectoryMeasurement( compat.second,
31  &layer));
32  LogDebug("LayerMeasurements")<<"adding a missing hit.";
33  }else LogDebug("LayerMeasurements")<<"adding not measurement.";
34  return result;
35  }
36 
37  GeometricSearchDetMeasurements gsdm( theDetSystem);
38  vector<TrajectoryMeasurement> tmpResult = gsdm.get( layer, compatDets, startingState, prop, est);
39 
40  for(vector<TrajectoryMeasurement>::const_iterator tmpIt=tmpResult.begin();tmpIt!=tmpResult.end();tmpIt++){
41  LogDebug("LayerMeasurements")<<"adding a measurement which rechit is: "<<(tmpIt->recHit()->isValid()?"valid":"invalid");
42  result.push_back( TrajectoryMeasurement(tmpIt->predictedState(),tmpIt->recHit(),tmpIt->estimate(),&layer) );
43  }
44 
45  return result;
46 }
47 
48 
49 vector<TrajectoryMeasurementGroup>
51  const TrajectoryStateOnSurface& startingState,
52  const Propagator& prop,
53  const MeasurementEstimator& est) const
54 {
55  vector<TrajectoryMeasurementGroup> result;
56 
57  vector<DetGroup> groups( layer.groupedCompatibleDets( startingState, prop, est));
58  result.reserve(groups.size());
59  for (vector<DetGroup>::const_iterator grp=groups.begin(); grp!=groups.end(); grp++) {
60  if ( grp->empty() ) continue;
61 
62  vector<TrajectoryMeasurement> tmpVec;
63  for (DetGroup::const_iterator idet=grp->begin(); idet!=grp->end(); idet++) {
64  const MeasurementDet* mdet = theDetSystem->idToDet(idet->det()->geographicalId());
65  if (mdet == 0) {
66  throw MeasurementDetException( "MeasurementDet not found");
67  }
68  vector<TrajectoryMeasurement> tmp =
69  mdet->fastMeasurements( idet->trajectoryState(), startingState, prop, est);
70  if (!tmp.empty()) {
71  // only collect valid RecHits
72  std::vector<TrajectoryMeasurement>::iterator end =
73  (tmp.back().recHit()->getType() != TrackingRecHit::missing ?
74  tmp.end() :
75  tmp.end()-1);
76  tmpVec.insert( tmpVec.end(), tmp.begin(), end);
77  }
78  }
79 
80  vector<TrajectoryMeasurement> tmpVec2;
81  tmpVec2.reserve(tmpVec.size());
82  for(vector<TrajectoryMeasurement>::const_iterator tmpIt=tmpVec.begin();tmpIt!=tmpVec.end();tmpIt++){
83  LogDebug("LayerMeasurements")<<"[grouped] temporaryly adding a measurement which rechit is: "<<(tmpIt->recHit()->isValid()?"valid":"invalid");
84  tmpVec2.push_back( TrajectoryMeasurement(tmpIt->predictedState(),tmpIt->recHit(),tmpIt->estimate(),&layer) );
85  }
86 
87 
88  // sort the final result
89  if ( static_cast<int>(tmpVec2.size()) > 1) {
90  sort( tmpVec2.begin(), tmpVec2.end(), TrajMeasLessEstim());
91  }
92  addInvalidMeas( tmpVec2, *grp,layer);
93  result.push_back( TrajectoryMeasurementGroup( tmpVec2, *grp));
94  }
95 
96  // if the result is empty check if the layer is compatible (for invalid measurement)
97  if (result.empty()) {
98  pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
99  if ( compat.first) {
100  TrajectoryMeasurement inval( compat.second, InvalidTransientRecHit::build(0, TrackingRecHit::inactive,&layer), 0.F,&layer);
101  vector<TrajectoryMeasurement> tmVec(1,inval);
102  result.push_back( TrajectoryMeasurementGroup( tmVec, DetGroup()));
103  }
104  }
105  return result;
106 }
107 
108 void LayerMeasurements::addInvalidMeas( vector<TrajectoryMeasurement>& measVec,
109  const DetGroup& group,
110  const DetLayer& layer) const
111 {
112  if (!measVec.empty()) {
113  // invalidMeas on Det of most compatible hit
114  measVec.push_back( TrajectoryMeasurement( measVec.front().predictedState(),
115  InvalidTransientRecHit::build(measVec.front().recHit()->det(), TrackingRecHit::missing),
116  0.,&layer));
117  }
118  else if (!group.empty()) {
119  // invalid state on first compatible Det
120  measVec.push_back( TrajectoryMeasurement( group.front().trajectoryState(),
121  InvalidTransientRecHit::build(group.front().det(), TrackingRecHit::missing), 0.,&layer));
122  }
123 }
#define LogDebug(id)
virtual std::pair< bool, TrajectoryStateOnSurface > compatible(const TrajectoryStateOnSurface &ts, const Propagator &, const MeasurementEstimator &) const =0
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
static RecHitPointer build(const GeomDet *geom, Type type=TrackingRecHit::missing, const DetLayer *layer=0)
virtual std::vector< DetGroup > groupedCompatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
tuple result
Definition: query.py:137
virtual std::vector< TrajectoryMeasurement > fastMeasurements(const TrajectoryStateOnSurface &stateOnThisDet, const TrajectoryStateOnSurface &startingState, const Propagator &, const MeasurementEstimator &) const =0
#define end
Definition: vmac.h:38
void addInvalidMeas(std::vector< TrajectoryMeasurement > &measVec, const DetGroup &group, const DetLayer &layer) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< TrajectoryMeasurementGroup > groupedMeasurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
std::vector< TrajectoryMeasurement > get(const GeometricSearchDet &det, const std::vector< DetWithState > &compatDets, const TrajectoryState &ts, const Propagator &prop, const MeasurementEstimator &est) const