00001 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
00002 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00003 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
00004 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00005
00006 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00007 #include "TrackingTools/MeasurementDet/interface/MeasurementDetSystem.h"
00008 #include "TrackingTools/MeasurementDet/interface/MeasurementDet.h"
00009 #include "TrackingTools/MeasurementDet/interface/TrajectoryMeasurementGroup.h"
00010
00011 #include "TrackingTools/DetLayers/interface/GeometricSearchDet.h"
00012 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00013 #include "TrackingTools/DetLayers/interface/DetGroup.h"
00014
00015 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00016
00017
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019
00020 #include <algorithm>
00021
00022 using namespace std;
00023
00024
00025 namespace {
00026 typedef GeometricSearchDet::DetWithState DetWithState;
00027 inline
00028 void addInvalidMeas( std::vector<TrajectoryMeasurement>& result,
00029 const TrajectoryStateOnSurface& ts, const GeomDet* det, const DetLayer& layer) {
00030 result.emplace_back(ts, InvalidTransientRecHit::build(det, TrackingRecHit::missing), 0.F,&layer);
00031 }
00032
00033
00034
00042 inline
00043 std::vector<TrajectoryMeasurement>
00044 get(const MeasurementDetSystem* theDetSystem,
00045 const DetLayer& layer,
00046 std::vector<DetWithState> const& compatDets,
00047 const TrajectoryStateOnSurface& ts,
00048 const Propagator& prop,
00049 const MeasurementEstimator& est) {
00050 std::vector<TrajectoryMeasurement> result;
00051 typedef TrajectoryMeasurement TM;
00052
00053 tracking::TempMeasurements tmps;
00054
00055 for ( auto const & ds : compatDets) {
00056 const MeasurementDet* mdet = theDetSystem->idToDet(ds.first->geographicalId());
00057 if unlikely(mdet == nullptr) {
00058 throw MeasurementDetException( "MeasurementDet not found");
00059 }
00060
00061 if (mdet->measurements(ds.second, est,tmps))
00062 for (std::size_t i=0; i!=tmps.size(); ++i)
00063 result.emplace_back(ds.second,std::move(tmps.hits[i]),tmps.distances[i],&layer);
00064 tmps.clear();
00065 }
00066
00067
00068
00069
00070 if ( result.size() > 1) {
00071 sort( result.begin(), result.end(), TrajMeasLessEstim());
00072 }
00073
00074
00075 if ( !result.empty()) {
00076
00077 addInvalidMeas( result, result.front().predictedState(), result.front().recHit()->det(),layer);
00078 }
00079 else {
00080
00081 addInvalidMeas( result, compatDets.front().second, compatDets.front().first,layer);
00082 }
00083
00084 return result;
00085 }
00086
00087 }
00088
00089 vector<TrajectoryMeasurement>
00090 LayerMeasurements::measurements( const DetLayer& layer,
00091 const TrajectoryStateOnSurface& startingState,
00092 const Propagator& prop,
00093 const MeasurementEstimator& est) const {
00094
00095 typedef DetLayer::DetWithState DetWithState;
00096
00097 vector<DetWithState> const & compatDets = layer.compatibleDets( startingState, prop, est);
00098
00099 if (!compatDets.empty()) return get(theDetSystem, layer, compatDets, startingState, prop, est);
00100
00101 vector<TrajectoryMeasurement> result;
00102 pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
00103
00104 if ( compat.first) {
00105 result.push_back( TrajectoryMeasurement( compat.second,
00106 InvalidTransientRecHit::build(0, TrackingRecHit::inactive,&layer), 0.F,
00107 &layer));
00108 LogDebug("LayerMeasurements")<<"adding a missing hit.";
00109 }else LogDebug("LayerMeasurements")<<"adding not measurement.";
00110
00111
00112 return result;
00113
00114 }
00115
00116
00117 vector<TrajectoryMeasurementGroup>
00118 LayerMeasurements::groupedMeasurements( const DetLayer& layer,
00119 const TrajectoryStateOnSurface& startingState,
00120 const Propagator& prop,
00121 const MeasurementEstimator& est) const {
00122 vector<TrajectoryMeasurementGroup> result;
00123
00124 vector<DetGroup> && groups = layer.groupedCompatibleDets( startingState, prop, est);
00125 result.reserve(groups.size());
00126
00127 tracking::TempMeasurements tmps;
00128 for (auto& grp : groups) {
00129 if ( grp.empty() ) continue;
00130
00131 vector<TrajectoryMeasurement> tmpVec;
00132 for (auto const & det : grp) {
00133 const MeasurementDet* mdet = theDetSystem->idToDet(det.det()->geographicalId());
00134 if (mdet == 0) {
00135 throw MeasurementDetException( "MeasurementDet not found");
00136 }
00137 if (mdet->measurements( det.trajectoryState(), est,tmps))
00138 for (std::size_t i=0; i!=tmps.size(); ++i)
00139 tmpVec.emplace_back(det.trajectoryState(),std::move(tmps.hits[i]),tmps.distances[i],&layer);
00140 tmps.clear();
00141 }
00142
00143
00144 sort( tmpVec.begin(), tmpVec.end(), TrajMeasLessEstim());
00145 addInvalidMeas( tmpVec, grp,layer);
00146 result.emplace_back(std::move(tmpVec), std::move(grp));
00147 }
00148
00149
00150
00151 if (result.empty()) {
00152 pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
00153 if ( compat.first) {
00154 TrajectoryMeasurement inval( compat.second, InvalidTransientRecHit::build(0, TrackingRecHit::inactive,&layer), 0.F,&layer);
00155 vector<TrajectoryMeasurement> tmVec(1,inval);
00156 result.push_back( TrajectoryMeasurementGroup( tmVec, DetGroup()));
00157 }
00158 }
00159 return result;
00160 }
00161
00162 void LayerMeasurements::addInvalidMeas( vector<TrajectoryMeasurement>& measVec,
00163 const DetGroup& group,
00164 const DetLayer& layer) const
00165 {
00166 if (!measVec.empty()) {
00167
00168 measVec.emplace_back(measVec.front().predictedState(),
00169 InvalidTransientRecHit::build(measVec.front().recHit()->det(), TrackingRecHit::missing),
00170 0.,&layer);
00171 }
00172 else if (!group.empty()) {
00173
00174 measVec.emplace_back(group.front().trajectoryState(),
00175 InvalidTransientRecHit::build(group.front().det(), TrackingRecHit::missing), 0.,&layer);
00176 }
00177 }