Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-12 03:09:55

0001 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
0002 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
0003 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
0004 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0005 
0006 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
0007 #include "TrackingTools/MeasurementDet/interface/MeasurementDetSystem.h"
0008 #include "TrackingTools/MeasurementDet/interface/MeasurementDet.h"
0009 #include "TrackingTools/MeasurementDet/interface/TrajectoryMeasurementGroup.h"
0010 
0011 #include "TrackingTools/DetLayers/interface/GeometricSearchDet.h"
0012 #include "TrackingTools/DetLayers/interface/DetLayer.h"
0013 #include "TrackingTools/DetLayers/interface/DetGroup.h"
0014 
0015 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
0016 
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/Utilities/interface/Likely.h"
0019 
0020 #include <algorithm>
0021 
0022 using namespace std;
0023 
0024 namespace {
0025   typedef GeometricSearchDet::DetWithState DetWithState;
0026   inline void addInvalidMeas(std::vector<TrajectoryMeasurement>& result,
0027                              const TrajectoryStateOnSurface& ts,
0028                              const GeomDet& det,
0029                              const DetLayer& layer) {
0030     result.emplace_back(ts, std::make_shared<InvalidTrackingRecHit>(det, TrackingRecHit::missing), 0.F, &layer);
0031   }
0032 
0033   /** The std::vector<DetWithState> passed to this method should not be empty.
0034    *  In case of no compatible dets the result should be either an empty container if 
0035    *  the det is itself incompatible, or a container with one invalid measurement
0036    *  on the det surface. The method does not have enough information to do
0037    *  this efficiently, so it should be done by the caller, or an exception will
0038    *  be thrown (DetLogicError).
0039    */
0040   inline std::vector<TrajectoryMeasurement> get(MeasurementDetSystem const& detSystem,
0041                                                 MeasurementTrackerEvent const& data,
0042                                                 const DetLayer& layer,
0043                                                 std::vector<DetWithState> const& compatDets,
0044                                                 const TrajectoryStateOnSurface& ts,
0045                                                 const Propagator& prop,
0046                                                 const MeasurementEstimator& est) {
0047     std::vector<TrajectoryMeasurement> result;
0048     typedef TrajectoryMeasurement TM;
0049 
0050     tracking::TempMeasurements tmps;
0051 
0052     for (auto const& ds : compatDets) {
0053       MeasurementDetWithData mdet = detSystem.idToDet(ds.first->geographicalId(), data);
0054       if UNLIKELY (mdet.isNull()) {
0055         throw MeasurementDetException("MeasurementDet not found");
0056       }
0057 
0058       if (mdet.measurements(ds.second, est, tmps))
0059         for (std::size_t i = 0; i != tmps.size(); ++i)
0060           result.emplace_back(ds.second, std::move(tmps.hits[i]), tmps.distances[i], &layer);
0061       tmps.clear();
0062     }
0063     // WARNING: we might end up with more than one invalid hit of type 'inactive' in result
0064     // to be fixed in order to avoid usless double traj candidates.
0065 
0066     // sort the final result
0067     if (result.size() > 1) {
0068       sort(result.begin(), result.end(), TrajMeasLessEstim());
0069     }
0070 
0071     if (!result.empty()) {
0072       // invalidMeas on Det of most compatible hit
0073       addInvalidMeas(result, result.front().predictedState(), *(result.front().recHit()->det()), layer);
0074     } else {
0075       // invalid state on first compatible Det
0076       addInvalidMeas(result, compatDets.front().second, *(compatDets.front().first), layer);
0077     }
0078 
0079     return result;
0080   }
0081 
0082   void addInvalidMeas(vector<TrajectoryMeasurement>& measVec, const DetGroup& group, const DetLayer& layer) {
0083     if (!measVec.empty()) {
0084       // invalidMeas on Det of most compatible hit
0085       auto const& ts = measVec.front().predictedState();
0086       auto toll = measVec.front().recHitR().det()->surface().bounds().significanceInside(
0087           ts.localPosition(), ts.localError().positionError());
0088       measVec.emplace_back(
0089           measVec.front().predictedState(),
0090           std::make_shared<InvalidTrackingRecHit>(*measVec.front().recHitR().det(), TrackingRecHit::missing),
0091           toll,
0092           &layer);
0093     } else if (!group.empty()) {
0094       // invalid state on first compatible Det
0095       auto const& ts = group.front().trajectoryState();
0096       auto toll = group.front().det()->surface().bounds().significanceInside(ts.localPosition(),
0097                                                                              ts.localError().positionError());
0098       measVec.emplace_back(group.front().trajectoryState(),
0099                            std::make_shared<InvalidTrackingRecHit>(*group.front().det(), TrackingRecHit::missing),
0100                            toll,
0101                            &layer);
0102     }
0103   }
0104 
0105 }  // namespace
0106 
0107 // return just valid hits, no sorting (for seeding mostly)
0108 std::vector<BaseTrackerRecHit*> LayerMeasurements::recHits(const DetLayer& layer,
0109                                                            const TrajectoryStateOnSurface& startingState,
0110                                                            const Propagator& prop,
0111                                                            const MeasurementEstimator& est) const {
0112   std::vector<BaseTrackerRecHit*> result;
0113   auto const& compatDets = layer.compatibleDets(startingState, prop, est);
0114   if (compatDets.empty())
0115     return result;
0116   for (auto const& ds : compatDets) {
0117     auto mdet = detSystem_.idToDet(ds.first->geographicalId(), data_);
0118     mdet.recHits(result, ds.second, est);
0119   }
0120   return result;
0121 }
0122 
0123 vector<TrajectoryMeasurement> LayerMeasurements::measurements(const DetLayer& layer,
0124                                                               const TrajectoryStateOnSurface& startingState,
0125                                                               const Propagator& prop,
0126                                                               const MeasurementEstimator& est) const {
0127   typedef DetLayer::DetWithState DetWithState;
0128 
0129   vector<DetWithState> const& compatDets = layer.compatibleDets(startingState, prop, est);
0130 
0131   if (!compatDets.empty())
0132     return get(detSystem_, data_, layer, compatDets, startingState, prop, est);
0133 
0134   vector<TrajectoryMeasurement> result;
0135   pair<bool, TrajectoryStateOnSurface> compat = layer.compatible(startingState, prop, est);
0136 
0137   if (compat.first) {
0138     result.push_back(
0139         TrajectoryMeasurement(compat.second,
0140                               std::make_shared<InvalidTrackingRecHitNoDet>(layer.surface(), TrackingRecHit::inactive),
0141                               0.F,
0142                               &layer));
0143     LogDebug("LayerMeasurements") << "adding a missing hit.";
0144   } else
0145     LogDebug("LayerMeasurements") << "adding not measurement.";
0146 
0147   return result;
0148 }
0149 
0150 vector<TrajectoryMeasurementGroup> LayerMeasurements::groupedMeasurements(const DetLayer& layer,
0151                                                                           const TrajectoryStateOnSurface& startingState,
0152                                                                           const Propagator& prop,
0153                                                                           const MeasurementEstimator& est) const {
0154   vector<TrajectoryMeasurementGroup> result;
0155 
0156   vector<DetGroup>&& groups = layer.groupedCompatibleDets(startingState, prop, est);
0157   result.reserve(groups.size());
0158 
0159   tracking::TempMeasurements tmps;
0160   for (auto& grp : groups) {
0161     if (grp.empty())
0162       continue;
0163 
0164     vector<TrajectoryMeasurement> tmpVec;
0165     for (auto const& det : grp) {
0166       MeasurementDetWithData mdet = detSystem_.idToDet(det.det()->geographicalId(), data_);
0167       if (mdet.isNull()) {
0168         throw MeasurementDetException("MeasurementDet not found");
0169       }
0170       if (mdet.measurements(det.trajectoryState(), est, tmps))
0171         for (std::size_t i = 0; i != tmps.size(); ++i)
0172           tmpVec.emplace_back(det.trajectoryState(), std::move(tmps.hits[i]), tmps.distances[i], &layer);
0173       tmps.clear();
0174     }
0175 
0176     // sort the final result
0177     LogDebug("LayerMeasurements") << "Sorting " << tmpVec.size() << " measurements in this grp.";
0178     sort(tmpVec.begin(), tmpVec.end(), TrajMeasLessEstim());
0179     addInvalidMeas(tmpVec, grp, layer);
0180     result.emplace_back(std::move(tmpVec), std::move(grp));
0181   }
0182 
0183   // if the result is empty check if the layer is compatible (for invalid measurement)
0184   if (result.empty()) {
0185     pair<bool, TrajectoryStateOnSurface> compat = layer.compatible(startingState, prop, est);
0186     if (compat.first) {
0187       vector<TrajectoryMeasurement> tmVec;
0188       tmVec.emplace_back(compat.second,
0189                          std::make_shared<InvalidTrackingRecHitNoDet>(layer.surface(), TrackingRecHit::inactive),
0190                          0.F,
0191                          &layer);
0192       result.emplace_back(std::move(tmVec), DetGroup());
0193     }
0194   }
0195   return result;
0196 }