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,
93  const TrajectoryStateOnSurface &state,
94  std::vector<TrajectorySeed> &out,
95  const Propagator &muon_propagator,
96  const Propagator &tracker_propagator,
97  const MeasurementTrackerEvent &mte) const ;
98  void doDebug(const reco::Track &tk) const;
99 
100 };
101 
103  src_(consumes<edm::View<reco::Muon> >(iConfig.getParameter<edm::InputTag>("src"))),
104  selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true),
105  layersToTry_(iConfig.getParameter<int32_t>("layersToTry")),
106  hitsToTry_(iConfig.getParameter<int32_t>("hitsToTry")),
107  fromVertex_(iConfig.getParameter<bool>("fromVertex")),
108  errorRescaling_(iConfig.getParameter<double>("errorRescaleFactor")),
109  trackerPropagatorName_(iConfig.getParameter<std::string>("trackerPropagator")),
110  muonPropagatorName_(iConfig.getParameter<std::string>("muonPropagator")),
111  measurementTrackerTag_(consumes<MeasurementTrackerEvent>(edm::InputTag("MeasurementTrackerEvent"))),
112  estimatorName_(iConfig.getParameter<std::string>("hitCollector")),
113  minEtaForTEC_(iConfig.getParameter<double>("minEtaForTEC")),
114  maxEtaForTOB_(iConfig.getParameter<double>("maxEtaForTOB")),
115  debug_(iConfig.getUntrackedParameter<bool>("debug",false)),
116  dummyPlane_(Plane::build(Plane::PositionType(), Plane::RotationType()))
117 {
118  produces<std::vector<TrajectorySeed> >();
119  updatorName_ = "KFUpdator";
120 }
121 
122 void
124  using namespace edm;
125  using namespace std;
126 
127  iSetup.get<IdealMagneticFieldRecord>().get(magfield_);
133 
136 
138  iEvent.getByToken(src_, src);
139 
140 
141  auto_ptr<vector<TrajectorySeed> > out(new vector<TrajectorySeed>());
142 
143  for (View<reco::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
144  const reco::Muon &mu = *it;
145  if (mu.outerTrack().isNull() || !selector_(mu)) continue;
146  if (debug_ && mu.innerTrack().isNonnull()) doDebug(*mu.innerTrack());
147 
148  // Better clone here and not directly into doLayer to avoid
149  // useless clone/destroy operations to set, in the end, the
150  // very same direction every single time.
151  std::unique_ptr<Propagator> pmuon_cloned = SetPropagationDirection(*muonPropagator_,
153  std::unique_ptr<Propagator> ptracker_cloned = SetPropagationDirection(*trackerPropagator_, alongMomentum);
154 
155  int sizeBefore = out->size();
156  if (debug_) std::cout << "\n\n\nSeeding for muon of pt " << mu.pt() << ", eta " << mu.eta() << ", phi " << mu.phi() << std::endl;
157  const reco::Track &tk = *mu.outerTrack();
158 
160  if (fromVertex_) {
162  dummyPlane_->move(fstate.position() - dummyPlane_->position());
163  state = TrajectoryStateOnSurface(fstate, *dummyPlane_);
164  } else {
166  }
167  if (std::abs(tk.eta()) < maxEtaForTOB_) {
168  std::vector< BarrelDetLayer const* > const & tob = measurementTracker->geometricSearchTracker()->tobLayers();
169  int iLayer = 6, found = 0;
170  for (auto it = tob.rbegin(), ed = tob.rend(); it != ed; ++it, --iLayer) {
171  if (debug_) std::cout << "\n ==== Trying TOB " << iLayer << " ====" << std::endl;
172  if (doLayer(**it, state, *out,
173  *(pmuon_cloned.get()),
174  *(ptracker_cloned.get()),
175  *measurementTracker)) {
176  if (++found == layersToTry_) break;
177  }
178  }
179  }
180  if (tk.eta() > minEtaForTEC_) {
181  int iLayer = 9, found = 0;
182  std::vector< ForwardDetLayer const* > const & tec = measurementTracker->geometricSearchTracker()->posTecLayers();
183  for (auto it = tec.rbegin(), ed = tec.rend(); it != ed; ++it, --iLayer) {
184  if (debug_) std::cout << "\n ==== Trying TEC " << +iLayer << " ====" << std::endl;
185  if (doLayer(**it, state, *out,
186  *(pmuon_cloned.get()),
187  *(ptracker_cloned.get()),
188  *measurementTracker)) {
189  if (++found == layersToTry_) break;
190  }
191  }
192  }
193  if (tk.eta() < -minEtaForTEC_) {
194  int iLayer = 9, found = 0;
195  std::vector< ForwardDetLayer const* > const & tec = measurementTracker->geometricSearchTracker()->negTecLayers();
196  for (auto it = tec.rbegin(), ed = tec.rend(); it != ed; ++it, --iLayer) {
197  if (debug_) std::cout << "\n ==== Trying TEC " << -iLayer << " ====" << std::endl;
198  if (doLayer(**it, state, *out,
199  *(pmuon_cloned.get()),
200  *(ptracker_cloned.get()),
201  *measurementTracker)) {
202  if (++found == layersToTry_) break;
203  }
204  }
205  }
206  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;
207 
208  }
209 
210  iEvent.put(out);
211 }
212 
213 int
215  const TrajectoryStateOnSurface &state,
216  std::vector<TrajectorySeed> &out,
217  const Propagator & muon_propagator,
218  const Propagator & tracker_propagator,
220  TrajectoryStateOnSurface onLayer(state);
221  onLayer.rescaleError(errorRescaling_);
222  std::vector< GeometricSearchDet::DetWithState > dets;
223  layer.compatibleDetsV(onLayer, muon_propagator, *estimator_, dets);
224 
225  if (debug_) {
226  std::cout << "Query on layer around x = " << onLayer.globalPosition() <<
227  " with local pos error " << sqrt(onLayer.localError().positionError().xx()) << " , " << sqrt(onLayer.localError().positionError().yy()) << " , " <<
228  " returned " << dets.size() << " compatible detectors" << std::endl;
229  }
230 
231  std::vector<TrajectoryMeasurement> meas;
232  for (std::vector<GeometricSearchDet::DetWithState>::const_iterator it = dets.begin(), ed = dets.end(); it != ed; ++it) {
233  MeasurementDetWithData det = measurementTracker.idToDet(it->first->geographicalId());
234  if (det.isNull()) { std::cerr << "BOGUS detid " << it->first->geographicalId().rawId() << std::endl; continue; }
235  if (!it->second.isValid()) continue;
236  std::vector < TrajectoryMeasurement > mymeas = det.fastMeasurements(it->second, state, tracker_propagator, *estimator_);
237  if (debug_) std::cout << "Query on detector " << it->first->geographicalId().rawId() << " returned " << mymeas.size() << " measurements." << std::endl;
238  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = mymeas.begin(), ed2 = mymeas.end(); it2 != ed2; ++it2) {
239  if (it2->recHit()->isValid()) meas.push_back(*it2);
240  }
241  }
242  int found = 0;
243  std::sort(meas.begin(), meas.end(), TrajMeasLessEstim());
244  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = meas.begin(), ed2 = meas.end(); it2 != ed2; ++it2) {
245  if (debug_) {
246  std::cout << " inspecting Hit with chi2 = " << it2->estimate() << std::endl;
247  std::cout << " track state " << it2->forwardPredictedState().globalPosition() << std::endl;
248  std::cout << " rechit position " << it2->recHit()->globalPosition() << std::endl;
249  }
250  TrajectoryStateOnSurface updated = updator_->update(it2->forwardPredictedState(), *it2->recHit());
251  if (updated.isValid()) {
252  if (debug_) std::cout << " --> updated state: x = " << updated.globalPosition() << ", p = " << updated.globalMomentum() << std::endl;
254  seedHits.push_back(*it2->recHit()->hit());
255  PTrajectoryStateOnDet const & pstate = trajectoryStateTransform::persistentState(updated, it2->recHit()->geographicalId().rawId());
256  TrajectorySeed seed(pstate, std::move(seedHits), oppositeToMomentum);
257  out.push_back(seed);
258  found++; if (found == hitsToTry_) break;
259  }
260  }
261  return found;
262 }
263 
264 void
267  std::unique_ptr<Propagator> pmuon_cloned = SetPropagationDirection(*muonPropagator_, alongMomentum);
268  for (unsigned int i = 0; i < tk.recHitsSize(); ++i) {
269  const TrackingRecHit *hit = &*tk.recHit(i);
270  const GeomDet *det = geometry_->idToDet(hit->geographicalId());
271  if (det == 0) continue;
272  if (i != 0) tsos = pmuon_cloned->propagate(tsos, det->surface());
273  if (!tsos.isValid()) continue;
274  std::cout << " state " << i << " at x = " << tsos.globalPosition() << ", p = " << tsos.globalMomentum() << std::endl;
275  if (hit->isValid()) {
276  std::cout << " valid rechit on detid " << hit->geographicalId().rawId() << std::endl;
277  } else {
278  std::cout << " invalid rechit on detid " << hit->geographicalId().rawId() << std::endl;
279  }
280  }
281 }
282 
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
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#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_
virtual double phi() const final
momentum azimuthal angle
GlobalPoint globalPosition() const
edm::ESHandle< Propagator > trackerPropagator_
edm::ESHandle< TrajectoryStateUpdator > updator_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
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
Definition: Plane.h:17
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
std::unique_ptr< Propagator > SetPropagationDirection(Propagator const &iprop, PropagationDirection dir)
void push_back(D *&d)
Definition: OwnVector.h:290
std::string trackerPropagatorName_
int iEvent
Definition: GenABIO.cc:230
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
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:121
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
def move
Definition: eostools.py:510
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 isNull() const
Checks for null.
Definition: Ref.h:249
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
edm::ESHandle< Propagator > muonPropagator_
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
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.
edm::EDGetTokenT< edm::View< reco::Muon > > src_
Labels for input collections.
void doDebug(const reco::Track &tk) const
GlobalVector globalMomentum() const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:114
tuple cout
Definition: gather_cfg.py:145
virtual double eta() const final
momentum pseudorapidity
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.
std::string measurementTrackerName_
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
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)
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
virtual double pt() const final
transverse momentum