CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OutsideInMuonSeeder.cc
Go to the documentation of this file.
1 
13 
15 
20 
37 
39 public:
41  ~OutsideInMuonSeeder() override {}
42 
43  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
44 
45 private:
48 
51 
53  const int layersToTry_;
54 
56  const int hitsToTry_;
57 
59  const bool fromVertex_;
60 
62  const double errorRescaling_;
63 
72 
73  float const minEtaForTEC_;
74  float const maxEtaForTOB_;
75 
81 
83  const bool debug_;
84 
85  int doLayer(const GeometricSearchDet &layer,
87  std::vector<TrajectorySeed> &out,
88  const Propagator &muon_propagator,
89  const Propagator &tracker_propagator,
90  const MeasurementTrackerEvent &mte) const;
91  void doDebug(const reco::Track &tk) const;
92 };
93 
95  : src_(consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("src"))),
96  selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true),
97  layersToTry_(iConfig.getParameter<int32_t>("layersToTry")),
98  hitsToTry_(iConfig.getParameter<int32_t>("hitsToTry")),
99  fromVertex_(iConfig.getParameter<bool>("fromVertex")),
100  errorRescaling_(iConfig.getParameter<double>("errorRescaleFactor")),
101  trackerPropagatorToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("trackerPropagator")))),
102  muonPropagatorToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("muonPropagator")))),
103  measurementTrackerTag_(consumes<MeasurementTrackerEvent>(edm::InputTag("MeasurementTrackerEvent"))),
104  estimatorToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("hitCollector")))),
105  updatorToken_(esConsumes(edm::ESInputTag("", "KFUpdator"))),
106  magfieldToken_(esConsumes()),
107  geometryToken_(esConsumes()),
108  tkGeometryToken_(esConsumes()),
109  minEtaForTEC_(iConfig.getParameter<double>("minEtaForTEC")),
110  maxEtaForTOB_(iConfig.getParameter<double>("maxEtaForTOB")),
111  debug_(iConfig.getUntrackedParameter<bool>("debug", false)) {
112  produces<std::vector<TrajectorySeed>>();
113 }
114 
116  using namespace edm;
117  using namespace std;
118 
119  magfield_ = &iSetup.getData(magfieldToken_);
120  auto const &trackerPropagator = iSetup.getData(trackerPropagatorToken_);
122  geometry_ = &iSetup.getData(geometryToken_);
124  updator_ = &iSetup.getData(updatorToken_);
125 
128 
129  const auto &tmpTkGeometry = iSetup.getData(tkGeometryToken_);
130 
132  iEvent.getByToken(src_, src);
133 
134  auto out = std::make_unique<std::vector<TrajectorySeed>>();
135 
136  for (auto const &mu : *src) {
137  if (mu.outerTrack().isNull() || !selector_(mu))
138  continue;
139  if (debug_ && mu.innerTrack().isNonnull())
140  doDebug(*mu.innerTrack());
141 
142  // Better clone here and not directly into doLayer to avoid
143  // useless clone/destroy operations to set, in the end, the
144  // very same direction every single time.
145  std::unique_ptr<Propagator> pmuon_cloned =
147  std::unique_ptr<Propagator> ptracker_cloned = SetPropagationDirection(trackerPropagator, alongMomentum);
148 
149  int sizeBefore = out->size();
150  if (debug_)
151  LogDebug("OutsideInMuonSeeder") << "\n\n\nSeeding for muon of pt " << mu.pt() << ", eta " << mu.eta() << ", phi "
152  << mu.phi() << std::endl;
153  const reco::Track &tk = *mu.outerTrack();
154 
158 
159  if (std::abs(tk.eta()) < maxEtaForTOB_) {
160  std::vector<BarrelDetLayer const *> const &tob = measurementTracker->geometricSearchTracker()->tobLayers();
161  int found = 0;
162  int iLayer = tob.size();
163  if (iLayer == 0)
164  LogError("OutsideInMuonSeeder") << "TOB has no layers.";
165 
166  for (auto it = tob.rbegin(), ed = tob.rend(); it != ed; ++it, --iLayer) {
167  if (debug_)
168  LogDebug("OutsideInMuonSeeder") << "\n ==== Trying TOB " << iLayer << " ====" << std::endl;
169  if (doLayer(**it, state, *out, *(pmuon_cloned.get()), *(ptracker_cloned.get()), *measurementTracker)) {
170  if (++found == layersToTry_)
171  break;
172  }
173  }
174  }
175  if (tk.eta() > minEtaForTEC_) {
176  const auto &forwLayers = tmpTkGeometry.isThere(GeomDetEnumerators::P2OTEC)
177  ? measurementTracker->geometricSearchTracker()->posTidLayers()
178  : measurementTracker->geometricSearchTracker()->posTecLayers();
179  if (tmpTkGeometry.isThere(GeomDetEnumerators::P2OTEC)) {
180  LogDebug("OutsideInMuonSeeder") << "\n We are using the Phase2 Outer Tracker (defined as a TID+). ";
181  }
182  LogTrace("OutsideInMuonSeeder") << "\n ==== TEC+ tot layers " << forwLayers.size() << " ====" << std::endl;
183  int found = 0;
184  int iLayer = forwLayers.size();
185  if (iLayer == 0)
186  LogError("OutsideInMuonSeeder") << "TEC+ has no layers.";
187 
188  if (debug_)
189  LogDebug("OutsideInMuonSeeder") << "\n ==== Tot layers " << forwLayers.size() << " ====" << std::endl;
190  for (auto it = forwLayers.rbegin(), ed = forwLayers.rend(); it != ed; ++it, --iLayer) {
191  if (debug_)
192  LogDebug("OutsideInMuonSeeder") << "\n ==== Trying Forward Layer +" << +iLayer << " ====" << std::endl;
193  if (doLayer(**it, state, *out, *(pmuon_cloned.get()), *(ptracker_cloned.get()), *measurementTracker)) {
194  if (++found == layersToTry_)
195  break;
196  }
197  }
198  }
199  if (tk.eta() < -minEtaForTEC_) {
200  const auto &forwLayers = tmpTkGeometry.isThere(GeomDetEnumerators::P2OTEC)
201  ? measurementTracker->geometricSearchTracker()->negTidLayers()
202  : measurementTracker->geometricSearchTracker()->negTecLayers();
203  if (tmpTkGeometry.isThere(GeomDetEnumerators::P2OTEC)) {
204  LogDebug("OutsideInMuonSeeder") << "\n We are using the Phase2 Outer Tracker (defined as a TID-). ";
205  }
206  LogTrace("OutsideInMuonSeeder") << "\n ==== TEC- tot layers " << forwLayers.size() << " ====" << std::endl;
207  int found = 0;
208  int iLayer = forwLayers.size();
209  if (iLayer == 0)
210  LogError("OutsideInMuonSeeder") << "TEC- has no layers.";
211 
212  if (debug_)
213  LogDebug("OutsideInMuonSeeder") << "\n ==== Tot layers " << forwLayers.size() << " ====" << std::endl;
214  for (auto it = forwLayers.rbegin(), ed = forwLayers.rend(); it != ed; ++it, --iLayer) {
215  if (debug_)
216  LogDebug("OutsideInMuonSeeder") << "\n ==== Trying Forward Layer -" << -iLayer << " ====" << std::endl;
217  if (doLayer(**it, state, *out, *(pmuon_cloned.get()), *(ptracker_cloned.get()), *measurementTracker)) {
218  if (++found == layersToTry_)
219  break;
220  }
221  }
222  }
223  if (debug_)
224  LogDebug("OutsideInMuonSeeder") << "Outcome of seeding for muon of pt " << mu.pt() << ", eta " << mu.eta()
225  << ", phi " << mu.phi() << ": found " << (out->size() - sizeBefore) << " seeds."
226  << std::endl;
227  }
228 
229  iEvent.put(std::move(out));
230 }
231 
234  std::vector<TrajectorySeed> &out,
235  const Propagator &muon_propagator,
236  const Propagator &tracker_propagator,
238  TrajectoryStateOnSurface onLayer(state);
239  onLayer.rescaleError(errorRescaling_);
240  std::vector<GeometricSearchDet::DetWithState> dets;
241  layer.compatibleDetsV(onLayer, muon_propagator, *estimator_, dets);
242 
243  if (debug_) {
244  LogDebug("OutsideInMuonSeeder") << "Query on layer around x = " << onLayer.globalPosition()
245  << " with local pos error " << sqrt(onLayer.localError().positionError().xx())
246  << " , " << sqrt(onLayer.localError().positionError().yy()) << " , "
247  << " returned " << dets.size() << " compatible detectors" << std::endl;
248  }
249 
250  std::vector<TrajectoryMeasurement> meas;
251  for (std::vector<GeometricSearchDet::DetWithState>::const_iterator it = dets.begin(), ed = dets.end(); it != ed;
252  ++it) {
253  MeasurementDetWithData det = measurementTracker.idToDet(it->first->geographicalId());
254  if (det.isNull()) {
255  std::cerr << "BOGUS detid " << it->first->geographicalId().rawId() << std::endl;
256  continue;
257  }
258  if (!it->second.isValid())
259  continue;
260  std::vector<TrajectoryMeasurement> mymeas =
261  det.fastMeasurements(it->second, state, tracker_propagator, *estimator_);
262  if (debug_)
263  LogDebug("OutsideInMuonSeeder") << "Query on detector " << it->first->geographicalId().rawId() << " returned "
264  << mymeas.size() << " measurements." << std::endl;
265  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = mymeas.begin(), ed2 = mymeas.end(); it2 != ed2;
266  ++it2) {
267  if (it2->recHit()->isValid())
268  meas.push_back(*it2);
269  }
270  }
271  int found = 0;
272  std::sort(meas.begin(), meas.end(), TrajMeasLessEstim());
273  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = meas.begin(), ed2 = meas.end(); it2 != ed2; ++it2) {
274  if (debug_) {
275  LogDebug("OutsideInMuonSeeder") << " inspecting Hit with chi2 = " << it2->estimate() << std::endl;
276  LogDebug("OutsideInMuonSeeder") << " track state " << it2->forwardPredictedState().globalPosition()
277  << std::endl;
278  LogDebug("OutsideInMuonSeeder") << " rechit position " << it2->recHit()->globalPosition() << std::endl;
279  }
280  TrajectoryStateOnSurface updated = updator_->update(it2->forwardPredictedState(), *it2->recHit());
281  if (updated.isValid()) {
282  if (debug_)
283  LogDebug("OutsideInMuonSeeder") << " --> updated state: x = " << updated.globalPosition()
284  << ", p = " << updated.globalMomentum() << std::endl;
286  seedHits.push_back(*it2->recHit()->hit());
287  PTrajectoryStateOnDet const &pstate =
288  trajectoryStateTransform::persistentState(updated, it2->recHit()->geographicalId().rawId());
289  TrajectorySeed seed(pstate, std::move(seedHits), oppositeToMomentum);
290  out.push_back(seed);
291  found++;
292  if (found == hitsToTry_)
293  break;
294  }
295  }
296  return found;
297 }
298 
301  std::unique_ptr<Propagator> pmuon_cloned = SetPropagationDirection(*muonPropagator_, alongMomentum);
302  for (unsigned int i = 0; i < tk.recHitsSize(); ++i) {
303  const TrackingRecHit *hit = &*tk.recHit(i);
304  const GeomDet *det = geometry_->idToDet(hit->geographicalId());
305  if (det == nullptr)
306  continue;
307  if (i != 0)
308  tsos = pmuon_cloned->propagate(tsos, det->surface());
309  if (!tsos.isValid())
310  continue;
311  LogDebug("OutsideInMuonSeeder") << " state " << i << " at x = " << tsos.globalPosition()
312  << ", p = " << tsos.globalMomentum() << std::endl;
313  if (hit->isValid()) {
314  LogDebug("OutsideInMuonSeeder") << " valid rechit on detid " << hit->geographicalId().rawId()
315  << std::endl;
316  } else {
317  LogDebug("OutsideInMuonSeeder") << " invalid rechit on detid " << hit->geographicalId().rawId()
318  << std::endl;
319  }
320  }
321 }
322 
MeasurementDetWithData idToDet(const DetId &id) const
Previous MeasurementDetSystem interface.
float xx() const
Definition: LocalError.h:22
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const TrajectoryStateUpdator * updator_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:97
const Chi2MeasurementEstimatorBase * estimator_
tuple measurementTracker
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
GlobalPoint globalPosition() const
const bool fromVertex_
Do inside-out.
Log< level::Error, false > LogError
const GeomDet * idToDet(DetId) const override
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
LocalError positionError() const
int doLayer(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &state, std::vector< TrajectorySeed > &out, const Propagator &muon_propagator, const Propagator &tracker_propagator, const MeasurementTrackerEvent &mte) const
#define LogTrace(id)
constexpr std::array< uint8_t, layerIndexSize > layer
const edm::ESGetToken< Propagator, TrackingComponentsRecord > muonPropagatorToken_
const MagneticField * magfield_
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magfieldToken_
std::unique_ptr< Propagator > SetPropagationDirection(Propagator const &iprop, PropagationDirection dir)
void push_back(D *&d)
Definition: OwnVector.h:326
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
const bool debug_
Dump deug information.
int iEvent
Definition: GenABIO.cc:224
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
const double errorRescaling_
How much to rescale errors from STA.
float yy() const
Definition: LocalError.h:24
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< TrajectoryMeasurement > fastMeasurements(const TrajectoryStateOnSurface &stateOnThisDet, const TrajectoryStateOnSurface &tsos2, const Propagator &prop, const MeasurementEstimator &est) const
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
const int mu
Definition: Constants.h:22
const LocalTrajectoryError & localError() const
const Propagator * muonPropagator_
const edm::ESGetToken< TrajectoryStateUpdator, TrackingComponentsRecord > updatorToken_
const edm::EDGetTokenT< MeasurementTrackerEvent > measurementTrackerTag_
bool isValid() const
const GlobalTrackingGeometry * geometry_
StringCutObjectSelector< reco::Muon > selector_
Muon selection.
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > geometryToken_
edm::EDGetTokenT< edm::View< reco::Muon > > src_
Labels for input collections.
void doDebug(const reco::Track &tk) const
const int layersToTry_
How many layers to try.
GlobalVector globalMomentum() const
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:94
const edm::ESGetToken< Chi2MeasurementEstimatorBase, TrackingComponentsRecord > estimatorToken_
const int hitsToTry_
How many hits to try on same layer.
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeometryToken_
DetId geographicalId() const
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual void compatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetWithState > &result) const
OutsideInMuonSeeder(const edm::ParameterSet &iConfig)
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > trackerPropagatorToken_
#define LogDebug(id)