CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutsideInMuonSeeder.cc
Go to the documentation of this file.
1 
2 //
3 //
4 
19 
21 
26 
43 
45  public:
46  explicit OutsideInMuonSeeder(const edm::ParameterSet & iConfig);
47  virtual ~OutsideInMuonSeeder() { }
48 
49  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
50 
51  private:
54 
57 
60 
63 
66 
69 
76 
78 
85 
87  bool debug_;
88 
91 
92  int doLayer(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &state, std::vector<TrajectorySeed> &out, const MeasurementTrackerEvent &mte) const ;
93  void doDebug(const reco::Track &tk) const;
94 
95 };
96 
98  src_(iConfig.getParameter<edm::InputTag>("src")),
99  selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true),
100  layersToTry_(iConfig.getParameter<int32_t>("layersToTry")),
101  hitsToTry_(iConfig.getParameter<int32_t>("hitsToTry")),
102  fromVertex_(iConfig.getParameter<bool>("fromVertex")),
103  errorRescaling_(iConfig.getParameter<double>("errorRescaleFactor")),
104  trackerPropagatorName_(iConfig.getParameter<std::string>("trackerPropagator")),
105  muonPropagatorName_(iConfig.getParameter<std::string>("muonPropagator")),
106  measurementTrackerTag_(consumes<MeasurementTrackerEvent>(edm::InputTag("MeasurementTrackerEvent"))),
107  estimatorName_(iConfig.getParameter<std::string>("hitCollector")),
108  minEtaForTEC_(iConfig.getParameter<double>("minEtaForTEC")),
109  maxEtaForTOB_(iConfig.getParameter<double>("maxEtaForTOB")),
110  debug_(iConfig.getUntrackedParameter<bool>("debug",false)),
111  dummyPlane_(Plane::build(Plane::PositionType(), Plane::RotationType()))
112 {
113  produces<std::vector<TrajectorySeed> >();
114  updatorName_ = "KFUpdator";
115 }
116 
117 void
119  using namespace edm;
120  using namespace std;
121 
122  iSetup.get<IdealMagneticFieldRecord>().get(magfield_);
128 
129  Handle<MeasurementTrackerEvent> measurementTracker;
130  iEvent.getByToken(measurementTrackerTag_, measurementTracker);
131 
133  iEvent.getByLabel(src_, src);
134 
135 
136  auto_ptr<vector<TrajectorySeed> > out(new vector<TrajectorySeed>());
137 
138  for (View<reco::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
139  const reco::Muon &mu = *it;
140  if (mu.outerTrack().isNull() || !selector_(mu)) continue;
141  if (debug_ && mu.innerTrack().isNonnull()) doDebug(*mu.innerTrack());
142 
143  muonPropagator_->setPropagationDirection(fromVertex_ ? alongMomentum : oppositeToMomentum);
144  trackerPropagator_->setPropagationDirection(alongMomentum);
145 
146  int sizeBefore = out->size();
147  if (debug_) std::cout << "\n\n\nSeeding for muon of pt " << mu.pt() << ", eta " << mu.eta() << ", phi " << mu.phi() << std::endl;
148  const reco::Track &tk = *mu.outerTrack();
149 
151  if (fromVertex_) {
153  dummyPlane_->move(fstate.position() - dummyPlane_->position());
154  state = TrajectoryStateOnSurface(fstate, *dummyPlane_);
155  } else {
157  }
158  if (std::abs(tk.eta()) < maxEtaForTOB_) {
159  std::vector< BarrelDetLayer * > const & tob = measurementTracker->geometricSearchTracker()->tobLayers();
160  int iLayer = 6, found = 0;
161  for (std::vector<BarrelDetLayer *>::const_reverse_iterator it = tob.rbegin(), ed = tob.rend(); it != ed; ++it, --iLayer) {
162  if (debug_) std::cout << "\n ==== Trying TOB " << iLayer << " ====" << std::endl;
163  if (doLayer(**it, state, *out, *measurementTracker)) {
164  if (++found == layersToTry_) break;
165  }
166  }
167  }
168  if (tk.eta() > minEtaForTEC_) {
169  int iLayer = 9, found = 0;
170  std::vector< ForwardDetLayer * > const & tec = measurementTracker->geometricSearchTracker()->posTecLayers();
171  for (std::vector<ForwardDetLayer *>::const_reverse_iterator it = tec.rbegin(), ed = tec.rend(); it != ed; ++it, --iLayer) {
172  if (debug_) std::cout << "\n ==== Trying TEC " << +iLayer << " ====" << std::endl;
173  if (doLayer(**it, state, *out, *measurementTracker)) {
174  if (++found == layersToTry_) break;
175  }
176  }
177  }
178  if (tk.eta() < -minEtaForTEC_) {
179  int iLayer = 9, found = 0;
180  std::vector< ForwardDetLayer * > const & tec = measurementTracker->geometricSearchTracker()->negTecLayers();
181  for (std::vector<ForwardDetLayer *>::const_reverse_iterator it = tec.rbegin(), ed = tec.rend(); it != ed; ++it, --iLayer) {
182  if (debug_) std::cout << "\n ==== Trying TEC " << -iLayer << " ====" << std::endl;
183  if (doLayer(**it, state, *out, *measurementTracker)) {
184  if (++found == layersToTry_) break;
185  }
186  }
187  }
188  if (debug_) std::cout << "Outcome of seeding for muon of pt " << mu.pt() << ", eta " << mu.eta() << ", phi " << mu.phi() << ": found " << (out->size() - sizeBefore) << " seeds."<< std::endl;
189 
190  }
191 
192  iEvent.put(out);
193 }
194 
195 int
196 OutsideInMuonSeeder::doLayer(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &state, std::vector<TrajectorySeed> &out, const MeasurementTrackerEvent &measurementTracker) const {
197  TrajectoryStateOnSurface onLayer(state);
198  onLayer.rescaleError(errorRescaling_);
199  std::vector< GeometricSearchDet::DetWithState > dets;
200  layer.compatibleDetsV(onLayer, *muonPropagator_, *estimator_, dets);
201 
202  if (debug_) {
203  std::cout << "Query on layer around x = " << onLayer.globalPosition() <<
204  " with local pos error " << sqrt(onLayer.localError().positionError().xx()) << " , " << sqrt(onLayer.localError().positionError().yy()) << " , " <<
205  " returned " << dets.size() << " compatible detectors" << std::endl;
206  }
207 
208  std::vector<TrajectoryMeasurement> meas;
209  for (std::vector<GeometricSearchDet::DetWithState>::const_iterator it = dets.begin(), ed = dets.end(); it != ed; ++it) {
210  MeasurementDetWithData det = measurementTracker.idToDet(it->first->geographicalId());
211  if (det.isNull()) { std::cerr << "BOGUS detid " << it->first->geographicalId().rawId() << std::endl; continue; }
212  if (!it->second.isValid()) continue;
213  std::vector < TrajectoryMeasurement > mymeas = det.fastMeasurements(it->second, state, *trackerPropagator_, *estimator_);
214  if (debug_) std::cout << "Query on detector " << it->first->geographicalId().rawId() << " returned " << mymeas.size() << " measurements." << std::endl;
215  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = mymeas.begin(), ed2 = mymeas.end(); it2 != ed2; ++it2) {
216  if (it2->recHit()->isValid()) meas.push_back(*it2);
217  }
218  }
219  int found = 0;
220  std::sort(meas.begin(), meas.end(), TrajMeasLessEstim());
221  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = meas.begin(), ed2 = meas.end(); it2 != ed2; ++it2) {
222  if (debug_) {
223  std::cout << " inspecting Hit with chi2 = " << it2->estimate() << std::endl;
224  std::cout << " track state " << it2->forwardPredictedState().globalPosition() << std::endl;
225  std::cout << " rechit position " << it2->recHit()->globalPosition() << std::endl;
226  }
227  TrajectoryStateOnSurface updated = updator_->update(it2->forwardPredictedState(), *it2->recHit());
228  if (updated.isValid()) {
229  if (debug_) std::cout << " --> updated state: x = " << updated.globalPosition() << ", p = " << updated.globalMomentum() << std::endl;
231  seedHits.push_back(*it2->recHit()->hit());
232  PTrajectoryStateOnDet const & pstate = trajectoryStateTransform::persistentState(updated, it2->recHit()->geographicalId().rawId());
233  TrajectorySeed seed(pstate, std::move(seedHits), oppositeToMomentum);
234  out.push_back(seed);
235  found++; if (found == hitsToTry_) break;
236  }
237  }
238  return found;
239 }
240 
241 void
244  muonPropagator_->setPropagationDirection(alongMomentum);
245  for (unsigned int i = 0; i < tk.recHitsSize(); ++i) {
246  const TrackingRecHit *hit = &*tk.recHit(i);
247  const GeomDet *det = geometry_->idToDet(hit->geographicalId());
248  if (det == 0) continue;
249  if (i != 0) tsos = muonPropagator_->propagate(tsos, det->surface());
250  if (!tsos.isValid()) continue;
251  std::cout << " state " << i << " at x = " << tsos.globalPosition() << ", p = " << tsos.globalMomentum() << std::endl;
252  if (hit->isValid()) {
253  std::cout << " valid rechit on detid " << hit->geographicalId().rawId() << std::endl;
254  } else {
255  std::cout << " invalid rechit on detid " << hit->geographicalId().rawId() << std::endl;
256  }
257  }
258 }
259 
int hitsToTry_
How many hits to try on same layer.
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
MeasurementDetWithData idToDet(const DetId &id) const
Previous MeasurementDetSystem interface.
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field)
edm::InputTag src_
Labels for input collections.
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#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:68
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_
edm::ESHandle< TrajectoryStateUpdator > updator_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
LocalError positionError() const
Definition: Plane.h:17
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
void push_back(D *&d)
Definition: OwnVector.h:273
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
std::string trackerPropagatorName_
int iEvent
Definition: GenABIO.cc:243
bool isNull() const
Checks for null.
Definition: Ref.h:247
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:139
float yy() const
Definition: LocalError.h:26
bool debug_
Dump deug information.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
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
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
const int mu
Definition: Constants.h:22
const LocalTrajectoryError & localError() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
edm::ESHandle< Propagator > muonPropagator_
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
tuple out
Definition: dbtoconf.py:99
GlobalPoint position() const
int doLayer(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &state, std::vector< TrajectorySeed > &out, const MeasurementTrackerEvent &mte) const
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
bool isValid() const
int layersToTry_
How many layers to try.
StringCutObjectSelector< reco::Muon > selector_
Muon selection.
double errorRescaling_
How much to rescale errors from STA.
void doDebug(const reco::Track &tk) const
GlobalVector globalMomentum() const
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:66
tuple cout
Definition: gather_cfg.py:121
edm::EDGetTokenT< MeasurementTrackerEvent > measurementTrackerTag_
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
Plane::PlanePointer dummyPlane_
Surface used to make a TSOS at the PCA to the beamline.
virtual float pt() const GCC11_FINAL
transverse momentum
std::string measurementTrackerName_
bool fromVertex_
Do inside-out.
virtual void compatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetWithState > &result) const
OutsideInMuonSeeder(const edm::ParameterSet &iConfig)