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 #include "FWCore/MessageLogger/interface/MessageLogger.h"
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
00028 if ( compat.first) {
00029 result.push_back( TrajectoryMeasurement( compat.second,
00030 InvalidTransientRecHit::build(0, TrackingRecHit::inactive,&layer), 0.F,
00031 &layer));
00032 LogDebug("LayerMeasurements")<<"adding a missing hit.";
00033 }else LogDebug("LayerMeasurements")<<"adding not measurement.";
00034 return result;
00035 }
00036
00037 GeometricSearchDetMeasurements gsdm( theDetSystem);
00038 vector<TrajectoryMeasurement> tmpResult = gsdm.get( layer, compatDets, startingState, prop, est);
00039
00040 for(vector<TrajectoryMeasurement>::const_iterator tmpIt=tmpResult.begin();tmpIt!=tmpResult.end();tmpIt++){
00041 LogDebug("LayerMeasurements")<<"adding a measurement which rechit is: "<<(tmpIt->recHit()->isValid()?"valid":"invalid");
00042 result.push_back( TrajectoryMeasurement(tmpIt->predictedState(),tmpIt->recHit(),tmpIt->estimate(),&layer) );
00043 }
00044
00045 return result;
00046 }
00047
00048
00049 vector<TrajectoryMeasurementGroup>
00050 LayerMeasurements::groupedMeasurements( const DetLayer& layer,
00051 const TrajectoryStateOnSurface& startingState,
00052 const Propagator& prop,
00053 const MeasurementEstimator& est) const
00054 {
00055 vector<TrajectoryMeasurementGroup> result;
00056
00057 vector<DetGroup> groups( layer.groupedCompatibleDets( startingState, prop, est));
00058 result.reserve(groups.size());
00059 for (vector<DetGroup>::const_iterator grp=groups.begin(); grp!=groups.end(); grp++) {
00060 if ( grp->empty() ) continue;
00061
00062 vector<TrajectoryMeasurement> tmpVec;
00063 for (DetGroup::const_iterator idet=grp->begin(); idet!=grp->end(); idet++) {
00064 const MeasurementDet* mdet = theDetSystem->idToDet(idet->det()->geographicalId());
00065 if (mdet == 0) {
00066 throw MeasurementDetException( "MeasurementDet not found");
00067 }
00068 vector<TrajectoryMeasurement> tmp =
00069 mdet->fastMeasurements( idet->trajectoryState(), startingState, prop, est);
00070 if (!tmp.empty()) {
00071
00072 std::vector<TrajectoryMeasurement>::iterator end =
00073 (tmp.back().recHit()->getType() != TrackingRecHit::missing ?
00074 tmp.end() :
00075 tmp.end()-1);
00076 tmpVec.insert( tmpVec.end(), tmp.begin(), end);
00077 }
00078 }
00079
00080 vector<TrajectoryMeasurement> tmpVec2;
00081 tmpVec2.reserve(tmpVec.size());
00082 for(vector<TrajectoryMeasurement>::const_iterator tmpIt=tmpVec.begin();tmpIt!=tmpVec.end();tmpIt++){
00083 LogDebug("LayerMeasurements")<<"[grouped] temporaryly adding a measurement which rechit is: "<<(tmpIt->recHit()->isValid()?"valid":"invalid");
00084 tmpVec2.push_back( TrajectoryMeasurement(tmpIt->predictedState(),tmpIt->recHit(),tmpIt->estimate(),&layer) );
00085 }
00086
00087
00088
00089 if ( static_cast<int>(tmpVec2.size()) > 1) {
00090 sort( tmpVec2.begin(), tmpVec2.end(), TrajMeasLessEstim());
00091 }
00092 addInvalidMeas( tmpVec2, *grp,layer);
00093 result.push_back( TrajectoryMeasurementGroup( tmpVec2, *grp));
00094 }
00095
00096
00097 if (result.empty()) {
00098 pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
00099 if ( compat.first) {
00100 TrajectoryMeasurement inval( compat.second, InvalidTransientRecHit::build(0, TrackingRecHit::inactive,&layer), 0.F,&layer);
00101 vector<TrajectoryMeasurement> tmVec(1,inval);
00102 result.push_back( TrajectoryMeasurementGroup( tmVec, DetGroup()));
00103 }
00104 }
00105 return result;
00106 }
00107
00108 void LayerMeasurements::addInvalidMeas( vector<TrajectoryMeasurement>& measVec,
00109 const DetGroup& group,
00110 const DetLayer& layer) const
00111 {
00112 if (!measVec.empty()) {
00113
00114 measVec.push_back( TrajectoryMeasurement( measVec.front().predictedState(),
00115 InvalidTransientRecHit::build(measVec.front().recHit()->det(), TrackingRecHit::missing),
00116 0.,&layer));
00117 }
00118 else if (!group.empty()) {
00119
00120 measVec.push_back( TrajectoryMeasurement( group.front().trajectoryState(),
00121 InvalidTransientRecHit::build(group.front().det(), TrackingRecHit::missing), 0.,&layer));
00122 }
00123 }