CMS 3D CMS Logo

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