File indexing completed on 2024-04-06 12:26:59
0001 #include "RecoMuon/L3TrackFinder/interface/MuonCkfTrajectoryBuilder.h"
0002
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0005 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0006 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
0007 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
0008 #include "RecoTracker/MeasurementDet/interface/MeasurementTracker.h"
0009 #include "RecoTracker/MeasurementDet/interface/MeasurementTrackerEvent.h"
0010 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
0011 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimatorBase.h"
0012 #include "TrackingTools/TrajectoryFiltering/interface/TrajectoryFilter.h"
0013 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
0014 #include "TrackingTools/DetLayers/interface/NavigationSchool.h"
0015 #include "RecoMuon/L3TrackFinder/src/EtaPhiEstimator.h"
0016 #include <sstream>
0017
0018 MuonCkfTrajectoryBuilder::MuonCkfTrajectoryBuilder(const edm::ParameterSet& conf, edm::ConsumesCollector& iC)
0019 : CkfTrajectoryBuilder(conf, iC),
0020 theDeltaEta(conf.getParameter<double>("deltaEta")),
0021 theDeltaPhi(conf.getParameter<double>("deltaPhi")),
0022 theProximityPropagatorName(conf.getParameter<std::string>("propagatorProximity")),
0023 theProximityPropagator(nullptr),
0024 thePropagatorToken(iC.esConsumes(edm::ESInputTag("", theProximityPropagatorName))),
0025 theEtaPhiEstimator(nullptr) {
0026
0027 theUseSeedLayer = conf.getParameter<bool>("useSeedLayer");
0028 theRescaleErrorIfFail = conf.getParameter<double>("rescaleErrorIfFail");
0029 }
0030
0031 MuonCkfTrajectoryBuilder::~MuonCkfTrajectoryBuilder() {}
0032
0033 void MuonCkfTrajectoryBuilder::fillPSetDescription(edm::ParameterSetDescription& iDesc) {
0034 CkfTrajectoryBuilder::fillPSetDescription(iDesc);
0035 iDesc.add<double>("deltaEta", .1);
0036 iDesc.add<double>("deltaPhi", .1);
0037 iDesc.add<std::string>("propagatorProximity", "SteppingHelixPropagatorAny");
0038 iDesc.add<bool>("useSeedLayer", false);
0039 iDesc.add<double>("rescaleErrorIfFail", 1.);
0040 }
0041
0042 void MuonCkfTrajectoryBuilder::setEvent_(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0043 CkfTrajectoryBuilder::setEvent_(iEvent, iSetup);
0044
0045 theProximityPropagator = &iSetup.getData(thePropagatorToken);
0046
0047
0048 if (theEstimatorWatcher.check(iSetup) && theDeltaEta > 0 && theDeltaPhi > 0)
0049 theEtaPhiEstimator = std::make_unique<EtaPhiEstimator>(theDeltaEta, theDeltaPhi, theEstimator);
0050 }
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 void MuonCkfTrajectoryBuilder::collectMeasurement(const DetLayer* layer,
0083 const std::vector<const DetLayer*>& nl,
0084 const TrajectoryStateOnSurface& currentState,
0085 std::vector<TM>& result,
0086 int& invalidHits,
0087 const Propagator* prop) const {
0088 for (std::vector<const DetLayer*>::const_iterator il = nl.begin(); il != nl.end(); il++) {
0089 TSOS stateToUse = currentState;
0090
0091 if (layer == (*il)) {
0092 LogDebug("CkfPattern") << " self propagating in findCompatibleMeasurements.\n from: \n" << stateToUse;
0093
0094
0095 TransverseImpactPointExtrapolator middle;
0096 GlobalPoint center(0, 0, 0);
0097 stateToUse = middle.extrapolate(stateToUse, center, *prop);
0098
0099 if (!stateToUse.isValid())
0100 continue;
0101 LogDebug("CkfPattern") << "to: " << stateToUse;
0102 }
0103
0104 LayerMeasurements layerMeasurements(theMeasurementTracker->measurementTracker(), *theMeasurementTracker);
0105 std::vector<TM> tmp = layerMeasurements.measurements((**il), stateToUse, *prop, *theEstimator);
0106
0107 if (tmp.size() == 1 && theEtaPhiEstimator) {
0108 LogDebug("CkfPattern") << "only an invalid hit is found. trying differently";
0109 tmp = layerMeasurements.measurements((**il), stateToUse, *prop, *theEtaPhiEstimator);
0110 }
0111 LogDebug("CkfPattern") << tmp.size() << " measurements returned by LayerMeasurements";
0112
0113 if (!tmp.empty()) {
0114
0115
0116
0117
0118 if (result.empty())
0119 result = tmp;
0120 else {
0121
0122 result.insert(result.end() - invalidHits, tmp.begin(), tmp.end());
0123 }
0124 invalidHits++;
0125 }
0126 }
0127
0128 LogDebug("CkfPattern") << "starting from:\n"
0129 << "x: " << currentState.globalPosition() << "\n"
0130 << "p: " << currentState.globalMomentum() << "\n"
0131 << PrintoutHelper::dumpMeasurements(result);
0132 }
0133
0134 void MuonCkfTrajectoryBuilder::findCompatibleMeasurements(const TrajectorySeed& seed,
0135 const TempTrajectory& traj,
0136 std::vector<TrajectoryMeasurement>& result) const {
0137 int invalidHits = 0;
0138
0139 std::vector<const DetLayer*> nl;
0140
0141 if (traj.empty()) {
0142 LogDebug("CkfPattern") << "using JR patch for no measurement case";
0143
0144
0145
0146 PTrajectoryStateOnDet ptod = seed.startingState();
0147 DetId id(ptod.detId());
0148 const GeomDet* g = theMeasurementTracker->geomTracker()->idToDet(id);
0149 const Surface* surface = &g->surface();
0150
0151 TrajectoryStateOnSurface currentState(
0152 trajectoryStateTransform::transientState(ptod, surface, forwardPropagator(seed)->magneticField()));
0153
0154
0155 const DetLayer* l = theMeasurementTracker->geometricSearchTracker()->detLayer(id);
0156
0157 if (theUseSeedLayer) {
0158 {
0159
0160 LogDebug("CkfPattern") << "using the layer of the seed first.";
0161 nl.push_back(l);
0162 collectMeasurement(l, nl, currentState, result, invalidHits, theProximityPropagator);
0163 }
0164
0165
0166 if ((unsigned int)invalidHits == result.size() && theRescaleErrorIfFail != 1.0 && !result.empty()) {
0167 result.clear();
0168 LogDebug("CkfPattern") << "using a rescale by " << theRescaleErrorIfFail << " to find measurements.";
0169 TrajectoryStateOnSurface rescaledCurrentState = currentState;
0170 rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
0171 invalidHits = 0;
0172 collectMeasurement(l, nl, rescaledCurrentState, result, invalidHits, theProximityPropagator);
0173 }
0174 }
0175
0176
0177 if (result.empty() || (unsigned int)invalidHits == result.size()) {
0178 result.clear();
0179 LogDebug("CkfPattern") << "Need to go to next layer to get measurements";
0180
0181 nl = theNavigationSchool->nextLayers(*l, *currentState.freeState(), traj.direction());
0182 if (nl.empty()) {
0183 LogDebug("CkfPattern") << " there was no next layer with wellInside. Use the next with no check.";
0184
0185
0186 nl = theNavigationSchool->nextLayers(*l, ((traj.direction() == alongMomentum) ? insideOut : outsideIn));
0187 }
0188 invalidHits = 0;
0189 collectMeasurement(l, nl, currentState, result, invalidHits, forwardPropagator(seed));
0190 }
0191
0192
0193 if (!result.empty() && (unsigned int)invalidHits == result.size() && theRescaleErrorIfFail != 1.0) {
0194 result.clear();
0195 LogDebug("CkfPattern") << "using a rescale by " << theRescaleErrorIfFail
0196 << " to find measurements on next layers.";
0197 TrajectoryStateOnSurface rescaledCurrentState = currentState;
0198 rescaledCurrentState.rescaleError(theRescaleErrorIfFail);
0199 invalidHits = 0;
0200 collectMeasurement(l, nl, rescaledCurrentState, result, invalidHits, forwardPropagator(seed));
0201 }
0202
0203 } else
0204 {
0205 TSOS currentState(traj.lastMeasurement().updatedState());
0206
0207 nl = theNavigationSchool->nextLayers(*traj.lastLayer(), *currentState.freeState(), traj.direction());
0208 if (nl.empty()) {
0209 LogDebug("CkfPattern") << " no next layers... going " << traj.direction() << "\n from: \n"
0210 << currentState
0211 << "\n from detId: " << traj.lastMeasurement().recHit()->geographicalId().rawId();
0212 return;
0213 }
0214
0215 collectMeasurement(traj.lastLayer(), nl, currentState, result, invalidHits, forwardPropagator(seed));
0216 }
0217
0218
0219 if (result.size() > 1) {
0220 sort(result.begin(), result.end() - invalidHits, TrajMeasLessEstim());
0221 }
0222
0223 #ifdef DEBUG_INVALID
0224 bool afterInvalid = false;
0225 for (std::vector<TM>::const_iterator i = result.begin(); i != result.end(); i++) {
0226 if (!i->recHit().isValid())
0227 afterInvalid = true;
0228 if (afterInvalid && i->recHit().isValid()) {
0229 edm::LogError("CkfPattern") << "CkfTrajectoryBuilder error: valid hit after invalid!";
0230 }
0231 }
0232 #endif
0233
0234
0235 }