00001 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
00002 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00003 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00004 #include "TrackingTools/MeasurementDet/interface/GeometricSearchDetMeasurements.h"
00005 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00006 #include "TrackingTools/MeasurementDet/interface/TrajectoryMeasurementGroup.h"
00007 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00008 #include "TrackingTools/MeasurementDet/interface/MeasurementDetSystem.h"
00009 #include "TrackingTools/DetLayers/interface/DetGroup.h"
00010
00011 using namespace std;
00012
00013 vector<TrajectoryMeasurement>
00014 LayerMeasurements::measurements( const DetLayer& layer,
00015 const TrajectoryStateOnSurface& startingState,
00016 const Propagator& prop,
00017 const MeasurementEstimator& est) const
00018 {
00019 typedef DetLayer::DetWithState DetWithState;
00020 vector<DetWithState> compatDets = layer.compatibleDets( startingState, prop, est);
00021
00022 vector<TrajectoryMeasurement> result;
00023 if (compatDets.empty()) {
00024 pair<bool, TrajectoryStateOnSurface> compat =
00025 layer.compatible( startingState, prop, est);
00026
00027 if ( compat.first) {
00028 result.push_back( TrajectoryMeasurement( compat.second,
00029 InvalidTransientRecHit::build(0, TrackingRecHit::missing,&layer), 0.F,
00030 &layer));
00031 }
00032 return result;
00033 }
00034
00035 GeometricSearchDetMeasurements gsdm( theDetSystem);
00036 vector<TrajectoryMeasurement> tmpResult = gsdm.get( layer, compatDets, startingState, prop, est);
00037
00038 for(vector<TrajectoryMeasurement>::const_iterator tmpIt=tmpResult.begin();tmpIt!=tmpResult.end();tmpIt++){
00039 result.push_back( TrajectoryMeasurement(tmpIt->predictedState(),tmpIt->recHit(),tmpIt->estimate(),&layer) );
00040 }
00041
00042 return result;
00043 }
00044
00045
00046 vector<TrajectoryMeasurementGroup>
00047 LayerMeasurements::groupedMeasurements( const DetLayer& layer,
00048 const TrajectoryStateOnSurface& startingState,
00049 const Propagator& prop,
00050 const MeasurementEstimator& est) const
00051 {
00052 vector<TrajectoryMeasurementGroup> result;
00053
00054 vector<DetGroup> groups( layer.groupedCompatibleDets( startingState, prop, est));
00055 for (vector<DetGroup>::const_iterator grp=groups.begin(); grp!=groups.end(); grp++) {
00056 if ( grp->empty() ) continue;
00057
00058 vector<TrajectoryMeasurement> tmpVec;
00059 for (DetGroup::const_iterator idet=grp->begin(); idet!=grp->end(); idet++) {
00060 const MeasurementDet* mdet = theDetSystem->idToDet(idet->det()->geographicalId());
00061 if (mdet == 0) {
00062 throw MeasurementDetException( "MeasurementDet not found");
00063 }
00064 vector<TrajectoryMeasurement> tmp =
00065 mdet->fastMeasurements( idet->trajectoryState(), startingState, prop, est);
00066 if (!tmp.empty()) {
00067
00068 std::vector<TrajectoryMeasurement>::iterator end =
00069 (tmp.back().recHit()->getType() != TrackingRecHit::missing ?
00070 tmp.end() :
00071 tmp.end()-1);
00072 tmpVec.insert( tmpVec.end(), tmp.begin(), end);
00073 }
00074 }
00075
00076 vector<TrajectoryMeasurement> tmpVec2;
00077 for(vector<TrajectoryMeasurement>::const_iterator tmpIt=tmpVec.begin();tmpIt!=tmpVec.end();tmpIt++){
00078 tmpVec2.push_back( TrajectoryMeasurement(tmpIt->predictedState(),tmpIt->recHit(),tmpIt->estimate(),&layer) );
00079 }
00080
00081
00082
00083 if ( static_cast<int>(tmpVec2.size()) > 1) {
00084 sort( tmpVec2.begin(), tmpVec2.end(), TrajMeasLessEstim());
00085 }
00086 addInvalidMeas( tmpVec2, *grp,layer);
00087 result.push_back( TrajectoryMeasurementGroup( tmpVec2, *grp));
00088 }
00089
00090
00091 if (result.empty()) {
00092 pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
00093 if ( compat.first) {
00094 TrajectoryMeasurement inval( compat.second, InvalidTransientRecHit::build(0, TrackingRecHit::missing,&layer), 0.F,&layer);
00095 vector<TrajectoryMeasurement> tmVec(1,inval);
00096 result.push_back( TrajectoryMeasurementGroup( tmVec, DetGroup()));
00097 }
00098 }
00099 return result;
00100 }
00101
00102 void LayerMeasurements::addInvalidMeas( vector<TrajectoryMeasurement>& measVec,
00103 const DetGroup& group,
00104 const DetLayer& layer) const
00105 {
00106 if (!measVec.empty()) {
00107
00108 measVec.push_back( TrajectoryMeasurement( measVec.front().predictedState(),
00109 InvalidTransientRecHit::build(measVec.front().recHit()->det(), TrackingRecHit::missing),
00110 0.,&layer));
00111 }
00112 else if (!group.empty()) {
00113
00114 measVec.push_back( TrajectoryMeasurement( group.front().trajectoryState(),
00115 InvalidTransientRecHit::build(group.front().det(), TrackingRecHit::missing), 0.,&layer));
00116 }
00117 }